@univerjs/watermark 0.20.1 → 0.21.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/facade.js CHANGED
@@ -1 +1,39 @@
1
- let e=require(`@univerjs/core/facade`),t=require(`@univerjs/engine-render`),n=require(`@univerjs/watermark`);var r=class extends e.FEnum{get IWatermarkTypeEnum(){return t.IWatermarkTypeEnum}},i=class extends e.FUniver{addWatermark(e,r){let i=this._injector.get(n.WatermarkService);if(e===t.IWatermarkTypeEnum.Text)i.updateWatermarkConfig({type:t.IWatermarkTypeEnum.Text,config:{text:{...n.WatermarkTextBaseConfig,...r}}});else if(e===t.IWatermarkTypeEnum.Image)i.updateWatermarkConfig({type:t.IWatermarkTypeEnum.Image,config:{image:{...n.WatermarkImageBaseConfig,...r}}});else throw Error(`Unknown watermark type`);return this}deleteWatermark(){return this._injector.get(n.WatermarkService).deleteWatermarkConfig(),this}};e.FUniver.extend(i),e.FEnum.extend(r);
1
+ let _univerjs_core_facade = require("@univerjs/core/facade");
2
+ let _univerjs_engine_render = require("@univerjs/engine-render");
3
+ let _univerjs_watermark = require("@univerjs/watermark");
4
+
5
+ //#region src/facade/f-univer.ts
6
+ var FWatermarkEnumMixin = class extends _univerjs_core_facade.FEnum {
7
+ get IWatermarkTypeEnum() {
8
+ return _univerjs_engine_render.IWatermarkTypeEnum;
9
+ }
10
+ };
11
+ var FUniverWatermarkMixin = class extends _univerjs_core_facade.FUniver {
12
+ addWatermark(type, config) {
13
+ const watermarkService = this._injector.get(_univerjs_watermark.WatermarkService);
14
+ if (type === _univerjs_engine_render.IWatermarkTypeEnum.Text) watermarkService.updateWatermarkConfig({
15
+ type: _univerjs_engine_render.IWatermarkTypeEnum.Text,
16
+ config: { text: {
17
+ ..._univerjs_watermark.WatermarkTextBaseConfig,
18
+ ...config
19
+ } }
20
+ });
21
+ else if (type === _univerjs_engine_render.IWatermarkTypeEnum.Image) watermarkService.updateWatermarkConfig({
22
+ type: _univerjs_engine_render.IWatermarkTypeEnum.Image,
23
+ config: { image: {
24
+ ..._univerjs_watermark.WatermarkImageBaseConfig,
25
+ ...config
26
+ } }
27
+ });
28
+ else throw new Error("Unknown watermark type");
29
+ return this;
30
+ }
31
+ deleteWatermark() {
32
+ this._injector.get(_univerjs_watermark.WatermarkService).deleteWatermarkConfig();
33
+ return this;
34
+ }
35
+ };
36
+ _univerjs_core_facade.FUniver.extend(FUniverWatermarkMixin);
37
+ _univerjs_core_facade.FEnum.extend(FWatermarkEnumMixin);
38
+
39
+ //#endregion
package/lib/cjs/index.js CHANGED
@@ -1 +1,289 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/engine-render`),n=require(`rxjs`);const r=[`image/png`,`image/jpeg`,`image/jpg`,`image/bmp`],i={content:``,fontSize:16,color:`rgb(0,0,0)`,bold:!1,italic:!1,direction:`ltr`,x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},a={url:``,width:100,height:100,maintainAspectRatio:!0,originRatio:1,x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},o={name:!0,email:!1,phone:!1,uid:!1,fontSize:16,color:`rgb(0,0,0)`,bold:!1,italic:!1,direction:`ltr`,x:60,y:60,repeat:!0,spacingX:200,spacingY:100,rotate:-30,opacity:.15};var s=`@univerjs/watermark`,c=`0.20.1`;const l=`watermark.config`;Symbol(l);const u={};function d(e){"@babel/helpers - typeof";return d=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},d(e)}function f(e,t){if(d(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(d(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function p(e){var t=f(e,`string`);return d(t)==`symbol`?t:t+``}function m(e,t,n){return(t=p(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h(e,t){return function(n,r){t(n,r,e)}}function g(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let _=class extends e.Disposable{constructor(e){super(),this._localStorageService=e,m(this,`_updateConfig$`,new n.Subject),m(this,`updateConfig$`,this._updateConfig$.asObservable()),m(this,`_refresh$`,new n.Subject),m(this,`refresh$`,this._refresh$.asObservable())}async getWatermarkConfig(){return await this._localStorageService.getItem(t.UNIVER_WATERMARK_STORAGE_KEY)}updateWatermarkConfig(e){this._localStorageService.setItem(t.UNIVER_WATERMARK_STORAGE_KEY,e),this._updateConfig$.next(e)}deleteWatermarkConfig(){this._localStorageService.removeItem(t.UNIVER_WATERMARK_STORAGE_KEY),this._updateConfig$.next(null)}refresh(){this._refresh$.next(Math.random())}dispose(){this._refresh$.complete(),this._updateConfig$.complete()}};_=g([h(0,(0,e.Inject)(e.ILocalStorageService))],_);let v=class extends e.RxDisposable{constructor(e,n,r,i){super(),this._context=e,this._watermarkService=n,this._localStorageService=r,this._userManagerService=i,m(this,`_watermarkLayer`,void 0),this._watermarkLayer=new t.WatermarkLayer(e.scene,[],t.UNIVER_WATERMARK_LAYER_INDEX),this._initAddRender(),this._initWatermarkUpdate(),this._initWatermarkConfig()}_initAddRender(){let{scene:e}=this._context;e.addLayer(this._watermarkLayer)}async _initWatermarkConfig(){let e=await this._localStorageService.getItem(t.UNIVER_WATERMARK_STORAGE_KEY);if(e){var n;this._watermarkService.updateWatermarkConfig(e),(n=this._context.mainComponent)==null||n.makeDirty()}}_initWatermarkUpdate(){this.disposeWithMe(this._watermarkService.updateConfig$.subscribe(e=>{var n;if(!e){var r;this._watermarkLayer.updateConfig(),(r=this._context.mainComponent)==null||r.makeDirty();return}e.type===t.IWatermarkTypeEnum.UserInfo?this._watermarkLayer.updateConfig(e,this._userManagerService.getCurrentUser()):this._watermarkLayer.updateConfig(e),(n=this._context.mainComponent)==null||n.makeDirty()}))}};v=g([h(1,(0,e.Inject)(_)),h(2,(0,e.Inject)(e.ILocalStorageService)),h(3,(0,e.Inject)(e.UserManagerService))],v);let y=class extends e.Plugin{constructor(t=u,n,r,i,a){super(),this._config=t,this._injector=n,this._configService=r,this._renderManagerSrv=i,this._localStorageService=a;let{...o}=(0,e.merge)({},u,this._config);this._configService.setConfig(l,o),this._initWatermarkStorage(),this._initDependencies()}async _initWatermarkStorage(){let n=this._configService.getConfig(l);if(!n)return;let{userWatermarkSettings:r,textWatermarkSettings:s,imageWatermarkSettings:c}=n;if(r)this._localStorageService.setItem(t.UNIVER_WATERMARK_STORAGE_KEY,{type:t.IWatermarkTypeEnum.UserInfo,config:{userInfo:(0,e.merge)({},o,r)}});else if(s)this._localStorageService.setItem(t.UNIVER_WATERMARK_STORAGE_KEY,{type:t.IWatermarkTypeEnum.Text,config:{text:(0,e.merge)({},i,s)}});else if(c)this._localStorageService.setItem(t.UNIVER_WATERMARK_STORAGE_KEY,{type:t.IWatermarkTypeEnum.Image,config:{image:(0,e.merge)({},a,c)}});else{let e=await this._localStorageService.getItem(t.UNIVER_WATERMARK_STORAGE_KEY);(e==null?void 0:e.type)===t.IWatermarkTypeEnum.UserInfo&&this._localStorageService.removeItem(t.UNIVER_WATERMARK_STORAGE_KEY)}}_initDependencies(){[[_]].forEach(e=>{this._injector.add(e)})}onRendered(){this._injector.get(_),this._initRenderDependencies()}_initRenderDependencies(){[[v]].forEach(t=>{this._renderManagerSrv.registerRenderModule(e.UniverInstanceType.UNIVER_SHEET,t),this._renderManagerSrv.registerRenderModule(e.UniverInstanceType.UNIVER_DOC,t)})}};m(y,`pluginName`,`UNIVER_WATERMARK_PLUGIN`),m(y,`packageName`,s),m(y,`version`,c),y=g([h(1,(0,e.Inject)(e.Injector)),h(2,e.IConfigService),h(3,t.IRenderManagerService),h(4,(0,e.Inject)(e.ILocalStorageService))],y),Object.defineProperty(exports,`UniverWatermarkPlugin`,{enumerable:!0,get:function(){return y}}),exports.WATERMARK_IMAGE_ALLOW_IMAGE_LIST=r,exports.WatermarkImageBaseConfig=a,Object.defineProperty(exports,`WatermarkService`,{enumerable:!0,get:function(){return _}}),exports.WatermarkTextBaseConfig=i,exports.WatermarkUserInfoBaseConfig=o;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let _univerjs_core = require("@univerjs/core");
3
+ let _univerjs_engine_render = require("@univerjs/engine-render");
4
+ let rxjs = require("rxjs");
5
+
6
+ //#region src/common/const.ts
7
+ const WATERMARK_IMAGE_ALLOW_IMAGE_LIST = [
8
+ "image/png",
9
+ "image/jpeg",
10
+ "image/jpg",
11
+ "image/bmp"
12
+ ];
13
+ const WatermarkTextBaseConfig = {
14
+ content: "",
15
+ fontSize: 16,
16
+ color: "rgb(0,0,0)",
17
+ bold: false,
18
+ italic: false,
19
+ direction: "ltr",
20
+ x: 60,
21
+ y: 36,
22
+ repeat: true,
23
+ spacingX: 200,
24
+ spacingY: 100,
25
+ rotate: 0,
26
+ opacity: .15
27
+ };
28
+ const WatermarkImageBaseConfig = {
29
+ url: "",
30
+ width: 100,
31
+ height: 100,
32
+ maintainAspectRatio: true,
33
+ originRatio: 1,
34
+ x: 60,
35
+ y: 36,
36
+ repeat: true,
37
+ spacingX: 200,
38
+ spacingY: 100,
39
+ rotate: 0,
40
+ opacity: .15
41
+ };
42
+ const WatermarkUserInfoBaseConfig = {
43
+ name: true,
44
+ email: false,
45
+ phone: false,
46
+ uid: false,
47
+ fontSize: 16,
48
+ color: "rgb(0,0,0)",
49
+ bold: false,
50
+ italic: false,
51
+ direction: "ltr",
52
+ x: 60,
53
+ y: 60,
54
+ repeat: true,
55
+ spacingX: 200,
56
+ spacingY: 100,
57
+ rotate: -30,
58
+ opacity: .15
59
+ };
60
+
61
+ //#endregion
62
+ //#region package.json
63
+ var name = "@univerjs/watermark";
64
+ var version = "0.21.0";
65
+
66
+ //#endregion
67
+ //#region src/config/config.ts
68
+ const WATERMARK_PLUGIN_CONFIG_KEY = "watermark.config";
69
+ const configSymbol = Symbol(WATERMARK_PLUGIN_CONFIG_KEY);
70
+ const defaultPluginConfig = {};
71
+
72
+ //#endregion
73
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
74
+ function _typeof(o) {
75
+ "@babel/helpers - typeof";
76
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
77
+ return typeof o;
78
+ } : function(o) {
79
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
80
+ }, _typeof(o);
81
+ }
82
+
83
+ //#endregion
84
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
85
+ function toPrimitive(t, r) {
86
+ if ("object" != _typeof(t) || !t) return t;
87
+ var e = t[Symbol.toPrimitive];
88
+ if (void 0 !== e) {
89
+ var i = e.call(t, r || "default");
90
+ if ("object" != _typeof(i)) return i;
91
+ throw new TypeError("@@toPrimitive must return a primitive value.");
92
+ }
93
+ return ("string" === r ? String : Number)(t);
94
+ }
95
+
96
+ //#endregion
97
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
98
+ function toPropertyKey(t) {
99
+ var i = toPrimitive(t, "string");
100
+ return "symbol" == _typeof(i) ? i : i + "";
101
+ }
102
+
103
+ //#endregion
104
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
105
+ function _defineProperty(e, r, t) {
106
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
107
+ value: t,
108
+ enumerable: !0,
109
+ configurable: !0,
110
+ writable: !0
111
+ }) : e[r] = t, e;
112
+ }
113
+
114
+ //#endregion
115
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
116
+ function __decorateParam(paramIndex, decorator) {
117
+ return function(target, key) {
118
+ decorator(target, key, paramIndex);
119
+ };
120
+ }
121
+
122
+ //#endregion
123
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
124
+ function __decorate(decorators, target, key, desc) {
125
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
126
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
127
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
128
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
129
+ }
130
+
131
+ //#endregion
132
+ //#region src/services/watermark.service.ts
133
+ let WatermarkService = class WatermarkService extends _univerjs_core.Disposable {
134
+ constructor(_localStorageService) {
135
+ super();
136
+ this._localStorageService = _localStorageService;
137
+ _defineProperty(this, "_updateConfig$", new rxjs.Subject());
138
+ _defineProperty(this, "updateConfig$", this._updateConfig$.asObservable());
139
+ _defineProperty(this, "_refresh$", new rxjs.Subject());
140
+ _defineProperty(this, "refresh$", this._refresh$.asObservable());
141
+ }
142
+ async getWatermarkConfig() {
143
+ return await this._localStorageService.getItem(_univerjs_engine_render.UNIVER_WATERMARK_STORAGE_KEY);
144
+ }
145
+ updateWatermarkConfig(config) {
146
+ this._localStorageService.setItem(_univerjs_engine_render.UNIVER_WATERMARK_STORAGE_KEY, config);
147
+ this._updateConfig$.next(config);
148
+ }
149
+ deleteWatermarkConfig() {
150
+ this._localStorageService.removeItem(_univerjs_engine_render.UNIVER_WATERMARK_STORAGE_KEY);
151
+ this._updateConfig$.next(null);
152
+ }
153
+ refresh() {
154
+ this._refresh$.next(Math.random());
155
+ }
156
+ dispose() {
157
+ this._refresh$.complete();
158
+ this._updateConfig$.complete();
159
+ }
160
+ };
161
+ WatermarkService = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.ILocalStorageService))], WatermarkService);
162
+
163
+ //#endregion
164
+ //#region src/controllers/watermark.render.controller.ts
165
+ let WatermarkRenderController = class WatermarkRenderController extends _univerjs_core.RxDisposable {
166
+ constructor(_context, _watermarkService, _localStorageService, _userManagerService) {
167
+ super();
168
+ this._context = _context;
169
+ this._watermarkService = _watermarkService;
170
+ this._localStorageService = _localStorageService;
171
+ this._userManagerService = _userManagerService;
172
+ _defineProperty(this, "_watermarkLayer", void 0);
173
+ this._watermarkLayer = new _univerjs_engine_render.WatermarkLayer(_context.scene, [], _univerjs_engine_render.UNIVER_WATERMARK_LAYER_INDEX);
174
+ this._initAddRender();
175
+ this._initWatermarkUpdate();
176
+ this._initWatermarkConfig();
177
+ }
178
+ _initAddRender() {
179
+ const { scene } = this._context;
180
+ scene.addLayer(this._watermarkLayer);
181
+ }
182
+ async _initWatermarkConfig() {
183
+ const config = await this._localStorageService.getItem(_univerjs_engine_render.UNIVER_WATERMARK_STORAGE_KEY);
184
+ if (config) {
185
+ var _this$_context$mainCo;
186
+ this._watermarkService.updateWatermarkConfig(config);
187
+ (_this$_context$mainCo = this._context.mainComponent) === null || _this$_context$mainCo === void 0 || _this$_context$mainCo.makeDirty();
188
+ }
189
+ }
190
+ _initWatermarkUpdate() {
191
+ this.disposeWithMe(this._watermarkService.updateConfig$.subscribe((_config) => {
192
+ var _this$_context$mainCo3;
193
+ if (!_config) {
194
+ var _this$_context$mainCo2;
195
+ this._watermarkLayer.updateConfig();
196
+ (_this$_context$mainCo2 = this._context.mainComponent) === null || _this$_context$mainCo2 === void 0 || _this$_context$mainCo2.makeDirty();
197
+ return;
198
+ }
199
+ if (_config.type === _univerjs_engine_render.IWatermarkTypeEnum.UserInfo) this._watermarkLayer.updateConfig(_config, this._userManagerService.getCurrentUser());
200
+ else this._watermarkLayer.updateConfig(_config);
201
+ (_this$_context$mainCo3 = this._context.mainComponent) === null || _this$_context$mainCo3 === void 0 || _this$_context$mainCo3.makeDirty();
202
+ }));
203
+ }
204
+ };
205
+ WatermarkRenderController = __decorate([
206
+ __decorateParam(1, (0, _univerjs_core.Inject)(WatermarkService)),
207
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.ILocalStorageService)),
208
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.UserManagerService))
209
+ ], WatermarkRenderController);
210
+
211
+ //#endregion
212
+ //#region src/plugin.ts
213
+ let UniverWatermarkPlugin = class UniverWatermarkPlugin extends _univerjs_core.Plugin {
214
+ constructor(_config = defaultPluginConfig, _injector, _configService, _renderManagerSrv, _localStorageService) {
215
+ super();
216
+ this._config = _config;
217
+ this._injector = _injector;
218
+ this._configService = _configService;
219
+ this._renderManagerSrv = _renderManagerSrv;
220
+ this._localStorageService = _localStorageService;
221
+ const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
222
+ this._configService.setConfig(WATERMARK_PLUGIN_CONFIG_KEY, rest);
223
+ this._initWatermarkStorage();
224
+ this._initDependencies();
225
+ }
226
+ async _initWatermarkStorage() {
227
+ const config = this._configService.getConfig(WATERMARK_PLUGIN_CONFIG_KEY);
228
+ if (!config) return;
229
+ const { userWatermarkSettings, textWatermarkSettings, imageWatermarkSettings } = config;
230
+ if (userWatermarkSettings) this._localStorageService.setItem(_univerjs_engine_render.UNIVER_WATERMARK_STORAGE_KEY, {
231
+ type: _univerjs_engine_render.IWatermarkTypeEnum.UserInfo,
232
+ config: { userInfo: (0, _univerjs_core.merge)({}, WatermarkUserInfoBaseConfig, userWatermarkSettings) }
233
+ });
234
+ else if (textWatermarkSettings) this._localStorageService.setItem(_univerjs_engine_render.UNIVER_WATERMARK_STORAGE_KEY, {
235
+ type: _univerjs_engine_render.IWatermarkTypeEnum.Text,
236
+ config: { text: (0, _univerjs_core.merge)({}, WatermarkTextBaseConfig, textWatermarkSettings) }
237
+ });
238
+ else if (imageWatermarkSettings) this._localStorageService.setItem(_univerjs_engine_render.UNIVER_WATERMARK_STORAGE_KEY, {
239
+ type: _univerjs_engine_render.IWatermarkTypeEnum.Image,
240
+ config: { image: (0, _univerjs_core.merge)({}, WatermarkImageBaseConfig, imageWatermarkSettings) }
241
+ });
242
+ else {
243
+ const config = await this._localStorageService.getItem(_univerjs_engine_render.UNIVER_WATERMARK_STORAGE_KEY);
244
+ if ((config === null || config === void 0 ? void 0 : config.type) === _univerjs_engine_render.IWatermarkTypeEnum.UserInfo) this._localStorageService.removeItem(_univerjs_engine_render.UNIVER_WATERMARK_STORAGE_KEY);
245
+ }
246
+ }
247
+ _initDependencies() {
248
+ [[WatermarkService]].forEach((d) => {
249
+ this._injector.add(d);
250
+ });
251
+ }
252
+ onRendered() {
253
+ this._injector.get(WatermarkService);
254
+ this._initRenderDependencies();
255
+ }
256
+ _initRenderDependencies() {
257
+ [[WatermarkRenderController]].forEach((d) => {
258
+ this._renderManagerSrv.registerRenderModule(_univerjs_core.UniverInstanceType.UNIVER_SHEET, d);
259
+ this._renderManagerSrv.registerRenderModule(_univerjs_core.UniverInstanceType.UNIVER_DOC, d);
260
+ });
261
+ }
262
+ };
263
+ _defineProperty(UniverWatermarkPlugin, "pluginName", "UNIVER_WATERMARK_PLUGIN");
264
+ _defineProperty(UniverWatermarkPlugin, "packageName", name);
265
+ _defineProperty(UniverWatermarkPlugin, "version", version);
266
+ UniverWatermarkPlugin = __decorate([
267
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
268
+ __decorateParam(2, _univerjs_core.IConfigService),
269
+ __decorateParam(3, _univerjs_engine_render.IRenderManagerService),
270
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_core.ILocalStorageService))
271
+ ], UniverWatermarkPlugin);
272
+
273
+ //#endregion
274
+ Object.defineProperty(exports, 'UniverWatermarkPlugin', {
275
+ enumerable: true,
276
+ get: function () {
277
+ return UniverWatermarkPlugin;
278
+ }
279
+ });
280
+ exports.WATERMARK_IMAGE_ALLOW_IMAGE_LIST = WATERMARK_IMAGE_ALLOW_IMAGE_LIST;
281
+ exports.WatermarkImageBaseConfig = WatermarkImageBaseConfig;
282
+ Object.defineProperty(exports, 'WatermarkService', {
283
+ enumerable: true,
284
+ get: function () {
285
+ return WatermarkService;
286
+ }
287
+ });
288
+ exports.WatermarkTextBaseConfig = WatermarkTextBaseConfig;
289
+ exports.WatermarkUserInfoBaseConfig = WatermarkUserInfoBaseConfig;
package/lib/es/facade.js CHANGED
@@ -1 +1,40 @@
1
- import{FEnum as e,FUniver as t}from"@univerjs/core/facade";import{IWatermarkTypeEnum as n}from"@univerjs/engine-render";import{WatermarkImageBaseConfig as r,WatermarkService as i,WatermarkTextBaseConfig as a}from"@univerjs/watermark";var o=class extends e{get IWatermarkTypeEnum(){return n}},s=class extends t{addWatermark(e,t){let o=this._injector.get(i);if(e===n.Text)o.updateWatermarkConfig({type:n.Text,config:{text:{...a,...t}}});else if(e===n.Image)o.updateWatermarkConfig({type:n.Image,config:{image:{...r,...t}}});else throw Error(`Unknown watermark type`);return this}deleteWatermark(){return this._injector.get(i).deleteWatermarkConfig(),this}};t.extend(s),e.extend(o);export{};
1
+ import { FEnum, FUniver } from "@univerjs/core/facade";
2
+ import { IWatermarkTypeEnum } from "@univerjs/engine-render";
3
+ import { WatermarkImageBaseConfig, WatermarkService, WatermarkTextBaseConfig } from "@univerjs/watermark";
4
+
5
+ //#region src/facade/f-univer.ts
6
+ var FWatermarkEnumMixin = class extends FEnum {
7
+ get IWatermarkTypeEnum() {
8
+ return IWatermarkTypeEnum;
9
+ }
10
+ };
11
+ var FUniverWatermarkMixin = class extends FUniver {
12
+ addWatermark(type, config) {
13
+ const watermarkService = this._injector.get(WatermarkService);
14
+ if (type === IWatermarkTypeEnum.Text) watermarkService.updateWatermarkConfig({
15
+ type: IWatermarkTypeEnum.Text,
16
+ config: { text: {
17
+ ...WatermarkTextBaseConfig,
18
+ ...config
19
+ } }
20
+ });
21
+ else if (type === IWatermarkTypeEnum.Image) watermarkService.updateWatermarkConfig({
22
+ type: IWatermarkTypeEnum.Image,
23
+ config: { image: {
24
+ ...WatermarkImageBaseConfig,
25
+ ...config
26
+ } }
27
+ });
28
+ else throw new Error("Unknown watermark type");
29
+ return this;
30
+ }
31
+ deleteWatermark() {
32
+ this._injector.get(WatermarkService).deleteWatermarkConfig();
33
+ return this;
34
+ }
35
+ };
36
+ FUniver.extend(FUniverWatermarkMixin);
37
+ FEnum.extend(FWatermarkEnumMixin);
38
+
39
+ //#endregion
40
+ export { };
package/lib/es/index.js CHANGED
@@ -1 +1,273 @@
1
- import{Disposable as e,IConfigService as t,ILocalStorageService as n,Inject as r,Injector as i,Plugin as a,RxDisposable as o,UniverInstanceType as s,UserManagerService as c,merge as l}from"@univerjs/core";import{IRenderManagerService as u,IWatermarkTypeEnum as d,UNIVER_WATERMARK_LAYER_INDEX as f,UNIVER_WATERMARK_STORAGE_KEY as p,WatermarkLayer as m}from"@univerjs/engine-render";import{Subject as h}from"rxjs";const g=[`image/png`,`image/jpeg`,`image/jpg`,`image/bmp`],_={content:``,fontSize:16,color:`rgb(0,0,0)`,bold:!1,italic:!1,direction:`ltr`,x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},v={url:``,width:100,height:100,maintainAspectRatio:!0,originRatio:1,x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},y={name:!0,email:!1,phone:!1,uid:!1,fontSize:16,color:`rgb(0,0,0)`,bold:!1,italic:!1,direction:`ltr`,x:60,y:60,repeat:!0,spacingX:200,spacingY:100,rotate:-30,opacity:.15};var b=`@univerjs/watermark`,x=`0.20.1`;const S=`watermark.config`;Symbol(S);const C={};function w(e){"@babel/helpers - typeof";return w=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},w(e)}function T(e,t){if(w(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(w(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function E(e){var t=T(e,`string`);return w(t)==`symbol`?t:t+``}function D(e,t,n){return(t=E(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function O(e,t){return function(n,r){t(n,r,e)}}function k(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let A=class extends e{constructor(e){super(),this._localStorageService=e,D(this,`_updateConfig$`,new h),D(this,`updateConfig$`,this._updateConfig$.asObservable()),D(this,`_refresh$`,new h),D(this,`refresh$`,this._refresh$.asObservable())}async getWatermarkConfig(){return await this._localStorageService.getItem(p)}updateWatermarkConfig(e){this._localStorageService.setItem(p,e),this._updateConfig$.next(e)}deleteWatermarkConfig(){this._localStorageService.removeItem(p),this._updateConfig$.next(null)}refresh(){this._refresh$.next(Math.random())}dispose(){this._refresh$.complete(),this._updateConfig$.complete()}};A=k([O(0,r(n))],A);let j=class extends o{constructor(e,t,n,r){super(),this._context=e,this._watermarkService=t,this._localStorageService=n,this._userManagerService=r,D(this,`_watermarkLayer`,void 0),this._watermarkLayer=new m(e.scene,[],f),this._initAddRender(),this._initWatermarkUpdate(),this._initWatermarkConfig()}_initAddRender(){let{scene:e}=this._context;e.addLayer(this._watermarkLayer)}async _initWatermarkConfig(){let e=await this._localStorageService.getItem(p);if(e){var t;this._watermarkService.updateWatermarkConfig(e),(t=this._context.mainComponent)==null||t.makeDirty()}}_initWatermarkUpdate(){this.disposeWithMe(this._watermarkService.updateConfig$.subscribe(e=>{var t;if(!e){var n;this._watermarkLayer.updateConfig(),(n=this._context.mainComponent)==null||n.makeDirty();return}e.type===d.UserInfo?this._watermarkLayer.updateConfig(e,this._userManagerService.getCurrentUser()):this._watermarkLayer.updateConfig(e),(t=this._context.mainComponent)==null||t.makeDirty()}))}};j=k([O(1,r(A)),O(2,r(n)),O(3,r(c))],j);let M=class extends a{constructor(e=C,t,n,r,i){super(),this._config=e,this._injector=t,this._configService=n,this._renderManagerSrv=r,this._localStorageService=i;let{...a}=l({},C,this._config);this._configService.setConfig(S,a),this._initWatermarkStorage(),this._initDependencies()}async _initWatermarkStorage(){let e=this._configService.getConfig(S);if(!e)return;let{userWatermarkSettings:t,textWatermarkSettings:n,imageWatermarkSettings:r}=e;if(t)this._localStorageService.setItem(p,{type:d.UserInfo,config:{userInfo:l({},y,t)}});else if(n)this._localStorageService.setItem(p,{type:d.Text,config:{text:l({},_,n)}});else if(r)this._localStorageService.setItem(p,{type:d.Image,config:{image:l({},v,r)}});else{let e=await this._localStorageService.getItem(p);(e==null?void 0:e.type)===d.UserInfo&&this._localStorageService.removeItem(p)}}_initDependencies(){[[A]].forEach(e=>{this._injector.add(e)})}onRendered(){this._injector.get(A),this._initRenderDependencies()}_initRenderDependencies(){[[j]].forEach(e=>{this._renderManagerSrv.registerRenderModule(s.UNIVER_SHEET,e),this._renderManagerSrv.registerRenderModule(s.UNIVER_DOC,e)})}};D(M,`pluginName`,`UNIVER_WATERMARK_PLUGIN`),D(M,`packageName`,b),D(M,`version`,x),M=k([O(1,r(i)),O(2,t),O(3,u),O(4,r(n))],M);export{M as UniverWatermarkPlugin,g as WATERMARK_IMAGE_ALLOW_IMAGE_LIST,v as WatermarkImageBaseConfig,A as WatermarkService,_ as WatermarkTextBaseConfig,y as WatermarkUserInfoBaseConfig};
1
+ import { Disposable, IConfigService, ILocalStorageService, Inject, Injector, Plugin, RxDisposable, UniverInstanceType, UserManagerService, merge } from "@univerjs/core";
2
+ import { IRenderManagerService, IWatermarkTypeEnum, UNIVER_WATERMARK_LAYER_INDEX, UNIVER_WATERMARK_STORAGE_KEY, WatermarkLayer } from "@univerjs/engine-render";
3
+ import { Subject } from "rxjs";
4
+
5
+ //#region src/common/const.ts
6
+ const WATERMARK_IMAGE_ALLOW_IMAGE_LIST = [
7
+ "image/png",
8
+ "image/jpeg",
9
+ "image/jpg",
10
+ "image/bmp"
11
+ ];
12
+ const WatermarkTextBaseConfig = {
13
+ content: "",
14
+ fontSize: 16,
15
+ color: "rgb(0,0,0)",
16
+ bold: false,
17
+ italic: false,
18
+ direction: "ltr",
19
+ x: 60,
20
+ y: 36,
21
+ repeat: true,
22
+ spacingX: 200,
23
+ spacingY: 100,
24
+ rotate: 0,
25
+ opacity: .15
26
+ };
27
+ const WatermarkImageBaseConfig = {
28
+ url: "",
29
+ width: 100,
30
+ height: 100,
31
+ maintainAspectRatio: true,
32
+ originRatio: 1,
33
+ x: 60,
34
+ y: 36,
35
+ repeat: true,
36
+ spacingX: 200,
37
+ spacingY: 100,
38
+ rotate: 0,
39
+ opacity: .15
40
+ };
41
+ const WatermarkUserInfoBaseConfig = {
42
+ name: true,
43
+ email: false,
44
+ phone: false,
45
+ uid: false,
46
+ fontSize: 16,
47
+ color: "rgb(0,0,0)",
48
+ bold: false,
49
+ italic: false,
50
+ direction: "ltr",
51
+ x: 60,
52
+ y: 60,
53
+ repeat: true,
54
+ spacingX: 200,
55
+ spacingY: 100,
56
+ rotate: -30,
57
+ opacity: .15
58
+ };
59
+
60
+ //#endregion
61
+ //#region package.json
62
+ var name = "@univerjs/watermark";
63
+ var version = "0.21.0";
64
+
65
+ //#endregion
66
+ //#region src/config/config.ts
67
+ const WATERMARK_PLUGIN_CONFIG_KEY = "watermark.config";
68
+ const configSymbol = Symbol(WATERMARK_PLUGIN_CONFIG_KEY);
69
+ const defaultPluginConfig = {};
70
+
71
+ //#endregion
72
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
73
+ function _typeof(o) {
74
+ "@babel/helpers - typeof";
75
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
76
+ return typeof o;
77
+ } : function(o) {
78
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
79
+ }, _typeof(o);
80
+ }
81
+
82
+ //#endregion
83
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
84
+ function toPrimitive(t, r) {
85
+ if ("object" != _typeof(t) || !t) return t;
86
+ var e = t[Symbol.toPrimitive];
87
+ if (void 0 !== e) {
88
+ var i = e.call(t, r || "default");
89
+ if ("object" != _typeof(i)) return i;
90
+ throw new TypeError("@@toPrimitive must return a primitive value.");
91
+ }
92
+ return ("string" === r ? String : Number)(t);
93
+ }
94
+
95
+ //#endregion
96
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
97
+ function toPropertyKey(t) {
98
+ var i = toPrimitive(t, "string");
99
+ return "symbol" == _typeof(i) ? i : i + "";
100
+ }
101
+
102
+ //#endregion
103
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
104
+ function _defineProperty(e, r, t) {
105
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
106
+ value: t,
107
+ enumerable: !0,
108
+ configurable: !0,
109
+ writable: !0
110
+ }) : e[r] = t, e;
111
+ }
112
+
113
+ //#endregion
114
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
115
+ function __decorateParam(paramIndex, decorator) {
116
+ return function(target, key) {
117
+ decorator(target, key, paramIndex);
118
+ };
119
+ }
120
+
121
+ //#endregion
122
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
123
+ function __decorate(decorators, target, key, desc) {
124
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
125
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
126
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
127
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
128
+ }
129
+
130
+ //#endregion
131
+ //#region src/services/watermark.service.ts
132
+ let WatermarkService = class WatermarkService extends Disposable {
133
+ constructor(_localStorageService) {
134
+ super();
135
+ this._localStorageService = _localStorageService;
136
+ _defineProperty(this, "_updateConfig$", new Subject());
137
+ _defineProperty(this, "updateConfig$", this._updateConfig$.asObservable());
138
+ _defineProperty(this, "_refresh$", new Subject());
139
+ _defineProperty(this, "refresh$", this._refresh$.asObservable());
140
+ }
141
+ async getWatermarkConfig() {
142
+ return await this._localStorageService.getItem(UNIVER_WATERMARK_STORAGE_KEY);
143
+ }
144
+ updateWatermarkConfig(config) {
145
+ this._localStorageService.setItem(UNIVER_WATERMARK_STORAGE_KEY, config);
146
+ this._updateConfig$.next(config);
147
+ }
148
+ deleteWatermarkConfig() {
149
+ this._localStorageService.removeItem(UNIVER_WATERMARK_STORAGE_KEY);
150
+ this._updateConfig$.next(null);
151
+ }
152
+ refresh() {
153
+ this._refresh$.next(Math.random());
154
+ }
155
+ dispose() {
156
+ this._refresh$.complete();
157
+ this._updateConfig$.complete();
158
+ }
159
+ };
160
+ WatermarkService = __decorate([__decorateParam(0, Inject(ILocalStorageService))], WatermarkService);
161
+
162
+ //#endregion
163
+ //#region src/controllers/watermark.render.controller.ts
164
+ let WatermarkRenderController = class WatermarkRenderController extends RxDisposable {
165
+ constructor(_context, _watermarkService, _localStorageService, _userManagerService) {
166
+ super();
167
+ this._context = _context;
168
+ this._watermarkService = _watermarkService;
169
+ this._localStorageService = _localStorageService;
170
+ this._userManagerService = _userManagerService;
171
+ _defineProperty(this, "_watermarkLayer", void 0);
172
+ this._watermarkLayer = new WatermarkLayer(_context.scene, [], UNIVER_WATERMARK_LAYER_INDEX);
173
+ this._initAddRender();
174
+ this._initWatermarkUpdate();
175
+ this._initWatermarkConfig();
176
+ }
177
+ _initAddRender() {
178
+ const { scene } = this._context;
179
+ scene.addLayer(this._watermarkLayer);
180
+ }
181
+ async _initWatermarkConfig() {
182
+ const config = await this._localStorageService.getItem(UNIVER_WATERMARK_STORAGE_KEY);
183
+ if (config) {
184
+ var _this$_context$mainCo;
185
+ this._watermarkService.updateWatermarkConfig(config);
186
+ (_this$_context$mainCo = this._context.mainComponent) === null || _this$_context$mainCo === void 0 || _this$_context$mainCo.makeDirty();
187
+ }
188
+ }
189
+ _initWatermarkUpdate() {
190
+ this.disposeWithMe(this._watermarkService.updateConfig$.subscribe((_config) => {
191
+ var _this$_context$mainCo3;
192
+ if (!_config) {
193
+ var _this$_context$mainCo2;
194
+ this._watermarkLayer.updateConfig();
195
+ (_this$_context$mainCo2 = this._context.mainComponent) === null || _this$_context$mainCo2 === void 0 || _this$_context$mainCo2.makeDirty();
196
+ return;
197
+ }
198
+ if (_config.type === IWatermarkTypeEnum.UserInfo) this._watermarkLayer.updateConfig(_config, this._userManagerService.getCurrentUser());
199
+ else this._watermarkLayer.updateConfig(_config);
200
+ (_this$_context$mainCo3 = this._context.mainComponent) === null || _this$_context$mainCo3 === void 0 || _this$_context$mainCo3.makeDirty();
201
+ }));
202
+ }
203
+ };
204
+ WatermarkRenderController = __decorate([
205
+ __decorateParam(1, Inject(WatermarkService)),
206
+ __decorateParam(2, Inject(ILocalStorageService)),
207
+ __decorateParam(3, Inject(UserManagerService))
208
+ ], WatermarkRenderController);
209
+
210
+ //#endregion
211
+ //#region src/plugin.ts
212
+ let UniverWatermarkPlugin = class UniverWatermarkPlugin extends Plugin {
213
+ constructor(_config = defaultPluginConfig, _injector, _configService, _renderManagerSrv, _localStorageService) {
214
+ super();
215
+ this._config = _config;
216
+ this._injector = _injector;
217
+ this._configService = _configService;
218
+ this._renderManagerSrv = _renderManagerSrv;
219
+ this._localStorageService = _localStorageService;
220
+ const { ...rest } = merge({}, defaultPluginConfig, this._config);
221
+ this._configService.setConfig(WATERMARK_PLUGIN_CONFIG_KEY, rest);
222
+ this._initWatermarkStorage();
223
+ this._initDependencies();
224
+ }
225
+ async _initWatermarkStorage() {
226
+ const config = this._configService.getConfig(WATERMARK_PLUGIN_CONFIG_KEY);
227
+ if (!config) return;
228
+ const { userWatermarkSettings, textWatermarkSettings, imageWatermarkSettings } = config;
229
+ if (userWatermarkSettings) this._localStorageService.setItem(UNIVER_WATERMARK_STORAGE_KEY, {
230
+ type: IWatermarkTypeEnum.UserInfo,
231
+ config: { userInfo: merge({}, WatermarkUserInfoBaseConfig, userWatermarkSettings) }
232
+ });
233
+ else if (textWatermarkSettings) this._localStorageService.setItem(UNIVER_WATERMARK_STORAGE_KEY, {
234
+ type: IWatermarkTypeEnum.Text,
235
+ config: { text: merge({}, WatermarkTextBaseConfig, textWatermarkSettings) }
236
+ });
237
+ else if (imageWatermarkSettings) this._localStorageService.setItem(UNIVER_WATERMARK_STORAGE_KEY, {
238
+ type: IWatermarkTypeEnum.Image,
239
+ config: { image: merge({}, WatermarkImageBaseConfig, imageWatermarkSettings) }
240
+ });
241
+ else {
242
+ const config = await this._localStorageService.getItem(UNIVER_WATERMARK_STORAGE_KEY);
243
+ if ((config === null || config === void 0 ? void 0 : config.type) === IWatermarkTypeEnum.UserInfo) this._localStorageService.removeItem(UNIVER_WATERMARK_STORAGE_KEY);
244
+ }
245
+ }
246
+ _initDependencies() {
247
+ [[WatermarkService]].forEach((d) => {
248
+ this._injector.add(d);
249
+ });
250
+ }
251
+ onRendered() {
252
+ this._injector.get(WatermarkService);
253
+ this._initRenderDependencies();
254
+ }
255
+ _initRenderDependencies() {
256
+ [[WatermarkRenderController]].forEach((d) => {
257
+ this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_SHEET, d);
258
+ this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_DOC, d);
259
+ });
260
+ }
261
+ };
262
+ _defineProperty(UniverWatermarkPlugin, "pluginName", "UNIVER_WATERMARK_PLUGIN");
263
+ _defineProperty(UniverWatermarkPlugin, "packageName", name);
264
+ _defineProperty(UniverWatermarkPlugin, "version", version);
265
+ UniverWatermarkPlugin = __decorate([
266
+ __decorateParam(1, Inject(Injector)),
267
+ __decorateParam(2, IConfigService),
268
+ __decorateParam(3, IRenderManagerService),
269
+ __decorateParam(4, Inject(ILocalStorageService))
270
+ ], UniverWatermarkPlugin);
271
+
272
+ //#endregion
273
+ export { UniverWatermarkPlugin, WATERMARK_IMAGE_ALLOW_IMAGE_LIST, WatermarkImageBaseConfig, WatermarkService, WatermarkTextBaseConfig, WatermarkUserInfoBaseConfig };
package/lib/facade.js CHANGED
@@ -1 +1,40 @@
1
- import{FEnum as e,FUniver as t}from"@univerjs/core/facade";import{IWatermarkTypeEnum as n}from"@univerjs/engine-render";import{WatermarkImageBaseConfig as r,WatermarkService as i,WatermarkTextBaseConfig as a}from"@univerjs/watermark";var o=class extends e{get IWatermarkTypeEnum(){return n}},s=class extends t{addWatermark(e,t){let o=this._injector.get(i);if(e===n.Text)o.updateWatermarkConfig({type:n.Text,config:{text:{...a,...t}}});else if(e===n.Image)o.updateWatermarkConfig({type:n.Image,config:{image:{...r,...t}}});else throw Error(`Unknown watermark type`);return this}deleteWatermark(){return this._injector.get(i).deleteWatermarkConfig(),this}};t.extend(s),e.extend(o);export{};
1
+ import { FEnum, FUniver } from "@univerjs/core/facade";
2
+ import { IWatermarkTypeEnum } from "@univerjs/engine-render";
3
+ import { WatermarkImageBaseConfig, WatermarkService, WatermarkTextBaseConfig } from "@univerjs/watermark";
4
+
5
+ //#region src/facade/f-univer.ts
6
+ var FWatermarkEnumMixin = class extends FEnum {
7
+ get IWatermarkTypeEnum() {
8
+ return IWatermarkTypeEnum;
9
+ }
10
+ };
11
+ var FUniverWatermarkMixin = class extends FUniver {
12
+ addWatermark(type, config) {
13
+ const watermarkService = this._injector.get(WatermarkService);
14
+ if (type === IWatermarkTypeEnum.Text) watermarkService.updateWatermarkConfig({
15
+ type: IWatermarkTypeEnum.Text,
16
+ config: { text: {
17
+ ...WatermarkTextBaseConfig,
18
+ ...config
19
+ } }
20
+ });
21
+ else if (type === IWatermarkTypeEnum.Image) watermarkService.updateWatermarkConfig({
22
+ type: IWatermarkTypeEnum.Image,
23
+ config: { image: {
24
+ ...WatermarkImageBaseConfig,
25
+ ...config
26
+ } }
27
+ });
28
+ else throw new Error("Unknown watermark type");
29
+ return this;
30
+ }
31
+ deleteWatermark() {
32
+ this._injector.get(WatermarkService).deleteWatermarkConfig();
33
+ return this;
34
+ }
35
+ };
36
+ FUniver.extend(FUniverWatermarkMixin);
37
+ FEnum.extend(FWatermarkEnumMixin);
38
+
39
+ //#endregion
40
+ export { };
package/lib/index.js CHANGED
@@ -1 +1,273 @@
1
- import{Disposable as e,IConfigService as t,ILocalStorageService as n,Inject as r,Injector as i,Plugin as a,RxDisposable as o,UniverInstanceType as s,UserManagerService as c,merge as l}from"@univerjs/core";import{IRenderManagerService as u,IWatermarkTypeEnum as d,UNIVER_WATERMARK_LAYER_INDEX as f,UNIVER_WATERMARK_STORAGE_KEY as p,WatermarkLayer as m}from"@univerjs/engine-render";import{Subject as h}from"rxjs";const g=[`image/png`,`image/jpeg`,`image/jpg`,`image/bmp`],_={content:``,fontSize:16,color:`rgb(0,0,0)`,bold:!1,italic:!1,direction:`ltr`,x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},v={url:``,width:100,height:100,maintainAspectRatio:!0,originRatio:1,x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},y={name:!0,email:!1,phone:!1,uid:!1,fontSize:16,color:`rgb(0,0,0)`,bold:!1,italic:!1,direction:`ltr`,x:60,y:60,repeat:!0,spacingX:200,spacingY:100,rotate:-30,opacity:.15};var b=`@univerjs/watermark`,x=`0.20.1`;const S=`watermark.config`;Symbol(S);const C={};function w(e){"@babel/helpers - typeof";return w=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},w(e)}function T(e,t){if(w(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(w(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function E(e){var t=T(e,`string`);return w(t)==`symbol`?t:t+``}function D(e,t,n){return(t=E(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function O(e,t){return function(n,r){t(n,r,e)}}function k(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let A=class extends e{constructor(e){super(),this._localStorageService=e,D(this,`_updateConfig$`,new h),D(this,`updateConfig$`,this._updateConfig$.asObservable()),D(this,`_refresh$`,new h),D(this,`refresh$`,this._refresh$.asObservable())}async getWatermarkConfig(){return await this._localStorageService.getItem(p)}updateWatermarkConfig(e){this._localStorageService.setItem(p,e),this._updateConfig$.next(e)}deleteWatermarkConfig(){this._localStorageService.removeItem(p),this._updateConfig$.next(null)}refresh(){this._refresh$.next(Math.random())}dispose(){this._refresh$.complete(),this._updateConfig$.complete()}};A=k([O(0,r(n))],A);let j=class extends o{constructor(e,t,n,r){super(),this._context=e,this._watermarkService=t,this._localStorageService=n,this._userManagerService=r,D(this,`_watermarkLayer`,void 0),this._watermarkLayer=new m(e.scene,[],f),this._initAddRender(),this._initWatermarkUpdate(),this._initWatermarkConfig()}_initAddRender(){let{scene:e}=this._context;e.addLayer(this._watermarkLayer)}async _initWatermarkConfig(){let e=await this._localStorageService.getItem(p);if(e){var t;this._watermarkService.updateWatermarkConfig(e),(t=this._context.mainComponent)==null||t.makeDirty()}}_initWatermarkUpdate(){this.disposeWithMe(this._watermarkService.updateConfig$.subscribe(e=>{var t;if(!e){var n;this._watermarkLayer.updateConfig(),(n=this._context.mainComponent)==null||n.makeDirty();return}e.type===d.UserInfo?this._watermarkLayer.updateConfig(e,this._userManagerService.getCurrentUser()):this._watermarkLayer.updateConfig(e),(t=this._context.mainComponent)==null||t.makeDirty()}))}};j=k([O(1,r(A)),O(2,r(n)),O(3,r(c))],j);let M=class extends a{constructor(e=C,t,n,r,i){super(),this._config=e,this._injector=t,this._configService=n,this._renderManagerSrv=r,this._localStorageService=i;let{...a}=l({},C,this._config);this._configService.setConfig(S,a),this._initWatermarkStorage(),this._initDependencies()}async _initWatermarkStorage(){let e=this._configService.getConfig(S);if(!e)return;let{userWatermarkSettings:t,textWatermarkSettings:n,imageWatermarkSettings:r}=e;if(t)this._localStorageService.setItem(p,{type:d.UserInfo,config:{userInfo:l({},y,t)}});else if(n)this._localStorageService.setItem(p,{type:d.Text,config:{text:l({},_,n)}});else if(r)this._localStorageService.setItem(p,{type:d.Image,config:{image:l({},v,r)}});else{let e=await this._localStorageService.getItem(p);(e==null?void 0:e.type)===d.UserInfo&&this._localStorageService.removeItem(p)}}_initDependencies(){[[A]].forEach(e=>{this._injector.add(e)})}onRendered(){this._injector.get(A),this._initRenderDependencies()}_initRenderDependencies(){[[j]].forEach(e=>{this._renderManagerSrv.registerRenderModule(s.UNIVER_SHEET,e),this._renderManagerSrv.registerRenderModule(s.UNIVER_DOC,e)})}};D(M,`pluginName`,`UNIVER_WATERMARK_PLUGIN`),D(M,`packageName`,b),D(M,`version`,x),M=k([O(1,r(i)),O(2,t),O(3,u),O(4,r(n))],M);export{M as UniverWatermarkPlugin,g as WATERMARK_IMAGE_ALLOW_IMAGE_LIST,v as WatermarkImageBaseConfig,A as WatermarkService,_ as WatermarkTextBaseConfig,y as WatermarkUserInfoBaseConfig};
1
+ import { Disposable, IConfigService, ILocalStorageService, Inject, Injector, Plugin, RxDisposable, UniverInstanceType, UserManagerService, merge } from "@univerjs/core";
2
+ import { IRenderManagerService, IWatermarkTypeEnum, UNIVER_WATERMARK_LAYER_INDEX, UNIVER_WATERMARK_STORAGE_KEY, WatermarkLayer } from "@univerjs/engine-render";
3
+ import { Subject } from "rxjs";
4
+
5
+ //#region src/common/const.ts
6
+ const WATERMARK_IMAGE_ALLOW_IMAGE_LIST = [
7
+ "image/png",
8
+ "image/jpeg",
9
+ "image/jpg",
10
+ "image/bmp"
11
+ ];
12
+ const WatermarkTextBaseConfig = {
13
+ content: "",
14
+ fontSize: 16,
15
+ color: "rgb(0,0,0)",
16
+ bold: false,
17
+ italic: false,
18
+ direction: "ltr",
19
+ x: 60,
20
+ y: 36,
21
+ repeat: true,
22
+ spacingX: 200,
23
+ spacingY: 100,
24
+ rotate: 0,
25
+ opacity: .15
26
+ };
27
+ const WatermarkImageBaseConfig = {
28
+ url: "",
29
+ width: 100,
30
+ height: 100,
31
+ maintainAspectRatio: true,
32
+ originRatio: 1,
33
+ x: 60,
34
+ y: 36,
35
+ repeat: true,
36
+ spacingX: 200,
37
+ spacingY: 100,
38
+ rotate: 0,
39
+ opacity: .15
40
+ };
41
+ const WatermarkUserInfoBaseConfig = {
42
+ name: true,
43
+ email: false,
44
+ phone: false,
45
+ uid: false,
46
+ fontSize: 16,
47
+ color: "rgb(0,0,0)",
48
+ bold: false,
49
+ italic: false,
50
+ direction: "ltr",
51
+ x: 60,
52
+ y: 60,
53
+ repeat: true,
54
+ spacingX: 200,
55
+ spacingY: 100,
56
+ rotate: -30,
57
+ opacity: .15
58
+ };
59
+
60
+ //#endregion
61
+ //#region package.json
62
+ var name = "@univerjs/watermark";
63
+ var version = "0.21.0";
64
+
65
+ //#endregion
66
+ //#region src/config/config.ts
67
+ const WATERMARK_PLUGIN_CONFIG_KEY = "watermark.config";
68
+ const configSymbol = Symbol(WATERMARK_PLUGIN_CONFIG_KEY);
69
+ const defaultPluginConfig = {};
70
+
71
+ //#endregion
72
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
73
+ function _typeof(o) {
74
+ "@babel/helpers - typeof";
75
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
76
+ return typeof o;
77
+ } : function(o) {
78
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
79
+ }, _typeof(o);
80
+ }
81
+
82
+ //#endregion
83
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
84
+ function toPrimitive(t, r) {
85
+ if ("object" != _typeof(t) || !t) return t;
86
+ var e = t[Symbol.toPrimitive];
87
+ if (void 0 !== e) {
88
+ var i = e.call(t, r || "default");
89
+ if ("object" != _typeof(i)) return i;
90
+ throw new TypeError("@@toPrimitive must return a primitive value.");
91
+ }
92
+ return ("string" === r ? String : Number)(t);
93
+ }
94
+
95
+ //#endregion
96
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
97
+ function toPropertyKey(t) {
98
+ var i = toPrimitive(t, "string");
99
+ return "symbol" == _typeof(i) ? i : i + "";
100
+ }
101
+
102
+ //#endregion
103
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
104
+ function _defineProperty(e, r, t) {
105
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
106
+ value: t,
107
+ enumerable: !0,
108
+ configurable: !0,
109
+ writable: !0
110
+ }) : e[r] = t, e;
111
+ }
112
+
113
+ //#endregion
114
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
115
+ function __decorateParam(paramIndex, decorator) {
116
+ return function(target, key) {
117
+ decorator(target, key, paramIndex);
118
+ };
119
+ }
120
+
121
+ //#endregion
122
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
123
+ function __decorate(decorators, target, key, desc) {
124
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
125
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
126
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
127
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
128
+ }
129
+
130
+ //#endregion
131
+ //#region src/services/watermark.service.ts
132
+ let WatermarkService = class WatermarkService extends Disposable {
133
+ constructor(_localStorageService) {
134
+ super();
135
+ this._localStorageService = _localStorageService;
136
+ _defineProperty(this, "_updateConfig$", new Subject());
137
+ _defineProperty(this, "updateConfig$", this._updateConfig$.asObservable());
138
+ _defineProperty(this, "_refresh$", new Subject());
139
+ _defineProperty(this, "refresh$", this._refresh$.asObservable());
140
+ }
141
+ async getWatermarkConfig() {
142
+ return await this._localStorageService.getItem(UNIVER_WATERMARK_STORAGE_KEY);
143
+ }
144
+ updateWatermarkConfig(config) {
145
+ this._localStorageService.setItem(UNIVER_WATERMARK_STORAGE_KEY, config);
146
+ this._updateConfig$.next(config);
147
+ }
148
+ deleteWatermarkConfig() {
149
+ this._localStorageService.removeItem(UNIVER_WATERMARK_STORAGE_KEY);
150
+ this._updateConfig$.next(null);
151
+ }
152
+ refresh() {
153
+ this._refresh$.next(Math.random());
154
+ }
155
+ dispose() {
156
+ this._refresh$.complete();
157
+ this._updateConfig$.complete();
158
+ }
159
+ };
160
+ WatermarkService = __decorate([__decorateParam(0, Inject(ILocalStorageService))], WatermarkService);
161
+
162
+ //#endregion
163
+ //#region src/controllers/watermark.render.controller.ts
164
+ let WatermarkRenderController = class WatermarkRenderController extends RxDisposable {
165
+ constructor(_context, _watermarkService, _localStorageService, _userManagerService) {
166
+ super();
167
+ this._context = _context;
168
+ this._watermarkService = _watermarkService;
169
+ this._localStorageService = _localStorageService;
170
+ this._userManagerService = _userManagerService;
171
+ _defineProperty(this, "_watermarkLayer", void 0);
172
+ this._watermarkLayer = new WatermarkLayer(_context.scene, [], UNIVER_WATERMARK_LAYER_INDEX);
173
+ this._initAddRender();
174
+ this._initWatermarkUpdate();
175
+ this._initWatermarkConfig();
176
+ }
177
+ _initAddRender() {
178
+ const { scene } = this._context;
179
+ scene.addLayer(this._watermarkLayer);
180
+ }
181
+ async _initWatermarkConfig() {
182
+ const config = await this._localStorageService.getItem(UNIVER_WATERMARK_STORAGE_KEY);
183
+ if (config) {
184
+ var _this$_context$mainCo;
185
+ this._watermarkService.updateWatermarkConfig(config);
186
+ (_this$_context$mainCo = this._context.mainComponent) === null || _this$_context$mainCo === void 0 || _this$_context$mainCo.makeDirty();
187
+ }
188
+ }
189
+ _initWatermarkUpdate() {
190
+ this.disposeWithMe(this._watermarkService.updateConfig$.subscribe((_config) => {
191
+ var _this$_context$mainCo3;
192
+ if (!_config) {
193
+ var _this$_context$mainCo2;
194
+ this._watermarkLayer.updateConfig();
195
+ (_this$_context$mainCo2 = this._context.mainComponent) === null || _this$_context$mainCo2 === void 0 || _this$_context$mainCo2.makeDirty();
196
+ return;
197
+ }
198
+ if (_config.type === IWatermarkTypeEnum.UserInfo) this._watermarkLayer.updateConfig(_config, this._userManagerService.getCurrentUser());
199
+ else this._watermarkLayer.updateConfig(_config);
200
+ (_this$_context$mainCo3 = this._context.mainComponent) === null || _this$_context$mainCo3 === void 0 || _this$_context$mainCo3.makeDirty();
201
+ }));
202
+ }
203
+ };
204
+ WatermarkRenderController = __decorate([
205
+ __decorateParam(1, Inject(WatermarkService)),
206
+ __decorateParam(2, Inject(ILocalStorageService)),
207
+ __decorateParam(3, Inject(UserManagerService))
208
+ ], WatermarkRenderController);
209
+
210
+ //#endregion
211
+ //#region src/plugin.ts
212
+ let UniverWatermarkPlugin = class UniverWatermarkPlugin extends Plugin {
213
+ constructor(_config = defaultPluginConfig, _injector, _configService, _renderManagerSrv, _localStorageService) {
214
+ super();
215
+ this._config = _config;
216
+ this._injector = _injector;
217
+ this._configService = _configService;
218
+ this._renderManagerSrv = _renderManagerSrv;
219
+ this._localStorageService = _localStorageService;
220
+ const { ...rest } = merge({}, defaultPluginConfig, this._config);
221
+ this._configService.setConfig(WATERMARK_PLUGIN_CONFIG_KEY, rest);
222
+ this._initWatermarkStorage();
223
+ this._initDependencies();
224
+ }
225
+ async _initWatermarkStorage() {
226
+ const config = this._configService.getConfig(WATERMARK_PLUGIN_CONFIG_KEY);
227
+ if (!config) return;
228
+ const { userWatermarkSettings, textWatermarkSettings, imageWatermarkSettings } = config;
229
+ if (userWatermarkSettings) this._localStorageService.setItem(UNIVER_WATERMARK_STORAGE_KEY, {
230
+ type: IWatermarkTypeEnum.UserInfo,
231
+ config: { userInfo: merge({}, WatermarkUserInfoBaseConfig, userWatermarkSettings) }
232
+ });
233
+ else if (textWatermarkSettings) this._localStorageService.setItem(UNIVER_WATERMARK_STORAGE_KEY, {
234
+ type: IWatermarkTypeEnum.Text,
235
+ config: { text: merge({}, WatermarkTextBaseConfig, textWatermarkSettings) }
236
+ });
237
+ else if (imageWatermarkSettings) this._localStorageService.setItem(UNIVER_WATERMARK_STORAGE_KEY, {
238
+ type: IWatermarkTypeEnum.Image,
239
+ config: { image: merge({}, WatermarkImageBaseConfig, imageWatermarkSettings) }
240
+ });
241
+ else {
242
+ const config = await this._localStorageService.getItem(UNIVER_WATERMARK_STORAGE_KEY);
243
+ if ((config === null || config === void 0 ? void 0 : config.type) === IWatermarkTypeEnum.UserInfo) this._localStorageService.removeItem(UNIVER_WATERMARK_STORAGE_KEY);
244
+ }
245
+ }
246
+ _initDependencies() {
247
+ [[WatermarkService]].forEach((d) => {
248
+ this._injector.add(d);
249
+ });
250
+ }
251
+ onRendered() {
252
+ this._injector.get(WatermarkService);
253
+ this._initRenderDependencies();
254
+ }
255
+ _initRenderDependencies() {
256
+ [[WatermarkRenderController]].forEach((d) => {
257
+ this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_SHEET, d);
258
+ this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_DOC, d);
259
+ });
260
+ }
261
+ };
262
+ _defineProperty(UniverWatermarkPlugin, "pluginName", "UNIVER_WATERMARK_PLUGIN");
263
+ _defineProperty(UniverWatermarkPlugin, "packageName", name);
264
+ _defineProperty(UniverWatermarkPlugin, "version", version);
265
+ UniverWatermarkPlugin = __decorate([
266
+ __decorateParam(1, Inject(Injector)),
267
+ __decorateParam(2, IConfigService),
268
+ __decorateParam(3, IRenderManagerService),
269
+ __decorateParam(4, Inject(ILocalStorageService))
270
+ ], UniverWatermarkPlugin);
271
+
272
+ //#endregion
273
+ export { UniverWatermarkPlugin, WATERMARK_IMAGE_ALLOW_IMAGE_LIST, WatermarkImageBaseConfig, WatermarkService, WatermarkTextBaseConfig, WatermarkUserInfoBaseConfig };
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/engine-render`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/engine-render`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverWatermark={},e.UniverCore,e.UniverEngineRender,e.rxjs))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let i=[`image/png`,`image/jpeg`,`image/jpg`,`image/bmp`],a={content:``,fontSize:16,color:`rgb(0,0,0)`,bold:!1,italic:!1,direction:`ltr`,x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},o={url:``,width:100,height:100,maintainAspectRatio:!0,originRatio:1,x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},s={name:!0,email:!1,phone:!1,uid:!1,fontSize:16,color:`rgb(0,0,0)`,bold:!1,italic:!1,direction:`ltr`,x:60,y:60,repeat:!0,spacingX:200,spacingY:100,rotate:-30,opacity:.15};var c=`@univerjs/watermark`,l=`0.20.1`;let u=`watermark.config`;Symbol(u);let d={};function f(e){"@babel/helpers - typeof";return f=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},f(e)}function p(e,t){if(f(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(f(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function m(e){var t=p(e,`string`);return f(t)==`symbol`?t:t+``}function h(e,t,n){return(t=m(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function g(e,t){return function(n,r){t(n,r,e)}}function _(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let v=class extends t.Disposable{constructor(e){super(),this._localStorageService=e,h(this,`_updateConfig$`,new r.Subject),h(this,`updateConfig$`,this._updateConfig$.asObservable()),h(this,`_refresh$`,new r.Subject),h(this,`refresh$`,this._refresh$.asObservable())}async getWatermarkConfig(){return await this._localStorageService.getItem(n.UNIVER_WATERMARK_STORAGE_KEY)}updateWatermarkConfig(e){this._localStorageService.setItem(n.UNIVER_WATERMARK_STORAGE_KEY,e),this._updateConfig$.next(e)}deleteWatermarkConfig(){this._localStorageService.removeItem(n.UNIVER_WATERMARK_STORAGE_KEY),this._updateConfig$.next(null)}refresh(){this._refresh$.next(Math.random())}dispose(){this._refresh$.complete(),this._updateConfig$.complete()}};v=_([g(0,(0,t.Inject)(t.ILocalStorageService))],v);let y=class extends t.RxDisposable{constructor(e,t,r,i){super(),this._context=e,this._watermarkService=t,this._localStorageService=r,this._userManagerService=i,h(this,`_watermarkLayer`,void 0),this._watermarkLayer=new n.WatermarkLayer(e.scene,[],n.UNIVER_WATERMARK_LAYER_INDEX),this._initAddRender(),this._initWatermarkUpdate(),this._initWatermarkConfig()}_initAddRender(){let{scene:e}=this._context;e.addLayer(this._watermarkLayer)}async _initWatermarkConfig(){let e=await this._localStorageService.getItem(n.UNIVER_WATERMARK_STORAGE_KEY);if(e){var t;this._watermarkService.updateWatermarkConfig(e),(t=this._context.mainComponent)==null||t.makeDirty()}}_initWatermarkUpdate(){this.disposeWithMe(this._watermarkService.updateConfig$.subscribe(e=>{var t;if(!e){var r;this._watermarkLayer.updateConfig(),(r=this._context.mainComponent)==null||r.makeDirty();return}e.type===n.IWatermarkTypeEnum.UserInfo?this._watermarkLayer.updateConfig(e,this._userManagerService.getCurrentUser()):this._watermarkLayer.updateConfig(e),(t=this._context.mainComponent)==null||t.makeDirty()}))}};y=_([g(1,(0,t.Inject)(v)),g(2,(0,t.Inject)(t.ILocalStorageService)),g(3,(0,t.Inject)(t.UserManagerService))],y);let b=class extends t.Plugin{constructor(e=d,n,r,i,a){super(),this._config=e,this._injector=n,this._configService=r,this._renderManagerSrv=i,this._localStorageService=a;let{...o}=(0,t.merge)({},d,this._config);this._configService.setConfig(u,o),this._initWatermarkStorage(),this._initDependencies()}async _initWatermarkStorage(){let e=this._configService.getConfig(u);if(!e)return;let{userWatermarkSettings:r,textWatermarkSettings:i,imageWatermarkSettings:c}=e;if(r)this._localStorageService.setItem(n.UNIVER_WATERMARK_STORAGE_KEY,{type:n.IWatermarkTypeEnum.UserInfo,config:{userInfo:(0,t.merge)({},s,r)}});else if(i)this._localStorageService.setItem(n.UNIVER_WATERMARK_STORAGE_KEY,{type:n.IWatermarkTypeEnum.Text,config:{text:(0,t.merge)({},a,i)}});else if(c)this._localStorageService.setItem(n.UNIVER_WATERMARK_STORAGE_KEY,{type:n.IWatermarkTypeEnum.Image,config:{image:(0,t.merge)({},o,c)}});else{let e=await this._localStorageService.getItem(n.UNIVER_WATERMARK_STORAGE_KEY);(e==null?void 0:e.type)===n.IWatermarkTypeEnum.UserInfo&&this._localStorageService.removeItem(n.UNIVER_WATERMARK_STORAGE_KEY)}}_initDependencies(){[[v]].forEach(e=>{this._injector.add(e)})}onRendered(){this._injector.get(v),this._initRenderDependencies()}_initRenderDependencies(){[[y]].forEach(e=>{this._renderManagerSrv.registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,e),this._renderManagerSrv.registerRenderModule(t.UniverInstanceType.UNIVER_DOC,e)})}};h(b,`pluginName`,`UNIVER_WATERMARK_PLUGIN`),h(b,`packageName`,c),h(b,`version`,l),b=_([g(1,(0,t.Inject)(t.Injector)),g(2,t.IConfigService),g(3,n.IRenderManagerService),g(4,(0,t.Inject)(t.ILocalStorageService))],b),Object.defineProperty(e,`UniverWatermarkPlugin`,{enumerable:!0,get:function(){return b}}),e.WATERMARK_IMAGE_ALLOW_IMAGE_LIST=i,e.WatermarkImageBaseConfig=o,Object.defineProperty(e,`WatermarkService`,{enumerable:!0,get:function(){return v}}),e.WatermarkTextBaseConfig=a,e.WatermarkUserInfoBaseConfig=s});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/engine-render`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/engine-render`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverWatermark={},e.UniverCore,e.UniverEngineRender,e.rxjs))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let i=[`image/png`,`image/jpeg`,`image/jpg`,`image/bmp`],a={content:``,fontSize:16,color:`rgb(0,0,0)`,bold:!1,italic:!1,direction:`ltr`,x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},o={url:``,width:100,height:100,maintainAspectRatio:!0,originRatio:1,x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},s={name:!0,email:!1,phone:!1,uid:!1,fontSize:16,color:`rgb(0,0,0)`,bold:!1,italic:!1,direction:`ltr`,x:60,y:60,repeat:!0,spacingX:200,spacingY:100,rotate:-30,opacity:.15};var c=`@univerjs/watermark`,l=`0.21.0`;let u=`watermark.config`;Symbol(u);let d={};function f(e){"@babel/helpers - typeof";return f=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},f(e)}function p(e,t){if(f(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(f(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function m(e){var t=p(e,`string`);return f(t)==`symbol`?t:t+``}function h(e,t,n){return(t=m(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function g(e,t){return function(n,r){t(n,r,e)}}function _(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let v=class extends t.Disposable{constructor(e){super(),this._localStorageService=e,h(this,`_updateConfig$`,new r.Subject),h(this,`updateConfig$`,this._updateConfig$.asObservable()),h(this,`_refresh$`,new r.Subject),h(this,`refresh$`,this._refresh$.asObservable())}async getWatermarkConfig(){return await this._localStorageService.getItem(n.UNIVER_WATERMARK_STORAGE_KEY)}updateWatermarkConfig(e){this._localStorageService.setItem(n.UNIVER_WATERMARK_STORAGE_KEY,e),this._updateConfig$.next(e)}deleteWatermarkConfig(){this._localStorageService.removeItem(n.UNIVER_WATERMARK_STORAGE_KEY),this._updateConfig$.next(null)}refresh(){this._refresh$.next(Math.random())}dispose(){this._refresh$.complete(),this._updateConfig$.complete()}};v=_([g(0,(0,t.Inject)(t.ILocalStorageService))],v);let y=class extends t.RxDisposable{constructor(e,t,r,i){super(),this._context=e,this._watermarkService=t,this._localStorageService=r,this._userManagerService=i,h(this,`_watermarkLayer`,void 0),this._watermarkLayer=new n.WatermarkLayer(e.scene,[],n.UNIVER_WATERMARK_LAYER_INDEX),this._initAddRender(),this._initWatermarkUpdate(),this._initWatermarkConfig()}_initAddRender(){let{scene:e}=this._context;e.addLayer(this._watermarkLayer)}async _initWatermarkConfig(){let e=await this._localStorageService.getItem(n.UNIVER_WATERMARK_STORAGE_KEY);if(e){var t;this._watermarkService.updateWatermarkConfig(e),(t=this._context.mainComponent)==null||t.makeDirty()}}_initWatermarkUpdate(){this.disposeWithMe(this._watermarkService.updateConfig$.subscribe(e=>{var t;if(!e){var r;this._watermarkLayer.updateConfig(),(r=this._context.mainComponent)==null||r.makeDirty();return}e.type===n.IWatermarkTypeEnum.UserInfo?this._watermarkLayer.updateConfig(e,this._userManagerService.getCurrentUser()):this._watermarkLayer.updateConfig(e),(t=this._context.mainComponent)==null||t.makeDirty()}))}};y=_([g(1,(0,t.Inject)(v)),g(2,(0,t.Inject)(t.ILocalStorageService)),g(3,(0,t.Inject)(t.UserManagerService))],y);let b=class extends t.Plugin{constructor(e=d,n,r,i,a){super(),this._config=e,this._injector=n,this._configService=r,this._renderManagerSrv=i,this._localStorageService=a;let{...o}=(0,t.merge)({},d,this._config);this._configService.setConfig(u,o),this._initWatermarkStorage(),this._initDependencies()}async _initWatermarkStorage(){let e=this._configService.getConfig(u);if(!e)return;let{userWatermarkSettings:r,textWatermarkSettings:i,imageWatermarkSettings:c}=e;if(r)this._localStorageService.setItem(n.UNIVER_WATERMARK_STORAGE_KEY,{type:n.IWatermarkTypeEnum.UserInfo,config:{userInfo:(0,t.merge)({},s,r)}});else if(i)this._localStorageService.setItem(n.UNIVER_WATERMARK_STORAGE_KEY,{type:n.IWatermarkTypeEnum.Text,config:{text:(0,t.merge)({},a,i)}});else if(c)this._localStorageService.setItem(n.UNIVER_WATERMARK_STORAGE_KEY,{type:n.IWatermarkTypeEnum.Image,config:{image:(0,t.merge)({},o,c)}});else{let e=await this._localStorageService.getItem(n.UNIVER_WATERMARK_STORAGE_KEY);(e==null?void 0:e.type)===n.IWatermarkTypeEnum.UserInfo&&this._localStorageService.removeItem(n.UNIVER_WATERMARK_STORAGE_KEY)}}_initDependencies(){[[v]].forEach(e=>{this._injector.add(e)})}onRendered(){this._injector.get(v),this._initRenderDependencies()}_initRenderDependencies(){[[y]].forEach(e=>{this._renderManagerSrv.registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,e),this._renderManagerSrv.registerRenderModule(t.UniverInstanceType.UNIVER_DOC,e)})}};h(b,`pluginName`,`UNIVER_WATERMARK_PLUGIN`),h(b,`packageName`,c),h(b,`version`,l),b=_([g(1,(0,t.Inject)(t.Injector)),g(2,t.IConfigService),g(3,n.IRenderManagerService),g(4,(0,t.Inject)(t.ILocalStorageService))],b),Object.defineProperty(e,`UniverWatermarkPlugin`,{enumerable:!0,get:function(){return b}}),e.WATERMARK_IMAGE_ALLOW_IMAGE_LIST=i,e.WatermarkImageBaseConfig=o,Object.defineProperty(e,`WatermarkService`,{enumerable:!0,get:function(){return v}}),e.WatermarkTextBaseConfig=a,e.WatermarkUserInfoBaseConfig=s});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/watermark",
3
- "version": "0.20.1",
3
+ "version": "0.21.0",
4
4
  "private": false,
5
5
  "description": "univer watermark plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -58,14 +58,14 @@
58
58
  "rxjs": ">=7.0.0"
59
59
  },
60
60
  "dependencies": {
61
- "@univerjs/core": "0.20.1",
62
- "@univerjs/engine-render": "0.20.1"
61
+ "@univerjs/core": "0.21.0",
62
+ "@univerjs/engine-render": "0.21.0"
63
63
  },
64
64
  "devDependencies": {
65
65
  "rxjs": "^7.8.2",
66
66
  "typescript": "^6.0.2",
67
- "vitest": "^4.1.1",
68
- "@univerjs-infra/shared": "0.20.1"
67
+ "vitest": "^4.1.4",
68
+ "@univerjs-infra/shared": "0.21.0"
69
69
  },
70
70
  "scripts": {
71
71
  "test": "vitest run",