@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,287 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/pixel-glitch
3
+ *
4
+ * Text that breaks into pixels under the pointer: a canvas over the text
5
+ * redraws it, and the cells the pointer passes heat up and are drawn as
6
+ * blocks (bigger the hotter), with the hottest rows slipping sideways.
7
+ * Heat fades in about half a second, so a trail of pixels follows the
8
+ * pointer and the text knits back together behind it. Faster movement adds
9
+ * more heat.
10
+ *
11
+ * With `stroke` set, the text at rest is a hollow outline of that width and
12
+ * the pixels it breaks into fill the letters solid, so the pointer lights
13
+ * the word up as it passes.
14
+ *
15
+ * The element keeps its text (it only turns transparent once the canvas
16
+ * has drawn), so fit-text, selection and the no-JS look are unchanged.
17
+ * Each glyph is drawn where the browser laid it out (one Range per
18
+ * character), so letter-spacing and kerning match the CSS.
19
+ *
20
+ * The pointer is read from the document, so the text can keep
21
+ * `pointer-events: none` (a big wordmark's line box often overlaps links).
22
+ * Animates only while some cell is hot, and only while the text is on
23
+ * screen. Off with prefers-reduced-motion and without a hovering pointer.
24
+ *
25
+ * From the SampleGrid (WaveGrid) theme's footer.
26
+ */
27
+
28
+ import { canHover, prefersReducedMotion } from './device.js';
29
+ import { textNodes } from './text.js';
30
+
31
+ /**
32
+ * @typedef {object} PixelGlitchConfig
33
+ * @property {number} [cell=14] The heat grid's cell, CSS px.
34
+ * @property {number} [reach=120] How far the pointer's heat reaches, CSS px.
35
+ * @property {number} [decay=0.9] Heat kept each frame (0.9 is gone in about half a second).
36
+ * @property {number} [block=22] The pixel block size at full heat, CSS px.
37
+ * @property {number} [shift=16] How far the hottest rows slip sideways, CSS px.
38
+ * @property {number} [stroke=0] With a width (CSS px), the text at rest is an outline that the pixels fill.
39
+ */
40
+
41
+ /**
42
+ * Starts the pixel glitch on an element of text.
43
+ *
44
+ * @param {HTMLElement} el The text.
45
+ * @param {PixelGlitchConfig} config The settings.
46
+ * @returns {() => void} Stops it.
47
+ */
48
+ export function pixelGlitch(el, config) {
49
+ if (prefersReducedMotion() || !canHover()) return () => {};
50
+ const CELL = config.cell ?? 14;
51
+ const REACH = config.reach ?? 120;
52
+ const DECAY = config.decay ?? 0.9;
53
+ const MAX_BLOCK = config.block ?? 22;
54
+ const SHIFT = config.shift ?? 16;
55
+ const STROKE = config.stroke ?? 0;
56
+
57
+ const canvas = document.createElement('canvas');
58
+ canvas.className = 'effect-pixel-glitch-canvas';
59
+ canvas.setAttribute('aria-hidden', 'true');
60
+ el.append(canvas);
61
+ const ctx = /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
62
+ const crisp = document.createElement('canvas');
63
+ const dpr = Math.min(window.devicePixelRatio || 1, 2);
64
+ const g = {
65
+ /** Coverage of the filled text, for choosing which blocks to draw. */
66
+ alpha: new Uint8ClampedArray(0),
67
+ w: 0,
68
+ h: 0,
69
+ /** Where the canvas sits in the element (the glyphs overflow a tight line-height). */
70
+ ox: 0,
71
+ oy: 0,
72
+ cols: 0,
73
+ rows: 0,
74
+ heat: new Float32Array(0),
75
+ ink: '',
76
+ visible: false,
77
+ running: false,
78
+ /** @type {{ x: number, y: number } | undefined} */
79
+ last: undefined,
80
+ };
81
+
82
+ /**
83
+ * Is the filled text inked at (x, y), CSS px?
84
+ *
85
+ * @param {number} x Across the canvas.
86
+ * @param {number} y Down the canvas.
87
+ * @returns {boolean} Whether that pixel is inside a glyph.
88
+ */
89
+ const inked = (x, y) => {
90
+ const px = Math.min(crisp.width - 1, Math.max(0, Math.round(x * dpr)));
91
+ const py = Math.min(crisp.height - 1, Math.max(0, Math.round(y * dpr)));
92
+ return g.alpha[(py * crisp.width + px) * 4 + 3] > 110;
93
+ };
94
+
95
+ /**
96
+ * One frame: the text at rest, with every hot cell redrawn as blocks.
97
+ *
98
+ * @returns {boolean} Whether any cell is still hot.
99
+ */
100
+ const draw = () => {
101
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
102
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
103
+ ctx.drawImage(crisp, 0, 0);
104
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
105
+ ctx.fillStyle = g.ink;
106
+ let hot = false;
107
+ for (let row = 0; row < g.rows; row++) {
108
+ for (let col = 0; col < g.cols; col++) {
109
+ const i = row * g.cols + col;
110
+ const heat = g.heat[i];
111
+ if (heat < 0.02) {
112
+ g.heat[i] = 0;
113
+ continue;
114
+ }
115
+ hot = true;
116
+ const x0 = col * CELL;
117
+ const y0 = row * CELL;
118
+ // Wipe the cell, then fill it with blocks sampled from the filled text.
119
+ ctx.clearRect(x0, y0, CELL, CELL);
120
+ const block = Math.max(3, Math.round(3 + heat * (MAX_BLOCK - 3)));
121
+ // The hottest cells also slip sideways: the glitch.
122
+ const shift = heat > 0.55 ? Math.round((Math.random() - 0.5) * heat * SHIFT) : 0;
123
+ const bx0 = Math.floor(x0 / block) * block;
124
+ const by0 = Math.floor(y0 / block) * block;
125
+ for (let by = by0; by < y0 + CELL; by += block) {
126
+ for (let bx = bx0; bx < x0 + CELL; bx += block) {
127
+ if (!inked(bx + block / 2, by + block / 2)) continue;
128
+ // Clipped to the cell, so neighbours tile cleanly.
129
+ const w = Math.min(bx + block, x0 + CELL) - Math.max(bx, x0);
130
+ const h = Math.min(by + block, y0 + CELL) - Math.max(by, y0);
131
+ ctx.fillRect(Math.max(bx, x0) + shift, Math.max(by, y0), w, h);
132
+ }
133
+ }
134
+ g.heat[i] = heat * DECAY;
135
+ }
136
+ }
137
+ return hot;
138
+ };
139
+
140
+ /** Animates while any cell is hot and the text is on screen. */
141
+ const loop = () => {
142
+ if (g.running) return;
143
+ g.running = true;
144
+ /** One frame, and the next if still needed. */
145
+ const tick = () => {
146
+ const hot = draw();
147
+ if (hot && g.visible) requestAnimationFrame(tick);
148
+ else g.running = false;
149
+ };
150
+ requestAnimationFrame(tick);
151
+ };
152
+
153
+ /**
154
+ * Draws the text at rest into `crisp`, each glyph where the browser put
155
+ * it: solid, or with `stroke` an outline (the stroke is centred on the
156
+ * glyph's edge, so it is drawn twice as wide and the inner half cut away).
157
+ */
158
+ const paint = () => {
159
+ const texts = textNodes(el);
160
+ if (!texts.length) return;
161
+ const box = el.getBoundingClientRect();
162
+ const all = document.createRange();
163
+ all.setStart(texts[0], 0);
164
+ all.setEnd(texts[texts.length - 1], texts[texts.length - 1].length);
165
+ const area = all.getBoundingClientRect();
166
+ const pad = 4;
167
+ g.ox = Math.floor(Math.min(0, area.left - box.left) - pad);
168
+ g.oy = Math.floor(area.top - box.top - pad);
169
+ g.w = Math.ceil(Math.max(box.right, area.right) - box.left - g.ox + pad);
170
+ g.h = Math.ceil(area.height + pad * 2);
171
+ const origin = { x: box.left + g.ox, y: box.top + g.oy };
172
+ for (const c of [canvas, crisp]) {
173
+ c.width = Math.max(1, Math.round(g.w * dpr));
174
+ c.height = Math.max(1, Math.round(g.h * dpr));
175
+ }
176
+ Object.assign(canvas.style, { width: `${g.w}px`, height: `${g.h}px`, left: `${g.ox}px`, top: `${g.oy}px` });
177
+
178
+ const cs = getComputedStyle(el);
179
+ g.ink = cs.color;
180
+ // Read back on every repaint (resizes, fonts loading): kept on the CPU.
181
+ const c2 = /** @type {CanvasRenderingContext2D} */ (crisp.getContext('2d', { willReadFrequently: true }));
182
+ c2.setTransform(dpr, 0, 0, dpr, 0, 0);
183
+ c2.clearRect(0, 0, g.w, g.h);
184
+ c2.fillStyle = g.ink;
185
+ c2.strokeStyle = g.ink;
186
+ c2.lineJoin = 'round';
187
+ c2.font = `${cs.fontStyle} ${cs.fontWeight} ${cs.fontSize} ${cs.fontFamily}`;
188
+ c2.textBaseline = 'alphabetic';
189
+ const range = document.createRange();
190
+ /**
191
+ * Draws every glyph where the browser laid it out.
192
+ *
193
+ * @param {(ch: string, x: number, y: number) => void} glyph Draws one glyph at a baseline position.
194
+ */
195
+ const eachGlyph = (glyph) => {
196
+ for (const text of texts) {
197
+ const str = text.textContent ?? '';
198
+ for (let i = 0; i < str.length; i++) {
199
+ const ch = str[i];
200
+ if (!ch.trim()) continue;
201
+ range.setStart(text, i);
202
+ range.setEnd(text, i + 1);
203
+ const r = range.getBoundingClientRect();
204
+ // The glyph's box starts at r.top; its baseline sits one font ascent below.
205
+ glyph(ch, r.left - origin.x, r.top - origin.y + c2.measureText(ch).fontBoundingBoxAscent);
206
+ }
207
+ }
208
+ };
209
+ eachGlyph((ch, x, y) => c2.fillText(ch, x, y));
210
+ g.alpha = c2.getImageData(0, 0, crisp.width, crisp.height).data;
211
+ if (STROKE > 0) {
212
+ c2.clearRect(0, 0, g.w, g.h);
213
+ c2.lineWidth = STROKE * 2;
214
+ eachGlyph((ch, x, y) => c2.strokeText(ch, x, y));
215
+ c2.globalCompositeOperation = 'destination-out';
216
+ eachGlyph((ch, x, y) => c2.fillText(ch, x, y));
217
+ c2.globalCompositeOperation = 'source-over';
218
+ }
219
+ g.cols = Math.ceil(g.w / CELL);
220
+ g.rows = Math.ceil(g.h / CELL);
221
+ g.heat = new Float32Array(g.cols * g.rows);
222
+ draw();
223
+ el.classList.add('is-ready');
224
+ };
225
+
226
+ /**
227
+ * Warms the cells around (x, y), more for a faster move.
228
+ *
229
+ * @param {number} x Across the canvas, CSS px.
230
+ * @param {number} y Down the canvas, CSS px.
231
+ */
232
+ const heatAt = (x, y) => {
233
+ const speed = g.last ? Math.hypot(x - g.last.x, y - g.last.y) : 0;
234
+ g.last = { x, y };
235
+ const add = Math.min(1, 0.25 + speed / 40);
236
+ const c0 = Math.max(0, Math.floor((x - REACH) / CELL));
237
+ const c1 = Math.min(g.cols - 1, Math.floor((x + REACH) / CELL));
238
+ const r0 = Math.max(0, Math.floor((y - REACH) / CELL));
239
+ const r1 = Math.min(g.rows - 1, Math.floor((y + REACH) / CELL));
240
+ for (let r = r0; r <= r1; r++) {
241
+ for (let c = c0; c <= c1; c++) {
242
+ const d = Math.hypot(c * CELL + CELL / 2 - x, r * CELL + CELL / 2 - y);
243
+ if (d > REACH) continue;
244
+ // A soft edge, with a little noise so the border is not a circle.
245
+ const falloff = (1 - d / REACH) ** 1.6 * (0.75 + Math.random() * 0.5);
246
+ g.heat[r * g.cols + c] = Math.min(1, g.heat[r * g.cols + c] + add * falloff);
247
+ }
248
+ }
249
+ loop();
250
+ };
251
+
252
+ /** @param {PointerEvent} e The move. */
253
+ const move = (e) => {
254
+ if (!g.visible || !g.alpha.length) return;
255
+ const box = el.getBoundingClientRect();
256
+ const x = e.clientX - box.left - g.ox;
257
+ const y = e.clientY - box.top - g.oy;
258
+ if (x < -REACH / 2 || y < -REACH / 2 || x > g.w + REACH / 2 || y > g.h + REACH / 2) {
259
+ g.last = undefined;
260
+ return;
261
+ }
262
+ heatAt(x, y);
263
+ };
264
+ document.addEventListener('pointermove', move, { passive: true });
265
+
266
+ // Repaint when the text changes size (fit-text, fonts loading).
267
+ let pending = 0;
268
+ const resizer = new ResizeObserver(() => {
269
+ cancelAnimationFrame(pending);
270
+ pending = requestAnimationFrame(paint);
271
+ });
272
+ resizer.observe(el);
273
+ const watcher = new IntersectionObserver(([entry]) => {
274
+ g.visible = entry.isIntersecting;
275
+ });
276
+ watcher.observe(el);
277
+ document.fonts?.ready.then(paint).catch(() => {});
278
+ paint();
279
+
280
+ return () => {
281
+ document.removeEventListener('pointermove', move);
282
+ resizer.disconnect();
283
+ watcher.disconnect();
284
+ canvas.remove();
285
+ el.classList.remove('is-ready');
286
+ };
287
+ }
@@ -0,0 +1,33 @@
1
+ import type { PaletteName } from './palettes.js';
2
+
3
+ export interface PointCloudConfig {
4
+ /** The word drawn in dots. */
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 draw in dots instead. */
9
+ src?: string;
10
+ /** Where the word sits, each 0–1 from the top left. Default across the middle. */
11
+ area?: { x: number; y: number; width: number; height: number };
12
+ /** The word's dots, then the clouds' low and high colours. Default white, deep blue, sky blue. */
13
+ colors?: string[];
14
+ /** A shared palette by name (`PALETTES`, any case), when there are no `colors`. */
15
+ palette?: PaletteName | (string & {});
16
+ /** The ground. Default `#020205`. */
17
+ background?: string;
18
+ /** Dots across the word's grid. Default 110. */
19
+ columns?: number;
20
+ /** A word dot's size, a share of the grid's spacing. Default 0.72. */
21
+ dot?: number;
22
+ /** How many sheets of point cloud. Default 9. */
23
+ sheets?: number;
24
+ /** A cloud point's size, CSS px. Default 2.2. */
25
+ pointSize?: number;
26
+ /** Tracker boxes locking onto the word, a detector's debug look (try 4); 0 for none. Default 0. */
27
+ trackers?: number;
28
+ /** How far the scene tilts towards the pointer. Default 1. */
29
+ tilt?: number;
30
+ }
31
+
32
+ /** Starts a point cloud in `el`'s canvas. Returns a function that stops it. */
33
+ export function pointCloud(el: HTMLElement, config: PointCloudConfig): () => void;
@@ -0,0 +1,287 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/point-cloud
3
+ *
4
+ * A machine-vision scene: a word drawn as a matrix of bright dots, floating
5
+ * among sheets of point cloud, each sheet a rippling surface scanned in
6
+ * rows of fine dots, coloured by height. The scene sways and tilts towards
7
+ * the pointer in perspective. Optionally (`trackers`), boxes lock onto
8
+ * parts of the word with confidence labels, like a detector's debug view.
9
+ *
10
+ * Positions are worked out on the GPU from each point's place on its sheet
11
+ * and a seed; tens of thousands of points cost one draw.
12
+ *
13
+ * Opaque: the effect is the whole background of what it fills. Without
14
+ * WebGL it removes its canvas and the element's background shows.
15
+ */
16
+
17
+ import { createStage } from './stage.js';
18
+ import { createPoints, projectPoint, GLSL_PROJECT } from './points.js';
19
+ import { drawShape, gridPoints } from './shape.js';
20
+ import { createTrackers } from './trackers.js';
21
+ import { parseColor } from './color.js';
22
+ import { canHover, isMobileGpu } from './device.js';
23
+ import { pointerIn } from './pointer.js';
24
+ import { watchColors } from './mount.js';
25
+ import { pickColors } from './palettes.js';
26
+
27
+ /**
28
+ * @typedef {object} PointCloudConfig
29
+ * @property {string} [text] The word drawn in dots.
30
+ * @property {string} [font] Its CSS font, without the size (default: the page's, bold).
31
+ * @property {string} [src] An image (an SVG logo) to draw in dots instead.
32
+ * @property {{ x: number, y: number, width: number, height: number }} [area]
33
+ * Where the word sits, each 0–1 from the top left (default: across the middle).
34
+ * @property {string[]} [colors] The word's dots, then the clouds' low and high colours (default white, deep blue, sky blue).
35
+ * @property {string} [palette] A shared palette by name (PALETTES; any case), when there are no `colors`.
36
+ * @property {string} [background='#020205'] The ground.
37
+ * @property {number} [columns=110] Dots across the word's grid.
38
+ * @property {number} [dot=0.72] A word dot's size, as a share of the grid's spacing.
39
+ * @property {number} [sheets=9] How many sheets of point cloud.
40
+ * @property {number} [pointSize=2.2] A cloud point's size, CSS px.
41
+ * @property {number} [trackers=0] Tracker boxes locking onto the word, a detector's debug look (try 4); 0 for none.
42
+ * @property {number} [tilt=1] How far the scene tilts towards the pointer.
43
+ */
44
+
45
+ /** The ground: near-black, a little lighter in the middle. */
46
+ const GROUND = `
47
+ precision highp float;
48
+ uniform vec2 uRes;
49
+ uniform vec3 uGround;
50
+ uniform vec3 uGlow;
51
+ void main() {
52
+ vec2 uv = gl_FragCoord.xy / uRes;
53
+ vec2 d = (uv - 0.5) * vec2(uRes.x / uRes.y, 1.0);
54
+ gl_FragColor = vec4(uGround + uGlow * exp(-dot(d, d) * 3.0) * 0.08, 1.0);
55
+ }
56
+ `;
57
+
58
+ /** Each point: a dot of the word (kind < 0), or a point on sheet `kind`. */
59
+ const VERTEX = `
60
+ precision highp float;
61
+ attribute vec4 p;
62
+ uniform vec2 uRes;
63
+ uniform float uTime;
64
+ uniform float uRatio;
65
+ uniform vec2 uShift;
66
+ uniform vec2 uTurn;
67
+ uniform vec3 uText;
68
+ uniform vec3 uLow;
69
+ uniform vec3 uHigh;
70
+ uniform float uTextSize;
71
+ uniform float uPointSize;
72
+ varying vec3 vColour;
73
+ varying float vAlpha;
74
+ ${GLSL_PROJECT}
75
+ float hash1(float n) { return fract(sin(n * 127.1) * 43758.5453); }
76
+ void main() {
77
+ float aspect = uRes.x / uRes.y;
78
+ vec3 v;
79
+ float size;
80
+ if (p.z < 0.0) {
81
+ // A dot of the word, trembling very slightly.
82
+ v = vec3((p.x * 2.0 - 1.0) * aspect, p.y * 2.0 - 1.0, 0.0);
83
+ v.xy += 0.002 * vec2(sin(uTime * 2.0 + p.w * 50.0), cos(uTime * 1.7 + p.w * 31.0));
84
+ vColour = uText;
85
+ vAlpha = 1.0;
86
+ size = uTextSize;
87
+ } else {
88
+ // A point on a sheet: the sheet's place, size and facing come from its index.
89
+ float k = p.z + 1.0;
90
+ vec3 centre = vec3((hash1(k * 1.3) - 0.5) * 2.2 * aspect, (hash1(k * 2.7) - 0.5) * 1.5, (hash1(k * 5.1) - 0.5) * 1.0);
91
+ centre.xy += vec2(sin(uTime * 0.05 + k), cos(uTime * 0.04 + k * 2.0)) * 0.12;
92
+ vec3 local = vec3((p.x - 0.5) * (1.4 + hash1(k * 7.7) * 1.4), (p.y - 0.5) * (0.6 + hash1(k * 9.1) * 0.8), 0.0);
93
+ float wave = sin(p.x * 6.0 + uTime * 0.35 + k) * cos(p.y * 5.0 - uTime * 0.27 + k * 2.0) * 0.22
94
+ + sin((p.x + p.y) * 11.0 + k * 3.0 + uTime * 0.2) * 0.06;
95
+ local.z = wave;
96
+ local = rotateX(local, hash1(k * 3.3) * 2.4 - 1.2);
97
+ local = rotateY(local, hash1(k * 4.4) * 3.0 - 1.5);
98
+ v = centre + local;
99
+ vColour = mix(uLow, uHigh, clamp(wave * 2.2 + 0.5, 0.0, 1.0));
100
+ // Thinning out towards the sheet's edges, so it has no hard border.
101
+ vAlpha = 0.95 * smoothstep(0.0, 0.18, p.x) * smoothstep(1.0, 0.82, p.x) * smoothstep(0.0, 0.25, p.y) * smoothstep(1.0, 0.75, p.y);
102
+ size = uPointSize * (0.75 + hash1(p.w * 91.0) * 0.5);
103
+ }
104
+ v = rotateY(v, uTurn.x);
105
+ v = rotateX(v, uTurn.y);
106
+ vec4 pos = project(v, aspect);
107
+ gl_Position = pos + vec4(uShift * pos.w, 0.0, 0.0);
108
+ gl_PointSize = size * uRatio / pos.w;
109
+ vAlpha *= clamp(1.25 - pos.w * 0.35, 0.25, 1.0);
110
+ }
111
+ `;
112
+
113
+ /** The defaults: white dots, deep and sky blue clouds. */
114
+ const COLORS = ['#ffffff', '#2a2aff', '#7cc8ff'];
115
+
116
+ /**
117
+ * The sheets of point cloud as particle data: a grid of points per sheet,
118
+ * each with its place on the sheet, the sheet's index and a seed.
119
+ *
120
+ * @param {number} sheets How many sheets.
121
+ * @param {number} columns Points across a sheet.
122
+ * @param {number} rows Rows down a sheet.
123
+ * @returns {number[]} Four numbers a point.
124
+ */
125
+ function sheetData(sheets, columns, rows) {
126
+ const out = [];
127
+ for (let k = 0; k < sheets; k++) {
128
+ for (let r = 0; r < rows; r++) {
129
+ for (let c = 0; c < columns; c++) out.push(c / (columns - 1), r / (rows - 1), k, Math.random());
130
+ }
131
+ }
132
+ return out;
133
+ }
134
+
135
+ /**
136
+ * Starts a point cloud on an element: an opaque canvas inside it, filling it.
137
+ *
138
+ * @param {HTMLElement} el The element (its first canvas is drawn into).
139
+ * @param {PointCloudConfig} config The settings.
140
+ * @returns {() => void} Stops it.
141
+ */
142
+ export function pointCloud(el, config) {
143
+ let colors = pickColors(config, COLORS, (p) => ['#ffffff', p.colors[0], p.colors[1]]);
144
+ const start = performance.now();
145
+ const turn = { y: 0, x: 0 };
146
+ /** @type {import('./points.js').Points | null} */
147
+ let points = null;
148
+ /** The word's dots (x, y pairs, 0–1, y up), for the trackers to lock onto. */
149
+ /** @type {Float32Array} */
150
+ let dots = new Float32Array(0);
151
+ let generation = 0;
152
+ const sheets = sheetData(config.sheets ?? 9, isMobileGpu() ? 100 : 170, isMobileGpu() ? 40 : 70);
153
+ const trackers = (config.trackers ?? 0) > 0 ? createTrackers(el, config.trackers ?? 0) : null;
154
+ /** What each tracker is locked onto: a box of the word in 0–1 coordinates, its label, and when it moves on. */
155
+ const locks = Array.from({ length: config.trackers ?? 0 }, () => ({ box: [0, 0, 0, 0], label: '', until: 0 }));
156
+
157
+ /**
158
+ * Locks a tracker onto a cluster of the word's dots: a random dot and its
159
+ * neighbours, boxed.
160
+ *
161
+ * @param {typeof locks[number]} lock The tracker's lock.
162
+ * @param {number} t The time, seconds.
163
+ */
164
+ const relock = (lock, t) => {
165
+ lock.until = t + 2 + Math.random() * 2.5;
166
+ const n = dots.length / 2;
167
+ if (!n) return;
168
+ // A dot well away from where the other trackers are, so they do not pile up.
169
+ let i = 0;
170
+ for (let tries = 0; tries < 24; tries++) {
171
+ i = Math.floor(Math.random() * n);
172
+ const x = dots[i * 2];
173
+ if (locks.every((other) => other === lock || Math.abs((other.box[0] + other.box[2]) / 2 - x) > 0.16)) break;
174
+ }
175
+ const cx = dots[i * 2];
176
+ const cy = dots[i * 2 + 1];
177
+ const reach = 0.05 + Math.random() * 0.06;
178
+ let [x0, y0, x1, y1] = [cx, cy, cx, cy];
179
+ for (let j = 0; j < n; j++) {
180
+ const x = dots[j * 2];
181
+ const y = dots[j * 2 + 1];
182
+ if (Math.abs(x - cx) < reach && Math.abs(y - cy) < reach * 1.6) {
183
+ x0 = Math.min(x0, x);
184
+ y0 = Math.min(y0, y);
185
+ x1 = Math.max(x1, x);
186
+ y1 = Math.max(y1, y);
187
+ }
188
+ }
189
+ lock.box = [x0 - 0.01, y0 - 0.015, x1 + 0.01, y1 + 0.015];
190
+ lock.label = `${Math.round(70 + Math.random() * 29)}%`;
191
+ };
192
+
193
+ const { stage, stop } = createStage(el, {
194
+ fragment: GROUND,
195
+ alpha: false,
196
+ setup({ gl, program }) {
197
+ points = createPoints(gl, VERTEX);
198
+ if (!points) return false;
199
+ gl.useProgram(program);
200
+ return () => trackers?.destroy();
201
+ },
202
+ resize({ canvas }) {
203
+ const mine = ++generation;
204
+ const width = Math.min(1024, canvas.width);
205
+ const height = Math.max(1, Math.round((width * canvas.height) / canvas.width));
206
+ drawShape(
207
+ { text: config.text, font: config.font, src: config.src, area: config.area ?? { x: 0.08, y: 0.3, width: 0.84, height: 0.3 }, padding: 0.02 },
208
+ width,
209
+ height,
210
+ )
211
+ .then((mask) => {
212
+ if (mine !== generation || !points) return;
213
+ dots = gridPoints(mask, Math.round((config.columns ?? 110) / (config.area?.width ?? 0.84)));
214
+ const data = new Float32Array(sheets.length + (dots.length / 2) * 4);
215
+ data.set(sheets);
216
+ for (let i = 0; i < dots.length / 2; i++) {
217
+ data.set([dots[i * 2], dots[i * 2 + 1], -1, Math.random()], sheets.length + i * 4);
218
+ }
219
+ points.upload(data);
220
+ locks.forEach((lock) => (lock.until = 0));
221
+ if (stage?.still) stage.redraw();
222
+ })
223
+ .catch((error) => console.warn('[effects-astro]', error));
224
+ },
225
+ uniforms({ gl, uniform }) {
226
+ gl.uniform3fv(uniform('uGround'), parseColor(config.background ?? '#020205'));
227
+ gl.uniform3fv(uniform('uGlow'), parseColor(colors[2] ?? COLORS[2]));
228
+ },
229
+ after({ gl, canvas, ratio, still }, now) {
230
+ if (!points?.count()) return;
231
+ const t = (now - start) / 1000;
232
+ const p = !still && canHover() ? pointerIn(el) : null;
233
+ const lean = p?.inside ? { x: (p.x - 0.5) * 2, y: (p.y - 0.5) * 2 } : { x: 0, y: 0 };
234
+ const tilt = config.tilt ?? 1;
235
+ turn.y += (lean.x * 0.3 * tilt + Math.sin(t * 0.1) * 0.08 - turn.y) * 0.05;
236
+ turn.x += (-lean.y * 0.2 * tilt - turn.x) * 0.05;
237
+ const u = points.program.uniform;
238
+ points.passes(0, () => {
239
+ gl.uniform2f(u('uRes'), canvas.width, canvas.height);
240
+ gl.uniform1f(u('uTime'), t);
241
+ gl.uniform1f(u('uRatio'), ratio);
242
+ gl.uniform2f(u('uTurn'), turn.y, turn.x);
243
+ gl.uniform3fv(u('uText'), parseColor(colors[0]));
244
+ gl.uniform3fv(u('uLow'), parseColor(colors[1] ?? COLORS[1]));
245
+ gl.uniform3fv(u('uHigh'), parseColor(colors[2] ?? COLORS[2]));
246
+ // A word dot: a share of the grid's spacing, in CSS px.
247
+ gl.uniform1f(u('uTextSize'), Math.max(2, (canvas.width / ratio / ((config.columns ?? 110) / (config.area?.width ?? 0.84))) * (config.dot ?? 0.72)));
248
+ gl.uniform1f(u('uPointSize'), config.pointSize ?? 2.2);
249
+ });
250
+
251
+ // The trackers, boxed over the word where the shader draws it.
252
+ if (!trackers) return;
253
+ const aspect = canvas.width / canvas.height;
254
+ const w = el.clientWidth;
255
+ const h = el.clientHeight;
256
+ locks.forEach((lock, i) => {
257
+ if (t > lock.until) relock(lock, t);
258
+ if (!dots.length) return trackers.place(i, null);
259
+ const [x0, y0, x1, y1] = lock.box;
260
+ /**
261
+ * Where a point of the word lands on screen.
262
+ *
263
+ * @param {number} x Across the word's canvas, 0–1.
264
+ * @param {number} y Up it, 0–1.
265
+ * @returns {{ x: number, y: number }} 0–1 from the top left.
266
+ */
267
+ const corner = (x, y) => projectPoint([(x * 2 - 1) * aspect, y * 2 - 1, 0], turn.y, turn.x, aspect);
268
+ const a = corner(x0, y1);
269
+ const b = corner(x1, y0);
270
+ trackers.place(i, { x: a.x * w, y: a.y * h, w: (b.x - a.x) * w, h: (b.y - a.y) * h }, lock.label);
271
+ });
272
+ },
273
+ });
274
+ if (!stage) {
275
+ trackers?.destroy();
276
+ return stop;
277
+ }
278
+
279
+ const unwatch = watchColors(el, (next) => {
280
+ colors = next.colors;
281
+ if (stage.still) stage.redraw();
282
+ });
283
+ return () => {
284
+ stop();
285
+ unwatch();
286
+ };
287
+ }
@@ -0,0 +1,27 @@
1
+ /** A point on a stroke: where (0–1 across, 0–1 up the element) and the stroke's velocity (element sizes a second). */
2
+ export interface StrokePoint {
3
+ x: number;
4
+ y: number;
5
+ dx: number;
6
+ dy: number;
7
+ }
8
+
9
+ /** Where the pointer is over `el`: x 0–1 left to right, y 0–1 bottom to top; `inside` false outside it or the window. */
10
+ export function pointerIn(el: Element): { x: number; y: number; inside: boolean };
11
+
12
+ /**
13
+ * Follows the pointer's strokes over `el`. `read(dt)` returns the points
14
+ * along the path since the last read, spaced at most `step` apart (default
15
+ * 0.01), at most `max` of them (default 16); a jump returns none.
16
+ * `reset()` makes the next move start a new stroke.
17
+ */
18
+ export function trail(el: Element, options?: { step?: number; max?: number }): {
19
+ read(dt: number): StrokePoint[];
20
+ reset(): void;
21
+ };
22
+
23
+ /** Links, buttons, form fields and `[data-effect-ignore]`: presses on these are not an effect's. */
24
+ export const CLICK_IGNORE: string;
25
+
26
+ /** Where a press landed on `el` (x 0–1 left to right, y 0–1 bottom to top), or null outside it or on an ignored target. */
27
+ export function pressAt(el: Element, e: PointerEvent, ignore?: string): { x: number; y: number } | null;