watermark-js-plus 0.0.2 → 0.0.4
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/dist/index.js +400 -0
- package/dist/index.min.js +1 -0
- 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
package/docs/zh/config/index.md
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
layout: doc
|
|
3
|
-
---
|
|
4
|
-
# 基础配置项
|
|
5
|
-
|
|
6
|
-
## width
|
|
7
|
-
|
|
8
|
-
- **Type:** `number`
|
|
9
|
-
- **Default:** `300`
|
|
10
|
-
|
|
11
|
-
单个水印的宽度。
|
|
12
|
-
|
|
13
|
-
## height
|
|
14
|
-
|
|
15
|
-
- **Type:** `number`
|
|
16
|
-
- **Default:** `300`
|
|
17
|
-
|
|
18
|
-
单个水印的高度。
|
|
19
|
-
|
|
20
|
-
## rotate
|
|
21
|
-
|
|
22
|
-
- **Type:** `number`
|
|
23
|
-
- **Default:** `45`
|
|
24
|
-
|
|
25
|
-
水印旋转角度
|
|
26
|
-
|
|
27
|
-
以文本的中心为原点旋转。
|
|
28
|
-
|
|
29
|
-
## contentType
|
|
30
|
-
|
|
31
|
-
- **Type:** `string`
|
|
32
|
-
- **Default:** `'text'`
|
|
33
|
-
- **available values**: `'text' | 'image' | 'multi-line-text' | 'rich-text'`
|
|
34
|
-
|
|
35
|
-
水印内容类型。
|
|
36
|
-
|
|
37
|
-
## content
|
|
38
|
-
|
|
39
|
-
- **Type:** `string`
|
|
40
|
-
- **Default:** `'hello watermark-js-plus'`
|
|
41
|
-
|
|
42
|
-
水印内容。
|
|
43
|
-
|
|
44
|
-
## imageWidth
|
|
45
|
-
|
|
46
|
-
- **Type:** `number`
|
|
47
|
-
- **Default:** `0`
|
|
48
|
-
|
|
49
|
-
水印图像宽度。
|
|
50
|
-
|
|
51
|
-
## imageHeight
|
|
52
|
-
|
|
53
|
-
- **Type:** `number`
|
|
54
|
-
- **Default:** `0`
|
|
55
|
-
|
|
56
|
-
水印图像高度。
|
|
57
|
-
|
|
58
|
-
## lineHeight
|
|
59
|
-
|
|
60
|
-
- **Type:** `number`
|
|
61
|
-
- **Default:** `30`
|
|
62
|
-
|
|
63
|
-
水印内容行高。
|
|
64
|
-
|
|
65
|
-
## zIndex
|
|
66
|
-
|
|
67
|
-
- **Type:** `number`
|
|
68
|
-
- **Default:** `10000`
|
|
69
|
-
|
|
70
|
-
z-index
|
|
71
|
-
|
|
72
|
-
## backgroundPosition
|
|
73
|
-
|
|
74
|
-
- **Type:** `string`
|
|
75
|
-
- **Default:** `'0 0, 0 0'`
|
|
76
|
-
|
|
77
|
-
background-position
|
|
78
|
-
|
|
79
|
-
## fontSize
|
|
80
|
-
|
|
81
|
-
- **Type:** `number`
|
|
82
|
-
- **Default:** `20`
|
|
83
|
-
|
|
84
|
-
水印内容的字体大小。
|
|
85
|
-
|
|
86
|
-
## fontFamily
|
|
87
|
-
|
|
88
|
-
- **Type:** `string`
|
|
89
|
-
- **Default:** `'sans-serif'`
|
|
90
|
-
|
|
91
|
-
水印内容的字体。
|
|
92
|
-
|
|
93
|
-
## textAlign
|
|
94
|
-
|
|
95
|
-
- **Type:** `string`
|
|
96
|
-
- **Default:** `'center'`
|
|
97
|
-
- **available values**: `'center' | 'left' | 'right'`
|
|
98
|
-
|
|
99
|
-
水印内容水平对齐方式。
|
|
100
|
-
|
|
101
|
-
## textBaseline
|
|
102
|
-
|
|
103
|
-
- **Type:** `string`
|
|
104
|
-
- **Default:** `'middle'`
|
|
105
|
-
- **available values**: `'top' | 'bottom' | 'middle'`
|
|
106
|
-
|
|
107
|
-
水印内容基准线。
|
|
108
|
-
|
|
109
|
-
## fontColor
|
|
110
|
-
|
|
111
|
-
- **Type:** `string`
|
|
112
|
-
- **Default:** `'#000'`
|
|
113
|
-
|
|
114
|
-
水印内容字体颜色。
|
|
115
|
-
|
|
116
|
-
## globalAlpha
|
|
117
|
-
|
|
118
|
-
- **Type:** `number`
|
|
119
|
-
- **Default:** `0.5`
|
|
120
|
-
|
|
121
|
-
水印的透明度。
|
|
122
|
-
|
|
123
|
-
## fontWeight
|
|
124
|
-
|
|
125
|
-
- **Type:** `string`
|
|
126
|
-
- **Default:** `'normal'`
|
|
127
|
-
|
|
128
|
-
水印内容字体权重。
|
|
129
|
-
|
|
130
|
-
## mode
|
|
131
|
-
|
|
132
|
-
- **Type:** `string`
|
|
133
|
-
- **Default:** `'default'`
|
|
134
|
-
- **available values**: `'default' | 'blind'`
|
|
135
|
-
|
|
136
|
-
水印模式。
|
|
137
|
-
|
|
138
|
-
## mutationObserve
|
|
139
|
-
|
|
140
|
-
- **Type:** `boolean`
|
|
141
|
-
- **Default:** `true`
|
|
142
|
-
|
|
143
|
-
启用侦听水印dom更改。
|
|
144
|
-
|
|
145
|
-
## unique
|
|
146
|
-
|
|
147
|
-
- **Type:** `boolean`
|
|
148
|
-
- **Default:** `true`
|
|
149
|
-
|
|
150
|
-
不能重复添加水印。
|
|
151
|
-
|
|
152
|
-
## parent
|
|
153
|
-
|
|
154
|
-
- **Type:** `Element | string`
|
|
155
|
-
- **Default:** `'body'`
|
|
156
|
-
|
|
157
|
-
水印的容器。
|
|
158
|
-
|
|
159
|
-
## onSuccess
|
|
160
|
-
|
|
161
|
-
- **Type:** `Function`
|
|
162
|
-
- **Default:** `() => {}`
|
|
163
|
-
|
|
164
|
-
水印添加成功的回调事件。
|
|
165
|
-
|
|
166
|
-
## onBeforeDestroy
|
|
167
|
-
|
|
168
|
-
- **Type:** `Function`
|
|
169
|
-
- **Default:** `() => {}`
|
|
170
|
-
|
|
171
|
-
水印删除前的回调事件。
|
|
172
|
-
|
|
173
|
-
## onDestroyed
|
|
174
|
-
|
|
175
|
-
- **Type:** `Function`
|
|
176
|
-
- **Default:** `() => {}`
|
|
177
|
-
|
|
178
|
-
水印删除后的回调事件。
|
|
@@ -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>
|