konfeti - v0.6.0
    Preparing search index...

    Class WorkerKonfetiInstance

    Konfeti Instance that Simulates and Draws in a Web Worker. The canvas is handed to the worker as an OffscreenCanvas, so confetti stays smooth while the page is busy. Without OffscreenCanvas support it transparently falls back to the main thread (isWorker() is false). Created by createWorker().

    Index
    • Create Worker Instance.

      Parameters

      • canvas: HTMLCanvasElement | null = null

        Target Canvas (null creates a fullscreen overlay)

      • options: WorkerCreateOptions = {}

        Worker Instance Options

      • connect: WorkerConnector = ...

        Worker Connector (defaults to the bundled worker script)

      Returns WorkerKonfetiInstance

    • Destroy Instance. Stops the worker, removes listeners and the overlay canvas.

      Returns void

    • Start a Continuous Emitter. Streams particles at rate per second until stop(). What it follows is measured on the main thread and sent to the worker.

      Parameters

      Returns KonfetiEmitter

      Emitter Handle

      Error when destroyed, TypeError for an invalid rate or options that cannot be sent to a worker

      const stage = createWorker(canvas);
      const trail = stage.emit({ rate: 80, follow: "pointer", spread: 360 });
      trail.stop();
    • Fire Burst (or Several Bursts at Once).

      Parameters

      • input: WorkerFireInput = {}

        Worker-Safe Burst Options, or an Array of Them

      Returns KonfetiHandle

      Awaitable Burst Handle (rejects if the worker reports invalid options)

      Error when destroyed, TypeError when the options cannot be sent to the worker

      const stage = createWorker(canvas);
      await stage.fire({ particleCount: 300, spread: 360 });
    • Return Canvas Element.

      Returns HTMLCanvasElement

      Canvas Element

    • Return Live Particle Count.

      Returns number

      Particle Count (worker mode: updated a few times per second)

    • Return the Adaptive Quality Level. Always 0 without the adaptiveQuality option.

      Returns number

      Level: 0 full quality, 1 CSS resolution, 2 no shadows / shine / trails, 3 fewer particles (worker mode: updated a few times per second)

    • Return Counters. The worker-mode replacement for hooks (which cannot run in a worker): live, spawned and died particles and finished bursts. Works the same in main-thread fallback mode.

      Returns WorkerStats

      Counters (worker mode: updated a few times per second)

      const stage = createWorker(canvas);
      await stage.fire({ particleCount: 200 });
      stage.getStats(); // { live: 0, spawned: 200, died: 200, completed: 1 }
    • Return Destroyed State.

      Returns boolean

      Destroyed State

    • Check Whether pause() Is in Effect.

      Returns boolean

      Paused Flag

    • Check Browser Support for Worker Rendering.

      Parameters

      • canvas: HTMLCanvasElement

        Target Canvas

      Returns boolean

      Supported Flag

    • Return Worker Mode State.

      Returns boolean

      true when drawing happens in a worker, false for the main-thread fallback

    • Fire on Every Click. Bursts start at the click position unless the options set their own origin.

      Parameters

      • target: Element | Window

        Element (or window) to Listen On

      • Optionaloptions: WorkerFireInput | ((event: MouseEvent) => WorkerFireInput)

        Worker-Safe Burst Options, or a Function Building Them from the Click Event

      • settings: ClickOptions = {}

        Trigger Event and Burst Callback

      Returns () => void

      Unsubscribe Function

    • Pause Everything. Freezes every running burst on its current frame; bursts fired while paused wait as well.

      Returns void

    • Stop All Bursts and Clear Canvas.

      Returns void

    • Resume After pause().

      Returns void