Engine & Core API
Every method exposed by the FluxFX singleton (FluxEngine) and core factory helpers.
FluxFX Engine Methods
| Method | Signature | Description |
|---|---|---|
FluxFX.init | (root?: ParentNode) => void | Scans root (defaults to document) for [data-fx] elements once DOM is ready. |
FluxFX.scan | (root?: ParentNode) => void | Immediately scans root for unmounted [data-fx] nodes and mounts them. |
FluxFX.apply | (el: HTMLElement, name: string, options?: FXOptions) => () => void | Mounts an effect onto an HTMLElement and returns an idempotent destroy() cleanup function. |
FluxFX.update | (el: HTMLElement, name: string, options?: FXOptions) => boolean | Hot-updates options on an active effect without destroying its WebGL context (remounts in place if plugin lacks setOptions). |
FluxFX.destroyAll | () => void | Cleanly destroys all active effects, observers, and WebGL contexts on the page. |
FluxFX.getStats | () => FluxStats | Returns live runtime telemetry (mounted count, FPS, WebGL context budget, PerformanceGuard tier). |
FluxFX.register | (plugin: FXPlugin) => this | Registers a custom effect plugin (chainable). |
FluxFX.has | (name: string) => boolean | Checks whether an effect plugin is registered. |
FluxFX.setMaxWebGLContexts | (limit: number) => void | Adjusts the global WebGL2 context budget cap (default: 6 Safari/mobile, 8 desktop). |
import { FluxFX } from '@votax572002/fluxfx';
const card = document.getElementById('showcase')!;
const cleanup = FluxFX.apply(card, 'prism-3d', { shape: 'prism', quality: 'high' });
// Hot-update shape & colors without losing WebGL context
FluxFX.update(card, 'prism-3d', { shape: 'torus', gloss: 1.5 });
// Later on unmount
cleanup(); FluxStats Reference (FluxFX.getStats())
| Field | Type | Meaning |
|---|---|---|
mounted | number | Total active mounted effect instances. |
visible | number | Instances currently inside the viewport. |
pausedEffects | number | Paused, hidden, idle, or faulted instances. |
activeLoops | number | 1 if main-thread CentralizedTicker is running, else 0. |
registered | number | Total registered plugins (8 built-in). |
webglContexts / activeContexts | number | Currently active WebGL2 contexts. |
maxWebGLContexts | number | Global WebGL2 context budget limit. |
suspendedContexts | number | Instances temporarily downgraded to CSS gradient fallback due to context budget. |
fps / frameTimeMs | number | Measured FPS and average frame time in milliseconds. |
reducedMotion | boolean | Whether OS prefers-reduced-motion: reduce is active. |
protectionTier / protectionLabel | 0|1|2|3 / string | Current PerformanceGuard tier (normal, reduced-res, low-fps, survival). |
Common FXOptions
| Option | Type | Default | Description |
|---|---|---|---|
speed | number | 1.0 | Animation speed multiplier (WebGL effects). |
quality | 'low' | 'medium' | 'high' | 'medium' | Controls DPR bounds, FBO dimensions, and shader iteration counts. |
colors | string | string[] | Effect default | Palette of 1–3 colors (any CSS color format; normalized via toHexColor). |
color1, color2, color3 | string | Effect default | Individual color overrides when colors is omitted. |
bgColor | string | Auto theme | Custom backdrop color or 'transparent'; mixes with effect colors via Additive Color Blending (ACD). |
theme | 'auto' | 'light' | 'dark' | 'auto' | Theme detection mode. |
lightColors / darkColors | string | string[] | — | Explicit palettes for light and dark themes. |
scrollColors | string[] | [string, string][] | — | Color stops interpolated smoothly across container scroll progress. |
trackScroll | boolean | false | Enables uScroll and uScrollVel uniforms. |
layer | 'background' | 'overlay' | 'background' | Places canvas behind content (z-index: -1) or above cards (z-index: 10, transparent). |
preserveBg | boolean | false (true in overlay) | Keeps underlying element background visible with premultiplied alpha. |
adaptToSurface | boolean | false | Shifts hovered palette hues to maintain contrast over colored cards. |
overlayOpacity | number | 0.78 | Canvas CSS opacity when layer="overlay" (clamped 0.05–1). |
interactive | boolean | true | Enables pointer/touch uniforms and interaction FPS boost. |
offscreen | boolean | true | Uses OffscreenCanvas Web Worker when supported. |
dynamicResolution | boolean | true | Enables adaptive DPR scaling. |
minDpr / maxDpr | number | Quality-based | Overrides DPR floor/ceiling. |
pauseWhenHidden | boolean | true | Pauses rendering when scrolled out of the viewport. |
respectReducedMotion | boolean | true | Freezes on a single frame when OS Reduce Motion is enabled. |
device | 'all' | 'desktop' | 'mobile' | 'tablet' | 'all' | Mounts effect only on matching viewport widths (live resize reactive). |
disableOnMobile | boolean | false | Unmounts/skips mounting below mobileBreakpoint (768px). |
disableOnDesktop | boolean | false | Unmounts/skips mounting at or above mobileBreakpoint. |
minWidth / maxWidth | number | — | Custom viewport width bounds (px) for mounting the effect. |
mobileBreakpoint | number | 768 | Custom pixel threshold between mobile and desktop modes. |
Device & Viewport Targeting (Desktop vs Mobile)
Every FluxFX WebGL2 and DOM effect supports responsive device targeting out of the box. When a rule excludes mobile (e.g., device="desktop"), FluxFX skips WebGL/DOM mounting completely on phones (saving 100% GPU & battery) and automatically mounts/unmounts if the window resizes across the breakpoint.
<!-- Desktop only (>= 768px) -->
<section data-fx="prism-3d" data-fx-device="desktop" style="min-height: 60vh;"></section>
<!-- Mobile only (< 768px) -->
<div data-fx="aurora" data-fx-device="mobile" style="min-height: 45vh;"></div>
<!-- Custom width range in HTML / React -->
<div data-fx="tilt-3d" data-fx-disable-on-mobile data-fx-mobile-breakpoint="900">Card</div> Combining Effects
You can stack a WebGL effect and a DOM effect on the same element (e.g. data-fx="liquid-metal tilt-3d"). Avoid putting tilt-3d and magnetic on the exact same element since both write CSS transform — wrap them parent/child instead:
<div data-fx="magnetic" data-fx-strength="0.3">
<div data-fx="tilt-3d" data-fx-max-tilt="10">Card Content</div>
</div> Core Exports & Types
src/index.ts exports FluxFX, FluxEngine, WebGLQuad, createWebGLEffect, and types FluxStats, FXPlugin, FXInstance, FXOptions, DeviceTarget, WebGLEffectConfig, LayerMode, PrismShape, QualityLevel, and ThemeMode.