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