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

canvaskitgame

v0.1.1

Published

Simple wrapper for html canvas with animation and event support

Downloads

20

Readme

CanvasKit

CanvasKit is a light weight HTML Canvas wrapper which provides an simple interface to create complex graphics and dynamic scenes

Installation

To use in your project run

npm install canvaskitgame

Features

CanvasKit

CanvasKit provides a simple API to interact with the canvas and draw shapes, images and lines. Drawable entities include:

  • Lines, Circles, Arcs, Rectangles, Images and Text

Example

const ck = new CanvasKit("canvasID", 500, 500)
ck.rectangle(250,250, 50,50, true, new Color(200,100,200), 1, 45)

CanvasKitGame

CanvasKitGame extends canvasKit providing more functionality. Instead of drawing shapes straight to the canvas you can now register shapes and draw all shapes with the drawFrame function. This allows you to set up a game loop and easily manipulate shape data to create a more dynamic scene. Features include:

  • Animations with easing
  • Events (onClick, OnHoverEnter and OnHoverExit)
  • Z-index render order
  • Tag system
  • Keyboard Inputs And Events
  • Particle System

Example

const ckg = new CanvasKitGame(new CanvasKit("canvas", 500, 500))

const r1 = ckg.newRectangleData("r1", 0, 200)
r1.addAnimation(new Animation([0, 1, 0], [440, 1.3, 360], ["x", "scale", "rotation"], "easeOut", 1, true))

function loop(){
  ckg.drawFrame()
  requestAnimationFrame(loop)
}
loop() 

Usage

CanvasKit

To create a simple scene in CanvasKit

  1. Create a new html canvas and give it an id
  2. Create a new instance of CanvasKit passing in the canvas id, width and height
const ck = new CanvasKit("canvasID", 500, 500)
  1. Create a new rectangle by calling the rectangle method which takes in: x-pos, y-pos, width, height, fill, color, borderWidth, rotationAngle and scale
ck.rectangle(100, 100, 40, 40, true, new Color(0,0,0), 1, 45, 1)

CanvasKitGame-Animation Example

To create a circle that depresses when you click on it and springs back we need to:

  1. Create a new CanvasKitGame instance which takes in a CanvasKit instance
const ckg = new CanvasKitGame(new CanvasKit("canvas", 500, 500))
  1. Next we need to create a new circle shape by calling the function newCircleData which takes in: a tag for your new shape, x-pos, y-pos and radius, note there are more optional parameters. newCircleData will then return a new CircleData instance
const r1 = ckg.newCircleData("c1", 200, 200, 50)
  1. We can now create a new onClick event on our circle
r1.onClick = () => {

}
  1. Now we can add our animations the first parameter is an array of the start values where out animation will start. The second parameter is an array of the end values of our animation with the third parameter specifing what each value represenets such as "scale", "x", "y" and/or "rotation"
 r1.onClick = () => {
  r1.addAnimation(new Animation([1], [0.8], ["scale"], "linear", 0.1, false))
  r1.addAnimation(new Animation([0.8], [1], ["scale"], "easeOut", 0.1, false))
}
  1. Finally we can call the drawFrame method in our game loop and click on our circle our final code should be as follows
const ckg = new CanvasKitGame(new CanvasKit("canvas", 500, 500))

const r1 = ckg.newCircleData("c1", 200, 200, 50)

r1.onClick = () => {
  r1.addAnimation(new Animation([1], [0.8], ["scale"], "linear", 0.1, false))
  r1.addAnimation(new Animation([0.8], [1], ["scale"], "easeOut", 0.1, false))
}

function loop(){
  ckg.drawFrame()
  requestAnimationFrame(loop)
}
loop() 

CanvasKitGame-Particle Example

To create a confetti effect we can do the following:

  1. Create a new CanvasKitGame instance which takes in a CanvasKit instance
const ckg = new CanvasKitGame(new CanvasKit("canvas", 500, 500))
  1. Create a new ParticleEmitterProps instance which can be any one of the following: RectangleParticleProps, CircleParticleProps or ImageParticleProps each one has unique properties associated with the given shape.
const particleProps = new RectangleParticleProps({
  gravity: {x: 0, y: 0.03},
  velocityVariation: {x: 1.5, y: 0},
  width: 7,
  height: 2,
  angularVelocity: 4
})
  1. We can now create a ParitlceEmmiter and pass in a position, particlesPerSecond and the particleProps we just created. We can also set the randomColoredParticle flag to true so our effect will look more like confetti.
const pe = new ParticleEmitter({x: 250, y: 250}, 50, ckg, particleProps)
pe.flags.randomColoredParticles = true 
  1. Finally we can just call the drawFrame() method. Our final code should look like this
import { CanvasKit, CanvasKitGame, ParticleEmitter, RectangleParticleProps } from "canvaskitgame"

const ckg = new CanvasKitGame(new CanvasKit("canvas", 500, 500))

const particleProps = new RectangleParticleProps({
  gravity: {x: 0, y: 0.03},
  velocityVariation: {x: 1.5, y: 0},
  width: 7,
  height: 2,
  angularVelocity: 4
})
const pe = new ParticleEmitter({x: 250, y: 250}, 50, ckg, particleProps)
pe.flags.randomColoredParticles = true 

function loop(){

  ckg.drawFrame()
  requestAnimationFrame(loop)
}
loop() 
  1. Aditionally we can also create a burst affect that happens every time a key is pressed with the following code
import { CanvasKit, CanvasKitGame, ParticleEmitter, RectangleParticleProps } from "canvaskitgame"

const ckg = new CanvasKitGame(new CanvasKit("canvas", 500, 500))

const particleProps = new RectangleParticleProps({
  gravity: {x: 0, y: 0.03},
  velocity: {x: 0, y: 0},
  velocityVariation: {x: 8, y: 8},
  width: 7,
  height: 2,
  angularVelocity: 10
})
const pe = new ParticleEmitter({x: 250, y: 250}, 50, ckg, particleProps)
pe.flags.randomColoredParticles = true 
pe.flags.burstMode = true
pe.flags.useCircularVariation = true
pe.setBurstParticleCount(400)
pe.deactivateEmitter()

ckg.keyBoard.addNewKeyPressEvent("t", () => {
  pe.emitBurst()
})

function loop(){

  ckg.drawFrame()
  requestAnimationFrame(loop)
}
loop() 

burst Recording 2025-05-22 125743