GitHub
Translate

Opens Google Translate in a new tab. Website translation availability varies by region. Details

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).
Imperative Lifecycle • ts
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
mountednumberTotal active mounted effect instances.
visiblenumberInstances currently inside the viewport.
pausedEffectsnumberPaused, hidden, idle, or faulted instances.
activeLoopsnumber1 if main-thread CentralizedTicker is running, else 0.
registerednumberTotal registered plugins (8 built-in).
webglContexts / activeContextsnumberCurrently active WebGL2 contexts.
maxWebGLContextsnumberGlobal WebGL2 context budget limit.
suspendedContextsnumberInstances temporarily downgraded to CSS gradient fallback due to context budget.
fps / frameTimeMsnumberMeasured FPS and average frame time in milliseconds.
reducedMotionbooleanWhether OS prefers-reduced-motion: reduce is active.
protectionTier / protectionLabel0|1|2|3 / stringCurrent PerformanceGuard tier (normal, reduced-res, low-fps, survival).

Common FXOptions

Option Type Default Description
speednumber1.0Animation speed multiplier (WebGL effects).
quality'low' | 'medium' | 'high''medium'Controls DPR bounds, FBO dimensions, and shader iteration counts.
colorsstring | string[]Effect defaultPalette of 1–3 colors (any CSS color format; normalized via toHexColor).
color1, color2, color3stringEffect defaultIndividual color overrides when colors is omitted.
bgColorstringAuto themeCustom backdrop color or 'transparent'; mixes with effect colors via Additive Color Blending (ACD).
theme'auto' | 'light' | 'dark''auto'Theme detection mode.
lightColors / darkColorsstring | string[]—Explicit palettes for light and dark themes.
scrollColorsstring[] | [string, string][]—Color stops interpolated smoothly across container scroll progress.
trackScrollbooleanfalseEnables uScroll and uScrollVel uniforms.
layer'background' | 'overlay''background'Places canvas behind content (z-index: -1) or above cards (z-index: 10, transparent).
preserveBgbooleanfalse (true in overlay)Keeps underlying element background visible with premultiplied alpha.
adaptToSurfacebooleanfalseShifts hovered palette hues to maintain contrast over colored cards.
overlayOpacitynumber0.78Canvas CSS opacity when layer="overlay" (clamped 0.05–1).
interactivebooleantrueEnables pointer/touch uniforms and interaction FPS boost.
offscreenbooleantrueUses OffscreenCanvas Web Worker when supported.
dynamicResolutionbooleantrueEnables adaptive DPR scaling.
minDpr / maxDprnumberQuality-basedOverrides DPR floor/ceiling.
pauseWhenHiddenbooleantruePauses rendering when scrolled out of the viewport.
respectReducedMotionbooleantrueFreezes 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).
disableOnMobilebooleanfalseUnmounts/skips mounting below mobileBreakpoint (768px).
disableOnDesktopbooleanfalseUnmounts/skips mounting at or above mobileBreakpoint.
minWidth / maxWidthnumber—Custom viewport width bounds (px) for mounting the effect.
mobileBreakpointnumber768Custom 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 / Mobile-only Examples • html
<!-- 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:

Nesting tilt-3d + magnetic • html
<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.