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

fast-confetti

v1.0.2

Published

The **Fast Confetti** class provides a powerful and customizable way to create various confetti effects using `canvas-confetti`. It supports multiple styles of confetti like fireworks, stars, circles, squares, and more, and allows users to configure diffe

Downloads

199

Readme

Fast Confetti

The Fast Confetti class provides a powerful and customizable way to create various confetti effects using canvas-confetti. It supports multiple styles of confetti like fireworks, stars, circles, squares, and more, and allows users to configure different attributes such as colors, particle count, velocity, and other options.

Features

  • Customizable Effects: Control the colors, shapes, particle count, velocity, gravity, and more for your confetti effects.
  • Predefined Effects: Built-in effects like cannon, fireworks, snow, pride, and more.
  • Infinite Confetti: Set up continuous confetti effects for a specific duration with adjustable intervals.
  • Custom Canvas Support: Render confetti on a custom canvas element, allowing greater flexibility in UI design.

Installation

npm install fast-confetti

Usage

1. Basic Usage

You can create a basic confetti effect with default options using the cannon method:

import { Confetti } from './confetti';

const confetti = new Confetti();
confetti.cannon();

2. Custom Colors

You can specify an array of colors for your confetti effect:

confetti.cannon({
  colors: ['#FF0000', '#00FF00', '#0000FF'],
});

3. Fireworks Effect

To trigger a firework-style confetti effect with custom options:

confetti.fireworks({
  colors: ['#FF0000', '#FFFF00'],
  duration: 10000, // Runs for 10 seconds
});

4. Snow Effect

To create a snow-like confetti effect with slow-falling particles:

confetti.snow({
  duration: 15000, // Runs for 15 seconds
});

5. Infinite Confetti

You can create an infinite confetti effect, repeating a method at specified intervals:

confetti.infinite('cannon', 1000, 5000); // Runs for 5 seconds with 1-second intervals

6. Pride Effect

You can trigger a pride-themed confetti effect with rainbow colors:

confetti.pride({
  duration: 15000,
});

7. Custom Canvas Support

To render the confetti on a specific canvas element:

const canvas = document.getElementById('myCanvas') as HTMLCanvasElement;
confetti.customCanvas(canvas);

8. Reset Confetti

You can reset the confetti effects instantly, clearing all confetti particles:

confetti.reset(); // Instant reset

Configuration Options

ConfettiOptions

The ConfettiOptions interface allows you to customize the behavior of the confetti effects:

  • colors: An array of colors (hex or RGBA) for the confetti particles.
  • particleCount: The number of confetti particles to generate.
  • spread: The angle in degrees over which the confetti particles will spread.
  • startVelocity: The initial velocity of the confetti particles.
  • gravity: The gravitational force affecting the particles.
  • decay: The rate at which the particle velocity decays over time.
  • ticks: The duration (in frames) for which the confetti should last.
  • delay: A delay (in milliseconds) before the effect is triggered.
  • scalar: A scaling factor for the size of the confetti particles.
  • angle: The launch angle for the confetti particles.
  • origin: The starting position of the confetti on the canvas, represented as an object { x, y }.

ResetOptions

The ResetOptions interface provides additional configuration options for the reset:

  • duration: The time (in milliseconds) over which the confetti will reset.
  • particleCount: The number of particles during the reset.
  • ticks: The lifespan of each confetti particle.
  • gravity: The gravitational pull during the reset.
  • colors: Colors for the particles during the reset.
  • shapes: Shapes of the confetti particles during the reset.

Available Methods

  • custom(options?: ConfettiOptions): Fires a highly customizable confetti effect, allowing users to control various parameters such as colors, shapes, and particle count.
  • cannon(options?: ConfettiOptions): Fires a basic confetti cannon effect.
  • randomDirection(options?: ConfettiOptions): Launches confetti particles in random directions.
  • realistic(options?: ConfettiOptions): Creates a realistic burst of confetti with multiple shots.
  • fireworks(options?: FireworksOptions): Creates a firework-style confetti effect.
  • snow(options?: SnowOptions): Creates a snow-like confetti effect with slow-falling particles.
  • pride(options?: PrideOptions): Creates a pride-themed confetti effect.
  • fall(options?: ConfettiOptions): Makes confetti particles fall from the top.
  • infinite(method: string, interval: number, duration: number, options?: ConfettiOptions): Runs the specified confetti effect in a loop.
  • reset(options?: ResetOptions): Resets the confetti effects instantly.
  • customCanvas(canvas: HTMLCanvasElement | null): Renders the confetti on a custom canvas element.