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

simple-canvas-drawer

v1.0.1

Published

- `npm install simple-canvas-drawer` or - `yarn add simple-canvas-drawer`

Readme

Simple Canvas Drawer, easier for front-end to create posters/images

Install

  • npm install simple-canvas-drawer or
  • yarn add simple-canvas-drawer

Usage

import CanvasDrawer from 'simple-canvas-drawer';

const drawer = new CanvasDrawer({ width: 400, height: 650 });
drawer
  .draw([
    {
      type: 'block',
      width: 400,
      height: 650,
      top: 0,
      left: 0,
      backgroundColor: '#ccc',
    },
    {
      type: 'img',
      width: 375,
      src: 'https://i.postimg.cc/yWsBgkkg/Comfy-UI-temp-mlyka-00004.png',
      bottom: 0,
      left: 0,
    },
    {
      type: 'text',
      text: 'Simple Canvas-Drawer is a simple canvas library for drawing posters',
      top: 20,
      left: 30,
      maxWidth: 360,
    },
  ])
  .then(() => {
    console.log(drawer.dataURL);
  });

API

CanvasDrawer

  • constructor()
    • args: config: Config
    • return: CanvasDrawer
    • the constructor method of CanvasDrawer. For detailed structure of the config parameter, please refer to the related Config explanation below
  • draw()
    • args: drawItems: Array<ItemConfig>
    • return: Promise<CanvasDrawer>
    • the drawing method, accepts an array as a parameter, where each element of the array represents a shape to be drawn. It returns a Promise. For the detailed structure of the array elements, please refer to the ItemConfig explanation below
  • dataURL:the base64 URL obtained after calling the toDataURL() method on the canvas element
  • getTempFilePath()
    • args: component: any
    • return: Promise<string>
    • generates a temporary file path for the canvas drawing image, available only in the WeChat mini-program environment. The input parameter component refers to the wx.canvasToTempFilePath() method in the WeChat mini-program.

Config

The parameter structure for the CanvasDrawer constructor:

interface Config {
  canvas?: HTMLCanvasElement; // the canvas element required for drawing. Required in the WeChat mini-program environment; in the web environment, it can be omitted, as Simple Canvas Drawer will automatically create one
  width?: number; // width of canvas, required when canvas is omitted
  height?: number; // height of canvas, same as width
}

ItemConfig

The element structure for the array parameter of CanvasDrawer.draw(), can be of the following types:

  • BlockConfig: Rectangular color block
    interface BlockConfig {
      type: 'block';
      width: number;
      height: number;
      backgroundColor?: string;
      gradientBackground?:
        | Array<string>
        | {
            direction: 'horizontal' | 'vertical';
            colors: Array<string>;
          }; // gradient background. when passing a color string array, direction will be defaultly set vertical
      top?: number; // top,left,right,bottom,are the positioning relative to the canvas, one of 'left' or 'right' must be included, same as 'top' and 'bottom'
      left?: number;
      right?: number;
      bottom?: number;
      border?: string; // border style, with the format similar to the CSS border property, supports two types of line styles: dashed and solid
      borderRadius?: number; // borderRadius
    }
    • About the border and size:
      • width and height includes the border;
      • if backgroundColor and border are both set, half of the border will be covered by the background color.
  • TextConfig: Text block
    interface TextConfig {
      type: 'text';
      text: string; // text content
      fontSize?: number; // default set 24
      fontWeight?: number | string;
      lineHeight?: number;
      color?: string;
      font?: string; // same format with CanvasRenderingContext2D.font, will cover fontSize and fontWeight
      top?: number; // same with BlockConfig
      left?: number;
      right?: number;
      bottom?: number;
      textAlign?: 'left' | 'right' | 'center' | 'start' | 'end';
      maxWidth?: number; // max width of text,if set, text will wrap automatically
    }
  • ImgConfig: image block
    interface ImgConfig {
      type: 'img';
      src?: string;
      image?: HTMLImageElement; // image element, will cover src
      width?: number; // image width, if height is not set, image will keep aspect ratio
      height?: number; // image height, if width is not set, image will keep aspect ratio
      top?: number;
      left?: number;
      right?: number;
      bottom?: number;
      borderRadius?: number;
    }
  • CustomConfig
    interface CustomConfig {
      type: 'custom';
      render: (ctx: CanvasRenderingContext2D) => void | Promise<void>;
      // custom render method
    }