@arraypress/effects-astro 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/AGENTS.md +2 -2
  2. package/COMPONENTS.md +175 -10
  3. package/package.json +1 -1
  4. package/src/components/DitherGradient.astro +41 -0
  5. package/src/components/FlutedGlow.astro +39 -0
  6. package/src/components/GlassDrop.astro +40 -0
  7. package/src/components/GlassStack.astro +41 -0
  8. package/src/components/PixelFountain.astro +20 -7
  9. package/src/components/PixelGlitchText.astro +4 -3
  10. package/src/components/PixelHorizon.astro +40 -0
  11. package/src/components/TruchetField.astro +40 -0
  12. package/src/index.d.ts +19 -1
  13. package/src/index.js +11 -1
  14. package/src/runtime/bayer.d.ts +5 -0
  15. package/src/runtime/bayer.js +48 -0
  16. package/src/runtime/dither-field.js +7 -33
  17. package/src/runtime/dither-gradient.d.ts +91 -0
  18. package/src/runtime/dither-gradient.js +410 -0
  19. package/src/runtime/fluted-glow.d.ts +79 -0
  20. package/src/runtime/fluted-glow.js +312 -0
  21. package/src/runtime/glass-drop-plan.d.ts +59 -0
  22. package/src/runtime/glass-drop-plan.js +133 -0
  23. package/src/runtime/glass-drop.d.ts +61 -0
  24. package/src/runtime/glass-drop.js +331 -0
  25. package/src/runtime/glass-optics.d.ts +5 -0
  26. package/src/runtime/glass-optics.js +49 -0
  27. package/src/runtime/glass-stack.d.ts +65 -0
  28. package/src/runtime/glass-stack.js +315 -0
  29. package/src/runtime/pixel-fountain.d.ts +29 -13
  30. package/src/runtime/pixel-fountain.js +183 -42
  31. package/src/runtime/pixel-glitch.d.ts +2 -0
  32. package/src/runtime/pixel-glitch.js +8 -2
  33. package/src/runtime/pixel-horizon.d.ts +60 -0
  34. package/src/runtime/pixel-horizon.js +274 -0
  35. package/src/runtime/slab-runs.d.ts +18 -0
  36. package/src/runtime/slab-runs.js +112 -0
  37. package/src/runtime/truchet-field.d.ts +60 -0
  38. package/src/runtime/truchet-field.js +272 -0
package/src/index.d.ts CHANGED
@@ -15,6 +15,15 @@ export { flowField } from './runtime/flow-field.js';
15
15
  export { voronoiMesh, meshStill } from './runtime/voronoi-mesh.js';
16
16
  export { kineticGrid, gridStill } from './runtime/kinetic-grid.js';
17
17
  export { hash33, grad, gnoise, GLSL_HASH33, GLSL_GRADIENT_NOISE, GLSL_NOISE_FIELD } from './runtime/hash-noise.js';
18
+ export { ditherGradient, gradientStill } from './runtime/dither-gradient.js';
19
+ export { truchetField, truchetStill } from './runtime/truchet-field.js';
20
+ export { pixelHorizon, horizonStill } from './runtime/pixel-horizon.js';
21
+ export { flutedGlow, glowStill } from './runtime/fluted-glow.js';
22
+ export { bayer, GLSL_BAYER } from './runtime/bayer.js';
23
+ export type { DitherGradientConfig } from './runtime/dither-gradient.js';
24
+ export type { TruchetFieldConfig } from './runtime/truchet-field.js';
25
+ export type { PixelHorizonConfig } from './runtime/pixel-horizon.js';
26
+ export type { FlutedGlowConfig } from './runtime/fluted-glow.js';
18
27
  export type { LightLeakConfig } from './runtime/light-leak.js';
19
28
  export type { DitherFieldConfig } from './runtime/dither-field.js';
20
29
  export type { CascadeGridConfig } from './runtime/cascade-grid.js';
@@ -23,6 +32,15 @@ export type { VoronoiMeshConfig } from './runtime/voronoi-mesh.js';
23
32
  export type { KineticGridConfig } from './runtime/kinetic-grid.js';
24
33
  export { glassGlyph } from './runtime/glass-glyph.js';
25
34
  export type { GlassGlyphConfig } from './runtime/glass-glyph.js';
35
+ export { glassDrop } from './runtime/glass-drop.js';
36
+ export type { GlassDropConfig } from './runtime/glass-drop.js';
37
+ export { dropAt, dropCycle, dropLayout, DROP_PHASES, DROP_SIZE } from './runtime/glass-drop-plan.js';
38
+ export type { DropLayout, DropState, DropPlanConfig } from './runtime/glass-drop-plan.js';
39
+ export { glassStack, stackLayout, sliceTints } from './runtime/glass-stack.js';
40
+ export type { GlassStackConfig } from './runtime/glass-stack.js';
41
+ export { sliceRuns, runsTexture, slabGrowth } from './runtime/slab-runs.js';
42
+ export type { Run as SlabRun } from './runtime/slab-runs.js';
43
+ export { GLSL_STUDIO, lightVector } from './runtime/glass-optics.js';
26
44
  export { flutedGlass } from './runtime/fluted-glass.js';
27
45
  export type { FlutedGlassConfig } from './runtime/fluted-glass.js';
28
46
  export { particleLogo } from './runtime/particle-logo.js';
@@ -33,7 +51,7 @@ export { voxelLogo } from './runtime/voxel-logo.js';
33
51
  export type { VoxelLogoConfig } from './runtime/voxel-logo.js';
34
52
  export { pixelGlitch, outlineAlpha, rowTears } from './runtime/pixel-glitch.js';
35
53
  export type { PixelGlitchConfig } from './runtime/pixel-glitch.js';
36
- export { pixelFountain, createFountain, fadeSteps, shadeAt, tierSizes, pixelRect, inkedCells, MAX_PIXELS } from './runtime/pixel-fountain.js';
54
+ export { pixelFountain, createFountain, fadeSteps, shadeAt, tierSizes, pixelRect, inkedCells, MAX_PIXELS, TRAIL_CAP, POINTER_DEFAULTS } from './runtime/pixel-fountain.js';
37
55
  export type { PixelFountainConfig, Pixel, EmitKind, FountainOptions, Fountain } from './runtime/pixel-fountain.js';
38
56
  export { fit, fitText } from './runtime/fit-text.js';
39
57
  export { textNodes, textRange, splitLetters, joinLetters, textNodesWithin, paintGlyphs } from './runtime/text.js';
package/src/index.js CHANGED
@@ -23,13 +23,23 @@ export { flowField } from './runtime/flow-field.js';
23
23
  export { voronoiMesh, meshStill } from './runtime/voronoi-mesh.js';
24
24
  export { kineticGrid, gridStill } from './runtime/kinetic-grid.js';
25
25
  export { hash33, grad, gnoise, GLSL_HASH33, GLSL_GRADIENT_NOISE, GLSL_NOISE_FIELD } from './runtime/hash-noise.js';
26
+ export { ditherGradient, gradientStill } from './runtime/dither-gradient.js';
27
+ export { truchetField, truchetStill } from './runtime/truchet-field.js';
28
+ export { pixelHorizon, horizonStill } from './runtime/pixel-horizon.js';
29
+ export { flutedGlow, glowStill } from './runtime/fluted-glow.js';
30
+ export { bayer, GLSL_BAYER } from './runtime/bayer.js';
26
31
  export { glassGlyph } from './runtime/glass-glyph.js';
32
+ export { glassDrop } from './runtime/glass-drop.js';
33
+ export { dropAt, dropCycle, dropLayout, DROP_PHASES, DROP_SIZE } from './runtime/glass-drop-plan.js';
34
+ export { glassStack, stackLayout, sliceTints } from './runtime/glass-stack.js';
35
+ export { sliceRuns, runsTexture, slabGrowth } from './runtime/slab-runs.js';
36
+ export { GLSL_STUDIO, lightVector } from './runtime/glass-optics.js';
27
37
  export { flutedGlass } from './runtime/fluted-glass.js';
28
38
  export { particleLogo } from './runtime/particle-logo.js';
29
39
  export { pointCloud } from './runtime/point-cloud.js';
30
40
  export { voxelLogo } from './runtime/voxel-logo.js';
31
41
  export { pixelGlitch, outlineAlpha, rowTears } from './runtime/pixel-glitch.js';
32
- export { pixelFountain, createFountain, fadeSteps, shadeAt, tierSizes, pixelRect, inkedCells, MAX_PIXELS } from './runtime/pixel-fountain.js';
42
+ export { pixelFountain, createFountain, fadeSteps, shadeAt, tierSizes, pixelRect, inkedCells, MAX_PIXELS, TRAIL_CAP, POINTER_DEFAULTS } from './runtime/pixel-fountain.js';
33
43
  export { fit, fitText } from './runtime/fit-text.js';
34
44
  export { textNodes, textRange, splitLetters, joinLetters, textNodesWithin, paintGlyphs } from './runtime/text.js';
35
45
  export { variableType, DEFAULT_AXES } from './runtime/variable-type.js';
@@ -0,0 +1,5 @@
1
+ /** GLSL (ES 1.00): `float bayer8(vec2 cell)`, the 8×8 Bayer threshold 0–63/64 at a dot. */
2
+ export declare const GLSL_BAYER: string;
3
+
4
+ /** The 8×8 Bayer threshold at a dot, 0–63/64 (it repeats every 8 dots). */
5
+ export declare function bayer(x: number, y: number): number;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/bayer
3
+ *
4
+ * The 8×8 Bayer ordered-dither threshold, as GLSL and as a JS function of
5
+ * the same values, built from the 2×2 matrix at three scales so neither
6
+ * side needs a texture. Shared by DitherField and DitherGradient.
7
+ */
8
+
9
+ /**
10
+ * The fractional part.
11
+ *
12
+ * @param {number} n A number.
13
+ * @returns {number} `n − floor(n)`, 0–1.
14
+ */
15
+ const fract = (n) => n - Math.floor(n);
16
+
17
+ /** GLSL (ES 1.00): `float bayer8(vec2 cell)`, the threshold 0–63/64 at a dot (it repeats every 8 dots). */
18
+ export const GLSL_BAYER = `
19
+ float bayer2(vec2 a) { return fract(a.x * 0.5 + a.y * a.y * 0.75); }
20
+ float bayer8(vec2 cell) {
21
+ vec2 a = mod(floor(cell), 8.0);
22
+ vec2 b = floor(a * 0.5);
23
+ vec2 c = floor(a * 0.25);
24
+ return bayer2(a) + bayer2(b) * 0.25 + bayer2(c) * 0.0625;
25
+ }
26
+ `;
27
+
28
+ /**
29
+ * The 8×8 Bayer threshold at a dot (the shader's `bayer8`): the classic
30
+ * ordered-dither matrix, 0/64 to 63/64.
31
+ *
32
+ * @param {number} x The dot's column (any integer; it repeats every 8).
33
+ * @param {number} y The dot's row.
34
+ * @returns {number} The threshold, 0–63/64.
35
+ */
36
+ export function bayer(x, y) {
37
+ /**
38
+ * The 2×2 matrix (0, 2 / 3, 1 over 4) by a cell's parity.
39
+ *
40
+ * @param {number} a Column.
41
+ * @param {number} b Row.
42
+ * @returns {number} 0, 0.25, 0.5 or 0.75.
43
+ */
44
+ const two = (a, b) => fract(a * 0.5 + b * b * 0.75);
45
+ const ax = ((Math.floor(x) % 8) + 8) % 8;
46
+ const ay = ((Math.floor(y) % 8) + 8) % 8;
47
+ return two(ax, ay) + two(Math.floor(ax / 2), Math.floor(ay / 2)) * 0.25 + two(Math.floor(ax / 4), Math.floor(ay / 4)) * 0.0625;
48
+ }
@@ -37,6 +37,7 @@ import { GLSL_GRADIENT_NOISE, GLSL_NOISE_FIELD, grad, gnoise, noiseField } from
37
37
  import { GLSL_OKLAB, parseColor, toOklab, mixOklab, toHex } from './color.js';
38
38
  import { GLSL_QUIET, quietUniform } from './glsl.js';
39
39
  import { watchColors } from './mount.js';
40
+ import { GLSL_BAYER, bayer } from './bayer.js';
40
41
  import { pickColors } from './palettes.js';
41
42
 
42
43
  /**
@@ -92,19 +93,12 @@ const ZONES = { edge: 0.1, core: 0.3, bias: 0.2, inner: 0.8, fuzz: 0.02, gain: 8
92
93
  const AMBER = ['#b4b4b4', '#ffbe50'];
93
94
 
94
95
  /**
95
- * GLSL (ES 1.00): `float bayer8(vec2 cell)`, the 8×8 Bayer threshold
96
- * (0–63 over 64) built from the 2×2 one, and `float ripplePulse(float s)`,
97
- * a smooth 1-D noise, 0–1, that the rings are cut from. `bayer` and
98
- * `ripplePulse` below are the same in JavaScript.
96
+ * GLSL (ES 1.00): `float ripplePulse(float s)`, a smooth 1-D noise, 0–1,
97
+ * that the rings are cut from (`ripplePulse` below is the same in
98
+ * JavaScript). The Bayer threshold is `./bayer.js`'s.
99
99
  */
100
100
  const GLSL_DITHER = `
101
- float bayer2(vec2 a) { return fract(a.x * 0.5 + a.y * a.y * 0.75); }
102
- float bayer8(vec2 cell) {
103
- vec2 a = mod(floor(cell), 8.0);
104
- vec2 b = floor(a * 0.5);
105
- vec2 c = floor(a * 0.25);
106
- return bayer2(a) + bayer2(b) * 0.25 + bayer2(c) * 0.0625;
107
- }
101
+ ${GLSL_BAYER}
108
102
  float hash11(float p) {
109
103
  p = fract(p * 0.1031);
110
104
  p *= p + 33.33;
@@ -203,28 +197,8 @@ const smooth = (e0, e1, x) => {
203
197
  */
204
198
  const quintic = (f) => f * f * f * (f * (f * 6 - 15) + 10);
205
199
 
206
- /**
207
- * The 8×8 Bayer threshold at a dot (the shader's `bayer8`): the classic
208
- * ordered-dither matrix, 0/64 to 63/64, built from the 2×2 one at three
209
- * scales, so neither side needs a texture.
210
- *
211
- * @param {number} x The dot's column (any integer; it repeats every 8).
212
- * @param {number} y The dot's row.
213
- * @returns {number} The threshold, 0–63/64.
214
- */
215
- export function bayer(x, y) {
216
- /**
217
- * The 2×2 matrix (0, 2 / 3, 1 over 4) by a cell's parity.
218
- *
219
- * @param {number} a Column.
220
- * @param {number} b Row.
221
- * @returns {number} 0, 0.25, 0.5 or 0.75.
222
- */
223
- const two = (a, b) => fract(a * 0.5 + b * b * 0.75);
224
- const ax = ((Math.floor(x) % 8) + 8) % 8;
225
- const ay = ((Math.floor(y) % 8) + 8) % 8;
226
- return two(ax, ay) + two(Math.floor(ax / 2), Math.floor(ay / 2)) * 0.25 + two(Math.floor(ax / 4), Math.floor(ay / 4)) * 0.0625;
227
- }
200
+ /** The 8×8 Bayer threshold at a dot (`./bayer.js`), exported here as before. */
201
+ export { bayer };
228
202
 
229
203
  /**
230
204
  * A hash of one number (the shader's `hash11`): Dave Hoskins' Hash without
@@ -0,0 +1,91 @@
1
+ import type { PaletteName } from './palettes.js';
2
+
3
+ /** The gradient's shapes. */
4
+ export type GradientShape = 'wave' | 'band' | 'swirl' | 'pinwheel' | 'steps';
5
+
6
+ export interface DitherGradientConfig {
7
+ /** Two CSS hex colours: the dim one where the tone is low and the bright one where it is full. Default a plum and a hot pink. */
8
+ colors?: string[];
9
+ /** A shared palette by name (`PALETTES`, any case), when there are no `colors`: its first and last colours. */
10
+ palette?: PaletteName | (string & {});
11
+ /** A CSS hex colour to fill behind the dots; none leaves the canvas clear there. */
12
+ background?: string;
13
+ /** The gradient's shape. Default 'wave'. */
14
+ shape?: GradientShape;
15
+ /** Square dots an ordered dither thins out, or round dots that shrink. Default 'bayer'. */
16
+ mode?: 'bayer' | 'halftone';
17
+ /** The dots' grid, in CSS px. Default 4. */
18
+ dot?: number;
19
+ /** Share of its cell a full dot covers (below 1 leaves a gap between dots). Default 1. */
20
+ fill?: number;
21
+ /** How soft the gradient is: the edge's width in widths (wave, band, steps), a share of a turn (swirl, pinwheel). Default 0.35. */
22
+ soft?: number;
23
+ /** Which way the wave, band and steps rise from, degrees: 0 from the bottom, 90 from the left. Default 0. */
24
+ angle?: number;
25
+ /** Where the wave's horizon, the band's middle and the steps' line sit, widths below the centre (along `angle`). Default 0.12. */
26
+ level?: number;
27
+ /** The swirl's and pinwheel's arms. Default 3. */
28
+ arms?: number;
29
+ /** How tightly the swirl winds and the pinwheel bends. Default 2. */
30
+ twist?: number;
31
+ /** How fast it moves, cycles a second. Default 0.03. */
32
+ rate?: number;
33
+ /** The steps' block, in dots. Default 6. */
34
+ block?: number;
35
+ /** Colour bands from dim to bright; 0 blends smoothly. Default 0. */
36
+ steps?: number;
37
+ /** The swirl's and pinwheel's centre, and the wave's and band's pivot, 0–1 from the top left. Default [0.5, 0.5]. */
38
+ centre?: [number, number];
39
+ /** Where the shapes' noise starts, so two cards differ. Default [0, 0]. */
40
+ offset?: [number, number];
41
+ /** Plays the clock faster or slower; 0 for one still frame. Default 1. */
42
+ speed?: number;
43
+ /** An area kept empty: centre (0–1 from the top left), radius (share of the height), depth (0–1). Its opening is squared. */
44
+ quiet?: { x?: number; y?: number; radius?: number; depth?: number } | null;
45
+ }
46
+
47
+ /** The shapes, in the order the shader numbers them. */
48
+ export declare const GRADIENT_SHAPES: readonly ['wave', 'band', 'swirl', 'pinwheel', 'steps'];
49
+
50
+ /** The settings' defaults, shared by the shader and the JS twin. */
51
+ export declare const GRADIENT_DEFAULTS: {
52
+ shape: GradientShape;
53
+ mode: 'bayer' | 'halftone';
54
+ dot: number;
55
+ fill: number;
56
+ soft: number;
57
+ angle: number;
58
+ level: number;
59
+ arms: number;
60
+ twist: number;
61
+ rate: number;
62
+ block: number;
63
+ steps: number;
64
+ centre: [number, number];
65
+ };
66
+
67
+ /** The settings filled with the defaults, as the shader takes them. */
68
+ export type GradientSettings = Required<Omit<DitherGradientConfig, 'colors' | 'palette' | 'background' | 'quiet'>> & {
69
+ shapeIndex: number;
70
+ modeIndex: number;
71
+ rad: number;
72
+ blockW: number;
73
+ };
74
+
75
+ /** The settings as the shader takes them, for a target `cols` dots wide (the steps' block is in dots). */
76
+ export declare function gradientSettings(config: DitherGradientConfig, cols: number): GradientSettings;
77
+
78
+ /** The tone 0–1 at a point (widths from the top left; `H` the height in widths), before the quiet area. */
79
+ export declare function gradientTone(s: GradientSettings, x: number, y: number, H: number, time?: number): number;
80
+
81
+ /** One frame dot for dot on a target exactly `cols` by `rows` dots: each dot's tone after the quiet area, and whether a bayer dot is lit. */
82
+ export declare function gradientDots(config: DitherGradientConfig, cols: number, rows: number, time?: number): { tone: number; lit: boolean }[][];
83
+
84
+ /** The two colours as the shader takes them: the dim one and the bright one. */
85
+ export declare function gradientColors(config: DitherGradientConfig): [string, string];
86
+
87
+ /** A CSS `background` that stands in for the gradient before the shader starts and without WebGL. */
88
+ export declare function gradientStill(config: DitherGradientConfig): string;
89
+
90
+ /** Starts the gradient on an element (its first canvas). Returns a function that stops it. */
91
+ export declare function ditherGradient(el: HTMLElement, config: DitherGradientConfig): () => void;