@univerjs/docs-ui 0.2.4-alpha.0 → 0.2.4

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,5 +1,5 @@
1
- "use strict";var ot=Object.defineProperty;var rt=(o,e,t)=>e in o?ot(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var R=(o,e,t)=>rt(o,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),g=require("@univerjs/ui"),d=require("@univerjs/docs"),I=require("@univerjs/engine-render"),T=require("rxjs"),X=require("react"),H=require("@univerjs/design"),it=require("clsx");function U(o){return o.getContextValue(a.FOCUSING_DOC)&&o.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!o.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function st(o){return o.getContextValue(a.FOCUSING_DOC)&&o.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!o.getContextValue(a.FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE)&&!o.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}const at=10,ct=6;function lt(){return a.Tools.generateRandomId(ct)}function dt(o){const e=o.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class ut{constructor(){R(this,"_cache",new a.LRUMap(at))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}clear(){this._cache.clear()}}const Te=new ut;function ve(o){const e=o.style,t={},n=o.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 i=e[r],s=e.getPropertyValue(i);switch(i){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=I.pixelToPt(c)));break}case"font-style":{s==="italic"&&(t.it=a.BooleanNumber.TRUE);break}case"font-weight":{(Number(s)>400||String(s)==="bold")&&(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(o){const e=new DOMParser,t=`<x-univer id="univer-root">${o}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function Re(o,e){const t=o.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(o)}const ie=class ie{constructor(){R(this,"_styleCache",new Map);R(this,"_styleRules",[]);R(this,"_afterProcessRules",[])}static use(e){if(this._pluginList.includes(e))throw new Error(`Univer paste plugin ${e.name} already added`);this._pluginList.push(e)}convert(e){const t=ie._pluginList.find(i=>i.checkPasteType(e)),n=gt(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,i,s;for(const c of t)if(c.nodeType===Node.TEXT_NODE){if(((r=c.nodeValue)==null?void 0:r.trim())==="")continue;let l=(i=c.nodeValue)==null?void 0:i.replace(/[\r\n]/g,""),h;if(e&&e.nodeType===Node.ELEMENT_NODE&&e.tagName.toUpperCase()==="A"){const m=a.Tools.generateRandomId();l=`${a.DataStreamTreeTokenType.CUSTOM_RANGE_START}${l}${a.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,n.customRanges=[...(s=n.customRanges)!=null?s:[],{startIndex:n.dataStream.length,endIndex:n.dataStream.length+l.length-1,rangeId:m,rangeType:a.CustomRangeType.HYPERLINK}],n.payloads={...n.payloads,[m]:e.href}}e&&this._styleCache.has(e)&&(h=this._styleCache.get(e)),n.dataStream+=l,h&&Object.getOwnPropertyNames(h).length&&n.textRuns.push({st:n.dataStream.length-l.length,ed:n.dataStream.length,ts:h})}else{if(a.skipParseTagNames.includes(c.nodeName.toLowerCase()))continue;if(c.nodeType===Node.ELEMENT_NODE){const l=e?this._styleCache.get(e):{},h=this._styleRules.find(({filter:u})=>Re(c,u)),m=h?h.getStyle(c):ve(c);this._styleCache.set(c,{...l,...m});const{childNodes:_}=c;this._process(c,_,n);const f=this._afterProcessRules.find(({filter:u})=>Re(c,u));f&&f.handler(n,c)}}}};R(ie,"_pluginList",[]);let V=ie;const ht={name:"univer-doc-paste-plugin-lark",checkPasteType(o){return/lark-record-clipboard/i.test(o)},stylesRules:[{filter:["s"],getStyle(o){const e=ve(o);return{st:{s:a.BooleanNumber.TRUE},...e}}}],afterProcessRules:[{filter(o){return o.tagName==="DIV"&&/ace-line/i.test(o.className)},handler(o){o.paragraphs==null&&(o.paragraphs=[]),o.paragraphs.push({startIndex:o.dataStream.length}),o.dataStream+="\r"}}]},we=ht;function $e(o){const e=o.style,t={};for(let n=0;n<e.length;n++){const r=e[n],i=e.getPropertyValue(r);switch(r){case"margin-top":{const s=Number.parseInt(i);t.spaceAbove={v:/pt/.test(i)?I.ptToPixel(s):s};break}case"margin-bottom":{const s=Number.parseInt(i);t.spaceBelow={v:/pt/.test(i)?I.ptToPixel(s):s};break}case"line-height":{const s=Number.parseFloat(i);t.lineSpacing=s;break}}}return Object.getOwnPropertyNames(t).length?t:null}const pt={name:"univer-doc-paste-plugin-word",checkPasteType(o){return/word|mso/i.test(o)},stylesRules:[{filter:["b"],getStyle(o){const e=ve(o);return{bl:a.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(o){return o.tagName==="P"},handler(o,e){o.paragraphs==null&&(o.paragraphs=[]);const t={startIndex:o.dataStream.length},n=$e(e);n&&(t.paragraphStyle=n),o.paragraphs.push(t),o.dataStream+="\r"}}]},He=pt,mt={name:"univer-doc-paste-plugin-univer",checkPasteType(o){return/UniverNormal/i.test(o)},stylesRules:[],afterProcessRules:[{filter(o){return o.tagName==="P"&&/UniverNormal/i.test(o.className)},handler(o,e){o.paragraphs==null&&(o.paragraphs=[]);const t={startIndex:o.dataStream.length},n=$e(e);n&&(t.paragraphStyle=n),o.paragraphs.push(t),o.dataStream+="\r"}}]},Ve=mt;function Ee(o,e){const{st:t,ed:n,ts:r={}}=e,{ff:i,fs:s,it:c,bl:l,ul:h,st:m,ol:_,bg:f,cl:u,va:v}=r;let p=o.slice(t,n);const S=[];return c===a.BooleanNumber.TRUE&&(p=`<i>${p}</i>`),v===a.BaselineOffset.SUPERSCRIPT?p=`<sup>${p}</sup>`:v===a.BaselineOffset.SUBSCRIPT&&(p=`<sub>${p}</sub>`),(h==null?void 0:h.s)===a.BooleanNumber.TRUE&&(p=`<u>${p}</u>`),(m==null?void 0:m.s)===a.BooleanNumber.TRUE&&(p=`<s>${p}</s>`),l===a.BooleanNumber.TRUE&&(p=`<strong>${p}</strong>`),i&&S.push(`font-family: ${i}`),u&&S.push(`color: ${u.rgb}`),s&&S.push(`font-size: ${s}pt`),_&&S.push("text-decoration: overline"),f&&S.push(`background: ${f.rgb}`),S.length?`<span style="${S.join("; ")};">${p}</span>`:p}function de(o,e,t){const{dataStream:n,textRuns:r=[]}=o;let i=e;const s=[];for(const c of r){const{st:l,ed:h}=c;a.Tools.hasIntersectionBetweenTwoRanges(e,t,l,h)&&(l>i?(s.push(n.slice(i,l)),s.push(Ee(n,{...c,ed:Math.min(h,t)}))):s.push(Ee(n,{...c,st:i,ed:Math.min(h,t)}))),i=Math.max(e,Math.min(h,t))}return i!==t&&s.push(n.slice(i,t)),s.join("")}function be(o,e=!0){var t;if(e&&((t=o.paragraphs)!=null&&t.length)){const{dataStream:n,paragraphs:r=[]}=o;let i="",s=-1;for(const c of r){const{startIndex:l,paragraphStyle:h={}}=c,{spaceAbove:m,spaceBelow:_,lineSpacing:f}=h,u=[];m!=null&&(typeof m=="number"?u.push(`margin-top: ${m}px`):u.push(`margin-top: ${m.v}px`)),_!=null&&(typeof _=="number"?u.push(`margin-bottom: ${_}px`):u.push(`margin-bottom: ${_.v}px`)),f!=null&&u.push(`line-height: ${f}`),l>s+1?i+=`<p class="UniverNormal" ${u.length?`style="${u.join("; ")};"`:""}>${de(o,s+1,l)}</p>`:i+=`<p class="UniverNormal" ${u.length?`style="${u.join("; ")};"`:""}></p>`,s=l}return s!==n.length&&(i+=de(o,s,n.length)),i}else return de(o,0,o.dataStream.length)}class _t{convert(e){if(e.length===0)throw new Error("The bodyList length at least to be 1");if(e.length===1)return be(e[0]);let t="";for(const n of e)t+='<p className="UniverNormal">',t+=be(n,!1),t+="</p>";return t}}var ft=Object.defineProperty,St=Object.getOwnPropertyDescriptor,vt=(o,e,t,n)=>{for(var r=n>1?void 0:n?St(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&ft(e,t,r),r},w=(o,e)=>(t,n)=>e(t,n,o);V.use(He);V.use(we);V.use(Ve);const j=a.createIdentifier("doc.clipboard-service");let pe=class extends a.Disposable{constructor(e,t,n,r,i,s){super();R(this,"_clipboardHooks",[]);R(this,"_htmlToUDM",new V);R(this,"_umdToHtml",new _t);this._univerInstanceService=e,this._logService=t,this._commandService=n,this._clipboardInterfaceService=r,this._textSelectionManagerService=i,this._docCustomRangeService=s}async copy(e=a.SliceBodyType.copy){const t=this._getDocumentBodyInRanges(e);if(t.length===0)return!1;try{const n=this._textSelectionManagerService.getActiveRange(),r=!!(n!=null&&n.segmentId);this._setClipboardData(t,!r)}catch(n){return this._logService.error("[DocClipboardService] copy failed",n),!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 i;const{segmentId:e,endOffset:t,style:n}=(i=this._textSelectionManagerService.getActiveRange())!=null?i:{},r=this._textSelectionManagerService.getCurrentSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),t==null||r==null)return!1;this.copy(a.SliceBodyType.cut);try{let s=t;for(const l of r){const{startOffset:h,endOffset:m}=l;h==null||m==null||m<=t&&(s-=m-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 h,m;let t=a.normalizeBody(e);const n=(h=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC))==null?void 0:h.getUnitId();if(!n)return!1;this._clipboardHooks.forEach(_=>{_.onBeforePaste&&(t=_.onBeforePaste(t))}),t.customRanges=(m=t.customRanges)==null?void 0:m.map(_=>this._docCustomRangeService.copyCustomRange(n,_));const r=this._textSelectionManagerService.getActiveRange(),{segmentId:i,endOffset:s,style:c}=r||{},l=this._textSelectionManagerService.getCurrentSelections();if(i==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),s==null||l==null)return!1;try{let _=s;for(const u of l){const{startOffset:v,endOffset:p}=u;v==null||p==null||p<=s&&(_+=t.dataStream.length-(p-v))}const f=[{startOffset:_,endOffset:_,style:c}];return this._commandService.executeCommand(d.InnerPasteCommand.id,{body:t,segmentId:i,textRanges:f})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(e,t=!0){const n=lt(),r=e.length>1?e.map(s=>s.dataStream).join(`
2
- `):e[0].dataStream;let i=this._umdToHtml.convert(e);return e.length===1&&t&&(i=i.replace(/(<[a-z]+)/,(s,c)=>`${c} data-copy-id="${n}"`),Te.set(n,e[0])),this._clipboardInterfaceService.write(r,i)}addClipboardHook(e){return this._clipboardHooks.push(e),a.toDisposable(()=>{const t=this._clipboardHooks.indexOf(e);t>-1&&this._clipboardHooks.splice(t,1)})}_getDocumentBodyInRanges(e){const t=this._textSelectionManagerService.getCurrentSelections(),n=this._textSelectionManagerService.getActiveRange(),r=this._univerInstanceService.getCurrentUniverDocInstance(),i=[],s=r==null?void 0:r.getBody();if(t==null||r==null||s==null||n==null)return i;const{segmentId:c}=n;for(const l of t){const{startOffset:h,endOffset:m,collapsed:_}=l;if(_||h==null||m==null)continue;const f=d.getDeleteSelection({startOffset:h,endOffset:m,collapsed:_},s),u=r.getSelfOrHeaderFooterModel(c).sliceBody(f.startOffset,f.endOffset,e);if(u!=null){if(u.customRanges){const v=[];u.customRanges.forEach(C=>{C.startIndex===C.endIndex&&v.push(C)}),u.customRanges=u.customRanges.filter(C=>v.indexOf(C)===-1);let p="",S=0;v.forEach(C=>{p+=u.dataStream.slice(S,C.endIndex),S=C.endIndex+1}),p+=u.dataStream.slice(S,u.dataStream.length),u.dataStream=p}i.push(u)}}return i}async _generateBodyFromClipboardItems(e){try{let t="",n="";for(const r of e)for(const i of r.types)i===g.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await r.getType(i).then(s=>s&&s.text()):i===g.HTML_CLIPBOARD_MIME_TYPE&&(t=await r.getType(i).then(s=>s&&s.text()));return this._generateBodyFromHtmlAndText(t,n)}catch(t){return Promise.reject(t)}}_generateBody(e){const t=e.replace(/\n/g,"\r");if(!e.includes("\r")&&a.Tools.isLegalUrl(e)){const r=a.Tools.generateRandomId(),i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),s=this._docCustomRangeService.copyCustomRange(i.getUnitId(),{startIndex:0,endIndex:t.length-1,rangeId:r,rangeType:a.CustomRangeType.HYPERLINK,data:e});return{dataStream:`${a.DataStreamTreeTokenType.CUSTOM_RANGE_START}${t}${a.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,customRanges:[s]}}const n=[];for(let r=0;r<t.length;r++)t[r]==="\r"&&n.push({startIndex:r});return{dataStream:t,paragraphs:n}}_generateBodyFromHtmlAndText(e,t){if(!e){if(t)return this._generateBody(t);throw new Error("[DocClipboardService] html and text cannot be both empty!")}const n=dt(e);if(n){const r=Te.get(n);if(r)return r}return this._htmlToUDM.convert(e)}};pe=vt([w(0,a.IUniverInstanceService),w(1,a.ILogService),w(2,a.ICommandService),w(3,g.IClipboardInterfaceService),w(4,a.Inject(d.TextSelectionManagerService)),w(5,a.Inject(d.DocCustomRangeService))],pe);var It=Object.defineProperty,Ct=Object.getOwnPropertyDescriptor,Ot=(o,e,t,n)=>{for(var r=n>1?void 0:n?Ct(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&It(e,t,r),r},Z=(o,e)=>(t,n)=>e(t,n,o);const Me=1.5;exports.DocBackScrollRenderController=class extends a.RxDisposable{constructor(e,t,n,r,i){super(),this._context=e,this._textSelectionManagerService=t,this._editorService=n,this._univerInstanceService=r,this._renderManagerService=i,this._init()}_init(){this._textSelectionManagerService.textSelection$.pipe(T.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const{isEditing:t,unitId:n}=e;t&&this._scrollToSelection(n)})}scrollToRange(e,t){var c;const n=(c=this._renderManagerService.getRenderById(e))==null?void 0:c.with(d.DocSkeletonManagerService),r=n==null?void 0:n.getSkeleton();if(!r)return;const{startOffset:i}=t,s=r.findNodePositionByCharIndex(i);this.scrollToNode(e,s)}scrollToNode(e,t){var Oe;const n=this._getDocObject(),r=(Oe=this._renderManagerService.getRenderById(e))==null?void 0:Oe.with(d.DocSkeletonManagerService),i=r==null?void 0:r.getSkeleton();if(n==null||i==null)return;const s=n.document.getOffsetConfig(),{docsLeft:c,docsTop:l}=s,h=new I.NodePositionConvertToCursor(s,i),{contentBoxPointGroup:m}=h.getRangePointData(t,t),{left:_,top:f,height:u}=I.getAnchorBounding(m),v=_+c,p=f+l,S=n.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN),C=!!this._editorService.getEditor(e);if(S==null)return;const{left:O,top:E,right:M,bottom:b}=S.getBounding().viewBound;let D=0,N=0;const P=C?0:100;p<E?D=p-E-P:p>b-u&&(D=p-b+u+P),v<O?N=v-O:v>M-Me&&(N=v-M+Me);const F=S.transViewportScroll2ScrollValue(N,D);S.scrollBy(F)}_scrollToSelection(e){const t=this._textSelectionManagerService.getActiveRange();if(t==null)return;const{collapsed:n,startNodePosition:r}=t;n&&this.scrollToNode(e,r)}_getDocObject(){return d.getDocObject(this._univerInstanceService,this._renderManagerService)}};exports.DocBackScrollRenderController=Ot([Z(1,a.Inject(d.TextSelectionManagerService)),Z(2,g.IEditorService),Z(3,a.Inject(a.IUniverInstanceService)),Z(4,I.IRenderManagerService)],exports.DocBackScrollRenderController);const je={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},We={outerLeft:!1,outerRight:!1,header:!0,footer:!0,innerLeft:!1,innerRight:!1,frozenHeaderLT:!1,frozenHeaderRT:!1,frozenHeaderLM:!1,frozenContent:!1,infoBar:!0,toolbar:!0},ke={layout:{docContainerConfig:We,toolbarConfig:je}},Ge="DocUI",Tt={id:d.MoveCursorOperation.id,binding:g.KeyCode.ARROW_UP,preconditions:U,staticParameters:{direction:a.Direction.UP}},Rt={id:d.MoveCursorOperation.id,binding:g.KeyCode.ARROW_DOWN,preconditions:U,staticParameters:{direction:a.Direction.DOWN}},Et={id:d.MoveCursorOperation.id,binding:g.KeyCode.ARROW_LEFT,preconditions:U,staticParameters:{direction:a.Direction.LEFT}},bt={id:d.MoveCursorOperation.id,binding:g.KeyCode.ARROW_RIGHT,preconditions:U,staticParameters:{direction:a.Direction.RIGHT}},Mt={id:d.MoveSelectionOperation.id,binding:g.KeyCode.ARROW_UP|g.MetaKeys.SHIFT,preconditions:U,staticParameters:{direction:a.Direction.UP}},yt={id:d.MoveSelectionOperation.id,binding:g.KeyCode.ARROW_DOWN|g.MetaKeys.SHIFT,preconditions:U,staticParameters:{direction:a.Direction.DOWN}},Dt={id:d.MoveSelectionOperation.id,binding:g.KeyCode.ARROW_LEFT|g.MetaKeys.SHIFT,preconditions:U,staticParameters:{direction:a.Direction.LEFT}},Pt={id:d.MoveSelectionOperation.id,binding:g.KeyCode.ARROW_RIGHT|g.MetaKeys.SHIFT,preconditions:U,staticParameters:{direction:a.Direction.RIGHT}},xt={id:d.SelectAllOperation.id,binding:g.KeyCode.A|g.MetaKeys.CTRL_COMMAND,preconditions:o=>o.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&(o.getContextValue(a.FOCUSING_DOC)||o.getContextValue(a.EDITOR_ACTIVATED))};var At=Object.defineProperty,Nt=Object.getOwnPropertyDescriptor,Ut=(o,e,t,n)=>{for(var r=n>1?void 0:n?Nt(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&At(e,t,r),r},ye=(o,e)=>(t,n)=>e(t,n,o);let me=class{constructor(o,e,t){R(this,"_docContainer");R(this,"getComponent",o=>{if(this._docContainer=o,!o.getContentRef().current)throw new Error("container is not ready")});R(this,"changeLocale",o=>{this._localeService.setLocale(o)});this._config=o,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(o){if(this._docContainer)return o(this._docContainer)}getDocContainer(){return this._docContainer}};me=Ut([ye(1,a.Inject(a.LocaleService)),ye(2,a.Inject(a.Injector))],me);var Ft=Object.defineProperty,Lt=Object.getOwnPropertyDescriptor,Bt=(o,e,t,n)=>{for(var r=n>1?void 0:n?Lt(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Ft(e,t,r),r},q=(o,e)=>(t,n)=>e(t,n,o);let z=class extends a.RxDisposable{constructor(e,t,n,r,i){super();R(this,"_docContainerController");R(this,"changeLocale",e=>{this._localeService.setLocale(e)});this._localeService=t,this._injector=n,this._textSelectionRenderManager=r,this._layoutService=i,this._docContainerController=this._injector.createInstance(me,e),this._registerContainer()}_registerContainer(){this._layoutService&&this.disposeWithMe(this._layoutService.registerContainerElement(this._textSelectionRenderManager.__getEditorContainer()))}getDocContainerController(){return this._docContainerController}};z=Bt([q(1,a.Inject(a.LocaleService)),q(2,a.Inject(a.Injector)),q(3,I.ITextSelectionRenderManager),q(4,a.Optional(g.ILayoutService))],z);const se="UI_PLUGIN_DOCS",Ie=`${se}_COLOR_PICKER_COMPONENT`,Ye=`${se}_FONT_FAMILY_COMPONENT`,ze=`${se}_FONT_FAMILY_ITEM_COMPONENT`,Ke=`${se}_FONT_SIZE_COMPONENT`,De=18,Pe=200,ue=6,wt=4;function $t(o,e){let{radius:t,width:n,height:r}=e;t=t!=null?t:0,n=n!=null?n:30,r=r!=null?r:30;let i=0;i=Math.min(t,n/2,r/2),o.beginPath(),o.moveTo(0,0),o.lineTo(n,0),o.lineTo(n,r-i),o.arc(n-i,r-i,i,0,Math.PI/2,!1),o.lineTo(0,r),o.lineTo(0,0),o.closePath(),e.fill&&(o.save(),o.fillStyle=e.fill,e.fillRule==="evenodd"?o.fill("evenodd"):o.fill(),o.restore())}class re extends I.Shape{constructor(t,n){super(t,n);R(this,"color");R(this,"text");this.color=n==null?void 0:n.color,this.text=n==null?void 0:n.text}static drawWith(t,n){const{text:r,color:i}=n;t.save(),t.font="13px Source Han Sans CN";const s=t.measureText(r).width,c=Math.min(s+2*ue,Pe);$t(t,{height:De,width:c,radius:4,fill:i,evented:!1}),t.fillStyle="rgba(58, 96, 247, 1)";const l=ue,h=De-wt,m=Pe-2*ue;if(s>m){let _="",f=0;for(const u of r){const v=t.measureText(u).width;if(f+v<=m-t.measureText("...").width)_+=u,f+=v;else{_+="...";break}}t.fillText(_,l,h)}else t.fillText(r,l,h);t.restore()}_draw(t){re.drawWith(t,this)}}const Xe="COMPONENT_DOC_HEADER_FOOTER_PANEL";var Ze={exports:{}},ae={};/**
1
+ "use strict";var it=Object.defineProperty;var st=(o,e,t)=>e in o?it(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var M=(o,e,t)=>st(o,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),u=require("@univerjs/ui"),T=require("@wendellhu/redi"),d=require("@univerjs/docs"),I=require("@univerjs/engine-render"),R=require("rxjs"),q=require("react"),L=require("@wendellhu/redi/react-bindings"),j=require("@univerjs/design"),at=require("clsx");function F(o){return o.getContextValue(a.FOCUSING_DOC)&&o.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!o.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function ct(o){return o.getContextValue(a.FOCUSING_DOC)&&o.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!o.getContextValue(a.FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE)&&!o.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}const lt=10,dt=6;function ut(){return a.Tools.generateRandomId(dt)}function gt(o){const e=o.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class ht{constructor(){M(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 Ee=new ht;function Ce(o){const e=o.style,t={},n=o.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 i=e[r],s=e.getPropertyValue(i);switch(i){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=I.pixelToPt(c)));break}case"font-style":{s==="italic"&&(t.it=a.BooleanNumber.TRUE);break}case"font-weight":{(Number(s)>400||String(s)==="bold")&&(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 pt(o){const e=new DOMParser,t=`<x-univer id="univer-root">${o}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function be(o,e){const t=o.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(o)}const ae=class ae{constructor(){M(this,"_styleCache",new Map);M(this,"_styleRules",[]);M(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=ae._pluginList.find(i=>i.checkPasteType(e)),n=pt(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,i,s;for(const c of t)if(c.nodeType===Node.TEXT_NODE){if(((r=c.nodeValue)==null?void 0:r.trim())==="")continue;let l=(i=c.nodeValue)==null?void 0:i.replace(/[\r\n]/g,""),h;if(e&&e.nodeType===Node.ELEMENT_NODE&&e.tagName.toUpperCase()==="A"){const m=a.Tools.generateRandomId();l=`${a.DataStreamTreeTokenType.CUSTOM_RANGE_START}${l}${a.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,n.customRanges=[...(s=n.customRanges)!=null?s:[],{startIndex:n.dataStream.length,endIndex:n.dataStream.length+l.length-1,rangeId:m,rangeType:a.CustomRangeType.HYPERLINK}],n.payloads={...n.payloads,[m]:e.href}}e&&this._styleCache.has(e)&&(h=this._styleCache.get(e)),n.dataStream+=l,h&&Object.getOwnPropertyNames(h).length&&n.textRuns.push({st:n.dataStream.length-l.length,ed:n.dataStream.length,ts:h})}else{if(a.skipParseTagNames.includes(c.nodeName.toLowerCase()))continue;if(c.nodeType===Node.ELEMENT_NODE){const l=e?this._styleCache.get(e):{},h=this._styleRules.find(({filter:g})=>be(c,g)),m=h?h.getStyle(c):Ce(c);this._styleCache.set(c,{...l,...m});const{childNodes:_}=c;this._process(c,_,n);const f=this._afterProcessRules.find(({filter:g})=>be(c,g));f&&f.handler(n,c)}}}};M(ae,"_pluginList",[]);let W=ae;const mt={name:"univer-doc-paste-plugin-lark",checkPasteType(o){return/lark-record-clipboard/i.test(o)},stylesRules:[{filter:["s"],getStyle(o){const e=Ce(o);return{st:{s:a.BooleanNumber.TRUE},...e}}}],afterProcessRules:[{filter(o){return o.tagName==="DIV"&&/ace-line/i.test(o.className)},handler(o){o.paragraphs==null&&(o.paragraphs=[]),o.paragraphs.push({startIndex:o.dataStream.length}),o.dataStream+="\r"}}]},He=mt;function Ve(o){const e=o.style,t={};for(let n=0;n<e.length;n++){const r=e[n],i=e.getPropertyValue(r);switch(r){case"margin-top":{const s=Number.parseInt(i);t.spaceAbove={v:/pt/.test(i)?I.ptToPixel(s):s};break}case"margin-bottom":{const s=Number.parseInt(i);t.spaceBelow={v:/pt/.test(i)?I.ptToPixel(s):s};break}case"line-height":{const s=Number.parseFloat(i);t.lineSpacing=s;break}}}return Object.getOwnPropertyNames(t).length?t:null}const _t={name:"univer-doc-paste-plugin-word",checkPasteType(o){return/word|mso/i.test(o)},stylesRules:[{filter:["b"],getStyle(o){const e=Ce(o);return{bl:a.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(o){return o.tagName==="P"},handler(o,e){o.paragraphs==null&&(o.paragraphs=[]);const t={startIndex:o.dataStream.length},n=Ve(e);n&&(t.paragraphStyle=n),o.paragraphs.push(t),o.dataStream+="\r"}}]},je=_t,ft={name:"univer-doc-paste-plugin-univer",checkPasteType(o){return/UniverNormal/i.test(o)},stylesRules:[],afterProcessRules:[{filter(o){return o.tagName==="P"&&/UniverNormal/i.test(o.className)},handler(o,e){o.paragraphs==null&&(o.paragraphs=[]);const t={startIndex:o.dataStream.length},n=Ve(e);n&&(t.paragraphStyle=n),o.paragraphs.push(t),o.dataStream+="\r"}}]},We=ft;function Me(o,e){const{st:t,ed:n,ts:r={}}=e,{ff:i,fs:s,it:c,bl:l,ul:h,st:m,ol:_,bg:f,cl:g,va:v}=r;let p=o.slice(t,n);const S=[];return c===a.BooleanNumber.TRUE&&(p=`<i>${p}</i>`),v===a.BaselineOffset.SUPERSCRIPT?p=`<sup>${p}</sup>`:v===a.BaselineOffset.SUBSCRIPT&&(p=`<sub>${p}</sub>`),(h==null?void 0:h.s)===a.BooleanNumber.TRUE&&(p=`<u>${p}</u>`),(m==null?void 0:m.s)===a.BooleanNumber.TRUE&&(p=`<s>${p}</s>`),l===a.BooleanNumber.TRUE&&(p=`<strong>${p}</strong>`),i&&S.push(`font-family: ${i}`),g&&S.push(`color: ${g.rgb}`),s&&S.push(`font-size: ${s}pt`),_&&S.push("text-decoration: overline"),f&&S.push(`background: ${f.rgb}`),S.length?`<span style="${S.join("; ")};">${p}</span>`:p}function ge(o,e,t){const{dataStream:n,textRuns:r=[]}=o;let i=e;const s=[];for(const c of r){const{st:l,ed:h}=c;a.Tools.hasIntersectionBetweenTwoRanges(e,t,l,h)&&(l>i?(s.push(n.slice(i,l)),s.push(Me(n,{...c,ed:Math.min(h,t)}))):s.push(Me(n,{...c,st:i,ed:Math.min(h,t)}))),i=Math.max(e,Math.min(h,t))}return i!==t&&s.push(n.slice(i,t)),s.join("")}function ye(o,e=!0){var t;if(e&&((t=o.paragraphs)!=null&&t.length)){const{dataStream:n,paragraphs:r=[]}=o;let i="",s=-1;for(const c of r){const{startIndex:l,paragraphStyle:h={}}=c,{spaceAbove:m,spaceBelow:_,lineSpacing:f}=h,g=[];m!=null&&(typeof m=="number"?g.push(`margin-top: ${m}px`):g.push(`margin-top: ${m.v}px`)),_!=null&&(typeof _=="number"?g.push(`margin-bottom: ${_}px`):g.push(`margin-bottom: ${_.v}px`)),f!=null&&g.push(`line-height: ${f}`),l>s+1?i+=`<p class="UniverNormal" ${g.length?`style="${g.join("; ")};"`:""}>${ge(o,s+1,l)}</p>`:i+=`<p class="UniverNormal" ${g.length?`style="${g.join("; ")};"`:""}></p>`,s=l}return s!==n.length&&(i+=ge(o,s,n.length)),i}else return ge(o,0,o.dataStream.length)}class St{convert(e){if(e.length===0)throw new Error("The bodyList length at least to be 1");if(e.length===1)return ye(e[0]);let t="";for(const n of e)t+='<p className="UniverNormal">',t+=ye(n,!1),t+="</p>";return t}}var vt=Object.defineProperty,It=Object.getOwnPropertyDescriptor,Ct=(o,e,t,n)=>{for(var r=n>1?void 0:n?It(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&vt(e,t,r),r},H=(o,e)=>(t,n)=>e(t,n,o);W.use(je);W.use(He);W.use(We);const k=T.createIdentifier("doc.clipboard-service");let _e=class extends a.Disposable{constructor(e,t,n,r,i,s){super();M(this,"_clipboardHooks",[]);M(this,"_htmlToUDM",new W);M(this,"_umdToHtml",new St);this._univerInstanceService=e,this._logService=t,this._commandService=n,this._clipboardInterfaceService=r,this._textSelectionManagerService=i,this._docCustomRangeService=s}async copy(e=a.SliceBodyType.copy){const t=this._getDocumentBodyInRanges(e);if(t.length===0)return!1;try{const n=this._textSelectionManagerService.getActiveRange(),r=!!(n!=null&&n.segmentId);this._setClipboardData(t,!r)}catch(n){return this._logService.error("[DocClipboardService] copy failed",n),!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 i;const{segmentId:e,endOffset:t,style:n}=(i=this._textSelectionManagerService.getActiveRange())!=null?i:{},r=this._textSelectionManagerService.getCurrentSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),t==null||r==null)return!1;this.copy(a.SliceBodyType.cut);try{let s=t;for(const l of r){const{startOffset:h,endOffset:m}=l;h==null||m==null||m<=t&&(s-=m-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 h,m;let t=a.normalizeBody(e);const n=(h=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC))==null?void 0:h.getUnitId();if(!n)return!1;this._clipboardHooks.forEach(_=>{_.onBeforePaste&&(t=_.onBeforePaste(t))}),t.customRanges=(m=t.customRanges)==null?void 0:m.map(_=>this._docCustomRangeService.copyCustomRange(n,_));const r=this._textSelectionManagerService.getActiveRange(),{segmentId:i,endOffset:s,style:c}=r||{},l=this._textSelectionManagerService.getCurrentSelections();if(i==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),s==null||l==null)return!1;try{let _=s;for(const g of l){const{startOffset:v,endOffset:p}=g;v==null||p==null||p<=s&&(_+=t.dataStream.length-(p-v))}const f=[{startOffset:_,endOffset:_,style:c}];return this._commandService.executeCommand(d.InnerPasteCommand.id,{body:t,segmentId:i,textRanges:f})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(e,t=!0){const n=ut(),r=e.length>1?e.map(s=>s.dataStream).join(`
2
+ `):e[0].dataStream;let i=this._umdToHtml.convert(e);return e.length===1&&t&&(i=i.replace(/(<[a-z]+)/,(s,c)=>`${c} data-copy-id="${n}"`),Ee.set(n,e[0])),this._clipboardInterfaceService.write(r,i)}addClipboardHook(e){return this._clipboardHooks.push(e),a.toDisposable(()=>{const t=this._clipboardHooks.indexOf(e);t>-1&&this._clipboardHooks.splice(t,1)})}_getDocumentBodyInRanges(e){const t=this._textSelectionManagerService.getCurrentSelections(),n=this._textSelectionManagerService.getActiveRange(),r=this._univerInstanceService.getCurrentUniverDocInstance(),i=[],s=r==null?void 0:r.getBody();if(t==null||r==null||s==null||n==null)return i;const{segmentId:c}=n;for(const l of t){const{startOffset:h,endOffset:m,collapsed:_}=l;if(_||h==null||m==null)continue;const f=d.getDeleteSelection({startOffset:h,endOffset:m,collapsed:_},s),g=r.getSelfOrHeaderFooterModel(c).sliceBody(f.startOffset,f.endOffset,e);if(g!=null){if(g.customRanges){const v=[];g.customRanges.forEach(C=>{C.startIndex===C.endIndex&&v.push(C)}),g.customRanges=g.customRanges.filter(C=>v.indexOf(C)===-1);let p="",S=0;v.forEach(C=>{p+=g.dataStream.slice(S,C.endIndex),S=C.endIndex+1}),p+=g.dataStream.slice(S,g.dataStream.length),g.dataStream=p}i.push(g)}}return i}async _generateBodyFromClipboardItems(e){try{let t="",n="";for(const r of e)for(const i of r.types)i===u.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await r.getType(i).then(s=>s&&s.text()):i===u.HTML_CLIPBOARD_MIME_TYPE&&(t=await r.getType(i).then(s=>s&&s.text()));return this._generateBodyFromHtmlAndText(t,n)}catch(t){return Promise.reject(t)}}_generateBody(e){const t=e.replace(/\n/g,"\r");if(!e.includes("\r")&&a.Tools.isLegalUrl(e)){const r=a.Tools.generateRandomId(),i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),s=this._docCustomRangeService.copyCustomRange(i.getUnitId(),{startIndex:0,endIndex:t.length-1,rangeId:r,rangeType:a.CustomRangeType.HYPERLINK,data:e});return{dataStream:`${a.DataStreamTreeTokenType.CUSTOM_RANGE_START}${t}${a.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,customRanges:[s]}}const n=[];for(let r=0;r<t.length;r++)t[r]==="\r"&&n.push({startIndex:r});return{dataStream:t,paragraphs:n}}_generateBodyFromHtmlAndText(e,t){if(!e){if(t)return this._generateBody(t);throw new Error("[DocClipboardService] html and text cannot be both empty!")}const n=gt(e);if(n){const r=Ee.get(n);if(r)return r}return this._htmlToUDM.convert(e)}};_e=Ct([H(0,a.IUniverInstanceService),H(1,a.ILogService),H(2,a.ICommandService),H(3,u.IClipboardInterfaceService),H(4,T.Inject(d.TextSelectionManagerService)),H(5,T.Inject(d.DocCustomRangeService))],_e);var Ot=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,Rt=(o,e,t,n)=>{for(var r=n>1?void 0:n?Tt(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Ot(e,t,r),r},J=(o,e)=>(t,n)=>e(t,n,o);const De=1.5;exports.DocBackScrollRenderController=class extends a.RxDisposable{constructor(e,t,n,r,i){super(),this._context=e,this._textSelectionManagerService=t,this._editorService=n,this._univerInstanceService=r,this._renderManagerService=i,this._init()}_init(){this._textSelectionManagerService.textSelection$.pipe(R.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const{isEditing:t,unitId:n}=e;t&&this._scrollToSelection(n)})}scrollToRange(e,t){var c;const n=(c=this._renderManagerService.getRenderById(e))==null?void 0:c.with(d.DocSkeletonManagerService),r=n==null?void 0:n.getSkeleton();if(!r)return;const{startOffset:i}=t,s=r.findNodePositionByCharIndex(i);this.scrollToNode(e,s)}scrollToNode(e,t){var Re;const n=this._getDocObject(),r=(Re=this._renderManagerService.getRenderById(e))==null?void 0:Re.with(d.DocSkeletonManagerService),i=r==null?void 0:r.getSkeleton();if(n==null||i==null)return;const s=n.document.getOffsetConfig(),{docsLeft:c,docsTop:l}=s,h=new I.NodePositionConvertToCursor(s,i),{contentBoxPointGroup:m}=h.getRangePointData(t,t),{left:_,top:f,height:g}=I.getAnchorBounding(m),v=_+c,p=f+l,S=n.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN),C=!!this._editorService.getEditor(e);if(S==null)return;const{left:O,top:E,right:b,bottom:y}=S.getBounding().viewBound;let P=0,U=0;const x=C?0:100;p<E?P=p-E-x:p>y-g&&(P=p-y+g+x),v<O?U=v-O:v>b-De&&(U=v-b+De);const B=S.transViewportScroll2ScrollValue(U,P);S.scrollBy(B)}_scrollToSelection(e){const t=this._textSelectionManagerService.getActiveRange();if(t==null)return;const{collapsed:n,startNodePosition:r}=t;n&&this.scrollToNode(e,r)}_getDocObject(){return d.getDocObject(this._univerInstanceService,this._renderManagerService)}};exports.DocBackScrollRenderController=Rt([J(1,T.Inject(d.TextSelectionManagerService)),J(2,u.IEditorService),J(3,T.Inject(a.IUniverInstanceService)),J(4,I.IRenderManagerService)],exports.DocBackScrollRenderController);const ke={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},Ge={outerLeft:!1,outerRight:!1,header:!0,footer:!0,innerLeft:!1,innerRight:!1,frozenHeaderLT:!1,frozenHeaderRT:!1,frozenHeaderLM:!1,frozenContent:!1,infoBar:!0,toolbar:!0},Ye={layout:{docContainerConfig:Ge,toolbarConfig:ke}},ze="DocUI",Et={id:d.MoveCursorOperation.id,binding:u.KeyCode.ARROW_UP,preconditions:F,staticParameters:{direction:a.Direction.UP}},bt={id:d.MoveCursorOperation.id,binding:u.KeyCode.ARROW_DOWN,preconditions:F,staticParameters:{direction:a.Direction.DOWN}},Mt={id:d.MoveCursorOperation.id,binding:u.KeyCode.ARROW_LEFT,preconditions:F,staticParameters:{direction:a.Direction.LEFT}},yt={id:d.MoveCursorOperation.id,binding:u.KeyCode.ARROW_RIGHT,preconditions:F,staticParameters:{direction:a.Direction.RIGHT}},Dt={id:d.MoveSelectionOperation.id,binding:u.KeyCode.ARROW_UP|u.MetaKeys.SHIFT,preconditions:F,staticParameters:{direction:a.Direction.UP}},Pt={id:d.MoveSelectionOperation.id,binding:u.KeyCode.ARROW_DOWN|u.MetaKeys.SHIFT,preconditions:F,staticParameters:{direction:a.Direction.DOWN}},xt={id:d.MoveSelectionOperation.id,binding:u.KeyCode.ARROW_LEFT|u.MetaKeys.SHIFT,preconditions:F,staticParameters:{direction:a.Direction.LEFT}},At={id:d.MoveSelectionOperation.id,binding:u.KeyCode.ARROW_RIGHT|u.MetaKeys.SHIFT,preconditions:F,staticParameters:{direction:a.Direction.RIGHT}},Nt={id:d.SelectAllOperation.id,binding:u.KeyCode.A|u.MetaKeys.CTRL_COMMAND,preconditions:o=>o.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&(o.getContextValue(a.FOCUSING_DOC)||o.getContextValue(a.EDITOR_ACTIVATED))};var Ut=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,Lt=(o,e,t,n)=>{for(var r=n>1?void 0:n?Ft(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Ut(e,t,r),r},Pe=(o,e)=>(t,n)=>e(t,n,o);let fe=class{constructor(o,e,t){M(this,"_docContainer");M(this,"getComponent",o=>{if(this._docContainer=o,!o.getContentRef().current)throw new Error("container is not ready")});M(this,"changeLocale",o=>{this._localeService.setLocale(o)});this._config=o,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(o){if(this._docContainer)return o(this._docContainer)}getDocContainer(){return this._docContainer}};fe=Lt([Pe(1,T.Inject(a.LocaleService)),Pe(2,T.Inject(T.Injector))],fe);var Bt=Object.defineProperty,wt=Object.getOwnPropertyDescriptor,$t=(o,e,t,n)=>{for(var r=n>1?void 0:n?wt(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Bt(e,t,r),r},Q=(o,e)=>(t,n)=>e(t,n,o);let X=class extends a.RxDisposable{constructor(e,t,n,r,i){super();M(this,"_docContainerController");M(this,"changeLocale",e=>{this._localeService.setLocale(e)});this._localeService=t,this._injector=n,this._textSelectionRenderManager=r,this._layoutService=i,this._docContainerController=this._injector.createInstance(fe,e),this._registerContainer()}_registerContainer(){this._layoutService&&this.disposeWithMe(this._layoutService.registerContainerElement(this._textSelectionRenderManager.__getEditorContainer()))}getDocContainerController(){return this._docContainerController}};X=$t([Q(1,T.Inject(a.LocaleService)),Q(2,T.Inject(T.Injector)),Q(3,I.ITextSelectionRenderManager),Q(4,T.Optional(u.ILayoutService))],X);const ce="UI_PLUGIN_DOCS",Oe=`${ce}_COLOR_PICKER_COMPONENT`,Ke=`${ce}_FONT_FAMILY_COMPONENT`,Xe=`${ce}_FONT_FAMILY_ITEM_COMPONENT`,Ze=`${ce}_FONT_SIZE_COMPONENT`,xe=18,Ae=200,he=6,Ht=4;function Vt(o,e){let{radius:t,width:n,height:r}=e;t=t!=null?t:0,n=n!=null?n:30,r=r!=null?r:30;let i=0;i=Math.min(t,n/2,r/2),o.beginPath(),o.moveTo(0,0),o.lineTo(n,0),o.lineTo(n,r-i),o.arc(n-i,r-i,i,0,Math.PI/2,!1),o.lineTo(0,r),o.lineTo(0,0),o.closePath(),e.fill&&(o.save(),o.fillStyle=e.fill,e.fillRule==="evenodd"?o.fill("evenodd"):o.fill(),o.restore())}class se extends I.Shape{constructor(t,n){super(t,n);M(this,"color");M(this,"text");this.color=n==null?void 0:n.color,this.text=n==null?void 0:n.text}static drawWith(t,n){const{text:r,color:i}=n;t.save(),t.font="13px Source Han Sans CN";const s=t.measureText(r).width,c=Math.min(s+2*he,Ae);Vt(t,{height:xe,width:c,radius:4,fill:i,evented:!1}),t.fillStyle="rgba(58, 96, 247, 1)";const l=he,h=xe-Ht,m=Ae-2*he;if(s>m){let _="",f=0;for(const g of r){const v=t.measureText(g).width;if(f+v<=m-t.measureText("...").width)_+=g,f+=v;else{_+="...";break}}t.fillText(_,l,h)}else t.fillText(r,l,h);t.restore()}_draw(t){se.drawWith(t,this)}}const qe="COMPONENT_DOC_HEADER_FOOTER_PANEL";var Je={exports:{}},le={};/**
3
3
  * @license React
4
4
  * react-jsx-runtime.production.min.js
5
5
  *
@@ -7,5 +7,5 @@
7
7
  *
8
8
  * This source code is licensed under the MIT license found in the
9
9
  * LICENSE file in the root directory of this source tree.
10
- */var Ht=X,Vt=Symbol.for("react.element"),jt=Symbol.for("react.fragment"),Wt=Object.prototype.hasOwnProperty,kt=Ht.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Gt={key:!0,ref:!0,__self:!0,__source:!0};function qe(o,e,t){var n,r={},i=null,s=null;t!==void 0&&(i=""+t),e.key!==void 0&&(i=""+e.key),e.ref!==void 0&&(s=e.ref);for(n in e)Wt.call(e,n)&&!Gt.hasOwnProperty(n)&&(r[n]=e[n]);if(o&&o.defaultProps)for(n in e=o.defaultProps,e)r[n]===void 0&&(r[n]=e[n]);return{$$typeof:Vt,type:o,key:i,ref:s,props:r,_owner:kt.current}}ae.Fragment=jt;ae.jsx=qe;ae.jsxs=qe;Ze.exports=ae;var y=Ze.exports;const Yt="univer-panel",zt="univer-options-section",Kt="univer-options-form-item",Xt="univer-options-input",Zt="univer-options-margin-setting",A={panel:Yt,optionsSection:zt,optionsFormItem:Kt,optionsInput:Xt,optionsMarginSetting:Zt},qt=o=>{const e=a.useDependency(a.LocaleService),t=a.useDependency(a.IUniverInstanceService),n=a.useDependency(I.IRenderManagerService),r=a.useDependency(a.ICommandService),i=a.useDependency(I.ITextSelectionRenderManager),s=a.useDependency(d.TextSelectionManagerService),{unitId:c}=o,[l,h]=X.useState({}),m=(u,v)=>{var N;h(P=>({...P,[v]:u?a.BooleanNumber.TRUE:a.BooleanNumber.FALSE}));const p=t.getUniverDocInstance(c),S=p==null?void 0:p.getSnapshot().documentStyle,C=(N=n.getRenderById(c))==null?void 0:N.with(d.DocSkeletonManagerService),O=C==null?void 0:C.getViewModel();if(S==null||O==null)return;const E=O.getEditArea();let M=!1;const b=i.getSegmentPage();let D=!1;if(v==="useFirstPageHeaderFooter"&&u===!0&&((E===I.DocumentEditArea.HEADER&&!S.firstPageHeaderId||E===I.DocumentEditArea.FOOTER&&!S.firstPageFooterId)&&(M=!0),M&&b===0&&(D=!0)),v==="evenAndOddHeaders"&&u===!0&&((E===I.DocumentEditArea.HEADER&&!S.evenPageHeaderId||E===I.DocumentEditArea.FOOTER&&!S.evenPageFooterId)&&(M=!0),M&&b%2===1&&(D=!0)),M){const F=a.Tools.generateRandomId(6);D&&i.setSegment(F),r.executeCommand(te,{unitId:c,segmentId:F,headerFooterProps:{[v]:u?a.BooleanNumber.TRUE:a.BooleanNumber.FALSE}})}else r.executeCommand(te,{unitId:c,headerFooterProps:{[v]:u?a.BooleanNumber.TRUE:a.BooleanNumber.FALSE}})},_=async(u,v)=>{h(p=>({...p,[v]:u})),await r.executeCommand(te,{unitId:c,headerFooterProps:{[v]:u}}),i.removeAllTextRanges(),i.blur()},f=()=>{var C,O;const u=(C=n.getRenderById(c))==null?void 0:C.with(d.DocSkeletonManagerService),v=u==null?void 0:u.getSkeleton(),p=u==null?void 0:u.getViewModel(),S=n.getRenderById(c);S==null||p==null||v==null||(s.replaceTextRanges([]),i.setSegment(""),i.setSegmentPage(-1),p.setEditArea(I.DocumentEditArea.BODY),v.calculate(),(O=S.mainComponent)==null||O.makeDirty(!0))};return X.useEffect(()=>{const u=t.getUniverDocInstance(c),v=u==null?void 0:u.getSnapshot().documentStyle;if(v){const{marginHeader:p,marginFooter:S,useFirstPageHeaderFooter:C,evenAndOddHeaders:O}=v;h({marginHeader:p,marginFooter:S,useFirstPageHeaderFooter:C,evenAndOddHeaders:O})}},[c]),y.jsxs("div",{className:A.options,children:[y.jsxs("div",{className:A.optionsSection,children:[y.jsx("div",{className:A.optionsFormItem,children:y.jsx(H.Checkbox,{checked:l.useFirstPageHeaderFooter===a.BooleanNumber.TRUE,onChange:u=>{m(u,"useFirstPageHeaderFooter")},children:e.t("headerFooter.firstPageCheckBox")})}),y.jsx("div",{className:A.optionsFormItem,children:y.jsx(H.Checkbox,{checked:l.evenAndOddHeaders===a.BooleanNumber.TRUE,onChange:u=>{m(u,"evenAndOddHeaders")},children:e.t("headerFooter.oddEvenCheckBox")})})]}),y.jsxs("div",{className:it(A.optionsSection,A.optionsMarginSetting),children:[y.jsxs("div",{className:A.optionsMarginItem,children:[y.jsx("span",{children:e.t("headerFooter.headerTopMargin")}),y.jsx(H.InputNumber,{min:0,max:200,precision:1,value:l.marginHeader,onChange:u=>{_(u,"marginHeader")},className:A.optionsInput})]}),y.jsxs("div",{className:A.optionsMarginItem,children:[y.jsx("span",{children:e.t("headerFooter.footerBottomMargin")}),y.jsx(H.InputNumber,{min:0,max:200,precision:1,value:l.marginFooter,onChange:u=>{_(u,"marginFooter")},className:A.optionsInput})]})]}),y.jsx("div",{className:A.optionsSection,children:y.jsx(H.Button,{onClick:f,children:e.t("headerFooter.closeHeaderFooter")})})]})},Jt=()=>{var h;const o=a.useDependency(a.LocaleService),e=a.useDependency(I.IRenderManagerService),r=a.useDependency(a.IUniverInstanceService).getCurrentUniverDocInstance().getUnitId(),s=((h=e.getRenderById(r))==null?void 0:h.with(d.DocSkeletonManagerService)).getViewModel(),[c,l]=X.useState(!0);return X.useEffect(()=>{const m=s.getEditArea();l(m!==I.DocumentEditArea.BODY);const _=s.editAreaChange$.subscribe(f=>{f!=null&&l(f!==I.DocumentEditArea.BODY)});return()=>{_.unsubscribe()}},[]),y.jsx("div",{className:A.panel,children:c?y.jsx(qt,{unitId:r}):y.jsx("div",{className:A.panelDisableText,children:o.t("headerFooter.disableText")})})},Je={id:"sidebar.operation.doc-header-footer-panel",type:a.CommandType.COMMAND,handler:async(o,e)=>{const t=o.get(g.ISidebarService),n=o.get(a.LocaleService);switch(e.value){case"open":t.open({header:{title:n.t("headerFooter.panel")},children:{label:Xe},onClose:()=>{},width:400});break;case"close":default:t.close();break}return!0}};var Qt=Object.defineProperty,en=Object.getOwnPropertyDescriptor,tn=(o,e,t,n)=>{for(var r=n>1?void 0:n?en(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Qt(e,t,r),r},L=(o,e)=>(t,n)=>e(t,n,o);const xe="rgba(58, 96, 247, 1)",Ae="rgba(58, 96, 247, 0.08)";var x=(o=>(o[o.FIRST_PAGE_HEADER=0]="FIRST_PAGE_HEADER",o[o.FIRST_PAGE_FOOTER=1]="FIRST_PAGE_FOOTER",o[o.DEFAULT_HEADER=2]="DEFAULT_HEADER",o[o.DEFAULT_FOOTER=3]="DEFAULT_FOOTER",o[o.EVEN_PAGE_HEADER=4]="EVEN_PAGE_HEADER",o[o.EVEN_PAGE_FOOTER=5]="EVEN_PAGE_FOOTER",o))(x||{});function nn(o,e,t){const{documentStyle:n}=o.getDataModel().getSnapshot(),{defaultHeaderId:r,defaultFooterId:i,evenPageHeaderId:s,evenPageFooterId:c,firstPageHeaderId:l,firstPageFooterId:h,evenAndOddHeaders:m,useFirstPageHeaderFooter:_}=n;switch(e){case I.DocumentEditArea.BODY:return{createType:null,headerFooterId:null};case I.DocumentEditArea.HEADER:return _===a.BooleanNumber.TRUE&&!l?{createType:0,headerFooterId:null}:m===a.BooleanNumber.TRUE&&t%2===0&&!s?{createType:4,headerFooterId:null}:r?{createType:null,headerFooterId:r}:{createType:2,headerFooterId:null};case I.DocumentEditArea.FOOTER:return _===a.BooleanNumber.TRUE&&!h?{createType:1,headerFooterId:null}:m===a.BooleanNumber.TRUE&&t%2===0&&!c?{createType:5,headerFooterId:null}:i?{createType:null,headerFooterId:i}:{createType:3,headerFooterId:null};default:throw new Error(`Invalid editArea: ${e}`)}}let _e=class extends a.Disposable{constructor(e,t,n,r,i,s,c,l,h){super();R(this,"_loadedMap",new WeakSet);this._context=e,this._commandService=t,this._editorService=n,this._instanceSrv=r,this._renderManagerService=i,this._docSkeletonManagerService=s,this._textSelectionRenderManager=c,this._localeService=l,this._componentManager=h,this._initialize()}_initialize(){this._context.unit.getSnapshot().documentStyle.documentFlavor===a.DocumentFlavor.TRADITIONAL&&(this._init(),this._drawHeaderFooterLabel(),this._registerCommands(),this._initCustomComponents())}_registerCommands(){[Ue,Qe,Je].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initCustomComponents(){const e=this._componentManager;this.disposeWithMe(e.register(Xe,Jt))}_init(){const{unitId:e}=this._context,t=d.neoGetDocObject(this._context);t==null||t.document==null||this._loadedMap.has(t.document)||(this._initialMain(e),this._loadedMap.add(t.document))}_initialMain(e){const t=d.neoGetDocObject(this._context),{document:n}=t;this.disposeWithMe(n.onDblclick$.subscribeEvent(async r=>{if(this._isEditorReadOnly(e))return;const{offsetX:i,offsetY:s}=r,{pageLayoutType:c=I.PageLayoutType.VERTICAL,pageMarginLeft:l,pageMarginTop:h}=n.getOffsetConfig(),m=this._getTransformCoordForDocumentOffset(i,s);if(m==null)return;const _=this._docSkeletonManagerService.getViewModel(),f=this._docSkeletonManagerService.getSkeleton(),u=_.getEditArea(),{editArea:v,pageNumber:p}=f.findEditAreaByCoord(m,c,l,h);if(u===v)return;_.setEditArea(v);const{createType:S,headerFooterId:C}=nn(_,v,p);if(v===I.DocumentEditArea.BODY)this._textSelectionRenderManager.setSegment(""),this._textSelectionRenderManager.setSegmentPage(-1),this._textSelectionRenderManager.setCursorManually(i,s);else if(S!=null){const E=a.Tools.generateRandomId(6);this._textSelectionRenderManager.setSegment(E),this._textSelectionRenderManager.setSegmentPage(p),await this._commandService.executeCommand(Ue.id,{unitId:e,createType:S,segmentId:E})}else C!=null&&(this._textSelectionRenderManager.setSegment(C),this._textSelectionRenderManager.setSegmentPage(p),this._textSelectionRenderManager.setCursorManually(i,s))}))}_getTransformCoordForDocumentOffset(e,t){const n=d.neoGetDocObject(this._context),{document:r,scene:i}=n,{documentTransform:s}=r.getOffsetConfig(),c=i.getViewports()[0];if(c==null)return;const l=c.transformVector2SceneCoord(I.Vector2.FromArray([e,t]));return s.clone().invert().applyPoint(l)}_drawHeaderFooterLabel(){const e=this._localeService;this._renderManagerService.currentRender$.subscribe(t=>{if(t==null)return;const n=this._renderManagerService.getRenderById(t);if(this._editorService.isEditor(t)||this._instanceSrv.getUniverDocInstance(t)==null||n==null)return;const{mainComponent:r}=n,i=r;this.disposeWithMe(a.toDisposable(i.pageRender$.subscribe(s=>{if(this._editorService.isEditor(t))return;const h=this._docSkeletonManagerService.getViewModel().getEditArea()===I.DocumentEditArea.BODY,{page:m,pageLeft:_,pageTop:f,ctx:u}=s,{pageWidth:v,pageHeight:p,marginTop:S,marginBottom:C}=m;if(u.save(),u.translate(_-.5,f-.5),h?(I.Rect.drawWith(u,{left:0,top:0,width:v,height:S,fill:"rgba(255, 255, 255, 0.5)"}),u.save(),u.translate(0,p-C),I.Rect.drawWith(u,{left:0,top:0,width:v,height:C,fill:"rgba(255, 255, 255, 0.5)"}),u.restore()):(u.save(),u.translate(0,S),I.Rect.drawWith(u,{left:0,top:S,width:v,height:p-S-C,fill:"rgba(255, 255, 255, 0.5)"}),u.restore()),!h){const O={dataArray:[{command:"M",points:[0,S]},{command:"L",points:[v,S]}],strokeWidth:1,stroke:xe},E={dataArray:[{command:"M",points:[0,p-C]},{command:"L",points:[v,p-C]}],strokeWidth:1,stroke:xe};I.Path.drawWith(u,O),I.Path.drawWith(u,E),u.translate(0,S+1),re.drawWith(u,{text:e.t("headerFooter.header"),color:Ae}),u.translate(0,p-S-C),re.drawWith(u,{text:e.t("headerFooter.footer"),color:Ae})}u.restore()})))})}_isEditorReadOnly(e){const t=this._editorService.getEditor(e);return t?t.isReadOnly():!1}_getDocDataModel(){return this._context.unit}};_e=tn([L(1,a.ICommandService),L(2,g.IEditorService),L(3,a.IUniverInstanceService),L(4,I.IRenderManagerService),L(5,a.Inject(d.DocSkeletonManagerService)),L(6,I.ITextSelectionRenderManager),L(7,a.Inject(a.LocaleService)),L(8,a.Inject(g.ComponentManager))],_e);function Ne(){return{dataStream:`\r
11
- `,textRuns:[{st:0,ed:0,ts:{fs:9}}],customBlocks:[],paragraphs:[{startIndex:0,paragraphStyle:{spaceAbove:{v:0},lineSpacing:1.5,spaceBelow:{v:0}}}],sectionBreaks:[{startIndex:1}]}}function ge(o,e,t,n){const r=a.JSONX.getInstance(),i=6,s=o!=null?o:a.Tools.generateRandomId(i),c=e===x.DEFAULT_HEADER||e===x.FIRST_PAGE_HEADER||e===x.EVEN_PAGE_HEADER,l=r.insertOp([c?"headers":"footers",s],{[c?"headerId":"footerId"]:s,body:Ne()});n.push(l);const h=a.Tools.generateRandomId(i),m=r.insertOp([c?"footers":"headers",h],{[c?"footers":"headers"]:h,body:Ne()});n.push(m);let _="defaultHeaderId",f="defaultFooterId";switch(e){case x.DEFAULT_HEADER:_="defaultHeaderId",f="defaultFooterId";break;case x.DEFAULT_FOOTER:_="defaultFooterId",f="defaultHeaderId";break;case x.FIRST_PAGE_HEADER:_="firstPageHeaderId",f="firstPageFooterId";break;case x.FIRST_PAGE_FOOTER:_="firstPageFooterId",f="firstPageHeaderId";break;case x.EVEN_PAGE_HEADER:_="evenPageHeaderId",f="evenPageFooterId";break;case x.EVEN_PAGE_FOOTER:_="evenPageFooterId",f="evenPageHeaderId";break;default:throw new Error(`Unknown header footer type: ${e}`)}for(const[u,v]of[[_,s],[f,h]])if(t[u]!=null){const p=r.replaceOp(["documentStyle",u],t[u],v);n.push(p)}else{const p=r.insertOp(["documentStyle",u],v);n.push(p)}return n}const te="doc.command.core-header-footer",Ue={id:te,type:a.CommandType.COMMAND,handler:async(o,e)=>{var M;const t=o.get(a.ICommandService),n=o.get(a.IUniverInstanceService),r=o.get(I.IRenderManagerService),{unitId:i,segmentId:s,createType:c,headerFooterProps:l}=e,h=(M=r.getRenderById(i))==null?void 0:M.with(d.DocSkeletonManagerService),m=n.getUniverDocInstance(i),_=h==null?void 0:h.getViewModel();if(m==null||_==null)return!1;const f=_.getEditArea(),{documentStyle:u}=m.getSnapshot(),v=(l==null?void 0:l.marginFooter)!=null||(l==null?void 0:l.marginHeader)!=null,p=[{startOffset:0,endOffset:0,collapsed:!0}],S={id:d.RichTextEditingMutation.id,params:{unitId:i,actions:[],textRanges:p,debounce:!0}};v&&(S.params.noNeedSetTextRange=!0);const C=a.JSONX.getInstance(),O=[];return c!=null&&ge(s,c,u,O),l!=null&&Object.keys(l).forEach(b=>{const D=l[b],N=u[b];if(D===N)return;let P;if(N===void 0?P=C.insertOp(["documentStyle",b],D):P=C.replaceOp(["documentStyle",b],N,D),O.push(P),b==="useFirstPageHeaderFooter"&&D===a.BooleanNumber.TRUE&&!u.firstPageHeaderId){const F=f===I.DocumentEditArea.HEADER?x.FIRST_PAGE_HEADER:x.FIRST_PAGE_FOOTER;ge(s,F,u,O)}else if(b==="evenAndOddHeaders"&&D===a.BooleanNumber.TRUE&&!u.evenPageHeaderId){const F=f===I.DocumentEditArea.HEADER?x.EVEN_PAGE_HEADER:x.EVEN_PAGE_FOOTER;ge(s,F,u,O)}}),O.length===0?!1:(S.params.actions=O.reduce((b,D)=>a.JSONX.compose(b,D),null),!!t.syncExecuteCommand(S.id,S.params))}},Qe={id:"doc.command.open-header-footer-panel",type:a.CommandType.COMMAND,handler:async(o,e)=>o.get(a.ICommandService).executeCommand(Je.id,{value:"open"})};function on(o){const e=o.get(a.ICommandService);return{id:d.SetInlineFormatBoldCommand.id,group:g.MenuGroup.TOOLBAR_FORMAT,type:g.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",positions:[g.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const c=B(o);if(c==null)return;const l=(s=c.ts)==null?void 0:s.bl;t.next(l===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:g.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function rn(o){const e=o.get(a.ICommandService);return{id:d.SetInlineFormatItalicCommand.id,group:g.MenuGroup.TOOLBAR_FORMAT,type:g.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",positions:[g.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const c=B(o);if(c==null)return;const l=(s=c.ts)==null?void 0:s.it;t.next(l===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:g.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function sn(o){const e=o.get(a.ICommandService);return{id:d.SetInlineFormatUnderlineCommand.id,group:g.MenuGroup.TOOLBAR_FORMAT,type:g.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",positions:[g.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const c=B(o);if(c==null)return;const l=(s=c.ts)==null?void 0:s.ul;t.next((l==null?void 0:l.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:g.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function an(o){const e=o.get(a.ICommandService);return{id:d.SetInlineFormatStrikethroughCommand.id,group:g.MenuGroup.TOOLBAR_FORMAT,type:g.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",positions:[g.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const c=B(o);if(c==null)return;const l=(s=c.ts)==null?void 0:s.st;t.next((l==null?void 0:l.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:g.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function cn(o){const e=o.get(a.ICommandService);return{id:d.SetInlineFormatSubscriptCommand.id,group:g.MenuGroup.TOOLBAR_FORMAT,type:g.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",positions:[g.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const c=B(o);if(c==null)return;const l=(s=c.ts)==null?void 0:s.va;t.next(l===a.BaselineOffset.SUBSCRIPT)}});return t.next(!1),n.dispose}),hidden$:g.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function ln(o){const e=o.get(a.ICommandService);return{id:d.SetInlineFormatSuperscriptCommand.id,group:g.MenuGroup.TOOLBAR_FORMAT,type:g.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",positions:[g.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const c=B(o);if(c==null)return;const l=(s=c.ts)==null?void 0:s.va;t.next(l===a.BaselineOffset.SUPERSCRIPT)}});return t.next(!1),n.dispose}),hidden$:g.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function dn(o){const e=o.get(a.ICommandService);return{id:d.SetInlineFormatFontFamilyCommand.id,tooltip:"toolbar.font",group:g.MenuGroup.TOOLBAR_FORMAT,type:g.MenuItemType.SELECTOR,label:Ye,positions:[g.MenuPosition.TOOLBAR_START],selections:g.FONT_FAMILY_LIST.map(t=>({label:{name:ze,hoverable:!0},value:t.value})),value$:new T.Observable(t=>{const n=g.FONT_FAMILY_LIST[0].value,r=e.onCommandExecuted(i=>{var c;const s=i.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontFamilyCommand.id){const l=B(o);if(l==null)return;const h=(c=l.ts)==null?void 0:c.ff;t.next(h!=null?h:n)}});return t.next(n),r.dispose}),hidden$:g.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function un(o){const e=o.get(a.ICommandService);return{id:d.SetInlineFormatFontSizeCommand.id,group:g.MenuGroup.TOOLBAR_FORMAT,type:g.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Ke,props:{min:1,max:400}},positions:[g.MenuPosition.TOOLBAR_START],selections:g.FONT_SIZE_LIST,value$:new T.Observable(t=>{const r=e.onCommandExecuted(i=>{var c;const s=i.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontSizeCommand.id){const l=B(o);if(l==null)return;const h=(c=l.ts)==null?void 0:c.fs;t.next(h!=null?h:14)}});return t.next(14),r.dispose}),hidden$:g.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function gn(o){const e=o.get(a.ICommandService),t=o.get(a.ThemeService);return{id:d.SetInlineFormatTextColorCommand.id,icon:"FontColor",tooltip:"toolbar.textColor.main",group:g.MenuGroup.TOOLBAR_FORMAT,type:g.MenuItemType.BUTTON_SELECTOR,positions:[g.MenuPosition.TOOLBAR_START],selections:[{label:{name:Ie,hoverable:!1}}],value$:new T.Observable(n=>{const r=t.getCurrentTheme().textColor,i=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextColorCommand.id){const c=s.params.value;n.next(c!=null?c:r)}});return n.next(r),i.dispose}),hidden$:g.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function hn(o){return{id:Qe.id,group:g.MenuGroup.TOOLBAR_OTHERS,type:g.MenuItemType.BUTTON,icon:"FreezeRowSingle",tooltip:"toolbar.headerFooter",positions:[g.MenuPosition.TOOLBAR_START],hidden$:T.combineLatest(g.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),g.getHeaderFooterMenuHiddenObservable(o),(e,t)=>e||t)}}function pn(o){const e=o.get(a.ICommandService);return{id:d.AlignLeftCommand.id,group:g.MenuGroup.TOOLBAR_LAYOUT,type:g.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",positions:[g.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.AlignOperationCommand.id){const c=ce(o);if(c==null)return;const l=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(l===a.HorizontalAlign.LEFT)}});return t.next(!1),n.dispose}),hidden$:g.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function mn(o){const e=o.get(a.ICommandService);return{id:d.AlignCenterCommand.id,group:g.MenuGroup.TOOLBAR_LAYOUT,type:g.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",positions:[g.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.AlignOperationCommand.id){const c=ce(o);if(c==null)return;const l=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(l===a.HorizontalAlign.CENTER)}});return t.next(!1),n.dispose}),hidden$:g.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function _n(o){const e=o.get(a.ICommandService);return{id:d.AlignRightCommand.id,group:g.MenuGroup.TOOLBAR_LAYOUT,type:g.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",positions:[g.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.AlignOperationCommand.id){const c=ce(o);if(c==null)return;const l=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(l===a.HorizontalAlign.RIGHT)}});return t.next(!1),n.dispose}),hidden$:g.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function fn(o){const e=o.get(a.ICommandService);return{id:d.AlignJustifyCommand.id,group:g.MenuGroup.TOOLBAR_LAYOUT,type:g.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",positions:[g.MenuPosition.TOOLBAR_START],activated$:new T.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.AlignOperationCommand.id){const c=ce(o);if(c==null)return;const l=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(l===a.HorizontalAlign.JUSTIFIED)}});return t.next(!1),n.dispose}),hidden$:g.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function Sn(o){return{id:d.OrderListCommand.id,group:g.MenuGroup.TOOLBAR_LAYOUT,type:g.MenuItemType.BUTTON,icon:"OrderSingle",tooltip:"toolbar.order",positions:[g.MenuPosition.TOOLBAR_START],hidden$:g.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function vn(o){return{id:d.BulletListCommand.id,group:g.MenuGroup.TOOLBAR_LAYOUT,type:g.MenuItemType.BUTTON,icon:"UnorderSingle",tooltip:"toolbar.unorder",positions:[g.MenuPosition.TOOLBAR_START],hidden$:g.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function In(o){return{id:d.ResetInlineFormatTextBackgroundColorCommand.id,type:g.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:d.SetInlineFormatTextBackgroundColorCommand.id}}function Cn(o){const e=o.get(a.ICommandService),t=o.get(a.ThemeService);return{id:d.SetInlineFormatTextBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",group:g.MenuGroup.TOOLBAR_FORMAT,type:g.MenuItemType.BUTTON_SELECTOR,positions:[g.MenuPosition.TOOLBAR_START],icon:"PaintBucket",selections:[{label:{name:Ie,hoverable:!1}}],value$:new T.Observable(n=>{const r=t.getCurrentTheme().primaryColor,i=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextBackgroundColorCommand.id){const c=s.params.value;n.next(c!=null?c:r)}});return n.next(r),i.dispose}),hidden$:g.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function B(o){var h;const e=o.get(a.IUniverInstanceService),t=o.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const{startOffset:i,segmentId:s}=r,c=(h=n.getSelfOrHeaderFooterModel(s).getBody())==null?void 0:h.textRuns;if(c==null)return;let l;for(let m=0;m<c.length;m++){const _=c[m],f=c[m+1];if(f&&f.st===f.ed&&i===f.st){l=f;break}if(_.st<=i&&i<=_.ed){l=_;break}}return l}function ce(o){var h;const e=o.get(a.IUniverInstanceService),t=o.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const{startOffset:i,segmentId:s}=r,c=(h=n.getSelfOrHeaderFooterModel(s).getBody())==null?void 0:h.paragraphs;if(c==null)return;let l=-1;for(const m of c){const{startIndex:_}=m;if(i>l&&i<=_)return m;l=_}return null}var On=Object.defineProperty,Tn=Object.getOwnPropertyDescriptor,Rn=(o,e,t,n)=>{for(var r=n>1?void 0:n?Tn(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&On(e,t,r),r},J=(o,e)=>(t,n)=>e(t,n,o);let K=class extends a.Disposable{constructor(o,e,t,n,r){super(),this._config=o,this._injector=e,this._componentManager=t,this._layoutService=n,this._menuService=r,this._init()}_initCustomComponents(){const o=this._componentManager;this.disposeWithMe(o.register(Ie,H.ColorPicker)),this.disposeWithMe(o.register(Ye,g.FontFamily)),this.disposeWithMe(o.register(ze,g.FontFamilyItem)),this.disposeWithMe(o.register(Ke,g.FontSize))}_initMenus(){const{menu:o={}}=this._config;[on,rn,sn,an,cn,ln,un,dn,gn,hn,pn,mn,_n,fn,Sn,vn,In,Cn].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e),o))})}_init(){this._initCustomComponents(),this._initMenus(),this._initFocusHandler()}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.UNIVER_DOC,()=>{this._injector.get(I.ITextSelectionRenderManager).focus()}))}};K=Rn([a.OnLifecycle(a.LifecycleStages.Rendered,K),J(1,a.Inject(a.Injector)),J(2,a.Inject(g.ComponentManager)),J(3,g.ILayoutService),J(4,g.IMenuService)],K);const En={id:d.BreakLineCommand.id,preconditions:st,binding:g.KeyCode.ENTER},bn={id:d.DeleteLeftCommand.id,preconditions:U,binding:g.KeyCode.BACKSPACE},Mn={id:d.DeleteRightCommand.id,preconditions:U,binding:g.KeyCode.DELETE};function le(o){return o.getContextValue(a.FOCUSING_DOC)||o.getContextValue(a.EDITOR_ACTIVATED)}const Ce=999,et={id:g.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:Ce,preconditions:le,handler:async o=>o.get(j).copy()},tt={id:g.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:Ce,preconditions:le,handler:async o=>o.get(j).cut()},nt={id:g.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:Ce,preconditions:le,handler:async o=>{const e=o.get(j),n=await o.get(g.IClipboardInterfaceService).read();return n.length===0?!1:e.paste(n)}};var yn=Object.defineProperty,Dn=Object.getOwnPropertyDescriptor,Pn=(o,e,t,n)=>{for(var r=n>1?void 0:n?Dn(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&yn(e,t,r),r},W=(o,e)=>(t,n)=>e(t,n,o);let ne=class extends a.RxDisposable{constructor(o,e,t,n,r){super(),this._commandService=o,this._clipboardInterfaceService=e,this._docClipboardService=t,this._textSelectionRenderManager=n,this._contextService=r,this._init()}_init(){[et,tt,nt].forEach(o=>this.disposeWithMe(this._commandService.registerMultipleCommand(o))),[d.InnerPasteCommand,d.CutContentCommand].forEach(o=>this.disposeWithMe(this._commandService.registerCommand(o))),this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var o;(o=this._textSelectionRenderManager)==null||o.onPaste$.pipe(T.takeUntil(this.dispose$)).subscribe(e=>{var i,s;if(!le(this._contextService))return;e.event.preventDefault();const t=e.event,n=(i=t.clipboardData)==null?void 0:i.getData("text/html"),r=(s=t.clipboardData)==null?void 0:s.getData("text/plain");this._docClipboardService.legacyPaste(n,r)})}};ne=Pn([a.OnLifecycle(a.LifecycleStages.Rendered,ne),W(0,a.ICommandService),W(1,g.IClipboardInterfaceService),W(2,j),W(3,I.ITextSelectionRenderManager),W(4,a.IContextService)],ne);var xn=Object.defineProperty,An=Object.getOwnPropertyDescriptor,Nn=(o,e,t,n)=>{for(var r=n>1?void 0:n?An(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&xn(e,t,r),r},k=(o,e)=>(t,n)=>e(t,n,o);let oe=class extends a.Disposable{constructor(e,t,n,r,i){super();R(this,"_initialEditors",new Set);this._univerInstanceService=e,this._editorService=t,this._commandService=n,this._textSelectionRenderManager=r,this._renderManagerService=i,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 E,M,b;if(e==null)return;const t=this._editorService.getEditor(e);if((t==null?void 0:t.cancelDefaultResizeListener)===!0)return;const n=this._univerInstanceService.getUniverDocInstance(e);if(!n)return;const r=(E=this._renderManagerService.getRenderById(n.getUnitId()))==null?void 0:E.with(d.DocSkeletonManagerService).getSkeleton();if(t==null||t.render==null||r==null||n==null)return;r.calculate();const{marginTop:i=0,marginBottom:s=0,marginLeft:c=0,marginRight:l=0}=n.getSnapshot().documentStyle,{scene:h,mainComponent:m}=t.render;let{actualHeight:_,actualWidth:f}=r.getActualSize();_+=i+s,f+=c+l;const{width:u,height:v}=t.getBoundingClientRect(),p=h.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);let S=p==null?void 0:p.getScrollBar();const C=Math.max(f,u),O=Math.max(_,v);h.transformByState({width:C,height:O}),m==null||m.resize(C,O),t.isSingle()?f>u?S==null?p&&new I.ScrollBar(p,{barSize:8,enableVertical:!1}):p==null||p.resetCanvasSizeAndUpdateScrollBar():(S=null,p==null||p.scrollTo({x:0,y:0}),(b=p==null?void 0:p.getScrollBar())==null||b.dispose()):_>v?S==null?p&&new I.ScrollBar(p,{enableHorizontal:!1,barSize:8}):p==null||p.resetCanvasSizeAndUpdateScrollBar():(S=null,p==null||p.scrollTo({x:0,y:0}),(M=p==null?void 0:p.getScrollBar())==null||M.dispose())}_initialSetValue(){this.disposeWithMe(this._editorService.setValue$.subscribe(e=>{this._commandService.executeCommand(d.CoverContentCommand.id,{unitId:e.editorUnitId,body:e.body,segmentId:null})}))}_initialBlur(){this.disposeWithMe(this._editorService.blur$.subscribe(()=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.blur()})),this.disposeWithMe(this._textSelectionRenderManager.onBlur$.subscribe(()=>{var r;const e=(r=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:r.getUnitId();if(e==null)return;const t=this._editorService.getEditor(e),n=this._editorService.getFocusEditor();t==null||t.isSheetEditor()||n&&n.editorUnitId===e||this._editorService.blur()}))}_initialFocus(){this.disposeWithMe(this._editorService.focus$.subscribe(n=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges([n])}));const e=["univer-formula-search","univer-formula-help","formula-help-decorator","univer-formula-help-param"];this.disposeWithMe(T.fromEvent(window,"mousedown").subscribe(n=>{const i=n.target.classList[0]||"";if(a.checkForSubstrings(i,e)){this._editorService.changeSpreadsheetFocusState(!0),n.stopPropagation();return}this._editorService.changeSpreadsheetFocusState(!1)})),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(n=>{const r=n.getUnitId(),i=this._renderManagerService.getRenderById(r),s=i==null?void 0:i.engine.getCanvas().getCanvasEle();s!=null&&T.fromEvent(s,"mousedown").subscribe(c=>{this._editorService.changeSpreadsheetFocusState(!0),c.stopPropagation()})})}_initialValueChange(){this.disposeWithMe(this._textSelectionRenderManager.onCompositionupdate$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onInput$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onKeydown$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onPaste$.subscribe(this._valueChange.bind(this)))}_valueChange(){var n;const e=(n=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:n.getUnitId();if(e==null)return;const t=this._editorService.getEditor(e);t==null||t.isSheetEditor()||this._editorService.refreshValueChange(e)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,g.SetEditorResizeOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=t.params,{unitId:r}=n;if(this._editorService.isSheetEditor(r))return;this._resize(r),this._valueChange()}}))}};oe=Nn([a.OnLifecycle(a.LifecycleStages.Rendered,oe),k(0,a.IUniverInstanceService),k(1,g.IEditorService),k(2,a.ICommandService),k(3,I.ITextSelectionRenderManager),k(4,I.IRenderManagerService)],oe);var Un=Object.defineProperty,Fn=Object.getOwnPropertyDescriptor,Ln=(o,e,t,n)=>{for(var r=n>1?void 0:n?Fn(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Un(e,t,r),r},G=(o,e)=>(t,n)=>e(t,n,o);exports.DocRenderController=class extends a.RxDisposable{constructor(e,t,n,r,i,s){super(),this._context=e,this._commandService=t,this._docSkeletonManagerService=n,this._configService=r,this._editorService=i,this._renderManagerService=s,this._addNewRender(),this._initRenderRefresh(),this._initCommandListener()}reRender(e){var i,s;const t=(i=this._renderManagerService.getRenderById(e))==null?void 0:i.with(d.DocSkeletonManagerService),n=t==null?void 0:t.getSkeleton();if(!(!n||n.getViewModel().getDataModel().getSnapshot().disabled)){if(n.calculate(),this._editorService.isEditor(e)){(s=this._context.mainComponent)==null||s.makeDirty();return}this._recalculateSizeBySkeleton(n)}}_addNewRender(){const{scene:e,engine:t,unit:n}=this._context,r=new I.Viewport(d.VIEWPORT_KEY.VIEW_MAIN,e,{left:0,top:0,bottom:0,right:0,isRelativeX:!0,isRelativeY:!0,isWheelPreventDefaultX:!0});e.attachControl(),e.onMouseWheel$.subscribeEvent((c,l)=>{const h=c;if(h.ctrlKey){const m=Math.abs(h.deltaX);let _=m<40?.2:m<80?.4:.2;_*=h.deltaY>0?-1:1,e.scaleX<1&&(_/=2),e.scaleX+_>4?e.scale(4,4):e.scaleX+_<.1?e.scale(.1,.1):h.preventDefault()}else r.onMouseWheel(h,l)}),this._configService.getConfig("hasScroll")!==!1&&new I.ScrollBar(r),e.addLayer(new I.Layer(e,[],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),new I.Layer(e,[],d.DOCS_COMPONENT_HEADER_LAYER_INDEX)),this._addComponent(),n.getShouldRenderLoopImmediately()&&t.runRenderLoop(()=>{e.render()})}_addComponent(){const{scene:e,unit:t,components:n}=this._context,r={pageMarginLeft:t.documentStyle.marginLeft||0,pageMarginTop:t.documentStyle.marginTop||0},i=new I.Documents(d.DOCS_VIEW_KEY.MAIN,void 0,r);i.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX;const s=new I.DocBackground(d.DOCS_VIEW_KEY.BACKGROUND,void 0,r);s.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX,this._context.mainComponent=i,n.set(d.DOCS_VIEW_KEY.MAIN,i),n.set(d.DOCS_VIEW_KEY.BACKGROUND,s),e.addObjects([i],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),e.addObjects([s],d.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX),this._editorService.getEditor(t.getUnitId())==null&&e.enableLayerCache(d.DOCS_COMPONENT_MAIN_LAYER_INDEX)}_initRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(T.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)})}_create(e){if(!e)return;const{mainComponent:t,components:n}=this._context,r=t,i=n.get(d.DOCS_VIEW_KEY.BACKGROUND);r.changeSkeleton(e),i.changeSkeleton(e),this._recalculateSizeBySkeleton(e)}_initCommandListener(){const e=[d.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=t.params,{unitId:r}=n;this.reRender(r)}}))}_recalculateSizeBySkeleton(e){var _;const{mainComponent:t,scene:n,unitId:r,components:i}=this._context,s=t,c=i.get(d.DOCS_VIEW_KEY.BACKGROUND),l=(_=e.getSkeletonData())==null?void 0:_.pages;if(l==null)return;let h=0,m=0;for(let f=0,u=l.length;f<u;f++){const v=l[f],{pageWidth:p,pageHeight:S}=v;s.pageLayoutType===I.PageLayoutType.VERTICAL?(m+=S,m+=s.pageMarginTop,f===u-1&&(m+=s.pageMarginTop),h=Math.max(h,p)):s.pageLayoutType===I.PageLayoutType.HORIZONTAL&&(h+=p,f!==u-1&&(h+=s.pageMarginLeft),m=Math.max(m,S))}s.resize(h,m),c.resize(h,m),this._editorService.isEditor(r)||n.resize(h,m)}};exports.DocRenderController=Ln([G(1,a.ICommandService),G(2,a.Inject(d.DocSkeletonManagerService)),G(3,a.IConfigService),G(4,g.IEditorService),G(5,I.IRenderManagerService)],exports.DocRenderController);var Bn=Object.defineProperty,wn=Object.getOwnPropertyDescriptor,$n=(o,e,t,n)=>{for(var r=n>1?void 0:n?wn(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Bn(e,t,r),r},Y=(o,e)=>(t,n)=>e(t,n,o);let fe=class extends a.Disposable{constructor(o,e,t,n,r,i){super(),this._context=o,this._docSkeletonManagerService=e,this._univerInstanceService=t,this._commandService=n,this._textSelectionManagerService=r,this._editorService=i,this._init()}_init(){this._initSkeletonListener(),this._initCommandExecutedListener(),this._initRenderRefresher(),setTimeout(()=>this._updateViewZoom(1,!0),20)}_initRenderRefresher(){this._docSkeletonManagerService.currentSkeleton$.subscribe(o=>{if(o==null)return;const{unitId:e,scene:t}=this._context;this._editorService.isEditor(e)||this.disposeWithMe(t.onMouseWheel$.subscribeEvent(n=>{if(!n.ctrlKey)return;const r=this._univerInstanceService.getCurrentUniverDocInstance();if(!r)return;const i=Math.abs(n.deltaX);let s=i<40?.2:i<80?.4:.2;s*=n.deltaY>0?-1:1,t.scaleX<1&&(s/=2);const c=r.zoomRatio;let l=+Number.parseFloat(`${c+s}`).toFixed(1);l=l>=4?4:l<=.1?.1:l,this._commandService.executeCommand(d.SetDocZoomRatioCommand.id,{zoomRatio:l,unitId:r.getUnitId()}),n.preventDefault()}))})}_initSkeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(o=>{if(o==null)return;const e=this._univerInstanceService.getCurrentUniverDocInstance();if(!e)return;const t=e.zoomRatio||1;this._updateViewZoom(t,!1)}))}_initCommandExecutedListener(){const o=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(o.includes(e.id)){const t=this._univerInstanceService.getCurrentUniverDocInstance();if(!t)return;const n=e.params,{unitId:r}=n;if(r!==t.getUnitId())return;const i=t.zoomRatio||1;this._updateViewZoom(i)}}))}_updateViewZoom(o,e=!0){var n;const t=d.neoGetDocObject(this._context);t.scene.scale(o,o),this._calculatePagePosition(t,o),e&&this._textSelectionManagerService.refreshSelection(),(n=t.scene.getTransformer())==null||n.clearSelectedObjects()}_calculatePagePosition(o,e){const{document:t,scene:n,docBackground:r}=o,i=n==null?void 0:n.getParent(),{width:s,height:c,pageMarginLeft:l,pageMarginTop:h}=t;if(i==null||s===Number.POSITIVE_INFINITY||c===Number.POSITIVE_INFINITY)return;const{width:m,height:_}=i;let f=0,u=0,v=0,p=0,S=Number.POSITIVE_INFINITY;m>(s+l*2)*e?(f=m/2-s*e/2,f/=e,v=(m-l*2)/e,S=0):(f=l,v=s+l*2,S=(v-m/e)/2),_>c?(u=_/2-c/2,p=(_-h*2)/e):(u=h,p=c+h*2),n.resize(v,p+200),t.translate(f,u),r.translate(f,u);const C=n.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(S!==Number.POSITIVE_INFINITY&&C!=null){const O=C.transViewportScroll2ScrollValue(S,0).x;C.scrollTo({x:O})}return this}};fe=$n([Y(1,a.Inject(d.DocSkeletonManagerService)),Y(2,a.IUniverInstanceService),Y(3,a.ICommandService),Y(4,a.Inject(d.TextSelectionManagerService)),Y(5,g.IEditorService)],fe);var Hn=Object.defineProperty,Vn=Object.getOwnPropertyDescriptor,jn=(o,e,t,n)=>{for(var r=n>1?void 0:n?Vn(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Hn(e,t,r),r},$=(o,e)=>(t,n)=>e(t,n,o);let Se=class extends a.Disposable{constructor(e,t,n,r,i,s,c){super();R(this,"_loadedMap",new WeakSet);this._context=e,this._commandService=t,this._editorService=n,this._instanceSrv=r,this._textSelectionRenderManager=i,this._docSkeletonManagerService=s,this._textSelectionManagerService=c,this._initialize()}_initialize(){this._init(),this._skeletonListener(),this._commandExecutedListener()}_init(){const{unitId:e}=this._context,t=d.neoGetDocObject(this._context);t==null||t.document==null||this._loadedMap.has(t.document)||(this._initialMain(e),this._loadedMap.add(t.document))}_initialMain(e){const t=d.neoGetDocObject(this._context),{document:n,scene:r}=t;this.disposeWithMe(n.onPointerEnter$.subscribeEvent(()=>{this._isEditorReadOnly(e)||(n.cursor=I.CURSOR_TYPE.TEXT)})),this.disposeWithMe(n.onPointerLeave$.subscribeEvent(()=>{n.cursor=I.CURSOR_TYPE.DEFAULT,r.resetCursor()})),this.disposeWithMe(n.onPointerDown$.subscribeEvent((i,s)=>{if(this._isEditorReadOnly(e))return;const c=this._instanceSrv.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);(c==null?void 0:c.getUnitId())!==e&&this._instanceSrv.setCurrentUnitForType(e);const l=this._docSkeletonManagerService.getSkeleton(),{offsetX:h,offsetY:m}=i,_=this._getTransformCoordForDocumentOffset(h,m);if(_!=null){const{pageLayoutType:f=I.PageLayoutType.VERTICAL,pageMarginLeft:u,pageMarginTop:v}=n.getOffsetConfig(),{editArea:p}=l.findEditAreaByCoord(_,f,u,v),S=this._docSkeletonManagerService.getViewModel(),C=S.getEditArea();C!==I.DocumentEditArea.BODY&&p!==I.DocumentEditArea.BODY&&p!==C&&S.setEditArea(p)}if(this._textSelectionRenderManager.eventTrigger(i),this._editorService.getEditor(e)){this._setEditorFocus(e);const{offsetX:f,offsetY:u}=i;setTimeout(()=>{this._setEditorFocus(e),this._textSelectionRenderManager.setCursorManually(f,u)},0)}i.button!==2&&s.stopPropagation()})),this.disposeWithMe(n.onDblclick$.subscribeEvent(i=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleDblClick(i)})),this.disposeWithMe(n.onTripleClick$.subscribeEvent(i=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleTripleClick(i)}))}_getTransformCoordForDocumentOffset(e,t){const n=d.neoGetDocObject(this._context),{document:r,scene:i}=n,{documentTransform:s}=r.getOffsetConfig(),c=i.getViewports()[0];if(c==null)return;const l=c.transformVector2SceneCoord(I.Vector2.FromArray([e,t]));return s.clone().invert().applyPoint(l)}_isEditorReadOnly(e){const t=this._editorService.getEditor(e);return t?t.isReadOnly():!1}_setEditorFocus(e){this._editorService.focusStyle(e)}_commandExecutedListener(){const e=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:i}=r,s=(n=this._textSelectionManagerService.getCurrentSelection())==null?void 0:n.unitId;if(i!==s)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{scene:t,mainComponent:n,unitId:r}=this._context;this._textSelectionRenderManager.changeRuntime(e,t,n),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:r,subUnitId:""}),a.isInternalEditorID(r)||this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}],!1)}))}};Se=jn([$(1,a.ICommandService),$(2,g.IEditorService),$(3,a.IUniverInstanceService),$(4,I.ITextSelectionRenderManager),$(5,a.Inject(d.DocSkeletonManagerService)),$(6,a.Inject(d.TextSelectionManagerService))],Se);var Wn=Object.defineProperty,kn=Object.getOwnPropertyDescriptor,Gn=(o,e,t,n)=>{for(var r=n>1?void 0:n?kn(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Wn(e,t,r),r},Q=(o,e)=>(t,n)=>e(t,n,o);function Fe(o,e){const t=Le(o.left,o.top,e),n=Le(o.right,o.bottom,e);return{left:t.x,top:t.y,right:n.x,bottom:n.y}}function Le(o,e,t){const{scaleX:n,scaleY:r}=t.getAncestorScale(),i=t.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(!i)return{x:o,y:e};const{viewportScrollX:s,viewportScrollY:c}=i,l=(o-s)*n,h=(e-c)*r;return{x:l,y:h}}exports.DocCanvasPopManagerService=class extends a.Disposable{constructor(e,t,n,r){super(),this._globalPopupManagerService=e,this._renderManagerService=t,this._univerInstanceService=n,this._commandService=r}_createObjectPositionObserver(e,t){const n=()=>{const{scene:l,engine:h}=t,{left:m,top:_,width:f,height:u}=e,v={left:m,right:m+f,top:_,bottom:_+u},p=Fe(v,l),S=h.getCanvasElement().getBoundingClientRect().top;return{left:p.left,right:p.right,top:p.top+S,bottom:p.bottom+S}},r=n(),i=new T.BehaviorSubject(r),s=new a.DisposableCollection;s.add(this._commandService.onCommandExecuted(l=>{l.id===d.SetDocZoomRatioOperation.id&&i.next(n())}));const c=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);return c&&s.add(c.onScrollAfter$.subscribeEvent(()=>{i.next(n())})),{position:r,position$:i,disposable:s}}_createRangePositionObserver(e,t){var l;const n=()=>{const{scene:h,mainComponent:m,engine:_}=t,f=t.with(d.DocSkeletonManagerService).getSkeleton(),u=f.findNodePositionByCharIndex(e.startOffset),v=f.findNodePositionByCharIndex(e.endOffset),p=m;if(!v||!u)return;const S=p.getOffsetConfig(),{docsLeft:C,docsTop:O}=S,E=_.getCanvasElement().getBoundingClientRect().top,M=new I.NodePositionConvertToCursor(S,f),{borderBoxPointGroup:b}=M.getRangePointData(u,v);return I.getLineBounding(b).map(P=>Fe(P,h)).map(P=>({left:P.left+C,right:P.right+C,top:P.top+O+E,bottom:P.bottom+O+E}))},r=(l=n())!=null?l:[],i=new T.BehaviorSubject(r),s=new a.DisposableCollection;s.add(this._commandService.onCommandExecuted(h=>{if(h.id===d.SetDocZoomRatioOperation.id){const m=n();m&&i.next(m)}}));const c=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);return c&&s.add(c.onScrollAfter$.subscribeEvent(()=>{const h=n();h&&i.next(h)})),{positions:r,positions$:i,disposable:s}}attachPopupToObject(e,t){const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC).getUnitId(),i=this._renderManagerService.getRenderById(r);if(!i)return{dispose:()=>{}};const{position:s,position$:c,disposable:l}=this._createObjectPositionObserver(e,i),h=this._globalPopupManagerService.addPopup({...t,unitId:r,subUnitId:"default",anchorRect:s,anchorRect$:c});return{dispose:()=>{this._globalPopupManagerService.removePopup(h),c.complete(),l.dispose()}}}attachPopupToRange(e,t){const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC).getUnitId(),{direction:i="top"}=t,s=this._renderManagerService.getRenderById(r);if(!s)return{dispose:()=>{}};const{positions:c,positions$:l,disposable:h}=this._createRangePositionObserver(e,s),m=l.pipe(T.map(f=>i==="top"?f[0]:f[f.length-1])),_=this._globalPopupManagerService.addPopup({...t,unitId:r,subUnitId:"default",anchorRect:i==="top"?c[0]:c[c.length-1],anchorRect$:m,excludeRects:c,excludeRects$:l,direction:i==="top"?"top":"bottom"});return{dispose:()=>{this._globalPopupManagerService.removePopup(_),l.complete(),h.dispose()}}}};exports.DocCanvasPopManagerService=Gn([Q(0,a.Inject(g.ICanvasPopupService)),Q(1,I.IRenderManagerService),Q(2,a.IUniverInstanceService),Q(3,a.ICommandService)],exports.DocCanvasPopManagerService);var Yn=Object.defineProperty,zn=Object.getOwnPropertyDescriptor,Kn=(o,e,t,n)=>{for(var r=n>1?void 0:n?zn(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Yn(e,t,r),r},Be=(o,e)=>(t,n)=>e(t,n,o);exports.DocsRenderService=class extends a.RxDisposable{constructor(e,t){super(),this._instanceSrv=e,this._renderManagerService=t,this._init()}_init(){this._renderManagerService.createRender$.pipe(T.takeUntil(this.dispose$)).subscribe(e=>this._createRenderWithId(e)),this._instanceSrv.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_DOC).pipe(T.takeUntil(this.dispose$)).subscribe(e=>this._createRenderer(e)),this._instanceSrv.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC).forEach(e=>this._createRenderer(e)),this._instanceSrv.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_DOC).pipe(T.takeUntil(this.dispose$)).subscribe(e=>this._disposeRenderer(e))}_createRenderer(e){const t=e.getUnitId();this._renderManagerService.has(t)||(this._createRenderWithId(t),this._renderManagerService.setCurrent(t))}_createRenderWithId(e){this._renderManagerService.createRender(e)}_disposeRenderer(e){const t=e.getUnitId();this._renderManagerService.removeRender(t)}};exports.DocsRenderService=Kn([a.OnLifecycle(a.LifecycleStages.Ready,exports.DocsRenderService),Be(0,a.IUniverInstanceService),Be(1,I.IRenderManagerService)],exports.DocsRenderService);var Xn=Object.defineProperty,Zn=Object.getOwnPropertyDescriptor,qn=(o,e,t,n)=>{for(var r=n>1?void 0:n?Zn(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Xn(e,t,r),r},he=(o,e)=>(t,n)=>e(t,n,o),ee;exports.UniverDocsUIPlugin=(ee=class extends a.Plugin{constructor(e,t,n,r){super(),this._config=e,this._injector=t,this._renderManagerSrv=n,this._logService=r,this._config=a.Tools.deepMerge({},ke,this._config),this._initDependencies(t),this._initializeCommands()}onReady(){this._initRenderBasics()}onRendered(){this._initUI(),this._initRenderModules(),this._markDocAsFocused()}_initializeCommands(){[Tt,Rt,bt,Et,Mt,yt,Dt,Pt,xt,bn,Mn,En].forEach(e=>{this._injector.get(g.IShortcutService).registerShortcut(e)})}_initDependencies(e){[[K,{useFactory:()=>this._injector.createInstance(K,this._config)}],[ne],[oe],[exports.DocsRenderService],[z,{useFactory:()=>this._injector.createInstance(z,this._config)}],[j,{useClass:pe}],[exports.DocCanvasPopManagerService]].forEach(n=>e.add(n))}_markDocAsFocused(){const e=this._injector.get(a.IUniverInstanceService),t=this._injector.get(g.IEditorService);try{const n=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(!n)return;const r=n.getUnitId();t.isEditor(r)||e.focusUnit(n.getUnitId())}catch(n){this._logService.warn(n)}}_initUI(){this._injector.get(z)}_initRenderBasics(){[[d.DocSkeletonManagerService],[d.DocInterceptorService],[exports.DocRenderController],[fe]].forEach(e=>{this._renderManagerSrv.registerRenderModule(a.UniverInstanceType.UNIVER_DOC,e)})}_initRenderModules(){[[exports.DocBackScrollRenderController],[Se],[_e]].forEach(e=>{this._renderManagerSrv.registerRenderModule(a.UniverInstanceType.UNIVER_DOC,e)})}},R(ee,"pluginName",Ge),R(ee,"type",a.UniverInstanceType.UNIVER_DOC),ee);exports.UniverDocsUIPlugin=qn([he(1,a.Inject(a.Injector)),he(2,I.IRenderManagerService),he(3,a.ILogService)],exports.UniverDocsUIPlugin);function Jn(o){return{left:o.positionH.posOffset,top:o.positionV.posOffset,width:o.size.width,height:o.size.height}}function Qn(o,e=0,t=0){return{size:{width:o.width,height:o.height},positionH:{relativeFrom:a.ObjectRelativeFromH.MARGIN,posOffset:(o.left||0)-e},positionV:{relativeFrom:a.ObjectRelativeFromV.PAGE,posOffset:(o.top||0)-t},angle:o.angle||0}}exports.DOC_UI_PLUGIN_NAME=Ge;exports.DefaultDocContainerConfig=We;exports.DefaultDocUiConfig=ke;exports.DefaultToolbarConfig=je;exports.DocCopyCommand=et;exports.DocCutCommand=tt;exports.DocPasteCommand=nt;exports.IDocClipboardService=j;exports.PastePluginLark=we;exports.PastePluginUniver=Ve;exports.PastePluginWord=He;exports.docDrawingPositionToTransform=Jn;exports.transformToDocDrawingPosition=Qn;exports.whenDocAndEditorFocused=U;
10
+ */var jt=q,Wt=Symbol.for("react.element"),kt=Symbol.for("react.fragment"),Gt=Object.prototype.hasOwnProperty,Yt=jt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,zt={key:!0,ref:!0,__self:!0,__source:!0};function Qe(o,e,t){var n,r={},i=null,s=null;t!==void 0&&(i=""+t),e.key!==void 0&&(i=""+e.key),e.ref!==void 0&&(s=e.ref);for(n in e)Gt.call(e,n)&&!zt.hasOwnProperty(n)&&(r[n]=e[n]);if(o&&o.defaultProps)for(n in e=o.defaultProps,e)r[n]===void 0&&(r[n]=e[n]);return{$$typeof:Wt,type:o,key:i,ref:s,props:r,_owner:Yt.current}}le.Fragment=kt;le.jsx=Qe;le.jsxs=Qe;Je.exports=le;var D=Je.exports;const Kt="univer-panel",Xt="univer-options-section",Zt="univer-options-form-item",qt="univer-options-input",Jt="univer-options-margin-setting",N={panel:Kt,optionsSection:Xt,optionsFormItem:Zt,optionsInput:qt,optionsMarginSetting:Jt},Qt=o=>{const e=L.useDependency(a.LocaleService),t=L.useDependency(a.IUniverInstanceService),n=L.useDependency(I.IRenderManagerService),r=L.useDependency(a.ICommandService),i=L.useDependency(I.ITextSelectionRenderManager),s=L.useDependency(d.TextSelectionManagerService),{unitId:c}=o,[l,h]=q.useState({}),m=(g,v)=>{var U;h(x=>({...x,[v]:g?a.BooleanNumber.TRUE:a.BooleanNumber.FALSE}));const p=t.getUniverDocInstance(c),S=p==null?void 0:p.getSnapshot().documentStyle,C=(U=n.getRenderById(c))==null?void 0:U.with(d.DocSkeletonManagerService),O=C==null?void 0:C.getViewModel();if(S==null||O==null)return;const E=O.getEditArea();let b=!1;const y=i.getSegmentPage();let P=!1;if(v==="useFirstPageHeaderFooter"&&g===!0&&((E===I.DocumentEditArea.HEADER&&!S.firstPageHeaderId||E===I.DocumentEditArea.FOOTER&&!S.firstPageFooterId)&&(b=!0),b&&y===0&&(P=!0)),v==="evenAndOddHeaders"&&g===!0&&((E===I.DocumentEditArea.HEADER&&!S.evenPageHeaderId||E===I.DocumentEditArea.FOOTER&&!S.evenPageFooterId)&&(b=!0),b&&y%2===1&&(P=!0)),b){const B=a.Tools.generateRandomId(6);P&&i.setSegment(B),r.executeCommand(oe,{unitId:c,segmentId:B,headerFooterProps:{[v]:g?a.BooleanNumber.TRUE:a.BooleanNumber.FALSE}})}else r.executeCommand(oe,{unitId:c,headerFooterProps:{[v]:g?a.BooleanNumber.TRUE:a.BooleanNumber.FALSE}})},_=async(g,v)=>{h(p=>({...p,[v]:g})),await r.executeCommand(oe,{unitId:c,headerFooterProps:{[v]:g}}),i.removeAllTextRanges(),i.blur()},f=()=>{var b;const g=n.getRenderById(c);if(g==null)return;const{scene:v}=g,p=v.getTransformerByCreate(),S=g.with(d.DocSkeletonManagerService),C=S==null?void 0:S.getSkeleton(),O=S==null?void 0:S.getViewModel(),E=n.getRenderById(c);E==null||O==null||C==null||(s.replaceTextRanges([]),p.clearSelectedObjects(),i.setSegment(""),i.setSegmentPage(-1),O.setEditArea(I.DocumentEditArea.BODY),C.calculate(),(b=E.mainComponent)==null||b.makeDirty(!0))};return q.useEffect(()=>{const g=t.getUniverDocInstance(c),v=g==null?void 0:g.getSnapshot().documentStyle;if(v){const{marginHeader:p,marginFooter:S,useFirstPageHeaderFooter:C,evenAndOddHeaders:O}=v;h({marginHeader:p,marginFooter:S,useFirstPageHeaderFooter:C,evenAndOddHeaders:O})}},[c]),D.jsxs("div",{className:N.options,children:[D.jsxs("div",{className:N.optionsSection,children:[D.jsx("div",{className:N.optionsFormItem,children:D.jsx(j.Checkbox,{checked:l.useFirstPageHeaderFooter===a.BooleanNumber.TRUE,onChange:g=>{m(g,"useFirstPageHeaderFooter")},children:e.t("headerFooter.firstPageCheckBox")})}),D.jsx("div",{className:N.optionsFormItem,children:D.jsx(j.Checkbox,{checked:l.evenAndOddHeaders===a.BooleanNumber.TRUE,onChange:g=>{m(g,"evenAndOddHeaders")},children:e.t("headerFooter.oddEvenCheckBox")})})]}),D.jsxs("div",{className:at(N.optionsSection,N.optionsMarginSetting),children:[D.jsxs("div",{className:N.optionsMarginItem,children:[D.jsx("span",{children:e.t("headerFooter.headerTopMargin")}),D.jsx(j.InputNumber,{min:0,max:200,precision:1,value:l.marginHeader,onChange:g=>{_(g,"marginHeader")},className:N.optionsInput})]}),D.jsxs("div",{className:N.optionsMarginItem,children:[D.jsx("span",{children:e.t("headerFooter.footerBottomMargin")}),D.jsx(j.InputNumber,{min:0,max:200,precision:1,value:l.marginFooter,onChange:g=>{_(g,"marginFooter")},className:N.optionsInput})]})]}),D.jsx("div",{className:N.optionsSection,children:D.jsx(j.Button,{onClick:f,children:e.t("headerFooter.closeHeaderFooter")})})]})},en=()=>{var h;const o=L.useDependency(a.LocaleService),e=L.useDependency(I.IRenderManagerService),r=L.useDependency(a.IUniverInstanceService).getCurrentUniverDocInstance().getUnitId(),s=((h=e.getRenderById(r))==null?void 0:h.with(d.DocSkeletonManagerService)).getViewModel(),[c,l]=q.useState(!0);return q.useEffect(()=>{const m=s.getEditArea();l(m!==I.DocumentEditArea.BODY);const _=s.editAreaChange$.subscribe(f=>{f!=null&&l(f!==I.DocumentEditArea.BODY)});return()=>{_.unsubscribe()}},[]),D.jsx("div",{className:N.panel,children:c?D.jsx(Qt,{unitId:r}):D.jsx("div",{className:N.panelDisableText,children:o.t("headerFooter.disableText")})})},et={id:"sidebar.operation.doc-header-footer-panel",type:a.CommandType.COMMAND,handler:async(o,e)=>{const t=o.get(u.ISidebarService),n=o.get(a.LocaleService);switch(e.value){case"open":t.open({header:{title:n.t("headerFooter.panel")},children:{label:qe},onClose:()=>{},width:400});break;case"close":default:t.close();break}return!0}};var tn=Object.defineProperty,nn=Object.getOwnPropertyDescriptor,on=(o,e,t,n)=>{for(var r=n>1?void 0:n?nn(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&tn(e,t,r),r},w=(o,e)=>(t,n)=>e(t,n,o);const Ne="rgba(58, 96, 247, 1)",Ue="rgba(58, 96, 247, 0.08)";var A=(o=>(o[o.FIRST_PAGE_HEADER=0]="FIRST_PAGE_HEADER",o[o.FIRST_PAGE_FOOTER=1]="FIRST_PAGE_FOOTER",o[o.DEFAULT_HEADER=2]="DEFAULT_HEADER",o[o.DEFAULT_FOOTER=3]="DEFAULT_FOOTER",o[o.EVEN_PAGE_HEADER=4]="EVEN_PAGE_HEADER",o[o.EVEN_PAGE_FOOTER=5]="EVEN_PAGE_FOOTER",o))(A||{});function rn(o,e,t){const{documentStyle:n}=o.getDataModel().getSnapshot(),{defaultHeaderId:r,defaultFooterId:i,evenPageHeaderId:s,evenPageFooterId:c,firstPageHeaderId:l,firstPageFooterId:h,evenAndOddHeaders:m,useFirstPageHeaderFooter:_}=n;switch(e){case I.DocumentEditArea.BODY:return{createType:null,headerFooterId:null};case I.DocumentEditArea.HEADER:return _===a.BooleanNumber.TRUE&&!l?{createType:0,headerFooterId:null}:m===a.BooleanNumber.TRUE&&t%2===0&&!s?{createType:4,headerFooterId:null}:r?{createType:null,headerFooterId:r}:{createType:2,headerFooterId:null};case I.DocumentEditArea.FOOTER:return _===a.BooleanNumber.TRUE&&!h?{createType:1,headerFooterId:null}:m===a.BooleanNumber.TRUE&&t%2===0&&!c?{createType:5,headerFooterId:null}:i?{createType:null,headerFooterId:i}:{createType:3,headerFooterId:null};default:throw new Error(`Invalid editArea: ${e}`)}}let Se=class extends a.Disposable{constructor(e,t,n,r,i,s,c,l,h){super();M(this,"_loadedMap",new WeakSet);this._context=e,this._commandService=t,this._editorService=n,this._instanceSrv=r,this._renderManagerService=i,this._docSkeletonManagerService=s,this._textSelectionRenderManager=c,this._localeService=l,this._componentManager=h,this._initialize()}_initialize(){this._context.unit.getSnapshot().documentStyle.documentFlavor===a.DocumentFlavor.TRADITIONAL&&(this._init(),this._drawHeaderFooterLabel(),this._registerCommands(),this._initCustomComponents())}_registerCommands(){[Le,tt,et].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initCustomComponents(){const e=this._componentManager;this.disposeWithMe(e.register(qe,en))}_init(){const{unitId:e}=this._context,t=d.neoGetDocObject(this._context);t==null||t.document==null||this._loadedMap.has(t.document)||(this._initialMain(e),this._loadedMap.add(t.document))}_initialMain(e){const t=d.neoGetDocObject(this._context),{document:n}=t;this.disposeWithMe(n.onDblclick$.subscribeEvent(async r=>{if(this._isEditorReadOnly(e))return;const{offsetX:i,offsetY:s}=r,{pageLayoutType:c=I.PageLayoutType.VERTICAL,pageMarginLeft:l,pageMarginTop:h}=n.getOffsetConfig(),m=this._getTransformCoordForDocumentOffset(i,s);if(m==null)return;const _=this._docSkeletonManagerService.getViewModel(),f=this._docSkeletonManagerService.getSkeleton(),g=_.getEditArea(),{editArea:v,pageNumber:p}=f.findEditAreaByCoord(m,c,l,h);if(g===v)return;_.setEditArea(v);const{createType:S,headerFooterId:C}=rn(_,v,p);if(v===I.DocumentEditArea.BODY)this._textSelectionRenderManager.setSegment(""),this._textSelectionRenderManager.setSegmentPage(-1),this._textSelectionRenderManager.setCursorManually(i,s);else if(S!=null){const E=a.Tools.generateRandomId(6);this._textSelectionRenderManager.setSegment(E),this._textSelectionRenderManager.setSegmentPage(p),await this._commandService.executeCommand(Le.id,{unitId:e,createType:S,segmentId:E})}else C!=null&&(this._textSelectionRenderManager.setSegment(C),this._textSelectionRenderManager.setSegmentPage(p),this._textSelectionRenderManager.setCursorManually(i,s))}))}_getTransformCoordForDocumentOffset(e,t){const n=d.neoGetDocObject(this._context),{document:r,scene:i}=n,{documentTransform:s}=r.getOffsetConfig(),c=i.getViewports()[0];if(c==null)return;const l=c.transformVector2SceneCoord(I.Vector2.FromArray([e,t]));return s.clone().invert().applyPoint(l)}_drawHeaderFooterLabel(){const e=this._localeService;this._renderManagerService.currentRender$.subscribe(t=>{if(t==null)return;const n=this._renderManagerService.getRenderById(t);if(this._editorService.isEditor(t)||this._instanceSrv.getUniverDocInstance(t)==null||n==null)return;const{mainComponent:r}=n,i=r;this.disposeWithMe(a.toDisposable(i.pageRender$.subscribe(s=>{if(this._editorService.isEditor(t))return;const h=this._docSkeletonManagerService.getViewModel().getEditArea()===I.DocumentEditArea.BODY,{page:m,pageLeft:_,pageTop:f,ctx:g}=s,{pageWidth:v,pageHeight:p,marginTop:S,marginBottom:C}=m;if(g.save(),g.translate(_-.5,f-.5),h?(I.Rect.drawWith(g,{left:0,top:0,width:v,height:S,fill:"rgba(255, 255, 255, 0.5)"}),g.save(),g.translate(0,p-C),I.Rect.drawWith(g,{left:0,top:0,width:v,height:C,fill:"rgba(255, 255, 255, 0.5)"}),g.restore()):(g.save(),g.translate(0,S),I.Rect.drawWith(g,{left:0,top:S,width:v,height:p-S-C,fill:"rgba(255, 255, 255, 0.5)"}),g.restore()),!h){const O={dataArray:[{command:"M",points:[0,S]},{command:"L",points:[v,S]}],strokeWidth:1,stroke:Ne},E={dataArray:[{command:"M",points:[0,p-C]},{command:"L",points:[v,p-C]}],strokeWidth:1,stroke:Ne};I.Path.drawWith(g,O),I.Path.drawWith(g,E),g.translate(0,S+1),se.drawWith(g,{text:e.t("headerFooter.header"),color:Ue}),g.translate(0,p-S-C),se.drawWith(g,{text:e.t("headerFooter.footer"),color:Ue})}g.restore()})))})}_isEditorReadOnly(e){const t=this._editorService.getEditor(e);return t?t.isReadOnly():!1}_getDocDataModel(){return this._context.unit}};Se=on([w(1,a.ICommandService),w(2,u.IEditorService),w(3,a.IUniverInstanceService),w(4,I.IRenderManagerService),w(5,T.Inject(d.DocSkeletonManagerService)),w(6,I.ITextSelectionRenderManager),w(7,T.Inject(a.LocaleService)),w(8,T.Inject(u.ComponentManager))],Se);function Fe(){return{dataStream:`\r
11
+ `,textRuns:[{st:0,ed:0,ts:{fs:9}}],customBlocks:[],paragraphs:[{startIndex:0,paragraphStyle:{spaceAbove:{v:0},lineSpacing:1.5,spaceBelow:{v:0}}}],sectionBreaks:[{startIndex:1}]}}function pe(o,e,t,n){const r=a.JSONX.getInstance(),i=6,s=o!=null?o:a.Tools.generateRandomId(i),c=e===A.DEFAULT_HEADER||e===A.FIRST_PAGE_HEADER||e===A.EVEN_PAGE_HEADER,l=r.insertOp([c?"headers":"footers",s],{[c?"headerId":"footerId"]:s,body:Fe()});n.push(l);const h=a.Tools.generateRandomId(i),m=r.insertOp([c?"footers":"headers",h],{[c?"footers":"headers"]:h,body:Fe()});n.push(m);let _="defaultHeaderId",f="defaultFooterId";switch(e){case A.DEFAULT_HEADER:_="defaultHeaderId",f="defaultFooterId";break;case A.DEFAULT_FOOTER:_="defaultFooterId",f="defaultHeaderId";break;case A.FIRST_PAGE_HEADER:_="firstPageHeaderId",f="firstPageFooterId";break;case A.FIRST_PAGE_FOOTER:_="firstPageFooterId",f="firstPageHeaderId";break;case A.EVEN_PAGE_HEADER:_="evenPageHeaderId",f="evenPageFooterId";break;case A.EVEN_PAGE_FOOTER:_="evenPageFooterId",f="evenPageHeaderId";break;default:throw new Error(`Unknown header footer type: ${e}`)}for(const[g,v]of[[_,s],[f,h]])if(t[g]!=null){const p=r.replaceOp(["documentStyle",g],t[g],v);n.push(p)}else{const p=r.insertOp(["documentStyle",g],v);n.push(p)}return n}const oe="doc.command.core-header-footer",Le={id:oe,type:a.CommandType.COMMAND,handler:async(o,e)=>{var b;const t=o.get(a.ICommandService),n=o.get(a.IUniverInstanceService),r=o.get(I.IRenderManagerService),{unitId:i,segmentId:s,createType:c,headerFooterProps:l}=e,h=(b=r.getRenderById(i))==null?void 0:b.with(d.DocSkeletonManagerService),m=n.getUniverDocInstance(i),_=h==null?void 0:h.getViewModel();if(m==null||_==null)return!1;const f=_.getEditArea(),{documentStyle:g}=m.getSnapshot(),v=(l==null?void 0:l.marginFooter)!=null||(l==null?void 0:l.marginHeader)!=null,p=[{startOffset:0,endOffset:0,collapsed:!0}],S={id:d.RichTextEditingMutation.id,params:{unitId:i,actions:[],textRanges:p,debounce:!0}};v&&(S.params.noNeedSetTextRange=!0);const C=a.JSONX.getInstance(),O=[];return c!=null&&pe(s,c,g,O),l!=null&&Object.keys(l).forEach(y=>{const P=l[y],U=g[y];if(P===U)return;let x;if(U===void 0?x=C.insertOp(["documentStyle",y],P):x=C.replaceOp(["documentStyle",y],U,P),O.push(x),y==="useFirstPageHeaderFooter"&&P===a.BooleanNumber.TRUE&&!g.firstPageHeaderId){const B=f===I.DocumentEditArea.HEADER?A.FIRST_PAGE_HEADER:A.FIRST_PAGE_FOOTER;pe(s,B,g,O)}else if(y==="evenAndOddHeaders"&&P===a.BooleanNumber.TRUE&&!g.evenPageHeaderId){const B=f===I.DocumentEditArea.HEADER?A.EVEN_PAGE_HEADER:A.EVEN_PAGE_FOOTER;pe(s,B,g,O)}}),O.length===0?!1:(S.params.actions=O.reduce((y,P)=>a.JSONX.compose(y,P),null),!!t.syncExecuteCommand(S.id,S.params))}},tt={id:"doc.command.open-header-footer-panel",type:a.CommandType.COMMAND,handler:async(o,e)=>o.get(a.ICommandService).executeCommand(et.id,{value:"open"})};function sn(o){const e=o.get(a.ICommandService);return{id:d.SetInlineFormatBoldCommand.id,group:u.MenuGroup.TOOLBAR_FORMAT,type:u.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",positions:[u.MenuPosition.TOOLBAR_START],activated$:new R.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const c=$(o);if(c==null)return;const l=(s=c.ts)==null?void 0:s.bl;t.next(l===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:u.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function an(o){const e=o.get(a.ICommandService);return{id:d.SetInlineFormatItalicCommand.id,group:u.MenuGroup.TOOLBAR_FORMAT,type:u.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",positions:[u.MenuPosition.TOOLBAR_START],activated$:new R.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const c=$(o);if(c==null)return;const l=(s=c.ts)==null?void 0:s.it;t.next(l===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:u.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function cn(o){const e=o.get(a.ICommandService);return{id:d.SetInlineFormatUnderlineCommand.id,group:u.MenuGroup.TOOLBAR_FORMAT,type:u.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",positions:[u.MenuPosition.TOOLBAR_START],activated$:new R.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const c=$(o);if(c==null)return;const l=(s=c.ts)==null?void 0:s.ul;t.next((l==null?void 0:l.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:u.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function ln(o){const e=o.get(a.ICommandService);return{id:d.SetInlineFormatStrikethroughCommand.id,group:u.MenuGroup.TOOLBAR_FORMAT,type:u.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",positions:[u.MenuPosition.TOOLBAR_START],activated$:new R.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const c=$(o);if(c==null)return;const l=(s=c.ts)==null?void 0:s.st;t.next((l==null?void 0:l.s)===a.BooleanNumber.TRUE)}});return t.next(!1),n.dispose}),hidden$:u.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function dn(o){const e=o.get(a.ICommandService);return{id:d.SetInlineFormatSubscriptCommand.id,group:u.MenuGroup.TOOLBAR_FORMAT,type:u.MenuItemType.BUTTON,icon:"SubscriptSingle",tooltip:"toolbar.subscript",positions:[u.MenuPosition.TOOLBAR_START],activated$:new R.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const c=$(o);if(c==null)return;const l=(s=c.ts)==null?void 0:s.va;t.next(l===a.BaselineOffset.SUBSCRIPT)}});return t.next(!1),n.dispose}),hidden$:u.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function un(o){const e=o.get(a.ICommandService);return{id:d.SetInlineFormatSuperscriptCommand.id,group:u.MenuGroup.TOOLBAR_FORMAT,type:u.MenuItemType.BUTTON,icon:"SuperscriptSingle",tooltip:"toolbar.superscript",positions:[u.MenuPosition.TOOLBAR_START],activated$:new R.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.SetInlineFormatCommand.id){const c=$(o);if(c==null)return;const l=(s=c.ts)==null?void 0:s.va;t.next(l===a.BaselineOffset.SUPERSCRIPT)}});return t.next(!1),n.dispose}),hidden$:u.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function gn(o){const e=o.get(a.ICommandService);return{id:d.SetInlineFormatFontFamilyCommand.id,tooltip:"toolbar.font",group:u.MenuGroup.TOOLBAR_FORMAT,type:u.MenuItemType.SELECTOR,label:Ke,positions:[u.MenuPosition.TOOLBAR_START],selections:u.FONT_FAMILY_LIST.map(t=>({label:{name:Xe,hoverable:!0},value:t.value})),value$:new R.Observable(t=>{const n=u.FONT_FAMILY_LIST[0].value,r=e.onCommandExecuted(i=>{var c;const s=i.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontFamilyCommand.id){const l=$(o);if(l==null)return;const h=(c=l.ts)==null?void 0:c.ff;t.next(h!=null?h:n)}});return t.next(n),r.dispose}),hidden$:u.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function hn(o){const e=o.get(a.ICommandService);return{id:d.SetInlineFormatFontSizeCommand.id,group:u.MenuGroup.TOOLBAR_FORMAT,type:u.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Ze,props:{min:1,max:400}},positions:[u.MenuPosition.TOOLBAR_START],selections:u.FONT_SIZE_LIST,value$:new R.Observable(t=>{const r=e.onCommandExecuted(i=>{var c;const s=i.id;if(s===d.SetTextSelectionsOperation.id||s===d.SetInlineFormatFontSizeCommand.id){const l=$(o);if(l==null)return;const h=(c=l.ts)==null?void 0:c.fs;t.next(h!=null?h:14)}});return t.next(14),r.dispose}),hidden$:u.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function pn(o){const e=o.get(a.ICommandService),t=o.get(a.ThemeService);return{id:d.SetInlineFormatTextColorCommand.id,icon:"FontColor",tooltip:"toolbar.textColor.main",group:u.MenuGroup.TOOLBAR_FORMAT,type:u.MenuItemType.BUTTON_SELECTOR,positions:[u.MenuPosition.TOOLBAR_START],selections:[{label:{name:Oe,hoverable:!1}}],value$:new R.Observable(n=>{const r=t.getCurrentTheme().textColor,i=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextColorCommand.id){const c=s.params.value;n.next(c!=null?c:r)}});return n.next(r),i.dispose}),hidden$:u.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function mn(o){return{id:tt.id,group:u.MenuGroup.TOOLBAR_OTHERS,type:u.MenuItemType.BUTTON,icon:"FreezeRowSingle",tooltip:"toolbar.headerFooter",positions:[u.MenuPosition.TOOLBAR_START],hidden$:R.combineLatest(u.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC),u.getHeaderFooterMenuHiddenObservable(o),(e,t)=>e||t)}}function _n(o){const e=o.get(a.ICommandService);return{id:d.AlignLeftCommand.id,group:u.MenuGroup.TOOLBAR_LAYOUT,type:u.MenuItemType.BUTTON,icon:"LeftJustifyingSingle",tooltip:"toolbar.alignLeft",positions:[u.MenuPosition.TOOLBAR_START],activated$:new R.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.AlignOperationCommand.id){const c=de(o);if(c==null)return;const l=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(l===a.HorizontalAlign.LEFT)}});return t.next(!1),n.dispose}),hidden$:u.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function fn(o){const e=o.get(a.ICommandService);return{id:d.AlignCenterCommand.id,group:u.MenuGroup.TOOLBAR_LAYOUT,type:u.MenuItemType.BUTTON,icon:"HorizontallySingle",tooltip:"toolbar.alignCenter",positions:[u.MenuPosition.TOOLBAR_START],activated$:new R.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.AlignOperationCommand.id){const c=de(o);if(c==null)return;const l=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(l===a.HorizontalAlign.CENTER)}});return t.next(!1),n.dispose}),hidden$:u.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function Sn(o){const e=o.get(a.ICommandService);return{id:d.AlignRightCommand.id,group:u.MenuGroup.TOOLBAR_LAYOUT,type:u.MenuItemType.BUTTON,icon:"RightJustifyingSingle",tooltip:"toolbar.alignRight",positions:[u.MenuPosition.TOOLBAR_START],activated$:new R.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.AlignOperationCommand.id){const c=de(o);if(c==null)return;const l=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(l===a.HorizontalAlign.RIGHT)}});return t.next(!1),n.dispose}),hidden$:u.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function vn(o){const e=o.get(a.ICommandService);return{id:d.AlignJustifyCommand.id,group:u.MenuGroup.TOOLBAR_LAYOUT,type:u.MenuItemType.BUTTON,icon:"AlignTextBothSingle",tooltip:"toolbar.alignJustify",positions:[u.MenuPosition.TOOLBAR_START],activated$:new R.Observable(t=>{const n=e.onCommandExecuted(r=>{var s;const i=r.id;if(i===d.SetTextSelectionsOperation.id||i===d.AlignOperationCommand.id){const c=de(o);if(c==null)return;const l=(s=c.paragraphStyle)==null?void 0:s.horizontalAlign;t.next(l===a.HorizontalAlign.JUSTIFIED)}});return t.next(!1),n.dispose}),hidden$:u.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function In(o){return{id:d.OrderListCommand.id,group:u.MenuGroup.TOOLBAR_LAYOUT,type:u.MenuItemType.BUTTON,icon:"OrderSingle",tooltip:"toolbar.order",positions:[u.MenuPosition.TOOLBAR_START],hidden$:u.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function Cn(o){return{id:d.BulletListCommand.id,group:u.MenuGroup.TOOLBAR_LAYOUT,type:u.MenuItemType.BUTTON,icon:"UnorderSingle",tooltip:"toolbar.unorder",positions:[u.MenuPosition.TOOLBAR_START],hidden$:u.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function On(o){return{id:d.ResetInlineFormatTextBackgroundColorCommand.id,type:u.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",positions:d.SetInlineFormatTextBackgroundColorCommand.id}}function Tn(o){const e=o.get(a.ICommandService),t=o.get(a.ThemeService);return{id:d.SetInlineFormatTextBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",group:u.MenuGroup.TOOLBAR_FORMAT,type:u.MenuItemType.BUTTON_SELECTOR,positions:[u.MenuPosition.TOOLBAR_START],icon:"PaintBucket",selections:[{label:{name:Oe,hoverable:!1}}],value$:new R.Observable(n=>{const r=t.getCurrentTheme().primaryColor,i=e.onCommandExecuted(s=>{if(s.id===d.SetInlineFormatTextBackgroundColorCommand.id){const c=s.params.value;n.next(c!=null?c:r)}});return n.next(r),i.dispose}),hidden$:u.getMenuHiddenObservable(o,a.UniverInstanceType.UNIVER_DOC)}}function $(o){var h;const e=o.get(a.IUniverInstanceService),t=o.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const{startOffset:i,segmentId:s}=r,c=(h=n.getSelfOrHeaderFooterModel(s).getBody())==null?void 0:h.textRuns;if(c==null)return;let l;for(let m=0;m<c.length;m++){const _=c[m],f=c[m+1];if(f&&f.st===f.ed&&i===f.st){l=f;break}if(_.st<=i&&i<=_.ed){l=_;break}}return l}function de(o){var h;const e=o.get(a.IUniverInstanceService),t=o.get(d.TextSelectionManagerService),n=e.getCurrentUniverDocInstance(),r=t.getActiveRange();if(n==null||r==null)return;const{startOffset:i,segmentId:s}=r,c=(h=n.getSelfOrHeaderFooterModel(s).getBody())==null?void 0:h.paragraphs;if(c==null)return;let l=-1;for(const m of c){const{startIndex:_}=m;if(i>l&&i<=_)return m;l=_}return null}var Rn=Object.defineProperty,En=Object.getOwnPropertyDescriptor,bn=(o,e,t,n)=>{for(var r=n>1?void 0:n?En(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Rn(e,t,r),r},ee=(o,e)=>(t,n)=>e(t,n,o);let Z=class extends a.Disposable{constructor(o,e,t,n,r){super(),this._config=o,this._injector=e,this._componentManager=t,this._layoutService=n,this._menuService=r,this._init()}_initCustomComponents(){const o=this._componentManager;this.disposeWithMe(o.register(Oe,j.ColorPicker)),this.disposeWithMe(o.register(Ke,u.FontFamily)),this.disposeWithMe(o.register(Xe,u.FontFamilyItem)),this.disposeWithMe(o.register(Ze,u.FontSize))}_initMenus(){const{menu:o={}}=this._config;[sn,an,cn,ln,dn,un,hn,gn,pn,mn,_n,fn,Sn,vn,In,Cn,On,Tn].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e),o))})}_init(){this._initCustomComponents(),this._initMenus(),this._initFocusHandler()}_initFocusHandler(){this.disposeWithMe(this._layoutService.registerFocusHandler(a.UniverInstanceType.UNIVER_DOC,()=>{this._injector.get(I.ITextSelectionRenderManager).focus()}))}};Z=bn([a.OnLifecycle(a.LifecycleStages.Rendered,Z),ee(1,T.Inject(T.Injector)),ee(2,T.Inject(u.ComponentManager)),ee(3,u.ILayoutService),ee(4,u.IMenuService)],Z);const Mn={id:d.BreakLineCommand.id,preconditions:ct,binding:u.KeyCode.ENTER},yn={id:d.DeleteLeftCommand.id,preconditions:F,binding:u.KeyCode.BACKSPACE},Dn={id:d.DeleteRightCommand.id,preconditions:F,binding:u.KeyCode.DELETE};function ue(o){return o.getContextValue(a.FOCUSING_DOC)||o.getContextValue(a.EDITOR_ACTIVATED)}const Te=999,nt={id:u.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:Te,preconditions:ue,handler:async o=>o.get(k).copy()},ot={id:u.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:Te,preconditions:ue,handler:async o=>o.get(k).cut()},rt={id:u.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:Te,preconditions:ue,handler:async o=>{const e=o.get(k),n=await o.get(u.IClipboardInterfaceService).read();return n.length===0?!1:e.paste(n)}};var Pn=Object.defineProperty,xn=Object.getOwnPropertyDescriptor,An=(o,e,t,n)=>{for(var r=n>1?void 0:n?xn(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Pn(e,t,r),r},G=(o,e)=>(t,n)=>e(t,n,o);let re=class extends a.RxDisposable{constructor(o,e,t,n,r){super(),this._commandService=o,this._clipboardInterfaceService=e,this._docClipboardService=t,this._textSelectionRenderManager=n,this._contextService=r,this._init()}_init(){[nt,ot,rt].forEach(o=>this.disposeWithMe(this._commandService.registerMultipleCommand(o))),[d.InnerPasteCommand,d.CutContentCommand].forEach(o=>this.disposeWithMe(this._commandService.registerCommand(o))),this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var o;(o=this._textSelectionRenderManager)==null||o.onPaste$.pipe(R.takeUntil(this.dispose$)).subscribe(e=>{var i,s;if(!ue(this._contextService))return;e.event.preventDefault();const t=e.event,n=(i=t.clipboardData)==null?void 0:i.getData("text/html"),r=(s=t.clipboardData)==null?void 0:s.getData("text/plain");this._docClipboardService.legacyPaste(n,r)})}};re=An([a.OnLifecycle(a.LifecycleStages.Rendered,re),G(0,a.ICommandService),G(1,u.IClipboardInterfaceService),G(2,k),G(3,I.ITextSelectionRenderManager),G(4,a.IContextService)],re);var Nn=Object.defineProperty,Un=Object.getOwnPropertyDescriptor,Fn=(o,e,t,n)=>{for(var r=n>1?void 0:n?Un(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Nn(e,t,r),r},Y=(o,e)=>(t,n)=>e(t,n,o);let ie=class extends a.Disposable{constructor(e,t,n,r,i){super();M(this,"_initialEditors",new Set);this._univerInstanceService=e,this._editorService=t,this._commandService=n,this._textSelectionRenderManager=r,this._renderManagerService=i,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 E,b,y;if(e==null)return;const t=this._editorService.getEditor(e);if((t==null?void 0:t.cancelDefaultResizeListener)===!0)return;const n=this._univerInstanceService.getUniverDocInstance(e);if(!n)return;const r=(E=this._renderManagerService.getRenderById(n.getUnitId()))==null?void 0:E.with(d.DocSkeletonManagerService).getSkeleton();if(t==null||t.render==null||r==null||n==null)return;r.calculate();const{marginTop:i=0,marginBottom:s=0,marginLeft:c=0,marginRight:l=0}=n.getSnapshot().documentStyle,{scene:h,mainComponent:m}=t.render;let{actualHeight:_,actualWidth:f}=r.getActualSize();_+=i+s,f+=c+l;const{width:g,height:v}=t.getBoundingClientRect(),p=h.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);let S=p==null?void 0:p.getScrollBar();const C=Math.max(f,g),O=Math.max(_,v);h.transformByState({width:C,height:O}),m==null||m.resize(C,O),t.isSingle()?f>g?S==null?p&&new I.ScrollBar(p,{barSize:8,enableVertical:!1}):p==null||p.resetCanvasSizeAndUpdateScrollBar():(S=null,p==null||p.scrollTo({x:0,y:0}),(y=p==null?void 0:p.getScrollBar())==null||y.dispose()):_>v?S==null?p&&new I.ScrollBar(p,{enableHorizontal:!1,barSize:8}):p==null||p.resetCanvasSizeAndUpdateScrollBar():(S=null,p==null||p.scrollTo({x:0,y:0}),(b=p==null?void 0:p.getScrollBar())==null||b.dispose())}_initialSetValue(){this.disposeWithMe(this._editorService.setValue$.subscribe(e=>{this._commandService.executeCommand(d.CoverContentCommand.id,{unitId:e.editorUnitId,body:e.body,segmentId:null})}))}_initialBlur(){this.disposeWithMe(this._editorService.blur$.subscribe(()=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.blur()})),this.disposeWithMe(this._textSelectionRenderManager.onBlur$.subscribe(()=>{var r;const e=(r=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:r.getUnitId();if(e==null)return;const t=this._editorService.getEditor(e),n=this._editorService.getFocusEditor();t==null||t.isSheetEditor()||n&&n.editorUnitId===e||this._editorService.blur()}))}_initialFocus(){this.disposeWithMe(this._editorService.focus$.subscribe(n=>{this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges([n])}));const e=["univer-formula-search","univer-formula-help","formula-help-decorator","univer-formula-help-param"];this.disposeWithMe(R.fromEvent(window,"mousedown").subscribe(n=>{const i=n.target.classList[0]||"";if(a.checkForSubstrings(i,e)){this._editorService.changeSpreadsheetFocusState(!0),n.stopPropagation();return}this._editorService.changeSpreadsheetFocusState(!1)})),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(n=>{const r=n.getUnitId(),i=this._renderManagerService.getRenderById(r),s=i==null?void 0:i.engine.getCanvas().getCanvasEle();s!=null&&R.fromEvent(s,"mousedown").subscribe(c=>{this._editorService.changeSpreadsheetFocusState(!0),c.stopPropagation()})})}_initialValueChange(){this.disposeWithMe(this._textSelectionRenderManager.onCompositionupdate$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onInput$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onKeydown$.subscribe(this._valueChange.bind(this))),this.disposeWithMe(this._textSelectionRenderManager.onPaste$.subscribe(this._valueChange.bind(this)))}_valueChange(){var n;const e=(n=this._univerInstanceService.getCurrentUniverDocInstance())==null?void 0:n.getUnitId();if(e==null)return;const t=this._editorService.getEditor(e);t==null||t.isSheetEditor()||this._editorService.refreshValueChange(e)}_commandExecutedListener(){const e=[d.RichTextEditingMutation.id,u.SetEditorResizeOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=t.params,{unitId:r}=n;if(this._editorService.isSheetEditor(r))return;this._resize(r),this._valueChange()}}))}};ie=Fn([a.OnLifecycle(a.LifecycleStages.Rendered,ie),Y(0,a.IUniverInstanceService),Y(1,u.IEditorService),Y(2,a.ICommandService),Y(3,I.ITextSelectionRenderManager),Y(4,I.IRenderManagerService)],ie);var Ln=Object.defineProperty,Bn=Object.getOwnPropertyDescriptor,wn=(o,e,t,n)=>{for(var r=n>1?void 0:n?Bn(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Ln(e,t,r),r},z=(o,e)=>(t,n)=>e(t,n,o);exports.DocRenderController=class extends a.RxDisposable{constructor(e,t,n,r,i,s){super(),this._context=e,this._commandService=t,this._docSkeletonManagerService=n,this._configService=r,this._editorService=i,this._renderManagerService=s,this._addNewRender(),this._initRenderRefresh(),this._initCommandListener()}reRender(e){var i,s;const t=(i=this._renderManagerService.getRenderById(e))==null?void 0:i.with(d.DocSkeletonManagerService),n=t==null?void 0:t.getSkeleton();if(!(!n||n.getViewModel().getDataModel().getSnapshot().disabled)){if(n.calculate(),this._editorService.isEditor(e)){(s=this._context.mainComponent)==null||s.makeDirty();return}this._recalculateSizeBySkeleton(n)}}_addNewRender(){const{scene:e,engine:t,unit:n}=this._context,r=new I.Viewport(d.VIEWPORT_KEY.VIEW_MAIN,e,{left:0,top:0,bottom:0,right:0,isRelativeX:!0,isRelativeY:!0,isWheelPreventDefaultX:!0});e.attachControl(),e.onMouseWheel$.subscribeEvent((c,l)=>{const h=c;if(h.ctrlKey){const m=Math.abs(h.deltaX);let _=m<40?.2:m<80?.4:.2;_*=h.deltaY>0?-1:1,e.scaleX<1&&(_/=2),e.scaleX+_>4?e.scale(4,4):e.scaleX+_<.1?e.scale(.1,.1):h.preventDefault()}else r.onMouseWheel(h,l)}),this._configService.getConfig("hasScroll")!==!1&&new I.ScrollBar(r),e.addLayer(new I.Layer(e,[],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),new I.Layer(e,[],d.DOCS_COMPONENT_HEADER_LAYER_INDEX)),this._addComponent(),n.getShouldRenderLoopImmediately()&&t.runRenderLoop(()=>{e.render()})}_addComponent(){const{scene:e,unit:t,components:n}=this._context,r={pageMarginLeft:t.documentStyle.marginLeft||0,pageMarginTop:t.documentStyle.marginTop||0},i=new I.Documents(d.DOCS_VIEW_KEY.MAIN,void 0,r);i.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX;const s=new I.DocBackground(d.DOCS_VIEW_KEY.BACKGROUND,void 0,r);s.zIndex=d.DOCS_COMPONENT_DEFAULT_Z_INDEX,this._context.mainComponent=i,n.set(d.DOCS_VIEW_KEY.MAIN,i),n.set(d.DOCS_VIEW_KEY.BACKGROUND,s),e.addObjects([i],d.DOCS_COMPONENT_MAIN_LAYER_INDEX),e.addObjects([s],d.DOCS_COMPONENT_BACKGROUND_LAYER_INDEX),this._editorService.getEditor(t.getUnitId())==null&&e.enableLayerCache(d.DOCS_COMPONENT_MAIN_LAYER_INDEX)}_initRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(R.takeUntil(this.dispose$)).subscribe(e=>{this._create(e)})}_create(e){if(!e)return;const{mainComponent:t,components:n}=this._context,r=t,i=n.get(d.DOCS_VIEW_KEY.BACKGROUND);r.changeSkeleton(e),i.changeSkeleton(e),this._recalculateSizeBySkeleton(e)}_initCommandListener(){const e=[d.RichTextEditingMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=t.params,{unitId:r}=n;this.reRender(r)}}))}_recalculateSizeBySkeleton(e){var _;const{mainComponent:t,scene:n,unitId:r,components:i}=this._context,s=t,c=i.get(d.DOCS_VIEW_KEY.BACKGROUND),l=(_=e.getSkeletonData())==null?void 0:_.pages;if(l==null)return;let h=0,m=0;for(let f=0,g=l.length;f<g;f++){const v=l[f],{pageWidth:p,pageHeight:S}=v;s.pageLayoutType===I.PageLayoutType.VERTICAL?(m+=S,m+=s.pageMarginTop,f===g-1&&(m+=s.pageMarginTop),h=Math.max(h,p)):s.pageLayoutType===I.PageLayoutType.HORIZONTAL&&(h+=p,f!==g-1&&(h+=s.pageMarginLeft),m=Math.max(m,S))}s.resize(h,m),c.resize(h,m),this._editorService.isEditor(r)||n.resize(h,m)}};exports.DocRenderController=wn([z(1,a.ICommandService),z(2,T.Inject(d.DocSkeletonManagerService)),z(3,a.IConfigService),z(4,u.IEditorService),z(5,I.IRenderManagerService)],exports.DocRenderController);var $n=Object.defineProperty,Hn=Object.getOwnPropertyDescriptor,Vn=(o,e,t,n)=>{for(var r=n>1?void 0:n?Hn(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&$n(e,t,r),r},K=(o,e)=>(t,n)=>e(t,n,o);let ve=class extends a.Disposable{constructor(o,e,t,n,r,i){super(),this._context=o,this._docSkeletonManagerService=e,this._univerInstanceService=t,this._commandService=n,this._textSelectionManagerService=r,this._editorService=i,this._init()}_init(){this._initSkeletonListener(),this._initCommandExecutedListener(),this._initRenderRefresher(),setTimeout(()=>this._updateViewZoom(1,!0),20)}_initRenderRefresher(){this._docSkeletonManagerService.currentSkeleton$.subscribe(o=>{if(o==null)return;const{unitId:e,scene:t}=this._context;this._editorService.isEditor(e)||this.disposeWithMe(t.onMouseWheel$.subscribeEvent(n=>{if(!n.ctrlKey)return;const r=this._univerInstanceService.getCurrentUniverDocInstance();if(!r)return;const i=Math.abs(n.deltaX);let s=i<40?.2:i<80?.4:.2;s*=n.deltaY>0?-1:1,t.scaleX<1&&(s/=2);const c=r.zoomRatio;let l=+Number.parseFloat(`${c+s}`).toFixed(1);l=l>=4?4:l<=.1?.1:l,this._commandService.executeCommand(d.SetDocZoomRatioCommand.id,{zoomRatio:l,unitId:r.getUnitId()}),n.preventDefault()}))})}_initSkeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(o=>{if(o==null)return;const e=this._univerInstanceService.getCurrentUniverDocInstance();if(!e)return;const t=e.zoomRatio||1;this._updateViewZoom(t,!1)}))}_initCommandExecutedListener(){const o=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(o.includes(e.id)){const t=this._univerInstanceService.getCurrentUniverDocInstance();if(!t)return;const n=e.params,{unitId:r}=n;if(r!==t.getUnitId())return;const i=t.zoomRatio||1;this._updateViewZoom(i)}}))}_updateViewZoom(o,e=!0){var n;const t=d.neoGetDocObject(this._context);t.scene.scale(o,o),this._calculatePagePosition(t,o),e&&this._textSelectionManagerService.refreshSelection(),(n=t.scene.getTransformer())==null||n.clearSelectedObjects()}_calculatePagePosition(o,e){const{document:t,scene:n,docBackground:r}=o,i=n==null?void 0:n.getParent(),{width:s,height:c,pageMarginLeft:l,pageMarginTop:h}=t;if(i==null||s===Number.POSITIVE_INFINITY||c===Number.POSITIVE_INFINITY)return;const{width:m,height:_}=i;let f=0,g=0,v=0,p=0,S=Number.POSITIVE_INFINITY;m>(s+l*2)*e?(f=m/2-s*e/2,f/=e,v=(m-l*2)/e,S=0):(f=l,v=s+l*2,S=(v-m/e)/2),_>c?(g=_/2-c/2,p=(_-h*2)/e):(g=h,p=c+h*2),n.resize(v,p+200),t.translate(f,g),r.translate(f,g);const C=n.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(S!==Number.POSITIVE_INFINITY&&C!=null){const O=C.transViewportScroll2ScrollValue(S,0).x;C.scrollTo({x:O})}return this}};ve=Vn([K(1,T.Inject(d.DocSkeletonManagerService)),K(2,a.IUniverInstanceService),K(3,a.ICommandService),K(4,T.Inject(d.TextSelectionManagerService)),K(5,u.IEditorService)],ve);var jn=Object.defineProperty,Wn=Object.getOwnPropertyDescriptor,kn=(o,e,t,n)=>{for(var r=n>1?void 0:n?Wn(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&jn(e,t,r),r},V=(o,e)=>(t,n)=>e(t,n,o);let Ie=class extends a.Disposable{constructor(e,t,n,r,i,s,c){super();M(this,"_loadedMap",new WeakSet);this._context=e,this._commandService=t,this._editorService=n,this._instanceSrv=r,this._textSelectionRenderManager=i,this._docSkeletonManagerService=s,this._textSelectionManagerService=c,this._initialize()}_initialize(){this._init(),this._skeletonListener(),this._commandExecutedListener()}_init(){const{unitId:e}=this._context,t=d.neoGetDocObject(this._context);t==null||t.document==null||this._loadedMap.has(t.document)||(this._initialMain(e),this._loadedMap.add(t.document))}_initialMain(e){const t=d.neoGetDocObject(this._context),{document:n,scene:r}=t;this.disposeWithMe(n.onPointerEnter$.subscribeEvent(()=>{this._isEditorReadOnly(e)||(n.cursor=I.CURSOR_TYPE.TEXT)})),this.disposeWithMe(n.onPointerLeave$.subscribeEvent(()=>{n.cursor=I.CURSOR_TYPE.DEFAULT,r.resetCursor()})),this.disposeWithMe(n.onPointerDown$.subscribeEvent((i,s)=>{if(this._isEditorReadOnly(e))return;const c=this._instanceSrv.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);(c==null?void 0:c.getUnitId())!==e&&this._instanceSrv.setCurrentUnitForType(e);const l=this._docSkeletonManagerService.getSkeleton(),{offsetX:h,offsetY:m}=i,_=this._getTransformCoordForDocumentOffset(h,m);if(_!=null){const{pageLayoutType:f=I.PageLayoutType.VERTICAL,pageMarginLeft:g,pageMarginTop:v}=n.getOffsetConfig(),{editArea:p}=l.findEditAreaByCoord(_,f,g,v),S=this._docSkeletonManagerService.getViewModel(),C=S.getEditArea();C!==I.DocumentEditArea.BODY&&p!==I.DocumentEditArea.BODY&&p!==C&&S.setEditArea(p)}if(this._textSelectionRenderManager.eventTrigger(i),this._editorService.getEditor(e)){this._setEditorFocus(e);const{offsetX:f,offsetY:g}=i;setTimeout(()=>{this._setEditorFocus(e),this._textSelectionRenderManager.setCursorManually(f,g)},0)}i.button!==2&&s.stopPropagation()})),this.disposeWithMe(n.onDblclick$.subscribeEvent(i=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleDblClick(i)})),this.disposeWithMe(n.onTripleClick$.subscribeEvent(i=>{this._isEditorReadOnly(e)||this._textSelectionRenderManager.handleTripleClick(i)}))}_getTransformCoordForDocumentOffset(e,t){const n=d.neoGetDocObject(this._context),{document:r,scene:i}=n,{documentTransform:s}=r.getOffsetConfig(),c=i.getViewports()[0];if(c==null)return;const l=c.transformVector2SceneCoord(I.Vector2.FromArray([e,t]));return s.clone().invert().applyPoint(l)}_isEditorReadOnly(e){const t=this._editorService.getEditor(e);return t?t.isReadOnly():!1}_setEditorFocus(e){this._editorService.focusStyle(e)}_commandExecutedListener(){const e=[d.SetDocZoomRatioOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:i}=r,s=(n=this._textSelectionManagerService.getCurrentSelection())==null?void 0:n.unitId;if(i!==s)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{scene:t,mainComponent:n,unitId:r}=this._context;this._textSelectionRenderManager.changeRuntime(e,t,n),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:r,subUnitId:""}),a.isInternalEditorID(r)||this._textSelectionManagerService.replaceTextRanges([{startOffset:0,endOffset:0}],!1)}))}};Ie=kn([V(1,a.ICommandService),V(2,u.IEditorService),V(3,a.IUniverInstanceService),V(4,I.ITextSelectionRenderManager),V(5,T.Inject(d.DocSkeletonManagerService)),V(6,T.Inject(d.TextSelectionManagerService))],Ie);var Gn=Object.defineProperty,Yn=Object.getOwnPropertyDescriptor,zn=(o,e,t,n)=>{for(var r=n>1?void 0:n?Yn(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Gn(e,t,r),r},te=(o,e)=>(t,n)=>e(t,n,o);function Be(o,e){const t=we(o.left,o.top,e),n=we(o.right,o.bottom,e);return{left:t.x,top:t.y,right:n.x,bottom:n.y}}function we(o,e,t){const{scaleX:n,scaleY:r}=t.getAncestorScale(),i=t.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);if(!i)return{x:o,y:e};const{viewportScrollX:s,viewportScrollY:c}=i,l=(o-s)*n,h=(e-c)*r;return{x:l,y:h}}exports.DocCanvasPopManagerService=class extends a.Disposable{constructor(e,t,n,r){super(),this._globalPopupManagerService=e,this._renderManagerService=t,this._univerInstanceService=n,this._commandService=r}_createObjectPositionObserver(e,t){const n=()=>{const{scene:l,engine:h}=t,{left:m,top:_,width:f,height:g}=e,v={left:m,right:m+f,top:_,bottom:_+g},p=Be(v,l),S=h.getCanvasElement().getBoundingClientRect().top;return{left:p.left,right:p.right,top:p.top+S,bottom:p.bottom+S}},r=n(),i=new R.BehaviorSubject(r),s=new a.DisposableCollection;s.add(this._commandService.onCommandExecuted(l=>{l.id===d.SetDocZoomRatioOperation.id&&i.next(n())}));const c=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);return c&&s.add(c.onScrollAfter$.subscribeEvent(()=>{i.next(n())})),{position:r,position$:i,disposable:s}}_createRangePositionObserver(e,t){var l;const n=()=>{const{scene:h,mainComponent:m,engine:_}=t,f=t.with(d.DocSkeletonManagerService).getSkeleton(),g=f.findNodePositionByCharIndex(e.startOffset),v=f.findNodePositionByCharIndex(e.endOffset),p=m;if(!v||!g)return;const S=p.getOffsetConfig(),{docsLeft:C,docsTop:O}=S,E=_.getCanvasElement().getBoundingClientRect().top,b=new I.NodePositionConvertToCursor(S,f),{borderBoxPointGroup:y}=b.getRangePointData(g,v);return I.getLineBounding(y).map(x=>Be(x,h)).map(x=>({left:x.left+C,right:x.right+C,top:x.top+O+E,bottom:x.bottom+O+E}))},r=(l=n())!=null?l:[],i=new R.BehaviorSubject(r),s=new a.DisposableCollection;s.add(this._commandService.onCommandExecuted(h=>{if(h.id===d.SetDocZoomRatioOperation.id){const m=n();m&&i.next(m)}}));const c=t.scene.getViewport(d.VIEWPORT_KEY.VIEW_MAIN);return c&&s.add(c.onScrollAfter$.subscribeEvent(()=>{const h=n();h&&i.next(h)})),{positions:r,positions$:i,disposable:s}}attachPopupToObject(e,t){const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC).getUnitId(),i=this._renderManagerService.getRenderById(r);if(!i)return{dispose:()=>{}};const{position:s,position$:c,disposable:l}=this._createObjectPositionObserver(e,i),h=this._globalPopupManagerService.addPopup({...t,unitId:r,subUnitId:"default",anchorRect:s,anchorRect$:c});return{dispose:()=>{this._globalPopupManagerService.removePopup(h),c.complete(),l.dispose()}}}attachPopupToRange(e,t){const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC).getUnitId(),{direction:i="top"}=t,s=this._renderManagerService.getRenderById(r);if(!s)return{dispose:()=>{}};const{positions:c,positions$:l,disposable:h}=this._createRangePositionObserver(e,s),m=l.pipe(R.map(f=>i==="top"?f[0]:f[f.length-1])),_=this._globalPopupManagerService.addPopup({...t,unitId:r,subUnitId:"default",anchorRect:i==="top"?c[0]:c[c.length-1],anchorRect$:m,excludeRects:c,excludeRects$:l,direction:i==="top"?"top":"bottom"});return{dispose:()=>{this._globalPopupManagerService.removePopup(_),l.complete(),h.dispose()}}}};exports.DocCanvasPopManagerService=zn([te(0,T.Inject(u.ICanvasPopupService)),te(1,I.IRenderManagerService),te(2,a.IUniverInstanceService),te(3,a.ICommandService)],exports.DocCanvasPopManagerService);var Kn=Object.defineProperty,Xn=Object.getOwnPropertyDescriptor,Zn=(o,e,t,n)=>{for(var r=n>1?void 0:n?Xn(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&Kn(e,t,r),r},$e=(o,e)=>(t,n)=>e(t,n,o);exports.DocsRenderService=class extends a.RxDisposable{constructor(e,t){super(),this._instanceSrv=e,this._renderManagerService=t,this._init()}_init(){this._renderManagerService.createRender$.pipe(R.takeUntil(this.dispose$)).subscribe(e=>this._createRenderWithId(e)),this._instanceSrv.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_DOC).pipe(R.takeUntil(this.dispose$)).subscribe(e=>this._createRenderer(e)),this._instanceSrv.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC).forEach(e=>this._createRenderer(e)),this._instanceSrv.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_DOC).pipe(R.takeUntil(this.dispose$)).subscribe(e=>this._disposeRenderer(e))}_createRenderer(e){const t=e.getUnitId();this._renderManagerService.has(t)||(this._createRenderWithId(t),this._renderManagerService.setCurrent(t))}_createRenderWithId(e){this._renderManagerService.createRender(e)}_disposeRenderer(e){const t=e.getUnitId();this._renderManagerService.removeRender(t)}};exports.DocsRenderService=Zn([a.OnLifecycle(a.LifecycleStages.Ready,exports.DocsRenderService),$e(0,a.IUniverInstanceService),$e(1,I.IRenderManagerService)],exports.DocsRenderService);var qn=Object.defineProperty,Jn=Object.getOwnPropertyDescriptor,Qn=(o,e,t,n)=>{for(var r=n>1?void 0:n?Jn(e,t):e,i=o.length-1,s;i>=0;i--)(s=o[i])&&(r=(n?s(e,t,r):s(r))||r);return n&&r&&qn(e,t,r),r},me=(o,e)=>(t,n)=>e(t,n,o),ne;exports.UniverDocsUIPlugin=(ne=class extends a.Plugin{constructor(e,t,n,r){super(),this._config=e,this._injector=t,this._renderManagerSrv=n,this._logService=r,this._config=a.Tools.deepMerge({},Ye,this._config),this._initDependencies(t),this._initializeCommands()}onReady(){this._initRenderBasics()}onRendered(){this._initUI(),this._initRenderModules(),this._markDocAsFocused()}_initializeCommands(){[Et,bt,yt,Mt,Dt,Pt,xt,At,Nt,yn,Dn,Mn].forEach(e=>{this._injector.get(u.IShortcutService).registerShortcut(e)})}_initDependencies(e){[[Z,{useFactory:()=>this._injector.createInstance(Z,this._config)}],[re],[ie],[exports.DocsRenderService],[X,{useFactory:()=>this._injector.createInstance(X,this._config)}],[k,{useClass:_e}],[exports.DocCanvasPopManagerService]].forEach(n=>e.add(n))}_markDocAsFocused(){const e=this._injector.get(a.IUniverInstanceService),t=this._injector.get(u.IEditorService);try{const n=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(!n)return;const r=n.getUnitId();t.isEditor(r)||e.focusUnit(n.getUnitId())}catch(n){this._logService.warn(n)}}_initUI(){this._injector.get(X)}_initRenderBasics(){[[d.DocSkeletonManagerService],[d.DocInterceptorService],[exports.DocRenderController],[ve]].forEach(e=>{this._renderManagerSrv.registerRenderModule(a.UniverInstanceType.UNIVER_DOC,e)})}_initRenderModules(){[[exports.DocBackScrollRenderController],[Ie],[Se]].forEach(e=>{this._renderManagerSrv.registerRenderModule(a.UniverInstanceType.UNIVER_DOC,e)})}},M(ne,"pluginName",ze),M(ne,"type",a.UniverInstanceType.UNIVER_DOC),ne);exports.UniverDocsUIPlugin=Qn([me(1,T.Inject(T.Injector)),me(2,I.IRenderManagerService),me(3,a.ILogService)],exports.UniverDocsUIPlugin);function eo(o){return{left:o.positionH.posOffset,top:o.positionV.posOffset,width:o.size.width,height:o.size.height}}function to(o,e=0,t=0){return{size:{width:o.width,height:o.height},positionH:{relativeFrom:a.ObjectRelativeFromH.MARGIN,posOffset:(o.left||0)-e},positionV:{relativeFrom:a.ObjectRelativeFromV.PAGE,posOffset:(o.top||0)-t},angle:o.angle||0}}exports.DOC_UI_PLUGIN_NAME=ze;exports.DefaultDocContainerConfig=Ge;exports.DefaultDocUiConfig=Ye;exports.DefaultToolbarConfig=ke;exports.DocCopyCommand=nt;exports.DocCutCommand=ot;exports.DocPasteCommand=rt;exports.IDocClipboardService=k;exports.PastePluginLark=He;exports.PastePluginUniver=We;exports.PastePluginWord=je;exports.docDrawingPositionToTransform=eo;exports.transformToDocDrawingPosition=to;exports.whenDocAndEditorFocused=F;