Skip to content

Confetti API

Confetti

Extends Effect.

Factory Function

typescript
createConfetti(config?: ConfettiConfig)

Methods

burst(config): void

Fires a burst of confetti particles. All config properties are optional and merged with the defaults.

typescript
sim.burst(config: Partial<Config>): void

See Effect for the full method reference: mount(), start(), pause(), resume(), configure(), withFade(), and destroy().


Config

Configuration object for a confetti burst.

typescript
interface Config {
    angle: number;
    colors: string[];
    decay: number;
    gravity: number;
    palette: Palette;
    particles: number;
    shapes: Shape[];
    spread: number;
    startVelocity: number;
    ticks: number;
    x: number;
    y: number;
}
PropertyTypeDefaultDescription
anglenumber90Launch angle in degrees. 90 is straight up.
colorsstring[]Array of hex color strings. Overrides palette when set.
decaynumber0.9Velocity decay factor per tick. Lower = faster slowdown.
gravitynumber1Gravity acceleration. Higher = faster fall.
palettePalette'vibrant'Built-in color palette. Ignored when colors is set.
particlesnumber50Number of confetti particles to emit.
shapesShape[]All 11 shapesShapes to randomly select from.
spreadnumber45Spread angle in degrees.
startVelocitynumber45Initial particle velocity.
ticksnumber200Lifetime in ticks before a particle disappears.
xnumber0.5Horizontal position (0-1, normalized to canvas width).
ynumber0.5Vertical position (0-1, normalized to canvas height).

All properties are optional when calling burst(). Omitted properties use the defaults above.

TIP

startVelocity and gravity are automatically scaled by the simulation's scale setting.


ConfettiConfig

typescript
interface ConfettiConfig {
    scale?: number;
}
PropertyTypeDefaultDescription
scalenumber1Scales particle size, velocity, and gravity proportionally.

Palette

A built-in color palette. Use palette in config for a quick preset, or provide colors to override.

typescript
type Palette = 'classic' | 'pastel' | 'vibrant' | 'warm';
PaletteDescription
classicThe original neon color set.
pastelSoft, muted pastels.
vibrantBright, modern tones (default).
warmRich, warm and deep colors.

The PALETTES constant is exported and maps each palette name to its color array:

typescript
import { PALETTES } from '@basmilius/sparkle';

console.log(PALETTES.vibrant);
// ['#6366f1', '#8b5cf6', '#ec4899', '#f97316', '#eab308', '#22c55e', '#06b6d4']

Shape

The visual shape of a confetti particle.

typescript
type Shape = 'bowtie' | 'circle' | 'crescent' | 'diamond' | 'heart' | 'hexagon' | 'ribbon' | 'ring' | 'square' | 'star' | 'triangle';

Defaults

Default palette: 'vibrant'

Default shapes:

typescript
[
    'bowtie', 'circle', 'crescent', 'diamond', 'heart',
    'hexagon', 'ribbon', 'ring', 'square', 'star', 'triangle'
]