@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.
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 +303 -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,157 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/fluted-glass
3
+ *
4
+ * A pane of fluted glass over soft blooms of colour: the flutes run on a
5
+ * slant, each nearly flat across its middle and bending hard at its seams,
6
+ * so a bloom breaks into slices that slide as it moves. Red, green and
7
+ * blue bend by slightly different amounts, so every seam carries a thin
8
+ * rainbow, and a glossy highlight runs along each flute.
9
+ *
10
+ * The flute geometry and its highlight are adapted from shaders.com's
11
+ * FlutedGlass component (MIT, © 2026 Shader Effects Inc.; see LICENSE).
12
+ *
13
+ * The main bloom follows the pointer; two more drift on their own. On a
14
+ * light ground it reads as a gallery-white studio pane; on a dark one, as
15
+ * stage light through glass.
16
+ *
17
+ * Opaque: the effect is the whole background of what it fills. Without
18
+ * WebGL it removes its canvas and the element's background shows.
19
+ */
20
+
21
+ import { createStage } from './stage.js';
22
+ import { parseColor } from './color.js';
23
+ import { canHover } from './device.js';
24
+ import { pointerIn } from './pointer.js';
25
+ import { watchColors } from './mount.js';
26
+ import { GLSL_NOISE } from './glsl.js';
27
+ import { pickColors } from './palettes.js';
28
+
29
+ /**
30
+ * @typedef {object} FlutedGlassConfig
31
+ * @property {string[]} [colors] The blooms' colours: the one that follows the pointer first (default indigo, violet, pink).
32
+ * @property {string} [palette] A shared palette by name (PALETTES; any case), when there are no `colors`.
33
+ * @property {string} [background='#f4f4f5'] The ground behind the glass.
34
+ * @property {number} [angle=-35] The flutes' slant, in degrees from vertical.
35
+ * @property {number} [frequency=9] Flutes across the longer side.
36
+ * @property {number} [softness=0.5] 0: flat flutes with sharp seams; 1: a gentle curve all across.
37
+ * @property {number} [refraction=1.5] How hard each flute bends what is behind it.
38
+ * @property {number} [dispersion=0.6] How far the colours part at the seams; 0 for none.
39
+ * @property {number} [highlight=0.35] The highlight along each flute; 0 for none.
40
+ * @property {number} [bloom=1] How strong the blooms are.
41
+ */
42
+
43
+ const FRAG = `
44
+ precision highp float;
45
+ uniform vec2 uRes;
46
+ uniform float uTime;
47
+ uniform vec2 uPtr;
48
+ uniform vec3 uGround;
49
+ uniform vec3 uBloom[3];
50
+ uniform float uStrength;
51
+ uniform vec2 uRibDir;
52
+ uniform float uFrequency;
53
+ uniform float uSoftness;
54
+ uniform float uRefraction;
55
+ uniform float uDispersion;
56
+ uniform float uHighlight;
57
+ ${GLSL_NOISE}
58
+
59
+ // What is behind the glass: the ground and three soft blooms.
60
+ vec3 behind(vec2 uv) {
61
+ vec2 aspect = vec2(uRes.x / uRes.y, 1.0);
62
+ vec2 a = (uv - uPtr) * aspect;
63
+ vec2 b = (uv - vec2(0.3 + 0.2 * sin(uTime * 0.13), 0.65 + 0.15 * cos(uTime * 0.11))) * aspect;
64
+ vec2 c = (uv - vec2(0.8 + 0.12 * cos(uTime * 0.09), 0.2 + 0.12 * sin(uTime * 0.15))) * aspect;
65
+ float wa = exp(-dot(a, a) * 11.0) * 0.8;
66
+ float wb = exp(-dot(b, b) * 6.0) * 0.35;
67
+ float wc = exp(-dot(c, c) * 7.0) * 0.3;
68
+ vec3 col = uGround;
69
+ col = mix(col, uBloom[0], clamp(wa * uStrength, 0.0, 1.0));
70
+ col = mix(col, uBloom[1], clamp(wb * uStrength, 0.0, 1.0));
71
+ col = mix(col, uBloom[2], clamp(wc * uStrength, 0.0, 1.0));
72
+ // Soft shadows drifting through, so the white is never flat and the
73
+ // flutes have something to bend.
74
+ col *= 1.0 - 0.14 * smoothstep(0.35, 0.8, noise(uv * vec2(2.2, 1.6) + uTime * 0.03));
75
+ col *= 1.0 - 0.06 * smoothstep(0.5, 0.9, noise(uv * 5.0 - uTime * 0.05 + 3.0));
76
+ return col;
77
+ }
78
+
79
+ void main() {
80
+ vec2 uv = gl_FragCoord.xy / uRes;
81
+ float aspect = uRes.x / uRes.y;
82
+ // Across the flutes, in a square frame centred on the canvas.
83
+ vec2 centred = vec2((uv.x - 0.5) * aspect, uv.y - 0.5);
84
+ float across = dot(centred, uRibDir);
85
+ float cell = (fract(across * uFrequency) - 0.5) * 2.0;
86
+ // The flute's slope: near flat across the middle, steep at the seams.
87
+ float slope = sign(cell) * pow(max(abs(cell), 1e-4), mix(8.0, 3.0, uSoftness));
88
+ float shift = -slope * uRefraction * 0.5 / uFrequency;
89
+ vec2 refracted = uv + vec2(shift * uRibDir.x / aspect, shift * uRibDir.y);
90
+ vec2 split = vec2(shift * uRibDir.x / aspect, shift * uRibDir.y) * uDispersion * 0.5;
91
+ vec3 col = vec3(behind(refracted + split).r, behind(refracted).g, behind(refracted - split).b);
92
+ // A glossy highlight: Blinn over the flute's slope, stronger where it turns away.
93
+ float nz = sqrt(1.0 - min(slope * slope, 1.0));
94
+ float nDotH = max(slope * sin(0.2618) + nz * cos(0.2618), 0.0);
95
+ float fresnel = 0.04 + 0.96 * pow(1.0 - nz, 5.0);
96
+ col += pow(nDotH, 24.0) * fresnel * uHighlight * 3.0 + pow(nDotH, 160.0) * uHighlight * 0.25;
97
+ col += (hash(gl_FragCoord.xy + fract(uTime)) - 0.5) * 0.012;
98
+ gl_FragColor = vec4(col, 1.0);
99
+ }
100
+ `;
101
+
102
+ /** The default blooms: blue, cyan, amber. */
103
+ const COLORS = ['#2563eb', '#06b6d4', '#f59e0b'];
104
+
105
+ /**
106
+ * Starts fluted glass on an element: an opaque canvas inside it, filling it.
107
+ *
108
+ * @param {HTMLElement} el The element (its first canvas is drawn into).
109
+ * @param {FlutedGlassConfig} config The settings.
110
+ * @returns {() => void} Stops it.
111
+ */
112
+ export function flutedGlass(el, config) {
113
+ let colors = pickColors(config, COLORS);
114
+ const start = performance.now();
115
+ const ptr = { x: 0.62, y: 0.55 };
116
+
117
+ const { stage, stop } = createStage(el, {
118
+ fragment: FRAG,
119
+ alpha: false,
120
+ setup({ gl, uniform }) {
121
+ const angle = ((config.angle ?? -35) * Math.PI) / 180;
122
+ // The direction across the flutes: the flutes themselves run at `angle` from vertical.
123
+ gl.uniform2f(uniform('uRibDir'), Math.cos(angle), Math.sin(angle));
124
+ gl.uniform3fv(uniform('uGround'), parseColor(config.background ?? '#f4f4f5'));
125
+ gl.uniform1f(uniform('uStrength'), config.bloom ?? 1);
126
+ gl.uniform1f(uniform('uRefraction'), config.refraction ?? 1.5);
127
+ gl.uniform1f(uniform('uDispersion'), config.dispersion ?? 0.6);
128
+ gl.uniform1f(uniform('uSoftness'), config.softness ?? 0.5);
129
+ gl.uniform1f(uniform('uHighlight'), config.highlight ?? 0.35);
130
+ },
131
+ resize({ gl, uniform, canvas }) {
132
+ // Flutes across the longer side, measured in the square frame the shader works in.
133
+ const longer = Math.max(canvas.width, canvas.height) / canvas.height;
134
+ gl.uniform1f(uniform('uFrequency'), (config.frequency ?? 9) / longer);
135
+ },
136
+ uniforms({ gl, uniform, still }, now) {
137
+ const t = (now - start) / 1000;
138
+ const p = !still && canHover() ? pointerIn(el) : null;
139
+ const goal = p?.inside ? p : { x: 0.62 + Math.sin(t * 0.2) * 0.1, y: 0.55 + Math.cos(t * 0.17) * 0.1 };
140
+ ptr.x += (goal.x - ptr.x) * 0.04;
141
+ ptr.y += (goal.y - ptr.y) * 0.04;
142
+ gl.uniform1f(uniform('uTime'), t);
143
+ gl.uniform2f(uniform('uPtr'), ptr.x, ptr.y);
144
+ gl.uniform3fv(uniform('uBloom'), new Float32Array([0, 1, 2].flatMap((i) => parseColor(colors[i % colors.length]))));
145
+ },
146
+ });
147
+ if (!stage) return stop;
148
+
149
+ const unwatch = watchColors(el, (next) => {
150
+ colors = next.colors;
151
+ if (stage.still) stage.redraw();
152
+ });
153
+ return () => {
154
+ stop();
155
+ unwatch();
156
+ };
157
+ }
@@ -0,0 +1,19 @@
1
+ export type GL = WebGLRenderingContext | WebGL2RenderingContext;
2
+
3
+ /** A linked program and a cached uniform lookup. */
4
+ export interface Program {
5
+ program: WebGLProgram;
6
+ uniform(name: string): WebGLUniformLocation | null;
7
+ }
8
+
9
+ /** A WebGL 2 context, or WebGL 1 when `webgl1` (default true) and WebGL 2 is missing. Antialiasing off by default. */
10
+ export function getContext(canvas: HTMLCanvasElement, attributes?: WebGLContextAttributes, webgl1?: boolean): GL | null;
11
+
12
+ /** Compiles and links a program with `p` at attribute 0; null (reason in the console) on failure. */
13
+ export function createProgram(gl: GL, vertex: string, fragment: string): Program | null;
14
+
15
+ /** Makes (or binds again) the full-screen triangle buffer and points attribute 0 at it. */
16
+ export function bindTriangle(gl: GL, buffer?: WebGLBuffer): WebGLBuffer;
17
+
18
+ /** A vertex shader giving `vUv`, 0–1 across the target. */
19
+ export const VERTEX: string;
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/gl
3
+ *
4
+ * The WebGL plumbing every effect shares: getting a context, compiling a
5
+ * program, and the one full-screen triangle each pass draws.
6
+ *
7
+ * Every program reads its single attribute, `p` (clip-space position), at
8
+ * location 0, so passes from different modules can share one buffer.
9
+ */
10
+
11
+ /** The triangle that covers clip space: three corners, one draw. */
12
+ const TRIANGLE = new Float32Array([-1, -1, 3, -1, -1, 3]);
13
+
14
+ /**
15
+ * Gets a WebGL context, WebGL 2 first.
16
+ *
17
+ * @param {HTMLCanvasElement} canvas The canvas.
18
+ * @param {WebGLContextAttributes} [attributes] Context attributes;
19
+ * antialiasing is off by default (full-screen shaders do not need it).
20
+ * @param {boolean} [webgl1=true] Fall back to WebGL 1 without WebGL 2.
21
+ * @returns {WebGL2RenderingContext | WebGLRenderingContext | null} The context.
22
+ */
23
+ export function getContext(canvas, attributes = {}, webgl1 = true) {
24
+ const options = { antialias: false, powerPreference: 'low-power', ...attributes };
25
+ return /** @type {WebGL2RenderingContext | WebGLRenderingContext | null} */ (canvas.getContext('webgl2', options) ?? (webgl1 ? canvas.getContext('webgl', options) : null));
26
+ }
27
+
28
+ /**
29
+ * Compiles and links a program, with `p` at attribute 0.
30
+ *
31
+ * @param {WebGLRenderingContext | WebGL2RenderingContext} gl The context.
32
+ * @param {string} vertex The vertex shader.
33
+ * @param {string} fragment The fragment shader.
34
+ * @returns {{ program: WebGLProgram, uniform: (name: string) => WebGLUniformLocation | null } | null}
35
+ * The program and a uniform lookup, or null with the reason in the console.
36
+ */
37
+ export function createProgram(gl, vertex, fragment) {
38
+ const program = gl.createProgram();
39
+ if (!program) return null;
40
+ /** @type {[number, string][]} */
41
+ const stages = [
42
+ [gl.VERTEX_SHADER, vertex],
43
+ [gl.FRAGMENT_SHADER, fragment],
44
+ ];
45
+ for (const [type, source] of stages) {
46
+ const shader = gl.createShader(type);
47
+ if (!shader) return null;
48
+ gl.shaderSource(shader, source);
49
+ gl.compileShader(shader);
50
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
51
+ console.warn('[effects-astro]', gl.getShaderInfoLog(shader));
52
+ return null;
53
+ }
54
+ gl.attachShader(program, shader);
55
+ }
56
+ gl.bindAttribLocation(program, 0, 'p');
57
+ gl.linkProgram(program);
58
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
59
+ console.warn('[effects-astro]', gl.getProgramInfoLog(program));
60
+ return null;
61
+ }
62
+ /** @type {Map<string, WebGLUniformLocation | null>} */
63
+ const cache = new Map();
64
+ return {
65
+ program,
66
+ uniform(name) {
67
+ if (!cache.has(name)) cache.set(name, gl.getUniformLocation(program, name));
68
+ return cache.get(name) ?? null;
69
+ },
70
+ };
71
+ }
72
+
73
+ /**
74
+ * Makes the full-screen triangle's buffer and points attribute 0 at it.
75
+ * Call again before drawing whenever another module may have bound its own.
76
+ *
77
+ * @param {WebGLRenderingContext | WebGL2RenderingContext} gl The context.
78
+ * @param {WebGLBuffer} [buffer] A buffer made by an earlier call, to bind again.
79
+ * @returns {WebGLBuffer} The buffer.
80
+ */
81
+ export function bindTriangle(gl, buffer) {
82
+ let b = buffer;
83
+ if (!b) {
84
+ b = /** @type {WebGLBuffer} */ (gl.createBuffer());
85
+ gl.bindBuffer(gl.ARRAY_BUFFER, b);
86
+ gl.bufferData(gl.ARRAY_BUFFER, TRIANGLE, gl.STATIC_DRAW);
87
+ } else {
88
+ gl.bindBuffer(gl.ARRAY_BUFFER, b);
89
+ }
90
+ gl.enableVertexAttribArray(0);
91
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
92
+ return b;
93
+ }
94
+
95
+ /** The vertex shader most passes need: clip-space position, and `vUv` 0–1. */
96
+ export const VERTEX = `
97
+ precision highp float;
98
+ attribute vec2 p;
99
+ varying vec2 vUv;
100
+ void main() {
101
+ vUv = p * 0.5 + 0.5;
102
+ gl_Position = vec4(p, 0.0, 1.0);
103
+ }
104
+ `;
@@ -0,0 +1,49 @@
1
+ import type { PaletteName } from './palettes.js';
2
+
3
+ export interface GlassGlyphConfig {
4
+ /** The character or word to make of glass. */
5
+ text?: string;
6
+ /** Its CSS font, without the size. Default: the page's, bold. */
7
+ font?: string;
8
+ /** An image (an SVG logo) to make of glass instead. */
9
+ src?: string;
10
+ /** Where the shape sits, each 0–1 from the top left. Default the right half. */
11
+ area?: { x: number; y: number; width: number; height: number };
12
+ /** Where the beams of light cross, each 0–1 from the top left. Default two fifths of the way into the shape's area, a little below its middle. */
13
+ light?: { x: number; y: number };
14
+ /** The light's colour, then the glass's tint. Default acid green, white. */
15
+ colors?: string[];
16
+ /** A shared palette by name (`PALETTES`, any case), when there are no `colors`. */
17
+ palette?: PaletteName | (string & {});
18
+ /** The ground. Default `#050505`. */
19
+ background?: string;
20
+ /** How hard the glass bends what is behind it, most of all across its bevels, 0–2. Default 1. */
21
+ refraction?: number;
22
+ /** How wide the bevel round the edge is, a share of the height, 0.01–0.1. Default 0.035. */
23
+ thickness?: number;
24
+ /** How much the glass magnifies the light behind it, 1–1.3. Default 1.04. */
25
+ zoom?: number;
26
+ /** How far the colours part where it bends, 0–2; 0 for none. Default 0.6. */
27
+ aberration?: number;
28
+ /** Frosted glass: how much more the light through it is blurred, 0–1. Default 0. */
29
+ frost?: number;
30
+ /** How much the glass takes the tint colour, 0–1. Default 0.1. */
31
+ tint?: number;
32
+ /** The lit rims and the glints, 0–2. Default 0.8. */
33
+ highlight?: number;
34
+ /** How much the bevels mirror the light, 0–1. Default 0.5. */
35
+ fresnel?: number;
36
+ /** Where the light on the rims comes from, degrees, 0–360 (0 right, 90 top). Default 135. */
37
+ lightAngle?: number;
38
+ /** How strong the coloured light is, 0–2. Default 1. */
39
+ glow?: number;
40
+ /** How much of the light shows outside the glass, 0–1: 0 is a black ground, 1 the full beams. Default 0.1. */
41
+ ambient?: number;
42
+ /** Dither the light outside the glass into dots where it fades. Default false. */
43
+ halftone?: boolean;
44
+ /** How far the slab turns on its own and away from the pointer, 0–2; 0 holds it still. Default 1. */
45
+ sway?: number;
46
+ }
47
+
48
+ /** Starts glass in `el`'s canvas. Returns a function that stops it. */
49
+ export function glassGlyph(el: HTMLElement, config: GlassGlyphConfig): () => void;