lensfx 0.1.2 → 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/CHANGELOG.md +10 -0
- package/README.md +39 -0
- package/dist/cdn/lensfx.js +1717 -0
- package/dist/cdn/lensfx.js.map +1 -0
- package/dist/cdn/lensfx.min.js +371 -0
- package/dist/cdn/lensfx.min.js.map +1 -0
- package/dist/index.d.mts +3 -368
- package/dist/index.d.ts +3 -368
- package/dist/index.js +413 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +413 -1
- package/dist/index.mjs.map +1 -1
- package/dist/vanilla.d.mts +493 -0
- package/dist/vanilla.d.ts +493 -0
- package/dist/vanilla.js +1694 -0
- package/dist/vanilla.js.map +1 -0
- package/dist/vanilla.mjs +1675 -0
- package/dist/vanilla.mjs.map +1 -0
- package/package.json +28 -3
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lensfx — Engine Layer: Types & Constants
|
|
3
|
+
*
|
|
4
|
+
* Pure TypeScript — no React, no DOM. Can be imported in any environment.
|
|
5
|
+
*/
|
|
6
|
+
/** All optical parameters that control how a single lens looks and distorts. */
|
|
7
|
+
interface LensParams {
|
|
8
|
+
/** Lens width in pixels. */
|
|
9
|
+
lensW: number;
|
|
10
|
+
/** Lens height in pixels. */
|
|
11
|
+
lensH: number;
|
|
12
|
+
/** Lens corner radius in pixels. */
|
|
13
|
+
borderRadius: number;
|
|
14
|
+
/** Refraction depth/strength — higher = more distortion. Range: 0–10. */
|
|
15
|
+
depth: number;
|
|
16
|
+
/** Chromatic aberration split amount. 0 = monochromatic, 1 = full RGB split. */
|
|
17
|
+
chromaAmount: number;
|
|
18
|
+
/** Horizontal displacement scale. 0 = no lateral displacement. */
|
|
19
|
+
scaleX: number;
|
|
20
|
+
/** Vertical displacement scale. 0 = no vertical displacement. */
|
|
21
|
+
scaleY: number;
|
|
22
|
+
/** Resolution of the displacement map canvas (power-of-two recommended). */
|
|
23
|
+
mapSize: number;
|
|
24
|
+
/** Gaussian blur radius applied to the background behind the lens (px). */
|
|
25
|
+
blurAmount: number;
|
|
26
|
+
/** If true, clips displacement strictly to the lens SDF boundary. */
|
|
27
|
+
sdfBoundary: boolean;
|
|
28
|
+
/** If true, applies an erf-smoothed falloff at the lens edge. */
|
|
29
|
+
edgeFalloff: boolean;
|
|
30
|
+
/** Additive brightness overlay inside the lens. Positive = lighter, negative = darker. Range: -1 to 1. */
|
|
31
|
+
brightness: number;
|
|
32
|
+
/** Intensity of the specular highlight. Range: 0–3. */
|
|
33
|
+
specularStrength: number;
|
|
34
|
+
/** Angle of the specular directional light in degrees. */
|
|
35
|
+
specularRotation: number;
|
|
36
|
+
/** If true, uses dark (shadow) specular mode instead of bright. */
|
|
37
|
+
specularDark: boolean;
|
|
38
|
+
/** Uniform tint applied inside the lens. Range: -1 (black) to 1 (white). */
|
|
39
|
+
tint: number;
|
|
40
|
+
/** Strength of the inner glow band. Range: 0–1. */
|
|
41
|
+
glowStrength: number;
|
|
42
|
+
/** Angular spread of the glow band, normalised. Range: 0–1. */
|
|
43
|
+
glowSpread: number;
|
|
44
|
+
/** Exponent controlling glow falloff curve. Higher = sharper band. */
|
|
45
|
+
glowExponent: number;
|
|
46
|
+
/** Strength of the edge specular ring (separate from inner glow). Range: 0–1. */
|
|
47
|
+
edgeStrength: number;
|
|
48
|
+
/** Thickness of the edge specular ring in pixels. */
|
|
49
|
+
edgeWidth: number;
|
|
50
|
+
/** Exponent controlling edge ring falloff curve. */
|
|
51
|
+
edgeExponent: number;
|
|
52
|
+
/** Height of the ellipsoid dome above the lens surface in pixels. */
|
|
53
|
+
domeDepth: number;
|
|
54
|
+
/** How much to reduce displacement magnitude at corners (0 = no splay, 1 = full splay). */
|
|
55
|
+
splayAmount: number;
|
|
56
|
+
/** Box shadow applied to the lens container (outer drop shadow). */
|
|
57
|
+
edgeShadow?: string;
|
|
58
|
+
/** Inset box shadow applied to the lens container. */
|
|
59
|
+
edgeInsetShadow?: string;
|
|
60
|
+
/** Secondary rest-state shadow (e.g. when the slider thumb is at rest). */
|
|
61
|
+
restEdgeShadow?: string;
|
|
62
|
+
}
|
|
63
|
+
/** Precomputed geometric constants for dome curvature. */
|
|
64
|
+
interface DomeConstants {
|
|
65
|
+
/** Horizontal sphere radius for dome curvature. */
|
|
66
|
+
Rx: number;
|
|
67
|
+
/** Vertical sphere radius for dome curvature. */
|
|
68
|
+
Ry: number;
|
|
69
|
+
/** Normalised scale factor for the X gradient (trapezoidal integration). */
|
|
70
|
+
scaleX: number;
|
|
71
|
+
/** Normalised scale factor for the Y gradient (trapezoidal integration). */
|
|
72
|
+
scaleY: number;
|
|
73
|
+
}
|
|
74
|
+
/** Input to the synchronous displacement map generator. */
|
|
75
|
+
interface MapGeneratorInput {
|
|
76
|
+
lensHalfWidth: number;
|
|
77
|
+
lensHalfHeight: number;
|
|
78
|
+
borderRadius: number;
|
|
79
|
+
depth: number;
|
|
80
|
+
sdfBoundary: boolean;
|
|
81
|
+
edgeFalloff: boolean;
|
|
82
|
+
specularRotation: number;
|
|
83
|
+
glowStrength: number;
|
|
84
|
+
glowSpread: number;
|
|
85
|
+
glowExponent: number;
|
|
86
|
+
edgeStrength: number;
|
|
87
|
+
edgeWidth: number;
|
|
88
|
+
edgeExponent: number;
|
|
89
|
+
domeDepth: number;
|
|
90
|
+
splayAmount: number;
|
|
91
|
+
}
|
|
92
|
+
/** Output from the displacement map generator. */
|
|
93
|
+
interface MapGeneratorOutput {
|
|
94
|
+
/** PNG data URL of the generated displacement map. */
|
|
95
|
+
dataUrl: string;
|
|
96
|
+
/** Time taken for the pixel loop, in milliseconds. */
|
|
97
|
+
loopMs: number;
|
|
98
|
+
/** Time taken for canvas.toDataURL encoding, in milliseconds. */
|
|
99
|
+
encodeMs: number;
|
|
100
|
+
}
|
|
101
|
+
/** Zero-refraction baseline — all effects disabled. */
|
|
102
|
+
declare const DEFAULT_LENS_PARAMS: LensParams;
|
|
103
|
+
/** LensSwitch base optical parameters. */
|
|
104
|
+
declare const SWITCH_GLASS_DEFAULTS: Partial<LensParams>;
|
|
105
|
+
declare const SWITCH_DARK_OVERRIDES: Partial<LensParams>;
|
|
106
|
+
declare const SWITCH_LIGHT_OVERRIDES: Partial<LensParams>;
|
|
107
|
+
/** LensSlider base optical parameters. */
|
|
108
|
+
declare const SLIDER_GLASS_DEFAULTS: Partial<LensParams>;
|
|
109
|
+
declare const SLIDER_DARK_OVERRIDES: Partial<LensParams>;
|
|
110
|
+
declare const SLIDER_LIGHT_OVERRIDES: Partial<LensParams>;
|
|
111
|
+
declare const SLIDER_SAFARI_OVERRIDES: Partial<LensParams>;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* lensfx — Engine Layer: Core Mathematics & Displacement Map Generation
|
|
115
|
+
*
|
|
116
|
+
* Pure TypeScript — no React, no DOM references at module load time.
|
|
117
|
+
* DOM (canvas) is accessed only inside function bodies, never at import time,
|
|
118
|
+
* making this SSR-safe.
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Approximation of the Gauss error function using hyperbolic tangent.
|
|
123
|
+
*
|
|
124
|
+
* erf(x) ≈ tanh(√π · x)
|
|
125
|
+
*
|
|
126
|
+
* The constant √π ≈ 1.7724538509 ensures that the derivative at 0 equals
|
|
127
|
+
* 2/√π (matching the exact erf), giving a C∞ smooth clamping function that
|
|
128
|
+
* avoids branching and is monotone on (−∞, +∞).
|
|
129
|
+
*/
|
|
130
|
+
declare function erf(x: number): number;
|
|
131
|
+
/**
|
|
132
|
+
* Computes ellipsoid dome curvature geometry constants for the X and Y axes.
|
|
133
|
+
*
|
|
134
|
+
* The dome is modelled as a sphere of radius R that just touches both the
|
|
135
|
+
* centre and the edge of the lens: R = (halfDim² + depth²) / (2·depth).
|
|
136
|
+
*
|
|
137
|
+
* @param domeDepth - maximum height of the dome above the lens plane (px)
|
|
138
|
+
* @param halfW - half-width of the lens (px)
|
|
139
|
+
* @param halfH - half-height of the lens (px)
|
|
140
|
+
*/
|
|
141
|
+
declare function computeDomeConstants(domeDepth: number, halfW: number, halfH: number): DomeConstants;
|
|
142
|
+
/**
|
|
143
|
+
* Evaluates the gradient (surface slope) of the dome at a given offset
|
|
144
|
+
* from the lens centre. Returns a value in [0, 1] normalised by `scale`.
|
|
145
|
+
*/
|
|
146
|
+
declare function domeGradient(pos: number, R: number, scale: number): number;
|
|
147
|
+
/**
|
|
148
|
+
* Builds an SVG feColorMatrix 4×5 matrix string that rescales the
|
|
149
|
+
* displacement map's R and G channels around the neutral midpoint (128/255 = 0.5).
|
|
150
|
+
*
|
|
151
|
+
* When scaleX ≠ scaleY the lens has asymmetric horizontal/vertical displacement
|
|
152
|
+
* and we normalise the larger axis to 1 so both axes are within [0, 255].
|
|
153
|
+
*/
|
|
154
|
+
declare function colorMatrixValues(ratioX: number, ratioY: number): string;
|
|
155
|
+
/**
|
|
156
|
+
* Returns a memoised SVG rounded-rectangle mask as a data URI.
|
|
157
|
+
* Used as CSS `mask-image` on the backdrop-blur and tint layers to
|
|
158
|
+
* clip them to the lens shape without touching the filter graph.
|
|
159
|
+
*/
|
|
160
|
+
declare function getSvgMaskDataUri(width: number, height: number, radius: number): {
|
|
161
|
+
uri: string;
|
|
162
|
+
key: string;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Creates a stateful, synchronous displacement map generator with:
|
|
166
|
+
* • 4-fold quadrant symmetry (75 % fewer pixel evaluations)
|
|
167
|
+
* • Reusable canvas & ImageData to avoid GC pressure
|
|
168
|
+
* • Cached dome gradient lookup table (recalculated only when geometry changes)
|
|
169
|
+
*
|
|
170
|
+
* Use for animated lenses where the map must update every frame in sync with
|
|
171
|
+
* Framer Motion values. For static lenses, prefer `generateDisplacementMapAsync`.
|
|
172
|
+
*
|
|
173
|
+
* @param mapSize - side length of the square displacement map canvas (px)
|
|
174
|
+
*/
|
|
175
|
+
declare function createDisplacementMapGeneratorSync(mapSize: number): {
|
|
176
|
+
/**
|
|
177
|
+
* Generate a new displacement map and return a PNG data URL.
|
|
178
|
+
* Reuses internal canvas memory; safe to call every animation frame.
|
|
179
|
+
*/
|
|
180
|
+
generate(input: MapGeneratorInput): MapGeneratorOutput;
|
|
181
|
+
/** Release canvas memory. Call in React cleanup (useEffect return). */
|
|
182
|
+
dispose(): void;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Generates a displacement map asynchronously, processing 64 rows per
|
|
186
|
+
* animation frame via `setTimeout(0)` to avoid blocking the main thread.
|
|
187
|
+
*
|
|
188
|
+
* Returns a Blob Object URL (PNG). Caller is responsible for calling
|
|
189
|
+
* `URL.revokeObjectURL` when the Lens unmounts.
|
|
190
|
+
*
|
|
191
|
+
* Use for static lenses where the map does not need to update every frame.
|
|
192
|
+
*/
|
|
193
|
+
declare function generateDisplacementMapAsync(canvas: HTMLCanvasElement, params: {
|
|
194
|
+
canvasSize: number;
|
|
195
|
+
lensHalfWidth: number;
|
|
196
|
+
lensHalfHeight: number;
|
|
197
|
+
borderRadius: number;
|
|
198
|
+
depth: number;
|
|
199
|
+
sdfBoundary: boolean;
|
|
200
|
+
edgeFalloff: boolean;
|
|
201
|
+
specularRotation?: number;
|
|
202
|
+
glowStrength?: number;
|
|
203
|
+
glowSpread?: number;
|
|
204
|
+
glowExponent?: number;
|
|
205
|
+
edgeStrength?: number;
|
|
206
|
+
edgeWidth?: number;
|
|
207
|
+
edgeExponent?: number;
|
|
208
|
+
domeDepth?: number;
|
|
209
|
+
splayAmount?: number;
|
|
210
|
+
}): Promise<string | null>;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* lensfx — WebGL Layer: VideoRefractionRenderer
|
|
214
|
+
*
|
|
215
|
+
* Full WebGL 1 video refraction engine — Safari fallback for live <video> frames
|
|
216
|
+
* which cannot be filtered by SVG feDisplacementMap in WebKit.
|
|
217
|
+
*
|
|
218
|
+
* Features:
|
|
219
|
+
* - Analytical circle and rounded-rect bar SDFs
|
|
220
|
+
* - Multi-control dominant lens tracking with press scaling
|
|
221
|
+
* - Separable 9-tap Gaussian blur pass (two-pass half-res FBO)
|
|
222
|
+
* - Chromatic aberration (R, G, B pass)
|
|
223
|
+
* - Adaptive specular & Apple-style vibrancy luminance correction
|
|
224
|
+
*/
|
|
225
|
+
/** Options for constructing a VideoRefractionRenderer. */
|
|
226
|
+
interface VideoRendererOptions {
|
|
227
|
+
/** Canvas element to render into. */
|
|
228
|
+
canvas: HTMLCanvasElement;
|
|
229
|
+
/** Source video element to sample frames from. */
|
|
230
|
+
video: HTMLVideoElement;
|
|
231
|
+
/** Lens depth strength. Default: 2. */
|
|
232
|
+
depth?: number;
|
|
233
|
+
/** Chromatic aberration amount (0–1). Default: 0.5. */
|
|
234
|
+
chromaAmount?: number;
|
|
235
|
+
/** Angle of specular directional light (degrees). Default: 45. */
|
|
236
|
+
specularRotation?: number;
|
|
237
|
+
/** Specular highlight intensity. Default: 1. */
|
|
238
|
+
specularStrength?: number;
|
|
239
|
+
}
|
|
240
|
+
interface VideoLensConfig {
|
|
241
|
+
circles: Array<{
|
|
242
|
+
cx: number;
|
|
243
|
+
cy: number;
|
|
244
|
+
radius: number;
|
|
245
|
+
scale: number;
|
|
246
|
+
baseScale: number;
|
|
247
|
+
ratioX: number;
|
|
248
|
+
ratioY: number;
|
|
249
|
+
}>;
|
|
250
|
+
bar?: {
|
|
251
|
+
cx: number;
|
|
252
|
+
cy: number;
|
|
253
|
+
w: number;
|
|
254
|
+
h: number;
|
|
255
|
+
radius: number;
|
|
256
|
+
baseScale: number;
|
|
257
|
+
ratioX: number;
|
|
258
|
+
ratioY: number;
|
|
259
|
+
};
|
|
260
|
+
bbox: {
|
|
261
|
+
x: number;
|
|
262
|
+
y: number;
|
|
263
|
+
w: number;
|
|
264
|
+
h: number;
|
|
265
|
+
};
|
|
266
|
+
bboxSize: {
|
|
267
|
+
w: number;
|
|
268
|
+
h: number;
|
|
269
|
+
};
|
|
270
|
+
chromaAmount: number;
|
|
271
|
+
specStrength: number;
|
|
272
|
+
adaptStrength: number;
|
|
273
|
+
specLumaLow: number;
|
|
274
|
+
specLumaHigh: number;
|
|
275
|
+
hasBlur: boolean;
|
|
276
|
+
}
|
|
277
|
+
declare class VideoRefractionRenderer {
|
|
278
|
+
private gl;
|
|
279
|
+
private quadBuffer;
|
|
280
|
+
private blurProgram;
|
|
281
|
+
private refractionProgram;
|
|
282
|
+
private videoTexture;
|
|
283
|
+
private mapTexture;
|
|
284
|
+
private blurFboA;
|
|
285
|
+
private blurTexA;
|
|
286
|
+
private blurFboB;
|
|
287
|
+
private blurTexB;
|
|
288
|
+
private fboWidth;
|
|
289
|
+
private fboHeight;
|
|
290
|
+
constructor(canvas: HTMLCanvasElement);
|
|
291
|
+
setDisplacementMap(image: HTMLImageElement | HTMLCanvasElement): void;
|
|
292
|
+
private initBlurFBO;
|
|
293
|
+
render(video: HTMLVideoElement, config: VideoLensConfig): void;
|
|
294
|
+
dispose(): void;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* lensfx — WebGL Layer: QRRefractionRenderer
|
|
299
|
+
*
|
|
300
|
+
* Full WebGL 2 (#version 300 es) interactive QR code refraction engine.
|
|
301
|
+
* Uses an O(1) uniform texture occupancy grid for real-time liquid distortion
|
|
302
|
+
* through a 33×33 QR matrix.
|
|
303
|
+
*
|
|
304
|
+
* Features:
|
|
305
|
+
* - WebGL 2 (#version 300 es)
|
|
306
|
+
* - O(1) dot occupancy texture lookup
|
|
307
|
+
* - Analytical eye rounded-rect SDFs with hover scaling
|
|
308
|
+
* - Attenuated displacement for eye corner anchors
|
|
309
|
+
* - Chromatic aberration (scaleR = 1 + 2*chroma, scaleG = 1 + 1*chroma, scaleB = 1)
|
|
310
|
+
*/
|
|
311
|
+
/** Options for constructing a QRRefractionRenderer. */
|
|
312
|
+
interface QRRendererOptions {
|
|
313
|
+
/** Canvas element to render into. */
|
|
314
|
+
canvas: HTMLCanvasElement;
|
|
315
|
+
/** QR matrix data (boolean 33×33 grid, row-major). */
|
|
316
|
+
qrMatrix: boolean[][];
|
|
317
|
+
/** Lens depth strength. Default: 2. */
|
|
318
|
+
depth?: number;
|
|
319
|
+
/** Chromatic aberration amount (0–1). Default: 0.3. */
|
|
320
|
+
chromaAmount?: number;
|
|
321
|
+
/** Dot radius as a fraction of cell size. Default: 0.4. */
|
|
322
|
+
dotRadius?: number;
|
|
323
|
+
}
|
|
324
|
+
interface QREyeConfig {
|
|
325
|
+
center: [number, number];
|
|
326
|
+
half: [number, number, number];
|
|
327
|
+
radius: [number, number, number];
|
|
328
|
+
color: [number, number, number];
|
|
329
|
+
scale: number;
|
|
330
|
+
}
|
|
331
|
+
interface QRRendererInit {
|
|
332
|
+
canvas: HTMLCanvasElement;
|
|
333
|
+
size: number;
|
|
334
|
+
matrixLength: number;
|
|
335
|
+
occupancyMatrix: Uint8Array;
|
|
336
|
+
gridOriginUV: number;
|
|
337
|
+
cellUV: number;
|
|
338
|
+
dotRadius: number;
|
|
339
|
+
backgroundColor?: [number, number, number];
|
|
340
|
+
}
|
|
341
|
+
declare class QRRefractionRenderer {
|
|
342
|
+
private gl;
|
|
343
|
+
private program;
|
|
344
|
+
private quadBuffer;
|
|
345
|
+
private occupancyTexture;
|
|
346
|
+
private displacementTexture;
|
|
347
|
+
private paintingTexture;
|
|
348
|
+
private paintingColorTexture;
|
|
349
|
+
private matrixLength;
|
|
350
|
+
private gridOriginUV;
|
|
351
|
+
private cellUV;
|
|
352
|
+
private dotRadius;
|
|
353
|
+
private backgroundColor;
|
|
354
|
+
constructor(init: QRRendererInit);
|
|
355
|
+
setDisplacementMap(image: HTMLImageElement | HTMLCanvasElement): void;
|
|
356
|
+
render(params: {
|
|
357
|
+
displacementActive: boolean;
|
|
358
|
+
lensOrigin: [number, number];
|
|
359
|
+
lensSize: [number, number];
|
|
360
|
+
displacementScale: [number, number];
|
|
361
|
+
chromaAmount: number;
|
|
362
|
+
eyes: QREyeConfig[];
|
|
363
|
+
eyeRefractionScale?: number;
|
|
364
|
+
}): void;
|
|
365
|
+
dispose(): void;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* lensfx — Vanilla DOM Engine: createLens
|
|
370
|
+
*
|
|
371
|
+
* Zero-dependency, pure DOM + SVG + Canvas optical glass refraction.
|
|
372
|
+
* Runs anywhere without React, Framer Motion, or bundlers.
|
|
373
|
+
*/
|
|
374
|
+
interface LensOptions {
|
|
375
|
+
/** Lens width in pixels. Default: 160 */
|
|
376
|
+
width?: number;
|
|
377
|
+
/** Alias for width */
|
|
378
|
+
lensW?: number;
|
|
379
|
+
/** Lens height in pixels. Default: 100 */
|
|
380
|
+
height?: number;
|
|
381
|
+
/** Alias for height */
|
|
382
|
+
lensH?: number;
|
|
383
|
+
/** Corner radius in pixels. Default: 24 */
|
|
384
|
+
radius?: number;
|
|
385
|
+
/** Alias for radius */
|
|
386
|
+
borderRadius?: number;
|
|
387
|
+
/** Lens center X: 0..1 (fraction of container width) or pixel value. Default: 0.5 */
|
|
388
|
+
x?: number;
|
|
389
|
+
/** Lens center Y: 0..1 (fraction of container height) or pixel value. Default: 0.5 */
|
|
390
|
+
y?: number;
|
|
391
|
+
/** Automatically track pointer / mouse movement over the container element. Default: false */
|
|
392
|
+
interactive?: boolean;
|
|
393
|
+
/** Refraction depth / distortion strength (0–10). Default: 2 */
|
|
394
|
+
depth?: number;
|
|
395
|
+
/** Chromatic aberration split (0–1). 0 = monochrome, 1 = full RGB split. Default: 0.6 */
|
|
396
|
+
chroma?: number;
|
|
397
|
+
/** Alias for chroma */
|
|
398
|
+
chromaAmount?: number;
|
|
399
|
+
/** Aspect-ratio displacement scale X (0–1). Default: 0.25 */
|
|
400
|
+
scaleX?: number;
|
|
401
|
+
/** Aspect-ratio displacement scale Y (0–1). Default: 0.25 */
|
|
402
|
+
scaleY?: number;
|
|
403
|
+
/** Ellipsoid dome height in pixels. Default: 6 */
|
|
404
|
+
domeDepth?: number;
|
|
405
|
+
/** Directional specular angle in degrees. Default: 45 */
|
|
406
|
+
specularRotation?: number;
|
|
407
|
+
/** Specular highlight intensity. Default: 1 */
|
|
408
|
+
specularStrength?: number;
|
|
409
|
+
/** Invert specular to dark shadow mode. Default: false */
|
|
410
|
+
specularDark?: boolean;
|
|
411
|
+
/** Clip refraction strictly to the lens SDF boundary. Default: true */
|
|
412
|
+
sdfBoundary?: boolean;
|
|
413
|
+
/** Apply erf-smoothed edge falloff. Default: true */
|
|
414
|
+
edgeFalloff?: boolean;
|
|
415
|
+
/** Glow intensity (0–1). Default: 0.3 */
|
|
416
|
+
glowStrength?: number;
|
|
417
|
+
/** Glow spread factor (0–1). Default: 1 */
|
|
418
|
+
glowSpread?: number;
|
|
419
|
+
/** Glow falloff exponent. Default: 1.5 */
|
|
420
|
+
glowExponent?: number;
|
|
421
|
+
/** Edge ring highlight intensity (0–1). Default: 0.4 */
|
|
422
|
+
edgeStrength?: number;
|
|
423
|
+
/** Edge ring highlight width in pixels. Default: 3 */
|
|
424
|
+
edgeWidth?: number;
|
|
425
|
+
/** Splay attenuation factor at corners (0–1). Default: 0.8 */
|
|
426
|
+
splayAmount?: number;
|
|
427
|
+
/** Frosted glass blur radius in pixels. Default: 0 */
|
|
428
|
+
blur?: number;
|
|
429
|
+
/** Tint color CSS string (e.g. "rgba(255, 255, 255, 0.08)"). Default: "rgba(255, 255, 255, 0.05)" */
|
|
430
|
+
tintColor?: string;
|
|
431
|
+
/** Tint backdrop blur in pixels. Default: 0 */
|
|
432
|
+
tintBlur?: number;
|
|
433
|
+
/** Tint opacity (0–1). Default: 1 */
|
|
434
|
+
tintOpacity?: number;
|
|
435
|
+
/** Lens rim shadow (boolean or custom CSS box-shadow string). Default: true */
|
|
436
|
+
shadow?: boolean | string;
|
|
437
|
+
/** Lens rim border (boolean or custom CSS border string). Default: true */
|
|
438
|
+
border?: boolean | string;
|
|
439
|
+
/** Displacement map resolution in pixels. Default: 256 */
|
|
440
|
+
mapSize?: number;
|
|
441
|
+
/** Pre-rendered displacement map data URL. */
|
|
442
|
+
displacementMapUrl?: string;
|
|
443
|
+
/** Alternative element / selector to apply the filter to instead of container */
|
|
444
|
+
refractionTarget?: HTMLElement | string;
|
|
445
|
+
/** Callback fired when displacement map data URL changes */
|
|
446
|
+
onMapChange?: (url: string) => void;
|
|
447
|
+
/** Callback fired when lens position changes */
|
|
448
|
+
onPositionChange?: (x: number, y: number) => void;
|
|
449
|
+
}
|
|
450
|
+
interface LensInstance {
|
|
451
|
+
/** The container element */
|
|
452
|
+
el: HTMLElement;
|
|
453
|
+
/** The element receiving the SVG displacement filter */
|
|
454
|
+
targetEl: HTMLElement;
|
|
455
|
+
/** The hidden SVG root element housing the filter defs */
|
|
456
|
+
svgEl: SVGSVGElement;
|
|
457
|
+
/** The SVG filter element */
|
|
458
|
+
filterEl: SVGFilterElement;
|
|
459
|
+
/** The floating lens overlay element (rim lighting, border, tint) */
|
|
460
|
+
overlayEl: HTMLElement;
|
|
461
|
+
/** Current active options */
|
|
462
|
+
options: LensOptions;
|
|
463
|
+
/** Current displacement map data URL */
|
|
464
|
+
mapDataUrl: string;
|
|
465
|
+
/** Move lens to new x, y position (pixel or 0..1 normalized) */
|
|
466
|
+
setPosition: (x: number, y: number) => void;
|
|
467
|
+
/** Update lens options dynamically */
|
|
468
|
+
update: (newOptions: Partial<LensOptions>) => void;
|
|
469
|
+
/** Toggle interactive mouse/pointer tracking */
|
|
470
|
+
setInteractive: (interactive: boolean) => void;
|
|
471
|
+
/** Destroy the lens and restore all DOM modifications */
|
|
472
|
+
destroy: () => void;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Creates a real optical glass refraction lens on any DOM element.
|
|
476
|
+
*
|
|
477
|
+
* @param target - Target container element or CSS selector string
|
|
478
|
+
* @param options - Optical and behavioral options
|
|
479
|
+
* @returns LensInstance with control methods (setPosition, update, destroy)
|
|
480
|
+
*
|
|
481
|
+
* @example
|
|
482
|
+
* ```js
|
|
483
|
+
* const lens = lensfx.createLens(document.querySelector("#card"), {
|
|
484
|
+
* width: 200,
|
|
485
|
+
* height: 120,
|
|
486
|
+
* radius: 28,
|
|
487
|
+
* interactive: true,
|
|
488
|
+
* });
|
|
489
|
+
* ```
|
|
490
|
+
*/
|
|
491
|
+
declare function createLens(target: HTMLElement | string, options?: LensOptions): LensInstance;
|
|
492
|
+
|
|
493
|
+
export { DEFAULT_LENS_PARAMS, type DomeConstants, type LensInstance, type LensOptions, type LensParams, 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, VideoRefractionRenderer, type VideoRendererOptions, colorMatrixValues, computeDomeConstants, createDisplacementMapGeneratorSync, createLens, domeGradient, erf, generateDisplacementMapAsync, getSvgMaskDataUri };
|