@univerjs/docs-ui 0.1.0-beta.5 → 0.1.2
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 +10 -2
- package/lib/es/index.js +1431 -664
- package/lib/index.css +1 -0
- package/lib/types/controllers/app-ui-controller.d.ts +2 -2
- package/lib/types/controllers/back-scroll.controller.d.ts +30 -0
- package/lib/types/controllers/doc-editor-bridge.controller.d.ts +39 -0
- package/lib/types/controllers/doc-render.controller.d.ts +31 -0
- package/lib/types/controllers/doc-ui.controller.d.ts +8 -5
- package/lib/types/controllers/floating-object.controller.d.ts +35 -0
- package/lib/types/controllers/page-render.controller.d.ts +27 -0
- package/lib/types/controllers/text-selection.controller.d.ts +39 -0
- package/lib/types/controllers/zoom.controller.d.ts +37 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/locale/en-US.d.ts +3 -21
- package/lib/types/locale/zh-CN.d.ts +2 -2
- package/lib/types/services/clipboard/html-to-udm/utils.d.ts +0 -1
- package/lib/types/shortcuts/utils.d.ts +18 -0
- package/lib/types/views/doc-background/DocBackground.d.ts +20 -0
- package/lib/types/views/doc-canvas-view.d.ts +32 -0
- package/lib/umd/index.js +10 -2
- package/package.json +12 -12
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,2 +1,10 @@
|
|
|
1
|
-
"use strict";var oe=Object.defineProperty;var re=(e,t,n)=>t in e?oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var h=(e,t,n)=>(re(e,typeof t!="symbol"?t+"":t,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),g=require("@wendellhu/redi"),c=require("@univerjs/ui"),d=require("@univerjs/docs"),Y=require("@univerjs/engine-render"),ie=require("@univerjs/design"),S=require("rxjs"),k={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},q={outerLeft:!1,outerRight:!1,header:!0,footer:!0,innerLeft:!1,innerRight:!1,frozenHeaderLT:!1,frozenHeaderRT:!1,frozenHeaderLM:!1,frozenContent:!1,infoBar:!0,toolbar:!0},Z={layout:{docContainerConfig:q,toolbarConfig:k}},X="DocUI",se={id:d.MoveCursorOperation.id,binding:c.KeyCode.ARROW_UP,preconditions:e=>e.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.UP}},ae={id:d.MoveCursorOperation.id,binding:c.KeyCode.ARROW_DOWN,preconditions:e=>e.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.DOWN}},ce={id:d.MoveCursorOperation.id,binding:c.KeyCode.ARROW_LEFT,preconditions:e=>e.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.LEFT}},le={id:d.MoveCursorOperation.id,binding:c.KeyCode.ARROW_RIGHT,preconditions:e=>e.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.RIGHT}},de={id:d.MoveSelectionOperation.id,binding:c.KeyCode.ARROW_UP|c.MetaKeys.SHIFT,preconditions:e=>e.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.UP}},ue={id:d.MoveSelectionOperation.id,binding:c.KeyCode.ARROW_DOWN|c.MetaKeys.SHIFT,preconditions:e=>e.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.DOWN}},pe={id:d.MoveSelectionOperation.id,binding:c.KeyCode.ARROW_LEFT|c.MetaKeys.SHIFT,preconditions:e=>e.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.LEFT}},me={id:d.MoveSelectionOperation.id,binding:c.KeyCode.ARROW_RIGHT|c.MetaKeys.SHIFT,preconditions:e=>e.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.RIGHT}},fe={id:d.SelectAllOperation.id,binding:c.KeyCode.A|c.MetaKeys.CTRL_COMMAND,preconditions:e=>e.getContextValue(a.FOCUSING_DOC)||e.getContextValue(a.EDITOR_ACTIVATED)};var he=Object.defineProperty,ge=Object.getOwnPropertyDescriptor,Ce=(e,t,n,o)=>{for(var r=o>1?void 0:o?ge(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=(o?s(t,n,r):s(r))||r);return o&&r&&he(t,n,r),r},G=(e,t)=>(n,o)=>t(n,o,e);let $=class{constructor(e,t,n){h(this,"_docContainer");h(this,"getComponent",e=>{if(this._docContainer=e,!e.getContentRef().current)throw new Error("container is not ready")});h(this,"changeLocale",e=>{this._localeService.setLocale(e)});this._config=e,this._localeService=t,this._injector=n}getUIConfig(){return{injector:this._injector,config:this._config,changeLocale:this.changeLocale,getComponent:this.getComponent}}getContentRef(){return this._docContainer.getContentRef()}UIDidMount(e){if(this._docContainer)return e(this._docContainer)}getDocContainer(){return this._docContainer}};$=Ce([G(1,g.Inject(a.LocaleService)),G(2,g.Inject(g.Injector))],$);var _e=Object.defineProperty,Se=Object.getOwnPropertyDescriptor,Oe=(e,t,n,o)=>{for(var r=o>1?void 0:o?Se(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=(o?s(t,n,r):s(r))||r);return o&&r&&_e(t,n,r),r},P=(e,t)=>(n,o)=>t(n,o,e);let R=class extends a.RxDisposable{constructor(t,n,o,r,i){super();h(this,"_docContainerController");h(this,"changeLocale",t=>{this._localeService.setLocale(t)});this._localeService=n,this._injector=o,this._textSelectionRenderManager=r,this._layoutService=i,this._docContainerController=this._injector.createInstance($,t),this._registerContainer()}_registerContainer(){this._layoutService&&this.disposeWithMe(this._layoutService.registerContainer(this._textSelectionRenderManager.__getEditorContainer()))}getDocContainerController(){return this._docContainerController}};R=Oe([P(1,g.Inject(a.LocaleService)),P(2,g.Inject(g.Injector)),P(3,Y.ITextSelectionRenderManager),P(4,g.Optional(c.LayoutService))],R);const F="UI_PLUGIN_DOCS",J=`${F}_COLOR_PICKER_COMPONENT`,Q=`${F}_FONT_FAMILY_COMPONENT`,ee=`${F}_FONT_FAMILY_ITEM_COMPONENT`,te=`${F}_FONT_SIZE_COMPONENT`;function ve(e){const t=e.get(a.ICommandService);return{id:d.SetInlineFormatBoldCommand.id,group:c.MenuGroup.TOOLBAR_FORMAT,type:c.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",positions:[c.MenuPosition.TOOLBAR_START],activated$:new S.Observable(n=>{const o=t.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const l=O(e);if(l==null)return;const u=(s=l.ts)==null?void 0:s.bl;n.next(u===a.BooleanNumber.TRUE)}});return n.next(!1),o.dispose}),hidden$:c.getMenuHiddenObservable(e,a.UniverInstanceType.DOC)}}function Te(e){const t=e.get(a.ICommandService);return{id:d.SetInlineFormatItalicCommand.id,group:c.MenuGroup.TOOLBAR_FORMAT,type:c.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",positions:[c.MenuPosition.TOOLBAR_START],activated$:new S.Observable(n=>{const o=t.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const l=O(e);if(l==null)return;const u=(s=l.ts)==null?void 0:s.it;n.next(u===a.BooleanNumber.TRUE)}});return n.next(!1),o.dispose}),hidden$:c.getMenuHiddenObservable(e,a.UniverInstanceType.DOC)}}function Ie(e){const t=e.get(a.ICommandService);return{id:d.SetInlineFormatUnderlineCommand.id,group:c.MenuGroup.TOOLBAR_FORMAT,type:c.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",positions:[c.MenuPosition.TOOLBAR_START],activated$:new S.Observable(n=>{const o=t.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const l=O(e);if(l==null)return;const u=(s=l.ts)==null?void 0:s.ul;n.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return n.next(!1),o.dispose}),hidden$:c.getMenuHiddenObservable(e,a.UniverInstanceType.DOC)}}function be(e){const t=e.get(a.ICommandService);return{id:d.SetInlineFormatStrikethroughCommand.id,group:c.MenuGroup.TOOLBAR_FORMAT,type:c.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",positions:[c.MenuPosition.TOOLBAR_START],activated$:new S.Observable(n=>{const o=t.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const l=O(e);if(l==null)return;const u=(s=l.ts)==null?void 0:s.st;n.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return n.next(!1),o.dispose}),hidden$:c.getMenuHiddenObservable(e,a.UniverInstanceType.DOC)}}function ye(e){const t=e.get(a.ICommandService);return{id:d.SetInlineFormatSubscriptCommand.id,group:c.MenuGroup.TOOLBAR_FORMAT,type:c.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",positions:[c.MenuPosition.TOOLBAR_START],activated$:new S.Observable(n=>{const o=t.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const l=O(e);if(l==null)return;const u=(s=l.ts)==null?void 0:s.va;n.next(u===a.BaselineOffset.SUBSCRIPT)}});return n.next(!1),o.dispose}),hidden$:c.getMenuHiddenObservable(e,a.UniverInstanceType.DOC)}}function Re(e){const t=e.get(a.ICommandService);return{id:d.SetInlineFormatSuperscriptCommand.id,group:c.MenuGroup.TOOLBAR_FORMAT,type:c.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",positions:[c.MenuPosition.TOOLBAR_START],activated$:new S.Observable(n=>{const o=t.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const l=O(e);if(l==null)return;const u=(s=l.ts)==null?void 0:s.va;n.next(u===a.BaselineOffset.SUPERSCRIPT)}});return n.next(!1),o.dispose}),hidden$:c.getMenuHiddenObservable(e,a.UniverInstanceType.DOC)}}function Me(e){const t=e.get(a.ICommandService);return{id:d.SetInlineFormatFontFamilyCommand.id,tooltip:"toolbar.font",group:c.MenuGroup.TOOLBAR_FORMAT,type:c.MenuItemType.SELECTOR,label:Q,positions:[c.MenuPosition.TOOLBAR_START],selections:c.FONT_FAMILY_LIST.map(n=>({label:{name:ee,hoverable:!0},value:n.value})),value$:new S.Observable(n=>{const o=c.FONT_FAMILY_LIST[0].value,r=t.onCommandExecuted(i=>{var l;const s=i.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontFamilyCommand.id){const u=O(e);if(u==null)return;const p=(l=u.ts)==null?void 0:l.ff;n.next(p!=null?p:o)}});return n.next(o),r.dispose}),hidden$:c.getMenuHiddenObservable(e,a.UniverInstanceType.DOC)}}function De(e){const t=e.get(a.ICommandService);return{id:d.SetInlineFormatFontSizeCommand.id,group:c.MenuGroup.TOOLBAR_FORMAT,type:c.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:te,props:{min:1,max:400}},positions:[c.MenuPosition.TOOLBAR_START],selections:c.FONT_SIZE_LIST,value$:new S.Observable(n=>{const r=t.onCommandExecuted(i=>{var l;const s=i.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontSizeCommand.id){const u=O(e);if(u==null)return;const p=(l=u.ts)==null?void 0:l.fs;n.next(p!=null?p:14)}});return n.next(14),r.dispose}),hidden$:c.getMenuHiddenObservable(e,a.UniverInstanceType.DOC)}}function xe(e){const t=e.get(a.ICommandService),n=e.get(a.ThemeService);return{id:d.SetInlineFormatTextColorCommand.id,icon:"FontColor",tooltip:"toolbar.textColor.main",group:c.MenuGroup.TOOLBAR_FORMAT,type:c.MenuItemType.BUTTON_SELECTOR,positions:[c.MenuPosition.TOOLBAR_START],selections:[{label:{name:J,hoverable:!1}}],value$:new S.Observable(o=>{const r=n.getCurrentTheme().textColor,i=t.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextColorCommand.id){const l=s.params.value;o.next(l!=null?l:r)}});return o.next(r),i.dispose}),hidden$:c.getMenuHiddenObservable(e,a.UniverInstanceType.DOC)}}function Pe(e){return{id:d.OrderListCommand.id,group:c.MenuGroup.TOOLBAR_LAYOUT,type:c.MenuItemType.BUTTON,icon:"OrderSingle",tooltip:"toolbar.order",positions:[c.MenuPosition.TOOLBAR_START],hidden$:c.getMenuHiddenObservable(e,a.UniverInstanceType.DOC)}}function Ne(e){return{id:d.BulletListCommand.id,group:c.MenuGroup.TOOLBAR_LAYOUT,type:c.MenuItemType.BUTTON,icon:"UnorderSingle",tooltip:"toolbar.unorder",positions:[c.MenuPosition.TOOLBAR_START],hidden$:c.getMenuHiddenObservable(e,a.UniverInstanceType.DOC)}}function O(e){var u;const t=e.get(a.IUniverInstanceService),n=e.get(d.TextSelectionManagerService),o=t.getCurrentUniverDocInstance(),r=n.getActiveRange();if(o==null||r==null)return;const i=(u=o.getBody())==null?void 0:u.textRuns;if(i==null)return;const{startOffset:s}=r;return i.find(({st:p,ed:f})=>s>=p&&s<f)}var Ue=Object.defineProperty,Ee=Object.getOwnPropertyDescriptor,Fe=(e,t,n,o)=>{for(var r=o>1?void 0:o?Ee(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=(o?s(t,n,r):s(r))||r);return o&&r&&Ue(t,n,r),r},T=(e,t)=>(n,o)=>t(n,o,e);let N=class extends a.Disposable{constructor(e,t,n,o,r,i){super(),this._injector=e,this._componentManager=t,this._commandService=n,this._shortcutService=o,this._menuService=r,this._uiController=i,this._init()}_initCustomComponents(){const e=this._componentManager;this.disposeWithMe(e.register(J,ie.ColorPicker)),this.disposeWithMe(e.register(Q,c.FontFamily)),this.disposeWithMe(e.register(ee,c.FontFamilyItem)),this.disposeWithMe(e.register(te,c.FontSize))}_initMenus(){[ve,Te,Ie,be,ye,Re,De,Me,xe,Pe,Ne].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e)))})}_init(){this._initCustomComponents(),this._initMenus()}};N=Fe([a.OnLifecycle(a.LifecycleStages.Rendered,N),T(0,g.Inject(g.Injector)),T(1,g.Inject(c.ComponentManager)),T(2,a.ICommandService),T(3,c.IShortcutService),T(4,c.IMenuService),T(5,c.IUIController)],N);const Ae={toolbar:{undo:"Undo",redo:"Redo",font:"Font",fontSize:"Font size",bold:"Bold",italic:"Italic",strikethrough:"Strikethrough",subscript:"Subscript",superscript:"Superscript",textColor:{main:"Text color",right:"Choose color"},resetColor:"Reset",order:"Ordered list",unorder:"Unordered list"}},ne={toolbar:{undo:"撤销",redo:"重做",font:"字体",fontSize:"字号",bold:"粗体",italic:"斜体",strikethrough:"删除线",subscript:"下标",superscript:"上标",underline:"下划线",textColor:{main:"文本颜色",right:"颜色选择"},resetColor:"重置颜色",order:"有序列表",unorder:"无序列表"}},Le={id:d.BreakLineCommand.id,preconditions:e=>e.getContextValue(a.FOCUSING_DOC),binding:c.KeyCode.ENTER},Be={id:d.DeleteLeftCommand.id,preconditions:e=>e.getContextValue(a.FOCUSING_DOC),binding:c.KeyCode.BACKSPACE},$e={id:d.DeleteRightCommand.id,preconditions:e=>e.getContextValue(a.FOCUSING_DOC),binding:c.KeyCode.DELETE},we=10,je=6;function He(){return a.Tools.generateRandomId(je)}function Ge(e){const t=e.match(/data-copy-id="([^\s]+)"/);return t&&t[1]?t[1]:null}class Ve{constructor(){h(this,"_cache",new a.LRUMap(we))}set(t,n){this._cache.set(t,n)}get(t){return this._cache.get(t)}clear(){this._cache.clear()}}const V=new Ve;function j(e){const t=e.style,n={},o=e.tagName.toLowerCase();switch(o){case"b":case"em":case"strong":{n.bl=a.BooleanNumber.TRUE;break}case"s":{n.st={s:a.BooleanNumber.TRUE};break}case"u":{n.ul={s:a.BooleanNumber.TRUE};break}case"i":{n.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{n.va=o==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}for(let r=0;r<t.length;r++){const i=t[r],s=t.getPropertyValue(i);switch(i){case"font-family":{n.ff=s;break}case"font-size":{const l=Number.parseInt(s);Number.isNaN(l)||s.endsWith("pt")&&(n.fs=l);break}case"font-style":{s==="italic"&&(n.it=a.BooleanNumber.TRUE);break}case"font-weight":{Number(s)>400&&(n.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(s)?n.ul={s:a.BooleanNumber.TRUE}:/overline/.test(s)?n.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(s)&&(n.st={s:a.BooleanNumber.TRUE});break}case"color":{const l=new a.ColorKit(s);l.isValid&&(n.cl={rgb:l.toRgbString()});break}case"background-color":{const l=new a.ColorKit(s);l.isValid&&(n.bg={rgb:l.toRgbString()});break}}}return n}function Ke(e){const t=new DOMParser,n=`<x-univer id="univer-root">${e}</x-univer>`;return t.parseFromString(n,"text/html").querySelector("#univer-root")}function K(e,t){const n=e.tagName.toLowerCase();return typeof t=="string"?n===t:Array.isArray(t)?t.some(o=>o===n):t(e)}const E=class E{constructor(){h(this,"_styleCache",new Map);h(this,"_styleRules",[]);h(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 n=E._pluginList.find(i=>i.checkPasteType(t)),o=Ke(t),r={dataStream:"",textRuns:[]};return n&&(this._styleRules=[...n.stylesRules],this._afterProcessRules=[...n.afterProcessRules]),this._styleCache.clear(),this._process(null,o==null?void 0:o.childNodes,r),this._styleCache.clear(),this._styleRules=[],this._afterProcessRules=[],r}_process(t,n,o){var r;for(const i of n)if(i.nodeType===Node.TEXT_NODE){const s=(r=i.nodeValue)==null?void 0:r.replace(/[\r\n]/g,"");let l;t&&this._styleCache.has(t)&&(l=this._styleCache.get(t)),o.dataStream+=s,l&&Object.getOwnPropertyNames(l).length&&o.textRuns.push({st:o.dataStream.length-s.length,ed:o.dataStream.length,ts:l})}else if(i.nodeType===Node.ELEMENT_NODE){const s=t?this._styleCache.get(t):{},l=this._styleRules.find(({filter:_})=>K(i,_)),u=l?l.getStyle(i):j(i);this._styleCache.set(i,{...s,...u});const{childNodes:p}=i;this._process(i,p,o);const f=this._afterProcessRules.find(({filter:_})=>K(i,_));f&&f.handler(o,i)}}};h(E,"_pluginList",[]);let M=E;const We={name:"univer-doc-paste-plugin-lark",checkPasteType(e){return/lark-record-clipboard/i.test(e)},stylesRules:[{filter:["s"],getStyle(e){const t=j(e);return{st:{s:a.BooleanNumber.TRUE},...t}}}],afterProcessRules:[{filter(e){return e.tagName==="DIV"&&/ace-line/i.test(e.className)},handler(e){e.paragraphs==null&&(e.paragraphs=[]),e.paragraphs.push({startIndex:e.dataStream.length}),e.dataStream+="\r"}}]};function ze(e){const t=e.style,n={};for(let o=0;o<t.length;o++){const r=t[o],i=t.getPropertyValue(r);switch(r){case"margin-top":{const s=Number.parseInt(i);n.spaceAbove=/pt/.test(i)?W(s):s;break}case"margin-bottom":{const s=Number.parseInt(i);n.spaceBelow=/pt/.test(i)?W(s):s;break}}}return Object.getOwnPropertyNames(n).length?n:null}function W(e){return e/.75}const Ye={name:"univer-doc-paste-plugin-word",checkPasteType(e){return/word|mso/i.test(e)},stylesRules:[{filter:["b"],getStyle(e){const t=j(e);return{bl:a.BooleanNumber.TRUE,...t}}}],afterProcessRules:[{filter(e){return e.tagName==="P"&&/mso/i.test(e.className)},handler(e,t){e.paragraphs==null&&(e.paragraphs=[]);const n={startIndex:e.dataStream.length},o=ze(t);o&&(n.paragraphStyle=o),e.paragraphs.push(n),e.dataStream+="\r"}}]};function ke(e,t){const{st:n,ed:o,ts:r={}}=t,{ff:i,fs:s,it:l,bl:u,ul:p,st:f,ol:_,bg:I,cl:x,va:v}=r;let m=e.slice(n,o);const C=[];return l===a.BooleanNumber.TRUE&&(m=`<i>${m}</i>`),v===a.BaselineOffset.SUPERSCRIPT?m=`<sup>${m}</sup>`:v===a.BaselineOffset.SUBSCRIPT&&(m=`<sub>${m}</sub>`),(p==null?void 0:p.s)===a.BooleanNumber.TRUE&&(m=`<u>${m}</u>`),(f==null?void 0:f.s)===a.BooleanNumber.TRUE&&(m=`<s>${m}</s>`),u===a.BooleanNumber.TRUE&&(m=`<strong>${m}</strong>`),i&&C.push(`font-family: ${i}`),x&&C.push(`color: ${x.rgb}`),s&&C.push(`font-size: ${s}px`),_&&C.push("text-decoration: overline"),I&&C.push(`background: ${I.rgb}`),C.length?`<span style="${C.join(";")}">${m}</span>`:m}function z(e,t=!0){const{dataStream:n,textRuns:o=[],paragraphs:r=[]}=e;let i=0;const s=[],l=[];for(const u of o){const{st:p,ed:f}=u;if(p!==i&&s.push(n.slice(i,p)),s.push(ke(n,u)),i=f,t)for(const _ of r){const{startIndex:I,paragraphStyle:x={}}=_;if(I>=p&&I<=f){const{spaceAbove:v,spaceBelow:m}=x,C=[];v!=null&&(typeof v=="number"?C.push(`margin-top: ${v}px`):C.push(`margin-top: ${v.v}px`)),m!=null&&(typeof m=="number"?C.push(`margin-bottom: ${m}px`):C.push(`margin-bottom: ${m.v}px`)),l.push(`<p className="UniverNormal" ${C.length?`style="${C.join(";")}"`:""}>${s.join("")}</p>`),s.length=0}}}return i<n.length&&s.push(n.slice(i,n.length)),l.join("")+s.join("")}class qe{convert(t){if(t.length===0)throw new Error("The bodyList length at least to be 1");if(t.length===1)return z(t[0]);let n="";for(const o of t)n+='<p className="UniverNormal">',n+=z(o,!1),n+="</p>";return n}}var Ze=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,Je=(e,t,n,o)=>{for(var r=o>1?void 0:o?Xe(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=(o?s(t,n,r):s(r))||r);return o&&r&&Ze(t,n,r),r},b=(e,t)=>(n,o)=>t(n,o,e);M.use(Ye);M.use(We);function Qe(e){const t=e.replace(/\n/g,"\r"),n=[];for(let o=0;o<t.length;o++)t[o]==="\r"&&n.push({startIndex:o});return{dataStream:t,paragraphs:n}}const D=g.createIdentifier("doc.clipboard-service");let w=class extends a.Disposable{constructor(t,n,o,r,i){super();h(this,"_clipboardHooks",[]);h(this,"_htmlToUDM",new M);h(this,"_umdToHtml",new qe);this._currentUniverService=t,this._logService=n,this._commandService=o,this._clipboardInterfaceService=r,this._textSelectionManagerService=i}async copy(){const t=this._getDocumentBodyInRanges();try{this._setClipboardData(t)}catch(n){return this._logService.error("[DocClipboardService] copy failed",n),!1}return!0}async cut(){return this._cut()}async paste(t){const n=await this._generateBodyFromClipboardItems(t);return this._paste(n)}async legacyPaste(t,n){const o=this._generateBodyFromHtmlAndText(t,n);return this._paste(o)}async _cut(){var i;const{segmentId:t,endOffset:n,style:o}=(i=this._textSelectionManagerService.getActiveRange())!=null?i:{},r=this._textSelectionManagerService.getSelections();if(t==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),n==null||r==null)return!1;this.copy();try{let s=n;for(const u of r){const{startOffset:p,endOffset:f}=u;p==null||f==null||f<=n&&(s-=f-p)}const l=[{startOffset:s,endOffset:s,style:o}];return this._commandService.executeCommand(d.CutContentCommand.id,{segmentId:t,textRanges:l})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(t){var s;const{segmentId:n,endOffset:o,style:r}=(s=this._textSelectionManagerService.getActiveRange())!=null?s:{},i=this._textSelectionManagerService.getSelections();if(n==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),o==null||i==null)return!1;try{let l=o;for(const p of i){const{startOffset:f,endOffset:_}=p;f==null||_==null||_<=o&&(l+=t.dataStream.length-(_-f))}const u=[{startOffset:l,endOffset:l,style:r}];return this._commandService.executeCommand(d.InnerPasteCommand.id,{body:t,segmentId:n,textRanges:u})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(t){const n=He(),o=t.length>1?t.map(i=>i.dataStream).join(`
|
|
2
|
-
|
|
1
|
+
"use strict";var Ne=Object.defineProperty;var Be=(i,e,t)=>e in i?Ne(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var C=(i,e,t)=>(Be(i,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),O=require("@wendellhu/redi"),l=require("@univerjs/ui"),d=require("@univerjs/docs"),m=require("@univerjs/engine-render"),$e=require("@wendellhu/redi/react-bindings"),Ae=require("@univerjs/design"),Fe=require("react"),M=require("rxjs"),Ie={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},Oe={outerLeft:!1,outerRight:!1,header:!0,footer:!0,innerLeft:!1,innerRight:!1,frozenHeaderLT:!1,frozenHeaderRT:!1,frozenHeaderLM:!1,frozenContent:!1,infoBar:!0,toolbar:!0},be={layout:{docContainerConfig:Oe,toolbarConfig:Ie}},Me="DocUI";function y(i){return i.getContextValue(c.FOCUSING_DOC)&&i.getContextValue(c.FOCUSING_UNIVER_EDITOR)}function we(i){return i.getContextValue(c.FOCUSING_DOC)&&i.getContextValue(c.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(c.FOCUSING_UNIVER_EDITOR_SINGLE_MODE)}const je={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_UP,preconditions:y,staticParameters:{direction:c.Direction.UP}},We={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_DOWN,preconditions:y,staticParameters:{direction:c.Direction.DOWN}},Ve={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_LEFT,preconditions:y,staticParameters:{direction:c.Direction.LEFT}},ze={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_RIGHT,preconditions:y,staticParameters:{direction:c.Direction.RIGHT}},ke={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_UP|l.MetaKeys.SHIFT,preconditions:y,staticParameters:{direction:c.Direction.UP}},He={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_DOWN|l.MetaKeys.SHIFT,preconditions:y,staticParameters:{direction:c.Direction.DOWN}},Ye={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_LEFT|l.MetaKeys.SHIFT,preconditions:y,staticParameters:{direction:c.Direction.LEFT}},Ge={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_RIGHT|l.MetaKeys.SHIFT,preconditions:y,staticParameters:{direction:c.Direction.RIGHT}},Ke={id:d.SelectAllOperation.id,binding:l.KeyCode.A|l.MetaKeys.CTRL_COMMAND,preconditions:i=>i.getContextValue(c.FOCUSING_UNIVER_EDITOR)&&(i.getContextValue(c.FOCUSING_DOC)||i.getContextValue(c.EDITOR_ACTIVATED))};var qe=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,Ze=(i,e,t,n)=>{for(var r=n>1?void 0:n?Xe(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&&qe(e,t,r),r},Se=(i,e)=>(t,n)=>e(t,n,i);let he=class{constructor(i,e,t){C(this,"_docContainer");C(this,"getComponent",i=>{if(this._docContainer=i,!i.getContentRef().current)throw new Error("container is not ready")});C(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}};he=Ze([Se(1,O.Inject(c.LocaleService)),Se(2,O.Inject(O.Injector))],he);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},G=(i,e)=>(t,n)=>e(t,n,i);let V=class extends c.RxDisposable{constructor(e,t,n,r,o){super();C(this,"_docContainerController");C(this,"changeLocale",e=>{this._localeService.setLocale(e)});this._localeService=t,this._injector=n,this._textSelectionRenderManager=r,this._layoutService=o,this._docContainerController=this._injector.createInstance(he,e),this._registerContainer()}_registerContainer(){this._layoutService&&this.disposeWithMe(this._layoutService.registerContainerElement(this._textSelectionRenderManager.__getEditorContainer()))}getDocContainerController(){return this._docContainerController}};V=et([G(1,O.Inject(c.LocaleService)),G(2,O.Inject(O.Injector)),G(3,m.ITextSelectionRenderManager),G(4,O.Optional(l.ILayoutService))],V);const oe="UI_PLUGIN_DOCS",Te=`${oe}_COLOR_PICKER_COMPONENT`,Re=`${oe}_FONT_FAMILY_COMPONENT`,ye=`${oe}_FONT_FAMILY_ITEM_COMPONENT`,De=`${oe}_FONT_SIZE_COMPONENT`;var Ee={exports:{}},se={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react-jsx-runtime.production.min.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var tt=Fe,nt=Symbol.for("react.element"),rt=Symbol.for("react.fragment"),it=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 xe(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)it.call(e,n)&&!st.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:nt,type:i,key:o,ref:s,props:r,_owner:ot.current}}se.Fragment=rt;se.jsx=xe;se.jsxs=xe;Ee.exports=se;var ct=Ee.exports;const at="univer-docs-ui-canvas-background",lt={docsUiCanvasBackground:at},dt=()=>ct.jsx("div",{className:lt.docsUiCanvasBackground});function ut(i){const e=i.get(c.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(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const a=P(i);if(a==null)return;const u=(s=a.ts)==null?void 0:s.bl;t.next(u===c.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,c.UniverInstanceType.DOC)}}function ht(i){const e=i.get(c.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(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const a=P(i);if(a==null)return;const u=(s=a.ts)==null?void 0:s.it;t.next(u===c.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,c.UniverInstanceType.DOC)}}function _t(i){const e=i.get(c.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(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const a=P(i);if(a==null)return;const u=(s=a.ts)==null?void 0:s.ul;t.next((u==null?void 0:u.s)===c.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,c.UniverInstanceType.DOC)}}function pt(i){const e=i.get(c.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(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const a=P(i);if(a==null)return;const u=(s=a.ts)==null?void 0:s.st;t.next((u==null?void 0:u.s)===c.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,c.UniverInstanceType.DOC)}}function gt(i){const e=i.get(c.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(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const a=P(i);if(a==null)return;const u=(s=a.ts)==null?void 0:s.va;t.next(u===c.BaselineOffset.SUBSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,c.UniverInstanceType.DOC)}}function St(i){const e=i.get(c.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(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const a=P(i);if(a==null)return;const u=(s=a.ts)==null?void 0:s.va;t.next(u===c.BaselineOffset.SUPERSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,c.UniverInstanceType.DOC)}}function ft(i){const e=i.get(c.ICommandService);return{id:d.SetInlineFormatFontFamilyCommand.id,tooltip:"toolbar.font",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,label:Re,positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_FAMILY_LIST.map(t=>({label:{name:ye,hoverable:!0},value:t.value})),value$:new M.Observable(t=>{const n=l.FONT_FAMILY_LIST[0].value,r=e.onCommandExecuted(o=>{var a;const s=o.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontFamilyCommand.id){const u=P(i);if(u==null)return;const _=(a=u.ts)==null?void 0:a.ff;t.next(_!=null?_:n)}});return t.next(n),r.dispose}),hidden$:l.getMenuHiddenObservable(i,c.UniverInstanceType.DOC)}}function mt(i){const e=i.get(c.ICommandService);return{id:d.SetInlineFormatFontSizeCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:De,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 a;const s=o.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontSizeCommand.id){const u=P(i);if(u==null)return;const _=(a=u.ts)==null?void 0:a.fs;t.next(_!=null?_:14)}});return t.next(14),r.dispose}),hidden$:l.getMenuHiddenObservable(i,c.UniverInstanceType.DOC)}}function vt(i){const e=i.get(c.ICommandService),t=i.get(c.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:Te,hoverable:!1}}],value$:new M.Observable(n=>{const r=t.getCurrentTheme().textColor,o=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextColorCommand.id){const a=s.params.value;n.next(a!=null?a:r)}});return n.next(r),o.dispose}),hidden$:l.getMenuHiddenObservable(i,c.UniverInstanceType.DOC)}}function Ct(i){return{id:d.OrderListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"OrderSingle",tooltip:"toolbar.order",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(i,c.UniverInstanceType.DOC)}}function It(i){return{id:d.BulletListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"UnorderSingle",tooltip:"toolbar.unorder",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(i,c.UniverInstanceType.DOC)}}function P(i){var u;const e=i.get(c.IUniverInstanceService),t=i.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const o=(u=n.getBody())==null?void 0:u.textRuns;if(o==null)return;const{startOffset:s}=r;return o.find(({st:_,ed:p})=>s>=_&&s<p)}var Ot=Object.defineProperty,bt=Object.getOwnPropertyDescriptor,Mt=(i,e,t,n)=>{for(var r=n>1?void 0:n?bt(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&&Ot(e,t,r),r},U=(i,e)=>(t,n)=>e(t,n,i);let q=class extends c.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(Te,Ae.ColorPicker)),this.disposeWithMe(i.register(Re,l.FontFamily)),this.disposeWithMe(i.register(ye,l.FontFamilyItem)),this.disposeWithMe(i.register(De,l.FontSize))}_initMenus(){[ut,ht,_t,pt,gt,St,mt,ft,vt,Ct,It].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(()=>$e.connectInjector(dt,this._injector)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(c.UniverInstanceType.DOC,()=>{this._injector.get(m.ITextSelectionRenderManager).focus()}))}};q=Mt([c.OnLifecycle(c.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,c.IUniverInstanceService)],q);const Tt={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"}},Pe={toolbar:{undo:"撤销",redo:"重做",font:"字体",fontSize:"字号",bold:"粗体",italic:"斜体",strikethrough:"删除线",subscript:"下标",superscript:"上标",underline:"下划线",textColor:{main:"文本颜色",right:"颜色选择"},resetColor:"重置颜色",order:"有序列表",unorder:"无序列表"}},Rt={id:d.BreakLineCommand.id,preconditions:we,binding:l.KeyCode.ENTER},yt={id:d.DeleteLeftCommand.id,preconditions:y,binding:l.KeyCode.BACKSPACE},Dt={id:d.DeleteRightCommand.id,preconditions:y,binding:l.KeyCode.DELETE},Et=10,xt=6;function Pt(){return c.Tools.generateRandomId(xt)}function Ut(i){const e=i.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class Lt{constructor(){C(this,"_cache",new c.LRUMap(Et))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}clear(){this._cache.clear()}}const fe=new Lt;function pe(i){const e=i.style,t={},n=i.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{t.bl=c.BooleanNumber.TRUE;break}case"s":{t.st={s:c.BooleanNumber.TRUE};break}case"u":{t.ul={s:c.BooleanNumber.TRUE};break}case"i":{t.it=c.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=n==="sup"?c.BaselineOffset.SUPERSCRIPT:c.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 a=Number.parseInt(s);Number.isNaN(a)||s.endsWith("pt")&&(t.fs=a);break}case"font-style":{s==="italic"&&(t.it=c.BooleanNumber.TRUE);break}case"font-weight":{Number(s)>400&&(t.bl=c.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(s)?t.ul={s:c.BooleanNumber.TRUE}:/overline/.test(s)?t.ol={s:c.BooleanNumber.TRUE}:/line-through/.test(s)&&(t.st={s:c.BooleanNumber.TRUE});break}case"color":{const a=new c.ColorKit(s);a.isValid&&(t.cl={rgb:a.toRgbString()});break}case"background-color":{const a=new c.ColorKit(s);a.isValid&&(t.bg={rgb:a.toRgbString()});break}}}return t}function Nt(i){const e=new DOMParser,t=`<x-univer id="univer-root">${i}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function me(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(){C(this,"_styleCache",new Map);C(this,"_styleRules",[]);C(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=Nt(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 a;e&&this._styleCache.has(e)&&(a=this._styleCache.get(e)),n.dataStream+=s,a&&Object.getOwnPropertyNames(a).length&&n.textRuns.push({st:n.dataStream.length-s.length,ed:n.dataStream.length,ts:a})}else if(o.nodeType===Node.ELEMENT_NODE){const s=e?this._styleCache.get(e):{},a=this._styleRules.find(({filter:f})=>me(o,f)),u=a?a.getStyle(o):pe(o);this._styleCache.set(o,{...s,...u});const{childNodes:_}=o;this._process(o,_,n);const p=this._afterProcessRules.find(({filter:f})=>me(o,f));p&&p.handler(n,o)}}};C(ie,"_pluginList",[]);let z=ie;const Bt={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:c.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 $t(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}}}return Object.getOwnPropertyNames(t).length?t:null}const At={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:c.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=$t(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]};function Ft(i,e){const{st:t,ed:n,ts:r={}}=e,{ff:o,fs:s,it:a,bl:u,ul:_,st:p,ol:f,bg:v,cl:I,va:S}=r;let h=i.slice(t,n);const g=[];return a===c.BooleanNumber.TRUE&&(h=`<i>${h}</i>`),S===c.BaselineOffset.SUPERSCRIPT?h=`<sup>${h}</sup>`:S===c.BaselineOffset.SUBSCRIPT&&(h=`<sub>${h}</sub>`),(_==null?void 0:_.s)===c.BooleanNumber.TRUE&&(h=`<u>${h}</u>`),(p==null?void 0:p.s)===c.BooleanNumber.TRUE&&(h=`<s>${h}</s>`),u===c.BooleanNumber.TRUE&&(h=`<strong>${h}</strong>`),o&&g.push(`font-family: ${o}`),I&&g.push(`color: ${I.rgb}`),s&&g.push(`font-size: ${s}px`),f&&g.push("text-decoration: overline"),v&&g.push(`background: ${v.rgb}`),g.length?`<span style="${g.join(";")}">${h}</span>`:h}function ve(i,e=!0){const{dataStream:t,textRuns:n=[],paragraphs:r=[]}=i;let o=0;const s=[],a=[];for(const u of n){const{st:_,ed:p}=u;if(_!==o&&s.push(t.slice(o,_)),s.push(Ft(t,u)),o=p,e)for(const f of r){const{startIndex:v,paragraphStyle:I={}}=f;if(v>=_&&v<=p){const{spaceAbove:S,spaceBelow:h}=I,g=[];S!=null&&(typeof S=="number"?g.push(`margin-top: ${S}px`):g.push(`margin-top: ${S.v}px`)),h!=null&&(typeof h=="number"?g.push(`margin-bottom: ${h}px`):g.push(`margin-bottom: ${h.v}px`)),a.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)),a.join("")+s.join("")}class wt{convert(e){if(e.length===0)throw new Error("The bodyList length at least to be 1");if(e.length===1)return ve(e[0]);let t="";for(const n of e)t+='<p className="UniverNormal">',t+=ve(n,!1),t+="</p>";return t}}var jt=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&&jt(e,t,r),r},F=(i,e)=>(t,n)=>e(t,n,i);z.use(At);z.use(Bt);function zt(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 k=O.createIdentifier("doc.clipboard-service");let _e=class extends c.Disposable{constructor(e,t,n,r,o){super();C(this,"_clipboardHooks",[]);C(this,"_htmlToUDM",new z);C(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 u of r){const{startOffset:_,endOffset:p}=u;_==null||p==null||p<=t&&(s-=p-_)}const a=[{startOffset:s,endOffset:s,style:n}];return this._commandService.executeCommand(d.CutContentCommand.id,{segmentId:e,textRanges:a})}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 a=n;for(const _ of o){const{startOffset:p,endOffset:f}=_;p==null||f==null||f<=n&&(a+=e.dataStream.length-(f-p))}const u=[{startOffset:a,endOffset:a,style:r}];return this._commandService.executeCommand(d.InnerPasteCommand.id,{body:e,segmentId:t,textRanges:u})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(e){const t=Pt(),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}"`),fe.set(t,e[0])),this._clipboardInterfaceService.write(n,r)}addClipboardHook(e){return this._clipboardHooks.push(e),c.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:a}=r;if(a||o==null||s==null)continue;const u=t.sliceBody(o,s);u!=null&&n.push(u)}return n}async _generateBodyFromClipboardItems(e){try{let t="",n="";for(const r of e)for(const o of r.types)o===l.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await r.getType(o).then(s=>s&&s.text()):o===l.HTML_CLIPBOARD_MIME_TYPE&&(t=await r.getType(o).then(s=>s&&s.text()));return this._generateBodyFromHtmlAndText(t,n)}catch(t){return Promise.reject(t)}}_generateBodyFromHtmlAndText(e,t){if(!e){if(t)return zt(t);throw new Error("[DocClipboardService] html and text cannot be both empty!")}const n=Ut(e);if(n){const r=fe.get(n);if(r)return r}return this._htmlToUDM.convert(e)}};_e=Vt([F(0,c.IUniverInstanceService),F(1,c.ILogService),F(2,c.ICommandService),F(3,l.IClipboardInterfaceService),F(4,O.Inject(d.TextSelectionManagerService))],_e);function ce(i){return i.getContextValue(c.FOCUSING_DOC)||i.getContextValue(c.EDITOR_ACTIVATED)}const ge=999,kt={id:l.CopyCommand.id,name:"doc.command.copy",type:c.CommandType.COMMAND,multi:!0,priority:ge,preconditions:ce,handler:async i=>i.get(k).copy()},Ht={id:l.CutCommand.id,name:"doc.command.cut",type:c.CommandType.COMMAND,multi:!0,priority:ge,preconditions:ce,handler:async i=>i.get(k).cut()},Yt={id:l.PasteCommand.id,name:"doc.command.paste",type:c.CommandType.COMMAND,multi:!0,priority:ge,preconditions:ce,handler:async i=>{const e=i.get(k),n=await i.get(l.IClipboardInterfaceService).read();return n.length===0?!1:e.paste(n)}};var Gt=Object.defineProperty,Kt=Object.getOwnPropertyDescriptor,qt=(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&&Gt(e,t,r),r},w=(i,e)=>(t,n)=>e(t,n,i);let X=class extends c.RxDisposable{constructor(i,e,t,n,r){super(),this._commandService=i,this._clipboardInterfaceService=e,this._docClipboardService=t,this._textSelectionRenderManager=n,this._contextService=r,this._init()}_init(){[kt,Ht,Yt].forEach(i=>this.disposeWithMe(this._commandService.registerMultipleCommand(i))),[d.InnerPasteCommand,d.CutContentCommand].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i))),this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var i;this._clipboardInterfaceService.supportClipboard||(i=this._textSelectionRenderManager)==null||i.onPaste$.pipe(M.takeUntil(this.dispose$)).subscribe(e=>{var o,s;if(!ce(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=qt([c.OnLifecycle(c.LifecycleStages.Steady,X),w(0,c.ICommandService),w(1,l.IClipboardInterfaceService),w(2,k),w(3,m.ITextSelectionRenderManager),w(4,c.IContextService)],X);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},j=(i,e)=>(t,n)=>e(t,n,i);let Z=class extends c.Disposable{constructor(e,t,n,r,o){super();C(this,"_initialEditors",new Set);this._currentUniverService=e,this._docSkeletonManagerService=t,this._editorService=n,this._commandService=r,this._textSelectionRenderManager=o,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;const{marginTop:o=0,marginBottom:s=0,marginLeft:a=0,marginRight:u=0}=r.getSnapshot().documentStyle,{scene:_,mainComponent:p}=t.render;let{actualHeight:f,actualWidth:v}=n.getActualSize();f+=o+s,v+=a+u;const{width:I,height:S}=t.getBoundingClientRect(),h=_.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);let g=h==null?void 0:h.getScrollBar();const b=Math.max(v,I),T=Math.max(f,S);_.transformByState({width:b,height:T}),p==null||p.resize(b,T),t.isSingle()?v>I?g==null?h&&new m.ScrollBar(h,{barSize:8,enableVertical:!1}):h==null||h.resetSizeAndScrollBar():(g=null,h==null||h.scrollTo({x:0,y:0}),(x=h==null?void 0:h.getScrollBar())==null||x.dispose()):f>S?g==null?h&&new m.ScrollBar(h,{enableHorizontal:!1,barSize:8}):h==null||h.resetSizeAndScrollBar():(g=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(d.CoverContentCommand.id,{unitId:e.editorUnitId,body:e.body,segmentId:null})}))}_initialBlur(){this.disposeWithMe(this._editorService.blur$.subscribe(()=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.blur()}))}_initialFocus(){this.disposeWithMe(this._editorService.focus$.subscribe(e=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges([e])}))}_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:r}=n;if(this._editorService.isSheetEditor(r))return;this._resize(r),this._valueChange()}}))}};Z=Jt([c.OnLifecycle(c.LifecycleStages.Rendered,Z),j(0,c.IUniverInstanceService),j(1,O.Inject(d.DocSkeletonManagerService)),j(2,l.IEditorService),j(3,c.ICommandService),j(4,m.ITextSelectionRenderManager)],Z);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},K=(i,e)=>(t,n)=>e(t,n,i);let J=class extends c.RxDisposable{constructor(e,t,n,r){super();C(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 p;const{mainComponent:n,scene:r,unitId:o}=e,s=n,a=(p=t.getSkeletonData())==null?void 0:p.pages;if(a==null)return;let u=0,_=0;for(let f=0,v=a.length;f<v;f++){const I=a[f],{pageWidth:S,pageHeight:h}=I;s.pageLayoutType===m.PageLayoutType.VERTICAL?(_+=h,_+=s.pageMarginTop,f===v-1&&(_+=s.pageMarginTop),u=Math.max(u,S)):s.pageLayoutType===m.PageLayoutType.HORIZONTAL&&(u+=S,f!==v-1&&(u+=s.pageMarginLeft),_=Math.max(_,h))}s.resize(u,_),this._editorService.isEditor(o)||r.resize(u,_)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=this._docSkeletonManagerService.getSkeletonByUnitId(o);if(s==null)return;const{skeleton:a}=s,u=this._renderManagerService.getRenderById(o);if(u==null)return;if(a.calculate(),this._editorService.isEditor(o)){(n=u.mainComponent)==null||n.makeDirty();return}this._recalculateSizeBySkeleton(u,a)}}))}};J=tn([c.OnLifecycle(c.LifecycleStages.Rendered,J),K(0,O.Inject(d.DocSkeletonManagerService)),K(1,m.IRenderManagerService),K(2,c.ICommandService),K(3,l.IEditorService)],J);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},ae=(i,e)=>(t,n)=>e(t,n,i);exports.DocCanvasView=class extends c.RxDisposable{constructor(t,n,r){super();C(this,"_scene");C(this,"_currentDocumentModel");C(this,"_fps$",new M.BehaviorSubject(""));C(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:a,engine:u}=s;a.openTransformer(),this._scene=a;const _=new m.Viewport(d.VIEWPORT_KEY.VIEW_MAIN,a,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});a.attachControl(),a.on(m.EVENT_TYPE.wheel,(v,I)=>{const S=v;if(S.ctrlKey){const h=Math.abs(S.deltaX);let g=h<40?.2:h<80?.4:.2;g*=S.deltaY>0?-1:1,a.scaleX<1&&(g/=2),a.scaleX+g>4?a.scale(4,4):a.scaleX+g<.1?a.scale(.1,.1):S.preventDefault()}else _.onMouseWheel(S,I)}),this._configService.getConfig("hasScroll")!==!1&&new m.ScrollBar(_),a.addLayer(new m.Layer(a,[],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),new m.Layer(a,[],d.DOCS_COMPONENT_HEADER_LAYER_INDEX)),this._addComponent(s),this._currentDocumentModel.getShouldRenderLoopImmediately()&&u.runRenderLoop(()=>{a.render(),this._fps$.next(Math.round(u.getFps()).toString())}),this._renderManagerService.setCurrent(n)}_addComponent(t){const n=this._scene,r=this._currentDocumentModel,o=new m.Documents(d.DOCS_VIEW_KEY.MAIN,void 0,{pageMarginLeft:r.documentStyle.marginLeft||0,pageMarginTop:r.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)}};exports.DocCanvasView=on([c.OnLifecycle(c.LifecycleStages.Starting,exports.DocCanvasView),ae(0,m.IRenderManagerService),ae(1,c.IConfigService),ae(2,c.IUniverInstanceService)],exports.DocCanvasView);var sn=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,an=(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&&sn(e,t,r),r},$=(i,e)=>(t,n)=>e(t,n,i);let Q=class extends c.Disposable{constructor(e,t,n,r,o,s){super();C(this,"_liquid",new m.Liquid);C(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:a,scene:u}=o,_=s,{left:p,top:f}=_;e.forEach(v=>{const{unitId:I,subUnitId:S,floatingObjectId:h,floatingObject:g}=v,{left:b=0,top:T=0,width:D=0,height:E=0,angle:x,flipX:N,flipY:B,skewX:H,skewY:Y}=g,R=this._pageMarginCache.get(h),Ue=(R==null?void 0:R.marginLeft)||0,Le=(R==null?void 0:R.marginTop)||0;r==null||r.getViewModel().getDataModel().updateDrawing(h,{left:b-p-Ue,top:T-f-Le,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=[d.RichTextEditingMutation.id,d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=this._docSkeletonManagerService.getCurrent();if(s==null)return;const{unitId:a,skeleton:u}=s;if(o!==a)return;const _=this._renderManagerService.getRenderById(a);if(_==null)return;if(this._editorService.isEditor(a)){(n=_.mainComponent)==null||n.makeDirty();return}this._refreshFloatingObject(a,u,_)}}))}_refreshFloatingObject(e,t,n){const r=t==null?void 0:t.getSkeletonData(),{mainComponent:o,scene:s}=n,a=o;if(!r)return;const{left:u,top:_,pageLayoutType:p,pageMarginLeft:f,pageMarginTop:v}=a,{pages:I}=r,S=[];s.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let h=0,g=I.length;h<g;h++){const b=I[h],{skeDrawings:T,marginLeft:D,marginTop:E}=b;this._liquid.translatePagePadding(b),T.forEach(x=>{const{aLeft:N,aTop:B,height:H,width:Y,objectId:R}=x;S.push({unitId:e,subUnitId:c.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:R,floatingObject:{left:N+u+this._liquid.x,top:B+_+this._liquid.y,width:Y,height:H}}),this._pageMarginCache.set(R,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.translatePage(b,p,f,v)}this._floatingObjectManagerService.BatchAddOrUpdate(S)}};Q=an([c.OnLifecycle(c.LifecycleStages.Steady,Q),$(0,O.Inject(d.DocSkeletonManagerService)),$(1,c.IUniverInstanceService),$(2,m.IRenderManagerService),$(3,c.ICommandService),$(4,c.IFloatingObjectManagerService),$(5,l.IEditorService)],Q);var ln=Object.defineProperty,dn=Object.getOwnPropertyDescriptor,un=(i,e,t,n)=>{for(var r=n>1?void 0:n?dn(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&&ln(e,t,r),r},le=(i,e)=>(t,n)=>e(t,n,i);const hn="rgba(198, 198, 198, 1)",_n="rgba(255, 255, 255, 1)";let ee=class extends c.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(c.toDisposable(n.onPageRenderObservable.add(s=>{var h,g,b,T;if(this._editorService.isEditor(i))return;const{page:a,pageLeft:u,pageTop:_,ctx:p}=s,{width:f,pageWidth:v,height:I,pageHeight:S}=a;p.save(),p.translate(u-.5,_-.5),m.Rect.drawWith(p,{width:(g=(h=r==null?void 0:r.width)!=null?h:v)!=null?g:f,height:(T=(b=r==null?void 0:r.height)!=null?b:S)!=null?T:I,strokeWidth:1,stroke:hn,fill:_n,zIndex:3}),p.restore()})))})}_commandExecutedListener(){}};ee=un([c.OnLifecycle(c.LifecycleStages.Rendered,ee),le(0,m.IRenderManagerService),le(1,l.IEditorService),le(2,c.IUniverInstanceService)],ee);var pn=Object.defineProperty,gn=Object.getOwnPropertyDescriptor,Sn=(i,e,t,n)=>{for(var r=n>1?void 0:n?gn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&pn(e,t,r),r},A=(i,e)=>(t,n)=>e(t,n,i);let te=class extends c.Disposable{constructor(e,t,n,r,o,s){super();C(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(c.toDisposable(r.onMouseWheelObserver.add(o=>{if(!o.ctrlKey)return;const s=Math.abs(o.deltaX);let a=s<40?.2:s<80?.4:.2;a*=o.deltaY>0?-1:1,r.scaleX<1&&(a/=2);const u=this._currentUniverService.getCurrentUniverDocInstance(),_=u.zoomRatio;let p=+Number.parseFloat(`${_+a}`).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(c.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(),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:a,pageMarginLeft:u,pageMarginTop:_}=n;if(o==null||s===Number.POSITIVE_INFINITY||a===Number.POSITIVE_INFINITY)return;const{width:p,height:f}=o;let v=0,I=0,S=0,h=0,g=Number.POSITIVE_INFINITY;p>(s+u*2)*t?(v=p/2-s*t/2,v/=t,S=(p-u*2)/t,g=0):(v=u,S=s+u*2,g=(S-p/t)/2),f>a?(I=f/2-a/2,h=(f-_*2)/t):(I=_,h=a+_*2),r.resize(S,h+200),n.translate(v,I);const b=r.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(g!==Number.POSITIVE_INFINITY&&b!=null){const T=b.getBarScroll(g,0).x;b.scrollTo({x:T})}return this}_getDocObject(){return d.getDocObject(this._currentUniverService,this._renderManagerService)}};te=Sn([c.OnLifecycle(c.LifecycleStages.Rendered,te),A(0,O.Inject(d.DocSkeletonManagerService)),A(1,c.IUniverInstanceService),A(2,c.ICommandService),A(3,m.IRenderManagerService),A(4,O.Inject(d.TextSelectionManagerService)),A(5,l.IEditorService)],te);var fn=Object.defineProperty,mn=Object.getOwnPropertyDescriptor,vn=(i,e,t,n)=>{for(var r=n>1?void 0:n?mn(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&&fn(e,t,r),r},L=(i,e)=>(t,n)=>e(t,n,i);let ne=class extends c.Disposable{constructor(e,t,n,r,o,s,a){super();C(this,"_loadedMap",new WeakSet);this._docSkeletonManagerService=e,this._currentUniverService=t,this._commandService=n,this._renderManagerService=r,this._textSelectionRenderManager=o,this._textSelectionManagerService=s,this._editorService=a,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(c.toDisposable(n.onPointerEnterObserver.add(()=>{this._isEditorReadOnly(e)||(n.cursor=m.CURSOR_TYPE.TEXT)}))),this.disposeWithMe(c.toDisposable(n.onPointerLeaveObserver.add(()=>{n.cursor=m.CURSOR_TYPE.DEFAULT,r.resetCursor()}))),this.disposeWithMe(c.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._textSelectionRenderManager.eventTrigger(o),this._setEditorFocus(e),o.button!==2&&s.stopPropagation()}))),this.disposeWithMe(c.toDisposable(n==null?void 0:n.onDblclickObserver.add(o=>{this._textSelectionRenderManager.handleDblClick(o)}))),this.disposeWithMe(c.toDisposable(n==null?void 0:n.onTripleClickObserver.add(o=>{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 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 d.getDocObjectById(e,this._renderManagerService)}};ne=vn([c.OnLifecycle(c.LifecycleStages.Rendered,ne),L(0,O.Inject(d.DocSkeletonManagerService)),L(1,c.IUniverInstanceService),L(2,c.ICommandService),L(3,m.IRenderManagerService),L(4,m.ITextSelectionRenderManager),L(5,O.Inject(d.TextSelectionManagerService)),L(6,l.IEditorService)],ne);var Cn=Object.defineProperty,In=Object.getOwnPropertyDescriptor,On=(i,e,t,n)=>{for(var r=n>1?void 0:n?In(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Cn(e,t,r),r},W=(i,e)=>(t,n)=>e(t,n,i);const Ce=1.5;let re=class extends c.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 R;const e=this._textSelectionManagerService.getActiveRange(),t=this._getDocObject(),n=(R=this._docSkeletonManagerService.getCurrent())==null?void 0:R.skeleton;if(e==null||t==null||n==null)return;const{collapsed:r,startNodePosition:o}=e;if(!r)return;const s=t.document.getOffsetConfig(),{docsLeft:a,docsTop:u}=s,_=new m.NodePositionConvertToCursor(s,n),{contentBoxPointGroup:p}=_.getRangePointData(o,o),{left:f,top:v,height:I}=m.getAnchorBounding(p),S=f+a,h=v+u,g=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN),b=!!this._editorService.getEditor(i);if(g==null)return;const{left:T,top:D,right:E,bottom:x}=g.getBounding().viewBound;let N=0,B=0;const H=b?0:100;h<D?N=h-D:h>x-I&&(N=h-x+I+H),S<T?B=S-T:S>E-Ce&&(B=S-E+Ce);const Y=g.getBarScroll(B,N);g.scrollBy(Y)}_getDocObject(){return d.getDocObject(this._currentUniverService,this._renderManagerService)}};re=On([c.OnLifecycle(c.LifecycleStages.Rendered,re),W(0,O.Inject(d.DocSkeletonManagerService)),W(1,O.Inject(d.TextSelectionManagerService)),W(2,l.IEditorService),W(3,c.IUniverInstanceService),W(4,m.IRenderManagerService)],re);var bn=Object.defineProperty,Mn=Object.getOwnPropertyDescriptor,Tn=(i,e,t,n)=>{for(var r=n>1?void 0:n?Mn(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&&bn(e,t,r),r},de=(i,e)=>(t,n)=>e(t,n,i),ue;exports.UniverDocsUIPlugin=(ue=class extends c.Plugin{constructor(e,t,n,r){super(Me),this._config=e,this._injector=t,this._localeService=n,this._logService=r,this._localeService.load({zhCN:Pe}),this._config=c.Tools.deepMerge({},be,this._config),this._initDependencies(t),this._initializeCommands()}onRendered(){this._initModules(),this._markDocAsFocused()}onDestroy(){}_initializeCommands(){[je,We,ze,Ve,ke,He,Ye,Ge,Ke,yt,Dt,Rt].forEach(e=>{this._injector.get(l.IShortcutService).registerShortcut(e)})}_initDependencies(e){[[q],[X],[Z],[J],[Q],[ee],[te],[ne],[re],[V,{useFactory:()=>this._injector.createInstance(V,this._config)}],[k,{useClass:_e}],[exports.DocCanvasView]].forEach(n=>{e.add(n)})}_markDocAsFocused(){const e=this._injector.get(c.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)}},C(ue,"type",c.PluginType.Doc),ue);exports.UniverDocsUIPlugin=Tn([de(1,O.Inject(O.Injector)),de(2,O.Inject(c.LocaleService)),de(3,c.ILogService)],exports.UniverDocsUIPlugin);exports.DOC_UI_PLUGIN_NAME=Me;exports.DefaultDocContainerConfig=Oe;exports.DefaultDocUiConfig=be;exports.DefaultToolbarConfig=Ie;exports.enUS=Tt;exports.zhCN=Pe;
|