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

canvas-plus

v1.0.3

Published

Extend HTML5 Canvas with practical and high level methods that were missing

Downloads

10

Readme

canvas-plus

Extend HTML5 Canvas with practical and high level methods that were missing

## Install

npm install canvas-plus

Usage

canvas-plus can be used in two ways:

  1. Extending the prototype for the Canvas2DRenderingContext
  2. As a literal object of all the methods, where you can pass the context as the first argument

By default the documentation will assume the prototype was extended. Otherwise imagine all the method signatures with the context as the first argument. (E.g. rotateAt(ctx, …))

Example with extended prototype:

import 'canvas-plus';

var canvas = document.createElement('canvas');
canvas.width = 300;
canvas.height = 400;
var ctx = canvas.getContext('2d');

ctx.beginPath();
ctx.roundedRect(50, 50, 200, 300, 10);

ctx.lineWidth = 2;
ctx.strokeStyle = 'hsla(215, 100%, 50%, 0.7)';
ctx.stroke();

As an object:

import utilities from 'canvas-plus';

var canvas = document.createElement('canvas');
canvas.width = 300;
canvas.height = 400;
var ctx = canvas.getContext('2d');

ctx.beginPath();
utilities.roundedRect(ctx, 50, 50, 200, 300, 10);

ctx.lineWidth = 2;
ctx.strokeStyle = 'hsla(215, 100%, 50%, 0.7)';
ctx.stroke();

Documentation

### dashedLine (x0, y0, x1, y1, dash, gap)

* Start coordinates of line (x0, y0)

  • End coordinates of line (x1, y1)
  • Length of a solid dash (dash)
  • Length of gaps between dashes (gap)

Draws a dashed line, by using moveTo and lineTo to create small path segments in a straight line from A to B.

### roundedRect (x, y, w, h, r)

  • Position of top left edge (x, y)
  • Size of the rect (w, h)
  • Radius of the rounded corners (r)

Draws a rect with rounded corners using moveTo, lineTo and arcTo to create a path.

Keep in mind that no limits are in place on the radius, so you might get corrupt shapes by drawing corners larger than the size of the rect. I'd ideally like to have an implementation as similar as possible to border-radius; Feel free to create an issue with implementation notes or write a pull request if you can figure out how to get it close to the CSS spec :)

### rotateAt (x, y, a)

  • Axis position to rotate around (x, y)
  • Angle in radians for rotation (a)

Rotates around the given position like an axis on the canvas.

This, albeit simple, method makes rotating around arbitrary positions on the canvas a breeze.

## Requirements

  • canvas-plus expects ES6 modules syntax.
  • If your extending the prototype, then the Canvas2DRenderingContext is expected as a global
  • In general expects the Canvas2DRenderingContext interface to work on as a context