@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.
- package/README.md +10 -2
- package/lib/cjs/index.js +3 -3
- package/lib/es/index.js +1124 -836
- package/lib/types/controllers/back-scroll.controller.d.ts +30 -0
- package/lib/types/controllers/doc-editor-bridge.controller.d.ts +5 -2
- package/lib/types/controllers/doc-ui.controller.d.ts +4 -2
- package/lib/types/controllers/text-selection.controller.d.ts +39 -0
- package/lib/types/services/clipboard/html-to-udm/paste-plugins/plugin-univer.d.ts +18 -0
- package/lib/types/services/clipboard/udm-to-html/convertor.d.ts +4 -1
- package/lib/types/shortcuts/utils.d.ts +1 -0
- package/lib/umd/index.js +3 -3
- package/package.json +18 -16
package/README.md
CHANGED
|
@@ -5,12 +5,20 @@
|
|
|
5
5
|
|
|
6
6
|
## Introduction
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
`@univerjs/docs-ui` package provides the User Interface for Docs.
|
|
9
|
+
|
|
10
|
+
:::info
|
|
11
|
+
`@univerjs/docs-ui` is still in the experimental phase. It is not recommended for use in production environments. You can learn about the iteration plans on the [roadmap](/guides/roadmap).
|
|
12
|
+
:::
|
|
9
13
|
|
|
10
14
|
## Usage
|
|
11
15
|
|
|
12
16
|
### Installation
|
|
13
17
|
|
|
14
18
|
```shell
|
|
15
|
-
|
|
19
|
+
# Using npm
|
|
20
|
+
npm install @univerjs/docs-ui
|
|
21
|
+
|
|
22
|
+
# Using pnpm
|
|
23
|
+
pnpm add @univerjs/docs-ui
|
|
16
24
|
```
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var Fe=Object.defineProperty;var Ae=(i,e,t)=>e in i?Fe(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var I=(i,e,t)=>(Ae(i,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),O=require("@wendellhu/redi"),l=require("@univerjs/ui"),u=require("@univerjs/docs"),m=require("@univerjs/engine-render"),we=require("@wendellhu/redi/react-bindings"),je=require("@univerjs/design"),We=require("react"),M=require("rxjs"),be={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},Re={layout:{docContainerConfig:Me,toolbarConfig:be}},Te="DocUI";function y(i){return i.getContextValue(a.FOCUSING_DOC)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function Ve(i){return i.getContextValue(a.FOCUSING_DOC)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(a.FOCUSING_UNIVER_EDITOR_SINGLE_MODE)}const ke={id:u.MoveCursorOperation.id,binding:l.KeyCode.ARROW_UP,preconditions:y,staticParameters:{direction:a.Direction.UP}},ze={id:u.MoveCursorOperation.id,binding:l.KeyCode.ARROW_DOWN,preconditions:y,staticParameters:{direction:a.Direction.DOWN}},He={id:u.MoveCursorOperation.id,binding:l.KeyCode.ARROW_LEFT,preconditions:y,staticParameters:{direction:a.Direction.LEFT}},Ye={id:u.MoveCursorOperation.id,binding:l.KeyCode.ARROW_RIGHT,preconditions:y,staticParameters:{direction:a.Direction.RIGHT}},Ge={id:u.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_UP|l.MetaKeys.SHIFT,preconditions:y,staticParameters:{direction:a.Direction.UP}},Ke={id:u.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_DOWN|l.MetaKeys.SHIFT,preconditions:y,staticParameters:{direction:a.Direction.DOWN}},qe={id:u.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_LEFT|l.MetaKeys.SHIFT,preconditions:y,staticParameters:{direction:a.Direction.LEFT}},Xe={id:u.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_RIGHT|l.MetaKeys.SHIFT,preconditions:y,staticParameters:{direction:a.Direction.RIGHT}},Ze={id:u.SelectAllOperation.id,binding:l.KeyCode.A|l.MetaKeys.CTRL_COMMAND,preconditions:i=>i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&(i.getContextValue(a.FOCUSING_DOC)||i.getContextValue(a.EDITOR_ACTIVATED))};var Je=Object.defineProperty,Qe=Object.getOwnPropertyDescriptor,et=(i,e,t,n)=>{for(var r=n>1?void 0:n?Qe(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Je(e,t,r),r},fe=(i,e)=>(t,n)=>e(t,n,i);let _e=class{constructor(i,e,t){I(this,"_docContainer");I(this,"getComponent",i=>{if(this._docContainer=i,!i.getContentRef().current)throw new Error("container is not ready")});I(this,"changeLocale",i=>{this._localeService.setLocale(i)});this._config=i,this._localeService=e,this._injector=t}getUIConfig(){return{injector:this._injector,config:this._config,changeLocale:this.changeLocale,getComponent:this.getComponent}}getContentRef(){return this._docContainer.getContentRef()}UIDidMount(i){if(this._docContainer)return i(this._docContainer)}getDocContainer(){return this._docContainer}};_e=et([fe(1,O.Inject(a.LocaleService)),fe(2,O.Inject(O.Injector))],_e);var tt=Object.defineProperty,nt=Object.getOwnPropertyDescriptor,rt=(i,e,t,n)=>{for(var r=n>1?void 0:n?nt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&tt(e,t,r),r},G=(i,e)=>(t,n)=>e(t,n,i);let k=class extends a.RxDisposable{constructor(e,t,n,r,o){super();I(this,"_docContainerController");I(this,"changeLocale",e=>{this._localeService.setLocale(e)});this._localeService=t,this._injector=n,this._textSelectionRenderManager=r,this._layoutService=o,this._docContainerController=this._injector.createInstance(_e,e),this._registerContainer()}_registerContainer(){this._layoutService&&this.disposeWithMe(this._layoutService.registerContainerElement(this._textSelectionRenderManager.__getEditorContainer()))}getDocContainerController(){return this._docContainerController}};k=rt([G(1,O.Inject(a.LocaleService)),G(2,O.Inject(O.Injector)),G(3,m.ITextSelectionRenderManager),G(4,O.Optional(l.ILayoutService))],k);const oe="UI_PLUGIN_DOCS",ye=`${oe}_COLOR_PICKER_COMPONENT`,De=`${oe}_FONT_FAMILY_COMPONENT`,Ee=`${oe}_FONT_FAMILY_ITEM_COMPONENT`,xe=`${oe}_FONT_SIZE_COMPONENT`;var Pe={exports:{}},se={};/**
|
|
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 qe=Le,Xe=Symbol.for("react.element"),Ze=Symbol.for("react.fragment"),Je=Object.prototype.hasOwnProperty,Qe=qe.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,et={key:!0,ref:!0,__self:!0,__source:!0};function Re(i,e,t){var n,r={},o=null,s=null;t!==void 0&&(o=""+t),e.key!==void 0&&(o=""+e.key),e.ref!==void 0&&(s=e.ref);for(n in e)Je.call(e,n)&&!et.hasOwnProperty(n)&&(r[n]=e[n]);if(i&&i.defaultProps)for(n in e=i.defaultProps,e)r[n]===void 0&&(r[n]=e[n]);return{$$typeof:Xe,type:i,key:o,ref:s,props:r,_owner:Qe.current}}J.Fragment=Ze;J.jsx=Re;J.jsxs=Re;Te.exports=J;var tt=Te.exports;const nt="univer-docs-ui-canvas-background",rt={docsUiCanvasBackground:nt},it=()=>tt.jsx("div",{className:rt.docsUiCanvasBackground});function ot(i){const e=i.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 T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=D(i);if(c==null)return;const d=(s=c.ts)==null?void 0:s.bl;t.next(d===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function st(i){const e=i.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 T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=D(i);if(c==null)return;const d=(s=c.ts)==null?void 0:s.it;t.next(d===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function at(i){const e=i.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 T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=D(i);if(c==null)return;const d=(s=c.ts)==null?void 0:s.ul;t.next((d==null?void 0:d.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function ct(i){const e=i.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 T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=D(i);if(c==null)return;const d=(s=c.ts)==null?void 0:s.st;t.next((d==null?void 0:d.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function lt(i){const e=i.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 T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=D(i);if(c==null)return;const d=(s=c.ts)==null?void 0:s.va;t.next(d===a.BaselineOffset.SUBSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function dt(i){const e=i.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 T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=D(i);if(c==null)return;const d=(s=c.ts)==null?void 0:s.va;t.next(d===a.BaselineOffset.SUPERSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function ut(i){const e=i.get(a.ICommandService);return{id:u.SetInlineFormatFontFamilyCommand.id,tooltip:"toolbar.font",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,label:Ie,positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_FAMILY_LIST.map(t=>({label:{name:Oe,hoverable:!0},value:t.value})),value$:new T.Observable(t=>{const n=l.FONT_FAMILY_LIST[0].value,r=e.onCommandExecuted(o=>{var c;const s=o.id;if(s===u.SetTextSelectionsOperation.id||s===u.SetInlineFormatFontFamilyCommand.id){const d=D(i);if(d==null)return;const h=(c=d.ts)==null?void 0:c.ff;t.next(h!=null?h:n)}});return t.next(n),r.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function pt(i){const e=i.get(a.ICommandService);return{id:u.SetInlineFormatFontSizeCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:be,props:{min:1,max:400}},positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_SIZE_LIST,value$:new T.Observable(t=>{const r=e.onCommandExecuted(o=>{var c;const s=o.id;if(s===u.SetTextSelectionsOperation.id||s===u.SetInlineFormatFontSizeCommand.id){const d=D(i);if(d==null)return;const h=(c=d.ts)==null?void 0:c.fs;t.next(h!=null?h:14)}});return t.next(14),r.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function ht(i){const e=i.get(a.ICommandService),t=i.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:Ce,hoverable:!1}}],value$:new T.Observable(n=>{const r=t.getCurrentTheme().textColor,o=e.onCommandExecuted(s=>{if(s.id===u.SetInlineFormatTextColorCommand.id){const c=s.params.value;n.next(c!=null?c:r)}});return n.next(r),o.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function _t(i){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(i,a.UniverInstanceType.DOC)}}function gt(i){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(i,a.UniverInstanceType.DOC)}}function D(i){var d;const e=i.get(a.IUniverInstanceService),t=i.get(u.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const o=(d=n.getBody())==null?void 0:d.textRuns;if(o==null)return;const{startOffset:s}=r;return o.find(({st:h,ed:_})=>s>=h&&s<_)}var mt=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,St=(i,e,t,n)=>{for(var r=n>1?void 0:n?ft(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&mt(e,t,r),r},E=(i,e)=>(t,n)=>e(t,n,i);let V=class extends a.Disposable{constructor(i,e,t,n,r,o){super(),this._injector=i,this._componentManager=e,this._editorService=t,this._menuService=n,this._uiController=r,this._currentUniverService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Ce,Ue.ColorPicker)),this.disposeWithMe(i.register(Ie,l.FontFamily)),this.disposeWithMe(i.register(Oe,l.FontFamilyItem)),this.disposeWithMe(i.register(be,l.FontSize))}_initMenus(){[ot,st,at,ct,lt,dt,pt,ut,ht,_t,gt].forEach(i=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(i)))})}_init(){this._initCustomComponents(),this._initMenus(),this._initDocBackground()}_initDocBackground(){const i=this._currentUniverService.getAllUniverDocsInstance()[0].getUnitId();if(i==null)return;this._editorService.isEditor(i)||this.disposeWithMe(this._uiController.registerContentComponent(()=>Pe.connectInjector(it,this._injector)))}};V=St([a.OnLifecycle(a.LifecycleStages.Rendered,V),E(0,O.Inject(O.Injector)),E(1,O.Inject(l.ComponentManager)),E(2,l.IEditorService),E(3,l.IMenuService),E(4,l.IUIController),E(5,a.IUniverInstanceService)],V);const vt={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"}},Me={toolbar:{undo:"撤销",redo:"重做",font:"字体",fontSize:"字号",bold:"粗体",italic:"斜体",strikethrough:"删除线",subscript:"下标",superscript:"上标",underline:"下划线",textColor:{main:"文本颜色",right:"颜色选择"},resetColor:"重置颜色",order:"有序列表",unorder:"无序列表"}},Ct={id:u.BreakLineCommand.id,preconditions:M,binding:l.KeyCode.ENTER},It={id:u.DeleteLeftCommand.id,preconditions:M,binding:l.KeyCode.BACKSPACE},Ot={id:u.DeleteRightCommand.id,preconditions:M,binding:l.KeyCode.DELETE},bt=10,Tt=6;function Rt(){return a.Tools.generateRandomId(Tt)}function Mt(i){const e=i.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class yt{constructor(){v(this,"_cache",new a.LRUMap(bt))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}clear(){this._cache.clear()}}const he=new yt;function se(i){const e=i.style,t={},n=i.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{t.bl=a.BooleanNumber.TRUE;break}case"s":{t.st={s:a.BooleanNumber.TRUE};break}case"u":{t.ul={s:a.BooleanNumber.TRUE};break}case"i":{t.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=n==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}for(let r=0;r<e.length;r++){const o=e[r],s=e.getPropertyValue(o);switch(o){case"font-family":{t.ff=s;break}case"font-size":{const c=Number.parseInt(s);Number.isNaN(c)||s.endsWith("pt")&&(t.fs=c);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 Dt(i){const e=new DOMParser,t=`<x-univer id="univer-root">${i}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function _e(i,e){const t=i.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(i)}const X=class X{constructor(){v(this,"_styleCache",new Map);v(this,"_styleRules",[]);v(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=X._pluginList.find(o=>o.checkPasteType(e)),n=Dt(e),r={dataStream:"",textRuns:[]};return t&&(this._styleRules=[...t.stylesRules],this._afterProcessRules=[...t.afterProcessRules]),this._styleCache.clear(),this._process(null,n==null?void 0:n.childNodes,r),this._styleCache.clear(),this._styleRules=[],this._afterProcessRules=[],r}_process(e,t,n){var r;for(const o of t)if(o.nodeType===Node.TEXT_NODE){const s=(r=o.nodeValue)==null?void 0:r.replace(/[\r\n]/g,"");let c;e&&this._styleCache.has(e)&&(c=this._styleCache.get(e)),n.dataStream+=s,c&&Object.getOwnPropertyNames(c).length&&n.textRuns.push({st:n.dataStream.length-s.length,ed:n.dataStream.length,ts:c})}else if(o.nodeType===Node.ELEMENT_NODE){const s=e?this._styleCache.get(e):{},c=this._styleRules.find(({filter:m})=>_e(o,m)),d=c?c.getStyle(o):se(o);this._styleCache.set(o,{...s,...d});const{childNodes:h}=o;this._process(o,h,n);const _=this._afterProcessRules.find(({filter:m})=>_e(o,m));_&&_.handler(n,o)}}};v(X,"_pluginList",[]);let w=X;const Et={name:"univer-doc-paste-plugin-lark",checkPasteType(i){return/lark-record-clipboard/i.test(i)},stylesRules:[{filter:["s"],getStyle(i){const e=se(i);return{st:{s:a.BooleanNumber.TRUE},...e}}}],afterProcessRules:[{filter(i){return i.tagName==="DIV"&&/ace-line/i.test(i.className)},handler(i){i.paragraphs==null&&(i.paragraphs=[]),i.paragraphs.push({startIndex:i.dataStream.length}),i.dataStream+="\r"}}]};function xt(i){const e=i.style,t={};for(let n=0;n<e.length;n++){const r=e[n],o=e.getPropertyValue(r);switch(r){case"margin-top":{const s=Number.parseInt(o);t.spaceAbove=/pt/.test(o)?C.ptToPixel(s):s;break}case"margin-bottom":{const s=Number.parseInt(o);t.spaceBelow=/pt/.test(o)?C.ptToPixel(s):s;break}}}return Object.getOwnPropertyNames(t).length?t:null}const Pt={name:"univer-doc-paste-plugin-word",checkPasteType(i){return/word|mso/i.test(i)},stylesRules:[{filter:["b"],getStyle(i){const e=se(i);return{bl:a.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(i){return i.tagName==="P"&&/mso/i.test(i.className)},handler(i,e){i.paragraphs==null&&(i.paragraphs=[]);const t={startIndex:i.dataStream.length},n=xt(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]};function Ut(i,e){const{st:t,ed:n,ts:r={}}=e,{ff:o,fs:s,it:c,bl:d,ul:h,st:_,ol:m,bg:S,cl:I,va:f}=r;let p=i.slice(t,n);const g=[];return c===a.BooleanNumber.TRUE&&(p=`<i>${p}</i>`),f===a.BaselineOffset.SUPERSCRIPT?p=`<sup>${p}</sup>`:f===a.BaselineOffset.SUBSCRIPT&&(p=`<sub>${p}</sub>`),(h==null?void 0:h.s)===a.BooleanNumber.TRUE&&(p=`<u>${p}</u>`),(_==null?void 0:_.s)===a.BooleanNumber.TRUE&&(p=`<s>${p}</s>`),d===a.BooleanNumber.TRUE&&(p=`<strong>${p}</strong>`),o&&g.push(`font-family: ${o}`),I&&g.push(`color: ${I.rgb}`),s&&g.push(`font-size: ${s}px`),m&&g.push("text-decoration: overline"),S&&g.push(`background: ${S.rgb}`),g.length?`<span style="${g.join(";")}">${p}</span>`:p}function ge(i,e=!0){const{dataStream:t,textRuns:n=[],paragraphs:r=[]}=i;let o=0;const s=[],c=[];for(const d of n){const{st:h,ed:_}=d;if(h!==o&&s.push(t.slice(o,h)),s.push(Ut(t,d)),o=_,e)for(const m of r){const{startIndex:S,paragraphStyle:I={}}=m;if(S>=h&&S<=_){const{spaceAbove:f,spaceBelow:p}=I,g=[];f!=null&&(typeof f=="number"?g.push(`margin-top: ${f}px`):g.push(`margin-top: ${f.v}px`)),p!=null&&(typeof p=="number"?g.push(`margin-bottom: ${p}px`):g.push(`margin-bottom: ${p.v}px`)),c.push(`<p className="UniverNormal" ${g.length?`style="${g.join(";")}"`:""}>${s.join("")}</p>`),s.length=0}}}return o<t.length&&s.push(t.slice(o,t.length)),c.join("")+s.join("")}class Lt{convert(e){if(e.length===0)throw new Error("The bodyList length at least to be 1");if(e.length===1)return ge(e[0]);let t="";for(const n of e)t+='<p className="UniverNormal">',t+=ge(n,!1),t+="</p>";return t}}var Nt=Object.defineProperty,At=Object.getOwnPropertyDescriptor,Bt=(i,e,t,n)=>{for(var r=n>1?void 0:n?At(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Nt(e,t,r),r},A=(i,e)=>(t,n)=>e(t,n,i);w.use(Pt);w.use(Et);function Ft(i){const e=i.replace(/\n/g,"\r"),t=[];for(let n=0;n<e.length;n++)e[n]==="\r"&&t.push({startIndex:n});return{dataStream:e,paragraphs:t}}const j=O.createIdentifier("doc.clipboard-service");let oe=class extends a.Disposable{constructor(e,t,n,r,o){super();v(this,"_clipboardHooks",[]);v(this,"_htmlToUDM",new w);v(this,"_umdToHtml",new Lt);this._currentUniverService=e,this._logService=t,this._commandService=n,this._clipboardInterfaceService=r,this._textSelectionManagerService=o}async copy(){const e=this._getDocumentBodyInRanges();try{this._setClipboardData(e)}catch(t){return this._logService.error("[DocClipboardService] copy failed",t),!1}return!0}async cut(){return this._cut()}async paste(e){const t=await this._generateBodyFromClipboardItems(e);return this._paste(t)}async legacyPaste(e,t){const n=this._generateBodyFromHtmlAndText(e,t);return this._paste(n)}async _cut(){var o;const{segmentId:e,endOffset:t,style:n}=(o=this._textSelectionManagerService.getActiveRange())!=null?o:{},r=this._textSelectionManagerService.getSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),t==null||r==null)return!1;this.copy();try{let s=t;for(const d of r){const{startOffset:h,endOffset:_}=d;h==null||_==null||_<=t&&(s-=_-h)}const c=[{startOffset:s,endOffset:s,style:n}];return this._commandService.executeCommand(u.CutContentCommand.id,{segmentId:e,textRanges:c})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(e){var s;const{segmentId:t,endOffset:n,style:r}=(s=this._textSelectionManagerService.getActiveRange())!=null?s:{},o=this._textSelectionManagerService.getSelections();if(t==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),n==null||o==null)return!1;try{let c=n;for(const h of o){const{startOffset:_,endOffset:m}=h;_==null||m==null||m<=n&&(c+=e.dataStream.length-(m-_))}const d=[{startOffset:c,endOffset:c,style:r}];return this._commandService.executeCommand(u.InnerPasteCommand.id,{body:e,segmentId:t,textRanges:d})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(e){const t=Rt(),n=e.length>1?e.map(o=>o.dataStream).join(`
|
|
10
|
-
`):e[0].dataStream;let r=this._umdToHtml.convert(e);return e.length===1&&(r=r.replace(/(<[a-z]+)/,(o,s)=>`${s} data-copy-id="${t}"`),he.set(t,e[0])),this._clipboardInterfaceService.write(n,r)}addClipboardHook(e){return this._clipboardHooks.push(e),a.toDisposable(()=>{const t=this._clipboardHooks.indexOf(e);t>-1&&this._clipboardHooks.splice(t,1)})}_getDocumentBodyInRanges(){const e=this._textSelectionManagerService.getSelections(),t=this._currentUniverService.getCurrentUniverDocInstance(),n=[];if(e==null)return n;for(const r of e){const{startOffset:o,endOffset:s,collapsed:c}=r;if(c||o==null||s==null)continue;const d=t.sliceBody(o,s);d!=null&&n.push(d)}return n}async _generateBodyFromClipboardItems(e){try{let t="",n="";for(const r of e)for(const o of r.types)o===l.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await r.getType(o).then(s=>s&&s.text()):o===l.HTML_CLIPBOARD_MIME_TYPE&&(t=await r.getType(o).then(s=>s&&s.text()));return this._generateBodyFromHtmlAndText(t,n)}catch(t){return Promise.reject(t)}}_generateBodyFromHtmlAndText(e,t){if(!e){if(t)return Ft(t);throw new Error("[DocClipboardService] html and text cannot be both empty!")}const n=Mt(e);if(n){const r=he.get(n);if(r)return r}return this._htmlToUDM.convert(e)}};oe=Bt([A(0,a.IUniverInstanceService),A(1,a.ILogService),A(2,a.ICommandService),A(3,l.IClipboardInterfaceService),A(4,O.Inject(u.TextSelectionManagerService))],oe);function Q(i){return i.getContextValue(a.FOCUSING_DOC)||i.getContextValue(a.EDITOR_ACTIVATED)}const ae=999,$t={id:l.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:ae,preconditions:Q,handler:async i=>i.get(j).copy()},wt={id:l.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:ae,preconditions:Q,handler:async i=>i.get(j).cut()},jt={id:l.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:ae,preconditions:Q,handler:async i=>{const e=i.get(j),n=await i.get(l.IClipboardInterfaceService).read();return n.length===0?!1:e.paste(n)}};var zt=Object.defineProperty,Wt=Object.getOwnPropertyDescriptor,Vt=(i,e,t,n)=>{for(var r=n>1?void 0:n?Wt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&zt(e,t,r),r},B=(i,e)=>(t,n)=>e(t,n,i);let H=class extends a.RxDisposable{constructor(i,e,t,n,r){super(),this._commandService=i,this._clipboardInterfaceService=e,this._docClipboardService=t,this._textSelectionRenderManager=n,this._contextService=r,this._init()}_init(){[$t,wt,jt].forEach(i=>this.disposeWithMe(this._commandService.registerMultipleCommand(i))),[u.InnerPasteCommand,u.CutContentCommand].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i))),this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var i;this._clipboardInterfaceService.supportClipboard||(i=this._textSelectionRenderManager)==null||i.onPaste$.pipe(T.takeUntil(this.dispose$)).subscribe(e=>{var o,s;if(!Q(this._contextService))return;e.event.preventDefault();const t=e.event,n=(o=t.clipboardData)==null?void 0:o.getData("text/html"),r=(s=t.clipboardData)==null?void 0:s.getData("text/plain");this._docClipboardService.legacyPaste(n,r)})}};H=Vt([a.OnLifecycle(a.LifecycleStages.Steady,H),B(0,a.ICommandService),B(1,l.IClipboardInterfaceService),B(2,j),B(3,C.ITextSelectionRenderManager),B(4,a.IContextService)],H);var Ht=Object.defineProperty,kt=Object.getOwnPropertyDescriptor,Kt=(i,e,t,n)=>{for(var r=n>1?void 0:n?kt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Ht(e,t,r),r},F=(i,e)=>(t,n)=>e(t,n,i);let k=class extends a.Disposable{constructor(e,t,n,r,o){super();v(this,"_initialEditors",new Set);this._currentUniverService=e,this._docSkeletonManagerService=t,this._editorService=n,this._commandService=r,this._textSelectionRenderManager=o,this._initialize()}_initialize(){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()}_resize(e){var U,L,N;if(e==null)return;const t=this._editorService.getEditor(e);if((t==null?void 0:t.cancelDefaultResizeListener)===!0)return;const n=(U=this._docSkeletonManagerService.getSkeletonByUnitId(e))==null?void 0:U.skeleton,r=this._currentUniverService.getUniverDocInstance(e);if(t==null||t.render==null||n==null||r==null)return;const{marginTop:o=0,marginBottom:s=0,marginLeft:c=0,marginRight:d=0}=r.getSnapshot().documentStyle,{scene:h,mainComponent:_}=t.render;let{actualHeight:m,actualWidth:S}=n.getActualSize();m+=o+s,S+=c+d;const{width:I,height:f}=t.getBoundingClientRect(),p=h.getViewport(u.VIEWPORT_KEY.VIEW_MAIN);let g=p==null?void 0:p.getScrollBar();const b=Math.max(S,I),R=Math.max(m,f);h.transformByState({width:b,height:R}),_==null||_.resize(b,R),t.isSingle===!1?m>f?g==null?p&&new C.ScrollBar(p,{enableHorizontal:!1,barSize:8}):p==null||p.resetSizeAndScrollBar():(g=null,p==null||p.scrollTo({x:0,y:0}),(L=p==null?void 0:p.getScrollBar())==null||L.dispose()):S>I?g==null?p&&new C.ScrollBar(p,{barSize:8,enableVertical:!1}):p==null||p.resetSizeAndScrollBar():(g=null,p==null||p.scrollTo({x:0,y:0}),(N=p==null?void 0:p.getScrollBar())==null||N.dispose())}_initialSetValue(){this._editorService.setValue$.subscribe(e=>{this._commandService.executeCommand(u.CoverContentCommand.id,{unitId:e.editorUnitId,body:e.body,segmentId:null})})}_initialBlur(){this._editorService.blur$.subscribe(()=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.blur()})}_initialFocus(){this._editorService.focus$.subscribe(e=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges([e])})}_commandExecutedListener(){const e=[u.RichTextEditingMutation.id,l.SetEditorResizeOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=t.params,{unitId:r}=n;if(this._editorService.isSheetEditor(r))return;this._resize(r)}}))}};k=Kt([a.OnLifecycle(a.LifecycleStages.Rendered,k),F(0,a.IUniverInstanceService),F(1,O.Inject(u.DocSkeletonManagerService)),F(2,l.IEditorService),F(3,a.ICommandService),F(4,C.ITextSelectionRenderManager)],k);var Yt=Object.defineProperty,Gt=Object.getOwnPropertyDescriptor,qt=(i,e,t,n)=>{for(var r=n>1?void 0:n?Gt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Yt(e,t,r),r},W=(i,e)=>(t,n)=>e(t,n,i);let K=class extends a.RxDisposable{constructor(e,t,n,r){super();v(this,"_docRenderMap",new Set);this._docSkeletonManagerService=e,this._renderManagerService=t,this._commandService=n,this._editorService=r,this._initialRenderRefresh(),this._commandExecutedListener()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(T.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)})}_create(e){if(e==null)return;const{skeleton:t,unitId:n}=e;let r=this._renderManagerService.getRenderById(n);r==null&&(this._renderManagerService.create(n),r=this._renderManagerService.getRenderById(n));const{mainComponent:o}=r;o.changeSkeleton(t),this._recalculateSizeBySkeleton(r,t)}_recalculateSizeBySkeleton(e,t){var _;const{mainComponent:n,scene:r,unitId:o}=e,s=n,c=(_=t.getSkeletonData())==null?void 0:_.pages;if(c==null)return;let d=0,h=0;for(let m=0,S=c.length;m<S;m++){const I=c[m],{pageWidth:f,pageHeight:p}=I;s.pageLayoutType===C.PageLayoutType.VERTICAL?(h+=p,h+=s.pageMarginTop,m===S-1&&(h+=s.pageMarginTop),d=Math.max(d,f)):s.pageLayoutType===C.PageLayoutType.HORIZONTAL&&(d+=f,m!==S-1&&(d+=s.pageMarginLeft),h=Math.max(h,p))}s.resize(d,h),this._editorService.isEditor(o)||r.resize(d,h)}_commandExecutedListener(){const e=[u.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=this._docSkeletonManagerService.getSkeletonByUnitId(o);if(s==null)return;const{skeleton:c}=s,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)}}))}};K=qt([a.OnLifecycle(a.LifecycleStages.Rendered,K),W(0,O.Inject(u.DocSkeletonManagerService)),W(1,C.IRenderManagerService),W(2,a.ICommandService),W(3,l.IEditorService)],K);var Xt=Object.defineProperty,Zt=Object.getOwnPropertyDescriptor,Jt=(i,e,t,n)=>{for(var r=n>1?void 0:n?Zt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Xt(e,t,r),r},ee=(i,e)=>(t,n)=>e(t,n,i);exports.DocCanvasView=class extends a.RxDisposable{constructor(t,n,r){super();v(this,"_scene");v(this,"_currentDocumentModel");v(this,"_fps$",new T.BehaviorSubject(""));v(this,"fps$",this._fps$.asObservable());this._renderManagerService=t,this._configService=n,this._currentUniverService=r,this._initialize()}_initialize(){this._renderManagerService.createRender$.pipe(T.takeUntil(this.dispose$)).subscribe(t=>{this._create(t)}),this._currentUniverService.currentDoc$.pipe(T.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(),r=t.getContainer(),o=t.getParentRenderUnitId();if(r!=null&&o!=null)throw new Error("container or parentRenderUnitId can only exist one");r==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 h=new C.Viewport(u.VIEWPORT_KEY.VIEW_MAIN,c,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});c.attachControl(),c.on(C.EVENT_TYPE.wheel,(S,I)=>{const f=S;if(f.ctrlKey){const p=Math.abs(f.deltaX);let g=p<40?.2:p<80?.4:.2;g*=f.deltaY>0?-1:1,c.scaleX<1&&(g/=2),c.scaleX+g>4?c.scale(4,4):c.scaleX+g<.1?c.scale(.1,.1):f.preventDefault()}else h.onMouseWheel(f,I)}),this._configService.getConfig("hasScroll")!==!1&&new C.ScrollBar(h),c.addLayer(new C.Layer(c,[],u.DOCS_COMPONENT_MAIN_LAYER_INDEX),new C.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(t){const n=this._scene,r=this._currentDocumentModel,o=new C.Documents(u.DOCS_VIEW_KEY.MAIN,void 0,{pageMarginLeft:r.documentStyle.marginLeft||0,pageMarginTop:r.documentStyle.marginTop||0});o.zIndex=u.DOCS_COMPONENT_DEFAULT_Z_INDEX,t.mainComponent=o,t.components.set(u.DOCS_VIEW_KEY.MAIN,o),n.addObjects([o],u.DOCS_COMPONENT_MAIN_LAYER_INDEX)}};exports.DocCanvasView=Jt([a.OnLifecycle(a.LifecycleStages.Starting,exports.DocCanvasView),ee(0,C.IRenderManagerService),ee(1,a.IConfigService),ee(2,a.IUniverInstanceService)],exports.DocCanvasView);var Qt=Object.defineProperty,en=Object.getOwnPropertyDescriptor,tn=(i,e,t,n)=>{for(var r=n>1?void 0:n?en(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Qt(e,t,r),r},x=(i,e)=>(t,n)=>e(t,n,i);let Y=class extends a.Disposable{constructor(e,t,n,r,o,s){super();v(this,"_liquid",new C.Liquid);v(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._commandService=r,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:r}=t,o=this._renderManagerService.getRenderById(n);if(o==null)return;const{mainComponent:s,components:c,scene:d}=o,h=s,{left:_,top:m}=h;e.forEach(S=>{const{unitId:I,subUnitId:f,floatingObjectId:p,floatingObject:g}=S,{left:b=0,top:R=0,width:U=0,height:L=0,angle:N,flipX:ce,flipY:le,skewX:de,skewY:ue}=g,y=this._pageMarginCache.get(p),ye=(y==null?void 0:y.marginLeft)||0,De=(y==null?void 0:y.marginTop)||0;r==null||r.getViewModel().getDataModel().updateDrawing(p,{left:b-_-ye,top:R-m-De,height:L,width:U})}),r==null||r.calculate(),s==null||s.makeDirty()})}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{skeleton:t,unitId:n}=e,r=this._renderManagerService.getRenderById(n);if(r==null)return;const{mainComponent:o}=r;o.changeSkeleton(t),this._refreshFloatingObject(n,t,r)})}_commandExecutedListener(){const e=[u.RichTextEditingMutation.id,u.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=this._docSkeletonManagerService.getCurrent();if(s==null)return;const{unitId:c,skeleton:d}=s;if(o!==c)return;const h=this._renderManagerService.getRenderById(c);if(h==null)return;if(this._editorService.isEditor(c)){(n=h.mainComponent)==null||n.makeDirty();return}this._refreshFloatingObject(c,d,h)}}))}_refreshFloatingObject(e,t,n){const r=t==null?void 0:t.getSkeletonData(),{mainComponent:o,scene:s}=n,c=o;if(!r)return;const{left:d,top:h,pageLayoutType:_,pageMarginLeft:m,pageMarginTop:S}=c,{pages:I}=r,f=[];s.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let p=0,g=I.length;p<g;p++){const b=I[p],{skeDrawings:R,marginLeft:U,marginTop:L}=b;this._liquid.translatePagePadding(b),R.forEach(N=>{const{aLeft:ce,aTop:le,height:de,width:ue,objectId:y}=N;f.push({unitId:e,subUnitId:a.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:y,floatingObject:{left:ce+d+this._liquid.x,top:le+h+this._liquid.y,width:ue,height:de}}),this._pageMarginCache.set(y,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.translatePage(b,_,m,S)}this._floatingObjectManagerService.BatchAddOrUpdate(f)}};Y=tn([a.OnLifecycle(a.LifecycleStages.Steady,Y),x(0,O.Inject(u.DocSkeletonManagerService)),x(1,a.IUniverInstanceService),x(2,C.IRenderManagerService),x(3,a.ICommandService),x(4,a.IFloatingObjectManagerService),x(5,l.IEditorService)],Y);var nn=Object.defineProperty,rn=Object.getOwnPropertyDescriptor,on=(i,e,t,n)=>{for(var r=n>1?void 0:n?rn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&nn(e,t,r),r},te=(i,e)=>(t,n)=>e(t,n,i);const sn="rgba(198, 198, 198, 1)",an="rgba(255, 255, 255, 1)";let G=class extends a.Disposable{constructor(i,e,t){super(),this._renderManagerService=i,this._editorService=e,this._currentUniverService=t,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this._renderManagerService.currentRender$.subscribe(i=>{var o;if(i==null)return;const e=this._renderManagerService.getRenderById(i);if(this._editorService.isEditor(i)||this._currentUniverService.getUniverDocInstance(i)==null||e==null)return;const{mainComponent:t}=e,n=t,r=(o=n.getSkeleton())==null?void 0:o.getPageSize();this.disposeWithMe(a.toDisposable(n.onPageRenderObservable.add(s=>{var p,g,b,R;if(this._editorService.isEditor(i))return;const{page:c,pageLeft:d,pageTop:h,ctx:_}=s,{width:m,pageWidth:S,height:I,pageHeight:f}=c;_.save(),_.translate(d-.5,h-.5),C.Rect.drawWith(_,{width:(g=(p=r==null?void 0:r.width)!=null?p:S)!=null?g:m,height:(R=(b=r==null?void 0:r.height)!=null?b:f)!=null?R:I,strokeWidth:1,stroke:sn,fill:an,zIndex:3}),_.restore()})))})}_commandExecutedListener(){}};G=on([a.OnLifecycle(a.LifecycleStages.Rendered,G),te(0,C.IRenderManagerService),te(1,l.IEditorService),te(2,a.IUniverInstanceService)],G);var cn=Object.defineProperty,ln=Object.getOwnPropertyDescriptor,dn=(i,e,t,n)=>{for(var r=n>1?void 0:n?ln(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&cn(e,t,r),r},P=(i,e)=>(t,n)=>e(t,n,i);let q=class extends a.Disposable{constructor(e,t,n,r,o,s){super();v(this,"_initializedRender",new Set);this._docSkeletonManagerService=e,this._currentUniverService=t,this._commandService=n,this._renderManagerService=r,this._textSelectionManagerService=o,this._editorService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._initialRenderRefresh()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t}=e,n=this._renderManagerService.getRenderById(t);if(n==null||this._initializedRender.has(t)||this._editorService.isEditor(t))return;this._initializedRender.add(t);const{scene:r}=n;this.disposeWithMe(a.toDisposable(r.onMouseWheelObserver.add(o=>{if(!o.ctrlKey)return;const s=Math.abs(o.deltaX);let c=s<40?.2:s<80?.4:.2;c*=o.deltaY>0?-1:1,r.scaleX<1&&(c/=2);const d=this._currentUniverService.getCurrentUniverDocInstance(),h=d.zoomRatio;let _=+Number.parseFloat(`${h+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(e=>{if(e==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance().zoomRatio||1;this._updateViewZoom(n,!1)})))}_commandExecutedListener(){const e=[u.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=this._currentUniverService.getCurrentUniverDocInstance(),r=t.params,{unitId:o}=r;if(o!==n.getUnitId())return;const s=n.zoomRatio||1;this._updateViewZoom(s)}}))}_updateViewZoom(e,t=!0){var r;const n=this._getDocObject();n!=null&&(n.scene.scale(e,e),this._calculatePagePosition(n,e),t&&this._textSelectionManagerService.refreshSelection(),(r=n.scene.getTransformer())==null||r.hideControl())}_calculatePagePosition(e,t){const{document:n,scene:r}=e,o=r==null?void 0:r.getParent(),{width:s,height:c,pageMarginLeft:d,pageMarginTop:h}=n;if(o==null||s===Number.POSITIVE_INFINITY||c===Number.POSITIVE_INFINITY)return;const{width:_,height:m}=o;let S=0,I=0,f=0,p=0,g=Number.POSITIVE_INFINITY;_>(s+d*2)*t?(S=_/2-s*t/2,S/=t,f=(_-d*2)/t,g=0):(S=d,f=s+d*2,g=(f-_/t)/2),m>c?(I=m/2-c/2,p=(m-h*2)/t):(I=h,p=c+h*2),r.resize(f,p+200),n.translate(S,I);const b=r.getViewport(u.VIEWPORT_KEY.VIEW_MAIN);if(g!==Number.POSITIVE_INFINITY&&b!=null){const R=b.getBarScroll(g,0).x;b.scrollTo({x:R})}return this}_getDocObject(){return u.getDocObject(this._currentUniverService,this._renderManagerService)}};q=dn([a.OnLifecycle(a.LifecycleStages.Rendered,q),P(0,O.Inject(u.DocSkeletonManagerService)),P(1,a.IUniverInstanceService),P(2,a.ICommandService),P(3,C.IRenderManagerService),P(4,O.Inject(u.TextSelectionManagerService)),P(5,l.IEditorService)],q);var un=Object.defineProperty,pn=Object.getOwnPropertyDescriptor,hn=(i,e,t,n)=>{for(var r=n>1?void 0:n?pn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&un(e,t,r),r},ne=(i,e)=>(t,n)=>e(t,n,i),re;exports.UniverDocsUIPlugin=(re=class extends a.Plugin{constructor(e,t,n,r){super(ve),this._config=e,this._injector=t,this._localeService=n,this._logService=r,this._localeService.load({zhCN:Me}),this._config=a.Tools.deepMerge({},Se,this._config),this._initDependencies(t),this._initializeCommands()}onRendered(){this._initModules(),this._markDocAsFocused()}onDestroy(){}_initializeCommands(){[Ne,Ae,Fe,Be,$e,we,je,ze,We,It,Ot,Ct].forEach(e=>{this._injector.get(l.IShortcutService).registerShortcut(e)})}_initDependencies(e){[[V],[H],[k],[K],[Y],[G],[q],[$,{useFactory:()=>this._injector.createInstance($,this._config)}],[j,{useClass:oe}],[exports.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(),r=n.getUnitId();t.isEditor(r)||e.focusUniverInstance(n.getUnitId())}catch(n){this._logService.warn(n)}}_initModules(){this._injector.get($)}},v(re,"type",a.PluginType.Doc),re);exports.UniverDocsUIPlugin=hn([ne(1,O.Inject(O.Injector)),ne(2,O.Inject(a.LocaleService)),ne(3,a.ILogService)],exports.UniverDocsUIPlugin);exports.DOC_UI_PLUGIN_NAME=ve;exports.DefaultDocContainerConfig=fe;exports.DefaultDocUiConfig=Se;exports.DefaultToolbarConfig=me;exports.enUS=vt;exports.zhCN=Me;
|
|
9
|
+
*/var it=We,ot=Symbol.for("react.element"),st=Symbol.for("react.fragment"),at=Object.prototype.hasOwnProperty,ct=it.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,lt={key:!0,ref:!0,__self:!0,__source:!0};function Ue(i,e,t){var n,r={},o=null,s=null;t!==void 0&&(o=""+t),e.key!==void 0&&(o=""+e.key),e.ref!==void 0&&(s=e.ref);for(n in e)at.call(e,n)&&!lt.hasOwnProperty(n)&&(r[n]=e[n]);if(i&&i.defaultProps)for(n in e=i.defaultProps,e)r[n]===void 0&&(r[n]=e[n]);return{$$typeof:ot,type:i,key:o,ref:s,props:r,_owner:ct.current}}se.Fragment=st;se.jsx=Ue;se.jsxs=Ue;Pe.exports=se;var dt=Pe.exports;const ut="univer-docs-ui-canvas-background",ht={docsUiCanvasBackground:ut},_t=()=>dt.jsx("div",{className:ht.docsUiCanvasBackground});function gt(i){const e=i.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 M.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=P(i);if(c==null)return;const d=(s=c.ts)==null?void 0:s.bl;t.next(d===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function pt(i){const e=i.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 M.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=P(i);if(c==null)return;const d=(s=c.ts)==null?void 0:s.it;t.next(d===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function St(i){const e=i.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 M.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=P(i);if(c==null)return;const d=(s=c.ts)==null?void 0:s.ul;t.next((d==null?void 0:d.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function ft(i){const e=i.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 M.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=P(i);if(c==null)return;const d=(s=c.ts)==null?void 0:s.st;t.next((d==null?void 0:d.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function mt(i){const e=i.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 M.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=P(i);if(c==null)return;const d=(s=c.ts)==null?void 0:s.va;t.next(d===a.BaselineOffset.SUBSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function vt(i){const e=i.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 M.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===u.SetTextSelectionsOperation.id||o===u.SetInlineFormatCommand.id){const c=P(i);if(c==null)return;const d=(s=c.ts)==null?void 0:s.va;t.next(d===a.BaselineOffset.SUPERSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function Ct(i){const e=i.get(a.ICommandService);return{id:u.SetInlineFormatFontFamilyCommand.id,tooltip:"toolbar.font",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,label:De,positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_FAMILY_LIST.map(t=>({label:{name:Ee,hoverable:!0},value:t.value})),value$:new M.Observable(t=>{const n=l.FONT_FAMILY_LIST[0].value,r=e.onCommandExecuted(o=>{var c;const s=o.id;if(s===u.SetTextSelectionsOperation.id||s===u.SetInlineFormatFontFamilyCommand.id){const d=P(i);if(d==null)return;const _=(c=d.ts)==null?void 0:c.ff;t.next(_!=null?_:n)}});return t.next(n),r.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function It(i){const e=i.get(a.ICommandService);return{id:u.SetInlineFormatFontSizeCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:xe,props:{min:1,max:400}},positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_SIZE_LIST,value$:new M.Observable(t=>{const r=e.onCommandExecuted(o=>{var c;const s=o.id;if(s===u.SetTextSelectionsOperation.id||s===u.SetInlineFormatFontSizeCommand.id){const d=P(i);if(d==null)return;const _=(c=d.ts)==null?void 0:c.fs;t.next(_!=null?_:14)}});return t.next(14),r.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function Ot(i){const e=i.get(a.ICommandService),t=i.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:ye,hoverable:!1}}],value$:new M.Observable(n=>{const r=t.getCurrentTheme().textColor,o=e.onCommandExecuted(s=>{if(s.id===u.SetInlineFormatTextColorCommand.id){const c=s.params.value;n.next(c!=null?c:r)}});return n.next(r),o.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.DOC)}}function bt(i){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(i,a.UniverInstanceType.DOC)}}function Mt(i){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(i,a.UniverInstanceType.DOC)}}function P(i){var d;const e=i.get(a.IUniverInstanceService),t=i.get(u.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const o=(d=n.getBody())==null?void 0:d.textRuns;if(o==null)return;const{startOffset:s}=r;return o.find(({st:_,ed:g})=>s>=_&&s<g)}var Rt=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,yt=(i,e,t,n)=>{for(var r=n>1?void 0:n?Tt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Rt(e,t,r),r},U=(i,e)=>(t,n)=>e(t,n,i);let q=class extends a.Disposable{constructor(i,e,t,n,r,o,s){super(),this._injector=i,this._componentManager=e,this._layoutService=t,this._editorService=n,this._menuService=r,this._uiController=o,this._currentUniverService=s,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(ye,je.ColorPicker)),this.disposeWithMe(i.register(De,l.FontFamily)),this.disposeWithMe(i.register(Ee,l.FontFamilyItem)),this.disposeWithMe(i.register(xe,l.FontSize))}_initMenus(){[gt,pt,St,ft,mt,vt,It,Ct,Ot,bt,Mt].forEach(i=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(i)))})}_init(){this._initCustomComponents(),this._initMenus(),this._initDocBackground(),this._initFocusHandler()}_initDocBackground(){const i=this._currentUniverService.getAllUniverDocsInstance()[0].getUnitId();if(i==null)return;this._editorService.isEditor(i)||this.disposeWithMe(this._uiController.registerContentComponent(()=>we.connectInjector(_t,this._injector)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.DOC,()=>{this._injector.get(m.ITextSelectionRenderManager).focus()}))}};q=yt([a.OnLifecycle(a.LifecycleStages.Rendered,q),U(0,O.Inject(O.Injector)),U(1,O.Inject(l.ComponentManager)),U(2,l.ILayoutService),U(3,l.IEditorService),U(4,l.IMenuService),U(5,l.IUIController),U(6,a.IUniverInstanceService)],q);const Dt={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"}},Le={toolbar:{undo:"撤销",redo:"重做",font:"字体",fontSize:"字号",bold:"粗体",italic:"斜体",strikethrough:"删除线",subscript:"下标",superscript:"上标",underline:"下划线",textColor:{main:"文本颜色",right:"颜色选择"},resetColor:"重置颜色",order:"有序列表",unorder:"无序列表"}},Et={id:u.BreakLineCommand.id,preconditions:Ve,binding:l.KeyCode.ENTER},xt={id:u.DeleteLeftCommand.id,preconditions:y,binding:l.KeyCode.BACKSPACE},Pt={id:u.DeleteRightCommand.id,preconditions:y,binding:l.KeyCode.DELETE},Ut=10,Lt=6;function Nt(){return a.Tools.generateRandomId(Lt)}function Bt(i){const e=i.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class $t{constructor(){I(this,"_cache",new a.LRUMap(Ut))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}clear(){this._cache.clear()}}const me=new $t;function pe(i){const e=i.style,t={},n=i.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{t.bl=a.BooleanNumber.TRUE;break}case"s":{t.st={s:a.BooleanNumber.TRUE};break}case"u":{t.ul={s:a.BooleanNumber.TRUE};break}case"i":{t.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=n==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}for(let r=0;r<e.length;r++){const o=e[r],s=e.getPropertyValue(o);switch(o){case"font-family":{t.ff=s;break}case"font-size":{const c=Number.parseInt(s);Number.isNaN(c)||(s.endsWith("pt")?t.fs=c:s.endsWith("px")&&(t.fs=m.pixelToPt(c)));break}case"font-style":{s==="italic"&&(t.it=a.BooleanNumber.TRUE);break}case"font-weight":{Number(s)>400&&(t.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(s)?t.ul={s:a.BooleanNumber.TRUE}:/overline/.test(s)?t.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(s)&&(t.st={s:a.BooleanNumber.TRUE});break}case"color":{const c=new a.ColorKit(s);c.isValid&&(t.cl={rgb:c.toRgbString()});break}case"background-color":{const c=new a.ColorKit(s);c.isValid&&(t.bg={rgb:c.toRgbString()});break}}}return t}function Ft(i){const e=new DOMParser,t=`<x-univer id="univer-root">${i}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function ve(i,e){const t=i.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(i)}const ie=class ie{constructor(){I(this,"_styleCache",new Map);I(this,"_styleRules",[]);I(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=ie._pluginList.find(o=>o.checkPasteType(e)),n=Ft(e),r={dataStream:"",textRuns:[]};return t&&(this._styleRules=[...t.stylesRules],this._afterProcessRules=[...t.afterProcessRules]),this._styleCache.clear(),this._process(null,n==null?void 0:n.childNodes,r),this._styleCache.clear(),this._styleRules=[],this._afterProcessRules=[],r}_process(e,t,n){var r;for(const o of t)if(o.nodeType===Node.TEXT_NODE){const s=(r=o.nodeValue)==null?void 0:r.replace(/[\r\n]/g,"");let c;e&&this._styleCache.has(e)&&(c=this._styleCache.get(e)),n.dataStream+=s,c&&Object.getOwnPropertyNames(c).length&&n.textRuns.push({st:n.dataStream.length-s.length,ed:n.dataStream.length,ts:c})}else if(o.nodeType===Node.ELEMENT_NODE){const s=e?this._styleCache.get(e):{},c=this._styleRules.find(({filter:p})=>ve(o,p)),d=c?c.getStyle(o):pe(o);this._styleCache.set(o,{...s,...d});const{childNodes:_}=o;this._process(o,_,n);const g=this._afterProcessRules.find(({filter:p})=>ve(o,p));g&&g.handler(n,o)}}};I(ie,"_pluginList",[]);let w=ie;const At={name:"univer-doc-paste-plugin-lark",checkPasteType(i){return/lark-record-clipboard/i.test(i)},stylesRules:[{filter:["s"],getStyle(i){const e=pe(i);return{st:{s:a.BooleanNumber.TRUE},...e}}}],afterProcessRules:[{filter(i){return i.tagName==="DIV"&&/ace-line/i.test(i.className)},handler(i){i.paragraphs==null&&(i.paragraphs=[]),i.paragraphs.push({startIndex:i.dataStream.length}),i.dataStream+="\r"}}]};function Ne(i){const e=i.style,t={};for(let n=0;n<e.length;n++){const r=e[n],o=e.getPropertyValue(r);switch(r){case"margin-top":{const s=Number.parseInt(o);t.spaceAbove=/pt/.test(o)?m.ptToPixel(s):s;break}case"margin-bottom":{const s=Number.parseInt(o);t.spaceBelow=/pt/.test(o)?m.ptToPixel(s):s;break}case"line-height":{const s=Number.parseFloat(o);t.lineSpacing=s;break}}}return Object.getOwnPropertyNames(t).length?t:null}const wt={name:"univer-doc-paste-plugin-word",checkPasteType(i){return/word|mso/i.test(i)},stylesRules:[{filter:["b"],getStyle(i){const e=pe(i);return{bl:a.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(i){return i.tagName==="P"&&/mso/i.test(i.className)},handler(i,e){i.paragraphs==null&&(i.paragraphs=[]);const t={startIndex:i.dataStream.length},n=Ne(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]},jt={name:"univer-doc-paste-plugin-univer",checkPasteType(i){return/UniverNormal/i.test(i)},stylesRules:[],afterProcessRules:[{filter(i){return i.tagName==="P"&&/UniverNormal/i.test(i.className)},handler(i,e){i.paragraphs==null&&(i.paragraphs=[]);const t={startIndex:i.dataStream.length},n=Ne(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]};function Ce(i,e){const{st:t,ed:n,ts:r={}}=e,{ff:o,fs:s,it:c,bl:d,ul:_,st:g,ol:p,bg:C,cl:f,va:v}=r;let h=i.slice(t,n);const S=[];return c===a.BooleanNumber.TRUE&&(h=`<i>${h}</i>`),v===a.BaselineOffset.SUPERSCRIPT?h=`<sup>${h}</sup>`:v===a.BaselineOffset.SUBSCRIPT&&(h=`<sub>${h}</sub>`),(_==null?void 0:_.s)===a.BooleanNumber.TRUE&&(h=`<u>${h}</u>`),(g==null?void 0:g.s)===a.BooleanNumber.TRUE&&(h=`<s>${h}</s>`),d===a.BooleanNumber.TRUE&&(h=`<strong>${h}</strong>`),o&&S.push(`font-family: ${o}`),f&&S.push(`color: ${f.rgb}`),s&&S.push(`font-size: ${s}pt`),p&&S.push("text-decoration: overline"),C&&S.push(`background: ${C.rgb}`),S.length?`<span style="${S.join("; ")};">${h}</span>`:h}function ce(i,e,t){const{dataStream:n,textRuns:r=[]}=i;let o=e;const s=[];for(const c of r){const{st:d,ed:_}=c;a.Tools.hasIntersectionBetweenTwoRanges(e,t,d,_)&&(d>o?(s.push(n.slice(o,d)),s.push(Ce(n,{...c,ed:Math.min(_,t)}))):s.push(Ce(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 Ie(i,e=!0){var t;if(e&&((t=i.paragraphs)!=null&&t.length)){const{dataStream:n,paragraphs:r=[]}=i;let o="",s=-1;for(const c of r){const{startIndex:d,paragraphStyle:_={}}=c,{spaceAbove:g,spaceBelow:p,lineSpacing:C}=_,f=[];g!=null&&(typeof g=="number"?f.push(`margin-top: ${g}px`):f.push(`margin-top: ${g.v}px`)),p!=null&&(typeof p=="number"?f.push(`margin-bottom: ${p}px`):f.push(`margin-bottom: ${p.v}px`)),C!=null&&f.push(`line-height: ${C}`),d>s+1?o+=`<p class="UniverNormal" ${f.length?`style="${f.join("; ")};"`:""}>${ce(i,s+1,d)}</p>`:o+=`<p class="UniverNormal" ${f.length?`style="${f.join("; ")};"`:""}></p>`,s=d}return s!==n.length&&(o+=ce(i,s,n.length)),o}else return ce(i,0,i.dataStream.length)}class Wt{convert(e){if(e.length===0)throw new Error("The bodyList length at least to be 1");if(e.length===1)return Ie(e[0]);let t="";for(const n of e)t+='<p className="UniverNormal">',t+=Ie(n,!1),t+="</p>";return t}}var Vt=Object.defineProperty,kt=Object.getOwnPropertyDescriptor,zt=(i,e,t,n)=>{for(var r=n>1?void 0:n?kt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Vt(e,t,r),r},j=(i,e)=>(t,n)=>e(t,n,i);w.use(wt);w.use(At);w.use(jt);function Ht(i){const e=i.replace(/\n/g,"\r"),t=[];for(let n=0;n<e.length;n++)e[n]==="\r"&&t.push({startIndex:n});return{dataStream:e,paragraphs:t}}const z=O.createIdentifier("doc.clipboard-service");let ge=class extends a.Disposable{constructor(e,t,n,r,o){super();I(this,"_clipboardHooks",[]);I(this,"_htmlToUDM",new w);I(this,"_umdToHtml",new Wt);this._currentUniverService=e,this._logService=t,this._commandService=n,this._clipboardInterfaceService=r,this._textSelectionManagerService=o}async copy(){const e=this._getDocumentBodyInRanges();if(e.length===0)return!1;try{this._setClipboardData(e)}catch(t){return this._logService.error("[DocClipboardService] copy failed",t),!1}return!0}async cut(){return this._cut()}async paste(e){const t=await this._generateBodyFromClipboardItems(e);return this._paste(t)}async legacyPaste(e,t){const n=this._generateBodyFromHtmlAndText(e,t);return this._paste(n)}async _cut(){var o;const{segmentId:e,endOffset:t,style:n}=(o=this._textSelectionManagerService.getActiveRange())!=null?o:{},r=this._textSelectionManagerService.getSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),t==null||r==null)return!1;this.copy();try{let s=t;for(const d of r){const{startOffset:_,endOffset:g}=d;_==null||g==null||g<=t&&(s-=g-_)}const c=[{startOffset:s,endOffset:s,style:n}];return this._commandService.executeCommand(u.CutContentCommand.id,{segmentId:e,textRanges:c})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(e){var s;const{segmentId:t,endOffset:n,style:r}=(s=this._textSelectionManagerService.getActiveRange())!=null?s:{},o=this._textSelectionManagerService.getSelections();if(t==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),n==null||o==null)return!1;try{let c=n;for(const _ of o){const{startOffset:g,endOffset:p}=_;g==null||p==null||p<=n&&(c+=e.dataStream.length-(p-g))}const d=[{startOffset:c,endOffset:c,style:r}];return this._commandService.executeCommand(u.InnerPasteCommand.id,{body:e,segmentId:t,textRanges:d})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(e){const t=Nt(),n=e.length>1?e.map(o=>o.dataStream).join(`
|
|
10
|
+
`):e[0].dataStream;let r=this._umdToHtml.convert(e);return e.length===1&&(r=r.replace(/(<[a-z]+)/,(o,s)=>`${s} data-copy-id="${t}"`),me.set(t,e[0])),this._clipboardInterfaceService.write(n,r)}addClipboardHook(e){return this._clipboardHooks.push(e),a.toDisposable(()=>{const t=this._clipboardHooks.indexOf(e);t>-1&&this._clipboardHooks.splice(t,1)})}_getDocumentBodyInRanges(){const e=this._textSelectionManagerService.getSelections(),t=this._currentUniverService.getCurrentUniverDocInstance(),n=[];if(e==null)return n;for(const r of e){const{startOffset:o,endOffset:s,collapsed:c}=r;if(c||o==null||s==null)continue;const d=t.sliceBody(o,s);d!=null&&n.push(d)}return n}async _generateBodyFromClipboardItems(e){try{let t="",n="";for(const r of e)for(const o of r.types)o===l.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await r.getType(o).then(s=>s&&s.text()):o===l.HTML_CLIPBOARD_MIME_TYPE&&(t=await r.getType(o).then(s=>s&&s.text()));return this._generateBodyFromHtmlAndText(t,n)}catch(t){return Promise.reject(t)}}_generateBodyFromHtmlAndText(e,t){if(!e){if(t)return Ht(t);throw new Error("[DocClipboardService] html and text cannot be both empty!")}const n=Bt(e);if(n){const r=me.get(n);if(r)return r}return this._htmlToUDM.convert(e)}};ge=zt([j(0,a.IUniverInstanceService),j(1,a.ILogService),j(2,a.ICommandService),j(3,l.IClipboardInterfaceService),j(4,O.Inject(u.TextSelectionManagerService))],ge);function ae(i){return i.getContextValue(a.FOCUSING_DOC)||i.getContextValue(a.EDITOR_ACTIVATED)}const Se=999,Yt={id:l.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:Se,preconditions:ae,handler:async i=>i.get(z).copy()},Gt={id:l.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:Se,preconditions:ae,handler:async i=>i.get(z).cut()},Kt={id:l.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:Se,preconditions:ae,handler:async i=>{const e=i.get(z),n=await i.get(l.IClipboardInterfaceService).read();return n.length===0?!1:e.paste(n)}};var qt=Object.defineProperty,Xt=Object.getOwnPropertyDescriptor,Zt=(i,e,t,n)=>{for(var r=n>1?void 0:n?Xt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&qt(e,t,r),r},W=(i,e)=>(t,n)=>e(t,n,i);let X=class extends a.RxDisposable{constructor(i,e,t,n,r){super(),this._commandService=i,this._clipboardInterfaceService=e,this._docClipboardService=t,this._textSelectionRenderManager=n,this._contextService=r,this._init()}_init(){[Yt,Gt,Kt].forEach(i=>this.disposeWithMe(this._commandService.registerMultipleCommand(i))),[u.InnerPasteCommand,u.CutContentCommand].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i))),this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var i;(i=this._textSelectionRenderManager)==null||i.onPaste$.pipe(M.takeUntil(this.dispose$)).subscribe(e=>{var o,s;if(!ae(this._contextService))return;e.event.preventDefault();const t=e.event,n=(o=t.clipboardData)==null?void 0:o.getData("text/html"),r=(s=t.clipboardData)==null?void 0:s.getData("text/plain");this._docClipboardService.legacyPaste(n,r)})}};X=Zt([a.OnLifecycle(a.LifecycleStages.Steady,X),W(0,a.ICommandService),W(1,l.IClipboardInterfaceService),W(2,z),W(3,m.ITextSelectionRenderManager),W(4,a.IContextService)],X);var Jt=Object.defineProperty,Qt=Object.getOwnPropertyDescriptor,en=(i,e,t,n)=>{for(var r=n>1?void 0:n?Qt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Jt(e,t,r),r},$=(i,e)=>(t,n)=>e(t,n,i);let Z=class extends a.Disposable{constructor(e,t,n,r,o,s){super();I(this,"_initialEditors",new Set);this._currentUniverService=e,this._docSkeletonManagerService=t,this._editorService=n,this._commandService=r,this._textSelectionRenderManager=o,this._renderManagerService=s,this._initialize()}_initialize(){this.disposeWithMe(this._editorService.resize$.subscribe(e=>{this._resize(e)})),this._editorService.getAllEditor().forEach(e=>{const t=e.editorUnitId;this._initialEditors.has(t)||(this._initialEditors.add(t),this._resize(t))}),this._commandExecutedListener(),this._initialSetValue(),this._initialBlur(),this._initialFocus(),this._initialValueChange()}_resize(e){var D,E,x;if(e==null)return;const t=this._editorService.getEditor(e);if((t==null?void 0:t.cancelDefaultResizeListener)===!0)return;const n=(D=this._docSkeletonManagerService.getSkeletonByUnitId(e))==null?void 0:D.skeleton,r=this._currentUniverService.getUniverDocInstance(e);if(t==null||t.render==null||n==null||r==null)return;n.calculate();const{marginTop:o=0,marginBottom:s=0,marginLeft:c=0,marginRight:d=0}=r.getSnapshot().documentStyle,{scene:_,mainComponent:g}=t.render;let{actualHeight:p,actualWidth:C}=n.getActualSize();p+=o+s,C+=c+d;const{width:f,height:v}=t.getBoundingClientRect(),h=_.getViewport(u.VIEWPORT_KEY.VIEW_MAIN);let S=h==null?void 0:h.getScrollBar();const b=Math.max(C,f),R=Math.max(p,v);_.transformByState({width:b,height:R}),g==null||g.resize(b,R),t.isSingle()?C>f?S==null?h&&new m.ScrollBar(h,{barSize:8,enableVertical:!1}):h==null||h.resetSizeAndScrollBar():(S=null,h==null||h.scrollTo({x:0,y:0}),(x=h==null?void 0:h.getScrollBar())==null||x.dispose()):p>v?S==null?h&&new m.ScrollBar(h,{enableHorizontal:!1,barSize:8}):h==null||h.resetSizeAndScrollBar():(S=null,h==null||h.scrollTo({x:0,y:0}),(E=h==null?void 0:h.getScrollBar())==null||E.dispose())}_initialSetValue(){this.disposeWithMe(this._editorService.setValue$.subscribe(e=>{this._commandService.executeCommand(u.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 r=n.getUnitId(),o=this._renderManagerService.getRenderById(r),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=[u.RichTextEditingMutation.id,l.SetEditorResizeOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=t.params,{unitId:r}=n;if(this._editorService.isSheetEditor(r))return;this._resize(r),this._valueChange()}}))}};Z=en([a.OnLifecycle(a.LifecycleStages.Rendered,Z),$(0,a.IUniverInstanceService),$(1,O.Inject(u.DocSkeletonManagerService)),$(2,l.IEditorService),$(3,a.ICommandService),$(4,m.ITextSelectionRenderManager),$(5,m.IRenderManagerService)],Z);var tn=Object.defineProperty,nn=Object.getOwnPropertyDescriptor,rn=(i,e,t,n)=>{for(var r=n>1?void 0:n?nn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&tn(e,t,r),r},K=(i,e)=>(t,n)=>e(t,n,i);let J=class extends a.RxDisposable{constructor(e,t,n,r){super();I(this,"_docRenderMap",new Set);this._docSkeletonManagerService=e,this._renderManagerService=t,this._commandService=n,this._editorService=r,this._initialRenderRefresh(),this._commandExecutedListener()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(M.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)})}_create(e){if(e==null)return;const{skeleton:t,unitId:n}=e;let r=this._renderManagerService.getRenderById(n);r==null&&(this._renderManagerService.create(n),r=this._renderManagerService.getRenderById(n));const{mainComponent:o}=r;o.changeSkeleton(t),this._recalculateSizeBySkeleton(r,t)}_recalculateSizeBySkeleton(e,t){var g;const{mainComponent:n,scene:r,unitId:o}=e,s=n,c=(g=t.getSkeletonData())==null?void 0:g.pages;if(c==null)return;let d=0,_=0;for(let p=0,C=c.length;p<C;p++){const f=c[p],{pageWidth:v,pageHeight:h}=f;s.pageLayoutType===m.PageLayoutType.VERTICAL?(_+=h,_+=s.pageMarginTop,p===C-1&&(_+=s.pageMarginTop),d=Math.max(d,v)):s.pageLayoutType===m.PageLayoutType.HORIZONTAL&&(d+=v,p!==C-1&&(d+=s.pageMarginLeft),_=Math.max(_,h))}s.resize(d,_),this._editorService.isEditor(o)||r.resize(d,_)}_commandExecutedListener(){const e=[u.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=this._docSkeletonManagerService.getSkeletonByUnitId(o);if(s==null)return;const{skeleton:c}=s,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)}}))}};J=rn([a.OnLifecycle(a.LifecycleStages.Rendered,J),K(0,O.Inject(u.DocSkeletonManagerService)),K(1,m.IRenderManagerService),K(2,a.ICommandService),K(3,l.IEditorService)],J);var on=Object.defineProperty,sn=Object.getOwnPropertyDescriptor,an=(i,e,t,n)=>{for(var r=n>1?void 0:n?sn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&on(e,t,r),r},le=(i,e)=>(t,n)=>e(t,n,i);exports.DocCanvasView=class extends a.RxDisposable{constructor(t,n,r){super();I(this,"_scene");I(this,"_currentDocumentModel");I(this,"_fps$",new M.BehaviorSubject(""));I(this,"fps$",this._fps$.asObservable());this._renderManagerService=t,this._configService=n,this._currentUniverService=r,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(),r=t.getContainer(),o=t.getParentRenderUnitId();if(r!=null&&o!=null)throw new Error("container or parentRenderUnitId can only exist one");r==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 _=new m.Viewport(u.VIEWPORT_KEY.VIEW_MAIN,c,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});c.attachControl(),c.on(m.EVENT_TYPE.wheel,(C,f)=>{const v=C;if(v.ctrlKey){const h=Math.abs(v.deltaX);let S=h<40?.2:h<80?.4:.2;S*=v.deltaY>0?-1:1,c.scaleX<1&&(S/=2),c.scaleX+S>4?c.scale(4,4):c.scaleX+S<.1?c.scale(.1,.1):v.preventDefault()}else _.onMouseWheel(v,f)}),this._configService.getConfig("hasScroll")!==!1&&new m.ScrollBar(_),c.addLayer(new m.Layer(c,[],u.DOCS_COMPONENT_MAIN_LAYER_INDEX),new m.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(t){const n=this._scene,r=this._currentDocumentModel,o=new m.Documents(u.DOCS_VIEW_KEY.MAIN,void 0,{pageMarginLeft:r.documentStyle.marginLeft||0,pageMarginTop:r.documentStyle.marginTop||0});o.zIndex=u.DOCS_COMPONENT_DEFAULT_Z_INDEX,t.mainComponent=o,t.components.set(u.DOCS_VIEW_KEY.MAIN,o),n.addObjects([o],u.DOCS_COMPONENT_MAIN_LAYER_INDEX)}};exports.DocCanvasView=an([a.OnLifecycle(a.LifecycleStages.Starting,exports.DocCanvasView),le(0,m.IRenderManagerService),le(1,a.IConfigService),le(2,a.IUniverInstanceService)],exports.DocCanvasView);var cn=Object.defineProperty,ln=Object.getOwnPropertyDescriptor,dn=(i,e,t,n)=>{for(var r=n>1?void 0:n?ln(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&cn(e,t,r),r},F=(i,e)=>(t,n)=>e(t,n,i);let Q=class extends a.Disposable{constructor(e,t,n,r,o,s){super();I(this,"_liquid",new m.Liquid);I(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._commandService=r,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:r}=t,o=this._renderManagerService.getRenderById(n);if(o==null)return;const{mainComponent:s,components:c,scene:d}=o,_=s,{left:g,top:p}=_;e.forEach(C=>{const{unitId:f,subUnitId:v,floatingObjectId:h,floatingObject:S}=C,{left:b=0,top:R=0,width:D=0,height:E=0,angle:x,flipX:N,flipY:B,skewX:H,skewY:Y}=S,T=this._pageMarginCache.get(h),Be=(T==null?void 0:T.marginLeft)||0,$e=(T==null?void 0:T.marginTop)||0;r==null||r.getViewModel().getDataModel().updateDrawing(h,{left:b-g-Be,top:R-p-$e,height:E,width:D})}),r==null||r.calculate(),s==null||s.makeDirty()})}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{skeleton:t,unitId:n}=e,r=this._renderManagerService.getRenderById(n);if(r==null)return;const{mainComponent:o}=r;o.changeSkeleton(t),this._refreshFloatingObject(n,t,r)})}_commandExecutedListener(){const e=[u.RichTextEditingMutation.id,u.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=this._docSkeletonManagerService.getCurrent();if(s==null)return;const{unitId:c,skeleton:d}=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,d,_)}}))}_refreshFloatingObject(e,t,n){const r=t==null?void 0:t.getSkeletonData(),{mainComponent:o,scene:s}=n,c=o;if(!r)return;const{left:d,top:_,pageLayoutType:g,pageMarginLeft:p,pageMarginTop:C}=c,{pages:f}=r,v=[];s.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let h=0,S=f.length;h<S;h++){const b=f[h],{skeDrawings:R,marginLeft:D,marginTop:E}=b;this._liquid.translatePagePadding(b),R.forEach(x=>{const{aLeft:N,aTop:B,height:H,width:Y,objectId:T}=x;v.push({unitId:e,subUnitId:a.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:T,floatingObject:{left:N+d+this._liquid.x,top:B+_+this._liquid.y,width:Y,height:H}}),this._pageMarginCache.set(T,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.translatePage(b,g,p,C)}this._floatingObjectManagerService.BatchAddOrUpdate(v)}};Q=dn([a.OnLifecycle(a.LifecycleStages.Steady,Q),F(0,O.Inject(u.DocSkeletonManagerService)),F(1,a.IUniverInstanceService),F(2,m.IRenderManagerService),F(3,a.ICommandService),F(4,a.IFloatingObjectManagerService),F(5,l.IEditorService)],Q);var un=Object.defineProperty,hn=Object.getOwnPropertyDescriptor,_n=(i,e,t,n)=>{for(var r=n>1?void 0:n?hn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&un(e,t,r),r},de=(i,e)=>(t,n)=>e(t,n,i);const gn="rgba(198, 198, 198, 1)",pn="rgba(255, 255, 255, 1)";let ee=class extends a.Disposable{constructor(i,e,t){super(),this._renderManagerService=i,this._editorService=e,this._currentUniverService=t,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this._renderManagerService.currentRender$.subscribe(i=>{var o;if(i==null)return;const e=this._renderManagerService.getRenderById(i);if(this._editorService.isEditor(i)||this._currentUniverService.getUniverDocInstance(i)==null||e==null)return;const{mainComponent:t}=e,n=t,r=(o=n.getSkeleton())==null?void 0:o.getPageSize();this.disposeWithMe(a.toDisposable(n.onPageRenderObservable.add(s=>{var h,S,b,R;if(this._editorService.isEditor(i))return;const{page:c,pageLeft:d,pageTop:_,ctx:g}=s,{width:p,pageWidth:C,height:f,pageHeight:v}=c;g.save(),g.translate(d-.5,_-.5),m.Rect.drawWith(g,{width:(S=(h=r==null?void 0:r.width)!=null?h:C)!=null?S:p,height:(R=(b=r==null?void 0:r.height)!=null?b:v)!=null?R:f,strokeWidth:1,stroke:gn,fill:pn,zIndex:3}),g.restore()})))})}_commandExecutedListener(){}};ee=_n([a.OnLifecycle(a.LifecycleStages.Rendered,ee),de(0,m.IRenderManagerService),de(1,l.IEditorService),de(2,a.IUniverInstanceService)],ee);var Sn=Object.defineProperty,fn=Object.getOwnPropertyDescriptor,mn=(i,e,t,n)=>{for(var r=n>1?void 0:n?fn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Sn(e,t,r),r},A=(i,e)=>(t,n)=>e(t,n,i);let te=class extends a.Disposable{constructor(e,t,n,r,o,s){super();I(this,"_initializedRender",new Set);this._docSkeletonManagerService=e,this._currentUniverService=t,this._commandService=n,this._renderManagerService=r,this._textSelectionManagerService=o,this._editorService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._initialRenderRefresh()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t}=e,n=this._renderManagerService.getRenderById(t);if(n==null||this._initializedRender.has(t)||this._editorService.isEditor(t))return;this._initializedRender.add(t);const{scene:r}=n;this.disposeWithMe(a.toDisposable(r.onMouseWheelObserver.add(o=>{if(!o.ctrlKey)return;const s=Math.abs(o.deltaX);let c=s<40?.2:s<80?.4:.2;c*=o.deltaY>0?-1:1,r.scaleX<1&&(c/=2);const d=this._currentUniverService.getCurrentUniverDocInstance(),_=d.zoomRatio;let g=+Number.parseFloat(`${_+c}`).toFixed(1);g=g>=4?4:g<=.1?.1:g,this._commandService.executeCommand(u.SetDocZoomRatioCommand.id,{zoomRatio:g,unitId:d.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=[u.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=this._currentUniverService.getCurrentUniverDocInstance(),r=t.params,{unitId:o}=r;if(o!==n.getUnitId())return;const s=n.zoomRatio||1;this._updateViewZoom(s)}}))}_updateViewZoom(e,t=!0){var r;const n=this._getDocObject();n!=null&&(n.scene.scale(e,e),this._calculatePagePosition(n,e),t&&this._textSelectionManagerService.refreshSelection(),(r=n.scene.getTransformer())==null||r.hideControl())}_calculatePagePosition(e,t){const{document:n,scene:r}=e,o=r==null?void 0:r.getParent(),{width:s,height:c,pageMarginLeft:d,pageMarginTop:_}=n;if(o==null||s===Number.POSITIVE_INFINITY||c===Number.POSITIVE_INFINITY)return;const{width:g,height:p}=o;let C=0,f=0,v=0,h=0,S=Number.POSITIVE_INFINITY;g>(s+d*2)*t?(C=g/2-s*t/2,C/=t,v=(g-d*2)/t,S=0):(C=d,v=s+d*2,S=(v-g/t)/2),p>c?(f=p/2-c/2,h=(p-_*2)/t):(f=_,h=c+_*2),r.resize(v,h+200),n.translate(C,f);const b=r.getViewport(u.VIEWPORT_KEY.VIEW_MAIN);if(S!==Number.POSITIVE_INFINITY&&b!=null){const R=b.getBarScroll(S,0).x;b.scrollTo({x:R})}return this}_getDocObject(){return u.getDocObject(this._currentUniverService,this._renderManagerService)}};te=mn([a.OnLifecycle(a.LifecycleStages.Rendered,te),A(0,O.Inject(u.DocSkeletonManagerService)),A(1,a.IUniverInstanceService),A(2,a.ICommandService),A(3,m.IRenderManagerService),A(4,O.Inject(u.TextSelectionManagerService)),A(5,l.IEditorService)],te);var vn=Object.defineProperty,Cn=Object.getOwnPropertyDescriptor,In=(i,e,t,n)=>{for(var r=n>1?void 0:n?Cn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&vn(e,t,r),r},L=(i,e)=>(t,n)=>e(t,n,i);let ne=class extends a.Disposable{constructor(e,t,n,r,o,s,c){super();I(this,"_loadedMap",new WeakSet);this._docSkeletonManagerService=e,this._currentUniverService=t,this._commandService=n,this._renderManagerService=r,this._textSelectionRenderManager=o,this._textSelectionManagerService=s,this._editorService=c,this._initialize()}_initialize(){this._init(),this._skeletonListener(),this._commandExecutedListener()}_init(){this.disposeWithMe(this._renderManagerService.currentRender$.subscribe(e=>{this._create(e)})),this._renderManagerService.getRenderAll().forEach((e,t)=>{this._create(t)})}_create(e){if(e==null||this._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:r}=t;this.disposeWithMe(a.toDisposable(n.onPointerEnterObserver.add(()=>{this._isEditorReadOnly(e)||(n.cursor=m.CURSOR_TYPE.TEXT)}))),this.disposeWithMe(a.toDisposable(n.onPointerLeaveObserver.add(()=>{n.cursor=m.CURSOR_TYPE.DEFAULT,r.resetCursor()}))),this.disposeWithMe(a.toDisposable(n==null?void 0:n.onPointerDownObserver.add((o,s)=>{if(this._isEditorReadOnly(e))return;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=[u.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=(n=this._textSelectionManagerService.getCurrentSelection())==null?void 0:n.unitId;if(o!==s)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t,skeleton:n}=e,r=this._renderManagerService.getRenderById(t);if(r==null)return;const{scene:o,mainComponent:s}=r;this._textSelectionRenderManager.changeRuntime(n,o,s),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:t,subUnitId:""})}))}_getDocObjectById(e){return u.getDocObjectById(e,this._renderManagerService)}};ne=In([a.OnLifecycle(a.LifecycleStages.Rendered,ne),L(0,O.Inject(u.DocSkeletonManagerService)),L(1,a.IUniverInstanceService),L(2,a.ICommandService),L(3,m.IRenderManagerService),L(4,m.ITextSelectionRenderManager),L(5,O.Inject(u.TextSelectionManagerService)),L(6,l.IEditorService)],ne);var On=Object.defineProperty,bn=Object.getOwnPropertyDescriptor,Mn=(i,e,t,n)=>{for(var r=n>1?void 0:n?bn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&On(e,t,r),r},V=(i,e)=>(t,n)=>e(t,n,i);const Oe=1.5;let re=class extends a.RxDisposable{constructor(i,e,t,n,r){super(),this._docSkeletonManagerService=i,this._textSelectionManagerService=e,this._editorService=t,this._currentUniverService=n,this._renderManagerService=r,this._init()}_init(){this._textSelectionManagerService.textSelection$.pipe(M.takeUntil(this.dispose$)).subscribe(i=>{if(i==null)return;const{isEditing:e,unitId:t}=i;e&&this._scrollToSelection(t)})}_scrollToSelection(i){var T;const e=this._textSelectionManagerService.getActiveRange(),t=this._getDocObject(),n=(T=this._docSkeletonManagerService.getCurrent())==null?void 0:T.skeleton;if(e==null||t==null||n==null)return;const{collapsed:r,startNodePosition:o}=e;if(!r)return;const s=t.document.getOffsetConfig(),{docsLeft:c,docsTop:d}=s,_=new m.NodePositionConvertToCursor(s,n),{contentBoxPointGroup:g}=_.getRangePointData(o,o),{left:p,top:C,height:f}=m.getAnchorBounding(g),v=p+c,h=C+d,S=t.scene.getViewport(u.VIEWPORT_KEY.VIEW_MAIN),b=!!this._editorService.getEditor(i);if(S==null)return;const{left:R,top:D,right:E,bottom:x}=S.getBounding().viewBound;let N=0,B=0;const H=b?0:100;h<D?N=h-D:h>x-f&&(N=h-x+f+H),v<R?B=v-R:v>E-Oe&&(B=v-E+Oe);const Y=S.getBarScroll(B,N);S.scrollBy(Y)}_getDocObject(){return u.getDocObject(this._currentUniverService,this._renderManagerService)}};re=Mn([a.OnLifecycle(a.LifecycleStages.Rendered,re),V(0,O.Inject(u.DocSkeletonManagerService)),V(1,O.Inject(u.TextSelectionManagerService)),V(2,l.IEditorService),V(3,a.IUniverInstanceService),V(4,m.IRenderManagerService)],re);var Rn=Object.defineProperty,Tn=Object.getOwnPropertyDescriptor,yn=(i,e,t,n)=>{for(var r=n>1?void 0:n?Tn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Rn(e,t,r),r},ue=(i,e)=>(t,n)=>e(t,n,i),he;exports.UniverDocsUIPlugin=(he=class extends a.Plugin{constructor(e,t,n,r){super(Te),this._config=e,this._injector=t,this._localeService=n,this._logService=r,this._localeService.load({zhCN:Le}),this._config=a.Tools.deepMerge({},Re,this._config),this._initDependencies(t),this._initializeCommands()}onRendered(){this._initModules(),this._markDocAsFocused()}onDestroy(){}_initializeCommands(){[ke,ze,Ye,He,Ge,Ke,qe,Xe,Ze,xt,Pt,Et].forEach(e=>{this._injector.get(l.IShortcutService).registerShortcut(e)})}_initDependencies(e){[[q],[X],[Z],[J],[Q],[ee],[te],[ne],[re],[k,{useFactory:()=>this._injector.createInstance(k,this._config)}],[z,{useClass:ge}],[exports.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(),r=n.getUnitId();t.isEditor(r)||e.focusUniverInstance(n.getUnitId())}catch(n){this._logService.warn(n)}}_initModules(){this._injector.get(k)}},I(he,"type",a.PluginType.Doc),he);exports.UniverDocsUIPlugin=yn([ue(1,O.Inject(O.Injector)),ue(2,O.Inject(a.LocaleService)),ue(3,a.ILogService)],exports.UniverDocsUIPlugin);exports.DOC_UI_PLUGIN_NAME=Te;exports.DefaultDocContainerConfig=Me;exports.DefaultDocUiConfig=Re;exports.DefaultToolbarConfig=be;exports.enUS=Dt;exports.zhCN=Le;
|