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

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