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