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

@fewell/canvas-confetti-ts

v1.1.7

Published

A TypeScript-first fork of canvas-confetti with modern ES module support

Downloads

497

Readme

Canvas Confetti TypeScript 🎉

A TypeScript-first fork of canvas-confetti with modern ES module support.

Why This Fork?

This fork modernizes the original canvas-confetti library by:

  • Converting to TypeScript for better type safety and IDE support
  • Using ES modules as the primary distribution format
  • Modernizing the build system with esbuild
  • Providing better development tooling

Installation

npm install @fewell/canvas-confetti-ts

Usage

ES Modules (Recommended)

import confetti from "@fewell/canvas-confetti-ts";

// Basic usage
confetti();

// With options
confetti({
  particleCount: 100,
  spread: 70,
  origin: { y: 0.6 },
});

// Custom shapes and emojis
import { shapeFromText } from "@fewell/canvas-confetti-ts";

const emoji = shapeFromText({
  text: "🎉",
  scalar: 1.5,
});

confetti({
  shapes: [emoji],
  particleCount: 30,
  scalar: 2,
  spread: 45,
});

CommonJS

const confetti = require("canvas-confetti");
confetti();

Browser

<script type="module">
  import confetti from "https://cdn.jsdelivr.net/npm/canvas-confetti/dist/confetti.js";
  confetti();
</script>

API

Options

interface Options {
  particleCount?: number; // Number of confetti particles (default: 50)
  angle?: number; // Angle in degrees (default: 90)
  spread?: number; // How far particles spread (default: 45)
  startVelocity?: number; // Initial velocity (default: 45)
  decay?: number; // How quickly particles slow down (default: 0.9)
  gravity?: number; // Gravity force (default: 1)
  drift?: number; // Horizontal drift (default: 0)
  ticks?: number; // Animation length (default: 200)
  origin?: {
    // Starting position
    x?: number; // Horizontal position (0-1)
    y?: number; // Vertical position (0-1)
  };
  colors?: string[]; // Array of hex colors
  shapes?: Shape[]; // Array of shapes ('square', 'circle', or custom)
  scalar?: number; // Size scaling factor (default: 1)
  zIndex?: number; // Z-index for the canvas (default: 100)
}

Custom Shapes

// Create text/emoji shapes
const shape = shapeFromText({
  text: "🎉", // Any text or emoji
  scalar: 1.5, // Size scaling
  color: "#ff0000", // Optional color
  fontFamily: "Arial", // Optional font
});

// Create path shapes
const shape = shapeFromPath({
  path: "M0 0h1v1h-1z", // SVG path
  matrix: new DOMMatrix(), // Optional transform
});

Browser Support

  • Chrome/Edge (latest)
  • Firefox (latest)
  • Safari (latest)
  • Most modern browsers that support Canvas

Development

# Install dependencies
npm install

# Start development server
npm run dev

# Build for production
npm run build

# Run tests
npm test

Credits

This project is a TypeScript fork of canvas-confetti by Kiril Vatev.

License

ISC License - See LICENSE file

Contributing

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