0.1.0 β€’ Published 9 months ago

watermark-lite v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

github stars npm version npm downloads bundle JSDocs License

Xiaohe / github@xiaohe0601 / gitee@xiaohe0601

πŸŽ‰ Features

  • πŸͺΆ Lightweight and easy-to-use API design

  • πŸ–ŒοΈ Rich customization options

  • πŸ” Monitors DOM behavior and automatically rebuilds the watermark

  • πŸ§€ Full support for TypeScript

  • πŸ‘Œ No framework restrictions

🚁 Installation

PNPM

pnpm add watermark-lite

YARN

yarn add watermark-lite

NPM

npm install watermark-lite

πŸ›Ή Usage

Basic Usage

import { Watermark } from "watermark-lite";

const wm = new Watermark();

// Display the watermark
wm.mount({
  text: "watermark text"
});

// To modify the watermark text or style, just call the `mount` method again
wm.mount({
  text: "modified watermark text"
});

// Remove the watermark
wm.unmount();

Default Instance

Since version 0.0.7, you can directly use the exported default instance

import { watermark } from "watermark-lite";

watermark.mount({
  text: "watermark text"
});

You can also use the alias wm for watermark

import { wm } from "watermark-lite";

wm.mount({
  text: "watermark text"
});

Custom Watermark Style

wm.mount({
  text: "watermark text",
  fontSize: "14px",
  fontFamily: "inherit",
  color: "#000000",
  opacity: 0.15,
  rotate: 15
});

Custom Watermark Parent Element

By default, the watermark is mounted under document.body. You can change the parent element using the parentEl parameter, which supports passing in an element id or HTMLElement

wm.mount({
  text: "watermark text",
  parentEl: "app"
});

About Single-Page Applications

For single-page applications, make sure to call the unmount method at the appropriate time to avoid repeated listeners and potential memory leaks

// The following is an example using Vue3, but the plugin itself is not limited to any framework

import { onBeforeUnmount, onMounted } from "vue";
import { Watermark } from "watermark-lite";

const wm = new Watermark();

onMounted(() => {
  wm.mount({
    text: "watermark text"
  });
});

onBeforeUnmount(() => {
  wm.unmount();
});

Configuration Options

ParameterDescriptionTypeDefault
elwatermark element idstringwatermark
textwatermark textstringdefault watermark
xwatermark starting x-coordinate (px)number0
ywatermark starting y-coordinate (px)number0
rowsnumber of watermark rowsnumberauto-calculated
colsnumber of watermark columnsnumberauto-calculated
xGapwatermark x-axis spacing (px)number50
yGapwatermark y-axis spacing (px)number50
zIndexz-index of the watermarknumber / string99999
itemIdPrefixprefix for watermark item idsstringwatermark-item
itemWidthwidth of the watermark item (px)number100
itemHeightheight of the watermark item (px)number100
fontSizewatermark font sizestring14px
fontFamilywatermark fontstringinherit
colorwatermark text colorstring#000000
opacitywatermark opacity (range: 0 ~ 1)number0.15
rotate 0.1.0watermark rotate (range: 0 ~ 360)number15
parentElparent element for watermarkstring / HTMLElementdocument.body
monitormonitor watermark changes and automatically rebuildbooleantrue
angle 0.1.0 removedwatermark rotate (range: 0 ~ 360) (removed in 0.1.0, use rotate instead)number15

Type Definitions

See jsdocs.io

🐢 Discussion & Communication

  • β“οΌšFor questions or bug feedback, you can submit an issues and PRs are welcome~
  • πŸ“«οΌšxiaohe0601@outlook.com
  • 🐧:Not yet available

πŸ† License

0.1.0

9 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago