@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.
- package/AGENTS.md +85 -0
- package/COMPONENTS.md +1264 -0
- package/LICENSE +139 -0
- package/README.md +197 -2
- package/package.json +60 -4
- package/src/components/AsciiRain.astro +36 -0
- package/src/components/BorderSweep.astro +39 -0
- package/src/components/Caustics.astro +39 -0
- package/src/components/ColorPanels.astro +62 -0
- package/src/components/Cursor.astro +97 -0
- package/src/components/DotGrid.astro +34 -0
- package/src/components/DotSurface.astro +35 -0
- package/src/components/EffectCanvas.astro +152 -0
- package/src/components/FitText.astro +35 -0
- package/src/components/FlutedGlass.astro +36 -0
- package/src/components/Glass.astro +69 -0
- package/src/components/GlassGlyph.astro +38 -0
- package/src/components/GlowField.astro +177 -0
- package/src/components/Grain.astro +98 -0
- package/src/components/HaloRing.astro +38 -0
- package/src/components/HighlightSweep.astro +74 -0
- package/src/components/ImageRipple.astro +56 -0
- package/src/components/Ink.astro +37 -0
- package/src/components/InkField.astro +45 -0
- package/src/components/IsoCity.astro +54 -0
- package/src/components/LightField.astro +40 -0
- package/src/components/LiquidMetal.astro +41 -0
- package/src/components/Magnetic.astro +52 -0
- package/src/components/Marquee.astro +216 -0
- package/src/components/MosaicReveal.astro +196 -0
- package/src/components/NebulaLogo.astro +38 -0
- package/src/components/NeonSwarm.astro +38 -0
- package/src/components/Ocean.astro +40 -0
- package/src/components/OutlineWordmark.astro +222 -0
- package/src/components/PaperBackground.astro +40 -0
- package/src/components/PaperShader.astro +55 -0
- package/src/components/Parallax.astro +49 -0
- package/src/components/ParticleLogo.astro +37 -0
- package/src/components/PixelGlitchText.astro +70 -0
- package/src/components/PointCloud.astro +37 -0
- package/src/components/ProductStack.astro +298 -0
- package/src/components/PulseMark.astro +189 -0
- package/src/components/RadiantGlass.astro +38 -0
- package/src/components/RainOnGlass.astro +71 -0
- package/src/components/Reveal.astro +115 -0
- package/src/components/ScrambleText.astro +52 -0
- package/src/components/ScrollReveal.astro +38 -0
- package/src/components/ShaderBackground.astro +55 -0
- package/src/components/SignalLines.astro +41 -0
- package/src/components/SilkRibbon.astro +37 -0
- package/src/components/SpotlightText.astro +131 -0
- package/src/components/Tilt.astro +79 -0
- package/src/components/Topography.astro +38 -0
- package/src/components/Typewriter.astro +66 -0
- package/src/components/VariableType.astro +59 -0
- package/src/components/VoxelLogo.astro +46 -0
- package/src/components/WaveBars.astro +41 -0
- package/src/components/WorldRoutes.astro +41 -0
- package/src/components/style.js +19 -0
- package/src/index.d.ts +143 -0
- package/src/index.js +105 -0
- package/src/runtime/ascii-rain.d.ts +53 -0
- package/src/runtime/ascii-rain.js +355 -0
- package/src/runtime/audio-meter.d.ts +65 -0
- package/src/runtime/audio-meter.js +282 -0
- package/src/runtime/audio.d.ts +26 -0
- package/src/runtime/audio.js +453 -0
- package/src/runtime/blur.d.ts +2 -0
- package/src/runtime/blur.js +56 -0
- package/src/runtime/canvas2d.d.ts +23 -0
- package/src/runtime/canvas2d.js +105 -0
- package/src/runtime/caustics.d.ts +40 -0
- package/src/runtime/caustics.js +286 -0
- package/src/runtime/color.d.ts +33 -0
- package/src/runtime/color.js +213 -0
- package/src/runtime/curl.d.ts +5 -0
- package/src/runtime/curl.js +81 -0
- package/src/runtime/cursor.d.ts +9 -0
- package/src/runtime/cursor.js +80 -0
- package/src/runtime/device.d.ts +14 -0
- package/src/runtime/device.js +73 -0
- package/src/runtime/dot-grid.d.ts +27 -0
- package/src/runtime/dot-grid.js +245 -0
- package/src/runtime/dot-surface.d.ts +46 -0
- package/src/runtime/dot-surface.js +429 -0
- package/src/runtime/feedback.d.ts +18 -0
- package/src/runtime/feedback.js +131 -0
- package/src/runtime/fit-text.d.ts +5 -0
- package/src/runtime/fit-text.js +60 -0
- package/src/runtime/fluid.d.ts +55 -0
- package/src/runtime/fluid.js +504 -0
- package/src/runtime/fluted-glass.d.ts +27 -0
- package/src/runtime/fluted-glass.js +157 -0
- package/src/runtime/gl.d.ts +19 -0
- package/src/runtime/gl.js +104 -0
- package/src/runtime/glass-glyph.d.ts +49 -0
- package/src/runtime/glass-glyph.js +355 -0
- package/src/runtime/glass-sheen.d.ts +2 -0
- package/src/runtime/glass-sheen.js +30 -0
- package/src/runtime/glsl.d.ts +17 -0
- package/src/runtime/glsl.js +78 -0
- package/src/runtime/glyphs.d.ts +22 -0
- package/src/runtime/glyphs.js +107 -0
- package/src/runtime/halo-ring.d.ts +47 -0
- package/src/runtime/halo-ring.js +334 -0
- package/src/runtime/height-field.d.ts +50 -0
- package/src/runtime/height-field.js +176 -0
- package/src/runtime/image-ripple.d.ts +25 -0
- package/src/runtime/image-ripple.js +353 -0
- package/src/runtime/image.d.ts +11 -0
- package/src/runtime/image.js +81 -0
- package/src/runtime/in-view.d.ts +6 -0
- package/src/runtime/in-view.js +36 -0
- package/src/runtime/ink-field/shaders.js +258 -0
- package/src/runtime/ink-field/sim.js +582 -0
- package/src/runtime/ink-field.d.ts +39 -0
- package/src/runtime/ink-field.js +311 -0
- package/src/runtime/ink.d.ts +31 -0
- package/src/runtime/ink.js +109 -0
- package/src/runtime/instancing.d.ts +12 -0
- package/src/runtime/instancing.js +37 -0
- package/src/runtime/iso-camera.d.ts +35 -0
- package/src/runtime/iso-camera.js +85 -0
- package/src/runtime/iso-city/figures.d.ts +30 -0
- package/src/runtime/iso-city/figures.js +136 -0
- package/src/runtime/iso-city/look.d.ts +34 -0
- package/src/runtime/iso-city/look.js +105 -0
- package/src/runtime/iso-city/plan.d.ts +59 -0
- package/src/runtime/iso-city/plan.js +463 -0
- package/src/runtime/iso-city/roads.d.ts +64 -0
- package/src/runtime/iso-city/roads.js +320 -0
- package/src/runtime/iso-city/scene.d.ts +27 -0
- package/src/runtime/iso-city/scene.js +432 -0
- package/src/runtime/iso-city/shaders.d.ts +6 -0
- package/src/runtime/iso-city/shaders.js +233 -0
- package/src/runtime/iso-city/shadows.d.ts +13 -0
- package/src/runtime/iso-city/shadows.js +148 -0
- package/src/runtime/iso-city/traffic.d.ts +80 -0
- package/src/runtime/iso-city/traffic.js +457 -0
- package/src/runtime/iso-city.d.ts +37 -0
- package/src/runtime/iso-city.js +458 -0
- package/src/runtime/lens-map.d.ts +11 -0
- package/src/runtime/lens-map.js +146 -0
- package/src/runtime/light-field.d.ts +29 -0
- package/src/runtime/light-field.js +292 -0
- package/src/runtime/liquid-glass.d.ts +48 -0
- package/src/runtime/liquid-glass.js +423 -0
- package/src/runtime/liquid-metal/beads.js +217 -0
- package/src/runtime/liquid-metal/field.js +88 -0
- package/src/runtime/liquid-metal/look.js +64 -0
- package/src/runtime/liquid-metal/shaders.js +255 -0
- package/src/runtime/liquid-metal/wave.js +53 -0
- package/src/runtime/liquid-metal.d.ts +46 -0
- package/src/runtime/liquid-metal.js +366 -0
- package/src/runtime/loop.d.ts +7 -0
- package/src/runtime/loop.js +112 -0
- package/src/runtime/magnetic.d.ts +9 -0
- package/src/runtime/magnetic.js +46 -0
- package/src/runtime/marquee.d.ts +2 -0
- package/src/runtime/marquee.js +27 -0
- package/src/runtime/mesh.d.ts +30 -0
- package/src/runtime/mesh.js +217 -0
- package/src/runtime/mosaic-reveal.d.ts +34 -0
- package/src/runtime/mosaic-reveal.js +504 -0
- package/src/runtime/motion.d.ts +2 -0
- package/src/runtime/motion.js +21 -0
- package/src/runtime/mount.d.ts +13 -0
- package/src/runtime/mount.js +120 -0
- package/src/runtime/nebula-logo.d.ts +31 -0
- package/src/runtime/nebula-logo.js +282 -0
- package/src/runtime/neon-swarm.d.ts +31 -0
- package/src/runtime/neon-swarm.js +258 -0
- package/src/runtime/ocean/presets.d.ts +54 -0
- package/src/runtime/ocean/presets.js +184 -0
- package/src/runtime/ocean/shader.d.ts +14 -0
- package/src/runtime/ocean/shader.js +389 -0
- package/src/runtime/ocean/view.d.ts +24 -0
- package/src/runtime/ocean/view.js +98 -0
- package/src/runtime/ocean/waves.d.ts +29 -0
- package/src/runtime/ocean/waves.js +119 -0
- package/src/runtime/ocean.d.ts +31 -0
- package/src/runtime/ocean.js +173 -0
- package/src/runtime/palettes.d.ts +37 -0
- package/src/runtime/palettes.js +75 -0
- package/src/runtime/paper-look.d.ts +42 -0
- package/src/runtime/paper-look.js +91 -0
- package/src/runtime/paper-looks.d.ts +17 -0
- package/src/runtime/paper-looks.js +21 -0
- package/src/runtime/paper.d.ts +37 -0
- package/src/runtime/paper.js +285 -0
- package/src/runtime/particle-logo.d.ts +31 -0
- package/src/runtime/particle-logo.js +196 -0
- package/src/runtime/ping-pong.d.ts +43 -0
- package/src/runtime/ping-pong.js +175 -0
- package/src/runtime/pixel-glitch.d.ts +17 -0
- package/src/runtime/pixel-glitch.js +287 -0
- package/src/runtime/point-cloud.d.ts +33 -0
- package/src/runtime/point-cloud.js +287 -0
- package/src/runtime/pointer.d.ts +27 -0
- package/src/runtime/pointer.js +128 -0
- package/src/runtime/points.d.ts +25 -0
- package/src/runtime/points.js +130 -0
- package/src/runtime/pools.d.ts +2 -0
- package/src/runtime/pools.js +25 -0
- package/src/runtime/product-stack.d.ts +24 -0
- package/src/runtime/product-stack.js +210 -0
- package/src/runtime/radiant-glass.d.ts +29 -0
- package/src/runtime/radiant-glass.js +282 -0
- package/src/runtime/rain-on-glass/backdrop.d.ts +22 -0
- package/src/runtime/rain-on-glass/backdrop.js +185 -0
- package/src/runtime/rain-on-glass/shader.d.ts +2 -0
- package/src/runtime/rain-on-glass/shader.js +168 -0
- package/src/runtime/rain-on-glass/wipe.d.ts +16 -0
- package/src/runtime/rain-on-glass/wipe.js +65 -0
- package/src/runtime/rain-on-glass.d.ts +27 -0
- package/src/runtime/rain-on-glass.js +210 -0
- package/src/runtime/ramp.d.ts +2 -0
- package/src/runtime/ramp.js +30 -0
- package/src/runtime/random.d.ts +2 -0
- package/src/runtime/random.js +22 -0
- package/src/runtime/scroll-reveal.d.ts +22 -0
- package/src/runtime/scroll-reveal.js +73 -0
- package/src/runtime/shader-background.d.ts +42 -0
- package/src/runtime/shader-background.js +261 -0
- package/src/runtime/shader-backgrounds/band-lens.js +72 -0
- package/src/runtime/shader-backgrounds/common.js +53 -0
- package/src/runtime/shader-backgrounds/grain-gradient.js +87 -0
- package/src/runtime/shader-backgrounds/grid.js +33 -0
- package/src/runtime/shader-backgrounds/mesh-gradient.js +74 -0
- package/src/runtime/shader-backgrounds/silk.js +57 -0
- package/src/runtime/shader-backgrounds/waves.js +31 -0
- package/src/runtime/shape.d.ts +42 -0
- package/src/runtime/shape.js +313 -0
- package/src/runtime/silk-ribbon.d.ts +23 -0
- package/src/runtime/silk-ribbon.js +206 -0
- package/src/runtime/slideshow.d.ts +27 -0
- package/src/runtime/slideshow.js +234 -0
- package/src/runtime/spotlight.d.ts +9 -0
- package/src/runtime/spotlight.js +97 -0
- package/src/runtime/stack-poses.d.ts +53 -0
- package/src/runtime/stack-poses.js +273 -0
- package/src/runtime/stage.d.ts +47 -0
- package/src/runtime/stage.js +187 -0
- package/src/runtime/swarm.d.ts +49 -0
- package/src/runtime/swarm.js +199 -0
- package/src/runtime/text-motion.d.ts +41 -0
- package/src/runtime/text-motion.js +165 -0
- package/src/runtime/text.d.ts +11 -0
- package/src/runtime/text.js +90 -0
- package/src/runtime/tilt.d.ts +19 -0
- package/src/runtime/tilt.js +116 -0
- package/src/runtime/topography.d.ts +71 -0
- package/src/runtime/topography.js +650 -0
- package/src/runtime/trackers.d.ts +21 -0
- package/src/runtime/trackers.js +76 -0
- package/src/runtime/variable-type.d.ts +43 -0
- package/src/runtime/variable-type.js +358 -0
- package/src/runtime/voxel-logo.d.ts +31 -0
- package/src/runtime/voxel-logo.js +237 -0
- package/src/runtime/waves.d.ts +70 -0
- package/src/runtime/waves.js +799 -0
- package/src/runtime/world-labels.d.ts +29 -0
- package/src/runtime/world-labels.js +59 -0
- package/src/runtime/world-land.d.ts +8 -0
- package/src/runtime/world-land.js +105 -0
- package/src/runtime/world-map.d.ts +69 -0
- package/src/runtime/world-map.js +308 -0
- package/src/runtime/world-plan.d.ts +101 -0
- package/src/runtime/world-plan.js +333 -0
- package/src/runtime/world-routes.d.ts +75 -0
- package/src/runtime/world-routes.js +673 -0
- package/src/styles/border-sweep.css +82 -0
- package/src/styles/glass.css +104 -0
- package/src/styles/motion.css +218 -0
- package/src/styles/reveal.css +51 -0
- package/src/vendor/paper/LICENSE +201 -0
- package/src/vendor/paper/NOTICE +5 -0
- package/src/vendor/paper/README.md +8 -0
- package/src/vendor/paper/get-shader-color-from-string.js +100 -0
- package/src/vendor/paper/get-shader-noise-texture.js +17 -0
- package/src/vendor/paper/presets.js +3678 -0
- package/src/vendor/paper/shader-sizing.js +37 -0
- package/src/vendor/paper/shader-utils.js +130 -0
- package/src/vendor/paper/shaders/color-panels.js +223 -0
- package/src/vendor/paper/shaders/dithering.js +270 -0
- package/src/vendor/paper/shaders/dot-grid.js +109 -0
- package/src/vendor/paper/shaders/dot-orbit.js +122 -0
- package/src/vendor/paper/shaders/fluted-glass.js +360 -0
- package/src/vendor/paper/shaders/gem-smoke.js +572 -0
- package/src/vendor/paper/shaders/god-rays.js +132 -0
- package/src/vendor/paper/shaders/grain-gradient.js +300 -0
- package/src/vendor/paper/shaders/halftone-cmyk.js +294 -0
- package/src/vendor/paper/shaders/halftone-dots.js +320 -0
- package/src/vendor/paper/shaders/heatmap.js +383 -0
- package/src/vendor/paper/shaders/image-dithering.js +198 -0
- package/src/vendor/paper/shaders/lens-distortion.js +275 -0
- package/src/vendor/paper/shaders/liquid-metal.js +632 -0
- package/src/vendor/paper/shaders/mesh-gradient.js +130 -0
- package/src/vendor/paper/shaders/metaballs.js +110 -0
- package/src/vendor/paper/shaders/neuro-noise.js +76 -0
- package/src/vendor/paper/shaders/paper-texture.js +526 -0
- package/src/vendor/paper/shaders/perlin-noise.js +166 -0
- package/src/vendor/paper/shaders/pulsing-border.js +238 -0
- package/src/vendor/paper/shaders/simplex-noise.js +91 -0
- package/src/vendor/paper/shaders/smoke-ring.js +132 -0
- package/src/vendor/paper/shaders/spiral.js +82 -0
- package/src/vendor/paper/shaders/static-mesh-gradient.js +130 -0
- package/src/vendor/paper/shaders/static-radial-gradient.js +187 -0
- package/src/vendor/paper/shaders/swirl.js +103 -0
- package/src/vendor/paper/shaders/voronoi.js +138 -0
- package/src/vendor/paper/shaders/warp.js +129 -0
- package/src/vendor/paper/shaders/water.js +121 -0
- package/src/vendor/paper/shaders/waves.js +65 -0
- package/src/vendor/paper/vertex-shader.js +159 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { GL } from './gl.js';
|
|
2
|
+
|
|
3
|
+
/** A float texture format a context offers for render targets. */
|
|
4
|
+
export interface FloatFormat {
|
|
5
|
+
/** The internal format. */
|
|
6
|
+
internal: number;
|
|
7
|
+
/** The texel type. */
|
|
8
|
+
type: number;
|
|
9
|
+
/** Whether it can be filtered linearly. */
|
|
10
|
+
linear: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** A texture and the framebuffer that draws into it. */
|
|
14
|
+
export interface Target {
|
|
15
|
+
texture: WebGLTexture;
|
|
16
|
+
fbo: WebGLFramebuffer;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Two float targets: read one, write the other, swap. */
|
|
20
|
+
export interface PingPong {
|
|
21
|
+
/** The target read this step. */
|
|
22
|
+
read: Target;
|
|
23
|
+
/** The target written this step. */
|
|
24
|
+
write: Target;
|
|
25
|
+
/** Swaps them, after a step. */
|
|
26
|
+
swap(): void;
|
|
27
|
+
/** Reallocates both at a new size, cleared; false if the GPU will not draw into them. */
|
|
28
|
+
resize(width: number, height: number): boolean;
|
|
29
|
+
/** Clears both to zero (leaves the canvas bound). */
|
|
30
|
+
clear(): void;
|
|
31
|
+
/** Their size, texels. */
|
|
32
|
+
size(): { width: number; height: number };
|
|
33
|
+
/** Whether they are filtered linearly (else nearest). */
|
|
34
|
+
linear: boolean;
|
|
35
|
+
/** Frees the textures and framebuffers. */
|
|
36
|
+
dispose(): void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The float formats a context offers for render targets, best first (full floats, then half). */
|
|
40
|
+
export function floatFormats(gl: GL): FloatFormat[];
|
|
41
|
+
|
|
42
|
+
/** Makes a pair of float targets, cleared; null where the GPU cannot draw into float textures. Uses texture unit 0 while allocating. */
|
|
43
|
+
export function createPingPong(gl: GL, width: number, height: number): PingPong | null;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/ping-pong
|
|
3
|
+
*
|
|
4
|
+
* Two float render targets for a simulation on the GPU: each step reads
|
|
5
|
+
* one and writes the other, then they swap. Full floats where the GPU can
|
|
6
|
+
* draw into and filter them, else half floats; none where it can do
|
|
7
|
+
* neither. WebGL 1 or 2. Uses texture unit 0 while it allocates.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const state = createPingPong(gl, 256, 128);
|
|
11
|
+
* gl.bindFramebuffer(gl.FRAMEBUFFER, state.write.fbo);
|
|
12
|
+
* // …bind state.read.texture, draw a pass…
|
|
13
|
+
* state.swap();
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A float texture format a context offers for render targets.
|
|
18
|
+
*
|
|
19
|
+
* @typedef {object} FloatFormat
|
|
20
|
+
* @property {number} internal The internal format.
|
|
21
|
+
* @property {number} type The texel type.
|
|
22
|
+
* @property {boolean} linear Whether it can be filtered linearly.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A texture and the framebuffer that draws into it.
|
|
27
|
+
*
|
|
28
|
+
* @typedef {object} Target
|
|
29
|
+
* @property {WebGLTexture} texture The texture.
|
|
30
|
+
* @property {WebGLFramebuffer} fbo The framebuffer.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @typedef {object} PingPong
|
|
35
|
+
* @property {Target} read The target read this step.
|
|
36
|
+
* @property {Target} write The target written this step.
|
|
37
|
+
* @property {() => void} swap Swaps them, after a step.
|
|
38
|
+
* @property {(width: number, height: number) => boolean} resize Reallocates
|
|
39
|
+
* both at a new size, cleared; false if the GPU will not draw into them.
|
|
40
|
+
* @property {() => void} clear Clears both to zero.
|
|
41
|
+
* @property {() => { width: number, height: number }} size Their size, texels.
|
|
42
|
+
* @property {boolean} linear Whether they are filtered linearly (else nearest).
|
|
43
|
+
* @property {() => void} dispose Frees the textures and framebuffers.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The float formats a context offers for render targets, best first: full
|
|
48
|
+
* floats where they can be filtered, then half floats, filtered where they
|
|
49
|
+
* can be. Asks for the extensions it needs on the way.
|
|
50
|
+
*
|
|
51
|
+
* @param {WebGLRenderingContext | WebGL2RenderingContext} gl The context.
|
|
52
|
+
* @returns {FloatFormat[]} The candidates (not yet proven drawable).
|
|
53
|
+
*/
|
|
54
|
+
export function floatFormats(gl) {
|
|
55
|
+
/** @type {FloatFormat[]} */
|
|
56
|
+
const formats = [];
|
|
57
|
+
if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
|
|
58
|
+
const color = gl.getExtension('EXT_color_buffer_float');
|
|
59
|
+
if (color && gl.getExtension('OES_texture_float_linear')) formats.push({ internal: gl.RGBA32F, type: gl.FLOAT, linear: true });
|
|
60
|
+
// Half floats always filter in WebGL 2.
|
|
61
|
+
if (color || gl.getExtension('EXT_color_buffer_half_float')) formats.push({ internal: gl.RGBA16F, type: gl.HALF_FLOAT, linear: true });
|
|
62
|
+
return formats;
|
|
63
|
+
}
|
|
64
|
+
const full = gl.getExtension('OES_texture_float');
|
|
65
|
+
if (full && gl.getExtension('OES_texture_float_linear')) {
|
|
66
|
+
gl.getExtension('WEBGL_color_buffer_float');
|
|
67
|
+
formats.push({ internal: gl.RGBA, type: gl.FLOAT, linear: true });
|
|
68
|
+
}
|
|
69
|
+
const half = gl.getExtension('OES_texture_half_float');
|
|
70
|
+
if (half) {
|
|
71
|
+
gl.getExtension('EXT_color_buffer_half_float');
|
|
72
|
+
formats.push({ internal: gl.RGBA, type: half.HALF_FLOAT_OES, linear: !!gl.getExtension('OES_texture_half_float_linear') });
|
|
73
|
+
}
|
|
74
|
+
return formats;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Makes a pair of float targets, cleared.
|
|
79
|
+
*
|
|
80
|
+
* @param {WebGLRenderingContext | WebGL2RenderingContext} gl The context.
|
|
81
|
+
* @param {number} width Texels across.
|
|
82
|
+
* @param {number} height Texels down.
|
|
83
|
+
* @returns {PingPong | null} The pair, or null where the GPU cannot draw into float textures.
|
|
84
|
+
*/
|
|
85
|
+
export function createPingPong(gl, width, height) {
|
|
86
|
+
const targets = [0, 1].map(() => ({
|
|
87
|
+
texture: /** @type {WebGLTexture} */ (gl.createTexture()),
|
|
88
|
+
fbo: /** @type {WebGLFramebuffer} */ (gl.createFramebuffer()),
|
|
89
|
+
}));
|
|
90
|
+
let w = 1;
|
|
91
|
+
let h = 1;
|
|
92
|
+
|
|
93
|
+
/** Frees both targets. */
|
|
94
|
+
const dispose = () => {
|
|
95
|
+
for (const { texture, fbo } of targets) {
|
|
96
|
+
gl.deleteTexture(texture);
|
|
97
|
+
gl.deleteFramebuffer(fbo);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Allocates both targets in a format, cleared.
|
|
103
|
+
*
|
|
104
|
+
* @param {FloatFormat} format The format.
|
|
105
|
+
* @returns {boolean} Whether the GPU can draw into them.
|
|
106
|
+
*/
|
|
107
|
+
const allocate = (format) => {
|
|
108
|
+
const filter = format.linear ? gl.LINEAR : gl.NEAREST;
|
|
109
|
+
for (const { texture, fbo } of targets) {
|
|
110
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
111
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
112
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter);
|
|
113
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);
|
|
114
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
115
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
116
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, format.internal, w, h, 0, gl.RGBA, format.type, null);
|
|
117
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
|
|
118
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
119
|
+
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE) return false;
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/** Clears both targets to zero, and leaves the canvas bound. */
|
|
125
|
+
const clear = () => {
|
|
126
|
+
gl.clearColor(0, 0, 0, 0);
|
|
127
|
+
for (const { fbo } of targets) {
|
|
128
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
|
|
129
|
+
gl.viewport(0, 0, w, h);
|
|
130
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
131
|
+
}
|
|
132
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
w = Math.max(1, Math.round(width));
|
|
136
|
+
h = Math.max(1, Math.round(height));
|
|
137
|
+
const format = floatFormats(gl).find(allocate);
|
|
138
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
139
|
+
if (!format) {
|
|
140
|
+
dispose();
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
clear();
|
|
144
|
+
const chosen = format;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Sizes both targets, cleared.
|
|
148
|
+
*
|
|
149
|
+
* @param {number} width Texels across.
|
|
150
|
+
* @param {number} height Texels down.
|
|
151
|
+
* @returns {boolean} Whether the GPU can draw into them.
|
|
152
|
+
*/
|
|
153
|
+
const resize = (width, height) => {
|
|
154
|
+
w = Math.max(1, Math.round(width));
|
|
155
|
+
h = Math.max(1, Math.round(height));
|
|
156
|
+
const ok = allocate(chosen);
|
|
157
|
+
clear();
|
|
158
|
+
return ok;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/** @type {PingPong} */
|
|
162
|
+
const pair = {
|
|
163
|
+
read: targets[0],
|
|
164
|
+
write: targets[1],
|
|
165
|
+
swap() {
|
|
166
|
+
[pair.read, pair.write] = [pair.write, pair.read];
|
|
167
|
+
},
|
|
168
|
+
resize,
|
|
169
|
+
clear,
|
|
170
|
+
size: () => ({ width: w, height: h }),
|
|
171
|
+
linear: format.linear,
|
|
172
|
+
dispose,
|
|
173
|
+
};
|
|
174
|
+
return pair;
|
|
175
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface PixelGlitchConfig {
|
|
2
|
+
/** The heat grid's cell, CSS px. Default 14. */
|
|
3
|
+
cell?: number;
|
|
4
|
+
/** How far the pointer's heat reaches, CSS px. Default 120. */
|
|
5
|
+
reach?: number;
|
|
6
|
+
/** Heat kept each frame (0.9 is gone in about half a second). Default 0.9. */
|
|
7
|
+
decay?: number;
|
|
8
|
+
/** The pixel block size at full heat, CSS px. Default 22. */
|
|
9
|
+
block?: number;
|
|
10
|
+
/** How far the hottest rows slip sideways, CSS px. Default 16. */
|
|
11
|
+
shift?: number;
|
|
12
|
+
/** With a width (CSS px), the text at rest is an outline that the pixels fill. Default 0 (solid). */
|
|
13
|
+
stroke?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Starts the pixel glitch on an element of text. Returns a function that stops it. */
|
|
17
|
+
export function pixelGlitch(el: HTMLElement, config: PixelGlitchConfig): () => void;
|
|
@@ -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;
|