watermark-js-plus 0.0.1 → 0.0.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.
@@ -1,4 +1,4 @@
1
- name: Deploy
1
+ name: deploy
2
2
 
3
3
  on:
4
4
  push:
@@ -1,7 +1,7 @@
1
1
  # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
2
  # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
3
 
4
- name: Publish
4
+ name: npm-publish
5
5
 
6
6
  on:
7
7
  release:
package/CHANGELOG.md CHANGED
@@ -1,4 +1,13 @@
1
- ## 0.0.1 (2022-12-05)
1
+ ## [0.0.2](https://github.com/zhensherlock/watermark-js-plus/compare/v0.0.1...v0.0.2) (2022-12-07)
2
+
3
+
4
+ ### ✨ Features | 新功能
5
+
6
+ * optimize parent element logic ([836a1ee](https://github.com/zhensherlock/watermark-js-plus/commit/836a1eed2319c42444bdb6362dbf8114ab9bcf0e))
7
+
8
+
9
+
10
+ ## [0.0.1](https://github.com/zhensherlock/watermark-js-plus/compare/fb530a78a35020947fec230142a131b56b3588b4...v0.0.1) (2022-12-05)
2
11
 
3
12
 
4
13
  ### ✨ Features | 新功能
@@ -5,9 +5,19 @@ export default {
5
5
  title: 'watermark-js-plus',
6
6
  description: 'A watermark plugin',
7
7
  base: '/watermark-js-plus',
8
+ head: [
9
+ ['link', { rel: 'shortcut icon', href: '/watermark-js-plus/favicons/favicon-64x64.png' }],
10
+ ['link', { rel: 'apple-touch-icon', sizes: '180x180', href: '/watermark-js-plus/favicons/apple-touch-icon.png' }],
11
+ // ['link', { rel: 'icon', type: 'image/png', sizes: '32x32', href: '/favicons/favicon-32x32.png' }],
12
+ // ['link', { rel: 'icon', type: 'image/png', sizes: '16x16', href: '/favicons/favicon-16x16.png' }],
13
+ // ['link', { rel: "manifest", href: "/assets/favicons/site.webmanifest"}],
14
+ // ['link', { rel: "mask-icon", href: "/assets/favicons/safari-pinned-tab.svg", color: "#3a0839"}],
15
+ // ['meta', { name: "msapplication-TileColor", content: "#3a0839"}],
16
+ // ['meta', { name: "msapplication-config", content: "/assets/favicons/browserconfig.xml"}],
17
+ // ['meta', { name: "theme-color", content: "#ffffff"}],
18
+ ],
8
19
  themeConfig: {
9
- // siteTitle: "Kitty",
10
- // logo: "/logo.png",
20
+ logo: '/logo.png',
11
21
  nav: [
12
22
  { text: 'Guide', link: '/guide/what-is-this', activeMatch: '/guide/' },
13
23
  { text: 'Configs', link: '/config/', activeMatch: '/config/' },
@@ -20,7 +30,7 @@ export default {
20
30
  },
21
31
  // {
22
32
  // text: 'Contributing',
23
- // link: 'https://github.com/vuejs/vitepress/blob/main/.github/contributing.md'
33
+ // link: 'https://github.com/zhensherlock/watermark-js-plus/blob/main/.github/contributing.md'
24
34
  // }
25
35
  ]
26
36
  }
@@ -32,6 +42,7 @@ export default {
32
42
  '/guide': [
33
43
  {
34
44
  text: 'Guide',
45
+ // collapsible: true,
35
46
  items: [
36
47
  { text: 'Introduce', link: '/guide/what-is-this' },
37
48
  { text: 'Getting Started', link: '/guide/getting-started' },
@@ -43,6 +54,7 @@ export default {
43
54
  '/config': [
44
55
  {
45
56
  text: 'Config',
57
+ // collapsible: true,
46
58
  items: [
47
59
  { text: 'Basic Config', link: '/config/' },
48
60
  { text: 'Blind Watermark Config', link: '/config/blind' },
@@ -24,6 +24,7 @@ export default {
24
24
  '/zh/guide': [
25
25
  {
26
26
  text: '向导',
27
+ // collapsible: true,
27
28
  items: [
28
29
  { text: '介绍', link: '/zh/guide/what-is-this' },
29
30
  { text: '开始使用', link: '/zh/guide/getting-started' },
@@ -35,6 +36,7 @@ export default {
35
36
  '/zh/config': [
36
37
  {
37
38
  text: '配置',
39
+ // collapsible: true,
38
40
  items: [
39
41
  { text: '基础配置项', link: '/zh/config/' },
40
42
  { text: '暗水印配置项', link: '/zh/config/blind' },
@@ -149,10 +149,10 @@ Enable listening for watermark dom changes.
149
149
 
150
150
  The watermark cannot be added repeatedly.
151
151
 
152
- ## parentElement
152
+ ## parent
153
153
 
154
- - **Type:** `HTMLElement`
155
- - **Default:** `document.body`
154
+ - **Type:** `Element | string`
155
+ - **Default:** `'body'`
156
156
 
157
157
  Watermarking container.
158
158
 
@@ -26,7 +26,7 @@ const textWatermark = new wm.Watermark({
26
26
  }
27
27
  });
28
28
  const handleAddTextWatermark = () => {
29
- if (isDark) {
29
+ if (isDark.value) {
30
30
  textWatermark.options.fontColor = '#fff'
31
31
  }
32
32
  textWatermark.create();
@@ -50,7 +50,7 @@ const multiLineTextWatermark = new wm.Watermark({
50
50
  }
51
51
  });
52
52
  const handleAddMultiLineTextWatermark = () => {
53
- if (isDark) {
53
+ if (isDark.value) {
54
54
  multiLineTextWatermark.options.fontColor = '#fff'
55
55
  }
56
56
  multiLineTextWatermark.create();
@@ -3,7 +3,7 @@ layout: doc
3
3
  ---
4
4
 
5
5
  # What is this?
6
- This is a canvas-based watermark for browser.
6
+ This is a *canvas-based* watermark for browser.
7
7
 
8
8
  ## Features
9
9
  - Create watermark and blind watermark
package/docs/index.md CHANGED
@@ -9,7 +9,7 @@ hero:
9
9
  text: Advanced watermark plugin
10
10
  tagline: Simple, powerful, and performant.
11
11
  image:
12
- src: /logo.png
12
+ src: /hero-image.png
13
13
  alt: watermark-js-plus
14
14
  actions:
15
15
  - theme: brand
Binary file
Binary file
@@ -1,14 +1,14 @@
1
1
  ---
2
2
  layout: doc
3
3
  ---
4
- # Blind Watermark Decode
4
+ # 解析暗水印
5
5
 
6
6
  ## url
7
7
 
8
8
  - **Type:** `string`
9
9
  - **Default:** `''`
10
10
 
11
- Decoding picture path.
11
+ 解码暗水印图片路径。
12
12
 
13
13
  ## mode
14
14
 
@@ -16,18 +16,18 @@ Decoding picture path.
16
16
  - **Default:** `'canvas'`
17
17
  - **available values**: `'canvas'`
18
18
 
19
- Mode of decoding.
19
+ 解码模式。
20
20
 
21
21
  ## fillColor
22
22
 
23
23
  - **Type:** `string`
24
24
  - **Default:** `'#000'`
25
25
 
26
- fill color.
26
+ 解码 fill color.
27
27
 
28
28
  ## compositeOperation
29
29
 
30
30
  - **Type:** `string`
31
31
  - **Default:** `'color-burn'`
32
32
 
33
- composite operation.
33
+ 解码 composite operation.
@@ -1,14 +1,14 @@
1
1
  ---
2
2
  layout: doc
3
3
  ---
4
- # Blind Watermark Config
4
+ # 暗水印
5
5
 
6
6
  ## globalAlpha
7
7
 
8
8
  - **Type:** `number`
9
9
  - **Default:** `0.005`
10
10
 
11
- Transparency of watermark.
11
+ 水印的透明度。
12
12
 
13
13
  ## mode
14
14
 
@@ -16,4 +16,4 @@ Transparency of watermark.
16
16
  - **Default:** `'blind'`
17
17
  - **available values**: `'default' | 'blind'`
18
18
 
19
- Watermark mode
19
+ 水印模式。
@@ -1,30 +1,30 @@
1
1
  ---
2
2
  layout: doc
3
3
  ---
4
- # Basic Config
4
+ # 基础配置项
5
5
 
6
6
  ## width
7
7
 
8
8
  - **Type:** `number`
9
9
  - **Default:** `300`
10
10
 
11
- A unit of width for a single watermark.
11
+ 单个水印的宽度。
12
12
 
13
13
  ## height
14
14
 
15
15
  - **Type:** `number`
16
16
  - **Default:** `300`
17
17
 
18
- A unit of height for a single watermark.
18
+ 单个水印的高度。
19
19
 
20
20
  ## rotate
21
21
 
22
22
  - **Type:** `number`
23
23
  - **Default:** `45`
24
24
 
25
- Watermark rotation Angle.
25
+ 水印旋转角度
26
26
 
27
- Rotate with the center of the text as the origin.
27
+ 以文本的中心为原点旋转。
28
28
 
29
29
  ## contentType
30
30
 
@@ -32,35 +32,35 @@ Rotate with the center of the text as the origin.
32
32
  - **Default:** `'text'`
33
33
  - **available values**: `'text' | 'image' | 'multi-line-text' | 'rich-text'`
34
34
 
35
- Type of watermark content.
35
+ 水印内容类型。
36
36
 
37
37
  ## content
38
38
 
39
39
  - **Type:** `string`
40
40
  - **Default:** `'hello watermark-js-plus'`
41
41
 
42
- Watermark content.
42
+ 水印内容。
43
43
 
44
44
  ## imageWidth
45
45
 
46
46
  - **Type:** `number`
47
47
  - **Default:** `0`
48
48
 
49
- Watermark image width.
49
+ 水印图像宽度。
50
50
 
51
51
  ## imageHeight
52
52
 
53
53
  - **Type:** `number`
54
54
  - **Default:** `0`
55
55
 
56
- Watermark image height.
56
+ 水印图像高度。
57
57
 
58
58
  ## lineHeight
59
59
 
60
60
  - **Type:** `number`
61
61
  - **Default:** `30`
62
62
 
63
- Watermark content line high.
63
+ 水印内容行高。
64
64
 
65
65
  ## zIndex
66
66
 
@@ -81,14 +81,14 @@ background-position
81
81
  - **Type:** `number`
82
82
  - **Default:** `20`
83
83
 
84
- The font size of the watermark content.
84
+ 水印内容的字体大小。
85
85
 
86
86
  ## fontFamily
87
87
 
88
88
  - **Type:** `string`
89
89
  - **Default:** `'sans-serif'`
90
90
 
91
- The font family of the watermark content.
91
+ 水印内容的字体。
92
92
 
93
93
  ## textAlign
94
94
 
@@ -96,7 +96,7 @@ The font family of the watermark content.
96
96
  - **Default:** `'center'`
97
97
  - **available values**: `'center' | 'left' | 'right'`
98
98
 
99
- Watermark content horizontal alignment.
99
+ 水印内容水平对齐方式。
100
100
 
101
101
  ## textBaseline
102
102
 
@@ -104,28 +104,28 @@ Watermark content horizontal alignment.
104
104
  - **Default:** `'middle'`
105
105
  - **available values**: `'top' | 'bottom' | 'middle'`
106
106
 
107
- Watermark content baseline.
107
+ 水印内容基准线。
108
108
 
109
109
  ## fontColor
110
110
 
111
111
  - **Type:** `string`
112
112
  - **Default:** `'#000'`
113
113
 
114
- Watermark content font color.
114
+ 水印内容字体颜色。
115
115
 
116
116
  ## globalAlpha
117
117
 
118
118
  - **Type:** `number`
119
119
  - **Default:** `0.5`
120
120
 
121
- Transparency of watermark.
121
+ 水印的透明度。
122
122
 
123
123
  ## fontWeight
124
124
 
125
125
  - **Type:** `string`
126
126
  - **Default:** `'normal'`
127
127
 
128
- Watermark content font weight.
128
+ 水印内容字体权重。
129
129
 
130
130
  ## mode
131
131
 
@@ -133,46 +133,46 @@ Watermark content font weight.
133
133
  - **Default:** `'default'`
134
134
  - **available values**: `'default' | 'blind'`
135
135
 
136
- Watermark mode
136
+ 水印模式。
137
137
 
138
138
  ## mutationObserve
139
139
 
140
140
  - **Type:** `boolean`
141
141
  - **Default:** `true`
142
142
 
143
- Enable listening for watermark dom changes.
143
+ 启用侦听水印dom更改。
144
144
 
145
145
  ## unique
146
146
 
147
147
  - **Type:** `boolean`
148
148
  - **Default:** `true`
149
149
 
150
- The watermark cannot be added repeatedly.
150
+ 不能重复添加水印。
151
151
 
152
- ## parentElement
152
+ ## parent
153
153
 
154
- - **Type:** `HTMLElement`
155
- - **Default:** `document.body`
154
+ - **Type:** `Element | string`
155
+ - **Default:** `'body'`
156
156
 
157
- Watermarking container.
157
+ 水印的容器。
158
158
 
159
159
  ## onSuccess
160
160
 
161
161
  - **Type:** `Function`
162
162
  - **Default:** `() => {}`
163
163
 
164
- Watermark added successful callback event.
164
+ 水印添加成功的回调事件。
165
165
 
166
166
  ## onBeforeDestroy
167
167
 
168
168
  - **Type:** `Function`
169
169
  - **Default:** `() => {}`
170
170
 
171
- Watermark delete before callback event.
171
+ 水印删除前的回调事件。
172
172
 
173
173
  ## onDestroyed
174
174
 
175
175
  - **Type:** `Function`
176
176
  - **Default:** `() => {}`
177
177
 
178
- Watermark deleted after callback event.
178
+ 水印删除后的回调事件。
@@ -26,7 +26,7 @@ const textWatermark = new wm.Watermark({
26
26
  }
27
27
  });
28
28
  const handleAddTextWatermark = () => {
29
- if (isDark) {
29
+ if (isDark.value) {
30
30
  textWatermark.options.fontColor = '#fff'
31
31
  }
32
32
  textWatermark.create();
@@ -50,7 +50,7 @@ const multiLineTextWatermark = new wm.Watermark({
50
50
  }
51
51
  });
52
52
  const handleAddMultiLineTextWatermark = () => {
53
- if (isDark) {
53
+ if (isDark.value) {
54
54
  multiLineTextWatermark.options.fontColor = '#fff'
55
55
  }
56
56
  multiLineTextWatermark.create();
package/docs/zh/index.md CHANGED
@@ -9,7 +9,7 @@ hero:
9
9
  text: 高级的水印插件
10
10
  tagline: 简易、强大、高性能。
11
11
  image:
12
- src: /logo.png
12
+ src: /hero-image.png
13
13
  alt: watermark-js-plus
14
14
  actions:
15
15
  - theme: brand
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "watermark-js-plus",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "watermark for the browser",
5
5
  "main": "lib/watermark.js",
6
6
  "type": "module",
package/src/blind.ts CHANGED
@@ -4,9 +4,9 @@ import { convertImage, isFunction } from './utils'
4
4
 
5
5
  export default class BlindWatermark extends Watermark {
6
6
  constructor (props: Partial<WatermarkOptions> = {}) {
7
+ props.globalAlpha = 0.005
8
+ props.mode = CreateWatermarkModeEnum.blind
7
9
  super(props)
8
- this.options.globalAlpha = 0.005
9
- this.options.mode = CreateWatermarkModeEnum.blind
10
10
  }
11
11
 
12
12
  static decode (props: Partial<DecodeBlindWatermark>) {
@@ -54,7 +54,7 @@ export interface WatermarkOptions {
54
54
  mode: CreateWatermarkModeEnum; // 模式 default | blind
55
55
  mutationObserve: boolean;
56
56
  unique: boolean;
57
- parentElement: HTMLElement;
57
+ parent: Element | string;
58
58
  onSuccess: Function;
59
59
  onBeforeDestroy: Function;
60
60
  onDestroyed: Function;
package/src/watermark.ts CHANGED
@@ -9,10 +9,11 @@ import {
9
9
  } from './types'
10
10
 
11
11
  export default class Watermark {
12
- options: WatermarkOptions
13
- observer?: MutationObserver
14
- parentObserve?: MutationObserver
15
- watermarkDom?: WatermarkDom
12
+ private readonly options: WatermarkOptions
13
+ private parentElement: Element = document.body
14
+ private observer?: MutationObserver
15
+ private parentObserve?: MutationObserver
16
+ private watermarkDom?: WatermarkDom
16
17
 
17
18
  constructor (props: Partial<WatermarkOptions> = {}) {
18
19
  this.options = Object.assign({
@@ -36,7 +37,7 @@ export default class Watermark {
36
37
  mode: CreateWatermarkModeEnum.default, // 模式 default | blind
37
38
  mutationObserve: true,
38
39
  unique: true,
39
- parentElement: document.body,
40
+ parent: 'body',
40
41
  onSuccess: () => {},
41
42
  onBeforeDestroy: () => {},
42
43
  onDestroyed: () => {}
@@ -44,6 +45,7 @@ export default class Watermark {
44
45
  if (this.options?.rotate) {
45
46
  this.options.rotate = (360 - this.options.rotate % 360) * (Math.PI / 180)
46
47
  }
48
+ this.changeParentElement(this.options.parent)
47
49
  }
48
50
 
49
51
  static createCanvas (width: number, height: number): HTMLCanvasElement {
@@ -57,6 +59,15 @@ export default class Watermark {
57
59
  return canvas
58
60
  }
59
61
 
62
+ changeParentElement (parent: Element | string) {
63
+ if (typeof parent === 'string') {
64
+ const parentElement = document.querySelector(parent)
65
+ parentElement && (this.parentElement = parentElement)
66
+ } else {
67
+ this.parentElement = parent
68
+ }
69
+ }
70
+
60
71
  async create () {
61
72
  if (!this.validateUnique()) {
62
73
  return
@@ -74,6 +85,7 @@ export default class Watermark {
74
85
  this.watermarkDom.__WATERMARK__INSTANCE__ = this
75
86
  this.watermarkDom.style.cssText = `
76
87
  z-index: ${this.options.zIndex};
88
+ position: relative;
77
89
  `
78
90
  watermarkInnerDom.style.cssText = `
79
91
  position: fixed;
@@ -90,7 +102,7 @@ export default class Watermark {
90
102
  -webkit-print-color-adjust: exact;
91
103
  `
92
104
  this.watermarkDom.append(watermarkInnerDom)
93
- this.options.parentElement.appendChild(this.watermarkDom)
105
+ this.parentElement.appendChild(this.watermarkDom)
94
106
 
95
107
  if (this.options.mutationObserve) {
96
108
  this.bindMutationObserve()
@@ -109,7 +121,7 @@ export default class Watermark {
109
121
  private validateUnique (): boolean {
110
122
  let result = true
111
123
  if (this.options.unique) {
112
- this.options.parentElement.childNodes.forEach(node => {
124
+ this.parentElement.childNodes.forEach(node => {
113
125
  if (!result) {
114
126
  return
115
127
  }
@@ -278,7 +290,7 @@ export default class Watermark {
278
290
  }
279
291
  })
280
292
  })
281
- this.parentObserve.observe(this.options.parentElement, {
293
+ this.parentObserve.observe(this.parentElement, {
282
294
  attributes: true, // 子节点的变动(指新增,删除或者更改)
283
295
  childList: true, // 属性的变动
284
296
  subtree: true, // 布尔值,表示是否将该观察器应用于该节点的所有后代节点。