@arraypress/effects-astro 0.0.0-stage → 0.1.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 +85 -0
- package/COMPONENTS.md +1264 -0
- package/LICENSE +139 -0
- package/README.md +197 -2
- package/package.json +60 -4
- package/src/components/AsciiRain.astro +36 -0
- package/src/components/BorderSweep.astro +39 -0
- package/src/components/Caustics.astro +39 -0
- package/src/components/ColorPanels.astro +62 -0
- package/src/components/Cursor.astro +97 -0
- package/src/components/DotGrid.astro +34 -0
- package/src/components/DotSurface.astro +35 -0
- package/src/components/EffectCanvas.astro +152 -0
- package/src/components/FitText.astro +35 -0
- package/src/components/FlutedGlass.astro +36 -0
- package/src/components/Glass.astro +69 -0
- package/src/components/GlassGlyph.astro +38 -0
- package/src/components/GlowField.astro +177 -0
- package/src/components/Grain.astro +98 -0
- package/src/components/HaloRing.astro +38 -0
- package/src/components/HighlightSweep.astro +74 -0
- package/src/components/ImageRipple.astro +56 -0
- package/src/components/Ink.astro +37 -0
- package/src/components/InkField.astro +45 -0
- package/src/components/IsoCity.astro +54 -0
- package/src/components/LightField.astro +40 -0
- package/src/components/LiquidMetal.astro +41 -0
- package/src/components/Magnetic.astro +52 -0
- package/src/components/Marquee.astro +216 -0
- package/src/components/MosaicReveal.astro +196 -0
- package/src/components/NebulaLogo.astro +38 -0
- package/src/components/NeonSwarm.astro +38 -0
- package/src/components/Ocean.astro +40 -0
- package/src/components/OutlineWordmark.astro +222 -0
- package/src/components/PaperBackground.astro +40 -0
- package/src/components/PaperShader.astro +55 -0
- package/src/components/Parallax.astro +49 -0
- package/src/components/ParticleLogo.astro +37 -0
- package/src/components/PixelGlitchText.astro +70 -0
- package/src/components/PointCloud.astro +37 -0
- package/src/components/ProductStack.astro +298 -0
- package/src/components/PulseMark.astro +189 -0
- package/src/components/RadiantGlass.astro +38 -0
- package/src/components/RainOnGlass.astro +71 -0
- package/src/components/Reveal.astro +115 -0
- package/src/components/ScrambleText.astro +52 -0
- package/src/components/ScrollReveal.astro +38 -0
- package/src/components/ShaderBackground.astro +55 -0
- package/src/components/SignalLines.astro +41 -0
- package/src/components/SilkRibbon.astro +37 -0
- package/src/components/SpotlightText.astro +131 -0
- package/src/components/Tilt.astro +79 -0
- package/src/components/Topography.astro +38 -0
- package/src/components/Typewriter.astro +66 -0
- package/src/components/VariableType.astro +59 -0
- package/src/components/VoxelLogo.astro +46 -0
- package/src/components/WaveBars.astro +41 -0
- package/src/components/WorldRoutes.astro +41 -0
- package/src/components/style.js +19 -0
- package/src/index.d.ts +143 -0
- package/src/index.js +105 -0
- package/src/runtime/ascii-rain.d.ts +53 -0
- package/src/runtime/ascii-rain.js +355 -0
- package/src/runtime/audio-meter.d.ts +65 -0
- package/src/runtime/audio-meter.js +282 -0
- package/src/runtime/audio.d.ts +26 -0
- package/src/runtime/audio.js +453 -0
- package/src/runtime/blur.d.ts +2 -0
- package/src/runtime/blur.js +56 -0
- package/src/runtime/canvas2d.d.ts +23 -0
- package/src/runtime/canvas2d.js +105 -0
- package/src/runtime/caustics.d.ts +40 -0
- package/src/runtime/caustics.js +286 -0
- package/src/runtime/color.d.ts +33 -0
- package/src/runtime/color.js +213 -0
- package/src/runtime/curl.d.ts +5 -0
- package/src/runtime/curl.js +81 -0
- package/src/runtime/cursor.d.ts +9 -0
- package/src/runtime/cursor.js +80 -0
- package/src/runtime/device.d.ts +14 -0
- package/src/runtime/device.js +73 -0
- package/src/runtime/dot-grid.d.ts +27 -0
- package/src/runtime/dot-grid.js +245 -0
- package/src/runtime/dot-surface.d.ts +46 -0
- package/src/runtime/dot-surface.js +429 -0
- package/src/runtime/feedback.d.ts +18 -0
- package/src/runtime/feedback.js +131 -0
- package/src/runtime/fit-text.d.ts +5 -0
- package/src/runtime/fit-text.js +60 -0
- package/src/runtime/fluid.d.ts +55 -0
- package/src/runtime/fluid.js +504 -0
- package/src/runtime/fluted-glass.d.ts +27 -0
- package/src/runtime/fluted-glass.js +157 -0
- package/src/runtime/gl.d.ts +19 -0
- package/src/runtime/gl.js +104 -0
- package/src/runtime/glass-glyph.d.ts +49 -0
- package/src/runtime/glass-glyph.js +355 -0
- package/src/runtime/glass-sheen.d.ts +2 -0
- package/src/runtime/glass-sheen.js +30 -0
- package/src/runtime/glsl.d.ts +17 -0
- package/src/runtime/glsl.js +78 -0
- package/src/runtime/glyphs.d.ts +22 -0
- package/src/runtime/glyphs.js +107 -0
- package/src/runtime/halo-ring.d.ts +47 -0
- package/src/runtime/halo-ring.js +334 -0
- package/src/runtime/height-field.d.ts +50 -0
- package/src/runtime/height-field.js +176 -0
- package/src/runtime/image-ripple.d.ts +25 -0
- package/src/runtime/image-ripple.js +353 -0
- package/src/runtime/image.d.ts +11 -0
- package/src/runtime/image.js +81 -0
- package/src/runtime/in-view.d.ts +6 -0
- package/src/runtime/in-view.js +36 -0
- package/src/runtime/ink-field/shaders.js +258 -0
- package/src/runtime/ink-field/sim.js +582 -0
- package/src/runtime/ink-field.d.ts +39 -0
- package/src/runtime/ink-field.js +311 -0
- package/src/runtime/ink.d.ts +31 -0
- package/src/runtime/ink.js +109 -0
- package/src/runtime/instancing.d.ts +12 -0
- package/src/runtime/instancing.js +37 -0
- package/src/runtime/iso-camera.d.ts +35 -0
- package/src/runtime/iso-camera.js +85 -0
- package/src/runtime/iso-city/figures.d.ts +30 -0
- package/src/runtime/iso-city/figures.js +136 -0
- package/src/runtime/iso-city/look.d.ts +34 -0
- package/src/runtime/iso-city/look.js +105 -0
- package/src/runtime/iso-city/plan.d.ts +59 -0
- package/src/runtime/iso-city/plan.js +463 -0
- package/src/runtime/iso-city/roads.d.ts +64 -0
- package/src/runtime/iso-city/roads.js +320 -0
- package/src/runtime/iso-city/scene.d.ts +27 -0
- package/src/runtime/iso-city/scene.js +432 -0
- package/src/runtime/iso-city/shaders.d.ts +6 -0
- package/src/runtime/iso-city/shaders.js +233 -0
- package/src/runtime/iso-city/shadows.d.ts +13 -0
- package/src/runtime/iso-city/shadows.js +148 -0
- package/src/runtime/iso-city/traffic.d.ts +80 -0
- package/src/runtime/iso-city/traffic.js +457 -0
- package/src/runtime/iso-city.d.ts +37 -0
- package/src/runtime/iso-city.js +458 -0
- package/src/runtime/lens-map.d.ts +11 -0
- package/src/runtime/lens-map.js +146 -0
- package/src/runtime/light-field.d.ts +29 -0
- package/src/runtime/light-field.js +292 -0
- package/src/runtime/liquid-glass.d.ts +48 -0
- package/src/runtime/liquid-glass.js +423 -0
- package/src/runtime/liquid-metal/beads.js +217 -0
- package/src/runtime/liquid-metal/field.js +88 -0
- package/src/runtime/liquid-metal/look.js +64 -0
- package/src/runtime/liquid-metal/shaders.js +255 -0
- package/src/runtime/liquid-metal/wave.js +53 -0
- package/src/runtime/liquid-metal.d.ts +46 -0
- package/src/runtime/liquid-metal.js +366 -0
- package/src/runtime/loop.d.ts +7 -0
- package/src/runtime/loop.js +112 -0
- package/src/runtime/magnetic.d.ts +9 -0
- package/src/runtime/magnetic.js +46 -0
- package/src/runtime/marquee.d.ts +2 -0
- package/src/runtime/marquee.js +27 -0
- package/src/runtime/mesh.d.ts +30 -0
- package/src/runtime/mesh.js +217 -0
- package/src/runtime/mosaic-reveal.d.ts +34 -0
- package/src/runtime/mosaic-reveal.js +504 -0
- package/src/runtime/motion.d.ts +2 -0
- package/src/runtime/motion.js +21 -0
- package/src/runtime/mount.d.ts +13 -0
- package/src/runtime/mount.js +120 -0
- package/src/runtime/nebula-logo.d.ts +31 -0
- package/src/runtime/nebula-logo.js +282 -0
- package/src/runtime/neon-swarm.d.ts +31 -0
- package/src/runtime/neon-swarm.js +258 -0
- package/src/runtime/ocean/presets.d.ts +54 -0
- package/src/runtime/ocean/presets.js +184 -0
- package/src/runtime/ocean/shader.d.ts +14 -0
- package/src/runtime/ocean/shader.js +389 -0
- package/src/runtime/ocean/view.d.ts +24 -0
- package/src/runtime/ocean/view.js +98 -0
- package/src/runtime/ocean/waves.d.ts +29 -0
- package/src/runtime/ocean/waves.js +119 -0
- package/src/runtime/ocean.d.ts +31 -0
- package/src/runtime/ocean.js +173 -0
- package/src/runtime/palettes.d.ts +37 -0
- package/src/runtime/palettes.js +75 -0
- package/src/runtime/paper-look.d.ts +42 -0
- package/src/runtime/paper-look.js +91 -0
- package/src/runtime/paper-looks.d.ts +17 -0
- package/src/runtime/paper-looks.js +21 -0
- package/src/runtime/paper.d.ts +37 -0
- package/src/runtime/paper.js +285 -0
- package/src/runtime/particle-logo.d.ts +31 -0
- package/src/runtime/particle-logo.js +196 -0
- package/src/runtime/ping-pong.d.ts +43 -0
- package/src/runtime/ping-pong.js +175 -0
- package/src/runtime/pixel-glitch.d.ts +17 -0
- package/src/runtime/pixel-glitch.js +287 -0
- package/src/runtime/point-cloud.d.ts +33 -0
- package/src/runtime/point-cloud.js +287 -0
- package/src/runtime/pointer.d.ts +27 -0
- package/src/runtime/pointer.js +128 -0
- package/src/runtime/points.d.ts +25 -0
- package/src/runtime/points.js +130 -0
- package/src/runtime/pools.d.ts +2 -0
- package/src/runtime/pools.js +25 -0
- package/src/runtime/product-stack.d.ts +24 -0
- package/src/runtime/product-stack.js +210 -0
- package/src/runtime/radiant-glass.d.ts +29 -0
- package/src/runtime/radiant-glass.js +282 -0
- package/src/runtime/rain-on-glass/backdrop.d.ts +22 -0
- package/src/runtime/rain-on-glass/backdrop.js +185 -0
- package/src/runtime/rain-on-glass/shader.d.ts +2 -0
- package/src/runtime/rain-on-glass/shader.js +168 -0
- package/src/runtime/rain-on-glass/wipe.d.ts +16 -0
- package/src/runtime/rain-on-glass/wipe.js +65 -0
- package/src/runtime/rain-on-glass.d.ts +27 -0
- package/src/runtime/rain-on-glass.js +210 -0
- package/src/runtime/ramp.d.ts +2 -0
- package/src/runtime/ramp.js +30 -0
- package/src/runtime/random.d.ts +2 -0
- package/src/runtime/random.js +22 -0
- package/src/runtime/scroll-reveal.d.ts +22 -0
- package/src/runtime/scroll-reveal.js +73 -0
- package/src/runtime/shader-background.d.ts +42 -0
- package/src/runtime/shader-background.js +261 -0
- package/src/runtime/shader-backgrounds/band-lens.js +72 -0
- package/src/runtime/shader-backgrounds/common.js +53 -0
- package/src/runtime/shader-backgrounds/grain-gradient.js +87 -0
- package/src/runtime/shader-backgrounds/grid.js +33 -0
- package/src/runtime/shader-backgrounds/mesh-gradient.js +74 -0
- package/src/runtime/shader-backgrounds/silk.js +57 -0
- package/src/runtime/shader-backgrounds/waves.js +31 -0
- package/src/runtime/shape.d.ts +42 -0
- package/src/runtime/shape.js +313 -0
- package/src/runtime/silk-ribbon.d.ts +23 -0
- package/src/runtime/silk-ribbon.js +206 -0
- package/src/runtime/slideshow.d.ts +27 -0
- package/src/runtime/slideshow.js +234 -0
- package/src/runtime/spotlight.d.ts +9 -0
- package/src/runtime/spotlight.js +97 -0
- package/src/runtime/stack-poses.d.ts +53 -0
- package/src/runtime/stack-poses.js +273 -0
- package/src/runtime/stage.d.ts +47 -0
- package/src/runtime/stage.js +187 -0
- package/src/runtime/swarm.d.ts +49 -0
- package/src/runtime/swarm.js +199 -0
- package/src/runtime/text-motion.d.ts +41 -0
- package/src/runtime/text-motion.js +165 -0
- package/src/runtime/text.d.ts +11 -0
- package/src/runtime/text.js +90 -0
- package/src/runtime/tilt.d.ts +19 -0
- package/src/runtime/tilt.js +116 -0
- package/src/runtime/topography.d.ts +71 -0
- package/src/runtime/topography.js +650 -0
- package/src/runtime/trackers.d.ts +21 -0
- package/src/runtime/trackers.js +76 -0
- package/src/runtime/variable-type.d.ts +43 -0
- package/src/runtime/variable-type.js +358 -0
- package/src/runtime/voxel-logo.d.ts +31 -0
- package/src/runtime/voxel-logo.js +237 -0
- package/src/runtime/waves.d.ts +70 -0
- package/src/runtime/waves.js +799 -0
- package/src/runtime/world-labels.d.ts +29 -0
- package/src/runtime/world-labels.js +59 -0
- package/src/runtime/world-land.d.ts +8 -0
- package/src/runtime/world-land.js +105 -0
- package/src/runtime/world-map.d.ts +69 -0
- package/src/runtime/world-map.js +308 -0
- package/src/runtime/world-plan.d.ts +101 -0
- package/src/runtime/world-plan.js +333 -0
- package/src/runtime/world-routes.d.ts +75 -0
- package/src/runtime/world-routes.js +673 -0
- package/src/styles/border-sweep.css +82 -0
- package/src/styles/glass.css +104 -0
- package/src/styles/motion.css +218 -0
- package/src/styles/reveal.css +51 -0
- package/src/vendor/paper/LICENSE +201 -0
- package/src/vendor/paper/NOTICE +5 -0
- package/src/vendor/paper/README.md +8 -0
- package/src/vendor/paper/get-shader-color-from-string.js +100 -0
- package/src/vendor/paper/get-shader-noise-texture.js +17 -0
- package/src/vendor/paper/presets.js +3678 -0
- package/src/vendor/paper/shader-sizing.js +37 -0
- package/src/vendor/paper/shader-utils.js +130 -0
- package/src/vendor/paper/shaders/color-panels.js +223 -0
- package/src/vendor/paper/shaders/dithering.js +270 -0
- package/src/vendor/paper/shaders/dot-grid.js +109 -0
- package/src/vendor/paper/shaders/dot-orbit.js +122 -0
- package/src/vendor/paper/shaders/fluted-glass.js +360 -0
- package/src/vendor/paper/shaders/gem-smoke.js +572 -0
- package/src/vendor/paper/shaders/god-rays.js +132 -0
- package/src/vendor/paper/shaders/grain-gradient.js +300 -0
- package/src/vendor/paper/shaders/halftone-cmyk.js +294 -0
- package/src/vendor/paper/shaders/halftone-dots.js +320 -0
- package/src/vendor/paper/shaders/heatmap.js +383 -0
- package/src/vendor/paper/shaders/image-dithering.js +198 -0
- package/src/vendor/paper/shaders/lens-distortion.js +275 -0
- package/src/vendor/paper/shaders/liquid-metal.js +632 -0
- package/src/vendor/paper/shaders/mesh-gradient.js +130 -0
- package/src/vendor/paper/shaders/metaballs.js +110 -0
- package/src/vendor/paper/shaders/neuro-noise.js +76 -0
- package/src/vendor/paper/shaders/paper-texture.js +526 -0
- package/src/vendor/paper/shaders/perlin-noise.js +166 -0
- package/src/vendor/paper/shaders/pulsing-border.js +238 -0
- package/src/vendor/paper/shaders/simplex-noise.js +91 -0
- package/src/vendor/paper/shaders/smoke-ring.js +132 -0
- package/src/vendor/paper/shaders/spiral.js +82 -0
- package/src/vendor/paper/shaders/static-mesh-gradient.js +130 -0
- package/src/vendor/paper/shaders/static-radial-gradient.js +187 -0
- package/src/vendor/paper/shaders/swirl.js +103 -0
- package/src/vendor/paper/shaders/voronoi.js +138 -0
- package/src/vendor/paper/shaders/warp.js +129 -0
- package/src/vendor/paper/shaders/water.js +121 -0
- package/src/vendor/paper/shaders/waves.js +65 -0
- package/src/vendor/paper/vertex-shader.js +159 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/cursor
|
|
3
|
+
*
|
|
4
|
+
* A custom cursor: a small dot exactly at the pointer and a ring that
|
|
5
|
+
* trails it, easing behind. Over links and buttons (and anything with
|
|
6
|
+
* `data-cursor`) the ring swells, and it shows that element's
|
|
7
|
+
* `data-cursor` text as a label ("View", "Play"). The system cursor stays
|
|
8
|
+
* (hiding it costs people their bearings); the dot and ring add to it.
|
|
9
|
+
* Only with a hovering pointer, and still (no trailing) with reduced
|
|
10
|
+
* motion.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { canHover, prefersReducedMotion } from './device.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {object} CursorConfig
|
|
17
|
+
* @property {number} [ease=0.18] How quickly the ring catches up, 0–1 (1 is no trail).
|
|
18
|
+
* @property {string} [targets='a, button, [data-cursor]'] What makes the ring swell.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Starts the cursor.
|
|
23
|
+
*
|
|
24
|
+
* @param {HTMLElement} el The cursor's element (holds `.dot`, `.ring` and `.label`).
|
|
25
|
+
* @param {CursorConfig} config The settings.
|
|
26
|
+
* @returns {() => void} Stops it.
|
|
27
|
+
*/
|
|
28
|
+
export function cursor(el, config) {
|
|
29
|
+
if (!canHover()) {
|
|
30
|
+
el.remove();
|
|
31
|
+
return () => {};
|
|
32
|
+
}
|
|
33
|
+
const ease = prefersReducedMotion() ? 1 : config.ease ?? 0.18;
|
|
34
|
+
const targets = config.targets ?? 'a, button, [data-cursor]';
|
|
35
|
+
const dot = el.querySelector('.dot');
|
|
36
|
+
const ring = el.querySelector('.ring');
|
|
37
|
+
const label = el.querySelector('.label');
|
|
38
|
+
if (!(dot instanceof HTMLElement) || !(ring instanceof HTMLElement)) return () => {};
|
|
39
|
+
const at = { x: -100, y: -100 };
|
|
40
|
+
const trail = { x: -100, y: -100 };
|
|
41
|
+
let raf = 0;
|
|
42
|
+
|
|
43
|
+
/** Moves the ring a step closer to the pointer; carries on until it is there. */
|
|
44
|
+
const tick = () => {
|
|
45
|
+
trail.x += (at.x - trail.x) * ease;
|
|
46
|
+
trail.y += (at.y - trail.y) * ease;
|
|
47
|
+
ring.style.translate = `${trail.x}px ${trail.y}px`;
|
|
48
|
+
raf = Math.abs(at.x - trail.x) + Math.abs(at.y - trail.y) > 0.3 ? requestAnimationFrame(tick) : 0;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** @param {PointerEvent} e The pointer's move. */
|
|
52
|
+
const move = (e) => {
|
|
53
|
+
at.x = e.clientX;
|
|
54
|
+
at.y = e.clientY;
|
|
55
|
+
dot.style.translate = `${at.x}px ${at.y}px`;
|
|
56
|
+
el.classList.add('is-active');
|
|
57
|
+
const over = /** @type {Element | null} */ (e.target)?.closest?.(targets);
|
|
58
|
+
el.classList.toggle('is-over', !!over);
|
|
59
|
+
if (label) label.textContent = over instanceof HTMLElement ? over.dataset.cursor ?? '' : '';
|
|
60
|
+
raf ||= requestAnimationFrame(tick);
|
|
61
|
+
};
|
|
62
|
+
/** The pointer left the window: hide. */
|
|
63
|
+
const leave = () => el.classList.remove('is-active');
|
|
64
|
+
/** Pressed: the ring tightens. */
|
|
65
|
+
const down = () => el.classList.add('is-down');
|
|
66
|
+
/** Let go. */
|
|
67
|
+
const up = () => el.classList.remove('is-down');
|
|
68
|
+
|
|
69
|
+
document.addEventListener('pointermove', move, { passive: true });
|
|
70
|
+
document.documentElement.addEventListener('pointerleave', leave);
|
|
71
|
+
document.addEventListener('pointerdown', down);
|
|
72
|
+
document.addEventListener('pointerup', up);
|
|
73
|
+
return () => {
|
|
74
|
+
cancelAnimationFrame(raf);
|
|
75
|
+
document.removeEventListener('pointermove', move);
|
|
76
|
+
document.documentElement.removeEventListener('pointerleave', leave);
|
|
77
|
+
document.removeEventListener('pointerdown', down);
|
|
78
|
+
document.removeEventListener('pointerup', up);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** True on a phone or tablet: a coarse pointer on a screen no longer than 1366 CSS px. */
|
|
2
|
+
export function isMobileGpu(): boolean;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The pixel ratio to draw at: the device's own, capped at 2 on a desktop and
|
|
6
|
+
* 1.5 on a phone or tablet, times `scale`.
|
|
7
|
+
*/
|
|
8
|
+
export function pixelRatio(scale?: number): number;
|
|
9
|
+
|
|
10
|
+
/** True with prefers-reduced-motion: reduce. */
|
|
11
|
+
export function prefersReducedMotion(): boolean;
|
|
12
|
+
|
|
13
|
+
/** True with a fine, hovering pointer (a mouse or trackpad). */
|
|
14
|
+
export function canHover(): boolean;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/device
|
|
3
|
+
*
|
|
4
|
+
* What the visitor's device can afford and what they have asked for: the
|
|
5
|
+
* one place every effect reads it from, so the trade-offs are made the
|
|
6
|
+
* same way everywhere.
|
|
7
|
+
*
|
|
8
|
+
* Fragment cost grows with the square of the pixel ratio, and phones
|
|
9
|
+
* report 3 or more, so the ratio an effect draws at is capped: 2 on a
|
|
10
|
+
* desktop, 1.5 on a phone or tablet. All of it is safe to call during
|
|
11
|
+
* server rendering, where it answers as a desktop with motion allowed.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The longest side, in CSS px, of a touch screen still treated as a phone or
|
|
16
|
+
* tablet. Larger touch screens (2-in-1s, tablets driving a display) get the
|
|
17
|
+
* desktop budget.
|
|
18
|
+
*/
|
|
19
|
+
const MOBILE_LONG_SIDE = 1366;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Does a media query match? False outside a browser.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} query The media query.
|
|
25
|
+
* @returns {boolean} Whether it matches.
|
|
26
|
+
*/
|
|
27
|
+
function matches(query) {
|
|
28
|
+
return typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia(query).matches;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Is this a phone or tablet: a coarse pointer on a screen no longer than
|
|
33
|
+
* MOBILE_LONG_SIDE? Its GPU gets the lighter budget.
|
|
34
|
+
*
|
|
35
|
+
* @returns {boolean} True on a phone or tablet.
|
|
36
|
+
*/
|
|
37
|
+
export function isMobileGpu() {
|
|
38
|
+
if (typeof window === 'undefined' || !matches('(pointer: coarse)')) return false;
|
|
39
|
+
const longSide = Math.max(window.innerWidth || 0, window.innerHeight || 0);
|
|
40
|
+
return longSide > 0 && longSide <= MOBILE_LONG_SIDE;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The pixel ratio to draw at: the device's own, capped at 2 on a desktop and
|
|
45
|
+
* 1.5 on a phone or tablet.
|
|
46
|
+
*
|
|
47
|
+
* @param {number} [scale=1] A further share of it, for effects soft enough to
|
|
48
|
+
* draw at less (0.5 draws at half and lets the browser scale up).
|
|
49
|
+
* @returns {number} The ratio.
|
|
50
|
+
*/
|
|
51
|
+
export function pixelRatio(scale = 1) {
|
|
52
|
+
const native = typeof window === 'undefined' ? 1 : window.devicePixelRatio || 1;
|
|
53
|
+
return Math.min(native, isMobileGpu() ? 1.5 : 2) * scale;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Has the visitor asked for less motion?
|
|
58
|
+
*
|
|
59
|
+
* @returns {boolean} True with prefers-reduced-motion: reduce.
|
|
60
|
+
*/
|
|
61
|
+
export function prefersReducedMotion() {
|
|
62
|
+
return matches('(prefers-reduced-motion: reduce)');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Does the device have a pointer that hovers (a mouse or trackpad)? Effects
|
|
67
|
+
* that follow the pointer without a press only make sense with one.
|
|
68
|
+
*
|
|
69
|
+
* @returns {boolean} True with a fine, hovering pointer.
|
|
70
|
+
*/
|
|
71
|
+
export function canHover() {
|
|
72
|
+
return matches('(hover: hover) and (pointer: fine)');
|
|
73
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface DotGridConfig {
|
|
2
|
+
/** The dots' colour. Default `#ffffff`. */
|
|
3
|
+
color?: string;
|
|
4
|
+
/** Space between dots, CSS px. Default 26. */
|
|
5
|
+
pitch?: number;
|
|
6
|
+
/** A dot's size at rest, CSS px. Default 1.6. */
|
|
7
|
+
dot?: number;
|
|
8
|
+
/** Round dots rather than square. Default false. */
|
|
9
|
+
round?: boolean;
|
|
10
|
+
/** How strongly the noise current lights and nudges the dots; 0 for none. Default 1. */
|
|
11
|
+
flow?: number;
|
|
12
|
+
/** How fast a ripple travels, CSS px a second. Default 620. */
|
|
13
|
+
speed?: number;
|
|
14
|
+
/** Seconds before a ripple is spent. Default 2.6. */
|
|
15
|
+
life?: number;
|
|
16
|
+
/** How far a ripple displaces dots, CSS px. Default 9. */
|
|
17
|
+
push?: number;
|
|
18
|
+
/** The pointer's swell, CSS px; 0 for none. Default 210. */
|
|
19
|
+
radius?: number;
|
|
20
|
+
/** Drop one ripple from the middle soon after it first comes on screen. Default true. */
|
|
21
|
+
greet?: boolean;
|
|
22
|
+
/** Whether clicks drop ripples. Default true. */
|
|
23
|
+
ripples?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Starts the dot grid in `el`'s canvas. Returns a function that stops it. */
|
|
27
|
+
export function dotGrid(el: HTMLElement, config: DotGridConfig): () => void;
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/dot-grid
|
|
3
|
+
*
|
|
4
|
+
* A sea of dots you can drop stones into. The dots sit on a fixed grid,
|
|
5
|
+
* and a slow noise current moves across it, brightening and nudging them
|
|
6
|
+
* a little; a soft swell sits under the pointer. A click sends a wavefront
|
|
7
|
+
* out from that point across the grid, lifting and pushing the dots as it
|
|
8
|
+
* passes, and ripples sum where they cross.
|
|
9
|
+
*
|
|
10
|
+
* Three details make it read as water: the wave leaves its source (what
|
|
11
|
+
* reaches the far corner is the click from a second and a half ago), the
|
|
12
|
+
* front widens as it travels (a ring that keeps its width reads as a
|
|
13
|
+
* shockwave), and the dots are displaced along the surface's tilt, not
|
|
14
|
+
* only lit.
|
|
15
|
+
*
|
|
16
|
+
* Canvas 2D: about 1,600 squares a frame at the default pitch, which needs
|
|
17
|
+
* no GPU. With prefers-reduced-motion, one still frame.
|
|
18
|
+
*
|
|
19
|
+
* From the ArrayPress holding page, as refined for FilterSpark.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { parseColor, toHex } from './color.js';
|
|
23
|
+
import { createCanvas2D } from './canvas2d.js';
|
|
24
|
+
import { pressAt } from './pointer.js';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {object} DotGridConfig
|
|
28
|
+
* @property {string} [color='#ffffff'] The dots' colour.
|
|
29
|
+
* @property {number} [pitch=26] Space between dots, CSS px.
|
|
30
|
+
* @property {number} [dot=1.6] A dot's size at rest, CSS px.
|
|
31
|
+
* @property {boolean} [round=false] Round dots rather than square.
|
|
32
|
+
* @property {number} [flow=1] How strongly the noise current lights and nudges the dots; 0 for none.
|
|
33
|
+
* @property {number} [speed=620] How fast a ripple travels, CSS px a second.
|
|
34
|
+
* @property {number} [life=2.6] Seconds before a ripple is spent.
|
|
35
|
+
* @property {number} [push=9] How far a ripple displaces dots, CSS px (keep under half the pitch).
|
|
36
|
+
* @property {number} [radius=210] The pointer's swell, CSS px; 0 for none.
|
|
37
|
+
* @property {boolean} [greet=true] Drop one ripple from the middle soon after it first comes on screen, so it is clear it can be touched.
|
|
38
|
+
* @property {boolean} [ripples=true] Whether clicks drop ripples.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/** Most ripples alive at once: someone will hold the button and mash it. */
|
|
42
|
+
const MAX_RIPPLES = 14;
|
|
43
|
+
|
|
44
|
+
/** 256 lattice values, 0–1, for the noise: a table lookup rather than a sine a corner. */
|
|
45
|
+
const LATTICE = new Float32Array(256).map((_, i) => {
|
|
46
|
+
const n = Math.sin(i * 127.1 + 311.7) * 43758.5453123;
|
|
47
|
+
return n - Math.floor(n);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Value noise, 0–1: the lattice's values at the four corners around a
|
|
52
|
+
* point, eased between.
|
|
53
|
+
*
|
|
54
|
+
* @param {number} x Across.
|
|
55
|
+
* @param {number} y Down.
|
|
56
|
+
* @returns {number} The noise there.
|
|
57
|
+
*/
|
|
58
|
+
function noise(x, y) {
|
|
59
|
+
const xi = Math.floor(x);
|
|
60
|
+
const yi = Math.floor(y);
|
|
61
|
+
const xf = x - xi;
|
|
62
|
+
const yf = y - yi;
|
|
63
|
+
const u = xf * xf * (3 - 2 * xf);
|
|
64
|
+
const v = yf * yf * (3 - 2 * yf);
|
|
65
|
+
// A corner's value: its two indices mixed into one byte.
|
|
66
|
+
const a = LATTICE[(xi * 73 + yi * 151) & 255];
|
|
67
|
+
const b = LATTICE[((xi + 1) * 73 + yi * 151) & 255];
|
|
68
|
+
const c = LATTICE[(xi * 73 + (yi + 1) * 151) & 255];
|
|
69
|
+
const d = LATTICE[((xi + 1) * 73 + (yi + 1) * 151) & 255];
|
|
70
|
+
return (a * (1 - u) + b * u) * (1 - v) + (c * (1 - u) + d * u) * v;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Starts the dot grid on an element (its first canvas is drawn into).
|
|
75
|
+
*
|
|
76
|
+
* @param {HTMLElement} el The element.
|
|
77
|
+
* @param {DotGridConfig} config The settings.
|
|
78
|
+
* @returns {() => void} Stops it.
|
|
79
|
+
*/
|
|
80
|
+
export function dotGrid(el, config) {
|
|
81
|
+
const PITCH = config.pitch ?? 26;
|
|
82
|
+
const DOT = config.dot ?? 1.6;
|
|
83
|
+
const FLOW = config.flow ?? 1;
|
|
84
|
+
const SPEED = config.speed ?? 620;
|
|
85
|
+
const LIFE = config.life ?? 2.6;
|
|
86
|
+
const PUSH = config.push ?? 9;
|
|
87
|
+
const RADIUS = config.radius ?? 210;
|
|
88
|
+
// One colour for every dot, set once a frame: each dot only changes its alpha.
|
|
89
|
+
const ink = toHex(parseColor(config.color ?? '#ffffff'));
|
|
90
|
+
|
|
91
|
+
/** @type {{ x: number, y: number, t0: number, amp: number }[]} */
|
|
92
|
+
const ripples = [];
|
|
93
|
+
// Scratch for the ripples alive this frame, so the inner loop allocates nothing.
|
|
94
|
+
const rx = new Float64Array(16);
|
|
95
|
+
const ry = new Float64Array(16);
|
|
96
|
+
const rr = new Float64Array(16);
|
|
97
|
+
const rb = new Float64Array(16);
|
|
98
|
+
const rg = new Float64Array(16);
|
|
99
|
+
let cols = 0;
|
|
100
|
+
let rows = 0;
|
|
101
|
+
let greeted = config.greet === false;
|
|
102
|
+
/** When the first frame was drawn, seconds: the greeting waits for the grid to be seen, not merely set up. */
|
|
103
|
+
let shown = -1;
|
|
104
|
+
const start = performance.now();
|
|
105
|
+
/** The pointer, where it is (t) and eased towards it (m), in CSS px over the element. */
|
|
106
|
+
const ptr = { tx: -9999, ty: -9999, mx: -9999, my: -9999 };
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Drops a ripple.
|
|
110
|
+
*
|
|
111
|
+
* @param {number} x Across the element, CSS px.
|
|
112
|
+
* @param {number} y Down it, CSS px.
|
|
113
|
+
* @param {number} amp Its strength, 1 for a click.
|
|
114
|
+
* @param {number} now The time, seconds.
|
|
115
|
+
*/
|
|
116
|
+
const drop = (x, y, amp, now) => {
|
|
117
|
+
ripples.push({ x, y, t0: now, amp });
|
|
118
|
+
while (ripples.length > MAX_RIPPLES) ripples.shift();
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* One frame.
|
|
123
|
+
*
|
|
124
|
+
* @param {import('./canvas2d.js').Canvas2D} c The canvas.
|
|
125
|
+
* @param {number} ms The time, ms.
|
|
126
|
+
*/
|
|
127
|
+
const draw = (c, ms) => {
|
|
128
|
+
const { ctx, width: w, height: h } = c;
|
|
129
|
+
const moving = !c.still;
|
|
130
|
+
const now = (ms - start) / 1000;
|
|
131
|
+
const t = now * 0.16;
|
|
132
|
+
ptr.mx += (ptr.tx - ptr.mx) * 0.06;
|
|
133
|
+
ptr.my += (ptr.ty - ptr.my) * 0.06;
|
|
134
|
+
if (shown < 0) shown = now;
|
|
135
|
+
if (moving && !greeted && now - shown > 0.9) {
|
|
136
|
+
greeted = true;
|
|
137
|
+
drop(w * 0.5, h * 0.42, 0.85, now);
|
|
138
|
+
}
|
|
139
|
+
// Each live ripple resolved once a frame, not once a dot.
|
|
140
|
+
let n = 0;
|
|
141
|
+
for (let i = 0; i < ripples.length && n < 16; i++) {
|
|
142
|
+
const r = ripples[i];
|
|
143
|
+
const age = now - r.t0;
|
|
144
|
+
if (age < 0 || age > LIFE) continue;
|
|
145
|
+
const rad = age * SPEED;
|
|
146
|
+
const k = 1 - age / LIFE;
|
|
147
|
+
rx[n] = r.x;
|
|
148
|
+
ry[n] = r.y;
|
|
149
|
+
rr[n] = rad;
|
|
150
|
+
// The front widens as it travels: water losing coherence.
|
|
151
|
+
rb[n] = 44 + age * 46;
|
|
152
|
+
// Energy spreading round a growing ring, and the ripple running out of life.
|
|
153
|
+
rg[n] = r.amp * k * k * (1 / (1 + rad / 260));
|
|
154
|
+
n++;
|
|
155
|
+
}
|
|
156
|
+
if (ripples.length && now - ripples[0].t0 > LIFE) ripples.shift();
|
|
157
|
+
|
|
158
|
+
ctx.clearRect(0, 0, w, h);
|
|
159
|
+
ctx.fillStyle = ink;
|
|
160
|
+
for (let iy = 0; iy < rows; iy++) {
|
|
161
|
+
for (let ix = 0; ix < cols; ix++) {
|
|
162
|
+
const px = ix * PITCH;
|
|
163
|
+
const py = iy * PITCH;
|
|
164
|
+
// The current scrolls diagonally, so bands move across the grid.
|
|
165
|
+
const f = (noise(ix * 0.14 + t * 1.7, iy * 0.14 - t * 1.1) * 0.65 + noise(ix * 0.29 + t * 3.6, iy * 0.29 - t * 2.3) * 0.35) * FLOW;
|
|
166
|
+
const wob = (f - 0.5 * FLOW) * 3.2;
|
|
167
|
+
// The ripples: height lifts the dot, the slope pushes it along the radius.
|
|
168
|
+
let wave = 0;
|
|
169
|
+
let sx = 0;
|
|
170
|
+
let sy = 0;
|
|
171
|
+
for (let i = 0; i < n; i++) {
|
|
172
|
+
const dx = px - rx[i];
|
|
173
|
+
const dy = py - ry[i];
|
|
174
|
+
const d = Math.sqrt(dx * dx + dy * dy) || 0.001;
|
|
175
|
+
const off = (d - rr[i]) / rb[i];
|
|
176
|
+
if (off < -2.6 || off > 2.6) continue;
|
|
177
|
+
const g = Math.exp(-off * off);
|
|
178
|
+
wave += g * rg[i];
|
|
179
|
+
const tilt = -2 * off * g * rg[i];
|
|
180
|
+
sx += (dx / d) * tilt;
|
|
181
|
+
sy += (dy / d) * tilt;
|
|
182
|
+
}
|
|
183
|
+
// A soft presence under the pointer.
|
|
184
|
+
let near = 0;
|
|
185
|
+
if (RADIUS > 0 && ptr.mx > -9000) {
|
|
186
|
+
const d = Math.hypot(px - ptr.mx, py - ptr.my);
|
|
187
|
+
if (d < RADIUS) {
|
|
188
|
+
const k = 1 - d / RADIUS;
|
|
189
|
+
near = k * k * (3 - 2 * k) * 0.22;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const flow = Math.pow(Math.max(f, 0), 2.2);
|
|
193
|
+
const lift = Math.min(1, flow * 0.7 + wave * 0.9 + near);
|
|
194
|
+
// Brighter and more opaque as it lifts: on the dark grounds this is
|
|
195
|
+
// for, a dimmer dot and a fainter one look alike, so both go into alpha.
|
|
196
|
+
const v = (150 + 105 * lift) / 255;
|
|
197
|
+
const alpha = (0.045 + flow * 0.16 + Math.min(0.62, wave * 0.62) + near * 0.5) * v;
|
|
198
|
+
if (alpha < 0.01) continue;
|
|
199
|
+
const size = DOT + Math.min(1.9, wave * 1.9) + flow * 0.5 + near;
|
|
200
|
+
const x = px + wob + sx * PUSH;
|
|
201
|
+
const y = py + wob * 0.7 + sy * PUSH;
|
|
202
|
+
ctx.globalAlpha = Math.min(1, alpha);
|
|
203
|
+
if (config.round) {
|
|
204
|
+
ctx.beginPath();
|
|
205
|
+
ctx.arc(x, y, size / 2, 0, Math.PI * 2);
|
|
206
|
+
ctx.fill();
|
|
207
|
+
} else {
|
|
208
|
+
ctx.fillRect(x - size / 2, y - size / 2, size, size);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
ctx.globalAlpha = 1;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/** @param {PointerEvent} e The move. */
|
|
216
|
+
const move = (e) => {
|
|
217
|
+
const box = el.getBoundingClientRect();
|
|
218
|
+
ptr.tx = e.clientX - box.left;
|
|
219
|
+
ptr.ty = e.clientY - box.top;
|
|
220
|
+
if (ptr.mx < -9000) Object.assign(ptr, { mx: ptr.tx, my: ptr.ty });
|
|
221
|
+
};
|
|
222
|
+
/** @param {PointerEvent} e The press: a ripple where it landed (on press, not release). */
|
|
223
|
+
const press = (e) => {
|
|
224
|
+
const at = pressAt(el, e);
|
|
225
|
+
if (!at) return;
|
|
226
|
+
move(e);
|
|
227
|
+
drop(at.x * el.clientWidth, (1 - at.y) * el.clientHeight, 1, (performance.now() - start) / 1000);
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const { c, stop } = createCanvas2D(el, {
|
|
231
|
+
draw,
|
|
232
|
+
resize: ({ width, height }) => {
|
|
233
|
+
cols = Math.ceil(width / PITCH) + 1;
|
|
234
|
+
rows = Math.ceil(height / PITCH) + 1;
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
if (!c || c.still) return stop;
|
|
238
|
+
document.addEventListener('pointermove', move, { passive: true });
|
|
239
|
+
if (config.ripples !== false) document.addEventListener('pointerdown', press, { passive: true });
|
|
240
|
+
return () => {
|
|
241
|
+
stop();
|
|
242
|
+
document.removeEventListener('pointermove', move);
|
|
243
|
+
document.removeEventListener('pointerdown', press);
|
|
244
|
+
};
|
|
245
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { PaletteName } from './palettes.js';
|
|
2
|
+
|
|
3
|
+
export interface DotSurfaceConfig {
|
|
4
|
+
/** The dots' colour. Default `#ff8a1f`. */
|
|
5
|
+
color?: string;
|
|
6
|
+
/** A gradient instead (up to five), blended in Oklab, from near to far or left to right (see `gradient`). */
|
|
7
|
+
colors?: string[];
|
|
8
|
+
/** A shared palette by name (`PALETTES`, any case), when there are no `colors` or `color`. */
|
|
9
|
+
palette?: PaletteName | (string & {});
|
|
10
|
+
/** Which way `colors` runs: near to far, or left to right. Default `depth`. */
|
|
11
|
+
gradient?: 'depth' | 'width';
|
|
12
|
+
/** Space between dots, CSS px, at the middle of the sheet (nearer is wider, further closer). Default 10. */
|
|
13
|
+
pitch?: number;
|
|
14
|
+
/** The largest dot, CSS px, at the middle of the sheet. Default 6. */
|
|
15
|
+
dot?: number;
|
|
16
|
+
/** How tall the swells are: 1 a gentle roll, 2 a heavy sea, 0 flat. Default 1. */
|
|
17
|
+
amplitude?: number;
|
|
18
|
+
/** How fast the sheet rolls; 0 holds it still. Default 1. */
|
|
19
|
+
speed?: number;
|
|
20
|
+
/** The camera's angle above the sheet, degrees (10 grazing, 70 nearly overhead). Default 42. */
|
|
21
|
+
tilt?: number;
|
|
22
|
+
/** Where the light comes from: x right, y up, z into the distance. Default `[-0.5, 0.6, -0.6]`. */
|
|
23
|
+
light?: [number, number, number];
|
|
24
|
+
/** Whether the pointer raises a swell and a click sends a ring. Default true. */
|
|
25
|
+
interactive?: boolean;
|
|
26
|
+
/** An area kept dim behind copy: centre (0–1 from the top left), radius (a share of the height), depth (0–1). Default none; `{}` for the middle. */
|
|
27
|
+
quiet?: { x?: number; y?: number; radius?: number; depth?: number } | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Most colours a gradient takes. */
|
|
31
|
+
export const MAX_COLORS: number;
|
|
32
|
+
|
|
33
|
+
/** How far into the distance the flat sheet lies at clip-space height `y` (-1 bottom to 1); Infinity at or above the horizon. */
|
|
34
|
+
export function sheetDepth(y: number, tilt: number): number;
|
|
35
|
+
|
|
36
|
+
/** Where a point on screen (x 0–1 from the left, y 0–1 from the bottom) lies on the flat sheet; null above the horizon. */
|
|
37
|
+
export function sheetAt(x: number, y: number, tilt: number, aspect: number): { x: number; z: number } | null;
|
|
38
|
+
|
|
39
|
+
/** The sheet's grid as particle data, four floats a dot: x, z, depth (0 near, 1 far) and across (0 left, 1 right). */
|
|
40
|
+
export function sheetGrid(aspect: number, spacing: number, tilt: number): Float32Array;
|
|
41
|
+
|
|
42
|
+
/** A gradient as the shader takes it: each colour in Oklab, padded to MAX_COLORS. Throws a TypeError for a colour that is not hex. */
|
|
43
|
+
export function gradientUniform(colors: string[]): Float32Array;
|
|
44
|
+
|
|
45
|
+
/** Starts the dot surface in `el`'s canvas. Returns a function that stops it. */
|
|
46
|
+
export function dotSurface(el: HTMLElement, config: DotSurfaceConfig): () => void;
|