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