watermark-js-plus 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -1
- package/package.json +22 -10
- package/.editorconfig +0 -16
- package/.eslintignore +0 -7
- package/.eslintrc.cjs +0 -46
- package/.github/workflows/deploy.yml +0 -29
- package/.github/workflows/npm-publish.yml +0 -32
- package/.husky/commit-msg +0 -4
- package/.husky/pre-commit +0 -4
- package/.prettierrc +0 -10
- package/CHANGELOG.md +0 -18
- package/babel.config.cjs +0 -23
- package/changelog-option.cjs +0 -87
- package/commitlint.config.cjs +0 -26
- package/docs/.vitepress/config.ts +0 -103
- package/docs/.vitepress/locales/zh-CN.ts +0 -51
- package/docs/.vitepress/theme/index.ts +0 -12
- package/docs/config/blind-decode.md +0 -33
- package/docs/config/blind.md +0 -19
- package/docs/config/index.md +0 -178
- package/docs/guide/blind-watermark.md +0 -267
- package/docs/guide/getting-started.md +0 -73
- package/docs/guide/watermark.md +0 -213
- package/docs/guide/what-is-this.md +0 -19
- package/docs/index.md +0 -33
- package/docs/public/favicons/apple-touch-icon.png +0 -0
- package/docs/public/favicons/favicon-64x64.png +0 -0
- package/docs/public/hero-image.png +0 -0
- package/docs/public/logo.png +0 -0
- package/docs/zh/config/blind-decode.md +0 -33
- package/docs/zh/config/blind.md +0 -19
- package/docs/zh/config/index.md +0 -178
- package/docs/zh/guide/blink-watermark.md +0 -288
- package/docs/zh/guide/getting-started.md +0 -48
- package/docs/zh/guide/watermark.md +0 -213
- package/docs/zh/guide/what-is-this.md +0 -19
- package/docs/zh/index.md +0 -33
- package/rollup.config.mjs +0 -40
- package/src/blind.ts +0 -43
- package/src/index.ts +0 -7
- package/src/types/index.ts +0 -69
- package/src/utils/index.ts +0 -63
- package/src/watermark.ts +0 -300
- package/tools/terser.js +0 -19
- package/tsconfig.json +0 -15
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
layout: doc
|
|
3
|
-
---
|
|
4
|
-
# 暗水印
|
|
5
|
-
|
|
6
|
-
<script setup lang="ts">
|
|
7
|
-
import VPButton from 'vitepress/dist/client/theme-default/components/VPButton.vue';
|
|
8
|
-
import { ref, getCurrentInstance } from 'vue';
|
|
9
|
-
import { Plus } from '@element-plus/icons-vue';
|
|
10
|
-
import wm from '../../../src';
|
|
11
|
-
import { useData } from 'vitepress';
|
|
12
|
-
|
|
13
|
-
const { isDark } = useData();
|
|
14
|
-
const app = getCurrentInstance();
|
|
15
|
-
const decodeBlindImage = ref('');
|
|
16
|
-
|
|
17
|
-
// 文本暗水印
|
|
18
|
-
const textBlindWatermark = new wm.BlindWatermark({
|
|
19
|
-
content: 'hello my watermark',
|
|
20
|
-
width: 200,
|
|
21
|
-
height: 200,
|
|
22
|
-
onSuccess: () => {
|
|
23
|
-
app.appContext.config.globalProperties.$message({
|
|
24
|
-
message: '文本暗水印添加成功!',
|
|
25
|
-
type: 'success'
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
const handleAddTextBlindWatermark = () => {
|
|
30
|
-
if (isDark) {
|
|
31
|
-
textBlindWatermark.options.fontColor = '#fff'
|
|
32
|
-
}
|
|
33
|
-
textBlindWatermark.create();
|
|
34
|
-
};
|
|
35
|
-
const handleRemoveTextBlindWatermark = () => {
|
|
36
|
-
textBlindWatermark.destroy();
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// 多行水印
|
|
40
|
-
const multiLineTextBlindWatermark = new wm.BlindWatermark({
|
|
41
|
-
contentType: 'multi-line-text',
|
|
42
|
-
content: 'hello my watermark watermark',
|
|
43
|
-
fontSize: 30,
|
|
44
|
-
width: 200,
|
|
45
|
-
height: 200,
|
|
46
|
-
onSuccess: () => {
|
|
47
|
-
app.appContext.config.globalProperties.$message({
|
|
48
|
-
message: '多行文本暗水印添加成功!',
|
|
49
|
-
type: 'success'
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
const handleAddMultiLineTextBlindWatermark = () => {
|
|
54
|
-
if (isDark) {
|
|
55
|
-
multiLineTextBlindWatermark.options.fontColor = '#fff'
|
|
56
|
-
}
|
|
57
|
-
multiLineTextBlindWatermark.create();
|
|
58
|
-
};
|
|
59
|
-
const handleRemoveMultiLineTextBlindWatermark = () => {
|
|
60
|
-
multiLineTextBlindWatermark.destroy();
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// 图片暗水印
|
|
64
|
-
const imageBlindWatermark = new wm.BlindWatermark({
|
|
65
|
-
contentType: 'image',
|
|
66
|
-
image: 'http://upic-service.test.upcdn.net/uPic/github-JxMIKf.png',
|
|
67
|
-
imageWidth: 200,
|
|
68
|
-
// imageHeight: 20,
|
|
69
|
-
width: 300,
|
|
70
|
-
height: 300,
|
|
71
|
-
onSuccess: () => {
|
|
72
|
-
app.appContext.config.globalProperties.$message({
|
|
73
|
-
message: '图片暗水印添加成功!',
|
|
74
|
-
type: 'success'
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
const handleAddImageBlindWatermark = () => {
|
|
79
|
-
imageBlindWatermark.create();
|
|
80
|
-
};
|
|
81
|
-
const handleRemoveImageBlindWatermark = () => {
|
|
82
|
-
imageBlindWatermark.destroy();
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
// 富文本水印
|
|
86
|
-
const richTextBlindWatermark = new wm.BlindWatermark({
|
|
87
|
-
contentType: 'rich-text',
|
|
88
|
-
content: '<div style="background: #ccc;">富文本暗水印 <span style="color: #f00">good</span></div>',
|
|
89
|
-
width: 300,
|
|
90
|
-
height: 300,
|
|
91
|
-
onSuccess: () => {
|
|
92
|
-
app.appContext.config.globalProperties.$message({
|
|
93
|
-
message: '富文本暗水印添加成功!',
|
|
94
|
-
type: 'success'
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
const handleAddRichTextBlindWatermark = () => {
|
|
99
|
-
richTextBlindWatermark.create();
|
|
100
|
-
};
|
|
101
|
-
const handleRemoveRichTextBlindWatermark = () => {
|
|
102
|
-
richTextBlindWatermark.destroy();
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
// 支持暗黑模式单行文本暗水印
|
|
106
|
-
const textBlindWatermarkSupportDark = new wm.BlindWatermark({
|
|
107
|
-
content: 'hello my watermark',
|
|
108
|
-
width: 200,
|
|
109
|
-
height: 200,
|
|
110
|
-
onSuccess: () => {
|
|
111
|
-
app.appContext.config.globalProperties.$message({
|
|
112
|
-
message: '支持暗黑模式单行文本暗水印添加成功!',
|
|
113
|
-
type: 'success'
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
const handleSupportDarkAddTextBlindWatermark = () => {
|
|
118
|
-
textBlindWatermarkSupportDark.create();
|
|
119
|
-
};
|
|
120
|
-
const handleSupportDarkRemoveTextBlindWatermark = () => {
|
|
121
|
-
textBlindWatermarkSupportDark.destroy();
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
// 解析暗水印
|
|
125
|
-
const handleSuccess = (uploadFile) => {
|
|
126
|
-
wm.BlindWatermark.decode({
|
|
127
|
-
...(isDark ? {
|
|
128
|
-
compositeOperation: 'overlay',
|
|
129
|
-
fillColor: '#fff',
|
|
130
|
-
} : {}),
|
|
131
|
-
url: uploadFile.url,
|
|
132
|
-
onSuccess: (imageBase64) => {
|
|
133
|
-
decodeBlindImage.value = imageBase64
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
</script>
|
|
138
|
-
|
|
139
|
-
## 文本暗水印
|
|
140
|
-
|
|
141
|
-
```js
|
|
142
|
-
import wm from 'watermark-js-plus' // 引入水印插件
|
|
143
|
-
|
|
144
|
-
const watermark = new wm.BlindWatermark({
|
|
145
|
-
content: 'hello my watermark',
|
|
146
|
-
width: 200,
|
|
147
|
-
height: 200,
|
|
148
|
-
onSuccess: () => {
|
|
149
|
-
app.appContext.config.globalProperties.$message({
|
|
150
|
-
message: '文本暗水印添加成功!',
|
|
151
|
-
type: 'success'
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
watermark.create() // 添加水印
|
|
157
|
-
|
|
158
|
-
watermark.destroy() // 删除水印
|
|
159
|
-
```
|
|
160
|
-
<el-space>
|
|
161
|
-
<VPButton text="添加文本暗水印" @click="handleAddTextBlindWatermark"></VPButton>
|
|
162
|
-
<VPButton text="删除文本暗水印" @click="handleRemoveTextBlindWatermark"></VPButton>
|
|
163
|
-
</el-space>
|
|
164
|
-
|
|
165
|
-
## 多行文本暗水印
|
|
166
|
-
|
|
167
|
-
```js
|
|
168
|
-
import wm from 'watermark-js-plus' // 引入水印插件
|
|
169
|
-
|
|
170
|
-
const watermark = new wm.BlindWatermark({
|
|
171
|
-
contentType: 'multi-line-text',
|
|
172
|
-
content: 'hello my watermark watermark',
|
|
173
|
-
fontSize: 30,
|
|
174
|
-
width: 200,
|
|
175
|
-
height: 200,
|
|
176
|
-
onSuccess: () => {
|
|
177
|
-
app.appContext.config.globalProperties.$message({
|
|
178
|
-
message: '多行文本暗水印添加成功!',
|
|
179
|
-
type: 'success'
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
watermark.create() // 添加水印
|
|
185
|
-
|
|
186
|
-
watermark.destroy() // 删除水印
|
|
187
|
-
```
|
|
188
|
-
<el-space>
|
|
189
|
-
<VPButton text="添加多行文本暗水印" @click="handleAddMultiLineTextBlindWatermark"></VPButton>
|
|
190
|
-
<VPButton text="删除多行文本暗水印" @click="handleRemoveMultiLineTextBlindWatermark"></VPButton>
|
|
191
|
-
</el-space>
|
|
192
|
-
|
|
193
|
-
## 图片暗水印
|
|
194
|
-
|
|
195
|
-
```js
|
|
196
|
-
import wm from 'watermark-js-plus' // 引入水印插件
|
|
197
|
-
|
|
198
|
-
const watermark = new wm.BlindWatermark({
|
|
199
|
-
contentType: 'image',
|
|
200
|
-
content: 'http://upic-service.test.upcdn.net/uPic/github-JxMIKf.png',
|
|
201
|
-
width: 300,
|
|
202
|
-
height: 300,
|
|
203
|
-
imageWidth: 100, // 图片宽度
|
|
204
|
-
// imageHeight: 20, // 图片高度
|
|
205
|
-
onSuccess: () => {
|
|
206
|
-
app.appContext.config.globalProperties.$message({
|
|
207
|
-
message: '图片暗水印添加成功!',
|
|
208
|
-
type: 'success'
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
watermark.create() // 添加水印
|
|
214
|
-
|
|
215
|
-
watermark.destroy() // 删除水印
|
|
216
|
-
```
|
|
217
|
-
<el-space>
|
|
218
|
-
<VPButton text="添加图片暗水印" @click="handleAddImageBlindWatermark"></VPButton>
|
|
219
|
-
<VPButton text="删除图片暗水印" @click="handleRemoveImageBlindWatermark"></VPButton>
|
|
220
|
-
</el-space>
|
|
221
|
-
|
|
222
|
-
## 富文本水印
|
|
223
|
-
|
|
224
|
-
```js
|
|
225
|
-
import wm from 'watermark-js-plus' // 引入水印插件
|
|
226
|
-
|
|
227
|
-
const watermark = new wm.BlindWatermark({
|
|
228
|
-
contentType: 'rich-text',
|
|
229
|
-
content: '<div style="background: #ccc;">富文本暗水印 <span style="color: #f00">good</span></div>',
|
|
230
|
-
width: 300,
|
|
231
|
-
height: 300,
|
|
232
|
-
onSuccess: () => {
|
|
233
|
-
app.appContext.config.globalProperties.$message({
|
|
234
|
-
message: '富文本暗水印添加成功!',
|
|
235
|
-
type: 'success'
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
watermark.create() // 添加水印
|
|
241
|
-
|
|
242
|
-
watermark.destroy() // 删除水印
|
|
243
|
-
```
|
|
244
|
-
<el-space>
|
|
245
|
-
<VPButton text="添加富文本暗水印" @click="handleAddRichTextBlindWatermark"></VPButton>
|
|
246
|
-
<VPButton text="删除富文本暗水印" @click="handleRemoveRichTextBlindWatermark"></VPButton>
|
|
247
|
-
</el-space>
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
## 解析暗水印
|
|
252
|
-
|
|
253
|
-
```js
|
|
254
|
-
import wm from 'watermark-js-plus' // 引入水印插件
|
|
255
|
-
|
|
256
|
-
wm.BlindWatermark.decode({
|
|
257
|
-
url: uploadFile.url, // 需要解析暗水印图片的URL
|
|
258
|
-
onSuccess: (imageBase64) => { // 解析成功后的回调事件,返回的是解析后图片的base64
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
<div>
|
|
264
|
-
<el-upload
|
|
265
|
-
list-type="picture-card"
|
|
266
|
-
accept="image/*"
|
|
267
|
-
:auto-upload="false"
|
|
268
|
-
:show-file-list="false"
|
|
269
|
-
:on-change="handleSuccess"
|
|
270
|
-
>
|
|
271
|
-
<el-icon><Plus /></el-icon>
|
|
272
|
-
</el-upload>
|
|
273
|
-
<el-image
|
|
274
|
-
v-if="decodeBlindImage"
|
|
275
|
-
style="width: 400px; height: 400px;margin-top: 20px;"
|
|
276
|
-
:src="decodeBlindImage"
|
|
277
|
-
:preview-src-list="[decodeBlindImage]"
|
|
278
|
-
fit="cover"
|
|
279
|
-
/>
|
|
280
|
-
</div>
|
|
281
|
-
|
|
282
|
-
[//]: # (<div style="position: relative;">)
|
|
283
|
-
|
|
284
|
-
[//]: # ( <div style="position: absolute;top:0;bottom: 0;left: 0;right: 0;mix-blend-mode: color-burn;background: #000;"></div>)
|
|
285
|
-
|
|
286
|
-
[//]: # ( <img width="200" src="http://upic-service.test.upcdn.net/uPic/iShot_2022-11-28_10.35.29-RP6dBG.png" alt="">)
|
|
287
|
-
|
|
288
|
-
[//]: # (</div>)
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
layout: doc
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# 开始
|
|
6
|
-
|
|
7
|
-
## 安装
|
|
8
|
-
|
|
9
|
-
Using npm:
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
$ npm install watermark-js-plus
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
[//]: # (Using bower:)
|
|
16
|
-
|
|
17
|
-
[//]: # ()
|
|
18
|
-
[//]: # (```bash)
|
|
19
|
-
|
|
20
|
-
[//]: # ($ bower install watermark-js-plus)
|
|
21
|
-
|
|
22
|
-
[//]: # (```)
|
|
23
|
-
|
|
24
|
-
Using yarn:
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
$ yarn add watermark-js-plus
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
[//]: # ()
|
|
31
|
-
[//]: # (Using jsDelivr CDN:)
|
|
32
|
-
|
|
33
|
-
[//]: # ()
|
|
34
|
-
[//]: # (```html)
|
|
35
|
-
|
|
36
|
-
[//]: # (<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>)
|
|
37
|
-
|
|
38
|
-
[//]: # (```)
|
|
39
|
-
|
|
40
|
-
[//]: # ()
|
|
41
|
-
[//]: # (Using unpkg CDN:)
|
|
42
|
-
|
|
43
|
-
[//]: # ()
|
|
44
|
-
[//]: # (```html)
|
|
45
|
-
|
|
46
|
-
[//]: # (<script src="https://unpkg.com/axios/dist/axios.min.js"></script>)
|
|
47
|
-
|
|
48
|
-
[//]: # (```)
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
layout: doc
|
|
3
|
-
---
|
|
4
|
-
# 明水印
|
|
5
|
-
|
|
6
|
-
<script setup lang="ts">
|
|
7
|
-
import VPButton from 'vitepress/dist/client/theme-default/components/VPButton.vue';
|
|
8
|
-
import { ref, getCurrentInstance } from 'vue';
|
|
9
|
-
import wm from '../../../src';
|
|
10
|
-
import { useData } from 'vitepress';
|
|
11
|
-
|
|
12
|
-
const { isDark } = useData();
|
|
13
|
-
const decodeBlindImage = ref('');
|
|
14
|
-
const app = getCurrentInstance();
|
|
15
|
-
|
|
16
|
-
// 文本水印
|
|
17
|
-
const textWatermark = new wm.Watermark({
|
|
18
|
-
content: 'hello my watermark',
|
|
19
|
-
width: 200,
|
|
20
|
-
height: 200,
|
|
21
|
-
onSuccess: () => {
|
|
22
|
-
app.appContext.config.globalProperties.$message({
|
|
23
|
-
message: '文本水印添加成功!',
|
|
24
|
-
type: 'success'
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
const handleAddTextWatermark = () => {
|
|
29
|
-
if (isDark.value) {
|
|
30
|
-
textWatermark.options.fontColor = '#fff'
|
|
31
|
-
}
|
|
32
|
-
textWatermark.create();
|
|
33
|
-
};
|
|
34
|
-
const handleRemoveTextWatermark = () => {
|
|
35
|
-
textWatermark.destroy();
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// 多行文本水印
|
|
39
|
-
const multiLineTextWatermark = new wm.Watermark({
|
|
40
|
-
contentType: 'multi-line-text',
|
|
41
|
-
content: 'hello my watermark watermark',
|
|
42
|
-
fontSize: 30,
|
|
43
|
-
width: 200,
|
|
44
|
-
height: 200,
|
|
45
|
-
onSuccess: () => {
|
|
46
|
-
app.appContext.config.globalProperties.$message({
|
|
47
|
-
message: '多行文本水印添加成功!',
|
|
48
|
-
type: 'success'
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
const handleAddMultiLineTextWatermark = () => {
|
|
53
|
-
if (isDark.value) {
|
|
54
|
-
multiLineTextWatermark.options.fontColor = '#fff'
|
|
55
|
-
}
|
|
56
|
-
multiLineTextWatermark.create();
|
|
57
|
-
};
|
|
58
|
-
const handleRemoveMultiLineTextWatermark = () => {
|
|
59
|
-
multiLineTextWatermark.destroy();
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// 图片水印
|
|
63
|
-
const imageWatermark = new wm.Watermark({
|
|
64
|
-
contentType: 'image',
|
|
65
|
-
image: 'http://upic-service.test.upcdn.net/uPic/github-JxMIKf.png',
|
|
66
|
-
imageWidth: 200,
|
|
67
|
-
// imageHeight: 20,
|
|
68
|
-
width: 300,
|
|
69
|
-
height: 300,
|
|
70
|
-
onSuccess: () => {
|
|
71
|
-
app.appContext.config.globalProperties.$message({
|
|
72
|
-
message: '图片水印添加成功!',
|
|
73
|
-
type: 'success'
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
const handleAddImageWatermark = () => {
|
|
78
|
-
imageWatermark.create();
|
|
79
|
-
};
|
|
80
|
-
const handleRemoveImageWatermark = () => {
|
|
81
|
-
imageWatermark.destroy();
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
// 富文本水印
|
|
85
|
-
const richTextWatermark = new wm.Watermark({
|
|
86
|
-
contentType: 'rich-text',
|
|
87
|
-
content: '<div style="background: #ccc;">富文本水印 <span style="color: #f00">good</span></div>',
|
|
88
|
-
width: 300,
|
|
89
|
-
height: 300,
|
|
90
|
-
onSuccess: () => {
|
|
91
|
-
app.appContext.config.globalProperties.$message({
|
|
92
|
-
message: '富文本水印添加成功!',
|
|
93
|
-
type: 'success'
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
const handleAddRichTextWatermark = () => {
|
|
98
|
-
richTextWatermark.create();
|
|
99
|
-
};
|
|
100
|
-
const handleRemoveRichTextWatermark = () => {
|
|
101
|
-
richTextWatermark.destroy();
|
|
102
|
-
};
|
|
103
|
-
</script>
|
|
104
|
-
|
|
105
|
-
## 文本水印
|
|
106
|
-
|
|
107
|
-
```js
|
|
108
|
-
import wm from 'watermark-js-plus' // 引入水印插件
|
|
109
|
-
|
|
110
|
-
const watermark = new wm.Watermark({
|
|
111
|
-
content: 'hello my watermark',
|
|
112
|
-
width: 200,
|
|
113
|
-
height: 200,
|
|
114
|
-
onSuccess: () => {
|
|
115
|
-
app.appContext.config.globalProperties.$message({
|
|
116
|
-
message: '文本水印添加成功!',
|
|
117
|
-
type: 'success'
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
watermark.create() // 添加水印
|
|
123
|
-
|
|
124
|
-
watermark.destroy() // 删除水印
|
|
125
|
-
```
|
|
126
|
-
<el-space>
|
|
127
|
-
<VPButton text="添加文本水印" @click="handleAddTextWatermark"></VPButton>
|
|
128
|
-
<VPButton text="删除文本水印" @click="handleRemoveTextWatermark"></VPButton>
|
|
129
|
-
</el-space>
|
|
130
|
-
|
|
131
|
-
## 多行文本水印
|
|
132
|
-
|
|
133
|
-
```js
|
|
134
|
-
import wm from 'watermark-js-plus' // 引入水印插件
|
|
135
|
-
|
|
136
|
-
const watermark = new wm.Watermark({
|
|
137
|
-
contentType: 'multi-line-text',
|
|
138
|
-
content: 'hello my watermark watermark',
|
|
139
|
-
fontSize: 30,
|
|
140
|
-
width: 200,
|
|
141
|
-
height: 200,
|
|
142
|
-
onSuccess: () => {
|
|
143
|
-
app.appContext.config.globalProperties.$message({
|
|
144
|
-
message: '多行文本水印添加成功!',
|
|
145
|
-
type: 'success'
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
watermark.create() // 添加水印
|
|
151
|
-
|
|
152
|
-
watermark.destroy() // 删除水印
|
|
153
|
-
```
|
|
154
|
-
<el-space>
|
|
155
|
-
<VPButton text="添加多行文本水印" @click="handleAddMultiLineTextWatermark"></VPButton>
|
|
156
|
-
<VPButton text="删除多行文本水印" @click="handleRemoveMultiLineTextWatermark"></VPButton>
|
|
157
|
-
</el-space>
|
|
158
|
-
|
|
159
|
-
## 图片水印
|
|
160
|
-
|
|
161
|
-
```js
|
|
162
|
-
import wm from 'watermark-js-plus' // 引入水印插件
|
|
163
|
-
|
|
164
|
-
const watermark = new wm.Watermark({
|
|
165
|
-
contentType: 'image',
|
|
166
|
-
content: 'http://upic-service.test.upcdn.net/uPic/github-JxMIKf.png',
|
|
167
|
-
width: 300,
|
|
168
|
-
height: 300,
|
|
169
|
-
imageWidth: 100, // 图片宽度
|
|
170
|
-
// imageHeight: 20, // 图片高度
|
|
171
|
-
onSuccess: () => {
|
|
172
|
-
app.appContext.config.globalProperties.$message({
|
|
173
|
-
message: '图片水印添加成功!',
|
|
174
|
-
type: 'success'
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
watermark.create() // 添加水印
|
|
180
|
-
|
|
181
|
-
watermark.destroy() // 删除水印
|
|
182
|
-
```
|
|
183
|
-
<el-space>
|
|
184
|
-
<VPButton text="添加图片水印" @click="handleAddImageWatermark"></VPButton>
|
|
185
|
-
<VPButton text="删除图片水印" @click="handleRemoveImageWatermark"></VPButton>
|
|
186
|
-
</el-space>
|
|
187
|
-
|
|
188
|
-
## 富文本水印
|
|
189
|
-
|
|
190
|
-
```js
|
|
191
|
-
import wm from 'watermark-js-plus' // 引入水印插件
|
|
192
|
-
|
|
193
|
-
const watermark = new wm.Watermark({
|
|
194
|
-
contentType: 'rich-text',
|
|
195
|
-
content: '<div style="background: #ccc;">富文本水印超级 <span style="color: #f00">棒</span></div>',
|
|
196
|
-
width: 300,
|
|
197
|
-
height: 300,
|
|
198
|
-
onSuccess: () => {
|
|
199
|
-
app.appContext.config.globalProperties.$message({
|
|
200
|
-
message: '富文本水印添加成功!',
|
|
201
|
-
type: 'success'
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
watermark.create() // 添加水印
|
|
207
|
-
|
|
208
|
-
watermark.destroy() // 删除水印
|
|
209
|
-
```
|
|
210
|
-
<el-space>
|
|
211
|
-
<VPButton text="添加富文本水印" @click="handleAddRichTextWatermark"></VPButton>
|
|
212
|
-
<VPButton text="删除富文本水印" @click="handleRemoveRichTextWatermark"></VPButton>
|
|
213
|
-
</el-space>
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
layout: doc
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# 这是什么?
|
|
6
|
-
这是一个基于 *canvas* 画布的水印库,作用于浏览器中。
|
|
7
|
-
|
|
8
|
-
## 功能
|
|
9
|
-
- 创建水印和暗水印
|
|
10
|
-
- 支持文本、多行文本、图片、富文本
|
|
11
|
-
- 支持监听DOM改动行为,可防止水印被手动删除
|
|
12
|
-
- 支持TS
|
|
13
|
-
- 丰富的配置项
|
|
14
|
-
|
|
15
|
-
## 浏览器兼容性
|
|
16
|
-
|
|
17
|
-
|  |  |  |  |  |  |
|
|
18
|
-
|:-------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------------:|
|
|
19
|
-
| Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |
|
package/docs/zh/index.md
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
layout: home
|
|
3
|
-
sidebar: false
|
|
4
|
-
title: watermark-js-plus.js
|
|
5
|
-
titleTemplate: Watermark
|
|
6
|
-
|
|
7
|
-
hero:
|
|
8
|
-
name: watermark-js-plus
|
|
9
|
-
text: 高级的水印插件
|
|
10
|
-
tagline: 简易、强大、高性能。
|
|
11
|
-
image:
|
|
12
|
-
src: /hero-image.png
|
|
13
|
-
alt: watermark-js-plus
|
|
14
|
-
actions:
|
|
15
|
-
- theme: brand
|
|
16
|
-
text: 开始 👆
|
|
17
|
-
link: /zh/guide/getting-started
|
|
18
|
-
- theme: alt
|
|
19
|
-
text: 在 GitHub 上查看
|
|
20
|
-
link: https://github.com/zhensherlock/watermark-js-plus
|
|
21
|
-
|
|
22
|
-
features:
|
|
23
|
-
- icon: 🛠️
|
|
24
|
-
title: 丰富的功能
|
|
25
|
-
details: 支持文本、多行文本、图片、富文本和暗水印。
|
|
26
|
-
- icon: 🔑
|
|
27
|
-
title: 完全类型化的API
|
|
28
|
-
details: 灵活的 API 和完整的 TypeScript 类型。
|
|
29
|
-
- icon: 📦
|
|
30
|
-
title: 极致轻量化
|
|
31
|
-
details: 大小只有 2kb 左右,你甚至可能忘记它的存在!
|
|
32
|
-
---
|
|
33
|
-
|
package/rollup.config.mjs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import filesize from 'rollup-plugin-filesize'
|
|
2
|
-
import babel from '@rollup/plugin-babel'
|
|
3
|
-
import resolve from '@rollup/plugin-node-resolve'
|
|
4
|
-
import commonjs from '@rollup/plugin-commonjs'
|
|
5
|
-
import eslint from '@rollup/plugin-eslint'
|
|
6
|
-
// import terser from './tools/terser.js'
|
|
7
|
-
import terser from '@rollup/plugin-terser'
|
|
8
|
-
import typescript from '@rollup/plugin-typescript'
|
|
9
|
-
|
|
10
|
-
export default {
|
|
11
|
-
input: 'src/index.ts',
|
|
12
|
-
output: [
|
|
13
|
-
{
|
|
14
|
-
file: 'dist/watermark.js',
|
|
15
|
-
format: 'umd',
|
|
16
|
-
exports: 'default',
|
|
17
|
-
name: 'watermark',
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
file: 'dist/watermark.min.js',
|
|
21
|
-
format: 'umd',
|
|
22
|
-
exports: 'default',
|
|
23
|
-
name: 'watermark',
|
|
24
|
-
plugins: [terser()]
|
|
25
|
-
}
|
|
26
|
-
],
|
|
27
|
-
plugins: [
|
|
28
|
-
typescript(),
|
|
29
|
-
eslint({
|
|
30
|
-
throwOnError: true,
|
|
31
|
-
throwOnWarning: true,
|
|
32
|
-
include: ['src/**'],
|
|
33
|
-
exclude: ['node_modules/**']
|
|
34
|
-
}),
|
|
35
|
-
resolve(),
|
|
36
|
-
commonjs(),
|
|
37
|
-
filesize(),
|
|
38
|
-
babel({ babelHelpers: 'runtime', exclude: ['node_modules/**'] })
|
|
39
|
-
]
|
|
40
|
-
}
|
package/src/blind.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import Watermark from './watermark'
|
|
2
|
-
import { CreateWatermarkModeEnum, DecodeBlindWatermark, DecodeBlindWatermarkModeEnum, WatermarkOptions } from './types'
|
|
3
|
-
import { convertImage, isFunction } from './utils'
|
|
4
|
-
|
|
5
|
-
export default class BlindWatermark extends Watermark {
|
|
6
|
-
constructor (props: Partial<WatermarkOptions> = {}) {
|
|
7
|
-
props.globalAlpha = 0.005
|
|
8
|
-
props.mode = CreateWatermarkModeEnum.blind
|
|
9
|
-
super(props)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
static decode (props: Partial<DecodeBlindWatermark>) {
|
|
13
|
-
const options = Object.assign({
|
|
14
|
-
url: '',
|
|
15
|
-
fillColor: '#000',
|
|
16
|
-
compositeOperation: 'color-burn',
|
|
17
|
-
mode: DecodeBlindWatermarkModeEnum.canvas
|
|
18
|
-
}, props)
|
|
19
|
-
if (!options.url) {
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
if (options.mode === DecodeBlindWatermarkModeEnum.canvas) {
|
|
23
|
-
const img = new Image()
|
|
24
|
-
img.src = options.url
|
|
25
|
-
img.onload = () => {
|
|
26
|
-
const { width, height } = img
|
|
27
|
-
const canvas = Watermark.createCanvas(width, height)
|
|
28
|
-
const ctx = canvas.getContext('2d')
|
|
29
|
-
if (ctx === null) {
|
|
30
|
-
throw new Error('get context error')
|
|
31
|
-
}
|
|
32
|
-
ctx.drawImage(img, 0, 0, width, height)
|
|
33
|
-
ctx.globalCompositeOperation = options.compositeOperation as any
|
|
34
|
-
ctx.fillStyle = options.fillColor
|
|
35
|
-
ctx.fillRect(0, 0, width, height)
|
|
36
|
-
const resultImage = convertImage(canvas)
|
|
37
|
-
if (options.onSuccess && isFunction(options.onSuccess)) {
|
|
38
|
-
options.onSuccess?.(resultImage)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|