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

canvasff

v0.1.1

Published

File format for creating JS canvases

Readme

Canvas File Format

A simple file format for storing canvas commands to later be generated. Supports most of the canvas API.

Installation

npm install canvasff

Usage

import applyCFF from "canvasff";
applyCFF(ctx, file, scale = 1);

Applies the file to the ctx, scaled by a factor of scale (a scale of 2 produces a image twice as wide and twice as tall).

Node.JS use

This requires polyfilling Path2D and CanvasRenderingContext2D.

// Get polyfills
import { createCanvas, CanvasRenderingContext2D } from "canvas";
import { Path2D, applyPath2DToCanvasRenderingContext } from "path2d";
// Apply polyfills
globalThis.Path2D = Path2D as any;
applyPath2DToCanvasRenderingContext(CanvasRenderingContext2D as any);
// Create a canvas context
const canvas = createCanvas(1000, 1000);
const ctx = canvas.getContext("2d");
// NOTE: The "reset" command is not polyfilled.
applyCFF(ctx as any, ...);

File format

This is the spec for the file format. Each line is in the format of command arg1 arg2..., and commands are seperated by line. Comments are denoted with //, and work similar to JS. Angles default to degrees, but can be changed with use rad or use turns (use deg resets to degrees). The text PI appearing next to a number (e.g. 12PI) will be converted to 12 * Pi.

Basic Commands

See MDN for more details on how the canvas uses these commands, most of them directly translate to a CanvasRenderingContext2D method. | Command | Arguments | Description | | :--- | :--- | :--- | height | point | Sets the canvas height. | | width | point | Sets the canvas width. | | fill | - | Fills the current path. | | stroke | - | Strokes the current path. | | fill style | text | Sets the style used when filling shapes (color, gradient, or pattern). | | stroke style | text | Sets the style used for strokes. | | stroke width | point | Sets the line width. | | line cap | text | Sets the appearance of the ends of lines (butt, round, square). | | line join | text | Sets the appearance of line corners (round, bevel, miter). | | miter limit | point | Sets the limit for miter joins. | | dash | pointArray | Sets the line dash pattern. | | dash offset | point | Sets the phase of the line dash pattern. | | begin path | - | Starts a new path. | | close path | - | Closes the current path. | | save | - | Saves the current state of the canvas. | | restore | - | Restores the most recently saved canvas state. | | reset | - | Resets the canvas context to its default state. | | clear | - | Clears the entire canvas. | | clear rect | point, point, point, point | Clears a rectangular section of the canvas. | | rect | point, point, point, point | Adds a rectangle to the current path. | | round rect | point, point, point, point, point | Adds a rounded rectangle to the current path. | | stroke rect | point, point, point, point | Paints a rectangle which has a starting point at (x, y) and has a w and h. | | fill rect | point, point, point, point | Fills a rectangle. | | ellipse | point, point, point, point, angle, angle, angle, boolean | Adds an elliptical arc to the current path. | | arc | point, point, point, angle, angle, boolean | Adds a circular arc to the current path. | | circle | point, point, point | Adds a circle to the current path. | | curve | point, point, point, point, point, point | Adds a cubic Bézier curve to the current path. | | quadratic | point, point, point, point | Adds a quadratic Bézier curve to the current path. | | line to | point, point | Connects the last point to the specified point. | | move to | point, point | Moves the starting point of a new sub-path. | | arc to | point, point, point, point, point | Adds a circular arc to the current path, using control points and radius. |

Text Commands

| Command | Arguments | Description | | :--- | :--- | :--- | fill text | text, point, point, point | Fills a given text at the given (x,y) position. | | stroke text | text, point, point, point | Strokes a given text at the given (x,y) position. | | text align | text | Sets the alignment for text. | | text baseline | text | Sets the baseline alignment for text. | | text direction | text | Sets the directionality of the text. | | font | textArray | Sets the font properties. | | font kerning | text | Sets the font kerning. Doesn't work in Safari. | | font stretch | text | Sets the font stretch. Doesn't work in Safari. | | font caps | text | Sets the font variant caps. Doesn't work in Safari. |

Other Commands

| Command | Arguments | Description | | :--- | :--- | :--- | reset transformations | - | Resets the current transformation matrix to the identity matrix. | | rotate | angle | Rotates the canvas context. | | scale | point, point | Scales the canvas units by x and y. | | transform | point, point, point, point, point, point | Multiplies the current transformation matrix. | | fill linear | point, point, point, point, textArray | Sets a linear gradient for filling. Each item in the textArray is a color stop spaced evenly (2 items -> stops at 0% and 100%, 3 items -> stops at 0%, 50%, and 100%) | | stroke linear | point, point, point, point, textArray | Sets a linear gradient for stroking. Each item in the textArray is a color stop spaced evenly (2 items -> stops at 0% and 100%, 3 items -> stops at 0%, 50%, and 100%) | | fill radial | point, point, point, textArray | Sets a radial gradient for filling. Each item in the textArray is a color stop spaced evenly (2 items -> stops at 0% and 100%, 3 items -> stops at 0%, 50%, and 100%) | | stroke radial | point, point, point, textArray | Sets a radial gradient for stroking. Each item in the textArray is a color stop spaced evenly (2 items -> stops at 0% and 100%, 3 items -> stops at 0%, 50%, and 100%) | | fill conic | point, point, point, textArray | Sets a conic gradient for filling. Each item in the textArray is a color stop spaced evenly (2 items -> stops at 0% and 100%, 3 items -> stops at 0%, 50%, and 100%) | | stroke conic | point, point, point, textArray | Sets a conic gradient for stroking. Each item in the textArray is a color stop spaced evenly (2 items -> stops at 0% and 100%, 3 items -> stops at 0%, 50%, and 100%) | | shadow blur | point | Sets the amount of blur for shadows. | | shadow color | text | Sets the color of shadows. | | shadow offset | point, point | Sets the distance that shadows will be offset. | | alpha | number | Sets the global alpha value. | | composite | text | Sets the global composite operation. | | filter | textArray | Sets the filter effects (e.g. blur). Not supported in Safari. |

Path Mode

Path mode is a special mode that creates a Path2D. This is opened with fill path {, stroke path {, clip path {, and multi path { (to both fill and stroke), and is closed with }. It only supports the following commands: | Command | Arguments | Description | | :--- | :--- | :--- | move to | point, point | Moves the starting point of a new sub-path. | | line to | point, point | Connects the last point to the specified point. | | arc to | point, point, point, point, point | Adds a circular arc to the current path, using control points and radius. | | arc | point, point, point, angle, angle, boolean | Adds a circular arc to the current path. | | circle | point, point, point | Adds a circle to the current path. | | curve | point, point, point, point, point, point | Adds a cubic Bézier curve to the current path. | | quadratic | point, point, point, point | Adds a quadratic Bézier curve to the current path. | | rect | point, point, point, point | Adds a rectangle to the current path. | | round rect | point, point, point, point, point | Adds a rounded rectangle to the current path. | | close | - | Closes the current path. |

Groups

Groups can be used to structure commands together and will revert to the previous styles after the group is closed. Groups are opened with group { and closed with }. Groups can be nested but this does not work perfectly.

fromSVG

Takes a document of an svg or just the svg as a string and returns a canvas file. Does not work well, but can provide a basis at least.

Contributing

Contributions are welcome! Please submit a pull request. The tests can be ran with npm run test and build into the tests/output folder.

License

This is licensed under the MIT license.