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