@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,334 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/halo-ring
3
+ *
4
+ * A ring of light on a dark ground: a soft-cornered outline, sized to the
5
+ * element with a margin, whose bright core line bleeds a little light
6
+ * inward and a long glow outward into a wide, soft bloom. Colour travels
7
+ * around it, looping through three colours in Oklab, while brighter and
8
+ * dimmer stretches drift along it at their own pace, so the hottest
9
+ * passages burn through to white.
10
+ *
11
+ * The outline is a rounded polygon of six corners: a hexagon, a
12
+ * rectangle fitted to the element (with a corner at the middle of each
13
+ * side), or (the default) a slow drift between the hexagon and a squarer
14
+ * rectangle, its corners breathing a little and the whole turning as it
15
+ * goes; or a circle. Its light is summed in linear light and exposed, so
16
+ * the brightest stretches saturate to white rather than clip. The pointer
17
+ * draws the ring a touch towards it, bends the nearest corner its way and
18
+ * lights the stretch nearest it.
19
+ *
20
+ * One full-screen pass with a six-step loop for the distance; sizes are
21
+ * worked out in device pixels, so the line stays crisp at any size or
22
+ * pixel ratio. With prefers-reduced-motion, one still frame.
23
+ *
24
+ * Opaque: the effect is the whole background of what it fills. Without
25
+ * WebGL it removes its canvas and the element's background shows.
26
+ */
27
+
28
+ import { createStage } from './stage.js';
29
+ import { parseColor } from './color.js';
30
+ import { GLSL_NOISE, GLSL_PALETTE, GLSL_QUIET, paletteUniform, quietUniform } from './glsl.js';
31
+ import { canHover } from './device.js';
32
+ import { pointerIn } from './pointer.js';
33
+ import { watchColors } from './mount.js';
34
+ import { pickColors } from './palettes.js';
35
+
36
+ /**
37
+ * @typedef {'morph' | 'hexagon' | 'rect' | 'circle'} HaloShape
38
+ */
39
+
40
+ /**
41
+ * @typedef {object} HaloRingConfig
42
+ * @property {string[]} [colors] Three colours looped around the ring, blended in Oklab (default amber, coral, electric blue).
43
+ * @property {string} [palette] A shared palette by name (PALETTES; any case), when there are no `colors`.
44
+ * @property {HaloShape} [shape='morph'] The outline: a rounded hexagon, a rounded rectangle fitted to the element, a circle, or a slow drift between the hexagon and a squarer rectangle.
45
+ * @property {number} [corner=0.3] How round the corners are: 0 sharp, 1 as round as they go.
46
+ * @property {number} [margin=0.05] Space between the ring and the element's edge, a share of its shorter side.
47
+ * @property {number} [thickness=10] The bright core line, CSS px.
48
+ * @property {number} [glow=1] How far and how strongly the light spreads; 0 for the bare line.
49
+ * @property {number} [speed=1] How fast the colour travels and the shape drifts; 0 holds it still.
50
+ * @property {string} [background='#0d0c10'] The ground.
51
+ * @property {boolean} [interactive=true] Whether the ring leans towards the pointer and lights up near it.
52
+ * @property {{ x?: number, y?: number, radius?: number, depth?: number } | null} [quiet=null]
53
+ * An area kept dim behind copy: centre (0–1 from the top left), radius (a
54
+ * share of the height) and depth (0–1). The middle with `{}`.
55
+ */
56
+
57
+ /** The default colours: amber, coral and electric blue. */
58
+ const COLORS = ['#ffb020', '#ff5a6e', '#2f7bff'];
59
+ /** The default ground: near black, a touch cool. */
60
+ const BACKGROUND = '#0d0c10';
61
+ /** The clock's start, and the still frame: the hexagon, with a bright stretch on each side. */
62
+ const START = 0;
63
+ /** Corners an outline has: a hexagon's six (a rectangle's four, with one more at the middle of each side). */
64
+ const CORNERS = 6;
65
+
66
+ /**
67
+ * The ring's sizes in pixels for a canvas: the hexagon's inradius, the
68
+ * rectangle's half width and height, the circle's radius and the corner
69
+ * radius. The hexagon (flat top and bottom) and circle fit inside the
70
+ * margin; `rect` fills it; `morph`'s rectangle is a squarer one inside the
71
+ * hexagon's bounds. On a canvas taller than wide, all but `rect` are
72
+ * measured on their side and `upright` is set: they are turned a quarter,
73
+ * and the hexagon and rectangle stretch along the longer side so they
74
+ * fill a phone's screen.
75
+ *
76
+ * @param {number} width The canvas's width, px.
77
+ * @param {number} height Its height, px.
78
+ * @param {HaloShape} shape The outline.
79
+ * @param {number} margin Space to the edge, a share of the shorter side.
80
+ * @param {number} corner Corner roundness, 0–1.
81
+ * @returns {{ hex: number, reach: number, box: [number, number], circle: number, corner: number, upright: boolean }}
82
+ * The sizes, px: `reach` is the hexagon's half length, corner to corner.
83
+ */
84
+ export function ringSize(width, height, shape, margin, corner) {
85
+ const m = Math.min(width, height) * margin;
86
+ const halfW = Math.max(1, width / 2 - m);
87
+ const halfH = Math.max(1, height / 2 - m);
88
+ const upright = shape !== 'rect' && height > width;
89
+ const across = Math.max(halfW, halfH);
90
+ const tall = Math.min(halfW, halfH);
91
+ // A regular flat-topped hexagon is √3/2 as tall as it is wide.
92
+ const hex = Math.min(tall, across * (Math.sqrt(3) / 2));
93
+ const reach = upright ? Math.max(hex * (2 / Math.sqrt(3)), across * 0.85) : hex * (2 / Math.sqrt(3));
94
+ /** @type {[number, number]} */
95
+ const box = shape === 'rect' ? [halfW, halfH] : [upright ? reach * 0.92 : Math.min(across, hex * 1.08), hex * 0.86];
96
+ const shorter = shape === 'rect' || shape === 'circle' ? tall : shape === 'hexagon' ? hex : box[1];
97
+ return { hex, reach, box, circle: tall, corner: Math.min(1, Math.max(0, corner)) * shorter * 0.98, upright };
98
+ }
99
+
100
+ /**
101
+ * How far the outline is from the hexagon to the rectangle at a moment,
102
+ * 0–1. Only `morph` changes, easing between them.
103
+ *
104
+ * @param {HaloShape} shape The outline.
105
+ * @param {number} time The ring's clock, seconds.
106
+ * @returns {number} 0 the hexagon, 1 the rectangle.
107
+ */
108
+ export function shapeBlend(shape, time) {
109
+ if (shape === 'rect') return 1;
110
+ if (shape !== 'morph') return 0;
111
+ // Eased twice, so it lingers at each end and passes quickly through the in-between.
112
+ const k = 0.5 - 0.5 * Math.cos(time * 0.2);
113
+ const e = k * k * (3 - 2 * k);
114
+ return e * e * (3 - 2 * e);
115
+ }
116
+
117
+ /**
118
+ * The outline's corners, counter-clockwise from the right, before its
119
+ * corners are rounded: the hexagon's and the rectangle's (with a corner
120
+ * at the middle of each side, so the two match up) blended, each pulled
121
+ * in by the corner radius so the rounded shape keeps its size.
122
+ *
123
+ * @param {{ hex: number, reach: number, box: [number, number], corner: number }} size From `ringSize`.
124
+ * @param {number} blend 0 the hexagon, 1 the rectangle.
125
+ * @returns {Float32Array} Two floats a corner, CORNERS corners, px from the centre.
126
+ */
127
+ export function outline(size, blend) {
128
+ const c = size.corner;
129
+ const r = Math.max(0, size.hex - c);
130
+ // A hexagon's corners turn through 60°: rounding by c pulls each one in 2c/√3.
131
+ const R = Math.max(0, size.reach - c * (2 / Math.sqrt(3)));
132
+ const slant = R - r / Math.sqrt(3);
133
+ const a = Math.max(0, size.box[0] - c);
134
+ const b = Math.max(0, size.box[1] - c);
135
+ const hexagon = [R, 0, slant, r, -slant, r, -R, 0, -slant, -r, slant, -r];
136
+ const rect = [a, 0, a, b, -a, b, -a, 0, -a, -b, a, -b];
137
+ return new Float32Array(hexagon.map((v, i) => v + (rect[i] - v) * blend));
138
+ }
139
+
140
+ const FRAG = `
141
+ precision highp float;
142
+ uniform vec2 uRes;
143
+ uniform float uTime;
144
+ uniform vec3 uGround;
145
+ uniform vec2 uCorners[${CORNERS}];
146
+ uniform float uCircle;
147
+ uniform float uCorner;
148
+ uniform vec2 uCentre;
149
+ uniform float uTurn;
150
+ uniform float uWidth;
151
+ uniform float uGlow;
152
+ uniform vec3 uPtr;
153
+ ${GLSL_PALETTE}
154
+ ${GLSL_NOISE}
155
+ ${GLSL_QUIET}
156
+
157
+ // Signed distance to the polygon through uCorners (negative inside), px.
158
+ float polygon(vec2 p) {
159
+ float d = dot(p - uCorners[0], p - uCorners[0]);
160
+ float side = 1.0;
161
+ for (int i = 0; i < ${CORNERS}; i++) {
162
+ vec2 v = uCorners[i];
163
+ vec2 u = i == 0 ? uCorners[${CORNERS - 1}] : uCorners[i - 1];
164
+ vec2 e = u - v;
165
+ vec2 w = p - v;
166
+ vec2 off = w - e * clamp(dot(w, e) / max(dot(e, e), 1e-6), 0.0, 1.0);
167
+ d = min(d, dot(off, off));
168
+ // Crossings of a ray to the right: odd is inside.
169
+ bool up = p.y >= v.y, down = p.y < u.y, left = e.x * w.y > e.y * w.x;
170
+ if ((up && down && left) || (!up && !down && !left)) side = -side;
171
+ }
172
+ return side * sqrt(d);
173
+ }
174
+
175
+ void main() {
176
+ vec2 p = gl_FragCoord.xy - 0.5 * uRes - uCentre;
177
+ float s = sin(uTurn), co = cos(uTurn);
178
+ vec2 q = mat2(co, s, -s, co) * p;
179
+
180
+ // Signed distance to the outline, px: negative inside.
181
+ float d = uCircle > 0.0 ? length(q) - uCircle : polygon(q) - uCorner;
182
+
183
+ // Around the ring, 0–1: colour travels one way, brightness drifts the other.
184
+ float around = atan(p.y, p.x) / 6.2831853;
185
+ float a = around * 6.2831853;
186
+ float t = uTime;
187
+ float shorter = min(uRes.x, uRes.y);
188
+ vec3 tint = oklabToLinear(pal(around - t * 0.07 + d / shorter * 0.4));
189
+ float swell = 0.5 + 0.5 * sin(2.0 * a + t * 0.45 + 0.9 * sin(a - t * 0.27));
190
+ float bright = 0.05 + 1.2 * swell * swell * swell + 0.35 * pow(0.5 + 0.5 * sin(3.0 * a - t * 0.6), 3.0);
191
+
192
+ // Near the pointer, the ring burns hotter.
193
+ vec2 toPtr = gl_FragCoord.xy - uPtr.xy;
194
+ bright *= 1.0 + uPtr.z * 1.4 * exp(-dot(toPtr, toPtr) / (shorter * shorter * 0.1));
195
+
196
+ // The light: a crisp core line with a short bleed inward, then a glow
197
+ // outward that hands over to a long, soft bloom.
198
+ float w = uWidth;
199
+ float g = uGlow * shorter;
200
+ float core = exp(-(d * d) / (w * w));
201
+ float inner = exp(min(d, 0.0) / (w * 1.6));
202
+ float outer = d > 0.0 ? exp(-d / max(g * 0.07, w)) : inner;
203
+ float bloom = d > 0.0 ? exp(-d / max(g * 0.1, w)) : exp(d / max(g * 0.045, w));
204
+ float light = bright * (core * 0.7 + outer * 1.2 + bloom * 0.38 * min(uGlow, 1.0)) * 3.0;
205
+
206
+ // Kept dim behind copy.
207
+ vec2 uv = (gl_FragCoord.xy - 0.5 * uRes) / uRes.y;
208
+ light *= mix(1.0 - uQuiet.w, 1.0, quietOpen(uv));
209
+
210
+ vec3 lin = oklabToLinear(uGround) + (1.0 - exp(-tint * light));
211
+ vec3 col = oklabToSrgb(lin);
212
+ // A breath of dither, so the long glows do not band.
213
+ col += (hash(gl_FragCoord.xy + fract(t)) - 0.5) / 255.0;
214
+ gl_FragColor = vec4(col, 1.0);
215
+ }
216
+ `;
217
+
218
+ /**
219
+ * Starts a halo ring on an element: an opaque canvas inside it, filling it.
220
+ *
221
+ * @param {HTMLElement} el The element (its first canvas is drawn into).
222
+ * @param {HaloRingConfig} config The settings.
223
+ * @returns {() => void} Stops it.
224
+ */
225
+ export function haloRing(el, config) {
226
+ const shape = config.shape ?? 'morph';
227
+ const speed = config.speed ?? 1;
228
+ const interactive = config.interactive !== false;
229
+ let palette = paletteUniform(pickColors(config, COLORS));
230
+ let time = START;
231
+ /** The ring's sizes, from the last resize. @type {ReturnType<typeof ringSize> | null} */
232
+ let size = null;
233
+ /** The pointer's pull: where it is heading (tx, ty), where it is (x, y), 0–1 from the bottom left, and how strong (on, 0–1). */
234
+ const lean = { tx: 0.5, ty: 0.5, x: 0.5, y: 0.5, on: 0 };
235
+
236
+ /**
237
+ * Follows the pointer: the lean eases towards it, and fades when it leaves.
238
+ *
239
+ * @param {number} dt Seconds since the last frame.
240
+ */
241
+ const follow = (dt) => {
242
+ const p = pointerIn(el);
243
+ if (p.inside) {
244
+ if (lean.on < 0.01) Object.assign(lean, { x: p.x, y: p.y });
245
+ lean.tx = p.x;
246
+ lean.ty = p.y;
247
+ }
248
+ const k = 1 - Math.exp(-dt * 3);
249
+ lean.x += (lean.tx - lean.x) * k;
250
+ lean.y += (lean.ty - lean.y) * k;
251
+ lean.on += ((p.inside ? 1 : 0) - lean.on) * (1 - Math.exp(-dt * 2));
252
+ };
253
+
254
+ /**
255
+ * Lets the outline breathe and reach for the pointer: with `morph`, each
256
+ * corner drifts in and out a little on its own; the corner nearest the
257
+ * pointer is drawn a little towards it.
258
+ *
259
+ * @param {Float32Array} corners From `outline`, changed in place.
260
+ * @param {number} w The canvas's width, px.
261
+ * @param {number} h Its height, px.
262
+ * @param {number} cx The ring's centre, px right of the canvas's.
263
+ * @param {number} cy And px above it.
264
+ * @param {number} turn The ring's turn, radians, as the shader applies it.
265
+ * @returns {Float32Array} The corners.
266
+ */
267
+ const bend = (corners, w, h, cx, cy, turn) => {
268
+ const reach = Math.min(w, h) * 0.45;
269
+ // The pointer in the outline's own frame, as the shader turns it.
270
+ const px = lean.x * w - w / 2 - cx;
271
+ const py = lean.y * h - h / 2 - cy;
272
+ const s = Math.sin(turn);
273
+ const c = Math.cos(turn);
274
+ const qx = c * px - s * py;
275
+ const qy = s * px + c * py;
276
+ for (let i = 0; i < CORNERS; i++) {
277
+ const breathe = shape === 'morph' ? 1 + 0.03 * Math.sin(time * 0.37 + i * 2.3) : 1;
278
+ let x = corners[i * 2] * breathe;
279
+ let y = corners[i * 2 + 1] * breathe;
280
+ const near = lean.on * Math.exp(-((qx - x) ** 2 + (qy - y) ** 2) / (reach * reach));
281
+ x += (qx - x) * 0.08 * near;
282
+ y += (qy - y) * 0.08 * near;
283
+ corners[i * 2] = x;
284
+ corners[i * 2 + 1] = y;
285
+ }
286
+ return corners;
287
+ };
288
+
289
+ const { stage, stop } = createStage(el, {
290
+ fragment: FRAG,
291
+ alpha: false,
292
+ setup({ gl, uniform }) {
293
+ gl.uniform3fv(uniform('uGround'), parseColor(config.background ?? BACKGROUND));
294
+ },
295
+ resize({ gl, uniform, canvas, ratio }) {
296
+ size = ringSize(canvas.width, canvas.height, shape, config.margin ?? 0.05, config.corner ?? 0.3);
297
+ gl.uniform1f(uniform('uCircle'), shape === 'circle' ? size.circle : 0);
298
+ gl.uniform1f(uniform('uCorner'), size.corner);
299
+ gl.uniform1f(uniform('uWidth'), Math.max(0.5, config.thickness ?? 10) * ratio);
300
+ },
301
+ uniforms({ gl, uniform, canvas, still }, _now, dt) {
302
+ if (!still) {
303
+ time += dt * speed;
304
+ if (interactive && canHover()) follow(dt);
305
+ }
306
+ const { width: w, height: h } = canvas;
307
+ const shorter = Math.min(w, h);
308
+ // The ring leans a little towards the pointer and turns with it; `morph` also sways on its own.
309
+ const pull = 0.035 * lean.on;
310
+ const cx = (lean.x - 0.5) * shorter * pull;
311
+ const cy = (lean.y - 0.5) * shorter * pull;
312
+ const sway = shape === 'morph' ? 0.32 * Math.sin(time * 0.13) : 0;
313
+ const turn = shape === 'rect' ? 0 : sway + (lean.x - 0.5) * 0.12 * lean.on + (size?.upright ? Math.PI / 2 : 0);
314
+ if (size) gl.uniform2fv(uniform('uCorners'), bend(outline(size, shapeBlend(shape, time)), w, h, cx, cy, turn));
315
+ gl.uniform1f(uniform('uTime'), time);
316
+ gl.uniform2f(uniform('uCentre'), cx, cy);
317
+ gl.uniform1f(uniform('uTurn'), turn);
318
+ gl.uniform1f(uniform('uGlow'), Math.max(0, config.glow ?? 1));
319
+ gl.uniform3f(uniform('uPtr'), lean.x * w, lean.y * h, lean.on);
320
+ gl.uniform3fv(uniform('uPal'), palette);
321
+ gl.uniform4f(uniform('uQuiet'), ...quietUniform(config.quiet, w / h));
322
+ },
323
+ });
324
+ if (!stage) return stop;
325
+
326
+ const unwatch = watchColors(el, (next) => {
327
+ palette = paletteUniform(next.colors);
328
+ if (stage.still) stage.redraw();
329
+ });
330
+ return () => {
331
+ stop();
332
+ unwatch();
333
+ };
334
+ }
@@ -0,0 +1,50 @@
1
+ import type { GL } from './gl.js';
2
+
3
+ /** The most pushes one step takes. */
4
+ export const MAX_PUSHES: number;
5
+
6
+ /**
7
+ * GLSL (ES 1.00) for a step shader: `waveState(uv)` (height, speed and the
8
+ * Laplacian of each), `waveForce(s)` (wave, spring and viscosity),
9
+ * `wavePushes(uv)` (how far the pushes press a cell down) and
10
+ * `wavePack(h, v)` (the new state, clamped). Declares `uState`, `uTexel`,
11
+ * `uAspect`, `uMotion`, `uPush` and `uPushes`.
12
+ */
13
+ export const GLSL_HEIGHT_FIELD: string;
14
+
15
+ /** How the surface moves, per step. */
16
+ export interface WaveMotion {
17
+ /** Wave speed squared, cells a step (at most 0.5). */
18
+ speed: number;
19
+ /** The pull back to rest. */
20
+ spring: number;
21
+ /** The share of speed kept each step. */
22
+ keep: number;
23
+ /** How much neighbouring speeds even out. */
24
+ viscosity: number;
25
+ }
26
+
27
+ /** A wave surface on the GPU: heights (r) and speeds (g) in a pair of float targets. */
28
+ export interface HeightField {
29
+ /** The step's program. */
30
+ program: WebGLProgram;
31
+ /** A uniform of the step. */
32
+ uniform(name: string): WebGLUniformLocation | null;
33
+ /** Sizes the grid: `longSide` cells along the box's longer side, square cells; cleared. */
34
+ resize(longSide: number, aspect: number): void;
35
+ /** One step. `pushes` holds x, y (box heights), radius and strength for each of `count` pushes (at most MAX_PUSHES). */
36
+ step(motion: WaveMotion, pushes: Float32Array, count: number): void;
37
+ /** Flattens the surface. */
38
+ clear(): void;
39
+ /** The current state. */
40
+ texture(): WebGLTexture;
41
+ /** One cell, as a share of the box. */
42
+ texel(): [number, number];
43
+ /** Whether the state is filtered linearly (else nearest). */
44
+ linear: boolean;
45
+ /** Frees its targets, program and buffer. */
46
+ dispose(): void;
47
+ }
48
+
49
+ /** Sets up a height field with a step shader built on GLSL_HEIGHT_FIELD; null without drawable float textures or when the step does not compile. Uses texture unit 0. */
50
+ export function createHeightField(gl: GL, step: string): HeightField | null;
@@ -0,0 +1,176 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/height-field
3
+ *
4
+ * A surface of waves simulated on the GPU, cheaply: a grid of heights and
5
+ * vertical speeds in a pair of float targets (src/runtime/ping-pong.js),
6
+ * stepped by a damped wave equation. The cells are square, so waves run at
7
+ * the same speed every way. Pushes from the pointer dent it; each effect
8
+ * writes its own step shader round the shared pieces (GLSL_HEIGHT_FIELD),
9
+ * so a liquid metal and a pond differ only in what holds the water.
10
+ *
11
+ * The state texture: r the surface's height off its rest, g its vertical
12
+ * speed. Uses texture unit 0 for it. Each step leaves its program,
13
+ * framebuffer and viewport bound: whoever draws next restores theirs.
14
+ *
15
+ * @example
16
+ * const STEP = `precision highp float;
17
+ * varying vec2 vUv;
18
+ * ${GLSL_HEIGHT_FIELD}
19
+ * void main() {
20
+ * vec4 s = waveState(vUv);
21
+ * float v = (s.y + waveForce(s) - wavePushes(vUv)) * uMotion.z;
22
+ * gl_FragColor = wavePack(s.x + v, v);
23
+ * }`;
24
+ * const field = createHeightField(gl, STEP);
25
+ */
26
+
27
+ import { createProgram, bindTriangle, VERTEX } from './gl.js';
28
+ import { createPingPong } from './ping-pong.js';
29
+
30
+ /** The most pushes one step takes. */
31
+ export const MAX_PUSHES = 20;
32
+
33
+ /**
34
+ * GLSL (ES 1.00) for a step shader: the state and its neighbours, the
35
+ * forces on a cell, and the pushes.
36
+ *
37
+ * - `vec4 waveState(vec2 uv)`: height, speed, and the Laplacian of each
38
+ * (how far the cell sits below its neighbours).
39
+ * - `float waveForce(vec4 s)`: the change in speed this step: the wave
40
+ * (`uMotion.x`, speed squared in cells a step, at most 0.5), a spring
41
+ * back to rest (`uMotion.y`) and viscosity evening out speeds
42
+ * (`uMotion.w`). `uMotion.z` is the share of speed kept each step, for
43
+ * the shader to apply as it likes.
44
+ * - `float wavePushes(vec2 uv)`: how far the pushes press the cell down
45
+ * this step. Each is a dent ringed by a smaller swell (a difference of
46
+ * gaussians that adds no volume), at x, y in box heights.
47
+ * - `vec4 wavePack(float h, float v)`: the new state, clamped.
48
+ */
49
+ export const GLSL_HEIGHT_FIELD = `
50
+ uniform sampler2D uState;
51
+ uniform vec2 uTexel;
52
+ uniform float uAspect;
53
+ uniform vec4 uMotion;
54
+ uniform vec4 uPush[${MAX_PUSHES}];
55
+ uniform int uPushes;
56
+
57
+ vec4 waveState(vec2 uv) {
58
+ vec2 s = texture2D(uState, uv).rg;
59
+ vec2 l = texture2D(uState, uv - vec2(uTexel.x, 0.0)).rg;
60
+ vec2 r = texture2D(uState, uv + vec2(uTexel.x, 0.0)).rg;
61
+ vec2 t = texture2D(uState, uv + vec2(0.0, uTexel.y)).rg;
62
+ vec2 b = texture2D(uState, uv - vec2(0.0, uTexel.y)).rg;
63
+ return vec4(s, l + r + t + b - 4.0 * s);
64
+ }
65
+
66
+ float waveForce(vec4 s) {
67
+ return uMotion.x * s.z - uMotion.y * s.x + uMotion.w * s.w;
68
+ }
69
+
70
+ float wavePushes(vec2 uv) {
71
+ vec2 p = uv * vec2(uAspect, 1.0);
72
+ float dent = 0.0;
73
+ for (int i = 0; i < ${MAX_PUSHES}; i++) {
74
+ if (i >= uPushes) break;
75
+ vec4 push = uPush[i];
76
+ vec2 d = p - push.xy;
77
+ float k = dot(d, d) / (push.z * push.z);
78
+ dent += push.w * (exp(-k) - 0.25 * exp(-k * 0.25));
79
+ }
80
+ return dent;
81
+ }
82
+
83
+ vec4 wavePack(float h, float v) {
84
+ return vec4(clamp(h, -6.0, 6.0), clamp(v, -3.0, 3.0), 0.0, 1.0);
85
+ }
86
+ `;
87
+
88
+ /**
89
+ * How the surface moves, per step.
90
+ *
91
+ * @typedef {object} WaveMotion
92
+ * @property {number} speed Wave speed squared, cells a step (at most 0.5).
93
+ * @property {number} spring The pull back to rest.
94
+ * @property {number} keep The share of speed kept each step.
95
+ * @property {number} viscosity How much neighbouring speeds even out.
96
+ */
97
+
98
+ /**
99
+ * @typedef {object} HeightField
100
+ * @property {WebGLProgram} program The step's program.
101
+ * @property {(name: string) => WebGLUniformLocation | null} uniform A uniform of the step.
102
+ * @property {(longSide: number, aspect: number) => void} resize Sizes the
103
+ * grid: `longSide` cells along the box's longer side, square cells; cleared.
104
+ * @property {(motion: WaveMotion, pushes: Float32Array, count: number) => void} step
105
+ * One step. `pushes` holds x, y (box heights), radius and strength for each
106
+ * of `count` pushes (at most MAX_PUSHES).
107
+ * @property {() => void} clear Flattens the surface.
108
+ * @property {() => WebGLTexture} texture The current state.
109
+ * @property {() => [number, number]} texel One cell, as a share of the box.
110
+ * @property {boolean} linear Whether the state is filtered linearly (else nearest).
111
+ * @property {() => void} dispose Frees its targets, program and buffer.
112
+ */
113
+
114
+ /**
115
+ * Sets up a height field with a step shader built on GLSL_HEIGHT_FIELD.
116
+ *
117
+ * @param {WebGLRenderingContext | WebGL2RenderingContext} gl The context.
118
+ * @param {string} step The step's fragment shader (`vUv` 0–1 across the box).
119
+ * @returns {HeightField | null} The field, or null where the GPU cannot draw
120
+ * into float textures or the step does not compile.
121
+ */
122
+ export function createHeightField(gl, step) {
123
+ const pass = createProgram(gl, VERTEX, step);
124
+ if (!pass) return null;
125
+ const state = createPingPong(gl, 2, 2);
126
+ if (!state) {
127
+ gl.deleteProgram(pass.program);
128
+ return null;
129
+ }
130
+ const triangle = bindTriangle(gl);
131
+ const { uniform } = pass;
132
+ gl.useProgram(pass.program);
133
+ gl.uniform1i(uniform('uState'), 0);
134
+
135
+ return {
136
+ program: pass.program,
137
+ uniform,
138
+ resize(longSide, aspect) {
139
+ const cols = aspect >= 1 ? longSide : Math.round(longSide * aspect);
140
+ const rows = Math.max(2, Math.round(cols / aspect));
141
+ state.resize(Math.max(2, cols), rows);
142
+ const size = state.size();
143
+ gl.useProgram(pass.program);
144
+ gl.uniform2f(uniform('uTexel'), 1 / size.width, 1 / size.height);
145
+ gl.uniform1f(uniform('uAspect'), aspect);
146
+ },
147
+ step(motion, pushes, count) {
148
+ const { width, height } = state.size();
149
+ gl.useProgram(pass.program);
150
+ bindTriangle(gl, triangle);
151
+ gl.disable(gl.BLEND);
152
+ gl.bindFramebuffer(gl.FRAMEBUFFER, state.write.fbo);
153
+ gl.viewport(0, 0, width, height);
154
+ gl.activeTexture(gl.TEXTURE0);
155
+ gl.bindTexture(gl.TEXTURE_2D, state.read.texture);
156
+ gl.uniform4f(uniform('uMotion'), motion.speed, motion.spring, motion.keep, motion.viscosity);
157
+ const n = Math.min(count, MAX_PUSHES);
158
+ gl.uniform1i(uniform('uPushes'), n);
159
+ if (n) gl.uniform4fv(uniform('uPush'), pushes.subarray(0, MAX_PUSHES * 4));
160
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
161
+ state.swap();
162
+ },
163
+ clear: () => state.clear(),
164
+ texture: () => state.read.texture,
165
+ texel() {
166
+ const { width, height } = state.size();
167
+ return [1 / width, 1 / height];
168
+ },
169
+ linear: state.linear,
170
+ dispose() {
171
+ state.dispose();
172
+ gl.deleteBuffer(triangle);
173
+ gl.deleteProgram(pass.program);
174
+ },
175
+ };
176
+ }
@@ -0,0 +1,25 @@
1
+ export interface ImageRippleConfig {
2
+ /** The photo's URL (same origin, or served with CORS). */
3
+ src: string;
4
+ /** How far the ripples bend the photo, 0–3. Default 1. */
5
+ strength?: number;
6
+ /** How wide the ripples the pointer makes are, 0.3–3. Default 1. */
7
+ size?: number;
8
+ /** How thick the water is: more settles sooner, with smaller ripples, 0.25–4. Default 1. */
9
+ viscosity?: number;
10
+ /** How far the colours part at the wave fronts, 0–3; 0 for none. Default 1. */
11
+ fringe?: number;
12
+ /** Whether the pointer ripples it; false leaves the plain photo. Default true. */
13
+ interactive?: boolean;
14
+ /** How the photo fills the element, as CSS `object-fit`. Default `cover`. */
15
+ fit?: 'cover' | 'contain';
16
+ }
17
+
18
+ /** The texture-coordinate scale that fits a picture to a box like CSS `object-fit` (`cover` or `contain`), for `coverUv`. */
19
+ export function fitScale(fit: 'cover' | 'contain' | string | undefined, imageAspect: number, boxAspect: number): [number, number];
20
+
21
+ /** How the water moves for a viscosity, and how long (ms) its waves take to settle. */
22
+ export function waterMotion(viscosity: number): { motion: import('./height-field.js').WaveMotion; settle: number };
23
+
24
+ /** Starts the ripples in `el`'s canvas, over the photo under it. Returns a function that stops it. */
25
+ export function imageRipple(el: HTMLElement, config: ImageRippleConfig): () => void;