@univerjs/docs-ui 0.1.1 → 0.1.3

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.
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { IUniverInstanceService, RxDisposable } from '@univerjs/core';
17
+ import { DocSkeletonManagerService, TextSelectionManagerService } from '@univerjs/docs';
18
+ import { IRenderManagerService } from '@univerjs/engine-render';
19
+ import { IEditorService } from '@univerjs/ui';
20
+ export declare class BackScrollController extends RxDisposable {
21
+ private readonly _docSkeletonManagerService;
22
+ private readonly _textSelectionManagerService;
23
+ private readonly _editorService;
24
+ private readonly _currentUniverService;
25
+ private readonly _renderManagerService;
26
+ constructor(_docSkeletonManagerService: DocSkeletonManagerService, _textSelectionManagerService: TextSelectionManagerService, _editorService: IEditorService, _currentUniverService: IUniverInstanceService, _renderManagerService: IRenderManagerService);
27
+ private _init;
28
+ private _scrollToSelection;
29
+ private _getDocObject;
30
+ }
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
17
- import { ITextSelectionRenderManager } from '@univerjs/engine-render';
17
+ import { IRenderManagerService, ITextSelectionRenderManager } from '@univerjs/engine-render';
18
18
  import { DocSkeletonManagerService } from '@univerjs/docs';
19
19
  import { IEditorService } from '@univerjs/ui';
20
20
  export declare class DocEditorBridgeController extends Disposable {
@@ -23,13 +23,16 @@ export declare class DocEditorBridgeController extends Disposable {
23
23
  private readonly _editorService;
24
24
  private readonly _commandService;
25
25
  private readonly _textSelectionRenderManager;
26
+ private readonly _renderManagerService;
26
27
  private _initialEditors;
27
- constructor(_currentUniverService: IUniverInstanceService, _docSkeletonManagerService: DocSkeletonManagerService, _editorService: IEditorService, _commandService: ICommandService, _textSelectionRenderManager: ITextSelectionRenderManager);
28
+ constructor(_currentUniverService: IUniverInstanceService, _docSkeletonManagerService: DocSkeletonManagerService, _editorService: IEditorService, _commandService: ICommandService, _textSelectionRenderManager: ITextSelectionRenderManager, _renderManagerService: IRenderManagerService);
28
29
  private _initialize;
29
30
  private _resize;
30
31
  private _initialSetValue;
31
32
  private _initialBlur;
32
33
  private _initialFocus;
34
+ private _initialValueChange;
35
+ private _valueChange;
33
36
  /**
34
37
  * Listen to document edits to refresh the size of the normula editor.
35
38
  */
@@ -15,18 +15,20 @@
15
15
  */
16
16
  import { Disposable, IUniverInstanceService } from '@univerjs/core';
17
17
  import type { IDesktopUIController } from '@univerjs/ui';
18
- import { ComponentManager, IEditorService, IMenuService } from '@univerjs/ui';
18
+ import { ComponentManager, IEditorService, ILayoutService, IMenuService } from '@univerjs/ui';
19
19
  import { Injector } from '@wendellhu/redi';
20
20
  export declare class DocUIController extends Disposable {
21
21
  private readonly _injector;
22
22
  private readonly _componentManager;
23
+ private readonly _layoutService;
23
24
  private readonly _editorService;
24
25
  private readonly _menuService;
25
26
  private readonly _uiController;
26
27
  private readonly _currentUniverService;
27
- constructor(_injector: Injector, _componentManager: ComponentManager, _editorService: IEditorService, _menuService: IMenuService, _uiController: IDesktopUIController, _currentUniverService: IUniverInstanceService);
28
+ constructor(_injector: Injector, _componentManager: ComponentManager, _layoutService: ILayoutService, _editorService: IEditorService, _menuService: IMenuService, _uiController: IDesktopUIController, _currentUniverService: IUniverInstanceService);
28
29
  private _initCustomComponents;
29
30
  private _initMenus;
30
31
  private _init;
31
32
  private _initDocBackground;
33
+ private _initFocusHandler;
32
34
  }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
17
+ import { IRenderManagerService, ITextSelectionRenderManager } from '@univerjs/engine-render';
18
+ import { IEditorService } from '@univerjs/ui';
19
+ import { DocSkeletonManagerService, TextSelectionManagerService } from '@univerjs/docs';
20
+ export declare class TextSelectionController extends Disposable {
21
+ private readonly _docSkeletonManagerService;
22
+ private readonly _currentUniverService;
23
+ private readonly _commandService;
24
+ private readonly _renderManagerService;
25
+ private readonly _textSelectionRenderManager;
26
+ private readonly _textSelectionManagerService;
27
+ private readonly _editorService;
28
+ private _loadedMap;
29
+ constructor(_docSkeletonManagerService: DocSkeletonManagerService, _currentUniverService: IUniverInstanceService, _commandService: ICommandService, _renderManagerService: IRenderManagerService, _textSelectionRenderManager: ITextSelectionRenderManager, _textSelectionManagerService: TextSelectionManagerService, _editorService: IEditorService);
30
+ private _initialize;
31
+ private _init;
32
+ private _create;
33
+ private _initialMain;
34
+ private _isEditorReadOnly;
35
+ private _setEditorFocus;
36
+ private _commandExecutedListener;
37
+ private _skeletonListener;
38
+ private _getDocObjectById;
39
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IPastePlugin } from './type';
17
+ declare const univerPastePlugin: IPastePlugin;
18
+ export default univerPastePlugin;
@@ -13,7 +13,10 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import type { IDocumentBody } from '@univerjs/core';
16
+ import type { IDocumentBody, ITextRun } from '@univerjs/core';
17
+ export declare function covertTextRunToHtml(dataStream: string, textRun: ITextRun): string;
18
+ export declare function getBodySliceHtml(body: IDocumentBody, startIndex: number, endIndex: number): string;
19
+ export declare function convertBodyToHtml(body: IDocumentBody, withParagraphInfo?: boolean): string;
17
20
  export declare class UDMToHtmlService {
18
21
  convert(bodyList: IDocumentBody[]): string;
19
22
  }
@@ -15,3 +15,4 @@
15
15
  */
16
16
  import type { IContextService } from '@univerjs/core';
17
17
  export declare function whenDocAndEditorFocused(contextService: IContextService): boolean;
18
+ export declare function whenDocAndEditorFocusedWithBreakLine(contextService: IContextService): boolean;
package/lib/umd/index.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(g,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("@univerjs/docs"),require("@univerjs/engine-render"),require("@wendellhu/redi/react-bindings"),require("@univerjs/design"),require("react"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","@univerjs/docs","@univerjs/engine-render","@wendellhu/redi/react-bindings","@univerjs/design","react","rxjs"],a):(g=typeof globalThis<"u"?globalThis:g||self,a(g.UniverDocsUi={},g.UniverCore,g["@wendellhu/redi"],g.UniverUi,g.UniverDocs,g.UniverEngineRender,g["@wendellhu/redi/react-bindings"],g.UniverDesign,g.React,g.rxjs))})(this,function(g,a,v,l,u,O,De,Ee,Pe,y){"use strict";var hn=Object.defineProperty;var pn=(g,a,v)=>a in g?hn(g,a,{enumerable:!0,configurable:!0,writable:!0,value:v}):g[a]=v;var I=(g,a,v)=>(pn(g,typeof a!="symbol"?a+"":a,v),v);var ce;const le={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},de={outerLeft:!1,outerRight:!1,header:!0,footer:!0,innerLeft:!1,innerRight:!1,frozenHeaderLT:!1,frozenHeaderRT:!1,frozenHeaderLM:!1,frozenContent:!1,infoBar:!0,toolbar:!0},ue={layout:{docContainerConfig:de,toolbarConfig:le}},he="DocUI";function M(r){return r.getContextValue(a.FOCUSING_DOC)&&r.getContextValue(a.FOCUSING_UNIVER_EDITOR)}const Ue={id:u.MoveCursorOperation.id,binding:l.KeyCode.ARROW_UP,preconditions:M,staticParameters:{direction:a.Direction.UP}},xe={id:u.MoveCursorOperation.id,binding:l.KeyCode.ARROW_DOWN,preconditions:M,staticParameters:{direction:a.Direction.DOWN}},Le={id:u.MoveCursorOperation.id,binding:l.KeyCode.ARROW_LEFT,preconditions:M,staticParameters:{direction:a.Direction.LEFT}},Ne={id:u.MoveCursorOperation.id,binding:l.KeyCode.ARROW_RIGHT,preconditions:M,staticParameters:{direction:a.Direction.RIGHT}},Ae={id:u.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_UP|l.MetaKeys.SHIFT,preconditions:M,staticParameters:{direction:a.Direction.UP}},Be={id:u.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_DOWN|l.MetaKeys.SHIFT,preconditions:M,staticParameters:{direction:a.Direction.DOWN}},Fe={id:u.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_LEFT|l.MetaKeys.SHIFT,preconditions:M,staticParameters:{direction:a.Direction.LEFT}},we={id:u.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_RIGHT|l.MetaKeys.SHIFT,preconditions:M,staticParameters:{direction:a.Direction.RIGHT}},$e={id:u.SelectAllOperation.id,binding:l.KeyCode.A|l.MetaKeys.CTRL_COMMAND,preconditions:r=>r.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&(r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.EDITOR_ACTIVATED))};var je=Object.defineProperty,ze=Object.getOwnPropertyDescriptor,We=(r,t,e,n)=>{for(var i=n>1?void 0:n?ze(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&je(t,e,i),i},pe=(r,t)=>(e,n)=>t(e,n,r);let te=class{constructor(r,t,e){I(this,"_docContainer");I(this,"getComponent",r=>{if(this._docContainer=r,!r.getContentRef().current)throw new Error("container is not ready")});I(this,"changeLocale",r=>{this._localeService.setLocale(r)});this._config=r,this._localeService=t,this._injector=e}getUIConfig(){return{injector:this._injector,config:this._config,changeLocale:this.changeLocale,getComponent:this.getComponent}}getContentRef(){return this._docContainer.getContentRef()}UIDidMount(r){if(this._docContainer)return r(this._docContainer)}getDocContainer(){return this._docContainer}};te=We([pe(1,v.Inject(a.LocaleService)),pe(2,v.Inject(v.Injector))],te);var Ve=Object.defineProperty,He=Object.getOwnPropertyDescriptor,ke=(r,t,e,n)=>{for(var i=n>1?void 0:n?He(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&Ve(t,e,i),i},W=(r,t)=>(e,n)=>t(e,n,r);let L=class extends a.RxDisposable{constructor(t,e,n,i,o){super();I(this,"_docContainerController");I(this,"changeLocale",t=>{this._localeService.setLocale(t)});this._localeService=e,this._injector=n,this._textSelectionRenderManager=i,this._layoutService=o,this._docContainerController=this._injector.createInstance(te,t),this._registerContainer()}_registerContainer(){this._layoutService&&this.disposeWithMe(this._layoutService.registerContainerElement(this._textSelectionRenderManager.__getEditorContainer()))}getDocContainerController(){return this._docContainerController}};L=ke([W(1,v.Inject(a.LocaleService)),W(2,v.Inject(v.Injector)),W(3,O.ITextSelectionRenderManager),W(4,v.Optional(l.ILayoutService))],L);const V="UI_PLUGIN_DOCS",_e=`${V}_COLOR_PICKER_COMPONENT`,me=`${V}_FONT_FAMILY_COMPONENT`,ge=`${V}_FONT_FAMILY_ITEM_COMPONENT`,fe=`${V}_FONT_SIZE_COMPONENT`;var Se={exports:{}},H={};/**
1
+ (function(S,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("@univerjs/docs"),require("@univerjs/engine-render"),require("@wendellhu/redi/react-bindings"),require("@univerjs/design"),require("react"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","@univerjs/docs","@univerjs/engine-render","@wendellhu/redi/react-bindings","@univerjs/design","react","rxjs"],a):(S=typeof globalThis<"u"?globalThis:S||self,a(S.UniverDocsUi={},S.UniverCore,S["@wendellhu/redi"],S.UniverUi,S.UniverDocs,S.UniverEngineRender,S["@wendellhu/redi/react-bindings"],S.UniverDesign,S.React,S.rxjs))})(this,function(S,a,C,l,d,v,we,$e,Fe,M){"use strict";var Rn=Object.defineProperty;var yn=(S,a,C)=>a in S?Rn(S,a,{enumerable:!0,configurable:!0,writable:!0,value:C}):S[a]=C;var b=(S,a,C)=>(yn(S,typeof a!="symbol"?a+"":a,C),C);var fe;const ve={undo:!0,redo:!0,font:!0,fontSize:!0,bold:!0,italic:!0,strikethrough:!0,underline:!0,textColor:!0,fillColor:!0,horizontalAlignMode:!0,verticalAlignMode:!0,textWrapMode:!0,textRotateMode:!0},me={outerLeft:!1,outerRight:!1,header:!0,footer:!0,innerLeft:!1,innerRight:!1,frozenHeaderLT:!1,frozenHeaderRT:!1,frozenHeaderLM:!1,frozenContent:!1,infoBar:!0,toolbar:!0},Ce={layout:{docContainerConfig:me,toolbarConfig:ve}},Ie="DocUI";function D(r){return r.getContextValue(a.FOCUSING_DOC)&&r.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function Ae(r){return r.getContextValue(a.FOCUSING_DOC)&&r.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!r.getContextValue(a.FOCUSING_UNIVER_EDITOR_SINGLE_MODE)}const je={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_UP,preconditions:D,staticParameters:{direction:a.Direction.UP}},We={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_DOWN,preconditions:D,staticParameters:{direction:a.Direction.DOWN}},Ve={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_LEFT,preconditions:D,staticParameters:{direction:a.Direction.LEFT}},ke={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_RIGHT,preconditions:D,staticParameters:{direction:a.Direction.RIGHT}},ze={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_UP|l.MetaKeys.SHIFT,preconditions:D,staticParameters:{direction:a.Direction.UP}},He={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_DOWN|l.MetaKeys.SHIFT,preconditions:D,staticParameters:{direction:a.Direction.DOWN}},Ye={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_LEFT|l.MetaKeys.SHIFT,preconditions:D,staticParameters:{direction:a.Direction.LEFT}},Ge={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_RIGHT|l.MetaKeys.SHIFT,preconditions:D,staticParameters:{direction:a.Direction.RIGHT}},Ke={id:d.SelectAllOperation.id,binding:l.KeyCode.A|l.MetaKeys.CTRL_COMMAND,preconditions:r=>r.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&(r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.EDITOR_ACTIVATED))};var qe=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,Ze=(r,e,t,n)=>{for(var i=n>1?void 0:n?Xe(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&qe(e,t,i),i},Oe=(r,e)=>(t,n)=>e(t,n,r);let le=class{constructor(r,e,t){b(this,"_docContainer");b(this,"getComponent",r=>{if(this._docContainer=r,!r.getContentRef().current)throw new Error("container is not ready")});b(this,"changeLocale",r=>{this._localeService.setLocale(r)});this._config=r,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(r){if(this._docContainer)return r(this._docContainer)}getDocContainer(){return this._docContainer}};le=Ze([Oe(1,C.Inject(a.LocaleService)),Oe(2,C.Inject(C.Injector))],le);var Je=Object.defineProperty,Qe=Object.getOwnPropertyDescriptor,et=(r,e,t,n)=>{for(var i=n>1?void 0:n?Qe(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&Je(e,t,i),i},Y=(r,e)=>(t,n)=>e(t,n,r);let W=class extends a.RxDisposable{constructor(e,t,n,i,o){super();b(this,"_docContainerController");b(this,"changeLocale",e=>{this._localeService.setLocale(e)});this._localeService=t,this._injector=n,this._textSelectionRenderManager=i,this._layoutService=o,this._docContainerController=this._injector.createInstance(le,e),this._registerContainer()}_registerContainer(){this._layoutService&&this.disposeWithMe(this._layoutService.registerContainerElement(this._textSelectionRenderManager.__getEditorContainer()))}getDocContainerController(){return this._docContainerController}};W=et([Y(1,C.Inject(a.LocaleService)),Y(2,C.Inject(C.Injector)),Y(3,v.ITextSelectionRenderManager),Y(4,C.Optional(l.ILayoutService))],W);const G="UI_PLUGIN_DOCS",be=`${G}_COLOR_PICKER_COMPONENT`,Me=`${G}_FONT_FAMILY_COMPONENT`,Te=`${G}_FONT_FAMILY_ITEM_COMPONENT`,Re=`${G}_FONT_SIZE_COMPONENT`;var ye={exports:{}},K={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,5 +6,5 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var Ke=Pe,Ye=Symbol.for("react.element"),Ge=Symbol.for("react.fragment"),qe=Object.prototype.hasOwnProperty,Xe=Ke.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Ze={key:!0,ref:!0,__self:!0,__source:!0};function ve(r,t,e){var n,i={},o=null,s=null;e!==void 0&&(o=""+e),t.key!==void 0&&(o=""+t.key),t.ref!==void 0&&(s=t.ref);for(n in t)qe.call(t,n)&&!Ze.hasOwnProperty(n)&&(i[n]=t[n]);if(r&&r.defaultProps)for(n in t=r.defaultProps,t)i[n]===void 0&&(i[n]=t[n]);return{$$typeof:Ye,type:r,key:o,ref:s,props:i,_owner:Xe.current}}H.Fragment=Ge,H.jsx=ve,H.jsxs=ve,Se.exports=H;var Je=Se.exports;const Qe={docsUiCanvasBackground:"univer-docs-ui-canvas-background"},et=()=>Je.jsx("div",{className:Qe.docsUiCanvasBackground});function tt(r){const t=r.get(a.ICommandService);return{id:u.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 y.Observable(e=>{const n=t.onCommandExecuted(i=>{var s;const o=i.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=E(r);if(c==null)return;const d=(s=c.ts)==null?void 0:s.bl;e.next(d===a.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function nt(r){const t=r.get(a.ICommandService);return{id:u.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 y.Observable(e=>{const n=t.onCommandExecuted(i=>{var s;const o=i.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=E(r);if(c==null)return;const d=(s=c.ts)==null?void 0:s.it;e.next(d===a.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function it(r){const t=r.get(a.ICommandService);return{id:u.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 y.Observable(e=>{const n=t.onCommandExecuted(i=>{var s;const o=i.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=E(r);if(c==null)return;const d=(s=c.ts)==null?void 0:s.ul;e.next((d==null?void 0:d.s)===a.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function rt(r){const t=r.get(a.ICommandService);return{id:u.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 y.Observable(e=>{const n=t.onCommandExecuted(i=>{var s;const o=i.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=E(r);if(c==null)return;const d=(s=c.ts)==null?void 0:s.st;e.next((d==null?void 0:d.s)===a.BooleanNumber.TRUE)}});return e.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function ot(r){const t=r.get(a.ICommandService);return{id:u.SetInlineFormatSubscriptCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",positions:[l.MenuPosition.TOOLBAR_START],activated$:new y.Observable(e=>{const n=t.onCommandExecuted(i=>{var s;const o=i.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=E(r);if(c==null)return;const d=(s=c.ts)==null?void 0:s.va;e.next(d===a.BaselineOffset.SUBSCRIPT)}});return e.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function st(r){const t=r.get(a.ICommandService);return{id:u.SetInlineFormatSuperscriptCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",positions:[l.MenuPosition.TOOLBAR_START],activated$:new y.Observable(e=>{const n=t.onCommandExecuted(i=>{var s;const o=i.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=E(r);if(c==null)return;const d=(s=c.ts)==null?void 0:s.va;e.next(d===a.BaselineOffset.SUPERSCRIPT)}});return e.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function at(r){const t=r.get(a.ICommandService);return{id:u.SetInlineFormatFontFamilyCommand.id,tooltip:"toolbar.font",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,label:me,positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_FAMILY_LIST.map(e=>({label:{name:ge,hoverable:!0},value:e.value})),value$:new y.Observable(e=>{const n=l.FONT_FAMILY_LIST[0].value,i=t.onCommandExecuted(o=>{var c;const s=o.id;if(s===u.SetTextSelectionsOperation.id||s===u.SetInlineFormatFontFamilyCommand.id){const d=E(r);if(d==null)return;const p=(c=d.ts)==null?void 0:c.ff;e.next(p!=null?p:n)}});return e.next(n),i.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function ct(r){const t=r.get(a.ICommandService);return{id:u.SetInlineFormatFontSizeCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:fe,props:{min:1,max:400}},positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_SIZE_LIST,value$:new y.Observable(e=>{const i=t.onCommandExecuted(o=>{var c;const s=o.id;if(s===u.SetTextSelectionsOperation.id||s===u.SetInlineFormatFontSizeCommand.id){const d=E(r);if(d==null)return;const p=(c=d.ts)==null?void 0:c.fs;e.next(p!=null?p:14)}});return e.next(14),i.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function lt(r){const t=r.get(a.ICommandService),e=r.get(a.ThemeService);return{id:u.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:_e,hoverable:!1}}],value$:new y.Observable(n=>{const i=e.getCurrentTheme().textColor,o=t.onCommandExecuted(s=>{if(s.id===u.SetInlineFormatTextColorCommand.id){const c=s.params.value;n.next(c!=null?c:i)}});return n.next(i),o.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function dt(r){return{id:u.OrderListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"OrderSingle",tooltip:"toolbar.order",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function ut(r){return{id:u.BulletListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"UnorderSingle",tooltip:"toolbar.unorder",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function E(r){var d;const t=r.get(a.IUniverInstanceService),e=r.get(u.TextSelectionManagerService),n=t.getCurrentUniverDocInstance(),i=e.getActiveRange();if(n==null||i==null)return;const o=(d=n.getBody())==null?void 0:d.textRuns;if(o==null)return;const{startOffset:s}=i;return o.find(({st:p,ed:_})=>s>=p&&s<_)}var ht=Object.defineProperty,pt=Object.getOwnPropertyDescriptor,_t=(r,t,e,n)=>{for(var i=n>1?void 0:n?pt(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&ht(t,e,i),i},P=(r,t)=>(e,n)=>t(e,n,r);let k=class extends a.Disposable{constructor(r,t,e,n,i,o){super(),this._injector=r,this._componentManager=t,this._editorService=e,this._menuService=n,this._uiController=i,this._currentUniverService=o,this._init()}_initCustomComponents(){const r=this._componentManager;this.disposeWithMe(r.register(_e,Ee.ColorPicker)),this.disposeWithMe(r.register(me,l.FontFamily)),this.disposeWithMe(r.register(ge,l.FontFamilyItem)),this.disposeWithMe(r.register(fe,l.FontSize))}_initMenus(){[tt,nt,it,rt,ot,st,ct,at,lt,dt,ut].forEach(r=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(r)))})}_init(){this._initCustomComponents(),this._initMenus(),this._initDocBackground()}_initDocBackground(){const r=this._currentUniverService.getAllUniverDocsInstance()[0].getUnitId();if(r==null)return;this._editorService.isEditor(r)||this.disposeWithMe(this._uiController.registerContentComponent(()=>De.connectInjector(et,this._injector)))}};k=_t([a.OnLifecycle(a.LifecycleStages.Rendered,k),P(0,v.Inject(v.Injector)),P(1,v.Inject(l.ComponentManager)),P(2,l.IEditorService),P(3,l.IMenuService),P(4,l.IUIController),P(5,a.IUniverInstanceService)],k);const mt={toolbar:{undo:"Undo",redo:"Redo",font:"Font",fontSize:"Font size",bold:"Bold",italic:"Italic",strikethrough:"Strikethrough",subscript:"Subscript",superscript:"Superscript",underline:"Underline",textColor:{main:"Text color",right:"Choose color"},resetColor:"Reset",order:"Ordered list",unorder:"Unordered list"}},Ce={toolbar:{undo:"撤销",redo:"重做",font:"字体",fontSize:"字号",bold:"粗体",italic:"斜体",strikethrough:"删除线",subscript:"下标",superscript:"上标",underline:"下划线",textColor:{main:"文本颜色",right:"颜色选择"},resetColor:"重置颜色",order:"有序列表",unorder:"无序列表"}},gt={id:u.BreakLineCommand.id,preconditions:M,binding:l.KeyCode.ENTER},ft={id:u.DeleteLeftCommand.id,preconditions:M,binding:l.KeyCode.BACKSPACE},St={id:u.DeleteRightCommand.id,preconditions:M,binding:l.KeyCode.DELETE},vt=10,Ct=6;function It(){return a.Tools.generateRandomId(Ct)}function Ot(r){const t=r.match(/data-copy-id="([^\s]+)"/);return t&&t[1]?t[1]:null}class bt{constructor(){I(this,"_cache",new a.LRUMap(vt))}set(t,e){this._cache.set(t,e)}get(t){return this._cache.get(t)}clear(){this._cache.clear()}}const Ie=new bt;function ne(r){const t=r.style,e={},n=r.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{e.bl=a.BooleanNumber.TRUE;break}case"s":{e.st={s:a.BooleanNumber.TRUE};break}case"u":{e.ul={s:a.BooleanNumber.TRUE};break}case"i":{e.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{e.va=n==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}for(let i=0;i<t.length;i++){const o=t[i],s=t.getPropertyValue(o);switch(o){case"font-family":{e.ff=s;break}case"font-size":{const c=Number.parseInt(s);Number.isNaN(c)||s.endsWith("pt")&&(e.fs=c);break}case"font-style":{s==="italic"&&(e.it=a.BooleanNumber.TRUE);break}case"font-weight":{Number(s)>400&&(e.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(s)?e.ul={s:a.BooleanNumber.TRUE}:/overline/.test(s)?e.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(s)&&(e.st={s:a.BooleanNumber.TRUE});break}case"color":{const c=new a.ColorKit(s);c.isValid&&(e.cl={rgb:c.toRgbString()});break}case"background-color":{const c=new a.ColorKit(s);c.isValid&&(e.bg={rgb:c.toRgbString()});break}}}return e}function Tt(r){const t=new DOMParser,e=`<x-univer id="univer-root">${r}</x-univer>`;return t.parseFromString(e,"text/html").querySelector("#univer-root")}function Oe(r,t){const e=r.tagName.toLowerCase();return typeof t=="string"?e===t:Array.isArray(t)?t.some(n=>n===e):t(r)}const ee=class ee{constructor(){I(this,"_styleCache",new Map);I(this,"_styleRules",[]);I(this,"_afterProcessRules",[])}static use(t){if(this._pluginList.includes(t))throw new Error(`Univer paste plugin ${t.name} already added`);this._pluginList.push(t)}convert(t){const e=ee._pluginList.find(o=>o.checkPasteType(t)),n=Tt(t),i={dataStream:"",textRuns:[]};return e&&(this._styleRules=[...e.stylesRules],this._afterProcessRules=[...e.afterProcessRules]),this._styleCache.clear(),this._process(null,n==null?void 0:n.childNodes,i),this._styleCache.clear(),this._styleRules=[],this._afterProcessRules=[],i}_process(t,e,n){var i;for(const o of e)if(o.nodeType===Node.TEXT_NODE){const s=(i=o.nodeValue)==null?void 0:i.replace(/[\r\n]/g,"");let c;t&&this._styleCache.has(t)&&(c=this._styleCache.get(t)),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=t?this._styleCache.get(t):{},c=this._styleRules.find(({filter:f})=>Oe(o,f)),d=c?c.getStyle(o):ne(o);this._styleCache.set(o,{...s,...d});const{childNodes:p}=o;this._process(o,p,n);const _=this._afterProcessRules.find(({filter:f})=>Oe(o,f));_&&_.handler(n,o)}}};I(ee,"_pluginList",[]);let N=ee;const yt={name:"univer-doc-paste-plugin-lark",checkPasteType(r){return/lark-record-clipboard/i.test(r)},stylesRules:[{filter:["s"],getStyle(r){const t=ne(r);return{st:{s:a.BooleanNumber.TRUE},...t}}}],afterProcessRules:[{filter(r){return r.tagName==="DIV"&&/ace-line/i.test(r.className)},handler(r){r.paragraphs==null&&(r.paragraphs=[]),r.paragraphs.push({startIndex:r.dataStream.length}),r.dataStream+="\r"}}]};function Mt(r){const t=r.style,e={};for(let n=0;n<t.length;n++){const i=t[n],o=t.getPropertyValue(i);switch(i){case"margin-top":{const s=Number.parseInt(o);e.spaceAbove=/pt/.test(o)?O.ptToPixel(s):s;break}case"margin-bottom":{const s=Number.parseInt(o);e.spaceBelow=/pt/.test(o)?O.ptToPixel(s):s;break}}}return Object.getOwnPropertyNames(e).length?e:null}const Rt={name:"univer-doc-paste-plugin-word",checkPasteType(r){return/word|mso/i.test(r)},stylesRules:[{filter:["b"],getStyle(r){const t=ne(r);return{bl:a.BooleanNumber.TRUE,...t}}}],afterProcessRules:[{filter(r){return r.tagName==="P"&&/mso/i.test(r.className)},handler(r,t){r.paragraphs==null&&(r.paragraphs=[]);const e={startIndex:r.dataStream.length},n=Mt(t);n&&(e.paragraphStyle=n),r.paragraphs.push(e),r.dataStream+="\r"}}]};function Dt(r,t){const{st:e,ed:n,ts:i={}}=t,{ff:o,fs:s,it:c,bl:d,ul:p,st:_,ol:f,bg:C,cl:b,va:S}=i;let h=r.slice(e,n);const m=[];return c===a.BooleanNumber.TRUE&&(h=`<i>${h}</i>`),S===a.BaselineOffset.SUPERSCRIPT?h=`<sup>${h}</sup>`:S===a.BaselineOffset.SUBSCRIPT&&(h=`<sub>${h}</sub>`),(p==null?void 0:p.s)===a.BooleanNumber.TRUE&&(h=`<u>${h}</u>`),(_==null?void 0:_.s)===a.BooleanNumber.TRUE&&(h=`<s>${h}</s>`),d===a.BooleanNumber.TRUE&&(h=`<strong>${h}</strong>`),o&&m.push(`font-family: ${o}`),b&&m.push(`color: ${b.rgb}`),s&&m.push(`font-size: ${s}px`),f&&m.push("text-decoration: overline"),C&&m.push(`background: ${C.rgb}`),m.length?`<span style="${m.join(";")}">${h}</span>`:h}function be(r,t=!0){const{dataStream:e,textRuns:n=[],paragraphs:i=[]}=r;let o=0;const s=[],c=[];for(const d of n){const{st:p,ed:_}=d;if(p!==o&&s.push(e.slice(o,p)),s.push(Dt(e,d)),o=_,t)for(const f of i){const{startIndex:C,paragraphStyle:b={}}=f;if(C>=p&&C<=_){const{spaceAbove:S,spaceBelow:h}=b,m=[];S!=null&&(typeof S=="number"?m.push(`margin-top: ${S}px`):m.push(`margin-top: ${S.v}px`)),h!=null&&(typeof h=="number"?m.push(`margin-bottom: ${h}px`):m.push(`margin-bottom: ${h.v}px`)),c.push(`<p className="UniverNormal" ${m.length?`style="${m.join(";")}"`:""}>${s.join("")}</p>`),s.length=0}}}return o<e.length&&s.push(e.slice(o,e.length)),c.join("")+s.join("")}class Et{convert(t){if(t.length===0)throw new Error("The bodyList length at least to be 1");if(t.length===1)return be(t[0]);let e="";for(const n of t)e+='<p className="UniverNormal">',e+=be(n,!1),e+="</p>";return e}}var Pt=Object.defineProperty,Ut=Object.getOwnPropertyDescriptor,xt=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ut(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&Pt(t,e,i),i},A=(r,t)=>(e,n)=>t(e,n,r);N.use(Rt),N.use(yt);function Lt(r){const t=r.replace(/\n/g,"\r"),e=[];for(let n=0;n<t.length;n++)t[n]==="\r"&&e.push({startIndex:n});return{dataStream:t,paragraphs:e}}const B=v.createIdentifier("doc.clipboard-service");let ie=class extends a.Disposable{constructor(t,e,n,i,o){super();I(this,"_clipboardHooks",[]);I(this,"_htmlToUDM",new N);I(this,"_umdToHtml",new Et);this._currentUniverService=t,this._logService=e,this._commandService=n,this._clipboardInterfaceService=i,this._textSelectionManagerService=o}async copy(){const t=this._getDocumentBodyInRanges();try{this._setClipboardData(t)}catch(e){return this._logService.error("[DocClipboardService] copy failed",e),!1}return!0}async cut(){return this._cut()}async paste(t){const e=await this._generateBodyFromClipboardItems(t);return this._paste(e)}async legacyPaste(t,e){const n=this._generateBodyFromHtmlAndText(t,e);return this._paste(n)}async _cut(){var o;const{segmentId:t,endOffset:e,style:n}=(o=this._textSelectionManagerService.getActiveRange())!=null?o:{},i=this._textSelectionManagerService.getSelections();if(t==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),e==null||i==null)return!1;this.copy();try{let s=e;for(const d of i){const{startOffset:p,endOffset:_}=d;p==null||_==null||_<=e&&(s-=_-p)}const c=[{startOffset:s,endOffset:s,style:n}];return this._commandService.executeCommand(u.CutContentCommand.id,{segmentId:t,textRanges:c})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(t){var s;const{segmentId:e,endOffset:n,style:i}=(s=this._textSelectionManagerService.getActiveRange())!=null?s:{},o=this._textSelectionManagerService.getSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),n==null||o==null)return!1;try{let c=n;for(const p of o){const{startOffset:_,endOffset:f}=p;_==null||f==null||f<=n&&(c+=t.dataStream.length-(f-_))}const d=[{startOffset:c,endOffset:c,style:i}];return this._commandService.executeCommand(u.InnerPasteCommand.id,{body:t,segmentId:e,textRanges:d})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(t){const e=It(),n=t.length>1?t.map(o=>o.dataStream).join(`
10
- `):t[0].dataStream;let i=this._umdToHtml.convert(t);return t.length===1&&(i=i.replace(/(<[a-z]+)/,(o,s)=>`${s} data-copy-id="${e}"`),Ie.set(e,t[0])),this._clipboardInterfaceService.write(n,i)}addClipboardHook(t){return this._clipboardHooks.push(t),a.toDisposable(()=>{const e=this._clipboardHooks.indexOf(t);e>-1&&this._clipboardHooks.splice(e,1)})}_getDocumentBodyInRanges(){const t=this._textSelectionManagerService.getSelections(),e=this._currentUniverService.getCurrentUniverDocInstance(),n=[];if(t==null)return n;for(const i of t){const{startOffset:o,endOffset:s,collapsed:c}=i;if(c||o==null||s==null)continue;const d=e.sliceBody(o,s);d!=null&&n.push(d)}return n}async _generateBodyFromClipboardItems(t){try{let e="",n="";for(const i of t)for(const o of i.types)o===l.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await i.getType(o).then(s=>s&&s.text()):o===l.HTML_CLIPBOARD_MIME_TYPE&&(e=await i.getType(o).then(s=>s&&s.text()));return this._generateBodyFromHtmlAndText(e,n)}catch(e){return Promise.reject(e)}}_generateBodyFromHtmlAndText(t,e){if(!t){if(e)return Lt(e);throw new Error("[DocClipboardService] html and text cannot be both empty!")}const n=Ot(t);if(n){const i=Ie.get(n);if(i)return i}return this._htmlToUDM.convert(t)}};ie=xt([A(0,a.IUniverInstanceService),A(1,a.ILogService),A(2,a.ICommandService),A(3,l.IClipboardInterfaceService),A(4,v.Inject(u.TextSelectionManagerService))],ie);function K(r){return r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.EDITOR_ACTIVATED)}const re=999,Nt={id:l.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:re,preconditions:K,handler:async r=>r.get(B).copy()},At={id:l.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:re,preconditions:K,handler:async r=>r.get(B).cut()},Bt={id:l.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:re,preconditions:K,handler:async r=>{const t=r.get(B),n=await r.get(l.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}};var Ft=Object.defineProperty,wt=Object.getOwnPropertyDescriptor,$t=(r,t,e,n)=>{for(var i=n>1?void 0:n?wt(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&Ft(t,e,i),i},F=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends a.RxDisposable{constructor(r,t,e,n,i){super(),this._commandService=r,this._clipboardInterfaceService=t,this._docClipboardService=e,this._textSelectionRenderManager=n,this._contextService=i,this._init()}_init(){[Nt,At,Bt].forEach(r=>this.disposeWithMe(this._commandService.registerMultipleCommand(r))),[u.InnerPasteCommand,u.CutContentCommand].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r))),this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var r;this._clipboardInterfaceService.supportClipboard||(r=this._textSelectionRenderManager)==null||r.onPaste$.pipe(y.takeUntil(this.dispose$)).subscribe(t=>{var o,s;if(!K(this._contextService))return;t.event.preventDefault();const e=t.event,n=(o=e.clipboardData)==null?void 0:o.getData("text/html"),i=(s=e.clipboardData)==null?void 0:s.getData("text/plain");this._docClipboardService.legacyPaste(n,i)})}};Y=$t([a.OnLifecycle(a.LifecycleStages.Steady,Y),F(0,a.ICommandService),F(1,l.IClipboardInterfaceService),F(2,B),F(3,O.ITextSelectionRenderManager),F(4,a.IContextService)],Y);var jt=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,Wt=(r,t,e,n)=>{for(var i=n>1?void 0:n?zt(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&jt(t,e,i),i},w=(r,t)=>(e,n)=>t(e,n,r);let G=class extends a.Disposable{constructor(t,e,n,i,o){super();I(this,"_initialEditors",new Set);this._currentUniverService=t,this._docSkeletonManagerService=e,this._editorService=n,this._commandService=i,this._textSelectionRenderManager=o,this._initialize()}_initialize(){this._editorService.resize$.subscribe(t=>{this._resize(t)}),this._editorService.getAllEditor().forEach(t=>{const e=t.editorUnitId;this._initialEditors.has(e)||(this._initialEditors.add(e),this._resize(e))}),this._commandExecutedListener(),this._initialSetValue(),this._initialBlur(),this._initialFocus()}_resize(t){var $,j,z;if(t==null)return;const e=this._editorService.getEditor(t);if((e==null?void 0:e.cancelDefaultResizeListener)===!0)return;const n=($=this._docSkeletonManagerService.getSkeletonByUnitId(t))==null?void 0:$.skeleton,i=this._currentUniverService.getUniverDocInstance(t);if(e==null||e.render==null||n==null||i==null)return;const{marginTop:o=0,marginBottom:s=0,marginLeft:c=0,marginRight:d=0}=i.getSnapshot().documentStyle,{scene:p,mainComponent:_}=e.render;let{actualHeight:f,actualWidth:C}=n.getActualSize();f+=o+s,C+=c+d;const{width:b,height:S}=e.getBoundingClientRect(),h=p.getViewport(u.VIEWPORT_KEY.VIEW_MAIN);let m=h==null?void 0:h.getScrollBar();const T=Math.max(C,b),R=Math.max(f,S);p.transformByState({width:T,height:R}),_==null||_.resize(T,R),e.isSingle===!1?f>S?m==null?h&&new O.ScrollBar(h,{enableHorizontal:!1,barSize:8}):h==null||h.resetSizeAndScrollBar():(m=null,h==null||h.scrollTo({x:0,y:0}),(j=h==null?void 0:h.getScrollBar())==null||j.dispose()):C>b?m==null?h&&new O.ScrollBar(h,{barSize:8,enableVertical:!1}):h==null||h.resetSizeAndScrollBar():(m=null,h==null||h.scrollTo({x:0,y:0}),(z=h==null?void 0:h.getScrollBar())==null||z.dispose())}_initialSetValue(){this._editorService.setValue$.subscribe(t=>{this._commandService.executeCommand(u.CoverContentCommand.id,{unitId:t.editorUnitId,body:t.body,segmentId:null})})}_initialBlur(){this._editorService.blur$.subscribe(()=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.blur()})}_initialFocus(){this._editorService.focus$.subscribe(t=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges([t])})}_commandExecutedListener(){const t=[u.RichTextEditingMutation.id,l.SetEditorResizeOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(t.includes(e.id)){const n=e.params,{unitId:i}=n;if(this._editorService.isSheetEditor(i))return;this._resize(i)}}))}};G=Wt([a.OnLifecycle(a.LifecycleStages.Rendered,G),w(0,a.IUniverInstanceService),w(1,v.Inject(u.DocSkeletonManagerService)),w(2,l.IEditorService),w(3,a.ICommandService),w(4,O.ITextSelectionRenderManager)],G);var Vt=Object.defineProperty,Ht=Object.getOwnPropertyDescriptor,kt=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ht(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&Vt(t,e,i),i},q=(r,t)=>(e,n)=>t(e,n,r);let X=class extends a.RxDisposable{constructor(t,e,n,i){super();I(this,"_docRenderMap",new Set);this._docSkeletonManagerService=t,this._renderManagerService=e,this._commandService=n,this._editorService=i,this._initialRenderRefresh(),this._commandExecutedListener()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(y.takeUntil(this.dispose$)).subscribe(t=>{this._create(t)})}_create(t){if(t==null)return;const{skeleton:e,unitId:n}=t;let i=this._renderManagerService.getRenderById(n);i==null&&(this._renderManagerService.create(n),i=this._renderManagerService.getRenderById(n));const{mainComponent:o}=i;o.changeSkeleton(e),this._recalculateSizeBySkeleton(i,e)}_recalculateSizeBySkeleton(t,e){var _;const{mainComponent:n,scene:i,unitId:o}=t,s=n,c=(_=e.getSkeletonData())==null?void 0:_.pages;if(c==null)return;let d=0,p=0;for(let f=0,C=c.length;f<C;f++){const b=c[f],{pageWidth:S,pageHeight:h}=b;s.pageLayoutType===O.PageLayoutType.VERTICAL?(p+=h,p+=s.pageMarginTop,f===C-1&&(p+=s.pageMarginTop),d=Math.max(d,S)):s.pageLayoutType===O.PageLayoutType.HORIZONTAL&&(d+=S,f!==C-1&&(d+=s.pageMarginLeft),p=Math.max(p,h))}s.resize(d,p),this._editorService.isEditor(o)||i.resize(d,p)}_commandExecutedListener(){const t=[u.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n;if(t.includes(e.id)){const i=e.params,{unitId:o}=i,s=this._docSkeletonManagerService.getSkeletonByUnitId(o);if(s==null)return;const{skeleton:c}=s,d=this._renderManagerService.getRenderById(o);if(d==null)return;if(c.calculate(),this._editorService.isEditor(o)){(n=d.mainComponent)==null||n.makeDirty();return}this._recalculateSizeBySkeleton(d,c)}}))}};X=kt([a.OnLifecycle(a.LifecycleStages.Rendered,X),q(0,v.Inject(u.DocSkeletonManagerService)),q(1,O.IRenderManagerService),q(2,a.ICommandService),q(3,l.IEditorService)],X);var Kt=Object.defineProperty,Yt=Object.getOwnPropertyDescriptor,Gt=(r,t,e,n)=>{for(var i=n>1?void 0:n?Yt(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&Kt(t,e,i),i},oe=(r,t)=>(e,n)=>t(e,n,r);g.DocCanvasView=class extends a.RxDisposable{constructor(e,n,i){super();I(this,"_scene");I(this,"_currentDocumentModel");I(this,"_fps$",new y.BehaviorSubject(""));I(this,"fps$",this._fps$.asObservable());this._renderManagerService=e,this._configService=n,this._currentUniverService=i,this._initialize()}_initialize(){this._renderManagerService.createRender$.pipe(y.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)}),this._currentUniverService.currentDoc$.pipe(y.takeUntil(this.dispose$)).subscribe(e=>{this._create(e==null?void 0:e.getUnitId())}),this._currentUniverService.getAllUniverDocsInstance().forEach(e=>{this._create(e.getUnitId())})}dispose(){this._fps$.complete()}_create(e){if(e==null)return;const n=this._currentUniverService.getUniverDocInstance(e);n!=null&&(this._currentDocumentModel=n,this._renderManagerService.has(e)||this._addNewRender())}_addNewRender(){const e=this._currentDocumentModel,n=e.getUnitId(),i=e.getContainer(),o=e.getParentRenderUnitId();if(i!=null&&o!=null)throw new Error("container or parentRenderUnitId can only exist one");i==null&&o!=null?this._renderManagerService.createRenderWithParent(n,o):this._renderManagerService.createRender(n);const s=this._renderManagerService.getRenderById(n);if(s==null)return;const{scene:c,engine:d}=s;c.openTransformer(),this._scene=c;const p=new O.Viewport(u.VIEWPORT_KEY.VIEW_MAIN,c,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});c.attachControl(),c.on(O.EVENT_TYPE.wheel,(C,b)=>{const S=C;if(S.ctrlKey){const h=Math.abs(S.deltaX);let m=h<40?.2:h<80?.4:.2;m*=S.deltaY>0?-1:1,c.scaleX<1&&(m/=2),c.scaleX+m>4?c.scale(4,4):c.scaleX+m<.1?c.scale(.1,.1):S.preventDefault()}else p.onMouseWheel(S,b)}),this._configService.getConfig("hasScroll")!==!1&&new O.ScrollBar(p),c.addLayer(new O.Layer(c,[],u.DOCS_COMPONENT_MAIN_LAYER_INDEX),new O.Layer(c,[],u.DOCS_COMPONENT_HEADER_LAYER_INDEX)),this._addComponent(s),this._currentDocumentModel.getShouldRenderLoopImmediately()&&d.runRenderLoop(()=>{c.render(),this._fps$.next(Math.round(d.getFps()).toString())}),this._renderManagerService.setCurrent(n)}_addComponent(e){const n=this._scene,i=this._currentDocumentModel,o=new O.Documents(u.DOCS_VIEW_KEY.MAIN,void 0,{pageMarginLeft:i.documentStyle.marginLeft||0,pageMarginTop:i.documentStyle.marginTop||0});o.zIndex=u.DOCS_COMPONENT_DEFAULT_Z_INDEX,e.mainComponent=o,e.components.set(u.DOCS_VIEW_KEY.MAIN,o),n.addObjects([o],u.DOCS_COMPONENT_MAIN_LAYER_INDEX)}},g.DocCanvasView=Gt([a.OnLifecycle(a.LifecycleStages.Starting,g.DocCanvasView),oe(0,O.IRenderManagerService),oe(1,a.IConfigService),oe(2,a.IUniverInstanceService)],g.DocCanvasView);var qt=Object.defineProperty,Xt=Object.getOwnPropertyDescriptor,Zt=(r,t,e,n)=>{for(var i=n>1?void 0:n?Xt(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&qt(t,e,i),i},U=(r,t)=>(e,n)=>t(e,n,r);let Z=class extends a.Disposable{constructor(t,e,n,i,o,s){super();I(this,"_liquid",new O.Liquid);I(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,this._commandService=i,this._floatingObjectManagerService=o,this._editorService=s,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh(),this._updateOnPluginChange()}_updateOnPluginChange(){this._floatingObjectManagerService.pluginUpdate$.subscribe(t=>{const e=this._docSkeletonManagerService.getCurrent();if(e==null)return;const{unitId:n,skeleton:i}=e,o=this._renderManagerService.getRenderById(n);if(o==null)return;const{mainComponent:s,components:c,scene:d}=o,p=s,{left:_,top:f}=p;t.forEach(C=>{const{unitId:b,subUnitId:S,floatingObjectId:h,floatingObject:m}=C,{left:T=0,top:R=0,width:$=0,height:j=0,angle:z,flipX:Te,flipY:ye,skewX:Me,skewY:Re}=m,D=this._pageMarginCache.get(h),dn=(D==null?void 0:D.marginLeft)||0,un=(D==null?void 0:D.marginTop)||0;i==null||i.getViewModel().getDataModel().updateDrawing(h,{left:T-_-dn,top:R-f-un,height:j,width:$})}),i==null||i.calculate(),s==null||s.makeDirty()})}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(t==null)return;const{skeleton:e,unitId:n}=t,i=this._renderManagerService.getRenderById(n);if(i==null)return;const{mainComponent:o}=i;o.changeSkeleton(e),this._refreshFloatingObject(n,e,i)})}_commandExecutedListener(){const t=[u.RichTextEditingMutation.id,u.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n;if(t.includes(e.id)){const i=e.params,{unitId:o}=i,s=this._docSkeletonManagerService.getCurrent();if(s==null)return;const{unitId:c,skeleton:d}=s;if(o!==c)return;const p=this._renderManagerService.getRenderById(c);if(p==null)return;if(this._editorService.isEditor(c)){(n=p.mainComponent)==null||n.makeDirty();return}this._refreshFloatingObject(c,d,p)}}))}_refreshFloatingObject(t,e,n){const i=e==null?void 0:e.getSkeletonData(),{mainComponent:o,scene:s}=n,c=o;if(!i)return;const{left:d,top:p,pageLayoutType:_,pageMarginLeft:f,pageMarginTop:C}=c,{pages:b}=i,S=[];s.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let h=0,m=b.length;h<m;h++){const T=b[h],{skeDrawings:R,marginLeft:$,marginTop:j}=T;this._liquid.translatePagePadding(T),R.forEach(z=>{const{aLeft:Te,aTop:ye,height:Me,width:Re,objectId:D}=z;S.push({unitId:t,subUnitId:a.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:D,floatingObject:{left:Te+d+this._liquid.x,top:ye+p+this._liquid.y,width:Re,height:Me}}),this._pageMarginCache.set(D,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.translatePage(T,_,f,C)}this._floatingObjectManagerService.BatchAddOrUpdate(S)}};Z=Zt([a.OnLifecycle(a.LifecycleStages.Steady,Z),U(0,v.Inject(u.DocSkeletonManagerService)),U(1,a.IUniverInstanceService),U(2,O.IRenderManagerService),U(3,a.ICommandService),U(4,a.IFloatingObjectManagerService),U(5,l.IEditorService)],Z);var Jt=Object.defineProperty,Qt=Object.getOwnPropertyDescriptor,en=(r,t,e,n)=>{for(var i=n>1?void 0:n?Qt(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&Jt(t,e,i),i},se=(r,t)=>(e,n)=>t(e,n,r);const tn="rgba(198, 198, 198, 1)",nn="rgba(255, 255, 255, 1)";let J=class extends a.Disposable{constructor(r,t,e){super(),this._renderManagerService=r,this._editorService=t,this._currentUniverService=e,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this._renderManagerService.currentRender$.subscribe(r=>{var o;if(r==null)return;const t=this._renderManagerService.getRenderById(r);if(this._editorService.isEditor(r)||this._currentUniverService.getUniverDocInstance(r)==null||t==null)return;const{mainComponent:e}=t,n=e,i=(o=n.getSkeleton())==null?void 0:o.getPageSize();this.disposeWithMe(a.toDisposable(n.onPageRenderObservable.add(s=>{var h,m,T,R;if(this._editorService.isEditor(r))return;const{page:c,pageLeft:d,pageTop:p,ctx:_}=s,{width:f,pageWidth:C,height:b,pageHeight:S}=c;_.save(),_.translate(d-.5,p-.5),O.Rect.drawWith(_,{width:(m=(h=i==null?void 0:i.width)!=null?h:C)!=null?m:f,height:(R=(T=i==null?void 0:i.height)!=null?T:S)!=null?R:b,strokeWidth:1,stroke:tn,fill:nn,zIndex:3}),_.restore()})))})}_commandExecutedListener(){}};J=en([a.OnLifecycle(a.LifecycleStages.Rendered,J),se(0,O.IRenderManagerService),se(1,l.IEditorService),se(2,a.IUniverInstanceService)],J);var rn=Object.defineProperty,on=Object.getOwnPropertyDescriptor,sn=(r,t,e,n)=>{for(var i=n>1?void 0:n?on(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&rn(t,e,i),i},x=(r,t)=>(e,n)=>t(e,n,r);let Q=class extends a.Disposable{constructor(t,e,n,i,o,s){super();I(this,"_initializedRender",new Set);this._docSkeletonManagerService=t,this._currentUniverService=e,this._commandService=n,this._renderManagerService=i,this._textSelectionManagerService=o,this._editorService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._initialRenderRefresh()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(t==null)return;const{unitId:e}=t,n=this._renderManagerService.getRenderById(e);if(n==null||this._initializedRender.has(e)||this._editorService.isEditor(e))return;this._initializedRender.add(e);const{scene:i}=n;this.disposeWithMe(a.toDisposable(i.onMouseWheelObserver.add(o=>{if(!o.ctrlKey)return;const s=Math.abs(o.deltaX);let c=s<40?.2:s<80?.4:.2;c*=o.deltaY>0?-1:1,i.scaleX<1&&(c/=2);const d=this._currentUniverService.getCurrentUniverDocInstance(),p=d.zoomRatio;let _=+Number.parseFloat(`${p+c}`).toFixed(1);_=_>=4?4:_<=.1?.1:_,this._commandService.executeCommand(u.SetDocZoomRatioCommand.id,{zoomRatio:_,unitId:d.getUnitId()}),o.preventDefault()})))})}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(t==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance().zoomRatio||1;this._updateViewZoom(n,!1)})))}_commandExecutedListener(){const t=[u.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(t.includes(e.id)){const n=this._currentUniverService.getCurrentUniverDocInstance(),i=e.params,{unitId:o}=i;if(o!==n.getUnitId())return;const s=n.zoomRatio||1;this._updateViewZoom(s)}}))}_updateViewZoom(t,e=!0){var i;const n=this._getDocObject();n!=null&&(n.scene.scale(t,t),this._calculatePagePosition(n,t),e&&this._textSelectionManagerService.refreshSelection(),(i=n.scene.getTransformer())==null||i.hideControl())}_calculatePagePosition(t,e){const{document:n,scene:i}=t,o=i==null?void 0:i.getParent(),{width:s,height:c,pageMarginLeft:d,pageMarginTop:p}=n;if(o==null||s===Number.POSITIVE_INFINITY||c===Number.POSITIVE_INFINITY)return;const{width:_,height:f}=o;let C=0,b=0,S=0,h=0,m=Number.POSITIVE_INFINITY;_>(s+d*2)*e?(C=_/2-s*e/2,C/=e,S=(_-d*2)/e,m=0):(C=d,S=s+d*2,m=(S-_/e)/2),f>c?(b=f/2-c/2,h=(f-p*2)/e):(b=p,h=c+p*2),i.resize(S,h+200),n.translate(C,b);const T=i.getViewport(u.VIEWPORT_KEY.VIEW_MAIN);if(m!==Number.POSITIVE_INFINITY&&T!=null){const R=T.getBarScroll(m,0).x;T.scrollTo({x:R})}return this}_getDocObject(){return u.getDocObject(this._currentUniverService,this._renderManagerService)}};Q=sn([a.OnLifecycle(a.LifecycleStages.Rendered,Q),x(0,v.Inject(u.DocSkeletonManagerService)),x(1,a.IUniverInstanceService),x(2,a.ICommandService),x(3,O.IRenderManagerService),x(4,v.Inject(u.TextSelectionManagerService)),x(5,l.IEditorService)],Q);var an=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,ln=(r,t,e,n)=>{for(var i=n>1?void 0:n?cn(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&an(t,e,i),i},ae=(r,t)=>(e,n)=>t(e,n,r);g.UniverDocsUIPlugin=(ce=class extends a.Plugin{constructor(t,e,n,i){super(he),this._config=t,this._injector=e,this._localeService=n,this._logService=i,this._localeService.load({zhCN:Ce}),this._config=a.Tools.deepMerge({},ue,this._config),this._initDependencies(e),this._initializeCommands()}onRendered(){this._initModules(),this._markDocAsFocused()}onDestroy(){}_initializeCommands(){[Ue,xe,Ne,Le,Ae,Be,Fe,we,$e,ft,St,gt].forEach(t=>{this._injector.get(l.IShortcutService).registerShortcut(t)})}_initDependencies(t){[[k],[Y],[G],[X],[Z],[J],[Q],[L,{useFactory:()=>this._injector.createInstance(L,this._config)}],[B,{useClass:ie}],[g.DocCanvasView]].forEach(n=>{t.add(n)})}_markDocAsFocused(){const t=this._injector.get(a.IUniverInstanceService),e=this._injector.get(l.IEditorService);try{const n=t.getCurrentUniverDocInstance(),i=n.getUnitId();e.isEditor(i)||t.focusUniverInstance(n.getUnitId())}catch(n){this._logService.warn(n)}}_initModules(){this._injector.get(L)}},I(ce,"type",a.PluginType.Doc),ce),g.UniverDocsUIPlugin=ln([ae(1,v.Inject(v.Injector)),ae(2,v.Inject(a.LocaleService)),ae(3,a.ILogService)],g.UniverDocsUIPlugin),g.DOC_UI_PLUGIN_NAME=he,g.DefaultDocContainerConfig=de,g.DefaultDocUiConfig=ue,g.DefaultToolbarConfig=le,g.enUS=mt,g.zhCN=Ce,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
9
+ */var tt=Fe,nt=Symbol.for("react.element"),it=Symbol.for("react.fragment"),rt=Object.prototype.hasOwnProperty,ot=tt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,st={key:!0,ref:!0,__self:!0,__source:!0};function De(r,e,t){var n,i={},o=null,s=null;t!==void 0&&(o=""+t),e.key!==void 0&&(o=""+e.key),e.ref!==void 0&&(s=e.ref);for(n in e)rt.call(e,n)&&!st.hasOwnProperty(n)&&(i[n]=e[n]);if(r&&r.defaultProps)for(n in e=r.defaultProps,e)i[n]===void 0&&(i[n]=e[n]);return{$$typeof:nt,type:r,key:o,ref:s,props:i,_owner:ot.current}}K.Fragment=it,K.jsx=De,K.jsxs=De,ye.exports=K;var at=ye.exports;const ct={docsUiCanvasBackground:"univer-docs-ui-canvas-background"},lt=()=>at.jsx("div",{className:ct.docsUiCanvasBackground});function dt(r){const e=r.get(a.ICommandService);return{id:d.SetInlineFormatBoldCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",positions:[l.MenuPosition.TOOLBAR_START],activated$:new M.Observable(t=>{const n=e.onCommandExecuted(i=>{var s;const o=i.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(r);if(c==null)return;const u=(s=c.ts)==null?void 0:s.bl;t.next(u===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function ut(r){const e=r.get(a.ICommandService);return{id:d.SetInlineFormatItalicCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",positions:[l.MenuPosition.TOOLBAR_START],activated$:new M.Observable(t=>{const n=e.onCommandExecuted(i=>{var s;const o=i.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(r);if(c==null)return;const u=(s=c.ts)==null?void 0:s.it;t.next(u===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function ht(r){const e=r.get(a.ICommandService);return{id:d.SetInlineFormatUnderlineCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",positions:[l.MenuPosition.TOOLBAR_START],activated$:new M.Observable(t=>{const n=e.onCommandExecuted(i=>{var s;const o=i.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(r);if(c==null)return;const u=(s=c.ts)==null?void 0:s.ul;t.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function _t(r){const e=r.get(a.ICommandService);return{id:d.SetInlineFormatStrikethroughCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",positions:[l.MenuPosition.TOOLBAR_START],activated$:new M.Observable(t=>{const n=e.onCommandExecuted(i=>{var s;const o=i.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(r);if(c==null)return;const u=(s=c.ts)==null?void 0:s.st;t.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function pt(r){const e=r.get(a.ICommandService);return{id:d.SetInlineFormatSubscriptCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",positions:[l.MenuPosition.TOOLBAR_START],activated$:new M.Observable(t=>{const n=e.onCommandExecuted(i=>{var s;const o=i.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(r);if(c==null)return;const u=(s=c.ts)==null?void 0:s.va;t.next(u===a.BaselineOffset.SUBSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function gt(r){const e=r.get(a.ICommandService);return{id:d.SetInlineFormatSuperscriptCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",positions:[l.MenuPosition.TOOLBAR_START],activated$:new M.Observable(t=>{const n=e.onCommandExecuted(i=>{var s;const o=i.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(r);if(c==null)return;const u=(s=c.ts)==null?void 0:s.va;t.next(u===a.BaselineOffset.SUPERSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function St(r){const e=r.get(a.ICommandService);return{id:d.SetInlineFormatFontFamilyCommand.id,tooltip:"toolbar.font",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,label:Me,positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_FAMILY_LIST.map(t=>({label:{name:Te,hoverable:!0},value:t.value})),value$:new M.Observable(t=>{const n=l.FONT_FAMILY_LIST[0].value,i=e.onCommandExecuted(o=>{var c;const s=o.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontFamilyCommand.id){const u=E(r);if(u==null)return;const _=(c=u.ts)==null?void 0:c.ff;t.next(_!=null?_:n)}});return t.next(n),i.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function ft(r){const e=r.get(a.ICommandService);return{id:d.SetInlineFormatFontSizeCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Re,props:{min:1,max:400}},positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_SIZE_LIST,value$:new M.Observable(t=>{const i=e.onCommandExecuted(o=>{var c;const s=o.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontSizeCommand.id){const u=E(r);if(u==null)return;const _=(c=u.ts)==null?void 0:c.fs;t.next(_!=null?_:14)}});return t.next(14),i.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function vt(r){const e=r.get(a.ICommandService),t=r.get(a.ThemeService);return{id:d.SetInlineFormatTextColorCommand.id,icon:"FontColor",tooltip:"toolbar.textColor.main",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON_SELECTOR,positions:[l.MenuPosition.TOOLBAR_START],selections:[{label:{name:be,hoverable:!1}}],value$:new M.Observable(n=>{const i=t.getCurrentTheme().textColor,o=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextColorCommand.id){const c=s.params.value;n.next(c!=null?c:i)}});return n.next(i),o.dispose}),hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function mt(r){return{id:d.OrderListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"OrderSingle",tooltip:"toolbar.order",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function Ct(r){return{id:d.BulletListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"UnorderSingle",tooltip:"toolbar.unorder",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.DOC)}}function E(r){var u;const e=r.get(a.IUniverInstanceService),t=r.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),i=t.getActiveRange();if(n==null||i==null)return;const o=(u=n.getBody())==null?void 0:u.textRuns;if(o==null)return;const{startOffset:s}=i;return o.find(({st:_,ed:p})=>s>=_&&s<p)}var It=Object.defineProperty,Ot=Object.getOwnPropertyDescriptor,bt=(r,e,t,n)=>{for(var i=n>1?void 0:n?Ot(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&It(e,t,i),i},L=(r,e)=>(t,n)=>e(t,n,r);let q=class extends a.Disposable{constructor(r,e,t,n,i,o,s){super(),this._injector=r,this._componentManager=e,this._layoutService=t,this._editorService=n,this._menuService=i,this._uiController=o,this._currentUniverService=s,this._init()}_initCustomComponents(){const r=this._componentManager;this.disposeWithMe(r.register(be,$e.ColorPicker)),this.disposeWithMe(r.register(Me,l.FontFamily)),this.disposeWithMe(r.register(Te,l.FontFamilyItem)),this.disposeWithMe(r.register(Re,l.FontSize))}_initMenus(){[dt,ut,ht,_t,pt,gt,ft,St,vt,mt,Ct].forEach(r=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(r)))})}_init(){this._initCustomComponents(),this._initMenus(),this._initDocBackground(),this._initFocusHandler()}_initDocBackground(){const r=this._currentUniverService.getAllUniverDocsInstance()[0].getUnitId();if(r==null)return;this._editorService.isEditor(r)||this.disposeWithMe(this._uiController.registerContentComponent(()=>we.connectInjector(lt,this._injector)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.DOC,()=>{this._injector.get(v.ITextSelectionRenderManager).focus()}))}};q=bt([a.OnLifecycle(a.LifecycleStages.Rendered,q),L(0,C.Inject(C.Injector)),L(1,C.Inject(l.ComponentManager)),L(2,l.ILayoutService),L(3,l.IEditorService),L(4,l.IMenuService),L(5,l.IUIController),L(6,a.IUniverInstanceService)],q);const Mt={toolbar:{undo:"Undo",redo:"Redo",font:"Font",fontSize:"Font size",bold:"Bold",italic:"Italic",strikethrough:"Strikethrough",subscript:"Subscript",superscript:"Superscript",underline:"Underline",textColor:{main:"Text color",right:"Choose color"},resetColor:"Reset",order:"Ordered list",unorder:"Unordered list"}},Ee={toolbar:{undo:"撤销",redo:"重做",font:"字体",fontSize:"字号",bold:"粗体",italic:"斜体",strikethrough:"删除线",subscript:"下标",superscript:"上标",underline:"下划线",textColor:{main:"文本颜色",right:"颜色选择"},resetColor:"重置颜色",order:"有序列表",unorder:"无序列表"}},Tt={id:d.BreakLineCommand.id,preconditions:Ae,binding:l.KeyCode.ENTER},Rt={id:d.DeleteLeftCommand.id,preconditions:D,binding:l.KeyCode.BACKSPACE},yt={id:d.DeleteRightCommand.id,preconditions:D,binding:l.KeyCode.DELETE},Dt=10,Et=6;function Pt(){return a.Tools.generateRandomId(Et)}function Ut(r){const e=r.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class xt{constructor(){b(this,"_cache",new a.LRUMap(Dt))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}clear(){this._cache.clear()}}const Pe=new xt;function de(r){const e=r.style,t={},n=r.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{t.bl=a.BooleanNumber.TRUE;break}case"s":{t.st={s:a.BooleanNumber.TRUE};break}case"u":{t.ul={s:a.BooleanNumber.TRUE};break}case"i":{t.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=n==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}for(let i=0;i<e.length;i++){const o=e[i],s=e.getPropertyValue(o);switch(o){case"font-family":{t.ff=s;break}case"font-size":{const c=Number.parseInt(s);Number.isNaN(c)||(s.endsWith("pt")?t.fs=c:s.endsWith("px")&&(t.fs=v.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 Lt(r){const e=new DOMParser,t=`<x-univer id="univer-root">${r}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function Ue(r,e){const t=r.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(r)}const se=class se{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=se._pluginList.find(o=>o.checkPasteType(e)),n=Lt(e),i={dataStream:"",textRuns:[]};return t&&(this._styleRules=[...t.stylesRules],this._afterProcessRules=[...t.afterProcessRules]),this._styleCache.clear(),this._process(null,n==null?void 0:n.childNodes,i),this._styleCache.clear(),this._styleRules=[],this._afterProcessRules=[],i}_process(e,t,n){var i;for(const o of t)if(o.nodeType===Node.TEXT_NODE){const s=(i=o.nodeValue)==null?void 0:i.replace(/[\r\n]/g,"");let c;e&&this._styleCache.has(e)&&(c=this._styleCache.get(e)),n.dataStream+=s,c&&Object.getOwnPropertyNames(c).length&&n.textRuns.push({st:n.dataStream.length-s.length,ed:n.dataStream.length,ts:c})}else if(o.nodeType===Node.ELEMENT_NODE){const s=e?this._styleCache.get(e):{},c=this._styleRules.find(({filter:g})=>Ue(o,g)),u=c?c.getStyle(o):de(o);this._styleCache.set(o,{...s,...u});const{childNodes:_}=o;this._process(o,_,n);const p=this._afterProcessRules.find(({filter:g})=>Ue(o,g));p&&p.handler(n,o)}}};b(se,"_pluginList",[]);let B=se;const Nt={name:"univer-doc-paste-plugin-lark",checkPasteType(r){return/lark-record-clipboard/i.test(r)},stylesRules:[{filter:["s"],getStyle(r){const e=de(r);return{st:{s:a.BooleanNumber.TRUE},...e}}}],afterProcessRules:[{filter(r){return r.tagName==="DIV"&&/ace-line/i.test(r.className)},handler(r){r.paragraphs==null&&(r.paragraphs=[]),r.paragraphs.push({startIndex:r.dataStream.length}),r.dataStream+="\r"}}]};function xe(r){const e=r.style,t={};for(let n=0;n<e.length;n++){const i=e[n],o=e.getPropertyValue(i);switch(i){case"margin-top":{const s=Number.parseInt(o);t.spaceAbove=/pt/.test(o)?v.ptToPixel(s):s;break}case"margin-bottom":{const s=Number.parseInt(o);t.spaceBelow=/pt/.test(o)?v.ptToPixel(s):s;break}case"line-height":{const s=Number.parseFloat(o);t.lineSpacing=s;break}}}return Object.getOwnPropertyNames(t).length?t:null}const Bt={name:"univer-doc-paste-plugin-word",checkPasteType(r){return/word|mso/i.test(r)},stylesRules:[{filter:["b"],getStyle(r){const e=de(r);return{bl:a.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(r){return r.tagName==="P"&&/mso/i.test(r.className)},handler(r,e){r.paragraphs==null&&(r.paragraphs=[]);const t={startIndex:r.dataStream.length},n=xe(e);n&&(t.paragraphStyle=n),r.paragraphs.push(t),r.dataStream+="\r"}}]},wt={name:"univer-doc-paste-plugin-univer",checkPasteType(r){return/UniverNormal/i.test(r)},stylesRules:[],afterProcessRules:[{filter(r){return r.tagName==="P"&&/UniverNormal/i.test(r.className)},handler(r,e){r.paragraphs==null&&(r.paragraphs=[]);const t={startIndex:r.dataStream.length},n=xe(e);n&&(t.paragraphStyle=n),r.paragraphs.push(t),r.dataStream+="\r"}}]};function Le(r,e){const{st:t,ed:n,ts:i={}}=e,{ff:o,fs:s,it:c,bl:u,ul:_,st:p,ol:g,bg:O,cl:m,va:I}=i;let h=r.slice(t,n);const f=[];return c===a.BooleanNumber.TRUE&&(h=`<i>${h}</i>`),I===a.BaselineOffset.SUPERSCRIPT?h=`<sup>${h}</sup>`:I===a.BaselineOffset.SUBSCRIPT&&(h=`<sub>${h}</sub>`),(_==null?void 0:_.s)===a.BooleanNumber.TRUE&&(h=`<u>${h}</u>`),(p==null?void 0:p.s)===a.BooleanNumber.TRUE&&(h=`<s>${h}</s>`),u===a.BooleanNumber.TRUE&&(h=`<strong>${h}</strong>`),o&&f.push(`font-family: ${o}`),m&&f.push(`color: ${m.rgb}`),s&&f.push(`font-size: ${s}pt`),g&&f.push("text-decoration: overline"),O&&f.push(`background: ${O.rgb}`),f.length?`<span style="${f.join("; ")};">${h}</span>`:h}function ue(r,e,t){const{dataStream:n,textRuns:i=[]}=r;let o=e;const s=[];for(const c of i){const{st:u,ed:_}=c;a.Tools.hasIntersectionBetweenTwoRanges(e,t,u,_)&&(u>o?(s.push(n.slice(o,u)),s.push(Le(n,{...c,ed:Math.min(_,t)}))):s.push(Le(n,{...c,st:o,ed:Math.min(_,t)}))),o=Math.max(e,Math.min(_,t))}return o!==t&&s.push(n.slice(o,t)),s.join("")}function Ne(r,e=!0){var t;if(e&&((t=r.paragraphs)!=null&&t.length)){const{dataStream:n,paragraphs:i=[]}=r;let o="",s=-1;for(const c of i){const{startIndex:u,paragraphStyle:_={}}=c,{spaceAbove:p,spaceBelow:g,lineSpacing:O}=_,m=[];p!=null&&(typeof p=="number"?m.push(`margin-top: ${p}px`):m.push(`margin-top: ${p.v}px`)),g!=null&&(typeof g=="number"?m.push(`margin-bottom: ${g}px`):m.push(`margin-bottom: ${g.v}px`)),O!=null&&m.push(`line-height: ${O}`),u>s+1?o+=`<p class="UniverNormal" ${m.length?`style="${m.join("; ")};"`:""}>${ue(r,s+1,u)}</p>`:o+=`<p class="UniverNormal" ${m.length?`style="${m.join("; ")};"`:""}></p>`,s=u}return s!==n.length&&(o+=ue(r,s,n.length)),o}else return ue(r,0,r.dataStream.length)}class $t{convert(e){if(e.length===0)throw new Error("The bodyList length at least to be 1");if(e.length===1)return Ne(e[0]);let t="";for(const n of e)t+='<p className="UniverNormal">',t+=Ne(n,!1),t+="</p>";return t}}var Ft=Object.defineProperty,At=Object.getOwnPropertyDescriptor,jt=(r,e,t,n)=>{for(var i=n>1?void 0:n?At(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&Ft(e,t,i),i},V=(r,e)=>(t,n)=>e(t,n,r);B.use(Bt),B.use(Nt),B.use(wt);function Wt(r){const e=r.replace(/\n/g,"\r"),t=[];for(let n=0;n<e.length;n++)e[n]==="\r"&&t.push({startIndex:n});return{dataStream:e,paragraphs:t}}const k=C.createIdentifier("doc.clipboard-service");let he=class extends a.Disposable{constructor(e,t,n,i,o){super();b(this,"_clipboardHooks",[]);b(this,"_htmlToUDM",new B);b(this,"_umdToHtml",new $t);this._currentUniverService=e,this._logService=t,this._commandService=n,this._clipboardInterfaceService=i,this._textSelectionManagerService=o}async copy(){const e=this._getDocumentBodyInRanges();if(e.length===0)return!1;try{this._setClipboardData(e)}catch(t){return this._logService.error("[DocClipboardService] copy failed",t),!1}return!0}async cut(){return this._cut()}async paste(e){const t=await this._generateBodyFromClipboardItems(e);return this._paste(t)}async legacyPaste(e,t){const n=this._generateBodyFromHtmlAndText(e,t);return this._paste(n)}async _cut(){var o;const{segmentId:e,endOffset:t,style:n}=(o=this._textSelectionManagerService.getActiveRange())!=null?o:{},i=this._textSelectionManagerService.getSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),t==null||i==null)return!1;this.copy();try{let s=t;for(const u of i){const{startOffset:_,endOffset:p}=u;_==null||p==null||p<=t&&(s-=p-_)}const c=[{startOffset:s,endOffset:s,style:n}];return this._commandService.executeCommand(d.CutContentCommand.id,{segmentId:e,textRanges:c})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(e){var s;const{segmentId:t,endOffset:n,style:i}=(s=this._textSelectionManagerService.getActiveRange())!=null?s:{},o=this._textSelectionManagerService.getSelections();if(t==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),n==null||o==null)return!1;try{let c=n;for(const _ of o){const{startOffset:p,endOffset:g}=_;p==null||g==null||g<=n&&(c+=e.dataStream.length-(g-p))}const u=[{startOffset:c,endOffset:c,style:i}];return this._commandService.executeCommand(d.InnerPasteCommand.id,{body:e,segmentId:t,textRanges:u})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(e){const t=Pt(),n=e.length>1?e.map(o=>o.dataStream).join(`
10
+ `):e[0].dataStream;let i=this._umdToHtml.convert(e);return e.length===1&&(i=i.replace(/(<[a-z]+)/,(o,s)=>`${s} data-copy-id="${t}"`),Pe.set(t,e[0])),this._clipboardInterfaceService.write(n,i)}addClipboardHook(e){return this._clipboardHooks.push(e),a.toDisposable(()=>{const t=this._clipboardHooks.indexOf(e);t>-1&&this._clipboardHooks.splice(t,1)})}_getDocumentBodyInRanges(){const e=this._textSelectionManagerService.getSelections(),t=this._currentUniverService.getCurrentUniverDocInstance(),n=[];if(e==null)return n;for(const i of e){const{startOffset:o,endOffset:s,collapsed:c}=i;if(c||o==null||s==null)continue;const u=t.sliceBody(o,s);u!=null&&n.push(u)}return n}async _generateBodyFromClipboardItems(e){try{let t="",n="";for(const i of e)for(const o of i.types)o===l.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await i.getType(o).then(s=>s&&s.text()):o===l.HTML_CLIPBOARD_MIME_TYPE&&(t=await i.getType(o).then(s=>s&&s.text()));return this._generateBodyFromHtmlAndText(t,n)}catch(t){return Promise.reject(t)}}_generateBodyFromHtmlAndText(e,t){if(!e){if(t)return Wt(t);throw new Error("[DocClipboardService] html and text cannot be both empty!")}const n=Ut(e);if(n){const i=Pe.get(n);if(i)return i}return this._htmlToUDM.convert(e)}};he=jt([V(0,a.IUniverInstanceService),V(1,a.ILogService),V(2,a.ICommandService),V(3,l.IClipboardInterfaceService),V(4,C.Inject(d.TextSelectionManagerService))],he);function X(r){return r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.EDITOR_ACTIVATED)}const _e=999,Vt={id:l.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:_e,preconditions:X,handler:async r=>r.get(k).copy()},kt={id:l.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:_e,preconditions:X,handler:async r=>r.get(k).cut()},zt={id:l.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:_e,preconditions:X,handler:async r=>{const e=r.get(k),n=await r.get(l.IClipboardInterfaceService).read();return n.length===0?!1:e.paste(n)}};var Ht=Object.defineProperty,Yt=Object.getOwnPropertyDescriptor,Gt=(r,e,t,n)=>{for(var i=n>1?void 0:n?Yt(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&Ht(e,t,i),i},z=(r,e)=>(t,n)=>e(t,n,r);let Z=class extends a.RxDisposable{constructor(r,e,t,n,i){super(),this._commandService=r,this._clipboardInterfaceService=e,this._docClipboardService=t,this._textSelectionRenderManager=n,this._contextService=i,this._init()}_init(){[Vt,kt,zt].forEach(r=>this.disposeWithMe(this._commandService.registerMultipleCommand(r))),[d.InnerPasteCommand,d.CutContentCommand].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r))),this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var r;(r=this._textSelectionRenderManager)==null||r.onPaste$.pipe(M.takeUntil(this.dispose$)).subscribe(e=>{var o,s;if(!X(this._contextService))return;e.event.preventDefault();const t=e.event,n=(o=t.clipboardData)==null?void 0:o.getData("text/html"),i=(s=t.clipboardData)==null?void 0:s.getData("text/plain");this._docClipboardService.legacyPaste(n,i)})}};Z=Gt([a.OnLifecycle(a.LifecycleStages.Steady,Z),z(0,a.ICommandService),z(1,l.IClipboardInterfaceService),z(2,k),z(3,v.ITextSelectionRenderManager),z(4,a.IContextService)],Z);var Kt=Object.defineProperty,qt=Object.getOwnPropertyDescriptor,Xt=(r,e,t,n)=>{for(var i=n>1?void 0:n?qt(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&Kt(e,t,i),i},w=(r,e)=>(t,n)=>e(t,n,r);let J=class extends a.Disposable{constructor(e,t,n,i,o,s){super();b(this,"_initialEditors",new Set);this._currentUniverService=e,this._docSkeletonManagerService=t,this._editorService=n,this._commandService=i,this._textSelectionRenderManager=o,this._renderManagerService=s,this._initialize()}_initialize(){this.disposeWithMe(this._editorService.resize$.subscribe(e=>{this._resize(e)})),this._editorService.getAllEditor().forEach(e=>{const t=e.editorUnitId;this._initialEditors.has(t)||(this._initialEditors.add(t),this._resize(t))}),this._commandExecutedListener(),this._initialSetValue(),this._initialBlur(),this._initialFocus(),this._initialValueChange()}_resize(e){var P,U,x;if(e==null)return;const t=this._editorService.getEditor(e);if((t==null?void 0:t.cancelDefaultResizeListener)===!0)return;const n=(P=this._docSkeletonManagerService.getSkeletonByUnitId(e))==null?void 0:P.skeleton,i=this._currentUniverService.getUniverDocInstance(e);if(t==null||t.render==null||n==null||i==null)return;n.calculate();const{marginTop:o=0,marginBottom:s=0,marginLeft:c=0,marginRight:u=0}=i.getSnapshot().documentStyle,{scene:_,mainComponent:p}=t.render;let{actualHeight:g,actualWidth:O}=n.getActualSize();g+=o+s,O+=c+u;const{width:m,height:I}=t.getBoundingClientRect(),h=_.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);let f=h==null?void 0:h.getScrollBar();const T=Math.max(O,m),R=Math.max(g,I);_.transformByState({width:T,height:R}),p==null||p.resize(T,R),t.isSingle()?O>m?f==null?h&&new v.ScrollBar(h,{barSize:8,enableVertical:!1}):h==null||h.resetSizeAndScrollBar():(f=null,h==null||h.scrollTo({x:0,y:0}),(x=h==null?void 0:h.getScrollBar())==null||x.dispose()):g>I?f==null?h&&new v.ScrollBar(h,{enableHorizontal:!1,barSize:8}):h==null||h.resetSizeAndScrollBar():(f=null,h==null||h.scrollTo({x:0,y:0}),(U=h==null?void 0:h.getScrollBar())==null||U.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(()=>{const e=this._currentUniverService.getCurrentUniverDocInstance().getUnitId();if(e==null)return;const t=this._editorService.getEditor(e);t==null||t.isSheetEditor()||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(M.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._currentUniverService.getAllUniverSheetsInstance().forEach(n=>{const i=n.getUnitId(),o=this._renderManagerService.getRenderById(i),s=o==null?void 0:o.engine.getCanvas().getCanvasEle();s!=null&&M.fromEvent(s,"mousedown").subscribe(c=>{this._editorService.changeSpreadsheetFocusState(!0),c.stopPropagation()})})}_initialValueChange(){this.disposeWithMe(this._textSelectionRenderManager.onCompositionupdate$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onInput$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onKeydown$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onPaste$.subscribe(this._valueChange.bind(this)))}_valueChange(){const e=this._currentUniverService.getCurrentUniverDocInstance().getUnitId();if(e==null)return;const t=this._editorService.getEditor(e);t==null||t.isSheetEditor()||this._editorService.refreshValueChange(e)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,l.SetEditorResizeOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=t.params,{unitId:i}=n;if(this._editorService.isSheetEditor(i))return;this._resize(i),this._valueChange()}}))}};J=Xt([a.OnLifecycle(a.LifecycleStages.Rendered,J),w(0,a.IUniverInstanceService),w(1,C.Inject(d.DocSkeletonManagerService)),w(2,l.IEditorService),w(3,a.ICommandService),w(4,v.ITextSelectionRenderManager),w(5,v.IRenderManagerService)],J);var Zt=Object.defineProperty,Jt=Object.getOwnPropertyDescriptor,Qt=(r,e,t,n)=>{for(var i=n>1?void 0:n?Jt(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&Zt(e,t,i),i},Q=(r,e)=>(t,n)=>e(t,n,r);let ee=class extends a.RxDisposable{constructor(e,t,n,i){super();b(this,"_docRenderMap",new Set);this._docSkeletonManagerService=e,this._renderManagerService=t,this._commandService=n,this._editorService=i,this._initialRenderRefresh(),this._commandExecutedListener()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(M.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)})}_create(e){if(e==null)return;const{skeleton:t,unitId:n}=e;let i=this._renderManagerService.getRenderById(n);i==null&&(this._renderManagerService.create(n),i=this._renderManagerService.getRenderById(n));const{mainComponent:o}=i;o.changeSkeleton(t),this._recalculateSizeBySkeleton(i,t)}_recalculateSizeBySkeleton(e,t){var p;const{mainComponent:n,scene:i,unitId:o}=e,s=n,c=(p=t.getSkeletonData())==null?void 0:p.pages;if(c==null)return;let u=0,_=0;for(let g=0,O=c.length;g<O;g++){const m=c[g],{pageWidth:I,pageHeight:h}=m;s.pageLayoutType===v.PageLayoutType.VERTICAL?(_+=h,_+=s.pageMarginTop,g===O-1&&(_+=s.pageMarginTop),u=Math.max(u,I)):s.pageLayoutType===v.PageLayoutType.HORIZONTAL&&(u+=I,g!==O-1&&(u+=s.pageMarginLeft),_=Math.max(_,h))}s.resize(u,_),this._editorService.isEditor(o)||i.resize(u,_)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const i=t.params,{unitId:o}=i,s=this._docSkeletonManagerService.getSkeletonByUnitId(o);if(s==null)return;const{skeleton:c}=s,u=this._renderManagerService.getRenderById(o);if(u==null)return;if(c.calculate(),this._editorService.isEditor(o)){(n=u.mainComponent)==null||n.makeDirty();return}this._recalculateSizeBySkeleton(u,c)}}))}};ee=Qt([a.OnLifecycle(a.LifecycleStages.Rendered,ee),Q(0,C.Inject(d.DocSkeletonManagerService)),Q(1,v.IRenderManagerService),Q(2,a.ICommandService),Q(3,l.IEditorService)],ee);var en=Object.defineProperty,tn=Object.getOwnPropertyDescriptor,nn=(r,e,t,n)=>{for(var i=n>1?void 0:n?tn(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&en(e,t,i),i},pe=(r,e)=>(t,n)=>e(t,n,r);S.DocCanvasView=class extends a.RxDisposable{constructor(t,n,i){super();b(this,"_scene");b(this,"_currentDocumentModel");b(this,"_fps$",new M.BehaviorSubject(""));b(this,"fps$",this._fps$.asObservable());this._renderManagerService=t,this._configService=n,this._currentUniverService=i,this._initialize()}_initialize(){this._renderManagerService.createRender$.pipe(M.takeUntil(this.dispose$)).subscribe(t=>{this._create(t)}),this._currentUniverService.currentDoc$.pipe(M.takeUntil(this.dispose$)).subscribe(t=>{this._create(t==null?void 0:t.getUnitId())}),this._currentUniverService.getAllUniverDocsInstance().forEach(t=>{this._create(t.getUnitId())})}dispose(){this._fps$.complete()}_create(t){if(t==null)return;const n=this._currentUniverService.getUniverDocInstance(t);n!=null&&(this._currentDocumentModel=n,this._renderManagerService.has(t)||this._addNewRender())}_addNewRender(){const t=this._currentDocumentModel,n=t.getUnitId(),i=t.getContainer(),o=t.getParentRenderUnitId();if(i!=null&&o!=null)throw new Error("container or parentRenderUnitId can only exist one");i==null&&o!=null?this._renderManagerService.createRenderWithParent(n,o):this._renderManagerService.createRender(n);const s=this._renderManagerService.getRenderById(n);if(s==null)return;const{scene:c,engine:u}=s;c.openTransformer(),this._scene=c;const _=new v.Viewport(d.VIEWPORT_KEY.VIEW_MAIN,c,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});c.attachControl(),c.on(v.EVENT_TYPE.wheel,(O,m)=>{const I=O;if(I.ctrlKey){const h=Math.abs(I.deltaX);let f=h<40?.2:h<80?.4:.2;f*=I.deltaY>0?-1:1,c.scaleX<1&&(f/=2),c.scaleX+f>4?c.scale(4,4):c.scaleX+f<.1?c.scale(.1,.1):I.preventDefault()}else _.onMouseWheel(I,m)}),this._configService.getConfig("hasScroll")!==!1&&new v.ScrollBar(_),c.addLayer(new v.Layer(c,[],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),new v.Layer(c,[],d.DOCS_COMPONENT_HEADER_LAYER_INDEX)),this._addComponent(s),this._currentDocumentModel.getShouldRenderLoopImmediately()&&u.runRenderLoop(()=>{c.render(),this._fps$.next(Math.round(u.getFps()).toString())}),this._renderManagerService.setCurrent(n)}_addComponent(t){const n=this._scene,i=this._currentDocumentModel,o=new v.Documents(d.DOCS_VIEW_KEY.MAIN,void 0,{pageMarginLeft:i.documentStyle.marginLeft||0,pageMarginTop:i.documentStyle.marginTop||0});o.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX,t.mainComponent=o,t.components.set(d.DOCS_VIEW_KEY.MAIN,o),n.addObjects([o],d.DOCS_COMPONENT_MAIN_LAYER_INDEX)}},S.DocCanvasView=nn([a.OnLifecycle(a.LifecycleStages.Starting,S.DocCanvasView),pe(0,v.IRenderManagerService),pe(1,a.IConfigService),pe(2,a.IUniverInstanceService)],S.DocCanvasView);var rn=Object.defineProperty,on=Object.getOwnPropertyDescriptor,sn=(r,e,t,n)=>{for(var i=n>1?void 0:n?on(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&rn(e,t,i),i},$=(r,e)=>(t,n)=>e(t,n,r);let te=class extends a.Disposable{constructor(e,t,n,i,o,s){super();b(this,"_liquid",new v.Liquid);b(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._commandService=i,this._floatingObjectManagerService=o,this._editorService=s,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh(),this._updateOnPluginChange()}_updateOnPluginChange(){this._floatingObjectManagerService.pluginUpdate$.subscribe(e=>{const t=this._docSkeletonManagerService.getCurrent();if(t==null)return;const{unitId:n,skeleton:i}=t,o=this._renderManagerService.getRenderById(n);if(o==null)return;const{mainComponent:s,components:c,scene:u}=o,_=s,{left:p,top:g}=_;e.forEach(O=>{const{unitId:m,subUnitId:I,floatingObjectId:h,floatingObject:f}=O,{left:T=0,top:R=0,width:P=0,height:U=0,angle:x,flipX:A,flipY:j,skewX:ae,skewY:ce}=f,y=this._pageMarginCache.get(h),Mn=(y==null?void 0:y.marginLeft)||0,Tn=(y==null?void 0:y.marginTop)||0;i==null||i.getViewModel().getDataModel().updateDrawing(h,{left:T-p-Mn,top:R-g-Tn,height:U,width:P})}),i==null||i.calculate(),s==null||s.makeDirty()})}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{skeleton:t,unitId:n}=e,i=this._renderManagerService.getRenderById(n);if(i==null)return;const{mainComponent:o}=i;o.changeSkeleton(t),this._refreshFloatingObject(n,t,i)})}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const i=t.params,{unitId:o}=i,s=this._docSkeletonManagerService.getCurrent();if(s==null)return;const{unitId:c,skeleton:u}=s;if(o!==c)return;const _=this._renderManagerService.getRenderById(c);if(_==null)return;if(this._editorService.isEditor(c)){(n=_.mainComponent)==null||n.makeDirty();return}this._refreshFloatingObject(c,u,_)}}))}_refreshFloatingObject(e,t,n){const i=t==null?void 0:t.getSkeletonData(),{mainComponent:o,scene:s}=n,c=o;if(!i)return;const{left:u,top:_,pageLayoutType:p,pageMarginLeft:g,pageMarginTop:O}=c,{pages:m}=i,I=[];s.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let h=0,f=m.length;h<f;h++){const T=m[h],{skeDrawings:R,marginLeft:P,marginTop:U}=T;this._liquid.translatePagePadding(T),R.forEach(x=>{const{aLeft:A,aTop:j,height:ae,width:ce,objectId:y}=x;I.push({unitId:e,subUnitId:a.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:y,floatingObject:{left:A+u+this._liquid.x,top:j+_+this._liquid.y,width:ce,height:ae}}),this._pageMarginCache.set(y,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.translatePage(T,p,g,O)}this._floatingObjectManagerService.BatchAddOrUpdate(I)}};te=sn([a.OnLifecycle(a.LifecycleStages.Steady,te),$(0,C.Inject(d.DocSkeletonManagerService)),$(1,a.IUniverInstanceService),$(2,v.IRenderManagerService),$(3,a.ICommandService),$(4,a.IFloatingObjectManagerService),$(5,l.IEditorService)],te);var an=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,ln=(r,e,t,n)=>{for(var i=n>1?void 0:n?cn(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&an(e,t,i),i},ge=(r,e)=>(t,n)=>e(t,n,r);const dn="rgba(198, 198, 198, 1)",un="rgba(255, 255, 255, 1)";let ne=class extends a.Disposable{constructor(r,e,t){super(),this._renderManagerService=r,this._editorService=e,this._currentUniverService=t,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this._renderManagerService.currentRender$.subscribe(r=>{var o;if(r==null)return;const e=this._renderManagerService.getRenderById(r);if(this._editorService.isEditor(r)||this._currentUniverService.getUniverDocInstance(r)==null||e==null)return;const{mainComponent:t}=e,n=t,i=(o=n.getSkeleton())==null?void 0:o.getPageSize();this.disposeWithMe(a.toDisposable(n.onPageRenderObservable.add(s=>{var h,f,T,R;if(this._editorService.isEditor(r))return;const{page:c,pageLeft:u,pageTop:_,ctx:p}=s,{width:g,pageWidth:O,height:m,pageHeight:I}=c;p.save(),p.translate(u-.5,_-.5),v.Rect.drawWith(p,{width:(f=(h=i==null?void 0:i.width)!=null?h:O)!=null?f:g,height:(R=(T=i==null?void 0:i.height)!=null?T:I)!=null?R:m,strokeWidth:1,stroke:dn,fill:un,zIndex:3}),p.restore()})))})}_commandExecutedListener(){}};ne=ln([a.OnLifecycle(a.LifecycleStages.Rendered,ne),ge(0,v.IRenderManagerService),ge(1,l.IEditorService),ge(2,a.IUniverInstanceService)],ne);var hn=Object.defineProperty,_n=Object.getOwnPropertyDescriptor,pn=(r,e,t,n)=>{for(var i=n>1?void 0:n?_n(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&hn(e,t,i),i},F=(r,e)=>(t,n)=>e(t,n,r);let ie=class extends a.Disposable{constructor(e,t,n,i,o,s){super();b(this,"_initializedRender",new Set);this._docSkeletonManagerService=e,this._currentUniverService=t,this._commandService=n,this._renderManagerService=i,this._textSelectionManagerService=o,this._editorService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._initialRenderRefresh()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t}=e,n=this._renderManagerService.getRenderById(t);if(n==null||this._initializedRender.has(t)||this._editorService.isEditor(t))return;this._initializedRender.add(t);const{scene:i}=n;this.disposeWithMe(a.toDisposable(i.onMouseWheelObserver.add(o=>{if(!o.ctrlKey)return;const s=Math.abs(o.deltaX);let c=s<40?.2:s<80?.4:.2;c*=o.deltaY>0?-1:1,i.scaleX<1&&(c/=2);const u=this._currentUniverService.getCurrentUniverDocInstance(),_=u.zoomRatio;let p=+Number.parseFloat(`${_+c}`).toFixed(1);p=p>=4?4:p<=.1?.1:p,this._commandService.executeCommand(d.SetDocZoomRatioCommand.id,{zoomRatio:p,unitId:u.getUnitId()}),o.preventDefault()})))})}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance().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._currentUniverService.getCurrentUniverDocInstance(),i=t.params,{unitId:o}=i;if(o!==n.getUnitId())return;const s=n.zoomRatio||1;this._updateViewZoom(s)}}))}_updateViewZoom(e,t=!0){var i;const n=this._getDocObject();n!=null&&(n.scene.scale(e,e),this._calculatePagePosition(n,e),t&&this._textSelectionManagerService.refreshSelection(),(i=n.scene.getTransformer())==null||i.hideControl())}_calculatePagePosition(e,t){const{document:n,scene:i}=e,o=i==null?void 0:i.getParent(),{width:s,height:c,pageMarginLeft:u,pageMarginTop:_}=n;if(o==null||s===Number.POSITIVE_INFINITY||c===Number.POSITIVE_INFINITY)return;const{width:p,height:g}=o;let O=0,m=0,I=0,h=0,f=Number.POSITIVE_INFINITY;p>(s+u*2)*t?(O=p/2-s*t/2,O/=t,I=(p-u*2)/t,f=0):(O=u,I=s+u*2,f=(I-p/t)/2),g>c?(m=g/2-c/2,h=(g-_*2)/t):(m=_,h=c+_*2),i.resize(I,h+200),n.translate(O,m);const T=i.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(f!==Number.POSITIVE_INFINITY&&T!=null){const R=T.getBarScroll(f,0).x;T.scrollTo({x:R})}return this}_getDocObject(){return d.getDocObject(this._currentUniverService,this._renderManagerService)}};ie=pn([a.OnLifecycle(a.LifecycleStages.Rendered,ie),F(0,C.Inject(d.DocSkeletonManagerService)),F(1,a.IUniverInstanceService),F(2,a.ICommandService),F(3,v.IRenderManagerService),F(4,C.Inject(d.TextSelectionManagerService)),F(5,l.IEditorService)],ie);var gn=Object.defineProperty,Sn=Object.getOwnPropertyDescriptor,fn=(r,e,t,n)=>{for(var i=n>1?void 0:n?Sn(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&gn(e,t,i),i},N=(r,e)=>(t,n)=>e(t,n,r);let re=class extends a.Disposable{constructor(e,t,n,i,o,s,c){super();b(this,"_loadedMap",new WeakSet);this._docSkeletonManagerService=e,this._currentUniverService=t,this._commandService=n,this._renderManagerService=i,this._textSelectionRenderManager=o,this._textSelectionManagerService=s,this._editorService=c,this._initialize()}_initialize(){this._init(),this._skeletonListener(),this._commandExecutedListener()}_init(){this.disposeWithMe(this._renderManagerService.currentRender$.subscribe(e=>{this._create(e)})),this._renderManagerService.getRenderAll().forEach((e,t)=>{this._create(t)})}_create(e){if(e==null||this._currentUniverService.getUniverDocInstance(e)==null)return;const t=this._getDocObjectById(e);t==null||t.document==null||this._loadedMap.has(t.document)||(this._initialMain(e),this._loadedMap.add(t.document))}_initialMain(e){const t=this._getDocObjectById(e);if(t==null)return;const{document:n,scene:i}=t;this.disposeWithMe(a.toDisposable(n.onPointerEnterObserver.add(()=>{this._isEditorReadOnly(e)||(n.cursor=v.CURSOR_TYPE.TEXT)}))),this.disposeWithMe(a.toDisposable(n.onPointerLeaveObserver.add(()=>{n.cursor=v.CURSOR_TYPE.DEFAULT,i.resetCursor()}))),this.disposeWithMe(a.toDisposable(n==null?void 0:n.onPointerDownObserver.add((o,s)=>{if(this._isEditorReadOnly(e))return;this._currentUniverService.getCurrentUniverDocInstance().getUnitId()!==e&&this._currentUniverService.setCurrentUniverDocInstance(e),this._editorService.getEditor(e)?setTimeout(()=>{this._textSelectionRenderManager.eventTrigger(o),this._setEditorFocus(e)},0):this._textSelectionRenderManager.eventTrigger(o),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._currentUniverService.getAllUniverSheetsInstance().length>0){const n=this._currentUniverService.getCurrentUniverSheetInstance();this._editorService.setOperationSheetUnitId(n.getUnitId())}this._editorService.focusStyle(e)}_commandExecutedListener(){const e=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const i=t.params,{unitId:o}=i,s=(n=this._textSelectionManagerService.getCurrentSelection())==null?void 0:n.unitId;if(o!==s)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t,skeleton:n}=e,i=this._renderManagerService.getRenderById(t);if(i==null)return;const{scene:o,mainComponent:s}=i;this._textSelectionRenderManager.changeRuntime(n,o,s),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:t,subUnitId:""})}))}_getDocObjectById(e){return d.getDocObjectById(e,this._renderManagerService)}};re=fn([a.OnLifecycle(a.LifecycleStages.Rendered,re),N(0,C.Inject(d.DocSkeletonManagerService)),N(1,a.IUniverInstanceService),N(2,a.ICommandService),N(3,v.IRenderManagerService),N(4,v.ITextSelectionRenderManager),N(5,C.Inject(d.TextSelectionManagerService)),N(6,l.IEditorService)],re);var vn=Object.defineProperty,mn=Object.getOwnPropertyDescriptor,Cn=(r,e,t,n)=>{for(var i=n>1?void 0:n?mn(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&vn(e,t,i),i},H=(r,e)=>(t,n)=>e(t,n,r);const Be=1.5;let oe=class extends a.RxDisposable{constructor(r,e,t,n,i){super(),this._docSkeletonManagerService=r,this._textSelectionManagerService=e,this._editorService=t,this._currentUniverService=n,this._renderManagerService=i,this._init()}_init(){this._textSelectionManagerService.textSelection$.pipe(M.takeUntil(this.dispose$)).subscribe(r=>{if(r==null)return;const{isEditing:e,unitId:t}=r;e&&this._scrollToSelection(t)})}_scrollToSelection(r){var y;const e=this._textSelectionManagerService.getActiveRange(),t=this._getDocObject(),n=(y=this._docSkeletonManagerService.getCurrent())==null?void 0:y.skeleton;if(e==null||t==null||n==null)return;const{collapsed:i,startNodePosition:o}=e;if(!i)return;const s=t.document.getOffsetConfig(),{docsLeft:c,docsTop:u}=s,_=new v.NodePositionConvertToCursor(s,n),{contentBoxPointGroup:p}=_.getRangePointData(o,o),{left:g,top:O,height:m}=v.getAnchorBounding(p),I=g+c,h=O+u,f=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN),T=!!this._editorService.getEditor(r);if(f==null)return;const{left:R,top:P,right:U,bottom:x}=f.getBounding().viewBound;let A=0,j=0;const ae=T?0:100;h<P?A=h-P:h>x-m&&(A=h-x+m+ae),I<R?j=I-R:I>U-Be&&(j=I-U+Be);const ce=f.getBarScroll(j,A);f.scrollBy(ce)}_getDocObject(){return d.getDocObject(this._currentUniverService,this._renderManagerService)}};oe=Cn([a.OnLifecycle(a.LifecycleStages.Rendered,oe),H(0,C.Inject(d.DocSkeletonManagerService)),H(1,C.Inject(d.TextSelectionManagerService)),H(2,l.IEditorService),H(3,a.IUniverInstanceService),H(4,v.IRenderManagerService)],oe);var In=Object.defineProperty,On=Object.getOwnPropertyDescriptor,bn=(r,e,t,n)=>{for(var i=n>1?void 0:n?On(e,t):e,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&In(e,t,i),i},Se=(r,e)=>(t,n)=>e(t,n,r);S.UniverDocsUIPlugin=(fe=class extends a.Plugin{constructor(e,t,n,i){super(Ie),this._config=e,this._injector=t,this._localeService=n,this._logService=i,this._localeService.load({zhCN:Ee}),this._config=a.Tools.deepMerge({},Ce,this._config),this._initDependencies(t),this._initializeCommands()}onRendered(){this._initModules(),this._markDocAsFocused()}onDestroy(){}_initializeCommands(){[je,We,ke,Ve,ze,He,Ye,Ge,Ke,Rt,yt,Tt].forEach(e=>{this._injector.get(l.IShortcutService).registerShortcut(e)})}_initDependencies(e){[[q],[Z],[J],[ee],[te],[ne],[ie],[re],[oe],[W,{useFactory:()=>this._injector.createInstance(W,this._config)}],[k,{useClass:he}],[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(),i=n.getUnitId();t.isEditor(i)||e.focusUniverInstance(n.getUnitId())}catch(n){this._logService.warn(n)}}_initModules(){this._injector.get(W)}},b(fe,"type",a.PluginType.Doc),fe),S.UniverDocsUIPlugin=bn([Se(1,C.Inject(C.Injector)),Se(2,C.Inject(a.LocaleService)),Se(3,a.ILogService)],S.UniverDocsUIPlugin),S.DOC_UI_PLUGIN_NAME=Ie,S.DefaultDocContainerConfig=me,S.DefaultDocUiConfig=Ce,S.DefaultToolbarConfig=ve,S.enUS=Mt,S.zhCN=Ee,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/docs-ui",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "private": false,
5
5
  "description": "Univer normal ui-plugin-docs",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -48,28 +48,30 @@
48
48
  "npm": ">=8.0.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "@wendellhu/redi": "^0.13.0",
52
- "@univerjs/core": "0.1.1",
53
- "@univerjs/design": "0.1.1",
54
- "@univerjs/docs": "0.1.1",
55
- "@univerjs/engine-render": "0.1.1",
56
- "@univerjs/ui": "0.1.1"
51
+ "@wendellhu/redi": "0.13.0",
52
+ "react": ">=16.9.0",
53
+ "rxjs": ">=7.0.0",
54
+ "@univerjs/core": "0.1.3",
55
+ "@univerjs/docs": "0.1.3",
56
+ "@univerjs/engine-render": "0.1.3",
57
+ "@univerjs/design": "0.1.3",
58
+ "@univerjs/ui": "0.1.3"
57
59
  },
58
60
  "devDependencies": {
59
- "@types/react": "^18.2.57",
61
+ "@types/react": "^18.2.66",
60
62
  "@wendellhu/redi": "^0.13.0",
61
63
  "less": "^4.2.0",
62
64
  "react": "^18.2.0",
63
65
  "rxjs": "^7.8.1",
64
- "typescript": "^5.3.3",
65
- "vite": "^5.1.4",
66
+ "typescript": "^5.4.2",
67
+ "vite": "^5.1.6",
66
68
  "vitest": "^1.3.1",
67
- "@univerjs/core": "0.1.1",
68
- "@univerjs/design": "0.1.1",
69
- "@univerjs/engine-render": "0.1.1",
70
- "@univerjs/docs": "0.1.1",
71
- "@univerjs/shared": "0.1.1",
72
- "@univerjs/ui": "0.1.1"
69
+ "@univerjs/core": "0.1.3",
70
+ "@univerjs/design": "0.1.3",
71
+ "@univerjs/docs": "0.1.3",
72
+ "@univerjs/shared": "0.1.3",
73
+ "@univerjs/engine-render": "0.1.3",
74
+ "@univerjs/ui": "0.1.3"
73
75
  },
74
76
  "scripts": {
75
77
  "test": "vitest run",