lensfx 0.1.1 → 0.1.3

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.ts CHANGED
@@ -1,372 +1,7 @@
1
+ import { LensParams } from './vanilla.js';
2
+ export { DEFAULT_LENS_PARAMS, DomeConstants, LensInstance, LensOptions, MapGeneratorInput, MapGeneratorOutput, QRRefractionRenderer, QRRendererOptions, SLIDER_DARK_OVERRIDES, SLIDER_GLASS_DEFAULTS, SLIDER_LIGHT_OVERRIDES, SLIDER_SAFARI_OVERRIDES, SWITCH_DARK_OVERRIDES, SWITCH_GLASS_DEFAULTS, SWITCH_LIGHT_OVERRIDES, VideoRefractionRenderer, VideoRendererOptions, colorMatrixValues, computeDomeConstants, createDisplacementMapGeneratorSync, createLens, domeGradient, erf, generateDisplacementMapAsync, getSvgMaskDataUri } from './vanilla.js';
1
3
  import React from 'react';
2
4
 
3
- /**
4
- * lensfx — Engine Layer: Types & Constants
5
- *
6
- * Pure TypeScript — no React, no DOM. Can be imported in any environment.
7
- */
8
- /** All optical parameters that control how a single lens looks and distorts. */
9
- interface LensParams {
10
- /** Lens width in pixels. */
11
- lensW: number;
12
- /** Lens height in pixels. */
13
- lensH: number;
14
- /** Lens corner radius in pixels. */
15
- borderRadius: number;
16
- /** Refraction depth/strength — higher = more distortion. Range: 0–10. */
17
- depth: number;
18
- /** Chromatic aberration split amount. 0 = monochromatic, 1 = full RGB split. */
19
- chromaAmount: number;
20
- /** Horizontal displacement scale. 0 = no lateral displacement. */
21
- scaleX: number;
22
- /** Vertical displacement scale. 0 = no vertical displacement. */
23
- scaleY: number;
24
- /** Resolution of the displacement map canvas (power-of-two recommended). */
25
- mapSize: number;
26
- /** Gaussian blur radius applied to the background behind the lens (px). */
27
- blurAmount: number;
28
- /** If true, clips displacement strictly to the lens SDF boundary. */
29
- sdfBoundary: boolean;
30
- /** If true, applies an erf-smoothed falloff at the lens edge. */
31
- edgeFalloff: boolean;
32
- /** Additive brightness overlay inside the lens. Positive = lighter, negative = darker. Range: -1 to 1. */
33
- brightness: number;
34
- /** Intensity of the specular highlight. Range: 0–3. */
35
- specularStrength: number;
36
- /** Angle of the specular directional light in degrees. */
37
- specularRotation: number;
38
- /** If true, uses dark (shadow) specular mode instead of bright. */
39
- specularDark: boolean;
40
- /** Uniform tint applied inside the lens. Range: -1 (black) to 1 (white). */
41
- tint: number;
42
- /** Strength of the inner glow band. Range: 0–1. */
43
- glowStrength: number;
44
- /** Angular spread of the glow band, normalised. Range: 0–1. */
45
- glowSpread: number;
46
- /** Exponent controlling glow falloff curve. Higher = sharper band. */
47
- glowExponent: number;
48
- /** Strength of the edge specular ring (separate from inner glow). Range: 0–1. */
49
- edgeStrength: number;
50
- /** Thickness of the edge specular ring in pixels. */
51
- edgeWidth: number;
52
- /** Exponent controlling edge ring falloff curve. */
53
- edgeExponent: number;
54
- /** Height of the ellipsoid dome above the lens surface in pixels. */
55
- domeDepth: number;
56
- /** How much to reduce displacement magnitude at corners (0 = no splay, 1 = full splay). */
57
- splayAmount: number;
58
- /** Box shadow applied to the lens container (outer drop shadow). */
59
- edgeShadow?: string;
60
- /** Inset box shadow applied to the lens container. */
61
- edgeInsetShadow?: string;
62
- /** Secondary rest-state shadow (e.g. when the slider thumb is at rest). */
63
- restEdgeShadow?: string;
64
- }
65
- /** Precomputed geometric constants for dome curvature. */
66
- interface DomeConstants {
67
- /** Horizontal sphere radius for dome curvature. */
68
- Rx: number;
69
- /** Vertical sphere radius for dome curvature. */
70
- Ry: number;
71
- /** Normalised scale factor for the X gradient (trapezoidal integration). */
72
- scaleX: number;
73
- /** Normalised scale factor for the Y gradient (trapezoidal integration). */
74
- scaleY: number;
75
- }
76
- /** Input to the synchronous displacement map generator. */
77
- interface MapGeneratorInput {
78
- lensHalfWidth: number;
79
- lensHalfHeight: number;
80
- borderRadius: number;
81
- depth: number;
82
- sdfBoundary: boolean;
83
- edgeFalloff: boolean;
84
- specularRotation: number;
85
- glowStrength: number;
86
- glowSpread: number;
87
- glowExponent: number;
88
- edgeStrength: number;
89
- edgeWidth: number;
90
- edgeExponent: number;
91
- domeDepth: number;
92
- splayAmount: number;
93
- }
94
- /** Output from the displacement map generator. */
95
- interface MapGeneratorOutput {
96
- /** PNG data URL of the generated displacement map. */
97
- dataUrl: string;
98
- /** Time taken for the pixel loop, in milliseconds. */
99
- loopMs: number;
100
- /** Time taken for canvas.toDataURL encoding, in milliseconds. */
101
- encodeMs: number;
102
- }
103
- /** Zero-refraction baseline — all effects disabled. */
104
- declare const DEFAULT_LENS_PARAMS: LensParams;
105
- /** LensSwitch base optical parameters. */
106
- declare const SWITCH_GLASS_DEFAULTS: Partial<LensParams>;
107
- declare const SWITCH_DARK_OVERRIDES: Partial<LensParams>;
108
- declare const SWITCH_LIGHT_OVERRIDES: Partial<LensParams>;
109
- /** LensSlider base optical parameters. */
110
- declare const SLIDER_GLASS_DEFAULTS: Partial<LensParams>;
111
- declare const SLIDER_DARK_OVERRIDES: Partial<LensParams>;
112
- declare const SLIDER_LIGHT_OVERRIDES: Partial<LensParams>;
113
- declare const SLIDER_SAFARI_OVERRIDES: Partial<LensParams>;
114
-
115
- /**
116
- * lensfx — Engine Layer: Core Mathematics & Displacement Map Generation
117
- *
118
- * Pure TypeScript — no React, no DOM references at module load time.
119
- * DOM (canvas) is accessed only inside function bodies, never at import time,
120
- * making this SSR-safe.
121
- */
122
-
123
- /**
124
- * Approximation of the Gauss error function using hyperbolic tangent.
125
- *
126
- * erf(x) ≈ tanh(√π · x)
127
- *
128
- * The constant √π ≈ 1.7724538509 ensures that the derivative at 0 equals
129
- * 2/√π (matching the exact erf), giving a C∞ smooth clamping function that
130
- * avoids branching and is monotone on (−∞, +∞).
131
- */
132
- declare function erf(x: number): number;
133
- /**
134
- * Computes ellipsoid dome curvature geometry constants for the X and Y axes.
135
- *
136
- * The dome is modelled as a sphere of radius R that just touches both the
137
- * centre and the edge of the lens: R = (halfDim² + depth²) / (2·depth).
138
- *
139
- * @param domeDepth - maximum height of the dome above the lens plane (px)
140
- * @param halfW - half-width of the lens (px)
141
- * @param halfH - half-height of the lens (px)
142
- */
143
- declare function computeDomeConstants(domeDepth: number, halfW: number, halfH: number): DomeConstants;
144
- /**
145
- * Evaluates the gradient (surface slope) of the dome at a given offset
146
- * from the lens centre. Returns a value in [0, 1] normalised by `scale`.
147
- */
148
- declare function domeGradient(pos: number, R: number, scale: number): number;
149
- /**
150
- * Builds an SVG feColorMatrix 4×5 matrix string that rescales the
151
- * displacement map's R and G channels around the neutral midpoint (128/255 = 0.5).
152
- *
153
- * When scaleX ≠ scaleY the lens has asymmetric horizontal/vertical displacement
154
- * and we normalise the larger axis to 1 so both axes are within [0, 255].
155
- */
156
- declare function colorMatrixValues(ratioX: number, ratioY: number): string;
157
- /**
158
- * Returns a memoised SVG rounded-rectangle mask as a data URI.
159
- * Used as CSS `mask-image` on the backdrop-blur and tint layers to
160
- * clip them to the lens shape without touching the filter graph.
161
- */
162
- declare function getSvgMaskDataUri(width: number, height: number, radius: number): {
163
- uri: string;
164
- key: string;
165
- };
166
- /**
167
- * Creates a stateful, synchronous displacement map generator with:
168
- * • 4-fold quadrant symmetry (75 % fewer pixel evaluations)
169
- * • Reusable canvas & ImageData to avoid GC pressure
170
- * • Cached dome gradient lookup table (recalculated only when geometry changes)
171
- *
172
- * Use for animated lenses where the map must update every frame in sync with
173
- * Framer Motion values. For static lenses, prefer `generateDisplacementMapAsync`.
174
- *
175
- * @param mapSize - side length of the square displacement map canvas (px)
176
- */
177
- declare function createDisplacementMapGeneratorSync(mapSize: number): {
178
- /**
179
- * Generate a new displacement map and return a PNG data URL.
180
- * Reuses internal canvas memory; safe to call every animation frame.
181
- */
182
- generate(input: MapGeneratorInput): MapGeneratorOutput;
183
- /** Release canvas memory. Call in React cleanup (useEffect return). */
184
- dispose(): void;
185
- };
186
- /**
187
- * Generates a displacement map asynchronously, processing 64 rows per
188
- * animation frame via `setTimeout(0)` to avoid blocking the main thread.
189
- *
190
- * Returns a Blob Object URL (PNG). Caller is responsible for calling
191
- * `URL.revokeObjectURL` when the Lens unmounts.
192
- *
193
- * Use for static lenses where the map does not need to update every frame.
194
- */
195
- declare function generateDisplacementMapAsync(canvas: HTMLCanvasElement, params: {
196
- canvasSize: number;
197
- lensHalfWidth: number;
198
- lensHalfHeight: number;
199
- borderRadius: number;
200
- depth: number;
201
- sdfBoundary: boolean;
202
- edgeFalloff: boolean;
203
- specularRotation?: number;
204
- glowStrength?: number;
205
- glowSpread?: number;
206
- glowExponent?: number;
207
- edgeStrength?: number;
208
- edgeWidth?: number;
209
- edgeExponent?: number;
210
- domeDepth?: number;
211
- splayAmount?: number;
212
- }): Promise<string | null>;
213
-
214
- /**
215
- * lensfx — WebGL Layer: VideoRefractionRenderer
216
- *
217
- * Full WebGL 1 video refraction engine — Safari fallback for live <video> frames
218
- * which cannot be filtered by SVG feDisplacementMap in WebKit.
219
- *
220
- * Features:
221
- * - Analytical circle and rounded-rect bar SDFs
222
- * - Multi-control dominant lens tracking with press scaling
223
- * - Separable 9-tap Gaussian blur pass (two-pass half-res FBO)
224
- * - Chromatic aberration (R, G, B pass)
225
- * - Adaptive specular & Apple-style vibrancy luminance correction
226
- */
227
- /** Options for constructing a VideoRefractionRenderer. */
228
- interface VideoRendererOptions {
229
- /** Canvas element to render into. */
230
- canvas: HTMLCanvasElement;
231
- /** Source video element to sample frames from. */
232
- video: HTMLVideoElement;
233
- /** Lens depth strength. Default: 2. */
234
- depth?: number;
235
- /** Chromatic aberration amount (0–1). Default: 0.5. */
236
- chromaAmount?: number;
237
- /** Angle of specular directional light (degrees). Default: 45. */
238
- specularRotation?: number;
239
- /** Specular highlight intensity. Default: 1. */
240
- specularStrength?: number;
241
- }
242
- interface VideoLensConfig {
243
- circles: Array<{
244
- cx: number;
245
- cy: number;
246
- radius: number;
247
- scale: number;
248
- baseScale: number;
249
- ratioX: number;
250
- ratioY: number;
251
- }>;
252
- bar?: {
253
- cx: number;
254
- cy: number;
255
- w: number;
256
- h: number;
257
- radius: number;
258
- baseScale: number;
259
- ratioX: number;
260
- ratioY: number;
261
- };
262
- bbox: {
263
- x: number;
264
- y: number;
265
- w: number;
266
- h: number;
267
- };
268
- bboxSize: {
269
- w: number;
270
- h: number;
271
- };
272
- chromaAmount: number;
273
- specStrength: number;
274
- adaptStrength: number;
275
- specLumaLow: number;
276
- specLumaHigh: number;
277
- hasBlur: boolean;
278
- }
279
- declare class VideoRefractionRenderer {
280
- private gl;
281
- private quadBuffer;
282
- private blurProgram;
283
- private refractionProgram;
284
- private videoTexture;
285
- private mapTexture;
286
- private blurFboA;
287
- private blurTexA;
288
- private blurFboB;
289
- private blurTexB;
290
- private fboWidth;
291
- private fboHeight;
292
- constructor(canvas: HTMLCanvasElement);
293
- setDisplacementMap(image: HTMLImageElement | HTMLCanvasElement): void;
294
- private initBlurFBO;
295
- render(video: HTMLVideoElement, config: VideoLensConfig): void;
296
- dispose(): void;
297
- }
298
-
299
- /**
300
- * lensfx — WebGL Layer: QRRefractionRenderer
301
- *
302
- * Full WebGL 2 (#version 300 es) interactive QR code refraction engine.
303
- * Uses an O(1) uniform texture occupancy grid for real-time liquid distortion
304
- * through a 33×33 QR matrix.
305
- *
306
- * Features:
307
- * - WebGL 2 (#version 300 es)
308
- * - O(1) dot occupancy texture lookup
309
- * - Analytical eye rounded-rect SDFs with hover scaling
310
- * - Attenuated displacement for eye corner anchors
311
- * - Chromatic aberration (scaleR = 1 + 2*chroma, scaleG = 1 + 1*chroma, scaleB = 1)
312
- */
313
- /** Options for constructing a QRRefractionRenderer. */
314
- interface QRRendererOptions {
315
- /** Canvas element to render into. */
316
- canvas: HTMLCanvasElement;
317
- /** QR matrix data (boolean 33×33 grid, row-major). */
318
- qrMatrix: boolean[][];
319
- /** Lens depth strength. Default: 2. */
320
- depth?: number;
321
- /** Chromatic aberration amount (0–1). Default: 0.3. */
322
- chromaAmount?: number;
323
- /** Dot radius as a fraction of cell size. Default: 0.4. */
324
- dotRadius?: number;
325
- }
326
- interface QREyeConfig {
327
- center: [number, number];
328
- half: [number, number, number];
329
- radius: [number, number, number];
330
- color: [number, number, number];
331
- scale: number;
332
- }
333
- interface QRRendererInit {
334
- canvas: HTMLCanvasElement;
335
- size: number;
336
- matrixLength: number;
337
- occupancyMatrix: Uint8Array;
338
- gridOriginUV: number;
339
- cellUV: number;
340
- dotRadius: number;
341
- backgroundColor?: [number, number, number];
342
- }
343
- declare class QRRefractionRenderer {
344
- private gl;
345
- private program;
346
- private quadBuffer;
347
- private occupancyTexture;
348
- private displacementTexture;
349
- private paintingTexture;
350
- private paintingColorTexture;
351
- private matrixLength;
352
- private gridOriginUV;
353
- private cellUV;
354
- private dotRadius;
355
- private backgroundColor;
356
- constructor(init: QRRendererInit);
357
- setDisplacementMap(image: HTMLImageElement | HTMLCanvasElement): void;
358
- render(params: {
359
- displacementActive: boolean;
360
- lensOrigin: [number, number];
361
- lensSize: [number, number];
362
- displacementScale: [number, number];
363
- chromaAmount: number;
364
- eyes: QREyeConfig[];
365
- eyeRefractionScale?: number;
366
- }): void;
367
- dispose(): void;
368
- }
369
-
370
5
  interface AaveGlassProps {
371
6
  children?: React.ReactNode;
372
7
  lens?: Partial<LensParams>;
@@ -523,4 +158,4 @@ interface GlassToggleGroupProps {
523
158
  }
524
159
  declare function GlassToggleGroup({ options, value: controlledValue, defaultValue, onValueChange, lens, theme, className, }: GlassToggleGroupProps): React.JSX.Element;
525
160
 
526
- export { DEFAULT_LENS_PARAMS, type DomeConstants, AaveGlass as Lens, type LensParams, type AaveGlassProps as LensProps, GlassSlider as LensSlider, type GlassSliderProps as LensSliderProps, GlassSwitch as LensSwitch, type GlassSwitchProps as LensSwitchProps, GlassToggleGroup as LensToggleGroup, type GlassToggleGroupProps as LensToggleGroupProps, type MapGeneratorInput, type MapGeneratorOutput, QRRefractionRenderer, type QRRendererOptions, SLIDER_DARK_OVERRIDES, SLIDER_GLASS_DEFAULTS, SLIDER_LIGHT_OVERRIDES, SLIDER_SAFARI_OVERRIDES, SWITCH_DARK_OVERRIDES, SWITCH_GLASS_DEFAULTS, SWITCH_LIGHT_OVERRIDES, type ToggleOption, VideoRefractionRenderer, type VideoRendererOptions, colorMatrixValues, computeDomeConstants, createDisplacementMapGeneratorSync, domeGradient, erf, generateDisplacementMapAsync, getSvgMaskDataUri };
161
+ export { AaveGlass as Lens, LensParams, type AaveGlassProps as LensProps, GlassSlider as LensSlider, type GlassSliderProps as LensSliderProps, GlassSwitch as LensSwitch, type GlassSwitchProps as LensSwitchProps, GlassToggleGroup as LensToggleGroup, type GlassToggleGroupProps as LensToggleGroupProps, type ToggleOption };