watermark-js-plus 0.0.1

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.
Files changed (43) hide show
  1. package/.editorconfig +16 -0
  2. package/.eslintignore +7 -0
  3. package/.eslintrc.cjs +46 -0
  4. package/.github/workflows/deploy.yml +29 -0
  5. package/.github/workflows/npm-publish.yml +32 -0
  6. package/.husky/commit-msg +4 -0
  7. package/.husky/pre-commit +4 -0
  8. package/.prettierrc +10 -0
  9. package/CHANGELOG.md +9 -0
  10. package/LICENSE +21 -0
  11. package/README.md +1 -0
  12. package/babel.config.cjs +23 -0
  13. package/changelog-option.cjs +87 -0
  14. package/commitlint.config.cjs +26 -0
  15. package/docs/.vitepress/config.ts +91 -0
  16. package/docs/.vitepress/locales/zh-CN.ts +49 -0
  17. package/docs/.vitepress/theme/index.ts +12 -0
  18. package/docs/config/blind-decode.md +33 -0
  19. package/docs/config/blind.md +19 -0
  20. package/docs/config/index.md +178 -0
  21. package/docs/guide/blind-watermark.md +267 -0
  22. package/docs/guide/getting-started.md +73 -0
  23. package/docs/guide/watermark.md +213 -0
  24. package/docs/guide/what-is-this.md +19 -0
  25. package/docs/index.md +33 -0
  26. package/docs/public/logo.png +0 -0
  27. package/docs/zh/config/blind-decode.md +33 -0
  28. package/docs/zh/config/blind.md +19 -0
  29. package/docs/zh/config/index.md +178 -0
  30. package/docs/zh/guide/blink-watermark.md +288 -0
  31. package/docs/zh/guide/getting-started.md +48 -0
  32. package/docs/zh/guide/watermark.md +213 -0
  33. package/docs/zh/guide/what-is-this.md +19 -0
  34. package/docs/zh/index.md +33 -0
  35. package/package.json +78 -0
  36. package/rollup.config.mjs +40 -0
  37. package/src/blind.ts +43 -0
  38. package/src/index.ts +7 -0
  39. package/src/types/index.ts +69 -0
  40. package/src/utils/index.ts +63 -0
  41. package/src/watermark.ts +288 -0
  42. package/tools/terser.js +19 -0
  43. package/tsconfig.json +15 -0
@@ -0,0 +1,213 @@
1
+ ---
2
+ layout: doc
3
+ ---
4
+ # Watemark
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
+ // text watermark
17
+ const textWatermark = new wm.Watermark({
18
+ content: 'hello my text watermark',
19
+ width: 200,
20
+ height: 200,
21
+ onSuccess: () => {
22
+ app.appContext.config.globalProperties.$message({
23
+ message: 'The text watermark added successfully!',
24
+ type: 'success'
25
+ });
26
+ }
27
+ });
28
+ const handleAddTextWatermark = () => {
29
+ if (isDark) {
30
+ textWatermark.options.fontColor = '#fff'
31
+ }
32
+ textWatermark.create();
33
+ };
34
+ const handleRemoveTextWatermark = () => {
35
+ textWatermark.destroy();
36
+ };
37
+
38
+ // multiline text watermark
39
+ const multiLineTextWatermark = new wm.Watermark({
40
+ contentType: 'multi-line-text',
41
+ content: 'hello my multi text watermark',
42
+ fontSize: 30,
43
+ width: 200,
44
+ height: 200,
45
+ onSuccess: () => {
46
+ app.appContext.config.globalProperties.$message({
47
+ message: 'The multi text watermark added successfully!',
48
+ type: 'success'
49
+ });
50
+ }
51
+ });
52
+ const handleAddMultiLineTextWatermark = () => {
53
+ if (isDark) {
54
+ multiLineTextWatermark.options.fontColor = '#fff'
55
+ }
56
+ multiLineTextWatermark.create();
57
+ };
58
+ const handleRemoveMultiLineTextWatermark = () => {
59
+ multiLineTextWatermark.destroy();
60
+ };
61
+
62
+ // image watermark
63
+ const imageWatermark = new wm.Watermark({
64
+ contentType: 'image',
65
+ image: 'https://cdn.jsdelivr.net/gh/zhensherlock/oss@main/uPic/github-mkWBiK.png',
66
+ imageWidth: 200,
67
+ // imageHeight: 20,
68
+ width: 300,
69
+ height: 300,
70
+ onSuccess: () => {
71
+ app.appContext.config.globalProperties.$message({
72
+ message: 'The image watermark added successfully!',
73
+ type: 'success'
74
+ });
75
+ }
76
+ });
77
+ const handleAddImageWatermark = () => {
78
+ imageWatermark.create();
79
+ };
80
+ const handleRemoveImageWatermark = () => {
81
+ imageWatermark.destroy();
82
+ };
83
+
84
+ // rich text watermark
85
+ const richTextWatermark = new wm.Watermark({
86
+ contentType: 'rich-text',
87
+ content: '<div style="background: #ccc;">The watermark is so <span style="color: #f00">nice</span>.</div>',
88
+ width: 300,
89
+ height: 300,
90
+ onSuccess: () => {
91
+ app.appContext.config.globalProperties.$message({
92
+ message: 'The rich text watermark added successfully!',
93
+ type: 'success'
94
+ });
95
+ }
96
+ });
97
+ const handleAddRichTextWatermark = () => {
98
+ richTextWatermark.create();
99
+ };
100
+ const handleRemoveRichTextWatermark = () => {
101
+ richTextWatermark.destroy();
102
+ };
103
+ </script>
104
+
105
+ ## Text Watermark
106
+
107
+ ```js
108
+ import wm from 'watermark-js-plus' // import watermark plugin
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: 'The text watermark added successfully!',
117
+ type: 'success'
118
+ });
119
+ }
120
+ })
121
+
122
+ watermark.create() // add watermark
123
+
124
+ watermark.destroy() // remove watermark
125
+ ```
126
+ <el-space>
127
+ <VPButton text="Add Text Watermark" @click="handleAddTextWatermark"></VPButton>
128
+ <VPButton text="Remove Text Watermark" @click="handleRemoveTextWatermark"></VPButton>
129
+ </el-space>
130
+
131
+ ## Multiline Text Watermark
132
+
133
+ ```js
134
+ import wm from 'watermark-js-plus' // import watermark plugin
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: 'The multiline text watermark added successfully!',
145
+ type: 'success'
146
+ });
147
+ }
148
+ })
149
+
150
+ watermark.create() // add watermark
151
+
152
+ watermark.destroy() // remove watermark
153
+ ```
154
+ <el-space>
155
+ <VPButton text="Add MultiLine Text Watermark" @click="handleAddMultiLineTextWatermark"></VPButton>
156
+ <VPButton text="Remove MultiLine Text Watermark" @click="handleRemoveMultiLineTextWatermark"></VPButton>
157
+ </el-space>
158
+
159
+ ## Image Watermark
160
+
161
+ ```js
162
+ import wm from 'watermark-js-plus' // import watermark plugin
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, // image width
170
+ // imageHeight: 20, // image height
171
+ onSuccess: () => {
172
+ app.appContext.config.globalProperties.$message({
173
+ message: 'The image watermark added successfully!',
174
+ type: 'success'
175
+ });
176
+ }
177
+ })
178
+
179
+ watermark.create() // add watermark
180
+
181
+ watermark.destroy() // remove watermark
182
+ ```
183
+ <el-space>
184
+ <VPButton text="Add Image Watermark" @click="handleAddImageWatermark"></VPButton>
185
+ <VPButton text="Remove Image Watermark" @click="handleRemoveImageWatermark"></VPButton>
186
+ </el-space>
187
+
188
+ ## Rich Text Watermark
189
+
190
+ ```js
191
+ import wm from 'watermark-js-plus' // import watermark plugin
192
+
193
+ const watermark = new wm.Watermark({
194
+ contentType: 'rich-text',
195
+ content: '<div style="background: #ccc;">Rich text watermark is so <span style="color: #f00">nice</span></div>',
196
+ width: 300,
197
+ height: 300,
198
+ onSuccess: () => {
199
+ app.appContext.config.globalProperties.$message({
200
+ message: 'The rich text watermark added successfully!',
201
+ type: 'success'
202
+ });
203
+ }
204
+ })
205
+
206
+ watermark.create() // add watermark
207
+
208
+ watermark.destroy() // remove watermark
209
+ ```
210
+ <el-space>
211
+ <VPButton text="Add Rich Text Watermark" @click="handleAddRichTextWatermark"></VPButton>
212
+ <VPButton text="Remove Rich Text Watermark" @click="handleRemoveRichTextWatermark"></VPButton>
213
+ </el-space>
@@ -0,0 +1,19 @@
1
+ ---
2
+ layout: doc
3
+ ---
4
+
5
+ # What is this?
6
+ This is a canvas-based watermark for browser.
7
+
8
+ ## Features
9
+ - Create watermark and blind watermark
10
+ - Supports text, multi text, image, rich text
11
+ - Watching for DOM changes
12
+ - Supports typescript
13
+ - Rich configuration
14
+
15
+ ## Browser Support
16
+
17
+ | ![Chrome](https://raw.githubusercontent.com/alrra/browser-logos/main/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.githubusercontent.com/alrra/browser-logos/main/src/firefox/firefox_48x48.png) | ![Safari](https://raw.githubusercontent.com/alrra/browser-logos/main/src/safari/safari_48x48.png) | ![Opera](https://raw.githubusercontent.com/alrra/browser-logos/main/src/opera/opera_48x48.png) | ![Edge](https://raw.githubusercontent.com/alrra/browser-logos/main/src/edge/edge_48x48.png) | ![IE](https://raw.githubusercontent.com/alrra/browser-logos/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png) |
18
+ |:-------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------------:|
19
+ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |
package/docs/index.md ADDED
@@ -0,0 +1,33 @@
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: Advanced watermark plugin
10
+ tagline: Simple, powerful, and performant.
11
+ image:
12
+ src: /logo.png
13
+ alt: watermark-js-plus
14
+ actions:
15
+ - theme: brand
16
+ text: Get Started 👆
17
+ link: /guide/getting-started
18
+ - theme: alt
19
+ text: View on GitHub
20
+ link: https://github.com/zhensherlock/watermark-js-plus
21
+
22
+ features:
23
+ - icon: 🛠️
24
+ title: Rich Features
25
+ details: Supports text, multi-line text, image and rich text.
26
+ - icon: 🔑
27
+ title: Fully Typed APIs
28
+ details: Flexible programmatic APIs with full TypeScript typing..
29
+ - icon: 📦
30
+ title: Extremely light
31
+ details: weighs ~2kb, you will forget it's even there!
32
+ ---
33
+
Binary file
@@ -0,0 +1,33 @@
1
+ ---
2
+ layout: doc
3
+ ---
4
+ # Blind Watermark Decode
5
+
6
+ ## url
7
+
8
+ - **Type:** `string`
9
+ - **Default:** `''`
10
+
11
+ Decoding picture path.
12
+
13
+ ## mode
14
+
15
+ - **Type:** `string`
16
+ - **Default:** `'canvas'`
17
+ - **available values**: `'canvas'`
18
+
19
+ Mode of decoding.
20
+
21
+ ## fillColor
22
+
23
+ - **Type:** `string`
24
+ - **Default:** `'#000'`
25
+
26
+ fill color.
27
+
28
+ ## compositeOperation
29
+
30
+ - **Type:** `string`
31
+ - **Default:** `'color-burn'`
32
+
33
+ composite operation.
@@ -0,0 +1,19 @@
1
+ ---
2
+ layout: doc
3
+ ---
4
+ # Blind Watermark Config
5
+
6
+ ## globalAlpha
7
+
8
+ - **Type:** `number`
9
+ - **Default:** `0.005`
10
+
11
+ Transparency of watermark.
12
+
13
+ ## mode
14
+
15
+ - **Type:** `string`
16
+ - **Default:** `'blind'`
17
+ - **available values**: `'default' | 'blind'`
18
+
19
+ Watermark mode
@@ -0,0 +1,178 @@
1
+ ---
2
+ layout: doc
3
+ ---
4
+ # Basic Config
5
+
6
+ ## width
7
+
8
+ - **Type:** `number`
9
+ - **Default:** `300`
10
+
11
+ A unit of width for a single watermark.
12
+
13
+ ## height
14
+
15
+ - **Type:** `number`
16
+ - **Default:** `300`
17
+
18
+ A unit of height for a single watermark.
19
+
20
+ ## rotate
21
+
22
+ - **Type:** `number`
23
+ - **Default:** `45`
24
+
25
+ Watermark rotation Angle.
26
+
27
+ Rotate with the center of the text as the origin.
28
+
29
+ ## contentType
30
+
31
+ - **Type:** `string`
32
+ - **Default:** `'text'`
33
+ - **available values**: `'text' | 'image' | 'multi-line-text' | 'rich-text'`
34
+
35
+ Type of watermark content.
36
+
37
+ ## content
38
+
39
+ - **Type:** `string`
40
+ - **Default:** `'hello watermark-js-plus'`
41
+
42
+ Watermark content.
43
+
44
+ ## imageWidth
45
+
46
+ - **Type:** `number`
47
+ - **Default:** `0`
48
+
49
+ Watermark image width.
50
+
51
+ ## imageHeight
52
+
53
+ - **Type:** `number`
54
+ - **Default:** `0`
55
+
56
+ Watermark image height.
57
+
58
+ ## lineHeight
59
+
60
+ - **Type:** `number`
61
+ - **Default:** `30`
62
+
63
+ Watermark content line high.
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
+ The font size of the watermark content.
85
+
86
+ ## fontFamily
87
+
88
+ - **Type:** `string`
89
+ - **Default:** `'sans-serif'`
90
+
91
+ The font family of the watermark content.
92
+
93
+ ## textAlign
94
+
95
+ - **Type:** `string`
96
+ - **Default:** `'center'`
97
+ - **available values**: `'center' | 'left' | 'right'`
98
+
99
+ Watermark content horizontal alignment.
100
+
101
+ ## textBaseline
102
+
103
+ - **Type:** `string`
104
+ - **Default:** `'middle'`
105
+ - **available values**: `'top' | 'bottom' | 'middle'`
106
+
107
+ Watermark content baseline.
108
+
109
+ ## fontColor
110
+
111
+ - **Type:** `string`
112
+ - **Default:** `'#000'`
113
+
114
+ Watermark content font color.
115
+
116
+ ## globalAlpha
117
+
118
+ - **Type:** `number`
119
+ - **Default:** `0.5`
120
+
121
+ Transparency of watermark.
122
+
123
+ ## fontWeight
124
+
125
+ - **Type:** `string`
126
+ - **Default:** `'normal'`
127
+
128
+ Watermark content font weight.
129
+
130
+ ## mode
131
+
132
+ - **Type:** `string`
133
+ - **Default:** `'default'`
134
+ - **available values**: `'default' | 'blind'`
135
+
136
+ Watermark mode
137
+
138
+ ## mutationObserve
139
+
140
+ - **Type:** `boolean`
141
+ - **Default:** `true`
142
+
143
+ Enable listening for watermark dom changes.
144
+
145
+ ## unique
146
+
147
+ - **Type:** `boolean`
148
+ - **Default:** `true`
149
+
150
+ The watermark cannot be added repeatedly.
151
+
152
+ ## parentElement
153
+
154
+ - **Type:** `HTMLElement`
155
+ - **Default:** `document.body`
156
+
157
+ Watermarking container.
158
+
159
+ ## onSuccess
160
+
161
+ - **Type:** `Function`
162
+ - **Default:** `() => {}`
163
+
164
+ Watermark added successful callback event.
165
+
166
+ ## onBeforeDestroy
167
+
168
+ - **Type:** `Function`
169
+ - **Default:** `() => {}`
170
+
171
+ Watermark delete before callback event.
172
+
173
+ ## onDestroyed
174
+
175
+ - **Type:** `Function`
176
+ - **Default:** `() => {}`
177
+
178
+ Watermark deleted after callback event.