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

@jfcmontmorency/maze-widget

v1.0.3

Published

Canvas maze widget (ES module)

Readme

@jfcmontmorency/maze-widget

A lightweight, customizable maze generator with HTML5 Canvas rendering. Create beautiful, interactive mazes with configurable options and ES module support.

npm version License: MIT

Features

  • Customizable: Configure colors, dimensions, entry/exit points
  • Deterministic: Use seeds for reproducible maze generation
  • Responsive: Automatically adapts to container size
  • Lightweight: Zero dependencies, pure JavaScript
  • ES Modules: Modern JavaScript module support
  • TypeScript Ready: Works seamlessly with TypeScript projects

Installation

npm install @jfcmontmorency/maze-widget

Quick Start

Basic Usage

import { createMazeWidget } from '@jfcmontmorency/maze-widget';

// Create a simple maze
const maze = createMazeWidget('#maze-container');

HTML Structure

<div id="maze-container" style="width: 400px; height: 400px;"></div>

API Reference

createMazeWidget(mount, options)

Creates a new maze widget instance.

Parameters

  • mount {HTMLElement|string} - Container element or CSS selector
  • options {Object} - Configuration options (optional)

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | cols | number | 5 | Number of columns in the maze | | rows | number | 5 | Number of rows in the maze | | wallColor | string | "#ffffff" | Color of the maze walls | | bgColor | string | "#000000" | Background color | | lineWidthRatio | number | 0.25 | Wall thickness as ratio of cell size | | seed | number | 983811 | Random seed for consistent maze generation | | entry | Object | {x: 0, y: 0, side: "top"} | Entry point configuration | | exit | Object | {x: null, y: null, side: "bottom"} | Exit point configuration | | squareBy | string | "width" | How to calculate dimensions ("width" or "min") | | padding | number | 0 | Internal padding in pixels |

Returns

An API object with the following methods:

  • regenerate() - Generate a new maze with current options
  • redraw() - Redraw the current maze
  • setOptions(options) - Update options and redraw
  • destroy() - Clean up and remove the widget
  • getState() - Get current state (options, grid, canvas, mount)

Examples

Custom Styling

const maze = createMazeWidget('#container', {
  cols: 15,
  rows: 15,
  wallColor: '#ff6b6b',
  bgColor: '#4ecdc4',
  lineWidthRatio: 0.3,
  padding: 10
});

Using Seeds for Reproducible Mazes

// Generate the same maze every time
const maze = createMazeWidget('#container', {
  cols: 10,
  rows: 10,
  seed: 12345
});

// Generate a random maze
const randomMaze = createMazeWidget('#container', {
  seed: Math.floor(Math.random() * 1000000)
});

Dynamic Options

const maze = createMazeWidget('#container');

// Change maze size
maze.setOptions({ cols: 20, rows: 15 });

// Change colors
maze.setOptions({ 
  wallColor: '#2c3e50', 
  bgColor: '#ecf0f1' 
});

// Generate new maze with same settings
maze.regenerate();

Custom Entry and Exit Points

const maze = createMazeWidget('#container', {
  cols: 12,
  rows: 8,
  entry: { x: 0, y: 0, side: 'left' },
  exit: { x: 11, y: 7, side: 'right' }
});

Responsive Design

// The maze automatically adapts to container size
const maze = createMazeWidget('#responsive-container', {
  cols: 15,
  rows: 15,
  squareBy: 'min' // Use minimum of width/height for square cells
});

// Listen for container size changes
window.addEventListener('resize', () => {
  maze.redraw();
});

Advanced Usage

Getting Maze State

const maze = createMazeWidget('#container');
const state = maze.getState();

console.log(state.options);  // Current configuration
console.log(state.grid);     // Maze grid data
console.log(state.canvas);   // Canvas element
console.log(state.mount);    // Mount element

Cleanup

const maze = createMazeWidget('#container');

// Clean up when no longer needed
maze.destroy();

Browser Support

  • Chrome/Edge 88+
  • Firefox 78+
  • Safari 14+

Requires ES2020 support and Canvas API.

TypeScript

While this package is written in JavaScript, it works seamlessly with TypeScript projects:

import { createMazeWidget } from '@jfcmontmorency/maze-widget';

interface MazeOptions {
  cols?: number;
  rows?: number;
  wallColor?: string;
  bgColor?: string;
  // ... other options
}

const options: MazeOptions = {
  cols: 10,
  rows: 10,
  wallColor: '#333'
};

const maze = createMazeWidget('#container', options);

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT © JF Cartier

Repository

https://github.com/jfcmontmorency/maze-widget