@arraypress/effects-astro 0.0.0-stage → 0.1.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 +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 +303 -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,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/pointer
|
|
3
|
+
*
|
|
4
|
+
* The pointer as the effects read it: one listener for the page, and
|
|
5
|
+
* positions given relative to an element, so an effect in a card and one
|
|
6
|
+
* behind the whole page read the same pointer in their own terms.
|
|
7
|
+
*
|
|
8
|
+
* `trail` turns movement into a ribbon of points: a fast stroke moves the
|
|
9
|
+
* pointer far between two frames, and an effect that only stamped where it
|
|
10
|
+
* landed would leave dots. A jump (the pointer entering the window, or
|
|
11
|
+
* coming back to the tab) is not a stroke, and lays nothing.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** What a click is not the effect's on: links, buttons, form fields, and anything marked `data-effect-ignore`. */
|
|
15
|
+
export const CLICK_IGNORE = 'a, button, input, select, textarea, label, [data-effect-ignore]';
|
|
16
|
+
|
|
17
|
+
/** Furthest a stroke may travel between two reads, as a share of the element's size, before it counts as a jump. */
|
|
18
|
+
const JUMP = 0.25;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The pointer in the viewport, whether it is in the window, and counts of
|
|
22
|
+
* its moves and of its exits (so a reader can tell it left between reads).
|
|
23
|
+
*/
|
|
24
|
+
const state = { x: 0, y: 0, inside: false, moved: 0, left: 0 };
|
|
25
|
+
|
|
26
|
+
if (typeof document !== 'undefined') {
|
|
27
|
+
document.addEventListener(
|
|
28
|
+
'pointermove',
|
|
29
|
+
(e) => {
|
|
30
|
+
state.x = e.clientX;
|
|
31
|
+
state.y = e.clientY;
|
|
32
|
+
state.inside = true;
|
|
33
|
+
state.moved++;
|
|
34
|
+
},
|
|
35
|
+
{ passive: true },
|
|
36
|
+
);
|
|
37
|
+
document.documentElement.addEventListener('pointerleave', () => {
|
|
38
|
+
state.inside = false;
|
|
39
|
+
state.left++;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Where the pointer is over an element.
|
|
45
|
+
*
|
|
46
|
+
* @param {Element} el The element.
|
|
47
|
+
* @returns {{ x: number, y: number, inside: boolean }} x 0 (left) to 1, y 0
|
|
48
|
+
* (bottom) to 1, as shaders count; `inside` false when the pointer has
|
|
49
|
+
* left the window or is outside the element.
|
|
50
|
+
*/
|
|
51
|
+
export function pointerIn(el) {
|
|
52
|
+
const box = el.getBoundingClientRect();
|
|
53
|
+
const x = (state.x - box.left) / (box.width || 1);
|
|
54
|
+
const y = 1 - (state.y - box.top) / (box.height || 1);
|
|
55
|
+
return { x, y, inside: state.inside && x >= 0 && x <= 1 && y >= 0 && y <= 1 };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Follows the pointer's strokes over an element. Each `read` returns the
|
|
60
|
+
* points along the path since the last read, spaced no further apart than
|
|
61
|
+
* `step`, with the stroke's velocity.
|
|
62
|
+
*
|
|
63
|
+
* @param {Element} el The element.
|
|
64
|
+
* @param {object} [options]
|
|
65
|
+
* @param {number} [options.step=0.01] Spacing of the points, as a share of the element's height.
|
|
66
|
+
* @param {number} [options.max=16] Most points laid in one read.
|
|
67
|
+
* @returns {{ read: (dt: number) => Array<{ x: number, y: number, dx: number, dy: number }>, reset: () => void }}
|
|
68
|
+
* `read(dt)`: the points since the last read, with the stroke's velocity in
|
|
69
|
+
* element-widths/heights a second; `reset()`: forget the last position, so
|
|
70
|
+
* the next move starts a new stroke.
|
|
71
|
+
*/
|
|
72
|
+
export function trail(el, { step = 0.01, max = 16 } = {}) {
|
|
73
|
+
/** @type {{ x: number, y: number } | null} */
|
|
74
|
+
let last = null;
|
|
75
|
+
let seen = state.moved;
|
|
76
|
+
let exits = state.left;
|
|
77
|
+
return {
|
|
78
|
+
read(dt) {
|
|
79
|
+
if (state.moved === seen) return [];
|
|
80
|
+
seen = state.moved;
|
|
81
|
+
const now = pointerIn(el);
|
|
82
|
+
// Left the window since the last read: whatever came before was another stroke.
|
|
83
|
+
if (exits !== state.left) {
|
|
84
|
+
exits = state.left;
|
|
85
|
+
last = null;
|
|
86
|
+
}
|
|
87
|
+
if (!state.inside) {
|
|
88
|
+
last = null;
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
const from = last;
|
|
92
|
+
last = { x: now.x, y: now.y };
|
|
93
|
+
if (!from) return [];
|
|
94
|
+
const ddx = now.x - from.x;
|
|
95
|
+
const ddy = now.y - from.y;
|
|
96
|
+
const distance = Math.hypot(ddx, ddy);
|
|
97
|
+
if (distance === 0 || distance > JUMP) return [];
|
|
98
|
+
const time = dt || 1 / 60;
|
|
99
|
+
const count = Math.min(max, Math.max(1, Math.ceil(distance / step)));
|
|
100
|
+
const points = [];
|
|
101
|
+
for (let i = 1; i <= count; i++) {
|
|
102
|
+
points.push({ x: from.x + (ddx * i) / count, y: from.y + (ddy * i) / count, dx: ddx / time, dy: ddy / time });
|
|
103
|
+
}
|
|
104
|
+
return points;
|
|
105
|
+
},
|
|
106
|
+
reset() {
|
|
107
|
+
last = null;
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Where a press landed on an element, unless it was on something whose
|
|
114
|
+
* clicks are its own.
|
|
115
|
+
*
|
|
116
|
+
* @param {Element} el The element.
|
|
117
|
+
* @param {PointerEvent} e The press.
|
|
118
|
+
* @param {string} [ignore=CLICK_IGNORE] Presses on these are theirs.
|
|
119
|
+
* @returns {{ x: number, y: number } | null} x 0 (left) to 1, y 0 (bottom)
|
|
120
|
+
* to 1; null outside the element or on an ignored target.
|
|
121
|
+
*/
|
|
122
|
+
export function pressAt(el, e, ignore = CLICK_IGNORE) {
|
|
123
|
+
if (/** @type {Element | null} */ (e.target)?.closest?.(ignore)) return null;
|
|
124
|
+
const box = el.getBoundingClientRect();
|
|
125
|
+
const x = (e.clientX - box.left) / (box.width || 1);
|
|
126
|
+
const y = 1 - (e.clientY - box.top) / (box.height || 1);
|
|
127
|
+
return x < 0 || x > 1 || y < 0 || y > 1 ? null : { x, y };
|
|
128
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { GL, Program } from './gl.js';
|
|
2
|
+
|
|
3
|
+
/** GLSL: `rotateX`, `rotateY` and `vec4 project(vec3 v, float aspect)` for a small 3D scene. */
|
|
4
|
+
export const GLSL_PROJECT: string;
|
|
5
|
+
|
|
6
|
+
/** GLSL_PROJECT in JavaScript: where a scene point lands, 0–1 from the top left, after turning `turnY` then `turnX`. */
|
|
7
|
+
export function projectPoint(v: [number, number, number], turnY: number, turnX: number, aspect: number): { x: number; y: number };
|
|
8
|
+
|
|
9
|
+
/** A point renderer: soft round dots, added together. */
|
|
10
|
+
export interface Points {
|
|
11
|
+
program: Program;
|
|
12
|
+
/** Draws once, or with `aberration` > 0 three times, red, green and blue that many canvas px apart; `draw` sets uniforms before each. */
|
|
13
|
+
passes(aberration: number, draw: () => void): void;
|
|
14
|
+
/** Replaces the particle data, four floats a particle (attribute `p`); the same size as before is written in place. */
|
|
15
|
+
upload(data: Float32Array): void;
|
|
16
|
+
count(): number;
|
|
17
|
+
bind(): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Makes a point renderer from the effect's vertex shader, and optionally a
|
|
22
|
+
* sprite of its own (reading `vColour`, `vAlpha`) in place of the soft round
|
|
23
|
+
* dot; null (reason in the console) if it does not compile.
|
|
24
|
+
*/
|
|
25
|
+
export function createPoints(gl: GL, vertex: string, fragment?: string): Points | null;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/points
|
|
3
|
+
*
|
|
4
|
+
* Particles drawn as points: a buffer of per-particle data (read as the
|
|
5
|
+
* vertex attribute `p`, a vec4), a program the effect writes the motion
|
|
6
|
+
* for, and soft round dots added together so where they crowd they glow.
|
|
7
|
+
*
|
|
8
|
+
* Drawn once, or three times with the red, green and blue drawn a little
|
|
9
|
+
* apart (`aberration`), so every dot fringes like light through a cheap
|
|
10
|
+
* lens. The vertex shader adds `uShift` (clip space) to its position for
|
|
11
|
+
* that, and gets `uRes`, `uTime` and `uRatio` (the pixel ratio, for sizes
|
|
12
|
+
* in CSS px).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { createProgram } from './gl.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* GLSL for a vertex shader: rotations and a gentle perspective, for points
|
|
19
|
+
* in a small 3D scene centred on the origin.
|
|
20
|
+
*/
|
|
21
|
+
export const GLSL_PROJECT = `
|
|
22
|
+
vec3 rotateX(vec3 v, float a) { float c = cos(a), s = sin(a); return vec3(v.x, c * v.y - s * v.z, s * v.y + c * v.z); }
|
|
23
|
+
vec3 rotateY(vec3 v, float a) { float c = cos(a), s = sin(a); return vec3(c * v.x + s * v.z, v.y, -s * v.x + c * v.z); }
|
|
24
|
+
// A point in the scene to clip space: x scaled to the canvas's aspect, nearer points larger.
|
|
25
|
+
vec4 project(vec3 v, float aspect) {
|
|
26
|
+
float w = 1.0 + v.z * 0.45;
|
|
27
|
+
return vec4(v.x / aspect, v.y, 0.0, w);
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* GLSL_PROJECT's rotations and perspective in JavaScript, for placing
|
|
33
|
+
* things over a point (a tracker box) where the shader draws it.
|
|
34
|
+
*
|
|
35
|
+
* @param {[number, number, number]} v The point in the scene.
|
|
36
|
+
* @param {number} turnY Rotation about the vertical axis, radians (applied first).
|
|
37
|
+
* @param {number} turnX Rotation about the horizontal axis, radians.
|
|
38
|
+
* @param {number} aspect The canvas's width over height.
|
|
39
|
+
* @returns {{ x: number, y: number }} Where it lands, 0–1 from the top left.
|
|
40
|
+
*/
|
|
41
|
+
export function projectPoint([x, y, z], turnY, turnX, aspect) {
|
|
42
|
+
const cy = Math.cos(turnY);
|
|
43
|
+
const sy = Math.sin(turnY);
|
|
44
|
+
const x1 = cy * x + sy * z;
|
|
45
|
+
const z1 = -sy * x + cy * z;
|
|
46
|
+
const cx = Math.cos(turnX);
|
|
47
|
+
const sx = Math.sin(turnX);
|
|
48
|
+
const y2 = cx * y - sx * z1;
|
|
49
|
+
const z2 = sx * y + cx * z1;
|
|
50
|
+
const w = 1 + z2 * 0.45;
|
|
51
|
+
return { x: (x1 / aspect / w) * 0.5 + 0.5, y: 0.5 - (y2 / w) * 0.5 };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The fragment shader every point effect shares: a soft round dot, in its colour, added up. */
|
|
55
|
+
const DOT = `
|
|
56
|
+
precision highp float;
|
|
57
|
+
varying vec3 vColour;
|
|
58
|
+
varying float vAlpha;
|
|
59
|
+
void main() {
|
|
60
|
+
float d = length(gl_PointCoord - 0.5);
|
|
61
|
+
float a = smoothstep(0.5, 0.15, d) * vAlpha;
|
|
62
|
+
gl_FragColor = vec4(vColour * a, a);
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @typedef {object} Points
|
|
68
|
+
* @property {import('./gl.js').Program} program The points' program.
|
|
69
|
+
* @property {(aberration: number, draw: () => void) => void} passes
|
|
70
|
+
* Draws the points: once, or with `aberration` > 0 three times, red,
|
|
71
|
+
* green and blue that many canvas pixels apart. `draw` sets the
|
|
72
|
+
* uniforms (the program is bound) before each pass.
|
|
73
|
+
* @property {(data: Float32Array) => void} upload Replaces the particle data (four floats a particle);
|
|
74
|
+
* data the same size as before is written in place, so it can change every frame.
|
|
75
|
+
* @property {() => number} count How many particles there are.
|
|
76
|
+
* @property {() => void} bind Binds the buffer to attribute 0.
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Makes a point renderer.
|
|
81
|
+
*
|
|
82
|
+
* @param {WebGLRenderingContext | WebGL2RenderingContext} gl The context.
|
|
83
|
+
* @param {string} vertex The effect's vertex shader: reads `attribute vec4 p`,
|
|
84
|
+
* writes `gl_Position`, `gl_PointSize`, `vColour` and `vAlpha`, and adds
|
|
85
|
+
* `uniform vec2 uShift` to its clip position.
|
|
86
|
+
* @param {string} [fragment] A sprite of its own instead of the soft round dot
|
|
87
|
+
* (reading `vColour` and `vAlpha`; what it writes is added up).
|
|
88
|
+
* @returns {Points | null} The renderer, or null with the reason in the console.
|
|
89
|
+
*/
|
|
90
|
+
export function createPoints(gl, vertex, fragment = DOT) {
|
|
91
|
+
const program = createProgram(gl, vertex, fragment);
|
|
92
|
+
if (!program) return null;
|
|
93
|
+
const buffer = gl.createBuffer();
|
|
94
|
+
let count = 0;
|
|
95
|
+
|
|
96
|
+
/** Binds the buffer to attribute 0, four floats a particle. */
|
|
97
|
+
const bind = () => {
|
|
98
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
99
|
+
gl.enableVertexAttribArray(0);
|
|
100
|
+
gl.vertexAttribPointer(0, 4, gl.FLOAT, false, 0, 0);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
program,
|
|
105
|
+
upload(data) {
|
|
106
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
107
|
+
if (count && data.length === count * 4) gl.bufferSubData(gl.ARRAY_BUFFER, 0, data);
|
|
108
|
+
else gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
|
|
109
|
+
count = data.length / 4;
|
|
110
|
+
},
|
|
111
|
+
count: () => count,
|
|
112
|
+
bind,
|
|
113
|
+
passes(aberration, draw) {
|
|
114
|
+
bind();
|
|
115
|
+
gl.useProgram(program.program);
|
|
116
|
+
gl.enable(gl.BLEND);
|
|
117
|
+
gl.blendFunc(gl.ONE, gl.ONE);
|
|
118
|
+
const split = aberration;
|
|
119
|
+
const channels = split > 0 ? [[1, 0, 0, -split], [0, 1, 0, 0], [0, 0, 1, split]] : [[1, 1, 1, 0]];
|
|
120
|
+
for (const [r, g, b, dx] of channels) {
|
|
121
|
+
gl.colorMask(!!r, !!g, !!b, true);
|
|
122
|
+
gl.uniform2f(program.uniform('uShift'), (dx * 2) / gl.drawingBufferWidth, 0);
|
|
123
|
+
draw();
|
|
124
|
+
gl.drawArrays(gl.POINTS, 0, count);
|
|
125
|
+
}
|
|
126
|
+
gl.colorMask(true, true, true, true);
|
|
127
|
+
gl.disable(gl.BLEND);
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/pools
|
|
3
|
+
*
|
|
4
|
+
* The still stand-in for a light effect without WebGL: its colours as soft
|
|
5
|
+
* pools of light on a ground, as a CSS `background`. A component sets it on
|
|
6
|
+
* its element, so it shows before the canvas draws and wherever it cannot.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Three colours as soft pools of light, upper left, upper right and lower
|
|
11
|
+
* right, over a ground.
|
|
12
|
+
*
|
|
13
|
+
* @param {string[]} colors CSS colours, at least one (looped to make three).
|
|
14
|
+
* @param {string} ground The colour under them.
|
|
15
|
+
* @returns {string} A CSS `background`.
|
|
16
|
+
*/
|
|
17
|
+
export function colorPools(colors, ground) {
|
|
18
|
+
const [a, b, c] = [0, 1, 2].map((i) => colors[i % colors.length]);
|
|
19
|
+
return [
|
|
20
|
+
`radial-gradient(60% 50% at 20% 25%, ${a} 0%, transparent 70%)`,
|
|
21
|
+
`radial-gradient(55% 45% at 80% 30%, ${b} 0%, transparent 70%)`,
|
|
22
|
+
`radial-gradient(60% 50% at 70% 85%, ${c} 0%, transparent 70%)`,
|
|
23
|
+
ground,
|
|
24
|
+
].join(', ');
|
|
25
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Layout } from './stack-poses.js';
|
|
2
|
+
|
|
3
|
+
export interface ProductStackConfig {
|
|
4
|
+
/** How the covers are laid out. Default `fan`. */
|
|
5
|
+
layout?: Layout;
|
|
6
|
+
/** How far apart the covers sit, 0–2. Default 1. */
|
|
7
|
+
spread?: number;
|
|
8
|
+
/** How far the stack leans towards the pointer, degrees. Default 12. */
|
|
9
|
+
tilt?: number;
|
|
10
|
+
/** How much the covers behind dim and soften, 0–1. Default 0.6. */
|
|
11
|
+
depth?: number;
|
|
12
|
+
/** Lean, fan and lift for the pointer and keyboard. Default true. */
|
|
13
|
+
interactive?: boolean;
|
|
14
|
+
/** A cover's width over its height. Default 1. */
|
|
15
|
+
ratio?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Lays out the covers in `el`'s `.ps-stage` and has them answer the pointer
|
|
20
|
+
* and keyboard: the stack leans towards the pointer, fans apart on hover
|
|
21
|
+
* or focus, and lifts the cover under the pointer. Returns a function that
|
|
22
|
+
* stops it.
|
|
23
|
+
*/
|
|
24
|
+
export function productStack(el: HTMLElement, config: ProductStackConfig): () => void;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/product-stack
|
|
3
|
+
*
|
|
4
|
+
* Product covers floating in 3D, in a fan, a stack or an arc
|
|
5
|
+
* (src/runtime/stack-poses.js places them). The covers are the page's own
|
|
6
|
+
* links and images, moved by CSS transforms, so they stay crisp, take
|
|
7
|
+
* focus and click through like any link. This module only decides which
|
|
8
|
+
* pose each cover is in and writes it; CSS eases between poses, floats the
|
|
9
|
+
* covers and sweeps the sheen, all on the compositor, so nothing runs on
|
|
10
|
+
* the main thread while the stack sits still.
|
|
11
|
+
*
|
|
12
|
+
* - Pointer: the stack leans towards it, wherever it is on the page.
|
|
13
|
+
* - Hover (or focus): the covers fan apart, and the one under the
|
|
14
|
+
* pointer (or focused) lifts forward, comes into focus and pushes its
|
|
15
|
+
* neighbours aside.
|
|
16
|
+
* - Depth of field: covers further from the one in front dim and lose a
|
|
17
|
+
* little colour; only the furthest blur, a little.
|
|
18
|
+
*
|
|
19
|
+
* With reduced motion it holds still and does not lean; hover and focus
|
|
20
|
+
* still lift a cover, without easing. On a touch screen it does not lean
|
|
21
|
+
* or fan: a tap is a tap on the link.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { canHover, prefersReducedMotion } from './device.js';
|
|
25
|
+
import { inView } from './in-view.js';
|
|
26
|
+
import { frontOf, layoutOf, poseFilter, poseTransform, stackBounds, stackPoses } from './stack-poses.js';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @typedef {object} ProductStackConfig
|
|
30
|
+
* @property {'fan' | 'stack' | 'arc'} [layout='fan'] How the covers are laid out.
|
|
31
|
+
* @property {number} [spread=1] How far apart the covers sit, 0–2.
|
|
32
|
+
* @property {number} [tilt=12] How far the stack leans towards the pointer, degrees.
|
|
33
|
+
* @property {number} [depth=0.6] How much the covers behind dim and soften, 0–1.
|
|
34
|
+
* @property {boolean} [interactive=true] Lean, fan and lift for the pointer and keyboard.
|
|
35
|
+
* @property {number} [ratio=1] A cover's width over its height.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Lays out an element's covers and, unless it is not interactive, has
|
|
40
|
+
* them answer the pointer and keyboard. The element holds a `.ps-scene`
|
|
41
|
+
* with a `.ps-stage` in it, whose children are the covers.
|
|
42
|
+
*
|
|
43
|
+
* @param {HTMLElement} el The component's element.
|
|
44
|
+
* @param {ProductStackConfig} config The settings.
|
|
45
|
+
* @returns {() => void} Stops it.
|
|
46
|
+
*/
|
|
47
|
+
export function productStack(el, config) {
|
|
48
|
+
const scene = /** @type {HTMLElement | null} */ (el.querySelector('.ps-scene'));
|
|
49
|
+
const stage = /** @type {HTMLElement | null} */ (el.querySelector('.ps-stage'));
|
|
50
|
+
if (!scene || !stage) return () => {};
|
|
51
|
+
const covers = /** @type {HTMLElement[]} */ ([...stage.children]);
|
|
52
|
+
const n = covers.length;
|
|
53
|
+
const layout = layoutOf(config.layout);
|
|
54
|
+
const spread = config.spread ?? 1;
|
|
55
|
+
const depth = config.depth ?? 0.6;
|
|
56
|
+
const ratio = config.ratio && config.ratio > 0 ? config.ratio : 1;
|
|
57
|
+
const tilt = config.tilt ?? 12;
|
|
58
|
+
const still = prefersReducedMotion();
|
|
59
|
+
let open = false;
|
|
60
|
+
let lifted = -1;
|
|
61
|
+
|
|
62
|
+
const bounds = stackBounds(layout, n, spread, ratio);
|
|
63
|
+
el.style.setProperty('--ps-wide', String(bounds.wide));
|
|
64
|
+
el.style.setProperty('--ps-tall', String(bounds.tall));
|
|
65
|
+
el.style.setProperty('--ps-ratio', String(ratio));
|
|
66
|
+
covers.forEach((cover, i) => {
|
|
67
|
+
cover.style.setProperty('--ps-i', String(i));
|
|
68
|
+
cover.querySelectorAll('img').forEach((img) => (img.draggable = false));
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
/** Writes every cover's pose for the state the stack is in, and marks the one in front. */
|
|
72
|
+
const pose = () => {
|
|
73
|
+
const front = lifted >= 0 ? lifted : Math.floor(frontOf(layout, n));
|
|
74
|
+
stackPoses(layout, n, { spread, open, lifted }).forEach((p, i) => {
|
|
75
|
+
covers[i].style.transform = poseTransform(p);
|
|
76
|
+
covers[i].style.filter = poseFilter(p, depth);
|
|
77
|
+
covers[i].classList.toggle('is-front', i === front);
|
|
78
|
+
covers[i].classList.toggle('is-lifted', i === lifted);
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Moves to a new state, if it is one.
|
|
84
|
+
*
|
|
85
|
+
* @param {boolean} nextOpen Whether the covers fan apart.
|
|
86
|
+
* @param {number} nextLifted The cover lifted forward; -1 for none.
|
|
87
|
+
*/
|
|
88
|
+
const set = (nextOpen, nextLifted) => {
|
|
89
|
+
if (nextOpen === open && nextLifted === lifted) return;
|
|
90
|
+
open = nextOpen;
|
|
91
|
+
lifted = nextLifted;
|
|
92
|
+
pose();
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
pose();
|
|
96
|
+
// Ease only from the first change on: the stack is in place when it appears.
|
|
97
|
+
const ready = requestAnimationFrame(() => el.classList.add('is-ready'));
|
|
98
|
+
/** @type {Array<() => void>} */
|
|
99
|
+
const stops = [() => cancelAnimationFrame(ready)];
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Listens to an event, and remembers to stop.
|
|
103
|
+
*
|
|
104
|
+
* @param {EventTarget} target What to listen to.
|
|
105
|
+
* @param {string} type The event.
|
|
106
|
+
* @param {(e: any) => void} handler The listener.
|
|
107
|
+
*/
|
|
108
|
+
const on = (target, type, handler) => {
|
|
109
|
+
target.addEventListener(type, handler, { passive: true });
|
|
110
|
+
stops.push(() => target.removeEventListener(type, handler));
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The cover an event happened in.
|
|
115
|
+
*
|
|
116
|
+
* @param {Event} e The event.
|
|
117
|
+
* @returns {number} Its index; -1 when it was in none.
|
|
118
|
+
*/
|
|
119
|
+
const coverOf = (e) => covers.findIndex((cover) => cover.contains(/** @type {Node | null} */ (e.target)));
|
|
120
|
+
|
|
121
|
+
if (config.interactive !== false) {
|
|
122
|
+
/** @param {PointerEvent} e The pointer coming over the stack, or moving over it. */
|
|
123
|
+
const hover = (e) => {
|
|
124
|
+
if (e.pointerType !== 'touch') set(true, coverOf(e));
|
|
125
|
+
};
|
|
126
|
+
on(scene, 'pointerover', hover);
|
|
127
|
+
on(scene, 'pointerleave', () => set(Boolean(scene.querySelector(':focus-visible')), -1));
|
|
128
|
+
on(scene, 'focusin', (e) => set(true, coverOf(e)));
|
|
129
|
+
on(scene, 'focusout', (/** @type {FocusEvent} */ e) => {
|
|
130
|
+
if (!scene.contains(/** @type {Node | null} */ (e.relatedTarget))) set(scene.matches(':hover'), -1);
|
|
131
|
+
});
|
|
132
|
+
if (!still && canHover() && tilt > 0) stops.push(lean(el, scene, tilt));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Asleep while out of view: the float and sheen stop with it.
|
|
136
|
+
stops.push(inView(el, () => el.classList.remove('is-asleep'), false, () => el.classList.add('is-asleep')));
|
|
137
|
+
return () => stops.forEach((stop) => stop());
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Leans a stack towards the pointer, anywhere on the page, while it is in
|
|
142
|
+
* view: `--ps-lean-x` / `--ps-lean-y` (degrees) on the element turn its
|
|
143
|
+
* stage, and `--ps-glint-x` / `--ps-glint-y` (-1 to 1) move the covers'
|
|
144
|
+
* gloss the other way, as a light would. One read and one write a frame at
|
|
145
|
+
* most, and only while the pointer moves.
|
|
146
|
+
*
|
|
147
|
+
* @param {HTMLElement} el The component's element.
|
|
148
|
+
* @param {HTMLElement} scene The box the stack sits in; it leans about its centre.
|
|
149
|
+
* @param {number} tilt The most it leans, degrees.
|
|
150
|
+
* @returns {() => void} Stops it.
|
|
151
|
+
*/
|
|
152
|
+
function lean(el, scene, tilt) {
|
|
153
|
+
let x = 0;
|
|
154
|
+
let y = 0;
|
|
155
|
+
let inside = false;
|
|
156
|
+
let frame = 0;
|
|
157
|
+
|
|
158
|
+
/** Writes the lean for where the pointer last was. */
|
|
159
|
+
const write = () => {
|
|
160
|
+
frame = 0;
|
|
161
|
+
const box = scene.getBoundingClientRect();
|
|
162
|
+
const reach = { x: Math.max(window.innerWidth * 0.5, 1), y: Math.max(window.innerHeight * 0.5, 1) };
|
|
163
|
+
const nx = inside ? Math.max(-1, Math.min(1, (x - (box.left + box.width / 2)) / reach.x)) : 0;
|
|
164
|
+
const ny = inside ? Math.max(-1, Math.min(1, (y - (box.top + box.height / 2)) / reach.y)) : 0;
|
|
165
|
+
el.style.setProperty('--ps-lean-x', `${(-ny * tilt * 0.6).toFixed(2)}deg`);
|
|
166
|
+
el.style.setProperty('--ps-lean-y', `${(nx * tilt).toFixed(2)}deg`);
|
|
167
|
+
el.style.setProperty('--ps-glint-x', (-nx).toFixed(3));
|
|
168
|
+
el.style.setProperty('--ps-glint-y', (-ny).toFixed(3));
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/** Books a write for the next frame, if none is booked. */
|
|
172
|
+
const book = () => {
|
|
173
|
+
frame ||= requestAnimationFrame(write);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
/** @param {PointerEvent} e The move. */
|
|
177
|
+
const move = (e) => {
|
|
178
|
+
if (e.pointerType === 'touch') return;
|
|
179
|
+
x = e.clientX;
|
|
180
|
+
y = e.clientY;
|
|
181
|
+
inside = true;
|
|
182
|
+
book();
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/** The pointer left the window: settle back. */
|
|
186
|
+
const leave = () => {
|
|
187
|
+
inside = false;
|
|
188
|
+
book();
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/** Starts following the pointer. */
|
|
192
|
+
const listen = () => {
|
|
193
|
+
document.addEventListener('pointermove', move, { passive: true });
|
|
194
|
+
document.documentElement.addEventListener('pointerleave', leave);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/** Stops following the pointer. */
|
|
198
|
+
const quiet = () => {
|
|
199
|
+
document.removeEventListener('pointermove', move);
|
|
200
|
+
document.documentElement.removeEventListener('pointerleave', leave);
|
|
201
|
+
cancelAnimationFrame(frame);
|
|
202
|
+
frame = 0;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const watching = inView(el, listen, false, quiet);
|
|
206
|
+
return () => {
|
|
207
|
+
watching();
|
|
208
|
+
quiet();
|
|
209
|
+
};
|
|
210
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { PaletteName } from './palettes.js';
|
|
2
|
+
|
|
3
|
+
export interface RadiantGlassConfig {
|
|
4
|
+
/** The lights' colours, the last the hot colour where they gather. Default amber, blue, white. */
|
|
5
|
+
colors?: string[];
|
|
6
|
+
/** A shared palette by name (`PALETTES`, any case), when there are no `colors`. Its colours light the glass; its glint is the hot colour. */
|
|
7
|
+
palette?: PaletteName | (string & {});
|
|
8
|
+
/** The ground. Default `#060818`. */
|
|
9
|
+
background?: string;
|
|
10
|
+
/** The tiles: four in a plus, three on a slant, or one large. Default `cross`. */
|
|
11
|
+
layout?: 'cross' | 'diagonal' | 'single';
|
|
12
|
+
/** Each tile's shape: a rounded square on its corner, square on, or round. Default `diamond`. */
|
|
13
|
+
shape?: 'diamond' | 'square' | 'circle';
|
|
14
|
+
/** Which side the cluster sits on, leaving the other for the copy. Default `left`. */
|
|
15
|
+
side?: 'left' | 'right';
|
|
16
|
+
/** The cluster's size; 1 fills the height. Default 1. */
|
|
17
|
+
size?: number;
|
|
18
|
+
/** How blurred the light through the glass is; 0 for clear. Default 1. */
|
|
19
|
+
frost?: number;
|
|
20
|
+
/** How strong the halo round each tile is; 0 for none. Default 1. */
|
|
21
|
+
glow?: number;
|
|
22
|
+
/** How bright the rim line is; 0 for none. Default 1. */
|
|
23
|
+
rim?: number;
|
|
24
|
+
/** How fast the lights drift. Default 1. */
|
|
25
|
+
speed?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Starts radiant glass in `el`'s canvas. Returns a function that stops it. */
|
|
29
|
+
export function radiantGlass(el: HTMLElement, config: RadiantGlassConfig): () => void;
|