@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,237 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/voxel-logo
3
+ *
4
+ * A logo built of cubes: the shape is cut into a grid, each filled cell
5
+ * extruded into a short column of voxels, and the solid rocks slowly in
6
+ * perspective, turning towards the pointer. Faces are lit by which way
7
+ * they point, every cube is outlined where it meets the next, and the
8
+ * whole is dithered down to two inks, the way a one-colour print or an
9
+ * old screen would show it. Optionally (`markers`), crosshair markers
10
+ * ring the solid, tracking it as it turns.
11
+ *
12
+ * Each pixel's ray is walked through the voxel grid on the GPU (a
13
+ * DDA, cell to cell), so the solid is exact at any size.
14
+ *
15
+ * Opaque: the effect is the whole background of what it fills. Without
16
+ * WebGL it removes its canvas and the element's background shows.
17
+ */
18
+
19
+ import { createStage } from './stage.js';
20
+ import { drawShape } from './shape.js';
21
+ import { createTrackers } from './trackers.js';
22
+ import { projectPoint } from './points.js';
23
+ import { parseColor } from './color.js';
24
+ import { canHover } from './device.js';
25
+ import { pointerIn } from './pointer.js';
26
+ import { watchColors } from './mount.js';
27
+ import { pickColors } from './palettes.js';
28
+
29
+ /**
30
+ * @typedef {object} VoxelLogoConfig
31
+ * @property {string} [text] A character or word to build in cubes.
32
+ * @property {string} [font] Its CSS font, without the size (default: the page's, bold).
33
+ * @property {string} [src] An image (an SVG logo) to build instead.
34
+ * @property {{ x: number, y: number, width: number, height: number }} [area]
35
+ * Where the solid sits, each 0–1 from the top left (default: the right half).
36
+ * @property {string[]} [colors] The ink, then the paper (default mint on near-black).
37
+ * @property {string} [palette] A shared palette by name (PALETTES; any case), when there are no `colors`. Its first colour is the ink.
38
+ * @property {number} [size=1.3] How large the solid is in its area (1 just fits when face-on).
39
+ * @property {number} [cells=28] Cubes across the shape.
40
+ * @property {number} [depth=4] Cubes deep.
41
+ * @property {number} [dither=2] The dither's pixel size, CSS px; 0 for smooth shading.
42
+ * @property {number} [markers=0] Tracking markers ringing the solid (try 6); 0 for none.
43
+ * @property {number} [rock=1] How far it rocks and turns towards the pointer.
44
+ */
45
+
46
+ const FRAG = `
47
+ precision highp float;
48
+ uniform vec2 uRes;
49
+ uniform float uTime;
50
+ uniform sampler2D uMask;
51
+ uniform vec3 uGrid;
52
+ uniform vec2 uTurn;
53
+ uniform vec4 uArea;
54
+ uniform vec3 uInk;
55
+ uniform vec3 uPaper;
56
+ uniform float uDither;
57
+ uniform float uSize;
58
+
59
+ // Is the cell at (x, y, z) filled? Columns of the shape, uGrid.z deep.
60
+ bool filled(vec3 c) {
61
+ if (c.x < 0.0 || c.y < 0.0 || c.z < 0.0 || c.x >= uGrid.x || c.y >= uGrid.y || c.z >= uGrid.z) return false;
62
+ return texture2D(uMask, vec2((c.x + 0.5) / uGrid.x, 1.0 - (c.y + 0.5) / uGrid.y)).r > 0.5;
63
+ }
64
+
65
+ vec3 turnY(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); }
66
+ vec3 turnX(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); }
67
+
68
+ // The ordered dither's threshold at a pixel: a 4 x 4 Bayer matrix.
69
+ float bayer(vec2 px) {
70
+ vec2 p = mod(floor(px), 4.0);
71
+ float i = p.y * 4.0 + p.x;
72
+ vec4 row = p.y < 1.0 ? vec4(0.0, 8.0, 2.0, 10.0) : p.y < 2.0 ? vec4(12.0, 4.0, 14.0, 6.0) : p.y < 3.0 ? vec4(3.0, 11.0, 1.0, 9.0) : vec4(15.0, 7.0, 13.0, 5.0);
73
+ float v = p.x < 1.0 ? row.x : p.x < 2.0 ? row.y : p.x < 3.0 ? row.z : row.w;
74
+ return (v + 0.5) / 16.0;
75
+ }
76
+
77
+ // How light the solid is at a pixel: 0 where there is none.
78
+ float shade(vec2 uv) {
79
+ // The area the solid fills, as a square view onto the grid, centred.
80
+ vec2 local = (uv - uArea.xy) / uArea.zw * 2.0 - 1.0;
81
+ float size = max(uGrid.x, uGrid.y);
82
+ vec2 aspect = vec2(uArea.z * uRes.x, uArea.w * uRes.y);
83
+ local *= aspect / max(aspect.x, aspect.y);
84
+ // A camera in front, a little perspective; the grid turned about its centre.
85
+ vec3 origin = vec3(local * 0.5 * size * 1.15 / uSize, -size * 2.2);
86
+ vec3 dir = normalize(vec3(local * 0.12, 1.0));
87
+ vec3 centre = uGrid * 0.5;
88
+ origin = turnX(turnY(origin, -uTurn.x), -uTurn.y) + centre;
89
+ dir = turnX(turnY(dir, -uTurn.x), -uTurn.y);
90
+ // Into the grid's box.
91
+ vec3 inv = 1.0 / dir;
92
+ vec3 t0 = (vec3(0.0) - origin) * inv;
93
+ vec3 t1 = (uGrid - origin) * inv;
94
+ vec3 tmin = min(t0, t1);
95
+ vec3 tmax = max(t0, t1);
96
+ float enter = max(max(tmin.x, tmin.y), tmin.z);
97
+ float leave = min(min(tmax.x, tmax.y), tmax.z);
98
+ if (leave < max(enter, 0.0)) return 0.0;
99
+ vec3 pos = origin + dir * (max(enter, 0.0) + 1e-3);
100
+ vec3 cell = floor(pos);
101
+ vec3 step_ = sign(dir);
102
+ vec3 delta = abs(inv);
103
+ vec3 side = (step_ * (cell - pos) + step_ * 0.5 + 0.5) * delta;
104
+ vec3 normal = -step_ * vec3(greaterThanEqual(tmin, vec3(enter)));
105
+ for (int i = 0; i < 160; i++) {
106
+ if (filled(cell)) {
107
+ // Lit by the way the face points, and outlined where cubes meet.
108
+ vec3 n = normalize(turnY(turnX(normal, uTurn.y), uTurn.x));
109
+ float light = 0.35 + 0.65 * max(dot(n, normalize(vec3(-0.4, 0.6, -0.7))), 0.0);
110
+ vec3 hit = origin + dir * (dot(side - delta, vec3(equal(abs(normal), vec3(1.0)))) - 1e-3);
111
+ vec3 f = fract(hit);
112
+ vec2 face = abs(normal.x) > 0.5 ? f.yz : abs(normal.y) > 0.5 ? f.xz : f.xy;
113
+ float edge = min(min(face.x, 1.0 - face.x), min(face.y, 1.0 - face.y));
114
+ return light * smoothstep(0.03, 0.09, edge);
115
+ }
116
+ if (side.x < side.y && side.x < side.z) {
117
+ cell.x += step_.x; side.x += delta.x; normal = vec3(-step_.x, 0.0, 0.0);
118
+ } else if (side.y < side.z) {
119
+ cell.y += step_.y; side.y += delta.y; normal = vec3(0.0, -step_.y, 0.0);
120
+ } else {
121
+ cell.z += step_.z; side.z += delta.z; normal = vec3(0.0, 0.0, -step_.z);
122
+ }
123
+ if (cell.x < -1.0 || cell.y < -1.0 || cell.z < -1.0 || cell.x > uGrid.x || cell.y > uGrid.y || cell.z > uGrid.z) break;
124
+ }
125
+ return 0.0;
126
+ }
127
+
128
+ void main() {
129
+ vec2 px = gl_FragCoord.xy;
130
+ float s = shade(px / uRes);
131
+ // Two inks: the shade against the dither's threshold, or smooth without one.
132
+ float ink = uDither > 0.0 ? step(bayer(px / uDither), s * 1.1) : s;
133
+ gl_FragColor = vec4(mix(uPaper, uInk, ink), 1.0);
134
+ }
135
+ `;
136
+
137
+ /** The defaults: mint ink on near-black paper. */
138
+ const COLORS = ['#a7f3d0', '#08090a'];
139
+
140
+ /**
141
+ * Starts a voxel logo on an element: an opaque canvas inside it, filling it.
142
+ *
143
+ * @param {HTMLElement} el The element (its first canvas is drawn into).
144
+ * @param {VoxelLogoConfig} config The settings.
145
+ * @returns {() => void} Stops it.
146
+ */
147
+ export function voxelLogo(el, config) {
148
+ let colors = pickColors(config, COLORS, (p) => [p.colors[0], COLORS[1]]);
149
+ const area = config.area ?? { x: 0.42, y: 0.04, width: 0.56, height: 0.92 };
150
+ const start = performance.now();
151
+ const turn = { x: 0, y: 0 };
152
+ const markers = (config.markers ?? 0) > 0 ? createTrackers(el, config.markers ?? 0, { kind: 'marker' }) : null;
153
+ /** The grid's size in cells, once the shape is drawn. */
154
+ let grid = [0, 0, 0];
155
+
156
+ const { stage, stop } = createStage(el, {
157
+ fragment: FRAG,
158
+ alpha: false,
159
+ setup({ gl, uniform }) {
160
+ gl.uniform1i(uniform('uMask'), 0);
161
+ gl.uniform1f(uniform('uSize'), config.size ?? 1.3);
162
+ gl.uniform4f(uniform('uArea'), area.x, 1 - area.y - area.height, area.width, area.height);
163
+ const texture = gl.createTexture();
164
+ gl.activeTexture(gl.TEXTURE0);
165
+ gl.bindTexture(gl.TEXTURE_2D, texture);
166
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
167
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
168
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
169
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
170
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, 1, 1, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, new Uint8Array([0]));
171
+ // The shape at one pixel a cube: drawn into a square, so cubes stay cubes.
172
+ const cells = config.cells ?? 28;
173
+ drawShape({ text: config.text, font: config.font, src: config.src, padding: 0.04 }, cells, cells)
174
+ .then((mask) => {
175
+ const bytes = Uint8Array.from(mask.alpha);
176
+ gl.activeTexture(gl.TEXTURE0);
177
+ gl.bindTexture(gl.TEXTURE_2D, texture);
178
+ gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
179
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, cells, cells, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, bytes);
180
+ grid = [cells, cells, config.depth ?? 4];
181
+ if (stage?.still) stage.redraw();
182
+ })
183
+ .catch((error) => console.warn('[effects-astro]', error));
184
+ return () => markers?.destroy();
185
+ },
186
+ resize({ gl, uniform, ratio }) {
187
+ gl.uniform1f(uniform('uDither'), (config.dither ?? 2) * ratio);
188
+ },
189
+ uniforms({ gl, uniform, still }, now) {
190
+ const t = (now - start) / 1000;
191
+ const p = !still && canHover() ? pointerIn(el) : null;
192
+ const rock = config.rock ?? 1;
193
+ // A slow rock, leaning towards the pointer when there is one.
194
+ const goal = {
195
+ x: (Math.sin(t * 0.45) * 0.45 + (p?.inside ? (p.x - 0.5) * 0.9 : 0)) * rock,
196
+ y: (Math.sin(t * 0.31) * 0.18 + (p?.inside ? (p.y - 0.5) * 0.5 : 0)) * rock,
197
+ };
198
+ turn.x += (goal.x - turn.x) * 0.05;
199
+ turn.y += (goal.y - turn.y) * 0.05;
200
+ gl.uniform1f(uniform('uTime'), t);
201
+ gl.uniform3f(uniform('uGrid'), grid[0] || 1, grid[1] || 1, grid[2] || 1);
202
+ gl.uniform2f(uniform('uTurn'), turn.x, turn.y);
203
+ gl.uniform3fv(uniform('uInk'), parseColor(colors[0]));
204
+ gl.uniform3fv(uniform('uPaper'), parseColor(colors[1] ?? COLORS[1]));
205
+ },
206
+ after({ canvas }, now) {
207
+ if (!markers || !grid[0]) return;
208
+ // Markers on a ring round the solid, turning with it.
209
+ const t = (now - start) / 1000;
210
+ const w = el.clientWidth;
211
+ const h = el.clientHeight;
212
+ const count = config.markers ?? 0;
213
+ const aspect = (area.width * canvas.width) / (area.height * canvas.height);
214
+ for (let i = 0; i < count; i++) {
215
+ const a = (i / count) * Math.PI * 2 + t * 0.05;
216
+ const ring = 0.62 * (config.size ?? 1.3);
217
+ const at = projectPoint([Math.cos(a) * ring, Math.sin(a) * ring, 0], turn.x * 0.8, turn.y * 0.8, aspect);
218
+ const x = (area.x + at.x * area.width) * w;
219
+ const y = (area.y + at.y * area.height) * h;
220
+ markers.place(i, { x: x - 14, y: y - 14, w: 28, h: 28 }, `${String(i + 1).padStart(2, '0')} · ${Math.round(40 + 50 * (0.5 + 0.5 * Math.sin(t * 0.7 + i)))}`);
221
+ }
222
+ },
223
+ });
224
+ if (!stage) {
225
+ markers?.destroy();
226
+ return stop;
227
+ }
228
+
229
+ const unwatch = watchColors(el, (next) => {
230
+ colors = next.colors;
231
+ if (stage.still) stage.redraw();
232
+ });
233
+ return () => {
234
+ stop();
235
+ unwatch();
236
+ };
237
+ }
@@ -0,0 +1,70 @@
1
+ import type { PaletteName } from './palettes.js';
2
+ import type { AudioSource } from './audio.js';
3
+
4
+ export interface SignalLinesConfig {
5
+ /** One colour for every line. Default: the `colors` gradient. */
6
+ color?: string;
7
+ /** Colours the lines run through from left to right, blended in Oklab. Default sea-glass, ice and pale gold. */
8
+ colors?: string[];
9
+ /** A shared palette by name (`PALETTES`, any case), when there are no `colors` or `color`. */
10
+ palette?: PaletteName | (string & {});
11
+ /** The pulses' colour. Default `#fafafa`. */
12
+ pulse?: string;
13
+ /** How many lines, 2–12. Default 7. */
14
+ lines?: number;
15
+ /** How tall the waves are. Default 1. */
16
+ amplitude?: number;
17
+ /** How fast they move. Default 1. */
18
+ speed?: number;
19
+ /** How often pulses run; 0 for none. Default 1. */
20
+ pulses?: number;
21
+ /** How much light the lines and pulses give off, 0–2. Default 1. */
22
+ glow?: number;
23
+ /** Film grain in the light, 0–1. Default 0.5. */
24
+ grain?: number;
25
+ /** How far out of focus the back lines are, and how much their colours fringe; 0 for all sharp. Default 1. */
26
+ depth?: number;
27
+ /** How far the lines part round the pointer and how much it lights them; 0 for not at all. Default 1. */
28
+ bend?: number;
29
+ /** Follow the sound playing: `'page'` for whatever plays, or a CSS selector for an `<audio>`/`<video>` or a player's container (a WaveformPlayer). The lines carry its waveform, as tall as it is loud, and kicks send pulses; while nothing plays they keep their own motion. Default none. */
30
+ audio?: AudioSource;
31
+ /** An area where the light dims (behind a headline): centre x/y (0–1, from the top left), radius (a share of the height) and depth (0 none, 1 dark). Default none. */
32
+ quiet?: { x?: number; y?: number; radius?: number; depth?: number } | null;
33
+ }
34
+
35
+ export interface WaveBarsConfig {
36
+ /** One colour for every bar. Default: the `colors` gradient. */
37
+ color?: string;
38
+ /** Colours the bars run through from left to right, blended in Oklab. Default teal, ice and apricot. */
39
+ colors?: string[];
40
+ /** A shared palette by name (`PALETTES`, any case), when there are no `colors` or `color`. */
41
+ palette?: PaletteName | (string & {});
42
+ /** Space between bars, CSS px. Default 8. */
43
+ step?: number;
44
+ /** A bar's width, CSS px. Default 3. */
45
+ bar?: number;
46
+ /** The tallest bar, a share of the height either side of the middle. Default 0.34. */
47
+ height?: number;
48
+ /** Seconds between retunes. Default 2. */
49
+ every?: number;
50
+ /** The playhead sweeping across, lighting the bars it plays. Default true. */
51
+ sweep?: boolean;
52
+ /** Film grain in the light, 0–1. Default 0.4. */
53
+ grain?: number;
54
+ /** Peak marks over the bars that hold, then drop, as a meter's do. Default true. */
55
+ peaks?: boolean;
56
+ /** How much light the bars and playhead give off, 0–2. Default 1. */
57
+ glow?: number;
58
+ /** How much the bars under the pointer rise and light; 0 for not at all. Default 1. */
59
+ scrub?: number;
60
+ /** Follow the sound playing: `'page'` for whatever plays, or a CSS selector for an `<audio>`/`<video>` or a player's container (a WaveformPlayer). The bars show its spectrum (bass in the middle) and the playhead follows the track; while nothing plays they keep their own motion. Default none. */
61
+ audio?: AudioSource;
62
+ /** An area where the light dims (behind a headline): centre x/y (0–1, from the top left), radius (a share of the height) and depth (0 none, 1 dark). Default none. */
63
+ quiet?: { x?: number; y?: number; radius?: number; depth?: number } | null;
64
+ }
65
+
66
+ /** Starts signal lines in `el`'s canvas (WebGL; the canvas is removed without it). Returns a function that stops it. */
67
+ export function signalLines(el: HTMLElement, config: SignalLinesConfig): () => void;
68
+
69
+ /** Starts tuning wave bars in `el`'s canvas (WebGL; the canvas is removed without it). Returns a function that stops it. */
70
+ export function waveBars(el: HTMLElement, config: WaveBarsConfig): () => void;