@univerjs/docs-ui 0.1.5 → 0.1.6

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