-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Mr.Hope <[email protected]>
- Loading branch information
1 parent
fca6b29
commit 969b03b
Showing
28 changed files
with
727 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# watermark | ||
|
||
<NpmBadge package="@vuepress/plugin-watermark" /> | ||
|
||
Integrate [watermark-js-plus](https://github.com/zhensherlock/watermark-js-plus) into VuePress。 | ||
|
||
This plugin can add watermark to the pages, you can choose between add watermark globally or on specific pages. You can also choose between add text watermark or image watermark. | ||
|
||
## Usage | ||
|
||
```sh | ||
npm i -D @vuepress/plugin-watermark@next | ||
``` | ||
|
||
```ts | ||
import { watermarkPlugin } from '@vuepress/plugin-watermark' | ||
|
||
export default { | ||
plugins: [ | ||
watermarkPlugin({ | ||
// options | ||
}), | ||
], | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
### enabled | ||
|
||
- Type: `boolean | ((page: Page) => boolean)` | ||
|
||
- Default: `false` | ||
|
||
- Details: | ||
|
||
Specify which pages need to have watermarks added. | ||
|
||
Pages with `true` value will have watermarks added. | ||
|
||
### watermarkOptions | ||
|
||
- Type: `WatermarkOptions` | ||
|
||
- Default: `undefined` | ||
|
||
- Details: Please refer to the [watermark-js-plus](https://zhensherlock.github.io/watermark-js-plus/zh/config/) configuration options. | ||
|
||
#### watermarkOptions.parent | ||
|
||
- Type: `string` | ||
|
||
- Default: `body` | ||
|
||
- Details: Parent element selector for adding watermark. | ||
|
||
By default, it is inserted into the body, but you can specify inserting it into a specific element on the page. | ||
|
||
### delay | ||
|
||
- Type: `number` | ||
|
||
- Default: `500` | ||
|
||
- Details: Delay for adding watermarks. In milliseconds. | ||
|
||
This delay will only take effect when adding watermarks to a specific element on the page. | ||
|
||
A delay is required when the watermark parent is rerendered when switching pages. | ||
|
||
## Frontmatter | ||
|
||
### watermark | ||
|
||
- Type: `boolean | WatermarkOptions` | ||
|
||
- Details: | ||
|
||
When the type is `boolean`, it indicates whether the watermark is enabled. | ||
|
||
When the type is `WatermarkOptions`, it represents the current page's watermark configuration. | ||
|
||
You can refer to [watermark-js-plus](https://zhensherlock.github.io/watermark-js-plus/zh/config/). | ||
|
||
```md | ||
--- | ||
watermark: | ||
width: 200 | ||
height: 200 | ||
content: Your content | ||
opacity: 0.5 | ||
--- | ||
``` | ||
|
||
## Client Config | ||
|
||
### defineWatermarkConfig(config) | ||
|
||
- Type: `(config: MaybeRefOrGetter<WatermarkOptions>) => void` | ||
|
||
Additional configuration passed to [watermark-js-plus](https://zhensherlock.github.io/watermark-js-plus/en/config/). | ||
|
||
```ts | ||
import { defineWatermarkConfig } from '@vuepress/plugin-watermark/client' | ||
|
||
defineWatermarkConfig({ | ||
// Set up additional watermark configurations here. | ||
}) | ||
``` | ||
|
||
In most cases, the majority of options should be defined in Node, | ||
but there are some special situations. For example, | ||
it may be necessary to control different watermark opacities, font colors, | ||
etc., in **dark/light mode** , or to pass in callbacks such as `onSuccess`, `extraDrawFunc`, and so on. | ||
|
||
```ts | ||
import { computed } from 'vue' | ||
|
||
export default defineClientConfig({ | ||
setup() { | ||
const isDark = useDarkMode() | ||
|
||
const watermarkConfig = computed(() => ({ | ||
fontColor: isDark.value ? '#fff' : '#000', | ||
onSuccess: () => { | ||
console.log('success') | ||
}, | ||
})) | ||
|
||
defineWatermarkConfig(watermarkConfig) | ||
}, | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# watermark | ||
|
||
<NpmBadge package="@vuepress/plugin-watermark" /> | ||
|
||
将 [watermark-js-plus](https://github.com/zhensherlock/watermark-js-plus) 到 VuePress 中。 | ||
|
||
此插件可在在页面中添加水印,可以选择为 全局页面 或 部分页面添加水印,还可以选择添加 文字水印 或 图片水印。 | ||
|
||
## 使用 | ||
|
||
```sh | ||
npm i -D @vuepress/plugin-watermark@next | ||
``` | ||
|
||
```ts | ||
import { watermarkPlugin } from '@vuepress/plugin-watermark' | ||
|
||
export default { | ||
plugins: [ | ||
watermarkPlugin({ | ||
// options | ||
}), | ||
], | ||
} | ||
``` | ||
|
||
## 配置项 | ||
|
||
### enabled | ||
|
||
- 类型: `boolean | ((page: Page) => boolean)` | ||
|
||
- 默认值: `false` | ||
|
||
- 详情: | ||
|
||
指定哪些页面需要添加水印。 | ||
|
||
拥有 `true` 值的页面将会被添加水印。 | ||
|
||
### watermarkOptions | ||
|
||
- 类型: `WatermarkOptions` | ||
|
||
- 默认值: `undefined` | ||
|
||
- 详情: 配置项请参考 [watermark-js-plus](https://zhensherlock.github.io/watermark-js-plus/zh/config/)。 | ||
|
||
#### watermarkOptions.parent | ||
|
||
- 类型: `string` | ||
|
||
- 默认值: `body` | ||
|
||
- 详情:添加水印的父元素选择器。 | ||
|
||
默认插入到 body 中,可以指定插入到页面的某个元素中。 | ||
|
||
### delay | ||
|
||
- 类型: `number` | ||
|
||
- 默认值: `500` | ||
|
||
- 详情:添加水印的延时。以毫秒为单位。 | ||
|
||
该延迟仅会在添加水印到页面某个元素时生效。 | ||
|
||
如果水印的父元素在切换页面时被重新渲染,那么需要延迟一段时间才能重新添加水印。 | ||
|
||
## Frontmatter | ||
|
||
### watermark | ||
|
||
- 类型: `boolean | WatermarkOptions` | ||
|
||
- 详情: | ||
|
||
当类型为 `boolean` 时,表示是否启用水印。 | ||
|
||
当类型为 `WatermarkOptions` 时,表示当前页面水印配置。 | ||
|
||
可以参考 [watermark-js-plus](https://zhensherlock.github.io/watermark-js-plus/zh/config/) 。 | ||
|
||
```md | ||
--- | ||
watermark: | ||
width: 200 | ||
height: 200 | ||
content: Your content | ||
opacity: 0.5 | ||
--- | ||
``` | ||
|
||
## 客户端配置 | ||
|
||
### defineWatermarkConfig(config) | ||
|
||
- 类型: `(config: MaybeRefOrGetter<WatermarkOptions>) => void` | ||
|
||
传递给 [watermark-js-plus](https://zhensherlock.github.io/watermark-js-plus/zh/config/) 的额外配置。 | ||
|
||
```ts | ||
import { defineWatermarkConfig } from '@vuepress/plugin-watermark/client' | ||
|
||
defineWatermarkConfig({ | ||
// 在此设置额外的 watermark 配置 | ||
}) | ||
``` | ||
|
||
通常来说,大部分选项应该在 Node 中定义,但存在一些特殊情况。 | ||
比如需要在 **深色/浅色 模式** 下控制不同的 水印 透明度、字体颜色等, | ||
或者需要传入如 `onSuccess`、`extraDrawFunc` 等回调函数。 | ||
|
||
```ts | ||
import { computed } from 'vue' | ||
|
||
export default defineClientConfig({ | ||
setup() { | ||
const isDark = useDarkMode() | ||
|
||
const watermarkConfig = computed(() => ({ | ||
fontColor: isDark.value ? '#fff' : '#000', | ||
onSuccess: () => { | ||
console.log('success') | ||
}, | ||
})) | ||
|
||
defineWatermarkConfig(watermarkConfig) | ||
}, | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
watermark: true | ||
--- | ||
|
||
# Default Watermark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
watermark: false | ||
--- | ||
|
||
# disabled watermark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { expect, test } from '@playwright/test' | ||
|
||
test.describe('plugin-watermark', () => { | ||
test('enabled watermark', async ({ page }) => { | ||
await page.goto('watermark/') | ||
|
||
expect( | ||
await page.locator('//html/body/div[2]').getAttribute('style'), | ||
).toContain('z-index: 2147483647 !important;') | ||
|
||
expect( | ||
await page.locator('//html/body/div[2]/div').getAttribute('style'), | ||
).toContain('background-image: url("data:image/png;base64,') | ||
}) | ||
|
||
test('disabled watermark', async ({ page }) => { | ||
await page.goto('watermark/disabled.html') | ||
|
||
await expect(page.locator('//html/body/div[2]')).not.toBeVisible() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. |
Oops, something went wrong.