@votax572002/fluxfx 0.1.1 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,4 +1,9 @@
1
+ type ProtectionTier = 0 | 1 | 2 | 3;
2
+ type ProtectionLabel = 'normal' | 'reduced-res' | 'low-fps' | 'survival';
3
+
1
4
  type QualityLevel = 'low' | 'medium' | 'high';
5
+ type ThemeMode = 'auto' | 'light' | 'dark';
6
+ type LayerMode = 'background' | 'overlay';
2
7
  type UniformValue = number | [number, number] | [number, number, number] | [number, number, number, number] | Float32Array;
3
8
  interface PerformanceOptions {
4
9
  /** Enable adaptive DPR scaling when FPS drops (default: true) */
@@ -16,10 +21,37 @@ interface PerformanceOptions {
16
21
  /** Track container scroll progress (uScroll) and velocity (uScrollVel) (default: false) */
17
22
  trackScroll?: boolean;
18
23
  }
24
+ interface FXInstance {
25
+ readonly isWebGL?: boolean;
26
+ update?: (time: number, delta: number) => void;
27
+ /** Hot-update options/uniforms without destroying & remounting WebGL context */
28
+ setOptions?: (options: FXOptions) => void;
29
+ resize?: () => void;
30
+ pause?: () => void;
31
+ resume?: () => void;
32
+ /** Optional: returns true when the effect is settled/idle and needs no ticks */
33
+ isIdle?: () => boolean;
34
+ /** Optional: Engine registers a wake callback so an idle effect can restart the ticker */
35
+ onWake?: (wake: () => void) => void;
36
+ destroy: () => void;
37
+ }
38
+ interface FXPlugin {
39
+ name: string;
40
+ mount: (el: HTMLElement, options: FXOptions) => FXInstance;
41
+ }
19
42
  interface FXOptions extends PerformanceOptions {
20
43
  speed?: number;
21
44
  quality?: QualityLevel;
45
+ bgColor?: string;
22
46
  colors?: string | [string, string, string] | string[];
47
+ theme?: ThemeMode;
48
+ lightColors?: string | [string, string, string] | string[];
49
+ darkColors?: string | [string, string, string] | string[];
50
+ scrollColors?: string[] | Array<[string, string]>;
51
+ layer?: LayerMode;
52
+ preserveBg?: boolean;
53
+ adaptToSurface?: boolean;
54
+ overlayOpacity?: number;
23
55
  color1?: string;
24
56
  color2?: string;
25
57
  color3?: string;
@@ -31,27 +63,22 @@ interface FXOptions extends PerformanceOptions {
31
63
  strength?: number;
32
64
  [key: string]: unknown;
33
65
  }
34
- interface FXInstance {
35
- update?: (time: number, delta: number) => void;
36
- /** Hot-update options/uniforms without destroying & remounting WebGL context */
37
- setOptions?: (options: FXOptions) => void;
38
- resize?: () => void;
39
- pause?: () => void;
40
- resume?: () => void;
41
- destroy: () => void;
42
- }
43
- interface FXPlugin {
44
- name: string;
45
- mount: (el: HTMLElement, options: FXOptions) => FXInstance;
46
- }
47
66
 
48
67
  interface FluxStats {
49
68
  mounted: number;
50
69
  visible: number;
70
+ pausedEffects: number;
51
71
  activeLoops: number;
52
72
  registered: number;
53
73
  webglContexts: number;
74
+ activeContexts: number;
75
+ maxWebGLContexts: number;
76
+ suspendedContexts: number;
77
+ fps: number;
78
+ frameTimeMs: number;
54
79
  reducedMotion: boolean;
80
+ protectionTier: ProtectionTier;
81
+ protectionLabel: ProtectionLabel;
55
82
  }
56
83
  declare class FluxEngine {
57
84
  private plugins;
@@ -60,11 +87,17 @@ declare class FluxEngine {
60
87
  private visibilityObserver;
61
88
  private visibilityCallbacks;
62
89
  private removeTicker;
90
+ private removeVisibilitySub;
63
91
  private ensureObserver;
92
+ private ensureVisibilitySub;
93
+ private hasActiveTickWork;
94
+ private syncTickerState;
64
95
  private ensureTicker;
65
- private stopTickerIfEmpty;
96
+ private cleanupEmptyEngine;
97
+ private bindWake;
66
98
  register(plugin: FXPlugin): this;
67
99
  has(name: string): boolean;
100
+ setMaxWebGLContexts(limit: number): void;
68
101
  getStats(): FluxStats;
69
102
  /**
70
103
  * Mounts an effect on a DOM element and returns a cleanup function.
@@ -96,12 +129,37 @@ interface WebGLQuadOptions extends PerformanceOptions {
96
129
  speed?: number;
97
130
  quality?: QualityLevel;
98
131
  colors?: [string, string, string] | string[];
132
+ theme?: ThemeMode;
133
+ lightColors?: string | [string, string, string] | string[];
134
+ darkColors?: string | [string, string, string] | string[];
135
+ scrollColors?: string[] | Array<[string, string]>;
136
+ layer?: LayerMode;
137
+ preserveBg?: boolean;
138
+ adaptToSurface?: boolean;
139
+ overlayOpacity?: number;
99
140
  uniforms?: Record<string, UniformValue>;
100
141
  interactive?: boolean;
101
142
  }
102
143
  declare class WebGLQuad {
103
144
  private static _activeContexts;
145
+ private static _maxContexts;
146
+ private static instances;
147
+ private static recycledMainContexts;
148
+ private static acquireRecycledMainContext;
149
+ private static recycleMainContext;
104
150
  static get activeContexts(): number;
151
+ static get maxActiveContexts(): number;
152
+ static get suspendedContexts(): number;
153
+ static setMaxActiveContexts(limit: number): void;
154
+ private static pickEvictionVictim;
155
+ private static ensureContextBudget;
156
+ private static enforceContextBudget;
157
+ private static reclaimBudgetForWaiting;
158
+ static getRenderStats(): {
159
+ activeRendering: number;
160
+ fps: number;
161
+ frameTimeMs: number;
162
+ };
105
163
  private container;
106
164
  private canvas;
107
165
  private options;
@@ -118,6 +176,13 @@ declare class WebGLQuad {
118
176
  private vbo;
119
177
  private dynamicRes;
120
178
  private lastRenderNow;
179
+ private lastDrawNow;
180
+ private lastTargetFps;
181
+ private prevFrameDrew;
182
+ private avgDrawDeltaMs;
183
+ private boostUntil;
184
+ private reportedFps;
185
+ private reportedFrameTimeMs;
121
186
  private elapsedSec;
122
187
  private lastDeltaSec;
123
188
  private currentSpeed;
@@ -131,6 +196,7 @@ declare class WebGLQuad {
131
196
  private readIdx;
132
197
  private writeIdx;
133
198
  private feedbackScale;
199
+ private baseFeedbackMaxDim;
134
200
  private feedbackMaxDim;
135
201
  private feedbackFloat;
136
202
  private customUniforms;
@@ -154,14 +220,79 @@ declare class WebGLQuad {
154
220
  private isReducedMotion;
155
221
  private respectReducedMotion;
156
222
  private isDestroyed;
223
+ private wakeCallback;
224
+ private ambientFps;
225
+ private activeFps;
226
+ private protectionTier;
227
+ private isSurvivalSuspended;
228
+ private unsubscribeGuard;
229
+ private isBudgetSuspended;
230
+ private lastActiveAt;
231
+ private hasDocVisibilityListener;
157
232
  private interactive;
158
233
  private hasPointerListener;
159
234
  private countedContext;
235
+ private isBodyMount;
236
+ private origBodyMinHeight;
237
+ private themeMode;
238
+ private resolvedDarkTheme;
239
+ private currentTheme;
240
+ private themeTweenRaf;
241
+ private colorSchemeQuery;
242
+ private themeMutationObserver;
243
+ private basePaletteRgb;
244
+ private activePaletteRgb;
245
+ private scrollStopsRgb;
246
+ private lastScrollColorT;
247
+ private hasScrollColorListener;
248
+ private scrollColorRaf;
249
+ private hasTouchListener;
250
+ private touchBurstTimer;
251
+ private touchLeaveTimer;
252
+ private layerMode;
253
+ private adaptToSurface;
254
+ private rawBasePaletteRgb;
255
+ private lastSurfaceEl;
256
+ private lastSurfaceKey;
257
+ private lastSurfaceCheckAt;
258
+ private isSurfaceAdapted;
160
259
  constructor(container: HTMLElement, options: WebGLQuadOptions);
260
+ private boostInteraction;
261
+ private resetFrameTracking;
262
+ private resolveTierConfig;
161
263
  private resolveDprBounds;
162
264
  private computeScrollProgress;
163
265
  private markContextActive;
164
266
  private markContextReleased;
267
+ private uniformVec3Css;
268
+ private applyBudgetFallbackStyle;
269
+ private syncDocVisibilityListener;
270
+ private releaseMainThreadContext;
271
+ private suspendContextForBudget;
272
+ private restoreContextFromBudget;
273
+ private computeEffectiveQuality;
274
+ private shouldPreserveBg;
275
+ private applyCanvasLayerStyle;
276
+ private startPaletteTween;
277
+ private inspectSurfaceFromTarget;
278
+ private parseColorList;
279
+ private parseScrollStops;
280
+ private detectDarkTheme;
281
+ private resolveTargetPalette;
282
+ private toTriplet;
283
+ private pushUniformBatch;
284
+ private startThemeTransition;
285
+ private handleThemeChange;
286
+ private bindThemeWatchers;
287
+ private unbindThemeWatchers;
288
+ private updateScrollColorShift;
289
+ private handleScrollColorEvent;
290
+ private syncScrollColorListener;
291
+ private getLocalTouchCoords;
292
+ private handleTouchStart;
293
+ private handleTouchMove;
294
+ private handleTouchEnd;
295
+ private syncTouchListener;
165
296
  private seedUniformsFromOptions;
166
297
  private fallbackToMainThread;
167
298
  private initOffscreenMode;
@@ -177,6 +308,8 @@ declare class WebGLQuad {
177
308
  private bindCommonUniformsMain;
178
309
  private drawMainThreadFrame;
179
310
  render(_timeSec?: number, _deltaSec?: number): void;
311
+ private applyProtectionState;
312
+ private handleProtectionTierChange;
180
313
  private syncDprBounds;
181
314
  private handleDprChange;
182
315
  private watchDevicePixelRatio;
@@ -184,6 +317,8 @@ declare class WebGLQuad {
184
317
  private applyReducedMotionState;
185
318
  private handleReducedMotionChange;
186
319
  private getLocalPointerCoords;
320
+ private syncInteractiveAttr;
321
+ private isShadowedByChildInteractive;
187
322
  private handlePointerEnter;
188
323
  private handlePointerMove;
189
324
  private handlePointerLeave;
@@ -196,11 +331,24 @@ declare class WebGLQuad {
196
331
  private bindObservers;
197
332
  setUniform(name: string, value: UniformValue): void;
198
333
  setColor(uniformName: string, color: string): void;
334
+ get isIdle(): boolean;
335
+ onWake(cb: (() => void) | null): void;
199
336
  pause(): void;
200
337
  resume(): void;
201
338
  destroy(): void;
202
339
  }
203
340
 
341
+ interface WebGLEffectConfig {
342
+ name: string;
343
+ fragmentShader: string;
344
+ vertexShader?: string;
345
+ feedbackShader?: string;
346
+ feedbackFloat?: boolean;
347
+ defaultColors: [string, string, string];
348
+ resolveUniforms?: (options: FXOptions) => Record<string, UniformValue>;
349
+ }
350
+ declare function createWebGLEffect(config: WebGLEffectConfig): FXPlugin;
351
+
204
352
  declare const FluxFX: FluxEngine;
205
353
 
206
- export { type FXInstance, type FXOptions, type FXPlugin, FluxEngine, FluxFX, WebGLQuad };
354
+ export { type FXInstance, type FXOptions, type FXPlugin, FluxEngine, FluxFX, type FluxStats, type LayerMode, type QualityLevel, type ThemeMode, type WebGLEffectConfig, WebGLQuad, createWebGLEffect };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,9 @@
1
+ type ProtectionTier = 0 | 1 | 2 | 3;
2
+ type ProtectionLabel = 'normal' | 'reduced-res' | 'low-fps' | 'survival';
3
+
1
4
  type QualityLevel = 'low' | 'medium' | 'high';
5
+ type ThemeMode = 'auto' | 'light' | 'dark';
6
+ type LayerMode = 'background' | 'overlay';
2
7
  type UniformValue = number | [number, number] | [number, number, number] | [number, number, number, number] | Float32Array;
3
8
  interface PerformanceOptions {
4
9
  /** Enable adaptive DPR scaling when FPS drops (default: true) */
@@ -16,10 +21,37 @@ interface PerformanceOptions {
16
21
  /** Track container scroll progress (uScroll) and velocity (uScrollVel) (default: false) */
17
22
  trackScroll?: boolean;
18
23
  }
24
+ interface FXInstance {
25
+ readonly isWebGL?: boolean;
26
+ update?: (time: number, delta: number) => void;
27
+ /** Hot-update options/uniforms without destroying & remounting WebGL context */
28
+ setOptions?: (options: FXOptions) => void;
29
+ resize?: () => void;
30
+ pause?: () => void;
31
+ resume?: () => void;
32
+ /** Optional: returns true when the effect is settled/idle and needs no ticks */
33
+ isIdle?: () => boolean;
34
+ /** Optional: Engine registers a wake callback so an idle effect can restart the ticker */
35
+ onWake?: (wake: () => void) => void;
36
+ destroy: () => void;
37
+ }
38
+ interface FXPlugin {
39
+ name: string;
40
+ mount: (el: HTMLElement, options: FXOptions) => FXInstance;
41
+ }
19
42
  interface FXOptions extends PerformanceOptions {
20
43
  speed?: number;
21
44
  quality?: QualityLevel;
45
+ bgColor?: string;
22
46
  colors?: string | [string, string, string] | string[];
47
+ theme?: ThemeMode;
48
+ lightColors?: string | [string, string, string] | string[];
49
+ darkColors?: string | [string, string, string] | string[];
50
+ scrollColors?: string[] | Array<[string, string]>;
51
+ layer?: LayerMode;
52
+ preserveBg?: boolean;
53
+ adaptToSurface?: boolean;
54
+ overlayOpacity?: number;
23
55
  color1?: string;
24
56
  color2?: string;
25
57
  color3?: string;
@@ -31,27 +63,22 @@ interface FXOptions extends PerformanceOptions {
31
63
  strength?: number;
32
64
  [key: string]: unknown;
33
65
  }
34
- interface FXInstance {
35
- update?: (time: number, delta: number) => void;
36
- /** Hot-update options/uniforms without destroying & remounting WebGL context */
37
- setOptions?: (options: FXOptions) => void;
38
- resize?: () => void;
39
- pause?: () => void;
40
- resume?: () => void;
41
- destroy: () => void;
42
- }
43
- interface FXPlugin {
44
- name: string;
45
- mount: (el: HTMLElement, options: FXOptions) => FXInstance;
46
- }
47
66
 
48
67
  interface FluxStats {
49
68
  mounted: number;
50
69
  visible: number;
70
+ pausedEffects: number;
51
71
  activeLoops: number;
52
72
  registered: number;
53
73
  webglContexts: number;
74
+ activeContexts: number;
75
+ maxWebGLContexts: number;
76
+ suspendedContexts: number;
77
+ fps: number;
78
+ frameTimeMs: number;
54
79
  reducedMotion: boolean;
80
+ protectionTier: ProtectionTier;
81
+ protectionLabel: ProtectionLabel;
55
82
  }
56
83
  declare class FluxEngine {
57
84
  private plugins;
@@ -60,11 +87,17 @@ declare class FluxEngine {
60
87
  private visibilityObserver;
61
88
  private visibilityCallbacks;
62
89
  private removeTicker;
90
+ private removeVisibilitySub;
63
91
  private ensureObserver;
92
+ private ensureVisibilitySub;
93
+ private hasActiveTickWork;
94
+ private syncTickerState;
64
95
  private ensureTicker;
65
- private stopTickerIfEmpty;
96
+ private cleanupEmptyEngine;
97
+ private bindWake;
66
98
  register(plugin: FXPlugin): this;
67
99
  has(name: string): boolean;
100
+ setMaxWebGLContexts(limit: number): void;
68
101
  getStats(): FluxStats;
69
102
  /**
70
103
  * Mounts an effect on a DOM element and returns a cleanup function.
@@ -96,12 +129,37 @@ interface WebGLQuadOptions extends PerformanceOptions {
96
129
  speed?: number;
97
130
  quality?: QualityLevel;
98
131
  colors?: [string, string, string] | string[];
132
+ theme?: ThemeMode;
133
+ lightColors?: string | [string, string, string] | string[];
134
+ darkColors?: string | [string, string, string] | string[];
135
+ scrollColors?: string[] | Array<[string, string]>;
136
+ layer?: LayerMode;
137
+ preserveBg?: boolean;
138
+ adaptToSurface?: boolean;
139
+ overlayOpacity?: number;
99
140
  uniforms?: Record<string, UniformValue>;
100
141
  interactive?: boolean;
101
142
  }
102
143
  declare class WebGLQuad {
103
144
  private static _activeContexts;
145
+ private static _maxContexts;
146
+ private static instances;
147
+ private static recycledMainContexts;
148
+ private static acquireRecycledMainContext;
149
+ private static recycleMainContext;
104
150
  static get activeContexts(): number;
151
+ static get maxActiveContexts(): number;
152
+ static get suspendedContexts(): number;
153
+ static setMaxActiveContexts(limit: number): void;
154
+ private static pickEvictionVictim;
155
+ private static ensureContextBudget;
156
+ private static enforceContextBudget;
157
+ private static reclaimBudgetForWaiting;
158
+ static getRenderStats(): {
159
+ activeRendering: number;
160
+ fps: number;
161
+ frameTimeMs: number;
162
+ };
105
163
  private container;
106
164
  private canvas;
107
165
  private options;
@@ -118,6 +176,13 @@ declare class WebGLQuad {
118
176
  private vbo;
119
177
  private dynamicRes;
120
178
  private lastRenderNow;
179
+ private lastDrawNow;
180
+ private lastTargetFps;
181
+ private prevFrameDrew;
182
+ private avgDrawDeltaMs;
183
+ private boostUntil;
184
+ private reportedFps;
185
+ private reportedFrameTimeMs;
121
186
  private elapsedSec;
122
187
  private lastDeltaSec;
123
188
  private currentSpeed;
@@ -131,6 +196,7 @@ declare class WebGLQuad {
131
196
  private readIdx;
132
197
  private writeIdx;
133
198
  private feedbackScale;
199
+ private baseFeedbackMaxDim;
134
200
  private feedbackMaxDim;
135
201
  private feedbackFloat;
136
202
  private customUniforms;
@@ -154,14 +220,79 @@ declare class WebGLQuad {
154
220
  private isReducedMotion;
155
221
  private respectReducedMotion;
156
222
  private isDestroyed;
223
+ private wakeCallback;
224
+ private ambientFps;
225
+ private activeFps;
226
+ private protectionTier;
227
+ private isSurvivalSuspended;
228
+ private unsubscribeGuard;
229
+ private isBudgetSuspended;
230
+ private lastActiveAt;
231
+ private hasDocVisibilityListener;
157
232
  private interactive;
158
233
  private hasPointerListener;
159
234
  private countedContext;
235
+ private isBodyMount;
236
+ private origBodyMinHeight;
237
+ private themeMode;
238
+ private resolvedDarkTheme;
239
+ private currentTheme;
240
+ private themeTweenRaf;
241
+ private colorSchemeQuery;
242
+ private themeMutationObserver;
243
+ private basePaletteRgb;
244
+ private activePaletteRgb;
245
+ private scrollStopsRgb;
246
+ private lastScrollColorT;
247
+ private hasScrollColorListener;
248
+ private scrollColorRaf;
249
+ private hasTouchListener;
250
+ private touchBurstTimer;
251
+ private touchLeaveTimer;
252
+ private layerMode;
253
+ private adaptToSurface;
254
+ private rawBasePaletteRgb;
255
+ private lastSurfaceEl;
256
+ private lastSurfaceKey;
257
+ private lastSurfaceCheckAt;
258
+ private isSurfaceAdapted;
160
259
  constructor(container: HTMLElement, options: WebGLQuadOptions);
260
+ private boostInteraction;
261
+ private resetFrameTracking;
262
+ private resolveTierConfig;
161
263
  private resolveDprBounds;
162
264
  private computeScrollProgress;
163
265
  private markContextActive;
164
266
  private markContextReleased;
267
+ private uniformVec3Css;
268
+ private applyBudgetFallbackStyle;
269
+ private syncDocVisibilityListener;
270
+ private releaseMainThreadContext;
271
+ private suspendContextForBudget;
272
+ private restoreContextFromBudget;
273
+ private computeEffectiveQuality;
274
+ private shouldPreserveBg;
275
+ private applyCanvasLayerStyle;
276
+ private startPaletteTween;
277
+ private inspectSurfaceFromTarget;
278
+ private parseColorList;
279
+ private parseScrollStops;
280
+ private detectDarkTheme;
281
+ private resolveTargetPalette;
282
+ private toTriplet;
283
+ private pushUniformBatch;
284
+ private startThemeTransition;
285
+ private handleThemeChange;
286
+ private bindThemeWatchers;
287
+ private unbindThemeWatchers;
288
+ private updateScrollColorShift;
289
+ private handleScrollColorEvent;
290
+ private syncScrollColorListener;
291
+ private getLocalTouchCoords;
292
+ private handleTouchStart;
293
+ private handleTouchMove;
294
+ private handleTouchEnd;
295
+ private syncTouchListener;
165
296
  private seedUniformsFromOptions;
166
297
  private fallbackToMainThread;
167
298
  private initOffscreenMode;
@@ -177,6 +308,8 @@ declare class WebGLQuad {
177
308
  private bindCommonUniformsMain;
178
309
  private drawMainThreadFrame;
179
310
  render(_timeSec?: number, _deltaSec?: number): void;
311
+ private applyProtectionState;
312
+ private handleProtectionTierChange;
180
313
  private syncDprBounds;
181
314
  private handleDprChange;
182
315
  private watchDevicePixelRatio;
@@ -184,6 +317,8 @@ declare class WebGLQuad {
184
317
  private applyReducedMotionState;
185
318
  private handleReducedMotionChange;
186
319
  private getLocalPointerCoords;
320
+ private syncInteractiveAttr;
321
+ private isShadowedByChildInteractive;
187
322
  private handlePointerEnter;
188
323
  private handlePointerMove;
189
324
  private handlePointerLeave;
@@ -196,11 +331,24 @@ declare class WebGLQuad {
196
331
  private bindObservers;
197
332
  setUniform(name: string, value: UniformValue): void;
198
333
  setColor(uniformName: string, color: string): void;
334
+ get isIdle(): boolean;
335
+ onWake(cb: (() => void) | null): void;
199
336
  pause(): void;
200
337
  resume(): void;
201
338
  destroy(): void;
202
339
  }
203
340
 
341
+ interface WebGLEffectConfig {
342
+ name: string;
343
+ fragmentShader: string;
344
+ vertexShader?: string;
345
+ feedbackShader?: string;
346
+ feedbackFloat?: boolean;
347
+ defaultColors: [string, string, string];
348
+ resolveUniforms?: (options: FXOptions) => Record<string, UniformValue>;
349
+ }
350
+ declare function createWebGLEffect(config: WebGLEffectConfig): FXPlugin;
351
+
204
352
  declare const FluxFX: FluxEngine;
205
353
 
206
- export { type FXInstance, type FXOptions, type FXPlugin, FluxEngine, FluxFX, WebGLQuad };
354
+ export { type FXInstance, type FXOptions, type FXPlugin, FluxEngine, FluxFX, type FluxStats, type LayerMode, type QualityLevel, type ThemeMode, type WebGLEffectConfig, WebGLQuad, createWebGLEffect };