@univerjs/docs-ui 0.1.0-beta.5 → 0.1.1

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