@glimmerui/core 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +15 -2
- package/dist/index.d.ts +603 -0
- package/dist/index.js +3556 -0
- package/package.json +38 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Charles Allotey
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @glimmerui/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Framework-agnostic WebGL effects for Glimmer UI, built on OGL and driven by Motion. Use `@glimmerui/react`, `@glimmerui/vue` or `@glimmerui/nuxt` unless you are writing your own wrapper.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { createTiltCard } from "@glimmerui/core";
|
|
7
|
+
|
|
8
|
+
const card = createTiltCard(element, { src: "/photo.jpg" });
|
|
9
|
+
element.addEventListener("pointermove", (e) => {
|
|
10
|
+
const r = element.getBoundingClientRect();
|
|
11
|
+
card.setPointer((e.clientX - r.left) / r.width, 1 - (e.clientY - r.top) / r.height);
|
|
12
|
+
});
|
|
13
|
+
// card.update({ src: "/other.jpg" }) changes options in place; card.destroy() cleans up.
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
All effects on a page share one WebGL context, fall back to plain CSS without WebGL, pause offscreen and respect `prefers-reduced-motion`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
import { Renderer } from 'ogl';
|
|
2
|
+
|
|
3
|
+
interface ShaderGradientOptions {
|
|
4
|
+
/** Three CSS hex colors blended by the shader. */
|
|
5
|
+
colors?: [string, string, string];
|
|
6
|
+
/** Time multiplier. 1 is the default speed. */
|
|
7
|
+
speed?: number;
|
|
8
|
+
/** Starting hover intensity from 0 to 1. */
|
|
9
|
+
intensity?: number;
|
|
10
|
+
}
|
|
11
|
+
interface ShaderGradientController {
|
|
12
|
+
/** Pointer position in 0 to 1 space, origin at the bottom left. Smoothed with a spring. */
|
|
13
|
+
setPointer(x: number, y: number): void;
|
|
14
|
+
/** Animate the hover intensity to a value from 0 to 1. */
|
|
15
|
+
setIntensity(value: number): void;
|
|
16
|
+
/** Apply new options in place, without rebuilding the effect. */
|
|
17
|
+
update(options: ShaderGradientOptions): void;
|
|
18
|
+
destroy(): void;
|
|
19
|
+
}
|
|
20
|
+
declare function createShaderGradient(container: HTMLElement, options?: ShaderGradientOptions): ShaderGradientController;
|
|
21
|
+
|
|
22
|
+
interface ImageDistortionOptions {
|
|
23
|
+
/** Image URL. Must be same origin or served with CORS headers. */
|
|
24
|
+
src: string;
|
|
25
|
+
/** Ripple and color split strength. 1 is the default. */
|
|
26
|
+
strength?: number;
|
|
27
|
+
}
|
|
28
|
+
interface ImageDistortionController {
|
|
29
|
+
/** Pointer position in 0 to 1 space, origin at the bottom left. Smoothed with a spring. */
|
|
30
|
+
setPointer(x: number, y: number): void;
|
|
31
|
+
/** Animate hover amount from 0 to 1. */
|
|
32
|
+
setHover(value: number): void;
|
|
33
|
+
/**
|
|
34
|
+
* Apply new options in place. A new src keeps showing the current image
|
|
35
|
+
* until the new one has loaded.
|
|
36
|
+
*/
|
|
37
|
+
update(options: ImageDistortionOptions): void;
|
|
38
|
+
destroy(): void;
|
|
39
|
+
}
|
|
40
|
+
declare function createImageDistortion(container: HTMLElement, options: ImageDistortionOptions): ImageDistortionController;
|
|
41
|
+
|
|
42
|
+
interface TiltCardOptions {
|
|
43
|
+
/** Image URL. Must be same origin or served with CORS headers. */
|
|
44
|
+
src: string;
|
|
45
|
+
/** Maximum tilt in radians. Defaults to 0.4. */
|
|
46
|
+
maxTilt?: number;
|
|
47
|
+
/** Corner radius in CSS pixels. Defaults to 20. */
|
|
48
|
+
radius?: number;
|
|
49
|
+
/** Glare strength from 0 to 1. Defaults to 1. */
|
|
50
|
+
glare?: number;
|
|
51
|
+
}
|
|
52
|
+
interface TiltCardController {
|
|
53
|
+
/** Pointer position in 0 to 1 space, origin at the bottom left. The card tilts toward it. */
|
|
54
|
+
setPointer(x: number, y: number): void;
|
|
55
|
+
/** Animate hover amount from 0 to 1. Controls glare. */
|
|
56
|
+
setHover(value: number): void;
|
|
57
|
+
/**
|
|
58
|
+
* Apply new options in place. A new src keeps showing the current image
|
|
59
|
+
* until the new one has loaded.
|
|
60
|
+
*/
|
|
61
|
+
update(options: TiltCardOptions): void;
|
|
62
|
+
destroy(): void;
|
|
63
|
+
}
|
|
64
|
+
declare function createTiltCard(container: HTMLElement, options: TiltCardOptions): TiltCardController;
|
|
65
|
+
interface TiltEffectController<O> {
|
|
66
|
+
setPointer(x: number, y: number): void;
|
|
67
|
+
setHover(value: number): void;
|
|
68
|
+
update(options: O): void;
|
|
69
|
+
destroy(): void;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The tilt card's engine: perspective, corners, glare and the image. Effects
|
|
73
|
+
* built on it pass their own fragment (from tiltShader) and extra uniforms.
|
|
74
|
+
*/
|
|
75
|
+
declare function createTiltEffect<O extends TiltCardOptions>(container: HTMLElement, options: O, fragment: string, extraUniforms?: (options: O) => Record<string, unknown>): TiltEffectController<O>;
|
|
76
|
+
|
|
77
|
+
interface ImageRevealOptions {
|
|
78
|
+
/** Image shown at rest. Must be same origin or served with CORS headers. */
|
|
79
|
+
src: string;
|
|
80
|
+
/** Image revealed on hover. Must be same origin or served with CORS headers. */
|
|
81
|
+
revealSrc: string;
|
|
82
|
+
}
|
|
83
|
+
interface ImageRevealController {
|
|
84
|
+
/** Pointer position in 0 to 1 space, origin at the bottom left. The reveal spreads from here. */
|
|
85
|
+
setPointer(x: number, y: number): void;
|
|
86
|
+
/** Animate the reveal from 0 (first image) to 1 (second image). */
|
|
87
|
+
setHover(value: number): void;
|
|
88
|
+
/**
|
|
89
|
+
* Apply new options in place. A new source keeps showing the current image
|
|
90
|
+
* until the new one has loaded.
|
|
91
|
+
*/
|
|
92
|
+
update(options: ImageRevealOptions): void;
|
|
93
|
+
destroy(): void;
|
|
94
|
+
}
|
|
95
|
+
declare function createImageReveal(container: HTMLElement, options: ImageRevealOptions): ImageRevealController;
|
|
96
|
+
|
|
97
|
+
interface DotGridOptions {
|
|
98
|
+
/** Dot color, as a hex value. */
|
|
99
|
+
color?: string;
|
|
100
|
+
/** Color the dots take on near the pointer, as a hex value. */
|
|
101
|
+
accent?: string;
|
|
102
|
+
/** Distance between dot centers, in CSS pixels. */
|
|
103
|
+
spacing?: number;
|
|
104
|
+
/** Dot radius, in CSS pixels. */
|
|
105
|
+
size?: number;
|
|
106
|
+
/** How far the pointer's influence reaches, in CSS pixels. */
|
|
107
|
+
radius?: number;
|
|
108
|
+
}
|
|
109
|
+
interface DotGridController {
|
|
110
|
+
/** Pointer position in 0 to 1 space, origin at the bottom left. Smoothed with a spring. */
|
|
111
|
+
setPointer(x: number, y: number): void;
|
|
112
|
+
/** Animate the pointer's influence from 0 to 1. */
|
|
113
|
+
setHover(value: number): void;
|
|
114
|
+
/** Apply new options in place, without rebuilding the effect. */
|
|
115
|
+
update(options: DotGridOptions): void;
|
|
116
|
+
destroy(): void;
|
|
117
|
+
}
|
|
118
|
+
declare function createDotGrid(container: HTMLElement, options?: DotGridOptions): DotGridController;
|
|
119
|
+
|
|
120
|
+
interface AuroraOptions {
|
|
121
|
+
/** Three hex colors, one for each curtain of light. */
|
|
122
|
+
colors?: [string, string, string];
|
|
123
|
+
/** Sky color behind the light, as a hex value. */
|
|
124
|
+
background?: string;
|
|
125
|
+
/** Time multiplier. 1 is the default speed. */
|
|
126
|
+
speed?: number;
|
|
127
|
+
/** How strongly the pointer pulls the light before the first hover, from 0 to 1. */
|
|
128
|
+
intensity?: number;
|
|
129
|
+
}
|
|
130
|
+
interface AuroraController {
|
|
131
|
+
/** Pointer position in 0 to 1 space, origin at the bottom left. Smoothed with a spring. */
|
|
132
|
+
setPointer(x: number, y: number): void;
|
|
133
|
+
/** Animate the pointer's pull to a value from 0 to 1. */
|
|
134
|
+
setIntensity(value: number): void;
|
|
135
|
+
/** Apply new options in place, without rebuilding the effect. */
|
|
136
|
+
update(options: AuroraOptions): void;
|
|
137
|
+
destroy(): void;
|
|
138
|
+
}
|
|
139
|
+
declare function createAurora(container: HTMLElement, options?: AuroraOptions): AuroraController;
|
|
140
|
+
|
|
141
|
+
interface LensImageOptions {
|
|
142
|
+
/** Image URL. Must be same origin or served with CORS headers. */
|
|
143
|
+
src: string;
|
|
144
|
+
/** Magnification at the center of the lens. Defaults to 1.75. */
|
|
145
|
+
zoom?: number;
|
|
146
|
+
/** Lens radius in CSS pixels. Defaults to 96. */
|
|
147
|
+
size?: number;
|
|
148
|
+
/** Strength of the color fringing toward the rim, from 0 to 1. Defaults to 1. */
|
|
149
|
+
fringe?: number;
|
|
150
|
+
}
|
|
151
|
+
interface LensImageController {
|
|
152
|
+
/** Pointer position in 0 to 1 space, origin at the bottom left. The lens centers here. */
|
|
153
|
+
setPointer(x: number, y: number): void;
|
|
154
|
+
/** Animate the lens in (1) or out (0). */
|
|
155
|
+
setHover(value: number): void;
|
|
156
|
+
/**
|
|
157
|
+
* Apply new options in place. A new src keeps showing the current image
|
|
158
|
+
* until the new one has loaded.
|
|
159
|
+
*/
|
|
160
|
+
update(options: LensImageOptions): void;
|
|
161
|
+
destroy(): void;
|
|
162
|
+
}
|
|
163
|
+
declare function createLensImage(container: HTMLElement, options: LensImageOptions): LensImageController;
|
|
164
|
+
|
|
165
|
+
interface LiquidMetalOptions {
|
|
166
|
+
/** Number of blobs, from 1 to 12. */
|
|
167
|
+
count?: number;
|
|
168
|
+
/** Color the chrome is tinted with, as a hex value. White gives plain chrome. */
|
|
169
|
+
tint?: string;
|
|
170
|
+
/** Color behind the blobs, as a hex value. */
|
|
171
|
+
background?: string;
|
|
172
|
+
/** Time multiplier. 1 is the default speed. */
|
|
173
|
+
speed?: number;
|
|
174
|
+
}
|
|
175
|
+
interface LiquidMetalController {
|
|
176
|
+
/** Pointer position in 0 to 1 space, origin at the bottom left. The pointer's blob follows it. */
|
|
177
|
+
setPointer(x: number, y: number): void;
|
|
178
|
+
/** Grow (1) or shrink (0) the pointer's blob. */
|
|
179
|
+
setHover(value: number): void;
|
|
180
|
+
/** Apply new options in place, without rebuilding the effect. */
|
|
181
|
+
update(options: LiquidMetalOptions): void;
|
|
182
|
+
destroy(): void;
|
|
183
|
+
}
|
|
184
|
+
declare function createLiquidMetal(container: HTMLElement, options?: LiquidMetalOptions): LiquidMetalController;
|
|
185
|
+
|
|
186
|
+
interface HalftoneImageOptions {
|
|
187
|
+
/** Image URL. Must be same origin or served with CORS headers. */
|
|
188
|
+
src: string;
|
|
189
|
+
/** Distance between dot centers, in CSS pixels. Defaults to 8. */
|
|
190
|
+
cell?: number;
|
|
191
|
+
/** Dot color, as a hex value. Defaults to near-black. */
|
|
192
|
+
ink?: string;
|
|
193
|
+
/** Paper color behind the dots, as a hex value. Defaults to off-white. */
|
|
194
|
+
paper?: string;
|
|
195
|
+
/** Radius of the full-color area around the pointer, in CSS pixels. Defaults to 140. */
|
|
196
|
+
radius?: number;
|
|
197
|
+
}
|
|
198
|
+
interface HalftoneImageController {
|
|
199
|
+
/** Pointer position in 0 to 1 space, origin at the bottom left. */
|
|
200
|
+
setPointer(x: number, y: number): void;
|
|
201
|
+
/** Animate the full-color area in (1) or out (0). */
|
|
202
|
+
setHover(value: number): void;
|
|
203
|
+
/**
|
|
204
|
+
* Apply new options in place. A new src keeps showing the current image
|
|
205
|
+
* until the new one has loaded.
|
|
206
|
+
*/
|
|
207
|
+
update(options: HalftoneImageOptions): void;
|
|
208
|
+
destroy(): void;
|
|
209
|
+
}
|
|
210
|
+
declare function createHalftoneImage(container: HTMLElement, options: HalftoneImageOptions): HalftoneImageController;
|
|
211
|
+
|
|
212
|
+
interface PixelImageOptions {
|
|
213
|
+
/** Image URL. Must be same origin or served with CORS headers. */
|
|
214
|
+
src: string;
|
|
215
|
+
/** Block size away from the pointer, in CSS pixels. Defaults to 32. */
|
|
216
|
+
block?: number;
|
|
217
|
+
/** Radius of the sharp area around the pointer, in CSS pixels. Defaults to 180. */
|
|
218
|
+
radius?: number;
|
|
219
|
+
}
|
|
220
|
+
interface PixelImageController {
|
|
221
|
+
/** Pointer position in 0 to 1 space, origin at the bottom left. */
|
|
222
|
+
setPointer(x: number, y: number): void;
|
|
223
|
+
/** Animate the sharp area in (1) or out (0). */
|
|
224
|
+
setHover(value: number): void;
|
|
225
|
+
/**
|
|
226
|
+
* Apply new options in place. A new src keeps showing the current image
|
|
227
|
+
* until the new one has loaded.
|
|
228
|
+
*/
|
|
229
|
+
update(options: PixelImageOptions): void;
|
|
230
|
+
destroy(): void;
|
|
231
|
+
}
|
|
232
|
+
declare function createPixelImage(container: HTMLElement, options: PixelImageOptions): PixelImageController;
|
|
233
|
+
|
|
234
|
+
interface ParticlesOptions {
|
|
235
|
+
/** Number of particles, from 1 to 20000. */
|
|
236
|
+
count?: number;
|
|
237
|
+
/** Particle color, as a hex value. */
|
|
238
|
+
color?: string;
|
|
239
|
+
/** Color particles take on near the pointer, as a hex value. */
|
|
240
|
+
accent?: string;
|
|
241
|
+
/** Average particle diameter, in CSS pixels. */
|
|
242
|
+
size?: number;
|
|
243
|
+
/** How far the pointer's pull reaches, in CSS pixels. */
|
|
244
|
+
radius?: number;
|
|
245
|
+
/** Time multiplier for the drift. 1 is the default speed. */
|
|
246
|
+
speed?: number;
|
|
247
|
+
}
|
|
248
|
+
interface ParticlesController {
|
|
249
|
+
/** Pointer position in 0 to 1 space, origin at the bottom left. Particles gather here. */
|
|
250
|
+
setPointer(x: number, y: number): void;
|
|
251
|
+
/** Animate the pointer's pull from 0 to 1. */
|
|
252
|
+
setHover(value: number): void;
|
|
253
|
+
/** Apply new options in place. Changing count rebuilds only the particle positions. */
|
|
254
|
+
update(options: ParticlesOptions): void;
|
|
255
|
+
destroy(): void;
|
|
256
|
+
}
|
|
257
|
+
declare function createParticles(container: HTMLElement, options?: ParticlesOptions): ParticlesController;
|
|
258
|
+
|
|
259
|
+
interface Transition {
|
|
260
|
+
type?: "spring" | "tween";
|
|
261
|
+
stiffness?: number;
|
|
262
|
+
damping?: number;
|
|
263
|
+
duration?: number;
|
|
264
|
+
ease?: "linear" | "easeIn" | "easeOut" | "easeInOut";
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Describes a full-surface shader background. Every background gets the same
|
|
269
|
+
* uniforms for free: uTime (seconds, scaled by speed), uRes (CSS pixels),
|
|
270
|
+
* uPointer (0 to 1, origin at the bottom left) and uHover (0 to 1).
|
|
271
|
+
*/
|
|
272
|
+
interface BackgroundSpec<O, R> {
|
|
273
|
+
fragment: string;
|
|
274
|
+
/** Fill in defaults and clamp ranges. */
|
|
275
|
+
resolve(options: O): R;
|
|
276
|
+
/** Uniform values for these options. Called on create and on every update. */
|
|
277
|
+
uniforms(resolved: R): Record<string, unknown>;
|
|
278
|
+
/** CSS `background` value used when WebGL is unavailable. */
|
|
279
|
+
fallback(resolved: R): string;
|
|
280
|
+
/** Time multiplier. Gets the current hover amount, so hovering can speed things up. */
|
|
281
|
+
speed?(resolved: R, hover: number): number;
|
|
282
|
+
pointerSpring?: Transition;
|
|
283
|
+
hoverTransition?: Transition;
|
|
284
|
+
}
|
|
285
|
+
interface BackgroundController<O> {
|
|
286
|
+
/** Pointer position in 0 to 1 space, origin at the bottom left. Smoothed with a spring. */
|
|
287
|
+
setPointer(x: number, y: number): void;
|
|
288
|
+
/** Animate the pointer's influence from 0 to 1. */
|
|
289
|
+
setHover(value: number): void;
|
|
290
|
+
/** Apply new options in place, without rebuilding the effect. */
|
|
291
|
+
update(options: O): void;
|
|
292
|
+
destroy(): void;
|
|
293
|
+
}
|
|
294
|
+
declare function createBackground<O, R>(container: HTMLElement, options: O, spec: BackgroundSpec<O, R>): BackgroundController<O>;
|
|
295
|
+
|
|
296
|
+
interface MeshGradientOptions {
|
|
297
|
+
/** Four hex colors, each anchored to a slowly wandering point. */
|
|
298
|
+
colors?: [string, string, string, string];
|
|
299
|
+
/** Film grain strength, from 0 to 1. */
|
|
300
|
+
grain?: number;
|
|
301
|
+
/** Time multiplier. 1 is the default speed. */
|
|
302
|
+
speed?: number;
|
|
303
|
+
}
|
|
304
|
+
type MeshGradientController = BackgroundController<MeshGradientOptions>;
|
|
305
|
+
declare function createMeshGradient(container: HTMLElement, options?: MeshGradientOptions): MeshGradientController;
|
|
306
|
+
|
|
307
|
+
interface SilkOptions {
|
|
308
|
+
/** Fabric color, as a hex value. */
|
|
309
|
+
color?: string;
|
|
310
|
+
/** Color of the sheen along the folds, as a hex value. */
|
|
311
|
+
sheen?: string;
|
|
312
|
+
/** How many folds cross the surface. 1 is the default. */
|
|
313
|
+
folds?: number;
|
|
314
|
+
/** Time multiplier. 1 is the default speed. */
|
|
315
|
+
speed?: number;
|
|
316
|
+
}
|
|
317
|
+
type SilkController = BackgroundController<SilkOptions>;
|
|
318
|
+
declare function createSilk(container: HTMLElement, options?: SilkOptions): SilkController;
|
|
319
|
+
|
|
320
|
+
interface CausticsOptions {
|
|
321
|
+
/** Water color at the bottom of the element, as a hex value. */
|
|
322
|
+
deep?: string;
|
|
323
|
+
/** Water color at the top of the element, as a hex value. */
|
|
324
|
+
shallow?: string;
|
|
325
|
+
/** Color of the light lines, as a hex value. */
|
|
326
|
+
light?: string;
|
|
327
|
+
/** Time multiplier. 1 is the default speed. */
|
|
328
|
+
speed?: number;
|
|
329
|
+
}
|
|
330
|
+
type CausticsController = BackgroundController<CausticsOptions>;
|
|
331
|
+
declare function createCaustics(container: HTMLElement, options?: CausticsOptions): CausticsController;
|
|
332
|
+
|
|
333
|
+
interface ContourLinesOptions {
|
|
334
|
+
/** Line color, as a hex value. */
|
|
335
|
+
color?: string;
|
|
336
|
+
/** Color lines take on near the pointer, as a hex value. */
|
|
337
|
+
accent?: string;
|
|
338
|
+
/** Roughly how many lines cross the element from top to bottom. */
|
|
339
|
+
density?: number;
|
|
340
|
+
/** Line width, in CSS pixels. Every fifth line is drawn heavier. */
|
|
341
|
+
width?: number;
|
|
342
|
+
/** Time multiplier. 1 is the default speed. */
|
|
343
|
+
speed?: number;
|
|
344
|
+
}
|
|
345
|
+
type ContourLinesController = BackgroundController<ContourLinesOptions>;
|
|
346
|
+
declare function createContourLines(container: HTMLElement, options?: ContourLinesOptions): ContourLinesController;
|
|
347
|
+
|
|
348
|
+
interface StarfieldOptions {
|
|
349
|
+
/** Star color, as a hex value. */
|
|
350
|
+
color?: string;
|
|
351
|
+
/** Sky color, as a hex value. */
|
|
352
|
+
background?: string;
|
|
353
|
+
/** How many stars, as a multiplier. 1 is the default. */
|
|
354
|
+
density?: number;
|
|
355
|
+
/** Flight speed. 1 is the default; hovering doubles it. */
|
|
356
|
+
speed?: number;
|
|
357
|
+
}
|
|
358
|
+
type StarfieldController = BackgroundController<StarfieldOptions>;
|
|
359
|
+
declare function createStarfield(container: HTMLElement, options?: StarfieldOptions): StarfieldController;
|
|
360
|
+
|
|
361
|
+
/** Options every image effect takes. */
|
|
362
|
+
interface ImageEffectBaseOptions {
|
|
363
|
+
/** Image URL. Must be same origin or served with CORS headers. */
|
|
364
|
+
src: string;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Describes a shader effect on one image. The shader gets these uniforms for
|
|
368
|
+
* free: uTex (the image), uImgAspect (its width over height), uLoaded (0 to 1,
|
|
369
|
+
* fades in once the image loads), uTime (seconds), uRes (CSS pixels), uPointer
|
|
370
|
+
* (0 to 1, origin at the bottom left) and uHover (0 to 1). Include coverChunk
|
|
371
|
+
* from shaders.ts to crop the image like object-fit: cover.
|
|
372
|
+
*/
|
|
373
|
+
interface ImageEffectSpec<O extends ImageEffectBaseOptions, R> {
|
|
374
|
+
fragment: string;
|
|
375
|
+
/** Fill in defaults and clamp ranges. */
|
|
376
|
+
resolve(options: O): R;
|
|
377
|
+
/** Uniform values for these options. Called on create and on every update. */
|
|
378
|
+
uniforms(resolved: R): Record<string, unknown>;
|
|
379
|
+
/**
|
|
380
|
+
* Create extra GPU resources once, such as a texture of glyphs, and return
|
|
381
|
+
* them as uniforms. Textures returned here are freed with the effect.
|
|
382
|
+
*/
|
|
383
|
+
setup?(gl: Renderer["gl"], resolved: R): Record<string, unknown>;
|
|
384
|
+
pointerSpring?: Transition;
|
|
385
|
+
hoverTransition?: Transition;
|
|
386
|
+
}
|
|
387
|
+
interface ImageEffectController<O> {
|
|
388
|
+
/** Pointer position in 0 to 1 space, origin at the bottom left. */
|
|
389
|
+
setPointer(x: number, y: number): void;
|
|
390
|
+
/** Animate the effect's hover state from 0 to 1. */
|
|
391
|
+
setHover(value: number): void;
|
|
392
|
+
/**
|
|
393
|
+
* Apply new options in place. A new src keeps showing the current image
|
|
394
|
+
* until the new one has loaded.
|
|
395
|
+
*/
|
|
396
|
+
update(options: O): void;
|
|
397
|
+
destroy(): void;
|
|
398
|
+
}
|
|
399
|
+
declare function createImageEffect<O extends ImageEffectBaseOptions, R>(container: HTMLElement, options: O, spec: ImageEffectSpec<O, R>): ImageEffectController<O>;
|
|
400
|
+
|
|
401
|
+
interface VoronoiOptions {
|
|
402
|
+
/** Three hex colors the cells are tinted from. */
|
|
403
|
+
colors?: [string, string, string];
|
|
404
|
+
/** Color of the lines between cells, as a hex value. */
|
|
405
|
+
line?: string;
|
|
406
|
+
/** Roughly how many cells fit across the element's height. */
|
|
407
|
+
scale?: number;
|
|
408
|
+
/** Time multiplier. 1 is the default speed. */
|
|
409
|
+
speed?: number;
|
|
410
|
+
}
|
|
411
|
+
type VoronoiController = BackgroundController<VoronoiOptions>;
|
|
412
|
+
declare function createVoronoi(container: HTMLElement, options?: VoronoiOptions): VoronoiController;
|
|
413
|
+
|
|
414
|
+
interface GridFloorOptions {
|
|
415
|
+
/** Grid line color, as a hex value. */
|
|
416
|
+
color?: string;
|
|
417
|
+
/** Glow along the horizon, as a hex value. */
|
|
418
|
+
glow?: string;
|
|
419
|
+
/** Sky and floor color, as a hex value. */
|
|
420
|
+
background?: string;
|
|
421
|
+
/** How fast the grid rolls toward you. 1 is the default speed. */
|
|
422
|
+
speed?: number;
|
|
423
|
+
}
|
|
424
|
+
type GridFloorController = BackgroundController<GridFloorOptions>;
|
|
425
|
+
declare function createGridFloor(container: HTMLElement, options?: GridFloorOptions): GridFloorController;
|
|
426
|
+
|
|
427
|
+
interface InkSmokeOptions {
|
|
428
|
+
/** Smoke color, as a hex value. */
|
|
429
|
+
color?: string;
|
|
430
|
+
/** Color behind the smoke, as a hex value. */
|
|
431
|
+
background?: string;
|
|
432
|
+
/** Time multiplier. 1 is the default speed. */
|
|
433
|
+
speed?: number;
|
|
434
|
+
}
|
|
435
|
+
type InkSmokeController = BackgroundController<InkSmokeOptions>;
|
|
436
|
+
declare function createInkSmoke(container: HTMLElement, options?: InkSmokeOptions): InkSmokeController;
|
|
437
|
+
|
|
438
|
+
interface GlitchImageOptions {
|
|
439
|
+
/** Image URL. Must be same origin or served with CORS headers. */
|
|
440
|
+
src: string;
|
|
441
|
+
/** How hard the image glitches on hover, from 0 to 2. 1 is the default. */
|
|
442
|
+
strength?: number;
|
|
443
|
+
}
|
|
444
|
+
type GlitchImageController = ImageEffectController<GlitchImageOptions>;
|
|
445
|
+
declare function createGlitchImage(container: HTMLElement, options: GlitchImageOptions): GlitchImageController;
|
|
446
|
+
|
|
447
|
+
interface DitherImageOptions {
|
|
448
|
+
/** Image URL. Must be same origin or served with CORS headers. */
|
|
449
|
+
src: string;
|
|
450
|
+
/** Size of each dither dot, in CSS pixels. Defaults to 2. */
|
|
451
|
+
pixel?: number;
|
|
452
|
+
/** Dark color, as a hex value. */
|
|
453
|
+
ink?: string;
|
|
454
|
+
/** Light color, as a hex value. */
|
|
455
|
+
paper?: string;
|
|
456
|
+
/** Radius of the full-color area around the pointer, in CSS pixels. Defaults to 140. */
|
|
457
|
+
radius?: number;
|
|
458
|
+
}
|
|
459
|
+
type DitherImageController = ImageEffectController<DitherImageOptions>;
|
|
460
|
+
declare function createDitherImage(container: HTMLElement, options: DitherImageOptions): DitherImageController;
|
|
461
|
+
|
|
462
|
+
/** Hooks for effects built on the tilt card: extra uniforms, helper functions, and code that adjusts `col` before output. */
|
|
463
|
+
interface TiltShaderHooks {
|
|
464
|
+
uniforms?: string;
|
|
465
|
+
functions?: string;
|
|
466
|
+
color?: string;
|
|
467
|
+
}
|
|
468
|
+
declare function tiltShader(hooks?: TiltShaderHooks): string;
|
|
469
|
+
declare const noiseChunk = "\n// \"Hash without Sine\" by Dave Hoskins (MIT). Its small multipliers keep\n// rounding differences tiny, so neighbouring grid cells always agree on the\n// value at their shared corners. Hashes built on large multipliers can turn the\n// GPU's last-bit rounding differences into visible seams along the grid.\nfloat hash(vec2 p) {\n vec3 p3 = fract(vec3(p.xyx) * 0.1031);\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.x + p3.y) * p3.z);\n}\nvec2 hash2(vec2 p) {\n vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.xx + p3.yz) * p3.zy);\n}\nfloat noise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = fract(p);\n vec2 u = f * f * (3.0 - 2.0 * f);\n return mix(\n mix(hash(i), hash(i + vec2(1.0, 0.0)), u.x),\n mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x),\n u.y\n );\n}\nfloat fbm(vec2 p) {\n float v = 0.0;\n float a = 0.5;\n for (int i = 0; i < 5; i++) {\n v += a * noise(p);\n p = p * 2.02 + 17.1;\n a *= 0.5;\n }\n return v;\n}\n";
|
|
470
|
+
declare const coverChunk = "\nvec2 coverUv(vec2 uv, float boxAspect, float imgAspect) {\n vec2 s = vec2(1.0);\n if (boxAspect > imgAspect) s.y = imgAspect / boxAspect;\n else s.x = boxAspect / imgAspect;\n return (uv - 0.5) * s + 0.5;\n}\n";
|
|
471
|
+
|
|
472
|
+
interface AsciiImageOptions {
|
|
473
|
+
/** Image URL. Must be same origin or served with CORS headers. */
|
|
474
|
+
src: string;
|
|
475
|
+
/** Size of each character cell, in CSS pixels. Defaults to 10. */
|
|
476
|
+
cell?: number;
|
|
477
|
+
/** Character color, as a hex value. */
|
|
478
|
+
color?: string;
|
|
479
|
+
/** Background color, as a hex value. */
|
|
480
|
+
background?: string;
|
|
481
|
+
/** Color each character with the image's own color there, instead of `color`. */
|
|
482
|
+
colored?: boolean;
|
|
483
|
+
/** Radius of the area around the pointer where the real image shows, in CSS pixels. */
|
|
484
|
+
radius?: number;
|
|
485
|
+
}
|
|
486
|
+
type AsciiImageController = ImageEffectController<AsciiImageOptions>;
|
|
487
|
+
declare function createAsciiImage(container: HTMLElement, options: AsciiImageOptions): AsciiImageController;
|
|
488
|
+
|
|
489
|
+
interface DuotoneImageOptions {
|
|
490
|
+
/** Image URL. Must be same origin or served with CORS headers. */
|
|
491
|
+
src: string;
|
|
492
|
+
/** Color for the image's shadows, as a hex value. */
|
|
493
|
+
dark?: string;
|
|
494
|
+
/** Color for the image's highlights, as a hex value. */
|
|
495
|
+
light?: string;
|
|
496
|
+
}
|
|
497
|
+
type DuotoneImageController = ImageEffectController<DuotoneImageOptions>;
|
|
498
|
+
declare function createDuotoneImage(container: HTMLElement, options: DuotoneImageOptions): DuotoneImageController;
|
|
499
|
+
|
|
500
|
+
interface FogImageOptions {
|
|
501
|
+
/** Image URL. Must be same origin or served with CORS headers. */
|
|
502
|
+
src: string;
|
|
503
|
+
/** How frosted the glass is, from 0 to 1. Defaults to 1. */
|
|
504
|
+
frost?: number;
|
|
505
|
+
/** Color of the fog, as a hex value. */
|
|
506
|
+
tint?: string;
|
|
507
|
+
/** Radius of the clear area around the pointer, in CSS pixels. Defaults to 120. */
|
|
508
|
+
radius?: number;
|
|
509
|
+
}
|
|
510
|
+
type FogImageController = ImageEffectController<FogImageOptions>;
|
|
511
|
+
declare function createFogImage(container: HTMLElement, options: FogImageOptions): FogImageController;
|
|
512
|
+
|
|
513
|
+
interface KaleidoscopeImageOptions {
|
|
514
|
+
/** Image URL. Must be same origin or served with CORS headers. */
|
|
515
|
+
src: string;
|
|
516
|
+
/** Number of mirrored segments around the center. Defaults to 8. */
|
|
517
|
+
segments?: number;
|
|
518
|
+
/** How fast the pattern turns on its own. 1 is the default; 0 holds it still. */
|
|
519
|
+
speed?: number;
|
|
520
|
+
}
|
|
521
|
+
type KaleidoscopeImageController = ImageEffectController<KaleidoscopeImageOptions>;
|
|
522
|
+
declare function createKaleidoscopeImage(container: HTMLElement, options: KaleidoscopeImageOptions): KaleidoscopeImageController;
|
|
523
|
+
|
|
524
|
+
interface HoloCardOptions extends TiltCardOptions {
|
|
525
|
+
/** Strength of the holographic foil, from 0 to 1. Defaults to 0.8. */
|
|
526
|
+
foil?: number;
|
|
527
|
+
}
|
|
528
|
+
type HoloCardController = TiltEffectController<HoloCardOptions>;
|
|
529
|
+
declare function createHoloCard(container: HTMLElement, options: HoloCardOptions): HoloCardController;
|
|
530
|
+
|
|
531
|
+
interface SpotlightCardOptions {
|
|
532
|
+
/** Color of the border light and spotlight, as a hex value. */
|
|
533
|
+
color?: string;
|
|
534
|
+
/** Card fill color, as a hex value. */
|
|
535
|
+
background?: string;
|
|
536
|
+
/** Corner radius in CSS pixels. Match it with the element's own border-radius. */
|
|
537
|
+
radius?: number;
|
|
538
|
+
/** Border width in CSS pixels. */
|
|
539
|
+
border?: number;
|
|
540
|
+
}
|
|
541
|
+
type SpotlightCardController = BackgroundController<SpotlightCardOptions>;
|
|
542
|
+
declare function createSpotlightCard(container: HTMLElement, options?: SpotlightCardOptions): SpotlightCardController;
|
|
543
|
+
|
|
544
|
+
interface ShaderButtonOptions {
|
|
545
|
+
/** Three hex colors that flow through the button. */
|
|
546
|
+
colors?: [string, string, string];
|
|
547
|
+
/** Time multiplier. 1 is the default speed. */
|
|
548
|
+
speed?: number;
|
|
549
|
+
}
|
|
550
|
+
type ShaderButtonController = BackgroundController<ShaderButtonOptions>;
|
|
551
|
+
declare function createShaderButton(container: HTMLElement, options?: ShaderButtonOptions): ShaderButtonController;
|
|
552
|
+
|
|
553
|
+
interface ShaderTextOptions {
|
|
554
|
+
/** The text to draw. Use "\n" for line breaks; lines don't wrap. */
|
|
555
|
+
text: string;
|
|
556
|
+
/** Three hex colors that flow through the letters. */
|
|
557
|
+
colors?: [string, string, string];
|
|
558
|
+
/** Time multiplier. 1 is the default speed. */
|
|
559
|
+
speed?: number;
|
|
560
|
+
}
|
|
561
|
+
interface ShaderTextController {
|
|
562
|
+
/** Pointer position in 0 to 1 space, origin at the bottom left. */
|
|
563
|
+
setPointer(x: number, y: number): void;
|
|
564
|
+
/** Animate the pointer highlight from 0 to 1. */
|
|
565
|
+
setHover(value: number): void;
|
|
566
|
+
/** Apply new options in place. A new text redraws the letter mask. */
|
|
567
|
+
update(options: ShaderTextOptions): void;
|
|
568
|
+
destroy(): void;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Draws flowing color inside text. The effect mirrors `textElement`: it draws
|
|
572
|
+
* the text in that element's font, at that element's position, so the visible
|
|
573
|
+
* letters line up with real (transparent) text that stays selectable and is
|
|
574
|
+
* read by screen readers. Without `textElement` it draws at the top left in the
|
|
575
|
+
* container's font.
|
|
576
|
+
*/
|
|
577
|
+
declare function createShaderText(container: HTMLElement, options: ShaderTextOptions, textElement?: HTMLElement): ShaderTextController;
|
|
578
|
+
|
|
579
|
+
interface CursorTrailOptions {
|
|
580
|
+
/** Color at the head of the trail, as a hex value. */
|
|
581
|
+
color?: string;
|
|
582
|
+
/** Color at the end of the trail, as a hex value. */
|
|
583
|
+
tail?: string;
|
|
584
|
+
/** Width of the trail at its head, in CSS pixels. */
|
|
585
|
+
width?: number;
|
|
586
|
+
/** How long the trail is, from 4 to 40 segments. */
|
|
587
|
+
length?: number;
|
|
588
|
+
}
|
|
589
|
+
interface CursorTrailController {
|
|
590
|
+
/** Apply new options in place. */
|
|
591
|
+
update(options: CursorTrailOptions): void;
|
|
592
|
+
destroy(): void;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* A glowing trail that follows the mouse across the whole page. `container`
|
|
596
|
+
* should be a fixed, full-viewport element that ignores pointer events. The
|
|
597
|
+
* effect listens to the window itself, pauses once the cursor has been still
|
|
598
|
+
* for a moment, and stays off when the user prefers reduced motion or the page
|
|
599
|
+
* is used by touch.
|
|
600
|
+
*/
|
|
601
|
+
declare function createCursorTrail(container: HTMLElement, options?: CursorTrailOptions): CursorTrailController;
|
|
602
|
+
|
|
603
|
+
export { type AsciiImageController, type AsciiImageOptions, type AuroraController, type AuroraOptions, type BackgroundController, type BackgroundSpec, type CausticsController, type CausticsOptions, type ContourLinesController, type ContourLinesOptions, type CursorTrailController, type CursorTrailOptions, type DitherImageController, type DitherImageOptions, type DotGridController, type DotGridOptions, type DuotoneImageController, type DuotoneImageOptions, type FogImageController, type FogImageOptions, type GlitchImageController, type GlitchImageOptions, type GridFloorController, type GridFloorOptions, type HalftoneImageController, type HalftoneImageOptions, type HoloCardController, type HoloCardOptions, type ImageDistortionController, type ImageDistortionOptions, type ImageEffectBaseOptions, type ImageEffectController, type ImageEffectSpec, type ImageRevealController, type ImageRevealOptions, type InkSmokeController, type InkSmokeOptions, type KaleidoscopeImageController, type KaleidoscopeImageOptions, type LensImageController, type LensImageOptions, type LiquidMetalController, type LiquidMetalOptions, type MeshGradientController, type MeshGradientOptions, type ParticlesController, type ParticlesOptions, type PixelImageController, type PixelImageOptions, type ShaderButtonController, type ShaderButtonOptions, type ShaderGradientController, type ShaderGradientOptions, type ShaderTextController, type ShaderTextOptions, type SilkController, type SilkOptions, type SpotlightCardController, type SpotlightCardOptions, type StarfieldController, type StarfieldOptions, type TiltCardController, type TiltCardOptions, type TiltEffectController, type TiltShaderHooks, type VoronoiController, type VoronoiOptions, coverChunk, createAsciiImage, createAurora, createBackground, createCaustics, createContourLines, createCursorTrail, createDitherImage, createDotGrid, createDuotoneImage, createFogImage, createGlitchImage, createGridFloor, createHalftoneImage, createHoloCard, createImageDistortion, createImageEffect, createImageReveal, createInkSmoke, createKaleidoscopeImage, createLensImage, createLiquidMetal, createMeshGradient, createParticles, createPixelImage, createShaderButton, createShaderGradient, createShaderText, createSilk, createSpotlightCard, createStarfield, createTiltCard, createTiltEffect, createVoronoi, noiseChunk, tiltShader };
|