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