@univerjs/docs-ui 0.1.16 → 0.1.17
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 +1121 -1244
- package/lib/types/controllers/doc-editor-bridge.controller.d.ts +1 -3
- package/lib/types/controllers/render-controllers/back-scroll.render-controller.d.ts +14 -0
- package/lib/types/controllers/render-controllers/doc-floating-object.render-controller.d.ts +17 -0
- package/lib/types/controllers/render-controllers/doc.render-controller.d.ts +19 -0
- package/lib/types/controllers/render-controllers/text-selection.render-controller.d.ts +23 -0
- package/lib/types/controllers/render-controllers/zoom.render-controller.d.ts +20 -0
- package/lib/types/docs-ui-plugin.d.ts +8 -4
- package/lib/types/index.d.ts +2 -1
- package/lib/types/services/docs-render.service.d.ts +12 -0
- package/lib/umd/index.js +3 -3
- package/package.json +12 -12
- package/lib/types/controllers/back-scroll.controller.d.ts +0 -16
- package/lib/types/controllers/doc-floating-object.controller.d.ts +0 -19
- package/lib/types/controllers/doc-render.controller.d.ts +0 -17
- package/lib/types/controllers/drawing.controller.d.ts +0 -19
- package/lib/types/controllers/text-selection.controller.d.ts +0 -25
- package/lib/types/controllers/zoom.controller.d.ts +0 -23
- package/lib/types/views/doc-canvas-view.d.ts +0 -20
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
2
2
|
import { IRenderManagerService, ITextSelectionRenderManager } from '@univerjs/engine-render';
|
|
3
|
-
import { DocSkeletonManagerService } from '@univerjs/docs';
|
|
4
3
|
import { IEditorService } from '@univerjs/ui';
|
|
5
4
|
|
|
6
5
|
export declare class DocEditorBridgeController extends Disposable {
|
|
7
6
|
private readonly _univerInstanceService;
|
|
8
|
-
private readonly _docSkeletonManagerService;
|
|
9
7
|
private readonly _editorService;
|
|
10
8
|
private readonly _commandService;
|
|
11
9
|
private readonly _textSelectionRenderManager;
|
|
12
10
|
private readonly _renderManagerService;
|
|
13
11
|
private _initialEditors;
|
|
14
|
-
constructor(_univerInstanceService: IUniverInstanceService,
|
|
12
|
+
constructor(_univerInstanceService: IUniverInstanceService, _editorService: IEditorService, _commandService: ICommandService, _textSelectionRenderManager: ITextSelectionRenderManager, _renderManagerService: IRenderManagerService);
|
|
15
13
|
private _initialize;
|
|
16
14
|
private _resize;
|
|
17
15
|
private _initialSetValue;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DocumentDataModel, RxDisposable } from '@univerjs/core';
|
|
2
|
+
import { DocSkeletonManagerService, TextSelectionManagerService } from '@univerjs/docs';
|
|
3
|
+
import { IRenderContext, IRenderModule } from '@univerjs/engine-render';
|
|
4
|
+
import { IEditorService } from '@univerjs/ui';
|
|
5
|
+
|
|
6
|
+
export declare class DocBackScrollRenderController extends RxDisposable implements IRenderModule {
|
|
7
|
+
private readonly _context;
|
|
8
|
+
private readonly _docSkeletonManagerService;
|
|
9
|
+
private readonly _textSelectionManagerService;
|
|
10
|
+
private readonly _editorService;
|
|
11
|
+
constructor(_context: IRenderContext<DocumentDataModel>, _docSkeletonManagerService: DocSkeletonManagerService, _textSelectionManagerService: TextSelectionManagerService, _editorService: IEditorService);
|
|
12
|
+
private _init;
|
|
13
|
+
private _scrollToSelection;
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DocumentDataModel, Disposable, ICommandService } from '@univerjs/core';
|
|
2
|
+
import { DocSkeletonManagerService } from '@univerjs/docs';
|
|
3
|
+
import { IRenderContext, IRenderModule } from '@univerjs/engine-render';
|
|
4
|
+
import { IEditorService } from '@univerjs/ui';
|
|
5
|
+
|
|
6
|
+
export declare class DocFloatingObjectRenderController extends Disposable implements IRenderModule {
|
|
7
|
+
private readonly _context;
|
|
8
|
+
private readonly _docSkeletonManagerService;
|
|
9
|
+
private readonly _commandService;
|
|
10
|
+
private readonly _editorService;
|
|
11
|
+
private _liquid;
|
|
12
|
+
private _pageMarginCache;
|
|
13
|
+
constructor(_context: IRenderContext<DocumentDataModel>, _docSkeletonManagerService: DocSkeletonManagerService, _commandService: ICommandService, _editorService: IEditorService);
|
|
14
|
+
private _initialize;
|
|
15
|
+
private _commandExecutedListener;
|
|
16
|
+
private _refreshDrawing;
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DocumentDataModel, ICommandService, IConfigService, RxDisposable } from '@univerjs/core';
|
|
2
|
+
import { DocSkeletonManagerService } from '@univerjs/docs';
|
|
3
|
+
import { IRenderContext, IRenderModule } from '@univerjs/engine-render';
|
|
4
|
+
import { IEditorService } from '@univerjs/ui';
|
|
5
|
+
|
|
6
|
+
export declare class DocRenderController extends RxDisposable implements IRenderModule {
|
|
7
|
+
private readonly _context;
|
|
8
|
+
private readonly _commandService;
|
|
9
|
+
private readonly _docSkeletonManagerService;
|
|
10
|
+
private readonly _configService;
|
|
11
|
+
private readonly _editorService;
|
|
12
|
+
constructor(_context: IRenderContext<DocumentDataModel>, _commandService: ICommandService, _docSkeletonManagerService: DocSkeletonManagerService, _configService: IConfigService, _editorService: IEditorService);
|
|
13
|
+
private _addNewRender;
|
|
14
|
+
private _addComponent;
|
|
15
|
+
private _initRenderRefresh;
|
|
16
|
+
private _create;
|
|
17
|
+
private _initCommandListener;
|
|
18
|
+
private _recalculateSizeBySkeleton;
|
|
19
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DocumentDataModel, Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
2
|
+
import { IRenderContext, IRenderModule, ITextSelectionRenderManager } from '@univerjs/engine-render';
|
|
3
|
+
import { IEditorService } from '@univerjs/ui';
|
|
4
|
+
import { DocSkeletonManagerService, TextSelectionManagerService } from '@univerjs/docs';
|
|
5
|
+
|
|
6
|
+
export declare class DocTextSelectionRenderController extends Disposable implements IRenderModule {
|
|
7
|
+
private readonly _context;
|
|
8
|
+
private readonly _commandService;
|
|
9
|
+
private readonly _editorService;
|
|
10
|
+
private readonly _instanceSrv;
|
|
11
|
+
private readonly _textSelectionRenderManager;
|
|
12
|
+
private readonly _docSkeletonManagerService;
|
|
13
|
+
private readonly _textSelectionManagerService;
|
|
14
|
+
private _loadedMap;
|
|
15
|
+
constructor(_context: IRenderContext<DocumentDataModel>, _commandService: ICommandService, _editorService: IEditorService, _instanceSrv: IUniverInstanceService, _textSelectionRenderManager: ITextSelectionRenderManager, _docSkeletonManagerService: DocSkeletonManagerService, _textSelectionManagerService: TextSelectionManagerService);
|
|
16
|
+
private _initialize;
|
|
17
|
+
private _init;
|
|
18
|
+
private _initialMain;
|
|
19
|
+
private _isEditorReadOnly;
|
|
20
|
+
private _setEditorFocus;
|
|
21
|
+
private _commandExecutedListener;
|
|
22
|
+
private _skeletonListener;
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DocumentDataModel, Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
2
|
+
import { DocSkeletonManagerService, TextSelectionManagerService } from '@univerjs/docs';
|
|
3
|
+
import { IRenderContext, IRenderModule } from '@univerjs/engine-render';
|
|
4
|
+
import { IEditorService } from '@univerjs/ui';
|
|
5
|
+
|
|
6
|
+
export declare class DocZoomRenderController extends Disposable implements IRenderModule {
|
|
7
|
+
private readonly _context;
|
|
8
|
+
private readonly _docSkeletonManagerService;
|
|
9
|
+
private readonly _univerInstanceService;
|
|
10
|
+
private readonly _commandService;
|
|
11
|
+
private readonly _textSelectionManagerService;
|
|
12
|
+
private readonly _editorService;
|
|
13
|
+
constructor(_context: IRenderContext<DocumentDataModel>, _docSkeletonManagerService: DocSkeletonManagerService, _univerInstanceService: IUniverInstanceService, _commandService: ICommandService, _textSelectionManagerService: TextSelectionManagerService, _editorService: IEditorService);
|
|
14
|
+
private _init;
|
|
15
|
+
private _initRenderRefresher;
|
|
16
|
+
private _initSkeletonListener;
|
|
17
|
+
private _initCommandExecutedListener;
|
|
18
|
+
private _updateViewZoom;
|
|
19
|
+
private _calculatePagePosition;
|
|
20
|
+
}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { ILogService,
|
|
1
|
+
import { ILogService, Plugin, UniverInstanceType } from '@univerjs/core';
|
|
2
2
|
import { Injector } from '@wendellhu/redi';
|
|
3
|
+
import { IRenderManagerService } from '@univerjs/engine-render';
|
|
3
4
|
import { IUniverDocsUIConfig } from './basics';
|
|
4
5
|
|
|
5
6
|
export declare class UniverDocsUIPlugin extends Plugin {
|
|
6
7
|
private readonly _config;
|
|
7
8
|
_injector: Injector;
|
|
8
|
-
private readonly
|
|
9
|
+
private readonly _renderManagerSrv;
|
|
9
10
|
private _logService;
|
|
10
11
|
static pluginName: string;
|
|
11
12
|
static type: UniverInstanceType;
|
|
12
|
-
constructor(_config: IUniverDocsUIConfig, _injector: Injector,
|
|
13
|
+
constructor(_config: IUniverDocsUIConfig, _injector: Injector, _renderManagerSrv: IRenderManagerService, _logService: ILogService);
|
|
14
|
+
onReady(): void;
|
|
13
15
|
onRendered(): void;
|
|
14
16
|
private _initializeCommands;
|
|
15
17
|
private _initDependencies;
|
|
16
18
|
private _markDocAsFocused;
|
|
17
|
-
private
|
|
19
|
+
private _initUI;
|
|
20
|
+
private _initRenderBasics;
|
|
21
|
+
private _initRenderModules;
|
|
18
22
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
*/
|
|
16
16
|
export * from './basics';
|
|
17
17
|
export * from './docs-ui-plugin';
|
|
18
|
-
export {
|
|
18
|
+
export { DocRenderController } from './controllers/render-controllers/doc.render-controller';
|
|
19
19
|
export * from './services';
|
|
20
|
+
export { DocsRenderService } from './services/docs-render.service';
|
|
20
21
|
export { DocCanvasPopManagerService } from './services/doc-popup-manager.service';
|
|
21
22
|
export { docDrawingPositionToTransform, transformToDocDrawingPosition } from './basics/transform-position';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IUniverInstanceService, RxDisposable } from '@univerjs/core';
|
|
2
|
+
import { IRenderManagerService } from '@univerjs/engine-render';
|
|
3
|
+
|
|
4
|
+
export declare class DocsRenderService extends RxDisposable {
|
|
5
|
+
private readonly _instanceSrv;
|
|
6
|
+
private readonly _renderManagerService;
|
|
7
|
+
constructor(_instanceSrv: IUniverInstanceService, _renderManagerService: IRenderManagerService);
|
|
8
|
+
private _init;
|
|
9
|
+
private _createRenderer;
|
|
10
|
+
private _createRenderWithId;
|
|
11
|
+
private _disposeRenderer;
|
|
12
|
+
}
|
package/lib/umd/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(g,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("@univerjs/engine-render"),require("@univerjs/docs"),require("@wendellhu/redi/react-bindings"),require("react"),require("rxjs"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","@univerjs/engine-render","@univerjs/docs","@wendellhu/redi/react-bindings","react","rxjs","@univerjs/design"],a):(g=typeof globalThis<"u"?globalThis:g||self,a(g.UniverDocsUi={},g.UniverCore,g["@wendellhu/redi"],g.UniverUi,g.UniverEngineRender,g.UniverDocs,g["@wendellhu/redi/react-bindings"],g.React,g.rxjs,g.UniverDesign))})(this,function(g,a,C,l,I,d,we,$e,T,Ve){"use strict";var Pn=Object.defineProperty;var Un=(g,a,C)=>a in g?Pn(g,a,{enumerable:!0,configurable:!0,writable:!0,value:C}):g[a]=C;var b=(g,a,C)=>Un(g,typeof a!="symbol"?a+"":a,C);var ee;const me={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},Se={outerLeft:!1,outerRight:!1,header:!0,footer:!0,innerLeft:!1,innerRight:!1,frozenHeaderLT:!1,frozenHeaderRT:!1,frozenHeaderLM:!1,frozenContent:!1,infoBar:!0,toolbar:!0},fe={layout:{docContainerConfig:Se,toolbarConfig:me}},ve="DocUI";function R(i){return i.getContextValue(a.FOCUSING_DOC)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function je(i){return i.getContextValue(a.FOCUSING_DOC)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(a.FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE)&&!i.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}const We={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_UP,preconditions:R,staticParameters:{direction:a.Direction.UP}},He={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_DOWN,preconditions:R,staticParameters:{direction:a.Direction.DOWN}},ze={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_LEFT,preconditions:R,staticParameters:{direction:a.Direction.LEFT}},ke={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_RIGHT,preconditions:R,staticParameters:{direction:a.Direction.RIGHT}},Ge={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_UP|l.MetaKeys.SHIFT,preconditions:R,staticParameters:{direction:a.Direction.UP}},Ye={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_DOWN|l.MetaKeys.SHIFT,preconditions:R,staticParameters:{direction:a.Direction.DOWN}},Ke={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_LEFT|l.MetaKeys.SHIFT,preconditions:R,staticParameters:{direction:a.Direction.LEFT}},Xe={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_RIGHT|l.MetaKeys.SHIFT,preconditions:R,staticParameters:{direction:a.Direction.RIGHT}},qe={id:d.SelectAllOperation.id,binding:l.KeyCode.A|l.MetaKeys.CTRL_COMMAND,preconditions:i=>i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&(i.getContextValue(a.FOCUSING_DOC)||i.getContextValue(a.EDITOR_ACTIVATED))};var Ze=Object.defineProperty,Je=Object.getOwnPropertyDescriptor,Qe=(i,e,t,n)=>{for(var r=n>1?void 0:n?Je(e,t):e,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&Ze(e,t,r),r},Ce=(i,e)=>(t,n)=>e(t,n,i);let ne=class{constructor(i,e,t){b(this,"_docContainer");b(this,"getComponent",i=>{if(this._docContainer=i,!i.getContentRef().current)throw new Error("container is not ready")});b(this,"changeLocale",i=>{this._localeService.setLocale(i)});this._config=i,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(i){if(this._docContainer)return i(this._docContainer)}getDocContainer(){return this._docContainer}};ne=Qe([Ce(1,C.Inject(a.LocaleService)),Ce(2,C.Inject(C.Injector))],ne);var et=Object.defineProperty,tt=Object.getOwnPropertyDescriptor,nt=(i,e,t,n)=>{for(var r=n>1?void 0:n?tt(e,t):e,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&et(e,t,r),r},z=(i,e)=>(t,n)=>e(t,n,i);let L=class extends a.RxDisposable{constructor(e,t,n,r,s){super();b(this,"_docContainerController");b(this,"changeLocale",e=>{this._localeService.setLocale(e)});this._localeService=t,this._injector=n,this._textSelectionRenderManager=r,this._layoutService=s,this._docContainerController=this._injector.createInstance(ne,e),this._registerContainer()}_registerContainer(){this._layoutService&&this.disposeWithMe(this._layoutService.registerContainerElement(this._textSelectionRenderManager.__getEditorContainer()))}getDocContainerController(){return this._docContainerController}};L=nt([z(1,C.Inject(a.LocaleService)),z(2,C.Inject(C.Injector)),z(3,I.ITextSelectionRenderManager),z(4,C.Optional(l.ILayoutService))],L);const k="UI_PLUGIN_DOCS",ie=`${k}_COLOR_PICKER_COMPONENT`,Ie=`${k}_FONT_FAMILY_COMPONENT`,Oe=`${k}_FONT_FAMILY_ITEM_COMPONENT`,Te=`${k}_FONT_SIZE_COMPONENT`;var be={exports:{}},G={};/**
|
|
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=je,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 Ee(i,e,t){var n,r={},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)&&(r[n]=e[n]);if(i&&i.defaultProps)for(n in e=i.defaultProps,e)r[n]===void 0&&(r[n]=e[n]);return{$$typeof:st,type:i,key:o,ref:s,props:r,_owner:lt.current}}K.Fragment=at,K.jsx=Ee,K.jsxs=Ee,ye.exports=K;var ut=ye.exports;const ht={docsUiCanvasBackground:"univer-docs-ui-canvas-background"},pt=()=>ut.jsx("div",{className:ht.docsUiCanvasBackground});function _t(i){const e=i.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(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);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(i,a.UniverInstanceType.UNIVER_DOC)}}function gt(i){const e=i.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(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);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(i,a.UniverInstanceType.UNIVER_DOC)}}function St(i){const e=i.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(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);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(i,a.UniverInstanceType.UNIVER_DOC)}}function ft(i){const e=i.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(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);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(i,a.UniverInstanceType.UNIVER_DOC)}}function mt(i){const e=i.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(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);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(i,a.UniverInstanceType.UNIVER_DOC)}}function vt(i){const e=i.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(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);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(i,a.UniverInstanceType.UNIVER_DOC)}}function It(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatFontFamilyCommand.id,tooltip:"toolbar.font",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,label:be,positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_FAMILY_LIST.map(t=>({label:{name:Me,hoverable:!0},value:t.value})),value$:new b.Observable(t=>{const n=l.FONT_FAMILY_LIST[0].value,r=e.onCommandExecuted(o=>{var c;const s=o.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontFamilyCommand.id){const u=E(i);if(u==null)return;const h=(c=u.ts)==null?void 0:c.ff;t.next(h!=null?h:n)}});return t.next(n),r.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Ct(i){const e=i.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 r=e.onCommandExecuted(o=>{var c;const s=o.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontSizeCommand.id){const u=E(i);if(u==null)return;const h=(c=u.ts)==null?void 0:c.fs;t.next(h!=null?h:14)}});return t.next(14),r.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Ot(i){const e=i.get(a.ICommandService),t=i.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 b.Observable(n=>{const r=t.getCurrentTheme().textColor,o=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextColorCommand.id){const c=s.params.value;n.next(c!=null?c:r)}});return n.next(r),o.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Tt(i){const e=i.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(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=X(i);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(i,a.UniverInstanceType.UNIVER_DOC)}}function bt(i){const e=i.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(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=X(i);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(i,a.UniverInstanceType.UNIVER_DOC)}}function Mt(i){const e=i.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(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=X(i);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(i,a.UniverInstanceType.UNIVER_DOC)}}function Rt(i){const e=i.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(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=X(i);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(i,a.UniverInstanceType.UNIVER_DOC)}}function yt(i){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(i,a.UniverInstanceType.UNIVER_DOC)}}function Et(i){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(i,a.UniverInstanceType.UNIVER_DOC)}}function Dt(i){return{id:d.ResetInlineFormatTextBackgroundColorCommand.id,type:l.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:d.SetInlineFormatTextBackgroundColorCommand.id}}function Pt(i){const e=i.get(a.ICommandService),t=i.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 b.Observable(n=>{const r=t.getCurrentTheme().primaryColor,o=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextBackgroundColorCommand.id){const c=s.params.value;n.next(c!=null?c:r)}});return n.next(r),o.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function E(i){var u;const e=i.get(a.IUniverInstanceService),t=i.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const o=(u=n.getBody())==null?void 0:u.textRuns;if(o==null)return;const{startOffset:s}=r;let c;for(let h=0;h<o.length;h++){const _=o[h],g=o[h+1];if(g&&g.st===g.ed&&s===g.st){c=g;break}if(_.st<=s&&s<=_.ed){c=_;break}}return c}function X(i){var u;const e=i.get(a.IUniverInstanceService),t=i.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const o=(u=n.getBody())==null?void 0:u.paragraphs;if(o==null)return;const{startOffset:s}=r;let c=-1;for(const h of o){const{startIndex:_}=h;if(s>c&&s<=_)return h;c=_}return null}var Ut=Object.defineProperty,Nt=Object.getOwnPropertyDescriptor,xt=(i,e,t,n)=>{for(var r=n>1?void 0:n?Nt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Ut(e,t,r),r},P=(i,e)=>(t,n)=>e(t,n,i);let F=class extends a.Disposable{constructor(i,e,t,n,r,o,s,c){super(),this._config=i,this._injector=e,this._componentManager=t,this._layoutService=n,this._editorService=r,this._menuService=o,this._uiPartsService=s,this._univerInstanceService=c,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(ue,We.ColorPicker)),this.disposeWithMe(i.register(be,l.FontFamily)),this.disposeWithMe(i.register(Me,l.FontFamilyItem)),this.disposeWithMe(i.register(Re,l.FontSize))}_initMenus(){const{menu:i={}}=this._config;[_t,gt,St,ft,mt,vt,Ct,It,Ot,Tt,bt,Mt,Rt,yt,Et,Dt,Pt].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e),i))})}_init(){this._initCustomComponents(),this._initMenus(),this._initDocBackground(),this._initFocusHandler()}_initDocBackground(){const i=this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC)[0].getUnitId();if(i==null)return;this._editorService.isEditor(i)||this.disposeWithMe(this._uiPartsService.registerComponent(l.BuiltInUIPart.CONTENT,()=>Ve.connectInjector(pt,this._injector)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.UNIVER_DOC,()=>{this._injector.get(m.ITextSelectionRenderManager).focus()}))}};F=xt([a.OnLifecycle(a.LifecycleStages.Rendered,F),P(1,I.Inject(I.Injector)),P(2,I.Inject(l.ComponentManager)),P(3,l.ILayoutService),P(4,l.IEditorService),P(5,l.IMenuService),P(6,l.IUIPartsService),P(7,a.IUniverInstanceService)],F);const Lt={id:d.BreakLineCommand.id,preconditions:He,binding:l.KeyCode.ENTER},At={id:d.DeleteLeftCommand.id,preconditions:y,binding:l.KeyCode.BACKSPACE},Bt={id:d.DeleteRightCommand.id,preconditions:y,binding:l.KeyCode.DELETE},wt=10,Ft=6;function $t(){return a.Tools.generateRandomId(Ft)}function Vt(i){const e=i.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class jt{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 De=new jt;function he(i){const e=i.style,t={},n=i.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 r=0;r<e.length;r++){const o=e[r],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 Wt(i){const e=new DOMParser,t=`<x-univer id="univer-root">${i}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function Pe(i,e){const t=i.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(i)}const ce=class ce{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=ce._pluginList.find(o=>o.checkPasteType(e)),n=Wt(e),r={dataStream:"",textRuns:[]};return t&&(this._styleRules=[...t.stylesRules],this._afterProcessRules=[...t.afterProcessRules]),this._styleCache.clear(),this._process(null,n==null?void 0:n.childNodes,r),this._styleCache.clear(),this._styleRules=[],this._afterProcessRules=[],r}_process(e,t,n){var r;for(const o of t)if(o.nodeType===Node.TEXT_NODE){const s=(r=o.nodeValue)==null?void 0:r.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:g})=>Pe(o,g)),u=c?c.getStyle(o):he(o);this._styleCache.set(o,{...s,...u});const{childNodes:h}=o;this._process(o,h,n);const _=this._afterProcessRules.find(({filter:g})=>Pe(o,g));_&&_.handler(n,o)}}};T(ce,"_pluginList",[]);let x=ce;const Ue={name:"univer-doc-paste-plugin-lark",checkPasteType(i){return/lark-record-clipboard/i.test(i)},stylesRules:[{filter:["s"],getStyle(i){const e=he(i);return{st:{s:a.BooleanNumber.TRUE},...e}}}],afterProcessRules:[{filter(i){return i.tagName==="DIV"&&/ace-line/i.test(i.className)},handler(i){i.paragraphs==null&&(i.paragraphs=[]),i.paragraphs.push({startIndex:i.dataStream.length}),i.dataStream+="\r"}}]};function Ne(i){const e=i.style,t={};for(let n=0;n<e.length;n++){const r=e[n],o=e.getPropertyValue(r);switch(r){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 xe={name:"univer-doc-paste-plugin-word",checkPasteType(i){return/word|mso/i.test(i)},stylesRules:[{filter:["b"],getStyle(i){const e=he(i);return{bl:a.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(i){return i.tagName==="P"&&/mso/i.test(i.className)},handler(i,e){i.paragraphs==null&&(i.paragraphs=[]);const t={startIndex:i.dataStream.length},n=Ne(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]},Le={name:"univer-doc-paste-plugin-univer",checkPasteType(i){return/UniverNormal/i.test(i)},stylesRules:[],afterProcessRules:[{filter(i){return i.tagName==="P"&&/UniverNormal/i.test(i.className)},handler(i,e){i.paragraphs==null&&(i.paragraphs=[]);const t={startIndex:i.dataStream.length},n=Ne(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]};function Ae(i,e){const{st:t,ed:n,ts:r={}}=e,{ff:o,fs:s,it:c,bl:u,ul:h,st:_,ol:g,bg:C,cl:f,va:v}=r;let p=i.slice(t,n);const O=[];return c===a.BooleanNumber.TRUE&&(p=`<i>${p}</i>`),v===a.BaselineOffset.SUPERSCRIPT?p=`<sup>${p}</sup>`:v===a.BaselineOffset.SUBSCRIPT&&(p=`<sub>${p}</sub>`),(h==null?void 0:h.s)===a.BooleanNumber.TRUE&&(p=`<u>${p}</u>`),(_==null?void 0:_.s)===a.BooleanNumber.TRUE&&(p=`<s>${p}</s>`),u===a.BooleanNumber.TRUE&&(p=`<strong>${p}</strong>`),o&&O.push(`font-family: ${o}`),f&&O.push(`color: ${f.rgb}`),s&&O.push(`font-size: ${s}pt`),g&&O.push("text-decoration: overline"),C&&O.push(`background: ${C.rgb}`),O.length?`<span style="${O.join("; ")};">${p}</span>`:p}function pe(i,e,t){const{dataStream:n,textRuns:r=[]}=i;let o=e;const s=[];for(const c of r){const{st:u,ed:h}=c;a.Tools.hasIntersectionBetweenTwoRanges(e,t,u,h)&&(u>o?(s.push(n.slice(o,u)),s.push(Ae(n,{...c,ed:Math.min(h,t)}))):s.push(Ae(n,{...c,st:o,ed:Math.min(h,t)}))),o=Math.max(e,Math.min(h,t))}return o!==t&&s.push(n.slice(o,t)),s.join("")}function Be(i,e=!0){var t;if(e&&((t=i.paragraphs)!=null&&t.length)){const{dataStream:n,paragraphs:r=[]}=i;let o="",s=-1;for(const c of r){const{startIndex:u,paragraphStyle:h={}}=c,{spaceAbove:_,spaceBelow:g,lineSpacing:C}=h,f=[];_!=null&&(typeof _=="number"?f.push(`margin-top: ${_}px`):f.push(`margin-top: ${_.v}px`)),g!=null&&(typeof g=="number"?f.push(`margin-bottom: ${g}px`):f.push(`margin-bottom: ${g.v}px`)),C!=null&&f.push(`line-height: ${C}`),u>s+1?o+=`<p class="UniverNormal" ${f.length?`style="${f.join("; ")};"`:""}>${pe(i,s+1,u)}</p>`:o+=`<p class="UniverNormal" ${f.length?`style="${f.join("; ")};"`:""}></p>`,s=u}return s!==n.length&&(o+=pe(i,s,n.length)),o}else return pe(i,0,i.dataStream.length)}class Ht{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 n of e)t+='<p className="UniverNormal">',t+=Be(n,!1),t+="</p>";return t}}var kt=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,Yt=(i,e,t,n)=>{for(var r=n>1?void 0:n?zt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&kt(e,t,r),r},$=(i,e)=>(t,n)=>e(t,n,i);x.use(xe),x.use(Ue),x.use(Le);function Gt(i){const e=i.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 V=I.createIdentifier("doc.clipboard-service");let _e=class extends a.Disposable{constructor(e,t,n,r,o){super();T(this,"_clipboardHooks",[]);T(this,"_htmlToUDM",new x);T(this,"_umdToHtml",new Ht);this._univerInstanceService=e,this._logService=t,this._commandService=n,this._clipboardInterfaceService=r,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:{},r=this._textSelectionManagerService.getSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),t==null||r==null)return!1;this.copy();try{let s=t;for(const u of r){const{startOffset:h,endOffset:_}=u;h==null||_==null||_<=t&&(s-=_-h)}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:r}=(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 h of o){const{startOffset:_,endOffset:g}=h;_==null||g==null||g<=n&&(c+=e.dataStream.length-(g-_))}const u=[{startOffset:c,endOffset:c,style:r}];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=$t(),n=e.length>1?e.map(o=>o.dataStream).join(`
|
|
10
|
-
`):e[0].dataStream;let r=this._umdToHtml.convert(e);return e.length===1&&(r=r.replace(/(<[a-z]+)/,(o,s)=>`${s} data-copy-id="${t}"`),De.set(t,e[0])),this._clipboardInterfaceService.write(n,r)}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 r of e){const{startOffset:o,endOffset:s,collapsed:c}=r;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 r of e)for(const o of r.types)o===l.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await r.getType(o).then(s=>s&&s.text()):o===l.HTML_CLIPBOARD_MIME_TYPE&&(t=await r.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 Gt(t);throw new Error("[DocClipboardService] html and text cannot be both empty!")}const n=Vt(e);if(n){const r=De.get(n);if(r)return r}return this._htmlToUDM.convert(e)}};_e=Yt([$(0,a.IUniverInstanceService),$(1,a.ILogService),$(2,a.ICommandService),$(3,l.IClipboardInterfaceService),$(4,I.Inject(d.TextSelectionManagerService))],_e);function q(i){return i.getContextValue(a.FOCUSING_DOC)||i.getContextValue(a.EDITOR_ACTIVATED)}const ge=999,Kt={id:l.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:ge,preconditions:q,handler:async i=>i.get(V).copy()},Xt={id:l.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:ge,preconditions:q,handler:async i=>i.get(V).cut()},qt={id:l.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:ge,preconditions:q,handler:async i=>{const e=i.get(V),n=await i.get(l.IClipboardInterfaceService).read();return n.length===0?!1:e.paste(n)}};var Zt=Object.defineProperty,Jt=Object.getOwnPropertyDescriptor,Qt=(i,e,t,n)=>{for(var r=n>1?void 0:n?Jt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Zt(e,t,r),r},j=(i,e)=>(t,n)=>e(t,n,i);let Z=class extends a.RxDisposable{constructor(i,e,t,n,r){super(),this._commandService=i,this._clipboardInterfaceService=e,this._docClipboardService=t,this._textSelectionRenderManager=n,this._contextService=r,this._init()}_init(){[Kt,Xt,qt].forEach(i=>this.disposeWithMe(this._commandService.registerMultipleCommand(i))),[d.InnerPasteCommand,d.CutContentCommand].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i))),this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var i;(i=this._textSelectionRenderManager)==null||i.onPaste$.pipe(b.takeUntil(this.dispose$)).subscribe(e=>{var o,s;if(!q(this._contextService))return;e.event.preventDefault();const t=e.event,n=(o=t.clipboardData)==null?void 0:o.getData("text/html"),r=(s=t.clipboardData)==null?void 0:s.getData("text/plain");this._docClipboardService.legacyPaste(n,r)})}};Z=Qt([a.OnLifecycle(a.LifecycleStages.Rendered,Z),j(0,a.ICommandService),j(1,l.IClipboardInterfaceService),j(2,V),j(3,m.ITextSelectionRenderManager),j(4,a.IContextService)],Z);var en=Object.defineProperty,tn=Object.getOwnPropertyDescriptor,nn=(i,e,t,n)=>{for(var r=n>1?void 0:n?tn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&en(e,t,r),r},L=(i,e)=>(t,n)=>e(t,n,i);let J=class extends a.Disposable{constructor(e,t,n,r,o,s){super();T(this,"_initialEditors",new Set);this._univerInstanceService=e,this._docSkeletonManagerService=t,this._editorService=n,this._commandService=r,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,B,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,r=this._univerInstanceService.getUniverDocInstance(e);if(t==null||t.render==null||n==null||r==null)return;n.calculate();const{marginTop:o=0,marginBottom:s=0,marginLeft:c=0,marginRight:u=0}=r.getSnapshot().documentStyle,{scene:h,mainComponent:_}=t.render;let{actualHeight:g,actualWidth:C}=n.getActualSize();g+=o+s,C+=c+u;const{width:f,height:v}=t.getBoundingClientRect(),p=h.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);let O=p==null?void 0:p.getScrollBar();const M=Math.max(C,f),R=Math.max(g,v);h.transformByState({width:M,height:R}),_==null||_.resize(M,R),t.isSingle()?C>f?O==null?p&&new m.ScrollBar(p,{barSize:8,enableVertical:!1}):p==null||p.resetCanvasSizeAndUpdateScrollBar():(O=null,p==null||p.scrollTo({x:0,y:0}),(N=p==null?void 0:p.getScrollBar())==null||N.dispose()):g>v?O==null?p&&new m.ScrollBar(p,{enableHorizontal:!1,barSize:8}):p==null||p.resetCanvasSizeAndUpdateScrollBar():(O=null,p==null||p.scrollTo({x:0,y:0}),(B=p==null?void 0:p.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 r;const e=(r=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:r.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 r=n.getUnitId(),o=this._renderManagerService.getRenderById(r),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:r}=n;if(this._editorService.isSheetEditor(r))return;this._resize(r),this._valueChange()}}))}};J=nn([a.OnLifecycle(a.LifecycleStages.Rendered,J),L(0,a.IUniverInstanceService),L(1,I.Inject(d.DocSkeletonManagerService)),L(2,l.IEditorService),L(3,a.ICommandService),L(4,m.ITextSelectionRenderManager),L(5,m.IRenderManagerService)],J);var rn=Object.defineProperty,on=Object.getOwnPropertyDescriptor,sn=(i,e,t,n)=>{for(var r=n>1?void 0:n?on(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&rn(e,t,r),r},Q=(i,e)=>(t,n)=>e(t,n,i);let ee=class extends a.RxDisposable{constructor(e,t,n,r){super();T(this,"_docRenderMap",new Set);this._docSkeletonManagerService=e,this._renderManagerService=t,this._commandService=n,this._editorService=r,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 r=this._renderManagerService.getRenderById(n);r==null&&(this._renderManagerService.create(n),r=this._renderManagerService.getRenderById(n));const{mainComponent:o,components:s}=r,c=o,u=s.get(d.DOCS_VIEW_KEY.BACKGROUND);c.changeSkeleton(t),u.changeSkeleton(t),this._recalculateSizeBySkeleton(r,t)}_recalculateSizeBySkeleton(e,t){var C;const{mainComponent:n,scene:r,unitId:o,components:s}=e,c=n,u=s.get(d.DOCS_VIEW_KEY.BACKGROUND),h=(C=t.getSkeletonData())==null?void 0:C.pages;if(h==null)return;let _=0,g=0;for(let f=0,v=h.length;f<v;f++){const p=h[f],{pageWidth:O,pageHeight:M}=p;c.pageLayoutType===m.PageLayoutType.VERTICAL?(g+=M,g+=c.pageMarginTop,f===v-1&&(g+=c.pageMarginTop),_=Math.max(_,O)):c.pageLayoutType===m.PageLayoutType.HORIZONTAL&&(_+=O,f!==v-1&&(_+=c.pageMarginLeft),g=Math.max(g,M))}c.resize(_,g),u.resize(_,g),this._editorService.isEditor(o)||r.resize(_,g)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,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)}}))}};ee=sn([a.OnLifecycle(a.LifecycleStages.Rendered,ee),Q(0,I.Inject(d.DocSkeletonManagerService)),Q(1,m.IRenderManagerService),Q(2,a.ICommandService),Q(3,l.IEditorService)],ee);var an=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,ln=(i,e,t,n)=>{for(var r=n>1?void 0:n?cn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&an(e,t,r),r},te=(i,e)=>(t,n)=>e(t,n,i);S.DocCanvasView=class extends a.RxDisposable{constructor(t,n,r,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=r,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 r=this._renderManagerService.getRenderById(n);if(r==null)return;const{scene:o,engine:s}=r;this._scene=o;const c=new m.Viewport(d.VIEWPORT_KEY.VIEW_MAIN,o,{left:0,top:0,bottom:0,right:0,isRelativeX:!0,isRelativeY:!0,isWheelPreventDefaultX:!0});o.attachControl(),o.on(m.EVENT_TYPE.wheel,(_,g)=>{const C=_;if(C.ctrlKey){const f=Math.abs(C.deltaX);let v=f<40?.2:f<80?.4:.2;v*=C.deltaY>0?-1:1,o.scaleX<1&&(v/=2),o.scaleX+v>4?o.scale(4,4):o.scaleX+v<.1?o.scale(.1,.1):C.preventDefault()}else c.onMouseWheel(C,g)}),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(r),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,r=this._currentDocumentModel,o={pageMarginLeft:r.documentStyle.marginLeft||0,pageMarginTop:r.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(r.getUnitId())==null&&n.enableLayerCache(d.DOCS_COMPONENT_MAIN_LAYER_INDEX)}},S.DocCanvasView=ln([a.OnLifecycle(a.LifecycleStages.Starting,S.DocCanvasView),te(0,m.IRenderManagerService),te(1,a.IConfigService),te(2,a.IUniverInstanceService),te(3,l.IEditorService)],S.DocCanvasView);var dn=Object.defineProperty,un=Object.getOwnPropertyDescriptor,hn=(i,e,t,n)=>{for(var r=n>1?void 0:n?un(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&dn(e,t,r),r},ne=(i,e)=>(t,n)=>e(t,n,i);let ie=class extends a.Disposable{constructor(e,t,n,r){super();T(this,"_liquid",new m.Liquid);T(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=e,this._renderManagerService=t,this._commandService=n,this._editorService=r,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh(),this._updateOnPluginChange()}_updateOnPluginChange(){}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{skeleton:t,unitId:n}=e,r=this._renderManagerService.getRenderById(n);if(r==null)return;const{mainComponent:o}=r;o.changeSkeleton(t),this._refreshDrawing(n,t,r)})}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=this._docSkeletonManagerService.getCurrent();if(s==null)return;const{unitId:c,skeleton:u}=s;if(o!==c)return;const h=this._renderManagerService.getRenderById(c);if(h==null)return;if(this._editorService.isEditor(c)){(n=h.mainComponent)==null||n.makeDirty();return}this._refreshDrawing(c,u,h)}}))}_refreshDrawing(e,t,n){const r=t==null?void 0:t.getSkeletonData(),{mainComponent:o,scene:s}=n,c=o;if(!r)return;const{left:u,top:h,pageLayoutType:_,pageMarginLeft:g,pageMarginTop:C}=c,{pages:f}=r,v=[];s.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let p=0,O=f.length;p<O;p++){const M=f[p],{skeDrawings:R,marginLeft:D,marginTop:B}=M;this._liquid.translatePagePadding(M),R.forEach(N=>{const{aLeft:H,aTop:k,height:fe,width:me,drawingId:z,drawingOrigin:$e}=N,Un=$e.layoutType===a.PositionedObjectLayoutType.WRAP_NONE&&$e.behindDoc===a.BooleanNumber.TRUE;v.push({unitId:e,subUnitId:a.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:z,behindText:Un,floatingObject:{left:H+u+this._liquid.x,top:k+h+this._liquid.y,width:me,height:fe}}),this._pageMarginCache.set(z,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.restorePagePadding(M),this._liquid.translatePage(M,_,g,C)}}};ie=hn([a.OnLifecycle(a.LifecycleStages.Steady,ie),ne(0,I.Inject(d.DocSkeletonManagerService)),ne(1,m.IRenderManagerService),ne(2,a.ICommandService),ne(3,l.IEditorService)],ie);var pn=Object.defineProperty,_n=Object.getOwnPropertyDescriptor,gn=(i,e,t,n)=>{for(var r=n>1?void 0:n?_n(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&pn(e,t,r),r},A=(i,e)=>(t,n)=>e(t,n,i);let re=class extends a.Disposable{constructor(e,t,n,r,o,s){super();T(this,"_initializedRender",new Set);this._docSkeletonManagerService=e,this._univerInstanceService=t,this._commandService=n,this._renderManagerService=r,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:r}=n;this.disposeWithMe(a.toDisposable(r.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,r.scaleX<1&&(u/=2);const h=s.zoomRatio;let _=+Number.parseFloat(`${h+u}`).toFixed(1);_=_>=4?4:_<=.1?.1:_,this._commandService.executeCommand(d.SetDocZoomRatioCommand.id,{zoomRatio:_,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 r=t.params,{unitId:o}=r;if(o!==n.getUnitId())return;const s=n.zoomRatio||1;this._updateViewZoom(s)}}))}_updateViewZoom(e,t=!0){var r;const n=this._getDocObject();n!=null&&(n.scene.scale(e,e),this._calculatePagePosition(n,e),t&&this._textSelectionManagerService.refreshSelection(),(r=n.scene.getTransformer())==null||r.clearSelectedObjects())}_calculatePagePosition(e,t){const{document:n,scene:r,docBackground:o}=e,s=r==null?void 0:r.getParent(),{width:c,height:u,pageMarginLeft:h,pageMarginTop:_}=n;if(s==null||c===Number.POSITIVE_INFINITY||u===Number.POSITIVE_INFINITY)return;const{width:g,height:C}=s;let f=0,v=0,p=0,O=0,M=Number.POSITIVE_INFINITY;g>(c+h*2)*t?(f=g/2-c*t/2,f/=t,p=(g-h*2)/t,M=0):(f=h,p=c+h*2,M=(p-g/t)/2),C>u?(v=C/2-u/2,O=(C-_*2)/t):(v=_,O=u+_*2),r.resize(p,O+200),n.translate(f,v),o.translate(f,v);const R=r.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(M!==Number.POSITIVE_INFINITY&&R!=null){const D=R.transViewportScroll2ScrollValue(M,0).x;R.scrollTo({x:D})}return this}_getDocObject(){return d.getDocObject(this._univerInstanceService,this._renderManagerService)}};re=gn([a.OnLifecycle(a.LifecycleStages.Rendered,re),A(0,I.Inject(d.DocSkeletonManagerService)),A(1,a.IUniverInstanceService),A(2,a.ICommandService),A(3,m.IRenderManagerService),A(4,I.Inject(d.TextSelectionManagerService)),A(5,l.IEditorService)],re);var Sn=Object.defineProperty,fn=Object.getOwnPropertyDescriptor,mn=(i,e,t,n)=>{for(var r=n>1?void 0:n?fn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Sn(e,t,r),r},U=(i,e)=>(t,n)=>e(t,n,i);let oe=class extends a.Disposable{constructor(e,t,n,r,o,s,c){super();T(this,"_loadedMap",new WeakSet);this._docSkeletonManagerService=e,this._univerInstanceService=t,this._commandService=n,this._renderManagerService=r,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:r}=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,r.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:h}=o;this._editorService.getEditor(e)&&(this._setEditorFocus(e),setTimeout(()=>{this._setEditorFocus(e),this._textSelectionRenderManager.setCursorManually(u,h)},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 r=t.params,{unitId:o}=r,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,r=this._renderManagerService.getRenderById(t);if(r==null)return;const{scene:o,mainComponent:s}=r;this._textSelectionRenderManager.changeRuntime(n,o,s),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:t,subUnitId:""}),this._editorService.isEditor(t)||this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}],!1)}))}_getDocObjectById(e){return this._univerInstanceService.getUnitType(e)!==a.UniverInstanceType.UNIVER_DOC?null:d.getDocObjectById(e,this._renderManagerService)}};oe=mn([a.OnLifecycle(a.LifecycleStages.Rendered,oe),U(0,I.Inject(d.DocSkeletonManagerService)),U(1,a.IUniverInstanceService),U(2,a.ICommandService),U(3,m.IRenderManagerService),U(4,m.ITextSelectionRenderManager),U(5,I.Inject(d.TextSelectionManagerService)),U(6,l.IEditorService)],oe);var vn=Object.defineProperty,In=Object.getOwnPropertyDescriptor,Cn=(i,e,t,n)=>{for(var r=n>1?void 0:n?In(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&vn(e,t,r),r},W=(i,e)=>(t,n)=>e(t,n,i);const we=1.5;let se=class extends a.RxDisposable{constructor(i,e,t,n,r){super(),this._docSkeletonManagerService=i,this._textSelectionManagerService=e,this._editorService=t,this._univerInstanceService=n,this._renderManagerService=r,this._init()}_init(){this._textSelectionManagerService.textSelection$.pipe(b.takeUntil(this.dispose$)).subscribe(i=>{if(i==null)return;const{isEditing:e,unitId:t}=i;e&&this._scrollToSelection(t)})}_scrollToSelection(i){var z;const e=this._textSelectionManagerService.getActiveRange(),t=this._getDocObject(),n=(z=this._docSkeletonManagerService.getCurrent())==null?void 0:z.skeleton;if(e==null||t==null||n==null)return;const{collapsed:r,startNodePosition:o}=e;if(!r)return;const s=t.document.getOffsetConfig(),{docsLeft:c,docsTop:u}=s,h=new m.NodePositionConvertToCursor(s,n),{contentBoxPointGroup:_}=h.getRangePointData(o,o),{left:g,top:C,height:f}=m.getAnchorBounding(_),v=g+c,p=C+u,O=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN),M=!!this._editorService.getEditor(i);if(O==null)return;const{left:R,top:D,right:B,bottom:N}=O.getBounding().viewBound;let H=0,k=0;const fe=M?0:100;p<D?H=p-D:p>N-f&&(H=p-N+f+fe),v<R?k=v-R:v>B-we&&(k=v-B+we);const me=O.transViewportScroll2ScrollValue(k,H);O.scrollBy(me)}_getDocObject(){return d.getDocObject(this._univerInstanceService,this._renderManagerService)}};se=Cn([a.OnLifecycle(a.LifecycleStages.Rendered,se),W(0,I.Inject(d.DocSkeletonManagerService)),W(1,I.Inject(d.TextSelectionManagerService)),W(2,l.IEditorService),W(3,a.IUniverInstanceService),W(4,m.IRenderManagerService)],se);var On=Object.defineProperty,Tn=Object.getOwnPropertyDescriptor,bn=(i,e,t,n)=>{for(var r=n>1?void 0:n?Tn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&On(e,t,r),r},ae=(i,e)=>(t,n)=>e(t,n,i);function Mn(i,e){const t=Fe(i.left,i.top,e),n=Fe(i.right,i.bottom,e);return{left:t.x,top:t.y,right:n.x,bottom:n.y}}function Fe(i,e,t){const{scaleX:n,scaleY:r}=t.getAncestorScale(),o=t.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(!o)return{x:i,y:e};const{viewportScrollX:s,viewportScrollY:c}=o,u=(i-s)*n,h=(e-c)*r;return{x:u,y:h}}S.DocCanvasPopManagerService=class extends a.Disposable{constructor(e,t,n,r){super(),this._globalPopupManagerService=e,this._renderManagerService=t,this._univerInstanceService=n,this._commandService=r}_createObjectPositionObserver(e,t){const n=()=>{const{scene:u}=t,{left:h,top:_,width:g,height:C}=e,f={left:h,right:h+g,top:_,bottom:_+C},v=Mn(f,u);return{left:v.left,right:v.right,top:v.top,bottom:v.bottom}},r=n(),o=new b.BehaviorSubject(r),s=new a.DisposableCollection;s.add(this._commandService.onCommandExecuted(u=>{u.id===d.SetDocZoomRatioOperation.id&&o.next(n())}));const c=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);return s.add(c==null?void 0:c.onScrollAfterObserver.add(()=>{o.next(n())})),{position:r,position$:o,disposable:s}}attachPopupToObject(e,t){const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC).getUnitId(),o=this._renderManagerService.getRenderById(r);if(!o)return{dispose:()=>{}};const{position:s,position$:c,disposable:u}=this._createObjectPositionObserver(e,o),h=this._globalPopupManagerService.addPopup({...t,unitId:r,subUnitId:"default",anchorRect:s,anchorRect$:c});return{dispose:()=>{this._globalPopupManagerService.removePopup(h),c.complete(),u.dispose()}}}},S.DocCanvasPopManagerService=bn([ae(0,I.Inject(l.ICanvasPopupService)),ae(1,m.IRenderManagerService),ae(2,a.IUniverInstanceService),ae(3,a.ICommandService)],S.DocCanvasPopManagerService);var Rn=Object.defineProperty,yn=Object.getOwnPropertyDescriptor,En=(i,e,t,n)=>{for(var r=n>1?void 0:n?yn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Rn(e,t,r),r},Se=(i,e)=>(t,n)=>e(t,n,i);S.UniverDocsUIPlugin=(le=class extends a.Plugin{constructor(e,t,n,r){super(),this._config=e,this._injector=t,this._localeService=n,this._logService=r,this._config=a.Tools.deepMerge({},Ce,this._config),this._initDependencies(t),this._initializeCommands()}onRendered(){this._initModules(),this._markDocAsFocused()}_initializeCommands(){[ke,ze,Ge,Ye,Ke,Xe,qe,Ze,Je,At,Bt,Lt].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],[w,{useFactory:()=>this._injector.createInstance(w,this._config)}],[V,{useClass:_e}],[S.DocCanvasPopManagerService],[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 r=n.getUnitId();t.isEditor(r)||e.focusUnit(n.getUnitId())}catch(n){this._logService.warn(n)}}_initModules(){this._injector.get(w)}},T(le,"pluginName",Oe),T(le,"type",a.UniverInstanceType.UNIVER_DOC),le),S.UniverDocsUIPlugin=En([Se(1,I.Inject(I.Injector)),Se(2,I.Inject(a.LocaleService)),Se(3,a.ILogService)],S.UniverDocsUIPlugin);function Dn(i){return{left:i.positionH.posOffset,top:i.positionV.posOffset,width:i.size.width,height:i.size.height}}function Pn(i,e=0,t=0){return{size:{width:i.width,height:i.height},positionH:{relativeFrom:a.ObjectRelativeFromH.MARGIN,posOffset:(i.left||0)-e},positionV:{relativeFrom:a.ObjectRelativeFromV.PAGE,posOffset:(i.top||0)-t},angle:i.angle||0}}S.DOC_UI_PLUGIN_NAME=Oe,S.DefaultDocContainerConfig=Ie,S.DefaultDocUiConfig=Ce,S.DefaultToolbarConfig=ve,S.PastePluginLark=Ue,S.PastePluginUniver=Le,S.PastePluginWord=xe,S.docDrawingPositionToTransform=Dn,S.transformToDocDrawingPosition=Pn,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
|
|
9
|
+
*/var it=$e,rt=Symbol.for("react.element"),ot=Symbol.for("react.fragment"),st=Object.prototype.hasOwnProperty,at=it.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,ct={key:!0,ref:!0,__self:!0,__source:!0};function Re(i,e,t){var n,r={},s=null,o=null;t!==void 0&&(s=""+t),e.key!==void 0&&(s=""+e.key),e.ref!==void 0&&(o=e.ref);for(n in e)st.call(e,n)&&!ct.hasOwnProperty(n)&&(r[n]=e[n]);if(i&&i.defaultProps)for(n in e=i.defaultProps,e)r[n]===void 0&&(r[n]=e[n]);return{$$typeof:rt,type:i,key:s,ref:o,props:r,_owner:at.current}}G.Fragment=ot,G.jsx=Re,G.jsxs=Re,be.exports=G;var lt=be.exports;const dt={docsUiCanvasBackground:"univer-docs-ui-canvas-background"},ut=()=>lt.jsx("div",{className:dt.docsUiCanvasBackground});function ht(i){const e=i.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 T.Observable(t=>{const n=e.onCommandExecuted(r=>{var o;const s=r.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatCommand.id){const c=y(i);if(c==null)return;const u=(o=c.ts)==null?void 0:o.bl;t.next(u===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function pt(i){const e=i.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 T.Observable(t=>{const n=e.onCommandExecuted(r=>{var o;const s=r.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatCommand.id){const c=y(i);if(c==null)return;const u=(o=c.ts)==null?void 0:o.it;t.next(u===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function _t(i){const e=i.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 T.Observable(t=>{const n=e.onCommandExecuted(r=>{var o;const s=r.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatCommand.id){const c=y(i);if(c==null)return;const u=(o=c.ts)==null?void 0:o.ul;t.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function gt(i){const e=i.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 T.Observable(t=>{const n=e.onCommandExecuted(r=>{var o;const s=r.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatCommand.id){const c=y(i);if(c==null)return;const u=(o=c.ts)==null?void 0:o.st;t.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function mt(i){const e=i.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 T.Observable(t=>{const n=e.onCommandExecuted(r=>{var o;const s=r.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatCommand.id){const c=y(i);if(c==null)return;const u=(o=c.ts)==null?void 0:o.va;t.next(u===a.BaselineOffset.SUBSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function St(i){const e=i.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 T.Observable(t=>{const n=e.onCommandExecuted(r=>{var o;const s=r.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatCommand.id){const c=y(i);if(c==null)return;const u=(o=c.ts)==null?void 0:o.va;t.next(u===a.BaselineOffset.SUPERSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function ft(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatFontFamilyCommand.id,tooltip:"toolbar.font",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,label:Ie,positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_FAMILY_LIST.map(t=>({label:{name:Oe,hoverable:!0},value:t.value})),value$:new T.Observable(t=>{const n=l.FONT_FAMILY_LIST[0].value,r=e.onCommandExecuted(s=>{var c;const o=s.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatFontFamilyCommand.id){const u=y(i);if(u==null)return;const h=(c=u.ts)==null?void 0:c.ff;t.next(h!=null?h:n)}});return t.next(n),r.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function vt(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatFontSizeCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Te,props:{min:1,max:400}},positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_SIZE_LIST,value$:new T.Observable(t=>{const r=e.onCommandExecuted(s=>{var c;const o=s.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatFontSizeCommand.id){const u=y(i);if(u==null)return;const h=(c=u.ts)==null?void 0:c.fs;t.next(h!=null?h:14)}});return t.next(14),r.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Ct(i){const e=i.get(a.ICommandService),t=i.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:ie,hoverable:!1}}],value$:new T.Observable(n=>{const r=t.getCurrentTheme().textColor,s=e.onCommandExecuted(o=>{if(o.id===d.SetInlineFormatTextColorCommand.id){const c=o.params.value;n.next(c!=null?c:r)}});return n.next(r),s.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function It(i){const e=i.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 T.Observable(t=>{const n=e.onCommandExecuted(r=>{var o;const s=r.id;if(s===d.SetTextSelectionsOperation.id||s===d.AlignOperationCommand.id){const c=Y(i);if(c==null)return;const u=(o=c.paragraphStyle)==null?void 0:o.horizontalAlign;t.next(u===a.HorizontalAlign.LEFT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Ot(i){const e=i.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 T.Observable(t=>{const n=e.onCommandExecuted(r=>{var o;const s=r.id;if(s===d.SetTextSelectionsOperation.id||s===d.AlignOperationCommand.id){const c=Y(i);if(c==null)return;const u=(o=c.paragraphStyle)==null?void 0:o.horizontalAlign;t.next(u===a.HorizontalAlign.CENTER)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Tt(i){const e=i.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 T.Observable(t=>{const n=e.onCommandExecuted(r=>{var o;const s=r.id;if(s===d.SetTextSelectionsOperation.id||s===d.AlignOperationCommand.id){const c=Y(i);if(c==null)return;const u=(o=c.paragraphStyle)==null?void 0:o.horizontalAlign;t.next(u===a.HorizontalAlign.RIGHT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function bt(i){const e=i.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 T.Observable(t=>{const n=e.onCommandExecuted(r=>{var o;const s=r.id;if(s===d.SetTextSelectionsOperation.id||s===d.AlignOperationCommand.id){const c=Y(i);if(c==null)return;const u=(o=c.paragraphStyle)==null?void 0:o.horizontalAlign;t.next(u===a.HorizontalAlign.JUSTIFIED)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Rt(i){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(i,a.UniverInstanceType.UNIVER_DOC)}}function Mt(i){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(i,a.UniverInstanceType.UNIVER_DOC)}}function yt(i){return{id:d.ResetInlineFormatTextBackgroundColorCommand.id,type:l.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:d.SetInlineFormatTextBackgroundColorCommand.id}}function Et(i){const e=i.get(a.ICommandService),t=i.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:ie,hoverable:!1}}],value$:new T.Observable(n=>{const r=t.getCurrentTheme().primaryColor,s=e.onCommandExecuted(o=>{if(o.id===d.SetInlineFormatTextBackgroundColorCommand.id){const c=o.params.value;n.next(c!=null?c:r)}});return n.next(r),s.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function y(i){var u;const e=i.get(a.IUniverInstanceService),t=i.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const s=(u=n.getBody())==null?void 0:u.textRuns;if(s==null)return;const{startOffset:o}=r;let c;for(let h=0;h<s.length;h++){const _=s[h],m=s[h+1];if(m&&m.st===m.ed&&o===m.st){c=m;break}if(_.st<=o&&o<=_.ed){c=_;break}}return c}function Y(i){var u;const e=i.get(a.IUniverInstanceService),t=i.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const s=(u=n.getBody())==null?void 0:u.paragraphs;if(s==null)return;const{startOffset:o}=r;let c=-1;for(const h of s){const{startIndex:_}=h;if(o>c&&o<=_)return h;c=_}return null}var Dt=Object.defineProperty,Pt=Object.getOwnPropertyDescriptor,Ut=(i,e,t,n)=>{for(var r=n>1?void 0:n?Pt(e,t):e,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&Dt(e,t,r),r},D=(i,e)=>(t,n)=>e(t,n,i);let B=class extends a.Disposable{constructor(i,e,t,n,r,s,o,c){super(),this._config=i,this._injector=e,this._componentManager=t,this._layoutService=n,this._editorService=r,this._menuService=s,this._uiPartsService=o,this._univerInstanceService=c,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(ie,Ve.ColorPicker)),this.disposeWithMe(i.register(Ie,l.FontFamily)),this.disposeWithMe(i.register(Oe,l.FontFamilyItem)),this.disposeWithMe(i.register(Te,l.FontSize))}_initMenus(){const{menu:i={}}=this._config;[ht,pt,_t,gt,mt,St,vt,ft,Ct,It,Ot,Tt,bt,Rt,Mt,yt,Et].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e),i))})}_init(){this._initCustomComponents(),this._initMenus(),this._initDocBackground(),this._initFocusHandler()}_initDocBackground(){const i=this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC)[0].getUnitId();if(i==null)return;this._editorService.isEditor(i)||this.disposeWithMe(this._uiPartsService.registerComponent(l.BuiltInUIPart.CONTENT,()=>we.connectInjector(ut,this._injector)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.UNIVER_DOC,()=>{this._injector.get(I.ITextSelectionRenderManager).focus()}))}};B=Ut([a.OnLifecycle(a.LifecycleStages.Rendered,B),D(1,C.Inject(C.Injector)),D(2,C.Inject(l.ComponentManager)),D(3,l.ILayoutService),D(4,l.IEditorService),D(5,l.IMenuService),D(6,l.IUIPartsService),D(7,a.IUniverInstanceService)],B);const Nt={id:d.BreakLineCommand.id,preconditions:je,binding:l.KeyCode.ENTER},xt={id:d.DeleteLeftCommand.id,preconditions:R,binding:l.KeyCode.BACKSPACE},At={id:d.DeleteRightCommand.id,preconditions:R,binding:l.KeyCode.DELETE},Lt=10,Bt=6;function Ft(){return a.Tools.generateRandomId(Bt)}function wt(i){const e=i.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class $t{constructor(){b(this,"_cache",new a.LRUMap(Lt))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}clear(){this._cache.clear()}}const Me=new $t;function re(i){const e=i.style,t={},n=i.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 r=0;r<e.length;r++){const s=e[r],o=e.getPropertyValue(s);switch(s){case"font-family":{t.ff=o;break}case"font-size":{const c=Number.parseInt(o);Number.isNaN(c)||(o.endsWith("pt")?t.fs=c:o.endsWith("px")&&(t.fs=I.pixelToPt(c)));break}case"font-style":{o==="italic"&&(t.it=a.BooleanNumber.TRUE);break}case"font-weight":{(Number(o)>400||String(o)==="bold")&&(t.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(o)?t.ul={s:a.BooleanNumber.TRUE}:/overline/.test(o)?t.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(o)&&(t.st={s:a.BooleanNumber.TRUE});break}case"color":{const c=new a.ColorKit(o);c.isValid&&(t.cl={rgb:c.toRgbString()});break}case"background-color":{const c=new a.ColorKit(o);c.isValid&&(t.bg={rgb:c.toRgbString()});break}}}return t}function Vt(i){const e=new DOMParser,t=`<x-univer id="univer-root">${i}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function ye(i,e){const t=i.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(i)}const Q=class Q{constructor(){b(this,"_styleCache",new Map);b(this,"_styleRules",[]);b(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=Q._pluginList.find(s=>s.checkPasteType(e)),n=Vt(e),r={dataStream:"",textRuns:[]};return t&&(this._styleRules=[...t.stylesRules],this._afterProcessRules=[...t.afterProcessRules]),this._styleCache.clear(),this._process(null,n==null?void 0:n.childNodes,r),this._styleCache.clear(),this._styleRules=[],this._afterProcessRules=[],r}_process(e,t,n){var r,s;for(const o of t)if(o.nodeType===Node.TEXT_NODE){if(((r=o.nodeValue)==null?void 0:r.trim())==="")continue;const c=(s=o.nodeValue)==null?void 0:s.replace(/[\r\n]/g,"");let u;e&&this._styleCache.has(e)&&(u=this._styleCache.get(e)),n.dataStream+=c,u&&Object.getOwnPropertyNames(u).length&&n.textRuns.push({st:n.dataStream.length-c.length,ed:n.dataStream.length,ts:u})}else{if(a.skipParseTagNames.includes(o.nodeName.toLowerCase()))continue;if(o.nodeType===Node.ELEMENT_NODE){const c=e?this._styleCache.get(e):{},u=this._styleRules.find(({filter:S})=>ye(o,S)),h=u?u.getStyle(o):re(o);this._styleCache.set(o,{...c,...h});const{childNodes:_}=o;this._process(o,_,n);const m=this._afterProcessRules.find(({filter:S})=>ye(o,S));m&&m.handler(n,o)}}}};b(Q,"_pluginList",[]);let N=Q;const Ee={name:"univer-doc-paste-plugin-lark",checkPasteType(i){return/lark-record-clipboard/i.test(i)},stylesRules:[{filter:["s"],getStyle(i){const e=re(i);return{st:{s:a.BooleanNumber.TRUE},...e}}}],afterProcessRules:[{filter(i){return i.tagName==="DIV"&&/ace-line/i.test(i.className)},handler(i){i.paragraphs==null&&(i.paragraphs=[]),i.paragraphs.push({startIndex:i.dataStream.length}),i.dataStream+="\r"}}]};function De(i){const e=i.style,t={};for(let n=0;n<e.length;n++){const r=e[n],s=e.getPropertyValue(r);switch(r){case"margin-top":{const o=Number.parseInt(s);t.spaceAbove=/pt/.test(s)?I.ptToPixel(o):o;break}case"margin-bottom":{const o=Number.parseInt(s);t.spaceBelow=/pt/.test(s)?I.ptToPixel(o):o;break}case"line-height":{const o=Number.parseFloat(s);t.lineSpacing=o;break}}}return Object.getOwnPropertyNames(t).length?t:null}const Pe={name:"univer-doc-paste-plugin-word",checkPasteType(i){return/word|mso/i.test(i)},stylesRules:[{filter:["b"],getStyle(i){const e=re(i);return{bl:a.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(i){return i.tagName==="P"},handler(i,e){i.paragraphs==null&&(i.paragraphs=[]);const t={startIndex:i.dataStream.length},n=De(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]},Ue={name:"univer-doc-paste-plugin-univer",checkPasteType(i){return/UniverNormal/i.test(i)},stylesRules:[],afterProcessRules:[{filter(i){return i.tagName==="P"&&/UniverNormal/i.test(i.className)},handler(i,e){i.paragraphs==null&&(i.paragraphs=[]);const t={startIndex:i.dataStream.length},n=De(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]};function Ne(i,e){const{st:t,ed:n,ts:r={}}=e,{ff:s,fs:o,it:c,bl:u,ul:h,st:_,ol:m,bg:S,cl:f,va:O}=r;let p=i.slice(t,n);const v=[];return c===a.BooleanNumber.TRUE&&(p=`<i>${p}</i>`),O===a.BaselineOffset.SUPERSCRIPT?p=`<sup>${p}</sup>`:O===a.BaselineOffset.SUBSCRIPT&&(p=`<sub>${p}</sub>`),(h==null?void 0:h.s)===a.BooleanNumber.TRUE&&(p=`<u>${p}</u>`),(_==null?void 0:_.s)===a.BooleanNumber.TRUE&&(p=`<s>${p}</s>`),u===a.BooleanNumber.TRUE&&(p=`<strong>${p}</strong>`),s&&v.push(`font-family: ${s}`),f&&v.push(`color: ${f.rgb}`),o&&v.push(`font-size: ${o}pt`),m&&v.push("text-decoration: overline"),S&&v.push(`background: ${S.rgb}`),v.length?`<span style="${v.join("; ")};">${p}</span>`:p}function oe(i,e,t){const{dataStream:n,textRuns:r=[]}=i;let s=e;const o=[];for(const c of r){const{st:u,ed:h}=c;a.Tools.hasIntersectionBetweenTwoRanges(e,t,u,h)&&(u>s?(o.push(n.slice(s,u)),o.push(Ne(n,{...c,ed:Math.min(h,t)}))):o.push(Ne(n,{...c,st:s,ed:Math.min(h,t)}))),s=Math.max(e,Math.min(h,t))}return s!==t&&o.push(n.slice(s,t)),o.join("")}function xe(i,e=!0){var t;if(e&&((t=i.paragraphs)!=null&&t.length)){const{dataStream:n,paragraphs:r=[]}=i;let s="",o=-1;for(const c of r){const{startIndex:u,paragraphStyle:h={}}=c,{spaceAbove:_,spaceBelow:m,lineSpacing:S}=h,f=[];_!=null&&(typeof _=="number"?f.push(`margin-top: ${_}px`):f.push(`margin-top: ${_.v}px`)),m!=null&&(typeof m=="number"?f.push(`margin-bottom: ${m}px`):f.push(`margin-bottom: ${m.v}px`)),S!=null&&f.push(`line-height: ${S}`),u>o+1?s+=`<p class="UniverNormal" ${f.length?`style="${f.join("; ")};"`:""}>${oe(i,o+1,u)}</p>`:s+=`<p class="UniverNormal" ${f.length?`style="${f.join("; ")};"`:""}></p>`,o=u}return o!==n.length&&(s+=oe(i,o,n.length)),s}else return oe(i,0,i.dataStream.length)}class jt{convert(e){if(e.length===0)throw new Error("The bodyList length at least to be 1");if(e.length===1)return xe(e[0]);let t="";for(const n of e)t+='<p className="UniverNormal">',t+=xe(n,!1),t+="</p>";return t}}var Wt=Object.defineProperty,Ht=Object.getOwnPropertyDescriptor,zt=(i,e,t,n)=>{for(var r=n>1?void 0:n?Ht(e,t):e,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&Wt(e,t,r),r},F=(i,e)=>(t,n)=>e(t,n,i);N.use(Pe),N.use(Ee),N.use(Ue);function kt(i){const e=i.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 w=C.createIdentifier("doc.clipboard-service");let se=class extends a.Disposable{constructor(e,t,n,r,s){super();b(this,"_clipboardHooks",[]);b(this,"_htmlToUDM",new N);b(this,"_umdToHtml",new jt);this._univerInstanceService=e,this._logService=t,this._commandService=n,this._clipboardInterfaceService=r,this._textSelectionManagerService=s}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 s;const{segmentId:e,endOffset:t,style:n}=(s=this._textSelectionManagerService.getActiveRange())!=null?s:{},r=this._textSelectionManagerService.getSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),t==null||r==null)return!1;this.copy();try{let o=t;for(const u of r){const{startOffset:h,endOffset:_}=u;h==null||_==null||_<=t&&(o-=_-h)}const c=[{startOffset:o,endOffset:o,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 o;const{segmentId:t,endOffset:n,style:r}=(o=this._textSelectionManagerService.getActiveRange())!=null?o:{},s=this._textSelectionManagerService.getSelections();if(t==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),n==null||s==null)return!1;try{let c=n;for(const h of s){const{startOffset:_,endOffset:m}=h;_==null||m==null||m<=n&&(c+=e.dataStream.length-(m-_))}const u=[{startOffset:c,endOffset:c,style:r}];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=Ft(),n=e.length>1?e.map(s=>s.dataStream).join(`
|
|
10
|
+
`):e[0].dataStream;let r=this._umdToHtml.convert(e);return e.length===1&&(r=r.replace(/(<[a-z]+)/,(s,o)=>`${o} data-copy-id="${t}"`),Me.set(t,e[0])),this._clipboardInterfaceService.write(n,r)}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 r of e){const{startOffset:s,endOffset:o,collapsed:c}=r;if(c||s==null||o==null)continue;const u=t.sliceBody(s,o);u!=null&&n.push(u)}return n}async _generateBodyFromClipboardItems(e){try{let t="",n="";for(const r of e)for(const s of r.types)s===l.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await r.getType(s).then(o=>o&&o.text()):s===l.HTML_CLIPBOARD_MIME_TYPE&&(t=await r.getType(s).then(o=>o&&o.text()));return this._generateBodyFromHtmlAndText(t,n)}catch(t){return Promise.reject(t)}}_generateBodyFromHtmlAndText(e,t){if(!e){if(t)return kt(t);throw new Error("[DocClipboardService] html and text cannot be both empty!")}const n=wt(e);if(n){const r=Me.get(n);if(r)return r}return this._htmlToUDM.convert(e)}};se=zt([F(0,a.IUniverInstanceService),F(1,a.ILogService),F(2,a.ICommandService),F(3,l.IClipboardInterfaceService),F(4,C.Inject(d.TextSelectionManagerService))],se);function K(i){return i.getContextValue(a.FOCUSING_DOC)||i.getContextValue(a.EDITOR_ACTIVATED)}const ae=999,Gt={id:l.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:ae,preconditions:K,handler:async i=>i.get(w).copy()},Yt={id:l.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:ae,preconditions:K,handler:async i=>i.get(w).cut()},Kt={id:l.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:ae,preconditions:K,handler:async i=>{const e=i.get(w),n=await i.get(l.IClipboardInterfaceService).read();return n.length===0?!1:e.paste(n)}};var Xt=Object.defineProperty,qt=Object.getOwnPropertyDescriptor,Zt=(i,e,t,n)=>{for(var r=n>1?void 0:n?qt(e,t):e,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&Xt(e,t,r),r},$=(i,e)=>(t,n)=>e(t,n,i);let X=class extends a.RxDisposable{constructor(i,e,t,n,r){super(),this._commandService=i,this._clipboardInterfaceService=e,this._docClipboardService=t,this._textSelectionRenderManager=n,this._contextService=r,this._init()}_init(){[Gt,Yt,Kt].forEach(i=>this.disposeWithMe(this._commandService.registerMultipleCommand(i))),[d.InnerPasteCommand,d.CutContentCommand].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i))),this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var i;(i=this._textSelectionRenderManager)==null||i.onPaste$.pipe(T.takeUntil(this.dispose$)).subscribe(e=>{var s,o;if(!K(this._contextService))return;e.event.preventDefault();const t=e.event,n=(s=t.clipboardData)==null?void 0:s.getData("text/html"),r=(o=t.clipboardData)==null?void 0:o.getData("text/plain");this._docClipboardService.legacyPaste(n,r)})}};X=Zt([a.OnLifecycle(a.LifecycleStages.Rendered,X),$(0,a.ICommandService),$(1,l.IClipboardInterfaceService),$(2,w),$(3,I.ITextSelectionRenderManager),$(4,a.IContextService)],X);var Jt=Object.defineProperty,Qt=Object.getOwnPropertyDescriptor,en=(i,e,t,n)=>{for(var r=n>1?void 0:n?Qt(e,t):e,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&Jt(e,t,r),r},V=(i,e)=>(t,n)=>e(t,n,i);let q=class extends a.Disposable{constructor(e,t,n,r,s){super();b(this,"_initialEditors",new Set);this._univerInstanceService=e,this._editorService=t,this._commandService=n,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 A,P,U;if(e==null)return;const t=this._editorService.getEditor(e);if((t==null?void 0:t.cancelDefaultResizeListener)===!0)return;const n=this._univerInstanceService.getUniverDocInstance(e);if(!n)return;const r=(A=this._renderManagerService.getRenderById(n.getUnitId()))==null?void 0:A.with(d.DocSkeletonManagerService).getSkeleton();if(t==null||t.render==null||r==null||n==null)return;r.calculate();const{marginTop:s=0,marginBottom:o=0,marginLeft:c=0,marginRight:u=0}=n.getSnapshot().documentStyle,{scene:h,mainComponent:_}=t.render;let{actualHeight:m,actualWidth:S}=r.getActualSize();m+=s+o,S+=c+u;const{width:f,height:O}=t.getBoundingClientRect(),p=h.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);let v=p==null?void 0:p.getScrollBar();const M=Math.max(S,f),E=Math.max(m,O);h.transformByState({width:M,height:E}),_==null||_.resize(M,E),t.isSingle()?S>f?v==null?p&&new I.ScrollBar(p,{barSize:8,enableVertical:!1}):p==null||p.resetCanvasSizeAndUpdateScrollBar():(v=null,p==null||p.scrollTo({x:0,y:0}),(U=p==null?void 0:p.getScrollBar())==null||U.dispose()):m>O?v==null?p&&new I.ScrollBar(p,{enableHorizontal:!1,barSize:8}):p==null||p.resetCanvasSizeAndUpdateScrollBar():(v=null,p==null||p.scrollTo({x:0,y:0}),(P=p==null?void 0:p.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 r;const e=(r=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:r.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(T.fromEvent(window,"mousedown").subscribe(n=>{const s=n.target.classList[0]||"";if(a.checkForSubstrings(s,e)){this._editorService.changeSpreadsheetFocusState(!0),n.stopPropagation();return}this._editorService.changeSpreadsheetFocusState(!1)})),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(n=>{const r=n.getUnitId(),s=this._renderManagerService.getRenderById(r),o=s==null?void 0:s.engine.getCanvas().getCanvasEle();o!=null&&T.fromEvent(o,"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:r}=n;if(this._editorService.isSheetEditor(r))return;this._resize(r),this._valueChange()}}))}};q=en([a.OnLifecycle(a.LifecycleStages.Rendered,q),V(0,a.IUniverInstanceService),V(1,l.IEditorService),V(2,a.ICommandService),V(3,I.ITextSelectionRenderManager),V(4,I.IRenderManagerService)],q);var tn=Object.defineProperty,nn=Object.getOwnPropertyDescriptor,rn=(i,e,t,n)=>{for(var r=n>1?void 0:n?nn(e,t):e,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&tn(e,t,r),r},Z=(i,e)=>(t,n)=>e(t,n,i);g.DocRenderController=class extends a.RxDisposable{constructor(e,t,n,r,s){super(),this._context=e,this._commandService=t,this._docSkeletonManagerService=n,this._configService=r,this._editorService=s,this._addNewRender(),this._initRenderRefresh(),this._initCommandListener()}_addNewRender(){const{scene:e,engine:t,unit:n}=this._context,r=new I.Viewport(d.VIEWPORT_KEY.VIEW_MAIN,e,{left:0,top:0,bottom:0,right:0,isRelativeX:!0,isRelativeY:!0,isWheelPreventDefaultX:!0});e.attachControl(),e.onMouseWheel$.subscribeEvent((c,u)=>{const h=c;if(h.ctrlKey){const _=Math.abs(h.deltaX);let m=_<40?.2:_<80?.4:.2;m*=h.deltaY>0?-1:1,e.scaleX<1&&(m/=2),e.scaleX+m>4?e.scale(4,4):e.scaleX+m<.1?e.scale(.1,.1):h.preventDefault()}else r.onMouseWheel(h,u)}),this._configService.getConfig("hasScroll")!==!1&&new I.ScrollBar(r),e.addLayer(new I.Layer(e,[],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),new I.Layer(e,[],d.DOCS_COMPONENT_HEADER_LAYER_INDEX)),this._addComponent(),n.getShouldRenderLoopImmediately()&&t.runRenderLoop(()=>{e.render()})}_addComponent(){const{scene:e,unit:t,components:n}=this._context,r={pageMarginLeft:t.documentStyle.marginLeft||0,pageMarginTop:t.documentStyle.marginTop||0},s=new I.Documents(d.DOCS_VIEW_KEY.MAIN,void 0,r);s.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX;const o=new I.DocBackground(d.DOCS_VIEW_KEY.BACKGROUND,void 0,r);o.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX,this._context.mainComponent=s,n.set(d.DOCS_VIEW_KEY.MAIN,s),n.set(d.DOCS_VIEW_KEY.BACKGROUND,o),e.addObjects([s],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),e.addObjects([o],d.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX),this._editorService.getEditor(t.getUnitId())==null&&e.enableLayerCache(d.DOCS_COMPONENT_MAIN_LAYER_INDEX)}_initRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(T.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)})}_create(e){if(!e)return;const{mainComponent:t,components:n}=this._context,r=t,s=n.get(d.DOCS_VIEW_KEY.BACKGROUND);r.changeSkeleton(e),s.changeSkeleton(e),this._recalculateSizeBySkeleton(e)}_initCommandListener(){const e=[d.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:s}=r,o=this._docSkeletonManagerService.getSkeleton();if(!o||!!o.getViewModel().getDataModel().getSnapshot().disabled)return;if(o.calculate(),this._editorService.isEditor(s)){(n=this._context.mainComponent)==null||n.makeDirty();return}this._recalculateSizeBySkeleton(o)}}))}_recalculateSizeBySkeleton(e){var m;const{mainComponent:t,scene:n,unitId:r,components:s}=this._context,o=t,c=s.get(d.DOCS_VIEW_KEY.BACKGROUND),u=(m=e.getSkeletonData())==null?void 0:m.pages;if(u==null)return;let h=0,_=0;for(let S=0,f=u.length;S<f;S++){const O=u[S],{pageWidth:p,pageHeight:v}=O;o.pageLayoutType===I.PageLayoutType.VERTICAL?(_+=v,_+=o.pageMarginTop,S===f-1&&(_+=o.pageMarginTop),h=Math.max(h,p)):o.pageLayoutType===I.PageLayoutType.HORIZONTAL&&(h+=p,S!==f-1&&(h+=o.pageMarginLeft),_=Math.max(_,v))}o.resize(h,_),c.resize(h,_),this._editorService.isEditor(r)||n.resize(h,_)}},g.DocRenderController=rn([Z(1,a.ICommandService),Z(2,C.Inject(d.DocSkeletonManagerService)),Z(3,a.IConfigService),Z(4,l.IEditorService)],g.DocRenderController);var on=Object.defineProperty,sn=Object.getOwnPropertyDescriptor,an=(i,e,t,n)=>{for(var r=n>1?void 0:n?sn(e,t):e,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&on(e,t,r),r},ce=(i,e)=>(t,n)=>e(t,n,i);let le=class extends a.Disposable{constructor(e,t,n,r){super();b(this,"_liquid",new I.Liquid);b(this,"_pageMarginCache",new Map);this._context=e,this._docSkeletonManagerService=t,this._commandService=n,this._editorService=r,this._initialize(),this._commandExecutedListener()}_initialize(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{e!=null&&this._refreshDrawing(e)})}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:s}=r,o=this._docSkeletonManagerService.getSkeleton();if(!o)return;if(this._editorService.isEditor(s)){(n=this._context.mainComponent)==null||n.makeDirty();return}this._refreshDrawing(o)}}))}_refreshDrawing(e){const t=e==null?void 0:e.getSkeletonData(),{mainComponent:n,scene:r,unitId:s}=this._context,o=n;if(!t)return;const{left:c,top:u,pageLayoutType:h,pageMarginLeft:_,pageMarginTop:m}=o,{pages:S}=t,f=[];r.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let O=0,p=S.length;O<p;O++){const v=S[O],{skeDrawings:M,marginLeft:E,marginTop:A}=v;this._liquid.translatePagePadding(v),M.forEach(P=>{const{aLeft:U,aTop:W,height:H,width:ge,drawingId:te,drawingOrigin:Fe}=P,Dn=Fe.layoutType===a.PositionedObjectLayoutType.WRAP_NONE&&Fe.behindDoc===a.BooleanNumber.TRUE;f.push({unitId:s,subUnitId:a.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:te,behindText:Dn,floatingObject:{left:U+c+this._liquid.x,top:W+u+this._liquid.y,width:ge,height:H}}),this._pageMarginCache.set(te,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.restorePagePadding(v),this._liquid.translatePage(v,h,_,m)}}};le=an([ce(1,C.Inject(d.DocSkeletonManagerService)),ce(2,a.ICommandService),ce(3,l.IEditorService)],le);var cn=Object.defineProperty,ln=Object.getOwnPropertyDescriptor,dn=(i,e,t,n)=>{for(var r=n>1?void 0:n?ln(e,t):e,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&cn(e,t,r),r},j=(i,e)=>(t,n)=>e(t,n,i);let de=class extends a.Disposable{constructor(i,e,t,n,r,s){super(),this._context=i,this._docSkeletonManagerService=e,this._univerInstanceService=t,this._commandService=n,this._textSelectionManagerService=r,this._editorService=s,this._init()}_init(){this._initSkeletonListener(),this._initCommandExecutedListener(),this._initRenderRefresher(),setTimeout(()=>this._updateViewZoom(1,!0),20)}_initRenderRefresher(){this._docSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const{unitId:e,scene:t}=this._context;this._editorService.isEditor(e)||this.disposeWithMe(t.onMouseWheel$.subscribeEvent(n=>{if(!n.ctrlKey)return;const r=this._univerInstanceService.getCurrentUniverDocInstance();if(!r)return;const s=Math.abs(n.deltaX);let o=s<40?.2:s<80?.4:.2;o*=n.deltaY>0?-1:1,t.scaleX<1&&(o/=2);const c=r.zoomRatio;let u=+Number.parseFloat(`${c+o}`).toFixed(1);u=u>=4?4:u<=.1?.1:u,this._commandService.executeCommand(d.SetDocZoomRatioCommand.id,{zoomRatio:u,unitId:r.getUnitId()}),n.preventDefault()}))})}_initSkeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(i=>{if(i==null)return;const e=this._univerInstanceService.getCurrentUniverDocInstance();if(!e)return;const t=e.zoomRatio||1;this._updateViewZoom(t,!1)}))}_initCommandExecutedListener(){const i=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(i.includes(e.id)){const t=this._univerInstanceService.getCurrentUniverDocInstance();if(!t)return;const n=e.params,{unitId:r}=n;if(r!==t.getUnitId())return;const s=t.zoomRatio||1;this._updateViewZoom(s)}}))}_updateViewZoom(i,e=!0){var n;const t=d.neoGetDocObject(this._context);t.scene.scale(i,i),this._calculatePagePosition(t,i),e&&this._textSelectionManagerService.refreshSelection(),(n=t.scene.getTransformer())==null||n.clearSelectedObjects()}_calculatePagePosition(i,e){const{document:t,scene:n,docBackground:r}=i,s=n==null?void 0:n.getParent(),{width:o,height:c,pageMarginLeft:u,pageMarginTop:h}=t;if(s==null||o===Number.POSITIVE_INFINITY||c===Number.POSITIVE_INFINITY)return;const{width:_,height:m}=s;let S=0,f=0,O=0,p=0,v=Number.POSITIVE_INFINITY;_>(o+u*2)*e?(S=_/2-o*e/2,S/=e,O=(_-u*2)/e,v=0):(S=u,O=o+u*2,v=(O-_/e)/2),m>c?(f=m/2-c/2,p=(m-h*2)/e):(f=h,p=c+h*2),n.resize(O,p+200),t.translate(S,f),r.translate(S,f);const M=n.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(v!==Number.POSITIVE_INFINITY&&M!=null){const E=M.transViewportScroll2ScrollValue(v,0).x;M.scrollTo({x:E})}return this}};de=dn([j(1,C.Inject(d.DocSkeletonManagerService)),j(2,a.IUniverInstanceService),j(3,a.ICommandService),j(4,C.Inject(d.TextSelectionManagerService)),j(5,l.IEditorService)],de);var un=Object.defineProperty,hn=Object.getOwnPropertyDescriptor,pn=(i,e,t,n)=>{for(var r=n>1?void 0:n?hn(e,t):e,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&un(e,t,r),r},x=(i,e)=>(t,n)=>e(t,n,i);let ue=class extends a.Disposable{constructor(e,t,n,r,s,o,c){super();b(this,"_loadedMap",new WeakSet);this._context=e,this._commandService=t,this._editorService=n,this._instanceSrv=r,this._textSelectionRenderManager=s,this._docSkeletonManagerService=o,this._textSelectionManagerService=c,this._initialize()}_initialize(){this._init(),this._skeletonListener(),this._commandExecutedListener()}_init(){const{unitId:e}=this._context,t=d.neoGetDocObject(this._context);t==null||t.document==null||this._loadedMap.has(t.document)||(this._initialMain(e),this._loadedMap.add(t.document))}_initialMain(e){const t=d.neoGetDocObject(this._context),{document:n,scene:r}=t;this.disposeWithMe(n.onPointerEnter$.subscribeEvent(()=>{this._isEditorReadOnly(e)||(n.cursor=I.CURSOR_TYPE.TEXT)})),this.disposeWithMe(n.onPointerLeave$.subscribeEvent(()=>{n.cursor=I.CURSOR_TYPE.DEFAULT,r.resetCursor()})),this.disposeWithMe(n.onPointerDown$.subscribeEvent((s,o)=>{if(this._isEditorReadOnly(e))return;const c=this._instanceSrv.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if((c==null?void 0:c.getUnitId())!==e&&this._instanceSrv.setCurrentUnitForType(e),this._textSelectionRenderManager.eventTrigger(s),this._editorService.getEditor(e)){this._setEditorFocus(e);const{offsetX:u,offsetY:h}=s;setTimeout(()=>{this._setEditorFocus(e),this._textSelectionRenderManager.setCursorManually(u,h)},0)}s.button!==2&&o.stopPropagation()})),this.disposeWithMe(n.onDblclick$.subscribeEvent(s=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleDblClick(s)})),this.disposeWithMe(n.onTripleClick$.subscribeEvent(s=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleTripleClick(s)}))}_isEditorReadOnly(e){const t=this._editorService.getEditor(e);return t?t.isReadOnly():!1}_setEditorFocus(e){this._editorService.focusStyle(e)}_commandExecutedListener(){const e=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:s}=r,o=(n=this._textSelectionManagerService.getCurrentSelection())==null?void 0:n.unitId;if(s!==o)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{scene:t,mainComponent:n,unitId:r}=this._context;this._textSelectionRenderManager.changeRuntime(e,t,n),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:r,subUnitId:""}),this._editorService.isEditor(r)||this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}],!1)}))}};ue=pn([x(1,a.ICommandService),x(2,l.IEditorService),x(3,a.IUniverInstanceService),x(4,I.ITextSelectionRenderManager),x(5,C.Inject(d.DocSkeletonManagerService)),x(6,C.Inject(d.TextSelectionManagerService))],ue);var _n=Object.defineProperty,gn=Object.getOwnPropertyDescriptor,mn=(i,e,t,n)=>{for(var r=n>1?void 0:n?gn(e,t):e,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&_n(e,t,r),r},he=(i,e)=>(t,n)=>e(t,n,i);const Ae=1.5;let pe=class extends a.RxDisposable{constructor(i,e,t,n){super(),this._context=i,this._docSkeletonManagerService=e,this._textSelectionManagerService=t,this._editorService=n,this._init()}_init(){this._textSelectionManagerService.textSelection$.pipe(T.takeUntil(this.dispose$)).subscribe(i=>{if(i==null)return;const{isEditing:e,unitId:t}=i;e&&this._scrollToSelection(t)})}_scrollToSelection(i){const e=this._textSelectionManagerService.getActiveRange(),t=d.neoGetDocObject(this._context),n=this._docSkeletonManagerService.getSkeleton();if(e==null||t==null)return;const{collapsed:r,startNodePosition:s}=e;if(!r)return;const o=t.document.getOffsetConfig(),{docsLeft:c,docsTop:u}=o,h=new I.NodePositionConvertToCursor(o,n),{contentBoxPointGroup:_}=h.getRangePointData(s,s),{left:m,top:S,height:f}=I.getAnchorBounding(_),O=m+c,p=S+u,v=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN),M=!!this._editorService.getEditor(i);if(v==null)return;const{left:E,top:A,right:P,bottom:U}=v.getBounding().viewBound;let W=0,H=0;const ge=M?0:100;p<A?W=p-A:p>U-f&&(W=p-U+f+ge),O<E?H=O-E:O>P-Ae&&(H=O-P+Ae);const te=v.transViewportScroll2ScrollValue(H,W);v.scrollBy(te)}};pe=mn([he(1,C.Inject(d.DocSkeletonManagerService)),he(2,C.Inject(d.TextSelectionManagerService)),he(3,l.IEditorService)],pe);var Sn=Object.defineProperty,fn=Object.getOwnPropertyDescriptor,vn=(i,e,t,n)=>{for(var r=n>1?void 0:n?fn(e,t):e,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&Sn(e,t,r),r},J=(i,e)=>(t,n)=>e(t,n,i);function Cn(i,e){const t=Le(i.left,i.top,e),n=Le(i.right,i.bottom,e);return{left:t.x,top:t.y,right:n.x,bottom:n.y}}function Le(i,e,t){const{scaleX:n,scaleY:r}=t.getAncestorScale(),s=t.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(!s)return{x:i,y:e};const{viewportScrollX:o,viewportScrollY:c}=s,u=(i-o)*n,h=(e-c)*r;return{x:u,y:h}}g.DocCanvasPopManagerService=class extends a.Disposable{constructor(e,t,n,r){super(),this._globalPopupManagerService=e,this._renderManagerService=t,this._univerInstanceService=n,this._commandService=r}_createObjectPositionObserver(e,t){const n=()=>{const{scene:u}=t,{left:h,top:_,width:m,height:S}=e,f={left:h,right:h+m,top:_,bottom:_+S},O=Cn(f,u);return{left:O.left,right:O.right,top:O.top,bottom:O.bottom}},r=n(),s=new T.BehaviorSubject(r),o=new a.DisposableCollection;o.add(this._commandService.onCommandExecuted(u=>{u.id===d.SetDocZoomRatioOperation.id&&s.next(n())}));const c=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);return c&&o.add(c.onScrollAfter$.subscribeEvent(()=>{s.next(n())})),{position:r,position$:s,disposable:o}}attachPopupToObject(e,t){const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC).getUnitId(),s=this._renderManagerService.getRenderById(r);if(!s)return{dispose:()=>{}};const{position:o,position$:c,disposable:u}=this._createObjectPositionObserver(e,s),h=this._globalPopupManagerService.addPopup({...t,unitId:r,subUnitId:"default",anchorRect:o,anchorRect$:c});return{dispose:()=>{this._globalPopupManagerService.removePopup(h),c.complete(),u.dispose()}}}},g.DocCanvasPopManagerService=vn([J(0,C.Inject(l.ICanvasPopupService)),J(1,I.IRenderManagerService),J(2,a.IUniverInstanceService),J(3,a.ICommandService)],g.DocCanvasPopManagerService);var In=Object.defineProperty,On=Object.getOwnPropertyDescriptor,Tn=(i,e,t,n)=>{for(var r=n>1?void 0:n?On(e,t):e,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&In(e,t,r),r},Be=(i,e)=>(t,n)=>e(t,n,i);g.DocsRenderService=class extends a.RxDisposable{constructor(e,t){super(),this._instanceSrv=e,this._renderManagerService=t,this._init()}_init(){this._renderManagerService.createRender$.pipe(T.takeUntil(this.dispose$)).subscribe(e=>this._createRenderWithId(e)),this._instanceSrv.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_DOC).pipe(T.takeUntil(this.dispose$)).subscribe(e=>this._createRenderer(e)),this._instanceSrv.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC).forEach(e=>this._createRenderer(e)),this._instanceSrv.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_DOC).pipe(T.takeUntil(this.dispose$)).subscribe(e=>this._disposeRenderer(e))}_createRenderer(e){const t=e.getUnitId();this._renderManagerService.has(t)||(this._createRenderWithId(t),this._renderManagerService.setCurrent(t))}_createRenderWithId(e){this._renderManagerService.createRender(e)}_disposeRenderer(e){const t=e.getUnitId();this._renderManagerService.removeRender(t)}},g.DocsRenderService=Tn([a.OnLifecycle(a.LifecycleStages.Ready,g.DocsRenderService),Be(0,a.IUniverInstanceService),Be(1,I.IRenderManagerService)],g.DocsRenderService);var bn=Object.defineProperty,Rn=Object.getOwnPropertyDescriptor,Mn=(i,e,t,n)=>{for(var r=n>1?void 0:n?Rn(e,t):e,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(n?o(e,t,r):o(r))||r);return n&&r&&bn(e,t,r),r},_e=(i,e)=>(t,n)=>e(t,n,i);g.UniverDocsUIPlugin=(ee=class extends a.Plugin{constructor(e,t,n,r){super(),this._config=e,this._injector=t,this._renderManagerSrv=n,this._logService=r,this._config=a.Tools.deepMerge({},fe,this._config),this._initDependencies(t),this._initializeCommands()}onReady(){this._initRenderBasics()}onRendered(){this._initUI(),this._initRenderModules(),this._markDocAsFocused()}_initializeCommands(){[We,He,ke,ze,Ge,Ye,Ke,Xe,qe,xt,At,Nt].forEach(e=>{this._injector.get(l.IShortcutService).registerShortcut(e)})}_initDependencies(e){[[B,{useFactory:()=>this._injector.createInstance(B,this._config)}],[X],[q],[g.DocsRenderService],[L,{useFactory:()=>this._injector.createInstance(L,this._config)}],[w,{useClass:se}],[g.DocCanvasPopManagerService]].forEach(n=>e.add(n))}_markDocAsFocused(){const e=this._injector.get(a.IUniverInstanceService),t=this._injector.get(l.IEditorService);try{const n=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(!n)return;const r=n.getUnitId();t.isEditor(r)||e.focusUnit(n.getUnitId())}catch(n){this._logService.warn(n)}}_initUI(){this._injector.get(L)}_initRenderBasics(){[d.DocSkeletonManagerService,g.DocRenderController,de].forEach(e=>{this._renderManagerSrv.registerRenderModule(a.UniverInstanceType.UNIVER_DOC,e)})}_initRenderModules(){[pe,le,ue].forEach(e=>{this._renderManagerSrv.registerRenderModule(a.UniverInstanceType.UNIVER_DOC,e)})}},b(ee,"pluginName",ve),b(ee,"type",a.UniverInstanceType.UNIVER_DOC),ee),g.UniverDocsUIPlugin=Mn([_e(1,C.Inject(C.Injector)),_e(2,I.IRenderManagerService),_e(3,a.ILogService)],g.UniverDocsUIPlugin);function yn(i){return{left:i.positionH.posOffset,top:i.positionV.posOffset,width:i.size.width,height:i.size.height}}function En(i,e=0,t=0){return{size:{width:i.width,height:i.height},positionH:{relativeFrom:a.ObjectRelativeFromH.MARGIN,posOffset:(i.left||0)-e},positionV:{relativeFrom:a.ObjectRelativeFromV.PAGE,posOffset:(i.top||0)-t},angle:i.angle||0}}g.DOC_UI_PLUGIN_NAME=ve,g.DefaultDocContainerConfig=Se,g.DefaultDocUiConfig=fe,g.DefaultToolbarConfig=me,g.PastePluginLark=Ee,g.PastePluginUniver=Ue,g.PastePluginWord=Pe,g.docDrawingPositionToTransform=yn,g.transformToDocDrawingPosition=En,Object.defineProperty(g,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.17",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer normal ui-plugin-docs",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
"@wendellhu/redi": "0.15.4",
|
|
54
54
|
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
|
|
55
55
|
"rxjs": ">=7.0.0",
|
|
56
|
-
"@univerjs/core": "0.1.
|
|
57
|
-
"@univerjs/design": "0.1.
|
|
58
|
-
"@univerjs/docs": "0.1.
|
|
59
|
-
"@univerjs/
|
|
60
|
-
"@univerjs/
|
|
56
|
+
"@univerjs/core": "0.1.17",
|
|
57
|
+
"@univerjs/design": "0.1.17",
|
|
58
|
+
"@univerjs/docs": "0.1.17",
|
|
59
|
+
"@univerjs/ui": "0.1.17",
|
|
60
|
+
"@univerjs/engine-render": "0.1.17"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/react": "^18.3.3",
|
|
@@ -68,12 +68,12 @@
|
|
|
68
68
|
"typescript": "^5.4.5",
|
|
69
69
|
"vite": "^5.3.1",
|
|
70
70
|
"vitest": "^1.6.0",
|
|
71
|
-
"@univerjs/design": "0.1.
|
|
72
|
-
"@univerjs/core": "0.1.
|
|
73
|
-
"@univerjs/
|
|
74
|
-
"@univerjs/
|
|
75
|
-
"@univerjs/
|
|
76
|
-
"@univerjs/
|
|
71
|
+
"@univerjs/design": "0.1.17",
|
|
72
|
+
"@univerjs/core": "0.1.17",
|
|
73
|
+
"@univerjs/docs": "0.1.17",
|
|
74
|
+
"@univerjs/engine-render": "0.1.17",
|
|
75
|
+
"@univerjs/shared": "0.1.17",
|
|
76
|
+
"@univerjs/ui": "0.1.17"
|
|
77
77
|
},
|
|
78
78
|
"univerSpace": {
|
|
79
79
|
".": {
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { IUniverInstanceService, RxDisposable } from '@univerjs/core';
|
|
2
|
-
import { DocSkeletonManagerService, TextSelectionManagerService } from '@univerjs/docs';
|
|
3
|
-
import { IRenderManagerService } from '@univerjs/engine-render';
|
|
4
|
-
import { IEditorService } from '@univerjs/ui';
|
|
5
|
-
|
|
6
|
-
export declare class BackScrollController extends RxDisposable {
|
|
7
|
-
private readonly _docSkeletonManagerService;
|
|
8
|
-
private readonly _textSelectionManagerService;
|
|
9
|
-
private readonly _editorService;
|
|
10
|
-
private readonly _univerInstanceService;
|
|
11
|
-
private readonly _renderManagerService;
|
|
12
|
-
constructor(_docSkeletonManagerService: DocSkeletonManagerService, _textSelectionManagerService: TextSelectionManagerService, _editorService: IEditorService, _univerInstanceService: IUniverInstanceService, _renderManagerService: IRenderManagerService);
|
|
13
|
-
private _init;
|
|
14
|
-
private _scrollToSelection;
|
|
15
|
-
private _getDocObject;
|
|
16
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ICommandService, RxDisposable } from '@univerjs/core';
|
|
2
|
-
import { IRenderManagerService } from '@univerjs/engine-render';
|
|
3
|
-
import { IEditorService } from '@univerjs/ui';
|
|
4
|
-
import { DocSkeletonManagerService } from '@univerjs/docs';
|
|
5
|
-
|
|
6
|
-
export declare class DocRenderController extends RxDisposable {
|
|
7
|
-
private readonly _docSkeletonManagerService;
|
|
8
|
-
private readonly _renderManagerService;
|
|
9
|
-
private readonly _commandService;
|
|
10
|
-
private readonly _editorService;
|
|
11
|
-
private _docRenderMap;
|
|
12
|
-
constructor(_docSkeletonManagerService: DocSkeletonManagerService, _renderManagerService: IRenderManagerService, _commandService: ICommandService, _editorService: IEditorService);
|
|
13
|
-
private _initialRenderRefresh;
|
|
14
|
-
private _create;
|
|
15
|
-
private _recalculateSizeBySkeleton;
|
|
16
|
-
private _commandExecutedListener;
|
|
17
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
2
|
-
import { IRenderManagerService, ITextSelectionRenderManager } from '@univerjs/engine-render';
|
|
3
|
-
import { IEditorService } from '@univerjs/ui';
|
|
4
|
-
import { DocSkeletonManagerService, TextSelectionManagerService } from '@univerjs/docs';
|
|
5
|
-
|
|
6
|
-
export declare class TextSelectionController extends Disposable {
|
|
7
|
-
private readonly _docSkeletonManagerService;
|
|
8
|
-
private readonly _univerInstanceService;
|
|
9
|
-
private readonly _commandService;
|
|
10
|
-
private readonly _renderManagerService;
|
|
11
|
-
private readonly _textSelectionRenderManager;
|
|
12
|
-
private readonly _textSelectionManagerService;
|
|
13
|
-
private readonly _editorService;
|
|
14
|
-
private _loadedMap;
|
|
15
|
-
constructor(_docSkeletonManagerService: DocSkeletonManagerService, _univerInstanceService: IUniverInstanceService, _commandService: ICommandService, _renderManagerService: IRenderManagerService, _textSelectionRenderManager: ITextSelectionRenderManager, _textSelectionManagerService: TextSelectionManagerService, _editorService: IEditorService);
|
|
16
|
-
private _initialize;
|
|
17
|
-
private _init;
|
|
18
|
-
private _create;
|
|
19
|
-
private _initialMain;
|
|
20
|
-
private _isEditorReadOnly;
|
|
21
|
-
private _setEditorFocus;
|
|
22
|
-
private _commandExecutedListener;
|
|
23
|
-
private _skeletonListener;
|
|
24
|
-
private _getDocObjectById;
|
|
25
|
-
}
|