@univerjs/docs-ui 0.1.14 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +3 -3
- package/lib/es/index.js +47 -48
- package/lib/umd/index.js +3 -3
- package/package.json +17 -16
package/lib/cjs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var je=Object.defineProperty;var Ve=(i,e,t)=>e in i?je(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var C=(i,e,t)=>
|
|
1
|
+
"use strict";var je=Object.defineProperty;var Ve=(i,e,t)=>e in i?je(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var C=(i,e,t)=>Ve(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),O=require("@wendellhu/redi"),l=require("@univerjs/ui"),d=require("@univerjs/docs"),We=require("@wendellhu/redi/react-bindings"),f=require("@univerjs/engine-render"),He=require("react"),T=require("rxjs"),ke=require("@univerjs/design"),Me={undo:!0,redo:!0,font:!0,fontSize:!0,bold:!0,italic:!0,strikethrough:!0,underline:!0,textColor:!0,fillColor:!0,horizontalAlignMode:!0,verticalAlignMode:!0,textWrapMode:!0,textRotateMode:!0},ye={outerLeft:!1,outerRight:!1,header:!0,footer:!0,innerLeft:!1,innerRight:!1,frozenHeaderLT:!1,frozenHeaderRT:!1,frozenHeaderLM:!1,frozenContent:!1,infoBar:!0,toolbar:!0},Ee={layout:{docContainerConfig:ye,toolbarConfig:Me}},De="DocUI";function M(i){return i.getContextValue(a.FOCUSING_DOC)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function ze(i){return i.getContextValue(a.FOCUSING_DOC)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(a.FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE)&&!i.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}const Ye={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_UP,preconditions:M,staticParameters:{direction:a.Direction.UP}},Ge={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_DOWN,preconditions:M,staticParameters:{direction:a.Direction.DOWN}},Ke={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_LEFT,preconditions:M,staticParameters:{direction:a.Direction.LEFT}},Xe={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_RIGHT,preconditions:M,staticParameters:{direction:a.Direction.RIGHT}},qe={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_UP|l.MetaKeys.SHIFT,preconditions:M,staticParameters:{direction:a.Direction.UP}},Ze={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_DOWN|l.MetaKeys.SHIFT,preconditions:M,staticParameters:{direction:a.Direction.DOWN}},Je={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_LEFT|l.MetaKeys.SHIFT,preconditions:M,staticParameters:{direction:a.Direction.LEFT}},Qe={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_RIGHT|l.MetaKeys.SHIFT,preconditions:M,staticParameters:{direction:a.Direction.RIGHT}},et={id:d.SelectAllOperation.id,binding:l.KeyCode.A|l.MetaKeys.CTRL_COMMAND,preconditions:i=>i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&(i.getContextValue(a.FOCUSING_DOC)||i.getContextValue(a.EDITOR_ACTIVATED))};var tt=Object.defineProperty,nt=Object.getOwnPropertyDescriptor,it=(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},ve=(i,e)=>(t,n)=>e(t,n,i);let pe=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}};pe=it([ve(1,O.Inject(a.LocaleService)),ve(2,O.Inject(O.Injector))],pe);var rt=Object.defineProperty,ot=Object.getOwnPropertyDescriptor,st=(i,e,t,n)=>{for(var r=n>1?void 0:n?ot(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},z=(i,e)=>(t,n)=>e(t,n,i);let W=class extends a.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(pe,e),this._registerContainer()}_registerContainer(){this._layoutService&&this.disposeWithMe(this._layoutService.registerContainerElement(this._textSelectionRenderManager.__getEditorContainer()))}getDocContainerController(){return this._docContainerController}};W=st([z(1,O.Inject(a.LocaleService)),z(2,O.Inject(O.Injector)),z(3,f.ITextSelectionRenderManager),z(4,O.Optional(l.ILayoutService))],W);const oe="UI_PLUGIN_DOCS",_e=`${oe}_COLOR_PICKER_COMPONENT`,Pe=`${oe}_FONT_FAMILY_COMPONENT`,xe=`${oe}_FONT_FAMILY_ITEM_COMPONENT`,Ue=`${oe}_FONT_SIZE_COMPONENT`;var Ne={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 at=He,ct=Symbol.for("react.element"),lt=Symbol.for("react.fragment"),dt=Object.prototype.hasOwnProperty,ut=at.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,ht={key:!0,ref:!0,__self:!0,__source:!0};function Le(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)dt.call(e,n)&&!ht.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:ct,type:i,key:o,ref:s,props:r,_owner:ut.current}}se.Fragment=lt;se.jsx=Le;se.jsxs=Le;Ne.exports=se;var pt=Ne.exports;const gt="univer-docs-ui-canvas-background",_t={docsUiCanvasBackground:gt},St=()=>pt.jsx("div",{className:_t.docsUiCanvasBackground});function mt(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatBoldCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.bl;t.next(u===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function ft(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatItalicCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.it;t.next(u===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function vt(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatUnderlineCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.ul;t.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function It(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatStrikethroughCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.st;t.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Ct(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatSubscriptCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.va;t.next(u===a.BaselineOffset.SUBSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Ot(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatSuperscriptCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.va;t.next(u===a.BaselineOffset.SUPERSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Tt(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatFontFamilyCommand.id,tooltip:"toolbar.font",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,label:Pe,positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_FAMILY_LIST.map(t=>({label:{name:xe,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===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontFamilyCommand.id){const u=E(i);if(u==null)return;const h=(c=u.ts)==null?void 0:c.ff;t.next(h!=null?h:n)}});return t.next(n),r.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function bt(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatFontSizeCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Ue,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===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontSizeCommand.id){const u=E(i);if(u==null)return;const h=(c=u.ts)==null?void 0:c.fs;t.next(h!=null?h:14)}});return t.next(14),r.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Rt(i){const e=i.get(a.ICommandService),t=i.get(a.ThemeService);return{id:d.SetInlineFormatTextColorCommand.id,icon:"FontColor",tooltip:"toolbar.textColor.main",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON_SELECTOR,positions:[l.MenuPosition.TOOLBAR_START],selections:[{label:{name:_e,hoverable:!1}}],value$:new T.Observable(n=>{const r=t.getCurrentTheme().textColor,o=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextColorCommand.id){const c=s.params.value;n.next(c!=null?c:r)}});return n.next(r),o.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Mt(i){const e=i.get(a.ICommandService);return{id:d.AlignLeftCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=ae(i);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.LEFT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function yt(i){const e=i.get(a.ICommandService);return{id:d.AlignCenterCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=ae(i);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.CENTER)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Et(i){const e=i.get(a.ICommandService);return{id:d.AlignRightCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=ae(i);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.RIGHT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Dt(i){const e=i.get(a.ICommandService);return{id:d.AlignJustifyCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=ae(i);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.JUSTIFIED)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Pt(i){return{id:d.OrderListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"OrderSingle",tooltip:"toolbar.order",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function xt(i){return{id:d.BulletListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"UnorderSingle",tooltip:"toolbar.unorder",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Ut(i){return{id:d.ResetInlineFormatTextBackgroundColorCommand.id,type:l.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:d.SetInlineFormatTextBackgroundColorCommand.id}}function Nt(i){const e=i.get(a.ICommandService),t=i.get(a.ThemeService);return{id:d.SetInlineFormatTextBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON_SELECTOR,positions:[l.MenuPosition.TOOLBAR_START],icon:"PaintBucket",selections:[{label:{name:_e,hoverable:!1}}],value$:new T.Observable(n=>{const r=t.getCurrentTheme().primaryColor,o=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextBackgroundColorCommand.id){const c=s.params.value;n.next(c!=null?c:r)}});return n.next(r),o.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function E(i){var u;const e=i.get(a.IUniverInstanceService),t=i.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const o=(u=n.getBody())==null?void 0:u.textRuns;if(o==null)return;const{startOffset:s}=r;let c;for(let h=0;h<o.length;h++){const g=o[h],_=o[h+1];if(_&&_.st===_.ed&&s===_.st){c=_;break}if(g.st<=s&&s<=g.ed){c=g;break}}return c}function ae(i){var u;const e=i.get(a.IUniverInstanceService),t=i.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const o=(u=n.getBody())==null?void 0:u.paragraphs;if(o==null)return;const{startOffset:s}=r;let c=-1;for(const h of o){const{startIndex:g}=h;if(s>c&&s<=g)return h;c=g}return null}var Lt=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&&Lt(e,t,r),r},P=(i,e)=>(t,n)=>e(t,n,i);let H=class extends a.Disposable{constructor(i,e,t,n,r,o,s,c){super(),this._config=i,this._injector=e,this._componentManager=t,this._layoutService=n,this._editorService=r,this._menuService=o,this._uiPartsService=s,this._univerInstanceService=c,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(_e,ke.ColorPicker)),this.disposeWithMe(i.register(Pe,l.FontFamily)),this.disposeWithMe(i.register(xe,l.FontFamilyItem)),this.disposeWithMe(i.register(Ue,l.FontSize))}_initMenus(){const{menu:i={}}=this._config;[mt,ft,vt,It,Ct,Ot,bt,Tt,Rt,Mt,yt,Et,Dt,Pt,xt,Ut,Nt].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e),i))})}_init(){this._initCustomComponents(),this._initMenus(),this._initDocBackground(),this._initFocusHandler()}_initDocBackground(){const i=this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC)[0].getUnitId();if(i==null)return;this._editorService.isEditor(i)||this.disposeWithMe(this._uiPartsService.registerComponent(l.BuiltInUIPart.CONTENT,()=>We.connectInjector(St,this._injector)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.UNIVER_DOC,()=>{this._injector.get(m.ITextSelectionRenderManager).focus()}))}};H=Bt([a.OnLifecycle(a.LifecycleStages.Rendered,H),P(1,O.Inject(O.Injector)),P(2,O.Inject(l.ComponentManager)),P(3,l.ILayoutService),P(4,l.IEditorService),P(5,l.IMenuService),P(6,l.IUIPartsService),P(7,a.IUniverInstanceService)],H);const Ft={id:d.BreakLineCommand.id,preconditions:ze,binding:l.KeyCode.ENTER},wt={id:d.DeleteLeftCommand.id,preconditions:M,binding:l.KeyCode.BACKSPACE},$t={id:d.DeleteRightCommand.id,preconditions:M,binding:l.KeyCode.DELETE},jt=10,Vt=6;function Wt(){return a.Tools.generateRandomId(Vt)}function Ht(i){const e=i.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class kt{constructor(){C(this,"_cache",new a.LRUMap(jt))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}clear(){this._cache.clear()}}const Ie=new kt;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: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 zt(i){const e=new DOMParser,t=`<x-univer id="univer-root">${i}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function Ce(i,e){const t=i.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(i)}const re=class re{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=re._pluginList.find(o=>o.checkPasteType(e)),n=zt(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:_})=>Ce(o,_)),u=c?c.getStyle(o):Se(o);this._styleCache.set(o,{...s,...u});const{childNodes:h}=o;this._process(o,h,n);const g=this._afterProcessRules.find(({filter:_})=>Ce(o,_));g&&g.handler(n,o)}}};C(re,"_pluginList",[]);let A=re;const Yt={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"}}]},Ae=Yt;function Be(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 Gt={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=Be(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]},Fe=Gt,Kt={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=Be(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]},we=Kt;function Oe(i,e){const{st:t,ed:n,ts:r={}}=e,{ff:o,fs:s,it:c,bl:u,ul:h,st:g,ol:_,bg:v,cl:S,va:f}=r;let p=i.slice(t,n);const I=[];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>`),(g==null?void 0:g.s)===a.BooleanNumber.TRUE&&(p=`<s>${p}</s>`),u===a.BooleanNumber.TRUE&&(p=`<strong>${p}</strong>`),o&&I.push(`font-family: ${o}`),S&&I.push(`color: ${S.rgb}`),s&&I.push(`font-size: ${s}pt`),_&&I.push("text-decoration: overline"),v&&I.push(`background: ${v.rgb}`),I.length?`<span style="${I.join("; ")};">${p}</span>`:p}function ue(i,e,t){const{dataStream:n,textRuns:r=[]}=i;let o=e;const s=[];for(const c of r){const{st:u,ed:h}=c;a.Tools.hasIntersectionBetweenTwoRanges(e,t,u,h)&&(u>o?(s.push(n.slice(o,u)),s.push(Oe(n,{...c,ed:Math.min(h,t)}))):s.push(Oe(n,{...c,st:o,ed:Math.min(h,t)}))),o=Math.max(e,Math.min(h,t))}return o!==t&&s.push(n.slice(o,t)),s.join("")}function Te(i,e=!0){var t;if(e&&((t=i.paragraphs)!=null&&t.length)){const{dataStream:n,paragraphs:r=[]}=i;let o="",s=-1;for(const c of r){const{startIndex:u,paragraphStyle:h={}}=c,{spaceAbove:g,spaceBelow:_,lineSpacing:v}=h,S=[];g!=null&&(typeof g=="number"?S.push(`margin-top: ${g}px`):S.push(`margin-top: ${g.v}px`)),_!=null&&(typeof _=="number"?S.push(`margin-bottom: ${_}px`):S.push(`margin-bottom: ${_.v}px`)),v!=null&&S.push(`line-height: ${v}`),u>s+1?o+=`<p class="UniverNormal" ${S.length?`style="${S.join("; ")};"`:""}>${ue(i,s+1,u)}</p>`:o+=`<p class="UniverNormal" ${S.length?`style="${S.join("; ")};"`:""}></p>`,s=u}return s!==n.length&&(o+=ue(i,s,n.length)),o}else return ue(i,0,i.dataStream.length)}class Xt{convert(e){if(e.length===0)throw new Error("The bodyList length at least to be 1");if(e.length===1)return Te(e[0]);let t="";for(const n of e)t+='<p className="UniverNormal">',t+=Te(n,!1),t+="</p>";return t}}var qt=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&&qt(e,t,r),r},$=(i,e)=>(t,n)=>e(t,n,i);A.use(Fe);A.use(Ae);A.use(we);function Qt(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 ge=class extends a.Disposable{constructor(e,t,n,r,o){super();C(this,"_clipboardHooks",[]);C(this,"_htmlToUDM",new A);C(this,"_umdToHtml",new Xt);this._univerInstanceService=e,this._logService=t,this._commandService=n,this._clipboardInterfaceService=r,this._textSelectionManagerService=o}async copy(){const e=this._getDocumentBodyInRanges();if(e.length===0)return!1;try{this._setClipboardData(e)}catch(t){return this._logService.error("[DocClipboardService] copy failed",t),!1}return!0}async cut(){return this._cut()}async paste(e){const t=await this._generateBodyFromClipboardItems(e);return this._paste(t)}async legacyPaste(e,t){const n=this._generateBodyFromHtmlAndText(e,t);return this._paste(n)}async _cut(){var o;const{segmentId:e,endOffset:t,style:n}=(o=this._textSelectionManagerService.getActiveRange())!=null?o:{},r=this._textSelectionManagerService.getSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),t==null||r==null)return!1;this.copy();try{let s=t;for(const u of r){const{startOffset:h,endOffset:g}=u;h==null||g==null||g<=t&&(s-=g-h)}const c=[{startOffset:s,endOffset:s,style:n}];return this._commandService.executeCommand(d.CutContentCommand.id,{segmentId:e,textRanges:c})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(e){var s;const{segmentId:t,endOffset:n,style:r}=(s=this._textSelectionManagerService.getActiveRange())!=null?s:{},o=this._textSelectionManagerService.getSelections();if(t==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),n==null||o==null)return!1;try{let c=n;for(const h of o){const{startOffset:g,endOffset:_}=h;g==null||_==null||_<=n&&(c+=e.dataStream.length-(_-g))}const u=[{startOffset:c,endOffset:c,style:r}];return this._commandService.executeCommand(d.InnerPasteCommand.id,{body:e,segmentId:t,textRanges:u})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(e){const t=Wt(),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}"`),Ie.set(t,e[0])),this._clipboardInterfaceService.write(n,r)}addClipboardHook(e){return this._clipboardHooks.push(e),a.toDisposable(()=>{const t=this._clipboardHooks.indexOf(e);t>-1&&this._clipboardHooks.splice(t,1)})}_getDocumentBodyInRanges(){const e=this._textSelectionManagerService.getSelections(),t=this._univerInstanceService.getCurrentUniverDocInstance(),n=[];if(e==null||!t)return n;for(const r of e){const{startOffset:o,endOffset:s,collapsed:c}=r;if(c||o==null||s==null)continue;const u=t.sliceBody(o,s);u!=null&&n.push(u)}return n}async _generateBodyFromClipboardItems(e){try{let t="",n="";for(const r of e)for(const o of r.types)o===l.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await r.getType(o).then(s=>s&&s.text()):o===l.HTML_CLIPBOARD_MIME_TYPE&&(t=await r.getType(o).then(s=>s&&s.text()));return this._generateBodyFromHtmlAndText(t,n)}catch(t){return Promise.reject(t)}}_generateBodyFromHtmlAndText(e,t){if(!e){if(t)return Qt(t);throw new Error("[DocClipboardService] html and text cannot be both empty!")}const n=Ht(e);if(n){const r=Ie.get(n);if(r)return r}return this._htmlToUDM.convert(e)}};ge=Jt([$(0,a.IUniverInstanceService),$(1,a.ILogService),$(2,a.ICommandService),$(3,l.IClipboardInterfaceService),$(4,O.Inject(d.TextSelectionManagerService))],ge);function ce(i){return i.getContextValue(a.FOCUSING_DOC)||i.getContextValue(a.EDITOR_ACTIVATED)}const me=999,en={id:l.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:me,preconditions:ce,handler:async i=>i.get(k).copy()},tn={id:l.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:me,preconditions:ce,handler:async i=>i.get(k).cut()},nn={id:l.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:me,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 rn=Object.defineProperty,on=Object.getOwnPropertyDescriptor,sn=(i,e,t,n)=>{for(var r=n>1?void 0:n?on(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&rn(e,t,r),r},j=(i,e)=>(t,n)=>e(t,n,i);let Z=class extends a.RxDisposable{constructor(i,e,t,n,r){super(),this._commandService=i,this._clipboardInterfaceService=e,this._docClipboardService=t,this._textSelectionRenderManager=n,this._contextService=r,this._init()}_init(){[en,tn,nn].forEach(i=>this.disposeWithMe(this._commandService.registerMultipleCommand(i))),[d.InnerPasteCommand,d.CutContentCommand].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i))),this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var i;(i=this._textSelectionRenderManager)==null||i.onPaste$.pipe(T.takeUntil(this.dispose$)).subscribe(e=>{var 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)})}};Z=sn([a.OnLifecycle(a.LifecycleStages.Rendered,Z),j(0,a.ICommandService),j(1,l.IClipboardInterfaceService),j(2,k),j(3,m.ITextSelectionRenderManager),j(4,a.IContextService)],Z);var an=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,ln=(i,e,t,n)=>{for(var r=n>1?void 0:n?cn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&an(e,t,r),r},N=(i,e)=>(t,n)=>e(t,n,i);let J=class extends a.Disposable{constructor(e,t,n,r,o,s){super();C(this,"_initialEditors",new Set);this._univerInstanceService=e,this._docSkeletonManagerService=t,this._editorService=n,this._commandService=r,this._textSelectionRenderManager=o,this._renderManagerService=s,this._initialize()}_initialize(){this.disposeWithMe(this._editorService.resize$.subscribe(e=>{this._resize(e)})),this._editorService.getAllEditor().forEach(e=>{const t=e.editorUnitId;this._initialEditors.has(t)||(this._initialEditors.add(t),this._resize(t))}),this._commandExecutedListener(),this._initialSetValue(),this._initialBlur(),this._initialFocus(),this._initialValueChange()}_resize(e){var y,U,D;if(e==null)return;const t=this._editorService.getEditor(e);if((t==null?void 0:t.cancelDefaultResizeListener)===!0)return;const n=(y=this._docSkeletonManagerService.getSkeletonByUnitId(e))==null?void 0:y.skeleton,r=this._univerInstanceService.getUniverDocInstance(e);if(t==null||t.render==null||n==null||r==null)return;n.calculate();const{marginTop:o=0,marginBottom:s=0,marginLeft:c=0,marginRight:u=0}=r.getSnapshot().documentStyle,{scene:h,mainComponent:g}=t.render;let{actualHeight:_,actualWidth:v}=n.getActualSize();_+=o+s,v+=c+u;const{width:S,height:f}=t.getBoundingClientRect(),p=h.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);let I=p==null?void 0:p.getScrollBar();const b=Math.max(v,S),R=Math.max(_,f);h.transformByState({width:b,height:R}),g==null||g.resize(b,R),t.isSingle()?v>S?I==null?p&&new m.ScrollBar(p,{barSize:8,enableVertical:!1}):p==null||p.resetSizeAndScrollBar():(I=null,p==null||p.scrollTo({x:0,y:0}),(D=p==null?void 0:p.getScrollBar())==null||D.dispose()):_>f?I==null?p&&new m.ScrollBar(p,{enableHorizontal:!1,barSize:8}):p==null||p.resetSizeAndScrollBar():(I=null,p==null||p.scrollTo({x:0,y:0}),(U=p==null?void 0:p.getScrollBar())==null||U.dispose())}_initialSetValue(){this.disposeWithMe(this._editorService.setValue$.subscribe(e=>{this._commandService.executeCommand(d.CoverContentCommand.id,{unitId:e.editorUnitId,body:e.body,segmentId:null})}))}_initialBlur(){this.disposeWithMe(this._editorService.blur$.subscribe(()=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.blur()})),this.disposeWithMe(this._textSelectionRenderManager.onBlur$.subscribe(()=>{var r;const e=(r=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:r.getUnitId();if(e==null)return;const t=this._editorService.getEditor(e),n=this._editorService.getFocusEditor();t==null||t.isSheetEditor()||n&&n.editorUnitId===e||this._editorService.blur()}))}_initialFocus(){this.disposeWithMe(this._editorService.focus$.subscribe(n=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges([n])}));const e=["univer-formula-search","univer-formula-help","formula-help-decorator","univer-formula-help-param"];this.disposeWithMe(T.fromEvent(window,"mousedown").subscribe(n=>{const o=n.target.classList[0]||"";if(a.checkForSubstrings(o,e)){this._editorService.changeSpreadsheetFocusState(!0),n.stopPropagation();return}this._editorService.changeSpreadsheetFocusState(!1)})),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(n=>{const r=n.getUnitId(),o=this._renderManagerService.getRenderById(r),s=o==null?void 0:o.engine.getCanvas().getCanvasEle();s!=null&&T.fromEvent(s,"mousedown").subscribe(c=>{this._editorService.changeSpreadsheetFocusState(!0),c.stopPropagation()})})}_initialValueChange(){this.disposeWithMe(this._textSelectionRenderManager.onCompositionupdate$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onInput$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onKeydown$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onPaste$.subscribe(this._valueChange.bind(this)))}_valueChange(){var n;const e=(n=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:n.getUnitId();if(e==null)return;const t=this._editorService.getEditor(e);t==null||t.isSheetEditor()||this._editorService.refreshValueChange(e)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,l.SetEditorResizeOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=t.params,{unitId:r}=n;if(this._editorService.isSheetEditor(r))return;this._resize(r),this._valueChange()}}))}};J=ln([a.OnLifecycle(a.LifecycleStages.Rendered,J),N(0,a.IUniverInstanceService),N(1,O.Inject(d.DocSkeletonManagerService)),N(2,l.IEditorService),N(3,a.ICommandService),N(4,m.ITextSelectionRenderManager),N(5,m.IRenderManagerService)],J);var dn=Object.defineProperty,un=Object.getOwnPropertyDescriptor,hn=(i,e,t,n)=>{for(var r=n>1?void 0:n?un(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&dn(e,t,r),r},Y=(i,e)=>(t,n)=>e(t,n,i);let Q=class extends a.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(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,components:s}=r,c=o,u=s.get(d.DOCS_VIEW_KEY.BACKGROUND);c.changeSkeleton(t),u.changeSkeleton(t),this._recalculateSizeBySkeleton(r,t)}_recalculateSizeBySkeleton(e,t){var v;const{mainComponent:n,scene:r,unitId:o,components:s}=e,c=n,u=s.get(d.DOCS_VIEW_KEY.BACKGROUND),h=(v=t.getSkeletonData())==null?void 0:v.pages;if(h==null)return;let g=0,_=0;for(let S=0,f=h.length;S<f;S++){const p=h[S],{pageWidth:I,pageHeight:b}=p;c.pageLayoutType===m.PageLayoutType.VERTICAL?(_+=b,_+=c.pageMarginTop,S===f-1&&(_+=c.pageMarginTop),g=Math.max(g,I)):c.pageLayoutType===m.PageLayoutType.HORIZONTAL&&(g+=I,S!==f-1&&(g+=c.pageMarginLeft),_=Math.max(_,b))}c.resize(g,_),u.resize(g,_),this._editorService.isEditor(o)||r.resize(g,_)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=this._docSkeletonManagerService.getSkeletonByUnitId(o);if(s==null)return;const{skeleton:c}=s,u=this._renderManagerService.getRenderById(o);if(u==null||!!c.getViewModel().getDataModel().getSnapshot().disabled)return;if(c.calculate(),this._editorService.isEditor(o)){(n=u.mainComponent)==null||n.makeDirty();return}this._recalculateSizeBySkeleton(u,c)}}))}};Q=hn([a.OnLifecycle(a.LifecycleStages.Rendered,Q),Y(0,O.Inject(d.DocSkeletonManagerService)),Y(1,m.IRenderManagerService),Y(2,a.ICommandService),Y(3,l.IEditorService)],Q);var pn=Object.defineProperty,gn=Object.getOwnPropertyDescriptor,_n=(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},G=(i,e)=>(t,n)=>e(t,n,i);exports.DocCanvasView=class extends a.RxDisposable{constructor(t,n,r,o){super();C(this,"_scene");C(this,"_currentDocumentModel");C(this,"_fps$",new T.BehaviorSubject(""));C(this,"fps$",this._fps$.asObservable());this._renderManagerService=t,this._configService=n,this._univerInstanceService=r,this._editorService=o,this._initialize()}_initialize(){this._renderManagerService.createRender$.pipe(T.takeUntil(this.dispose$)).subscribe(t=>{this._create(t)}),this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC).pipe(T.takeUntil(this.dispose$)).subscribe(t=>{this._create(t==null?void 0:t.getUnitId())}),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC).forEach(t=>{this._create(t.getUnitId())})}dispose(){this._fps$.complete()}_create(t){if(t==null)return;const n=this._univerInstanceService.getUniverDocInstance(t);n!=null&&(this._currentDocumentModel=n,this._renderManagerService.has(t)||this._addNewRender())}_addNewRender(){const n=this._currentDocumentModel.getUnitId();this._renderManagerService.createRender(n);const r=this._renderManagerService.getRenderById(n);if(r==null)return;const{scene:o,engine:s}=r;this._scene=o;const c=new m.Viewport(d.VIEWPORT_KEY.VIEW_MAIN,o,{left:0,top:0,bottom:0,right:0,isRelativeX:!0,isRelativeY:!0,isWheelPreventDefaultX:!0});o.attachControl(),o.on(m.EVENT_TYPE.wheel,(g,_)=>{const v=g;if(v.ctrlKey){const S=Math.abs(v.deltaX);let f=S<40?.2:S<80?.4:.2;f*=v.deltaY>0?-1:1,o.scaleX<1&&(f/=2),o.scaleX+f>4?o.scale(4,4):o.scaleX+f<.1?o.scale(.1,.1):v.preventDefault()}else c.onMouseWheel(v,_)}),this._configService.getConfig("hasScroll")!==!1&&new m.ScrollBar(c),o.addLayer(new m.Layer(o,[],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),new m.Layer(o,[],d.DOCS_COMPONENT_HEADER_LAYER_INDEX)),this._addComponent(r),this._currentDocumentModel.getShouldRenderLoopImmediately()&&s.runRenderLoop(()=>{o.render(),this._fps$.next(Math.round(s.getFps()).toString())}),this._renderManagerService.setCurrent(n)}_addComponent(t){const n=this._scene,r=this._currentDocumentModel,o={pageMarginLeft:r.documentStyle.marginLeft||0,pageMarginTop:r.documentStyle.marginTop||0},s=new m.Documents(d.DOCS_VIEW_KEY.MAIN,void 0,o),c=new m.DocBackground(d.DOCS_VIEW_KEY.BACKGROUND,void 0,o);s.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX,c.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX,t.mainComponent=s,t.components.set(d.DOCS_VIEW_KEY.MAIN,s),t.components.set(d.DOCS_VIEW_KEY.BACKGROUND,c),n.addObjects([s],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),n.addObjects([c],d.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX),this._editorService.getEditor(r.getUnitId())==null&&n.enableLayerCache(d.DOCS_COMPONENT_MAIN_LAYER_INDEX)}};exports.DocCanvasView=_n([a.OnLifecycle(a.LifecycleStages.Starting,exports.DocCanvasView),G(0,m.IRenderManagerService),G(1,a.IConfigService),G(2,a.IUniverInstanceService),G(3,l.IEditorService)],exports.DocCanvasView);var Sn=Object.defineProperty,mn=Object.getOwnPropertyDescriptor,fn=(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&&Sn(e,t,r),r},K=(i,e)=>(t,n)=>e(t,n,i);let ee=class extends a.Disposable{constructor(e,t,n,r){super();C(this,"_liquid",new m.Liquid);C(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=e,this._renderManagerService=t,this._commandService=n,this._editorService=r,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh(),this._updateOnPluginChange()}_updateOnPluginChange(){}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{skeleton:t,unitId:n}=e,r=this._renderManagerService.getRenderById(n);if(r==null)return;const{mainComponent:o}=r;o.changeSkeleton(t),this._refreshDrawing(n,t,r)})}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=this._docSkeletonManagerService.getCurrent();if(s==null)return;const{unitId:c,skeleton:u}=s;if(o!==c)return;const h=this._renderManagerService.getRenderById(c);if(h==null)return;if(this._editorService.isEditor(c)){(n=h.mainComponent)==null||n.makeDirty();return}this._refreshDrawing(c,u,h)}}))}_refreshDrawing(e,t,n){const r=t==null?void 0:t.getSkeletonData(),{mainComponent:o,scene:s}=n,c=o;if(!r)return;const{left:u,top:h,pageLayoutType:g,pageMarginLeft:_,pageMarginTop:v}=c,{pages:S}=r,f=[];s.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let p=0,I=S.length;p<I;p++){const b=S[p],{skeDrawings:R,marginLeft:y,marginTop:U}=b;this._liquid.translatePagePadding(b),R.forEach(D=>{const{aLeft:B,aTop:F,height:le,width:de,drawingId:w,drawingOrigin:fe}=D,$e=fe.layoutType===a.PositionedObjectLayoutType.WRAP_NONE&&fe.behindDoc===a.BooleanNumber.TRUE;f.push({unitId:e,subUnitId:a.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:w,behindText:$e,floatingObject:{left:B+u+this._liquid.x,top:F+h+this._liquid.y,width:de,height:le}}),this._pageMarginCache.set(w,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.restorePagePadding(b),this._liquid.translatePage(b,g,_,v)}}};ee=fn([a.OnLifecycle(a.LifecycleStages.Steady,ee),K(0,O.Inject(d.DocSkeletonManagerService)),K(1,m.IRenderManagerService),K(2,a.ICommandService),K(3,l.IEditorService)],ee);var vn=Object.defineProperty,In=Object.getOwnPropertyDescriptor,Cn=(i,e,t,n)=>{for(var r=n>1?void 0:n?In(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&vn(e,t,r),r},L=(i,e)=>(t,n)=>e(t,n,i);let te=class extends a.Disposable{constructor(e,t,n,r,o,s){super();C(this,"_initializedRender",new Set);this._docSkeletonManagerService=e,this._univerInstanceService=t,this._commandService=n,this._renderManagerService=r,this._textSelectionManagerService=o,this._editorService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._initialRenderRefresh()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t}=e,n=this._renderManagerService.getRenderById(t);if(n==null||this._initializedRender.has(t)||this._editorService.isEditor(t))return;this._initializedRender.add(t);const{scene:r}=n;this.disposeWithMe(a.toDisposable(r.onMouseWheelObserver.add(o=>{if(!o.ctrlKey)return;const s=this._univerInstanceService.getCurrentUniverDocInstance();if(!s)return;const c=Math.abs(o.deltaX);let u=c<40?.2:c<80?.4:.2;u*=o.deltaY>0?-1:1,r.scaleX<1&&(u/=2);const h=s.zoomRatio;let g=+Number.parseFloat(`${h+u}`).toFixed(1);g=g>=4?4:g<=.1?.1:g,this._commandService.executeCommand(d.SetDocZoomRatioCommand.id,{zoomRatio:g,unitId:s.getUnitId()}),o.preventDefault()})))})}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const t=this._univerInstanceService.getCurrentUniverDocInstance();if(!t)return;const n=t.zoomRatio||1;this._updateViewZoom(n,!1)})))}_commandExecutedListener(){const e=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=this._univerInstanceService.getCurrentUniverDocInstance();if(!n)return;const r=t.params,{unitId:o}=r;if(o!==n.getUnitId())return;const s=n.zoomRatio||1;this._updateViewZoom(s)}}))}_updateViewZoom(e,t=!0){var r;const n=this._getDocObject();n!=null&&(n.scene.scale(e,e),this._calculatePagePosition(n,e),t&&this._textSelectionManagerService.refreshSelection(),(r=n.scene.getTransformer())==null||r.clearSelectedObjects())}_calculatePagePosition(e,t){const{document:n,scene:r,docBackground:o}=e,s=r==null?void 0:r.getParent(),{width:c,height:u,pageMarginLeft:h,pageMarginTop:g}=n;if(s==null||c===Number.POSITIVE_INFINITY||u===Number.POSITIVE_INFINITY)return;const{width:_,height:v}=s;let S=0,f=0,p=0,I=0,b=Number.POSITIVE_INFINITY;_>(c+h*2)*t?(S=_/2-c*t/2,S/=t,p=(_-h*2)/t,b=0):(S=h,p=c+h*2,b=(p-_/t)/2),v>u?(f=v/2-u/2,I=(v-g*2)/t):(f=g,I=u+g*2),r.resize(p,I+200),n.translate(S,f),o.translate(S,f);const R=r.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(b!==Number.POSITIVE_INFINITY&&R!=null){const y=R.getBarScroll(b,0).x;R.scrollTo({x:y})}return this}_getDocObject(){return d.getDocObject(this._univerInstanceService,this._renderManagerService)}};te=Cn([a.OnLifecycle(a.LifecycleStages.Rendered,te),L(0,O.Inject(d.DocSkeletonManagerService)),L(1,a.IUniverInstanceService),L(2,a.ICommandService),L(3,m.IRenderManagerService),L(4,O.Inject(d.TextSelectionManagerService)),L(5,l.IEditorService)],te);var On=Object.defineProperty,Tn=Object.getOwnPropertyDescriptor,bn=(i,e,t,n)=>{for(var r=n>1?void 0:n?Tn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&On(e,t,r),r},x=(i,e)=>(t,n)=>e(t,n,i);let ne=class extends a.Disposable{constructor(e,t,n,r,o,s,c){super();C(this,"_loadedMap",new WeakSet);this._docSkeletonManagerService=e,this._univerInstanceService=t,this._commandService=n,this._renderManagerService=r,this._textSelectionRenderManager=o,this._textSelectionManagerService=s,this._editorService=c,this._initialize()}_initialize(){this._init(),this._skeletonListener(),this._commandExecutedListener()}_init(){this.disposeWithMe(this._renderManagerService.currentRender$.subscribe(e=>{this._create(e)})),this._renderManagerService.getRenderAll().forEach((e,t)=>{this._create(t)})}_create(e){if(e==null||this._univerInstanceService.getUniverDocInstance(e)==null)return;const t=this._getDocObjectById(e);t==null||t.document==null||this._loadedMap.has(t.document)||(this._initialMain(e),this._loadedMap.add(t.document))}_initialMain(e){const t=this._getDocObjectById(e);if(t==null)return;const{document:n,scene:r}=t;this.disposeWithMe(a.toDisposable(n.onPointerEnterObserver.add(()=>{this._isEditorReadOnly(e)||(n.cursor=m.CURSOR_TYPE.TEXT)}))),this.disposeWithMe(a.toDisposable(n.onPointerLeaveObserver.add(()=>{n.cursor=m.CURSOR_TYPE.DEFAULT,r.resetCursor()}))),this.disposeWithMe(a.toDisposable(n==null?void 0:n.onPointerDownObserver.add((o,s)=>{if(this._isEditorReadOnly(e))return;const c=this._univerInstanceService.getCurrentUniverDocInstance();(c==null?void 0:c.getUnitId())!==e&&this._univerInstanceService.setCurrentUnitForType(e),this._textSelectionRenderManager.eventTrigger(o);const{offsetX:u,offsetY:h}=o;this._editorService.getEditor(e)&&(this._setEditorFocus(e),setTimeout(()=>{this._setEditorFocus(e),this._textSelectionRenderManager.setCursorManually(u,h)},0)),o.button!==2&&s.stopPropagation()}))),this.disposeWithMe(a.toDisposable(n==null?void 0:n.onDblclickObserver.add(o=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleDblClick(o)}))),this.disposeWithMe(a.toDisposable(n==null?void 0:n.onTripleClickObserver.add(o=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleTripleClick(o)})))}_isEditorReadOnly(e){const t=this._editorService.getEditor(e);return t?t.isReadOnly():!1}_setEditorFocus(e){if(this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).length>0){const n=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);this._editorService.setOperationSheetUnitId(n.getUnitId())}this._editorService.focusStyle(e)}_commandExecutedListener(){const e=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=(n=this._textSelectionManagerService.getCurrentSelection())==null?void 0:n.unitId;if(o!==s)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t,skeleton:n}=e,r=this._renderManagerService.getRenderById(t);if(r==null)return;const{scene:o,mainComponent:s}=r;this._textSelectionRenderManager.changeRuntime(n,o,s),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:t,subUnitId:""})}))}_getDocObjectById(e){return this._univerInstanceService.getUnitType(e)!==a.UniverInstanceType.UNIVER_DOC?null:d.getDocObjectById(e,this._renderManagerService)}};ne=bn([a.OnLifecycle(a.LifecycleStages.Rendered,ne),x(0,O.Inject(d.DocSkeletonManagerService)),x(1,a.IUniverInstanceService),x(2,a.ICommandService),x(3,m.IRenderManagerService),x(4,m.ITextSelectionRenderManager),x(5,O.Inject(d.TextSelectionManagerService)),x(6,l.IEditorService)],ne);var Rn=Object.defineProperty,Mn=Object.getOwnPropertyDescriptor,yn=(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&&Rn(e,t,r),r},V=(i,e)=>(t,n)=>e(t,n,i);const be=1.5;let ie=class extends a.RxDisposable{constructor(i,e,t,n,r){super(),this._docSkeletonManagerService=i,this._textSelectionManagerService=e,this._editorService=t,this._univerInstanceService=n,this._renderManagerService=r,this._init()}_init(){this._textSelectionManagerService.textSelection$.pipe(T.takeUntil(this.dispose$)).subscribe(i=>{if(i==null)return;const{isEditing:e,unitId:t}=i;e&&this._scrollToSelection(t)})}_scrollToSelection(i){var w;const e=this._textSelectionManagerService.getActiveRange(),t=this._getDocObject(),n=(w=this._docSkeletonManagerService.getCurrent())==null?void 0:w.skeleton;if(e==null||t==null||n==null)return;const{collapsed:r,startNodePosition:o}=e;if(!r)return;const s=t.document.getOffsetConfig(),{docsLeft:c,docsTop:u}=s,h=new m.NodePositionConvertToCursor(s,n),{contentBoxPointGroup:g}=h.getRangePointData(o,o),{left:_,top:v,height:S}=m.getAnchorBounding(g),f=_+c,p=v+u,I=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN),b=!!this._editorService.getEditor(i);if(I==null)return;const{left:R,top:y,right:U,bottom:D}=I.getBounding().viewBound;let B=0,F=0;const le=b?0:100;p<y?B=p-y:p>D-S&&(B=p-D+S+le),f<R?F=f-R:f>U-be&&(F=f-U+be);const de=I.getBarScroll(F,B);I.scrollBy(de)}_getDocObject(){return d.getDocObject(this._univerInstanceService,this._renderManagerService)}};ie=yn([a.OnLifecycle(a.LifecycleStages.Rendered,ie),V(0,O.Inject(d.DocSkeletonManagerService)),V(1,O.Inject(d.TextSelectionManagerService)),V(2,l.IEditorService),V(3,a.IUniverInstanceService),V(4,m.IRenderManagerService)],ie);var En=Object.defineProperty,Dn=Object.getOwnPropertyDescriptor,Pn=(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&&En(e,t,r),r},X=(i,e)=>(t,n)=>e(t,n,i);function xn(i,e){const t=Re(i.left,i.top,e),n=Re(i.right,i.bottom,e);return{left:t.x,top:t.y,right:n.x,bottom:n.y}}function Re(i,e,t){const{scaleX:n,scaleY:r}=t.getAncestorScale(),o=t.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(!o)return{x:i,y:e};const{viewportScrollX:s,viewportScrollY:c}=o,u=(i-s)*n,h=(e-c)*r;return{x:u,y:h}}exports.DocCanvasPopManagerService=class extends a.Disposable{constructor(e,t,n,r){super(),this._globalPopupManagerService=e,this._renderManagerService=t,this._univerInstanceService=n,this._commandService=r}_createObjectPositionObserver(e,t){const n=()=>{const{scene:u}=t,{left:h,top:g,width:_,height:v}=e,S={left:h,right:h+_,top:g,bottom:g+v},f=xn(S,u);return{left:f.left,right:f.right,top:f.top,bottom:f.bottom}},r=n(),o=new T.BehaviorSubject(r),s=new a.DisposableCollection;s.add(this._commandService.onCommandExecuted(u=>{u.id===d.SetDocZoomRatioOperation.id&&o.next(n())}));const c=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);return s.add(c==null?void 0:c.onScrollAfterObserver.add(()=>{o.next(n())})),{position:r,position$:o,disposable:s}}attachPopupToObject(e,t){const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC).getUnitId(),o=this._renderManagerService.getRenderById(r);if(!o)return{dispose:()=>{}};const{position:s,position$:c,disposable:u}=this._createObjectPositionObserver(e,o),h=this._globalPopupManagerService.addPopup({...t,unitId:r,subUnitId:"default",anchorRect:s,anchorRect$:c});return{dispose:()=>{this._globalPopupManagerService.removePopup(h),c.complete(),u.dispose()}}}};exports.DocCanvasPopManagerService=Pn([X(0,O.Inject(l.ICanvasPopupService)),X(1,m.IRenderManagerService),X(2,a.IUniverInstanceService),X(3,a.ICommandService)],exports.DocCanvasPopManagerService);var Un=Object.defineProperty,Nn=Object.getOwnPropertyDescriptor,Ln=(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&&Un(e,t,r),r},he=(i,e)=>(t,n)=>e(t,n,i),q;exports.UniverDocsUIPlugin=(q=class extends a.Plugin{constructor(e,t,n,r){super(),this._config=e,this._injector=t,this._localeService=n,this._logService=r,this._config=a.Tools.deepMerge({},Ee,this._config),this._initDependencies(t),this._initializeCommands()}onRendered(){this._initModules(),this._markDocAsFocused()}_initializeCommands(){[Ye,Ge,Xe,Ke,qe,Ze,Je,Qe,et,wt,$t,Ft].forEach(e=>{this._injector.get(l.IShortcutService).registerShortcut(e)})}_initDependencies(e){[[H,{useFactory:()=>this._injector.createInstance(H,this._config)}],[Z],[J],[Q],[ee],[te],[ne],[ie],[W,{useFactory:()=>this._injector.createInstance(W,this._config)}],[k,{useClass:ge}],[exports.DocCanvasPopManagerService],[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();if(!n)return;const r=n.getUnitId();t.isEditor(r)||e.focusUnit(n.getUnitId())}catch(n){this._logService.warn(n)}}_initModules(){this._injector.get(W)}},C(q,"pluginName",De),C(q,"type",a.UniverInstanceType.UNIVER_DOC),q);exports.UniverDocsUIPlugin=Ln([he(1,O.Inject(O.Injector)),he(2,O.Inject(a.LocaleService)),he(3,a.ILogService)],exports.UniverDocsUIPlugin);function An(i){return{left:i.positionH.posOffset,top:i.positionV.posOffset,width:i.size.width,height:i.size.height}}function Bn(i,e=0,t=0){return{size:{width:i.width,height:i.height},positionH:{relativeFrom:a.ObjectRelativeFromH.MARGIN,posOffset:(i.left||0)-e},positionV:{relativeFrom:a.ObjectRelativeFromV.PAGE,posOffset:(i.top||0)-t},angle:i.angle||0}}exports.DOC_UI_PLUGIN_NAME=De;exports.DefaultDocContainerConfig=ye;exports.DefaultDocUiConfig=Ee;exports.DefaultToolbarConfig=Me;exports.PastePluginLark=Ae;exports.PastePluginUniver=we;exports.PastePluginWord=Fe;exports.docDrawingPositionToTransform=An;exports.transformToDocDrawingPosition=Bn;
|
|
9
|
+
*/var at=He,ct=Symbol.for("react.element"),lt=Symbol.for("react.fragment"),dt=Object.prototype.hasOwnProperty,ut=at.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,ht={key:!0,ref:!0,__self:!0,__source:!0};function Le(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)dt.call(e,n)&&!ht.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:ct,type:i,key:o,ref:s,props:r,_owner:ut.current}}se.Fragment=lt;se.jsx=Le;se.jsxs=Le;Ne.exports=se;var pt=Ne.exports;const gt="univer-docs-ui-canvas-background",_t={docsUiCanvasBackground:gt},St=()=>pt.jsx("div",{className:_t.docsUiCanvasBackground});function ft(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatBoldCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.bl;t.next(u===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function mt(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatItalicCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.it;t.next(u===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function vt(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatUnderlineCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.ul;t.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function It(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatStrikethroughCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.st;t.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Ct(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatSubscriptCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.va;t.next(u===a.BaselineOffset.SUBSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Ot(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatSuperscriptCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.va;t.next(u===a.BaselineOffset.SUPERSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Tt(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatFontFamilyCommand.id,tooltip:"toolbar.font",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,label:Pe,positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_FAMILY_LIST.map(t=>({label:{name:xe,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===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontFamilyCommand.id){const u=E(i);if(u==null)return;const h=(c=u.ts)==null?void 0:c.ff;t.next(h!=null?h:n)}});return t.next(n),r.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function bt(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatFontSizeCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Ue,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===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontSizeCommand.id){const u=E(i);if(u==null)return;const h=(c=u.ts)==null?void 0:c.fs;t.next(h!=null?h:14)}});return t.next(14),r.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Rt(i){const e=i.get(a.ICommandService),t=i.get(a.ThemeService);return{id:d.SetInlineFormatTextColorCommand.id,icon:"FontColor",tooltip:"toolbar.textColor.main",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON_SELECTOR,positions:[l.MenuPosition.TOOLBAR_START],selections:[{label:{name:_e,hoverable:!1}}],value$:new T.Observable(n=>{const r=t.getCurrentTheme().textColor,o=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextColorCommand.id){const c=s.params.value;n.next(c!=null?c:r)}});return n.next(r),o.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Mt(i){const e=i.get(a.ICommandService);return{id:d.AlignLeftCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=ae(i);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.LEFT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function yt(i){const e=i.get(a.ICommandService);return{id:d.AlignCenterCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=ae(i);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.CENTER)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Et(i){const e=i.get(a.ICommandService);return{id:d.AlignRightCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=ae(i);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.RIGHT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Dt(i){const e=i.get(a.ICommandService);return{id:d.AlignJustifyCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",positions:[l.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=ae(i);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.JUSTIFIED)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Pt(i){return{id:d.OrderListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"OrderSingle",tooltip:"toolbar.order",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function xt(i){return{id:d.BulletListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"UnorderSingle",tooltip:"toolbar.unorder",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Ut(i){return{id:d.ResetInlineFormatTextBackgroundColorCommand.id,type:l.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:d.SetInlineFormatTextBackgroundColorCommand.id}}function Nt(i){const e=i.get(a.ICommandService),t=i.get(a.ThemeService);return{id:d.SetInlineFormatTextBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON_SELECTOR,positions:[l.MenuPosition.TOOLBAR_START],icon:"PaintBucket",selections:[{label:{name:_e,hoverable:!1}}],value$:new T.Observable(n=>{const r=t.getCurrentTheme().primaryColor,o=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextBackgroundColorCommand.id){const c=s.params.value;n.next(c!=null?c:r)}});return n.next(r),o.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function E(i){var u;const e=i.get(a.IUniverInstanceService),t=i.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const o=(u=n.getBody())==null?void 0:u.textRuns;if(o==null)return;const{startOffset:s}=r;let c;for(let h=0;h<o.length;h++){const g=o[h],_=o[h+1];if(_&&_.st===_.ed&&s===_.st){c=_;break}if(g.st<=s&&s<=g.ed){c=g;break}}return c}function ae(i){var u;const e=i.get(a.IUniverInstanceService),t=i.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const o=(u=n.getBody())==null?void 0:u.paragraphs;if(o==null)return;const{startOffset:s}=r;let c=-1;for(const h of o){const{startIndex:g}=h;if(s>c&&s<=g)return h;c=g}return null}var Lt=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&&Lt(e,t,r),r},P=(i,e)=>(t,n)=>e(t,n,i);let H=class extends a.Disposable{constructor(i,e,t,n,r,o,s,c){super(),this._config=i,this._injector=e,this._componentManager=t,this._layoutService=n,this._editorService=r,this._menuService=o,this._uiPartsService=s,this._univerInstanceService=c,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(_e,ke.ColorPicker)),this.disposeWithMe(i.register(Pe,l.FontFamily)),this.disposeWithMe(i.register(xe,l.FontFamilyItem)),this.disposeWithMe(i.register(Ue,l.FontSize))}_initMenus(){const{menu:i={}}=this._config;[ft,mt,vt,It,Ct,Ot,bt,Tt,Rt,Mt,yt,Et,Dt,Pt,xt,Ut,Nt].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e),i))})}_init(){this._initCustomComponents(),this._initMenus(),this._initDocBackground(),this._initFocusHandler()}_initDocBackground(){const i=this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC)[0].getUnitId();if(i==null)return;this._editorService.isEditor(i)||this.disposeWithMe(this._uiPartsService.registerComponent(l.BuiltInUIPart.CONTENT,()=>We.connectInjector(St,this._injector)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.UNIVER_DOC,()=>{this._injector.get(f.ITextSelectionRenderManager).focus()}))}};H=Bt([a.OnLifecycle(a.LifecycleStages.Rendered,H),P(1,O.Inject(O.Injector)),P(2,O.Inject(l.ComponentManager)),P(3,l.ILayoutService),P(4,l.IEditorService),P(5,l.IMenuService),P(6,l.IUIPartsService),P(7,a.IUniverInstanceService)],H);const Ft={id:d.BreakLineCommand.id,preconditions:ze,binding:l.KeyCode.ENTER},wt={id:d.DeleteLeftCommand.id,preconditions:M,binding:l.KeyCode.BACKSPACE},$t={id:d.DeleteRightCommand.id,preconditions:M,binding:l.KeyCode.DELETE},jt=10,Vt=6;function Wt(){return a.Tools.generateRandomId(Vt)}function Ht(i){const e=i.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class kt{constructor(){C(this,"_cache",new a.LRUMap(jt))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}clear(){this._cache.clear()}}const Ie=new kt;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:s.endsWith("px")&&(t.fs=f.pixelToPt(c)));break}case"font-style":{s==="italic"&&(t.it=a.BooleanNumber.TRUE);break}case"font-weight":{Number(s)>400&&(t.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(s)?t.ul={s:a.BooleanNumber.TRUE}:/overline/.test(s)?t.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(s)&&(t.st={s:a.BooleanNumber.TRUE});break}case"color":{const c=new a.ColorKit(s);c.isValid&&(t.cl={rgb:c.toRgbString()});break}case"background-color":{const c=new a.ColorKit(s);c.isValid&&(t.bg={rgb:c.toRgbString()});break}}}return t}function zt(i){const e=new DOMParser,t=`<x-univer id="univer-root">${i}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function Ce(i,e){const t=i.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(i)}const re=class re{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=re._pluginList.find(o=>o.checkPasteType(e)),n=zt(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:_})=>Ce(o,_)),u=c?c.getStyle(o):Se(o);this._styleCache.set(o,{...s,...u});const{childNodes:h}=o;this._process(o,h,n);const g=this._afterProcessRules.find(({filter:_})=>Ce(o,_));g&&g.handler(n,o)}}};C(re,"_pluginList",[]);let A=re;const Yt={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"}}]},Ae=Yt;function Be(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)?f.ptToPixel(s):s;break}case"margin-bottom":{const s=Number.parseInt(o);t.spaceBelow=/pt/.test(o)?f.ptToPixel(s):s;break}case"line-height":{const s=Number.parseFloat(o);t.lineSpacing=s;break}}}return Object.getOwnPropertyNames(t).length?t:null}const Gt={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=Be(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]},Fe=Gt,Kt={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=Be(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]},we=Kt;function Oe(i,e){const{st:t,ed:n,ts:r={}}=e,{ff:o,fs:s,it:c,bl:u,ul:h,st:g,ol:_,bg:v,cl:S,va:m}=r;let p=i.slice(t,n);const I=[];return c===a.BooleanNumber.TRUE&&(p=`<i>${p}</i>`),m===a.BaselineOffset.SUPERSCRIPT?p=`<sup>${p}</sup>`:m===a.BaselineOffset.SUBSCRIPT&&(p=`<sub>${p}</sub>`),(h==null?void 0:h.s)===a.BooleanNumber.TRUE&&(p=`<u>${p}</u>`),(g==null?void 0:g.s)===a.BooleanNumber.TRUE&&(p=`<s>${p}</s>`),u===a.BooleanNumber.TRUE&&(p=`<strong>${p}</strong>`),o&&I.push(`font-family: ${o}`),S&&I.push(`color: ${S.rgb}`),s&&I.push(`font-size: ${s}pt`),_&&I.push("text-decoration: overline"),v&&I.push(`background: ${v.rgb}`),I.length?`<span style="${I.join("; ")};">${p}</span>`:p}function ue(i,e,t){const{dataStream:n,textRuns:r=[]}=i;let o=e;const s=[];for(const c of r){const{st:u,ed:h}=c;a.Tools.hasIntersectionBetweenTwoRanges(e,t,u,h)&&(u>o?(s.push(n.slice(o,u)),s.push(Oe(n,{...c,ed:Math.min(h,t)}))):s.push(Oe(n,{...c,st:o,ed:Math.min(h,t)}))),o=Math.max(e,Math.min(h,t))}return o!==t&&s.push(n.slice(o,t)),s.join("")}function Te(i,e=!0){var t;if(e&&((t=i.paragraphs)!=null&&t.length)){const{dataStream:n,paragraphs:r=[]}=i;let o="",s=-1;for(const c of r){const{startIndex:u,paragraphStyle:h={}}=c,{spaceAbove:g,spaceBelow:_,lineSpacing:v}=h,S=[];g!=null&&(typeof g=="number"?S.push(`margin-top: ${g}px`):S.push(`margin-top: ${g.v}px`)),_!=null&&(typeof _=="number"?S.push(`margin-bottom: ${_}px`):S.push(`margin-bottom: ${_.v}px`)),v!=null&&S.push(`line-height: ${v}`),u>s+1?o+=`<p class="UniverNormal" ${S.length?`style="${S.join("; ")};"`:""}>${ue(i,s+1,u)}</p>`:o+=`<p class="UniverNormal" ${S.length?`style="${S.join("; ")};"`:""}></p>`,s=u}return s!==n.length&&(o+=ue(i,s,n.length)),o}else return ue(i,0,i.dataStream.length)}class Xt{convert(e){if(e.length===0)throw new Error("The bodyList length at least to be 1");if(e.length===1)return Te(e[0]);let t="";for(const n of e)t+='<p className="UniverNormal">',t+=Te(n,!1),t+="</p>";return t}}var qt=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&&qt(e,t,r),r},$=(i,e)=>(t,n)=>e(t,n,i);A.use(Fe);A.use(Ae);A.use(we);function Qt(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 ge=class extends a.Disposable{constructor(e,t,n,r,o){super();C(this,"_clipboardHooks",[]);C(this,"_htmlToUDM",new A);C(this,"_umdToHtml",new Xt);this._univerInstanceService=e,this._logService=t,this._commandService=n,this._clipboardInterfaceService=r,this._textSelectionManagerService=o}async copy(){const e=this._getDocumentBodyInRanges();if(e.length===0)return!1;try{this._setClipboardData(e)}catch(t){return this._logService.error("[DocClipboardService] copy failed",t),!1}return!0}async cut(){return this._cut()}async paste(e){const t=await this._generateBodyFromClipboardItems(e);return this._paste(t)}async legacyPaste(e,t){const n=this._generateBodyFromHtmlAndText(e,t);return this._paste(n)}async _cut(){var o;const{segmentId:e,endOffset:t,style:n}=(o=this._textSelectionManagerService.getActiveRange())!=null?o:{},r=this._textSelectionManagerService.getSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),t==null||r==null)return!1;this.copy();try{let s=t;for(const u of r){const{startOffset:h,endOffset:g}=u;h==null||g==null||g<=t&&(s-=g-h)}const c=[{startOffset:s,endOffset:s,style:n}];return this._commandService.executeCommand(d.CutContentCommand.id,{segmentId:e,textRanges:c})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(e){var s;const{segmentId:t,endOffset:n,style:r}=(s=this._textSelectionManagerService.getActiveRange())!=null?s:{},o=this._textSelectionManagerService.getSelections();if(t==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),n==null||o==null)return!1;try{let c=n;for(const h of o){const{startOffset:g,endOffset:_}=h;g==null||_==null||_<=n&&(c+=e.dataStream.length-(_-g))}const u=[{startOffset:c,endOffset:c,style:r}];return this._commandService.executeCommand(d.InnerPasteCommand.id,{body:e,segmentId:t,textRanges:u})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(e){const t=Wt(),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}"`),Ie.set(t,e[0])),this._clipboardInterfaceService.write(n,r)}addClipboardHook(e){return this._clipboardHooks.push(e),a.toDisposable(()=>{const t=this._clipboardHooks.indexOf(e);t>-1&&this._clipboardHooks.splice(t,1)})}_getDocumentBodyInRanges(){const e=this._textSelectionManagerService.getSelections(),t=this._univerInstanceService.getCurrentUniverDocInstance(),n=[];if(e==null||!t)return n;for(const r of e){const{startOffset:o,endOffset:s,collapsed:c}=r;if(c||o==null||s==null)continue;const u=t.sliceBody(o,s);u!=null&&n.push(u)}return n}async _generateBodyFromClipboardItems(e){try{let t="",n="";for(const r of e)for(const o of r.types)o===l.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await r.getType(o).then(s=>s&&s.text()):o===l.HTML_CLIPBOARD_MIME_TYPE&&(t=await r.getType(o).then(s=>s&&s.text()));return this._generateBodyFromHtmlAndText(t,n)}catch(t){return Promise.reject(t)}}_generateBodyFromHtmlAndText(e,t){if(!e){if(t)return Qt(t);throw new Error("[DocClipboardService] html and text cannot be both empty!")}const n=Ht(e);if(n){const r=Ie.get(n);if(r)return r}return this._htmlToUDM.convert(e)}};ge=Jt([$(0,a.IUniverInstanceService),$(1,a.ILogService),$(2,a.ICommandService),$(3,l.IClipboardInterfaceService),$(4,O.Inject(d.TextSelectionManagerService))],ge);function ce(i){return i.getContextValue(a.FOCUSING_DOC)||i.getContextValue(a.EDITOR_ACTIVATED)}const fe=999,en={id:l.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:fe,preconditions:ce,handler:async i=>i.get(k).copy()},tn={id:l.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:fe,preconditions:ce,handler:async i=>i.get(k).cut()},nn={id:l.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:fe,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 rn=Object.defineProperty,on=Object.getOwnPropertyDescriptor,sn=(i,e,t,n)=>{for(var r=n>1?void 0:n?on(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&rn(e,t,r),r},j=(i,e)=>(t,n)=>e(t,n,i);let Z=class extends a.RxDisposable{constructor(i,e,t,n,r){super(),this._commandService=i,this._clipboardInterfaceService=e,this._docClipboardService=t,this._textSelectionRenderManager=n,this._contextService=r,this._init()}_init(){[en,tn,nn].forEach(i=>this.disposeWithMe(this._commandService.registerMultipleCommand(i))),[d.InnerPasteCommand,d.CutContentCommand].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i))),this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var i;(i=this._textSelectionRenderManager)==null||i.onPaste$.pipe(T.takeUntil(this.dispose$)).subscribe(e=>{var 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)})}};Z=sn([a.OnLifecycle(a.LifecycleStages.Rendered,Z),j(0,a.ICommandService),j(1,l.IClipboardInterfaceService),j(2,k),j(3,f.ITextSelectionRenderManager),j(4,a.IContextService)],Z);var an=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,ln=(i,e,t,n)=>{for(var r=n>1?void 0:n?cn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&an(e,t,r),r},N=(i,e)=>(t,n)=>e(t,n,i);let J=class extends a.Disposable{constructor(e,t,n,r,o,s){super();C(this,"_initialEditors",new Set);this._univerInstanceService=e,this._docSkeletonManagerService=t,this._editorService=n,this._commandService=r,this._textSelectionRenderManager=o,this._renderManagerService=s,this._initialize()}_initialize(){this.disposeWithMe(this._editorService.resize$.subscribe(e=>{this._resize(e)})),this._editorService.getAllEditor().forEach(e=>{const t=e.editorUnitId;this._initialEditors.has(t)||(this._initialEditors.add(t),this._resize(t))}),this._commandExecutedListener(),this._initialSetValue(),this._initialBlur(),this._initialFocus(),this._initialValueChange()}_resize(e){var y,U,D;if(e==null)return;const t=this._editorService.getEditor(e);if((t==null?void 0:t.cancelDefaultResizeListener)===!0)return;const n=(y=this._docSkeletonManagerService.getSkeletonByUnitId(e))==null?void 0:y.skeleton,r=this._univerInstanceService.getUniverDocInstance(e);if(t==null||t.render==null||n==null||r==null)return;n.calculate();const{marginTop:o=0,marginBottom:s=0,marginLeft:c=0,marginRight:u=0}=r.getSnapshot().documentStyle,{scene:h,mainComponent:g}=t.render;let{actualHeight:_,actualWidth:v}=n.getActualSize();_+=o+s,v+=c+u;const{width:S,height:m}=t.getBoundingClientRect(),p=h.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);let I=p==null?void 0:p.getScrollBar();const b=Math.max(v,S),R=Math.max(_,m);h.transformByState({width:b,height:R}),g==null||g.resize(b,R),t.isSingle()?v>S?I==null?p&&new f.ScrollBar(p,{barSize:8,enableVertical:!1}):p==null||p.resetCanvasSizeAndUpdateScrollBar():(I=null,p==null||p.scrollTo({x:0,y:0}),(D=p==null?void 0:p.getScrollBar())==null||D.dispose()):_>m?I==null?p&&new f.ScrollBar(p,{enableHorizontal:!1,barSize:8}):p==null||p.resetCanvasSizeAndUpdateScrollBar():(I=null,p==null||p.scrollTo({x:0,y:0}),(U=p==null?void 0:p.getScrollBar())==null||U.dispose())}_initialSetValue(){this.disposeWithMe(this._editorService.setValue$.subscribe(e=>{this._commandService.executeCommand(d.CoverContentCommand.id,{unitId:e.editorUnitId,body:e.body,segmentId:null})}))}_initialBlur(){this.disposeWithMe(this._editorService.blur$.subscribe(()=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.blur()})),this.disposeWithMe(this._textSelectionRenderManager.onBlur$.subscribe(()=>{var r;const e=(r=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:r.getUnitId();if(e==null)return;const t=this._editorService.getEditor(e),n=this._editorService.getFocusEditor();t==null||t.isSheetEditor()||n&&n.editorUnitId===e||this._editorService.blur()}))}_initialFocus(){this.disposeWithMe(this._editorService.focus$.subscribe(n=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges([n])}));const e=["univer-formula-search","univer-formula-help","formula-help-decorator","univer-formula-help-param"];this.disposeWithMe(T.fromEvent(window,"mousedown").subscribe(n=>{const o=n.target.classList[0]||"";if(a.checkForSubstrings(o,e)){this._editorService.changeSpreadsheetFocusState(!0),n.stopPropagation();return}this._editorService.changeSpreadsheetFocusState(!1)})),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(n=>{const r=n.getUnitId(),o=this._renderManagerService.getRenderById(r),s=o==null?void 0:o.engine.getCanvas().getCanvasEle();s!=null&&T.fromEvent(s,"mousedown").subscribe(c=>{this._editorService.changeSpreadsheetFocusState(!0),c.stopPropagation()})})}_initialValueChange(){this.disposeWithMe(this._textSelectionRenderManager.onCompositionupdate$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onInput$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onKeydown$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onPaste$.subscribe(this._valueChange.bind(this)))}_valueChange(){var n;const e=(n=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:n.getUnitId();if(e==null)return;const t=this._editorService.getEditor(e);t==null||t.isSheetEditor()||this._editorService.refreshValueChange(e)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,l.SetEditorResizeOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=t.params,{unitId:r}=n;if(this._editorService.isSheetEditor(r))return;this._resize(r),this._valueChange()}}))}};J=ln([a.OnLifecycle(a.LifecycleStages.Rendered,J),N(0,a.IUniverInstanceService),N(1,O.Inject(d.DocSkeletonManagerService)),N(2,l.IEditorService),N(3,a.ICommandService),N(4,f.ITextSelectionRenderManager),N(5,f.IRenderManagerService)],J);var dn=Object.defineProperty,un=Object.getOwnPropertyDescriptor,hn=(i,e,t,n)=>{for(var r=n>1?void 0:n?un(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&dn(e,t,r),r},Y=(i,e)=>(t,n)=>e(t,n,i);let Q=class extends a.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(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,components:s}=r,c=o,u=s.get(d.DOCS_VIEW_KEY.BACKGROUND);c.changeSkeleton(t),u.changeSkeleton(t),this._recalculateSizeBySkeleton(r,t)}_recalculateSizeBySkeleton(e,t){var v;const{mainComponent:n,scene:r,unitId:o,components:s}=e,c=n,u=s.get(d.DOCS_VIEW_KEY.BACKGROUND),h=(v=t.getSkeletonData())==null?void 0:v.pages;if(h==null)return;let g=0,_=0;for(let S=0,m=h.length;S<m;S++){const p=h[S],{pageWidth:I,pageHeight:b}=p;c.pageLayoutType===f.PageLayoutType.VERTICAL?(_+=b,_+=c.pageMarginTop,S===m-1&&(_+=c.pageMarginTop),g=Math.max(g,I)):c.pageLayoutType===f.PageLayoutType.HORIZONTAL&&(g+=I,S!==m-1&&(g+=c.pageMarginLeft),_=Math.max(_,b))}c.resize(g,_),u.resize(g,_),this._editorService.isEditor(o)||r.resize(g,_)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=this._docSkeletonManagerService.getSkeletonByUnitId(o);if(s==null)return;const{skeleton:c}=s,u=this._renderManagerService.getRenderById(o);if(u==null||!!c.getViewModel().getDataModel().getSnapshot().disabled)return;if(c.calculate(),this._editorService.isEditor(o)){(n=u.mainComponent)==null||n.makeDirty();return}this._recalculateSizeBySkeleton(u,c)}}))}};Q=hn([a.OnLifecycle(a.LifecycleStages.Rendered,Q),Y(0,O.Inject(d.DocSkeletonManagerService)),Y(1,f.IRenderManagerService),Y(2,a.ICommandService),Y(3,l.IEditorService)],Q);var pn=Object.defineProperty,gn=Object.getOwnPropertyDescriptor,_n=(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},G=(i,e)=>(t,n)=>e(t,n,i);exports.DocCanvasView=class extends a.RxDisposable{constructor(t,n,r,o){super();C(this,"_scene");C(this,"_currentDocumentModel");C(this,"_fps$",new T.BehaviorSubject(""));C(this,"fps$",this._fps$.asObservable());this._renderManagerService=t,this._configService=n,this._univerInstanceService=r,this._editorService=o,this._initialize()}_initialize(){this._renderManagerService.createRender$.pipe(T.takeUntil(this.dispose$)).subscribe(t=>{this._create(t)}),this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC).pipe(T.takeUntil(this.dispose$)).subscribe(t=>{this._create(t==null?void 0:t.getUnitId())}),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC).forEach(t=>{this._create(t.getUnitId())})}dispose(){this._fps$.complete()}_create(t){if(t==null)return;const n=this._univerInstanceService.getUniverDocInstance(t);n!=null&&(this._currentDocumentModel=n,this._renderManagerService.has(t)||this._addNewRender())}_addNewRender(){const n=this._currentDocumentModel.getUnitId();this._renderManagerService.createRender(n);const r=this._renderManagerService.getRenderById(n);if(r==null)return;const{scene:o,engine:s}=r;this._scene=o;const c=new f.Viewport(d.VIEWPORT_KEY.VIEW_MAIN,o,{left:0,top:0,bottom:0,right:0,isRelativeX:!0,isRelativeY:!0,isWheelPreventDefaultX:!0});o.attachControl(),o.on(f.EVENT_TYPE.wheel,(g,_)=>{const v=g;if(v.ctrlKey){const S=Math.abs(v.deltaX);let m=S<40?.2:S<80?.4:.2;m*=v.deltaY>0?-1:1,o.scaleX<1&&(m/=2),o.scaleX+m>4?o.scale(4,4):o.scaleX+m<.1?o.scale(.1,.1):v.preventDefault()}else c.onMouseWheel(v,_)}),this._configService.getConfig("hasScroll")!==!1&&new f.ScrollBar(c),o.addLayer(new f.Layer(o,[],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),new f.Layer(o,[],d.DOCS_COMPONENT_HEADER_LAYER_INDEX)),this._addComponent(r),this._currentDocumentModel.getShouldRenderLoopImmediately()&&s.runRenderLoop(()=>{o.render(),this._fps$.next(Math.round(s.getFps()).toString())}),this._renderManagerService.setCurrent(n)}_addComponent(t){const n=this._scene,r=this._currentDocumentModel,o={pageMarginLeft:r.documentStyle.marginLeft||0,pageMarginTop:r.documentStyle.marginTop||0},s=new f.Documents(d.DOCS_VIEW_KEY.MAIN,void 0,o),c=new f.DocBackground(d.DOCS_VIEW_KEY.BACKGROUND,void 0,o);s.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX,c.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX,t.mainComponent=s,t.components.set(d.DOCS_VIEW_KEY.MAIN,s),t.components.set(d.DOCS_VIEW_KEY.BACKGROUND,c),n.addObjects([s],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),n.addObjects([c],d.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX),this._editorService.getEditor(r.getUnitId())==null&&n.enableLayerCache(d.DOCS_COMPONENT_MAIN_LAYER_INDEX)}};exports.DocCanvasView=_n([a.OnLifecycle(a.LifecycleStages.Starting,exports.DocCanvasView),G(0,f.IRenderManagerService),G(1,a.IConfigService),G(2,a.IUniverInstanceService),G(3,l.IEditorService)],exports.DocCanvasView);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},K=(i,e)=>(t,n)=>e(t,n,i);let ee=class extends a.Disposable{constructor(e,t,n,r){super();C(this,"_liquid",new f.Liquid);C(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=e,this._renderManagerService=t,this._commandService=n,this._editorService=r,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh(),this._updateOnPluginChange()}_updateOnPluginChange(){}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{skeleton:t,unitId:n}=e,r=this._renderManagerService.getRenderById(n);if(r==null)return;const{mainComponent:o}=r;o.changeSkeleton(t),this._refreshDrawing(n,t,r)})}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=this._docSkeletonManagerService.getCurrent();if(s==null)return;const{unitId:c,skeleton:u}=s;if(o!==c)return;const h=this._renderManagerService.getRenderById(c);if(h==null)return;if(this._editorService.isEditor(c)){(n=h.mainComponent)==null||n.makeDirty();return}this._refreshDrawing(c,u,h)}}))}_refreshDrawing(e,t,n){const r=t==null?void 0:t.getSkeletonData(),{mainComponent:o,scene:s}=n,c=o;if(!r)return;const{left:u,top:h,pageLayoutType:g,pageMarginLeft:_,pageMarginTop:v}=c,{pages:S}=r,m=[];s.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let p=0,I=S.length;p<I;p++){const b=S[p],{skeDrawings:R,marginLeft:y,marginTop:U}=b;this._liquid.translatePagePadding(b),R.forEach(D=>{const{aLeft:B,aTop:F,height:le,width:de,drawingId:w,drawingOrigin:me}=D,$e=me.layoutType===a.PositionedObjectLayoutType.WRAP_NONE&&me.behindDoc===a.BooleanNumber.TRUE;m.push({unitId:e,subUnitId:a.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:w,behindText:$e,floatingObject:{left:B+u+this._liquid.x,top:F+h+this._liquid.y,width:de,height:le}}),this._pageMarginCache.set(w,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.restorePagePadding(b),this._liquid.translatePage(b,g,_,v)}}};ee=mn([a.OnLifecycle(a.LifecycleStages.Steady,ee),K(0,O.Inject(d.DocSkeletonManagerService)),K(1,f.IRenderManagerService),K(2,a.ICommandService),K(3,l.IEditorService)],ee);var vn=Object.defineProperty,In=Object.getOwnPropertyDescriptor,Cn=(i,e,t,n)=>{for(var r=n>1?void 0:n?In(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&vn(e,t,r),r},L=(i,e)=>(t,n)=>e(t,n,i);let te=class extends a.Disposable{constructor(e,t,n,r,o,s){super();C(this,"_initializedRender",new Set);this._docSkeletonManagerService=e,this._univerInstanceService=t,this._commandService=n,this._renderManagerService=r,this._textSelectionManagerService=o,this._editorService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._initialRenderRefresh()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t}=e,n=this._renderManagerService.getRenderById(t);if(n==null||this._initializedRender.has(t)||this._editorService.isEditor(t))return;this._initializedRender.add(t);const{scene:r}=n;this.disposeWithMe(a.toDisposable(r.onMouseWheelObserver.add(o=>{if(!o.ctrlKey)return;const s=this._univerInstanceService.getCurrentUniverDocInstance();if(!s)return;const c=Math.abs(o.deltaX);let u=c<40?.2:c<80?.4:.2;u*=o.deltaY>0?-1:1,r.scaleX<1&&(u/=2);const h=s.zoomRatio;let g=+Number.parseFloat(`${h+u}`).toFixed(1);g=g>=4?4:g<=.1?.1:g,this._commandService.executeCommand(d.SetDocZoomRatioCommand.id,{zoomRatio:g,unitId:s.getUnitId()}),o.preventDefault()})))})}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const t=this._univerInstanceService.getCurrentUniverDocInstance();if(!t)return;const n=t.zoomRatio||1;this._updateViewZoom(n,!1)})))}_commandExecutedListener(){const e=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=this._univerInstanceService.getCurrentUniverDocInstance();if(!n)return;const r=t.params,{unitId:o}=r;if(o!==n.getUnitId())return;const s=n.zoomRatio||1;this._updateViewZoom(s)}}))}_updateViewZoom(e,t=!0){var r;const n=this._getDocObject();n!=null&&(n.scene.scale(e,e),this._calculatePagePosition(n,e),t&&this._textSelectionManagerService.refreshSelection(),(r=n.scene.getTransformer())==null||r.clearSelectedObjects())}_calculatePagePosition(e,t){const{document:n,scene:r,docBackground:o}=e,s=r==null?void 0:r.getParent(),{width:c,height:u,pageMarginLeft:h,pageMarginTop:g}=n;if(s==null||c===Number.POSITIVE_INFINITY||u===Number.POSITIVE_INFINITY)return;const{width:_,height:v}=s;let S=0,m=0,p=0,I=0,b=Number.POSITIVE_INFINITY;_>(c+h*2)*t?(S=_/2-c*t/2,S/=t,p=(_-h*2)/t,b=0):(S=h,p=c+h*2,b=(p-_/t)/2),v>u?(m=v/2-u/2,I=(v-g*2)/t):(m=g,I=u+g*2),r.resize(p,I+200),n.translate(S,m),o.translate(S,m);const R=r.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(b!==Number.POSITIVE_INFINITY&&R!=null){const y=R.transViewportScroll2ScrollValue(b,0).x;R.scrollTo({x:y})}return this}_getDocObject(){return d.getDocObject(this._univerInstanceService,this._renderManagerService)}};te=Cn([a.OnLifecycle(a.LifecycleStages.Rendered,te),L(0,O.Inject(d.DocSkeletonManagerService)),L(1,a.IUniverInstanceService),L(2,a.ICommandService),L(3,f.IRenderManagerService),L(4,O.Inject(d.TextSelectionManagerService)),L(5,l.IEditorService)],te);var On=Object.defineProperty,Tn=Object.getOwnPropertyDescriptor,bn=(i,e,t,n)=>{for(var r=n>1?void 0:n?Tn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&On(e,t,r),r},x=(i,e)=>(t,n)=>e(t,n,i);let ne=class extends a.Disposable{constructor(e,t,n,r,o,s,c){super();C(this,"_loadedMap",new WeakSet);this._docSkeletonManagerService=e,this._univerInstanceService=t,this._commandService=n,this._renderManagerService=r,this._textSelectionRenderManager=o,this._textSelectionManagerService=s,this._editorService=c,this._initialize()}_initialize(){this._init(),this._skeletonListener(),this._commandExecutedListener()}_init(){this.disposeWithMe(this._renderManagerService.currentRender$.subscribe(e=>{this._create(e)})),this._renderManagerService.getRenderAll().forEach((e,t)=>{this._create(t)})}_create(e){if(e==null||this._univerInstanceService.getUniverDocInstance(e)==null)return;const t=this._getDocObjectById(e);t==null||t.document==null||this._loadedMap.has(t.document)||(this._initialMain(e),this._loadedMap.add(t.document))}_initialMain(e){const t=this._getDocObjectById(e);if(t==null)return;const{document:n,scene:r}=t;this.disposeWithMe(a.toDisposable(n.onPointerEnterObserver.add(()=>{this._isEditorReadOnly(e)||(n.cursor=f.CURSOR_TYPE.TEXT)}))),this.disposeWithMe(a.toDisposable(n.onPointerLeaveObserver.add(()=>{n.cursor=f.CURSOR_TYPE.DEFAULT,r.resetCursor()}))),this.disposeWithMe(a.toDisposable(n==null?void 0:n.onPointerDownObserver.add((o,s)=>{if(this._isEditorReadOnly(e))return;const c=this._univerInstanceService.getCurrentUniverDocInstance();(c==null?void 0:c.getUnitId())!==e&&this._univerInstanceService.setCurrentUnitForType(e),this._textSelectionRenderManager.eventTrigger(o);const{offsetX:u,offsetY:h}=o;this._editorService.getEditor(e)&&(this._setEditorFocus(e),setTimeout(()=>{this._setEditorFocus(e),this._textSelectionRenderManager.setCursorManually(u,h)},0)),o.button!==2&&s.stopPropagation()}))),this.disposeWithMe(a.toDisposable(n==null?void 0:n.onDblclickObserver.add(o=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleDblClick(o)}))),this.disposeWithMe(a.toDisposable(n==null?void 0:n.onTripleClickObserver.add(o=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleTripleClick(o)})))}_isEditorReadOnly(e){const t=this._editorService.getEditor(e);return t?t.isReadOnly():!1}_setEditorFocus(e){if(this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).length>0){const n=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);this._editorService.setOperationSheetUnitId(n.getUnitId())}this._editorService.focusStyle(e)}_commandExecutedListener(){const e=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=(n=this._textSelectionManagerService.getCurrentSelection())==null?void 0:n.unitId;if(o!==s)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t,skeleton:n}=e,r=this._renderManagerService.getRenderById(t);if(r==null)return;const{scene:o,mainComponent:s}=r;this._textSelectionRenderManager.changeRuntime(n,o,s),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:t,subUnitId:""}),this._editorService.isEditor(t)||this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}],!1)}))}_getDocObjectById(e){return this._univerInstanceService.getUnitType(e)!==a.UniverInstanceType.UNIVER_DOC?null:d.getDocObjectById(e,this._renderManagerService)}};ne=bn([a.OnLifecycle(a.LifecycleStages.Rendered,ne),x(0,O.Inject(d.DocSkeletonManagerService)),x(1,a.IUniverInstanceService),x(2,a.ICommandService),x(3,f.IRenderManagerService),x(4,f.ITextSelectionRenderManager),x(5,O.Inject(d.TextSelectionManagerService)),x(6,l.IEditorService)],ne);var Rn=Object.defineProperty,Mn=Object.getOwnPropertyDescriptor,yn=(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&&Rn(e,t,r),r},V=(i,e)=>(t,n)=>e(t,n,i);const be=1.5;let ie=class extends a.RxDisposable{constructor(i,e,t,n,r){super(),this._docSkeletonManagerService=i,this._textSelectionManagerService=e,this._editorService=t,this._univerInstanceService=n,this._renderManagerService=r,this._init()}_init(){this._textSelectionManagerService.textSelection$.pipe(T.takeUntil(this.dispose$)).subscribe(i=>{if(i==null)return;const{isEditing:e,unitId:t}=i;e&&this._scrollToSelection(t)})}_scrollToSelection(i){var w;const e=this._textSelectionManagerService.getActiveRange(),t=this._getDocObject(),n=(w=this._docSkeletonManagerService.getCurrent())==null?void 0:w.skeleton;if(e==null||t==null||n==null)return;const{collapsed:r,startNodePosition:o}=e;if(!r)return;const s=t.document.getOffsetConfig(),{docsLeft:c,docsTop:u}=s,h=new f.NodePositionConvertToCursor(s,n),{contentBoxPointGroup:g}=h.getRangePointData(o,o),{left:_,top:v,height:S}=f.getAnchorBounding(g),m=_+c,p=v+u,I=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN),b=!!this._editorService.getEditor(i);if(I==null)return;const{left:R,top:y,right:U,bottom:D}=I.getBounding().viewBound;let B=0,F=0;const le=b?0:100;p<y?B=p-y:p>D-S&&(B=p-D+S+le),m<R?F=m-R:m>U-be&&(F=m-U+be);const de=I.transViewportScroll2ScrollValue(F,B);I.scrollBy(de)}_getDocObject(){return d.getDocObject(this._univerInstanceService,this._renderManagerService)}};ie=yn([a.OnLifecycle(a.LifecycleStages.Rendered,ie),V(0,O.Inject(d.DocSkeletonManagerService)),V(1,O.Inject(d.TextSelectionManagerService)),V(2,l.IEditorService),V(3,a.IUniverInstanceService),V(4,f.IRenderManagerService)],ie);var En=Object.defineProperty,Dn=Object.getOwnPropertyDescriptor,Pn=(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&&En(e,t,r),r},X=(i,e)=>(t,n)=>e(t,n,i);function xn(i,e){const t=Re(i.left,i.top,e),n=Re(i.right,i.bottom,e);return{left:t.x,top:t.y,right:n.x,bottom:n.y}}function Re(i,e,t){const{scaleX:n,scaleY:r}=t.getAncestorScale(),o=t.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(!o)return{x:i,y:e};const{viewportScrollX:s,viewportScrollY:c}=o,u=(i-s)*n,h=(e-c)*r;return{x:u,y:h}}exports.DocCanvasPopManagerService=class extends a.Disposable{constructor(e,t,n,r){super(),this._globalPopupManagerService=e,this._renderManagerService=t,this._univerInstanceService=n,this._commandService=r}_createObjectPositionObserver(e,t){const n=()=>{const{scene:u}=t,{left:h,top:g,width:_,height:v}=e,S={left:h,right:h+_,top:g,bottom:g+v},m=xn(S,u);return{left:m.left,right:m.right,top:m.top,bottom:m.bottom}},r=n(),o=new T.BehaviorSubject(r),s=new a.DisposableCollection;s.add(this._commandService.onCommandExecuted(u=>{u.id===d.SetDocZoomRatioOperation.id&&o.next(n())}));const c=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);return s.add(c==null?void 0:c.onScrollAfterObserver.add(()=>{o.next(n())})),{position:r,position$:o,disposable:s}}attachPopupToObject(e,t){const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC).getUnitId(),o=this._renderManagerService.getRenderById(r);if(!o)return{dispose:()=>{}};const{position:s,position$:c,disposable:u}=this._createObjectPositionObserver(e,o),h=this._globalPopupManagerService.addPopup({...t,unitId:r,subUnitId:"default",anchorRect:s,anchorRect$:c});return{dispose:()=>{this._globalPopupManagerService.removePopup(h),c.complete(),u.dispose()}}}};exports.DocCanvasPopManagerService=Pn([X(0,O.Inject(l.ICanvasPopupService)),X(1,f.IRenderManagerService),X(2,a.IUniverInstanceService),X(3,a.ICommandService)],exports.DocCanvasPopManagerService);var Un=Object.defineProperty,Nn=Object.getOwnPropertyDescriptor,Ln=(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&&Un(e,t,r),r},he=(i,e)=>(t,n)=>e(t,n,i),q;exports.UniverDocsUIPlugin=(q=class extends a.Plugin{constructor(e,t,n,r){super(),this._config=e,this._injector=t,this._localeService=n,this._logService=r,this._config=a.Tools.deepMerge({},Ee,this._config),this._initDependencies(t),this._initializeCommands()}onRendered(){this._initModules(),this._markDocAsFocused()}_initializeCommands(){[Ye,Ge,Xe,Ke,qe,Ze,Je,Qe,et,wt,$t,Ft].forEach(e=>{this._injector.get(l.IShortcutService).registerShortcut(e)})}_initDependencies(e){[[H,{useFactory:()=>this._injector.createInstance(H,this._config)}],[Z],[J],[Q],[ee],[te],[ne],[ie],[W,{useFactory:()=>this._injector.createInstance(W,this._config)}],[k,{useClass:ge}],[exports.DocCanvasPopManagerService],[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();if(!n)return;const r=n.getUnitId();t.isEditor(r)||e.focusUnit(n.getUnitId())}catch(n){this._logService.warn(n)}}_initModules(){this._injector.get(W)}},C(q,"pluginName",De),C(q,"type",a.UniverInstanceType.UNIVER_DOC),q);exports.UniverDocsUIPlugin=Ln([he(1,O.Inject(O.Injector)),he(2,O.Inject(a.LocaleService)),he(3,a.ILogService)],exports.UniverDocsUIPlugin);function An(i){return{left:i.positionH.posOffset,top:i.positionV.posOffset,width:i.size.width,height:i.size.height}}function Bn(i,e=0,t=0){return{size:{width:i.width,height:i.height},positionH:{relativeFrom:a.ObjectRelativeFromH.MARGIN,posOffset:(i.left||0)-e},positionV:{relativeFrom:a.ObjectRelativeFromV.PAGE,posOffset:(i.top||0)-t},angle:i.angle||0}}exports.DOC_UI_PLUGIN_NAME=De;exports.DefaultDocContainerConfig=ye;exports.DefaultDocUiConfig=Ee;exports.DefaultToolbarConfig=Me;exports.PastePluginLark=Ae;exports.PastePluginUniver=we;exports.PastePluginWord=Fe;exports.docDrawingPositionToTransform=An;exports.transformToDocDrawingPosition=Bn;
|
package/lib/es/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
var Wt = (i, e, t) => e in i ?
|
|
3
|
-
var g = (i, e, t) =>
|
|
1
|
+
var jt = Object.defineProperty;
|
|
2
|
+
var Wt = (i, e, t) => e in i ? jt(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
+
var g = (i, e, t) => Wt(i, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
import { FOCUSING_DOC as xe, FOCUSING_UNIVER_EDITOR as Ze, FOCUSING_COMMON_DRAWINGS as bt, FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE as zt, Direction as w, EDITOR_ACTIVATED as Mt, LocaleService as qe, RxDisposable as de, ICommandService as v, BooleanNumber as C, UniverInstanceType as f, BaselineOffset as K, ThemeService as yt, HorizontalAlign as De, IUniverInstanceService as P, Disposable as k, OnLifecycle as U, LifecycleStages as A, Tools as Je, LRUMap as kt, ColorKit as st, toDisposable as B, ILogService as Et, CommandType as Qe, IContextService as Ht, checkForSubstrings as Yt, IConfigService as Gt, PositionedObjectLayoutType as Xt, DEFAULT_DOCUMENT_SUB_COMPONENT_ID as Kt, DisposableCollection as Zt, Plugin as qt, ObjectRelativeFromH as Jt, ObjectRelativeFromV as Qt } from "@univerjs/core";
|
|
5
5
|
import { Inject as O, Injector as Pe, Optional as en, createIdentifier as tn } from "@wendellhu/redi";
|
|
6
6
|
import { KeyCode as E, MetaKeys as ue, ILayoutService as xt, MenuGroup as I, MenuItemType as T, MenuPosition as b, getMenuHiddenObservable as M, FONT_FAMILY_LIST as at, FONT_SIZE_LIST as nn, FontFamily as rn, FontFamilyItem as on, FontSize as sn, BuiltInUIPart as an, ComponentManager as cn, IEditorService as L, IMenuService as ln, IUIPartsService as dn, PLAIN_TEXT_CLIPBOARD_MIME_TYPE as un, HTML_CLIPBOARD_MIME_TYPE as hn, IClipboardInterfaceService as et, CopyCommand as pn, CutCommand as _n, PasteCommand as gn, SetEditorResizeOperation as fn, ICanvasPopupService as mn, IShortcutService as Sn } from "@univerjs/ui";
|
|
7
|
-
import { MoveCursorOperation as Ne, MoveSelectionOperation as Ue, SelectAllOperation as vn, SetInlineFormatBoldCommand as Cn, SetTextSelectionsOperation as x, SetInlineFormatCommand as q, SetInlineFormatItalicCommand as On, SetInlineFormatUnderlineCommand as Rn, SetInlineFormatStrikethroughCommand as Tn, SetInlineFormatSubscriptCommand as In, SetInlineFormatSuperscriptCommand as bn, SetInlineFormatFontFamilyCommand as ct, SetInlineFormatFontSizeCommand as lt, SetInlineFormatTextColorCommand as dt, AlignLeftCommand as Mn, AlignOperationCommand as Ae, AlignCenterCommand as yn, AlignRightCommand as En, AlignJustifyCommand as xn, OrderListCommand as Dn, BulletListCommand as Pn, ResetInlineFormatTextBackgroundColorCommand as Nn, SetInlineFormatTextBackgroundColorCommand as He, TextSelectionManagerService as J, BreakLineCommand as Un, DeleteLeftCommand as An, DeleteRightCommand as Ln, CutContentCommand as Dt, InnerPasteCommand as Pt, VIEWPORT_KEY as Q, CoverContentCommand as $n, RichTextEditingMutation as tt, DocSkeletonManagerService as ee, DOCS_VIEW_KEY as X, DOCS_COMPONENT_MAIN_LAYER_INDEX as We, DOCS_COMPONENT_HEADER_LAYER_INDEX as Bn, DOCS_COMPONENT_DEFAULT_Z_INDEX as ut, DOCS_COMPONENT_BACKGROUND_LAYER_INDEX as wn, SetDocZoomRatioOperation as Le, SetDocZoomRatioCommand as Fn, getDocObject as Nt, getDocObjectById as
|
|
8
|
-
import { connectInjector as
|
|
7
|
+
import { MoveCursorOperation as Ne, MoveSelectionOperation as Ue, SelectAllOperation as vn, SetInlineFormatBoldCommand as Cn, SetTextSelectionsOperation as x, SetInlineFormatCommand as q, SetInlineFormatItalicCommand as On, SetInlineFormatUnderlineCommand as Rn, SetInlineFormatStrikethroughCommand as Tn, SetInlineFormatSubscriptCommand as In, SetInlineFormatSuperscriptCommand as bn, SetInlineFormatFontFamilyCommand as ct, SetInlineFormatFontSizeCommand as lt, SetInlineFormatTextColorCommand as dt, AlignLeftCommand as Mn, AlignOperationCommand as Ae, AlignCenterCommand as yn, AlignRightCommand as En, AlignJustifyCommand as xn, OrderListCommand as Dn, BulletListCommand as Pn, ResetInlineFormatTextBackgroundColorCommand as Nn, SetInlineFormatTextBackgroundColorCommand as He, TextSelectionManagerService as J, BreakLineCommand as Un, DeleteLeftCommand as An, DeleteRightCommand as Ln, CutContentCommand as Dt, InnerPasteCommand as Pt, VIEWPORT_KEY as Q, CoverContentCommand as $n, RichTextEditingMutation as tt, DocSkeletonManagerService as ee, DOCS_VIEW_KEY as X, DOCS_COMPONENT_MAIN_LAYER_INDEX as We, DOCS_COMPONENT_HEADER_LAYER_INDEX as Bn, DOCS_COMPONENT_DEFAULT_Z_INDEX as ut, DOCS_COMPONENT_BACKGROUND_LAYER_INDEX as wn, SetDocZoomRatioOperation as Le, SetDocZoomRatioCommand as Fn, getDocObject as Nt, getDocObjectById as Vn } from "@univerjs/docs";
|
|
8
|
+
import { connectInjector as jn } from "@wendellhu/redi/react-bindings";
|
|
9
9
|
import { ITextSelectionRenderManager as he, pixelToPt as Wn, ptToPixel as ht, ScrollBar as Ye, IRenderManagerService as F, PageLayoutType as pt, Viewport as zn, EVENT_TYPE as kn, Layer as _t, Documents as Hn, DocBackground as Yn, Liquid as Gn, CURSOR_TYPE as gt, NodePositionConvertToCursor as Xn, getAnchorBounding as Kn } from "@univerjs/engine-render";
|
|
10
10
|
import Zn from "react";
|
|
11
11
|
import { Observable as y, takeUntil as le, fromEvent as ft, BehaviorSubject as Ut } from "rxjs";
|
|
@@ -224,11 +224,8 @@ var Si = Zn, vi = Symbol.for("react.element"), Ci = Symbol.for("react.fragment")
|
|
|
224
224
|
function wt(i, e, t) {
|
|
225
225
|
var n, r = {}, o = null, s = null;
|
|
226
226
|
t !== void 0 && (o = "" + t), e.key !== void 0 && (o = "" + e.key), e.ref !== void 0 && (s = e.ref);
|
|
227
|
-
for (n in e)
|
|
228
|
-
|
|
229
|
-
if (i && i.defaultProps)
|
|
230
|
-
for (n in e = i.defaultProps, e)
|
|
231
|
-
r[n] === void 0 && (r[n] = e[n]);
|
|
227
|
+
for (n in e) Oi.call(e, n) && !Ti.hasOwnProperty(n) && (r[n] = e[n]);
|
|
228
|
+
if (i && i.defaultProps) for (n in e = i.defaultProps, e) r[n] === void 0 && (r[n] = e[n]);
|
|
232
229
|
return { $$typeof: vi, type: i, key: o, ref: s, props: r, _owner: Ri.current };
|
|
233
230
|
}
|
|
234
231
|
Be.Fragment = Ci;
|
|
@@ -254,7 +251,7 @@ function Ei(i) {
|
|
|
254
251
|
var s;
|
|
255
252
|
const o = r.id;
|
|
256
253
|
if (o === x.id || o === q.id) {
|
|
257
|
-
const a =
|
|
254
|
+
const a = V(i);
|
|
258
255
|
if (a == null)
|
|
259
256
|
return;
|
|
260
257
|
const c = (s = a.ts) == null ? void 0 : s.bl;
|
|
@@ -281,7 +278,7 @@ function xi(i) {
|
|
|
281
278
|
var s;
|
|
282
279
|
const o = r.id;
|
|
283
280
|
if (o === x.id || o === q.id) {
|
|
284
|
-
const a =
|
|
281
|
+
const a = V(i);
|
|
285
282
|
if (a == null)
|
|
286
283
|
return;
|
|
287
284
|
const c = (s = a.ts) == null ? void 0 : s.it;
|
|
@@ -308,7 +305,7 @@ function Di(i) {
|
|
|
308
305
|
var s;
|
|
309
306
|
const o = r.id;
|
|
310
307
|
if (o === x.id || o === q.id) {
|
|
311
|
-
const a =
|
|
308
|
+
const a = V(i);
|
|
312
309
|
if (a == null)
|
|
313
310
|
return;
|
|
314
311
|
const c = (s = a.ts) == null ? void 0 : s.ul;
|
|
@@ -335,7 +332,7 @@ function Pi(i) {
|
|
|
335
332
|
var s;
|
|
336
333
|
const o = r.id;
|
|
337
334
|
if (o === x.id || o === q.id) {
|
|
338
|
-
const a =
|
|
335
|
+
const a = V(i);
|
|
339
336
|
if (a == null)
|
|
340
337
|
return;
|
|
341
338
|
const c = (s = a.ts) == null ? void 0 : s.st;
|
|
@@ -361,7 +358,7 @@ function Ni(i) {
|
|
|
361
358
|
var s;
|
|
362
359
|
const o = r.id;
|
|
363
360
|
if (o === x.id || o === q.id) {
|
|
364
|
-
const a =
|
|
361
|
+
const a = V(i);
|
|
365
362
|
if (a == null)
|
|
366
363
|
return;
|
|
367
364
|
const c = (s = a.ts) == null ? void 0 : s.va;
|
|
@@ -387,7 +384,7 @@ function Ui(i) {
|
|
|
387
384
|
var s;
|
|
388
385
|
const o = r.id;
|
|
389
386
|
if (o === x.id || o === q.id) {
|
|
390
|
-
const a =
|
|
387
|
+
const a = V(i);
|
|
391
388
|
if (a == null)
|
|
392
389
|
return;
|
|
393
390
|
const c = (s = a.ts) == null ? void 0 : s.va;
|
|
@@ -421,7 +418,7 @@ function Ai(i) {
|
|
|
421
418
|
var a;
|
|
422
419
|
const s = o.id;
|
|
423
420
|
if (s === x.id || s === ct.id) {
|
|
424
|
-
const c =
|
|
421
|
+
const c = V(i);
|
|
425
422
|
if (c == null)
|
|
426
423
|
return;
|
|
427
424
|
const l = (a = c.ts) == null ? void 0 : a.ff;
|
|
@@ -456,7 +453,7 @@ function Li(i) {
|
|
|
456
453
|
var a;
|
|
457
454
|
const s = o.id;
|
|
458
455
|
if (s === x.id || s === lt.id) {
|
|
459
|
-
const c =
|
|
456
|
+
const c = V(i);
|
|
460
457
|
if (c == null)
|
|
461
458
|
return;
|
|
462
459
|
const l = (a = c.ts) == null ? void 0 : a.fs;
|
|
@@ -576,7 +573,7 @@ function Fi(i) {
|
|
|
576
573
|
hidden$: M(i, f.UNIVER_DOC)
|
|
577
574
|
};
|
|
578
575
|
}
|
|
579
|
-
function
|
|
576
|
+
function Vi(i) {
|
|
580
577
|
const e = i.get(v);
|
|
581
578
|
return {
|
|
582
579
|
id: xn.id,
|
|
@@ -602,7 +599,7 @@ function ji(i) {
|
|
|
602
599
|
hidden$: M(i, f.UNIVER_DOC)
|
|
603
600
|
};
|
|
604
601
|
}
|
|
605
|
-
function
|
|
602
|
+
function ji(i) {
|
|
606
603
|
return {
|
|
607
604
|
id: Dn.id,
|
|
608
605
|
group: I.TOOLBAR_LAYOUT,
|
|
@@ -662,7 +659,7 @@ function ki(i) {
|
|
|
662
659
|
hidden$: M(i, f.UNIVER_DOC)
|
|
663
660
|
};
|
|
664
661
|
}
|
|
665
|
-
function
|
|
662
|
+
function V(i) {
|
|
666
663
|
var c;
|
|
667
664
|
const e = i.get(P), t = i.get(J), n = e.getCurrentUniverDocInstance(), r = t.getActiveRange();
|
|
668
665
|
if (n == null || r == null)
|
|
@@ -731,8 +728,8 @@ let ce = class extends k {
|
|
|
731
728
|
Bi,
|
|
732
729
|
wi,
|
|
733
730
|
Fi,
|
|
734
|
-
ji,
|
|
735
731
|
Vi,
|
|
732
|
+
ji,
|
|
736
733
|
Wi,
|
|
737
734
|
zi,
|
|
738
735
|
ki
|
|
@@ -748,7 +745,7 @@ let ce = class extends k {
|
|
|
748
745
|
if (i == null)
|
|
749
746
|
return;
|
|
750
747
|
this._editorService.isEditor(i) || this.disposeWithMe(
|
|
751
|
-
this._uiPartsService.registerComponent(an.CONTENT, () =>
|
|
748
|
+
this._uiPartsService.registerComponent(an.CONTENT, () => jn(yi, this._injector))
|
|
752
749
|
);
|
|
753
750
|
}
|
|
754
751
|
_initFocusHandler() {
|
|
@@ -1330,7 +1327,7 @@ let Oe = class extends k {
|
|
|
1330
1327
|
}), this._commandExecutedListener(), this._initialSetValue(), this._initialBlur(), this._initialFocus(), this._initialValueChange();
|
|
1331
1328
|
}
|
|
1332
1329
|
_resize(e) {
|
|
1333
|
-
var $, H,
|
|
1330
|
+
var $, H, j;
|
|
1334
1331
|
if (e == null)
|
|
1335
1332
|
return;
|
|
1336
1333
|
const t = this._editorService.getEditor(e);
|
|
@@ -1349,7 +1346,7 @@ let Oe = class extends k {
|
|
|
1349
1346
|
l.transformByState({
|
|
1350
1347
|
width: R,
|
|
1351
1348
|
height: D
|
|
1352
|
-
}), u == null || u.resize(R, D), t.isSingle() ? m > p ? _ == null ? d && new Ye(d, { barSize: 8, enableVertical: !1 }) : d == null || d.
|
|
1349
|
+
}), u == null || u.resize(R, D), t.isSingle() ? m > p ? _ == null ? d && new Ye(d, { barSize: 8, enableVertical: !1 }) : d == null || d.resetCanvasSizeAndUpdateScrollBar() : (_ = null, d == null || d.scrollTo({ x: 0, y: 0 }), (j = d == null ? void 0 : d.getScrollBar()) == null || j.dispose()) : h > S ? _ == null ? d && new Ye(d, { enableHorizontal: !1, barSize: 8 }) : d == null || d.resetCanvasSizeAndUpdateScrollBar() : (_ = null, d == null || d.scrollTo({ x: 0, y: 0 }), (H = d == null ? void 0 : d.getScrollBar()) == null || H.dispose());
|
|
1353
1350
|
}
|
|
1354
1351
|
_initialSetValue() {
|
|
1355
1352
|
this.disposeWithMe(
|
|
@@ -1656,18 +1653,18 @@ let Ie = class extends k {
|
|
|
1656
1653
|
s.getAncestorScale(), this._liquid.reset(), this._pageMarginCache.clear();
|
|
1657
1654
|
for (let d = 0, _ = p.length; d < _; d++) {
|
|
1658
1655
|
const R = p[d], { skeDrawings: D, marginLeft: $, marginTop: H } = R;
|
|
1659
|
-
this._liquid.translatePagePadding(R), D.forEach((
|
|
1660
|
-
const { aLeft: te, aTop: ne, height:
|
|
1656
|
+
this._liquid.translatePagePadding(R), D.forEach((j) => {
|
|
1657
|
+
const { aLeft: te, aTop: ne, height: Ve, width: je, drawingId: ie, drawingOrigin: ot } = j, Vt = ot.layoutType === Xt.WRAP_NONE && ot.behindDoc === C.TRUE;
|
|
1661
1658
|
S.push({
|
|
1662
1659
|
unitId: e,
|
|
1663
1660
|
subUnitId: Kt,
|
|
1664
1661
|
floatingObjectId: ie,
|
|
1665
|
-
behindText:
|
|
1662
|
+
behindText: Vt,
|
|
1666
1663
|
floatingObject: {
|
|
1667
1664
|
left: te + c + this._liquid.x,
|
|
1668
1665
|
top: ne + l + this._liquid.y,
|
|
1669
|
-
width:
|
|
1670
|
-
height:
|
|
1666
|
+
width: je,
|
|
1667
|
+
height: Ve
|
|
1671
1668
|
}
|
|
1672
1669
|
}), this._pageMarginCache.set(ie, {
|
|
1673
1670
|
marginLeft: this._liquid.x,
|
|
@@ -1746,8 +1743,7 @@ let be = class extends k {
|
|
|
1746
1743
|
if (e == null)
|
|
1747
1744
|
return;
|
|
1748
1745
|
const t = this._univerInstanceService.getCurrentUniverDocInstance();
|
|
1749
|
-
if (!t)
|
|
1750
|
-
return;
|
|
1746
|
+
if (!t) return;
|
|
1751
1747
|
const n = t.zoomRatio || 1;
|
|
1752
1748
|
this._updateViewZoom(n, !1);
|
|
1753
1749
|
})
|
|
@@ -1760,8 +1756,7 @@ let be = class extends k {
|
|
|
1760
1756
|
this._commandService.onCommandExecuted((t) => {
|
|
1761
1757
|
if (e.includes(t.id)) {
|
|
1762
1758
|
const n = this._univerInstanceService.getCurrentUniverDocInstance();
|
|
1763
|
-
if (!n)
|
|
1764
|
-
return;
|
|
1759
|
+
if (!n) return;
|
|
1765
1760
|
const r = t.params, { unitId: o } = r;
|
|
1766
1761
|
if (o !== n.getUnitId())
|
|
1767
1762
|
return;
|
|
@@ -1785,7 +1780,7 @@ let be = class extends k {
|
|
|
1785
1780
|
h > (a + l * 2) * t ? (p = h / 2 - a * t / 2, p /= t, d = (h - l * 2) / t, R = 0) : (p = l, d = a + l * 2, R = (d - h / t) / 2), m > c ? (S = m / 2 - c / 2, _ = (m - u * 2) / t) : (S = u, _ = c + u * 2), r.resize(d, _ + 200), n.translate(p, S), o.translate(p, S);
|
|
1786
1781
|
const D = r.getViewport(Q.VIEW_MAIN);
|
|
1787
1782
|
if (R !== Number.POSITIVE_INFINITY && D != null) {
|
|
1788
|
-
const $ = D.
|
|
1783
|
+
const $ = D.transViewportScroll2ScrollValue(R, 0).x;
|
|
1789
1784
|
D.scrollTo({
|
|
1790
1785
|
x: $
|
|
1791
1786
|
});
|
|
@@ -1916,12 +1911,17 @@ let Me = class extends k {
|
|
|
1916
1911
|
this._textSelectionRenderManager.changeRuntime(n, o, s), this._textSelectionManagerService.setCurrentSelectionNotRefresh({
|
|
1917
1912
|
unitId: t,
|
|
1918
1913
|
subUnitId: ""
|
|
1919
|
-
})
|
|
1914
|
+
}), this._editorService.isEditor(t) || this._textSelectionManagerService.replaceTextRanges([
|
|
1915
|
+
{
|
|
1916
|
+
startOffset: 0,
|
|
1917
|
+
endOffset: 0
|
|
1918
|
+
}
|
|
1919
|
+
], !1);
|
|
1920
1920
|
})
|
|
1921
1921
|
);
|
|
1922
1922
|
}
|
|
1923
1923
|
_getDocObjectById(e) {
|
|
1924
|
-
return this._univerInstanceService.getUnitType(e) !== f.UNIVER_DOC ? null :
|
|
1924
|
+
return this._univerInstanceService.getUnitType(e) !== f.UNIVER_DOC ? null : Vn(e, this._renderManagerService);
|
|
1925
1925
|
}
|
|
1926
1926
|
};
|
|
1927
1927
|
Me = Br([
|
|
@@ -1934,7 +1934,7 @@ Me = Br([
|
|
|
1934
1934
|
z(5, O(J)),
|
|
1935
1935
|
z(6, L)
|
|
1936
1936
|
], Me);
|
|
1937
|
-
var wr = Object.defineProperty, Fr = Object.getOwnPropertyDescriptor,
|
|
1937
|
+
var wr = Object.defineProperty, Fr = Object.getOwnPropertyDescriptor, Vr = (i, e, t, n) => {
|
|
1938
1938
|
for (var r = n > 1 ? void 0 : n ? Fr(e, t) : e, o = i.length - 1, s; o >= 0; o--)
|
|
1939
1939
|
(s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
|
|
1940
1940
|
return n && r && wr(e, t, r), r;
|
|
@@ -1968,19 +1968,19 @@ let ye = class extends de {
|
|
|
1968
1968
|
left: D,
|
|
1969
1969
|
top: $,
|
|
1970
1970
|
right: H,
|
|
1971
|
-
bottom:
|
|
1971
|
+
bottom: j
|
|
1972
1972
|
} = _.getBounding().viewBound;
|
|
1973
1973
|
let te = 0, ne = 0;
|
|
1974
|
-
const
|
|
1975
|
-
d < $ ? te = d - $ : d >
|
|
1976
|
-
const
|
|
1977
|
-
_.scrollBy(
|
|
1974
|
+
const Ve = R ? 0 : 100;
|
|
1975
|
+
d < $ ? te = d - $ : d > j - p && (te = d - j + p + Ve), S < D ? ne = S - D : S > H - Rt && (ne = S - H + Rt);
|
|
1976
|
+
const je = _.transViewportScroll2ScrollValue(ne, te);
|
|
1977
|
+
_.scrollBy(je);
|
|
1978
1978
|
}
|
|
1979
1979
|
_getDocObject() {
|
|
1980
1980
|
return Nt(this._univerInstanceService, this._renderManagerService);
|
|
1981
1981
|
}
|
|
1982
1982
|
};
|
|
1983
|
-
ye =
|
|
1983
|
+
ye = Vr([
|
|
1984
1984
|
U(A.Rendered, ye),
|
|
1985
1985
|
se(0, O(ee)),
|
|
1986
1986
|
se(1, O(J)),
|
|
@@ -1988,10 +1988,10 @@ ye = jr([
|
|
|
1988
1988
|
se(3, P),
|
|
1989
1989
|
se(4, F)
|
|
1990
1990
|
], ye);
|
|
1991
|
-
var
|
|
1991
|
+
var jr = Object.defineProperty, Wr = Object.getOwnPropertyDescriptor, zr = (i, e, t, n) => {
|
|
1992
1992
|
for (var r = n > 1 ? void 0 : n ? Wr(e, t) : e, o = i.length - 1, s; o >= 0; o--)
|
|
1993
1993
|
(s = i[o]) && (r = (n ? s(e, t, r) : s(r)) || r);
|
|
1994
|
-
return n && r &&
|
|
1994
|
+
return n && r && jr(e, t, r), r;
|
|
1995
1995
|
}, Se = (i, e) => (t, n) => e(t, n, i);
|
|
1996
1996
|
function kr(i, e) {
|
|
1997
1997
|
const t = Tt(i.left, i.top, e), n = Tt(i.right, i.bottom, e);
|
|
@@ -2150,8 +2150,7 @@ let It = (ve = class extends qt {
|
|
|
2150
2150
|
const i = this._injector.get(P), e = this._injector.get(L);
|
|
2151
2151
|
try {
|
|
2152
2152
|
const t = i.getCurrentUniverDocInstance();
|
|
2153
|
-
if (!t)
|
|
2154
|
-
return;
|
|
2153
|
+
if (!t) return;
|
|
2155
2154
|
const n = t.getUnitId();
|
|
2156
2155
|
e.isEditor(n) || i.focusUnit(t.getUnitId());
|
|
2157
2156
|
} catch (t) {
|
package/lib/umd/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(S,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("@univerjs/docs"),require("@wendellhu/redi/react-bindings"),require("@univerjs/engine-render"),require("react"),require("rxjs"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","@univerjs/docs","@wendellhu/redi/react-bindings","@univerjs/engine-render","react","rxjs","@univerjs/design"],a):(S=typeof globalThis<"u"?globalThis:S||self,a(S.UniverDocsUi={},S.UniverCore,S["@wendellhu/redi"],S.UniverUi,S.UniverDocs,S["@wendellhu/redi/react-bindings"],S.UniverEngineRender,S.React,S.rxjs,S.UniverDesign))})(this,function(S,a,
|
|
1
|
+
(function(S,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("@univerjs/docs"),require("@wendellhu/redi/react-bindings"),require("@univerjs/engine-render"),require("react"),require("rxjs"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","@univerjs/docs","@wendellhu/redi/react-bindings","@univerjs/engine-render","react","rxjs","@univerjs/design"],a):(S=typeof globalThis<"u"?globalThis:S||self,a(S.UniverDocsUi={},S.UniverCore,S["@wendellhu/redi"],S.UniverUi,S.UniverDocs,S["@wendellhu/redi/react-bindings"],S.UniverEngineRender,S.React,S.rxjs,S.UniverDesign))})(this,function(S,a,I,l,d,Ve,m,je,b,We){"use strict";var Nn=Object.defineProperty;var xn=(S,a,I)=>a in S?Nn(S,a,{enumerable:!0,configurable:!0,writable:!0,value:I}):S[a]=I;var T=(S,a,I)=>xn(S,typeof a!="symbol"?a+"":a,I);var le;const ve={undo:!0,redo:!0,font:!0,fontSize:!0,bold:!0,italic:!0,strikethrough:!0,underline:!0,textColor:!0,fillColor:!0,horizontalAlignMode:!0,verticalAlignMode:!0,textWrapMode:!0,textRotateMode:!0},Ie={outerLeft:!1,outerRight:!1,header:!0,footer:!0,innerLeft:!1,innerRight:!1,frozenHeaderLT:!1,frozenHeaderRT:!1,frozenHeaderLM:!1,frozenContent:!1,infoBar:!0,toolbar:!0},Ce={layout:{docContainerConfig:Ie,toolbarConfig:ve}},Oe="DocUI";function y(i){return i.getContextValue(a.FOCUSING_DOC)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function He(i){return i.getContextValue(a.FOCUSING_DOC)&&i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!i.getContextValue(a.FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE)&&!i.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}const ke={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_UP,preconditions:y,staticParameters:{direction:a.Direction.UP}},ze={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_DOWN,preconditions:y,staticParameters:{direction:a.Direction.DOWN}},Ye={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_LEFT,preconditions:y,staticParameters:{direction:a.Direction.LEFT}},Ge={id:d.MoveCursorOperation.id,binding:l.KeyCode.ARROW_RIGHT,preconditions:y,staticParameters:{direction:a.Direction.RIGHT}},Ke={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_UP|l.MetaKeys.SHIFT,preconditions:y,staticParameters:{direction:a.Direction.UP}},Xe={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_DOWN|l.MetaKeys.SHIFT,preconditions:y,staticParameters:{direction:a.Direction.DOWN}},qe={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_LEFT|l.MetaKeys.SHIFT,preconditions:y,staticParameters:{direction:a.Direction.LEFT}},Ze={id:d.MoveSelectionOperation.id,binding:l.KeyCode.ARROW_RIGHT|l.MetaKeys.SHIFT,preconditions:y,staticParameters:{direction:a.Direction.RIGHT}},Je={id:d.SelectAllOperation.id,binding:l.KeyCode.A|l.MetaKeys.CTRL_COMMAND,preconditions:i=>i.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&(i.getContextValue(a.FOCUSING_DOC)||i.getContextValue(a.EDITOR_ACTIVATED))};var Qe=Object.defineProperty,et=Object.getOwnPropertyDescriptor,tt=(i,e,t,n)=>{for(var r=n>1?void 0:n?et(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},Te=(i,e)=>(t,n)=>e(t,n,i);let de=class{constructor(i,e,t){T(this,"_docContainer");T(this,"getComponent",i=>{if(this._docContainer=i,!i.getContentRef().current)throw new Error("container is not ready")});T(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}};de=tt([Te(1,I.Inject(a.LocaleService)),Te(2,I.Inject(I.Injector))],de);var nt=Object.defineProperty,it=Object.getOwnPropertyDescriptor,rt=(i,e,t,n)=>{for(var r=n>1?void 0:n?it(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},Y=(i,e)=>(t,n)=>e(t,n,i);let w=class extends a.RxDisposable{constructor(e,t,n,r,o){super();T(this,"_docContainerController");T(this,"changeLocale",e=>{this._localeService.setLocale(e)});this._localeService=t,this._injector=n,this._textSelectionRenderManager=r,this._layoutService=o,this._docContainerController=this._injector.createInstance(de,e),this._registerContainer()}_registerContainer(){this._layoutService&&this.disposeWithMe(this._layoutService.registerContainerElement(this._textSelectionRenderManager.__getEditorContainer()))}getDocContainerController(){return this._docContainerController}};w=rt([Y(1,I.Inject(a.LocaleService)),Y(2,I.Inject(I.Injector)),Y(3,m.ITextSelectionRenderManager),Y(4,I.Optional(l.ILayoutService))],w);const G="UI_PLUGIN_DOCS",ue=`${G}_COLOR_PICKER_COMPONENT`,be=`${G}_FONT_FAMILY_COMPONENT`,Me=`${G}_FONT_FAMILY_ITEM_COMPONENT`,Re=`${G}_FONT_SIZE_COMPONENT`;var ye={exports:{}},K={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var ot=je,st=Symbol.for("react.element"),at=Symbol.for("react.fragment"),ct=Object.prototype.hasOwnProperty,lt=ot.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,dt={key:!0,ref:!0,__self:!0,__source:!0};function Ee(i,e,t){var n,r={},o=null,s=null;t!==void 0&&(o=""+t),e.key!==void 0&&(o=""+e.key),e.ref!==void 0&&(s=e.ref);for(n in e)ct.call(e,n)&&!dt.hasOwnProperty(n)&&(r[n]=e[n]);if(i&&i.defaultProps)for(n in e=i.defaultProps,e)r[n]===void 0&&(r[n]=e[n]);return{$$typeof:st,type:i,key:o,ref:s,props:r,_owner:lt.current}}K.Fragment=at,K.jsx=Ee,K.jsxs=Ee,ye.exports=K;var ut=ye.exports;const ht={docsUiCanvasBackground:"univer-docs-ui-canvas-background"},pt=()=>ut.jsx("div",{className:ht.docsUiCanvasBackground});function _t(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatBoldCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.bl;t.next(u===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function gt(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatItalicCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.it;t.next(u===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function St(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatUnderlineCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.ul;t.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function ft(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatStrikethroughCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.st;t.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function mt(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatSubscriptCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.va;t.next(u===a.BaselineOffset.SUBSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function vt(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatSuperscriptCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.va;t.next(u===a.BaselineOffset.SUPERSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function It(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatFontFamilyCommand.id,tooltip:"toolbar.font",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,label:be,positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_FAMILY_LIST.map(t=>({label:{name:Me,hoverable:!0},value:t.value})),value$:new b.Observable(t=>{const n=l.FONT_FAMILY_LIST[0].value,r=e.onCommandExecuted(o=>{var c;const s=o.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontFamilyCommand.id){const u=E(i);if(u==null)return;const h=(c=u.ts)==null?void 0:c.ff;t.next(h!=null?h:n)}});return t.next(n),r.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Ct(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatFontSizeCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Re,props:{min:1,max:400}},positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_SIZE_LIST,value$:new b.Observable(t=>{const r=e.onCommandExecuted(o=>{var c;const s=o.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontSizeCommand.id){const u=E(i);if(u==null)return;const h=(c=u.ts)==null?void 0:c.fs;t.next(h!=null?h:14)}});return t.next(14),r.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Ot(i){const e=i.get(a.ICommandService),t=i.get(a.ThemeService);return{id:d.SetInlineFormatTextColorCommand.id,icon:"FontColor",tooltip:"toolbar.textColor.main",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON_SELECTOR,positions:[l.MenuPosition.TOOLBAR_START],selections:[{label:{name:ue,hoverable:!1}}],value$:new b.Observable(n=>{const r=t.getCurrentTheme().textColor,o=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextColorCommand.id){const c=s.params.value;n.next(c!=null?c:r)}});return n.next(r),o.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Tt(i){const e=i.get(a.ICommandService);return{id:d.AlignLeftCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=X(i);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.LEFT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function bt(i){const e=i.get(a.ICommandService);return{id:d.AlignCenterCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=X(i);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.CENTER)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Mt(i){const e=i.get(a.ICommandService);return{id:d.AlignRightCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=X(i);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.RIGHT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Rt(i){const e=i.get(a.ICommandService);return{id:d.AlignJustifyCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=X(i);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.JUSTIFIED)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function yt(i){return{id:d.OrderListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"OrderSingle",tooltip:"toolbar.order",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Et(i){return{id:d.BulletListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"UnorderSingle",tooltip:"toolbar.unorder",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Dt(i){return{id:d.ResetInlineFormatTextBackgroundColorCommand.id,type:l.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:d.SetInlineFormatTextBackgroundColorCommand.id}}function Pt(i){const e=i.get(a.ICommandService),t=i.get(a.ThemeService);return{id:d.SetInlineFormatTextBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON_SELECTOR,positions:[l.MenuPosition.TOOLBAR_START],icon:"PaintBucket",selections:[{label:{name:ue,hoverable:!1}}],value$:new b.Observable(n=>{const r=t.getCurrentTheme().primaryColor,o=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextBackgroundColorCommand.id){const c=s.params.value;n.next(c!=null?c:r)}});return n.next(r),o.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function E(i){var u;const e=i.get(a.IUniverInstanceService),t=i.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const o=(u=n.getBody())==null?void 0:u.textRuns;if(o==null)return;const{startOffset:s}=r;let c;for(let h=0;h<o.length;h++){const _=o[h],g=o[h+1];if(g&&g.st===g.ed&&s===g.st){c=g;break}if(_.st<=s&&s<=_.ed){c=_;break}}return c}function X(i){var u;const e=i.get(a.IUniverInstanceService),t=i.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const o=(u=n.getBody())==null?void 0:u.paragraphs;if(o==null)return;const{startOffset:s}=r;let c=-1;for(const h of o){const{startIndex:_}=h;if(s>c&&s<=_)return h;c=_}return null}var Ut=Object.defineProperty,Nt=Object.getOwnPropertyDescriptor,xt=(i,e,t,n)=>{for(var r=n>1?void 0:n?Nt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Ut(e,t,r),r},P=(i,e)=>(t,n)=>e(t,n,i);let w=class extends a.Disposable{constructor(i,e,t,n,r,o,s,c){super(),this._config=i,this._injector=e,this._componentManager=t,this._layoutService=n,this._editorService=r,this._menuService=o,this._uiPartsService=s,this._univerInstanceService=c,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(ue,We.ColorPicker)),this.disposeWithMe(i.register(be,l.FontFamily)),this.disposeWithMe(i.register(Me,l.FontFamilyItem)),this.disposeWithMe(i.register(Re,l.FontSize))}_initMenus(){const{menu:i={}}=this._config;[_t,gt,St,ft,mt,vt,Ct,It,Ot,Tt,bt,Mt,Rt,yt,Et,Dt,Pt].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e),i))})}_init(){this._initCustomComponents(),this._initMenus(),this._initDocBackground(),this._initFocusHandler()}_initDocBackground(){const i=this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC)[0].getUnitId();if(i==null)return;this._editorService.isEditor(i)||this.disposeWithMe(this._uiPartsService.registerComponent(l.BuiltInUIPart.CONTENT,()=>Ve.connectInjector(pt,this._injector)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.UNIVER_DOC,()=>{this._injector.get(m.ITextSelectionRenderManager).focus()}))}};w=xt([a.OnLifecycle(a.LifecycleStages.Rendered,w),P(1,v.Inject(v.Injector)),P(2,v.Inject(l.ComponentManager)),P(3,l.ILayoutService),P(4,l.IEditorService),P(5,l.IMenuService),P(6,l.IUIPartsService),P(7,a.IUniverInstanceService)],w);const Lt={id:d.BreakLineCommand.id,preconditions:He,binding:l.KeyCode.ENTER},At={id:d.DeleteLeftCommand.id,preconditions:y,binding:l.KeyCode.BACKSPACE},Bt={id:d.DeleteRightCommand.id,preconditions:y,binding:l.KeyCode.DELETE},Ft=10,wt=6;function $t(){return a.Tools.generateRandomId(wt)}function Vt(i){const e=i.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class jt{constructor(){T(this,"_cache",new a.LRUMap(Ft))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}clear(){this._cache.clear()}}const De=new jt;function he(i){const e=i.style,t={},n=i.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{t.bl=a.BooleanNumber.TRUE;break}case"s":{t.st={s:a.BooleanNumber.TRUE};break}case"u":{t.ul={s:a.BooleanNumber.TRUE};break}case"i":{t.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=n==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}for(let r=0;r<e.length;r++){const o=e[r],s=e.getPropertyValue(o);switch(o){case"font-family":{t.ff=s;break}case"font-size":{const c=Number.parseInt(s);Number.isNaN(c)||(s.endsWith("pt")?t.fs=c:s.endsWith("px")&&(t.fs=m.pixelToPt(c)));break}case"font-style":{s==="italic"&&(t.it=a.BooleanNumber.TRUE);break}case"font-weight":{Number(s)>400&&(t.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(s)?t.ul={s:a.BooleanNumber.TRUE}:/overline/.test(s)?t.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(s)&&(t.st={s:a.BooleanNumber.TRUE});break}case"color":{const c=new a.ColorKit(s);c.isValid&&(t.cl={rgb:c.toRgbString()});break}case"background-color":{const c=new a.ColorKit(s);c.isValid&&(t.bg={rgb:c.toRgbString()});break}}}return t}function Wt(i){const e=new DOMParser,t=`<x-univer id="univer-root">${i}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function Pe(i,e){const t=i.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(i)}const ce=class ce{constructor(){T(this,"_styleCache",new Map);T(this,"_styleRules",[]);T(this,"_afterProcessRules",[])}static use(e){if(this._pluginList.includes(e))throw new Error(`Univer paste plugin ${e.name} already added`);this._pluginList.push(e)}convert(e){const t=ce._pluginList.find(o=>o.checkPasteType(e)),n=Wt(e),r={dataStream:"",textRuns:[]};return t&&(this._styleRules=[...t.stylesRules],this._afterProcessRules=[...t.afterProcessRules]),this._styleCache.clear(),this._process(null,n==null?void 0:n.childNodes,r),this._styleCache.clear(),this._styleRules=[],this._afterProcessRules=[],r}_process(e,t,n){var r;for(const o of t)if(o.nodeType===Node.TEXT_NODE){const s=(r=o.nodeValue)==null?void 0:r.replace(/[\r\n]/g,"");let c;e&&this._styleCache.has(e)&&(c=this._styleCache.get(e)),n.dataStream+=s,c&&Object.getOwnPropertyNames(c).length&&n.textRuns.push({st:n.dataStream.length-s.length,ed:n.dataStream.length,ts:c})}else if(o.nodeType===Node.ELEMENT_NODE){const s=e?this._styleCache.get(e):{},c=this._styleRules.find(({filter:g})=>Pe(o,g)),u=c?c.getStyle(o):he(o);this._styleCache.set(o,{...s,...u});const{childNodes:h}=o;this._process(o,h,n);const _=this._afterProcessRules.find(({filter:g})=>Pe(o,g));_&&_.handler(n,o)}}};T(ce,"_pluginList",[]);let x=ce;const Ue={name:"univer-doc-paste-plugin-lark",checkPasteType(i){return/lark-record-clipboard/i.test(i)},stylesRules:[{filter:["s"],getStyle(i){const e=he(i);return{st:{s:a.BooleanNumber.TRUE},...e}}}],afterProcessRules:[{filter(i){return i.tagName==="DIV"&&/ace-line/i.test(i.className)},handler(i){i.paragraphs==null&&(i.paragraphs=[]),i.paragraphs.push({startIndex:i.dataStream.length}),i.dataStream+="\r"}}]};function Ne(i){const e=i.style,t={};for(let n=0;n<e.length;n++){const r=e[n],o=e.getPropertyValue(r);switch(r){case"margin-top":{const s=Number.parseInt(o);t.spaceAbove=/pt/.test(o)?m.ptToPixel(s):s;break}case"margin-bottom":{const s=Number.parseInt(o);t.spaceBelow=/pt/.test(o)?m.ptToPixel(s):s;break}case"line-height":{const s=Number.parseFloat(o);t.lineSpacing=s;break}}}return Object.getOwnPropertyNames(t).length?t:null}const xe={name:"univer-doc-paste-plugin-word",checkPasteType(i){return/word|mso/i.test(i)},stylesRules:[{filter:["b"],getStyle(i){const e=he(i);return{bl:a.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(i){return i.tagName==="P"&&/mso/i.test(i.className)},handler(i,e){i.paragraphs==null&&(i.paragraphs=[]);const t={startIndex:i.dataStream.length},n=Ne(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]},Le={name:"univer-doc-paste-plugin-univer",checkPasteType(i){return/UniverNormal/i.test(i)},stylesRules:[],afterProcessRules:[{filter(i){return i.tagName==="P"&&/UniverNormal/i.test(i.className)},handler(i,e){i.paragraphs==null&&(i.paragraphs=[]);const t={startIndex:i.dataStream.length},n=Ne(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]};function Ae(i,e){const{st:t,ed:n,ts:r={}}=e,{ff:o,fs:s,it:c,bl:u,ul:h,st:_,ol:g,bg:C,cl:f,va:I}=r;let p=i.slice(t,n);const O=[];return c===a.BooleanNumber.TRUE&&(p=`<i>${p}</i>`),I===a.BaselineOffset.SUPERSCRIPT?p=`<sup>${p}</sup>`:I===a.BaselineOffset.SUBSCRIPT&&(p=`<sub>${p}</sub>`),(h==null?void 0:h.s)===a.BooleanNumber.TRUE&&(p=`<u>${p}</u>`),(_==null?void 0:_.s)===a.BooleanNumber.TRUE&&(p=`<s>${p}</s>`),u===a.BooleanNumber.TRUE&&(p=`<strong>${p}</strong>`),o&&O.push(`font-family: ${o}`),f&&O.push(`color: ${f.rgb}`),s&&O.push(`font-size: ${s}pt`),g&&O.push("text-decoration: overline"),C&&O.push(`background: ${C.rgb}`),O.length?`<span style="${O.join("; ")};">${p}</span>`:p}function pe(i,e,t){const{dataStream:n,textRuns:r=[]}=i;let o=e;const s=[];for(const c of r){const{st:u,ed:h}=c;a.Tools.hasIntersectionBetweenTwoRanges(e,t,u,h)&&(u>o?(s.push(n.slice(o,u)),s.push(Ae(n,{...c,ed:Math.min(h,t)}))):s.push(Ae(n,{...c,st:o,ed:Math.min(h,t)}))),o=Math.max(e,Math.min(h,t))}return o!==t&&s.push(n.slice(o,t)),s.join("")}function Be(i,e=!0){var t;if(e&&((t=i.paragraphs)!=null&&t.length)){const{dataStream:n,paragraphs:r=[]}=i;let o="",s=-1;for(const c of r){const{startIndex:u,paragraphStyle:h={}}=c,{spaceAbove:_,spaceBelow:g,lineSpacing:C}=h,f=[];_!=null&&(typeof _=="number"?f.push(`margin-top: ${_}px`):f.push(`margin-top: ${_.v}px`)),g!=null&&(typeof g=="number"?f.push(`margin-bottom: ${g}px`):f.push(`margin-bottom: ${g.v}px`)),C!=null&&f.push(`line-height: ${C}`),u>s+1?o+=`<p class="UniverNormal" ${f.length?`style="${f.join("; ")};"`:""}>${pe(i,s+1,u)}</p>`:o+=`<p class="UniverNormal" ${f.length?`style="${f.join("; ")};"`:""}></p>`,s=u}return s!==n.length&&(o+=pe(i,s,n.length)),o}else return pe(i,0,i.dataStream.length)}class Ht{convert(e){if(e.length===0)throw new Error("The bodyList length at least to be 1");if(e.length===1)return Be(e[0]);let t="";for(const n of e)t+='<p className="UniverNormal">',t+=Be(n,!1),t+="</p>";return t}}var kt=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,Yt=(i,e,t,n)=>{for(var r=n>1?void 0:n?zt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&kt(e,t,r),r},$=(i,e)=>(t,n)=>e(t,n,i);x.use(xe),x.use(Ue),x.use(Le);function Gt(i){const e=i.replace(/\n/g,"\r"),t=[];for(let n=0;n<e.length;n++)e[n]==="\r"&&t.push({startIndex:n});return{dataStream:e,paragraphs:t}}const V=v.createIdentifier("doc.clipboard-service");let _e=class extends a.Disposable{constructor(e,t,n,r,o){super();T(this,"_clipboardHooks",[]);T(this,"_htmlToUDM",new x);T(this,"_umdToHtml",new Ht);this._univerInstanceService=e,this._logService=t,this._commandService=n,this._clipboardInterfaceService=r,this._textSelectionManagerService=o}async copy(){const e=this._getDocumentBodyInRanges();if(e.length===0)return!1;try{this._setClipboardData(e)}catch(t){return this._logService.error("[DocClipboardService] copy failed",t),!1}return!0}async cut(){return this._cut()}async paste(e){const t=await this._generateBodyFromClipboardItems(e);return this._paste(t)}async legacyPaste(e,t){const n=this._generateBodyFromHtmlAndText(e,t);return this._paste(n)}async _cut(){var o;const{segmentId:e,endOffset:t,style:n}=(o=this._textSelectionManagerService.getActiveRange())!=null?o:{},r=this._textSelectionManagerService.getSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),t==null||r==null)return!1;this.copy();try{let s=t;for(const u of r){const{startOffset:h,endOffset:_}=u;h==null||_==null||_<=t&&(s-=_-h)}const c=[{startOffset:s,endOffset:s,style:n}];return this._commandService.executeCommand(d.CutContentCommand.id,{segmentId:e,textRanges:c})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(e){var s;const{segmentId:t,endOffset:n,style:r}=(s=this._textSelectionManagerService.getActiveRange())!=null?s:{},o=this._textSelectionManagerService.getSelections();if(t==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),n==null||o==null)return!1;try{let c=n;for(const h of o){const{startOffset:_,endOffset:g}=h;_==null||g==null||g<=n&&(c+=e.dataStream.length-(g-_))}const u=[{startOffset:c,endOffset:c,style:r}];return this._commandService.executeCommand(d.InnerPasteCommand.id,{body:e,segmentId:t,textRanges:u})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(e){const t=$t(),n=e.length>1?e.map(o=>o.dataStream).join(`
|
|
10
|
-
`):e[0].dataStream;let r=this._umdToHtml.convert(e);return e.length===1&&(r=r.replace(/(<[a-z]+)/,(o,s)=>`${s} data-copy-id="${t}"`),De.set(t,e[0])),this._clipboardInterfaceService.write(n,r)}addClipboardHook(e){return this._clipboardHooks.push(e),a.toDisposable(()=>{const t=this._clipboardHooks.indexOf(e);t>-1&&this._clipboardHooks.splice(t,1)})}_getDocumentBodyInRanges(){const e=this._textSelectionManagerService.getSelections(),t=this._univerInstanceService.getCurrentUniverDocInstance(),n=[];if(e==null||!t)return n;for(const r of e){const{startOffset:o,endOffset:s,collapsed:c}=r;if(c||o==null||s==null)continue;const u=t.sliceBody(o,s);u!=null&&n.push(u)}return n}async _generateBodyFromClipboardItems(e){try{let t="",n="";for(const r of e)for(const o of r.types)o===l.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await r.getType(o).then(s=>s&&s.text()):o===l.HTML_CLIPBOARD_MIME_TYPE&&(t=await r.getType(o).then(s=>s&&s.text()));return this._generateBodyFromHtmlAndText(t,n)}catch(t){return Promise.reject(t)}}_generateBodyFromHtmlAndText(e,t){if(!e){if(t)return Gt(t);throw new Error("[DocClipboardService] html and text cannot be both empty!")}const n=Vt(e);if(n){const r=De.get(n);if(r)return r}return this._htmlToUDM.convert(e)}};_e=Yt([$(0,a.IUniverInstanceService),$(1,a.ILogService),$(2,a.ICommandService),$(3,l.IClipboardInterfaceService),$(4,v.Inject(d.TextSelectionManagerService))],_e);function q(i){return i.getContextValue(a.FOCUSING_DOC)||i.getContextValue(a.EDITOR_ACTIVATED)}const ge=999,Kt={id:l.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:ge,preconditions:q,handler:async i=>i.get(V).copy()},Xt={id:l.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:ge,preconditions:q,handler:async i=>i.get(V).cut()},qt={id:l.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:ge,preconditions:q,handler:async i=>{const e=i.get(V),n=await i.get(l.IClipboardInterfaceService).read();return n.length===0?!1:e.paste(n)}};var Zt=Object.defineProperty,Jt=Object.getOwnPropertyDescriptor,Qt=(i,e,t,n)=>{for(var r=n>1?void 0:n?Jt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Zt(e,t,r),r},j=(i,e)=>(t,n)=>e(t,n,i);let Z=class extends a.RxDisposable{constructor(i,e,t,n,r){super(),this._commandService=i,this._clipboardInterfaceService=e,this._docClipboardService=t,this._textSelectionRenderManager=n,this._contextService=r,this._init()}_init(){[Kt,Xt,qt].forEach(i=>this.disposeWithMe(this._commandService.registerMultipleCommand(i))),[d.InnerPasteCommand,d.CutContentCommand].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i))),this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var i;(i=this._textSelectionRenderManager)==null||i.onPaste$.pipe(b.takeUntil(this.dispose$)).subscribe(e=>{var o,s;if(!q(this._contextService))return;e.event.preventDefault();const t=e.event,n=(o=t.clipboardData)==null?void 0:o.getData("text/html"),r=(s=t.clipboardData)==null?void 0:s.getData("text/plain");this._docClipboardService.legacyPaste(n,r)})}};Z=Qt([a.OnLifecycle(a.LifecycleStages.Rendered,Z),j(0,a.ICommandService),j(1,l.IClipboardInterfaceService),j(2,V),j(3,m.ITextSelectionRenderManager),j(4,a.IContextService)],Z);var en=Object.defineProperty,tn=Object.getOwnPropertyDescriptor,nn=(i,e,t,n)=>{for(var r=n>1?void 0:n?tn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&en(e,t,r),r},L=(i,e)=>(t,n)=>e(t,n,i);let J=class extends a.Disposable{constructor(e,t,n,r,o,s){super();T(this,"_initialEditors",new Set);this._univerInstanceService=e,this._docSkeletonManagerService=t,this._editorService=n,this._commandService=r,this._textSelectionRenderManager=o,this._renderManagerService=s,this._initialize()}_initialize(){this.disposeWithMe(this._editorService.resize$.subscribe(e=>{this._resize(e)})),this._editorService.getAllEditor().forEach(e=>{const t=e.editorUnitId;this._initialEditors.has(t)||(this._initialEditors.add(t),this._resize(t))}),this._commandExecutedListener(),this._initialSetValue(),this._initialBlur(),this._initialFocus(),this._initialValueChange()}_resize(e){var D,B,N;if(e==null)return;const t=this._editorService.getEditor(e);if((t==null?void 0:t.cancelDefaultResizeListener)===!0)return;const n=(D=this._docSkeletonManagerService.getSkeletonByUnitId(e))==null?void 0:D.skeleton,r=this._univerInstanceService.getUniverDocInstance(e);if(t==null||t.render==null||n==null||r==null)return;n.calculate();const{marginTop:o=0,marginBottom:s=0,marginLeft:c=0,marginRight:u=0}=r.getSnapshot().documentStyle,{scene:h,mainComponent:_}=t.render;let{actualHeight:g,actualWidth:C}=n.getActualSize();g+=o+s,C+=c+u;const{width:f,height:I}=t.getBoundingClientRect(),p=h.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);let O=p==null?void 0:p.getScrollBar();const M=Math.max(C,f),R=Math.max(g,I);h.transformByState({width:M,height:R}),_==null||_.resize(M,R),t.isSingle()?C>f?O==null?p&&new m.ScrollBar(p,{barSize:8,enableVertical:!1}):p==null||p.resetSizeAndScrollBar():(O=null,p==null||p.scrollTo({x:0,y:0}),(N=p==null?void 0:p.getScrollBar())==null||N.dispose()):g>I?O==null?p&&new m.ScrollBar(p,{enableHorizontal:!1,barSize:8}):p==null||p.resetSizeAndScrollBar():(O=null,p==null||p.scrollTo({x:0,y:0}),(B=p==null?void 0:p.getScrollBar())==null||B.dispose())}_initialSetValue(){this.disposeWithMe(this._editorService.setValue$.subscribe(e=>{this._commandService.executeCommand(d.CoverContentCommand.id,{unitId:e.editorUnitId,body:e.body,segmentId:null})}))}_initialBlur(){this.disposeWithMe(this._editorService.blur$.subscribe(()=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.blur()})),this.disposeWithMe(this._textSelectionRenderManager.onBlur$.subscribe(()=>{var r;const e=(r=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:r.getUnitId();if(e==null)return;const t=this._editorService.getEditor(e),n=this._editorService.getFocusEditor();t==null||t.isSheetEditor()||n&&n.editorUnitId===e||this._editorService.blur()}))}_initialFocus(){this.disposeWithMe(this._editorService.focus$.subscribe(n=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges([n])}));const e=["univer-formula-search","univer-formula-help","formula-help-decorator","univer-formula-help-param"];this.disposeWithMe(b.fromEvent(window,"mousedown").subscribe(n=>{const o=n.target.classList[0]||"";if(a.checkForSubstrings(o,e)){this._editorService.changeSpreadsheetFocusState(!0),n.stopPropagation();return}this._editorService.changeSpreadsheetFocusState(!1)})),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(n=>{const r=n.getUnitId(),o=this._renderManagerService.getRenderById(r),s=o==null?void 0:o.engine.getCanvas().getCanvasEle();s!=null&&b.fromEvent(s,"mousedown").subscribe(c=>{this._editorService.changeSpreadsheetFocusState(!0),c.stopPropagation()})})}_initialValueChange(){this.disposeWithMe(this._textSelectionRenderManager.onCompositionupdate$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onInput$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onKeydown$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onPaste$.subscribe(this._valueChange.bind(this)))}_valueChange(){var n;const e=(n=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:n.getUnitId();if(e==null)return;const t=this._editorService.getEditor(e);t==null||t.isSheetEditor()||this._editorService.refreshValueChange(e)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,l.SetEditorResizeOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=t.params,{unitId:r}=n;if(this._editorService.isSheetEditor(r))return;this._resize(r),this._valueChange()}}))}};J=nn([a.OnLifecycle(a.LifecycleStages.Rendered,J),L(0,a.IUniverInstanceService),L(1,v.Inject(d.DocSkeletonManagerService)),L(2,l.IEditorService),L(3,a.ICommandService),L(4,m.ITextSelectionRenderManager),L(5,m.IRenderManagerService)],J);var rn=Object.defineProperty,on=Object.getOwnPropertyDescriptor,sn=(i,e,t,n)=>{for(var r=n>1?void 0:n?on(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&rn(e,t,r),r},Q=(i,e)=>(t,n)=>e(t,n,i);let ee=class extends a.RxDisposable{constructor(e,t,n,r){super();T(this,"_docRenderMap",new Set);this._docSkeletonManagerService=e,this._renderManagerService=t,this._commandService=n,this._editorService=r,this._initialRenderRefresh(),this._commandExecutedListener()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(b.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)})}_create(e){if(e==null)return;const{skeleton:t,unitId:n}=e;let r=this._renderManagerService.getRenderById(n);r==null&&(this._renderManagerService.create(n),r=this._renderManagerService.getRenderById(n));const{mainComponent:o,components:s}=r,c=o,u=s.get(d.DOCS_VIEW_KEY.BACKGROUND);c.changeSkeleton(t),u.changeSkeleton(t),this._recalculateSizeBySkeleton(r,t)}_recalculateSizeBySkeleton(e,t){var C;const{mainComponent:n,scene:r,unitId:o,components:s}=e,c=n,u=s.get(d.DOCS_VIEW_KEY.BACKGROUND),h=(C=t.getSkeletonData())==null?void 0:C.pages;if(h==null)return;let _=0,g=0;for(let f=0,I=h.length;f<I;f++){const p=h[f],{pageWidth:O,pageHeight:M}=p;c.pageLayoutType===m.PageLayoutType.VERTICAL?(g+=M,g+=c.pageMarginTop,f===I-1&&(g+=c.pageMarginTop),_=Math.max(_,O)):c.pageLayoutType===m.PageLayoutType.HORIZONTAL&&(_+=O,f!==I-1&&(_+=c.pageMarginLeft),g=Math.max(g,M))}c.resize(_,g),u.resize(_,g),this._editorService.isEditor(o)||r.resize(_,g)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=this._docSkeletonManagerService.getSkeletonByUnitId(o);if(s==null)return;const{skeleton:c}=s,u=this._renderManagerService.getRenderById(o);if(u==null||!!c.getViewModel().getDataModel().getSnapshot().disabled)return;if(c.calculate(),this._editorService.isEditor(o)){(n=u.mainComponent)==null||n.makeDirty();return}this._recalculateSizeBySkeleton(u,c)}}))}};ee=sn([a.OnLifecycle(a.LifecycleStages.Rendered,ee),Q(0,v.Inject(d.DocSkeletonManagerService)),Q(1,m.IRenderManagerService),Q(2,a.ICommandService),Q(3,l.IEditorService)],ee);var an=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,ln=(i,e,t,n)=>{for(var r=n>1?void 0:n?cn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&an(e,t,r),r},te=(i,e)=>(t,n)=>e(t,n,i);S.DocCanvasView=class extends a.RxDisposable{constructor(t,n,r,o){super();T(this,"_scene");T(this,"_currentDocumentModel");T(this,"_fps$",new b.BehaviorSubject(""));T(this,"fps$",this._fps$.asObservable());this._renderManagerService=t,this._configService=n,this._univerInstanceService=r,this._editorService=o,this._initialize()}_initialize(){this._renderManagerService.createRender$.pipe(b.takeUntil(this.dispose$)).subscribe(t=>{this._create(t)}),this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC).pipe(b.takeUntil(this.dispose$)).subscribe(t=>{this._create(t==null?void 0:t.getUnitId())}),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC).forEach(t=>{this._create(t.getUnitId())})}dispose(){this._fps$.complete()}_create(t){if(t==null)return;const n=this._univerInstanceService.getUniverDocInstance(t);n!=null&&(this._currentDocumentModel=n,this._renderManagerService.has(t)||this._addNewRender())}_addNewRender(){const n=this._currentDocumentModel.getUnitId();this._renderManagerService.createRender(n);const r=this._renderManagerService.getRenderById(n);if(r==null)return;const{scene:o,engine:s}=r;this._scene=o;const c=new m.Viewport(d.VIEWPORT_KEY.VIEW_MAIN,o,{left:0,top:0,bottom:0,right:0,isRelativeX:!0,isRelativeY:!0,isWheelPreventDefaultX:!0});o.attachControl(),o.on(m.EVENT_TYPE.wheel,(_,g)=>{const C=_;if(C.ctrlKey){const f=Math.abs(C.deltaX);let I=f<40?.2:f<80?.4:.2;I*=C.deltaY>0?-1:1,o.scaleX<1&&(I/=2),o.scaleX+I>4?o.scale(4,4):o.scaleX+I<.1?o.scale(.1,.1):C.preventDefault()}else c.onMouseWheel(C,g)}),this._configService.getConfig("hasScroll")!==!1&&new m.ScrollBar(c),o.addLayer(new m.Layer(o,[],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),new m.Layer(o,[],d.DOCS_COMPONENT_HEADER_LAYER_INDEX)),this._addComponent(r),this._currentDocumentModel.getShouldRenderLoopImmediately()&&s.runRenderLoop(()=>{o.render(),this._fps$.next(Math.round(s.getFps()).toString())}),this._renderManagerService.setCurrent(n)}_addComponent(t){const n=this._scene,r=this._currentDocumentModel,o={pageMarginLeft:r.documentStyle.marginLeft||0,pageMarginTop:r.documentStyle.marginTop||0},s=new m.Documents(d.DOCS_VIEW_KEY.MAIN,void 0,o),c=new m.DocBackground(d.DOCS_VIEW_KEY.BACKGROUND,void 0,o);s.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX,c.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX,t.mainComponent=s,t.components.set(d.DOCS_VIEW_KEY.MAIN,s),t.components.set(d.DOCS_VIEW_KEY.BACKGROUND,c),n.addObjects([s],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),n.addObjects([c],d.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX),this._editorService.getEditor(r.getUnitId())==null&&n.enableLayerCache(d.DOCS_COMPONENT_MAIN_LAYER_INDEX)}},S.DocCanvasView=ln([a.OnLifecycle(a.LifecycleStages.Starting,S.DocCanvasView),te(0,m.IRenderManagerService),te(1,a.IConfigService),te(2,a.IUniverInstanceService),te(3,l.IEditorService)],S.DocCanvasView);var dn=Object.defineProperty,un=Object.getOwnPropertyDescriptor,hn=(i,e,t,n)=>{for(var r=n>1?void 0:n?un(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&dn(e,t,r),r},ne=(i,e)=>(t,n)=>e(t,n,i);let ie=class extends a.Disposable{constructor(e,t,n,r){super();T(this,"_liquid",new m.Liquid);T(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=e,this._renderManagerService=t,this._commandService=n,this._editorService=r,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh(),this._updateOnPluginChange()}_updateOnPluginChange(){}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{skeleton:t,unitId:n}=e,r=this._renderManagerService.getRenderById(n);if(r==null)return;const{mainComponent:o}=r;o.changeSkeleton(t),this._refreshDrawing(n,t,r)})}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=this._docSkeletonManagerService.getCurrent();if(s==null)return;const{unitId:c,skeleton:u}=s;if(o!==c)return;const h=this._renderManagerService.getRenderById(c);if(h==null)return;if(this._editorService.isEditor(c)){(n=h.mainComponent)==null||n.makeDirty();return}this._refreshDrawing(c,u,h)}}))}_refreshDrawing(e,t,n){const r=t==null?void 0:t.getSkeletonData(),{mainComponent:o,scene:s}=n,c=o;if(!r)return;const{left:u,top:h,pageLayoutType:_,pageMarginLeft:g,pageMarginTop:C}=c,{pages:f}=r,I=[];s.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let p=0,O=f.length;p<O;p++){const M=f[p],{skeDrawings:R,marginLeft:D,marginTop:B}=M;this._liquid.translatePagePadding(M),R.forEach(N=>{const{aLeft:H,aTop:k,height:fe,width:me,drawingId:z,drawingOrigin:$e}=N,Un=$e.layoutType===a.PositionedObjectLayoutType.WRAP_NONE&&$e.behindDoc===a.BooleanNumber.TRUE;I.push({unitId:e,subUnitId:a.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:z,behindText:Un,floatingObject:{left:H+u+this._liquid.x,top:k+h+this._liquid.y,width:me,height:fe}}),this._pageMarginCache.set(z,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.restorePagePadding(M),this._liquid.translatePage(M,_,g,C)}}};ie=hn([a.OnLifecycle(a.LifecycleStages.Steady,ie),ne(0,v.Inject(d.DocSkeletonManagerService)),ne(1,m.IRenderManagerService),ne(2,a.ICommandService),ne(3,l.IEditorService)],ie);var pn=Object.defineProperty,_n=Object.getOwnPropertyDescriptor,gn=(i,e,t,n)=>{for(var r=n>1?void 0:n?_n(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&pn(e,t,r),r},A=(i,e)=>(t,n)=>e(t,n,i);let re=class extends a.Disposable{constructor(e,t,n,r,o,s){super();T(this,"_initializedRender",new Set);this._docSkeletonManagerService=e,this._univerInstanceService=t,this._commandService=n,this._renderManagerService=r,this._textSelectionManagerService=o,this._editorService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._initialRenderRefresh()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t}=e,n=this._renderManagerService.getRenderById(t);if(n==null||this._initializedRender.has(t)||this._editorService.isEditor(t))return;this._initializedRender.add(t);const{scene:r}=n;this.disposeWithMe(a.toDisposable(r.onMouseWheelObserver.add(o=>{if(!o.ctrlKey)return;const s=this._univerInstanceService.getCurrentUniverDocInstance();if(!s)return;const c=Math.abs(o.deltaX);let u=c<40?.2:c<80?.4:.2;u*=o.deltaY>0?-1:1,r.scaleX<1&&(u/=2);const h=s.zoomRatio;let _=+Number.parseFloat(`${h+u}`).toFixed(1);_=_>=4?4:_<=.1?.1:_,this._commandService.executeCommand(d.SetDocZoomRatioCommand.id,{zoomRatio:_,unitId:s.getUnitId()}),o.preventDefault()})))})}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const t=this._univerInstanceService.getCurrentUniverDocInstance();if(!t)return;const n=t.zoomRatio||1;this._updateViewZoom(n,!1)})))}_commandExecutedListener(){const e=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=this._univerInstanceService.getCurrentUniverDocInstance();if(!n)return;const r=t.params,{unitId:o}=r;if(o!==n.getUnitId())return;const s=n.zoomRatio||1;this._updateViewZoom(s)}}))}_updateViewZoom(e,t=!0){var r;const n=this._getDocObject();n!=null&&(n.scene.scale(e,e),this._calculatePagePosition(n,e),t&&this._textSelectionManagerService.refreshSelection(),(r=n.scene.getTransformer())==null||r.clearSelectedObjects())}_calculatePagePosition(e,t){const{document:n,scene:r,docBackground:o}=e,s=r==null?void 0:r.getParent(),{width:c,height:u,pageMarginLeft:h,pageMarginTop:_}=n;if(s==null||c===Number.POSITIVE_INFINITY||u===Number.POSITIVE_INFINITY)return;const{width:g,height:C}=s;let f=0,I=0,p=0,O=0,M=Number.POSITIVE_INFINITY;g>(c+h*2)*t?(f=g/2-c*t/2,f/=t,p=(g-h*2)/t,M=0):(f=h,p=c+h*2,M=(p-g/t)/2),C>u?(I=C/2-u/2,O=(C-_*2)/t):(I=_,O=u+_*2),r.resize(p,O+200),n.translate(f,I),o.translate(f,I);const R=r.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(M!==Number.POSITIVE_INFINITY&&R!=null){const D=R.getBarScroll(M,0).x;R.scrollTo({x:D})}return this}_getDocObject(){return d.getDocObject(this._univerInstanceService,this._renderManagerService)}};re=gn([a.OnLifecycle(a.LifecycleStages.Rendered,re),A(0,v.Inject(d.DocSkeletonManagerService)),A(1,a.IUniverInstanceService),A(2,a.ICommandService),A(3,m.IRenderManagerService),A(4,v.Inject(d.TextSelectionManagerService)),A(5,l.IEditorService)],re);var Sn=Object.defineProperty,fn=Object.getOwnPropertyDescriptor,mn=(i,e,t,n)=>{for(var r=n>1?void 0:n?fn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Sn(e,t,r),r},U=(i,e)=>(t,n)=>e(t,n,i);let oe=class extends a.Disposable{constructor(e,t,n,r,o,s,c){super();T(this,"_loadedMap",new WeakSet);this._docSkeletonManagerService=e,this._univerInstanceService=t,this._commandService=n,this._renderManagerService=r,this._textSelectionRenderManager=o,this._textSelectionManagerService=s,this._editorService=c,this._initialize()}_initialize(){this._init(),this._skeletonListener(),this._commandExecutedListener()}_init(){this.disposeWithMe(this._renderManagerService.currentRender$.subscribe(e=>{this._create(e)})),this._renderManagerService.getRenderAll().forEach((e,t)=>{this._create(t)})}_create(e){if(e==null||this._univerInstanceService.getUniverDocInstance(e)==null)return;const t=this._getDocObjectById(e);t==null||t.document==null||this._loadedMap.has(t.document)||(this._initialMain(e),this._loadedMap.add(t.document))}_initialMain(e){const t=this._getDocObjectById(e);if(t==null)return;const{document:n,scene:r}=t;this.disposeWithMe(a.toDisposable(n.onPointerEnterObserver.add(()=>{this._isEditorReadOnly(e)||(n.cursor=m.CURSOR_TYPE.TEXT)}))),this.disposeWithMe(a.toDisposable(n.onPointerLeaveObserver.add(()=>{n.cursor=m.CURSOR_TYPE.DEFAULT,r.resetCursor()}))),this.disposeWithMe(a.toDisposable(n==null?void 0:n.onPointerDownObserver.add((o,s)=>{if(this._isEditorReadOnly(e))return;const c=this._univerInstanceService.getCurrentUniverDocInstance();(c==null?void 0:c.getUnitId())!==e&&this._univerInstanceService.setCurrentUnitForType(e),this._textSelectionRenderManager.eventTrigger(o);const{offsetX:u,offsetY:h}=o;this._editorService.getEditor(e)&&(this._setEditorFocus(e),setTimeout(()=>{this._setEditorFocus(e),this._textSelectionRenderManager.setCursorManually(u,h)},0)),o.button!==2&&s.stopPropagation()}))),this.disposeWithMe(a.toDisposable(n==null?void 0:n.onDblclickObserver.add(o=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleDblClick(o)}))),this.disposeWithMe(a.toDisposable(n==null?void 0:n.onTripleClickObserver.add(o=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleTripleClick(o)})))}_isEditorReadOnly(e){const t=this._editorService.getEditor(e);return t?t.isReadOnly():!1}_setEditorFocus(e){if(this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).length>0){const n=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);this._editorService.setOperationSheetUnitId(n.getUnitId())}this._editorService.focusStyle(e)}_commandExecutedListener(){const e=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=(n=this._textSelectionManagerService.getCurrentSelection())==null?void 0:n.unitId;if(o!==s)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t,skeleton:n}=e,r=this._renderManagerService.getRenderById(t);if(r==null)return;const{scene:o,mainComponent:s}=r;this._textSelectionRenderManager.changeRuntime(n,o,s),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:t,subUnitId:""})}))}_getDocObjectById(e){return this._univerInstanceService.getUnitType(e)!==a.UniverInstanceType.UNIVER_DOC?null:d.getDocObjectById(e,this._renderManagerService)}};oe=mn([a.OnLifecycle(a.LifecycleStages.Rendered,oe),U(0,v.Inject(d.DocSkeletonManagerService)),U(1,a.IUniverInstanceService),U(2,a.ICommandService),U(3,m.IRenderManagerService),U(4,m.ITextSelectionRenderManager),U(5,v.Inject(d.TextSelectionManagerService)),U(6,l.IEditorService)],oe);var vn=Object.defineProperty,In=Object.getOwnPropertyDescriptor,Cn=(i,e,t,n)=>{for(var r=n>1?void 0:n?In(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&vn(e,t,r),r},W=(i,e)=>(t,n)=>e(t,n,i);const Fe=1.5;let se=class extends a.RxDisposable{constructor(i,e,t,n,r){super(),this._docSkeletonManagerService=i,this._textSelectionManagerService=e,this._editorService=t,this._univerInstanceService=n,this._renderManagerService=r,this._init()}_init(){this._textSelectionManagerService.textSelection$.pipe(b.takeUntil(this.dispose$)).subscribe(i=>{if(i==null)return;const{isEditing:e,unitId:t}=i;e&&this._scrollToSelection(t)})}_scrollToSelection(i){var z;const e=this._textSelectionManagerService.getActiveRange(),t=this._getDocObject(),n=(z=this._docSkeletonManagerService.getCurrent())==null?void 0:z.skeleton;if(e==null||t==null||n==null)return;const{collapsed:r,startNodePosition:o}=e;if(!r)return;const s=t.document.getOffsetConfig(),{docsLeft:c,docsTop:u}=s,h=new m.NodePositionConvertToCursor(s,n),{contentBoxPointGroup:_}=h.getRangePointData(o,o),{left:g,top:C,height:f}=m.getAnchorBounding(_),I=g+c,p=C+u,O=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN),M=!!this._editorService.getEditor(i);if(O==null)return;const{left:R,top:D,right:B,bottom:N}=O.getBounding().viewBound;let H=0,k=0;const fe=M?0:100;p<D?H=p-D:p>N-f&&(H=p-N+f+fe),I<R?k=I-R:I>B-Fe&&(k=I-B+Fe);const me=O.getBarScroll(k,H);O.scrollBy(me)}_getDocObject(){return d.getDocObject(this._univerInstanceService,this._renderManagerService)}};se=Cn([a.OnLifecycle(a.LifecycleStages.Rendered,se),W(0,v.Inject(d.DocSkeletonManagerService)),W(1,v.Inject(d.TextSelectionManagerService)),W(2,l.IEditorService),W(3,a.IUniverInstanceService),W(4,m.IRenderManagerService)],se);var On=Object.defineProperty,Tn=Object.getOwnPropertyDescriptor,bn=(i,e,t,n)=>{for(var r=n>1?void 0:n?Tn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&On(e,t,r),r},ae=(i,e)=>(t,n)=>e(t,n,i);function Mn(i,e){const t=we(i.left,i.top,e),n=we(i.right,i.bottom,e);return{left:t.x,top:t.y,right:n.x,bottom:n.y}}function we(i,e,t){const{scaleX:n,scaleY:r}=t.getAncestorScale(),o=t.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(!o)return{x:i,y:e};const{viewportScrollX:s,viewportScrollY:c}=o,u=(i-s)*n,h=(e-c)*r;return{x:u,y:h}}S.DocCanvasPopManagerService=class extends a.Disposable{constructor(e,t,n,r){super(),this._globalPopupManagerService=e,this._renderManagerService=t,this._univerInstanceService=n,this._commandService=r}_createObjectPositionObserver(e,t){const n=()=>{const{scene:u}=t,{left:h,top:_,width:g,height:C}=e,f={left:h,right:h+g,top:_,bottom:_+C},I=Mn(f,u);return{left:I.left,right:I.right,top:I.top,bottom:I.bottom}},r=n(),o=new b.BehaviorSubject(r),s=new a.DisposableCollection;s.add(this._commandService.onCommandExecuted(u=>{u.id===d.SetDocZoomRatioOperation.id&&o.next(n())}));const c=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);return s.add(c==null?void 0:c.onScrollAfterObserver.add(()=>{o.next(n())})),{position:r,position$:o,disposable:s}}attachPopupToObject(e,t){const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC).getUnitId(),o=this._renderManagerService.getRenderById(r);if(!o)return{dispose:()=>{}};const{position:s,position$:c,disposable:u}=this._createObjectPositionObserver(e,o),h=this._globalPopupManagerService.addPopup({...t,unitId:r,subUnitId:"default",anchorRect:s,anchorRect$:c});return{dispose:()=>{this._globalPopupManagerService.removePopup(h),c.complete(),u.dispose()}}}},S.DocCanvasPopManagerService=bn([ae(0,v.Inject(l.ICanvasPopupService)),ae(1,m.IRenderManagerService),ae(2,a.IUniverInstanceService),ae(3,a.ICommandService)],S.DocCanvasPopManagerService);var Rn=Object.defineProperty,yn=Object.getOwnPropertyDescriptor,En=(i,e,t,n)=>{for(var r=n>1?void 0:n?yn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Rn(e,t,r),r},Se=(i,e)=>(t,n)=>e(t,n,i);S.UniverDocsUIPlugin=(le=class extends a.Plugin{constructor(e,t,n,r){super(),this._config=e,this._injector=t,this._localeService=n,this._logService=r,this._config=a.Tools.deepMerge({},Ce,this._config),this._initDependencies(t),this._initializeCommands()}onRendered(){this._initModules(),this._markDocAsFocused()}_initializeCommands(){[ke,ze,Ge,Ye,Ke,Xe,qe,Ze,Je,At,Bt,Lt].forEach(e=>{this._injector.get(l.IShortcutService).registerShortcut(e)})}_initDependencies(e){[[w,{useFactory:()=>this._injector.createInstance(w,this._config)}],[Z],[J],[ee],[ie],[re],[oe],[se],[F,{useFactory:()=>this._injector.createInstance(F,this._config)}],[V,{useClass:_e}],[S.DocCanvasPopManagerService],[S.DocCanvasView]].forEach(n=>{e.add(n)})}_markDocAsFocused(){const e=this._injector.get(a.IUniverInstanceService),t=this._injector.get(l.IEditorService);try{const n=e.getCurrentUniverDocInstance();if(!n)return;const r=n.getUnitId();t.isEditor(r)||e.focusUnit(n.getUnitId())}catch(n){this._logService.warn(n)}}_initModules(){this._injector.get(F)}},T(le,"pluginName",Oe),T(le,"type",a.UniverInstanceType.UNIVER_DOC),le),S.UniverDocsUIPlugin=En([Se(1,v.Inject(v.Injector)),Se(2,v.Inject(a.LocaleService)),Se(3,a.ILogService)],S.UniverDocsUIPlugin);function Dn(i){return{left:i.positionH.posOffset,top:i.positionV.posOffset,width:i.size.width,height:i.size.height}}function Pn(i,e=0,t=0){return{size:{width:i.width,height:i.height},positionH:{relativeFrom:a.ObjectRelativeFromH.MARGIN,posOffset:(i.left||0)-e},positionV:{relativeFrom:a.ObjectRelativeFromV.PAGE,posOffset:(i.top||0)-t},angle:i.angle||0}}S.DOC_UI_PLUGIN_NAME=Oe,S.DefaultDocContainerConfig=Ie,S.DefaultDocUiConfig=Ce,S.DefaultToolbarConfig=ve,S.PastePluginLark=Ue,S.PastePluginUniver=Le,S.PastePluginWord=xe,S.docDrawingPositionToTransform=Dn,S.transformToDocDrawingPosition=Pn,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
|
|
9
|
+
*/var ot=je,st=Symbol.for("react.element"),at=Symbol.for("react.fragment"),ct=Object.prototype.hasOwnProperty,lt=ot.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,dt={key:!0,ref:!0,__self:!0,__source:!0};function Ee(i,e,t){var n,r={},o=null,s=null;t!==void 0&&(o=""+t),e.key!==void 0&&(o=""+e.key),e.ref!==void 0&&(s=e.ref);for(n in e)ct.call(e,n)&&!dt.hasOwnProperty(n)&&(r[n]=e[n]);if(i&&i.defaultProps)for(n in e=i.defaultProps,e)r[n]===void 0&&(r[n]=e[n]);return{$$typeof:st,type:i,key:o,ref:s,props:r,_owner:lt.current}}K.Fragment=at,K.jsx=Ee,K.jsxs=Ee,ye.exports=K;var ut=ye.exports;const ht={docsUiCanvasBackground:"univer-docs-ui-canvas-background"},pt=()=>ut.jsx("div",{className:ht.docsUiCanvasBackground});function _t(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatBoldCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.bl;t.next(u===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function gt(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatItalicCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.it;t.next(u===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function St(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatUnderlineCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.ul;t.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function ft(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatStrikethroughCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.st;t.next((u==null?void 0:u.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function mt(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatSubscriptCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.va;t.next(u===a.BaselineOffset.SUBSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function vt(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatSuperscriptCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.SetInlineFormatCommand.id){const c=E(i);if(c==null)return;const u=(s=c.ts)==null?void 0:s.va;t.next(u===a.BaselineOffset.SUPERSCRIPT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function It(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatFontFamilyCommand.id,tooltip:"toolbar.font",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,label:be,positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_FAMILY_LIST.map(t=>({label:{name:Me,hoverable:!0},value:t.value})),value$:new b.Observable(t=>{const n=l.FONT_FAMILY_LIST[0].value,r=e.onCommandExecuted(o=>{var c;const s=o.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontFamilyCommand.id){const u=E(i);if(u==null)return;const h=(c=u.ts)==null?void 0:c.ff;t.next(h!=null?h:n)}});return t.next(n),r.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Ct(i){const e=i.get(a.ICommandService);return{id:d.SetInlineFormatFontSizeCommand.id,group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Re,props:{min:1,max:400}},positions:[l.MenuPosition.TOOLBAR_START],selections:l.FONT_SIZE_LIST,value$:new b.Observable(t=>{const r=e.onCommandExecuted(o=>{var c;const s=o.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontSizeCommand.id){const u=E(i);if(u==null)return;const h=(c=u.ts)==null?void 0:c.fs;t.next(h!=null?h:14)}});return t.next(14),r.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Ot(i){const e=i.get(a.ICommandService),t=i.get(a.ThemeService);return{id:d.SetInlineFormatTextColorCommand.id,icon:"FontColor",tooltip:"toolbar.textColor.main",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON_SELECTOR,positions:[l.MenuPosition.TOOLBAR_START],selections:[{label:{name:ue,hoverable:!1}}],value$:new b.Observable(n=>{const r=t.getCurrentTheme().textColor,o=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextColorCommand.id){const c=s.params.value;n.next(c!=null?c:r)}});return n.next(r),o.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Tt(i){const e=i.get(a.ICommandService);return{id:d.AlignLeftCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=X(i);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.LEFT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function bt(i){const e=i.get(a.ICommandService);return{id:d.AlignCenterCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=X(i);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.CENTER)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Mt(i){const e=i.get(a.ICommandService);return{id:d.AlignRightCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=X(i);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.RIGHT)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Rt(i){const e=i.get(a.ICommandService);return{id:d.AlignJustifyCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",positions:[l.MenuPosition.TOOLBAR_START],activated$:new b.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const o=r.id;if(o===d.SetTextSelectionsOperation.id||o===d.AlignOperationCommand.id){const c=X(i);if(c==null)return;const u=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(u===a.HorizontalAlign.JUSTIFIED)}});return t.next(!1),n.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function yt(i){return{id:d.OrderListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"OrderSingle",tooltip:"toolbar.order",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Et(i){return{id:d.BulletListCommand.id,group:l.MenuGroup.TOOLBAR_LAYOUT,type:l.MenuItemType.BUTTON,icon:"UnorderSingle",tooltip:"toolbar.unorder",positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function Dt(i){return{id:d.ResetInlineFormatTextBackgroundColorCommand.id,type:l.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:d.SetInlineFormatTextBackgroundColorCommand.id}}function Pt(i){const e=i.get(a.ICommandService),t=i.get(a.ThemeService);return{id:d.SetInlineFormatTextBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",group:l.MenuGroup.TOOLBAR_FORMAT,type:l.MenuItemType.BUTTON_SELECTOR,positions:[l.MenuPosition.TOOLBAR_START],icon:"PaintBucket",selections:[{label:{name:ue,hoverable:!1}}],value$:new b.Observable(n=>{const r=t.getCurrentTheme().primaryColor,o=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextBackgroundColorCommand.id){const c=s.params.value;n.next(c!=null?c:r)}});return n.next(r),o.dispose}),hidden$:l.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_DOC)}}function E(i){var u;const e=i.get(a.IUniverInstanceService),t=i.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const o=(u=n.getBody())==null?void 0:u.textRuns;if(o==null)return;const{startOffset:s}=r;let c;for(let h=0;h<o.length;h++){const _=o[h],g=o[h+1];if(g&&g.st===g.ed&&s===g.st){c=g;break}if(_.st<=s&&s<=_.ed){c=_;break}}return c}function X(i){var u;const e=i.get(a.IUniverInstanceService),t=i.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const o=(u=n.getBody())==null?void 0:u.paragraphs;if(o==null)return;const{startOffset:s}=r;let c=-1;for(const h of o){const{startIndex:_}=h;if(s>c&&s<=_)return h;c=_}return null}var Ut=Object.defineProperty,Nt=Object.getOwnPropertyDescriptor,xt=(i,e,t,n)=>{for(var r=n>1?void 0:n?Nt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Ut(e,t,r),r},P=(i,e)=>(t,n)=>e(t,n,i);let F=class extends a.Disposable{constructor(i,e,t,n,r,o,s,c){super(),this._config=i,this._injector=e,this._componentManager=t,this._layoutService=n,this._editorService=r,this._menuService=o,this._uiPartsService=s,this._univerInstanceService=c,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(ue,We.ColorPicker)),this.disposeWithMe(i.register(be,l.FontFamily)),this.disposeWithMe(i.register(Me,l.FontFamilyItem)),this.disposeWithMe(i.register(Re,l.FontSize))}_initMenus(){const{menu:i={}}=this._config;[_t,gt,St,ft,mt,vt,Ct,It,Ot,Tt,bt,Mt,Rt,yt,Et,Dt,Pt].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e),i))})}_init(){this._initCustomComponents(),this._initMenus(),this._initDocBackground(),this._initFocusHandler()}_initDocBackground(){const i=this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC)[0].getUnitId();if(i==null)return;this._editorService.isEditor(i)||this.disposeWithMe(this._uiPartsService.registerComponent(l.BuiltInUIPart.CONTENT,()=>Ve.connectInjector(pt,this._injector)))}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.UNIVER_DOC,()=>{this._injector.get(m.ITextSelectionRenderManager).focus()}))}};F=xt([a.OnLifecycle(a.LifecycleStages.Rendered,F),P(1,I.Inject(I.Injector)),P(2,I.Inject(l.ComponentManager)),P(3,l.ILayoutService),P(4,l.IEditorService),P(5,l.IMenuService),P(6,l.IUIPartsService),P(7,a.IUniverInstanceService)],F);const Lt={id:d.BreakLineCommand.id,preconditions:He,binding:l.KeyCode.ENTER},At={id:d.DeleteLeftCommand.id,preconditions:y,binding:l.KeyCode.BACKSPACE},Bt={id:d.DeleteRightCommand.id,preconditions:y,binding:l.KeyCode.DELETE},wt=10,Ft=6;function $t(){return a.Tools.generateRandomId(Ft)}function Vt(i){const e=i.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class jt{constructor(){T(this,"_cache",new a.LRUMap(wt))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}clear(){this._cache.clear()}}const De=new jt;function he(i){const e=i.style,t={},n=i.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{t.bl=a.BooleanNumber.TRUE;break}case"s":{t.st={s:a.BooleanNumber.TRUE};break}case"u":{t.ul={s:a.BooleanNumber.TRUE};break}case"i":{t.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=n==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}for(let r=0;r<e.length;r++){const o=e[r],s=e.getPropertyValue(o);switch(o){case"font-family":{t.ff=s;break}case"font-size":{const c=Number.parseInt(s);Number.isNaN(c)||(s.endsWith("pt")?t.fs=c:s.endsWith("px")&&(t.fs=m.pixelToPt(c)));break}case"font-style":{s==="italic"&&(t.it=a.BooleanNumber.TRUE);break}case"font-weight":{Number(s)>400&&(t.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(s)?t.ul={s:a.BooleanNumber.TRUE}:/overline/.test(s)?t.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(s)&&(t.st={s:a.BooleanNumber.TRUE});break}case"color":{const c=new a.ColorKit(s);c.isValid&&(t.cl={rgb:c.toRgbString()});break}case"background-color":{const c=new a.ColorKit(s);c.isValid&&(t.bg={rgb:c.toRgbString()});break}}}return t}function Wt(i){const e=new DOMParser,t=`<x-univer id="univer-root">${i}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function Pe(i,e){const t=i.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(i)}const ce=class ce{constructor(){T(this,"_styleCache",new Map);T(this,"_styleRules",[]);T(this,"_afterProcessRules",[])}static use(e){if(this._pluginList.includes(e))throw new Error(`Univer paste plugin ${e.name} already added`);this._pluginList.push(e)}convert(e){const t=ce._pluginList.find(o=>o.checkPasteType(e)),n=Wt(e),r={dataStream:"",textRuns:[]};return t&&(this._styleRules=[...t.stylesRules],this._afterProcessRules=[...t.afterProcessRules]),this._styleCache.clear(),this._process(null,n==null?void 0:n.childNodes,r),this._styleCache.clear(),this._styleRules=[],this._afterProcessRules=[],r}_process(e,t,n){var r;for(const o of t)if(o.nodeType===Node.TEXT_NODE){const s=(r=o.nodeValue)==null?void 0:r.replace(/[\r\n]/g,"");let c;e&&this._styleCache.has(e)&&(c=this._styleCache.get(e)),n.dataStream+=s,c&&Object.getOwnPropertyNames(c).length&&n.textRuns.push({st:n.dataStream.length-s.length,ed:n.dataStream.length,ts:c})}else if(o.nodeType===Node.ELEMENT_NODE){const s=e?this._styleCache.get(e):{},c=this._styleRules.find(({filter:g})=>Pe(o,g)),u=c?c.getStyle(o):he(o);this._styleCache.set(o,{...s,...u});const{childNodes:h}=o;this._process(o,h,n);const _=this._afterProcessRules.find(({filter:g})=>Pe(o,g));_&&_.handler(n,o)}}};T(ce,"_pluginList",[]);let x=ce;const Ue={name:"univer-doc-paste-plugin-lark",checkPasteType(i){return/lark-record-clipboard/i.test(i)},stylesRules:[{filter:["s"],getStyle(i){const e=he(i);return{st:{s:a.BooleanNumber.TRUE},...e}}}],afterProcessRules:[{filter(i){return i.tagName==="DIV"&&/ace-line/i.test(i.className)},handler(i){i.paragraphs==null&&(i.paragraphs=[]),i.paragraphs.push({startIndex:i.dataStream.length}),i.dataStream+="\r"}}]};function Ne(i){const e=i.style,t={};for(let n=0;n<e.length;n++){const r=e[n],o=e.getPropertyValue(r);switch(r){case"margin-top":{const s=Number.parseInt(o);t.spaceAbove=/pt/.test(o)?m.ptToPixel(s):s;break}case"margin-bottom":{const s=Number.parseInt(o);t.spaceBelow=/pt/.test(o)?m.ptToPixel(s):s;break}case"line-height":{const s=Number.parseFloat(o);t.lineSpacing=s;break}}}return Object.getOwnPropertyNames(t).length?t:null}const xe={name:"univer-doc-paste-plugin-word",checkPasteType(i){return/word|mso/i.test(i)},stylesRules:[{filter:["b"],getStyle(i){const e=he(i);return{bl:a.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(i){return i.tagName==="P"&&/mso/i.test(i.className)},handler(i,e){i.paragraphs==null&&(i.paragraphs=[]);const t={startIndex:i.dataStream.length},n=Ne(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]},Le={name:"univer-doc-paste-plugin-univer",checkPasteType(i){return/UniverNormal/i.test(i)},stylesRules:[],afterProcessRules:[{filter(i){return i.tagName==="P"&&/UniverNormal/i.test(i.className)},handler(i,e){i.paragraphs==null&&(i.paragraphs=[]);const t={startIndex:i.dataStream.length},n=Ne(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]};function Ae(i,e){const{st:t,ed:n,ts:r={}}=e,{ff:o,fs:s,it:c,bl:u,ul:h,st:_,ol:g,bg:C,cl:f,va:v}=r;let p=i.slice(t,n);const O=[];return c===a.BooleanNumber.TRUE&&(p=`<i>${p}</i>`),v===a.BaselineOffset.SUPERSCRIPT?p=`<sup>${p}</sup>`:v===a.BaselineOffset.SUBSCRIPT&&(p=`<sub>${p}</sub>`),(h==null?void 0:h.s)===a.BooleanNumber.TRUE&&(p=`<u>${p}</u>`),(_==null?void 0:_.s)===a.BooleanNumber.TRUE&&(p=`<s>${p}</s>`),u===a.BooleanNumber.TRUE&&(p=`<strong>${p}</strong>`),o&&O.push(`font-family: ${o}`),f&&O.push(`color: ${f.rgb}`),s&&O.push(`font-size: ${s}pt`),g&&O.push("text-decoration: overline"),C&&O.push(`background: ${C.rgb}`),O.length?`<span style="${O.join("; ")};">${p}</span>`:p}function pe(i,e,t){const{dataStream:n,textRuns:r=[]}=i;let o=e;const s=[];for(const c of r){const{st:u,ed:h}=c;a.Tools.hasIntersectionBetweenTwoRanges(e,t,u,h)&&(u>o?(s.push(n.slice(o,u)),s.push(Ae(n,{...c,ed:Math.min(h,t)}))):s.push(Ae(n,{...c,st:o,ed:Math.min(h,t)}))),o=Math.max(e,Math.min(h,t))}return o!==t&&s.push(n.slice(o,t)),s.join("")}function Be(i,e=!0){var t;if(e&&((t=i.paragraphs)!=null&&t.length)){const{dataStream:n,paragraphs:r=[]}=i;let o="",s=-1;for(const c of r){const{startIndex:u,paragraphStyle:h={}}=c,{spaceAbove:_,spaceBelow:g,lineSpacing:C}=h,f=[];_!=null&&(typeof _=="number"?f.push(`margin-top: ${_}px`):f.push(`margin-top: ${_.v}px`)),g!=null&&(typeof g=="number"?f.push(`margin-bottom: ${g}px`):f.push(`margin-bottom: ${g.v}px`)),C!=null&&f.push(`line-height: ${C}`),u>s+1?o+=`<p class="UniverNormal" ${f.length?`style="${f.join("; ")};"`:""}>${pe(i,s+1,u)}</p>`:o+=`<p class="UniverNormal" ${f.length?`style="${f.join("; ")};"`:""}></p>`,s=u}return s!==n.length&&(o+=pe(i,s,n.length)),o}else return pe(i,0,i.dataStream.length)}class Ht{convert(e){if(e.length===0)throw new Error("The bodyList length at least to be 1");if(e.length===1)return Be(e[0]);let t="";for(const n of e)t+='<p className="UniverNormal">',t+=Be(n,!1),t+="</p>";return t}}var kt=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,Yt=(i,e,t,n)=>{for(var r=n>1?void 0:n?zt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&kt(e,t,r),r},$=(i,e)=>(t,n)=>e(t,n,i);x.use(xe),x.use(Ue),x.use(Le);function Gt(i){const e=i.replace(/\n/g,"\r"),t=[];for(let n=0;n<e.length;n++)e[n]==="\r"&&t.push({startIndex:n});return{dataStream:e,paragraphs:t}}const V=I.createIdentifier("doc.clipboard-service");let _e=class extends a.Disposable{constructor(e,t,n,r,o){super();T(this,"_clipboardHooks",[]);T(this,"_htmlToUDM",new x);T(this,"_umdToHtml",new Ht);this._univerInstanceService=e,this._logService=t,this._commandService=n,this._clipboardInterfaceService=r,this._textSelectionManagerService=o}async copy(){const e=this._getDocumentBodyInRanges();if(e.length===0)return!1;try{this._setClipboardData(e)}catch(t){return this._logService.error("[DocClipboardService] copy failed",t),!1}return!0}async cut(){return this._cut()}async paste(e){const t=await this._generateBodyFromClipboardItems(e);return this._paste(t)}async legacyPaste(e,t){const n=this._generateBodyFromHtmlAndText(e,t);return this._paste(n)}async _cut(){var o;const{segmentId:e,endOffset:t,style:n}=(o=this._textSelectionManagerService.getActiveRange())!=null?o:{},r=this._textSelectionManagerService.getSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),t==null||r==null)return!1;this.copy();try{let s=t;for(const u of r){const{startOffset:h,endOffset:_}=u;h==null||_==null||_<=t&&(s-=_-h)}const c=[{startOffset:s,endOffset:s,style:n}];return this._commandService.executeCommand(d.CutContentCommand.id,{segmentId:e,textRanges:c})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(e){var s;const{segmentId:t,endOffset:n,style:r}=(s=this._textSelectionManagerService.getActiveRange())!=null?s:{},o=this._textSelectionManagerService.getSelections();if(t==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),n==null||o==null)return!1;try{let c=n;for(const h of o){const{startOffset:_,endOffset:g}=h;_==null||g==null||g<=n&&(c+=e.dataStream.length-(g-_))}const u=[{startOffset:c,endOffset:c,style:r}];return this._commandService.executeCommand(d.InnerPasteCommand.id,{body:e,segmentId:t,textRanges:u})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(e){const t=$t(),n=e.length>1?e.map(o=>o.dataStream).join(`
|
|
10
|
+
`):e[0].dataStream;let r=this._umdToHtml.convert(e);return e.length===1&&(r=r.replace(/(<[a-z]+)/,(o,s)=>`${s} data-copy-id="${t}"`),De.set(t,e[0])),this._clipboardInterfaceService.write(n,r)}addClipboardHook(e){return this._clipboardHooks.push(e),a.toDisposable(()=>{const t=this._clipboardHooks.indexOf(e);t>-1&&this._clipboardHooks.splice(t,1)})}_getDocumentBodyInRanges(){const e=this._textSelectionManagerService.getSelections(),t=this._univerInstanceService.getCurrentUniverDocInstance(),n=[];if(e==null||!t)return n;for(const r of e){const{startOffset:o,endOffset:s,collapsed:c}=r;if(c||o==null||s==null)continue;const u=t.sliceBody(o,s);u!=null&&n.push(u)}return n}async _generateBodyFromClipboardItems(e){try{let t="",n="";for(const r of e)for(const o of r.types)o===l.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await r.getType(o).then(s=>s&&s.text()):o===l.HTML_CLIPBOARD_MIME_TYPE&&(t=await r.getType(o).then(s=>s&&s.text()));return this._generateBodyFromHtmlAndText(t,n)}catch(t){return Promise.reject(t)}}_generateBodyFromHtmlAndText(e,t){if(!e){if(t)return Gt(t);throw new Error("[DocClipboardService] html and text cannot be both empty!")}const n=Vt(e);if(n){const r=De.get(n);if(r)return r}return this._htmlToUDM.convert(e)}};_e=Yt([$(0,a.IUniverInstanceService),$(1,a.ILogService),$(2,a.ICommandService),$(3,l.IClipboardInterfaceService),$(4,I.Inject(d.TextSelectionManagerService))],_e);function q(i){return i.getContextValue(a.FOCUSING_DOC)||i.getContextValue(a.EDITOR_ACTIVATED)}const ge=999,Kt={id:l.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:ge,preconditions:q,handler:async i=>i.get(V).copy()},Xt={id:l.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:ge,preconditions:q,handler:async i=>i.get(V).cut()},qt={id:l.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:ge,preconditions:q,handler:async i=>{const e=i.get(V),n=await i.get(l.IClipboardInterfaceService).read();return n.length===0?!1:e.paste(n)}};var Zt=Object.defineProperty,Jt=Object.getOwnPropertyDescriptor,Qt=(i,e,t,n)=>{for(var r=n>1?void 0:n?Jt(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Zt(e,t,r),r},j=(i,e)=>(t,n)=>e(t,n,i);let Z=class extends a.RxDisposable{constructor(i,e,t,n,r){super(),this._commandService=i,this._clipboardInterfaceService=e,this._docClipboardService=t,this._textSelectionRenderManager=n,this._contextService=r,this._init()}_init(){[Kt,Xt,qt].forEach(i=>this.disposeWithMe(this._commandService.registerMultipleCommand(i))),[d.InnerPasteCommand,d.CutContentCommand].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i))),this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var i;(i=this._textSelectionRenderManager)==null||i.onPaste$.pipe(b.takeUntil(this.dispose$)).subscribe(e=>{var o,s;if(!q(this._contextService))return;e.event.preventDefault();const t=e.event,n=(o=t.clipboardData)==null?void 0:o.getData("text/html"),r=(s=t.clipboardData)==null?void 0:s.getData("text/plain");this._docClipboardService.legacyPaste(n,r)})}};Z=Qt([a.OnLifecycle(a.LifecycleStages.Rendered,Z),j(0,a.ICommandService),j(1,l.IClipboardInterfaceService),j(2,V),j(3,m.ITextSelectionRenderManager),j(4,a.IContextService)],Z);var en=Object.defineProperty,tn=Object.getOwnPropertyDescriptor,nn=(i,e,t,n)=>{for(var r=n>1?void 0:n?tn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&en(e,t,r),r},L=(i,e)=>(t,n)=>e(t,n,i);let J=class extends a.Disposable{constructor(e,t,n,r,o,s){super();T(this,"_initialEditors",new Set);this._univerInstanceService=e,this._docSkeletonManagerService=t,this._editorService=n,this._commandService=r,this._textSelectionRenderManager=o,this._renderManagerService=s,this._initialize()}_initialize(){this.disposeWithMe(this._editorService.resize$.subscribe(e=>{this._resize(e)})),this._editorService.getAllEditor().forEach(e=>{const t=e.editorUnitId;this._initialEditors.has(t)||(this._initialEditors.add(t),this._resize(t))}),this._commandExecutedListener(),this._initialSetValue(),this._initialBlur(),this._initialFocus(),this._initialValueChange()}_resize(e){var D,B,N;if(e==null)return;const t=this._editorService.getEditor(e);if((t==null?void 0:t.cancelDefaultResizeListener)===!0)return;const n=(D=this._docSkeletonManagerService.getSkeletonByUnitId(e))==null?void 0:D.skeleton,r=this._univerInstanceService.getUniverDocInstance(e);if(t==null||t.render==null||n==null||r==null)return;n.calculate();const{marginTop:o=0,marginBottom:s=0,marginLeft:c=0,marginRight:u=0}=r.getSnapshot().documentStyle,{scene:h,mainComponent:_}=t.render;let{actualHeight:g,actualWidth:C}=n.getActualSize();g+=o+s,C+=c+u;const{width:f,height:v}=t.getBoundingClientRect(),p=h.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);let O=p==null?void 0:p.getScrollBar();const M=Math.max(C,f),R=Math.max(g,v);h.transformByState({width:M,height:R}),_==null||_.resize(M,R),t.isSingle()?C>f?O==null?p&&new m.ScrollBar(p,{barSize:8,enableVertical:!1}):p==null||p.resetCanvasSizeAndUpdateScrollBar():(O=null,p==null||p.scrollTo({x:0,y:0}),(N=p==null?void 0:p.getScrollBar())==null||N.dispose()):g>v?O==null?p&&new m.ScrollBar(p,{enableHorizontal:!1,barSize:8}):p==null||p.resetCanvasSizeAndUpdateScrollBar():(O=null,p==null||p.scrollTo({x:0,y:0}),(B=p==null?void 0:p.getScrollBar())==null||B.dispose())}_initialSetValue(){this.disposeWithMe(this._editorService.setValue$.subscribe(e=>{this._commandService.executeCommand(d.CoverContentCommand.id,{unitId:e.editorUnitId,body:e.body,segmentId:null})}))}_initialBlur(){this.disposeWithMe(this._editorService.blur$.subscribe(()=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.blur()})),this.disposeWithMe(this._textSelectionRenderManager.onBlur$.subscribe(()=>{var r;const e=(r=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:r.getUnitId();if(e==null)return;const t=this._editorService.getEditor(e),n=this._editorService.getFocusEditor();t==null||t.isSheetEditor()||n&&n.editorUnitId===e||this._editorService.blur()}))}_initialFocus(){this.disposeWithMe(this._editorService.focus$.subscribe(n=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges([n])}));const e=["univer-formula-search","univer-formula-help","formula-help-decorator","univer-formula-help-param"];this.disposeWithMe(b.fromEvent(window,"mousedown").subscribe(n=>{const o=n.target.classList[0]||"";if(a.checkForSubstrings(o,e)){this._editorService.changeSpreadsheetFocusState(!0),n.stopPropagation();return}this._editorService.changeSpreadsheetFocusState(!1)})),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(n=>{const r=n.getUnitId(),o=this._renderManagerService.getRenderById(r),s=o==null?void 0:o.engine.getCanvas().getCanvasEle();s!=null&&b.fromEvent(s,"mousedown").subscribe(c=>{this._editorService.changeSpreadsheetFocusState(!0),c.stopPropagation()})})}_initialValueChange(){this.disposeWithMe(this._textSelectionRenderManager.onCompositionupdate$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onInput$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onKeydown$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onPaste$.subscribe(this._valueChange.bind(this)))}_valueChange(){var n;const e=(n=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:n.getUnitId();if(e==null)return;const t=this._editorService.getEditor(e);t==null||t.isSheetEditor()||this._editorService.refreshValueChange(e)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,l.SetEditorResizeOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=t.params,{unitId:r}=n;if(this._editorService.isSheetEditor(r))return;this._resize(r),this._valueChange()}}))}};J=nn([a.OnLifecycle(a.LifecycleStages.Rendered,J),L(0,a.IUniverInstanceService),L(1,I.Inject(d.DocSkeletonManagerService)),L(2,l.IEditorService),L(3,a.ICommandService),L(4,m.ITextSelectionRenderManager),L(5,m.IRenderManagerService)],J);var rn=Object.defineProperty,on=Object.getOwnPropertyDescriptor,sn=(i,e,t,n)=>{for(var r=n>1?void 0:n?on(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&rn(e,t,r),r},Q=(i,e)=>(t,n)=>e(t,n,i);let ee=class extends a.RxDisposable{constructor(e,t,n,r){super();T(this,"_docRenderMap",new Set);this._docSkeletonManagerService=e,this._renderManagerService=t,this._commandService=n,this._editorService=r,this._initialRenderRefresh(),this._commandExecutedListener()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(b.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)})}_create(e){if(e==null)return;const{skeleton:t,unitId:n}=e;let r=this._renderManagerService.getRenderById(n);r==null&&(this._renderManagerService.create(n),r=this._renderManagerService.getRenderById(n));const{mainComponent:o,components:s}=r,c=o,u=s.get(d.DOCS_VIEW_KEY.BACKGROUND);c.changeSkeleton(t),u.changeSkeleton(t),this._recalculateSizeBySkeleton(r,t)}_recalculateSizeBySkeleton(e,t){var C;const{mainComponent:n,scene:r,unitId:o,components:s}=e,c=n,u=s.get(d.DOCS_VIEW_KEY.BACKGROUND),h=(C=t.getSkeletonData())==null?void 0:C.pages;if(h==null)return;let _=0,g=0;for(let f=0,v=h.length;f<v;f++){const p=h[f],{pageWidth:O,pageHeight:M}=p;c.pageLayoutType===m.PageLayoutType.VERTICAL?(g+=M,g+=c.pageMarginTop,f===v-1&&(g+=c.pageMarginTop),_=Math.max(_,O)):c.pageLayoutType===m.PageLayoutType.HORIZONTAL&&(_+=O,f!==v-1&&(_+=c.pageMarginLeft),g=Math.max(g,M))}c.resize(_,g),u.resize(_,g),this._editorService.isEditor(o)||r.resize(_,g)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=this._docSkeletonManagerService.getSkeletonByUnitId(o);if(s==null)return;const{skeleton:c}=s,u=this._renderManagerService.getRenderById(o);if(u==null||!!c.getViewModel().getDataModel().getSnapshot().disabled)return;if(c.calculate(),this._editorService.isEditor(o)){(n=u.mainComponent)==null||n.makeDirty();return}this._recalculateSizeBySkeleton(u,c)}}))}};ee=sn([a.OnLifecycle(a.LifecycleStages.Rendered,ee),Q(0,I.Inject(d.DocSkeletonManagerService)),Q(1,m.IRenderManagerService),Q(2,a.ICommandService),Q(3,l.IEditorService)],ee);var an=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,ln=(i,e,t,n)=>{for(var r=n>1?void 0:n?cn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&an(e,t,r),r},te=(i,e)=>(t,n)=>e(t,n,i);S.DocCanvasView=class extends a.RxDisposable{constructor(t,n,r,o){super();T(this,"_scene");T(this,"_currentDocumentModel");T(this,"_fps$",new b.BehaviorSubject(""));T(this,"fps$",this._fps$.asObservable());this._renderManagerService=t,this._configService=n,this._univerInstanceService=r,this._editorService=o,this._initialize()}_initialize(){this._renderManagerService.createRender$.pipe(b.takeUntil(this.dispose$)).subscribe(t=>{this._create(t)}),this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC).pipe(b.takeUntil(this.dispose$)).subscribe(t=>{this._create(t==null?void 0:t.getUnitId())}),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC).forEach(t=>{this._create(t.getUnitId())})}dispose(){this._fps$.complete()}_create(t){if(t==null)return;const n=this._univerInstanceService.getUniverDocInstance(t);n!=null&&(this._currentDocumentModel=n,this._renderManagerService.has(t)||this._addNewRender())}_addNewRender(){const n=this._currentDocumentModel.getUnitId();this._renderManagerService.createRender(n);const r=this._renderManagerService.getRenderById(n);if(r==null)return;const{scene:o,engine:s}=r;this._scene=o;const c=new m.Viewport(d.VIEWPORT_KEY.VIEW_MAIN,o,{left:0,top:0,bottom:0,right:0,isRelativeX:!0,isRelativeY:!0,isWheelPreventDefaultX:!0});o.attachControl(),o.on(m.EVENT_TYPE.wheel,(_,g)=>{const C=_;if(C.ctrlKey){const f=Math.abs(C.deltaX);let v=f<40?.2:f<80?.4:.2;v*=C.deltaY>0?-1:1,o.scaleX<1&&(v/=2),o.scaleX+v>4?o.scale(4,4):o.scaleX+v<.1?o.scale(.1,.1):C.preventDefault()}else c.onMouseWheel(C,g)}),this._configService.getConfig("hasScroll")!==!1&&new m.ScrollBar(c),o.addLayer(new m.Layer(o,[],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),new m.Layer(o,[],d.DOCS_COMPONENT_HEADER_LAYER_INDEX)),this._addComponent(r),this._currentDocumentModel.getShouldRenderLoopImmediately()&&s.runRenderLoop(()=>{o.render(),this._fps$.next(Math.round(s.getFps()).toString())}),this._renderManagerService.setCurrent(n)}_addComponent(t){const n=this._scene,r=this._currentDocumentModel,o={pageMarginLeft:r.documentStyle.marginLeft||0,pageMarginTop:r.documentStyle.marginTop||0},s=new m.Documents(d.DOCS_VIEW_KEY.MAIN,void 0,o),c=new m.DocBackground(d.DOCS_VIEW_KEY.BACKGROUND,void 0,o);s.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX,c.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX,t.mainComponent=s,t.components.set(d.DOCS_VIEW_KEY.MAIN,s),t.components.set(d.DOCS_VIEW_KEY.BACKGROUND,c),n.addObjects([s],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),n.addObjects([c],d.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX),this._editorService.getEditor(r.getUnitId())==null&&n.enableLayerCache(d.DOCS_COMPONENT_MAIN_LAYER_INDEX)}},S.DocCanvasView=ln([a.OnLifecycle(a.LifecycleStages.Starting,S.DocCanvasView),te(0,m.IRenderManagerService),te(1,a.IConfigService),te(2,a.IUniverInstanceService),te(3,l.IEditorService)],S.DocCanvasView);var dn=Object.defineProperty,un=Object.getOwnPropertyDescriptor,hn=(i,e,t,n)=>{for(var r=n>1?void 0:n?un(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&dn(e,t,r),r},ne=(i,e)=>(t,n)=>e(t,n,i);let ie=class extends a.Disposable{constructor(e,t,n,r){super();T(this,"_liquid",new m.Liquid);T(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=e,this._renderManagerService=t,this._commandService=n,this._editorService=r,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh(),this._updateOnPluginChange()}_updateOnPluginChange(){}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{skeleton:t,unitId:n}=e,r=this._renderManagerService.getRenderById(n);if(r==null)return;const{mainComponent:o}=r;o.changeSkeleton(t),this._refreshDrawing(n,t,r)})}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=this._docSkeletonManagerService.getCurrent();if(s==null)return;const{unitId:c,skeleton:u}=s;if(o!==c)return;const h=this._renderManagerService.getRenderById(c);if(h==null)return;if(this._editorService.isEditor(c)){(n=h.mainComponent)==null||n.makeDirty();return}this._refreshDrawing(c,u,h)}}))}_refreshDrawing(e,t,n){const r=t==null?void 0:t.getSkeletonData(),{mainComponent:o,scene:s}=n,c=o;if(!r)return;const{left:u,top:h,pageLayoutType:_,pageMarginLeft:g,pageMarginTop:C}=c,{pages:f}=r,v=[];s.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let p=0,O=f.length;p<O;p++){const M=f[p],{skeDrawings:R,marginLeft:D,marginTop:B}=M;this._liquid.translatePagePadding(M),R.forEach(N=>{const{aLeft:H,aTop:k,height:fe,width:me,drawingId:z,drawingOrigin:$e}=N,Un=$e.layoutType===a.PositionedObjectLayoutType.WRAP_NONE&&$e.behindDoc===a.BooleanNumber.TRUE;v.push({unitId:e,subUnitId:a.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:z,behindText:Un,floatingObject:{left:H+u+this._liquid.x,top:k+h+this._liquid.y,width:me,height:fe}}),this._pageMarginCache.set(z,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.restorePagePadding(M),this._liquid.translatePage(M,_,g,C)}}};ie=hn([a.OnLifecycle(a.LifecycleStages.Steady,ie),ne(0,I.Inject(d.DocSkeletonManagerService)),ne(1,m.IRenderManagerService),ne(2,a.ICommandService),ne(3,l.IEditorService)],ie);var pn=Object.defineProperty,_n=Object.getOwnPropertyDescriptor,gn=(i,e,t,n)=>{for(var r=n>1?void 0:n?_n(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&pn(e,t,r),r},A=(i,e)=>(t,n)=>e(t,n,i);let re=class extends a.Disposable{constructor(e,t,n,r,o,s){super();T(this,"_initializedRender",new Set);this._docSkeletonManagerService=e,this._univerInstanceService=t,this._commandService=n,this._renderManagerService=r,this._textSelectionManagerService=o,this._editorService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._initialRenderRefresh()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t}=e,n=this._renderManagerService.getRenderById(t);if(n==null||this._initializedRender.has(t)||this._editorService.isEditor(t))return;this._initializedRender.add(t);const{scene:r}=n;this.disposeWithMe(a.toDisposable(r.onMouseWheelObserver.add(o=>{if(!o.ctrlKey)return;const s=this._univerInstanceService.getCurrentUniverDocInstance();if(!s)return;const c=Math.abs(o.deltaX);let u=c<40?.2:c<80?.4:.2;u*=o.deltaY>0?-1:1,r.scaleX<1&&(u/=2);const h=s.zoomRatio;let _=+Number.parseFloat(`${h+u}`).toFixed(1);_=_>=4?4:_<=.1?.1:_,this._commandService.executeCommand(d.SetDocZoomRatioCommand.id,{zoomRatio:_,unitId:s.getUnitId()}),o.preventDefault()})))})}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const t=this._univerInstanceService.getCurrentUniverDocInstance();if(!t)return;const n=t.zoomRatio||1;this._updateViewZoom(n,!1)})))}_commandExecutedListener(){const e=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=this._univerInstanceService.getCurrentUniverDocInstance();if(!n)return;const r=t.params,{unitId:o}=r;if(o!==n.getUnitId())return;const s=n.zoomRatio||1;this._updateViewZoom(s)}}))}_updateViewZoom(e,t=!0){var r;const n=this._getDocObject();n!=null&&(n.scene.scale(e,e),this._calculatePagePosition(n,e),t&&this._textSelectionManagerService.refreshSelection(),(r=n.scene.getTransformer())==null||r.clearSelectedObjects())}_calculatePagePosition(e,t){const{document:n,scene:r,docBackground:o}=e,s=r==null?void 0:r.getParent(),{width:c,height:u,pageMarginLeft:h,pageMarginTop:_}=n;if(s==null||c===Number.POSITIVE_INFINITY||u===Number.POSITIVE_INFINITY)return;const{width:g,height:C}=s;let f=0,v=0,p=0,O=0,M=Number.POSITIVE_INFINITY;g>(c+h*2)*t?(f=g/2-c*t/2,f/=t,p=(g-h*2)/t,M=0):(f=h,p=c+h*2,M=(p-g/t)/2),C>u?(v=C/2-u/2,O=(C-_*2)/t):(v=_,O=u+_*2),r.resize(p,O+200),n.translate(f,v),o.translate(f,v);const R=r.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(M!==Number.POSITIVE_INFINITY&&R!=null){const D=R.transViewportScroll2ScrollValue(M,0).x;R.scrollTo({x:D})}return this}_getDocObject(){return d.getDocObject(this._univerInstanceService,this._renderManagerService)}};re=gn([a.OnLifecycle(a.LifecycleStages.Rendered,re),A(0,I.Inject(d.DocSkeletonManagerService)),A(1,a.IUniverInstanceService),A(2,a.ICommandService),A(3,m.IRenderManagerService),A(4,I.Inject(d.TextSelectionManagerService)),A(5,l.IEditorService)],re);var Sn=Object.defineProperty,fn=Object.getOwnPropertyDescriptor,mn=(i,e,t,n)=>{for(var r=n>1?void 0:n?fn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Sn(e,t,r),r},U=(i,e)=>(t,n)=>e(t,n,i);let oe=class extends a.Disposable{constructor(e,t,n,r,o,s,c){super();T(this,"_loadedMap",new WeakSet);this._docSkeletonManagerService=e,this._univerInstanceService=t,this._commandService=n,this._renderManagerService=r,this._textSelectionRenderManager=o,this._textSelectionManagerService=s,this._editorService=c,this._initialize()}_initialize(){this._init(),this._skeletonListener(),this._commandExecutedListener()}_init(){this.disposeWithMe(this._renderManagerService.currentRender$.subscribe(e=>{this._create(e)})),this._renderManagerService.getRenderAll().forEach((e,t)=>{this._create(t)})}_create(e){if(e==null||this._univerInstanceService.getUniverDocInstance(e)==null)return;const t=this._getDocObjectById(e);t==null||t.document==null||this._loadedMap.has(t.document)||(this._initialMain(e),this._loadedMap.add(t.document))}_initialMain(e){const t=this._getDocObjectById(e);if(t==null)return;const{document:n,scene:r}=t;this.disposeWithMe(a.toDisposable(n.onPointerEnterObserver.add(()=>{this._isEditorReadOnly(e)||(n.cursor=m.CURSOR_TYPE.TEXT)}))),this.disposeWithMe(a.toDisposable(n.onPointerLeaveObserver.add(()=>{n.cursor=m.CURSOR_TYPE.DEFAULT,r.resetCursor()}))),this.disposeWithMe(a.toDisposable(n==null?void 0:n.onPointerDownObserver.add((o,s)=>{if(this._isEditorReadOnly(e))return;const c=this._univerInstanceService.getCurrentUniverDocInstance();(c==null?void 0:c.getUnitId())!==e&&this._univerInstanceService.setCurrentUnitForType(e),this._textSelectionRenderManager.eventTrigger(o);const{offsetX:u,offsetY:h}=o;this._editorService.getEditor(e)&&(this._setEditorFocus(e),setTimeout(()=>{this._setEditorFocus(e),this._textSelectionRenderManager.setCursorManually(u,h)},0)),o.button!==2&&s.stopPropagation()}))),this.disposeWithMe(a.toDisposable(n==null?void 0:n.onDblclickObserver.add(o=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleDblClick(o)}))),this.disposeWithMe(a.toDisposable(n==null?void 0:n.onTripleClickObserver.add(o=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleTripleClick(o)})))}_isEditorReadOnly(e){const t=this._editorService.getEditor(e);return t?t.isReadOnly():!1}_setEditorFocus(e){if(this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).length>0){const n=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);this._editorService.setOperationSheetUnitId(n.getUnitId())}this._editorService.focusStyle(e)}_commandExecutedListener(){const e=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:o}=r,s=(n=this._textSelectionManagerService.getCurrentSelection())==null?void 0:n.unitId;if(o!==s)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t,skeleton:n}=e,r=this._renderManagerService.getRenderById(t);if(r==null)return;const{scene:o,mainComponent:s}=r;this._textSelectionRenderManager.changeRuntime(n,o,s),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:t,subUnitId:""}),this._editorService.isEditor(t)||this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}],!1)}))}_getDocObjectById(e){return this._univerInstanceService.getUnitType(e)!==a.UniverInstanceType.UNIVER_DOC?null:d.getDocObjectById(e,this._renderManagerService)}};oe=mn([a.OnLifecycle(a.LifecycleStages.Rendered,oe),U(0,I.Inject(d.DocSkeletonManagerService)),U(1,a.IUniverInstanceService),U(2,a.ICommandService),U(3,m.IRenderManagerService),U(4,m.ITextSelectionRenderManager),U(5,I.Inject(d.TextSelectionManagerService)),U(6,l.IEditorService)],oe);var vn=Object.defineProperty,In=Object.getOwnPropertyDescriptor,Cn=(i,e,t,n)=>{for(var r=n>1?void 0:n?In(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&vn(e,t,r),r},W=(i,e)=>(t,n)=>e(t,n,i);const we=1.5;let se=class extends a.RxDisposable{constructor(i,e,t,n,r){super(),this._docSkeletonManagerService=i,this._textSelectionManagerService=e,this._editorService=t,this._univerInstanceService=n,this._renderManagerService=r,this._init()}_init(){this._textSelectionManagerService.textSelection$.pipe(b.takeUntil(this.dispose$)).subscribe(i=>{if(i==null)return;const{isEditing:e,unitId:t}=i;e&&this._scrollToSelection(t)})}_scrollToSelection(i){var z;const e=this._textSelectionManagerService.getActiveRange(),t=this._getDocObject(),n=(z=this._docSkeletonManagerService.getCurrent())==null?void 0:z.skeleton;if(e==null||t==null||n==null)return;const{collapsed:r,startNodePosition:o}=e;if(!r)return;const s=t.document.getOffsetConfig(),{docsLeft:c,docsTop:u}=s,h=new m.NodePositionConvertToCursor(s,n),{contentBoxPointGroup:_}=h.getRangePointData(o,o),{left:g,top:C,height:f}=m.getAnchorBounding(_),v=g+c,p=C+u,O=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN),M=!!this._editorService.getEditor(i);if(O==null)return;const{left:R,top:D,right:B,bottom:N}=O.getBounding().viewBound;let H=0,k=0;const fe=M?0:100;p<D?H=p-D:p>N-f&&(H=p-N+f+fe),v<R?k=v-R:v>B-we&&(k=v-B+we);const me=O.transViewportScroll2ScrollValue(k,H);O.scrollBy(me)}_getDocObject(){return d.getDocObject(this._univerInstanceService,this._renderManagerService)}};se=Cn([a.OnLifecycle(a.LifecycleStages.Rendered,se),W(0,I.Inject(d.DocSkeletonManagerService)),W(1,I.Inject(d.TextSelectionManagerService)),W(2,l.IEditorService),W(3,a.IUniverInstanceService),W(4,m.IRenderManagerService)],se);var On=Object.defineProperty,Tn=Object.getOwnPropertyDescriptor,bn=(i,e,t,n)=>{for(var r=n>1?void 0:n?Tn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&On(e,t,r),r},ae=(i,e)=>(t,n)=>e(t,n,i);function Mn(i,e){const t=Fe(i.left,i.top,e),n=Fe(i.right,i.bottom,e);return{left:t.x,top:t.y,right:n.x,bottom:n.y}}function Fe(i,e,t){const{scaleX:n,scaleY:r}=t.getAncestorScale(),o=t.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(!o)return{x:i,y:e};const{viewportScrollX:s,viewportScrollY:c}=o,u=(i-s)*n,h=(e-c)*r;return{x:u,y:h}}S.DocCanvasPopManagerService=class extends a.Disposable{constructor(e,t,n,r){super(),this._globalPopupManagerService=e,this._renderManagerService=t,this._univerInstanceService=n,this._commandService=r}_createObjectPositionObserver(e,t){const n=()=>{const{scene:u}=t,{left:h,top:_,width:g,height:C}=e,f={left:h,right:h+g,top:_,bottom:_+C},v=Mn(f,u);return{left:v.left,right:v.right,top:v.top,bottom:v.bottom}},r=n(),o=new b.BehaviorSubject(r),s=new a.DisposableCollection;s.add(this._commandService.onCommandExecuted(u=>{u.id===d.SetDocZoomRatioOperation.id&&o.next(n())}));const c=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);return s.add(c==null?void 0:c.onScrollAfterObserver.add(()=>{o.next(n())})),{position:r,position$:o,disposable:s}}attachPopupToObject(e,t){const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC).getUnitId(),o=this._renderManagerService.getRenderById(r);if(!o)return{dispose:()=>{}};const{position:s,position$:c,disposable:u}=this._createObjectPositionObserver(e,o),h=this._globalPopupManagerService.addPopup({...t,unitId:r,subUnitId:"default",anchorRect:s,anchorRect$:c});return{dispose:()=>{this._globalPopupManagerService.removePopup(h),c.complete(),u.dispose()}}}},S.DocCanvasPopManagerService=bn([ae(0,I.Inject(l.ICanvasPopupService)),ae(1,m.IRenderManagerService),ae(2,a.IUniverInstanceService),ae(3,a.ICommandService)],S.DocCanvasPopManagerService);var Rn=Object.defineProperty,yn=Object.getOwnPropertyDescriptor,En=(i,e,t,n)=>{for(var r=n>1?void 0:n?yn(e,t):e,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Rn(e,t,r),r},Se=(i,e)=>(t,n)=>e(t,n,i);S.UniverDocsUIPlugin=(le=class extends a.Plugin{constructor(e,t,n,r){super(),this._config=e,this._injector=t,this._localeService=n,this._logService=r,this._config=a.Tools.deepMerge({},Ce,this._config),this._initDependencies(t),this._initializeCommands()}onRendered(){this._initModules(),this._markDocAsFocused()}_initializeCommands(){[ke,ze,Ge,Ye,Ke,Xe,qe,Ze,Je,At,Bt,Lt].forEach(e=>{this._injector.get(l.IShortcutService).registerShortcut(e)})}_initDependencies(e){[[F,{useFactory:()=>this._injector.createInstance(F,this._config)}],[Z],[J],[ee],[ie],[re],[oe],[se],[w,{useFactory:()=>this._injector.createInstance(w,this._config)}],[V,{useClass:_e}],[S.DocCanvasPopManagerService],[S.DocCanvasView]].forEach(n=>{e.add(n)})}_markDocAsFocused(){const e=this._injector.get(a.IUniverInstanceService),t=this._injector.get(l.IEditorService);try{const n=e.getCurrentUniverDocInstance();if(!n)return;const r=n.getUnitId();t.isEditor(r)||e.focusUnit(n.getUnitId())}catch(n){this._logService.warn(n)}}_initModules(){this._injector.get(w)}},T(le,"pluginName",Oe),T(le,"type",a.UniverInstanceType.UNIVER_DOC),le),S.UniverDocsUIPlugin=En([Se(1,I.Inject(I.Injector)),Se(2,I.Inject(a.LocaleService)),Se(3,a.ILogService)],S.UniverDocsUIPlugin);function Dn(i){return{left:i.positionH.posOffset,top:i.positionV.posOffset,width:i.size.width,height:i.size.height}}function Pn(i,e=0,t=0){return{size:{width:i.width,height:i.height},positionH:{relativeFrom:a.ObjectRelativeFromH.MARGIN,posOffset:(i.left||0)-e},positionV:{relativeFrom:a.ObjectRelativeFromV.PAGE,posOffset:(i.top||0)-t},angle:i.angle||0}}S.DOC_UI_PLUGIN_NAME=Oe,S.DefaultDocContainerConfig=Ie,S.DefaultDocUiConfig=Ce,S.DefaultToolbarConfig=ve,S.PastePluginLark=Ue,S.PastePluginUniver=Le,S.PastePluginWord=xe,S.docDrawingPositionToTransform=Dn,S.transformToDocDrawingPosition=Pn,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs-ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer normal ui-plugin-docs",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -50,30 +50,30 @@
|
|
|
50
50
|
"lib"
|
|
51
51
|
],
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@wendellhu/redi": "0.15.
|
|
53
|
+
"@wendellhu/redi": "0.15.4",
|
|
54
54
|
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
|
|
55
55
|
"rxjs": ">=7.0.0",
|
|
56
|
-
"@univerjs/
|
|
57
|
-
"@univerjs/
|
|
58
|
-
"@univerjs/
|
|
59
|
-
"@univerjs/
|
|
60
|
-
"@univerjs/
|
|
56
|
+
"@univerjs/core": "0.1.16",
|
|
57
|
+
"@univerjs/design": "0.1.16",
|
|
58
|
+
"@univerjs/docs": "0.1.16",
|
|
59
|
+
"@univerjs/engine-render": "0.1.16",
|
|
60
|
+
"@univerjs/ui": "0.1.16"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/react": "^18.3.3",
|
|
64
|
-
"@wendellhu/redi": "0.15.
|
|
64
|
+
"@wendellhu/redi": "0.15.4",
|
|
65
65
|
"less": "^4.2.0",
|
|
66
66
|
"react": "18.3.1",
|
|
67
67
|
"rxjs": "^7.8.1",
|
|
68
68
|
"typescript": "^5.4.5",
|
|
69
|
-
"vite": "^5.
|
|
69
|
+
"vite": "^5.3.1",
|
|
70
70
|
"vitest": "^1.6.0",
|
|
71
|
-
"@univerjs/design": "0.1.
|
|
72
|
-
"@univerjs/core": "0.1.
|
|
73
|
-
"@univerjs/engine-render": "0.1.
|
|
74
|
-
"@univerjs/shared": "0.1.
|
|
75
|
-
"@univerjs/
|
|
76
|
-
"@univerjs/
|
|
71
|
+
"@univerjs/design": "0.1.16",
|
|
72
|
+
"@univerjs/core": "0.1.16",
|
|
73
|
+
"@univerjs/engine-render": "0.1.16",
|
|
74
|
+
"@univerjs/shared": "0.1.16",
|
|
75
|
+
"@univerjs/ui": "0.1.16",
|
|
76
|
+
"@univerjs/docs": "0.1.16"
|
|
77
77
|
},
|
|
78
78
|
"univerSpace": {
|
|
79
79
|
".": {
|
|
@@ -94,6 +94,7 @@
|
|
|
94
94
|
"test:watch": "vitest",
|
|
95
95
|
"coverage": "vitest run --coverage",
|
|
96
96
|
"lint:types": "tsc --noEmit",
|
|
97
|
-
"build": "tsc && vite build"
|
|
97
|
+
"build": "tsc && vite build",
|
|
98
|
+
"sync:cnpm": "cnpm sync"
|
|
98
99
|
}
|
|
99
100
|
}
|