@univerjs/watermark 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +114 -106
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var L=Object.defineProperty;var O=(e,t,r)=>t in e?L(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var g=(e,t,r)=>O(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),T=require("@univerjs/engine-render"),P=require("rxjs"),f="UNIVER_WATERMARK_STORAGE_KEY",D=10,N=["image/png","image/jpeg","image/jpg","image/bmp"],U={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},j={url:"",width:100,height:100,maintainAspectRatio:!0,originRatio:1,x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},$={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=(e=>(e.UserInfo="userInfo",e.Text="text",e.Image="image",e))(c||{});const Y="watermark.config",b={};var K=Object.defineProperty,G=Object.getOwnPropertyDescriptor,X=(e,t,r,i)=>{for(var a=i>1?void 0:i?G(t,r):t,n=e.length-1,s;n>=0;n--)(s=e[n])&&(a=(i?s(t,r,a):s(a))||a);return i&&a&&K(t,r,a),a},V=(e,t)=>(r,i)=>t(r,i,e);exports.WatermarkService=class extends o.Disposable{constructor(r){super();g(this,"_updateConfig$",new P.Subject);g(this,"updateConfig$",this._updateConfig$.asObservable());g(this,"_refresh$",new P.Subject);g(this,"refresh$",this._refresh$.asObservable());this._localStorageService=r}async getWatermarkConfig(){return await this._localStorageService.getItem(f)}updateWatermarkConfig(r){this._localStorageService.setItem(f,r),this._updateConfig$.next(r)}deleteWatermarkConfig(){this._localStorageService.removeItem(f),this._updateConfig$.next(null)}refresh(){this._refresh$.next(Math.random())}dispose(){this._refresh$.complete(),this._updateConfig$.complete()}};exports.WatermarkService=X([V(0,o.Inject(o.ILocalStorageService))],exports.WatermarkService);function B(e,t,r,i){const a=t.type,n=t.config;a===c.UserInfo&&n.userInfo?H(e,n.userInfo,i):a===c.Image&&n.image?q(e,n.image,r):a===c.Text&&n.text&&z(e,n.text)}function H(e,t,r){const{x:i,y:a,repeat:n,spacingX:s,spacingY:I,rotate:u,opacity:p,name:v,fontSize:W,color:y,bold:R,italic:S,direction:l}=t;if(!r)return;let _="";if(v&&(_+=`${r.name} `),!_)return;e.save(),e.globalAlpha=p,e.direction=l;let d="";if(S&&(d+="italic "),R&&(d+="bold "),d+=`${W}px Arial`,e.font=d,e.fillStyle=y,n){const h=e.canvas.width,m=e.canvas.height;for(let k=a;k<m;k+=W+I)for(let A=i;A<h;A+=e.measureText(_).width+s)e.save(),e.translate(A,k),e.rotate(Math.PI/180*u),e.fillText(_,0,0),e.restore()}else e.save(),e.translate(i,a),e.rotate(Math.PI/180*u),e.fillText(_,0,0),e.restore();e.restore()}function z(e,t){const{x:r,y:i,repeat:a,spacingX:n,spacingY:s,rotate:I,opacity:u,content:p,fontSize:v,color:W,bold:y,italic:R,direction:S}=t;e.save(),e.globalAlpha=u,e.direction=S;let l="";if(R&&(l+="italic "),y&&(l+="bold "),l+=`${v}px Arial`,e.font=l,e.fillStyle=W,p)if(a){const _=e.canvas.width,d=e.canvas.height;for(let h=i;h<d;h+=v+s)for(let m=r;m<_;m+=e.measureText(p).width+n)e.save(),e.translate(m,h),e.rotate(Math.PI/180*I),e.fillText(p,0,0),e.restore()}else e.save(),e.translate(r,i),e.rotate(Math.PI/180*I),e.fillText(p,0,0),e.restore();e.restore()}function q(e,t,r){const{x:i,y:a,repeat:n,spacingX:s,spacingY:I,rotate:u,opacity:p,width:v,height:W,maintainAspectRatio:y,originRatio:R}=t;if(!(r!=null&&r.complete))return;e.save(),e.globalAlpha=p;const S=v,l=y?v/R:W;if(n){const _=e.canvas.width,d=e.canvas.height;for(let h=a;h<d;h+=l+I)for(let m=i;m<_;m+=S+s)e.save(),e.translate(m,h),e.rotate(Math.PI/180*u),e.drawImage(r,0,0,S,l),e.restore()}else e.save(),e.translate(i,a),e.rotate(Math.PI/180*u),e.drawImage(r,0,0,S,l),e.restore();e.restore()}class F extends T.Layer{constructor(){super(...arguments);g(this,"_config");g(this,"_image");g(this,"_user")}render(r,i=!1){var n;super.render(r,i);const a=r||((n=this.scene.getEngine())==null?void 0:n.getCanvas().getContext());return a&&a.getId()&&this._renderWatermark(a),this}updateConfig(r,i){var a;this._config=r,((a=this._config)==null?void 0:a.type)===c.Image&&this._config.config.image&&(this._image=new Image,this._image.src=this._config.config.image.url),i&&(this._user=i)}_renderWatermark(r){this._config&&B(r,this._config,this._image,this._user)}}var J=Object.defineProperty,Q=Object.getOwnPropertyDescriptor,Z=(e,t,r,i)=>{for(var a=i>1?void 0:i?Q(t,r):t,n=e.length-1,s;n>=0;n--)(s=e[n])&&(a=(i?s(t,r,a):s(a))||a);return i&&a&&J(t,r,a),a},w=(e,t)=>(r,i)=>t(r,i,e);let M=class extends o.RxDisposable{constructor(t,r,i,a){super();g(this,"_watermarkLayer");this._context=t,this._watermarkService=r,this._localStorageService=i,this._userManagerService=a,this._watermarkLayer=new F(t.scene,[],D),this._initAddRender(),this._initWatermarkUpdate(),this._initWatermarkConfig()}_initAddRender(){const{scene:t}=this._context;t.addLayer(this._watermarkLayer)}async _initWatermarkConfig(){var r;const t=await this._localStorageService.getItem(f);t&&(this._watermarkService.updateWatermarkConfig(t),(r=this._context.mainComponent)==null||r.makeDirty())}_initWatermarkUpdate(){this.disposeWithMe(this._watermarkService.updateConfig$.subscribe(t=>{var r,i;if(!t){this._watermarkLayer.updateConfig(),(r=this._context.mainComponent)==null||r.makeDirty();return}t.type===c.UserInfo?this._watermarkLayer.updateConfig(t,this._userManagerService.getCurrentUser()):this._watermarkLayer.updateConfig(t),(i=this._context.mainComponent)==null||i.makeDirty()}))}};M=Z([w(1,o.Inject(exports.WatermarkService)),w(2,o.Inject(o.ILocalStorageService)),w(3,o.Inject(o.UserManagerService))],M);var x=Object.defineProperty,ee=Object.getOwnPropertyDescriptor,te=(e,t,r,i)=>{for(var a=i>1?void 0:i?ee(t,r):t,n=e.length-1,s;n>=0;n--)(s=e[n])&&(a=(i?s(t,r,a):s(a))||a);return i&&a&&x(t,r,a),a},C=(e,t)=>(r,i)=>t(r,i,e);const re="UNIVER_WATERMARK_PLUGIN";var E;exports.UniverWatermarkPlugin=(E=class extends o.Plugin{constructor(t=b,r,i,a,n){super(),this._config=t,this._injector=r,this._configService=i,this._renderManagerSrv=a,this._localStorageService=n;const{...s}=o.merge({},b,this._config);this._configService.setConfig(Y,s),this._initWatermarkStorage(),this._initDependencies()}async _initWatermarkStorage(){const{userWatermarkSettings:t,textWatermarkSettings:r,imageWatermarkSettings:i}=this._config;if(t)this._localStorageService.setItem(f,{type:c.UserInfo,config:{userInfo:{...$,userWatermarkSettings:t}}});else if(r)this._localStorageService.setItem(f,{type:c.Text,config:{text:{...U,textWatermarkSettings:r}}});else if(i)this._localStorageService.setItem(f,{type:c.Image,config:{image:{...j,imageWatermarkSettings:i}}});else{const a=await this._localStorageService.getItem(f);(a==null?void 0:a.type)===c.UserInfo&&this._localStorageService.removeItem(f)}}_initDependencies(){[[exports.WatermarkService]].forEach(t=>{this._injector.add(t)})}onRendered(){this._injector.get(exports.WatermarkService),this._initRenderDependencies()}_initRenderDependencies(){[[M]].forEach(t=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,t),this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,t)})}},g(E,"pluginName",re),E);exports.UniverWatermarkPlugin=te([C(1,o.Inject(o.Injector)),C(2,o.IConfigService),C(3,T.IRenderManagerService),C(4,o.Inject(o.ILocalStorageService))],exports.UniverWatermarkPlugin);exports.IWatermarkTypeEnum=c;exports.UNIVER_WATERMARK_STORAGE_KEY=f;exports.WATERMARK_IMAGE_ALLOW_IMAGE_LIST=N;exports.WatermarkImageBaseConfig=j;exports.WatermarkTextBaseConfig=U;exports.WatermarkUserInfoBaseConfig=$;
|
package/lib/es/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var l = (e, t, r) =>
|
|
4
|
-
import { Inject as
|
|
5
|
-
import { Layer as
|
|
1
|
+
var D = Object.defineProperty;
|
|
2
|
+
var L = (e, t, r) => t in e ? D(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var l = (e, t, r) => L(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { Inject as C, ILocalStorageService as k, Disposable as j, UserManagerService as N, RxDisposable as Y, Injector as X, Plugin as K, merge as G, UniverInstanceType as $, IConfigService as V } from "@univerjs/core";
|
|
5
|
+
import { Layer as H, IRenderManagerService as z } from "@univerjs/engine-render";
|
|
6
6
|
import { Subject as U } from "rxjs";
|
|
7
|
-
const
|
|
7
|
+
const h = "UNIVER_WATERMARK_STORAGE_KEY", B = 10, ue = ["image/png", "image/jpeg", "image/jpg", "image/bmp"], F = {
|
|
8
8
|
content: "",
|
|
9
9
|
fontSize: 16,
|
|
10
10
|
color: "rgb(0,0,0)",
|
|
@@ -18,7 +18,7 @@ const _ = "UNIVER_WATERMARK_STORAGE_KEY", H = 10, me = ["image/png", "image/jpeg
|
|
|
18
18
|
spacingY: 100,
|
|
19
19
|
rotate: 0,
|
|
20
20
|
opacity: 0.15
|
|
21
|
-
},
|
|
21
|
+
}, q = {
|
|
22
22
|
url: "",
|
|
23
23
|
width: 100,
|
|
24
24
|
height: 100,
|
|
@@ -31,7 +31,7 @@ const _ = "UNIVER_WATERMARK_STORAGE_KEY", H = 10, me = ["image/png", "image/jpeg
|
|
|
31
31
|
spacingY: 100,
|
|
32
32
|
rotate: 0,
|
|
33
33
|
opacity: 0.15
|
|
34
|
-
},
|
|
34
|
+
}, J = {
|
|
35
35
|
name: !0,
|
|
36
36
|
email: !1,
|
|
37
37
|
phone: !1,
|
|
@@ -49,12 +49,14 @@ const _ = "UNIVER_WATERMARK_STORAGE_KEY", H = 10, me = ["image/png", "image/jpeg
|
|
|
49
49
|
rotate: -30,
|
|
50
50
|
opacity: 0.15
|
|
51
51
|
};
|
|
52
|
-
var c = /* @__PURE__ */ ((e) => (e.UserInfo = "userInfo", e.Text = "text", e.Image = "image", e))(c || {})
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
var c = /* @__PURE__ */ ((e) => (e.UserInfo = "userInfo", e.Text = "text", e.Image = "image", e))(c || {});
|
|
53
|
+
const Q = "watermark.config", T = {};
|
|
54
|
+
var Z = Object.defineProperty, x = Object.getOwnPropertyDescriptor, ee = (e, t, r, a) => {
|
|
55
|
+
for (var i = a > 1 ? void 0 : a ? x(t, r) : t, s = e.length - 1, n; s >= 0; s--)
|
|
56
|
+
(n = e[s]) && (i = (a ? n(t, r, i) : n(i)) || i);
|
|
57
|
+
return a && i && Z(t, r, i), i;
|
|
58
|
+
}, te = (e, t) => (r, a) => t(r, a, e);
|
|
59
|
+
let R = class extends j {
|
|
58
60
|
constructor(t) {
|
|
59
61
|
super();
|
|
60
62
|
l(this, "_updateConfig$", new U());
|
|
@@ -64,13 +66,13 @@ let w = class extends j {
|
|
|
64
66
|
this._localStorageService = t;
|
|
65
67
|
}
|
|
66
68
|
async getWatermarkConfig() {
|
|
67
|
-
return await this._localStorageService.getItem(
|
|
69
|
+
return await this._localStorageService.getItem(h);
|
|
68
70
|
}
|
|
69
71
|
updateWatermarkConfig(t) {
|
|
70
|
-
this._localStorageService.setItem(
|
|
72
|
+
this._localStorageService.setItem(h, t), this._updateConfig$.next(t);
|
|
71
73
|
}
|
|
72
74
|
deleteWatermarkConfig() {
|
|
73
|
-
this._localStorageService.removeItem(
|
|
75
|
+
this._localStorageService.removeItem(h), this._updateConfig$.next(null);
|
|
74
76
|
}
|
|
75
77
|
refresh() {
|
|
76
78
|
this._refresh$.next(Math.random());
|
|
@@ -79,15 +81,15 @@ let w = class extends j {
|
|
|
79
81
|
this._refresh$.complete(), this._updateConfig$.complete();
|
|
80
82
|
}
|
|
81
83
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
],
|
|
85
|
-
function
|
|
86
|
-
const
|
|
87
|
-
|
|
84
|
+
R = ee([
|
|
85
|
+
te(0, C(k))
|
|
86
|
+
], R);
|
|
87
|
+
function re(e, t, r, a) {
|
|
88
|
+
const i = t.type, s = t.config;
|
|
89
|
+
i === c.UserInfo && s.userInfo ? ae(e, s.userInfo, a) : i === c.Image && s.image ? se(e, s.image, r) : i === c.Text && s.text && ie(e, s.text);
|
|
88
90
|
}
|
|
89
|
-
function
|
|
90
|
-
const { x:
|
|
91
|
+
function ae(e, t, r) {
|
|
92
|
+
const { x: a, y: i, repeat: s, spacingX: n, spacingY: S, rotate: v, opacity: p, name: m, fontSize: I, color: y, bold: W, italic: u, direction: o } = t;
|
|
91
93
|
if (!r)
|
|
92
94
|
return;
|
|
93
95
|
let f = "";
|
|
@@ -95,75 +97,75 @@ function ee(e, t, r) {
|
|
|
95
97
|
return;
|
|
96
98
|
e.save(), e.globalAlpha = p, e.direction = o;
|
|
97
99
|
let d = "";
|
|
98
|
-
if (u && (d += "italic "),
|
|
99
|
-
const g = e.canvas.width,
|
|
100
|
-
for (let
|
|
101
|
-
for (let
|
|
102
|
-
e.save(), e.translate(
|
|
100
|
+
if (u && (d += "italic "), W && (d += "bold "), d += `${I}px Arial`, e.font = d, e.fillStyle = y, s) {
|
|
101
|
+
const g = e.canvas.width, _ = e.canvas.height;
|
|
102
|
+
for (let A = i; A < _; A += I + S)
|
|
103
|
+
for (let b = a; b < g; b += e.measureText(f).width + n)
|
|
104
|
+
e.save(), e.translate(b, A), e.rotate(Math.PI / 180 * v), e.fillText(f, 0, 0), e.restore();
|
|
103
105
|
} else
|
|
104
|
-
e.save(), e.translate(
|
|
106
|
+
e.save(), e.translate(a, i), e.rotate(Math.PI / 180 * v), e.fillText(f, 0, 0), e.restore();
|
|
105
107
|
e.restore();
|
|
106
108
|
}
|
|
107
|
-
function
|
|
108
|
-
const { x: r, y:
|
|
109
|
+
function ie(e, t) {
|
|
110
|
+
const { x: r, y: a, repeat: i, spacingX: s, spacingY: n, rotate: S, opacity: v, content: p, fontSize: m, color: I, bold: y, italic: W, direction: u } = t;
|
|
109
111
|
e.save(), e.globalAlpha = v, e.direction = u;
|
|
110
112
|
let o = "";
|
|
111
|
-
if (
|
|
112
|
-
if (
|
|
113
|
+
if (W && (o += "italic "), y && (o += "bold "), o += `${m}px Arial`, e.font = o, e.fillStyle = I, p)
|
|
114
|
+
if (i) {
|
|
113
115
|
const f = e.canvas.width, d = e.canvas.height;
|
|
114
|
-
for (let g =
|
|
115
|
-
for (let
|
|
116
|
-
e.save(), e.translate(
|
|
116
|
+
for (let g = a; g < d; g += m + n)
|
|
117
|
+
for (let _ = r; _ < f; _ += e.measureText(p).width + s)
|
|
118
|
+
e.save(), e.translate(_, g), e.rotate(Math.PI / 180 * S), e.fillText(p, 0, 0), e.restore();
|
|
117
119
|
} else
|
|
118
|
-
e.save(), e.translate(r,
|
|
120
|
+
e.save(), e.translate(r, a), e.rotate(Math.PI / 180 * S), e.fillText(p, 0, 0), e.restore();
|
|
119
121
|
e.restore();
|
|
120
122
|
}
|
|
121
|
-
function
|
|
122
|
-
const { x:
|
|
123
|
+
function se(e, t, r) {
|
|
124
|
+
const { x: a, y: i, repeat: s, spacingX: n, spacingY: S, rotate: v, opacity: p, width: m, height: I, maintainAspectRatio: y, originRatio: W } = t;
|
|
123
125
|
if (!(r != null && r.complete))
|
|
124
126
|
return;
|
|
125
127
|
e.save(), e.globalAlpha = p;
|
|
126
|
-
const u = m, o = y ? m /
|
|
128
|
+
const u = m, o = y ? m / W : I;
|
|
127
129
|
if (s) {
|
|
128
130
|
const f = e.canvas.width, d = e.canvas.height;
|
|
129
|
-
for (let g =
|
|
130
|
-
for (let
|
|
131
|
-
e.save(), e.translate(
|
|
131
|
+
for (let g = i; g < d; g += o + S)
|
|
132
|
+
for (let _ = a; _ < f; _ += u + n)
|
|
133
|
+
e.save(), e.translate(_, g), e.rotate(Math.PI / 180 * v), e.drawImage(r, 0, 0, u, o), e.restore();
|
|
132
134
|
} else
|
|
133
|
-
e.save(), e.translate(
|
|
135
|
+
e.save(), e.translate(a, i), e.rotate(Math.PI / 180 * v), e.drawImage(r, 0, 0, u, o), e.restore();
|
|
134
136
|
e.restore();
|
|
135
137
|
}
|
|
136
|
-
class
|
|
138
|
+
class ne extends H {
|
|
137
139
|
constructor() {
|
|
138
140
|
super(...arguments);
|
|
139
141
|
l(this, "_config");
|
|
140
142
|
l(this, "_image");
|
|
141
143
|
l(this, "_user");
|
|
142
144
|
}
|
|
143
|
-
render(r,
|
|
145
|
+
render(r, a = !1) {
|
|
144
146
|
var s;
|
|
145
|
-
super.render(r,
|
|
146
|
-
const
|
|
147
|
-
return
|
|
147
|
+
super.render(r, a);
|
|
148
|
+
const i = r || ((s = this.scene.getEngine()) == null ? void 0 : s.getCanvas().getContext());
|
|
149
|
+
return i && i.getId() && this._renderWatermark(i), this;
|
|
148
150
|
}
|
|
149
|
-
updateConfig(r,
|
|
150
|
-
var
|
|
151
|
-
this._config = r, ((
|
|
151
|
+
updateConfig(r, a) {
|
|
152
|
+
var i;
|
|
153
|
+
this._config = r, ((i = this._config) == null ? void 0 : i.type) === c.Image && this._config.config.image && (this._image = new Image(), this._image.src = this._config.config.image.url), a && (this._user = a);
|
|
152
154
|
}
|
|
153
155
|
_renderWatermark(r) {
|
|
154
|
-
this._config &&
|
|
156
|
+
this._config && re(r, this._config, this._image, this._user);
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
|
-
var
|
|
158
|
-
for (var
|
|
159
|
-
(n = e[s]) && (
|
|
160
|
-
return
|
|
161
|
-
},
|
|
162
|
-
let
|
|
163
|
-
constructor(t, r,
|
|
159
|
+
var oe = Object.defineProperty, le = Object.getOwnPropertyDescriptor, ce = (e, t, r, a) => {
|
|
160
|
+
for (var i = a > 1 ? void 0 : a ? le(t, r) : t, s = e.length - 1, n; s >= 0; s--)
|
|
161
|
+
(n = e[s]) && (i = (a ? n(t, r, i) : n(i)) || i);
|
|
162
|
+
return a && i && oe(t, r, i), i;
|
|
163
|
+
}, P = (e, t) => (r, a) => t(r, a, e);
|
|
164
|
+
let E = class extends Y {
|
|
165
|
+
constructor(t, r, a, i) {
|
|
164
166
|
super();
|
|
165
167
|
l(this, "_watermarkLayer");
|
|
166
|
-
this._context = t, this._watermarkService = r, this._localStorageService =
|
|
168
|
+
this._context = t, this._watermarkService = r, this._localStorageService = a, this._userManagerService = i, this._watermarkLayer = new ne(t.scene, [], B), this._initAddRender(), this._initWatermarkUpdate(), this._initWatermarkConfig();
|
|
167
169
|
}
|
|
168
170
|
_initAddRender() {
|
|
169
171
|
const { scene: t } = this._context;
|
|
@@ -171,80 +173,86 @@ let P = class extends Y {
|
|
|
171
173
|
}
|
|
172
174
|
async _initWatermarkConfig() {
|
|
173
175
|
var r;
|
|
174
|
-
const t = await this._localStorageService.getItem(
|
|
176
|
+
const t = await this._localStorageService.getItem(h);
|
|
175
177
|
t && (this._watermarkService.updateWatermarkConfig(t), (r = this._context.mainComponent) == null || r.makeDirty());
|
|
176
178
|
}
|
|
177
179
|
_initWatermarkUpdate() {
|
|
178
180
|
this.disposeWithMe(
|
|
179
181
|
this._watermarkService.updateConfig$.subscribe((t) => {
|
|
180
|
-
var r,
|
|
182
|
+
var r, a;
|
|
181
183
|
if (!t) {
|
|
182
184
|
this._watermarkLayer.updateConfig(), (r = this._context.mainComponent) == null || r.makeDirty();
|
|
183
185
|
return;
|
|
184
186
|
}
|
|
185
|
-
t.type === c.UserInfo ? this._watermarkLayer.updateConfig(t, this._userManagerService.getCurrentUser()) : this._watermarkLayer.updateConfig(t), (
|
|
187
|
+
t.type === c.UserInfo ? this._watermarkLayer.updateConfig(t, this._userManagerService.getCurrentUser()) : this._watermarkLayer.updateConfig(t), (a = this._context.mainComponent) == null || a.makeDirty();
|
|
186
188
|
})
|
|
187
189
|
);
|
|
188
190
|
}
|
|
189
191
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
],
|
|
195
|
-
var
|
|
196
|
-
for (var
|
|
197
|
-
(n = e[s]) && (
|
|
198
|
-
return
|
|
199
|
-
},
|
|
200
|
-
const
|
|
192
|
+
E = ce([
|
|
193
|
+
P(1, C(R)),
|
|
194
|
+
P(2, C(k)),
|
|
195
|
+
P(3, C(N))
|
|
196
|
+
], E);
|
|
197
|
+
var fe = Object.defineProperty, ge = Object.getOwnPropertyDescriptor, _e = (e, t, r, a) => {
|
|
198
|
+
for (var i = a > 1 ? void 0 : a ? ge(t, r) : t, s = e.length - 1, n; s >= 0; s--)
|
|
199
|
+
(n = e[s]) && (i = (a ? n(t, r, i) : n(i)) || i);
|
|
200
|
+
return a && i && fe(t, r, i), i;
|
|
201
|
+
}, w = (e, t) => (r, a) => t(r, a, e);
|
|
202
|
+
const he = "UNIVER_WATERMARK_PLUGIN";
|
|
201
203
|
var M;
|
|
202
|
-
let
|
|
203
|
-
constructor(e =
|
|
204
|
-
super(), this._config = e, this._injector = t, this._configService = r, this._renderManagerSrv =
|
|
204
|
+
let O = (M = class extends K {
|
|
205
|
+
constructor(e = T, t, r, a, i) {
|
|
206
|
+
super(), this._config = e, this._injector = t, this._configService = r, this._renderManagerSrv = a, this._localStorageService = i;
|
|
207
|
+
const { ...s } = G(
|
|
208
|
+
{},
|
|
209
|
+
T,
|
|
210
|
+
this._config
|
|
211
|
+
);
|
|
212
|
+
this._configService.setConfig(Q, s), this._initWatermarkStorage(), this._initDependencies();
|
|
205
213
|
}
|
|
206
214
|
async _initWatermarkStorage() {
|
|
207
|
-
const {
|
|
208
|
-
if (e
|
|
209
|
-
this._localStorageService.setItem(
|
|
210
|
-
else if (
|
|
211
|
-
this._localStorageService.setItem(
|
|
212
|
-
else if (
|
|
213
|
-
this._localStorageService.setItem(
|
|
215
|
+
const { userWatermarkSettings: e, textWatermarkSettings: t, imageWatermarkSettings: r } = this._config;
|
|
216
|
+
if (e)
|
|
217
|
+
this._localStorageService.setItem(h, { type: c.UserInfo, config: { userInfo: { ...J, userWatermarkSettings: e } } });
|
|
218
|
+
else if (t)
|
|
219
|
+
this._localStorageService.setItem(h, { type: c.Text, config: { text: { ...F, textWatermarkSettings: t } } });
|
|
220
|
+
else if (r)
|
|
221
|
+
this._localStorageService.setItem(h, { type: c.Image, config: { image: { ...q, imageWatermarkSettings: r } } });
|
|
214
222
|
else {
|
|
215
|
-
const
|
|
216
|
-
(
|
|
223
|
+
const a = await this._localStorageService.getItem(h);
|
|
224
|
+
(a == null ? void 0 : a.type) === c.UserInfo && this._localStorageService.removeItem(h);
|
|
217
225
|
}
|
|
218
226
|
}
|
|
219
227
|
_initDependencies() {
|
|
220
|
-
[[
|
|
228
|
+
[[R]].forEach((e) => {
|
|
221
229
|
this._injector.add(e);
|
|
222
230
|
});
|
|
223
231
|
}
|
|
224
232
|
onRendered() {
|
|
225
|
-
this._injector.get(
|
|
233
|
+
this._injector.get(R), this._initRenderDependencies();
|
|
226
234
|
}
|
|
227
235
|
_initRenderDependencies() {
|
|
228
236
|
[
|
|
229
|
-
[
|
|
237
|
+
[E]
|
|
230
238
|
].forEach((e) => {
|
|
231
239
|
this._renderManagerSrv.registerRenderModule($.UNIVER_SHEET, e), this._renderManagerSrv.registerRenderModule($.UNIVER_DOC, e);
|
|
232
240
|
});
|
|
233
241
|
}
|
|
234
|
-
}, l(M, "pluginName",
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
],
|
|
242
|
+
}, l(M, "pluginName", he), M);
|
|
243
|
+
O = _e([
|
|
244
|
+
w(1, C(X)),
|
|
245
|
+
w(2, V),
|
|
246
|
+
w(3, z),
|
|
247
|
+
w(4, C(k))
|
|
248
|
+
], O);
|
|
241
249
|
export {
|
|
242
250
|
c as IWatermarkTypeEnum,
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
251
|
+
h as UNIVER_WATERMARK_STORAGE_KEY,
|
|
252
|
+
O as UniverWatermarkPlugin,
|
|
253
|
+
ue as WATERMARK_IMAGE_ALLOW_IMAGE_LIST,
|
|
254
|
+
q as WatermarkImageBaseConfig,
|
|
255
|
+
R as WatermarkService,
|
|
256
|
+
F as WatermarkTextBaseConfig,
|
|
257
|
+
J as WatermarkUserInfoBaseConfig
|
|
250
258
|
};
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(n
|
|
1
|
+
(function(s,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","rxjs"],n):(s=typeof globalThis<"u"?globalThis:s||self,n(s.UniverWatermark={},s.UniverCore,s.UniverEngineRender,s.rxjs))})(this,function(s,n,S,T){"use strict";var te=Object.defineProperty;var re=(s,n,S)=>n in s?te(s,n,{enumerable:!0,configurable:!0,writable:!0,value:S}):s[n]=S;var _=(s,n,S)=>re(s,typeof n!="symbol"?n+"":n,S);var M;const c="UNIVER_WATERMARK_STORAGE_KEY",O=["image/png","image/jpeg","image/jpg","image/bmp"],j={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},b={url:"",width:100,height:100,maintainAspectRatio:!0,originRatio:1,x:60,y:36,repeat:!0,spacingX:200,spacingY:100,rotate:0,opacity:.15},L={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 l=(e=>(e.UserInfo="userInfo",e.Text="text",e.Image="image",e))(l||{});const D="watermark.config",$={};var N=Object.defineProperty,Y=Object.getOwnPropertyDescriptor,K=(e,r,t,i)=>{for(var a=i>1?void 0:i?Y(r,t):r,o=e.length-1,f;o>=0;o--)(f=e[o])&&(a=(i?f(r,t,a):f(a))||a);return i&&a&&N(r,t,a),a},G=(e,r)=>(t,i)=>r(t,i,e);s.WatermarkService=class extends n.Disposable{constructor(t){super();_(this,"_updateConfig$",new T.Subject);_(this,"updateConfig$",this._updateConfig$.asObservable());_(this,"_refresh$",new T.Subject);_(this,"refresh$",this._refresh$.asObservable());this._localStorageService=t}async getWatermarkConfig(){return await this._localStorageService.getItem(c)}updateWatermarkConfig(t){this._localStorageService.setItem(c,t),this._updateConfig$.next(t)}deleteWatermarkConfig(){this._localStorageService.removeItem(c),this._updateConfig$.next(null)}refresh(){this._refresh$.next(Math.random())}dispose(){this._refresh$.complete(),this._updateConfig$.complete()}},s.WatermarkService=K([G(0,n.Inject(n.ILocalStorageService))],s.WatermarkService);function X(e,r,t,i){const a=r.type,o=r.config;a===l.UserInfo&&o.userInfo?V(e,o.userInfo,i):a===l.Image&&o.image?H(e,o.image,t):a===l.Text&&o.text&&B(e,o.text)}function V(e,r,t){const{x:i,y:a,repeat:o,spacingX:f,spacingY:R,rotate:I,opacity:d,name:p,fontSize:y,color:C,bold:A,italic:W,direction:g}=r;if(!t)return;let h="";if(p&&(h+=`${t.name} `),!h)return;e.save(),e.globalAlpha=d,e.direction=g;let u="";if(W&&(u+="italic "),A&&(u+="bold "),u+=`${y}px Arial`,e.font=u,e.fillStyle=C,o){const m=e.canvas.width,v=e.canvas.height;for(let U=a;U<v;U+=y+R)for(let P=i;P<m;P+=e.measureText(h).width+f)e.save(),e.translate(P,U),e.rotate(Math.PI/180*I),e.fillText(h,0,0),e.restore()}else e.save(),e.translate(i,a),e.rotate(Math.PI/180*I),e.fillText(h,0,0),e.restore();e.restore()}function B(e,r){const{x:t,y:i,repeat:a,spacingX:o,spacingY:f,rotate:R,opacity:I,content:d,fontSize:p,color:y,bold:C,italic:A,direction:W}=r;e.save(),e.globalAlpha=I,e.direction=W;let g="";if(A&&(g+="italic "),C&&(g+="bold "),g+=`${p}px Arial`,e.font=g,e.fillStyle=y,d)if(a){const h=e.canvas.width,u=e.canvas.height;for(let m=i;m<u;m+=p+f)for(let v=t;v<h;v+=e.measureText(d).width+o)e.save(),e.translate(v,m),e.rotate(Math.PI/180*R),e.fillText(d,0,0),e.restore()}else e.save(),e.translate(t,i),e.rotate(Math.PI/180*R),e.fillText(d,0,0),e.restore();e.restore()}function H(e,r,t){const{x:i,y:a,repeat:o,spacingX:f,spacingY:R,rotate:I,opacity:d,width:p,height:y,maintainAspectRatio:C,originRatio:A}=r;if(!(t!=null&&t.complete))return;e.save(),e.globalAlpha=d;const W=p,g=C?p/A:y;if(o){const h=e.canvas.width,u=e.canvas.height;for(let m=a;m<u;m+=g+R)for(let v=i;v<h;v+=W+f)e.save(),e.translate(v,m),e.rotate(Math.PI/180*I),e.drawImage(t,0,0,W,g),e.restore()}else e.save(),e.translate(i,a),e.rotate(Math.PI/180*I),e.drawImage(t,0,0,W,g),e.restore();e.restore()}class z extends S.Layer{constructor(){super(...arguments);_(this,"_config");_(this,"_image");_(this,"_user")}render(t,i=!1){var o;super.render(t,i);const a=t||((o=this.scene.getEngine())==null?void 0:o.getCanvas().getContext());return a&&a.getId()&&this._renderWatermark(a),this}updateConfig(t,i){var a;this._config=t,((a=this._config)==null?void 0:a.type)===l.Image&&this._config.config.image&&(this._image=new Image,this._image.src=this._config.config.image.url),i&&(this._user=i)}_renderWatermark(t){this._config&&X(t,this._config,this._image,this._user)}}var q=Object.defineProperty,F=Object.getOwnPropertyDescriptor,J=(e,r,t,i)=>{for(var a=i>1?void 0:i?F(r,t):r,o=e.length-1,f;o>=0;o--)(f=e[o])&&(a=(i?f(r,t,a):f(a))||a);return i&&a&&q(r,t,a),a},E=(e,r)=>(t,i)=>r(t,i,e);let w=class extends n.RxDisposable{constructor(r,t,i,a){super();_(this,"_watermarkLayer");this._context=r,this._watermarkService=t,this._localStorageService=i,this._userManagerService=a,this._watermarkLayer=new z(r.scene,[],10),this._initAddRender(),this._initWatermarkUpdate(),this._initWatermarkConfig()}_initAddRender(){const{scene:r}=this._context;r.addLayer(this._watermarkLayer)}async _initWatermarkConfig(){var t;const r=await this._localStorageService.getItem(c);r&&(this._watermarkService.updateWatermarkConfig(r),(t=this._context.mainComponent)==null||t.makeDirty())}_initWatermarkUpdate(){this.disposeWithMe(this._watermarkService.updateConfig$.subscribe(r=>{var t,i;if(!r){this._watermarkLayer.updateConfig(),(t=this._context.mainComponent)==null||t.makeDirty();return}r.type===l.UserInfo?this._watermarkLayer.updateConfig(r,this._userManagerService.getCurrentUser()):this._watermarkLayer.updateConfig(r),(i=this._context.mainComponent)==null||i.makeDirty()}))}};w=J([E(1,n.Inject(s.WatermarkService)),E(2,n.Inject(n.ILocalStorageService)),E(3,n.Inject(n.UserManagerService))],w);var Q=Object.defineProperty,Z=Object.getOwnPropertyDescriptor,x=(e,r,t,i)=>{for(var a=i>1?void 0:i?Z(r,t):r,o=e.length-1,f;o>=0;o--)(f=e[o])&&(a=(i?f(r,t,a):f(a))||a);return i&&a&&Q(r,t,a),a},k=(e,r)=>(t,i)=>r(t,i,e);const ee="UNIVER_WATERMARK_PLUGIN";s.UniverWatermarkPlugin=(M=class extends n.Plugin{constructor(r=$,t,i,a,o){super(),this._config=r,this._injector=t,this._configService=i,this._renderManagerSrv=a,this._localStorageService=o;const{...f}=n.merge({},$,this._config);this._configService.setConfig(D,f),this._initWatermarkStorage(),this._initDependencies()}async _initWatermarkStorage(){const{userWatermarkSettings:r,textWatermarkSettings:t,imageWatermarkSettings:i}=this._config;if(r)this._localStorageService.setItem(c,{type:l.UserInfo,config:{userInfo:{...L,userWatermarkSettings:r}}});else if(t)this._localStorageService.setItem(c,{type:l.Text,config:{text:{...j,textWatermarkSettings:t}}});else if(i)this._localStorageService.setItem(c,{type:l.Image,config:{image:{...b,imageWatermarkSettings:i}}});else{const a=await this._localStorageService.getItem(c);(a==null?void 0:a.type)===l.UserInfo&&this._localStorageService.removeItem(c)}}_initDependencies(){[[s.WatermarkService]].forEach(r=>{this._injector.add(r)})}onRendered(){this._injector.get(s.WatermarkService),this._initRenderDependencies()}_initRenderDependencies(){[[w]].forEach(r=>{this._renderManagerSrv.registerRenderModule(n.UniverInstanceType.UNIVER_SHEET,r),this._renderManagerSrv.registerRenderModule(n.UniverInstanceType.UNIVER_DOC,r)})}},_(M,"pluginName",ee),M),s.UniverWatermarkPlugin=x([k(1,n.Inject(n.Injector)),k(2,n.IConfigService),k(3,S.IRenderManagerService),k(4,n.Inject(n.ILocalStorageService))],s.UniverWatermarkPlugin),s.IWatermarkTypeEnum=l,s.UNIVER_WATERMARK_STORAGE_KEY=c,s.WATERMARK_IMAGE_ALLOW_IMAGE_LIST=O,s.WatermarkImageBaseConfig=b,s.WatermarkTextBaseConfig=j,s.WatermarkUserInfoBaseConfig=L,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/watermark",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "univer watermark plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -59,15 +59,15 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"clsx": "^2.1.1",
|
|
62
|
-
"@univerjs/
|
|
63
|
-
"@univerjs/
|
|
62
|
+
"@univerjs/engine-render": "0.5.2",
|
|
63
|
+
"@univerjs/core": "0.5.2"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"rxjs": "^7.8.1",
|
|
67
67
|
"typescript": "^5.7.2",
|
|
68
|
-
"vite": "^6.0.
|
|
69
|
-
"vitest": "^2.1.
|
|
70
|
-
"@univerjs-infra/shared": "0.5.
|
|
68
|
+
"vite": "^6.0.3",
|
|
69
|
+
"vitest": "^2.1.8",
|
|
70
|
+
"@univerjs-infra/shared": "0.5.2"
|
|
71
71
|
},
|
|
72
72
|
"space": {
|
|
73
73
|
".": {
|