@arraypress/effects-astro 0.11.0 → 0.12.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), `<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) |
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), `<DitherGradient>` (a gradient in dithered or halftone dots: wave, band, swirl, pinwheel, steps), `<TruchetField>` (quarter-arc tiles turning a few at a time), `<PixelHorizon>` (a colour breaking into square blocks), `<FlutedGlow>` (a ring or orb of light through reeded glass), `<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
@@ -206,6 +206,23 @@ DitherField: a field of slow noise drawn in square dots, Bayer-dithered at its e
206
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
207
  | `class` | `string` | Classes for the element. |
208
208
 
209
+ ## `<DitherGradient>`
210
+
211
+ DitherGradient: a soft colour gradient drawn only in dots: a wavy horizon, a glowing band, a swirl, a pinwheel or stepped columns, square dots an ordered dither thins out or round halftone dots that shrink. See src/runtime/dither-gradient.js.
212
+
213
+ ```astro
214
+ <section class="hero" style="position: relative; background: #0b0b0b">
215
+ <DitherGradient background="#081226" colors={['#5a0f4a', '#ff1f8f']} shape="wave" quiet={{ radius: 0.5, depth: 1 }} />
216
+ <h1>…</h1>
217
+ </section>
218
+ ```
219
+
220
+ | Prop | Type | |
221
+ |---|---|---|
222
+ | `fixed` | `boolean` | Fill the viewport (position: fixed). Default false. |
223
+ | `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. |
224
+ | `class` | `string` | Classes for the element. |
225
+
209
226
  ## `<DotGrid>`
210
227
 
211
228
  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.
@@ -326,6 +343,23 @@ FlutedGlass: a pane of slanted fluted glass over soft blooms of colour, the main
326
343
  | `fixed` | `boolean` | Fill the viewport, behind the page (position: fixed, z-index -1). Default false. |
327
344
  | `class` | `string` | Classes for the element. |
328
345
 
346
+ ## `<FlutedGlow>`
347
+
348
+ FlutedGlow: a soft ring, orb or rising light seen through upright reeded glass, breathing slowly, made to sit behind copy (no pointer). See src/runtime/fluted-glow.js.
349
+
350
+ ```astro
351
+ <section class="hero" style="position: relative; background: #0b0b0b">
352
+ <FlutedGlow colors={['#7a1d00', '#ff7a00', '#ffd27a']} shape="ring" />
353
+ <h1>…</h1>
354
+ </section>
355
+ ```
356
+
357
+ | Prop | Type | |
358
+ |---|---|---|
359
+ | `fixed` | `boolean` | Fill the viewport (position: fixed). Default false. |
360
+ | `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. |
361
+ | `class` | `string` | Classes for the element. |
362
+
329
363
  ## `<Galaxy>`
330
364
 
331
365
  Galaxy: deep space in your colours. Soft nebula clouds with dark dust lanes, fine glitter shimmering over them and stars twinkling each on its own beat, the brightest with a cross of light, all drifting slowly. See src/runtime/galaxy.js.
@@ -1009,24 +1043,31 @@ PixelFountain: retro 8-bit sparks. Chunky square pixels fire up out of the host'
1009
1043
  <PixelFountain cell={8} />
1010
1044
  …
1011
1045
  </footer>
1046
+ @example
1047
+ <div class="wordmark-wrap" style="position: relative; color: #0b0b0b">
1048
+ <PixelFountain source="pointer" cell={10} />
1049
+ <FitText as="div">Arcadia</FitText>
1050
+ </div>
1012
1051
  ```
1013
1052
 
1014
1053
  | Prop | Type | |
1015
1054
  |---|---|---|
1016
- | `color` | `string` | The pixels' colour when they fire; the darker steps they fade through are made from it. Default `#c8ff00`. |
1017
- | `colors` | `string[]` | The steps a pixel fades through, first to last (overrides `color`). Default made from `color`. |
1055
+ | `color` | `string` | The pixels' colour when they fire; the darker steps they fade through are made from it. With `source="pointer"`, the one ink every block is drawn in. Default `#c8ff00` (from the pointer, the text's colour, `currentColor`). |
1056
+ | `colors` | `string[]` | The steps a pixel fades through, first to last (overrides `color`; from the pointer, only the first is used). Default made from `color`. |
1018
1057
  | `palette` | `string` | A shared palette by name, its colours as the steps, when there are no `colors`. Default none. |
1019
1058
  | `cell` | `number` | A pixel's size, CSS px (a power-up's biggest blocks are two). Default 8. |
1020
- | `rise` | `number` | How far above the edge the pixels can fly, CSS px. Default 240. |
1021
- | `rate` | `number` | Pixels a second trickling up on their own, per 1,000 CSS px of edge; 0 for none. Default 14. |
1022
- | `burst` | `number` | Pixels a click or tap fires. Default 40. |
1059
+ | `rise` | `number` | How far above the edge the pixels can fly, CSS px (from the pointer: how far above the host the canvas reaches). Default 240 (160 from the pointer). |
1060
+ | `rate` | `number` | Pixels a second trickling up on their own, per 1,000 CSS px of edge; 0 for none (always none from the pointer). Default 14. |
1061
+ | `burst` | `number` | Pixels a click or tap fires. Default 40 (24 from the pointer). |
1062
+ | `trail` | `number` | From the pointer: blocks fired for every 100 CSS px it moves, at most 12 a move. Default 10. |
1063
+ | `press` | `boolean` | Whether a mouse click fires a burst (a tap always does). Default true (false from the pointer). |
1023
1064
  | `gravity` | `number` | How hard they are pulled back, 0–2. Default 1. |
1024
1065
  | `spread` | `number` | How widely they fan out, 0–1. Default 0.5. |
1025
1066
  | `drift` | `number` | How much a wind pushes them sideways, 0–1. Default 0.3. |
1026
- | `life` | `number` | The longest a pixel lives, seconds. Default 1.4. |
1027
- | `split` | `number` | The chance a pixel splits into smaller ones rather than shrinking, 0–1. Default 0.4. |
1028
- | `flicker` | `number` | The chance a pixel flickers out on and off before it goes, 0–1. Default 0.35. |
1029
- | `source` | `'edge' \| 'text'` | Fire from the host's top edge, or from the filled pixels of its text. Default `edge`. |
1067
+ | `life` | `number` | The longest a pixel lives, seconds. Default 1.4 (0.9 from the pointer). |
1068
+ | `split` | `number` | The chance a pixel splits into smaller ones rather than shrinking, 0–1. Default 0.4 (0.2 from the pointer). |
1069
+ | `flicker` | `number` | The chance a pixel flickers out on and off before it goes, 0–1. Default 0.35 (0.5 from the pointer). |
1070
+ | `source` | `'edge' \| 'text' \| 'pointer'` | Fire from the host's top edge; from the filled pixels of its text; or only from the pointer, where it moves over the host (a block-dust trail in one ink, nothing on its own). Default `edge`. |
1030
1071
  | `host` | `string` | A selector for the element the pixels fire from and the pointer is followed over: the nearest ancestor that matches, else the first on the page. Default the element's positioned parent. |
1031
1072
  | `seed` | `number` | Seeds the randomness. Default 1. |
1032
1073
  | `zIndex` | `number` | The canvas's `z-index`, over what is above the host. Default none (auto). |
@@ -1035,7 +1076,7 @@ PixelFountain: retro 8-bit sparks. Chunky square pixels fire up out of the host'
1035
1076
 
1036
1077
  ## `<PixelGlitchText>`
1037
1078
 
1038
- PixelGlitchText: one line of text that breaks into pixels under the pointer and knits back together behind it. With `stroke`, a hollow outline at rest that the pixels fill in; `tear="row"` tears whole rows, and `ghost` lays a coloured copy behind the blocks. See src/runtime/pixel-glitch.js.
1079
+ PixelGlitchText: one line of text that breaks into pixels under the pointer and knits back together behind it. With `stroke`, a hollow outline at rest that the pixels fill in; `tear="row"` tears whole rows, and `ghost` lays a coloured copy behind the blocks; `glitch={false}` keeps only the drawing at rest (a still outlined wordmark). See src/runtime/pixel-glitch.js.
1039
1080
 
1040
1081
  ```astro
1041
1082
  <footer>
@@ -1053,10 +1094,28 @@ PixelGlitchText: one line of text that breaks into pixels under the pointer and
1053
1094
  | `stroke` | `number` | With a width (CSS px), the text at rest is an outline that the pixels fill: one outline round the word, so overlapping letters merge. Default 0 (solid). |
1054
1095
  | `tear` | `'cell' \| 'row'` | What slips: `cell`, each hot cell on its own; `row`, a whole row at once, now and then, by its hottest cell (up to half of `shift` either way). Default `cell`. |
1055
1096
  | `ghost` | `string` | A colour for a copy of the blocks, nudged 3px right behind them (an accent under the break). Default none. |
1097
+ | `glitch` | `boolean` | Break into pixels under the pointer. False only draws the text at rest (with `stroke`, its merged outline), everywhere, with reduced motion and on touch screens too: the same look, the pointer left to something else. Default true. |
1056
1098
  | `as` | `HTMLTag` | The element to render. Default `span`. |
1057
1099
  | `fit` | `boolean` | Size the text to span its parent's width. Default false. |
1058
1100
  | `class` | `string` | Classes for the element. |
1059
1101
 
1102
+ ## `<PixelHorizon>`
1103
+
1104
+ PixelHorizon: a flat colour filling one side and breaking up into square blocks toward the other, blocks winking on and off along a slowly swaying frontier. See src/runtime/pixel-horizon.js.
1105
+
1106
+ ```astro
1107
+ <section class="hero" style="position: relative; background: #0b0b0b">
1108
+ <PixelHorizon background="#0b0b0b" colors={['#1aff00']} side="bottom" quiet={{ radius: 0.42, depth: 1 }} />
1109
+ <h1>…</h1>
1110
+ </section>
1111
+ ```
1112
+
1113
+ | Prop | Type | |
1114
+ |---|---|---|
1115
+ | `fixed` | `boolean` | Fill the viewport (position: fixed). Default false. |
1116
+ | `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. |
1117
+ | `class` | `string` | Classes for the element. |
1118
+
1060
1119
  ## `<PointCloud>`
1061
1120
 
1062
1121
  PointCloud: a word drawn as a matrix of bright dots among rippling sheets of point cloud, the scene tilting towards the pointer. With `trackers`, boxes lock onto the word like a detector's debug view. See src/runtime/point-cloud.js.
@@ -1420,6 +1479,23 @@ Topography: a survey map that never sits still. The contour lines of a slowly dr
1420
1479
  | `fixed` | `boolean` | Fill the viewport, behind the page (position: fixed, z-index -1). Default false. |
1421
1480
  | `class` | `string` | Classes for the element. |
1422
1481
 
1482
+ ## `<TruchetField>`
1483
+
1484
+ TruchetField: a field of Truchet tiles, quarter arcs that join into loops and S-bends, a few tiles turning at a time, bright patches drifting through. See src/runtime/truchet-field.js.
1485
+
1486
+ ```astro
1487
+ <section class="hero" style="position: relative; background: #0b0b0b">
1488
+ <TruchetField background="#0b0b0b" colors={['#3a3a3a', '#f4f3ef']} quiet={{ radius: 0.5, depth: 0.9 }} />
1489
+ <h1>…</h1>
1490
+ </section>
1491
+ ```
1492
+
1493
+ | Prop | Type | |
1494
+ |---|---|---|
1495
+ | `fixed` | `boolean` | Fill the viewport (position: fixed). Default false. |
1496
+ | `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. |
1497
+ | `class` | `string` | Classes for the element. |
1498
+
1423
1499
  ## `<Typewriter>`
1424
1500
 
1425
1501
  Typewriter: types phrases one after another behind a blinking caret, deleting each before the next. "Sell beats / sample packs / presets." Screen readers get the phrases as a list once, not a stream of letters; with reduced motion the first phrase simply shows. See src/runtime/text-motion.js.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arraypress/effects-astro",
3
- "version": "0.11.0",
3
+ "version": "0.12.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
+ * DitherGradient: a soft colour gradient drawn only in dots: a wavy
4
+ * horizon, a glowing band, a swirl, a pinwheel or stepped columns, square
5
+ * dots an ordered dither thins out or round halftone dots that shrink. See
6
+ * src/runtime/dither-gradient.js.
7
+ *
8
+ * Fills its nearest positioned ancestor, or the viewport with `fixed`.
9
+ * Clear where there is nothing drawn, so it lays over any ground; with a
10
+ * `background`, the element shows a CSS still until the shader starts and
11
+ * without WebGL.
12
+ *
13
+ * @example
14
+ * <section class="hero" style="position: relative; background: #0b0b0b">
15
+ * <DitherGradient background="#081226" colors={['#5a0f4a', '#ff1f8f']} shape="wave" quiet={{ radius: 0.5, depth: 1 }} />
16
+ * <h1>…</h1>
17
+ * </section>
18
+ */
19
+ import EffectCanvas from './EffectCanvas.astro';
20
+ import { gradientStill, type DitherGradientConfig } from '../runtime/dither-gradient.js';
21
+
22
+ interface Props extends DitherGradientConfig {
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 ? gradientStill(config) : undefined;
32
+ ---
33
+
34
+ <EffectCanvas name="dither-gradient" config={config} fixed={fixed} lazy={lazy} background={still} class={className} />
35
+
36
+ <script>
37
+ import { mount } from '../runtime/mount.js';
38
+ import { ditherGradient } from '../runtime/dither-gradient.js';
39
+
40
+ mount('[data-effect-dither-gradient]', ditherGradient);
41
+ </script>
@@ -0,0 +1,39 @@
1
+ ---
2
+ /**
3
+ * FlutedGlow: a soft ring, orb or rising light seen through upright reeded
4
+ * glass, breathing slowly, made to sit behind copy (no pointer). See
5
+ * src/runtime/fluted-glow.js.
6
+ *
7
+ * Fills its nearest positioned ancestor, or the viewport with `fixed`.
8
+ * Opaque: it paints its `background` (default near-black) everywhere; the
9
+ * element shows a CSS still of it until the shader starts and without WebGL.
10
+ *
11
+ * @example
12
+ * <section class="hero" style="position: relative; background: #0b0b0b">
13
+ * <FlutedGlow colors={['#7a1d00', '#ff7a00', '#ffd27a']} shape="ring" />
14
+ * <h1>…</h1>
15
+ * </section>
16
+ */
17
+ import EffectCanvas from './EffectCanvas.astro';
18
+ import { glowStill, type FlutedGlowConfig } from '../runtime/fluted-glow.js';
19
+
20
+ interface Props extends FlutedGlowConfig {
21
+ /** Fill the viewport (position: fixed). Default false. */
22
+ fixed?: boolean;
23
+ /** 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. */
24
+ lazy?: boolean | string;
25
+ class?: string;
26
+ }
27
+
28
+ const { fixed = false, lazy = false, class: className, ...config } = Astro.props;
29
+ const still = glowStill(config);
30
+ ---
31
+
32
+ <EffectCanvas name="fluted-glow" config={config} fixed={fixed} lazy={lazy} background={still} class={className} />
33
+
34
+ <script>
35
+ import { mount } from '../runtime/mount.js';
36
+ import { flutedGlow } from '../runtime/fluted-glow.js';
37
+
38
+ mount('[data-effect-fluted-glow]', flutedGlow);
39
+ </script>
@@ -9,19 +9,31 @@
9
9
  * fires a stream, a click or tap a power-up. See
10
10
  * src/runtime/pixel-fountain.js.
11
11
  *
12
+ * With `source="pointer"`, blocks fire only where the pointer is, as it
13
+ * moves over the host: a block-dust trail off the cursor, in one solid ink
14
+ * (the text's colour, or `color`), that pops up, arcs and breaks down within
15
+ * about a second. Nothing on its own, nothing while the pointer rests; a
16
+ * tap fires a burst where it lands (a click too with `press`).
17
+ *
12
18
  * Put it inside the host (its nearest positioned ancestor): the canvas sits
13
19
  * above the host's top edge, `rise` px tall (over the host and above it
14
- * with `source="text"`), so the host must not clip its top (no
20
+ * with `source="text"` or `"pointer"`), so the host must not clip its top (no
15
21
  * `overflow: hidden`; `overflow-x: clip` is fine). Or put it in a
16
22
  * zero-height positioned strip on the host's top edge and name the host
17
23
  * with `host`. The canvas takes no pointer events; the host's are read.
18
- * With reduced motion, a still scatter of pixels.
24
+ * With reduced motion, a still scatter of pixels (nothing from the pointer).
19
25
  *
20
26
  * @example
21
27
  * <footer class="site-footer" style="position: relative">
22
28
  * <PixelFountain cell={8} />
23
29
  * …
24
30
  * </footer>
31
+ *
32
+ * @example
33
+ * <div class="wordmark-wrap" style="position: relative; color: #0b0b0b">
34
+ * <PixelFountain source="pointer" cell={10} />
35
+ * <FitText as="div">Arcadia</FitText>
36
+ * </div>
25
37
  */
26
38
  import EffectCanvas from './EffectCanvas.astro';
27
39
  import type { PixelFountainConfig } from '../runtime/pixel-fountain.js';
@@ -35,9 +47,10 @@ interface Props extends PixelFountainConfig {
35
47
  }
36
48
 
37
49
  const { zIndex, lazy = false, class: className, ...config } = Astro.props;
38
- const rise = config.rise ?? 240;
39
- const text = config.source === 'text';
40
- const classes = ['effect-pixel-fountain', text && 'is-text', className].filter(Boolean).join(' ');
50
+ const pointer = config.source === 'pointer';
51
+ const rise = config.rise ?? (pointer ? 160 : 240);
52
+ const over = config.source === 'text' || pointer;
53
+ const classes = ['effect-pixel-fountain', over && 'is-over', className].filter(Boolean).join(' ');
41
54
  ---
42
55
 
43
56
  <EffectCanvas
@@ -62,8 +75,8 @@ const classes = ['effect-pixel-fountain', text && 'is-text', className].filter(B
62
75
  inset: auto 0 100% 0;
63
76
  height: var(--fountain-rise);
64
77
  }
65
- /* From the text: over the host and the space above it. */
66
- :global(.effect-canvas.effect-pixel-fountain.is-text[data-effect-pixel-fountain]) {
78
+ /* From the text or the pointer: over the host and the space above it. */
79
+ :global(.effect-canvas.effect-pixel-fountain.is-over[data-effect-pixel-fountain]) {
67
80
  inset: auto 0 0 0;
68
81
  height: calc(100% + var(--fountain-rise));
69
82
  }
@@ -3,7 +3,8 @@
3
3
  * PixelGlitchText: one line of text that breaks into pixels under the
4
4
  * pointer and knits back together behind it. With `stroke`, a hollow
5
5
  * outline at rest that the pixels fill in; `tear="row"` tears whole rows,
6
- * and `ghost` lays a coloured copy behind the blocks. See
6
+ * and `ghost` lays a coloured copy behind the blocks; `glitch={false}`
7
+ * keeps only the drawing at rest (a still outlined wordmark). See
7
8
  * src/runtime/pixel-glitch.js.
8
9
  *
9
10
  * With `fit`, the text is sized to span its parent's width (a footer
@@ -27,13 +28,13 @@ interface Props extends PixelGlitchConfig {
27
28
  [attribute: string]: unknown;
28
29
  }
29
30
 
30
- const { as: Tag = 'span', fit = false, cell, reach, decay, block, shift, stroke, tear, ghost, class: className, style: given, ...attributes } = Astro.props;
31
+ const { as: Tag = 'span', fit = false, cell, reach, decay, block, shift, stroke, tear, ghost, glitch, class: className, style: given, ...attributes } = Astro.props;
31
32
  ---
32
33
 
33
34
  <Tag
34
35
  class:list={['effect-pixel-glitch', { 'is-outline': (stroke ?? 0) > 0 }, className]}
35
36
  data-effect-pixel-glitch
36
- data-effect-config={JSON.stringify({ cell, reach, decay, block, shift, stroke, tear, ghost })}
37
+ data-effect-config={JSON.stringify({ cell, reach, decay, block, shift, stroke, tear, ghost, glitch })}
37
38
  data-fit-text={fit ? '' : undefined}
38
39
  style={withStyle(stroke ? `--glitch-stroke: ${stroke}px` : undefined, given)}
39
40
  {...attributes}
@@ -0,0 +1,40 @@
1
+ ---
2
+ /**
3
+ * PixelHorizon: a flat colour filling one side and breaking up into square
4
+ * blocks toward the other, blocks winking on and off along a slowly
5
+ * swaying frontier. See src/runtime/pixel-horizon.js.
6
+ *
7
+ * Fills its nearest positioned ancestor, or the viewport with `fixed`.
8
+ * Clear where there is nothing drawn, so it lays over any ground; with a
9
+ * `background`, the element shows a CSS still until the shader starts and
10
+ * without WebGL.
11
+ *
12
+ * @example
13
+ * <section class="hero" style="position: relative; background: #0b0b0b">
14
+ * <PixelHorizon background="#0b0b0b" colors={['#1aff00']} side="bottom" quiet={{ radius: 0.42, depth: 1 }} />
15
+ * <h1>…</h1>
16
+ * </section>
17
+ */
18
+ import EffectCanvas from './EffectCanvas.astro';
19
+ import { horizonStill, type PixelHorizonConfig } from '../runtime/pixel-horizon.js';
20
+
21
+ interface Props extends PixelHorizonConfig {
22
+ /** Fill the viewport (position: fixed). Default false. */
23
+ fixed?: boolean;
24
+ /** 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. */
25
+ lazy?: boolean | string;
26
+ class?: string;
27
+ }
28
+
29
+ const { fixed = false, lazy = false, class: className, ...config } = Astro.props;
30
+ const still = config.background ? horizonStill(config) : undefined;
31
+ ---
32
+
33
+ <EffectCanvas name="pixel-horizon" config={config} fixed={fixed} lazy={lazy} background={still} pixelated class={className} />
34
+
35
+ <script>
36
+ import { mount } from '../runtime/mount.js';
37
+ import { pixelHorizon } from '../runtime/pixel-horizon.js';
38
+
39
+ mount('[data-effect-pixel-horizon]', pixelHorizon);
40
+ </script>
@@ -0,0 +1,40 @@
1
+ ---
2
+ /**
3
+ * TruchetField: a field of Truchet tiles, quarter arcs that join into
4
+ * loops and S-bends, a few tiles turning at a time, bright patches
5
+ * drifting through. See src/runtime/truchet-field.js.
6
+ *
7
+ * Fills its nearest positioned ancestor, or the viewport with `fixed`.
8
+ * Clear where there is nothing drawn, so it lays over any ground; with a
9
+ * `background`, the element shows a CSS still until the shader starts and
10
+ * without WebGL.
11
+ *
12
+ * @example
13
+ * <section class="hero" style="position: relative; background: #0b0b0b">
14
+ * <TruchetField background="#0b0b0b" colors={['#3a3a3a', '#f4f3ef']} quiet={{ radius: 0.5, depth: 0.9 }} />
15
+ * <h1>…</h1>
16
+ * </section>
17
+ */
18
+ import EffectCanvas from './EffectCanvas.astro';
19
+ import { truchetStill, type TruchetFieldConfig } from '../runtime/truchet-field.js';
20
+
21
+ interface Props extends TruchetFieldConfig {
22
+ /** Fill the viewport (position: fixed). Default false. */
23
+ fixed?: boolean;
24
+ /** 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. */
25
+ lazy?: boolean | string;
26
+ class?: string;
27
+ }
28
+
29
+ const { fixed = false, lazy = false, class: className, ...config } = Astro.props;
30
+ const still = config.background ? truchetStill(config) : undefined;
31
+ ---
32
+
33
+ <EffectCanvas name="truchet-field" config={config} fixed={fixed} lazy={lazy} background={still} class={className} />
34
+
35
+ <script>
36
+ import { mount } from '../runtime/mount.js';
37
+ import { truchetField } from '../runtime/truchet-field.js';
38
+
39
+ mount('[data-effect-truchet-field]', truchetField);
40
+ </script>
package/src/index.d.ts CHANGED
@@ -15,6 +15,15 @@ export { flowField } from './runtime/flow-field.js';
15
15
  export { voronoiMesh, meshStill } from './runtime/voronoi-mesh.js';
16
16
  export { kineticGrid, gridStill } from './runtime/kinetic-grid.js';
17
17
  export { hash33, grad, gnoise, GLSL_HASH33, GLSL_GRADIENT_NOISE, GLSL_NOISE_FIELD } from './runtime/hash-noise.js';
18
+ export { ditherGradient, gradientStill } from './runtime/dither-gradient.js';
19
+ export { truchetField, truchetStill } from './runtime/truchet-field.js';
20
+ export { pixelHorizon, horizonStill } from './runtime/pixel-horizon.js';
21
+ export { flutedGlow, glowStill } from './runtime/fluted-glow.js';
22
+ export { bayer, GLSL_BAYER } from './runtime/bayer.js';
23
+ export type { DitherGradientConfig } from './runtime/dither-gradient.js';
24
+ export type { TruchetFieldConfig } from './runtime/truchet-field.js';
25
+ export type { PixelHorizonConfig } from './runtime/pixel-horizon.js';
26
+ export type { FlutedGlowConfig } from './runtime/fluted-glow.js';
18
27
  export type { LightLeakConfig } from './runtime/light-leak.js';
19
28
  export type { DitherFieldConfig } from './runtime/dither-field.js';
20
29
  export type { CascadeGridConfig } from './runtime/cascade-grid.js';
@@ -33,7 +42,7 @@ export { voxelLogo } from './runtime/voxel-logo.js';
33
42
  export type { VoxelLogoConfig } from './runtime/voxel-logo.js';
34
43
  export { pixelGlitch, outlineAlpha, rowTears } from './runtime/pixel-glitch.js';
35
44
  export type { PixelGlitchConfig } from './runtime/pixel-glitch.js';
36
- export { pixelFountain, createFountain, fadeSteps, shadeAt, tierSizes, pixelRect, inkedCells, MAX_PIXELS } from './runtime/pixel-fountain.js';
45
+ export { pixelFountain, createFountain, fadeSteps, shadeAt, tierSizes, pixelRect, inkedCells, MAX_PIXELS, TRAIL_CAP, POINTER_DEFAULTS } from './runtime/pixel-fountain.js';
37
46
  export type { PixelFountainConfig, Pixel, EmitKind, FountainOptions, Fountain } from './runtime/pixel-fountain.js';
38
47
  export { fit, fitText } from './runtime/fit-text.js';
39
48
  export { textNodes, textRange, splitLetters, joinLetters, textNodesWithin, paintGlyphs } from './runtime/text.js';
package/src/index.js CHANGED
@@ -23,13 +23,18 @@ export { flowField } from './runtime/flow-field.js';
23
23
  export { voronoiMesh, meshStill } from './runtime/voronoi-mesh.js';
24
24
  export { kineticGrid, gridStill } from './runtime/kinetic-grid.js';
25
25
  export { hash33, grad, gnoise, GLSL_HASH33, GLSL_GRADIENT_NOISE, GLSL_NOISE_FIELD } from './runtime/hash-noise.js';
26
+ export { ditherGradient, gradientStill } from './runtime/dither-gradient.js';
27
+ export { truchetField, truchetStill } from './runtime/truchet-field.js';
28
+ export { pixelHorizon, horizonStill } from './runtime/pixel-horizon.js';
29
+ export { flutedGlow, glowStill } from './runtime/fluted-glow.js';
30
+ export { bayer, GLSL_BAYER } from './runtime/bayer.js';
26
31
  export { glassGlyph } from './runtime/glass-glyph.js';
27
32
  export { flutedGlass } from './runtime/fluted-glass.js';
28
33
  export { particleLogo } from './runtime/particle-logo.js';
29
34
  export { pointCloud } from './runtime/point-cloud.js';
30
35
  export { voxelLogo } from './runtime/voxel-logo.js';
31
36
  export { pixelGlitch, outlineAlpha, rowTears } from './runtime/pixel-glitch.js';
32
- export { pixelFountain, createFountain, fadeSteps, shadeAt, tierSizes, pixelRect, inkedCells, MAX_PIXELS } from './runtime/pixel-fountain.js';
37
+ export { pixelFountain, createFountain, fadeSteps, shadeAt, tierSizes, pixelRect, inkedCells, MAX_PIXELS, TRAIL_CAP, POINTER_DEFAULTS } from './runtime/pixel-fountain.js';
33
38
  export { fit, fitText } from './runtime/fit-text.js';
34
39
  export { textNodes, textRange, splitLetters, joinLetters, textNodesWithin, paintGlyphs } from './runtime/text.js';
35
40
  export { variableType, DEFAULT_AXES } from './runtime/variable-type.js';
@@ -0,0 +1,5 @@
1
+ /** GLSL (ES 1.00): `float bayer8(vec2 cell)`, the 8×8 Bayer threshold 0–63/64 at a dot. */
2
+ export declare const GLSL_BAYER: string;
3
+
4
+ /** The 8×8 Bayer threshold at a dot, 0–63/64 (it repeats every 8 dots). */
5
+ export declare function bayer(x: number, y: number): number;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/bayer
3
+ *
4
+ * The 8×8 Bayer ordered-dither threshold, as GLSL and as a JS function of
5
+ * the same values, built from the 2×2 matrix at three scales so neither
6
+ * side needs a texture. Shared by DitherField and DitherGradient.
7
+ */
8
+
9
+ /**
10
+ * The fractional part.
11
+ *
12
+ * @param {number} n A number.
13
+ * @returns {number} `n − floor(n)`, 0–1.
14
+ */
15
+ const fract = (n) => n - Math.floor(n);
16
+
17
+ /** GLSL (ES 1.00): `float bayer8(vec2 cell)`, the threshold 0–63/64 at a dot (it repeats every 8 dots). */
18
+ export const GLSL_BAYER = `
19
+ float bayer2(vec2 a) { return fract(a.x * 0.5 + a.y * a.y * 0.75); }
20
+ float bayer8(vec2 cell) {
21
+ vec2 a = mod(floor(cell), 8.0);
22
+ vec2 b = floor(a * 0.5);
23
+ vec2 c = floor(a * 0.25);
24
+ return bayer2(a) + bayer2(b) * 0.25 + bayer2(c) * 0.0625;
25
+ }
26
+ `;
27
+
28
+ /**
29
+ * The 8×8 Bayer threshold at a dot (the shader's `bayer8`): the classic
30
+ * ordered-dither matrix, 0/64 to 63/64.
31
+ *
32
+ * @param {number} x The dot's column (any integer; it repeats every 8).
33
+ * @param {number} y The dot's row.
34
+ * @returns {number} The threshold, 0–63/64.
35
+ */
36
+ export function bayer(x, y) {
37
+ /**
38
+ * The 2×2 matrix (0, 2 / 3, 1 over 4) by a cell's parity.
39
+ *
40
+ * @param {number} a Column.
41
+ * @param {number} b Row.
42
+ * @returns {number} 0, 0.25, 0.5 or 0.75.
43
+ */
44
+ const two = (a, b) => fract(a * 0.5 + b * b * 0.75);
45
+ const ax = ((Math.floor(x) % 8) + 8) % 8;
46
+ const ay = ((Math.floor(y) % 8) + 8) % 8;
47
+ return two(ax, ay) + two(Math.floor(ax / 2), Math.floor(ay / 2)) * 0.25 + two(Math.floor(ax / 4), Math.floor(ay / 4)) * 0.0625;
48
+ }
@@ -37,6 +37,7 @@ import { GLSL_GRADIENT_NOISE, GLSL_NOISE_FIELD, grad, gnoise, noiseField } from
37
37
  import { GLSL_OKLAB, parseColor, toOklab, mixOklab, toHex } from './color.js';
38
38
  import { GLSL_QUIET, quietUniform } from './glsl.js';
39
39
  import { watchColors } from './mount.js';
40
+ import { GLSL_BAYER, bayer } from './bayer.js';
40
41
  import { pickColors } from './palettes.js';
41
42
 
42
43
  /**
@@ -92,19 +93,12 @@ const ZONES = { edge: 0.1, core: 0.3, bias: 0.2, inner: 0.8, fuzz: 0.02, gain: 8
92
93
  const AMBER = ['#b4b4b4', '#ffbe50'];
93
94
 
94
95
  /**
95
- * GLSL (ES 1.00): `float bayer8(vec2 cell)`, the 8×8 Bayer threshold
96
- * (0–63 over 64) built from the 2×2 one, and `float ripplePulse(float s)`,
97
- * a smooth 1-D noise, 0–1, that the rings are cut from. `bayer` and
98
- * `ripplePulse` below are the same in JavaScript.
96
+ * GLSL (ES 1.00): `float ripplePulse(float s)`, a smooth 1-D noise, 0–1,
97
+ * that the rings are cut from (`ripplePulse` below is the same in
98
+ * JavaScript). The Bayer threshold is `./bayer.js`'s.
99
99
  */
100
100
  const GLSL_DITHER = `
101
- float bayer2(vec2 a) { return fract(a.x * 0.5 + a.y * a.y * 0.75); }
102
- float bayer8(vec2 cell) {
103
- vec2 a = mod(floor(cell), 8.0);
104
- vec2 b = floor(a * 0.5);
105
- vec2 c = floor(a * 0.25);
106
- return bayer2(a) + bayer2(b) * 0.25 + bayer2(c) * 0.0625;
107
- }
101
+ ${GLSL_BAYER}
108
102
  float hash11(float p) {
109
103
  p = fract(p * 0.1031);
110
104
  p *= p + 33.33;
@@ -203,28 +197,8 @@ const smooth = (e0, e1, x) => {
203
197
  */
204
198
  const quintic = (f) => f * f * f * (f * (f * 6 - 15) + 10);
205
199
 
206
- /**
207
- * The 8×8 Bayer threshold at a dot (the shader's `bayer8`): the classic
208
- * ordered-dither matrix, 0/64 to 63/64, built from the 2×2 one at three
209
- * scales, so neither side needs a texture.
210
- *
211
- * @param {number} x The dot's column (any integer; it repeats every 8).
212
- * @param {number} y The dot's row.
213
- * @returns {number} The threshold, 0–63/64.
214
- */
215
- export function bayer(x, y) {
216
- /**
217
- * The 2×2 matrix (0, 2 / 3, 1 over 4) by a cell's parity.
218
- *
219
- * @param {number} a Column.
220
- * @param {number} b Row.
221
- * @returns {number} 0, 0.25, 0.5 or 0.75.
222
- */
223
- const two = (a, b) => fract(a * 0.5 + b * b * 0.75);
224
- const ax = ((Math.floor(x) % 8) + 8) % 8;
225
- const ay = ((Math.floor(y) % 8) + 8) % 8;
226
- return two(ax, ay) + two(Math.floor(ax / 2), Math.floor(ay / 2)) * 0.25 + two(Math.floor(ax / 4), Math.floor(ay / 4)) * 0.0625;
227
- }
200
+ /** The 8×8 Bayer threshold at a dot (`./bayer.js`), exported here as before. */
201
+ export { bayer };
228
202
 
229
203
  /**
230
204
  * A hash of one number (the shader's `hash11`): Dave Hoskins' Hash without