/** * A color in the Oklab color space, which party.js uses internally because it is perceptually uniform. * Gradients blend evenly, and lighting changes brightness without shifting the hue. * * You rarely need to build one by hand: You can pass a CSS color string to * {@link color | color()}, or anywhere that accepts colors, instead. * * @summary A color in the Oklab color space. * * @see {@link https://bottosson.github.io/posts/oklab/ | Björn Ottosson: A perceptual color space} * * @group Utilities */ interface Color { /** * Perceived lightness, from 0 (black) to 1 (white). */ l: number; /** * Position on the green (negative) to red (positive) axis, about -0.3 to 0.3 for screen colors. */ a: number; /** * Position on the blue (negative) to yellow (positive) axis, about -0.3 to 0.3 for screen colors. */ b: number; /** * Opacity, from 0 (transparent) to 1 (opaque). */ alpha: number; } /** * Converts a CSS color string to a {@link Color}. * * Accepts hex colors (`#f00`, `#ff5a5f`, `#ff000080`) and the `rgb()`/`rgba()`, * `hsl()`/`hsla()`, `oklab()` and `oklch()` functions. A {@link Color} passed in is returned unchanged. * * Note that named colors are **not** supported, to minimize bundle size. In particular, `transparent` * is not a valid color input. * * @param input - A CSS color string, or an existing color. * @returns The Oklab color. * * @throws {@link PartyJSError} If the string isn't a supported color. * * @summary Converts a CSS color string to an Oklab color. * * @example * ```ts * const cornflowerblue = color("#6495ed"); * ``` * * @group Utilities */ declare function color(input: string | Color): Color; /** * A vector in 3D space, usually used to represent a particle's position or velocity. * * @summary A 3D vector. * * @group Utilities */ interface Vec3 { x: number; y: number; z: number; } /** * A rotation in 3D, stored as a unit quaternion. Used for a particle's orientation. * * You rarely need to build one by hand: {@link randomOrientation | randomOrientation()} covers * the common case of generating a random initial rotation. * * @summary A 3D rotation, stored as a unit quaternion. * * @group Utilities */ interface Quat { x: number; y: number; z: number; w: number; } /** * A circular shape, centered at (0, 0) with a radius of 0.5. * * @summary Draws a particle as a circle. * * @group Particles */ interface CircleShape { type: "circle"; } /** * A picture drawn at its own aspect ratio with its longer side filling the 1x1 box. * * Either pass a URL or anything the canvas can draw, like an ``, `` or `ImageBitmap`. Particles * whose image hasn't loaded yet aren't drawn, and appear once it has. An image that fails to load is reported * once, in the console. * * An image keeps its own colors: it fades out with the particle's opacity, but isn't tinted by its color or lit. * * @summary Draws a particle as an image. * * @example * ```ts * confetti(button, { shapes: [{ type: "image", image: "/logo.png" }] }); * ``` * * @group Particles */ interface ImageShape { type: "image"; /** * A URL to load the image from, or anything the canvas can draw. * * Loading only starts when the first particle spawns, so a large image may not show up in the first effect. * To show it right away, preload it, for example with ``, * or pass an `` that has already loaded. An SVG passed as an `` needs a `width` and `height`. */ image: string | CanvasImageSource; } /** * A regular polygonal shape, centered at (0, 0), with a specified number of sides. * * @summary Draws a particle as a regular polygon. * * @group Particles */ interface PolygonShape { type: "polygon"; /** * The number of sides the regular polygon should have, which is expected to be an integer >= 3. */ sides: number; } /** * A square shape, centered at (0, 0), that can be stretched via an aspect ratio and rounded via a corner radius. * * @summary Draws a particle as a square. * * @group Particles */ interface SquareShape { type: "square"; /** * The ratio of width to height for the square. The longer side will be kept at length 1, so the shape always * fills the box in one direction. For example, a value of 0.3 produces a tall, narrow strip. * * @defaultValue 1 */ aspectRatio?: number; /** * The radius of the corners, in shape units where the longer side is 1. This is expected to be non-negative, * and will be clamped if it exceeds half of the width or height of the shape. * * @defaultValue 0 */ cornerRadius?: number; } /** * A regular, pointed star, centered at (0, 0), with a specified number of points. * * @summary Draws a particle as a regular, pointed star. * * @group Particles */ interface StarShape { type: "star"; /** * The number of points the star should have, which is expected to be an integer >= 3. * * @defaultValue 5 */ points?: number; /** * How far the inner corners between the points are from the center, relative to the points themselves, from * just above 0 (thin, spiky points) to 1 (no points at all). The default gives the proportions of a classic * five-pointed star. * * @defaultValue 0.382 */ innerRadius?: number; } /** * A string of text or emoji, rendered optionally with a specified font. * * @summary Draws a particle as text or emoji. * * @group Particles */ interface TextShape { type: "text"; /** * The text to draw, for example an emoji or glyph like `*`. */ text: string; /** * A CSS font family. * * @defaultValue sans-serif */ font?: string; } /** * A shape determined by a {@link Path2D}. * * The path is expected to fit in a 1x1 box centered at (0, 0), oriented to have +y pointing down. * A supplied {@link Path2D} should only be created once, outside of any samplers, to avoid it being * created for every particle. * * @summary Draws a particle according to a given path. * * @group Particles */ interface PathShape { type: "path"; path: Path2D; } /** * A shape drawn by a custom function, for anything a {@link Path2D} cannot express, such as text, * images or gradients. * * The function is called once per particle on every frame. Before it is called, the context is transformed * into shape space (centered at (0, 0), with +y pointing down, rotated according to the particle's `orientation`, * with 1 unit being equal to the particle's size) and `fillStyle` is set to the particle's (lit) color. * * The function also receives the particle being drawn, so the drawing can depend on it. * * You are free to modify any context state, since it is saved and restored around each call. Nothing will be drawn * unless your function does so, for example via `ctx.fill()`. * * If the shape can be built using a {@link Path2D}, it is recommended to use {@link PathShape} instead. * * @summary A custom draw instruction for a particle. * * @example * ```ts * const ring: CustomShape = { * type: "custom", * draw(ctx, particle) { * const progress = particle.age / particle.lifetime; * ctx.strokeStyle = ctx.fillStyle; * ctx.lineWidth = 0.2 * (1 - progress); * ctx.beginPath(); * ctx.arc(0, 0, 0.4, 0, 2 * Math.PI); * ctx.stroke(); * }, * }; * ``` * * @group Particles */ interface CustomShape { type: "custom"; /** * Draws the particle, in shape space. * * @param ctx - The canvas' context, already transformed into shape space, with `fillStyle` set to the particle's * lit color. * @param particle - The particle being drawn. Read it to draw something that depends on the particle, like its * `age`, or its opacity for drawings that don't use `fillStyle`. This should never modify the particle, * such changes should be done via a {@link Behavior} instead. */ draw: (ctx: CanvasRenderingContext2D, particle: Readonly) => void; } /** * Controls the way a particle is drawn onto the canvas. * * Every shape is drawn in the same space: centered at (0, 0), fitting inside a 1x1 box from -0.5 to 0.5, * with +y pointing down, as it would on a regular canvas. That box is then scaled to the particle's `size`, * rotated by its `orientation`, and the `fillStyle` is set to its (lit) `color`. Built-in and path shapes * are filled with this color, while custom shapes draw themselves. * * @summary The shape a particle is drawn as. * * @group Particles */ type ParticleShape = SquareShape | CircleShape | StarShape | PolygonShape | PathShape | TextShape | ImageShape | CustomShape; /** * The state of a single particle while it is alive. * * Particles live in particle space, measured in pixels from the effect's origin: +x points right, +y points up * and +z points out of the screen towards the viewer. Particles are drawn without perspective, so the z-axis * only matters for directions, not positions. * * On every simulation step, the particle's `age` advances first. If the particle is still alive, * the behaviors run in the order they are listed in the effect. Then the particle is moved by `velocity` * and rotated by `angularVelocity`. A particle is removed (i.e. it dies) once its `age` reaches its `lifetime`. * * Each particle has its own copies of its vectors, color and shape, so behaviors can change them in place * or replace them. The only exception is the `path` of a {@link PathShape}, which is shared with other particles * possessing the same shape, so it should be replaced rather than modified. * * @summary The state of a single particle. * * @group Particles */ interface Particle { /** * Where the particle is, in pixels from the effect's origin, in particle space. */ position: Vec3; /** * How fast the particle moves, in px/s. Applied to `position` on every step, after the behaviors have run. */ velocity: Vec3; /** * How the particle is rotated. With no rotation, the shape faces the viewer and is drawn exactly as its shape defines. */ orientation: Quat; /** * How fast the particle spins. The direction is the rotation axis (following the right-hand rule), and the * length is the speed in degrees per second. */ angularVelocity: Vec3; /** * The particle's size, in pixels. Its shape's 1x1 box is scaled to this size. */ size: number; /** * The particle's color, before lighting is applied. */ color: Color; /** * The shape the particle is drawn as. */ shape: ParticleShape; /** * How long the particle has been alive, in seconds. */ age: number; /** * How long the particle lives, in seconds. It's removed (i.e. it dies) once `age` reaches this value. */ lifetime: number; } /** * A function that returns a pseudo-random number from 0 (inclusive) to 1 (exclusive), * like {@link Math.random | Math.random()}. * * Every effect has one, created from its `seed`, to ensure that seeded effects play out * the same way every time. Samplers and behaviors receive it as `ctx.rng`. It is recommended * that you use it instead of `Math.random()` in your own samplers and behaviors, so they * stay reproducible too. * * @summary A source of random numbers from 0 to 1. * * @returns A pseudo-random number from 0 (inclusive) to 1 (exclusive). * * @group Utilities */ type Rng = () => number; /** * Passed to {@link BehaviorObject.init} once, after the particle spawns and before its first update. * * @summary Context passed to a behavior when a particle spawns. * * @group Behaviors */ interface BehaviorInitContext { /** * The effect's random number generator. Use it in place of `Math.random()` to keep seeded effects reproducible. */ rng: Rng; } /** * Passed to a behavior's update function on every simulation step. * * @summary Context passed to a behavior on every simulation step. * * @group Behaviors */ interface BehaviorUpdateContext { /** * The effect's random number generator. Use it in place of `Math.random()` to keep seeded effects reproducible. */ rng: Rng; /** * The length of this step, in seconds. */ dt: number; } /** * A function that prepares a newly spawned particle for a behavior. * * Called once per particle right after it has been constructed, but before its first update. * Initializations are called in the order that the behaviors are listed in. * * A common use case is to remember initial particle data or to choose a random initial value for a behavior via * the random number generator. * * @param particle - The new particle. * @param ctx - The context supplied to the initialization, including the random number generator. * * @summary Prepares a newly spawned particle for a behavior. * * @group Behaviors */ type BehaviorInit = (particle: Particle, ctx: BehaviorInitContext) => void; /** * A function that updates a particle by a single simulation step. * * Called for every particle on every step, in the order that the behaviors are listed in. * Any "per-second" changes should be scaled by `ctx.dt` to make the behavior independent of the step size. * * @param particle - The particle to be updated. * @param ctx - The context supplied to the update, including the random number generator and the time step. * * @summary Updates a particle by one simulation step. * * @group Behaviors */ type BehaviorUpdate = (particle: Particle, ctx: BehaviorUpdateContext) => void; /** * A behavior that can also perform initialization when the particle is spawned. * * To remember something per particle, create a {@link WeakMap} keyed by particle inside your behavior's * factory function, so that every instance of the behavior gets its own map. * * @summary A behavior with an optional setup step for each particle. * * @example * ```ts * const shrink = (): Behavior => { * const startSize = new WeakMap(); * return { * init(particle) { * startSize.set(particle, particle.size); * }, * update(particle) { * const start = startSize.get(particle) as number; * particle.size = start * (1 - particle.age / particle.lifetime); * }, * }; * }; * ``` * * @group Behaviors */ interface BehaviorObject { /** * The initialization function of the behavior, called once for each particle, right after it spawns. */ init?: BehaviorInit; /** * The update function of the behavior, called on every particle every simulation step. */ update: BehaviorUpdate; } /** * Modifies a particle over its lifetime, for example gravity, drag or fading. * * Either a plain update function, called for every particle on every step, or a {@link BehaviorObject} when * the behavior also needs to perform setup for each new particle. Behaviors run in the order they are listed in. * * @summary Changes a particle over its lifetime. * * @group Behaviors */ type Behavior = BehaviorUpdate | BehaviorObject; /** * Information passed to a {@link SamplerFn} each time it is called. * * @summary Information passed to a sampler function. * * @group Samplers */ interface SamplerContext { /** * The effect's random number generator. Use it instead of `Math.random()` to keep seeded effects reproducible. */ rng: Rng; /** * A running count. For a particle's properties, it's the number of particles the effect has spawned before * this one. For a burst's `count`, it's the current loop of the {@link EmissionSchedule}. */ index: number; /** * When sampling particle properties, multiple particles spawned in one simulation step are batched, in which * case this field contains information on the batch. Otherwise this field will be absent. */ batch?: { /** * The particle's position in the batch, starting at 0. */ index: number; /** * How many particles will be spawned at once. */ size: number; }; } /** * A function that produces a value each time it's called, such as a random size or color. * * @summary A function that produces a value. * * @example * ```ts * // Every particle's size will be a bit larger than the one before. * const growing: SamplerFn = (ctx) => 2 + ctx.index * 0.5; * ``` * * @group Samplers */ type SamplerFn = (ctx: SamplerContext) => T; /** * Either a fixed value, or a {@link SamplerFn} that produces one. * * Wherever party.js accepts a sampler, you can pass a plain value that is shared between particles * (for example `size: 8`), or a function that is called again for each particle (for example `size: range(4, 12)`). * Typically, these functions will be evaluated when the particle spawns. * * @summary A fixed value, or a function that produces one. * * @group Samplers */ type Sampler = T | SamplerFn; /** * Creates a behavior that applies air resistance proportional to a particle's speed. * * Every second, a particle loses the fraction `rate` of its velocity. A fast particle therefore slows down sharply * at first, then more and more gently. Together with {@link gravity | gravity()}, a falling particle speeds up * until it reaches its terminal velocity of `gravity / rate`, so if you know how fast particles should fall, * use `drag(gravity / terminalVelocity)`. The rate is sampled once for each particle, when it spawns. * * Flat particles like paper feel more resistance when they move face-on than when they move edge-on. Set * `edgeRatio` below 1 to simulate this: a tilted particle then glides sideways while it falls, and as it tumbles, * the glide reverses, so it sways back and forth. The face is the plane of the particle's shape, so this needs * particles that spin, for example with {@link randomSpin | randomSpin()}. On average over all orientations, * the drag stays at `rate`, so the terminal velocity stays close to `gravity / rate`. * * @param rate - The fraction of its velocity a particle loses per second, in 1/s. Values between 2 and 10 * are usually sensible. Sampled for each particle. * @param edgeRatio - How much drag a particle feels when it moves edge-on, relative to face-on. 1 makes drag * the same in every direction. Values between 0.3 and 0.5 give a paper-like flutter, while lower values make * particles glide far to the side. Defaults to 1. * * @summary Slows particles down in proportion to their speed. * * @example * ```ts * // Falls at most 160px/s under gravity(800), and flutters like paper. * const behaviors = [gravity(800), drag(800 / 160, 0.4)]; * ``` * * @see {@link https://lampz.tugraz.at/~hadley/physikm/script/motion/terminal.en.php | Terminal Velocity - Falling with a Linear Drag Force} * * @group Behaviors */ declare function drag(rate: Sampler, edgeRatio?: number): Behavior; /** * A function that reshapes progress from 0 to 1, used by behaviors like {@link fade | fade()} and * {@link scale | scale()} to make a transition start or end softly. * * It receives a progress `t` from 0 to 1 and returns the eased value. It is expected to return 0 at `t = 0` * and 1 at `t = 1`. In between, its shape determines how fast the transition moves. * * @param t - The received progress from 0 to 1. * @returns The reshaped progress. * * @summary Reshapes progress to make transitions start or end softly. * * @example * ```ts * // A custom ease that starts even more slowly than sineIn. * const cubicIn: Easing = (t) => t ** 3; * fade(0.2, 0.5, cubicIn); * ``` * * @group Behaviors */ type Easing = (t: number) => number; /** * Creates an easing that moves at a constant rate. * * @summary Moves at a constant rate. * * @group Behaviors */ declare function linear(): Easing; /** * Creates an easing that starts slowly and speeds up towards the end. * * @summary Starts slowly and speeds up. * * @see {@link https://easings.net/#easeInSine | easings.net: easeInSine} * * @group Behaviors */ declare function sineIn(): Easing; /** * Creates an easing that starts quickly and slows down towards the end. * * @summary Starts quickly and slows down. * * @see {@link https://easings.net/#easeOutSine | easings.net: easeOutSine} * * @group Behaviors */ declare function sineOut(): Easing; /** * Creates an easing that starts slowly, speeds up towards the middle and slows down at the end. * * @summary Starts slowly, speeds up and slows down again. * * @see {@link https://easings.net/#easeInOutSine | easings.net: easeInOutSine} * * @group Behaviors */ declare function sineInOut(): Easing; /** * Creates a behavior that fades a particle's opacity in and out over the specified durations. * * The fade-in takes place during the first `inDuration` seconds of a particle's lifetime, while * the fade-out happens during the last `outDuration` seconds of the particle's lifetime. The * supplied easing is applied forwards when fading in, and in reverse when fading out. * * @param inDuration - The duration in seconds it takes for the particle to fade in fully, or * 0 if no fade-in should be applied. * @param outDuration - The duration in seconds it takes for the particle to fade out fully, or * 0 if no fade-out should be applied. * @param ease - How the transition progresses. Defaults to {@link linear | linear()}. * * @summary Fades a particle in and out. * * @group Behaviors */ declare function fade(inDuration: number, outDuration: number, ease?: Easing): Behavior; /** * Creates a behavior that continuously accelerates a particle downward by a constant amount, simulating gravity. * * @param strength - The downward acceleration, in px/s². A positive value pulls towards -y in particle space, * which is down in screen space. * * @summary Pulls particles down with a constant acceleration. * * @group Behaviors */ declare function gravity(strength: number): Behavior; /** * Creates a behavior that grows a particle from 0 to its sampled size and shrinks it back * to 0 over the specified durations. * * The growing takes place during the first `inDuration` seconds of a particle's lifetime, while * the shrinking happens during the last `outDuration` seconds of the particle's lifetime. The * supplied easing is applied forwards when growing, and in reverse when shrinking. * * @param inDuration - The duration in seconds it takes for the particle to grow from 0 to its * sampled size, or 0 if it should start at its sampled size. * @param outDuration - The duration in seconds it takes for the particle to shrink back to 0, * or 0 if it should end at its sampled size. * @param ease - How the transition progresses. Defaults to {@link linear | linear()}. * * @summary Scales a particle in and out. * * @group Behaviors */ declare function scale(inDuration: number, outDuration: number, ease?: Easing): Behavior; /** * Options for {@link twinkle | twinkle()}. * * @summary How often and how strongly particles twinkle. * * @group Behaviors */ interface TwinkleOptions { /** * How many glints a particle catches per second, on average. A particle that lives for one second with the default * of 1.5 glints once or twice, at random moments. * * @defaultValue 1.5 */ glints?: number; /** * How long a single glint lasts, from start to end, in seconds. Longer glints look softer. * * @defaultValue 0.22 */ length?: number; /** * How much a particle grows at the peak of a glint, relative to its size. `0.25` makes it 25% larger. * * @defaultValue 0.25 */ size?: number; /** * How far a particle's color moves towards white at the peak of a glint, from 0 (not at all) to 1 (fully white). * * @defaultValue 0.6 */ brightness?: number; } /** * Creates a behavior that makes particles twinkle occasionally. * * Each particle glints a few times during its life, at random moments: for a short while, it grows a little and * flashes towards white, then settles back. Between glints, it looks as it would without this behavior. * * The glint is applied on top of the particle's size and color, so it works together with behaviors that change * them. List it after {@link scale | scale()}, which sets the size from scratch on every step and would otherwise * overwrite the glint. * * @param options - How often and how strongly particles glint. See {@link TwinkleOptions}. * * @throws {@link PartyJSError} If an option is out of range. * * @summary Makes particles glint now and then, like glitter. * * @example * ```ts * const behaviors = [scale(0.05, 0.25), twinkle({ glints: 2, brightness: 0.8 })]; * ``` * * @group Behaviors */ declare function twinkle(options?: TwinkleOptions): Behavior; /** * A color at a specific position along a gradient, to be used with the {@link gradient | gradient()} * sampler when the colors should not be spaced evenly. * * Because {@link gradient | gradient()} chooses a (uniformly) random position along it for each particle, * the spacing of the stops determines how common a color is: the wider the gap between two stops, the more * particles get a color that is sampled between those stops. * * Stops can be listed in any order, and two stops at the same offset create a hard edge instead of a blend. * * @summary A color at a chosen position along a gradient. * * @example * ```ts * // Mostly pinks, with a short blend into gold at the end. * gradient([ * { offset: 0, color: "#ff5a5f" }, * { offset: 0.8, color: "#ff8fa3" }, * { offset: 1, color: "#ffb400" }, * ]); * ``` * @group Samplers */ interface GradientStop { /** * The position of the stop, from 0 (the start of the gradient) to 1 (the end). * Values outside this range throw a {@link PartyJSError}. */ offset: number; /** * The color at this position. Accepts anything {@link color | color()} accepts. */ color: string | Color; } /** * Creates a sampler that picks a random color from a gradient. * * Each particle gets a random position along the gradient, with every position being equally likely. This means * that the colors appear in the proportions the gradient gives them. Plain colors are spaced evenly, and one * can use {@link GradientStop | stops} to give some colors a higher chance than others. * * @param colors - The colors, evenly spaced, or explicit stops. * * @throws {@link PartyJSError} If no colors or stops are given, if a stop's offset is outside `[0, 1]`, or if * a color string is invalid. * * @summary Picks random colors from a gradient. * * @group Samplers */ declare function gradient(colors: (string | Color)[] | GradientStop[]): SamplerFn; /** * Options for {@link randomHue | randomHue()}. * * @summary The lightness, chroma and opacity of random-hue colors. * * @group Samplers */ interface RandomHueOptions { /** * Lightness, from 0 (black) to 1 (white). */ l: number; /** * Chroma: how intense the colors are, from 0 (gray) upwards. Around 0.1-0.2 gives vivid colors, while very * high values cannot be shown on a screen and will be clipped. */ c: number; /** * Opacity, from 0 (transparent) to 1 (opaque). * * @defaultValue 1 */ alpha?: number; } /** * Creates a sampler for colors of the same lightness and intensity, with a random hue. * * Because Oklch is perceptually uniform, all hues come out equally bright, which makes for even, rainbow-like mixes. * * @param options - The lightness, chroma and opacity shared by all colors. * * @throws {@link PartyJSError} If the supplied chroma is negative. * * @summary Picks colors with a random hue. * * @see {@link https://oklch.com | oklch.com} * * @example * ```ts * const color = randomHue({ l: 0.7, c: 0.15 }); * ``` * * @group Samplers */ declare function randomHue(options: RandomHueOptions): SamplerFn; /** * Creates a sampler for velocities that point in a direction, with some deviation. * * Angles are in degrees, measured counter-clockwise from +x in particle space, so 0 points right and 90 points up. * The angle is chosen with {@link spread | spread()}, so a burst fans out evenly across the cone. A `deviation` * of 0 sends every particle in exactly the same direction. * * @param angle - The direction of the cone's center, in degrees. * @param deviation - How far a particle's direction may lie from `angle`, in degrees, in either direction. * @param speed - The speed, in px/s. Can itself be a sampler. * * @summary Creates velocities in a direction, with some random spread. * * @example * ```ts * // Upwards, fanning out 30° to either side, with constant speed. * cone(90, 30, 400) * * // Straight down, at varying speeds. * cone(-90, 0, range(60, 120)) * ``` * * @group Samplers */ declare function cone(angle: number, deviation: number, speed: Sampler): SamplerFn; /** * A vector in 2D space. * * @summary A 2D vector. * * @group Utilities */ interface Vec2 { x: number; y: number; } /** * Resolves a {@link Sampler} to a value, by calling it if it is a function, or returning it unchanged * if it is a fixed value. * * This can be useful when writing your own samplers that build on other samplers. * * @param sampler - The sampler to resolve. * @param ctx - The context to pass on if the `sampler` is a function. * @returns The sampled value. * * @summary Resolves a sampler to a value. * * @example * ```ts * const doubled = (base: Sampler): SamplerFn => * (ctx) => 2 * evaluateSampler(base, ctx); * ``` * * @group Samplers */ declare function evaluateSampler(sampler: Sampler, ctx: SamplerContext): T; /** * Creates a sampler to uniformly choose a value between `min` and `max`. * * @param min - The lower bound. * @param max - The upper bound. * * @summary Picks a random number between two bounds. * * @example * ```ts * const size = range(8, 16); * ``` * * @group Samplers */ declare function range(min: number, max: number): SamplerFn; /** * Creates a sampler that picks numbers from a normal (bell curve) distribution: most values land near `mean`, * and fewer the further away they are. About 68% fall within one `stdDev` of the mean, about 95% within two and * about 99.7% within three. * * The values have no hard limits, so occasionally one can be produced that's far from the mean. Prefer * {@link range | range()} for properties that must stay within bounds, like a size that cannot be negative. * * @param mean - The value the results cluster around. * @param stdDev - How widely the results spread around the mean. * * @summary Picks random numbers that cluster around a mean. * * @see {@link https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform | Wikipedia: Box–Muller transform} * * @group Samplers */ declare function normal(mean: number, stdDev: number): SamplerFn; /** * Creates a sampler that picks numbers from `center - deviation` to `center + deviation`, spread * evenly across each batch of particles. * * Within a batch (a group of particles spawned in the same simulation step, such as a burst), the range is * divided into one equal slice per particle, and each particle gets a random value within its own slice. * A burst therefore will always cover the whole range evenly, without the clumps and gaps that truly * independent random values could produce. A particle spawned on its own gets a random value from the whole range. * * @param center - The middle of the range. * @param deviation - How far values may lie from the center, in either direction. * * @summary Picks numbers spread evenly around a center. * * @group Samplers */ declare function spread(center: number, deviation: number): SamplerFn; /** * Creates a sampler that picks one of the given values at random, either with equal chances or weighted ones. * * Weights are relative and don't need to add up to 1: `[3, 1]` will make the first value three times as likely * as the second one. * * @param arr - The values to pick from. * @param weights - Optional relative chances, one per value. * * @throws {@link PartyJSError} If `arr` is empty, if the number of weights doesn't match the number of values, * if a weight is negative or if all weights are zero. * * @summary Picks one of several values at random. * * @example * ```ts * // Mostly circles with an occasional star. * pick([{ type: "circle" }, { type: "star" }], [4, 1]) * ``` * * @group Samplers */ declare function pick(arr: T[], weights?: number[]): SamplerFn; /** * Creates a sampler for random rotations. If no axis is provided then each orientation is equally likely, * otherwise the rotation is only created around the given axis. * * For example, rotations around +z keep flat shapes facing the viewer, only turning them within the screen plane. * * @param axis - Optionally, the axis to create the rotation around. * * @summary Picks a random rotation. * * @see Shoemake, K. (1992). "III.6 - Uniform Random Rotations." * * @group Samplers */ declare function randomOrientation(axis?: Readonly): SamplerFn; /** * Creates a sampler for spinning in a random direction: a speed between `min` and `max` on a rotation axis. * If no axis is provided, a random one is sampled. * * @param min - The slowest spin, in degrees per second. * @param max - The fastest spin, in degrees per second. * @param axis - Optionally, the axis to create the rotation on. * * @summary Picks a random spin axis and speed. * * @see {@link https://mathworld.wolfram.com/SpherePointPicking.html | Wolfram MathWorld: Sphere Point Picking} * * @group Samplers */ declare function randomSpin(min: number, max: number, axis?: Readonly): SamplerFn; /** * A value that can change while an effect runs: either a fixed value, or a function that party.js * calls again each time it needs the value. * * Use a function to follow something outside of the effect, for example the window size, the scroll position * or an element that moves its position. Unlike a {@link Sampler}, the function receives no context. It is not * about variety between particles, but rather about reacting to page state. * * @summary A value that can change while an effect runs. * * @example * ```ts * // Keep emitting from the center of the window, even when it's resized. * const origin = () => ({ x: window.innerWidth / 2, y: window.innerHeight / 2 }); * ``` * * @group Custom effects */ type Live = T | (() => T); /** * A group of particles emitted all at once, at a set time in each loop of an {@link EmissionSchedule}. * * @summary A group of particles emitted all at once. * * @group Custom effects */ interface EmissionBurst { /** * When the burst fires, in seconds from the start of each loop. Must be at least 0 and at most the schedule's * `duration`, or an error will be thrown as the burst would never fire. * * @defaultValue 0 */ time?: number; /** * How many particles the burst emits. Sampled once each time the burst fires, with `ctx.index` set to the * current loop. The sampled number will be rounded to the nearest integer. */ count: Sampler; } /** * When and how many particles an effect emits. * * A schedule runs for `duration` seconds, `loops` times in a row. During that time, particles are emitted * continuously at `rate` per second, and each burst fires at its set time once per loop. The effect ends once * all loops have run and the last particle has expired (i.e. died). * * @summary When and how many particles an effect emits. * * @example * ```ts * // A single burst of 40 particles. * const scheduleA = { bursts: [{ count: 40 }] }; * * // A steady stream of 20 particles per second, running forever. * const scheduleB = { loops: Infinity, rate: 20 }; * ``` * * @group Custom effects */ interface EmissionSchedule { /** * The length of one loop, in seconds. Must be positive and finite. * * @defaultValue 1 */ duration?: number; /** * How many loops the schedule runs. Use `Infinity` for an effect that runs until it's * {@link Effect.end | ended} or {@link Effect.stop | stopped}. * * @defaultValue 1 */ loops?: number; /** * How many particles to emit per second, continuously. This is read on every simulation step, so a function * can speed the stream up or slow it down, or (for example) make it dependent on the screen size. While it's 0, * the stream pauses, and it picks up at the same pace once the rate is raised again, without making up for the * time in between. * * @defaultValue 0 */ rate?: Live; /** * Groups of particles emitted all at once, each fired once per loop. * * @defaultValue [] */ bursts?: EmissionBurst[]; } /** * A filled circle that particles spawn from, with every point inside it equally likely. * * @summary A circular area that particles spawn from. * * @group Custom effects */ interface DiskEmissionShape { type: "disk"; /** * The center of the circle, in pixels from the origin. * * @defaultValue { x: 0, y: 0 } */ center?: Vec2; /** * The radius of the circle, in pixels. */ radius: number; } /** * A filled rectangle that particles spawn from, with every point inside it equally likely. * Set `width` or `height` to 0 to emit particles from a line. * * @summary A rectangular area that particles spawn from. * * @group Custom effects */ interface RectEmissionShape { type: "rect"; /** * The center of the rectangle, in pixels from the origin. * * @defaultValue { x: 0, y: 0 } */ center?: Vec2; /** * The width of the rectangle, in pixels. */ width: number; /** * The height of the rectangle, in pixels. */ height: number; } /** * An area that particles spawn from, for use with {@link emitFrom | emitFrom()}. * * Positions are in particle space, i.e. in pixels from the effect's origin, with +y pointing upwards. * * @summary An area that particles spawn from. * * @group Custom effects */ type EmissionShape = DiskEmissionShape | RectEmissionShape; /** * Creates a sampler for particle positions spread across an area. * * The shape is {@link Live}: pass a function to make the follow something that changes, for example the * window width. It's read again for every particle that spawns. * * @param shape - The area to spawn particles from. * @returns A sampler for {@link ParticleInit.position}. * * @summary Spawns particles from an area. * * @example * ```ts * // Along a line across the full width of the window. * const positionSampler = emitFrom(() => ({ type: "rect", width: window.innerWidth, height: 0 })); * ``` * * @group Custom effects */ declare function emitFrom(shape: Live): SamplerFn; /** * Describes the values that will be assigned to a particle when it's spawned. * * Every field is a {@link Sampler}: either a fixed value, or a function that's called once for each particle * when it spawns, so that particles can differ in appearance. The results become the particle's initial state * (see {@link Particle}). After that, behaviors and the simulation steps take over. * * The values `position`, `velocity`, `orientation` and `angularVelocity` are optional, and default to values * producing a particle that starts at the origin, does not move or spin and faces the viewer. * * @summary Describes the values assigned to a new particle. * * @example * ```ts * createEffect({ * origin: { x: 200, y: 300 }, * schedule: { bursts: [{ count: 30 }] }, * particleInit: { * position: emitFrom({ type: "disk", radius: 20 }), * velocity: cone(90, 30, range(200, 400)), * orientation: randomOrientation(), * angularVelocity: randomSpin(90, 270), * size: range(8, 14), * color: pick(["#ff5a5f", "#ffb400", "#00a699"]), * shape: { type: "circle" }, * lifetime: range(2, 3), * }, * }); * ``` * * @group Custom effects */ interface ParticleInit { /** * Where the particle spawns, in pixels from the effect's origin, in particle space so +y points upwards. * Use {@link emitFrom | emitFrom()} to spawn particles from an area. * * @defaultValue { x: 0, y: 0, z: 0 } */ position?: Sampler; /** * The particle's starting velocity, in px/s. Use {@link cone | cone()} to emit particles in * a direction with some spread. * * @defaultValue { x: 0, y: 0, z: 0 } */ velocity?: Sampler; /** * The particle's initial rotation. Use {@link randomOrientation | randomOrientation()} for a random one. * * @defaultValue { x: 0, y: 0, z: 0, w: 1 } */ orientation?: Sampler; /** * How fast the particle spins initially: the direction is the rotation axis (following the right-hand rule) and the * length is the speed in degrees per second. Use {@link randomSpin | randomSpin()} for a random axis and speed. * * @defaultValue { x: 0, y: 0, z: 0 } */ angularVelocity?: Sampler; /** * The particle's initial size, in pixels. */ size: Sampler; /** * The initial color of the particle: a CSS color string or a {@link Color}. Strings are converted * with {@link color | color()} when the particle spawns, so an invalid color throws at that point rather * than when the effect is created. */ color: Sampler; /** * The shape the particle is drawn as. Use {@link pick | pick()} to mix several shapes in the effect. */ shape: Sampler; /** * How long the particle lives, in seconds. */ lifetime: Sampler; } /** * A function that adjusts a particle's color to account for lighting, called for every particle on every frame. * * It receives the particle's color and how directly its face points towards the light, from -1 to 1, with 0 * meaning edge-on. It must return a new color instance, as it should not modify the particle's own color. * * @summary Adjusts a particle's color for lighting. * * @group Custom effects */ type LightingFn = (color: Readonly, coefficient: number) => Color; /** * Options for {@link createLighting | createLighting()}. * * @summary The strength of ambient and directional light. * * @group Custom effects */ interface CreateLightingOptions { /** * The lightness factor for a particle seen edge-on to the light. * * @defaultValue 0.5 */ ambient?: number; /** * The lightness factor for a particle facing the light directly. * * @defaultValue 1 */ peak?: number; } /** * Creates a {@link LightingFn} that scales a color's lightness by how directly the particle faces * the light, from both sides alike. * * The lightness of a particle is multiplied by a value from `options.ambient` to `options.peak`, which * is calculated via interpolation by the lighting coefficient. * * @param options - The ambient and peak lightness factors. * * @summary Creates a lighting function that brightens particles facing the light. * * @group Custom effects */ declare function createLighting(options?: CreateLightingOptions): LightingFn; /** * What an effect does when the user has asked their system for reduced motion, through the * `prefers-reduced-motion` media query: * * - `"skip"`: the effect doesn't play and draws nothing. The `finished` promise on the effect handle will still * resolve as "completed". * - `"play"`: the effect plays as usual. * * The user's preference is read once, when the effect starts. Changing it while an effect is running doesn't * affect that effect. * * Particle effects are usually decoration, so party.js skips them by default. Only use `"play"` when the particles * carry information the user would otherwise miss, or when the user has explicitly asked to see them, for example * through a setting on your site. * * @summary What an effect does when the user prefers reduced motion. * * @see {@link https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion | MDN: prefers-reduced-motion} * * @group Effects */ type ReducedMotion = "skip" | "play"; /** * Sets what effects do by default when the user has asked their system for reduced motion. Effects can override * this behavior with their `reducedMotion` option. Useful when your site has its own motion setting that should * take precedence. * * @param mode - What effects started afterwards do when the user prefers reduced motion. * * @summary Sets the default way of handling reduced motion. * * @example * ```ts * setDefaultReducedMotion("play"); * // This will produce confetti regardless of whether reduced motion is enabled * confetti(button); * ``` * * @group Effects */ declare function setDefaultReducedMotion(mode: ReducedMotion): void; /** * The result of a completed effect, either `"completed"` if it ended by itself or `"stopped"` if it ended early. * An effect that was told to wind down with {@link Effect.end | end()} also ends by itself, once its last particle * has expired, so its result is `"completed"` too. An effect that is skipped due to reduced motion will still have * `"completed"` as its result. * * @summary The result of a completed effect. * * @group Effects */ type EffectResult = "completed" | "stopped"; /** * A handle to a running effect, returned by {@link createEffect | createEffect()} and the built-in * effects, such as {@link confetti | confetti()}. * * An effect starts as soon as it's created, and ends by itself once its schedule is finished and the last particle * has expired (i.e. died). You can use this handle to pause it, to let it wind down early with * {@link Effect.end | end()}, or to stop it right away with {@link Effect.stop | stop()}. * * @summary A handle to control a running effect. * * @example * ```ts * const effect = confetti(button); * effect.pause(); * effect.resume(); * effect.stop(); // removes the particles right away * ``` * * @group Effects */ interface Effect { /** * Settles once the effect is over: with `"completed"` when it ended by itself, including after * {@link Effect.end | end()}, or with `"stopped"` when it ended early, because {@link Effect.stop | stop()} was * called or it threw while running. Never rejects. */ readonly finished: Promise; /** * Ends the effect immediately and removes its particles. The `finished` promise resolves as `"stopped"`, and * the effect can't be resumed afterwards. Calling it again has no effect. * * The canvas the effect was drawn on is removed (or, if you provided it, cleared) once no other effect is * drawing on it. To let the particles finish their lifetime instead, use {@link Effect.end | end()}. */ stop(): void; /** * Stops the effect from emitting new particles, and lets the ones that are already alive finish their * lifetime. The effect then ends by itself, and the `finished` promise resolves as `"completed"`. Useful to * turn off an effect that runs forever, like a stream with `loops: Infinity`. * * On a paused effect, the remaining particles stay frozen until it's resumed. Calling * {@link Effect.stop | stop()} afterwards still removes them right away. Calling it again, or after the effect * has ended, has no effect. */ end(): void; /** * Freezes the effect: particles stop moving and stay visible where they are. Calling it while already paused * has no effect. */ pause(): void; /** * Continues a paused effect from where it was paused. The time spent paused is skipped, so particles * do not jump ahead. Does nothing if the effect isn't paused or has already ended. */ resume(): void; } /** * Options for {@link createEffect | createEffect()}, with everything that defines a custom effect: where it * happens, when particles are emitted, how they start out and how they change. * * @summary Everything that defines a custom effect. * * @group Custom effects */ interface CreateEffectOptions extends BaseEffectOptions { /** * The point particle positions are measured from. Read again on every frame, so a function can * make the whole effect follow something or, for example, react to the window size. * * Without a `canvas`, party.js draws onto its own fullscreen canvas, and the origin is in page coordinates, i.e. * pixels from the top-left of the document, with +y pointing down. With a `canvas`, it's in that canvas' * coordinate system instead, i.e. pixels from its top-left corner. * * To start the effect at an element, use {@link measureTarget | measureTarget()}, which also handles * the conversion to a canvas’ coordinates. */ origin: Live; /** * When and how many particles are emitted. */ schedule: EmissionSchedule; /** * How new particles start out. */ particleInit: ParticleInit; /** * How particles change over their lifetime, run in this order on every simulation step. * See {@link Behavior}. */ behaviors?: Behavior[]; /** * The direction that light comes from, in particle space. The vector's length does not matter. * This value is read every frame. The default value points straight from the viewer. * * @defaultValue { x: 0, y: 0, z: 1 } */ light?: Live; /** * How a particle's color changes with the angle between its face and the light. See * {@link createLighting | createLighting()}. Pass `null` to disable lighting. * * @defaultValue createLighting() */ lighting?: LightingFn | null; /** * A random number generator to use instead of the built-in one. This takes precedence over `seed`. */ rng?: Rng; } /** * Shared options for built-in and custom effects. * * @summary Shared options for effects. * * @group Effects */ interface BaseEffectOptions { /** * What the effect does when the user has asked their system for reduced motion. A skipped effect draws nothing, * and the `finished` promise on the effect handle resolves as "completed" after `createEffect()` returns, * unless you stop the effect immediately. See {@link ReducedMotion} for more information. * * Without this option, the default set with {@link setDefaultReducedMotion | setDefaultReducedMotion()} is used, * which is `"skip"` unless you changed it. */ reducedMotion?: ReducedMotion; /** * A canvas to draw onto. If none is provided, party.js draws onto a fullscreen canvas it shares between all * effects, and removes it once no effect is using it anymore. If provided, positions are measured from the * canvas' top-left corner: the built-in effects measure their target relative to it, and a custom effect's * origin is given in its coordinates (see {@link measureTarget | measureTarget()}). */ canvas?: HTMLCanvasElement; /** * A seed for the effect's random number generator. The same seed with the same options produces the same * visuals each time. Without one, a random seed is generated and every run of the effect looks different. */ seed?: number; } /** * Creates and starts a custom effect, using the provided options. * * The built-in effects like {@link confetti | confetti()} are made using this function. You can use it directly * if your needs are not covered by them. * * @param options - Everything that defines the effect. * @returns A handle to pause, resume or stop the effect early. * * @summary Creates and starts a custom effect. * * @example * ```ts * createEffect({ * origin: { x: 200, y: 300 }, * schedule: { bursts: [{ count: 30 }] }, * particleInit: { * position: emitFrom({ type: "disk", radius: 20 }), * velocity: cone(90, 30, range(200, 400)), * orientation: randomOrientation(), * angularVelocity: randomSpin(90, 270), * size: range(8, 14), * color: pick(["#ff5a5f", "#ffb400", "#00a699"]), * shape: { type: "circle" }, * lifetime: range(2, 3), * }, * behaviors: [gravity(800), fade(0, 0.5)], * }); * ``` * * @group Custom effects */ declare function createEffect(options: CreateEffectOptions): Effect; /** * What an effect bursts out of: an element on the page, or a point. * * For an element, the built-in effects burst out of a small area in its middle, which grows with the element's * size. For a point, they spawn exactly there, in page coordinates, i.e. in pixels from the top-left corner of the * document, with +y pointing down. Either way, the position is read only once, when the effect starts; moving or * scrolling afterwards does not move the effect. * * @summary An element or point that an effect bursts out of. * * @example * ```ts * confetti(document.querySelector("#submit")!); * confetti({ x: event.pageX, y: event.pageY }); * ``` * * @group Effects */ type EffectTarget = HTMLElement | Vec2; /** * Where an effect happens and which area its particles spawn from, as returned by * {@link measureTarget | measureTarget()}. * * @summary An effect's origin and the area its particles spawn from. * * @group Custom effects */ interface MeasuredTarget { /** * The effect's origin, for {@link CreateEffectOptions.origin}: the target's center, in page coordinates, * or in the canvas' coordinates if a canvas was given. */ origin: Vec2; /** * The area particles spawn from, relative to the `origin`, for {@link emitFrom | emitFrom()}: the element's * whole area, or a single point. */ area: EmissionShape; } /** * Turns an element or a point into an origin and an emission area for {@link createEffect | createEffect()}. * Use it to make a custom effect burst out of an element. * * The target is measured once, when this function is called. Moving or scrolling afterwards does not * move the effect. * * @param target - An element, or a point in page coordinates. * @param canvas - The canvas the effect draws onto, if it doesn't use the default fullscreen canvas. * The origin is then measured from the canvas' top-left corner, as {@link CreateEffectOptions.canvas} expects. * @returns The origin, and the area for {@link emitFrom | emitFrom()}. * * @throws {@link PartyJSError} If called outside a browser, for example during server-side rendering. * * @summary Turns an element or point into an origin and an emission area. * * @example * ```ts * const { origin, area } = measureTarget(button); * * createEffect({ * origin, * schedule: { bursts: [{ count: 30 }] }, * particleInit: { * position: emitFrom(area), * // ... * }, * }); * ``` * * @group Custom effects */ declare function measureTarget(target: EffectTarget, canvas?: HTMLCanvasElement): MeasuredTarget; /** * Options for {@link confetti | confetti()}. * * @summary Customization of the built-in confetti effect. * * @group Effects */ interface ConfettiOptions extends BaseEffectOptions { /** * How many pieces of confetti are emitted simultaneously at the start of the effect. * Sampled once and rounded to the nearest integer. * * @defaultValue range(15, 30) */ count?: Sampler; /** * The angle at which the confetti is emitted, measured counter-clockwise from +x in degrees in particle space, so * 0 points right and 90 points up. Sampled once when the effect starts, so all confetti shares the value. * * @defaultValue 90 */ angle?: Sampler; /** * How much a confetti's emission angle may differ from `angle`, in degrees, in either direction. * Most confetti flies close to `angle`, and becomes rarer and slower towards the edges of the cone, so the burst * shoots out as a jet rather than spraying evenly. Sampled once when the effect starts, so all confetti shares * the value. * * @defaultValue 50 */ spread?: Sampler; /** * How fast confetti starts out, in px/s. Its direction comes from `angle` and `spread`, and confetti towards * the edges of the cone starts out up to 45% slower. Drag slows the confetti down quickly, so it travels roughly * `startVelocity * drag / gravity` pixels before it starts to fall. * Sampled for each piece of confetti. * * @defaultValue range(800, 1500) */ startVelocity?: Sampler; /** * The initial size of the confetti, in pixels. Sampled for each piece of confetti. * * @defaultValue range(6, 16) */ size?: Sampler; /** * The lifetime of the confetti, in seconds. Sampled for each piece of confetti. * * @defaultValue range(2, 4) */ lifetime?: Sampler; /** * The colors that the confetti can take on. If an array of color strings is given, they are converted to * {@link Color} objects via {@link color | color()}, and a random one will be picked for each confetti. * Otherwise, the sampler is evaluated for each piece of confetti. * * @defaultValue randomHue({ l: 0.65, c: 0.15 }) */ colors?: string[] | Sampler; /** * The shapes that the confetti can take on. If any array of shapes is given, a random one will be picked * for each confetti. Otherwise, the sampler is evaluated for each piece of confetti. * * @defaultValue [{ type: "circle" }, { type: "square", cornerRadius: 0.2 }, { type: "square", aspectRatio: 0.2, cornerRadius: 0.05 }] */ shapes?: ParticleShape[] | Sampler; /** * The strength of gravity affecting the confetti, in px/s². * Sampled once when the effect starts, so all confetti shares the value. * * @defaultValue 800 */ gravity?: Sampler; /** * The speed at which falling confetti stops accelerating, in px/s, where drag balances gravity. * Lower values make confetti drift down more slowly, and also keep it from flying as far. Unlike the * {@link drag | drag()} behavior, this is a speed, not a rate. Sampled for each piece of confetti, so a range * lets the cloud spread out as it falls. * * @defaultValue range(130, 220) */ drag?: Sampler; } /** * Fires a burst of confetti in a cone, upwards by default, from the specified target. * * The confetti shoots out of the middle of the target, fast and mostly along `angle`. Drag slows it down within * a fraction of a second, and it then flutters down slowly like paper, swaying as it tumbles. It grows to its full * size over its first 0.03 seconds, fades out over its last second, and is lit with a glossy sheen (`peak: 1.5`). * * @summary Emits a burst of confetti. * * @param target - The target the confetti bursts out of. Its position and size are read once, when the effect starts. * @param options - Overrides of the default options. See {@link ConfettiOptions} for all fields. * @returns A handle to the running effect. * * @example * ```ts * button.addEventListener("click", () => confetti(button, { spread: 70 })); * ``` * * @group Effects */ declare function confetti(target: EffectTarget, options?: ConfettiOptions): Effect; /** * Options for {@link sparkles | sparkles()}. * * @summary How many sparkles to emit, and their color, size, speed and lifetime. * * @group Effects */ interface SparklesOptions extends BaseEffectOptions { /** * How many sparkles are emitted in total. They're split into four quick bursts over the first 0.3 seconds, so * the sparkles don't all appear at once. Sampled once, and rounded to the nearest integer. * * @defaultValue range(20, 40) */ count?: Sampler; /** * How fast sparkles burst outwards, in px/s. Drag slows them down quickly, after which they hover and settle. * Sampled for each sparkle. * * @defaultValue range(250, 480) */ startVelocity?: Sampler; /** * The size of the largest sparkles, in pixels. Most sparkles are smaller: each one is scaled down by a random * factor between 0.2 and 1, with small factors being far more likely, so a few big sparkles stand out among * many small ones. Sampled for each sparkle. * * @defaultValue 24 */ size?: Sampler; /** * How long the sparkles live, in seconds. Sampled for each sparkle. * * @defaultValue range(0.7, 1.4) */ lifetime?: Sampler; /** * The colors the sparkles can take on. An array of color strings is converted with * {@link color | color()} right away, and a random one is picked for each sparkle. A sampler is * evaluated for each sparkle instead. * * Sparkles aren't affected by lighting, so their colors appear exactly as given, except while they glint. * * @defaultValue gradient(["oklch(0.7 0.15 70)", "oklch(0.95 0.15 70)"]) */ colors?: string[] | Sampler; } /** * Bursts twinkling, four-pointed stars, golden by default, out of the specified target, in all directions. * * The sparkles appear in four quick bursts from the middle of the target, each spread evenly around it. They shoot * outwards, slow down quickly and hover, settling slightly downwards while they turn slowly. Occasionally each * sparkle catches the light: it briefly grows and flashes towards white, see {@link twinkle | twinkle()}. Most * sparkles are small, with a few big ones among them. They pop in almost instantly and shrink away over their * last quarter of a second. * * @summary Bursts twinkling golden sparkles out in all directions. * * @param target - The target the sparkles burst out of. Its position and size are read once, when the effect starts. * @param options - Overrides of the default options. See {@link SparklesOptions} for all fields. * @returns A handle to the running effect. * * @example * ```ts * button.addEventListener("click", () => sparkles(button, { count: 12 })); * ``` * * @group Effects */ declare function sparkles(target: EffectTarget, options?: SparklesOptions): Effect; /** * The error party.js throws when it's given invalid input, for example a color string it cannot parse. * * Its error message is prefixed with `[party-js]`. * * @summary The error party.js throws for invalid input. * * @example * ```ts * try { * confetti(button, { colors: gradient([]) }); * } catch (error) { * if (error instanceof PartyJSError) showHint(error.message); * else throw error; * } * ``` * * @group Utilities */ declare class PartyJSError extends Error { constructor(message: string); } export { type BaseEffectOptions, type Behavior, type BehaviorInit, type BehaviorInitContext, type BehaviorObject, type BehaviorUpdate, type BehaviorUpdateContext, type CircleShape, type Color, type ConfettiOptions, type CreateEffectOptions, type CreateLightingOptions, type CustomShape, type DiskEmissionShape, type Easing, type Effect, type EffectResult, type EffectTarget, type EmissionBurst, type EmissionSchedule, type EmissionShape, type GradientStop, type ImageShape, type LightingFn, type Live, type MeasuredTarget, type Particle, type ParticleInit, type ParticleShape, PartyJSError, type PathShape, type PolygonShape, type Quat, type RandomHueOptions, type RectEmissionShape, type ReducedMotion, type Rng, type Sampler, type SamplerContext, type SamplerFn, type SparklesOptions, type SquareShape, type StarShape, type TextShape, type TwinkleOptions, type Vec2, type Vec3, color, cone, confetti, createEffect, createLighting, drag, emitFrom, evaluateSampler, fade, gradient, gravity, linear, measureTarget, normal, pick, randomHue, randomOrientation, randomSpin, range, scale, setDefaultReducedMotion, sineIn, sineInOut, sineOut, sparkles, spread, twinkle };