@arraypress/effects-astro 0.8.0 → 0.10.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), `<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), `<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) |
@@ -38,7 +38,7 @@ Pick by what is asked for:
38
38
  | Sections that arrive on scroll, site-wide | `<ScrollReveal />` once in the layout, then reveal.css classes (`fade-in-up`…) on elements |
39
39
  | A type foundry or bold brand headline: big variable-font letters that swell under the pointer | `<VariableType as="h1" fit>` set in a variable font (`axes` for which axes swell) |
40
40
  | Text that arrives or moves | `<Reveal>`, `<ScrambleText>`, `<Typewriter>`, `<HighlightSweep>`, `<Marquee>` |
41
- | A headline that glitches now and then (a label, a studio, a "make it yours" card) | `<GlitchText as="h2">` (CSS only; `blend="screen"` on a dark ground, `every`, `colors`) |
41
+ | A headline that glitches now and then (a label, a studio, a "make it yours" card) | `<GlitchText as="h2">` (CSS only; `blend="screen"` on a dark ground, `every`, `colors`; `variant="skew"` shakes the whole word; `copies="pseudo"` for one element of plain text) |
42
42
  | A small logo mark, a loading or "live" sign | `<PulseMark>`, `.fx-live` from `motion.css` |
43
43
  | A hero photo that reacts like water: ripples, a pond, "touch the photo" | `<ImageRipple src="…" alt="…">` (`strength`, `size`, `viscosity`, `fringe`, `fit="contain"`) |
44
44
  | A digital-goods or shop hero showing the products: their covers as the centrepiece, copy beside them | `<ProductStack items={[{ src, href, alt }, …]}>` (`layout="fan"`, `"stack"` or `"arc"`), or the covers as `<a><img></a>` children |
package/COMPONENTS.md CHANGED
@@ -4,6 +4,38 @@ Every component in `@arraypress/effects-astro`, with every prop. Generated from
4
4
 
5
5
  Import each from its own path: `import Name from '@arraypress/effects-astro/Name.astro'`.
6
6
 
7
+ ## `<AsciiNoise>`
8
+
9
+ AsciiNoise: a field of slow noise drawn as a grid of monospace characters, soft-edged blobs of type drifting and morphing, the quiet cells in one colour and the loud in another. See src/runtime/ascii-noise.js.
10
+
11
+ ```astro
12
+ <section class="hero" style="position: relative; background: #0b0b0b">
13
+ <AsciiNoise glyphs="shade" colors={['#2c3a0a', '#c8ff00']} quiet={{ x: 0.3, y: 0.5, radius: 0.6, depth: 0.9 }} />
14
+ <h1>…</h1>
15
+ </section>
16
+ ```
17
+
18
+ | Prop | Type | |
19
+ |---|---|---|
20
+ | `colors` | `string[]` | Two CSS hex colours: the quietest cells' and the loudest's. Default a dim grey and white. |
21
+ | `palette` | `PaletteName \| (string & {})` | A shared palette by name (`PALETTES`, any case), when there are no `colors`: its first and last colours. |
22
+ | `background` | `string` | A CSS hex colour to fill behind the type; none leaves the canvas clear there. |
23
+ | `glyphs` | `keyof typeof NOISE_RAMPS \| (string & {})` | A ramp (`ascii`, `shade`, `digits`, `rise`, `quads`, `bars`, `arrows`, `letters`, `dense`, or a set of `GLYPH_SETS`) or the characters, quietest first. Default `ascii`. |
24
+ | `cell` | `number` | A character cell's height in CSS px. Default 14. |
25
+ | `cols` | `number` | Cells across instead, whatever the width (overrides `cell`). |
26
+ | `aspect` | `number` | A cell's width over its height. Default 0.6. |
27
+ | `scale` | `number` | How many noise features span the width (higher is busier). Default 2.45. |
28
+ | `contrast` | `number` | How hard the edges are: higher pushes cells to empty or full. Default 6. |
29
+ | `brightness` | `number` | Shifts the whole field; lower leaves more cells empty. Default -0.1. |
30
+ | `drift` | `[number, number]` | How fast the sample window pans, widths a second, x and y. Default [0.036, 0.012]. |
31
+ | `evolve` | `number` | How fast the shapes morph. Default 0.24. |
32
+ | `offset` | `[number, number]` | Where the sample window starts, so two cards differ. Default [0, 0]. |
33
+ | `speed` | `number` | Plays every clock faster or slower; 0 for one still frame. Default 1. |
34
+ | `quiet` | `{ x?: number; y?: number; radius?: number; depth?: number } \| null` | An area kept quiet: centre (0–1 from the top left), radius (share of the height), depth (0–1). |
35
+ | `font` | `string` | The font family the glyphs are drawn in (a monospace stack by default); it is loaded first. |
36
+ | `fixed` | `boolean` | Fill the viewport (position: fixed). Default false. |
37
+ | `class` | `string` | Classes for the element. |
38
+
7
39
  ## `<AsciiRain>`
8
40
 
9
41
  AsciiRain: data rain on a rippling surface, drawn in text characters, with red and blue fringes at the glyph edges. The pointer ripples the surface and a click sends a ring out. See src/runtime/ascii-rain.js.
@@ -60,6 +92,10 @@ BorderSweep: a light travelling round an element's outline, on hover and focus o
60
92
  | `always` | `boolean` | Run all the time, not only on hover. Default false. |
61
93
  | `lights` | `1 \| 2` | How many lights go round, 1–2: two chase each other half a lap apart. Default 1. |
62
94
  | `inset` | `boolean` | Draw the ring inside the edge and over the content, for elements that clip (`overflow: hidden`) and fill themselves with a picture or a canvas. Default false. |
95
+ | `long` | `boolean` | A longer light: a faint lead-in over the quarter lap before it, then the light and its tail. Default false. |
96
+ | `outset` | `number` | How far the ring sits out past the edge, px: 1 lays it over a 1px border. Default 0. |
97
+ | `focus` | `'within' \| 'visible' \| 'none'` | Which focus lights it: `within` when it or anything in it has the focus, `visible` only its own keyboard focus, `none` never (hover only). Default `within`. |
98
+ | `still` | `'ring' \| 'none'` | What reduced motion shows: `ring` a still lit edge where the light would run, `none` nothing. Default `ring`. |
63
99
  | `class` | `string` | Classes for the element. |
64
100
 
65
101
  ## `<Caustics>`
@@ -327,6 +363,8 @@ GlitchText: a headline that glitches now and then. Every few seconds two coloure
327
363
  | `colors` | `string[]` | The two copies' colours. Default `['#ff3ea5', '#2e4bff']` (pink and blue). |
328
364
  | `palette` | `PaletteName \| (string & {})` | A shared palette by name (`PALETTES`, any case), its first two colours, when there are no `colors`. |
329
365
  | `blend` | `'multiply' \| 'screen' \| 'normal' \| 'difference' \| 'plus-lighter'` | How the copies blend with the text and what is behind: `multiply` on a light ground, `screen` on a dark one. Default `multiply`. |
366
+ | `copies` | `'spans' \| 'pseudo'` | How the copies are drawn: `spans`, the slot laid twice more (inline formatting kept), or `pseudo`, the element's `::before` and `::after` from a `data-text` of the slot's words (one element; plain text only). Default `spans`. |
367
+ | `variant` | `'slice' \| 'skew'` | The glitch: `slice`, the copies sliced into four bands and shifted a few pixels while the text nudges; `skew`, the whole word shaking and skewing while the copies tear through three bands, shifted by a share of the type size. Default `slice`. |
330
368
  | `class` | `string` | Classes for the element. |
331
369
 
332
370
  ## `<GlowField>`
@@ -632,7 +670,10 @@ Marquee: an endless strip that scrolls sideways, for "as featured in" logos, art
632
670
  | `gap` | `string` | Space between items, CSS length. Default `2.5rem`. |
633
671
  | `pauseOnHover` | `boolean` | Pause while the pointer is over it. Default true. |
634
672
  | `pauseButton` | `boolean` | Show a pause button. Default true. |
635
- | `fade` | `number` | How wide the faded edges are, % of the strip. Default 8. |
673
+ | `fade` | `number` | How wide the faded edges are, % of the strip; 0 cuts them. Default 8. |
674
+ | `copies` | `2 \| 3 \| 4` | How many times the content is laid, 2–4; the strip moves by one of them a loop. Two is enough when one set is always wider than the strip. Default 4. |
675
+ | `role` | `'region' \| 'marquee' \| 'note'` | What it is to assistive technology: `region` a landmark, `marquee` a ticker, `note` an aside. Default `region`. |
676
+ | `still` | `'scroll' \| 'hold'` | With reduced motion: `scroll`, one set as a still row to scroll by hand; `hold`, the strip held where it starts, every set laid. Default `scroll`. |
636
677
  | `labels` | `{ pause: string; resume: string }` | The pause button's labels, for other languages. Default English. |
637
678
  | `label` | `string` | What the strip is, for screen readers. Default the items joined. |
638
679
  | `class` | `string` | Classes for the element. |
package/LICENSE CHANGED
@@ -78,8 +78,8 @@ SOFTWARE.
78
78
 
79
79
  ---
80
80
 
81
- The hash in src/runtime/shader-backgrounds/grain-gradient.js is Dave Hoskins'
82
- "Hash without Sine" (https://www.shadertoy.com/view/4djSRW):
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):
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.8.0",
3
+ "version": "0.10.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,37 @@
1
+ ---
2
+ /**
3
+ * AsciiNoise: a field of slow noise drawn as a grid of monospace
4
+ * characters, soft-edged blobs of type drifting and morphing, the quiet
5
+ * cells in one colour and the loud in another. See
6
+ * src/runtime/ascii-noise.js.
7
+ *
8
+ * Fills its nearest positioned ancestor, or the viewport with `fixed`.
9
+ * Clear where the cells are empty (or `background`), so it lays over any
10
+ * ground. Without WebGL nothing is drawn.
11
+ *
12
+ * @example
13
+ * <section class="hero" style="position: relative; background: #0b0b0b">
14
+ * <AsciiNoise glyphs="shade" colors={['#2c3a0a', '#c8ff00']} quiet={{ x: 0.3, y: 0.5, radius: 0.6, depth: 0.9 }} />
15
+ * <h1>…</h1>
16
+ * </section>
17
+ */
18
+ import EffectCanvas from './EffectCanvas.astro';
19
+ import type { AsciiNoiseConfig } from '../runtime/ascii-noise.js';
20
+
21
+ interface Props extends AsciiNoiseConfig {
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
+ ---
29
+
30
+ <EffectCanvas name="ascii-noise" config={config} fixed={fixed} class={className} />
31
+
32
+ <script>
33
+ import { mount } from '../runtime/mount.js';
34
+ import { asciiNoise } from '../runtime/ascii-noise.js';
35
+
36
+ mount('[data-effect-ascii-noise]', asciiNoise);
37
+ </script>
@@ -8,7 +8,9 @@
8
8
  * Suits outlined things: cards, ghost buttons, a featured pricing tier. A
9
9
  * filled button has no outline for the light to travel. `lights={2}` sends
10
10
  * two round, chasing each other; `inset` keeps the ring over the content of
11
- * a card that clips and fills itself.
11
+ * a card that clips and fills itself. `long` draws a longer light with a
12
+ * faint lead-in, `outset` lays the ring over a border, `focus` picks which
13
+ * focus lights it, and `still` what reduced motion shows.
12
14
  *
13
15
  * @example
14
16
  * <BorderSweep as="a" href="/pricing" class="card" color="#a5b4fc" always>…</BorderSweep>
@@ -32,14 +34,51 @@ interface Props {
32
34
  lights?: 1 | 2;
33
35
  /** Draw the ring inside the edge and over the content, for elements that clip (`overflow: hidden`) and fill themselves with a picture or a canvas. Default false. */
34
36
  inset?: boolean;
37
+ /** A longer light: a faint lead-in over the quarter lap before it, then the light and its tail. Default false. */
38
+ long?: boolean;
39
+ /** How far the ring sits out past the edge, px: 1 lays it over a 1px border. Default 0. */
40
+ outset?: number;
41
+ /** Which focus lights it: `within` when it or anything in it has the focus, `visible` only its own keyboard focus, `none` never (hover only). Default `within`. */
42
+ focus?: 'within' | 'visible' | 'none';
43
+ /** What reduced motion shows: `ring` a still lit edge where the light would run, `none` nothing. Default `ring`. */
44
+ still?: 'ring' | 'none';
35
45
  class?: string;
36
46
  [attribute: string]: unknown;
37
47
  }
38
48
 
39
- const { as: Tag = 'div', color, speed, width, always = false, lights = 1, inset = false, class: className, style: given, ...attributes } = Astro.props;
40
- const style = [color && `--sweep-color: ${color}`, speed !== undefined && `--sweep-speed: ${speed}s`, width !== undefined && `--sweep-width: ${width}px`]
49
+ const {
50
+ as: Tag = 'div',
51
+ color,
52
+ speed,
53
+ width,
54
+ always = false,
55
+ lights = 1,
56
+ inset = false,
57
+ long = false,
58
+ outset,
59
+ focus = 'within',
60
+ still = 'ring',
61
+ class: className,
62
+ style: given,
63
+ ...attributes
64
+ } = Astro.props;
65
+ const style = [
66
+ color && `--sweep-color: ${color}`,
67
+ speed !== undefined && `--sweep-speed: ${speed}s`,
68
+ width !== undefined && `--sweep-width: ${width}px`,
69
+ outset !== undefined && `--sweep-outset: ${outset}px`,
70
+ ]
41
71
  .filter(Boolean)
42
72
  .join('; ');
43
73
  ---
44
74
 
45
- <Tag class:list={['sweep-ring', { 'sweep-ring--always': always, 'sweep-ring--two': lights === 2, 'sweep-ring--inset': inset }, className]} style={withStyle(style, given)} {...attributes}><slot /></Tag>
75
+ <Tag
76
+ class:list={['sweep-ring',
77
+ { 'sweep-ring--always': always, 'sweep-ring--two': lights === 2, 'sweep-ring--inset': inset, 'sweep-ring--long': long },
78
+ focus !== 'within' && `sweep-ring--focus-${focus}`,
79
+ still !== 'ring' && `sweep-ring--still-${still}`,
80
+ className,
81
+ ]}
82
+ style={withStyle(style, given)}
83
+ {...attributes}><slot /></Tag
84
+ >
@@ -11,7 +11,10 @@
11
11
  *
12
12
  * The slot is rendered three times: once as the real text, twice as the
13
13
  * copies (hidden from assistive technology and from focus), so keep it to
14
- * text and inline formatting. For elements you render yourself, import
14
+ * text and inline formatting. `copies="pseudo"` draws the copies as the
15
+ * element's `::before` and `::after` from a `data-text` instead: one
16
+ * element, for plain text. `variant="skew"` is another glitch, the whole
17
+ * word shaking and skewing. For elements you render yourself, import
15
18
  * `@arraypress/effects-astro/glitch-text.css` and follow its markup.
16
19
  *
17
20
  * @example
@@ -22,6 +25,7 @@ import type { PaletteName } from '../runtime/palettes.js';
22
25
  import { pickColors } from '../runtime/palettes.js';
23
26
  import '../styles/glitch-text.css';
24
27
  import { withStyle } from './style.js';
28
+ import { plainText } from './text.js';
25
29
 
26
30
  interface Props {
27
31
  /** The element to render. Default `span`. */
@@ -38,11 +42,15 @@ interface Props {
38
42
  palette?: PaletteName | (string & {});
39
43
  /** How the copies blend with the text and what is behind: `multiply` on a light ground, `screen` on a dark one. Default `multiply`. */
40
44
  blend?: 'multiply' | 'screen' | 'normal' | 'difference' | 'plus-lighter';
45
+ /** How the copies are drawn: `spans`, the slot laid twice more (inline formatting kept), or `pseudo`, the element's `::before` and `::after` from a `data-text` of the slot's words (one element; plain text only). Default `spans`. */
46
+ copies?: 'spans' | 'pseudo';
47
+ /** The glitch: `slice`, the copies sliced into four bands and shifted a few pixels while the text nudges; `skew`, the whole word shaking and skewing while the copies tear through three bands, shifted by a share of the type size. Default `slice`. */
48
+ variant?: 'slice' | 'skew';
41
49
  class?: string;
42
50
  [attribute: string]: unknown;
43
51
  }
44
52
 
45
- const { as: Tag = 'span', every, hoverEvery, delay, colors, palette, blend, class: className, style: given, ...attributes } = Astro.props;
53
+ const { as: Tag = 'span', every, hoverEvery, delay, colors, palette, blend, copies = 'spans', variant = 'slice', class: className, style: given, ...attributes } = Astro.props;
46
54
  const [a, b] = colors?.length || palette ? pickColors({ colors, palette }, ['#ff3ea5', '#2e4bff'], (p) => [p.colors[0], p.colors[1]]) : [];
47
55
  const cycle = every ?? 5;
48
56
  // Rendered once, at build time: each instance gets its own beat in the static page.
@@ -58,12 +66,13 @@ const style = [
58
66
  .filter(Boolean)
59
67
  .join('; ');
60
68
  const html = await Astro.slots.render('default');
69
+ const pseudo = copies === 'pseudo';
61
70
  ---
62
71
 
63
- <Tag class:list={['glitch-text', className]} style={withStyle(style, given)} {...attributes}
64
- ><span><Fragment set:html={html} /></span><span class="glitch-text-a" aria-hidden="true" inert><Fragment set:html={html} /></span><span
65
- class="glitch-text-b"
66
- aria-hidden="true"
67
- inert><Fragment set:html={html} /></span
68
- ></Tag
72
+ <Tag
73
+ class:list={['glitch-text', pseudo && 'glitch-text--pseudo', variant !== 'slice' && `glitch-text--${variant}`, className]}
74
+ data-text={pseudo ? plainText(html) : undefined}
75
+ style={withStyle(style, given)}
76
+ {...attributes}
77
+ >{pseudo ? <Fragment set:html={html} /> : <Fragment><span><Fragment set:html={html} /></span><span class="glitch-text-a" aria-hidden="true" inert><Fragment set:html={html} /></span><span class="glitch-text-b" aria-hidden="true" inert><Fragment set:html={html} /></span></Fragment>}</Tag
69
78
  >
@@ -5,10 +5,12 @@
5
5
  * anything as the slot (logos, images, cards).
6
6
  *
7
7
  * The content is laid four times and the strip moves by one set, so the
8
- * loop is seamless even when a set is narrower than the screen. The edges
9
- * fade out rather than cutting, it can pause under the pointer, and a
10
- * small pause button stops it for good (moving content needs one, WCAG
11
- * 2.2.2). With reduced motion it is a still row, scrollable by hand.
8
+ * loop is seamless even when a set is narrower than the screen (`copies`
9
+ * lays it fewer times, for a set that is always wider). The edges fade
10
+ * out rather than cutting (`fade={0}` cuts them), it can pause under the
11
+ * pointer, and a small pause button stops it for good (moving content
12
+ * needs one, WCAG 2.2.2). With reduced motion it is a still row,
13
+ * scrollable by hand, or (`still="hold"`) the strip held where it starts.
12
14
  * Screen readers get the content once.
13
15
  *
14
16
  * Merges the marquees of the WaveGrid, SellGrid, LinkGrid and LaunchGrid
@@ -34,8 +36,14 @@ interface Props {
34
36
  pauseOnHover?: boolean;
35
37
  /** Show a pause button. Default true. */
36
38
  pauseButton?: boolean;
37
- /** How wide the faded edges are, % of the strip. Default 8. */
39
+ /** How wide the faded edges are, % of the strip; 0 cuts them. Default 8. */
38
40
  fade?: number;
41
+ /** How many times the content is laid, 2–4; the strip moves by one of them a loop. Two is enough when one set is always wider than the strip. Default 4. */
42
+ copies?: 2 | 3 | 4;
43
+ /** What it is to assistive technology: `region` a landmark, `marquee` a ticker, `note` an aside. Default `region`. */
44
+ role?: 'region' | 'marquee' | 'note';
45
+ /** With reduced motion: `scroll`, one set as a still row to scroll by hand; `hold`, the strip held where it starts, every set laid. Default `scroll`. */
46
+ still?: 'scroll' | 'hold';
39
47
  /** The pause button's labels, for other languages. Default English. */
40
48
  labels?: { pause: string; resume: string };
41
49
  /** What the strip is, for screen readers. Default the items joined. */
@@ -52,6 +60,9 @@ const {
52
60
  pauseOnHover = true,
53
61
  pauseButton = true,
54
62
  fade = 8,
63
+ copies = 4,
64
+ role = 'region',
65
+ still = 'scroll',
55
66
  labels = { pause: 'Pause scrolling', resume: 'Resume scrolling' },
56
67
  label,
57
68
  class: className,
@@ -59,13 +70,14 @@ const {
59
70
 
60
71
  // Slot content is rendered once and laid again for the copies.
61
72
  const slotted = items ? '' : await Astro.slots.render('default');
62
- const sets = [0, 1, 2, 3];
73
+ const sets = Array.from({ length: copies }, (_, set) => set);
74
+ const shift = copies === 4 ? '' : `; --marquee-shift: ${-100 / copies}%`;
63
75
  ---
64
76
 
65
77
  <div
66
- class:list={['effect-marquee', `is-${direction}`, { 'pause-on-hover': pauseOnHover }, className]}
67
- style={`--marquee-speed: ${speed}s; --marquee-gap: ${gap}; --marquee-fade: ${fade}%`}
68
- role="region"
78
+ class:list={['effect-marquee', `is-${direction}`, { 'pause-on-hover': pauseOnHover, 'no-fade': fade === 0, 'still-hold': still === 'hold' }, className]}
79
+ style={`--marquee-speed: ${speed}s; --marquee-gap: ${gap}; --marquee-fade: ${fade}%${shift}`}
80
+ role={role}
69
81
  aria-label={label ?? items?.join(', ')}
70
82
  data-effect-marquee
71
83
  >
@@ -159,9 +171,14 @@ const sets = [0, 1, 2, 3];
159
171
  .effect-marquee:global(.is-paused) .track {
160
172
  animation-play-state: paused;
161
173
  }
174
+ .no-fade .viewport {
175
+ -webkit-mask-image: none;
176
+ mask-image: none;
177
+ }
178
+ /* One set a loop: a quarter of the four, or --marquee-shift for fewer. */
162
179
  @keyframes effect-marquee {
163
180
  to {
164
- transform: translateX(-25%);
181
+ transform: translateX(var(--marquee-shift, -25%));
165
182
  }
166
183
  }
167
184
 
@@ -212,5 +229,12 @@ const sets = [0, 1, 2, 3];
212
229
  .toggle {
213
230
  display: none;
214
231
  }
232
+ /* Held: every set laid, still, as it starts. */
233
+ .still-hold .viewport {
234
+ overflow-x: hidden;
235
+ }
236
+ .still-hold .set[aria-hidden='true'] {
237
+ display: flex;
238
+ }
215
239
  }
216
240
  </style>
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/components/text
3
+ *
4
+ * The words of a rendered slot, for an attribute that repeats them
5
+ * (`<GlitchText copies="pseudo">`'s `data-text`): its tags dropped and its
6
+ * character references read back into characters, so Astro escapes them
7
+ * once, as the attribute's own.
8
+ */
9
+
10
+ /** The named references Astro's escaping writes, and the no-break space. */
11
+ const NAMED = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ' };
12
+
13
+ /**
14
+ * A slot's HTML as plain text.
15
+ *
16
+ * @param {string} html The rendered slot.
17
+ * @returns {string} Its text: no tags, each run of white space one space, trimmed, references decoded.
18
+ */
19
+ export function plainText(html) {
20
+ return html
21
+ .replace(/<[^>]*>/g, '')
22
+ .replace(/[ \t\n\r\f]+/g, ' ')
23
+ .trim()
24
+ .replace(/&(#x[\da-f]+|#\d+|[a-z]+);/gi, (whole, ref) => {
25
+ if (ref[0] !== '#') return NAMED[/** @type {keyof typeof NAMED} */ (ref.toLowerCase())] ?? whole;
26
+ const code = /^#x/i.test(ref) ? parseInt(ref.slice(2), 16) : parseInt(ref.slice(1), 10);
27
+ return code <= 0x10ffff ? String.fromCodePoint(code) : whole;
28
+ });
29
+ }
package/src/index.d.ts CHANGED
@@ -6,6 +6,8 @@ export { spotlight } from './runtime/spotlight.js';
6
6
  export type { SpotlightConfig } from './runtime/spotlight.js';
7
7
  export { asciiRain } from './runtime/ascii-rain.js';
8
8
  export type { AsciiRainConfig } from './runtime/ascii-rain.js';
9
+ export { asciiNoise, asciiCells, noiseField, noiseColors, rampOf, NOISE_RAMPS, NOISE_DEFAULTS } from './runtime/ascii-noise.js';
10
+ export type { AsciiNoiseConfig } from './runtime/ascii-noise.js';
9
11
  export { glassGlyph } from './runtime/glass-glyph.js';
10
12
  export type { GlassGlyphConfig } from './runtime/glass-glyph.js';
11
13
  export { flutedGlass } from './runtime/fluted-glass.js';
package/src/index.js CHANGED
@@ -15,6 +15,7 @@ export { lightField } from './runtime/light-field.js';
15
15
  export { ink } from './runtime/ink.js';
16
16
  export { spotlight } from './runtime/spotlight.js';
17
17
  export { asciiRain } from './runtime/ascii-rain.js';
18
+ export { asciiNoise, asciiCells, noiseField, noiseColors, rampOf, NOISE_RAMPS, NOISE_DEFAULTS } from './runtime/ascii-noise.js';
18
19
  export { glassGlyph } from './runtime/glass-glyph.js';
19
20
  export { flutedGlass } from './runtime/fluted-glass.js';
20
21
  export { particleLogo } from './runtime/particle-logo.js';
@@ -0,0 +1,75 @@
1
+ import type { PaletteName } from './palettes.js';
2
+
3
+ export interface AsciiNoiseConfig {
4
+ /** Two CSS hex colours: the quietest cells' and the loudest's. Default a dim grey and white. */
5
+ colors?: string[];
6
+ /** A shared palette by name (`PALETTES`, any case), when there are no `colors`: its first and last colours. */
7
+ palette?: PaletteName | (string & {});
8
+ /** A CSS hex colour to fill behind the type; none leaves the canvas clear there. */
9
+ background?: string;
10
+ /** A ramp (`ascii`, `shade`, `digits`, `rise`, `quads`, `bars`, `arrows`, `letters`, `dense`, or a set of `GLYPH_SETS`) or the characters, quietest first. Default `ascii`. */
11
+ glyphs?: keyof typeof NOISE_RAMPS | (string & {});
12
+ /** A character cell's height in CSS px. Default 14. */
13
+ cell?: number;
14
+ /** Cells across instead, whatever the width (overrides `cell`). */
15
+ cols?: number;
16
+ /** A cell's width over its height. Default 0.6. */
17
+ aspect?: number;
18
+ /** How many noise features span the width (higher is busier). Default 2.45. */
19
+ scale?: number;
20
+ /** How hard the edges are: higher pushes cells to empty or full. Default 6. */
21
+ contrast?: number;
22
+ /** Shifts the whole field; lower leaves more cells empty. Default -0.1. */
23
+ brightness?: number;
24
+ /** How fast the sample window pans, widths a second, x and y. Default [0.036, 0.012]. */
25
+ drift?: [number, number];
26
+ /** How fast the shapes morph. Default 0.24. */
27
+ evolve?: number;
28
+ /** Where the sample window starts, so two cards differ. Default [0, 0]. */
29
+ offset?: [number, number];
30
+ /** Plays every clock faster or slower; 0 for one still frame. Default 1. */
31
+ speed?: number;
32
+ /** An area kept quiet: centre (0–1 from the top left), radius (share of the height), depth (0–1). */
33
+ quiet?: { x?: number; y?: number; radius?: number; depth?: number } | null;
34
+ /** The font family the glyphs are drawn in (a monospace stack by default); it is loaded first. */
35
+ font?: string;
36
+ }
37
+
38
+ /** The ramps, each quietest first. A ramp starting with a space leaves quiet cells empty. */
39
+ export declare const NOISE_RAMPS: {
40
+ readonly ascii: string;
41
+ readonly shade: string;
42
+ readonly digits: string;
43
+ readonly rise: string;
44
+ readonly quads: string;
45
+ readonly bars: string;
46
+ readonly arrows: string;
47
+ readonly letters: string;
48
+ readonly dense: string;
49
+ };
50
+
51
+ /** The settings' defaults, shared by the shader and `asciiCells`. */
52
+ export declare const NOISE_DEFAULTS: {
53
+ glyphs: string;
54
+ scale: number;
55
+ contrast: number;
56
+ brightness: number;
57
+ drift: [number, number];
58
+ evolve: number;
59
+ aspect: number;
60
+ };
61
+
62
+ /** A ramp's characters, quietest first (at least two). */
63
+ export declare function rampOf(glyphs?: string): string[];
64
+
65
+ /** The field: five octaves of gradient noise, each warped by the sum so far; 0–1. */
66
+ export declare function noiseField(x: number, y: number, evo: number, wt: number): number;
67
+
68
+ /** One frame as ramp indices: what the shader draws, cell for cell, on a target exactly `cols` by `rows` cells. */
69
+ export declare function asciiCells(config: AsciiNoiseConfig, cols: number, rows: number, time?: number): number[][];
70
+
71
+ /** The two colours as the shader takes them: the quietest cells' and the loudest's. */
72
+ export declare function noiseColors(config: AsciiNoiseConfig): [string, string];
73
+
74
+ /** Starts the noise on an element (its first canvas is drawn into). Returns a function that stops it. */
75
+ export declare function asciiNoise(el: HTMLElement, config: AsciiNoiseConfig): () => void;
@@ -0,0 +1,377 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/ascii-noise
3
+ *
4
+ * A field of slow noise drawn as a grid of monospace characters: each cell
5
+ * samples a five-octave gradient noise (quintic fade, a domain warp) at its
6
+ * centre, the value is pushed hard toward empty or full (`contrast`) and
7
+ * picks a character from a ramp, quietest first, so the field reads as
8
+ * soft-edged blobs of type drifting and morphing across the frame. The
9
+ * quiet cells take one colour and the loud ones another, blended in Oklab.
10
+ *
11
+ * Two clocks, both in seconds: the sample window pans (`drift`) and the
12
+ * shapes morph (`evolve`); the warp drifts on its own, more slowly. The
13
+ * same field is here in plain JavaScript (`noiseField`, `asciiCells`), so a
14
+ * page can lay its first frame as text before the shader starts, and the
15
+ * two agree.
16
+ *
17
+ * Clear where the cells are empty (or the `background` colour), so it lays
18
+ * over any ground. A `quiet` area thins the type behind copy. Without
19
+ * WebGL nothing is drawn; with prefers-reduced-motion it is one still frame.
20
+ *
21
+ * After `ascii_noise_bg`, a Processing sketch shared with the owner
22
+ * (2026-11-20): the noise, the warp, the tunings and the ramps are its;
23
+ * here it runs on the GPU, by the second rather than by the frame, with
24
+ * the width as its unit so a tall card and a wide hero sample alike, and
25
+ * its lattice hash is Dave Hoskins' Hash without Sine (MIT, © 2014 David
26
+ * Hoskins), which keeps the GPU and `asciiCells` in step.
27
+ */
28
+
29
+ import { createStage } from './stage.js';
30
+ import { GLSL_OKLAB, parseColor, toOklab } from './color.js';
31
+ import { GLSL_QUIET, quietUniform } from './glsl.js';
32
+ import { GLSL_GLYPHS, GLYPH_SETS, createGlyphs } from './glyphs.js';
33
+ import { watchColors } from './mount.js';
34
+ import { pickColors } from './palettes.js';
35
+
36
+ /**
37
+ * @typedef {object} AsciiNoiseConfig
38
+ * @property {string[]} [colors] Two CSS hex colours: the quietest cells' and the loudest's. Default a dim grey and white.
39
+ * @property {string} [palette] A shared palette by name (PALETTES; any case), when there are no `colors`: its first and last colours.
40
+ * @property {string} [background] A CSS hex colour to fill behind the type; none leaves the canvas clear there.
41
+ * @property {string} [glyphs='ascii'] A ramp (`ascii`, `shade`, `digits`, `rise`, `quads`, `bars`, `arrows`,
42
+ * `letters`, `dense`; or a set of GLYPH_SETS) or the characters themselves, quietest first.
43
+ * @property {number} [cell=14] A character cell's height in CSS px.
44
+ * @property {number} [cols] Cells across instead, whatever the width (overrides `cell`).
45
+ * @property {number} [aspect=0.6] A cell's width over its height.
46
+ * @property {number} [scale=2.45] How many noise features span the width (higher is busier).
47
+ * @property {number} [contrast=6] How hard the edges are: higher pushes cells to empty or full.
48
+ * @property {number} [brightness=-0.1] Shifts the whole field; lower leaves more cells empty.
49
+ * @property {[number, number]} [drift=[0.036, 0.012]] How fast the sample window pans, widths a second, x and y.
50
+ * @property {number} [evolve=0.24] How fast the shapes morph.
51
+ * @property {[number, number]} [offset=[0, 0]] Where the sample window starts, so two cards differ.
52
+ * @property {number} [speed=1] Plays every clock faster or slower; 0 for one still frame.
53
+ * @property {{ x?: number, y?: number, radius?: number, depth?: number } | null} [quiet=null]
54
+ * An area kept quiet: centre (0–1 from the top left), radius (share of the height), depth (0–1).
55
+ * @property {string} [font] The font family the glyphs are drawn in (a monospace stack by default); it is loaded first.
56
+ */
57
+
58
+ /** The ramps, each quietest first. A ramp starting with a space leaves quiet cells empty. */
59
+ export const NOISE_RAMPS = {
60
+ /** Punctuation building to `@`. */
61
+ ascii: ' `^",:;!+*#%@',
62
+ /** Shade blocks, never empty: the whole frame is type. */
63
+ shade: '░▒▓█',
64
+ /** Numerals, 1 to 9. */
65
+ digits: ' 123456789',
66
+ /** Blocks rising from the baseline. */
67
+ rise: ' ▁▂▃▄▅▆▇█',
68
+ /** Quadrant blocks, from one corner to all four. */
69
+ quads: ' ▖▗▘▝▚▞▛▙▜▟█',
70
+ /** Bars filling from the left. */
71
+ bars: ' ▏▎▍▌▋▊▉█',
72
+ /** Arrows (the font must have them). */
73
+ arrows: ' ↑↗→↘↓↙←↖↕',
74
+ /** Letters, light to heavy. */
75
+ letters: ' iljtfrvxzcknyuUHPAOEGQDBMWR',
76
+ /** The long classic ramp. */
77
+ dense: " .'`^,:;I}{1)(|OZbkhao*#MW&8%B@$",
78
+ };
79
+
80
+ /** The settings' defaults, shared by the shader and `asciiCells`. */
81
+ export const NOISE_DEFAULTS = {
82
+ glyphs: 'ascii',
83
+ scale: 2.45,
84
+ contrast: 6,
85
+ brightness: -0.1,
86
+ drift: /** @type {[number, number]} */ ([0.036, 0.012]),
87
+ evolve: 0.24,
88
+ aspect: 0.6,
89
+ };
90
+
91
+ /** The default colours: a dim grey for the quiet cells, white for the loud. */
92
+ const GREY = ['#3a3a3a', '#ffffff'];
93
+
94
+ /**
95
+ * A ramp's characters.
96
+ *
97
+ * @param {string} [glyphs] A ramp's name (NOISE_RAMPS, then GLYPH_SETS) or the characters.
98
+ * @returns {string[]} The characters, quietest first (at least two).
99
+ */
100
+ export function rampOf(glyphs = NOISE_DEFAULTS.glyphs) {
101
+ const chars = [
102
+ ...(NOISE_RAMPS[/** @type {keyof typeof NOISE_RAMPS} */ (glyphs)] ??
103
+ GLYPH_SETS[/** @type {keyof typeof GLYPH_SETS} */ (glyphs)] ??
104
+ glyphs),
105
+ ];
106
+ return chars.length > 1 ? chars : [...NOISE_RAMPS.ascii];
107
+ }
108
+
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
+ const FRAG = `
146
+ precision highp float;
147
+ uniform vec2 uRes;
148
+ uniform vec2 uCell;
149
+ uniform float uTime;
150
+ uniform float uScale;
151
+ uniform float uContrast;
152
+ uniform float uBrightness;
153
+ uniform vec2 uDrift;
154
+ uniform float uEvolve;
155
+ uniform vec2 uOffset;
156
+ uniform vec3 uLo;
157
+ uniform vec3 uHi;
158
+ uniform vec4 uBg;
159
+ ${GLSL_OKLAB}
160
+ ${GLSL_QUIET}
161
+ ${GLSL_GLYPHS}
162
+ ${GLSL_FIELD}
163
+
164
+ void main() {
165
+ // Cells counted from the top left, as the text still lays them.
166
+ vec2 px = vec2(gl_FragCoord.x, uRes.y - gl_FragCoord.y);
167
+ vec2 cell = floor(px / uCell);
168
+ vec2 centre = (cell + 0.5) * uCell;
169
+ // The field in widths, so its features keep their size whatever the shape.
170
+ vec2 p = (centre / uRes.x) * uScale + uOffset + uDrift * uTime;
171
+ float v = noiseField(p, uEvolve * uTime, uTime);
172
+ v = clamp((v - 0.5) * uContrast + 0.5 + uBrightness, 0.0, 1.0);
173
+ vec2 q = vec2(centre.x - 0.5 * uRes.x, 0.5 * uRes.y - centre.y) / uRes.y;
174
+ v *= mix(1.0 - uQuiet.w, 1.0, quietOpen(q));
175
+ float last = uGlyphCount - 1.0;
176
+ float index = min(floor(v * uGlyphCount), last);
177
+ float k = index / last;
178
+ float a = glyph(vec2(fract(px.x / uCell.x), 1.0 - fract(px.y / uCell.y)), k);
179
+ vec3 col = fromOklab(mix(uLo, uHi, k));
180
+ gl_FragColor = vec4(col * a + uBg.rgb * uBg.a * (1.0 - a), a + uBg.a * (1.0 - a));
181
+ }
182
+ `;
183
+
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
+ /**
255
+ * One frame as ramp indices: what the shader draws, cell for cell, on a
256
+ * target exactly `cols` by `rows` cells.
257
+ *
258
+ * @param {AsciiNoiseConfig} config The settings (the same as the shader's).
259
+ * @param {number} cols Cells across.
260
+ * @param {number} rows Cells down.
261
+ * @param {number} [time=0] Seconds, as the shader's clock (already at its speed).
262
+ * @returns {number[][]} Each row's indices into `rampOf(config.glyphs)`.
263
+ */
264
+ export function asciiCells(config, cols, rows, time = 0) {
265
+ const { scale, contrast, brightness, drift, evolve, aspect } = { ...NOISE_DEFAULTS, ...config };
266
+ const n = rampOf(config.glyphs).length;
267
+ const [ox, oy] = config.offset ?? [0, 0];
268
+ // a cell is 1 wide and 1 / aspect tall; the quiet area is measured as the shader measures it
269
+ const height = rows / aspect;
270
+ const [qx, qy, radius, depth] = quietUniform(config.quiet, cols / height);
271
+ const smooth = (/** @type {number} */ e0, /** @type {number} */ e1, /** @type {number} */ x) => {
272
+ const t = Math.min(1, Math.max(0, (x - e0) / (e1 - e0)));
273
+ return t * t * (3 - 2 * t);
274
+ };
275
+ return Array.from({ length: rows }, (_, r) =>
276
+ Array.from({ length: cols }, (_, c) => {
277
+ const cx = c + 0.5;
278
+ const cy = (r + 0.5) / aspect;
279
+ let v = noiseField((cx / cols) * scale + ox + drift[0] * time, (cy / cols) * scale + oy + drift[1] * time, evolve * time, time);
280
+ v = Math.min(1, Math.max(0, (v - 0.5) * contrast + 0.5 + brightness));
281
+ if (radius > 0) {
282
+ const d = Math.hypot((cx - cols / 2) / height - qx, (height / 2 - cy) / height - qy);
283
+ v *= 1 - depth + depth * smooth(radius * 0.06, radius, d);
284
+ }
285
+ return Math.min(Math.floor(v * n), n - 1);
286
+ }),
287
+ );
288
+ }
289
+
290
+ /**
291
+ * The two colours as the shader takes them.
292
+ *
293
+ * @param {AsciiNoiseConfig} config The settings.
294
+ * @returns {[string, string]} The quietest cells' colour and the loudest's.
295
+ */
296
+ export function noiseColors(config) {
297
+ const colors = pickColors(config, GREY);
298
+ return [colors[0], colors[colors.length - 1]];
299
+ }
300
+
301
+ /**
302
+ * Starts the noise on an element: a canvas inside it (its first), filling
303
+ * it. With a `font`, the font is loaded before the glyphs are drawn.
304
+ *
305
+ * @param {HTMLElement} el The element.
306
+ * @param {AsciiNoiseConfig} config The settings.
307
+ * @returns {() => void} Stops it.
308
+ */
309
+ export function asciiNoise(el, config) {
310
+ let stop = () => {};
311
+ let stopped = false;
312
+ const ramp = rampOf(config.glyphs);
313
+ /** Starts the stage, unless it was stopped while the font loaded. */
314
+ const begin = () => {
315
+ if (!stopped) stop = run(el, config, ramp);
316
+ };
317
+ if (config.font && typeof document !== 'undefined' && document.fonts) document.fonts.load(`48px ${config.font}`, ramp.join('')).then(begin, begin);
318
+ else begin();
319
+ return () => {
320
+ stopped = true;
321
+ stop();
322
+ };
323
+ }
324
+
325
+ /**
326
+ * The stage itself, once the font is ready.
327
+ *
328
+ * @param {HTMLElement} el The element.
329
+ * @param {AsciiNoiseConfig} config The settings.
330
+ * @param {string[]} ramp The characters.
331
+ * @returns {() => void} Stops it.
332
+ */
333
+ function run(el, config, ramp) {
334
+ const o = { ...NOISE_DEFAULTS, ...config };
335
+ const speed = config.speed ?? 1;
336
+ const lab = (/** @type {string} */ c) => toOklab(parseColor(c));
337
+ let [lo, hi] = noiseColors(config).map(lab);
338
+ const bg = config.background ? [...parseColor(config.background), 1] : [0, 0, 0, 0];
339
+ const start = performance.now();
340
+
341
+ const { stage, stop } = createStage(el, {
342
+ fragment: FRAG,
343
+ still: speed <= 0,
344
+ setup({ gl, uniform }) {
345
+ const { count } = createGlyphs(gl, ramp.join(''), { unit: 0, font: config.font, aspect: o.aspect });
346
+ gl.uniform1i(uniform('uGlyphs'), 0);
347
+ gl.uniform1f(uniform('uGlyphCount'), count);
348
+ gl.uniform1f(uniform('uScale'), o.scale);
349
+ gl.uniform1f(uniform('uContrast'), o.contrast);
350
+ gl.uniform1f(uniform('uBrightness'), o.brightness);
351
+ gl.uniform2f(uniform('uDrift'), o.drift[0], o.drift[1]);
352
+ gl.uniform1f(uniform('uEvolve'), o.evolve);
353
+ gl.uniform2f(uniform('uOffset'), ...(config.offset ?? [0, 0]));
354
+ gl.uniform4f(uniform('uBg'), bg[0], bg[1], bg[2], bg[3]);
355
+ },
356
+ resize({ gl, uniform, canvas, ratio }) {
357
+ const w = config.cols ? canvas.width / config.cols : (config.cell ?? 14) * ratio * o.aspect;
358
+ gl.uniform2f(uniform('uCell'), w, w / o.aspect);
359
+ gl.uniform4f(uniform('uQuiet'), ...quietUniform(config.quiet, canvas.width / canvas.height));
360
+ },
361
+ uniforms({ gl, uniform }, now) {
362
+ gl.uniform1f(uniform('uTime'), ((now - start) / 1000) * Math.max(0, speed));
363
+ gl.uniform3f(uniform('uLo'), lo[0], lo[1], lo[2]);
364
+ gl.uniform3f(uniform('uHi'), hi[0], hi[1], hi[2]);
365
+ },
366
+ });
367
+ if (!stage) return stop;
368
+
369
+ const unwatch = watchColors(el, (next) => {
370
+ [lo, hi] = noiseColors({ colors: next.colors }).map(lab);
371
+ if (stage.still) stage.redraw();
372
+ });
373
+ return () => {
374
+ stop();
375
+ unwatch();
376
+ };
377
+ }
@@ -21,7 +21,16 @@
21
21
  * contents (`overflow: hidden`) and fill themselves with a picture or a
22
22
  * canvas that would otherwise cover it.
23
23
  *
24
- * From the ArrayPress theme; the two lights from the Logomarks site.
24
+ * `sweep-ring--long` is a longer light: a faint lead-in over the quarter
25
+ * lap before it, then the light and its tail. `--sweep-outset` moves the
26
+ * ring out past the edge (`1px` lays it over a 1px border). Focus lights
27
+ * it when the element or anything in it has the focus; `--focus-visible`
28
+ * only on the element's own keyboard focus, `--focus-none` never (hover
29
+ * only). `sweep-ring--still-none` shows no ring at all with reduced
30
+ * motion, where the default keeps a still lit edge.
31
+ *
32
+ * From the ArrayPress theme; the two lights, the long light, the outset,
33
+ * the focus and the still options from the Logomarks site.
25
34
  * ───────────────────────────────────────────────────────────────────── */
26
35
 
27
36
  @property --sweep-angle {
@@ -37,7 +46,7 @@
37
46
  .sweep-ring::after {
38
47
  content: '';
39
48
  position: absolute;
40
- inset: 0;
49
+ inset: calc(var(--sweep-outset, 0px) * -1);
41
50
  border-radius: inherit;
42
51
  padding: var(--sweep-width, 1px);
43
52
  background: conic-gradient(
@@ -57,9 +66,10 @@
57
66
  pointer-events: none;
58
67
  }
59
68
 
69
+ /* Focus lights it unless told otherwise; `:where` keeps the selectors' weight as it was. */
60
70
  .sweep-ring:hover::after,
61
- .sweep-ring:focus-visible::after,
62
- .sweep-ring:focus-within::after,
71
+ .sweep-ring:where(:not(.sweep-ring--focus-none)):focus-visible::after,
72
+ .sweep-ring:where(:not(.sweep-ring--focus-visible, .sweep-ring--focus-none)):focus-within::after,
63
73
  .sweep-ring--always::after {
64
74
  opacity: 1;
65
75
  animation: effect-border-sweep var(--sweep-speed, 2.6s) linear infinite;
@@ -69,6 +79,19 @@
69
79
  --sweep-speed: 1.8s;
70
80
  }
71
81
 
82
+ /* A longer light: a faint lead-in over the quarter lap before it, then the light and its tail. */
83
+ .sweep-ring--long::after {
84
+ background: conic-gradient(
85
+ from var(--sweep-angle),
86
+ transparent 0%,
87
+ transparent 50%,
88
+ color-mix(in srgb, var(--sweep-color, currentColor) 30%, transparent) 64%,
89
+ var(--sweep-color, currentColor) 78%,
90
+ color-mix(in srgb, var(--sweep-color, currentColor) 35%, transparent) 88%,
91
+ transparent 96%
92
+ );
93
+ }
94
+
72
95
  /* Two lights, half a lap apart, each with a faint lead-in. */
73
96
  .sweep-ring--two::after {
74
97
  background: conic-gradient(
@@ -98,12 +121,18 @@
98
121
 
99
122
  @media (prefers-reduced-motion: reduce) {
100
123
  .sweep-ring:hover::after,
101
- .sweep-ring:focus-visible::after,
102
- .sweep-ring:focus-within::after,
124
+ .sweep-ring:where(:not(.sweep-ring--focus-none)):focus-visible::after,
125
+ .sweep-ring:where(:not(.sweep-ring--focus-visible, .sweep-ring--focus-none)):focus-within::after,
103
126
  .sweep-ring--always::after {
104
127
  animation: none;
105
128
  /* Keep the lit edge, drop the travel. */
106
129
  background: none;
107
130
  box-shadow: inset 0 0 0 1px var(--sweep-color, currentColor);
108
131
  }
132
+
133
+ /* Or no ring at all: still and see-through, outweighing the lit states. */
134
+ .sweep-ring.sweep-ring--still-none::after {
135
+ animation: none;
136
+ opacity: 0;
137
+ }
109
138
  }
@@ -23,7 +23,18 @@
23
23
  * `--glitch-blend` (how they blend: multiply on a light ground, screen on
24
24
  * a dark one). With reduced motion it is the plain text, still.
25
25
  *
26
- * CSS only. From the Logomarks site's Custom card.
26
+ * `glitch-text--pseudo` draws the copies as the element's own `::before`
27
+ * and `::after` from its `data-text` instead, for one element of plain
28
+ * text:
29
+ *
30
+ * <span class="glitch-text glitch-text--pseudo" data-text="Free logos">Free logos</span>
31
+ *
32
+ * `glitch-text--skew` is another glitch: the whole word shakes and skews
33
+ * while the copies tear through three bands each, shifted by a share of
34
+ * the type size (em), the second a touch fainter. With either markup.
35
+ *
36
+ * CSS only. From the Logomarks site's Custom card; the pseudo copies and
37
+ * the skew from its home page's headline.
27
38
  * ───────────────────────────────────────────────────────────────────── */
28
39
 
29
40
  .glitch-text {
@@ -162,8 +173,150 @@
162
173
  }
163
174
  }
164
175
 
176
+ /* The copies as the element's ::before and ::after, from its data-text: one element, plain text. */
177
+ .glitch-text--pseudo::before,
178
+ .glitch-text--pseudo::after {
179
+ content: attr(data-text);
180
+ position: absolute;
181
+ inset: 0;
182
+ opacity: 0;
183
+ pointer-events: none;
184
+ mix-blend-mode: var(--glitch-blend, multiply);
185
+ animation: effect-glitch-text-a var(--glitch-every, 5s) steps(1, end) infinite;
186
+ animation-delay: var(--glitch-delay, 0s);
187
+ }
188
+
189
+ .glitch-text--pseudo::before {
190
+ color: var(--glitch-a, #ff3ea5);
191
+ -webkit-text-fill-color: currentColor;
192
+ }
193
+
194
+ .glitch-text--pseudo::after {
195
+ color: var(--glitch-b, #2e4bff);
196
+ -webkit-text-fill-color: currentColor;
197
+ animation-name: effect-glitch-text-b;
198
+ }
199
+
200
+ /* Here the element itself nudges, its copies with it. */
201
+ .glitch-text--pseudo {
202
+ animation: effect-glitch-text-main var(--glitch-every, 5s) steps(1, end) infinite;
203
+ animation-delay: var(--glitch-delay, 0s);
204
+ }
205
+
206
+ /* The skew: the whole word shakes and skews while the copies tear through three bands. */
207
+ .glitch-text--skew {
208
+ animation: effect-glitch-text-skew var(--glitch-every, 5s) steps(1, end) infinite;
209
+ animation-delay: var(--glitch-delay, 0s);
210
+ }
211
+
212
+ .glitch-text--skew > :not(.glitch-text-a, .glitch-text-b) {
213
+ animation: none;
214
+ }
215
+
216
+ .glitch-text--skew > .glitch-text-a,
217
+ .glitch-text--skew::before {
218
+ animation-name: effect-glitch-text-skew-a;
219
+ }
220
+
221
+ .glitch-text--skew > .glitch-text-b,
222
+ .glitch-text--skew::after {
223
+ animation-name: effect-glitch-text-skew-b;
224
+ }
225
+
226
+ .glitch-text:is(.glitch-text--pseudo, .glitch-text--skew):hover,
227
+ .glitch-text--pseudo:hover::before,
228
+ .glitch-text--pseudo:hover::after,
229
+ :is(a, button):is(:hover, :focus-visible) .glitch-text:is(.glitch-text--pseudo, .glitch-text--skew),
230
+ :is(a, button):is(:hover, :focus-visible) .glitch-text--pseudo::before,
231
+ :is(a, button):is(:hover, :focus-visible) .glitch-text--pseudo::after {
232
+ animation-duration: var(--glitch-hover, 1.6s);
233
+ }
234
+
235
+ @keyframes effect-glitch-text-skew-a {
236
+ 0%,
237
+ 88%,
238
+ 100% {
239
+ opacity: 0;
240
+ transform: none;
241
+ clip-path: inset(0 0 100% 0);
242
+ }
243
+
244
+ 89% {
245
+ opacity: 1;
246
+ transform: translate(-0.04em, 0.01em);
247
+ clip-path: inset(12% 0 58% 0);
248
+ }
249
+
250
+ 91% {
251
+ opacity: 1;
252
+ transform: translate(0.05em, -0.01em);
253
+ clip-path: inset(62% 0 8% 0);
254
+ }
255
+
256
+ 93% {
257
+ opacity: 1;
258
+ transform: translate(-0.02em, 0);
259
+ clip-path: inset(38% 0 40% 0);
260
+ }
261
+
262
+ 95% {
263
+ opacity: 0;
264
+ }
265
+ }
266
+
267
+ @keyframes effect-glitch-text-skew-b {
268
+ 0%,
269
+ 89%,
270
+ 100% {
271
+ opacity: 0;
272
+ transform: none;
273
+ clip-path: inset(0 0 100% 0);
274
+ }
275
+
276
+ 90% {
277
+ opacity: 0.9;
278
+ transform: translate(0.05em, 0);
279
+ clip-path: inset(48% 0 22% 0);
280
+ }
281
+
282
+ 92% {
283
+ opacity: 0.9;
284
+ transform: translate(-0.04em, 0.01em);
285
+ clip-path: inset(6% 0 70% 0);
286
+ }
287
+
288
+ 94% {
289
+ opacity: 0;
290
+ }
291
+ }
292
+
293
+ @keyframes effect-glitch-text-skew {
294
+ 0%,
295
+ 88%,
296
+ 95%,
297
+ 100% {
298
+ transform: none;
299
+ }
300
+
301
+ 89% {
302
+ transform: translateX(0.012em) skewX(-4deg);
303
+ }
304
+
305
+ 91% {
306
+ transform: translateX(-0.012em);
307
+ }
308
+
309
+ 93% {
310
+ transform: skewX(3deg);
311
+ }
312
+ }
313
+
165
314
  @media (prefers-reduced-motion: reduce) {
166
- .glitch-text > * {
315
+ .glitch-text > *,
316
+ .glitch-text--pseudo,
317
+ .glitch-text--pseudo::before,
318
+ .glitch-text--pseudo::after,
319
+ .glitch-text--skew {
167
320
  animation: none !important;
168
321
  }
169
322
  }