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

@r-t-p/renderer

v0.0.5

Published

A package for rendering to a canvas element

Downloads

2

Readme

Renderer

Getting Started

You probably will want to save this to your dev dependencies.

npm i --save-dev @r-t-p/renderer

Also remember to bundle it with a bundler like webpack in your project to pull it into your bundle

Renderer

The renderer is the object that holds a reference to your canvas and it's context. Instantiating one by passing in the canvas element.

import { Renderer } from '@r-t-p/renderer';

let canvas = document.getElementById("canvas") as HTMLCanvasElement;
let renderer = new Renderer(canvas);

The renderer only has 2 methods:

  • Clear - will clear teh canvas.
  • Draw - takes in a spec and draws it.

Builders

There are builders that make it easy to create specs for circles, rectangles, images and text. Each builder can update the properties that are available to it's own type. Here is an example of a circle being built.

import { BuildCircleSpec } from '@r-t-p/renderer';

let circle = BuildCircleSpec()
  .Center({ x: 250, y: 250 })
  .FillStyle("blue")
  .Radius(100)
  .Create();

Once you have a spec created (from the Create function) it is an object you can interact with and change on the fly, then pass back into the Renderer's Draw method.

Together

Putting it all together you might make something like this:

import { BuildCircleSpec, Renderer } from '@r-t-p/renderer';

let canvas = document.getElementById("canvas") as HTMLCanvasElement;
let r = new Renderer(canvas);

let circle = BuildCircleSpec()
  .Center({ x: 100, y: 100 })
  .FillStyle("blue")
  .Radius(100)
  .Create();

r.Draw(circle);
circle.center = {x: 300, y: 300 };
circle.metadata.fillStyle = "green";
r.Draw(circle);

Contributing

Pull requests are welcome, if you add bloat they will be rejected. Keep things simple.

Running locally

npm run test # Runs the test runner
npm run build # Builds using `tsc` from configs in the `tsconfig.json`
npm run dev # Runs build and watches for changes

Under the hood

  • tsc for building js sent to /dist/
  • jest for testing all .test.ts or .spec.ts files and files in __test__
  • npm for versioning
  • .github/workflows (i.e github actions) for automation
    • main.yml runs tests and build on all branches
    • publish.yml ships code to npm when a release is published