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

@canvas-tile-engine/core

v0.11.0

Published

Lightweight library for building interactive 2D grid-based maps and visualizations with Canvas

Readme

@canvas-tile-engine/core

npm version bundle size license

The renderer-agnostic engine behind Canvas Tile Engine. Use it when you want direct TypeScript control over a zoomable 2D grid surface without React or another UI wrapper.

@canvas-tile-engine/core owns the camera, coordinate math, event callbacks, layers, draw helpers, static caches, sprites, and viewport culling. You bring a renderer: Canvas2D, WebGL, React Native Skia, server-side Node.js, or your own implementation of the IRenderer contract.

Install

Canvas2D web app:

npm install @canvas-tile-engine/core @canvas-tile-engine/renderer-canvas

Other renderer choices:

npm install @canvas-tile-engine/core @canvas-tile-engine/renderer-webgl
npm install @canvas-tile-engine/core @canvas-tile-engine/renderer-server

Quick Start

<div id="map">
    <canvas></canvas>
</div>
import { CanvasTileEngine, type CanvasTileEngineConfig } from "@canvas-tile-engine/core";
import { RendererCanvas } from "@canvas-tile-engine/renderer-canvas";

const wrapper = document.getElementById("map") as HTMLDivElement;

const config: CanvasTileEngineConfig = {
    scale: 48,
    size: { width: 800, height: 500 },
    backgroundColor: "#0f172a",
    eventHandlers: { drag: true, zoom: true, hover: true, click: true },
    coordinates: { enabled: true, shownScaleRange: { min: 16, max: 96 } },
};

const engine = new CanvasTileEngine(wrapper, config, new RendererCanvas(), { x: 0, y: 0 });

engine.drawGridLines(1, 1, "#1e293b", 0);
engine.drawRect({ x: 0, y: 0, size: 1, radius: 4, style: { fillStyle: "#22c55e" } }, 1);
engine.drawText(
    {
        x: 0,
        y: -1,
        text: "Spawn",
        size: 0.35,
        style: { fillStyle: "#e2e8f0", fontFamily: "sans-serif", textAlign: "center" },
    },
    2,
);

engine.onClick = (coords) => {
    console.log("Clicked tile:", coords.snapped);
};

engine.render();

What Core Handles

  • Camera state: pan, zoom, bounds, smooth movement, resize-aware center updates.
  • Coordinate transforms: screen/pointer coordinates to raw and snapped world coordinates.
  • Event callbacks: click, right-click, hover, mouse/touch down, mouse/touch up, leave, zoom, resize.
  • Layered drawing: lower layers draw first, higher layers draw on top.
  • Draw helpers: rect, circle, image, text, line, path, grid lines, static rect/circle/image, and custom draw functions.
  • Performance basics: viewport culling, RBush spatial indexing for large item sets, and static draw caches where the renderer supports them.
  • Sprite utilities: SpriteSheet frame calculation and SpriteAnimator frame scheduling.

Renderers

Core does not draw by itself. It delegates to an injected renderer:

import { CanvasTileEngine } from "@canvas-tile-engine/core";
import { RendererCanvas } from "@canvas-tile-engine/renderer-canvas";
import { RendererWebGL } from "@canvas-tile-engine/renderer-webgl";

new CanvasTileEngine(wrapper, config, new RendererCanvas());
new CanvasTileEngine(wrapper, config, new RendererWebGL());
new CanvasTileEngine(wrapper, config, new MyCustomRenderer());

Official renderers:

| Package | Surface | | ----------------------------------------------------------- | ------------------------------ | | @canvas-tile-engine/renderer-canvas | HTML Canvas2D | | @canvas-tile-engine/renderer-webgl | WebGL with a 2D overlay | | @canvas-tile-engine/renderer-skia | React Native Skia | | @canvas-tile-engine/renderer-server | Headless Node.js image buffers |

Useful APIs

| API | Purpose | | --------------------------------------------------- | --------------------------------------------------------------------- | | engine.render() | Render the current scene. | | engine.setCenter({ x, y }) | Move the camera center immediately. | | engine.goCenter(x, y, durationMs) | Animate the camera center. | | engine.setScale(scale) / zoomIn() / zoomOut() | Control zoom programmatically. | | engine.getVisibleBounds() | Read the visible world bounds for culling, lazy loading, or UI state. | | engine.setBounds(bounds) | Clamp camera movement. | | engine.setEventHandlers(partial) | Enable or disable interactions at runtime. | | engine.clearLayer(layer) / clearAll() | Replace dynamic content safely. | | engine.images.load(src) | Load platform-specific image handles through the active renderer. |

Sprites

import { SpriteSheet, SpriteAnimator } from "@canvas-tile-engine/core";

const sheet = new SpriteSheet({ frameWidth: 32, frameHeight: 32, columns: 8 });
const player = { x: 4, y: 2, size: 1, img, sprite: sheet.frame(0, 0) };

engine.drawImage(player, 2);

const animator = new SpriteAnimator({ frames: sheet.framesInRow(0, 0, 5), fps: 8 });
animator.start((frame) => {
    player.sprite = frame;
    engine.render();
});

Documentation

License

MIT