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 🙏

© 2025 – Pkg Stats / Ryan Hefner

canvasbox

v1.0.8

Published

A lightweight JavaScript library for drawing on HTML5 Canvas with intuitive APIs and interactive features.

Readme

Canvas Drawing Library

A lightweight JavaScript library for drawing on HTML5 Canvas with intuitive APIs and interactive features.

Quickly draw basic shapes, create animations, electronic seals, and canvas functions based on Canvas.

Support ESM, CJS, and IIFE.

If you find it useful, please give me stars. I really hope to receive your suggestions or join in to make CanvasJS more compliant and user-friendly.

Online demo: https://ghchenjingqi.github.io/CanvasJS/

NPM address: https://www.npmjs.com/package/canvasbox

Git address:https://github.com/GHchenjingqi/CanvasJS

Features

  • 🎨 Draw various shapes (lines, rectangles, circles, triangles, text, images, Bezier curves)
  • 📏 Customizable coordinate system with Y-axis inversion support
  • 🖱 Interactive elements with click event handling
  • ✏️ Freehand drawing mode
  • 🖼 Image rendering with rotation and anchor point control
  • 📊 Grid drawing for visual reference
  • 💾 Export canvas as image (PNG/JPEG) with download functionality
  • 🔄 Responsive design that adapts to window resizing

Installation

NPM

# https://www.npmjs.com/package/canvasbox
npm install canvasbox

Basic Usage

Initialization

const canvas = new Canvas('#my-canvas', (canvas, ctx) => {
  // Your drawing code here
});

// Or with options
const canvas = new Canvas('#my-canvas', {
  // Optional configuration
});
canvas.render()

If you are using Vue or React, please ensure that the canvas tag element exists, otherwise the page will display 2 canvases.

import Canvas from 'canvasbox'
import { onMounted } from 'vue';

onMounted(() => {
  const canvas = new Canvas("#canvas")
  canvas.drawingBoard({
    lineWidth: 3,
    color: 'red'
  });
})

Coordinate System

// Center the coordinate system (Y-axis points up)
canvas.center({ yUp: true });

// Custom origin point (50px from left, 30% from top)
canvas.center({ origin: [50, '30%'] });

Drawing Methods

Lines

canvas.line({
  type: 'dash',       // 'solid' or 'dash'
  a: [10, 10],        // Start point
  b: [100, 100],      // End point
  color: 'red',       // Color
  line: 2,            // Line width
  dash: [5, 3]        // Dash pattern
});

Rects

canvas.rect({
  type: 'stroke',     // 'fill', 'stroke', or 'dash'
  position: [50, 50], // Top-left corner
  size: [100, 80],    // Width and height
  color: 'blue',
  line: 1,
  onClick: () => console.log('Rectangle clicked!')
});

Triangles

canvas.triangle({
  points: [[10, 10], [100, 10], [50, 100]],
  color: 'red',
  type: 'fill',
  onClick: function () {
    console.log('点击了三角形');
  }
});

Circles/Arcs

canvas.arc({
  type: 'fill',
  center: [150, 150],
  radius: 40,
  startAngle: 0,
  endAngle: Math.PI * 1.5,
  color: 'green'
});

Text

canvas.text({
  position: [100, 100],
  text: 'Hello World',
  color: 'black',
  fontSize: 24,
  fontFamily: 'Arial',
  align: 'center',
  baseline: 'middle'
});

Images

canvas.image({
  src: 'path/to/image.png',
  position: [200, 200],
  size: [100, 100],   // Optional scaling
  rotation: Math.PI/4, // 45 degrees
  anchor: [0.5, 0.5]  // Center anchor
});

Freehand Drawing

// Enable drawing mode
canvas.drawingBoard({
  lineWidth: 3,
  color: '#000000'
});

Advanced Features

Event Handling

// Add clickable shape
canvas.rect({
  position: [50, 50],
  size: [100, 100],
  onClick: () => alert('Rectangle clicked!')
});

Exporting Canvas

// Save as PNG
canvas.save({
  type: 'png',
  filename: 'my-drawing.png'
});

// Get as data URL
const dataURL = canvas.toDataURL('image/jpeg', 0.8);

Grid Display

canvas.drawGrid();

Examples

Check out the examples folder for complete usage examples.

Apis

  • clear() —— Used for cleaning canvas
  • center() —— Used to change the origin point
  • render() —— Used for rendering canvas
  • line() —— Used for drawing lines
  • rect() —— Used for drawing rectangles
  • triangle() —— Used for drawing triangles
  • arc() —— Used for drawing arc
  • text() —— Used for drawing text
  • bezier() —— Used for drawing bezier
  • image() —— Used for drawing image
  • drawingBoard() —— Used to create a drawing board
  • drawTextAlongArc() —— Used to create curved wrap around text
  • drawGrid() —— Used to create a drawing grid
  • drawStar() —— Used to create a drawing star
  • toDataURL() —— Convert canvas content into a data URL
  • toBlob() —— Convert canvas content to blob data
  • save() —— Save PNG and download

Keywords

Canvasbox , CanvasJS, Electronic seals