@univerjs/watermark 0.4.1-experimental.20241022-507567a
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/README.md +37 -0
- package/lib/cjs/index.js +9 -0
- package/lib/es/index.js +911 -0
- package/lib/index.css +1 -0
- package/lib/locale/en-US.json +32 -0
- package/lib/locale/fa-IR.json +32 -0
- package/lib/locale/ru-RU.json +32 -0
- package/lib/locale/vi-VN.json +32 -0
- package/lib/locale/zh-CN.json +32 -0
- package/lib/locale/zh-TW.json +32 -0
- package/lib/types/commands/operations/open-watermark-panel.operation.d.ts +2 -0
- package/lib/types/common/const.d.ts +10 -0
- package/lib/types/common/type.d.ts +59 -0
- package/lib/types/controllers/config.schema.d.ts +12 -0
- package/lib/types/controllers/menu.d.ts +3 -0
- package/lib/types/controllers/menu.schema.d.ts +2 -0
- package/lib/types/controllers/watermark.menu.controller.d.ts +9 -0
- package/lib/types/controllers/watermark.render.controller.d.ts +14 -0
- package/lib/types/index.d.ts +20 -0
- package/lib/types/locale/en-US.d.ts +3 -0
- package/lib/types/locale/fa-IR.d.ts +3 -0
- package/lib/types/locale/ru-RU.d.ts +3 -0
- package/lib/types/locale/vi-VN.d.ts +3 -0
- package/lib/types/locale/zh-CN.d.ts +48 -0
- package/lib/types/locale/zh-TW.d.ts +3 -0
- package/lib/types/plugin.d.ts +18 -0
- package/lib/types/services/watermark.service.d.ts +15 -0
- package/lib/types/util.d.ts +7 -0
- package/lib/types/views/components/WatermarkImageSetting.d.ts +8 -0
- package/lib/types/views/components/WatermarkPanel.d.ts +2 -0
- package/lib/types/views/components/WatermarkPanelFooter.d.ts +2 -0
- package/lib/types/views/components/WatermarkTextSetting.d.ts +8 -0
- package/lib/types/views/extensions/watermark-layer.d.ts +11 -0
- package/lib/umd/index.js +9 -0
- package/package.json +92 -0
package/lib/es/index.js
ADDED
|
@@ -0,0 +1,911 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
+
import { CommandType, LocaleService, Inject, ILocalStorageService, Disposable, useDependency, useObservable, IUniverInstanceService, DOCS_ZEN_EDITOR_UNIT_ID_KEY, UserManagerService, RxDisposable, Injector, ICommandService, Plugin, UniverInstanceType, IConfigService } from "@univerjs/core";
|
|
6
|
+
import { Layer, IRenderManagerService } from "@univerjs/engine-render";
|
|
7
|
+
import { ISidebarService, ILocalFileService, IClipboardInterfaceService, MenuItemType, RibbonStartGroup, ComponentManager, IMenuManagerService } from "@univerjs/ui";
|
|
8
|
+
import require$$0, { forwardRef, useRef, createElement, useState, useCallback, useEffect } from "react";
|
|
9
|
+
import { Button, InputNumber, Checkbox, Input, Select, Dropdown, ColorPicker } from "@univerjs/design";
|
|
10
|
+
import { Subject, switchMap, of } from "rxjs";
|
|
11
|
+
const UNIVER_WATERMARK_MENU = "UNIVER_WATERMARK_MENU", WATERMARK_PANEL = "WATERMARK_PANEL", WATERMARK_PANEL_FOOTER = "WATERMARK_PANEL_FOOTER", UNIVER_WATERMARK_STORAGE_KEY = "UNIVER_WATERMARK_STORAGE_KEY", UNIVER_WATERMARK_LAYER_INDEX = 10, WATERMARK_IMAGE_ALLOW_IMAGE_LIST = ["image/png", "image/jpeg", "image/jpg", "image/bmp"], WatermarkTextBaseConfig = {
|
|
12
|
+
content: "",
|
|
13
|
+
fontSize: 16,
|
|
14
|
+
color: "rgb(0,0,0)",
|
|
15
|
+
bold: !1,
|
|
16
|
+
italic: !1,
|
|
17
|
+
direction: "ltr",
|
|
18
|
+
x: 60,
|
|
19
|
+
y: 36,
|
|
20
|
+
repeat: !0,
|
|
21
|
+
spacingX: 200,
|
|
22
|
+
spacingY: 100,
|
|
23
|
+
rotate: 0,
|
|
24
|
+
opacity: 0.15
|
|
25
|
+
}, WatermarkImageBaseConfig = {
|
|
26
|
+
url: "",
|
|
27
|
+
width: 100,
|
|
28
|
+
height: 100,
|
|
29
|
+
maintainAspectRatio: !0,
|
|
30
|
+
originRatio: 1,
|
|
31
|
+
x: 60,
|
|
32
|
+
y: 36,
|
|
33
|
+
repeat: !0,
|
|
34
|
+
spacingX: 200,
|
|
35
|
+
spacingY: 100,
|
|
36
|
+
rotate: 0,
|
|
37
|
+
opacity: 0.15
|
|
38
|
+
}, WatermarkUserInfoBaseConfig = {
|
|
39
|
+
name: !0,
|
|
40
|
+
email: !1,
|
|
41
|
+
phone: !1,
|
|
42
|
+
uid: !1,
|
|
43
|
+
fontSize: 16,
|
|
44
|
+
color: "rgb(0,0,0)",
|
|
45
|
+
bold: !1,
|
|
46
|
+
italic: !1,
|
|
47
|
+
direction: "ltr",
|
|
48
|
+
x: 60,
|
|
49
|
+
y: 60,
|
|
50
|
+
repeat: !0,
|
|
51
|
+
spacingX: 200,
|
|
52
|
+
spacingY: 100,
|
|
53
|
+
rotate: -30,
|
|
54
|
+
opacity: 0.15
|
|
55
|
+
}, OpenWatermarkPanelOperation = {
|
|
56
|
+
type: CommandType.OPERATION,
|
|
57
|
+
id: "univer.operation.open-watermark-panel",
|
|
58
|
+
handler(accessor) {
|
|
59
|
+
const sidebarService = accessor.get(ISidebarService), localeService = accessor.get(LocaleService);
|
|
60
|
+
return sidebarService.open({
|
|
61
|
+
header: { title: localeService.t("univer-watermark.title") },
|
|
62
|
+
children: { label: WATERMARK_PANEL },
|
|
63
|
+
footer: { label: WATERMARK_PANEL_FOOTER },
|
|
64
|
+
onClose: /* @__PURE__ */ __name(() => {
|
|
65
|
+
}, "onClose"),
|
|
66
|
+
width: 330
|
|
67
|
+
}), !0;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var IWatermarkTypeEnum = /* @__PURE__ */ ((IWatermarkTypeEnum2) => (IWatermarkTypeEnum2.UserInfo = "userInfo", IWatermarkTypeEnum2.Text = "text", IWatermarkTypeEnum2.Image = "image", IWatermarkTypeEnum2))(IWatermarkTypeEnum || {}), __assign = function() {
|
|
71
|
+
return __assign = Object.assign || function(t) {
|
|
72
|
+
for (var s, i = 1, n2 = arguments.length; i < n2; i++) {
|
|
73
|
+
s = arguments[i];
|
|
74
|
+
for (var p2 in s) Object.prototype.hasOwnProperty.call(s, p2) && (t[p2] = s[p2]);
|
|
75
|
+
}
|
|
76
|
+
return t;
|
|
77
|
+
}, __assign.apply(this, arguments);
|
|
78
|
+
}, __rest = function(s, e) {
|
|
79
|
+
var t = {};
|
|
80
|
+
for (var p2 in s) Object.prototype.hasOwnProperty.call(s, p2) && e.indexOf(p2) < 0 && (t[p2] = s[p2]);
|
|
81
|
+
if (s != null && typeof Object.getOwnPropertySymbols == "function")
|
|
82
|
+
for (var i = 0, p2 = Object.getOwnPropertySymbols(s); i < p2.length; i++)
|
|
83
|
+
e.indexOf(p2[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p2[i]) && (t[p2[i]] = s[p2[i]]);
|
|
84
|
+
return t;
|
|
85
|
+
}, IconBase = forwardRef(function(props, ref) {
|
|
86
|
+
var icon = props.icon, id = props.id, className = props.className, extend = props.extend, restProps = __rest(props, ["icon", "id", "className", "extend"]), cls = "univerjs-icon univerjs-icon-".concat(id, " ").concat(className || "").trim(), idSuffix = useRef("_".concat(generateShortUuid()));
|
|
87
|
+
return render(icon, "".concat(id), { defIds: icon.defIds, idSuffix: idSuffix.current }, __assign({ ref, className: cls }, restProps), extend);
|
|
88
|
+
});
|
|
89
|
+
function render(node, id, runtimeProps, rootProps, extend) {
|
|
90
|
+
return createElement(node.tag, __assign(__assign({ key: id }, replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend)), rootProps), (replaceRuntimeIdsInDefs(node, runtimeProps).children || []).map(function(child, index) {
|
|
91
|
+
return render(child, "".concat(id, "-").concat(node.tag, "-").concat(index), runtimeProps, void 0, extend);
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
__name(render, "render");
|
|
95
|
+
function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
|
|
96
|
+
var attrs = __assign({}, node.attrs);
|
|
97
|
+
extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
|
|
98
|
+
var defIds = runtimeProps.defIds;
|
|
99
|
+
return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a5) {
|
|
100
|
+
var key = _a5[0], value = _a5[1];
|
|
101
|
+
typeof value == "string" && (attrs[key] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
|
|
102
|
+
})), attrs;
|
|
103
|
+
}
|
|
104
|
+
__name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
|
|
105
|
+
function replaceRuntimeIdsInDefs(node, runtimeProps) {
|
|
106
|
+
var _a5, defIds = runtimeProps.defIds;
|
|
107
|
+
return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a5 = node.children) === null || _a5 === void 0) && _a5.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
|
|
108
|
+
return typeof child.attrs.id == "string" && defIds && defIds.indexOf(child.attrs.id) > -1 ? __assign(__assign({}, child), { attrs: __assign(__assign({}, child.attrs), { id: child.attrs.id + runtimeProps.idSuffix }) }) : child;
|
|
109
|
+
}) }) : node;
|
|
110
|
+
}
|
|
111
|
+
__name(replaceRuntimeIdsInDefs, "replaceRuntimeIdsInDefs");
|
|
112
|
+
function generateShortUuid() {
|
|
113
|
+
return Math.random().toString(36).substring(2, 8);
|
|
114
|
+
}
|
|
115
|
+
__name(generateShortUuid, "generateShortUuid");
|
|
116
|
+
IconBase.displayName = "UniverIcon";
|
|
117
|
+
var element$3 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M4.65791 1.30005C3.77355 1.30005 3.05664 2.01696 3.05664 2.90132V12.8588C3.05664 13.8755 3.88086 14.6998 4.89759 14.6998H9.1016C11.2233 14.6998 12.9433 12.9798 12.9433 10.8581C12.9433 9.13925 11.8145 7.68407 10.2578 7.1934C10.8806 6.56856 11.2655 5.70659 11.2655 4.75472C11.2655 2.84676 9.71883 1.30005 7.81087 1.30005H4.65791ZM4.25664 2.90132C4.25664 2.6797 4.4363 2.50005 4.65791 2.50005H7.81087C9.05609 2.50005 10.0655 3.5095 10.0655 4.75472C10.0655 5.99993 9.05609 7.00938 7.81087 7.00938H4.25664V2.90132ZM4.25664 12.8588V8.21636H9.1016C10.5606 8.21636 11.7433 9.39909 11.7433 10.8581C11.7433 12.317 10.5606 13.4998 9.1016 13.4998H4.89759C4.5436 13.4998 4.25664 13.2128 4.25664 12.8588Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, BoldSingle = forwardRef(function(props, ref) {
|
|
118
|
+
return createElement(IconBase, Object.assign({}, props, {
|
|
119
|
+
id: "bold-single",
|
|
120
|
+
ref,
|
|
121
|
+
icon: element$3
|
|
122
|
+
}));
|
|
123
|
+
});
|
|
124
|
+
BoldSingle.displayName = "BoldSingle";
|
|
125
|
+
var element$2 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "mask", attrs: { id: "mask0_102_1198", style: { maskType: "alpha" }, width: 16, height: 16, x: 0, y: 0, maskUnits: "userSpaceOnUse" }, children: [{ tag: "path", attrs: { fill: "#DCDCDC", d: "M0 0H16V16H0z" } }] }, { tag: "g", attrs: { mask: "url(#mask0_102_1198)" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M5.68731 9.98425C5.73282 9.87144 5.77827 9.75442 5.82366 9.63323L6.3312 8.27586H9.65859L10.3523 10.1159C10.405 10.284 10.4868 10.4276 10.6023 10.5378C10.74 10.669 10.9119 10.7236 11.1014 10.714C11.3544 10.7131 11.5919 10.6379 11.6996 10.4032L11.7013 10.3992C11.7901 10.1937 11.7749 9.9634 11.6929 9.7289L8.85351 1.86337C8.79546 1.68828 8.6901 1.54881 8.54213 1.45002C8.38836 1.33863 8.1989 1.29112 7.98798 1.29112C7.78272 1.29112 7.59752 1.34014 7.4446 1.45198C7.30481 1.55223 7.20617 1.69184 7.14935 1.86343L4.324 9.70145L4.32281 9.70495C4.27002 9.86052 4.23828 10.0056 4.23828 10.1346C4.23828 10.2646 4.27116 10.3937 4.36281 10.4909C4.50256 10.6468 4.6921 10.714 4.90604 10.714C5.0369 10.714 5.15805 10.6745 5.26156 10.5916C5.3633 10.5247 5.44621 10.4332 5.51101 10.3217C5.57988 10.2177 5.63858 10.1051 5.68731 9.98425ZM6.72105 7.00152L8.00144 3.32827L9.28183 7.00152H6.72105Z", fillRule: "evenodd", clipRule: "evenodd" } }, { tag: "rect", attrs: { width: 11.58, height: 2.56, x: 2.21, y: 12.2, fill: "colorChannel1", rx: 1.28 } }] }] }, FontColor = forwardRef(function(props, ref) {
|
|
126
|
+
return createElement(IconBase, Object.assign({}, props, {
|
|
127
|
+
id: "font-color",
|
|
128
|
+
ref,
|
|
129
|
+
icon: element$2
|
|
130
|
+
}));
|
|
131
|
+
});
|
|
132
|
+
FontColor.displayName = "FontColor";
|
|
133
|
+
var element$1 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M9.80385 1.40005H11.9997C12.3311 1.40005 12.5997 1.66868 12.5997 2.00005C12.5997 2.33143 12.3311 2.60005 11.9997 2.60005H10.1185L7.12251 13.4001H9.33324C9.66461 13.4001 9.93324 13.6687 9.93324 14.0001C9.93324 14.3314 9.66461 14.6001 9.33324 14.6001H6.34785C6.33847 14.6003 6.32905 14.6003 6.31962 14.6001H3.9999C3.66853 14.6001 3.3999 14.3314 3.3999 14.0001C3.3999 13.6687 3.66853 13.4001 3.9999 13.4001H5.87719L8.87322 2.60005H6.66641C6.33504 2.60005 6.06641 2.33143 6.06641 2.00005C6.06641 1.66868 6.33504 1.40005 6.66641 1.40005H9.52916C9.61698 1.37929 9.71064 1.3781 9.80385 1.40005Z" } }] }, ItalicSingle = forwardRef(function(props, ref) {
|
|
134
|
+
return createElement(IconBase, Object.assign({}, props, {
|
|
135
|
+
id: "italic-single",
|
|
136
|
+
ref,
|
|
137
|
+
icon: element$1
|
|
138
|
+
}));
|
|
139
|
+
});
|
|
140
|
+
ItalicSingle.displayName = "ItalicSingle";
|
|
141
|
+
var element = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M1.93949 12.3363L1.94048 12.3357 1.95034 12.33C1.95981 12.3245 1.97499 12.3158 1.99548 12.3043 2.0365 12.2813 2.09866 12.2474 2.17888 12.2061 2.33971 12.1234 2.57112 12.0123 2.84885 11.9012 3.41339 11.6754 4.12822 11.4664 4.81552 11.4664 5.82167 11.4664 6.71309 11.8774 7.74399 12.3643 7.7595 12.3717 7.77504 12.379 7.79061 12.3864 8.77119 12.8497 9.88765 13.3772 11.185 13.3772 12.0901 13.3772 12.9676 13.1085 13.5973 12.8566 13.9167 12.7289 14.1829 12.6011 14.3704 12.5047 14.4644 12.4564 14.5391 12.4157 14.5914 12.3864 14.6175 12.3717 14.6381 12.3599 14.6527 12.3514L14.6702 12.3412 14.6755 12.3381 14.6772 12.337 14.6782 12.3365C14.6782 12.3365 14.6784 12.3363 14.3697 11.8218L14.6782 12.3365C14.9623 12.166 15.0547 11.7973 14.8842 11.5131 14.7138 11.2291 14.3454 11.1369 14.0613 11.3071L14.06 11.3079 14.0502 11.3137C14.0407 11.3192 14.0255 11.3279 14.005 11.3394 13.964 11.3623 13.9019 11.3963 13.8216 11.4375 13.6608 11.5202 13.4294 11.6314 13.1517 11.7424 12.5871 11.9683 11.8723 12.1772 11.185 12.1772 10.1788 12.1772 9.28742 11.7663 8.25652 11.2793 8.24101 11.272 8.22547 11.2646 8.2099 11.2573 7.22931 10.7939 6.11286 10.2664 4.81552 10.2664 3.91046 10.2664 3.03292 10.5351 2.40318 10.787 2.08377 10.9148 1.81757 11.0425 1.63007 11.139 1.53613 11.1873 1.46144 11.228 1.40916 11.2573 1.383 11.2719 1.36241 11.2837 1.34778 11.2922L1.33033 11.3024 1.32504 11.3056 1.32327 11.3066 1.32233 11.3072C1.32233 11.3072 1.32209 11.3073 1.63068 11.8217L1.32233 11.3072C1.03818 11.4777.945803 11.8464 1.11629 12.1305 1.28674 12.4146 1.65536 12.5066 1.93949 12.3363zM1.93949 8.51464L1.94048 8.51406 1.95034 8.50829C1.95981 8.50279 1.97499 8.49407 1.99548 8.4826 2.0365 8.45963 2.09866 8.4257 2.17888 8.38443 2.33971 8.30172 2.57112 8.19061 2.84885 8.07952 3.41339 7.85371 4.12822 7.64473 4.81552 7.64473 5.82167 7.64473 6.71309 8.05572 7.74399 8.54267 7.7595 8.54999 7.77504 8.55733 7.79061 8.56469 8.77119 9.02803 9.88765 9.55557 11.185 9.55557 12.0901 9.55557 12.9676 9.28684 13.5973 9.03494 13.9167 8.90718 14.1829 8.77943 14.3704 8.683 14.4644 8.63469 14.5391 8.59398 14.5914 8.5647 14.6175 8.55006 14.6381 8.53825 14.6527 8.52975L14.6702 8.51954 14.6755 8.51641 14.6772 8.51535 14.6782 8.51479C14.6782 8.51479 14.6784 8.51464 14.3697 8.00015L14.6782 8.51479C14.9623 8.3443 15.0547 7.9756 14.8842 7.69145 14.7138 7.4074 14.3454 7.31523 14.0613 7.48547L14.06 7.48623 14.0502 7.492C14.0407 7.4975 14.0255 7.50622 14.005 7.5177 13.964 7.54067 13.9019 7.5746 13.8216 7.61586 13.6608 7.69857 13.4294 7.80968 13.1517 7.92077 12.5871 8.14659 11.8723 8.35557 11.185 8.35557 10.1788 8.35557 9.28742 7.94457 8.25652 7.45762 8.24101 7.4503 8.22547 7.44296 8.2099 7.4356 7.22931 6.97226 6.11286 6.44473 4.81552 6.44473 3.91046 6.44473 3.03292 6.71346 2.40318 6.96535 2.08377 7.09311 1.81757 7.22086 1.63007 7.31729 1.53613 7.3656 1.46144 7.40631 1.40916 7.43559 1.383 7.45024 1.36241 7.46205 1.34778 7.47054L1.33033 7.48075 1.32504 7.48389 1.32327 7.48494 1.32233 7.48551C1.32233 7.48551 1.32209 7.48565 1.63068 7.99997L1.32233 7.48551C1.03818 7.656.945803 8.0247 1.11629 8.30884 1.28674 8.59292 1.65536 8.68496 1.93949 8.51464zM1.93949 4.69296L1.94048 4.69238 1.95034 4.68661C1.95981 4.68111 1.97499 4.67239 1.99548 4.66092 2.0365 4.63795 2.09866 4.60402 2.17888 4.56276 2.33971 4.48004 2.57112 4.36893 2.84885 4.25784 3.41339 4.03203 4.12822 3.82305 4.81552 3.82305 5.82167 3.82305 6.71309 4.23404 7.74399 4.72099 7.7595 4.72831 7.77504 4.73566 7.79061 4.74301 8.77119 5.20635 9.88765 5.73389 11.185 5.73389 12.0901 5.73389 12.9676 5.46516 13.5973 5.21326 13.9167 5.0855 14.1829 4.95775 14.3704 4.86132 14.4644 4.81301 14.5391 4.7723 14.5914 4.74302 14.6175 4.72838 14.6381 4.71657 14.6527 4.70807L14.6702 4.69786 14.6755 4.69473 14.6772 4.69367 14.6782 4.69311C14.6782 4.69311 14.6784 4.69296 14.3697 4.17847L14.6782 4.69311C14.9623 4.52262 15.0547 4.15392 14.8842 3.86977 14.7138 3.58572 14.3454 3.49355 14.0613 3.66379L14.06 3.66455 14.0502 3.67032C14.0407 3.67582 14.0255 3.68454 14.005 3.69602 13.964 3.71899 13.9019 3.75292 13.8216 3.79418 13.6608 3.87689 13.4294 3.988 13.1517 4.09909 12.5871 4.32491 11.8723 4.53389 11.185 4.53389 10.1788 4.53389 9.28742 4.12289 8.25652 3.63594 8.24101 3.62862 8.22547 3.62128 8.2099 3.61392 7.22931 3.15058 6.11286 2.62305 4.81552 2.62305 3.91046 2.62305 3.03292 2.89178 2.40318 3.14367 2.08377 3.27143 1.81757 3.39918 1.63007 3.49561 1.53613 3.54392 1.46144 3.58463 1.40916 3.61391 1.383 3.62856 1.36241 3.64037 1.34778 3.64886L1.33033 3.65907 1.32504 3.66221 1.32327 3.66326 1.32233 3.66383C1.32233 3.66383 1.32209 3.66397 1.63068 4.17829L1.32233 3.66383C1.03818 3.83432.945803 4.20302 1.11629 4.48716 1.28674 4.77124 1.65536 4.86329 1.93949 4.69296z", fillRule: "evenodd", clipRule: "evenodd" } }] }, WatermarkSingle = forwardRef(function(props, ref) {
|
|
142
|
+
return createElement(IconBase, Object.assign({}, props, {
|
|
143
|
+
id: "watermark-single",
|
|
144
|
+
ref,
|
|
145
|
+
icon: element
|
|
146
|
+
}));
|
|
147
|
+
});
|
|
148
|
+
WatermarkSingle.displayName = "WatermarkSingle";
|
|
149
|
+
var jsxRuntime = { exports: {} }, reactJsxRuntime_production_min = {};
|
|
150
|
+
/**
|
|
151
|
+
* @license React
|
|
152
|
+
* react-jsx-runtime.production.min.js
|
|
153
|
+
*
|
|
154
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
155
|
+
*
|
|
156
|
+
* This source code is licensed under the MIT license found in the
|
|
157
|
+
* LICENSE file in the root directory of this source tree.
|
|
158
|
+
*/
|
|
159
|
+
var f = require$$0, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: !0, ref: !0, __self: !0, __source: !0 };
|
|
160
|
+
function q(c, a, g) {
|
|
161
|
+
var b, d = {}, e = null, h = null;
|
|
162
|
+
g !== void 0 && (e = "" + g), a.key !== void 0 && (e = "" + a.key), a.ref !== void 0 && (h = a.ref);
|
|
163
|
+
for (b in a) m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
|
|
164
|
+
if (c && c.defaultProps) for (b in a = c.defaultProps, a) d[b] === void 0 && (d[b] = a[b]);
|
|
165
|
+
return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
|
|
166
|
+
}
|
|
167
|
+
__name(q, "q");
|
|
168
|
+
reactJsxRuntime_production_min.Fragment = l;
|
|
169
|
+
reactJsxRuntime_production_min.jsx = q;
|
|
170
|
+
reactJsxRuntime_production_min.jsxs = q;
|
|
171
|
+
jsxRuntime.exports = reactJsxRuntime_production_min;
|
|
172
|
+
var jsxRuntimeExports = jsxRuntime.exports, __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
173
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
174
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
175
|
+
return kind && result && __defProp$3(target, key, result), result;
|
|
176
|
+
}, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a;
|
|
177
|
+
let WatermarkService = (_a = class extends Disposable {
|
|
178
|
+
constructor(_localStorageService) {
|
|
179
|
+
super();
|
|
180
|
+
__publicField(this, "_updateConfig$", new Subject());
|
|
181
|
+
__publicField(this, "updateConfig$", this._updateConfig$.asObservable());
|
|
182
|
+
__publicField(this, "_refresh$", new Subject());
|
|
183
|
+
__publicField(this, "refresh$", this._refresh$.asObservable());
|
|
184
|
+
this._localStorageService = _localStorageService;
|
|
185
|
+
}
|
|
186
|
+
async getWatermarkConfig() {
|
|
187
|
+
return await this._localStorageService.getItem(UNIVER_WATERMARK_STORAGE_KEY);
|
|
188
|
+
}
|
|
189
|
+
updateWatermarkConfig(config) {
|
|
190
|
+
this._localStorageService.setItem(UNIVER_WATERMARK_STORAGE_KEY, config), this._updateConfig$.next(config);
|
|
191
|
+
}
|
|
192
|
+
deleteWatermarkConfig() {
|
|
193
|
+
this._localStorageService.removeItem(UNIVER_WATERMARK_STORAGE_KEY), this._updateConfig$.next(null);
|
|
194
|
+
}
|
|
195
|
+
refresh() {
|
|
196
|
+
this._refresh$.next(Math.random());
|
|
197
|
+
}
|
|
198
|
+
dispose() {
|
|
199
|
+
this._refresh$.complete(), this._updateConfig$.complete();
|
|
200
|
+
}
|
|
201
|
+
}, __name(_a, "WatermarkService"), _a);
|
|
202
|
+
WatermarkService = __decorateClass$3([
|
|
203
|
+
__decorateParam$3(0, Inject(ILocalStorageService))
|
|
204
|
+
], WatermarkService);
|
|
205
|
+
const watermarkPanel = "univer-watermark-panel", watermarkPanelTypeTitle = "univer-watermark-panel-type-title", watermarkPanelTypeSelect = "univer-watermark-panel-type-select", watermarkPanelSetting = "univer-watermark-panel-setting", watermarkPanelFooter = "univer-watermark-panel-footer", watermarkPanelFooterButtonWrapper = "univer-watermark-panel-footer-button-wrapper", watermarkPanelFooterReset = "univer-watermark-panel-footer-reset", watermarkTextSetting = "univer-watermark-text-setting", watermarkTextSettingHeader = "univer-watermark-text-setting-header", watermarkTextSettingFontContent = "univer-watermark-text-setting-font-content", watermarkTextSettingFontStylePart = "univer-watermark-text-setting-font-style-part", watermarkTextSettingLayoutFontWrapper = "univer-watermark-text-setting-layout-font-wrapper", watermarkImageSetting = "univer-watermark-image-setting", watermarkInput = "univer-watermark-input", watermarkInputContent = "univer-watermark-input-content", watermarkIcon = "univer-watermark-icon", watermarkIconWrapper = "univer-watermark-icon-wrapper", watermarkIconWrapperSelect = "univer-watermark-icon-wrapper-select", watermarkColorPickerWrapper = "univer-watermark-color-picker-wrapper", styles = {
|
|
206
|
+
watermarkPanel,
|
|
207
|
+
watermarkPanelTypeTitle,
|
|
208
|
+
watermarkPanelTypeSelect,
|
|
209
|
+
watermarkPanelSetting,
|
|
210
|
+
watermarkPanelFooter,
|
|
211
|
+
watermarkPanelFooterButtonWrapper,
|
|
212
|
+
watermarkPanelFooterReset,
|
|
213
|
+
watermarkTextSetting,
|
|
214
|
+
watermarkTextSettingHeader,
|
|
215
|
+
watermarkTextSettingFontContent,
|
|
216
|
+
watermarkTextSettingFontStylePart,
|
|
217
|
+
watermarkTextSettingLayoutFontWrapper,
|
|
218
|
+
watermarkImageSetting,
|
|
219
|
+
watermarkInput,
|
|
220
|
+
watermarkInputContent,
|
|
221
|
+
watermarkIcon,
|
|
222
|
+
watermarkIconWrapper,
|
|
223
|
+
watermarkIconWrapperSelect,
|
|
224
|
+
watermarkColorPickerWrapper
|
|
225
|
+
}, WatermarkImageSetting = /* @__PURE__ */ __name(({ config, onChange }) => {
|
|
226
|
+
const fileOpenService = useDependency(ILocalFileService), localeService = useDependency(LocaleService);
|
|
227
|
+
if (!config) return null;
|
|
228
|
+
const handleUpdateImageUrl = /* @__PURE__ */ __name(async () => {
|
|
229
|
+
const files = await fileOpenService.openFile({
|
|
230
|
+
multiple: !1,
|
|
231
|
+
accept: WATERMARK_IMAGE_ALLOW_IMAGE_LIST.map((image) => `.${image.replace("image/", "")}`).join(",")
|
|
232
|
+
});
|
|
233
|
+
if (files.length === 0)
|
|
234
|
+
return !1;
|
|
235
|
+
const file = files[0], reader = new FileReader();
|
|
236
|
+
reader.onload = function(event) {
|
|
237
|
+
var _a5;
|
|
238
|
+
if ((_a5 = event.target) != null && _a5.result) {
|
|
239
|
+
const base64String = event.target.result, img = new Image();
|
|
240
|
+
img.onload = function() {
|
|
241
|
+
onChange({ ...config, url: base64String, width: Math.max(20, img.width), height: Math.max(img.height, 20), originRatio: img.width / img.height });
|
|
242
|
+
}, img.src = base64String;
|
|
243
|
+
}
|
|
244
|
+
}, reader.readAsDataURL(file);
|
|
245
|
+
}, "handleUpdateImageUrl");
|
|
246
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkImageSetting, children: [
|
|
247
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.watermarkTextSettingHeader, children: localeService.t("univer-watermark.image") }),
|
|
248
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayout, children: [
|
|
249
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: localeService.t("univer-watermark.image") }),
|
|
250
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
251
|
+
Button,
|
|
252
|
+
{
|
|
253
|
+
onClick: handleUpdateImageUrl,
|
|
254
|
+
style: { marginLeft: 8 },
|
|
255
|
+
children: config.url ? localeService.t("univer-watermark.replaceImage") : localeService.t("univer-watermark.uploadImage")
|
|
256
|
+
}
|
|
257
|
+
),
|
|
258
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingFontStylePart, children: [
|
|
259
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayoutFontWrapper, children: [
|
|
260
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.opacity") }),
|
|
261
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
262
|
+
InputNumber,
|
|
263
|
+
{
|
|
264
|
+
value: config.opacity,
|
|
265
|
+
onChange: /* @__PURE__ */ __name((val) => {
|
|
266
|
+
val != null && onChange({ ...config, opacity: Number.parseFloat(val.toString()) });
|
|
267
|
+
}, "onChange"),
|
|
268
|
+
max: 1,
|
|
269
|
+
min: 0,
|
|
270
|
+
step: 0.05,
|
|
271
|
+
className: styles.watermarkInput
|
|
272
|
+
}
|
|
273
|
+
)
|
|
274
|
+
] }),
|
|
275
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayoutFontWrapper, children: [
|
|
276
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.keepRatio") }),
|
|
277
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
278
|
+
Checkbox,
|
|
279
|
+
{
|
|
280
|
+
checked: config.maintainAspectRatio,
|
|
281
|
+
onChange: /* @__PURE__ */ __name((val) => {
|
|
282
|
+
onChange(val === !0 ? { ...config, maintainAspectRatio: val, height: Math.round(config.width / config.originRatio) } : { ...config, maintainAspectRatio: val });
|
|
283
|
+
}, "onChange")
|
|
284
|
+
}
|
|
285
|
+
)
|
|
286
|
+
] })
|
|
287
|
+
] })
|
|
288
|
+
] }),
|
|
289
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.watermarkTextSettingLayout, children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingFontStylePart, children: [
|
|
290
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayoutFontWrapper, children: [
|
|
291
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.width") }),
|
|
292
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
293
|
+
InputNumber,
|
|
294
|
+
{
|
|
295
|
+
value: config.width,
|
|
296
|
+
onChange: /* @__PURE__ */ __name((val) => {
|
|
297
|
+
if (val != null) {
|
|
298
|
+
const newWidth = Math.max(20, Number.parseInt(val.toString()));
|
|
299
|
+
config.maintainAspectRatio ? onChange({ ...config, width: newWidth, height: Math.round(newWidth / config.originRatio) }) : onChange({ ...config, width: newWidth });
|
|
300
|
+
}
|
|
301
|
+
}, "onChange"),
|
|
302
|
+
min: 20,
|
|
303
|
+
className: styles.watermarkInput
|
|
304
|
+
}
|
|
305
|
+
)
|
|
306
|
+
] }),
|
|
307
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayoutFontWrapper, children: [
|
|
308
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.height") }),
|
|
309
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
310
|
+
InputNumber,
|
|
311
|
+
{
|
|
312
|
+
value: config.height,
|
|
313
|
+
onChange: /* @__PURE__ */ __name((val) => {
|
|
314
|
+
if (val != null) {
|
|
315
|
+
const newHeight = Math.max(20, Number.parseInt(val.toString()));
|
|
316
|
+
config.maintainAspectRatio ? onChange({ ...config, height: newHeight, width: Math.round(newHeight * config.originRatio) }) : onChange({ ...config, height: Number.parseInt(val.toString()) });
|
|
317
|
+
}
|
|
318
|
+
}, "onChange"),
|
|
319
|
+
min: 20,
|
|
320
|
+
className: styles.watermarkInput
|
|
321
|
+
}
|
|
322
|
+
)
|
|
323
|
+
] })
|
|
324
|
+
] }) }),
|
|
325
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.watermarkTextSettingHeader, children: localeService.t("univer-watermark.layout") }),
|
|
326
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayout, children: [
|
|
327
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingFontStylePart, children: [
|
|
328
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayoutFontWrapper, children: [
|
|
329
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.rotate") }),
|
|
330
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
331
|
+
InputNumber,
|
|
332
|
+
{
|
|
333
|
+
value: config.rotate,
|
|
334
|
+
onChange: /* @__PURE__ */ __name((val) => {
|
|
335
|
+
val != null && onChange({ ...config, rotate: Number.parseInt(val.toString()) });
|
|
336
|
+
}, "onChange"),
|
|
337
|
+
max: 360,
|
|
338
|
+
min: -360,
|
|
339
|
+
className: styles.watermarkInput
|
|
340
|
+
}
|
|
341
|
+
)
|
|
342
|
+
] }),
|
|
343
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayoutFontWrapper, children: [
|
|
344
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.repeat") }),
|
|
345
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
346
|
+
Checkbox,
|
|
347
|
+
{
|
|
348
|
+
checked: config.repeat,
|
|
349
|
+
onChange: /* @__PURE__ */ __name((val) => onChange({ ...config, repeat: val }), "onChange")
|
|
350
|
+
}
|
|
351
|
+
)
|
|
352
|
+
] })
|
|
353
|
+
] }),
|
|
354
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingFontStylePart, children: [
|
|
355
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayoutFontWrapper, children: [
|
|
356
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.spacingX") }),
|
|
357
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
358
|
+
InputNumber,
|
|
359
|
+
{
|
|
360
|
+
value: config.spacingX,
|
|
361
|
+
onChange: /* @__PURE__ */ __name((val) => {
|
|
362
|
+
val != null && onChange({ ...config, spacingX: Number.parseInt(val.toString()) });
|
|
363
|
+
}, "onChange"),
|
|
364
|
+
min: 0,
|
|
365
|
+
className: styles.watermarkInput
|
|
366
|
+
}
|
|
367
|
+
)
|
|
368
|
+
] }),
|
|
369
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayoutFontWrapper, children: [
|
|
370
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.spacingY") }),
|
|
371
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
372
|
+
InputNumber,
|
|
373
|
+
{
|
|
374
|
+
value: config.spacingY,
|
|
375
|
+
onChange: /* @__PURE__ */ __name((val) => {
|
|
376
|
+
val != null && onChange({ ...config, spacingY: Number.parseInt(val.toString()) });
|
|
377
|
+
}, "onChange"),
|
|
378
|
+
min: 0,
|
|
379
|
+
className: styles.watermarkInput
|
|
380
|
+
}
|
|
381
|
+
)
|
|
382
|
+
] })
|
|
383
|
+
] }),
|
|
384
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingFontStylePart, children: [
|
|
385
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayoutFontWrapper, children: [
|
|
386
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.startX") }),
|
|
387
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
388
|
+
InputNumber,
|
|
389
|
+
{
|
|
390
|
+
value: config.x,
|
|
391
|
+
onChange: /* @__PURE__ */ __name((val) => {
|
|
392
|
+
val != null && onChange({ ...config, x: Number.parseInt(val.toString()) });
|
|
393
|
+
}, "onChange"),
|
|
394
|
+
min: 0,
|
|
395
|
+
className: styles.watermarkInput
|
|
396
|
+
}
|
|
397
|
+
)
|
|
398
|
+
] }),
|
|
399
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayoutFontWrapper, children: [
|
|
400
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.startY") }),
|
|
401
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
402
|
+
InputNumber,
|
|
403
|
+
{
|
|
404
|
+
value: config.y,
|
|
405
|
+
onChange: /* @__PURE__ */ __name((val) => {
|
|
406
|
+
val != null && onChange({ ...config, y: Number.parseInt(val.toString()) });
|
|
407
|
+
}, "onChange"),
|
|
408
|
+
min: 0,
|
|
409
|
+
className: styles.watermarkInput
|
|
410
|
+
}
|
|
411
|
+
)
|
|
412
|
+
] })
|
|
413
|
+
] })
|
|
414
|
+
] })
|
|
415
|
+
] });
|
|
416
|
+
}, "WatermarkImageSetting");
|
|
417
|
+
function r(e) {
|
|
418
|
+
var t, f2, n2 = "";
|
|
419
|
+
if (typeof e == "string" || typeof e == "number") n2 += e;
|
|
420
|
+
else if (typeof e == "object") if (Array.isArray(e)) {
|
|
421
|
+
var o = e.length;
|
|
422
|
+
for (t = 0; t < o; t++) e[t] && (f2 = r(e[t])) && (n2 && (n2 += " "), n2 += f2);
|
|
423
|
+
} else for (f2 in e) e[f2] && (n2 && (n2 += " "), n2 += f2);
|
|
424
|
+
return n2;
|
|
425
|
+
}
|
|
426
|
+
__name(r, "r");
|
|
427
|
+
function clsx() {
|
|
428
|
+
for (var e, t, f2 = 0, n2 = "", o = arguments.length; f2 < o; f2++) (e = arguments[f2]) && (t = r(e)) && (n2 && (n2 += " "), n2 += t);
|
|
429
|
+
return n2;
|
|
430
|
+
}
|
|
431
|
+
__name(clsx, "clsx");
|
|
432
|
+
const WatermarkTextSetting = /* @__PURE__ */ __name((props) => {
|
|
433
|
+
var _a5;
|
|
434
|
+
const { config, onChange } = props, localeService = useDependency(LocaleService);
|
|
435
|
+
return config ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSetting, children: [
|
|
436
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.watermarkTextSettingHeader, children: localeService.t("univer-watermark.style") }),
|
|
437
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingFontContent, children: [
|
|
438
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.content") }),
|
|
439
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
440
|
+
Input,
|
|
441
|
+
{
|
|
442
|
+
value: config.content,
|
|
443
|
+
onChange: /* @__PURE__ */ __name((val) => onChange({ ...config, content: val }), "onChange"),
|
|
444
|
+
className: styles.watermarkInputContent,
|
|
445
|
+
placeholder: localeService.t("univer-watermark.textPlaceholder")
|
|
446
|
+
}
|
|
447
|
+
)
|
|
448
|
+
] }),
|
|
449
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingFontStyle, children: [
|
|
450
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingFontStylePart, children: [
|
|
451
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
452
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.fontSize") }),
|
|
453
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
454
|
+
InputNumber,
|
|
455
|
+
{
|
|
456
|
+
value: config.fontSize,
|
|
457
|
+
onChange: /* @__PURE__ */ __name((val) => {
|
|
458
|
+
val != null && onChange({ ...config, fontSize: Number.parseInt(val.toString()) });
|
|
459
|
+
}, "onChange"),
|
|
460
|
+
max: 72,
|
|
461
|
+
min: 12,
|
|
462
|
+
className: styles.watermarkInput
|
|
463
|
+
}
|
|
464
|
+
)
|
|
465
|
+
] }),
|
|
466
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: { margin: "0 8px" }, children: [
|
|
467
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.direction") }),
|
|
468
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
469
|
+
Select,
|
|
470
|
+
{
|
|
471
|
+
value: config.direction,
|
|
472
|
+
onChange: /* @__PURE__ */ __name((v) => onChange({ ...config, direction: v }), "onChange"),
|
|
473
|
+
options: [
|
|
474
|
+
{ label: localeService.t("univer-watermark.ltr"), value: "ltr" },
|
|
475
|
+
{ label: localeService.t("univer-watermark.rtl"), value: "rtl" }
|
|
476
|
+
]
|
|
477
|
+
}
|
|
478
|
+
)
|
|
479
|
+
] }),
|
|
480
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
481
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.opacity") }),
|
|
482
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
483
|
+
InputNumber,
|
|
484
|
+
{
|
|
485
|
+
value: config.opacity,
|
|
486
|
+
onChange: /* @__PURE__ */ __name((val) => {
|
|
487
|
+
val != null && onChange({ ...config, opacity: Number.parseFloat(val.toString()) });
|
|
488
|
+
}, "onChange"),
|
|
489
|
+
max: 1,
|
|
490
|
+
min: 0,
|
|
491
|
+
step: 0.05,
|
|
492
|
+
className: styles.watermarkInput
|
|
493
|
+
}
|
|
494
|
+
)
|
|
495
|
+
] })
|
|
496
|
+
] }),
|
|
497
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingFontStylePart, children: [
|
|
498
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.watermarkIconWrapper, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
499
|
+
Dropdown,
|
|
500
|
+
{
|
|
501
|
+
overlay: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.watermarkColorPickerWrapper, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ColorPicker, { color: config.color, onChange: /* @__PURE__ */ __name((val) => onChange({ ...config, color: val }), "onChange") }) }),
|
|
502
|
+
children: /* @__PURE__ */ jsxRuntimeExports.jsx(FontColor, { className: styles.watermarkIcon, extend: { colorChannel1: (_a5 = config.color) != null ? _a5 : "rgb(var(--primary-color))" } })
|
|
503
|
+
}
|
|
504
|
+
) }),
|
|
505
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: clsx(styles.watermarkIconWrapper, { [styles.watermarkIconWrapperSelect]: config.bold }), onClick: /* @__PURE__ */ __name(() => {
|
|
506
|
+
onChange({ ...config, bold: !config.bold });
|
|
507
|
+
}, "onClick"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(BoldSingle, { className: styles.watermarkIcon }) }),
|
|
508
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: clsx(styles.watermarkIconWrapper, { [styles.watermarkIconWrapperSelect]: config.italic }), onClick: /* @__PURE__ */ __name(() => {
|
|
509
|
+
onChange({ ...config, italic: !config.italic });
|
|
510
|
+
}, "onClick"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(ItalicSingle, { className: styles.watermarkIcon }) })
|
|
511
|
+
] })
|
|
512
|
+
] }),
|
|
513
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.watermarkTextSettingHeader, children: localeService.t("univer-watermark.layout") }),
|
|
514
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayout, children: [
|
|
515
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingFontStylePart, children: [
|
|
516
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayoutFontWrapper, children: [
|
|
517
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.rotate") }),
|
|
518
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
519
|
+
InputNumber,
|
|
520
|
+
{
|
|
521
|
+
value: config.rotate,
|
|
522
|
+
onChange: /* @__PURE__ */ __name((val) => {
|
|
523
|
+
val != null && onChange({ ...config, rotate: Number.parseInt(val.toString()) });
|
|
524
|
+
}, "onChange"),
|
|
525
|
+
max: 360,
|
|
526
|
+
min: -360,
|
|
527
|
+
className: styles.watermarkInput
|
|
528
|
+
}
|
|
529
|
+
)
|
|
530
|
+
] }),
|
|
531
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayoutFontWrapper, children: [
|
|
532
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.repeat") }),
|
|
533
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
534
|
+
Checkbox,
|
|
535
|
+
{
|
|
536
|
+
checked: config.repeat,
|
|
537
|
+
onChange: /* @__PURE__ */ __name((val) => onChange({ ...config, repeat: val }), "onChange")
|
|
538
|
+
}
|
|
539
|
+
)
|
|
540
|
+
] })
|
|
541
|
+
] }),
|
|
542
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingFontStylePart, children: [
|
|
543
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayoutFontWrapper, children: [
|
|
544
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.spacingX") }),
|
|
545
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
546
|
+
InputNumber,
|
|
547
|
+
{
|
|
548
|
+
value: config.spacingX,
|
|
549
|
+
onChange: /* @__PURE__ */ __name((val) => {
|
|
550
|
+
val != null && onChange({ ...config, spacingX: Number.parseInt(val.toString()) });
|
|
551
|
+
}, "onChange"),
|
|
552
|
+
min: 0,
|
|
553
|
+
className: styles.watermarkInput
|
|
554
|
+
}
|
|
555
|
+
)
|
|
556
|
+
] }),
|
|
557
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayoutFontWrapper, children: [
|
|
558
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.spacingY") }),
|
|
559
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
560
|
+
InputNumber,
|
|
561
|
+
{
|
|
562
|
+
value: config.spacingY,
|
|
563
|
+
onChange: /* @__PURE__ */ __name((val) => {
|
|
564
|
+
val != null && onChange({ ...config, spacingY: Number.parseInt(val.toString()) });
|
|
565
|
+
}, "onChange"),
|
|
566
|
+
min: 0,
|
|
567
|
+
className: styles.watermarkInput
|
|
568
|
+
}
|
|
569
|
+
)
|
|
570
|
+
] })
|
|
571
|
+
] }),
|
|
572
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingFontStylePart, children: [
|
|
573
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayoutFontWrapper, children: [
|
|
574
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.startX") }),
|
|
575
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
576
|
+
InputNumber,
|
|
577
|
+
{
|
|
578
|
+
value: config.x,
|
|
579
|
+
onChange: /* @__PURE__ */ __name((val) => {
|
|
580
|
+
val != null && onChange({ ...config, x: Number.parseInt(val.toString()) });
|
|
581
|
+
}, "onChange"),
|
|
582
|
+
min: 0,
|
|
583
|
+
className: styles.watermarkInput
|
|
584
|
+
}
|
|
585
|
+
)
|
|
586
|
+
] }),
|
|
587
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkTextSettingLayoutFontWrapper, children: [
|
|
588
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t("univer-watermark.startY") }),
|
|
589
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
590
|
+
InputNumber,
|
|
591
|
+
{
|
|
592
|
+
value: config.y,
|
|
593
|
+
onChange: /* @__PURE__ */ __name((val) => {
|
|
594
|
+
val != null && onChange({ ...config, y: Number.parseInt(val.toString()) });
|
|
595
|
+
}, "onChange"),
|
|
596
|
+
min: 0,
|
|
597
|
+
className: styles.watermarkInput
|
|
598
|
+
}
|
|
599
|
+
)
|
|
600
|
+
] })
|
|
601
|
+
] })
|
|
602
|
+
] })
|
|
603
|
+
] }) : null;
|
|
604
|
+
}, "WatermarkTextSetting"), WatermarkPanel = /* @__PURE__ */ __name(() => {
|
|
605
|
+
const [watermarkType, setWatermarkType] = useState(IWatermarkTypeEnum.Text), [config, setConfig] = useState(), watermarkService = useDependency(WatermarkService), localStorageService = useDependency(ILocalStorageService), _refresh = useObservable(watermarkService.refresh$), localeService = useDependency(LocaleService);
|
|
606
|
+
function handleConfigChange(config2, type) {
|
|
607
|
+
setConfig(config2), watermarkService.updateWatermarkConfig({ type: type != null ? type : watermarkType, config: config2 });
|
|
608
|
+
}
|
|
609
|
+
__name(handleConfigChange, "handleConfigChange");
|
|
610
|
+
const getWatermarkConfig = useCallback(async () => {
|
|
611
|
+
const watermarkConfig = await localStorageService.getItem(UNIVER_WATERMARK_STORAGE_KEY);
|
|
612
|
+
watermarkConfig ? (setWatermarkType(watermarkConfig.type), setConfig(watermarkConfig.config)) : setConfig({ text: WatermarkTextBaseConfig });
|
|
613
|
+
}, []);
|
|
614
|
+
return useEffect(() => {
|
|
615
|
+
getWatermarkConfig();
|
|
616
|
+
}, [_refresh, getWatermarkConfig]), /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkPanel, children: [
|
|
617
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.watermarkPanelTypeTitle, children: localeService.t("univer-watermark.type") }),
|
|
618
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
619
|
+
Select,
|
|
620
|
+
{
|
|
621
|
+
value: watermarkType,
|
|
622
|
+
onChange: /* @__PURE__ */ __name((v) => {
|
|
623
|
+
setWatermarkType(v), v === IWatermarkTypeEnum.Text ? handleConfigChange({ text: WatermarkTextBaseConfig }, IWatermarkTypeEnum.Text) : v === IWatermarkTypeEnum.Image && handleConfigChange({ image: WatermarkImageBaseConfig }, IWatermarkTypeEnum.Image);
|
|
624
|
+
}, "onChange"),
|
|
625
|
+
options: [
|
|
626
|
+
{ label: localeService.t("univer-watermark.text"), value: IWatermarkTypeEnum.Text },
|
|
627
|
+
{ label: localeService.t("univer-watermark.image"), value: IWatermarkTypeEnum.Image }
|
|
628
|
+
],
|
|
629
|
+
className: styles.watermarkPanelTypeSelect
|
|
630
|
+
}
|
|
631
|
+
),
|
|
632
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkPanelSetting, children: [
|
|
633
|
+
watermarkType === IWatermarkTypeEnum.Text && /* @__PURE__ */ jsxRuntimeExports.jsx(WatermarkTextSetting, { config: config == null ? void 0 : config.text, onChange: /* @__PURE__ */ __name((v) => handleConfigChange({ text: v }), "onChange") }),
|
|
634
|
+
watermarkType === IWatermarkTypeEnum.Image && /* @__PURE__ */ jsxRuntimeExports.jsx(WatermarkImageSetting, { config: config == null ? void 0 : config.image, onChange: /* @__PURE__ */ __name((v) => handleConfigChange({ image: v }), "onChange") })
|
|
635
|
+
] })
|
|
636
|
+
] });
|
|
637
|
+
}, "WatermarkPanel"), WatermarkPanelFooter = /* @__PURE__ */ __name(() => {
|
|
638
|
+
const sidebarService = useDependency(ISidebarService), watermarkService = useDependency(WatermarkService), localeService = useDependency(LocaleService), clipboardService = useDependency(IClipboardInterfaceService);
|
|
639
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkPanelFooter, children: [
|
|
640
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
641
|
+
"div",
|
|
642
|
+
{
|
|
643
|
+
className: styles.watermarkPanelFooterReset,
|
|
644
|
+
onClick: /* @__PURE__ */ __name(() => {
|
|
645
|
+
watermarkService.updateWatermarkConfig({
|
|
646
|
+
type: IWatermarkTypeEnum.Text,
|
|
647
|
+
config: { text: WatermarkTextBaseConfig }
|
|
648
|
+
}), watermarkService.refresh();
|
|
649
|
+
}, "onClick"),
|
|
650
|
+
children: localeService.t("univer-watermark.cancel")
|
|
651
|
+
}
|
|
652
|
+
),
|
|
653
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.watermarkPanelFooterButtonWrapper, children: [
|
|
654
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
655
|
+
Button,
|
|
656
|
+
{
|
|
657
|
+
style: { marginRight: 8 },
|
|
658
|
+
onClick: /* @__PURE__ */ __name(async () => {
|
|
659
|
+
const watermarkConfig = await watermarkService.getWatermarkConfig();
|
|
660
|
+
let config;
|
|
661
|
+
(watermarkConfig == null ? void 0 : watermarkConfig.type) === IWatermarkTypeEnum.Text ? config = watermarkConfig.config.text : (watermarkConfig == null ? void 0 : watermarkConfig.type) === IWatermarkTypeEnum.Image && (config = watermarkConfig.config.image), clipboardService.writeText(JSON.stringify(config));
|
|
662
|
+
}, "onClick"),
|
|
663
|
+
children: localeService.t("univer-watermark.copy")
|
|
664
|
+
}
|
|
665
|
+
),
|
|
666
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
667
|
+
Button,
|
|
668
|
+
{
|
|
669
|
+
onClick: /* @__PURE__ */ __name(async () => {
|
|
670
|
+
var _a5, _b;
|
|
671
|
+
const watermarkConfig = await watermarkService.getWatermarkConfig();
|
|
672
|
+
((watermarkConfig == null ? void 0 : watermarkConfig.type) === IWatermarkTypeEnum.Text && !((_a5 = watermarkConfig.config.text) != null && _a5.content) || (watermarkConfig == null ? void 0 : watermarkConfig.type) === IWatermarkTypeEnum.Image && !((_b = watermarkConfig.config.image) != null && _b.url)) && watermarkService.deleteWatermarkConfig(), sidebarService.close();
|
|
673
|
+
}, "onClick"),
|
|
674
|
+
children: localeService.t("univer-watermark.close")
|
|
675
|
+
}
|
|
676
|
+
)
|
|
677
|
+
] })
|
|
678
|
+
] });
|
|
679
|
+
}, "WatermarkPanelFooter");
|
|
680
|
+
function WatermarkMenuItemFactory(accessor) {
|
|
681
|
+
return {
|
|
682
|
+
id: OpenWatermarkPanelOperation.id,
|
|
683
|
+
title: "univer-watermark.title",
|
|
684
|
+
tooltip: "univer-watermark.title",
|
|
685
|
+
icon: UNIVER_WATERMARK_MENU,
|
|
686
|
+
type: MenuItemType.BUTTON,
|
|
687
|
+
hidden$: getWatermarkMenuHiddenObservable(accessor)
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
__name(WatermarkMenuItemFactory, "WatermarkMenuItemFactory");
|
|
691
|
+
function getWatermarkMenuHiddenObservable(accessor) {
|
|
692
|
+
return accessor.get(IUniverInstanceService).focused$.pipe(
|
|
693
|
+
switchMap((id) => id === DOCS_ZEN_EDITOR_UNIT_ID_KEY ? of(!0) : of(!1))
|
|
694
|
+
);
|
|
695
|
+
}
|
|
696
|
+
__name(getWatermarkMenuHiddenObservable, "getWatermarkMenuHiddenObservable");
|
|
697
|
+
const menuSchema = {
|
|
698
|
+
[RibbonStartGroup.OTHERS]: {
|
|
699
|
+
[OpenWatermarkPanelOperation.id]: {
|
|
700
|
+
order: 0,
|
|
701
|
+
menuItemFactory: WatermarkMenuItemFactory
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
706
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
707
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
708
|
+
return kind && result && __defProp$2(target, key, result), result;
|
|
709
|
+
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a2;
|
|
710
|
+
let UniverWatermarkMenuController = (_a2 = class extends Disposable {
|
|
711
|
+
constructor(_menuManagerService, _componentManager) {
|
|
712
|
+
super(), this._menuManagerService = _menuManagerService, this._componentManager = _componentManager, this._initMenu(), this._initComponents();
|
|
713
|
+
}
|
|
714
|
+
_initComponents() {
|
|
715
|
+
[
|
|
716
|
+
[UNIVER_WATERMARK_MENU, WatermarkSingle],
|
|
717
|
+
[WATERMARK_PANEL, WatermarkPanel],
|
|
718
|
+
[WATERMARK_PANEL_FOOTER, WatermarkPanelFooter]
|
|
719
|
+
].forEach(([key, component]) => {
|
|
720
|
+
this.disposeWithMe(this._componentManager.register(key, component));
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
_initMenu() {
|
|
724
|
+
this._menuManagerService.mergeMenu(menuSchema);
|
|
725
|
+
}
|
|
726
|
+
}, __name(_a2, "UniverWatermarkMenuController"), _a2);
|
|
727
|
+
UniverWatermarkMenuController = __decorateClass$2([
|
|
728
|
+
__decorateParam$2(0, IMenuManagerService),
|
|
729
|
+
__decorateParam$2(1, Inject(ComponentManager))
|
|
730
|
+
], UniverWatermarkMenuController);
|
|
731
|
+
function renderWatermark(ctx, config, image, userInfo) {
|
|
732
|
+
const type = config.type, watermarkConfig = config.config;
|
|
733
|
+
type === IWatermarkTypeEnum.UserInfo && watermarkConfig.userInfo ? renderUserInfoWatermark(ctx, watermarkConfig.userInfo, userInfo) : type === IWatermarkTypeEnum.Image && watermarkConfig.image ? renderImageWatermark(ctx, watermarkConfig.image, image) : type === IWatermarkTypeEnum.Text && watermarkConfig.text && renderTextWatermark(ctx, watermarkConfig.text);
|
|
734
|
+
}
|
|
735
|
+
__name(renderWatermark, "renderWatermark");
|
|
736
|
+
function renderUserInfoWatermark(ctx, config, userInfo) {
|
|
737
|
+
const { x, y, repeat, spacingX, spacingY, rotate, opacity, name, fontSize, color, bold, italic, direction } = config;
|
|
738
|
+
if (!userInfo)
|
|
739
|
+
return;
|
|
740
|
+
let watermarkContent = "";
|
|
741
|
+
if (name && (watermarkContent += `${userInfo.name} `), !watermarkContent)
|
|
742
|
+
return;
|
|
743
|
+
ctx.save(), ctx.globalAlpha = opacity, ctx.direction = direction;
|
|
744
|
+
let fontStyle = "";
|
|
745
|
+
if (italic && (fontStyle += "italic "), bold && (fontStyle += "bold "), fontStyle += `${fontSize}px Arial`, ctx.font = fontStyle, ctx.fillStyle = color, repeat) {
|
|
746
|
+
const canvasWidth = ctx.canvas.width, canvasHeight = ctx.canvas.height;
|
|
747
|
+
for (let posY = y; posY < canvasHeight; posY += fontSize + spacingY)
|
|
748
|
+
for (let posX = x; posX < canvasWidth; posX += ctx.measureText(watermarkContent).width + spacingX)
|
|
749
|
+
ctx.save(), ctx.translate(posX, posY), ctx.rotate(Math.PI / 180 * rotate), ctx.fillText(watermarkContent, 0, 0), ctx.restore();
|
|
750
|
+
} else
|
|
751
|
+
ctx.save(), ctx.translate(x, y), ctx.rotate(Math.PI / 180 * rotate), ctx.fillText(watermarkContent, 0, 0), ctx.restore();
|
|
752
|
+
ctx.restore();
|
|
753
|
+
}
|
|
754
|
+
__name(renderUserInfoWatermark, "renderUserInfoWatermark");
|
|
755
|
+
function renderTextWatermark(ctx, config) {
|
|
756
|
+
const { x, y, repeat, spacingX, spacingY, rotate, opacity, content, fontSize, color, bold, italic, direction } = config;
|
|
757
|
+
ctx.save(), ctx.globalAlpha = opacity, ctx.direction = direction;
|
|
758
|
+
let fontStyle = "";
|
|
759
|
+
if (italic && (fontStyle += "italic "), bold && (fontStyle += "bold "), fontStyle += `${fontSize}px Arial`, ctx.font = fontStyle, ctx.fillStyle = color, content)
|
|
760
|
+
if (repeat) {
|
|
761
|
+
const canvasWidth = ctx.canvas.width, canvasHeight = ctx.canvas.height;
|
|
762
|
+
for (let posY = y; posY < canvasHeight; posY += fontSize + spacingY)
|
|
763
|
+
for (let posX = x; posX < canvasWidth; posX += ctx.measureText(content).width + spacingX)
|
|
764
|
+
ctx.save(), ctx.translate(posX, posY), ctx.rotate(Math.PI / 180 * rotate), ctx.fillText(content, 0, 0), ctx.restore();
|
|
765
|
+
} else
|
|
766
|
+
ctx.save(), ctx.translate(x, y), ctx.rotate(Math.PI / 180 * rotate), ctx.fillText(content, 0, 0), ctx.restore();
|
|
767
|
+
ctx.restore();
|
|
768
|
+
}
|
|
769
|
+
__name(renderTextWatermark, "renderTextWatermark");
|
|
770
|
+
function renderImageWatermark(ctx, config, image) {
|
|
771
|
+
const { x, y, repeat, spacingX, spacingY, rotate, opacity, width, height, maintainAspectRatio, originRatio } = config;
|
|
772
|
+
if (!(image != null && image.complete))
|
|
773
|
+
return;
|
|
774
|
+
ctx.save(), ctx.globalAlpha = opacity;
|
|
775
|
+
const actualWidth = width, actualHeight = maintainAspectRatio ? width / originRatio : height;
|
|
776
|
+
if (repeat) {
|
|
777
|
+
const canvasWidth = ctx.canvas.width, canvasHeight = ctx.canvas.height;
|
|
778
|
+
for (let posY = y; posY < canvasHeight; posY += actualHeight + spacingY)
|
|
779
|
+
for (let posX = x; posX < canvasWidth; posX += actualWidth + spacingX)
|
|
780
|
+
ctx.save(), ctx.translate(posX, posY), ctx.rotate(Math.PI / 180 * rotate), ctx.drawImage(image, 0, 0, actualWidth, actualHeight), ctx.restore();
|
|
781
|
+
} else
|
|
782
|
+
ctx.save(), ctx.translate(x, y), ctx.rotate(Math.PI / 180 * rotate), ctx.drawImage(image, 0, 0, actualWidth, actualHeight), ctx.restore();
|
|
783
|
+
ctx.restore();
|
|
784
|
+
}
|
|
785
|
+
__name(renderImageWatermark, "renderImageWatermark");
|
|
786
|
+
const _WatermarkLayer = class _WatermarkLayer extends Layer {
|
|
787
|
+
constructor() {
|
|
788
|
+
super(...arguments);
|
|
789
|
+
__publicField(this, "_config");
|
|
790
|
+
__publicField(this, "_image");
|
|
791
|
+
__publicField(this, "_user");
|
|
792
|
+
}
|
|
793
|
+
render(ctx, isMaxLayer = !1) {
|
|
794
|
+
var _a5;
|
|
795
|
+
super.render(ctx, isMaxLayer);
|
|
796
|
+
const mainCtx = ctx || ((_a5 = this.scene.getEngine()) == null ? void 0 : _a5.getCanvas().getContext());
|
|
797
|
+
return mainCtx && mainCtx.getId() && this._renderWatermark(mainCtx), this;
|
|
798
|
+
}
|
|
799
|
+
updateConfig(config, user) {
|
|
800
|
+
var _a5;
|
|
801
|
+
this._config = config, ((_a5 = this._config) == null ? void 0 : _a5.type) === IWatermarkTypeEnum.Image && this._config.config.image && (this._image = new Image(), this._image.src = this._config.config.image.url), user && (this._user = user);
|
|
802
|
+
}
|
|
803
|
+
_renderWatermark(ctx) {
|
|
804
|
+
this._config && renderWatermark(ctx, this._config, this._image, this._user);
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
__name(_WatermarkLayer, "WatermarkLayer");
|
|
808
|
+
let WatermarkLayer = _WatermarkLayer;
|
|
809
|
+
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
810
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
811
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
812
|
+
return kind && result && __defProp$1(target, key, result), result;
|
|
813
|
+
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a3;
|
|
814
|
+
let WatermarkRenderController = (_a3 = class extends RxDisposable {
|
|
815
|
+
constructor(_context, _watermarkService, _localStorageService, _userManagerService) {
|
|
816
|
+
super();
|
|
817
|
+
__publicField(this, "_watermarkLayer");
|
|
818
|
+
this._context = _context, this._watermarkService = _watermarkService, this._localStorageService = _localStorageService, this._userManagerService = _userManagerService, this._watermarkLayer = new WatermarkLayer(_context.scene, [], UNIVER_WATERMARK_LAYER_INDEX), this._initAddRender(), this._initWatermarkUpdate(), this._initWatermarkConfig();
|
|
819
|
+
}
|
|
820
|
+
_initAddRender() {
|
|
821
|
+
const { scene } = this._context;
|
|
822
|
+
scene.addLayer(this._watermarkLayer);
|
|
823
|
+
}
|
|
824
|
+
async _initWatermarkConfig() {
|
|
825
|
+
var _a5;
|
|
826
|
+
const config = await this._localStorageService.getItem(UNIVER_WATERMARK_STORAGE_KEY);
|
|
827
|
+
config && (this._watermarkService.updateWatermarkConfig(config), (_a5 = this._context.mainComponent) == null || _a5.makeDirty());
|
|
828
|
+
}
|
|
829
|
+
_initWatermarkUpdate() {
|
|
830
|
+
this.disposeWithMe(
|
|
831
|
+
this._watermarkService.updateConfig$.subscribe((_config) => {
|
|
832
|
+
var _a5, _b;
|
|
833
|
+
if (!_config) {
|
|
834
|
+
this._watermarkLayer.updateConfig(), (_a5 = this._context.mainComponent) == null || _a5.makeDirty();
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
_config.type === IWatermarkTypeEnum.UserInfo ? this._watermarkLayer.updateConfig(_config, this._userManagerService.getCurrentUser()) : this._watermarkLayer.updateConfig(_config), (_b = this._context.mainComponent) == null || _b.makeDirty();
|
|
838
|
+
})
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
}, __name(_a3, "WatermarkRenderController"), _a3);
|
|
842
|
+
WatermarkRenderController = __decorateClass$1([
|
|
843
|
+
__decorateParam$1(1, Inject(WatermarkService)),
|
|
844
|
+
__decorateParam$1(2, Inject(ILocalStorageService)),
|
|
845
|
+
__decorateParam$1(3, Inject(UserManagerService))
|
|
846
|
+
], WatermarkRenderController);
|
|
847
|
+
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
848
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
849
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
850
|
+
return kind && result && __defProp2(target, key, result), result;
|
|
851
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam");
|
|
852
|
+
const PLUGIN_NAME = "UNIVER_WATERMARK_PLUGIN";
|
|
853
|
+
var _a4;
|
|
854
|
+
let UniverWatermarkPlugin = (_a4 = class extends Plugin {
|
|
855
|
+
constructor(_config = {}, _injector, _configService, _commandService, _renderManagerSrv, _localStorageService) {
|
|
856
|
+
super(), this._config = _config, this._injector = _injector, this._configService = _configService, this._commandService = _commandService, this._renderManagerSrv = _renderManagerSrv, this._localStorageService = _localStorageService;
|
|
857
|
+
const { menu } = this._config;
|
|
858
|
+
menu && this._configService.setConfig("menu", menu, { merge: !0 }), this._initWatermarkStorage(), this._initDependencies(), this._initRegisterCommand();
|
|
859
|
+
}
|
|
860
|
+
async _initWatermarkStorage() {
|
|
861
|
+
const { menu, ...rest } = this._config;
|
|
862
|
+
if (rest.userWatermarkSettings)
|
|
863
|
+
this._localStorageService.setItem(UNIVER_WATERMARK_STORAGE_KEY, { type: IWatermarkTypeEnum.UserInfo, config: { userInfo: { ...WatermarkUserInfoBaseConfig, ...rest.userWatermarkSettings } } });
|
|
864
|
+
else if (rest.textWatermarkSettings)
|
|
865
|
+
this._localStorageService.setItem(UNIVER_WATERMARK_STORAGE_KEY, { type: IWatermarkTypeEnum.Text, config: { text: { ...WatermarkTextBaseConfig, ...rest.textWatermarkSettings } } });
|
|
866
|
+
else if (rest.imageWatermarkSettings)
|
|
867
|
+
this._localStorageService.setItem(UNIVER_WATERMARK_STORAGE_KEY, { type: IWatermarkTypeEnum.Image, config: { image: { ...WatermarkImageBaseConfig, ...rest.imageWatermarkSettings } } });
|
|
868
|
+
else {
|
|
869
|
+
const config = await this._localStorageService.getItem(UNIVER_WATERMARK_STORAGE_KEY);
|
|
870
|
+
(config == null ? void 0 : config.type) === IWatermarkTypeEnum.UserInfo && this._localStorageService.removeItem(UNIVER_WATERMARK_STORAGE_KEY);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
_initDependencies() {
|
|
874
|
+
[[WatermarkService], [UniverWatermarkMenuController]].forEach((d) => {
|
|
875
|
+
this._injector.add(d);
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
_initRegisterCommand() {
|
|
879
|
+
[
|
|
880
|
+
OpenWatermarkPanelOperation
|
|
881
|
+
].forEach((m2) => this._commandService.registerCommand(m2));
|
|
882
|
+
}
|
|
883
|
+
onRendered() {
|
|
884
|
+
const injector = this._injector;
|
|
885
|
+
injector.get(WatermarkService);
|
|
886
|
+
const { userWatermarkSettings, textWatermarkSettings, imageWatermarkSettings, showMenu = !0 } = this._config;
|
|
887
|
+
!(userWatermarkSettings || textWatermarkSettings || imageWatermarkSettings) && showMenu && injector.get(UniverWatermarkMenuController), this._initRenderDependencies();
|
|
888
|
+
}
|
|
889
|
+
_initRenderDependencies() {
|
|
890
|
+
[
|
|
891
|
+
[WatermarkRenderController]
|
|
892
|
+
].forEach((d) => {
|
|
893
|
+
this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_SHEET, d), this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_DOC, d);
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
}, __name(_a4, "UniverWatermarkPlugin"), __publicField(_a4, "pluginName", PLUGIN_NAME), _a4);
|
|
897
|
+
UniverWatermarkPlugin = __decorateClass([
|
|
898
|
+
__decorateParam(1, Inject(Injector)),
|
|
899
|
+
__decorateParam(2, IConfigService),
|
|
900
|
+
__decorateParam(3, Inject(ICommandService)),
|
|
901
|
+
__decorateParam(4, IRenderManagerService),
|
|
902
|
+
__decorateParam(5, Inject(ILocalStorageService))
|
|
903
|
+
], UniverWatermarkPlugin);
|
|
904
|
+
export {
|
|
905
|
+
IWatermarkTypeEnum,
|
|
906
|
+
UniverWatermarkPlugin,
|
|
907
|
+
WatermarkImageBaseConfig,
|
|
908
|
+
WatermarkService,
|
|
909
|
+
WatermarkTextBaseConfig,
|
|
910
|
+
WatermarkUserInfoBaseConfig
|
|
911
|
+
};
|