@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.
Files changed (314) hide show
  1. package/AGENTS.md +85 -0
  2. package/COMPONENTS.md +1264 -0
  3. package/LICENSE +139 -0
  4. package/README.md +197 -2
  5. package/package.json +60 -4
  6. package/src/components/AsciiRain.astro +36 -0
  7. package/src/components/BorderSweep.astro +39 -0
  8. package/src/components/Caustics.astro +39 -0
  9. package/src/components/ColorPanels.astro +62 -0
  10. package/src/components/Cursor.astro +97 -0
  11. package/src/components/DotGrid.astro +34 -0
  12. package/src/components/DotSurface.astro +35 -0
  13. package/src/components/EffectCanvas.astro +152 -0
  14. package/src/components/FitText.astro +35 -0
  15. package/src/components/FlutedGlass.astro +36 -0
  16. package/src/components/Glass.astro +69 -0
  17. package/src/components/GlassGlyph.astro +38 -0
  18. package/src/components/GlowField.astro +177 -0
  19. package/src/components/Grain.astro +98 -0
  20. package/src/components/HaloRing.astro +38 -0
  21. package/src/components/HighlightSweep.astro +74 -0
  22. package/src/components/ImageRipple.astro +56 -0
  23. package/src/components/Ink.astro +37 -0
  24. package/src/components/InkField.astro +45 -0
  25. package/src/components/IsoCity.astro +54 -0
  26. package/src/components/LightField.astro +40 -0
  27. package/src/components/LiquidMetal.astro +41 -0
  28. package/src/components/Magnetic.astro +52 -0
  29. package/src/components/Marquee.astro +216 -0
  30. package/src/components/MosaicReveal.astro +196 -0
  31. package/src/components/NebulaLogo.astro +38 -0
  32. package/src/components/NeonSwarm.astro +38 -0
  33. package/src/components/Ocean.astro +40 -0
  34. package/src/components/OutlineWordmark.astro +222 -0
  35. package/src/components/PaperBackground.astro +40 -0
  36. package/src/components/PaperShader.astro +55 -0
  37. package/src/components/Parallax.astro +49 -0
  38. package/src/components/ParticleLogo.astro +37 -0
  39. package/src/components/PixelGlitchText.astro +70 -0
  40. package/src/components/PointCloud.astro +37 -0
  41. package/src/components/ProductStack.astro +298 -0
  42. package/src/components/PulseMark.astro +189 -0
  43. package/src/components/RadiantGlass.astro +38 -0
  44. package/src/components/RainOnGlass.astro +71 -0
  45. package/src/components/Reveal.astro +115 -0
  46. package/src/components/ScrambleText.astro +52 -0
  47. package/src/components/ScrollReveal.astro +38 -0
  48. package/src/components/ShaderBackground.astro +55 -0
  49. package/src/components/SignalLines.astro +41 -0
  50. package/src/components/SilkRibbon.astro +37 -0
  51. package/src/components/SpotlightText.astro +131 -0
  52. package/src/components/Tilt.astro +79 -0
  53. package/src/components/Topography.astro +38 -0
  54. package/src/components/Typewriter.astro +66 -0
  55. package/src/components/VariableType.astro +59 -0
  56. package/src/components/VoxelLogo.astro +46 -0
  57. package/src/components/WaveBars.astro +41 -0
  58. package/src/components/WorldRoutes.astro +41 -0
  59. package/src/components/style.js +19 -0
  60. package/src/index.d.ts +143 -0
  61. package/src/index.js +105 -0
  62. package/src/runtime/ascii-rain.d.ts +53 -0
  63. package/src/runtime/ascii-rain.js +355 -0
  64. package/src/runtime/audio-meter.d.ts +65 -0
  65. package/src/runtime/audio-meter.js +282 -0
  66. package/src/runtime/audio.d.ts +26 -0
  67. package/src/runtime/audio.js +453 -0
  68. package/src/runtime/blur.d.ts +2 -0
  69. package/src/runtime/blur.js +56 -0
  70. package/src/runtime/canvas2d.d.ts +23 -0
  71. package/src/runtime/canvas2d.js +105 -0
  72. package/src/runtime/caustics.d.ts +40 -0
  73. package/src/runtime/caustics.js +286 -0
  74. package/src/runtime/color.d.ts +33 -0
  75. package/src/runtime/color.js +213 -0
  76. package/src/runtime/curl.d.ts +5 -0
  77. package/src/runtime/curl.js +81 -0
  78. package/src/runtime/cursor.d.ts +9 -0
  79. package/src/runtime/cursor.js +80 -0
  80. package/src/runtime/device.d.ts +14 -0
  81. package/src/runtime/device.js +73 -0
  82. package/src/runtime/dot-grid.d.ts +27 -0
  83. package/src/runtime/dot-grid.js +245 -0
  84. package/src/runtime/dot-surface.d.ts +46 -0
  85. package/src/runtime/dot-surface.js +429 -0
  86. package/src/runtime/feedback.d.ts +18 -0
  87. package/src/runtime/feedback.js +131 -0
  88. package/src/runtime/fit-text.d.ts +5 -0
  89. package/src/runtime/fit-text.js +60 -0
  90. package/src/runtime/fluid.d.ts +55 -0
  91. package/src/runtime/fluid.js +504 -0
  92. package/src/runtime/fluted-glass.d.ts +27 -0
  93. package/src/runtime/fluted-glass.js +157 -0
  94. package/src/runtime/gl.d.ts +19 -0
  95. package/src/runtime/gl.js +104 -0
  96. package/src/runtime/glass-glyph.d.ts +49 -0
  97. package/src/runtime/glass-glyph.js +355 -0
  98. package/src/runtime/glass-sheen.d.ts +2 -0
  99. package/src/runtime/glass-sheen.js +30 -0
  100. package/src/runtime/glsl.d.ts +17 -0
  101. package/src/runtime/glsl.js +78 -0
  102. package/src/runtime/glyphs.d.ts +22 -0
  103. package/src/runtime/glyphs.js +107 -0
  104. package/src/runtime/halo-ring.d.ts +47 -0
  105. package/src/runtime/halo-ring.js +334 -0
  106. package/src/runtime/height-field.d.ts +50 -0
  107. package/src/runtime/height-field.js +176 -0
  108. package/src/runtime/image-ripple.d.ts +25 -0
  109. package/src/runtime/image-ripple.js +353 -0
  110. package/src/runtime/image.d.ts +11 -0
  111. package/src/runtime/image.js +81 -0
  112. package/src/runtime/in-view.d.ts +6 -0
  113. package/src/runtime/in-view.js +36 -0
  114. package/src/runtime/ink-field/shaders.js +258 -0
  115. package/src/runtime/ink-field/sim.js +582 -0
  116. package/src/runtime/ink-field.d.ts +39 -0
  117. package/src/runtime/ink-field.js +311 -0
  118. package/src/runtime/ink.d.ts +31 -0
  119. package/src/runtime/ink.js +109 -0
  120. package/src/runtime/instancing.d.ts +12 -0
  121. package/src/runtime/instancing.js +37 -0
  122. package/src/runtime/iso-camera.d.ts +35 -0
  123. package/src/runtime/iso-camera.js +85 -0
  124. package/src/runtime/iso-city/figures.d.ts +30 -0
  125. package/src/runtime/iso-city/figures.js +136 -0
  126. package/src/runtime/iso-city/look.d.ts +34 -0
  127. package/src/runtime/iso-city/look.js +105 -0
  128. package/src/runtime/iso-city/plan.d.ts +59 -0
  129. package/src/runtime/iso-city/plan.js +463 -0
  130. package/src/runtime/iso-city/roads.d.ts +64 -0
  131. package/src/runtime/iso-city/roads.js +320 -0
  132. package/src/runtime/iso-city/scene.d.ts +27 -0
  133. package/src/runtime/iso-city/scene.js +432 -0
  134. package/src/runtime/iso-city/shaders.d.ts +6 -0
  135. package/src/runtime/iso-city/shaders.js +233 -0
  136. package/src/runtime/iso-city/shadows.d.ts +13 -0
  137. package/src/runtime/iso-city/shadows.js +148 -0
  138. package/src/runtime/iso-city/traffic.d.ts +80 -0
  139. package/src/runtime/iso-city/traffic.js +457 -0
  140. package/src/runtime/iso-city.d.ts +37 -0
  141. package/src/runtime/iso-city.js +458 -0
  142. package/src/runtime/lens-map.d.ts +11 -0
  143. package/src/runtime/lens-map.js +146 -0
  144. package/src/runtime/light-field.d.ts +29 -0
  145. package/src/runtime/light-field.js +292 -0
  146. package/src/runtime/liquid-glass.d.ts +48 -0
  147. package/src/runtime/liquid-glass.js +423 -0
  148. package/src/runtime/liquid-metal/beads.js +217 -0
  149. package/src/runtime/liquid-metal/field.js +88 -0
  150. package/src/runtime/liquid-metal/look.js +64 -0
  151. package/src/runtime/liquid-metal/shaders.js +255 -0
  152. package/src/runtime/liquid-metal/wave.js +53 -0
  153. package/src/runtime/liquid-metal.d.ts +46 -0
  154. package/src/runtime/liquid-metal.js +366 -0
  155. package/src/runtime/loop.d.ts +7 -0
  156. package/src/runtime/loop.js +112 -0
  157. package/src/runtime/magnetic.d.ts +9 -0
  158. package/src/runtime/magnetic.js +46 -0
  159. package/src/runtime/marquee.d.ts +2 -0
  160. package/src/runtime/marquee.js +27 -0
  161. package/src/runtime/mesh.d.ts +30 -0
  162. package/src/runtime/mesh.js +217 -0
  163. package/src/runtime/mosaic-reveal.d.ts +34 -0
  164. package/src/runtime/mosaic-reveal.js +504 -0
  165. package/src/runtime/motion.d.ts +2 -0
  166. package/src/runtime/motion.js +21 -0
  167. package/src/runtime/mount.d.ts +13 -0
  168. package/src/runtime/mount.js +120 -0
  169. package/src/runtime/nebula-logo.d.ts +31 -0
  170. package/src/runtime/nebula-logo.js +282 -0
  171. package/src/runtime/neon-swarm.d.ts +31 -0
  172. package/src/runtime/neon-swarm.js +258 -0
  173. package/src/runtime/ocean/presets.d.ts +54 -0
  174. package/src/runtime/ocean/presets.js +184 -0
  175. package/src/runtime/ocean/shader.d.ts +14 -0
  176. package/src/runtime/ocean/shader.js +389 -0
  177. package/src/runtime/ocean/view.d.ts +24 -0
  178. package/src/runtime/ocean/view.js +98 -0
  179. package/src/runtime/ocean/waves.d.ts +29 -0
  180. package/src/runtime/ocean/waves.js +119 -0
  181. package/src/runtime/ocean.d.ts +31 -0
  182. package/src/runtime/ocean.js +173 -0
  183. package/src/runtime/palettes.d.ts +37 -0
  184. package/src/runtime/palettes.js +75 -0
  185. package/src/runtime/paper-look.d.ts +42 -0
  186. package/src/runtime/paper-look.js +91 -0
  187. package/src/runtime/paper-looks.d.ts +17 -0
  188. package/src/runtime/paper-looks.js +21 -0
  189. package/src/runtime/paper.d.ts +37 -0
  190. package/src/runtime/paper.js +285 -0
  191. package/src/runtime/particle-logo.d.ts +31 -0
  192. package/src/runtime/particle-logo.js +196 -0
  193. package/src/runtime/ping-pong.d.ts +43 -0
  194. package/src/runtime/ping-pong.js +175 -0
  195. package/src/runtime/pixel-glitch.d.ts +17 -0
  196. package/src/runtime/pixel-glitch.js +287 -0
  197. package/src/runtime/point-cloud.d.ts +33 -0
  198. package/src/runtime/point-cloud.js +287 -0
  199. package/src/runtime/pointer.d.ts +27 -0
  200. package/src/runtime/pointer.js +128 -0
  201. package/src/runtime/points.d.ts +25 -0
  202. package/src/runtime/points.js +130 -0
  203. package/src/runtime/pools.d.ts +2 -0
  204. package/src/runtime/pools.js +25 -0
  205. package/src/runtime/product-stack.d.ts +24 -0
  206. package/src/runtime/product-stack.js +210 -0
  207. package/src/runtime/radiant-glass.d.ts +29 -0
  208. package/src/runtime/radiant-glass.js +282 -0
  209. package/src/runtime/rain-on-glass/backdrop.d.ts +22 -0
  210. package/src/runtime/rain-on-glass/backdrop.js +185 -0
  211. package/src/runtime/rain-on-glass/shader.d.ts +2 -0
  212. package/src/runtime/rain-on-glass/shader.js +168 -0
  213. package/src/runtime/rain-on-glass/wipe.d.ts +16 -0
  214. package/src/runtime/rain-on-glass/wipe.js +65 -0
  215. package/src/runtime/rain-on-glass.d.ts +27 -0
  216. package/src/runtime/rain-on-glass.js +210 -0
  217. package/src/runtime/ramp.d.ts +2 -0
  218. package/src/runtime/ramp.js +30 -0
  219. package/src/runtime/random.d.ts +2 -0
  220. package/src/runtime/random.js +22 -0
  221. package/src/runtime/scroll-reveal.d.ts +22 -0
  222. package/src/runtime/scroll-reveal.js +73 -0
  223. package/src/runtime/shader-background.d.ts +42 -0
  224. package/src/runtime/shader-background.js +261 -0
  225. package/src/runtime/shader-backgrounds/band-lens.js +72 -0
  226. package/src/runtime/shader-backgrounds/common.js +53 -0
  227. package/src/runtime/shader-backgrounds/grain-gradient.js +87 -0
  228. package/src/runtime/shader-backgrounds/grid.js +33 -0
  229. package/src/runtime/shader-backgrounds/mesh-gradient.js +74 -0
  230. package/src/runtime/shader-backgrounds/silk.js +57 -0
  231. package/src/runtime/shader-backgrounds/waves.js +31 -0
  232. package/src/runtime/shape.d.ts +42 -0
  233. package/src/runtime/shape.js +313 -0
  234. package/src/runtime/silk-ribbon.d.ts +23 -0
  235. package/src/runtime/silk-ribbon.js +206 -0
  236. package/src/runtime/slideshow.d.ts +27 -0
  237. package/src/runtime/slideshow.js +234 -0
  238. package/src/runtime/spotlight.d.ts +9 -0
  239. package/src/runtime/spotlight.js +97 -0
  240. package/src/runtime/stack-poses.d.ts +53 -0
  241. package/src/runtime/stack-poses.js +273 -0
  242. package/src/runtime/stage.d.ts +47 -0
  243. package/src/runtime/stage.js +187 -0
  244. package/src/runtime/swarm.d.ts +49 -0
  245. package/src/runtime/swarm.js +199 -0
  246. package/src/runtime/text-motion.d.ts +41 -0
  247. package/src/runtime/text-motion.js +165 -0
  248. package/src/runtime/text.d.ts +11 -0
  249. package/src/runtime/text.js +90 -0
  250. package/src/runtime/tilt.d.ts +19 -0
  251. package/src/runtime/tilt.js +116 -0
  252. package/src/runtime/topography.d.ts +71 -0
  253. package/src/runtime/topography.js +650 -0
  254. package/src/runtime/trackers.d.ts +21 -0
  255. package/src/runtime/trackers.js +76 -0
  256. package/src/runtime/variable-type.d.ts +43 -0
  257. package/src/runtime/variable-type.js +358 -0
  258. package/src/runtime/voxel-logo.d.ts +31 -0
  259. package/src/runtime/voxel-logo.js +237 -0
  260. package/src/runtime/waves.d.ts +70 -0
  261. package/src/runtime/waves.js +799 -0
  262. package/src/runtime/world-labels.d.ts +29 -0
  263. package/src/runtime/world-labels.js +59 -0
  264. package/src/runtime/world-land.d.ts +8 -0
  265. package/src/runtime/world-land.js +105 -0
  266. package/src/runtime/world-map.d.ts +69 -0
  267. package/src/runtime/world-map.js +308 -0
  268. package/src/runtime/world-plan.d.ts +101 -0
  269. package/src/runtime/world-plan.js +333 -0
  270. package/src/runtime/world-routes.d.ts +75 -0
  271. package/src/runtime/world-routes.js +673 -0
  272. package/src/styles/border-sweep.css +82 -0
  273. package/src/styles/glass.css +104 -0
  274. package/src/styles/motion.css +218 -0
  275. package/src/styles/reveal.css +51 -0
  276. package/src/vendor/paper/LICENSE +201 -0
  277. package/src/vendor/paper/NOTICE +5 -0
  278. package/src/vendor/paper/README.md +8 -0
  279. package/src/vendor/paper/get-shader-color-from-string.js +100 -0
  280. package/src/vendor/paper/get-shader-noise-texture.js +17 -0
  281. package/src/vendor/paper/presets.js +3678 -0
  282. package/src/vendor/paper/shader-sizing.js +37 -0
  283. package/src/vendor/paper/shader-utils.js +130 -0
  284. package/src/vendor/paper/shaders/color-panels.js +223 -0
  285. package/src/vendor/paper/shaders/dithering.js +270 -0
  286. package/src/vendor/paper/shaders/dot-grid.js +109 -0
  287. package/src/vendor/paper/shaders/dot-orbit.js +122 -0
  288. package/src/vendor/paper/shaders/fluted-glass.js +360 -0
  289. package/src/vendor/paper/shaders/gem-smoke.js +572 -0
  290. package/src/vendor/paper/shaders/god-rays.js +132 -0
  291. package/src/vendor/paper/shaders/grain-gradient.js +300 -0
  292. package/src/vendor/paper/shaders/halftone-cmyk.js +294 -0
  293. package/src/vendor/paper/shaders/halftone-dots.js +320 -0
  294. package/src/vendor/paper/shaders/heatmap.js +383 -0
  295. package/src/vendor/paper/shaders/image-dithering.js +198 -0
  296. package/src/vendor/paper/shaders/lens-distortion.js +275 -0
  297. package/src/vendor/paper/shaders/liquid-metal.js +632 -0
  298. package/src/vendor/paper/shaders/mesh-gradient.js +130 -0
  299. package/src/vendor/paper/shaders/metaballs.js +110 -0
  300. package/src/vendor/paper/shaders/neuro-noise.js +76 -0
  301. package/src/vendor/paper/shaders/paper-texture.js +526 -0
  302. package/src/vendor/paper/shaders/perlin-noise.js +166 -0
  303. package/src/vendor/paper/shaders/pulsing-border.js +238 -0
  304. package/src/vendor/paper/shaders/simplex-noise.js +91 -0
  305. package/src/vendor/paper/shaders/smoke-ring.js +132 -0
  306. package/src/vendor/paper/shaders/spiral.js +82 -0
  307. package/src/vendor/paper/shaders/static-mesh-gradient.js +130 -0
  308. package/src/vendor/paper/shaders/static-radial-gradient.js +187 -0
  309. package/src/vendor/paper/shaders/swirl.js +103 -0
  310. package/src/vendor/paper/shaders/voronoi.js +138 -0
  311. package/src/vendor/paper/shaders/warp.js +129 -0
  312. package/src/vendor/paper/shaders/water.js +121 -0
  313. package/src/vendor/paper/shaders/waves.js +65 -0
  314. package/src/vendor/paper/vertex-shader.js +159 -0
@@ -0,0 +1,287 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/point-cloud
3
+ *
4
+ * A machine-vision scene: a word drawn as a matrix of bright dots, floating
5
+ * among sheets of point cloud, each sheet a rippling surface scanned in
6
+ * rows of fine dots, coloured by height. The scene sways and tilts towards
7
+ * the pointer in perspective. Optionally (`trackers`), boxes lock onto
8
+ * parts of the word with confidence labels, like a detector's debug view.
9
+ *
10
+ * Positions are worked out on the GPU from each point's place on its sheet
11
+ * and a seed; tens of thousands of points cost one draw.
12
+ *
13
+ * Opaque: the effect is the whole background of what it fills. Without
14
+ * WebGL it removes its canvas and the element's background shows.
15
+ */
16
+
17
+ import { createStage } from './stage.js';
18
+ import { createPoints, projectPoint, GLSL_PROJECT } from './points.js';
19
+ import { drawShape, gridPoints } from './shape.js';
20
+ import { createTrackers } from './trackers.js';
21
+ import { parseColor } from './color.js';
22
+ import { canHover, isMobileGpu } from './device.js';
23
+ import { pointerIn } from './pointer.js';
24
+ import { watchColors } from './mount.js';
25
+ import { pickColors } from './palettes.js';
26
+
27
+ /**
28
+ * @typedef {object} PointCloudConfig
29
+ * @property {string} [text] The word drawn in dots.
30
+ * @property {string} [font] Its CSS font, without the size (default: the page's, bold).
31
+ * @property {string} [src] An image (an SVG logo) to draw in dots instead.
32
+ * @property {{ x: number, y: number, width: number, height: number }} [area]
33
+ * Where the word sits, each 0–1 from the top left (default: across the middle).
34
+ * @property {string[]} [colors] The word's dots, then the clouds' low and high colours (default white, deep blue, sky blue).
35
+ * @property {string} [palette] A shared palette by name (PALETTES; any case), when there are no `colors`.
36
+ * @property {string} [background='#020205'] The ground.
37
+ * @property {number} [columns=110] Dots across the word's grid.
38
+ * @property {number} [dot=0.72] A word dot's size, as a share of the grid's spacing.
39
+ * @property {number} [sheets=9] How many sheets of point cloud.
40
+ * @property {number} [pointSize=2.2] A cloud point's size, CSS px.
41
+ * @property {number} [trackers=0] Tracker boxes locking onto the word, a detector's debug look (try 4); 0 for none.
42
+ * @property {number} [tilt=1] How far the scene tilts towards the pointer.
43
+ */
44
+
45
+ /** The ground: near-black, a little lighter in the middle. */
46
+ const GROUND = `
47
+ precision highp float;
48
+ uniform vec2 uRes;
49
+ uniform vec3 uGround;
50
+ uniform vec3 uGlow;
51
+ void main() {
52
+ vec2 uv = gl_FragCoord.xy / uRes;
53
+ vec2 d = (uv - 0.5) * vec2(uRes.x / uRes.y, 1.0);
54
+ gl_FragColor = vec4(uGround + uGlow * exp(-dot(d, d) * 3.0) * 0.08, 1.0);
55
+ }
56
+ `;
57
+
58
+ /** Each point: a dot of the word (kind < 0), or a point on sheet `kind`. */
59
+ const VERTEX = `
60
+ precision highp float;
61
+ attribute vec4 p;
62
+ uniform vec2 uRes;
63
+ uniform float uTime;
64
+ uniform float uRatio;
65
+ uniform vec2 uShift;
66
+ uniform vec2 uTurn;
67
+ uniform vec3 uText;
68
+ uniform vec3 uLow;
69
+ uniform vec3 uHigh;
70
+ uniform float uTextSize;
71
+ uniform float uPointSize;
72
+ varying vec3 vColour;
73
+ varying float vAlpha;
74
+ ${GLSL_PROJECT}
75
+ float hash1(float n) { return fract(sin(n * 127.1) * 43758.5453); }
76
+ void main() {
77
+ float aspect = uRes.x / uRes.y;
78
+ vec3 v;
79
+ float size;
80
+ if (p.z < 0.0) {
81
+ // A dot of the word, trembling very slightly.
82
+ v = vec3((p.x * 2.0 - 1.0) * aspect, p.y * 2.0 - 1.0, 0.0);
83
+ v.xy += 0.002 * vec2(sin(uTime * 2.0 + p.w * 50.0), cos(uTime * 1.7 + p.w * 31.0));
84
+ vColour = uText;
85
+ vAlpha = 1.0;
86
+ size = uTextSize;
87
+ } else {
88
+ // A point on a sheet: the sheet's place, size and facing come from its index.
89
+ float k = p.z + 1.0;
90
+ vec3 centre = vec3((hash1(k * 1.3) - 0.5) * 2.2 * aspect, (hash1(k * 2.7) - 0.5) * 1.5, (hash1(k * 5.1) - 0.5) * 1.0);
91
+ centre.xy += vec2(sin(uTime * 0.05 + k), cos(uTime * 0.04 + k * 2.0)) * 0.12;
92
+ vec3 local = vec3((p.x - 0.5) * (1.4 + hash1(k * 7.7) * 1.4), (p.y - 0.5) * (0.6 + hash1(k * 9.1) * 0.8), 0.0);
93
+ float wave = sin(p.x * 6.0 + uTime * 0.35 + k) * cos(p.y * 5.0 - uTime * 0.27 + k * 2.0) * 0.22
94
+ + sin((p.x + p.y) * 11.0 + k * 3.0 + uTime * 0.2) * 0.06;
95
+ local.z = wave;
96
+ local = rotateX(local, hash1(k * 3.3) * 2.4 - 1.2);
97
+ local = rotateY(local, hash1(k * 4.4) * 3.0 - 1.5);
98
+ v = centre + local;
99
+ vColour = mix(uLow, uHigh, clamp(wave * 2.2 + 0.5, 0.0, 1.0));
100
+ // Thinning out towards the sheet's edges, so it has no hard border.
101
+ vAlpha = 0.95 * smoothstep(0.0, 0.18, p.x) * smoothstep(1.0, 0.82, p.x) * smoothstep(0.0, 0.25, p.y) * smoothstep(1.0, 0.75, p.y);
102
+ size = uPointSize * (0.75 + hash1(p.w * 91.0) * 0.5);
103
+ }
104
+ v = rotateY(v, uTurn.x);
105
+ v = rotateX(v, uTurn.y);
106
+ vec4 pos = project(v, aspect);
107
+ gl_Position = pos + vec4(uShift * pos.w, 0.0, 0.0);
108
+ gl_PointSize = size * uRatio / pos.w;
109
+ vAlpha *= clamp(1.25 - pos.w * 0.35, 0.25, 1.0);
110
+ }
111
+ `;
112
+
113
+ /** The defaults: white dots, deep and sky blue clouds. */
114
+ const COLORS = ['#ffffff', '#2a2aff', '#7cc8ff'];
115
+
116
+ /**
117
+ * The sheets of point cloud as particle data: a grid of points per sheet,
118
+ * each with its place on the sheet, the sheet's index and a seed.
119
+ *
120
+ * @param {number} sheets How many sheets.
121
+ * @param {number} columns Points across a sheet.
122
+ * @param {number} rows Rows down a sheet.
123
+ * @returns {number[]} Four numbers a point.
124
+ */
125
+ function sheetData(sheets, columns, rows) {
126
+ const out = [];
127
+ for (let k = 0; k < sheets; k++) {
128
+ for (let r = 0; r < rows; r++) {
129
+ for (let c = 0; c < columns; c++) out.push(c / (columns - 1), r / (rows - 1), k, Math.random());
130
+ }
131
+ }
132
+ return out;
133
+ }
134
+
135
+ /**
136
+ * Starts a point cloud on an element: an opaque canvas inside it, filling it.
137
+ *
138
+ * @param {HTMLElement} el The element (its first canvas is drawn into).
139
+ * @param {PointCloudConfig} config The settings.
140
+ * @returns {() => void} Stops it.
141
+ */
142
+ export function pointCloud(el, config) {
143
+ let colors = pickColors(config, COLORS, (p) => ['#ffffff', p.colors[0], p.colors[1]]);
144
+ const start = performance.now();
145
+ const turn = { y: 0, x: 0 };
146
+ /** @type {import('./points.js').Points | null} */
147
+ let points = null;
148
+ /** The word's dots (x, y pairs, 0–1, y up), for the trackers to lock onto. */
149
+ /** @type {Float32Array} */
150
+ let dots = new Float32Array(0);
151
+ let generation = 0;
152
+ const sheets = sheetData(config.sheets ?? 9, isMobileGpu() ? 100 : 170, isMobileGpu() ? 40 : 70);
153
+ const trackers = (config.trackers ?? 0) > 0 ? createTrackers(el, config.trackers ?? 0) : null;
154
+ /** What each tracker is locked onto: a box of the word in 0–1 coordinates, its label, and when it moves on. */
155
+ const locks = Array.from({ length: config.trackers ?? 0 }, () => ({ box: [0, 0, 0, 0], label: '', until: 0 }));
156
+
157
+ /**
158
+ * Locks a tracker onto a cluster of the word's dots: a random dot and its
159
+ * neighbours, boxed.
160
+ *
161
+ * @param {typeof locks[number]} lock The tracker's lock.
162
+ * @param {number} t The time, seconds.
163
+ */
164
+ const relock = (lock, t) => {
165
+ lock.until = t + 2 + Math.random() * 2.5;
166
+ const n = dots.length / 2;
167
+ if (!n) return;
168
+ // A dot well away from where the other trackers are, so they do not pile up.
169
+ let i = 0;
170
+ for (let tries = 0; tries < 24; tries++) {
171
+ i = Math.floor(Math.random() * n);
172
+ const x = dots[i * 2];
173
+ if (locks.every((other) => other === lock || Math.abs((other.box[0] + other.box[2]) / 2 - x) > 0.16)) break;
174
+ }
175
+ const cx = dots[i * 2];
176
+ const cy = dots[i * 2 + 1];
177
+ const reach = 0.05 + Math.random() * 0.06;
178
+ let [x0, y0, x1, y1] = [cx, cy, cx, cy];
179
+ for (let j = 0; j < n; j++) {
180
+ const x = dots[j * 2];
181
+ const y = dots[j * 2 + 1];
182
+ if (Math.abs(x - cx) < reach && Math.abs(y - cy) < reach * 1.6) {
183
+ x0 = Math.min(x0, x);
184
+ y0 = Math.min(y0, y);
185
+ x1 = Math.max(x1, x);
186
+ y1 = Math.max(y1, y);
187
+ }
188
+ }
189
+ lock.box = [x0 - 0.01, y0 - 0.015, x1 + 0.01, y1 + 0.015];
190
+ lock.label = `${Math.round(70 + Math.random() * 29)}%`;
191
+ };
192
+
193
+ const { stage, stop } = createStage(el, {
194
+ fragment: GROUND,
195
+ alpha: false,
196
+ setup({ gl, program }) {
197
+ points = createPoints(gl, VERTEX);
198
+ if (!points) return false;
199
+ gl.useProgram(program);
200
+ return () => trackers?.destroy();
201
+ },
202
+ resize({ canvas }) {
203
+ const mine = ++generation;
204
+ const width = Math.min(1024, canvas.width);
205
+ const height = Math.max(1, Math.round((width * canvas.height) / canvas.width));
206
+ drawShape(
207
+ { text: config.text, font: config.font, src: config.src, area: config.area ?? { x: 0.08, y: 0.3, width: 0.84, height: 0.3 }, padding: 0.02 },
208
+ width,
209
+ height,
210
+ )
211
+ .then((mask) => {
212
+ if (mine !== generation || !points) return;
213
+ dots = gridPoints(mask, Math.round((config.columns ?? 110) / (config.area?.width ?? 0.84)));
214
+ const data = new Float32Array(sheets.length + (dots.length / 2) * 4);
215
+ data.set(sheets);
216
+ for (let i = 0; i < dots.length / 2; i++) {
217
+ data.set([dots[i * 2], dots[i * 2 + 1], -1, Math.random()], sheets.length + i * 4);
218
+ }
219
+ points.upload(data);
220
+ locks.forEach((lock) => (lock.until = 0));
221
+ if (stage?.still) stage.redraw();
222
+ })
223
+ .catch((error) => console.warn('[effects-astro]', error));
224
+ },
225
+ uniforms({ gl, uniform }) {
226
+ gl.uniform3fv(uniform('uGround'), parseColor(config.background ?? '#020205'));
227
+ gl.uniform3fv(uniform('uGlow'), parseColor(colors[2] ?? COLORS[2]));
228
+ },
229
+ after({ gl, canvas, ratio, still }, now) {
230
+ if (!points?.count()) return;
231
+ const t = (now - start) / 1000;
232
+ const p = !still && canHover() ? pointerIn(el) : null;
233
+ const lean = p?.inside ? { x: (p.x - 0.5) * 2, y: (p.y - 0.5) * 2 } : { x: 0, y: 0 };
234
+ const tilt = config.tilt ?? 1;
235
+ turn.y += (lean.x * 0.3 * tilt + Math.sin(t * 0.1) * 0.08 - turn.y) * 0.05;
236
+ turn.x += (-lean.y * 0.2 * tilt - turn.x) * 0.05;
237
+ const u = points.program.uniform;
238
+ points.passes(0, () => {
239
+ gl.uniform2f(u('uRes'), canvas.width, canvas.height);
240
+ gl.uniform1f(u('uTime'), t);
241
+ gl.uniform1f(u('uRatio'), ratio);
242
+ gl.uniform2f(u('uTurn'), turn.y, turn.x);
243
+ gl.uniform3fv(u('uText'), parseColor(colors[0]));
244
+ gl.uniform3fv(u('uLow'), parseColor(colors[1] ?? COLORS[1]));
245
+ gl.uniform3fv(u('uHigh'), parseColor(colors[2] ?? COLORS[2]));
246
+ // A word dot: a share of the grid's spacing, in CSS px.
247
+ gl.uniform1f(u('uTextSize'), Math.max(2, (canvas.width / ratio / ((config.columns ?? 110) / (config.area?.width ?? 0.84))) * (config.dot ?? 0.72)));
248
+ gl.uniform1f(u('uPointSize'), config.pointSize ?? 2.2);
249
+ });
250
+
251
+ // The trackers, boxed over the word where the shader draws it.
252
+ if (!trackers) return;
253
+ const aspect = canvas.width / canvas.height;
254
+ const w = el.clientWidth;
255
+ const h = el.clientHeight;
256
+ locks.forEach((lock, i) => {
257
+ if (t > lock.until) relock(lock, t);
258
+ if (!dots.length) return trackers.place(i, null);
259
+ const [x0, y0, x1, y1] = lock.box;
260
+ /**
261
+ * Where a point of the word lands on screen.
262
+ *
263
+ * @param {number} x Across the word's canvas, 0–1.
264
+ * @param {number} y Up it, 0–1.
265
+ * @returns {{ x: number, y: number }} 0–1 from the top left.
266
+ */
267
+ const corner = (x, y) => projectPoint([(x * 2 - 1) * aspect, y * 2 - 1, 0], turn.y, turn.x, aspect);
268
+ const a = corner(x0, y1);
269
+ const b = corner(x1, y0);
270
+ trackers.place(i, { x: a.x * w, y: a.y * h, w: (b.x - a.x) * w, h: (b.y - a.y) * h }, lock.label);
271
+ });
272
+ },
273
+ });
274
+ if (!stage) {
275
+ trackers?.destroy();
276
+ return stop;
277
+ }
278
+
279
+ const unwatch = watchColors(el, (next) => {
280
+ colors = next.colors;
281
+ if (stage.still) stage.redraw();
282
+ });
283
+ return () => {
284
+ stop();
285
+ unwatch();
286
+ };
287
+ }
@@ -0,0 +1,27 @@
1
+ /** A point on a stroke: where (0–1 across, 0–1 up the element) and the stroke's velocity (element sizes a second). */
2
+ export interface StrokePoint {
3
+ x: number;
4
+ y: number;
5
+ dx: number;
6
+ dy: number;
7
+ }
8
+
9
+ /** Where the pointer is over `el`: x 0–1 left to right, y 0–1 bottom to top; `inside` false outside it or the window. */
10
+ export function pointerIn(el: Element): { x: number; y: number; inside: boolean };
11
+
12
+ /**
13
+ * Follows the pointer's strokes over `el`. `read(dt)` returns the points
14
+ * along the path since the last read, spaced at most `step` apart (default
15
+ * 0.01), at most `max` of them (default 16); a jump returns none.
16
+ * `reset()` makes the next move start a new stroke.
17
+ */
18
+ export function trail(el: Element, options?: { step?: number; max?: number }): {
19
+ read(dt: number): StrokePoint[];
20
+ reset(): void;
21
+ };
22
+
23
+ /** Links, buttons, form fields and `[data-effect-ignore]`: presses on these are not an effect's. */
24
+ export const CLICK_IGNORE: string;
25
+
26
+ /** Where a press landed on `el` (x 0–1 left to right, y 0–1 bottom to top), or null outside it or on an ignored target. */
27
+ export function pressAt(el: Element, e: PointerEvent, ignore?: string): { x: number; y: number } | null;
@@ -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,2 @@
1
+ /** Three colours (looped from those given) as soft pools of light over `ground`: a CSS `background` for a light effect without WebGL. */
2
+ export function colorPools(colors: string[], ground: string): string;
@@ -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;