npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tinyfe/watermark

v0.0.12

Published

use canvas generate the watermark

Downloads

7

Readme

@tinyfe/watermark

水印 APIs, 支持自动生成。外部传入水印,并实时监听补全被删除的水印。

Usage

基础用法(so easy)

import WaterMark from '@tinyfe/watermark';

new WaterMark({
  container: document.querySelector('.watermark'),
  text: '法网恢恢疏而不漏,POI',
});

进阶用法

new WaterMark({
  container: document.querySelector('.watermark'),
  text: '法网恢恢疏而不漏,POI',
  fontType: 'Microsoft YaHei',
  color: 'red',
  fontSize: 24,
  alpha: 0.2,
  image: '',
  repeat: true,
  style: {
    width: 1000,
    height: 800,
    top: '30px',
  },
});

new WaterMark({
  monitor: false,
  container: document.querySelector('.watermark1'),
  text: '还在想抄袭,搞屁哦',
  fontSize: 24,
  color: 'red',
  alpha: 0.5,
  image: '',
  repeat: true,
  style: {
    width: 1000,
    height: 800,
    top: '30px',
  },
});
new WaterMark({
  monitor: false,
  image: 'https://avatars.githubusercontent.com/u/20939839?v=4',
  container: document.querySelector('.watermark2'),
  fontSize: 24,
  color: 'red',
  alpha: 0.5,
  style: {
    width: 1000,
    height: 800,
    top: '30px',
  },
});

参数

Options

| Key | 类型 | 默认值 | 描述 | | ------------------------- | ------------------------- | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | container(必选参数) | string | HTMLElement | null | 挂载节点。 注意, 传入值为 string 时, 为了保证唯一性, 默认是以 id 的方式传入 | | monitor | boolean | true | monitor 是否监控, true: 不可删除水印; false: 可删水印 | | observer | MutationCallback | | MutationObserver Callback | | observerOptions | object | ObserverOptions | MutationObserver Options | | encoderOptions | number | 0.92 | 在指定图片格式为 image/jpegimage/webp的情况下可以从 01 的区间内选择图片的质量。如果超出取值范围, 将会使用默认值 0.92。其他参数会被忽略。 | | style | object | {} | 初始化 canvas 样式 |

水印配置

| Key | 类型 | 默认值 | 描述 | | -------------------- | --------- | ----------------- | ---------------------------------- | | prefix | string | '' | 水印前缀,只在 text 模式下使用 | | text(必选参数) | string | '' | 当 image为空值时使用 text 模式 | | font | string | Microsoft YaHei | 字体相关样式 | | fontSize | number | 24 | | | image | string | '' | 水印图片 | | color | string | #848FA7 | 水印颜色 | | alpha | number | 0.2 | 水印透明度 | | rotate | number | 340 | deg,水印旋转角度, | | scale | number | 1 | 缩放 | | repeat | boolean | true | 水印是够在xy 轴上重复 | | rows | number | 5 | 重复行数 | | cols | number | 5 | 重复列数 | | startX | number | 20 | px, 重复水印x轴起点 | | startY | number | 20 | px, 重复水印y轴起点 | | xGap | number | 200 | px, 重复水印x轴偏移 | | yGap | number | 100 | px, 重复水印y轴偏移 |

ObserverOptions

| Key | 类型 | 默认值 | 描述 | | ----------------------- | ----------------------- | ----------- | ----------------------------------------------------------------------------------------------------------- | | childList | boolean | true | 观察目标子节点的变化, 是否有添加或者删除 | | attributes | boolean | true | 观察属性变动 | | subtree | boolean | true | 观察后代节点 | | attributeFilter | string[], undefined | ['style'] | 特性名称数组, 只观察选定的特性 | | characterData | boolean | | 是否观察 node.data(文本内容) | | attributeOldValue | boolean | | 如果为 true, 则将特性的旧值和新值都传递给回调(参见下文), 否则只传新值(需要 attributes 选项) | | characterDataOldValue | boolean | | 如果为 true, 则将 node.data 的旧值和新值都传递给回调(参见下文), 否则只传新值(需要 characterData 选项) |

APIs 设计

自动水印实现

通过创建 canvas 绘制水印, 并转换成 base64, 然后添加到外部传入的 dom 上, 并通过 MutationObserver 提供监视用户对 DOM 树所做更改的能力来自动补全删除的水印。(Note: MutationObserver 兼容性)

外部水印

通过外部传入的 image 来实现自动补全删除的水印。