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

@canvas-components/qrcode

v0.1.5

Published

Canvas QR code drawing and export utilities.

Readme

@canvas-components/qrcode

@canvas-components/qrcode 是一个纯原生的 Canvas 二维码绘制与导出工具包,适合卡片、海报、票据、表格单元格和导出场景。

功能作用

  • 支持二维码矩阵编码和缓存读取
  • 支持直接绘制到 Canvas
  • 支持导出为 SVG、Data URL、Blob
  • 支持容错等级、配色、静区、透明度配置

安装方法

pnpm add @canvas-components/qrcode

最低环境要求:

  • Node.js >= 18.12.0
  • pnpm >= 9.0.0

使用方法

import {
  drawQrCodeToCanvas,
  getQrCodeMatrix,
} from "@canvas-components/qrcode";

const canvas = document.querySelector("canvas")!;
const ctx = canvas.getContext("2d")!;

drawQrCodeToCanvas({
  ctx,
  x: 0,
  y: 0,
  width: 160,
  height: 160,
  value: "https://example.com",
  level: "M",
});

const matrix = getQrCodeMatrix("https://example.com", "M");

属性说明

DrawQrCodeToCanvasOptions

| 属性 | 类型 | 说明 | | --- | --- | --- | | ctx | CanvasRenderingContext2D \| OffscreenCanvasRenderingContext2D | 目标画布上下文 | | x / y | number | 绘制起点 | | width / height | number | 绘制区域尺寸,内部按较短边生成二维码主体 | | value | string | 编码内容 | | level | "L" \| "M" \| "Q" \| "H" | 容错等级 | | color | string | 深色模块颜色 | | backgroundColor | string | 背景色 | | padding | number | 静区大小 | | opacity | number | 透明度 |

QrCodeMatrix

| 属性 | 类型 | 说明 | | --- | --- | --- | | version | number | 二维码版本号 | | size | number | 矩阵边长 | | modules | boolean[][] | 最终深浅模块矩阵 |

ExportQrCodeToImageOptions

| 属性 | 类型 | 说明 | | --- | --- | --- | | pixelRatio | number | 位图导出倍率 | | type | "image/png" \| "image/jpeg" \| "image/webp" | 导出类型 | | quality | number | 图片质量 | | canvas | ExportCanvasLike | 可复用外部 canvas |

方法说明

| 方法 | 签名 | 说明 | | --- | --- | --- | | encodeQrCodeMatrix | (value, level?) => QrCodeMatrix | 重新编码并返回新矩阵 | | getQrCodeMatrix | (value, level?) => QrCodeMatrix | 带缓存读取矩阵,适合重复使用 | | drawQrCodeToCanvas | (options) => void | 直接绘制到 canvas | | exportQrCodeToSvg | (options) => string | 导出 SVG 字符串 | | exportQrCodeToDataUrl | (options) => Promise<string> | 导出图片 Data URL | | exportQrCodeToBlob | (options) => Promise<Blob> | 导出图片 Blob |

适用场景

  • 海报、卡片、名片二维码
  • 表格中的二维码单元格
  • 前端离屏生成下载素材
  • 票据、设备标识和面板角标