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 🙏

© 2026 – Pkg Stats / Ryan Hefner

dolphin-watermark

v1.0.0

Published

A tool script about watermark

Readme

海豚水印接入文档

核心代码

图片合成模块watermark.js

// 获取字符串长度
const getTxtwidth = (str) => {
  // 创建一个画布
  const canStr = document.createElement('canvas')
  // 设置画布的长宽
  canStr.width = 500
  canStr.height = 300
  const canStrs = canStr.getContext('2d')
  canStrs.font = 'lighter 15px PingFangSC'
  return canStrs.measureText(str).width
}
// 合成背景图
const setWatermark = (str, roatev, xPadding, yPadding) => {
    // 参数说明 str为水印字符串,roatev为旋转角度,xPadding为横向间距,yPadding为纵向
  const txtWidth = getTxtwidth(str)
  const can = document.createElement('canvas')
  // 设置画布的长宽
  can.width = txtWidth * Math.cos(roatev * Math.PI / 180) + xPadding
  can.height = txtWidth * Math.sin(roatev * Math.PI / 180) + yPadding
  const cans = can.getContext('2d')
  // 旋转角度
  cans.rotate(-roatev * Math.PI / 180)
  cans.font = 'lighter 15px PingFangSC'
  // 设置填充绘画的颜色、渐变或者模式
  cans.fillStyle = 'rgba(220, 223, 230, 0.5)'
  // 设置文本内容的当前对齐方式
  cans.textAlign = 'left'
  // 设置在绘制文本时使用的当前文本基线
  cans.textBaseline = 'Middle'
  // 在画布上绘制填色的文本(输出的文本,开始绘制文本的X坐标位置,开始绘制文本的Y坐标位置)
  cans.fillText(str, 0, can.height)
  return 'url(' + can.toDataURL('image/png') + ') left top repeat'
}
export default setWatermark

使用方法:

(1)安装模块

npm install dolphin-watermark --save

(2)在登录入口引入setWatermark模块并调用

import setWatermark from 'dolphin-watermark'

例如:此处在登录成功之后调用合成模块并将图片存入浏览器缓存中

和UI沟通如下默认参数,后续有需要可以根据需求调整

{
  roatev: 15,
  xPadding: 100,
  yPadding: 100
}

image.png

(3)在需要水印的组件外层设置动态背景属性并修改内容背景色为透明

例如:在vue中使用实现如下效果image.png

data(){
    return {
        waterMark: {
        background: localStorage.getItem('watermark')
      } 
  }
}
<el-table :style="waterMark"></el-table>
<style>
.el-table tr {
  background: transparent;
}
</style>
// 部分组件可以修改组件库全局样式覆盖。例如elment-ui table组件可以直接修改覆盖样式文件统一修改