@arraypress/effects-astro 0.5.0 → 0.6.1
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 +6 -6
- package/COMPONENTS.md +8 -3
- package/README.md +21 -182
- package/package.json +2 -2
- package/src/components/PixelGlitchText.astro +5 -3
- package/src/components/Scene.astro +3 -3
- package/src/index.d.ts +5 -4
- package/src/index.js +4 -4
- package/src/runtime/canvas2d.d.ts +10 -1
- package/src/runtime/canvas2d.js +44 -9
- package/src/runtime/galaxy.d.ts +22 -7
- package/src/runtime/galaxy.js +169 -71
- package/src/runtime/paper.js +53 -2
- package/src/runtime/pixel-glitch.d.ts +7 -0
- package/src/runtime/pixel-glitch.js +57 -3
- package/src/runtime/random.d.ts +12 -0
- package/src/runtime/random.js +43 -2
- package/src/runtime/scene.d.ts +3 -3
- package/src/runtime/scene.js +5 -5
package/AGENTS.md
CHANGED
|
@@ -17,7 +17,7 @@ Pick by what is asked for:
|
|
|
17
17
|
| Smoke or ink on a light page | `<Ink dark colors={[…]}>` (dark dye alone barely shows) |
|
|
18
18
|
| Panels of colour fanning out of the dark, a bold launch or fintech hero with depth | `<ColorPanels>` (Opening by default; `preset="Glass"`, `"Default"` or `"Gradient"`; `palette` or `colors`, `quiet` behind copy) |
|
|
19
19
|
| A gradient, noise, halftone or liquid-metal look by name | `<PaperShader shader="…" preset="…">`; the demo has a hero for every shader, its presets in the tag |
|
|
20
|
-
| A glossy, glassy or studio-lit background a palette recolours: liquid marble, frosted or ribbed glass, glossy tiles, chrome, glitter, holographic foil, a neon ribbon, pastel spheres or a blob, glass rings or strands, ink in water, topographic lines | `<Scene name="…" palette="…">` (`marble`, `frosted`, `ribs`, `tiles`, `blob`, `chrome`, `glitter`, `foil`, `ribbon`, `spiral`, `swirl`, `arches`, `spheres`, `spheres2`, `strands`, `rings`, `ink-water`, `topo`); `params` reshapes it (`PARAMS[name]` in `@
|
|
20
|
+
| A glossy, glassy or studio-lit background a palette recolours: liquid marble, frosted or ribbed glass, glossy tiles, chrome, glitter, holographic foil, a neon ribbon, pastel spheres or a blob, glass rings or strands, ink in water, topographic lines | `<Scene name="…" palette="…">` (`marble`, `frosted`, `ribs`, `tiles`, `blob`, `chrome`, `glitter`, `foil`, `ribbon`, `spiral`, `swirl`, `arches`, `spheres`, `spheres2`, `strands`, `rings`, `ink-water`, `topo`); `params` reshapes it (`PARAMS[name]` in `@logomarks/shaders` lists each scene's); lazy by default, so a wall of cards can each have one |
|
|
21
21
|
| A themed hero background by name (mesh gradient, grainy gradient, silk, light bands, synthwave grid, neon waves), tinted from the site's accent | `<ShaderBackground effect="…">`; `static` when it sits behind body copy or is `fixed` |
|
|
22
22
|
| A launch, waitlist or coming-soon hero: light around centred copy | `<HaloRing>` |
|
|
23
23
|
| A dark, premium product or smart-home hero: frosted glass lit from within, copy beside it | `<RadiantGlass>` (`side="right"` mirrors it; `layout`, `shape`) |
|
|
@@ -60,7 +60,7 @@ Things that trip people up:
|
|
|
60
60
|
- **Clicks:** effects that react to clicks ignore links, buttons and form fields. Add `data-effect-ignore` to anything else whose clicks are its own.
|
|
61
61
|
- **`<SpotlightText fill="dodge">`** blends with what is behind it: no stacking context may sit between them (no `z-index` on a positioned ancestor, no `opacity`, `transform`, `filter` or `isolation`). Use `fill="solid"` where that cannot be arranged.
|
|
62
62
|
- **Styling a component's element** from the page needs `:global(.its-class)`, since the element belongs to the component.
|
|
63
|
-
- **`<Scene>` takes a palette by name** (`palette="Barbie"`); `@
|
|
63
|
+
- **`<Scene>` takes a palette by name** (`palette="Barbie"`); `@logomarks/shaders` itself takes the palette object (`PALETTES.Barbie`), never the name. Its `lazy` is the scene's own (a context held near the screen, given back four seconds after leaving on a fresh canvas), not `mount()`'s.
|
|
64
64
|
- **`<PaperShader>` needs WebGL 2** and shows `background` without it. Its picture shaders take `image` (same origin, or served with CORS).
|
|
65
65
|
- **Colour presets:** any effect that takes `colors` takes `palette="…"` (`PALETTES`: Lumetri, Forest, Cadmium, Peacock, Vermillion, Barbie, Uranium, Azure, Ruby, Ultramarine, Saffron, Crimson, Ember, Lagoon, Citrus, Glacier, Rosewater, Mono). Reach for a palette before inventing colours, and avoid violet unless the brand is violet.
|
|
66
66
|
- **Changing colours at runtime:** `setColors(el, colors, glint?)` from `@arraypress/effects-astro`.
|
|
@@ -68,7 +68,7 @@ Things that trip people up:
|
|
|
68
68
|
|
|
69
69
|
## Working on this package
|
|
70
70
|
|
|
71
|
-
Plain ES modules in `src/` with hand-written `.d.ts` files beside them: components in `src/components/`, the runtime in `src/runtime/` (one concern a file), stylesheets in `src/styles/`. No build step, and one dependency: `@
|
|
71
|
+
Plain ES modules in `src/` with hand-written `.d.ts` files beside them: components in `src/components/`, the runtime in `src/runtime/` (one concern a file), stylesheets in `src/styles/`. No build step, and one dependency: `@logomarks/shaders` (the owner's own scene shaders, for `<Scene>`). `demo/` is an Astro site (not published): one gallery page of every effect as a working hero, a file of heroes per group in `demo/src/heroes/` (listed in `demo/src/tour/groups.ts`), shown one at a time and filtered by type (`src/scripts/viewer.js`; only the hero on show has its effect stamped in). Each hero's Customise panel is generated from the components' prop docs by `npm run docs`, so every prop needs a doc comment with its default and, for numbers, a range written "0–1".
|
|
72
72
|
|
|
73
73
|
| | |
|
|
74
74
|
|---|---|
|
|
@@ -83,11 +83,11 @@ The shaders and canvases cannot run under Node. After changing an effect, check
|
|
|
83
83
|
### House rules
|
|
84
84
|
|
|
85
85
|
- **A new effect** is a runtime module (`src/runtime/<name>.js` + `.d.ts`, exporting `name(el, config) => stop`), a component (`src/components/<Name>.astro`) and a `<Hero>` for it in its group's file (`demo/src/heroes/<group>.astro`), behind real copy, with the line that makes it in its `code`. Canvas components render `<EffectCanvas name="<name>">` and call `mount('[data-effect-<name>]', fn)`.
|
|
86
|
-
- **Build on the shared parts:** `createStage` for a WebGL effect, `createCanvas2D` for a Canvas one, `animate` for any loop, `pointerIn` / `trail` / `pressAt` for the pointer, `watchColors` for `data-colors`, `drawShape` for logos and text shapes, `GLSL_*` for shader pieces. Each effect keeps the guarantees in
|
|
86
|
+
- **Build on the shared parts:** `createStage` for a WebGL effect, `createCanvas2D` for a Canvas one, `animate` for any loop, `pointerIn` / `trail` / `pressAt` for the pointer, `watchColors` for `data-colors`, `drawShape` for logos and text shapes, `GLSL_*` for shader pieces. Each effect keeps the guarantees in [docs/guarantees.md](docs/guarantees.md).
|
|
87
87
|
- **No repetition.** Anything two effects need goes in its own runtime module and is imported.
|
|
88
88
|
- **JSDoc on every function**, nested ones included: a short description, `@param` for each parameter, `@returns`, `@throws` where it applies. Every prop has a doc comment with its default (COMPONENTS.md is built from them). Keep the `.d.ts` files in step. Plain, concise voice: what a thing does and why.
|
|
89
89
|
- **Colour in Oklab** (`mixOklab`, `paletteAt`, `GLSL_PALETTE`), never mixed in RGB.
|
|
90
|
-
- **No telemetry, no network, no third-party dependencies.** Effects ship inside sites for other people's visitors. The one dependency is `@
|
|
90
|
+
- **No telemetry, no network, no third-party dependencies.** Effects ship inside sites for other people's visitors. The one dependency is `@logomarks/shaders`, the owner's own; a scene's shader belongs there, and `<Scene>` only wraps it.
|
|
91
91
|
- **`src/vendor/paper/` is Paper's code, unchanged but for dropped source-map comments** (Apache-2.0). Update it by re-vendoring a release and regenerating `presets.js`; never edit it by hand.
|
|
92
|
-
- **Credit what is adapted**, in the module's header,
|
|
92
|
+
- **Credit what is adapted**, in the module's header, [docs/credits.md](docs/credits.md) and LICENSE, and only from MIT-compatible sources. shaders.com's open-source components (MIT) may be adapted; its presets and sections are licensed content and may not be copied, even modified.
|
|
93
93
|
- **Every change goes in CHANGELOG.md** (Keep a Changelog, SemVer). Commit and push only with the owner's go-ahead; the owner publishes to npm.
|
package/COMPONENTS.md
CHANGED
|
@@ -243,6 +243,9 @@ Galaxy: deep space in your colours. Soft nebula clouds with dark dust lanes, fin
|
|
|
243
243
|
| `stars` | `number` | How many stars, as a share of the usual, 0–3; 0 for none. Default 1. |
|
|
244
244
|
| `glitter` | `number` | How bright the fine glitter is, as a share of the usual, 0–2; 0 for none. Default 1. |
|
|
245
245
|
| `seed` | `number` | Which sky, 1–999: the same seed draws the same nebula and stars. Default 7. |
|
|
246
|
+
| `starSeed` | `number` | The glitter and stars' own seed. Default `seed × 31 + 1`. |
|
|
247
|
+
| `rng` | `RandomName` | The generator. `mulberry32` scatters the glitter and stars afresh from `starSeed` on each resize; `park-miller` (the Logomarks studio's first galaxy) scatters them from one stream that runs on across resizes. With `seed: 7`, `starSeed: 31` and `blend: 'srgb'`, `park-miller` draws that sky to the pixel. Default `mulberry32`. |
|
|
248
|
+
| `blend` | `'oklab' \| 'srgb'` | How the ramp blends its colours: in Oklab, or plainly in sRGB (painted exactly along its stops, the first colour's bytes × 0.18 for its near-black). Default `oklab`. |
|
|
246
249
|
| `lazy` | `boolean \| string` | Run only while near the screen (true, or a CSS length; default `200px`), handled by `mount`. Default false. |
|
|
247
250
|
| `background` | `string` | What shows before it draws. Default `#05040d`. |
|
|
248
251
|
| `fixed` | `boolean` | Fill the viewport, behind the page (position: fixed, z-index -1). Default false. |
|
|
@@ -846,7 +849,7 @@ ParticleLogo: a logo or a word in thousands of twinkling particles that scatter
|
|
|
846
849
|
|
|
847
850
|
## `<PixelGlitchText>`
|
|
848
851
|
|
|
849
|
-
PixelGlitchText: one line of text that breaks into pixels under the pointer and knits back together behind it. With `stroke`, a hollow outline at rest that the pixels fill in. See src/runtime/pixel-glitch.js.
|
|
852
|
+
PixelGlitchText: one line of text that breaks into pixels under the pointer and knits back together behind it. With `stroke`, a hollow outline at rest that the pixels fill in; `tear="row"` tears whole rows, and `ghost` lays a coloured copy behind the blocks. See src/runtime/pixel-glitch.js.
|
|
850
853
|
|
|
851
854
|
```astro
|
|
852
855
|
<footer>
|
|
@@ -862,6 +865,8 @@ PixelGlitchText: one line of text that breaks into pixels under the pointer and
|
|
|
862
865
|
| `block` | `number` | The pixel block size at full heat, CSS px. Default 22. |
|
|
863
866
|
| `shift` | `number` | How far the hottest rows slip sideways, CSS px. Default 16. |
|
|
864
867
|
| `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). |
|
|
868
|
+
| `tear` | `'cell' \| 'row'` | What slips: `cell`, each hot cell on its own; `row`, a whole row at once, now and then, by its hottest cell (up to half of `shift` either way). Default `cell`. |
|
|
869
|
+
| `ghost` | `string` | A colour for a copy of the blocks, nudged 3px right behind them (an accent under the break). Default none. |
|
|
865
870
|
| `as` | `HTMLTag` | The element to render. Default `span`. |
|
|
866
871
|
| `fit` | `boolean` | Size the text to span its parent's width. Default false. |
|
|
867
872
|
| `class` | `string` | Classes for the element. |
|
|
@@ -1015,7 +1020,7 @@ Reveal: content that rises, slides, zooms or un-blurs into place as it scrolls i
|
|
|
1015
1020
|
|
|
1016
1021
|
## `<Scene>`
|
|
1017
1022
|
|
|
1018
|
-
Scene: one of the scenes from `@
|
|
1023
|
+
Scene: one of the scenes from `@logomarks/shaders` as a background: liquid marble, frosted glass, ribbed light, glossy tiles, a pastel blob, chrome liquid, a glitter galaxy, holographic foil, a neon ribbon, spiral trails, a glass swirl, arches, pastel spheres, glass strands, glass rings, ink in water and topographic lines. Any palette recolours it, and its own settings (`params`) reshape it. See src/runtime/scene.js.
|
|
1019
1024
|
|
|
1020
1025
|
```astro
|
|
1021
1026
|
<Scene name="marble" palette="Barbie" params={{ scale: 1.2 }} />
|
|
@@ -1029,7 +1034,7 @@ Scene: one of the scenes from `@arraypress/shaders` as a background: liquid marb
|
|
|
1029
1034
|
| `palette` | `PaletteName` | A named palette (PALETTES): its three colours and its glint. Default the scene's own colours. |
|
|
1030
1035
|
| `colors` | `string[]` | One to three colours (hex), over the palette's. Default the palette's, or the scene's own. |
|
|
1031
1036
|
| `glint` | `string` | The highlight colour (hex), over the palette's. Default the palette's, or the scene's own. |
|
|
1032
|
-
| `params` | `Record<string, number>` | The scene's own settings by key (`PARAMS[name]` in `@
|
|
1037
|
+
| `params` | `Record<string, number>` | The scene's own settings by key (`PARAMS[name]` in `@logomarks/shaders`; marble takes `scale`, `sharpness`, `warp` and `relief`). Default the scene's. |
|
|
1033
1038
|
| `speed` | `number` | How fast it moves, 0–3 (0 still). Default 1. |
|
|
1034
1039
|
| `hue` | `number` | Hue turned round the colour wheel, -180–180 degrees. Default 0. |
|
|
1035
1040
|
| `sat` | `number` | Saturation, 0–2 (0 grey). Default 1. |
|
package/README.md
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
# @arraypress/effects-astro
|
|
2
2
|
|
|
3
|
-
Effects for Astro sites, as components: shader backgrounds, a real fluid, logos made of glass, particles or cubes, text that glitches, scrambles or types itself, glass panels and marquees
|
|
4
|
-
|
|
5
|
-
```astro
|
|
6
|
-
---
|
|
7
|
-
import LightField from '@arraypress/effects-astro/LightField.astro';
|
|
8
|
-
---
|
|
9
|
-
<LightField fixed colors={['#7c3aed', '#db2777', '#06b6d4']} />
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
Every prop of every component is in **[COMPONENTS.md](COMPONENTS.md)**, generated from the components' own types.
|
|
3
|
+
Effects for Astro sites, as components: shader backgrounds, a real fluid, logos made of glass, particles or cubes, text that glitches, scrambles or types itself, glass panels and marquees. Plain WebGL, Canvas and CSS with no third-party dependencies, and the fallbacks a theme needs built in.
|
|
13
4
|
|
|
14
5
|
## Install
|
|
15
6
|
|
|
@@ -19,185 +10,33 @@ npm install @arraypress/effects-astro
|
|
|
19
10
|
|
|
20
11
|
Astro 6 or 7. The runtime underneath (`@arraypress/effects-astro`) works without Astro.
|
|
21
12
|
|
|
22
|
-
##
|
|
23
|
-
|
|
24
|
-
- **Runs only when it is seen.** One animation loop for the page; an effect draws only while it is within 128px of the viewport and the tab is showing.
|
|
25
|
-
- **Draws at what the device can afford.** The pixel ratio is capped at 2 on a desktop and 1.5 on a phone or tablet, and heavier passes (the light's prism split) are dropped on phones.
|
|
26
|
-
- **Respects reduced motion.** Every effect has a still state: one frame, a static date, the text simply there.
|
|
27
|
-
- **Has a fallback.** No WebGL: a still gradient, or the element's background. No hovering pointer: nothing waits for a hover.
|
|
28
|
-
- **Keeps content readable.** Effects are decoration (`aria-hidden`); real text stays in the page for screen readers and search; moving content has a pause button where it runs on.
|
|
29
|
-
- **Survives view transitions.** Effects start on `astro:page-load` and stop when their element leaves the page.
|
|
30
|
-
- **Mixes colour in Oklab**, so palettes blend without muddy midpoints.
|
|
31
|
-
- **Sends nothing anywhere.** No telemetry, no network.
|
|
32
|
-
|
|
33
|
-
## The effects
|
|
34
|
-
|
|
35
|
-
**Backgrounds** (fill their section, or the page with `fixed`)
|
|
36
|
-
|
|
37
|
-
| Component | | Drawn with |
|
|
38
|
-
|---|---|---|
|
|
39
|
-
| `<LightField>` | Liquid light in three colours with caustic glints and a pointer lens, over a real fluid that the pointer stirs and a click drops ink into | WebGL |
|
|
40
|
-
| `<Ink>` | The fluid on its own: ink in water over whatever is behind | WebGL 2 |
|
|
41
|
-
| `<InkField>` | Ink in water, lit by a lamp that follows the pointer: slow emitters keep it moving, the pointer stirs it, twelve named palettes (`palette="Peacock"`) that a palette switcher recolours live; with `audio`, the beat stirs it | WebGL |
|
|
42
|
-
| `<AsciiRain>` | Streams of data in text characters, rows sliding at their own pace, a cool cyan-green cast, a lens fringe and the odd glitch (or, with `pattern="waves"`, streaks on a rippling 3D surface) | WebGL |
|
|
43
|
-
| `<FlutedGlass>` | Slanted fluted glass bending soft blooms of colour, one following the pointer | WebGL |
|
|
44
|
-
| `<DotGrid>` | A sea of dots with a drifting current; a click sends a ripple across | Canvas |
|
|
45
|
-
| `<SignalLines>` | Waveform lines drawn as light: sharp in front, out of focus and lens-fringed behind, a shimmer where they cross, pulses of light running along them, and the pointer a lens they part round; with `audio`, the waveform of the sound playing | WebGL |
|
|
46
|
-
| `<WaveBars>` | A glowing bar waveform over its reflection, retuning like a meter with peak caps that hold and fall, a playhead that lights the bars it plays, and the pointer scrubbing; with `audio`, the spectrum of the sound playing on the page | WebGL |
|
|
47
|
-
| `<DotSurface>` | A halftone sea: dots on a slowly rolling sheet in perspective, sized and lit by the light; the pointer raises a swell, a click sends a ring | WebGL |
|
|
48
|
-
| `<ShaderBackground>` | Six shader backgrounds by name (`mesh-gradient`, `grain-gradient`, `silk`, `band-lens`, `grid`, `waves`), tinted from the page's `--color-accent` unless given `colors`; `static` for wallpaper | WebGL |
|
|
49
|
-
| `<HaloRing>` | A ring of light around centred copy: a soft-cornered outline drifting between a hexagon and a rounded rectangle, colour travelling round it and burning white where it is hottest, glowing far outward; the pointer draws it close | WebGL |
|
|
50
|
-
| `<SilkRibbon>` | A wide ribbon of satin twisting across a light ground, folds gathering where it turns and a sheen along each, over a soft glow; the folds undulate and lean to the pointer | WebGL |
|
|
51
|
-
| `<Topography>` | A survey map that never sits still: crisp contour lines of a slowly drifting landscape, every fifth heavier; the pointer lifts the ground and lights its lines, `labels` adds elevation numbers | WebGL |
|
|
52
|
-
| `<Caustics>` | Sunlight rippling through water onto a pool floor: a shifting net of light with a faint rainbow at its edges, stirred by the pointer; optional tiles | WebGL |
|
|
53
|
-
| `<RainOnGlass>` | Rain on a window over a photo: beads, drops running down in clearing trails, each a lens holding the scene upside down, soft bokeh behind fog; the pointer wipes a patch | WebGL |
|
|
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
|
-
| `<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
|
-
| `<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 |
|
|
58
|
-
| `<Scene>` | One of twenty studio-lit scenes from [`@arraypress/shaders`](https://github.com/arraypress/shaders) by `name`: liquid marble, frosted or ribbed glass, glossy tiles, chrome, glitter, holographic foil, a neon ribbon, pastel spheres, glass rings, ink in water, oil bubbles, a melting hologram, topographic lines and more; any `palette` recolours it, `params` reshapes it, lazy by default | WebGL 2 |
|
|
59
|
-
| `<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 |
|
|
60
|
-
| `<GlowField>` | A light to lay over a background: a bloom, a swaying stage spotlight, a horizon or a wash, breathing gently | CSS |
|
|
61
|
-
| `<Grain>` | Flickering film grain, to dither smooth gradients and make a picture read as film | CSS |
|
|
62
|
-
|
|
63
|
-
**Paper shaders**: `<PaperShader shader="mesh-gradient" preset="beach">`, any of the 30 shaders from [Paper](https://shaders.paper.design) with each of their 124 presets, run on the same loop and guarantees as the rest. Pass `params` to change any setting, `colors` for the palette, and `image` for the shaders that work on a picture (your logo in `liquid-metal`, `heatmap` or `gem-smoke`; a photo in `fluted-glass`, `halftone-dots`, `water` or `image-dithering`). The looks worth keeping become backgrounds of their own, with plain props: `<ColorPanels>` so far.
|
|
64
|
-
|
|
65
|
-
`color-panels`, `dithering`, `dot-grid`, `dot-orbit`, `fluted-glass`, `gem-smoke`, `god-rays`, `grain-gradient`, `halftone-cmyk`, `halftone-dots`, `heatmap`, `image-dithering`, `lens-distortion`, `liquid-metal`, `mesh-gradient`, `metaballs`, `neuro-noise`, `paper-texture`, `perlin-noise`, `pulsing-border`, `simplex-noise`, `smoke-ring`, `spiral`, `static-mesh-gradient`, `static-radial-gradient`, `swirl`, `voronoi`, `warp`, `water`, `waves`. The demo shows every preset.
|
|
66
|
-
|
|
67
|
-
**Logos and shapes** (`text` in any font, or `src`: your own SVG or PNG)
|
|
68
|
-
|
|
69
|
-
| Component | | Drawn with |
|
|
70
|
-
|---|---|---|
|
|
71
|
-
| `<GlassGlyph>` | The logo as a thick bevelled slab of glass, swaying slowly in front of fixed beams of coloured light that bend through its rims | WebGL |
|
|
72
|
-
| `<LiquidMetal>` | The logo as liquid chrome in a slowly turning studio: the pointer dents it and sends ripples across it, a stroke parts it, a click splashes it (a crater, a ring wave, droplets that crawl back), and it pulls itself back into shape; `tint` for gold, rose gold, copper or black chrome | WebGL |
|
|
73
|
-
| `<ParticleLogo>` | The logo in thousands of twinkling particles that scatter round the pointer | WebGL |
|
|
74
|
-
| `<NeonSwarm>` | The logo held by a swarm of neon particles that flows like a flock, trails light and scatters from the pointer | WebGL |
|
|
75
|
-
| `<NebulaLogo>` | The logo filled with drifting nebula gas, a glowing rim, a halo past its edge and twinkling stars; the pointer stirs it | WebGL |
|
|
76
|
-
| `<PointCloud>` | A word as a dot matrix among drifting point clouds, optional tracker boxes | WebGL |
|
|
77
|
-
| `<VoxelLogo>` | The logo built of cubes, rocking in 3D, dithered to two inks, optional markers | WebGL |
|
|
78
|
-
|
|
79
|
-
**Text**
|
|
80
|
-
|
|
81
|
-
| Component | | Drawn with |
|
|
82
|
-
|---|---|---|
|
|
83
|
-
| `<SpotlightText>` | An outline a soft light under the pointer fills in | CSS + JS |
|
|
84
|
-
| `<PixelGlitchText>` | Text that breaks into pixels under the pointer | Canvas |
|
|
85
|
-
| `<OutlineWordmark>` | A huge outlined name sinking out of the page, a beam passing through and a light under the pointer filling the letters | CSS + SVG |
|
|
86
|
-
| `<FitText>` | One line sized to span its parent exactly | JS |
|
|
87
|
-
| `<ScrambleText>` | Text resolving out of random characters | JS |
|
|
88
|
-
| `<Typewriter>` | Phrases typed one after another behind a caret | JS |
|
|
89
|
-
| `<Reveal>` | Content, or each word, rising into place on scroll | CSS + JS |
|
|
90
|
-
| `<ScrollReveal>` | Once in a layout: anything with a reveal.css class (`fade-in-up`, `zoom-in`, `flip-left`…) arrives on scroll | CSS + JS |
|
|
91
|
-
| `<HighlightSweep>` | A marker underline sweeping in under a word | CSS |
|
|
92
|
-
| `<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 |
|
|
93
|
-
| `<Marquee>` | An endless strip of names or logos, with a pause button | CSS + JS |
|
|
94
|
-
| `<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 |
|
|
95
|
-
|
|
96
|
-
**Surfaces and interaction**
|
|
97
|
-
|
|
98
|
-
| Component | | Drawn with |
|
|
99
|
-
|---|---|---|
|
|
100
|
-
| `<ImageRipple>` | A hero photo that ripples like water under the pointer: a wake as it moves, a ring where you click, a soft colour split at the wave fronts and light on the crests, then back to the still, sharp photo; a real `<img>` underneath | WebGL |
|
|
101
|
-
| `<ProductStack>` | A store's product covers floating in a 3D fan, stack or carousel arc with depth of field and a glossy sheen; leans to the pointer, fans apart on hover, lifts the cover under it; real, focusable links | CSS + JS |
|
|
102
|
-
| `<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 |
|
|
103
|
-
| `<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 |
|
|
104
|
-
| `<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 |
|
|
105
|
-
| `<BorderSweep>` | A light travelling round an outline (or two chasing each other); `inset` for cards that clip | CSS |
|
|
106
|
-
| `<Tilt>` | A card that leans towards the pointer, with a glare | CSS + JS |
|
|
107
|
-
| `<Parallax>` | Layers that drift with the pointer by depth | CSS + JS |
|
|
108
|
-
| `<Magnetic>` | A button the pointer pulls on | CSS + JS |
|
|
109
|
-
| `<Cursor>` | A dot and a trailing ring that swells over links | CSS + JS |
|
|
110
|
-
| `<PulseMark>` | A small animated mark: LED matrix, turning rings or sonar | SVG + CSS |
|
|
111
|
-
|
|
112
|
-
**Stylesheets**, for elements you render yourself:
|
|
113
|
-
|
|
114
|
-
| Import | Classes |
|
|
115
|
-
|---|---|
|
|
116
|
-
| `@arraypress/effects-astro/glass.css` | `.glass` (call `glassSheen()` once for the sheen) |
|
|
117
|
-
| `@arraypress/effects-astro/border-sweep.css` | `.sweep-ring`, `--always`, `--fast`, `--two`, `--inset` |
|
|
118
|
-
| `@arraypress/effects-astro/glitch-text.css` | `.glitch-text` with its copies `.glitch-text-a` and `.glitch-text-b` (markup in the file) |
|
|
119
|
-
| `@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) |
|
|
120
|
-
| `@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 />`) |
|
|
121
|
-
|
|
122
|
-
## Your own logo
|
|
123
|
-
|
|
124
|
-
The logo effects take `text` (any word, character or emoji, in the font you name with `font`, weight first: `font="900 Anton, sans-serif"`), or `src`: any image URL, an SVG logo or a transparent PNG. Only its shape is used: where it is opaque. `area` places it within the section (`{ x, y, width, height }`, 0–1 from the top left).
|
|
125
|
-
|
|
126
|
-
```astro
|
|
127
|
-
<VoxelLogo src="/logo.svg" cells={36} colors={['#a7f3d0', '#08090a']} />
|
|
128
|
-
<ParticleLogo src="/logo.svg" area={{ x: 0.5, y: 0.1, width: 0.45, height: 0.8 }} />
|
|
129
|
-
<GlassGlyph text="7" font="900 Anton, sans-serif" />
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
## Palettes
|
|
133
|
-
|
|
134
|
-
Every effect that takes `colors` also takes `palette`, one of eighteen named sets: Lumetri, Forest, Cadmium, Peacock, Vermillion, Barbie, Uranium, Azure, Ruby, Ultramarine, Saffron, Crimson, Ember, Lagoon, Citrus, Glacier, Rosewater, Mono (the first twelve are Trirat's, from the LumiThemes ink). An effect's own `colors` win; a palette fills in when there are none, shaped to what the effect takes:
|
|
13
|
+
## Quick start
|
|
135
14
|
|
|
136
15
|
```astro
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
`PALETTES` (from `@arraypress/effects-astro`) is the list, for a site's own palette switcher.
|
|
143
|
-
|
|
144
|
-
## Changing colours
|
|
145
|
-
|
|
146
|
-
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>`, `<Scene>`) 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.
|
|
147
|
-
|
|
148
|
-
```js
|
|
149
|
-
import { setColors } from '@arraypress/effects-astro';
|
|
150
|
-
|
|
151
|
-
setColors(document.querySelector('[data-effect-light-field]'), ['#e11d48', '#f97316', '#7c3aed'], '#fde68a');
|
|
16
|
+
---
|
|
17
|
+
import LightField from '@arraypress/effects-astro/LightField.astro';
|
|
18
|
+
---
|
|
19
|
+
<LightField fixed colors={['#7c3aed', '#db2777', '#06b6d4']} />
|
|
152
20
|
```
|
|
153
21
|
|
|
154
|
-
##
|
|
155
|
-
|
|
156
|
-
The package's main entry is the runtime the components are built on, for use without Astro or to build more: every effect as a function (`lightField(el, config)` and so on: start it on an element, get back a function that stops it), and the parts they share. Each module can also be imported on its own, which keeps a page's script small: `import { glassSheen } from '@arraypress/effects-astro/runtime/glass-sheen'`.
|
|
157
|
-
|
|
158
|
-
| Export | |
|
|
159
|
-
|---|---|
|
|
160
|
-
| `paperShader(el, config)`, `paperSettings`, `paperUniforms` | Paper's shaders, and the settings and uniforms for a shader and preset |
|
|
161
|
-
| `scene(el, config)`, `sceneSettings` | `<Scene>`: an `@arraypress/shaders` scene on an element's canvas, and its props as that package's options |
|
|
162
|
-
| `paperLook(el, config)`, `paperLookSettings`, `PAPER_LOOKS` | The Paper looks (`<ColorPanels>`…): a look's plain props as a Paper shader's settings, and the looks by name |
|
|
163
|
-
| `createStage(el, options)` | A full-canvas WebGL effect: context, program, sizing, the loop, reduced motion, clean-up |
|
|
164
|
-
| `createCanvas2D(el, options)`, `grainPattern`, `grainOnto` | The same for Canvas 2D effects, and grain laid onto strokes only |
|
|
165
|
-
| `createFluid(gl, options)`, `stir(fluid, el, options)` | A Stable Fluids solve, and its pointer hookup |
|
|
166
|
-
| `createPoints(gl, vertex)`, `projectPoint`, `GLSL_PROJECT` | Particles as soft points, with a 3D projection matched in JavaScript |
|
|
167
|
-
| `drawShape`, `samplePoints`, `gridPoints`, `distanceField`, `blurField`, `fontAt` | Shapes from text or images, and what effects take from them |
|
|
168
|
-
| `createGlyphs`, `GLYPH_SETS`, `GLSL_GLYPHS` | Text characters as a texture, for ASCII effects |
|
|
169
|
-
| `createTrackers(el, count)` | Machine-vision tracker boxes over an effect |
|
|
170
|
-
| `parseColor`, `toHex`, `toOklab`, `fromOklab`, `mixOklab`, `paletteAt`, `GLSL_OKLAB`, `GLSL_PALETTE`, `GLSL_NOISE`, `GLSL_QUIET` | Colour in Oklab and shared shader pieces |
|
|
171
|
-
| `isLand(lat, lon)`, `LAND`, `CITIES` | Where the land is (Natural Earth, 1.5°), and cities by name |
|
|
172
|
-
| `inView(el, show)` | A callback as an element scrolls into view |
|
|
173
|
-
| `scrollReveal(config)`, `REVEAL_CLASSES` | Class-based scroll reveal for a whole page |
|
|
174
|
-
| `animate(el, frame)` | A frame callback on the page's one loop, while `el` is near the screen |
|
|
175
|
-
| `pointerIn`, `trail`, `pressAt`, `CLICK_IGNORE` | The pointer over an element, its strokes, and presses |
|
|
176
|
-
| `pixelRatio`, `isMobileGpu`, `prefersReducedMotion`, `canHover` | The device checks every effect makes |
|
|
177
|
-
| `mount(selector, setup)`, `readConfig`, `watchColors` | Start an effect on every matching element, now and after each view transition |
|
|
178
|
-
|
|
179
|
-
## Demo
|
|
180
|
-
|
|
181
|
-
`demo/` is live at [effects.lumithemes.com](https://effects.lumithemes.com). It is an Astro site: one gallery of every effect as a working hero, each ShaderBackground and Paper shader on its own, shown one at a time with its own URL (`/#liquid-metal`), filters by type (backgrounds, logos, wordmarks, text, surfaces; `/?type=logos`), arrows and ← → keys to step through them, and a Customise panel to set each one up and copy the line:
|
|
182
|
-
|
|
183
|
-
```bash
|
|
184
|
-
cd demo && npm install && npm run dev # http://127.0.0.1:4400
|
|
185
|
-
```
|
|
22
|
+
## What's in it
|
|
186
23
|
|
|
187
|
-
|
|
24
|
+
- [The effects](https://github.com/arraypress/effects-astro/blob/main/docs/effects.md): backgrounds, Paper shaders, logos, text, surfaces and stylesheets
|
|
25
|
+
- [Every prop](https://github.com/arraypress/effects-astro/blob/main/COMPONENTS.md), generated from the components' types
|
|
26
|
+
- [What every effect does for you](https://github.com/arraypress/effects-astro/blob/main/docs/guarantees.md): runs only when seen, reduced motion, fallbacks
|
|
27
|
+
- [Your own logo](https://github.com/arraypress/effects-astro/blob/main/docs/logos.md)
|
|
28
|
+
- [Palettes and colours](https://github.com/arraypress/effects-astro/blob/main/docs/colours.md)
|
|
29
|
+
- [Runtime](https://github.com/arraypress/effects-astro/blob/main/docs/runtime.md): the effects without Astro
|
|
30
|
+
- [Credits](https://github.com/arraypress/effects-astro/blob/main/docs/credits.md)
|
|
188
31
|
|
|
189
|
-
|
|
190
|
-
- `<FlutedGlass>`'s flute geometry and `<GlassGlyph>`'s lens model are adapted from the FlutedGlass and Glass components of [Shaders](https://github.com/shader-effects-inc/shaders) (MIT, © 2026 Shader Effects Inc.).
|
|
191
|
-
- `<ShaderBackground>` is the shader set from the earlier `@arraypress/effect-canvas-astro` package; `silk` follows Inigo Quilez's domain-warping technique; `grain-gradient` dithers along its colour ramp as Paper's grain gradient does, with Dave Hoskins' [Hash without Sine](https://www.shadertoy.com/view/4djSRW) (MIT, © 2014 David Hoskins).
|
|
192
|
-
- `<PaperShader>` and the Paper looks (`<ColorPanels>`) run [Paper Shaders](https://github.com/paper-design/shaders) (Apache-2.0, © 2026 Paper), vendored unchanged in `src/vendor/paper/` with their presets. Powered by Paper Shaders: https://shaders.paper.design
|
|
193
|
-
- `<InkField>` is adapted from Trirat's ink shader for LumiThemes (its sim, display shader, emitters, lamp and twelve palettes), on Jos Stam's Stable Fluids in the shape of Pavel Dobryakov's WebGL-Fluid-Simulation (MIT, © 2017 Pavel Dobryakov).
|
|
194
|
-
- `<WorldRoutes>`'s land is sampled from [Natural Earth](https://www.naturalearthdata.com)'s 1:110m land (public domain).
|
|
195
|
-
- `<Ocean>`'s and `<LiquidMetal>`'s tone curve is Krzysztof Narkowicz's ACES fit.
|
|
196
|
-
- `<Glass refract>`'s lens (an SDF displacement map with a specular channel, fed to `feDisplacementMap` through `backdrop-filter`, and a three-pass RGB split) is adapted from Sam Asante's [liquid-glass](https://github.com/samasante/liquid-glass) (MIT, © 2026 Sam Asante).
|
|
197
|
-
- Oklab is Björn Ottosson's.
|
|
32
|
+
## Links
|
|
198
33
|
|
|
199
|
-
|
|
34
|
+
- [Demo](https://effects.lumithemes.com)
|
|
35
|
+
- [Docs](https://github.com/arraypress/effects-astro/tree/main/docs)
|
|
36
|
+
- [Changelog](https://github.com/arraypress/effects-astro/blob/main/CHANGELOG.md)
|
|
37
|
+
- [Licence](https://github.com/arraypress/effects-astro/blob/main/LICENSE)
|
|
38
|
+
- [`@arraypress/ui-astro`](https://github.com/LumiThemes/ui-astro) for small UI pieces; [`@arraypress/behaviors-astro`](https://github.com/arraypress/behaviors-astro) for counters and drag-to-scroll
|
|
200
39
|
|
|
201
40
|
## Licence
|
|
202
41
|
|
|
203
|
-
MIT © ArrayPress Limited
|
|
42
|
+
MIT © ArrayPress Limited; author David Sherlock. Third-party notices are in [LICENSE](https://github.com/arraypress/effects-astro/blob/main/LICENSE).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arraypress/effects-astro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
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",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"node": ">=20"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@
|
|
47
|
+
"@logomarks/shaders": "^0.1.1"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"astro": "^6 || ^7"
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* PixelGlitchText: one line of text that breaks into pixels under the
|
|
4
4
|
* pointer and knits back together behind it. With `stroke`, a hollow
|
|
5
|
-
* outline at rest that the pixels fill in
|
|
5
|
+
* outline at rest that the pixels fill in; `tear="row"` tears whole rows,
|
|
6
|
+
* and `ghost` lays a coloured copy behind the blocks. See
|
|
7
|
+
* src/runtime/pixel-glitch.js.
|
|
6
8
|
*
|
|
7
9
|
* With `fit`, the text is sized to span its parent's width (a footer
|
|
8
10
|
* wordmark). Any other attribute is passed to the element.
|
|
@@ -25,13 +27,13 @@ interface Props extends PixelGlitchConfig {
|
|
|
25
27
|
[attribute: string]: unknown;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
const { as: Tag = 'span', fit = false, cell, reach, decay, block, shift, stroke, class: className, style: given, ...attributes } = Astro.props;
|
|
30
|
+
const { as: Tag = 'span', fit = false, cell, reach, decay, block, shift, stroke, tear, ghost, class: className, style: given, ...attributes } = Astro.props;
|
|
29
31
|
---
|
|
30
32
|
|
|
31
33
|
<Tag
|
|
32
34
|
class:list={['effect-pixel-glitch', { 'is-outline': (stroke ?? 0) > 0 }, className]}
|
|
33
35
|
data-effect-pixel-glitch
|
|
34
|
-
data-effect-config={JSON.stringify({ cell, reach, decay, block, shift, stroke })}
|
|
36
|
+
data-effect-config={JSON.stringify({ cell, reach, decay, block, shift, stroke, tear, ghost })}
|
|
35
37
|
data-fit-text={fit ? '' : undefined}
|
|
36
38
|
style={withStyle(stroke ? `--glitch-stroke: ${stroke}px` : undefined, given)}
|
|
37
39
|
{...attributes}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
/**
|
|
3
|
-
* Scene: one of the scenes from `@
|
|
3
|
+
* Scene: one of the scenes from `@logomarks/shaders` as a
|
|
4
4
|
* background: liquid marble, frosted glass, ribbed light, glossy tiles, a
|
|
5
5
|
* pastel blob, chrome liquid, a glitter galaxy, holographic foil, a neon
|
|
6
6
|
* ribbon, spiral trails, a glass swirl, arches, pastel spheres, glass
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* <Scene name="foil" fixed opacity={0.5} />
|
|
23
23
|
*/
|
|
24
24
|
import EffectCanvas from './EffectCanvas.astro';
|
|
25
|
-
import { SCENES, fallback, validateOptions } from '@
|
|
25
|
+
import { SCENES, fallback, validateOptions } from '@logomarks/shaders';
|
|
26
26
|
import { sceneSettings } from '../runtime/scene.js';
|
|
27
27
|
import type { SceneName } from '../runtime/scene.js';
|
|
28
28
|
import type { PaletteName } from '../runtime/palettes.js';
|
|
@@ -36,7 +36,7 @@ interface Props {
|
|
|
36
36
|
colors?: string[];
|
|
37
37
|
/** The highlight colour (hex), over the palette's. Default the palette's, or the scene's own. */
|
|
38
38
|
glint?: string;
|
|
39
|
-
/** The scene's own settings by key (`PARAMS[name]` in `@
|
|
39
|
+
/** The scene's own settings by key (`PARAMS[name]` in `@logomarks/shaders`; marble takes `scale`, `sharpness`, `warp` and `relief`). Default the scene's. */
|
|
40
40
|
params?: Record<string, number>;
|
|
41
41
|
/** How fast it moves, 0–3 (0 still). Default 1. */
|
|
42
42
|
speed?: number;
|
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, outlineAlpha } from './runtime/pixel-glitch.js';
|
|
19
|
+
export { pixelGlitch, outlineAlpha, rowTears } 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,7 +68,7 @@ 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';
|
|
71
|
+
export { galaxy, galaxyRamp, galaxyStops, nebulaField } from './runtime/galaxy.js';
|
|
72
72
|
export type { GalaxyConfig } from './runtime/galaxy.js';
|
|
73
73
|
export { caustics, causticTones } from './runtime/caustics.js';
|
|
74
74
|
export type { CausticsConfig, CausticTones } from './runtime/caustics.js';
|
|
@@ -90,7 +90,7 @@ export { imageRipple, fitScale } from './runtime/image-ripple.js';
|
|
|
90
90
|
export type { ImageRippleConfig } from './runtime/image-ripple.js';
|
|
91
91
|
export { stackPoses, stackBounds, poseTransform, poseFilter, LAYOUTS as STACK_LAYOUTS } from './runtime/stack-poses.js';
|
|
92
92
|
export type { Layout as StackLayout, Pose, PoseState } from './runtime/stack-poses.js';
|
|
93
|
-
export { createCanvas2D, grainPattern, grainOnto } from './runtime/canvas2d.js';
|
|
93
|
+
export { createCanvas2D, claimCanvas, grainPattern, grainOnto } from './runtime/canvas2d.js';
|
|
94
94
|
export type { Canvas2D } from './runtime/canvas2d.js';
|
|
95
95
|
export { loadImage, imageTexture, coverScale, GLSL_COVER } from './runtime/image.js';
|
|
96
96
|
export { boxBlur } from './runtime/blur.js';
|
|
@@ -113,7 +113,8 @@ export { isoCamera, ISO_PITCH } from './runtime/iso-camera.js';
|
|
|
113
113
|
export type { IsoCamera, IsoCameraOptions } from './runtime/iso-camera.js';
|
|
114
114
|
export { instancing } from './runtime/instancing.js';
|
|
115
115
|
export type { Instancing } from './runtime/instancing.js';
|
|
116
|
-
export { seededRandom } from './runtime/random.js';
|
|
116
|
+
export { seededRandom, parkMiller, randomFrom, RANDOMS } from './runtime/random.js';
|
|
117
|
+
export type { RandomName } from './runtime/random.js';
|
|
117
118
|
export { createPingPong, floatFormats } from './runtime/ping-pong.js';
|
|
118
119
|
export type { PingPong, FloatFormat } from './runtime/ping-pong.js';
|
|
119
120
|
export { createHeightField, GLSL_HEIGHT_FIELD, MAX_PUSHES } from './runtime/height-field.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, outlineAlpha } from './runtime/pixel-glitch.js';
|
|
23
|
+
export { pixelGlitch, outlineAlpha, rowTears } 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,7 +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
|
+
export { galaxy, galaxyRamp, galaxyStops, nebulaField } from './runtime/galaxy.js';
|
|
55
55
|
export { caustics, causticTones } from './runtime/caustics.js';
|
|
56
56
|
export { rainOnGlass } from './runtime/rain-on-glass.js';
|
|
57
57
|
export { ocean } from './runtime/ocean.js';
|
|
@@ -62,7 +62,7 @@ export { slideshow } from './runtime/slideshow.js';
|
|
|
62
62
|
export { productStack } from './runtime/product-stack.js';
|
|
63
63
|
export { imageRipple, fitScale } from './runtime/image-ripple.js';
|
|
64
64
|
export { stackPoses, stackBounds, poseTransform, poseFilter, LAYOUTS as STACK_LAYOUTS } from './runtime/stack-poses.js';
|
|
65
|
-
export { createCanvas2D, grainPattern, grainOnto } from './runtime/canvas2d.js';
|
|
65
|
+
export { createCanvas2D, claimCanvas, grainPattern, grainOnto } from './runtime/canvas2d.js';
|
|
66
66
|
export { loadImage, imageTexture, coverScale, GLSL_COVER } from './runtime/image.js';
|
|
67
67
|
export { boxBlur } from './runtime/blur.js';
|
|
68
68
|
export { paperShader, paperSettings, paperUniforms } from './runtime/paper.js';
|
|
@@ -75,7 +75,7 @@ export { createStage } from './runtime/stage.js';
|
|
|
75
75
|
export { createMesh, STRIDE } from './runtime/mesh.js';
|
|
76
76
|
export { isoCamera, ISO_PITCH } from './runtime/iso-camera.js';
|
|
77
77
|
export { instancing } from './runtime/instancing.js';
|
|
78
|
-
export { seededRandom } from './runtime/random.js';
|
|
78
|
+
export { seededRandom, parkMiller, randomFrom, RANDOMS } from './runtime/random.js';
|
|
79
79
|
export { createPingPong, floatFormats } from './runtime/ping-pong.js';
|
|
80
80
|
export { createHeightField, GLSL_HEIGHT_FIELD, MAX_PUSHES } from './runtime/height-field.js';
|
|
81
81
|
export { createPoints, projectPoint, GLSL_PROJECT } from './runtime/points.js';
|
|
@@ -6,11 +6,20 @@ export interface Canvas2D {
|
|
|
6
6
|
/** The element's size, CSS px. */
|
|
7
7
|
width: number;
|
|
8
8
|
height: number;
|
|
9
|
+
/** The canvas's pixels per CSS px (the device's, up to 2). */
|
|
10
|
+
dpr: number;
|
|
9
11
|
/** True with prefers-reduced-motion. */
|
|
10
12
|
still: boolean;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* The element's canvas, ready for 2D drawing: its first canvas, or a fresh one in its place (with its attributes)
|
|
17
|
+
* when that one is already claimed for WebGL, or a fresh one added when it has none. `release` puts the element's
|
|
18
|
+
* own canvas back (or takes the added one out).
|
|
19
|
+
*/
|
|
20
|
+
export function claimCanvas(el: HTMLElement): { canvas: HTMLCanvasElement; ctx: CanvasRenderingContext2D | null; release(): void };
|
|
21
|
+
|
|
22
|
+
/** Starts a Canvas 2D effect in `el`'s canvas (or one in its place: see claimCanvas): sized, looped while near the screen, still with reduced motion. */
|
|
14
23
|
export function createCanvas2D(
|
|
15
24
|
el: HTMLElement,
|
|
16
25
|
options: { draw(c: Canvas2D, now: number, dt: number): void; resize?(c: Canvas2D): void },
|
package/src/runtime/canvas2d.js
CHANGED
|
@@ -6,6 +6,12 @@
|
|
|
6
6
|
* frames from the page's one loop while it is near the screen, one still
|
|
7
7
|
* frame with prefers-reduced-motion (redrawn on resize), and a grain tile
|
|
8
8
|
* for texturing strokes.
|
|
9
|
+
*
|
|
10
|
+
* A canvas holds one kind of context for life, so when the element's
|
|
11
|
+
* canvas has already been claimed for WebGL (a host that makes one canvas
|
|
12
|
+
* for whichever effect it shows), a fresh canvas takes its place, with
|
|
13
|
+
* its attributes, and the host's goes back when the effect stops. An
|
|
14
|
+
* element with no canvas gets one.
|
|
9
15
|
*/
|
|
10
16
|
|
|
11
17
|
import { prefersReducedMotion } from './device.js';
|
|
@@ -17,11 +23,37 @@ import { animate } from './loop.js';
|
|
|
17
23
|
* @property {HTMLCanvasElement} canvas The canvas.
|
|
18
24
|
* @property {number} width The element's width, CSS px.
|
|
19
25
|
* @property {number} height The element's height, CSS px.
|
|
26
|
+
* @property {number} dpr The canvas's pixels per CSS px (the device's, up to 2).
|
|
20
27
|
* @property {boolean} still True with prefers-reduced-motion.
|
|
21
28
|
*/
|
|
22
29
|
|
|
23
30
|
/**
|
|
24
|
-
*
|
|
31
|
+
* The element's canvas, ready for 2D drawing: its first canvas, or a
|
|
32
|
+
* fresh one in its place when that one is already claimed for another
|
|
33
|
+
* kind of context (WebGL), or a fresh one added when it has none.
|
|
34
|
+
*
|
|
35
|
+
* @param {HTMLElement} el The element.
|
|
36
|
+
* @returns {{ canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D | null, release: () => void }} The canvas, its context and a function that puts the element's own canvas back.
|
|
37
|
+
*/
|
|
38
|
+
export function claimCanvas(el) {
|
|
39
|
+
const found = el.querySelector('canvas');
|
|
40
|
+
const ctx = found?.getContext('2d', { alpha: true });
|
|
41
|
+
if (found && ctx) return { canvas: found, ctx, release: () => {} };
|
|
42
|
+
const canvas = document.createElement('canvas');
|
|
43
|
+
if (found) {
|
|
44
|
+
for (const { name, value } of found.attributes) canvas.setAttribute(name, value);
|
|
45
|
+
found.replaceWith(canvas);
|
|
46
|
+
} else el.append(canvas);
|
|
47
|
+
return {
|
|
48
|
+
canvas,
|
|
49
|
+
ctx: canvas.getContext('2d', { alpha: true }),
|
|
50
|
+
release: () => (found ? canvas.replaceWith(found) : canvas.remove()),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Starts a Canvas 2D effect on an element (its first canvas is drawn into,
|
|
56
|
+
* or one in its place: see claimCanvas).
|
|
25
57
|
*
|
|
26
58
|
* @param {HTMLElement} el The element.
|
|
27
59
|
* @param {object} options The effect.
|
|
@@ -30,20 +62,22 @@ import { animate } from './loop.js';
|
|
|
30
62
|
* @returns {{ c: Canvas2D | null, stop: () => void }} The canvas (null without a 2D context) and a function that stops it.
|
|
31
63
|
*/
|
|
32
64
|
export function createCanvas2D(el, options) {
|
|
33
|
-
const canvas = el
|
|
34
|
-
|
|
35
|
-
|
|
65
|
+
const { canvas, ctx, release } = claimCanvas(el);
|
|
66
|
+
if (!ctx) {
|
|
67
|
+
release();
|
|
68
|
+
return { c: null, stop: () => {} };
|
|
69
|
+
}
|
|
36
70
|
/** @type {Canvas2D} */
|
|
37
|
-
const c = { ctx, canvas, width: 0, height: 0, still: prefersReducedMotion() };
|
|
71
|
+
const c = { ctx, canvas, width: 0, height: 0, dpr: 1, still: prefersReducedMotion() };
|
|
38
72
|
|
|
39
73
|
/** Sizes the canvas to the element. */
|
|
40
74
|
const size = () => {
|
|
41
|
-
|
|
75
|
+
c.dpr = Math.min(window.devicePixelRatio || 1, 2);
|
|
42
76
|
c.width = Math.max(1, el.clientWidth);
|
|
43
77
|
c.height = Math.max(1, el.clientHeight);
|
|
44
|
-
canvas.width = Math.floor(c.width * dpr);
|
|
45
|
-
canvas.height = Math.floor(c.height * dpr);
|
|
46
|
-
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
78
|
+
canvas.width = Math.floor(c.width * c.dpr);
|
|
79
|
+
canvas.height = Math.floor(c.height * c.dpr);
|
|
80
|
+
ctx.setTransform(c.dpr, 0, 0, c.dpr, 0, 0);
|
|
47
81
|
options.resize?.(c);
|
|
48
82
|
if (c.still) options.draw(c, performance.now(), 0);
|
|
49
83
|
};
|
|
@@ -56,6 +90,7 @@ export function createCanvas2D(el, options) {
|
|
|
56
90
|
stop: () => {
|
|
57
91
|
stopLoop();
|
|
58
92
|
resizer.disconnect();
|
|
93
|
+
release();
|
|
59
94
|
},
|
|
60
95
|
};
|
|
61
96
|
}
|