@arraypress/effects-astro 0.3.0 → 0.4.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
@@ -29,12 +29,14 @@ Pick by what is asked for:
29
29
  | A map, outdoors, travel or trail hero: contour lines like a survey map | `<Topography>` (dark by default; `background="#f3ead6" colors={['#9a6b43']}` for a paper map; `labels` for elevation numbers, `quiet` behind copy) |
30
30
  | A taxi, ride-hailing, delivery, mobility or city-services hero: a tiny living city | `<IsoCity accent="…">` (`night` for lit windows and headlights, `side="right"` + `quiet` beside copy; a click on a street calls a taxi) |
31
31
  | A "we sell worldwide" or "we ship from here" section | `<WorldRoutes>` with the cities that matter to the shop; `home="…"` for a hub, `colors` + `gradient` for colour, `labels`, `region="europe"` (or `routes`) to crop |
32
+ | A space, astronomy, night-sky or sci-fi hero: a nebula with stars | `<Galaxy palette="…">` (Canvas 2D, no WebGL; `stars`, `glitter`, `speed`) |
32
33
  | A light or texture over a background (a spotlight, film grain) | `<GlowField>`, `<Grain>` (`still` for either to hold) |
33
34
  | The brand's logo as the hero's centrepiece | `<GlassGlyph>`, `<LiquidMetal>` (liquid chrome you can poke and splash; `tint="gold"`…), `<ParticleLogo>`, `<NeonSwarm>` (a flowing neon swarm), `<NebulaLogo>` (filled with nebula gas), `<VoxelLogo>`, `<PointCloud>`, all with `src="/logo.svg"` or `text` |
34
35
  | A footer wordmark | `<SpotlightText fit>`, `<PixelGlitchText fit>`, `<OutlineWordmark>` |
35
36
  | Sections that arrive on scroll, site-wide | `<ScrollReveal />` once in the layout, then reveal.css classes (`fade-in-up`…) on elements |
36
37
  | 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) |
37
38
  | Text that arrives or moves | `<Reveal>`, `<ScrambleText>`, `<Typewriter>`, `<HighlightSweep>`, `<Marquee>` |
39
+ | 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`) |
38
40
  | A small logo mark, a loading or "live" sign | `<PulseMark>`, `.fx-live` from `motion.css` |
39
41
  | A hero photo that reacts like water: ripples, a pond, "touch the photo" | `<ImageRipple src="…" alt="…">` (`strength`, `size`, `viscosity`, `fringe`, `fit="contain"`) |
40
42
  | 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
@@ -58,6 +58,8 @@ BorderSweep: a light travelling round an element's outline, on hover and focus o
58
58
  | `speed` | `number` | Seconds a lap takes. Default 2.6. |
59
59
  | `width` | `number` | The ring's width, px. Default 1. |
60
60
  | `always` | `boolean` | Run all the time, not only on hover. Default false. |
61
+ | `lights` | `1 \| 2` | How many lights go round, 1–2: two chase each other half a lap apart. Default 1. |
62
+ | `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. |
61
63
  | `class` | `string` | Classes for the element. |
62
64
 
63
65
  ## `<Caustics>`
@@ -222,6 +224,30 @@ FlutedGlass: a pane of slanted fluted glass over soft blooms of colour, the main
222
224
  | `fixed` | `boolean` | Fill the viewport, behind the page (position: fixed, z-index -1). Default false. |
223
225
  | `class` | `string` | Classes for the element. |
224
226
 
227
+ ## `<Galaxy>`
228
+
229
+ 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.
230
+
231
+ ```astro
232
+ <section class="hero" style="position: relative">
233
+ <Galaxy palette="Peacock" />
234
+ <h1>Made for <em>night owls.</em></h1>
235
+ </section>
236
+ ```
237
+
238
+ | Prop | Type | |
239
+ |---|---|---|
240
+ | `colors` | `string[]` | The nebula's colours, deep to bright (two to five read best), blended in Oklab from near-black up to a pale highlight. Default indigo, cornflower, violet and cyan. |
241
+ | `palette` | `PaletteName \| (string & {})` | A shared palette by name (`PALETTES`, any case), when there are no `colors`. |
242
+ | `speed` | `number` | How fast it drifts and twinkles, 0–4; 0 holds it still. Default 1. |
243
+ | `stars` | `number` | How many stars, as a share of the usual, 0–3; 0 for none. Default 1. |
244
+ | `glitter` | `number` | How bright the fine glitter is, as a share of the usual, 0–2; 0 for none. Default 1. |
245
+ | `seed` | `number` | Which sky, 1–999: the same seed draws the same nebula and stars. Default 7. |
246
+ | `lazy` | `boolean \| string` | Run only while near the screen (true, or a CSS length; default `200px`), handled by `mount`. Default false. |
247
+ | `background` | `string` | What shows before it draws. Default `#05040d`. |
248
+ | `fixed` | `boolean` | Fill the viewport, behind the page (position: fixed, z-index -1). Default false. |
249
+ | `class` | `string` | Classes for the element. |
250
+
225
251
  ## `<Glass>`
226
252
 
227
253
  Glass: a liquid glass panel, with a rim that catches the light and a sheen that follows the pointer. A wrapper for `class="glass"` from glass.css that also starts the sheen; for elements you render yourself, import `@arraypress/effects-astro/glass.css` and add the class, then call `glassSheen()` once.
@@ -281,6 +307,25 @@ GlassGlyph: a character or a logo as a thick slab of dark, smoked glass, lit fro
281
307
  | `fixed` | `boolean` | Fill the viewport, behind the page (position: fixed, z-index -1). Default false. |
282
308
  | `class` | `string` | Classes for the element. |
283
309
 
310
+ ## `<GlitchText>`
311
+
312
+ GlitchText: a headline that glitches now and then. Every few seconds two coloured copies of it (pink and blue by default) flash over it for a few frames, sliced into bands and shifted sideways, and the text nudges with them; the rest of the time it sits still. Livelier under the pointer (on the text, or a link or button round it). Each one on the page glitches on its own beat. CSS only, from glitch-text.css; with reduced motion it is the plain text. Not the canvas `<PixelGlitchText>`, which breaks into pixels under the pointer.
313
+
314
+ ```astro
315
+ <GlitchText as="h2" blend="screen">Seen one you like? <em>Make it yours.</em></GlitchText>
316
+ ```
317
+
318
+ | Prop | Type | |
319
+ |---|---|---|
320
+ | `as` | `HTMLTag` | The element to render. Default `span`. |
321
+ | `every` | `number` | Seconds from one glitch to the next, 2–12 (the burst is a fixed share of it, so it lengthens too). Default 5. |
322
+ | `hoverEvery` | `number` | Seconds from one glitch to the next under the pointer, 0.5–5. Default 1.6. |
323
+ | `delay` | `number` | Where in its cycle it starts, seconds (negative is part way in); give several the same to glitch together. Default a random offset, so each has its own beat. |
324
+ | `colors` | `string[]` | The two copies' colours. Default `['#ff3ea5', '#2e4bff']` (pink and blue). |
325
+ | `palette` | `PaletteName \| (string & {})` | A shared palette by name (`PALETTES`, any case), its first two colours, when there are no `colors`. |
326
+ | `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`. |
327
+ | `class` | `string` | Classes for the element. |
328
+
284
329
  ## `<GlowField>`
285
330
 
286
331
  GlowField: a light laid over a section's background, or over a shader: a hard light source above an organic wash, so a headline has something to sit in. Pure CSS gradients that move only by transform and opacity, so it costs next to nothing and cannot fail to start.
@@ -816,7 +861,7 @@ PixelGlitchText: one line of text that breaks into pixels under the pointer and
816
861
  | `decay` | `number` | Heat kept each frame (0.9 is gone in about half a second). Default 0.9. |
817
862
  | `block` | `number` | The pixel block size at full heat, CSS px. Default 22. |
818
863
  | `shift` | `number` | How far the hottest rows slip sideways, CSS px. Default 16. |
819
- | `stroke` | `number` | With a width (CSS px), the text at rest is an outline that the pixels fill. Default 0 (solid). |
864
+ | `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). |
820
865
  | `as` | `HTMLTag` | The element to render. Default `span`. |
821
866
  | `fit` | `boolean` | Size the text to span its parent's width. Default false. |
822
867
  | `class` | `string` | Classes for the element. |
package/README.md CHANGED
@@ -54,6 +54,7 @@ Astro 6 or 7. The runtime underneath (`@arraypress/effects-astro`) works without
54
54
  | `<Ocean>` | Photoreal open sea to the horizon: wind-driven waves, a glittering sun path, light through thin crests, whitecaps, high cloud and haze; `time` dawn, noon, sunset or a moonlit night; the camera drifts with the pointer | WebGL |
55
55
  | `<IsoCity>` | A tiny isometric low-poly city with traffic keeping its lanes and the brand's taxis; click a street and the nearest one drives round to pick you up; `night` lights the windows and headlights | WebGL |
56
56
  | `<ColorPanels>` | Translucent panels of colour swinging open out of the dark and sweeping past like turning pages: Paper's color-panels shader with plain props (`density`, `skewLeft`, `length`, `edges`, `blur`, `blend`…), its Opening preset by default (`preset` for the others) | WebGL 2 |
57
+ | `<Galaxy>` | Deep space in a palette's colours: soft nebula clouds with dust lanes, shimmering glitter and twinkling stars, drifting slowly | Canvas |
57
58
  | `<WorldRoutes>` | A dotted world map with comets of light arcing between cities: a home hub, per-route colours and Oklab gradients, labels, regions, great-circle arcs, hover | Canvas |
58
59
  | `<GlowField>` | A light to lay over a background: a bloom, a swaying stage spotlight, a horizon or a wash, breathing gently | CSS |
59
60
  | `<Grain>` | Flickering film grain, to dither smooth gradients and make a picture read as film | CSS |
@@ -87,6 +88,7 @@ Astro 6 or 7. The runtime underneath (`@arraypress/effects-astro`) works without
87
88
  | `<Reveal>` | Content, or each word, rising into place on scroll | CSS + JS |
88
89
  | `<ScrollReveal>` | Once in a layout: anything with a reveal.css class (`fade-in-up`, `zoom-in`, `flip-left`…) arrives on scroll | CSS + JS |
89
90
  | `<HighlightSweep>` | A marker underline sweeping in under a word | CSS |
91
+ | `<GlitchText>` | A headline that glitches every few seconds, each on its own beat: two coloured copies sliced and shifted for a few frames; livelier under the pointer | CSS |
90
92
  | `<Marquee>` | An endless strip of names or logos, with a pause button | CSS + JS |
91
93
  | `<VariableType>` | A variable-font headline whose letters swell heavier and wider under the pointer in a springy wave, and drift gently on their own | JS |
92
94
 
@@ -99,7 +101,7 @@ Astro 6 or 7. The runtime underneath (`@arraypress/effects-astro`) works without
99
101
  | `<MosaicReveal>` | A slideshow whose pictures change through a GPU transition: tiles flipping in a diagonal wave, a pixel-sort melt, pixelation or a glowing dissolve | WebGL |
100
102
  | `<RadiantGlass>` | A cluster of frosted glass tiles on a dark ground, glowing from inside with soft drifting light that shifts with the pointer; a two-tone rim and a halo on each | WebGL |
101
103
  | `<Glass>` | A liquid glass panel with a lit rim and a pointer sheen; `refract` bends the live page behind it like a thick lens, with colour at the rim (Chromium; elsewhere it stays frosted) | CSS + JS |
102
- | `<BorderSweep>` | A light travelling round an outline | CSS |
104
+ | `<BorderSweep>` | A light travelling round an outline (or two chasing each other); `inset` for cards that clip | CSS |
103
105
  | `<Tilt>` | A card that leans towards the pointer, with a glare | CSS + JS |
104
106
  | `<Parallax>` | Layers that drift with the pointer by depth | CSS + JS |
105
107
  | `<Magnetic>` | A button the pointer pulls on | CSS + JS |
@@ -111,7 +113,8 @@ Astro 6 or 7. The runtime underneath (`@arraypress/effects-astro`) works without
111
113
  | Import | Classes |
112
114
  |---|---|
113
115
  | `@arraypress/effects-astro/glass.css` | `.glass` (call `glassSheen()` once for the sheen) |
114
- | `@arraypress/effects-astro/border-sweep.css` | `.sweep-ring`, `--always`, `--fast` |
116
+ | `@arraypress/effects-astro/border-sweep.css` | `.sweep-ring`, `--always`, `--fast`, `--two`, `--inset` |
117
+ | `@arraypress/effects-astro/glitch-text.css` | `.glitch-text` with its copies `.glitch-text-a` and `.glitch-text-b` (markup in the file) |
115
118
  | `@arraypress/effects-astro/motion.css` | `.fx-pulse-ring`, `.fx-heartbeat`, `.fx-bump` (replay with `bump(el)`), `.fx-shimmer`, `.fx-pulse`, `.fx-wiggle`, `.fx-shake`, `.fx-settle`, `.fx-live` (a status dot) |
116
119
  | `@arraypress/effects-astro/reveal.css` | `.fade-in`, `.fade-in-up/down/left/right`, `.slide-in-*`, `.zoom-in`, `.zoom-out`, `.flip-up/down/left/right`, `.blur-in` (with `<ScrollReveal />`) |
117
120
 
@@ -139,7 +142,7 @@ Every effect that takes `colors` also takes `palette`, one of eighteen named set
139
142
 
140
143
  ## Changing colours
141
144
 
142
- The WebGL effects (`<LightField>`, `<InkField>`, `<Ink>`, `<AsciiRain>`, `<FlutedGlass>`, `<GlassGlyph>`, `<LiquidMetal>`, `<ParticleLogo>`, `<NeonSwarm>`, `<NebulaLogo>`, `<PointCloud>`, `<VoxelLogo>`, `<SignalLines>`, `<WaveBars>`, `<DotSurface>`, `<HaloRing>`, `<SilkRibbon>`, `<RadiantGlass>`, `<Topography>`, `<Caustics>`, `<RainOnGlass>`, `<MosaicReveal>`, `<Ocean>`, `<IsoCity>`) read a `data-colors` attribute; `setColors` writes it. A light or an ink field eases to the new palette in about a second; ink, rain and the rest take it from their next frame. Set before an effect starts, it is its colours from the first frame.
145
+ The WebGL effects (`<LightField>`, `<InkField>`, `<Ink>`, `<AsciiRain>`, `<FlutedGlass>`, `<GlassGlyph>`, `<LiquidMetal>`, `<ParticleLogo>`, `<NeonSwarm>`, `<NebulaLogo>`, `<PointCloud>`, `<VoxelLogo>`, `<SignalLines>`, `<WaveBars>`, `<DotSurface>`, `<HaloRing>`, `<SilkRibbon>`, `<RadiantGlass>`, `<Topography>`, `<Caustics>`, `<RainOnGlass>`, `<MosaicReveal>`, `<Ocean>`, `<IsoCity>`) and `<Galaxy>` read a `data-colors` attribute; `setColors` writes it. A light or an ink field eases to the new palette in about a second; ink, rain and the rest take it from their next frame. Set before an effect starts, it is its colours from the first frame.
143
146
 
144
147
  ```js
145
148
  import { setColors } from '@arraypress/effects-astro';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arraypress/effects-astro",
3
- "version": "0.3.0",
3
+ "version": "0.4.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 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",
@@ -6,7 +6,9 @@
6
6
  * `@arraypress/effects-astro/border-sweep.css` and add the class.
7
7
  *
8
8
  * Suits outlined things: cards, ghost buttons, a featured pricing tier. A
9
- * filled button has no outline for the light to travel.
9
+ * filled button has no outline for the light to travel. `lights={2}` sends
10
+ * two round, chasing each other; `inset` keeps the ring over the content of
11
+ * a card that clips and fills itself.
10
12
  *
11
13
  * @example
12
14
  * <BorderSweep as="a" href="/pricing" class="card" color="#a5b4fc" always>…</BorderSweep>
@@ -26,14 +28,18 @@ interface Props {
26
28
  width?: number;
27
29
  /** Run all the time, not only on hover. Default false. */
28
30
  always?: boolean;
31
+ /** How many lights go round, 1–2: two chase each other half a lap apart. Default 1. */
32
+ lights?: 1 | 2;
33
+ /** 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
+ inset?: boolean;
29
35
  class?: string;
30
36
  [attribute: string]: unknown;
31
37
  }
32
38
 
33
- const { as: Tag = 'div', color, speed, width, always = false, class: className, style: given, ...attributes } = Astro.props;
39
+ const { as: Tag = 'div', color, speed, width, always = false, lights = 1, inset = false, class: className, style: given, ...attributes } = Astro.props;
34
40
  const style = [color && `--sweep-color: ${color}`, speed !== undefined && `--sweep-speed: ${speed}s`, width !== undefined && `--sweep-width: ${width}px`]
35
41
  .filter(Boolean)
36
42
  .join('; ');
37
43
  ---
38
44
 
39
- <Tag class:list={['sweep-ring', { 'sweep-ring--always': always }, className]} style={withStyle(style, given)} {...attributes}><slot /></Tag>
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>
@@ -0,0 +1,40 @@
1
+ ---
2
+ /**
3
+ * Galaxy: deep space in your colours. Soft nebula clouds with dark dust
4
+ * lanes, fine glitter shimmering over them and stars twinkling each on
5
+ * its own beat, the brightest with a cross of light, all drifting slowly.
6
+ * See src/runtime/galaxy.js.
7
+ *
8
+ * Opaque: it is the whole background of what it fills (its nearest
9
+ * positioned ancestor, or the viewport with `fixed`). Canvas 2D, so it
10
+ * needs no WebGL; one still frame with reduced motion. `setColors`
11
+ * recolours it live.
12
+ *
13
+ * @example
14
+ * <section class="hero" style="position: relative">
15
+ * <Galaxy palette="Peacock" />
16
+ * <h1>Made for <em>night owls.</em></h1>
17
+ * </section>
18
+ */
19
+ import EffectCanvas from './EffectCanvas.astro';
20
+ import type { GalaxyConfig } from '../runtime/galaxy.js';
21
+
22
+ interface Props extends GalaxyConfig {
23
+ /** What shows before it draws. Default `#05040d`. */
24
+ background?: string;
25
+ /** Fill the viewport, behind the page (position: fixed, z-index -1). Default false. */
26
+ fixed?: boolean;
27
+ class?: string;
28
+ }
29
+
30
+ const { background = '#05040d', fixed = false, class: className, ...config } = Astro.props;
31
+ ---
32
+
33
+ <EffectCanvas name="galaxy" config={config} fixed={fixed} class={className} behind background={background} />
34
+
35
+ <script>
36
+ import { mount } from '../runtime/mount.js';
37
+ import { galaxy } from '../runtime/galaxy.js';
38
+
39
+ mount('[data-effect-galaxy]', galaxy);
40
+ </script>
@@ -0,0 +1,69 @@
1
+ ---
2
+ /**
3
+ * GlitchText: a headline that glitches now and then. Every few seconds two
4
+ * coloured copies of it (pink and blue by default) flash over it for a few
5
+ * frames, sliced into bands and shifted sideways, and the text nudges with
6
+ * them; the rest of the time it sits still. Livelier under the pointer (on
7
+ * the text, or a link or button round it). Each one on the page glitches
8
+ * on its own beat. CSS only, from glitch-text.css; with reduced motion it
9
+ * is the plain text. Not the canvas `<PixelGlitchText>`, which breaks
10
+ * into pixels under the pointer.
11
+ *
12
+ * The slot is rendered three times: once as the real text, twice as the
13
+ * copies (hidden from assistive technology and from focus), so keep it to
14
+ * text and inline formatting. For elements you render yourself, import
15
+ * `@arraypress/effects-astro/glitch-text.css` and follow its markup.
16
+ *
17
+ * @example
18
+ * <GlitchText as="h2" blend="screen">Seen one you like? <em>Make it yours.</em></GlitchText>
19
+ */
20
+ import type { HTMLTag } from 'astro/types';
21
+ import type { PaletteName } from '../runtime/palettes.js';
22
+ import { pickColors } from '../runtime/palettes.js';
23
+ import '../styles/glitch-text.css';
24
+ import { withStyle } from './style.js';
25
+
26
+ interface Props {
27
+ /** The element to render. Default `span`. */
28
+ as?: HTMLTag;
29
+ /** Seconds from one glitch to the next, 2–12 (the burst is a fixed share of it, so it lengthens too). Default 5. */
30
+ every?: number;
31
+ /** Seconds from one glitch to the next under the pointer, 0.5–5. Default 1.6. */
32
+ hoverEvery?: number;
33
+ /** Where in its cycle it starts, seconds (negative is part way in); give several the same to glitch together. Default a random offset, so each has its own beat. */
34
+ delay?: number;
35
+ /** The two copies' colours. Default `['#ff3ea5', '#2e4bff']` (pink and blue). */
36
+ colors?: string[];
37
+ /** A shared palette by name (`PALETTES`, any case), its first two colours, when there are no `colors`. */
38
+ palette?: PaletteName | (string & {});
39
+ /** How the copies blend with the text and what is behind: `multiply` on a light ground, `screen` on a dark one. Default `multiply`. */
40
+ blend?: 'multiply' | 'screen' | 'normal' | 'difference' | 'plus-lighter';
41
+ class?: string;
42
+ [attribute: string]: unknown;
43
+ }
44
+
45
+ const { as: Tag = 'span', every, hoverEvery, delay, colors, palette, blend, class: className, style: given, ...attributes } = Astro.props;
46
+ const [a, b] = colors?.length || palette ? pickColors({ colors, palette }, ['#ff3ea5', '#2e4bff'], (p) => [p.colors[0], p.colors[1]]) : [];
47
+ const cycle = every ?? 5;
48
+ // Rendered once, at build time: each instance gets its own beat in the static page.
49
+ const offset = delay ?? -Number((Math.random() * cycle).toFixed(2));
50
+ const style = [
51
+ every !== undefined && `--glitch-every: ${every}s`,
52
+ hoverEvery !== undefined && `--glitch-hover: ${hoverEvery}s`,
53
+ `--glitch-delay: ${offset}s`,
54
+ a && `--glitch-a: ${a}`,
55
+ (b ?? a) && `--glitch-b: ${b ?? a}`,
56
+ blend && `--glitch-blend: ${blend}`,
57
+ ]
58
+ .filter(Boolean)
59
+ .join('; ');
60
+ const html = await Astro.slots.render('default');
61
+ ---
62
+
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
69
+ >
@@ -58,10 +58,10 @@ const { as: Tag = 'span', fit = false, cell, reach, decay, block, shift, stroke,
58
58
  -webkit-text-fill-color: transparent;
59
59
  -webkit-text-stroke: var(--glitch-stroke) currentColor;
60
60
  }
61
- /* Once the canvas draws the text, the element's own is only for layout. */
61
+ /* Once the canvas draws the text (and its outline, merged), the element's own is only for layout. */
62
62
  .effect-pixel-glitch:global(.is-ready) {
63
63
  -webkit-text-fill-color: transparent;
64
- -webkit-text-stroke: 0;
64
+ -webkit-text-stroke: 0 transparent;
65
65
  }
66
66
  .effect-pixel-glitch :global(.effect-pixel-glitch-canvas) {
67
67
  position: absolute;
package/src/index.d.ts CHANGED
@@ -16,7 +16,7 @@ export { pointCloud } from './runtime/point-cloud.js';
16
16
  export type { PointCloudConfig } from './runtime/point-cloud.js';
17
17
  export { voxelLogo } from './runtime/voxel-logo.js';
18
18
  export type { VoxelLogoConfig } from './runtime/voxel-logo.js';
19
- export { pixelGlitch } from './runtime/pixel-glitch.js';
19
+ export { pixelGlitch, outlineAlpha } from './runtime/pixel-glitch.js';
20
20
  export type { PixelGlitchConfig } from './runtime/pixel-glitch.js';
21
21
  export { fit, fitText } from './runtime/fit-text.js';
22
22
  export { textNodes, textRange, splitLetters, joinLetters } from './runtime/text.js';
@@ -68,6 +68,8 @@ export { radiantGlass } from './runtime/radiant-glass.js';
68
68
  export type { RadiantGlassConfig } from './runtime/radiant-glass.js';
69
69
  export { topography } from './runtime/topography.js';
70
70
  export type { TopographyConfig } from './runtime/topography.js';
71
+ export { galaxy, galaxyRamp, nebulaField } from './runtime/galaxy.js';
72
+ export type { GalaxyConfig } from './runtime/galaxy.js';
71
73
  export { caustics, causticTones } from './runtime/caustics.js';
72
74
  export type { CausticsConfig, CausticTones } from './runtime/caustics.js';
73
75
  export { rainOnGlass } from './runtime/rain-on-glass.js';
package/src/index.js CHANGED
@@ -20,7 +20,7 @@ export { flutedGlass } from './runtime/fluted-glass.js';
20
20
  export { particleLogo } from './runtime/particle-logo.js';
21
21
  export { pointCloud } from './runtime/point-cloud.js';
22
22
  export { voxelLogo } from './runtime/voxel-logo.js';
23
- export { pixelGlitch } from './runtime/pixel-glitch.js';
23
+ export { pixelGlitch, outlineAlpha } from './runtime/pixel-glitch.js';
24
24
  export { fit, fitText } from './runtime/fit-text.js';
25
25
  export { textNodes, textRange, splitLetters, joinLetters } from './runtime/text.js';
26
26
  export { variableType, DEFAULT_AXES } from './runtime/variable-type.js';
@@ -51,6 +51,7 @@ export { haloRing } from './runtime/halo-ring.js';
51
51
  export { silkRibbon } from './runtime/silk-ribbon.js';
52
52
  export { radiantGlass } from './runtime/radiant-glass.js';
53
53
  export { topography } from './runtime/topography.js';
54
+ export { galaxy, galaxyRamp, nebulaField } from './runtime/galaxy.js';
54
55
  export { caustics, causticTones } from './runtime/caustics.js';
55
56
  export { rainOnGlass } from './runtime/rain-on-glass.js';
56
57
  export { ocean } from './runtime/ocean.js';
@@ -0,0 +1,37 @@
1
+ import type { PaletteName } from './palettes.js';
2
+
3
+ export interface GalaxyConfig {
4
+ /** The nebula's colours, deep to bright (two to five read best), blended in Oklab from near-black up to a pale highlight. Default indigo, cornflower, violet and cyan. */
5
+ colors?: string[];
6
+ /** A shared palette by name (`PALETTES`, any case), when there are no `colors`. */
7
+ palette?: PaletteName | (string & {});
8
+ /** How fast it drifts and twinkles, 0–4; 0 holds it still. Default 1. */
9
+ speed?: number;
10
+ /** How many stars, as a share of the usual, 0–3; 0 for none. Default 1. */
11
+ stars?: number;
12
+ /** How bright the fine glitter is, as a share of the usual, 0–2; 0 for none. Default 1. */
13
+ glitter?: number;
14
+ /** Which sky, 1–999: the same seed draws the same nebula and stars. Default 7. */
15
+ seed?: number;
16
+ /** Run only while near the screen (true, or a CSS length; default `200px`), handled by `mount`. Default false. */
17
+ lazy?: boolean | string;
18
+ }
19
+
20
+ /** The colours without `colors` or `palette`: indigo, cornflower, violet and cyan. */
21
+ export const COLORS: string[];
22
+
23
+ /** The worked-out nebula's size, px (drawn scaled up to cover). */
24
+ export const NEBULA_WIDTH: number;
25
+ export const NEBULA_HEIGHT: number;
26
+
27
+ /** The nebula as places on the colour ramp, 0–1, one a pixel row by row: layered noise clouds cut by ridged dust lanes. Tileable; the same seed gives the same field. */
28
+ export function nebulaField(width: number, height: number, seed?: number): Float32Array;
29
+
30
+ /** The ramp the nebula is painted along (the first colour darkened to near-black, the colours, a pale top), blended in Oklab: `steps` (default 256) RGB triples. Throws a TypeError for a colour that is not hex. */
31
+ export function galaxyRamp(colors: string[], steps?: number): Uint8ClampedArray;
32
+
33
+ /** Paints a nebula field along a ramp: opaque RGBA, a pixel per value. */
34
+ export function nebulaPixels(field: Float32Array, ramp: Uint8ClampedArray): Uint8ClampedArray;
35
+
36
+ /** Starts the galaxy on an element (its first canvas is drawn into). Returns a function that stops it. */
37
+ export function galaxy(el: HTMLElement, config: GalaxyConfig): () => void;
@@ -0,0 +1,311 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/galaxy
3
+ *
4
+ * Deep space in a palette's colours: soft nebula clouds with darker dust
5
+ * lanes through them, fine glitter that shimmers as a whole, and stars
6
+ * that twinkle each on its own beat (the brightest with a little cross of
7
+ * light), all drifting slowly.
8
+ *
9
+ * The nebula is worked out once, small (400 × 225), from tileable value
10
+ * noise: five octaves for the clouds, three ridged ones for the dust, and a
11
+ * broad field that shifts the colours along the ramp so they wander. Each
12
+ * frame draws it scaled up to cover (it is soft anyway) at a slowly
13
+ * drifting offset, the glitter over it at full resolution, then the stars
14
+ * from one pre-drawn sprite per tint. The ramp runs from near-black
15
+ * through the palette to a pale highlight, blended in Oklab; new colours
16
+ * (`setColors`) only remap the worked-out field.
17
+ *
18
+ * Canvas 2D, opaque. One still frame with prefers-reduced-motion.
19
+ *
20
+ * From the Logomarks studio's showcase.
21
+ */
22
+
23
+ import { createCanvas2D } from './canvas2d.js';
24
+ import { mixOklab, parseColor } from './color.js';
25
+ import { watchColors } from './mount.js';
26
+ import { pickColors } from './palettes.js';
27
+ import { seededRandom } from './random.js';
28
+
29
+ /**
30
+ * @typedef {object} GalaxyConfig
31
+ * @property {string[]} [colors] The nebula's colours, deep to bright, blended in Oklab.
32
+ * @property {string} [palette] A shared palette by name, when there are no `colors`.
33
+ * @property {number} [speed=1] How fast it drifts and twinkles; 0 holds it still.
34
+ * @property {number} [stars=1] How many stars, as a share of the usual.
35
+ * @property {number} [glitter=1] How bright the glitter is, as a share of the usual.
36
+ * @property {number} [seed=7] Which sky: the same seed draws the same nebula and stars.
37
+ */
38
+
39
+ /** The colours without `colors` or `palette`: indigo, cornflower, violet and cyan. */
40
+ export const COLORS = ['#3a2bd9', '#5c7cff', '#b45cff', '#5cecff'];
41
+
42
+ /** The worked-out nebula's size, px: small, since it is drawn scaled up and soft. */
43
+ export const NEBULA_WIDTH = 400;
44
+ export const NEBULA_HEIGHT = 225;
45
+
46
+ /** The ramp's top: a pale, faintly violet white. */
47
+ const PALE = /** @type {import('./color.js').Rgb} */ ([245 / 255, 240 / 255, 1]);
48
+
49
+ /** Star tints besides the palette's own: white, a violet white and a blue white. */
50
+ const WHITES = ['#ffffff', '#f2e9ff', '#e6f6ff'];
51
+
52
+ /**
53
+ * Tileable value noise on an n × n lattice of random values, eased
54
+ * between (smoothstep), wrapping at 0–1 in both directions.
55
+ *
56
+ * @param {number} n The lattice's size, cells a side.
57
+ * @param {() => number} rnd Random values, 0–1.
58
+ * @returns {(x: number, y: number) => number} The noise at (x, y), 0–1, for x and y in 0–1.
59
+ */
60
+ function lattice(n, rnd) {
61
+ const v = Float32Array.from({ length: n * n }, () => rnd());
62
+ /**
63
+ * A lattice value, wrapped.
64
+ *
65
+ * @param {number} i Across.
66
+ * @param {number} j Down.
67
+ * @returns {number} The value there.
68
+ */
69
+ const at = (i, j) => v[(((j % n) + n) % n) * n + (((i % n) + n) % n)];
70
+ return (x, y) => {
71
+ const fx = x * n;
72
+ const fy = y * n;
73
+ const x0 = Math.floor(fx);
74
+ const y0 = Math.floor(fy);
75
+ const tx = fx - x0;
76
+ const ty = fy - y0;
77
+ const sx = tx * tx * (3 - 2 * tx);
78
+ const sy = ty * ty * (3 - 2 * ty);
79
+ const a = at(x0, y0) + (at(x0 + 1, y0) - at(x0, y0)) * sx;
80
+ const b = at(x0, y0 + 1) + (at(x0 + 1, y0 + 1) - at(x0, y0 + 1)) * sx;
81
+ return a + (b - a) * sy;
82
+ };
83
+ }
84
+
85
+ /**
86
+ * The nebula as places on the colour ramp: clouds of layered noise, cut
87
+ * by ridged dust lanes, nudged along the ramp by a broad second field so
88
+ * the colours wander. Tileable.
89
+ *
90
+ * @param {number} width Across, px.
91
+ * @param {number} height Down, px.
92
+ * @param {number} [seed=7] The same seed gives the same nebula.
93
+ * @returns {Float32Array} One value a pixel, 0 (dark) to 1 (the pale top), row by row.
94
+ */
95
+ export function nebulaField(width, height, seed = 7) {
96
+ const rnd = seededRandom(seed);
97
+ const octaves = [3, 6, 12, 24, 48].map((n) => lattice(n, rnd));
98
+ const dust = [5, 10, 20].map((n) => lattice(n, rnd));
99
+ const hue = lattice(2, rnd);
100
+ const out = new Float32Array(width * height);
101
+ for (let y = 0; y < height; y++) {
102
+ for (let x = 0; x < width; x++) {
103
+ const u = x / width;
104
+ const v = y / height;
105
+ let n = 0;
106
+ let amp = 0.5;
107
+ for (const o of octaves) {
108
+ n += o(u, v) * amp;
109
+ amp *= 0.5;
110
+ }
111
+ n /= 0.97;
112
+ // Ridged dust lanes: dark filaments through the clouds.
113
+ let r = 0;
114
+ for (const o of dust) r += 1 - Math.abs(o(u, v) * 2 - 1);
115
+ r /= dust.length;
116
+ let t = Math.min(1, Math.max(0, (n - 0.3) * 2.3));
117
+ t = Math.max(0, t * (1 - Math.max(0, r - 0.72) * 2.2));
118
+ out[y * width + x] = Math.min(1, Math.max(0, t * 0.8 + (hue(u, v) - 0.5) * 0.6));
119
+ }
120
+ }
121
+ return out;
122
+ }
123
+
124
+ /**
125
+ * The colour ramp the nebula is painted along: near-black (the first
126
+ * colour, darkened), the colours in order, then a pale highlight, each
127
+ * stretch blended in Oklab.
128
+ *
129
+ * @param {string[]} colors The colours, as CSS hex.
130
+ * @param {number} [steps=256] How many entries.
131
+ * @returns {Uint8ClampedArray} `steps` RGB triples, 0–255.
132
+ * @throws {TypeError} When a colour is not hex.
133
+ */
134
+ export function galaxyRamp(colors, steps = 256) {
135
+ const cs = (colors.length ? colors : COLORS).map(parseColor);
136
+ const stops = [mixOklab(cs[0], [0, 0, 0], 0.62), ...cs, PALE];
137
+ const out = new Uint8ClampedArray(steps * 3);
138
+ for (let s = 0; s < steps; s++) {
139
+ const k = (s / (steps - 1)) * (stops.length - 1);
140
+ const i = Math.min(stops.length - 2, Math.floor(k));
141
+ const rgb = mixOklab(stops[i], stops[i + 1], k - i);
142
+ for (let ch = 0; ch < 3; ch++) out[s * 3 + ch] = Math.round(rgb[ch] * 255);
143
+ }
144
+ return out;
145
+ }
146
+
147
+ /**
148
+ * Paints a nebula field along a ramp.
149
+ *
150
+ * @param {Float32Array} field From nebulaField.
151
+ * @param {Uint8ClampedArray} ramp From galaxyRamp.
152
+ * @returns {Uint8ClampedArray} RGBA, opaque, one pixel per value of the field.
153
+ */
154
+ export function nebulaPixels(field, ramp) {
155
+ const last = ramp.length / 3 - 1;
156
+ const out = new Uint8ClampedArray(field.length * 4);
157
+ for (let p = 0; p < field.length; p++) {
158
+ const i = Math.round(field[p] * last) * 3;
159
+ out[p * 4] = ramp[i];
160
+ out[p * 4 + 1] = ramp[i + 1];
161
+ out[p * 4 + 2] = ramp[i + 2];
162
+ out[p * 4 + 3] = 255;
163
+ }
164
+ return out;
165
+ }
166
+
167
+ /**
168
+ * A star's glow, drawn once: a radial gradient in the tint, solid at the
169
+ * centre and gone at the edge.
170
+ *
171
+ * @param {string} tint CSS hex.
172
+ * @returns {HTMLCanvasElement} 64 × 64.
173
+ */
174
+ function starSprite(tint) {
175
+ const [r, g, b] = parseColor(tint).map((v) => Math.round(v * 255));
176
+ const sprite = document.createElement('canvas');
177
+ sprite.width = sprite.height = 64;
178
+ const s = /** @type {CanvasRenderingContext2D} */ (sprite.getContext('2d'));
179
+ const glow = s.createRadialGradient(32, 32, 0, 32, 32, 32);
180
+ glow.addColorStop(0, `rgb(${r} ${g} ${b})`);
181
+ glow.addColorStop(0.25, `rgb(${r} ${g} ${b} / 0.67)`);
182
+ glow.addColorStop(1, `rgb(${r} ${g} ${b} / 0)`);
183
+ s.fillStyle = glow;
184
+ s.fillRect(0, 0, 64, 64);
185
+ return sprite;
186
+ }
187
+
188
+ /**
189
+ * Starts the galaxy on an element (its first canvas is drawn into).
190
+ *
191
+ * @param {HTMLElement} el The element.
192
+ * @param {GalaxyConfig} config The settings.
193
+ * @returns {() => void} Stops it.
194
+ */
195
+ export function galaxy(el, config) {
196
+ const SPEED = config.speed ?? 1;
197
+ const STARS = Math.max(0, config.stars ?? 1);
198
+ const GLITTER = Math.max(0, config.glitter ?? 1);
199
+ const SEED = config.seed ?? 7;
200
+ let colors = pickColors(config, COLORS);
201
+
202
+ const field = nebulaField(NEBULA_WIDTH, NEBULA_HEIGHT, SEED);
203
+ const nebula = document.createElement('canvas');
204
+ nebula.width = NEBULA_WIDTH;
205
+ nebula.height = NEBULA_HEIGHT;
206
+ const nctx = nebula.getContext('2d');
207
+ /** @type {HTMLCanvasElement[]} */
208
+ let sprites = [];
209
+
210
+ /** Paints the nebula and the star sprites in the current colours. */
211
+ const paint = () => {
212
+ nctx?.putImageData(new ImageData(nebulaPixels(field, galaxyRamp(colors)), NEBULA_WIDTH, NEBULA_HEIGHT), 0, 0);
213
+ sprites = [...WHITES, ...colors].map(starSprite);
214
+ };
215
+ paint();
216
+
217
+ /** @type {HTMLCanvasElement | null} */
218
+ let glitter = null;
219
+ /** @type {{ x: number, y: number, r: number, phase: number, rate: number, cross: boolean, tint: number }[]} */
220
+ let stars = [];
221
+ let dpr = 1;
222
+ const start = performance.now();
223
+
224
+ /**
225
+ * Scatters the glitter and stars over the new size, the same way for
226
+ * the same seed and size.
227
+ *
228
+ * @param {import('./canvas2d.js').Canvas2D} c The canvas.
229
+ */
230
+ const resize = (c) => {
231
+ dpr = c.canvas.width / c.width;
232
+ const rnd = seededRandom(SEED * 31 + 1);
233
+ // Glitter: fine bright speckle at device resolution.
234
+ glitter = document.createElement('canvas');
235
+ glitter.width = c.canvas.width;
236
+ glitter.height = c.canvas.height;
237
+ const g = glitter.getContext('2d');
238
+ if (g) {
239
+ for (let k = 0; k < (glitter.width * glitter.height) / 70; k++) {
240
+ const x = rnd() * glitter.width;
241
+ const y = rnd() * glitter.height;
242
+ g.fillStyle = `rgb(255 255 255 / ${0.2 + rnd() ** 2.5 * 0.8})`;
243
+ const size = rnd() < 0.9 ? dpr : dpr * 1.6;
244
+ g.fillRect(x, y, size, size);
245
+ }
246
+ }
247
+ stars = Array.from({ length: Math.round(((c.width * c.height) / 9000) * STARS) }, () => ({
248
+ x: rnd() * c.width,
249
+ y: rnd() * c.height,
250
+ r: 0.6 + rnd() ** 4 * 3.4,
251
+ phase: rnd() * Math.PI * 2,
252
+ rate: 0.6 + rnd() * 1.8,
253
+ cross: rnd() < 0.12,
254
+ tint: Math.floor(rnd() * 64),
255
+ }));
256
+ };
257
+
258
+ /**
259
+ * One frame: the nebula drifting, the glitter shimmering over it, the
260
+ * stars twinkling.
261
+ *
262
+ * @param {import('./canvas2d.js').Canvas2D} c The canvas.
263
+ * @param {number} now The time, ms.
264
+ */
265
+ const draw = (c, now) => {
266
+ const { ctx, width: w, height: h } = c;
267
+ const t = c.still ? 0 : ((now - start) / 1000) * SPEED;
268
+ // The nebula, scaled to cover with a margin to drift through.
269
+ const k = Math.max(w / NEBULA_WIDTH, h / NEBULA_HEIGHT) * 1.12;
270
+ const nw = NEBULA_WIDTH * k;
271
+ const nh = NEBULA_HEIGHT * k;
272
+ const ox = -(nw - w) / 2 + Math.sin(t * 0.05) * (nw - w) * 0.4;
273
+ const oy = -(nh - h) / 2 + Math.cos(t * 0.04) * (nh - h) * 0.4;
274
+ ctx.globalCompositeOperation = 'source-over';
275
+ ctx.globalAlpha = 1;
276
+ ctx.imageSmoothingEnabled = true;
277
+ ctx.imageSmoothingQuality = 'high';
278
+ ctx.drawImage(nebula, ox, oy, nw, nh);
279
+ ctx.globalCompositeOperation = 'lighter';
280
+ if (glitter && GLITTER > 0) {
281
+ ctx.globalAlpha = Math.min(1, (0.75 + Math.sin(t * 1.7) * 0.12) * GLITTER);
282
+ ctx.drawImage(glitter, 0, 0, w, h);
283
+ }
284
+ const hair = 1 / dpr;
285
+ for (const s of stars) {
286
+ const a = 0.35 + 0.65 * (0.5 + 0.5 * Math.sin(s.phase + t * s.rate));
287
+ ctx.globalAlpha = a;
288
+ ctx.drawImage(sprites[s.tint % sprites.length], s.x - s.r * 4, s.y - s.r * 4, s.r * 8, s.r * 8);
289
+ if (s.cross) {
290
+ ctx.fillStyle = '#ffffff';
291
+ const arm = s.r * 9 * a;
292
+ ctx.fillRect(s.x - arm, s.y - hair / 2, arm * 2, hair);
293
+ ctx.fillRect(s.x - hair / 2, s.y - arm, hair, arm * 2);
294
+ }
295
+ }
296
+ ctx.globalAlpha = 1;
297
+ ctx.globalCompositeOperation = 'source-over';
298
+ };
299
+
300
+ const { c, stop } = createCanvas2D(el, { draw, resize });
301
+ if (!c) return stop;
302
+ const unwatch = watchColors(el, (next) => {
303
+ colors = next.colors;
304
+ paint();
305
+ if (c.still) draw(c, performance.now());
306
+ });
307
+ return () => {
308
+ stop();
309
+ unwatch();
310
+ };
311
+ }
@@ -9,9 +9,16 @@ export interface PixelGlitchConfig {
9
9
  block?: number;
10
10
  /** How far the hottest rows slip sideways, CSS px. Default 16. */
11
11
  shift?: number;
12
- /** With a width (CSS px), the text at rest is an outline that the pixels fill. Default 0 (solid). */
12
+ /** 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). */
13
13
  stroke?: number;
14
14
  }
15
15
 
16
+ /**
17
+ * The outline of a shape from its RGBA coverage: each pixel's alpha less the
18
+ * smallest within `radius` px of it, so the line runs inside the edge and
19
+ * touching shapes share one outline. One alpha byte a pixel.
20
+ */
21
+ export function outlineAlpha(rgba: Uint8ClampedArray, width: number, height: number, radius: number): Uint8ClampedArray;
22
+
16
23
  /** Starts the pixel glitch on an element of text. Returns a function that stops it. */
17
24
  export function pixelGlitch(el: HTMLElement, config: PixelGlitchConfig): () => void;
@@ -10,7 +10,10 @@
10
10
  *
11
11
  * With `stroke` set, the text at rest is a hollow outline of that width and
12
12
  * the pixels it breaks into fill the letters solid, so the pointer lights
13
- * the word up as it passes.
13
+ * the word up as it passes. The outline is one shape for the whole word
14
+ * (the solid letters less themselves eroded by the width), so letters that
15
+ * touch or overlap under tight tracking merge rather than each outline
16
+ * crossing the next.
14
17
  *
15
18
  * The element keeps its text (it only turns transparent once the canvas
16
19
  * has drawn), so fit-text, selection and the no-JS look are unchanged.
@@ -21,8 +24,11 @@
21
24
  * `pointer-events: none` (a big wordmark's line box often overlaps links).
22
25
  * Animates only while some cell is hot, and only while the text is on
23
26
  * screen. Off with prefers-reduced-motion and without a hovering pointer.
27
+ * Repainted when the text's own face has loaded (a face used only here can
28
+ * arrive after `document.fonts.ready`).
24
29
  *
25
- * From the SampleGrid (WaveGrid) theme's footer.
30
+ * From the SampleGrid (WaveGrid) theme's footer; the merged outline and the
31
+ * font reload from the Logomarks site's.
26
32
  */
27
33
 
28
34
  import { canHover, prefersReducedMotion } from './device.js';
@@ -38,6 +44,44 @@ import { textNodes } from './text.js';
38
44
  * @property {number} [stroke=0] With a width (CSS px), the text at rest is an outline that the pixels fill.
39
45
  */
40
46
 
47
+ /** The 16 directions the outline's erosion looks in, as unit vectors. */
48
+ const AROUND = Array.from({ length: 16 }, (_, k) => [Math.cos((k / 16) * Math.PI * 2), Math.sin((k / 16) * Math.PI * 2)]);
49
+
50
+ /**
51
+ * The outline of a shape, from its coverage: each pixel's alpha less the
52
+ * smallest alpha within `radius` of it (looked for in 16 directions), so
53
+ * the line runs `radius` px inside the shape's edge and stays smooth where
54
+ * the edge is antialiased. Shapes that touch or overlap give one outline
55
+ * round the lot.
56
+ *
57
+ * @param {Uint8ClampedArray} rgba The shape, RGBA (only alpha is read).
58
+ * @param {number} width Its width, px.
59
+ * @param {number} height Its height, px.
60
+ * @param {number} radius The outline's width, px (rounded, at least 1).
61
+ * @returns {Uint8ClampedArray} The outline's alpha, one byte a pixel.
62
+ */
63
+ export function outlineAlpha(rgba, width, height, radius) {
64
+ const r = Math.max(1, Math.round(radius));
65
+ const steps = AROUND.map(([x, y]) => [Math.round(x * r), Math.round(y * r)]);
66
+ const out = new Uint8ClampedArray(width * height);
67
+ for (let y = 0; y < height; y++) {
68
+ for (let x = 0; x < width; x++) {
69
+ const v = rgba[(y * width + x) * 4 + 3];
70
+ if (!v) continue;
71
+ let low = v;
72
+ for (const [dx, dy] of steps) {
73
+ const nx = x + dx;
74
+ const ny = y + dy;
75
+ const n = nx < 0 || ny < 0 || nx >= width || ny >= height ? 0 : rgba[(ny * width + nx) * 4 + 3];
76
+ if (n < low) low = n;
77
+ if (!low) break;
78
+ }
79
+ out[y * width + x] = v - low;
80
+ }
81
+ }
82
+ return out;
83
+ }
84
+
41
85
  /**
42
86
  * Starts the pixel glitch on an element of text.
43
87
  *
@@ -152,8 +196,8 @@ export function pixelGlitch(el, config) {
152
196
 
153
197
  /**
154
198
  * Draws the text at rest into `crisp`, each glyph where the browser put
155
- * it: solid, or with `stroke` an outline (the stroke is centred on the
156
- * glyph's edge, so it is drawn twice as wide and the inner half cut away).
199
+ * it: solid, or with `stroke` one outline round the whole word (see
200
+ * outlineAlpha), so overlapping letters do not show their crossings.
157
201
  */
158
202
  const paint = () => {
159
203
  const texts = textNodes(el);
@@ -182,8 +226,6 @@ export function pixelGlitch(el, config) {
182
226
  c2.setTransform(dpr, 0, 0, dpr, 0, 0);
183
227
  c2.clearRect(0, 0, g.w, g.h);
184
228
  c2.fillStyle = g.ink;
185
- c2.strokeStyle = g.ink;
186
- c2.lineJoin = 'round';
187
229
  c2.font = `${cs.fontStyle} ${cs.fontWeight} ${cs.fontSize} ${cs.fontFamily}`;
188
230
  c2.textBaseline = 'alphabetic';
189
231
  const range = document.createRange();
@@ -209,12 +251,16 @@ export function pixelGlitch(el, config) {
209
251
  eachGlyph((ch, x, y) => c2.fillText(ch, x, y));
210
252
  g.alpha = c2.getImageData(0, 0, crisp.width, crisp.height).data;
211
253
  if (STROKE > 0) {
212
- c2.clearRect(0, 0, g.w, g.h);
213
- c2.lineWidth = STROKE * 2;
214
- eachGlyph((ch, x, y) => c2.strokeText(ch, x, y));
215
- c2.globalCompositeOperation = 'destination-out';
216
- eachGlyph((ch, x, y) => c2.fillText(ch, x, y));
254
+ // The pixels still sample the solid letters (g.alpha); what shows at rest is their outline, in the ink.
255
+ const line = outlineAlpha(g.alpha, crisp.width, crisp.height, STROKE * dpr);
256
+ const img = c2.createImageData(crisp.width, crisp.height);
257
+ for (let i = 0; i < line.length; i++) img.data[i * 4 + 3] = line[i];
258
+ c2.putImageData(img, 0, 0);
259
+ c2.setTransform(1, 0, 0, 1, 0, 0);
260
+ c2.globalCompositeOperation = 'source-in';
261
+ c2.fillRect(0, 0, crisp.width, crisp.height);
217
262
  c2.globalCompositeOperation = 'source-over';
263
+ c2.setTransform(dpr, 0, 0, dpr, 0, 0);
218
264
  }
219
265
  g.cols = Math.ceil(g.w / CELL);
220
266
  g.rows = Math.ceil(g.h / CELL);
@@ -274,10 +320,23 @@ export function pixelGlitch(el, config) {
274
320
  g.visible = entry.isIntersecting;
275
321
  });
276
322
  watcher.observe(el);
277
- document.fonts?.ready.then(paint).catch(() => {});
323
+ // Repaint once the fonts are in, and once the text's own face is (it may load after fonts.ready).
324
+ let stopped = false;
325
+ /** Repaints, unless stopped meanwhile. */
326
+ const repaint = () => {
327
+ if (!stopped) paint();
328
+ };
329
+ document.fonts?.ready.then(repaint).catch(() => {});
330
+ const face = getComputedStyle(el);
331
+ document.fonts
332
+ ?.load(`${face.fontStyle} ${face.fontWeight} ${face.fontSize} ${face.fontFamily}`, el.textContent ?? '')
333
+ .then(repaint)
334
+ .catch(() => {});
278
335
  paint();
279
336
 
280
337
  return () => {
338
+ stopped = true;
339
+ cancelAnimationFrame(pending);
281
340
  document.removeEventListener('pointermove', move);
282
341
  resizer.disconnect();
283
342
  watcher.disconnect();
@@ -15,7 +15,13 @@
15
15
  * a pill reads as a stall). Colour and speed from `--sweep-color` and
16
16
  * `--sweep-speed`. With reduced motion the ring stays, still.
17
17
  *
18
- * From the ArrayPress theme.
18
+ * `sweep-ring--two` sends two lights round, chasing each other half a lap
19
+ * apart. `sweep-ring--inset` lifts the ring over the element's own
20
+ * content (z-index 3, inside its edge), for cards that clip their
21
+ * contents (`overflow: hidden`) and fill themselves with a picture or a
22
+ * canvas that would otherwise cover it.
23
+ *
24
+ * From the ArrayPress theme; the two lights from the Logomarks site.
19
25
  * ───────────────────────────────────────────────────────────────────── */
20
26
 
21
27
  @property --sweep-angle {
@@ -63,6 +69,27 @@
63
69
  --sweep-speed: 1.8s;
64
70
  }
65
71
 
72
+ /* Two lights, half a lap apart, each with a faint lead-in. */
73
+ .sweep-ring--two::after {
74
+ background: conic-gradient(
75
+ from var(--sweep-angle),
76
+ transparent 0%,
77
+ color-mix(in srgb, var(--sweep-color, currentColor) 25%, transparent) 14%,
78
+ var(--sweep-color, currentColor) 24%,
79
+ transparent 30%,
80
+ transparent 50%,
81
+ color-mix(in srgb, var(--sweep-color, currentColor) 25%, transparent) 64%,
82
+ var(--sweep-color, currentColor) 74%,
83
+ transparent 80%
84
+ );
85
+ }
86
+
87
+ /* Inside the edge and over the content, for cards that clip and fill themselves. */
88
+ .sweep-ring--inset::after {
89
+ inset: 0;
90
+ z-index: 3;
91
+ }
92
+
66
93
  @keyframes effect-border-sweep {
67
94
  to {
68
95
  --sweep-angle: 360deg;
@@ -0,0 +1,169 @@
1
+ /* ─────────────────────────────────────────────────────────────────────
2
+ * @arraypress/effects-astro/glitch-text.css
3
+ *
4
+ * A headline that glitches now and then: two coloured copies of it, laid
5
+ * over the real one, flash on for a few frames near the end of each
6
+ * cycle, each sliced to a different band (clip-path) and shifted
7
+ * sideways, while the real text nudges with them. Mostly it sits still.
8
+ * Livelier under the pointer, on the text or a link or button round it.
9
+ *
10
+ * Markup: the real text first, then the two copies, hidden from assistive
11
+ * technology and from focus:
12
+ *
13
+ * <h2 class="glitch-text" style="--glitch-delay: -1.7s">
14
+ * <span>Make it yours</span>
15
+ * <span class="glitch-text-a" aria-hidden="true" inert>Make it yours</span>
16
+ * <span class="glitch-text-b" aria-hidden="true" inert>Make it yours</span>
17
+ * </h2>
18
+ *
19
+ * Set from custom properties: `--glitch-every` (a cycle, default 5s),
20
+ * `--glitch-hover` (a cycle under the pointer, 1.6s), `--glitch-delay`
21
+ * (where in its cycle this one is, so several glitch on their own beats),
22
+ * `--glitch-a` and `--glitch-b` (the copies' colours, pink and blue) and
23
+ * `--glitch-blend` (how they blend: multiply on a light ground, screen on
24
+ * a dark one). With reduced motion it is the plain text, still.
25
+ *
26
+ * CSS only. From the Logomarks site's Custom card.
27
+ * ───────────────────────────────────────────────────────────────────── */
28
+
29
+ .glitch-text {
30
+ position: relative;
31
+ display: block;
32
+ }
33
+
34
+ :is(span, a, em, strong, b, i, small).glitch-text {
35
+ display: inline-block;
36
+ }
37
+
38
+ .glitch-text > * {
39
+ display: block;
40
+ animation: effect-glitch-text-main var(--glitch-every, 5s) steps(1, end) infinite;
41
+ animation-delay: var(--glitch-delay, 0s);
42
+ }
43
+
44
+ .glitch-text > .glitch-text-a,
45
+ .glitch-text > .glitch-text-b {
46
+ position: absolute;
47
+ inset: 0;
48
+ pointer-events: none;
49
+ user-select: none;
50
+ opacity: 0;
51
+ mix-blend-mode: var(--glitch-blend, multiply);
52
+ animation-name: effect-glitch-text-a;
53
+ }
54
+
55
+ .glitch-text > .glitch-text-a,
56
+ .glitch-text > .glitch-text-a * {
57
+ color: var(--glitch-a, #ff3ea5);
58
+ -webkit-text-fill-color: currentColor;
59
+ }
60
+
61
+ .glitch-text > .glitch-text-b,
62
+ .glitch-text > .glitch-text-b * {
63
+ color: var(--glitch-b, #2e4bff);
64
+ -webkit-text-fill-color: currentColor;
65
+ }
66
+
67
+ .glitch-text > .glitch-text-b {
68
+ animation-name: effect-glitch-text-b;
69
+ }
70
+
71
+ .glitch-text:hover > *,
72
+ :is(a, button):is(:hover, :focus-visible) .glitch-text > * {
73
+ animation-duration: var(--glitch-hover, 1.6s);
74
+ }
75
+
76
+ /* Mostly hidden; a burst near the end of each cycle: a few frames of offset slices. */
77
+ @keyframes effect-glitch-text-a {
78
+ 0%,
79
+ 88% {
80
+ opacity: 0;
81
+ clip-path: inset(0 0 100% 0);
82
+ transform: none;
83
+ }
84
+
85
+ 89% {
86
+ opacity: 1;
87
+ clip-path: inset(12% 0 64% 0);
88
+ transform: translateX(-3px);
89
+ }
90
+
91
+ 91% {
92
+ clip-path: inset(58% 0 22% 0);
93
+ transform: translateX(4px);
94
+ }
95
+
96
+ 93% {
97
+ clip-path: inset(30% 0 48% 0);
98
+ transform: translateX(-2px);
99
+ }
100
+
101
+ 95% {
102
+ clip-path: inset(78% 0 6% 0);
103
+ transform: translateX(2px);
104
+ }
105
+
106
+ 96%,
107
+ 100% {
108
+ opacity: 0;
109
+ clip-path: inset(0 0 100% 0);
110
+ transform: none;
111
+ }
112
+ }
113
+
114
+ /* The second copy a frame behind the first, on other bands. */
115
+ @keyframes effect-glitch-text-b {
116
+ 0%,
117
+ 89% {
118
+ opacity: 0;
119
+ clip-path: inset(0 0 100% 0);
120
+ transform: none;
121
+ }
122
+
123
+ 90% {
124
+ opacity: 1;
125
+ clip-path: inset(44% 0 36% 0);
126
+ transform: translateX(3px);
127
+ }
128
+
129
+ 92% {
130
+ clip-path: inset(6% 0 76% 0);
131
+ transform: translateX(-4px);
132
+ }
133
+
134
+ 94% {
135
+ clip-path: inset(66% 0 14% 0);
136
+ transform: translateX(2px);
137
+ }
138
+
139
+ 96%,
140
+ 100% {
141
+ opacity: 0;
142
+ clip-path: inset(0 0 100% 0);
143
+ transform: none;
144
+ }
145
+ }
146
+
147
+ /* The real text nudges with them. */
148
+ @keyframes effect-glitch-text-main {
149
+ 0%,
150
+ 88.9%,
151
+ 96%,
152
+ 100% {
153
+ transform: none;
154
+ }
155
+
156
+ 89% {
157
+ transform: translateX(1px);
158
+ }
159
+
160
+ 92% {
161
+ transform: translateX(-1px);
162
+ }
163
+ }
164
+
165
+ @media (prefers-reduced-motion: reduce) {
166
+ .glitch-text > * {
167
+ animation: none !important;
168
+ }
169
+ }