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

@djodjonx/gwen-renderer-canvas2d

v1.0.0

Published

GWEN Canvas2D Renderer Plugin

Downloads

753

Readme

#@djodjonx/gwen-renderer-canvas2d

GWEN Canvas2D Renderer Plugin — 2D rendering with HTML Canvas

Render sprites, shapes, and text using the Canvas 2D API.

Installation

npm install@djodjonx/gwen-renderer-canvas2d

Quick Start

Register the Plugin

// gwen.config.ts
import { defineConfig } from '@djodjonx/gwen-kit';
import { Canvas2DRenderer } from '@djodjonx/gwen-renderer-canvas2d';

export default defineConfig({
  canvas: 'game-canvas', // ID of your canvas element
  plugins: [new Canvas2DRenderer()],
});

HTML Setup

<!DOCTYPE html>
<html>
  <head>
    <title>My Game</title>
    <style>
      canvas {
        display: block;
        background: #222;
      }
    </style>
  </head>
  <body>
    <canvas id="game-canvas" width="800" height="600"></canvas>
    <script type="module" src="/src/main.ts"></script>
  </body>
</html>

API Reference

Rendering Primitives

const renderer = api.services.get('renderer');

// Clear canvas
renderer.clear('#222222');

// Fill rectangle
renderer.fillRect(x, y, width, height, color);

// Draw outlined rectangle
renderer.strokeRect(x, y, width, height, color, lineWidth);

// Fill circle
renderer.fillCircle(x, y, radius, color);

// Draw outlined circle
renderer.strokeCircle(x, y, radius, color, lineWidth);

// Draw sprite/image
renderer.drawImage(image, x, y, width, height);

// Draw text
renderer.drawText(text, x, y, { font: '16px Arial', color: '#fff' });

Camera Control

// Set camera position
renderer.setCamera(centerX, centerY);

// Set camera scale (zoom)
renderer.setZoom(scale);

// Translate canvas
renderer.translate(x, y);

Examples

Drawing a Simple Scene

const renderer = api.services.get('renderer');

export function renderGame() {
  // Clear
  renderer.clear('#1a1a1a');

  // Background
  renderer.fillRect(0, 0, 800, 600, '#2d2d2d');

  // Draw player
  renderer.fillCircle(playerX, playerY, 16, '#00ff00');

  // Draw enemies
  for (const enemy of enemies) {
    renderer.fillRect(enemy.x, enemy.y, 20, 20, '#ff0000');
  }

  // HUD text
  renderer.drawText(`Score: ${score}`, 10, 30, {
    font: 'bold 20px Arial',
    color: '#ffffff',
  });
}

Camera-Following Gameplay

function updateCamera() {
  const renderer = api.services.get('renderer');
  const screenWidth = 800;
  const screenHeight = 600;

  // Center camera on player
  renderer.setCamera(playerX - screenWidth / 2, playerY - screenHeight / 2);
}

Sprite Sheet Animation

function drawAnimatedSprite(sheet, frameIndex, x, y) {
  const frameWidth = 64;
  const frameHeight = 64;
  const row = Math.floor(frameIndex / 8);
  const col = frameIndex % 8;

  const sourceX = col * frameWidth;
  const sourceY = row * frameHeight;

  renderer.drawImage(sheet, x, y, frameWidth, frameHeight, {
    sourceX,
    sourceY,
    sourceWidth: frameWidth,
    sourceHeight: frameHeight,
  });
}

Performance Tips

  • Use renderer.clear() once per frame
  • Cache frequently-used colors as constants
  • Use renderer.setCamera() instead of translating individual objects
  • Consider sprite atlasing for many small sprites
  • Profile with @djodjonx/gwen-plugin-debug to identify bottlenecks

Browser Compatibility

  • Canvas 2D API: All modern browsers
  • Best performance on Chrome 90+, Firefox 88+

See Also