@arraypress/effects-astro 0.10.0 → 0.11.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/AGENTS.md CHANGED
@@ -10,7 +10,7 @@ Pick by what is asked for:
10
10
 
11
11
  | Asked for | Use |
12
12
  |---|---|
13
- | An animated, colourful background for a page or hero | `<LightField>` (liquid light), `<FlutedGlass>` (light, gallery-white or dark), `<AsciiRain>` (techy, dark), `<AsciiNoise>` (drifting blobs of monospace type; techy, terminal, studio), `<DotGrid>` (quiet, minimal), `<SignalLines>` / `<WaveBars>` (audio) |
13
+ | An animated, colourful background for a page or hero | `<LightField>` (liquid light), `<FlutedGlass>` (light, gallery-white or dark), `<AsciiRain>` (techy, dark), `<AsciiNoise>` (drifting blobs of monospace type; techy, terminal, studio), `<LightLeak>` (a soft drifting colour field), `<DitherField>` (dithered dots, ripples from a corner), `<CascadeGrid>` (a hex or dot spectrogram), `<FlowField>` (fine trails on a flow; Canvas), `<VoronoiMesh>` (thin nested cell lines), `<KineticGrid>` (a wire grid rain ripples), `<DotGrid>` (quiet, minimal), `<SignalLines>` / `<WaveBars>` (audio) |
14
14
  | Ink in water, a lit fluid background, or a hero whose colours a palette switcher changes | `<InkField palette="…">` (Lumetri, Forest, Cadmium, Peacock, Vermillion, Barbie, Uranium, Azure, Ruby, Ultramarine, Saffron, Crimson); `setColors(el, INK_PALETTES[name].colors, INK_PALETTES[name].glint)` recolours it live |
15
15
  | Something to play with: ink, smoke, liquid, "interactive" | `<Ink>` over a section, or `<LightField>` (it has the fluid under it), or `<DotGrid>` (click ripples) |
16
16
  | A soft gradient that drifts (a card, a hero, a section) — "grainy gradient", "mesh", "aurora" | `<LiveGradient colors={[…]}>` (lazy by default; `liveGradient(colors)` for HTML made in a script) |
package/COMPONENTS.md CHANGED
@@ -98,6 +98,23 @@ BorderSweep: a light travelling round an element's outline, on hover and focus o
98
98
  | `still` | `'ring' \| 'none'` | What reduced motion shows: `ring` a still lit edge where the light would run, `none` nothing. Default `ring`. |
99
99
  | `class` | `string` | Classes for the element. |
100
100
 
101
+ ## `<CascadeGrid>`
102
+
103
+ CascadeGrid: a grid of hexagons or dots that behaves like a scrolling spectrogram, each column showing the same made-up spectrum a little later than the last, so waves cascade across it and the cells swell from idle specks to reactive shapes. See src/runtime/cascade-grid.js.
104
+
105
+ ```astro
106
+ <section class="hero" style="position: relative; background: #0b0b0b">
107
+ <CascadeGrid colors={['#2a2a2a', '#c8ff00']} background="#0b0b0b" quiet={{ radius: 0.5, depth: 0.95 }} />
108
+ <h1>…</h1>
109
+ </section>
110
+ ```
111
+
112
+ | Prop | Type | |
113
+ |---|---|---|
114
+ | `fixed` | `boolean` | Fill the viewport (position: fixed). Default false. |
115
+ | `lazy` | `boolean \| string` | Run only while near the screen, giving its WebGL context back when away: for pages with many effects. Default false. |
116
+ | `class` | `string` | Classes for the element. |
117
+
101
118
  ## `<Caustics>`
102
119
 
103
120
  Caustics: sunlight through rippling water onto a pool floor, a bright, shifting net of light over an aqua ground, with a faint rainbow at the edges of its lines. The pointer stirs the water where it is; faint tiles can lie on the floor. See src/runtime/caustics.js.
@@ -172,6 +189,23 @@ Cursor: a custom cursor for the whole page: a dot at the pointer and a ring that
172
189
  | `size` | `number` | The ring's size at rest, px. Default 32. |
173
190
  | `blend` | `string` | Blend with the page: `difference` inverts what is under it, readable on any ground. Default `difference`. |
174
191
 
192
+ ## `<DitherField>`
193
+
194
+ DitherField: a field of slow noise drawn in square dots, Bayer-dithered at its edges into a solid, colour-banded core, with ripples running out from a corner, bent into shore-wave shapes. See src/runtime/dither-field.js.
195
+
196
+ ```astro
197
+ <section class="hero" style="position: relative; background: #0b0b0b">
198
+ <DitherField background="#0b0b0b" colors={['#3d4d0a', '#c8ff00']} quiet={{ x: 0.3, y: 0.5, radius: 0.6, depth: 1 }} />
199
+ <h1>…</h1>
200
+ </section>
201
+ ```
202
+
203
+ | Prop | Type | |
204
+ |---|---|---|
205
+ | `fixed` | `boolean` | Fill the viewport (position: fixed). Default false. |
206
+ | `lazy` | `boolean \| string` | Run only while near the screen (true, or how near as a CSS length), giving its WebGL context back when away: for pages with many effects. Default false. |
207
+ | `class` | `string` | Classes for the element. |
208
+
175
209
  ## `<DotGrid>`
176
210
 
177
211
  DotGrid: a sea of dots you can drop stones into. A slow current moves through a fixed grid of dots, a swell sits under the pointer, and a click sends a widening ripple across, lifting and pushing the dots. See src/runtime/dot-grid.js.
@@ -234,6 +268,38 @@ FitText: one line of text sized to exactly span its parent's content width, what
234
268
  | `as` | `HTMLTag` | The element to render. Default `div`. |
235
269
  | `class` | `string` | Classes for the element. |
236
270
 
271
+ ## `<FlowField>`
272
+
273
+ FlowField: hundreds of short, fine trails riding a slowly evolving noise flow, born, gathering into streams and fading, white on black by default; how many there are, how fast they go and how heavy the lines are drift slowly. See src/runtime/flow-field.js.
274
+
275
+ ```astro
276
+ <section class="hero" style="position: relative">
277
+ <FlowField colors={['#c8ff00', '#39ff88']} background="#0b0b0b" quiet={{ radius: 0.5, depth: 0.85 }} />
278
+ <h1>…</h1>
279
+ </section>
280
+ ```
281
+
282
+ | Prop | Type | |
283
+ |---|---|---|
284
+ | `colors` | `string[]` | The trails' colours, CSS hex, blended in Oklab along each trail's life (or by its speed). Default white. |
285
+ | `palette` | `PaletteName \| (string & {})` | A shared palette by name (`PALETTES`, any case), when there are no `colors`. |
286
+ | `background` | `string` | The ground, CSS hex: filled every frame, so the canvas is opaque. Default `#000000`. |
287
+ | `colorBy` | `'life' \| 'speed' \| 'random'` | What picks a trail's colour along `colors`: its age, how fast it travels, or one colour each at random. Default `life`. |
288
+ | `density` | `number` | Trails per 100 × 100 CSS px, on average. Default 12. |
289
+ | `length` | `number` | How much of its path a trail shows behind it, seconds. Default 0.5. |
290
+ | `weight` | `number` | Line width, CSS px. Default 0.7. |
291
+ | `opacity` | `number` | A trail head's opacity, 0–1; the tail fades from it. Default 0.75. |
292
+ | `pace` | `number` | How fast trails travel, CSS px a second, on average. Default 110. |
293
+ | `scale` | `number` | How many noise features span the element (across √(width × height)); higher is busier. Default 2. |
294
+ | `evolve` | `number` | How fast the field changes, noise units a second. Default 0.15. |
295
+ | `life` | `number` | A trail's average life, seconds (each lives half to one and a half times it). Default 4. |
296
+ | `vary` | `number` | How far the slow drives swing density, pace, weight and evolution, 0–1; 0 holds them. Default 0.7. |
297
+ | `speed` | `number` | Plays every clock faster or slower; 0 for one still frame. Default 1. |
298
+ | `seed` | `number` | Which field and which trails: the same seed draws the same. Default 1. |
299
+ | `quiet` | `{ x?: number; y?: number; radius?: number; depth?: number } \| null` | An area with fewer, fainter trails: centre (0–1 from the top left), radius (share of the height), depth (0–1). |
300
+ | `fixed` | `boolean` | Fill the viewport, behind the page (position: fixed, z-index -1). Default false. |
301
+ | `class` | `string` | Classes for the element. |
302
+
237
303
  ## `<FlutedGlass>`
238
304
 
239
305
  FlutedGlass: a pane of slanted fluted glass over soft blooms of colour, the main one following the pointer. Each rib bends what is behind it and fringes it with a thin rainbow. See src/runtime/fluted-glass.js.
@@ -560,6 +626,35 @@ IsoCity: a small isometric city in flat-shaded low poly, with cars driving its s
560
626
  | `fixed` | `boolean` | Fill the viewport, behind the page (position: fixed, z-index -1). Default false. |
561
627
  | `class` | `string` | Classes for the element. |
562
628
 
629
+ ## `<KineticGrid>`
630
+
631
+ KineticGrid: a fine wireframe grid that ripples where drops land, the rings spreading and settling, brighter where a wire is stretched, with thin bright ring pulses lighting the wire segments they cross. See src/runtime/kinetic-grid.js.
632
+
633
+ ```astro
634
+ <section class="hero" style="position: relative">
635
+ <KineticGrid colors={['#c8ff00', '#ffffff']} background="#0b0b0b" quiet={{ x: 0.3, y: 0.5, radius: 0.6, depth: 0.85 }} />
636
+ <h1>…</h1>
637
+ </section>
638
+ ```
639
+
640
+ | Prop | Type | |
641
+ |---|---|---|
642
+ | `colors` | `string[]` | Two CSS hex colours: the wires' and the pulses'. Default the sketch's blue and white. |
643
+ | `palette` | `PaletteName \| (string & {})` | A shared palette by name (`PALETTES`, any case), when there are no `colors`: its first colour for the wires, its glint for the pulses. |
644
+ | `background` | `string` | The ground, a CSS hex colour (opaque, so the canvas covers what is under it); `transparent` leaves it clear. Default '#0a0a0a'. |
645
+ | `cols` | `number` | Grid cells across, whatever the width (cells are square). Default 48. |
646
+ | `width` | `number` | A wire's width, CSS px. Default 1. |
647
+ | `rest` | `number` | How bright a wire at rest is, 0–1; stretched wires brighten to full. Default 0.35. |
648
+ | `drops` | `number` | Drops alive at once, 0–6 (each slot lands a new one about every five seconds). Default 4. |
649
+ | `strength` | `number` | How far the ripples push the wires, 0–1.6 (past that they fold). Default 1. |
650
+ | `size` | `number` | The ripples' scale: wavelength, reach and speed together, 0.5–2. Default 1. |
651
+ | `pulses` | `number` | Ring pulses alive at once, 0–4 (each slot about every two and a half seconds). Default 3. |
652
+ | `speed` | `number` | Plays the clock faster or slower; 0 for one still frame. Default 1. |
653
+ | `offset` | `number` | Seeds where and when drops land, so two cards differ. Default 0. |
654
+ | `quiet` | `{ x?: number; y?: number; radius?: number; depth?: number } \| null` | An area kept calm and dim: centre (0–1 from the top left), radius (share of the height), depth (0–1). |
655
+ | `fixed` | `boolean` | Fill the viewport (position: fixed). Default false. |
656
+ | `class` | `string` | Classes for the element. |
657
+
563
658
  ## `<LightField>`
564
659
 
565
660
  LightField: liquid light in three colours, bending around the pointer, with a real fluid under it that the pointer stirs and a click drops ink into. See src/runtime/light-field.js for how it is drawn.
@@ -585,6 +680,23 @@ LightField: liquid light in three colours, bending around the pointer, with a re
585
680
  | `background` | `string` | The colour under the light, and under the fallback gradient. Default `#08080a`. |
586
681
  | `class` | `string` | Classes for the element. |
587
682
 
683
+ ## `<LightLeak>`
684
+
685
+ LightLeak: a soft, slow colour field, a lava lamp or a light leak: drifting fBm blobs under a gentle warp, mixed through four colours (darkest first) in Oklab, with a breath too slow to see as one. See src/runtime/light-leak.js.
686
+
687
+ ```astro
688
+ <section class="hero" style="position: relative">
689
+ <LightLeak colors={['#0b0b0b', '#1a2a8c', '#0038ff', '#ff5c64']} quiet={{ radius: 0.5, depth: 0.8 }} />
690
+ <h1>…</h1>
691
+ </section>
692
+ ```
693
+
694
+ | Prop | Type | |
695
+ |---|---|---|
696
+ | `fixed` | `boolean` | Fill the viewport (position: fixed). Default false. |
697
+ | `lazy` | `boolean \| string` | Run only while near the screen (true, or a CSS length), giving its WebGL context back when away: for a wall of cards. Default false. |
698
+ | `class` | `string` | Classes for the element. |
699
+
588
700
  ## `<LiquidMetal>`
589
701
 
590
702
  LiquidMetal: a logo or a word made of liquid chrome. At rest it is a polished slab of metal reflecting a slowly turning studio; the pointer dents it and sends ripples across it, a stroke parts it, a click splashes it (a crater, a ring wave, droplets that fall and crawl back), and surface tension pulls it back into shape with a last wobble. See src/runtime/liquid-metal.js.
@@ -1344,6 +1456,22 @@ VariableType: a headline in a variable font whose letters swell under the pointe
1344
1456
  | `as` | `HTMLTag` | The element to render. Default `div`. |
1345
1457
  | `class` | `string` | Classes for the element. |
1346
1458
 
1459
+ ## `<VoronoiMesh>`
1460
+
1461
+ VoronoiMesh: a Voronoi mesh in thin lines on a ground, in two nested tiers: macro cells whose seeds orbit slowly, and inner cells inside each that pulse outward from its seed. Pale lines on deep maroon by default. See src/runtime/voronoi-mesh.js.
1462
+
1463
+ ```astro
1464
+ <section class="hero" style="position: relative">
1465
+ <VoronoiMesh cells={8} quiet={{ x: 0.3, y: 0.5, radius: 0.7, depth: 0.8 }} />
1466
+ <h1>…</h1>
1467
+ </section>
1468
+ ```
1469
+
1470
+ | Prop | Type | |
1471
+ |---|---|---|
1472
+ | `fixed` | `boolean` | Fill the viewport (position: fixed). Default false. |
1473
+ | `class` | `string` | Classes for the element. |
1474
+
1347
1475
  ## `<VoxelLogo>`
1348
1476
 
1349
1477
  VoxelLogo: a logo or character built of cubes, rocking slowly in perspective and turning towards the pointer, outlined where cubes meet and dithered down to two inks. With `markers`, tracking markers ring it. See src/runtime/voxel-logo.js.
package/LICENSE CHANGED
@@ -78,8 +78,8 @@ SOFTWARE.
78
78
 
79
79
  ---
80
80
 
81
- The hashes in src/runtime/shader-backgrounds/grain-gradient.js and
82
- src/runtime/ascii-noise.js are Dave Hoskins' "Hash without Sine" (https://www.shadertoy.com/view/4djSRW):
81
+ The hashes in src/runtime/shader-backgrounds/grain-gradient.js,
82
+ src/runtime/hash-noise.js and src/runtime/light-leak.js are Dave Hoskins' "Hash without Sine" (https://www.shadertoy.com/view/4djSRW):
83
83
 
84
84
  Copyright (c) 2014 David Hoskins
85
85
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arraypress/effects-astro",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "GPU effects for Astro sites, as components: liquid light with a real fluid under it, ink in water, and outline text a spotlight fills. Plain WebGL, no third-party dependencies, with the fallbacks a theme needs (reduced motion, no WebGL, touch screens, off-screen pausing).",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -0,0 +1,41 @@
1
+ ---
2
+ /**
3
+ * CascadeGrid: a grid of hexagons or dots that behaves like a scrolling
4
+ * spectrogram, each column showing the same made-up spectrum a little
5
+ * later than the last, so waves cascade across it and the cells swell
6
+ * from idle specks to reactive shapes. See src/runtime/cascade-grid.js.
7
+ *
8
+ * Fills its nearest positioned ancestor, or the viewport with `fixed`.
9
+ * Clear between the cells (or `background`), so it lays over any ground.
10
+ * Without WebGL it shows the grid at rest when it can (a `pitch` and a
11
+ * `background`), else the `background` colour.
12
+ *
13
+ * @example
14
+ * <section class="hero" style="position: relative; background: #0b0b0b">
15
+ * <CascadeGrid colors={['#2a2a2a', '#c8ff00']} background="#0b0b0b" quiet={{ radius: 0.5, depth: 0.95 }} />
16
+ * <h1>…</h1>
17
+ * </section>
18
+ */
19
+ import EffectCanvas from './EffectCanvas.astro';
20
+ import { cascadeStill, type CascadeGridConfig } from '../runtime/cascade-grid.js';
21
+
22
+ interface Props extends CascadeGridConfig {
23
+ /** Fill the viewport (position: fixed). Default false. */
24
+ fixed?: boolean;
25
+ /** Run only while near the screen, giving its WebGL context back when away: for pages with many effects. Default false. */
26
+ lazy?: boolean | string;
27
+ class?: string;
28
+ }
29
+
30
+ const { fixed = false, lazy = false, class: className, ...config } = Astro.props;
31
+ const still = config.background ? cascadeStill(config) : undefined;
32
+ ---
33
+
34
+ <EffectCanvas name="cascade-grid" config={config} fixed={fixed} lazy={lazy} background={still} class={className} />
35
+
36
+ <script>
37
+ import { mount } from '../runtime/mount.js';
38
+ import { cascadeGrid } from '../runtime/cascade-grid.js';
39
+
40
+ mount('[data-effect-cascade-grid]', cascadeGrid);
41
+ </script>
@@ -0,0 +1,41 @@
1
+ ---
2
+ /**
3
+ * DitherField: a field of slow noise drawn in square dots, Bayer-dithered
4
+ * at its edges into a solid, colour-banded core, with ripples running out
5
+ * from a corner, bent into shore-wave shapes. See
6
+ * src/runtime/dither-field.js.
7
+ *
8
+ * Fills its nearest positioned ancestor, or the viewport with `fixed`.
9
+ * Clear where there are no dots (or `background`), so it lays over any
10
+ * ground; with a `background`, the element shows a still of the field
11
+ * until the shader starts and without WebGL.
12
+ *
13
+ * @example
14
+ * <section class="hero" style="position: relative; background: #0b0b0b">
15
+ * <DitherField background="#0b0b0b" colors={['#3d4d0a', '#c8ff00']} quiet={{ x: 0.3, y: 0.5, radius: 0.6, depth: 1 }} />
16
+ * <h1>…</h1>
17
+ * </section>
18
+ */
19
+ import EffectCanvas from './EffectCanvas.astro';
20
+ import { ditherStill, type DitherFieldConfig } from '../runtime/dither-field.js';
21
+
22
+ interface Props extends DitherFieldConfig {
23
+ /** Fill the viewport (position: fixed). Default false. */
24
+ fixed?: boolean;
25
+ /** Run only while near the screen (true, or how near as a CSS length), giving its WebGL context back when away: for pages with many effects. Default false. */
26
+ lazy?: boolean | string;
27
+ class?: string;
28
+ }
29
+
30
+ const { fixed = false, lazy = false, class: className, ...config } = Astro.props;
31
+ const still = config.background ? ditherStill(config) : undefined;
32
+ ---
33
+
34
+ <EffectCanvas name="dither-field" config={config} fixed={fixed} lazy={lazy} background={still} pixelated class={className} />
35
+
36
+ <script>
37
+ import { mount } from '../runtime/mount.js';
38
+ import { ditherField } from '../runtime/dither-field.js';
39
+
40
+ mount('[data-effect-dither-field]', ditherField);
41
+ </script>
@@ -0,0 +1,38 @@
1
+ ---
2
+ /**
3
+ * FlowField: hundreds of short, fine trails riding a slowly evolving
4
+ * noise flow, born, gathering into streams and fading, white on black by
5
+ * default; how many there are, how fast they go and how heavy the lines
6
+ * are drift slowly. See src/runtime/flow-field.js.
7
+ *
8
+ * Opaque: it fills its `background` every frame, so it is the whole
9
+ * background of what it fills (its nearest positioned ancestor, or the
10
+ * viewport with `fixed`). Canvas 2D, so it needs no WebGL; one settled
11
+ * still frame with reduced motion. `setColors` recolours it live.
12
+ *
13
+ * @example
14
+ * <section class="hero" style="position: relative">
15
+ * <FlowField colors={['#c8ff00', '#39ff88']} background="#0b0b0b" quiet={{ radius: 0.5, depth: 0.85 }} />
16
+ * <h1>…</h1>
17
+ * </section>
18
+ */
19
+ import EffectCanvas from './EffectCanvas.astro';
20
+ import type { FlowFieldConfig } from '../runtime/flow-field.js';
21
+
22
+ interface Props extends FlowFieldConfig {
23
+ /** Fill the viewport, behind the page (position: fixed, z-index -1). Default false. */
24
+ fixed?: boolean;
25
+ class?: string;
26
+ }
27
+
28
+ const { fixed = false, class: className, ...config } = Astro.props;
29
+ ---
30
+
31
+ <EffectCanvas name="flow-field" config={config} fixed={fixed} class={className} behind background={config.background ?? '#000000'} />
32
+
33
+ <script>
34
+ import { mount } from '../runtime/mount.js';
35
+ import { flowField } from '../runtime/flow-field.js';
36
+
37
+ mount('[data-effect-flow-field]', flowField);
38
+ </script>
@@ -0,0 +1,38 @@
1
+ ---
2
+ /**
3
+ * KineticGrid: a fine wireframe grid that ripples where drops land, the
4
+ * rings spreading and settling, brighter where a wire is stretched, with
5
+ * thin bright ring pulses lighting the wire segments they cross. See
6
+ * src/runtime/kinetic-grid.js.
7
+ *
8
+ * Fills its nearest positioned ancestor, or the viewport with `fixed`.
9
+ * Paints its own ground (`background`; `transparent` lays it over the
10
+ * section's). Without WebGL the ground shows.
11
+ *
12
+ * @example
13
+ * <section class="hero" style="position: relative">
14
+ * <KineticGrid colors={['#c8ff00', '#ffffff']} background="#0b0b0b" quiet={{ x: 0.3, y: 0.5, radius: 0.6, depth: 0.85 }} />
15
+ * <h1>…</h1>
16
+ * </section>
17
+ */
18
+ import EffectCanvas from './EffectCanvas.astro';
19
+ import type { KineticGridConfig } from '../runtime/kinetic-grid.js';
20
+
21
+ interface Props extends KineticGridConfig {
22
+ /** Fill the viewport (position: fixed). Default false. */
23
+ fixed?: boolean;
24
+ class?: string;
25
+ }
26
+
27
+ const { fixed = false, class: className, ...config } = Astro.props;
28
+ const ground = config.background ?? '#0a0a0a';
29
+ ---
30
+
31
+ <EffectCanvas name="kinetic-grid" config={config} fixed={fixed} class={className} background={ground === 'transparent' ? undefined : ground} />
32
+
33
+ <script>
34
+ import { mount } from '../runtime/mount.js';
35
+ import { kineticGrid } from '../runtime/kinetic-grid.js';
36
+
37
+ mount('[data-effect-kinetic-grid]', kineticGrid);
38
+ </script>
@@ -0,0 +1,39 @@
1
+ ---
2
+ /**
3
+ * LightLeak: a soft, slow colour field, a lava lamp or a light leak:
4
+ * drifting fBm blobs under a gentle warp, mixed through four colours
5
+ * (darkest first) in Oklab, with a breath too slow to see as one. See
6
+ * src/runtime/light-leak.js.
7
+ *
8
+ * Fills its nearest positioned ancestor, or the viewport with `fixed`.
9
+ * Opaque. Shows a still of its first frame (`lightLeakStill`) before the
10
+ * shader starts and without WebGL.
11
+ *
12
+ * @example
13
+ * <section class="hero" style="position: relative">
14
+ * <LightLeak colors={['#0b0b0b', '#1a2a8c', '#0038ff', '#ff5c64']} quiet={{ radius: 0.5, depth: 0.8 }} />
15
+ * <h1>…</h1>
16
+ * </section>
17
+ */
18
+ import EffectCanvas from './EffectCanvas.astro';
19
+ import { lightLeakStill, type LightLeakConfig } from '../runtime/light-leak.js';
20
+
21
+ interface Props extends LightLeakConfig {
22
+ /** Fill the viewport (position: fixed). Default false. */
23
+ fixed?: boolean;
24
+ /** Run only while near the screen (true, or a CSS length), giving its WebGL context back when away: for a wall of cards. Default false. */
25
+ lazy?: boolean | string;
26
+ class?: string;
27
+ }
28
+
29
+ const { fixed = false, lazy = false, class: className, ...config } = Astro.props;
30
+ ---
31
+
32
+ <EffectCanvas name="light-leak" config={config} fixed={fixed} lazy={lazy} background={lightLeakStill(config, 16 / 9)} class={className} />
33
+
34
+ <script>
35
+ import { mount } from '../runtime/mount.js';
36
+ import { lightLeak } from '../runtime/light-leak.js';
37
+
38
+ mount('[data-effect-light-leak]', lightLeak);
39
+ </script>
@@ -0,0 +1,39 @@
1
+ ---
2
+ /**
3
+ * VoronoiMesh: a Voronoi mesh in thin lines on a ground, in two nested
4
+ * tiers: macro cells whose seeds orbit slowly, and inner cells inside each
5
+ * that pulse outward from its seed. Pale lines on deep maroon by default.
6
+ * See src/runtime/voronoi-mesh.js.
7
+ *
8
+ * Fills its nearest positioned ancestor, or the viewport with `fixed`.
9
+ * Opaque (its `background`), which the element shows before the shader
10
+ * starts and without WebGL; `meshStill` in the runtime makes an SVG still
11
+ * of the same frame for a box of known size (a card).
12
+ *
13
+ * @example
14
+ * <section class="hero" style="position: relative">
15
+ * <VoronoiMesh cells={8} quiet={{ x: 0.3, y: 0.5, radius: 0.7, depth: 0.8 }} />
16
+ * <h1>…</h1>
17
+ * </section>
18
+ */
19
+ import EffectCanvas from './EffectCanvas.astro';
20
+ import { MESH_DEFAULTS, type VoronoiMeshConfig } from '../runtime/voronoi-mesh.js';
21
+
22
+ interface Props extends VoronoiMeshConfig {
23
+ /** Fill the viewport (position: fixed). Default false. */
24
+ fixed?: boolean;
25
+ class?: string;
26
+ }
27
+
28
+ const { fixed = false, class: className, ...config } = Astro.props;
29
+ const ground = config.background ?? MESH_DEFAULTS.background;
30
+ ---
31
+
32
+ <EffectCanvas name="voronoi-mesh" config={config} fixed={fixed} background={ground} class={className} />
33
+
34
+ <script>
35
+ import { mount } from '../runtime/mount.js';
36
+ import { voronoiMesh } from '../runtime/voronoi-mesh.js';
37
+
38
+ mount('[data-effect-voronoi-mesh]', voronoiMesh);
39
+ </script>
package/src/index.d.ts CHANGED
@@ -8,6 +8,19 @@ export { asciiRain } from './runtime/ascii-rain.js';
8
8
  export type { AsciiRainConfig } from './runtime/ascii-rain.js';
9
9
  export { asciiNoise, asciiCells, noiseField, noiseColors, rampOf, NOISE_RAMPS, NOISE_DEFAULTS } from './runtime/ascii-noise.js';
10
10
  export type { AsciiNoiseConfig } from './runtime/ascii-noise.js';
11
+ export { lightLeak, lightLeakStill } from './runtime/light-leak.js';
12
+ export { ditherField, ditherStill } from './runtime/dither-field.js';
13
+ export { cascadeGrid, cascadeStill } from './runtime/cascade-grid.js';
14
+ export { flowField } from './runtime/flow-field.js';
15
+ export { voronoiMesh, meshStill } from './runtime/voronoi-mesh.js';
16
+ export { kineticGrid, gridStill } from './runtime/kinetic-grid.js';
17
+ export { hash33, grad, gnoise, GLSL_HASH33, GLSL_GRADIENT_NOISE, GLSL_NOISE_FIELD } from './runtime/hash-noise.js';
18
+ export type { LightLeakConfig } from './runtime/light-leak.js';
19
+ export type { DitherFieldConfig } from './runtime/dither-field.js';
20
+ export type { CascadeGridConfig } from './runtime/cascade-grid.js';
21
+ export type { FlowFieldConfig } from './runtime/flow-field.js';
22
+ export type { VoronoiMeshConfig } from './runtime/voronoi-mesh.js';
23
+ export type { KineticGridConfig } from './runtime/kinetic-grid.js';
11
24
  export { glassGlyph } from './runtime/glass-glyph.js';
12
25
  export type { GlassGlyphConfig } from './runtime/glass-glyph.js';
13
26
  export { flutedGlass } from './runtime/fluted-glass.js';
package/src/index.js CHANGED
@@ -16,6 +16,13 @@ export { ink } from './runtime/ink.js';
16
16
  export { spotlight } from './runtime/spotlight.js';
17
17
  export { asciiRain } from './runtime/ascii-rain.js';
18
18
  export { asciiNoise, asciiCells, noiseField, noiseColors, rampOf, NOISE_RAMPS, NOISE_DEFAULTS } from './runtime/ascii-noise.js';
19
+ export { lightLeak, lightLeakStill } from './runtime/light-leak.js';
20
+ export { ditherField, ditherStill } from './runtime/dither-field.js';
21
+ export { cascadeGrid, cascadeStill } from './runtime/cascade-grid.js';
22
+ export { flowField } from './runtime/flow-field.js';
23
+ export { voronoiMesh, meshStill } from './runtime/voronoi-mesh.js';
24
+ export { kineticGrid, gridStill } from './runtime/kinetic-grid.js';
25
+ export { hash33, grad, gnoise, GLSL_HASH33, GLSL_GRADIENT_NOISE, GLSL_NOISE_FIELD } from './runtime/hash-noise.js';
19
26
  export { glassGlyph } from './runtime/glass-glyph.js';
20
27
  export { flutedGlass } from './runtime/fluted-glass.js';
21
28
  export { particleLogo } from './runtime/particle-logo.js';
@@ -27,12 +27,16 @@
27
27
  */
28
28
 
29
29
  import { createStage } from './stage.js';
30
+ import { GLSL_GRADIENT_NOISE, GLSL_NOISE_FIELD, noiseField } from './hash-noise.js';
30
31
  import { GLSL_OKLAB, parseColor, toOklab } from './color.js';
31
32
  import { GLSL_QUIET, quietUniform } from './glsl.js';
32
33
  import { GLSL_GLYPHS, GLYPH_SETS, createGlyphs } from './glyphs.js';
33
34
  import { watchColors } from './mount.js';
34
35
  import { pickColors } from './palettes.js';
35
36
 
37
+ /** The warped field (./hash-noise.js), as 0.10.0 exported it from here. */
38
+ export { noiseField };
39
+
36
40
  /**
37
41
  * @typedef {object} AsciiNoiseConfig
38
42
  * @property {string[]} [colors] Two CSS hex colours: the quietest cells' and the loudest's. Default a dim grey and white.
@@ -106,42 +110,6 @@ export function rampOf(glyphs = NOISE_DEFAULTS.glyphs) {
106
110
  return chars.length > 1 ? chars : [...NOISE_RAMPS.ascii];
107
111
  }
108
112
 
109
- /**
110
- * GLSL (ES 1.00): `float noiseField(vec2 p, float evo, float wt)`, the
111
- * warped five-octave gradient noise, 0–1. `noiseField` below is the same
112
- * in JavaScript.
113
- */
114
- const GLSL_FIELD = `
115
- vec2 grad(vec2 p) {
116
- vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
117
- p3 += dot(p3, p3.yzx + 33.33);
118
- return -1.0 + 2.0 * fract((p3.xx + p3.yz) * p3.zy);
119
- }
120
- float gnoise(vec2 p) {
121
- vec2 i = floor(p);
122
- vec2 f = p - i;
123
- vec2 u = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);
124
- float a = dot(grad(i), f);
125
- float b = dot(grad(i + vec2(1.0, 0.0)), f - vec2(1.0, 0.0));
126
- float c = dot(grad(i + vec2(0.0, 1.0)), f - vec2(0.0, 1.0));
127
- float d = dot(grad(i + vec2(1.0, 1.0)), f - vec2(1.0, 1.0));
128
- return 0.5 + 0.5 * mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
129
- }
130
- float noiseField(vec2 p, float evo, float wt) {
131
- float warp = gnoise(p + wt * 0.04);
132
- float v = 0.0;
133
- float amp = 0.5;
134
- float freq = 1.0;
135
- for (int i = 0; i < 5; i++) {
136
- v += amp * gnoise(p * freq + vec2(warp * 0.3, warp * 0.25) + evo * 0.06);
137
- amp *= 0.5;
138
- freq *= 2.07;
139
- warp = v;
140
- }
141
- return v;
142
- }
143
- `;
144
-
145
113
  const FRAG = `
146
114
  precision highp float;
147
115
  uniform vec2 uRes;
@@ -159,7 +127,8 @@ uniform vec4 uBg;
159
127
  ${GLSL_OKLAB}
160
128
  ${GLSL_QUIET}
161
129
  ${GLSL_GLYPHS}
162
- ${GLSL_FIELD}
130
+ ${GLSL_GRADIENT_NOISE}
131
+ ${GLSL_NOISE_FIELD}
163
132
 
164
133
  void main() {
165
134
  // Cells counted from the top left, as the text still lays them.
@@ -181,76 +150,6 @@ void main() {
181
150
  }
182
151
  `;
183
152
 
184
- /**
185
- * One octave's gradient at a lattice point (the shader's `grad`): Dave
186
- * Hoskins' Hash without Sine, which brings its input under 1 before it
187
- * multiplies, so the GPU's 32-bit floats and these 64-bit ones agree.
188
- * (The sketch's own hash multiplied values in the thousands, where the
189
- * two drift apart and the text still would not be the shader's frame.)
190
- *
191
- * @param {number} x The point's x.
192
- * @param {number} y The point's y.
193
- * @returns {[number, number]} A gradient, each part −1 to 1.
194
- */
195
- function grad(x, y) {
196
- const fract = (/** @type {number} */ n) => n - Math.floor(n);
197
- let a = fract(x * 0.1031);
198
- let b = fract(y * 0.103);
199
- let c = fract(x * 0.0973);
200
- const d = a * (b + 33.33) + b * (c + 33.33) + c * (a + 33.33);
201
- a += d;
202
- b += d;
203
- c += d;
204
- return [-1 + 2 * fract((a + b) * c), -1 + 2 * fract((a + c) * b)];
205
- }
206
-
207
- /**
208
- * Gradient noise with a quintic fade (the shader's `gnoise`).
209
- *
210
- * @param {number} x Where, x.
211
- * @param {number} y Where, y.
212
- * @returns {number} 0–1.
213
- */
214
- function gnoise(x, y) {
215
- const ix = Math.floor(x);
216
- const iy = Math.floor(y);
217
- const fx = x - ix;
218
- const fy = y - iy;
219
- const ux = fx * fx * fx * (fx * (fx * 6 - 15) + 10);
220
- const uy = fy * fy * fy * (fy * (fy * 6 - 15) + 10);
221
- const dot = (/** @type {[number, number]} */ g, /** @type {number} */ dx, /** @type {number} */ dy) => g[0] * dx + g[1] * dy;
222
- const a = dot(grad(ix, iy), fx, fy);
223
- const b = dot(grad(ix + 1, iy), fx - 1, fy);
224
- const c = dot(grad(ix, iy + 1), fx, fy - 1);
225
- const d = dot(grad(ix + 1, iy + 1), fx - 1, fy - 1);
226
- const ab = a + (b - a) * ux;
227
- const cd = c + (d - c) * ux;
228
- return 0.5 + 0.5 * (ab + (cd - ab) * uy);
229
- }
230
-
231
- /**
232
- * The field: five octaves of gradient noise, each warped by the sum so far.
233
- *
234
- * @param {number} x Where, x.
235
- * @param {number} y Where, y.
236
- * @param {number} evo The morphing clock.
237
- * @param {number} wt The warp's clock (seconds).
238
- * @returns {number} 0–1, near 0.5 on average.
239
- */
240
- export function noiseField(x, y, evo, wt) {
241
- let warp = gnoise(x + wt * 0.04, y + wt * 0.04);
242
- let v = 0;
243
- let amp = 0.5;
244
- let freq = 1;
245
- for (let i = 0; i < 5; i++) {
246
- v += amp * gnoise(x * freq + warp * 0.3 + evo * 0.06, y * freq + warp * 0.25 + evo * 0.06);
247
- amp *= 0.5;
248
- freq *= 2.07;
249
- warp = v;
250
- }
251
- return v;
252
- }
253
-
254
153
  /**
255
154
  * One frame as ramp indices: what the shader draws, cell for cell, on a
256
155
  * target exactly `cols` by `rows` cells.