@arraypress/effects-astro 0.12.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.
package/AGENTS.md CHANGED
@@ -32,7 +32,7 @@ Pick by what is asked for:
32
32
  | A "we sell worldwide" or "we ship from here" section | `<WorldRoutes>` with the cities that matter to the shop; `home="…"` for a hub, `colors` + `gradient` for colour, `labels`, `region="europe"` (or `routes`) to crop |
33
33
  | A space, astronomy, night-sky or sci-fi hero: a nebula with stars | `<Galaxy palette="…">` (Canvas 2D, no WebGL; `stars`, `glitter`, `speed`) |
34
34
  | A light or texture over a background (a spotlight, film grain) | `<GlowField>`, `<Grain>` (`still` for either to hold) |
35
- | The brand's logo as the hero's centrepiece | `<GlassGlyph>`, `<LiquidMetal>` (liquid chrome you can poke and splash; `tint="gold"`…), `<ParticleLogo>`, `<NeonSwarm>` (a flowing neon swarm), `<NebulaLogo>` (filled with nebula gas), `<VoxelLogo>`, `<PointCloud>`, all with `src="/logo.svg"` or `text` |
35
+ | The brand's logo as the hero's centrepiece | `<GlassGlyph>`, `<GlassDrop>` (a drop of liquid glass becomes a tile over the logo, or the logo itself, then melts; `loop`), `<GlassStack>` (the logo as stacked tinted glass discs on a lit card), `<LiquidMetal>` (liquid chrome you can poke and splash; `tint="gold"`…), `<ParticleLogo>`, `<NeonSwarm>` (a flowing neon swarm), `<NebulaLogo>` (filled with nebula gas), `<VoxelLogo>`, `<PointCloud>`, all with `src="/logo.svg"` or `text` |
36
36
  | A footer wordmark | `<SpotlightText fit>`, `<PixelGlitchText fit>`, `<OutlineWordmark>` |
37
37
  | Something retro or 8-bit on a footer: pixels firing out of it, sparks, "insert coin" | `<PixelFountain>` inside the footer (its top edge must not clip: `overflow-x: clip`, not `overflow: hidden`); `source="text"` sheds pixels from a wordmark; `color` or `colors` for the ramp |
38
38
  | Sections that arrive on scroll, site-wide | `<ScrollReveal />` once in the layout, then reveal.css classes (`fade-in-up`…) on elements |
package/COMPONENTS.md CHANGED
@@ -409,6 +409,51 @@ Glass: a liquid glass panel, with a rim that catches the light and a sheen that
409
409
  | `specular` | `number` | With `refract`, how bright the highlight along the rim is, 0–1. Default 0.7. |
410
410
  | `class` | `string` | Classes for the element. |
411
411
 
412
+ ## `<GlassDrop>`
413
+
414
+ GlassDrop: a logo arriving as liquid glass. A drop forms, lands with rings running out, and spreads into a glass tile with the logo rising under it (or into the logo's own shape, `form="mark"`); it holds, then melts away and leaves the logo flat on the ground. Once, or on a loop. See src/runtime/glass-drop.js.
415
+
416
+ ```astro
417
+ <section class="hero" style="position: relative">
418
+ <GlassDrop src="/logo.svg" loop />
419
+ <h1>…</h1>
420
+ </section>
421
+ ```
422
+
423
+ | Prop | Type | |
424
+ |---|---|---|
425
+ | `src` | `string` | An image (an SVG logo) to make the glass of. |
426
+ | `text` | `string` | A character or word instead of an image. |
427
+ | `font` | `string` | Its CSS font, without the size. Default: the page's, bold. |
428
+ | `area` | `{ x: number; y: number; width: number; height: number }` | Where the glass sits, each 0–1 from the top left. Default all of the element. |
429
+ | `form` | `'tile' \| 'mark'` | What the drop becomes: `tile`, a glass tile with the logo under it, or `mark`, the logo's own shape in glass. Default `tile`. |
430
+ | `size` | `number` | The tile's edge, a share of the area's shorter side, 0.2–1. Default 0.7. |
431
+ | `markScale` | `number` | The logo's size under the glass, a share of the tile, 0.2–1. Default 0.62. |
432
+ | `restScale` | `number` | The logo's size once the glass has melted, times its size under the glass, 0.5–2. Default 1. |
433
+ | `radius` | `number` | The tile's corner radius, a share of its edge, 0–0.5. Default 0.24. |
434
+ | `background` | `string` | The ground. Default `#000000`. |
435
+ | `color` | `string` | The logo's colour. Default `#ffffff`. |
436
+ | `plate` | `string` | The tile's surface under the logo. Default `#0a1020`. |
437
+ | `light` | `string` | The studio light the glass mirrors. Default `#ffffff`. |
438
+ | `depth` | `number` | How hard the glass bends what is under it, 0–2. Default 1. |
439
+ | `dispersion` | `number` | How far the colours part at the rim, 0–2; 0 for none. Default 1. |
440
+ | `bevel` | `number` | How wide the rounded rim is, a share of the tile (or the logo), 0.02–0.3. Default 0.1. |
441
+ | `highlights` | `number` | The lip and the studio's reflections, 0–2. Default 1. |
442
+ | `caustics` | `number` | Light focused at the glass's edge and onto the ground, 0–2. Default 1. |
443
+ | `bloom` | `number` | A soft glow round the glass, 0–1. Default 0.5. |
444
+ | `ripples` | `number` | The rings the drop sends across the ground, 0–2; 0 for none. Default 1. |
445
+ | `tint` | `number` | With `form: 'mark'`: how strongly the glass takes the logo's colour, 0–1. Default 0.88. |
446
+ | `lightAngle` | `number` | Where the light comes from, degrees, 0–360 (0 right, 90 top). Default 125. |
447
+ | `speed` | `number` | How fast the sequence plays, 0.25–3. Default 1. |
448
+ | `delay` | `number` | Seconds to wait before it starts, 0–10. Default 0. |
449
+ | `hold` | `number` | Seconds the glass holds before it melts, 0–10. Default 2.4. |
450
+ | `loop` | `boolean` | Play it again after a rest; each round starts from the resting logo, which fades as the new drop forms. Default false. |
451
+ | `loopDelay` | `number` | With `loop`: seconds the logo rests before the next drop, 0–10. Default 1.6. |
452
+ | `rest` | `'flat' \| 'glass'` | How it ends: `flat`, the glass melted and the logo left on the ground, or `glass`, the glass held. Default `flat`. |
453
+ | `fixed` | `boolean` | Fill the viewport, behind the page (position: fixed, z-index -1). Default false. |
454
+ | `lazy` | `boolean \| string` | Run only while near the screen (true, or how near as a CSS length), giving its WebGL context back when away: for pages with many effects. Default false. |
455
+ | `class` | `string` | Classes for the element. |
456
+
412
457
  ## `<GlassGlyph>`
413
458
 
414
459
  GlassGlyph: a character or a logo as a thick slab of dark, smoked glass, lit from behind by beams of one coloured light. The light barely shows on the near-black ground; the glass catches it and glows with it through its body and bevels. The slab turns slowly on its own and leans away from the pointer; the light stays put. See src/runtime/glass-glyph.js.
@@ -446,6 +491,50 @@ GlassGlyph: a character or a logo as a thick slab of dark, smoked glass, lit fro
446
491
  | `fixed` | `boolean` | Fill the viewport, behind the page (position: fixed, z-index -1). Default false. |
447
492
  | `class` | `string` | Classes for the element. |
448
493
 
494
+ ## `<GlassStack>`
495
+
496
+ GlassStack: a logo as a stack of tinted glass discs in front of a lit card, seen a little from below. The logo is cut into slices and every stretch of it in a slice becomes a disc; the tints run from the top slice to the bottom. The discs grow from the bottom up when it first shows, then the stack leans gently on its own and toward the pointer. See src/runtime/glass-stack.js.
497
+
498
+ ```astro
499
+ <section class="hero" style="position: relative">
500
+ <GlassStack src="/logo.svg" background="#0b0b0b" colors={['#f4ffd0', '#c8ff00', '#0e8c7e']} />
501
+ <h1>…</h1>
502
+ </section>
503
+ ```
504
+
505
+ | Prop | Type | |
506
+ |---|---|---|
507
+ | `src` | `string` | An image (an SVG logo) to make the stack of. |
508
+ | `text` | `string` | A character or word instead of an image. |
509
+ | `font` | `string` | Its CSS font, without the size. Default: the page's, bold. |
510
+ | `area` | `{ x: number; y: number; width: number; height: number }` | Where the stack sits, each 0–1 from the top left. Default all of the element. |
511
+ | `logoScale` | `number` | The logo's size, a share of the area's shorter side, 0.2–1. Default 0.73. |
512
+ | `colors` | `string[]` | The glass's tints from the top slice to the bottom, 2–6 colours. Default aqua to deep blue. |
513
+ | `background` | `string` | The ground. Default `#ffffff`. |
514
+ | `light` | `string` | The lit card behind the stack, and the studio the glass mirrors. Default `#ffffff`. |
515
+ | `slabs` | `number` | How many slices the logo is cut into, 4–64. Default 22. |
516
+ | `phase` | `number` | Where in its slice each disc samples the logo, 0 the top to 1 the bottom. Default 0.5. |
517
+ | `band` | `number` | How much of its slice each disc samples, 0 a line to 1 all of it; more keeps small parts. Default 0.35. |
518
+ | `depth` | `number` | How open each disc is from below (the camera's height), a share of the slice, 0.05–1.4. Default 0.55. |
519
+ | `thickness` | `number` | How much of each disc's front edge shows, a share of the slice, 0–1. Default 0.35. |
520
+ | `ior` | `number` | The glass's refractive index: how hard its rims bend the card, 1–2. Default 1.45. |
521
+ | `reflectivity` | `number` | How strongly the glass mirrors the studio, 0–1. Default 0.3. |
522
+ | `density` | `number` | How deeply the glass is tinted, 0–3. Default 0.9. |
523
+ | `opacity` | `number` | How much the discs hide the discs behind them, 0–1. Default 0.92. |
524
+ | `exposure` | `number` | The card's brightness, 0–2. Default 1.1. |
525
+ | `ambient` | `number` | How far the card's light spills onto the ground, 0–1. Default 0.05. |
526
+ | `cardSize` | `number` | The card's size, times the logo's box, 0 for none to 3. Default 1.15. |
527
+ | `lightAngle` | `number` | Where the light comes from, degrees, 0–360 (0 right, 90 top). Default 115. |
528
+ | `tilt` | `number` | How far the stack leans toward the pointer, 0–2; 0 for not at all. Default 1. |
529
+ | `sway` | `number` | How far it leans on its own, slowly, 0–2; 0 holds it still. Default 0.5. |
530
+ | `intro` | `boolean` | Grow the discs from the bottom up when it first shows. Default true. |
531
+ | `introDuration` | `number` | Seconds until the top disc has grown, 0.2–6. Default 1.6. |
532
+ | `delay` | `number` | Seconds before the intro starts, 0–10. Default 0. |
533
+ | `speed` | `number` | How fast the intro plays, 0.25–3. Default 1. |
534
+ | `fixed` | `boolean` | Fill the viewport, behind the page (position: fixed, z-index -1). Default false. |
535
+ | `lazy` | `boolean \| string` | Run only while near the screen (true, or how near as a CSS length), giving its WebGL context back when away: for pages with many effects. Default false. |
536
+ | `class` | `string` | Classes for the element. |
537
+
449
538
  ## `<GlitchText>`
450
539
 
451
540
  GlitchText: a headline that glitches now and then. Every few seconds two coloured copies of it (pink and blue by default) flash over it for a few frames, sliced into bands and shifted sideways, and the text nudges with them; the rest of the time it sits still. Livelier under the pointer (on the text, or a link or button round it). Each one on the page glitches on its own beat. CSS only, from glitch-text.css; with reduced motion it is the plain text. Not the canvas `<PixelGlitchText>`, which breaks into pixels under the pointer.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arraypress/effects-astro",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "GPU effects for Astro sites, as components: liquid light with a real fluid under it, ink in water, and outline text a spotlight fills. Plain WebGL, no third-party dependencies, with the fallbacks a theme needs (reduced motion, no WebGL, touch screens, off-screen pausing).",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -0,0 +1,40 @@
1
+ ---
2
+ /**
3
+ * GlassDrop: a logo arriving as liquid glass. A drop forms, lands with
4
+ * rings running out, and spreads into a glass tile with the logo rising
5
+ * under it (or into the logo's own shape, `form="mark"`); it holds, then
6
+ * melts away and leaves the logo flat on the ground. Once, or on a loop.
7
+ * See src/runtime/glass-drop.js.
8
+ *
9
+ * Opaque: it is the whole background of what it fills (its nearest
10
+ * positioned ancestor, or the viewport with `fixed`). Without WebGL the
11
+ * `background` colour shows; with reduced motion, the final frame.
12
+ *
13
+ * @example
14
+ * <section class="hero" style="position: relative">
15
+ * <GlassDrop src="/logo.svg" loop />
16
+ * <h1>…</h1>
17
+ * </section>
18
+ */
19
+ import EffectCanvas from './EffectCanvas.astro';
20
+ import type { GlassDropConfig } from '../runtime/glass-drop.js';
21
+
22
+ interface Props extends GlassDropConfig {
23
+ /** Fill the viewport, behind the page (position: fixed, z-index -1). Default false. */
24
+ fixed?: boolean;
25
+ /** Run only while near the screen (true, or how near as a CSS length), giving its WebGL context back when away: for pages with many effects. Default false. */
26
+ lazy?: boolean | string;
27
+ class?: string;
28
+ }
29
+
30
+ const { fixed = false, lazy = false, class: className, ...config } = Astro.props;
31
+ ---
32
+
33
+ <EffectCanvas name="glass-drop" config={config} fixed={fixed} lazy={lazy} class={className} behind background={config.background ?? '#000000'} />
34
+
35
+ <script>
36
+ import { mount } from '../runtime/mount.js';
37
+ import { glassDrop } from '../runtime/glass-drop.js';
38
+
39
+ mount('[data-effect-glass-drop]', glassDrop);
40
+ </script>
@@ -0,0 +1,41 @@
1
+ ---
2
+ /**
3
+ * GlassStack: a logo as a stack of tinted glass discs in front of a lit
4
+ * card, seen a little from below. The logo is cut into slices and every
5
+ * stretch of it in a slice becomes a disc; the tints run from the top slice
6
+ * to the bottom. The discs grow from the bottom up when it first shows,
7
+ * then the stack leans gently on its own and toward the pointer.
8
+ * See src/runtime/glass-stack.js.
9
+ *
10
+ * Opaque: it is the whole background of what it fills (its nearest
11
+ * positioned ancestor, or the viewport with `fixed`). Without WebGL the
12
+ * `background` colour shows; with reduced motion, every disc grown.
13
+ *
14
+ * @example
15
+ * <section class="hero" style="position: relative">
16
+ * <GlassStack src="/logo.svg" background="#0b0b0b" colors={['#f4ffd0', '#c8ff00', '#0e8c7e']} />
17
+ * <h1>…</h1>
18
+ * </section>
19
+ */
20
+ import EffectCanvas from './EffectCanvas.astro';
21
+ import type { GlassStackConfig } from '../runtime/glass-stack.js';
22
+
23
+ interface Props extends GlassStackConfig {
24
+ /** Fill the viewport, behind the page (position: fixed, z-index -1). Default false. */
25
+ fixed?: boolean;
26
+ /** Run only while near the screen (true, or how near as a CSS length), giving its WebGL context back when away: for pages with many effects. Default false. */
27
+ lazy?: boolean | string;
28
+ class?: string;
29
+ }
30
+
31
+ const { fixed = false, lazy = false, class: className, ...config } = Astro.props;
32
+ ---
33
+
34
+ <EffectCanvas name="glass-stack" config={config} fixed={fixed} lazy={lazy} class={className} behind background={config.background ?? '#ffffff'} />
35
+
36
+ <script>
37
+ import { mount } from '../runtime/mount.js';
38
+ import { glassStack } from '../runtime/glass-stack.js';
39
+
40
+ mount('[data-effect-glass-stack]', glassStack);
41
+ </script>
package/src/index.d.ts CHANGED
@@ -32,6 +32,15 @@ export type { VoronoiMeshConfig } from './runtime/voronoi-mesh.js';
32
32
  export type { KineticGridConfig } from './runtime/kinetic-grid.js';
33
33
  export { glassGlyph } from './runtime/glass-glyph.js';
34
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';
35
44
  export { flutedGlass } from './runtime/fluted-glass.js';
36
45
  export type { FlutedGlassConfig } from './runtime/fluted-glass.js';
37
46
  export { particleLogo } from './runtime/particle-logo.js';
package/src/index.js CHANGED
@@ -29,6 +29,11 @@ export { pixelHorizon, horizonStill } from './runtime/pixel-horizon.js';
29
29
  export { flutedGlow, glowStill } from './runtime/fluted-glow.js';
30
30
  export { bayer, GLSL_BAYER } from './runtime/bayer.js';
31
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';
32
37
  export { flutedGlass } from './runtime/fluted-glass.js';
33
38
  export { particleLogo } from './runtime/particle-logo.js';
34
39
  export { pointCloud } from './runtime/point-cloud.js';
@@ -0,0 +1,59 @@
1
+ /** The sequence's parts, in seconds at speed 1: the drop forming, spreading into its shape, and melting away. */
2
+ export declare const DROP_PHASES: Readonly<{ form: number; spread: number; melt: number }>;
3
+
4
+ /** The drop's radius when it lands, a share of the tile's edge. */
5
+ export declare const DROP_SIZE: number;
6
+
7
+ export interface DropLayout {
8
+ /** The glass's middle, each 0–1 from the top left. */
9
+ centre: { x: number; y: number };
10
+ /** The tile's edge, a share of the element's height. */
11
+ tile: number;
12
+ /** The mark's box under the glass, a share of the height. */
13
+ mark: number;
14
+ /** The mark's box at rest, a share of the height. */
15
+ rest: number;
16
+ }
17
+
18
+ export interface DropState {
19
+ /** How far the drop has formed, 0–1. */
20
+ drop: number;
21
+ /** From the drop (0) to the tile or mark (1); it overshoots a little as the glass settles. */
22
+ morph: number;
23
+ /** How much the glass's edge still ripples, 0–1. */
24
+ wobble: number;
25
+ /** Seconds since the drop landed, or −1 before. */
26
+ ripple: number;
27
+ /** How far the mark has risen under the glass (or, as the logo's own glass melts, come through flat), 0–1. */
28
+ markIn: number;
29
+ /** How much glass there is, 1 whole to 0 melted. */
30
+ glass: number;
31
+ /** The mark's size, 1 under the glass to `restScale` at rest. */
32
+ scale: number;
33
+ /** Whether the sequence has finished and nothing more moves. */
34
+ done: boolean;
35
+ }
36
+
37
+ /** The settings the plan reads. */
38
+ export interface DropPlanConfig {
39
+ area?: { x: number; y: number; width: number; height: number };
40
+ size?: number;
41
+ markScale?: number;
42
+ restScale?: number;
43
+ hold?: number;
44
+ loopDelay?: number;
45
+ loop?: boolean;
46
+ rest?: 'flat' | 'glass';
47
+ delay?: number;
48
+ speed?: number;
49
+ form?: 'tile' | 'mark';
50
+ }
51
+
52
+ /** Where the glass and the mark sit in an element (`aspect`, its width over its height): a square tile `size` of the area's shorter side, the mark's box `markScale` of it, `restScale` times that at rest. */
53
+ export declare function dropLayout(config: DropPlanConfig, aspect: number): DropLayout;
54
+
55
+ /** The cycle's length in seconds at speed 1: the sequence, then the rest before it plays again (none without `loop`). */
56
+ export declare function dropCycle(config: DropPlanConfig): number;
57
+
58
+ /** What the sequence is doing `seconds` after it started (`Infinity`: the final state). */
59
+ export declare function dropAt(seconds: number, config: DropPlanConfig): DropState;
@@ -0,0 +1,133 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/glass-drop-plan
3
+ *
4
+ * GlassDrop's plan, apart from its shader so it can be tested and so a page
5
+ * can lay a still of the resting mark exactly where the effect leaves it:
6
+ * where the glass and the mark sit (`dropLayout`), and what the sequence
7
+ * is doing at a moment (`dropAt`): a drop of liquid glass forms, spreads
8
+ * into a tile (or into the mark's own shape) with the mark rising under it,
9
+ * holds, then melts away and leaves the mark flat on the ground. On a loop,
10
+ * each round starts from the resting mark, which fades as the drop forms, so
11
+ * a page can show the resting mark as the effect's still and the effect
12
+ * takes over from it without a jump.
13
+ */
14
+
15
+ /** The sequence's parts, in seconds at speed 1: the drop forming, spreading into its shape, and melting away. */
16
+ export const DROP_PHASES = Object.freeze({ form: 0.7, spread: 1.3, melt: 1.1 });
17
+
18
+ /** The drop's radius when it lands, a share of the tile's edge. */
19
+ export const DROP_SIZE = 0.17;
20
+
21
+ /** The settings the plan reads, with their defaults. */
22
+ const DEFAULTS = { size: 0.7, markScale: 0.62, restScale: 1, hold: 2.4, loopDelay: 1.6, loop: false, rest: 'flat', delay: 0, speed: 1 };
23
+
24
+ /**
25
+ * @typedef {object} DropLayout
26
+ * @property {{ x: number, y: number }} centre The glass's middle, each 0–1 from the top left.
27
+ * @property {number} tile The tile's edge, a share of the element's height.
28
+ * @property {number} mark The mark's box under the glass, a share of the height.
29
+ * @property {number} rest The mark's box at rest, a share of the height.
30
+ */
31
+
32
+ /**
33
+ * Where the glass and the mark sit in an element: the tile is a square
34
+ * `size` of the area's shorter side, centred in it; the mark's box is
35
+ * `markScale` of the tile under the glass, and `restScale` times that once
36
+ * the glass has gone. A square box holds the whole image (an SVG logo's
37
+ * viewBox), so a still drawn in the same box lines up exactly.
38
+ *
39
+ * @param {{ area?: { x: number, y: number, width: number, height: number }, size?: number, markScale?: number, restScale?: number }} config The settings.
40
+ * @param {number} aspect The element's width over its height.
41
+ * @returns {DropLayout} The layout.
42
+ */
43
+ export function dropLayout(config, aspect) {
44
+ const area = config.area ?? { x: 0, y: 0, width: 1, height: 1 };
45
+ const size = config.size ?? DEFAULTS.size;
46
+ const markScale = config.markScale ?? DEFAULTS.markScale;
47
+ const restScale = config.restScale ?? DEFAULTS.restScale;
48
+ const tile = Math.min(area.width * aspect, area.height) * size;
49
+ return {
50
+ centre: { x: area.x + area.width / 2, y: area.y + area.height / 2 },
51
+ tile,
52
+ mark: tile * markScale,
53
+ rest: tile * markScale * restScale,
54
+ };
55
+ }
56
+
57
+ /**
58
+ * @typedef {object} DropState
59
+ * @property {number} drop How far the drop has formed, 0–1 (its radius is `drop × DROP_SIZE` of the tile).
60
+ * @property {number} morph From the drop (0) to the tile or mark (1); it overshoots a little as the glass settles.
61
+ * @property {number} wobble How much the glass's edge still ripples, 0–1.
62
+ * @property {number} ripple Seconds since the drop landed (the rings on the ground), or −1 before.
63
+ * @property {number} markIn How far the mark has risen under the glass, 0–1.
64
+ * @property {number} glass How much glass there is, 1 whole to 0 melted.
65
+ * @property {number} scale The mark's size, 1 under the glass to `restScale` at rest.
66
+ * @property {boolean} done Whether the sequence has finished and nothing more moves.
67
+ */
68
+
69
+ /** Hermite ease, 0–1. */
70
+ const ease = (x) => {
71
+ const t = Math.min(1, Math.max(0, x));
72
+ return t * t * (3 - 2 * t);
73
+ };
74
+
75
+ /**
76
+ * The cycle's length in seconds at speed 1: the sequence, then the rest
77
+ * before it plays again (none when it does not loop).
78
+ *
79
+ * @param {{ hold?: number, loopDelay?: number, loop?: boolean, rest?: 'flat' | 'glass' }} config The settings.
80
+ * @returns {number} Seconds.
81
+ */
82
+ export function dropCycle(config) {
83
+ const hold = config.hold ?? DEFAULTS.hold;
84
+ if ((config.rest ?? DEFAULTS.rest) === 'glass') return DROP_PHASES.form + DROP_PHASES.spread;
85
+ const end = DROP_PHASES.form + DROP_PHASES.spread + hold + DROP_PHASES.melt;
86
+ return (config.loop ?? DEFAULTS.loop) ? end + (config.loopDelay ?? DEFAULTS.loopDelay) : end;
87
+ }
88
+
89
+ /**
90
+ * What the sequence is doing at a moment. `Infinity` gives the final state:
91
+ * the mark flat at its rest size (or, with `rest: 'glass'`, the glass held).
92
+ *
93
+ * @param {number} seconds Seconds since it started, before `delay` and `speed` are applied.
94
+ * @param {{ hold?: number, loopDelay?: number, loop?: boolean, rest?: 'flat' | 'glass', delay?: number, speed?: number, restScale?: number, form?: 'tile' | 'mark' }} config The settings.
95
+ * @returns {DropState} The state.
96
+ */
97
+ export function dropAt(seconds, config) {
98
+ const hold = config.hold ?? DEFAULTS.hold;
99
+ const restScale = config.restScale ?? DEFAULTS.restScale;
100
+ const keep = (config.rest ?? DEFAULTS.rest) === 'glass';
101
+ const looping = !keep && (config.loop ?? DEFAULTS.loop);
102
+ const speed = Math.max(0.05, config.speed ?? DEFAULTS.speed);
103
+ let t = (seconds - (config.delay ?? DEFAULTS.delay)) * speed;
104
+ const cycle = dropCycle(config);
105
+ if (!Number.isFinite(t)) t = keep ? cycle : cycle + hold + DROP_PHASES.melt + 1;
106
+ else if (looping && t > 0) t %= cycle;
107
+ const { form, spread, melt } = DROP_PHASES;
108
+ const glassOnly = (config.form ?? 'tile') === 'mark';
109
+
110
+ const drop = t <= 0 ? 0 : t >= form ? 1 : 1 - (1 - t / form) ** 3;
111
+ const u = (t - form) / spread;
112
+ // A damped spring from the drop to the shape: past it a little, then settling, landing on exactly 1.
113
+ const spring = u <= 0 ? 0 : 1 - Math.exp(-5 * u) * Math.cos(9 * u);
114
+ const morph = u <= 0 ? 0 : u >= 1 ? 1 : spring + (1 - spring) * ease((u - 0.75) / 0.25);
115
+ const wobble = t <= 0 ? 0 : u <= 0 ? Math.min(1, t / form) * 0.6 : u >= 1 ? 0 : Math.exp(-4 * u);
116
+ const ripple = t >= form ? t - form : -1;
117
+ const markIn = glassOnly ? 0 : ease((u - 0.2) / 0.6);
118
+ const v = keep ? 0 : ease((t - form - spread - hold) / melt);
119
+ const end = form + spread + (keep ? 0 : hold + melt);
120
+ // On a loop every round starts from where the last one rested: the flat mark, fading as the new drop forms.
121
+ if (looping && t < form)
122
+ return { drop, morph, wobble, ripple, markIn: 1 - drop, glass: 1, scale: restScale, done: false };
123
+ return {
124
+ drop,
125
+ morph,
126
+ wobble,
127
+ ripple,
128
+ markIn: glassOnly ? v : markIn,
129
+ glass: 1 - v,
130
+ scale: 1 + (restScale - 1) * v,
131
+ done: !looping && t >= end + 2,
132
+ };
133
+ }
@@ -0,0 +1,61 @@
1
+ export interface GlassDropConfig {
2
+ /** An image (an SVG logo) to make the glass of. */
3
+ src?: string;
4
+ /** A character or word instead of an image. */
5
+ text?: string;
6
+ /** Its CSS font, without the size. Default: the page's, bold. */
7
+ font?: string;
8
+ /** Where the glass sits, each 0–1 from the top left. Default all of the element. */
9
+ area?: { x: number; y: number; width: number; height: number };
10
+ /** What the drop becomes: `tile`, a glass tile with the logo under it, or `mark`, the logo's own shape in glass. Default `tile`. */
11
+ form?: 'tile' | 'mark';
12
+ /** The tile's edge, a share of the area's shorter side, 0.2–1. Default 0.7. */
13
+ size?: number;
14
+ /** The logo's size under the glass, a share of the tile, 0.2–1. Default 0.62. */
15
+ markScale?: number;
16
+ /** The logo's size once the glass has melted, times its size under the glass, 0.5–2. Default 1. */
17
+ restScale?: number;
18
+ /** The tile's corner radius, a share of its edge, 0–0.5. Default 0.24. */
19
+ radius?: number;
20
+ /** The ground. Default `#000000`. */
21
+ background?: string;
22
+ /** The logo's colour. Default `#ffffff`. */
23
+ color?: string;
24
+ /** The tile's surface under the logo. Default `#0a1020`. */
25
+ plate?: string;
26
+ /** The studio light the glass mirrors. Default `#ffffff`. */
27
+ light?: string;
28
+ /** How hard the glass bends what is under it, 0–2. Default 1. */
29
+ depth?: number;
30
+ /** How far the colours part at the rim, 0–2; 0 for none. Default 1. */
31
+ dispersion?: number;
32
+ /** How wide the rounded rim is, a share of the tile (or the logo), 0.02–0.3. Default 0.1. */
33
+ bevel?: number;
34
+ /** The lip and the studio's reflections, 0–2. Default 1. */
35
+ highlights?: number;
36
+ /** Light focused at the glass's edge and onto the ground, 0–2. Default 1. */
37
+ caustics?: number;
38
+ /** A soft glow round the glass, 0–1. Default 0.5. */
39
+ bloom?: number;
40
+ /** The rings the drop sends across the ground, 0–2; 0 for none. Default 1. */
41
+ ripples?: number;
42
+ /** With `form: 'mark'`: how strongly the glass takes the logo's colour, 0–1. Default 0.88. */
43
+ tint?: number;
44
+ /** Where the light comes from, degrees, 0–360 (0 right, 90 top). Default 125. */
45
+ lightAngle?: number;
46
+ /** How fast the sequence plays, 0.25–3. Default 1. */
47
+ speed?: number;
48
+ /** Seconds to wait before it starts, 0–10. Default 0. */
49
+ delay?: number;
50
+ /** Seconds the glass holds before it melts, 0–10. Default 2.4. */
51
+ hold?: number;
52
+ /** Play it again after a rest; each round starts from the resting logo, which fades as the new drop forms. Default false. */
53
+ loop?: boolean;
54
+ /** With `loop`: seconds the logo rests before the next drop, 0–10. Default 1.6. */
55
+ loopDelay?: number;
56
+ /** How it ends: `flat`, the glass melted and the logo left on the ground, or `glass`, the glass held. Default `flat`. */
57
+ rest?: 'flat' | 'glass';
58
+ }
59
+
60
+ /** Starts the glass drop on an element (its first canvas). Returns a function that stops it. */
61
+ export declare function glassDrop(el: HTMLElement, config: GlassDropConfig): () => void;