use-scroll-animate 5.4.0 → 5.6.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.
@@ -106,6 +106,135 @@ declare const PHYSICS_FX: EffectDefinition[];
106
106
 
107
107
  declare const PAGE_FX: EffectDefinition[];
108
108
 
109
+ /**
110
+ * 5.5 — generative backgrounds on Canvas 2D, registered through
111
+ * `registerEffect()` (kind `background`): `flow-field`, `voronoi`,
112
+ * `mesh-gradient`, `starfield`, `metaballs`, `contours`.
113
+ *
114
+ * Shared runner (`canvasBackground()`): a canvas behind the element's content
115
+ * (`aria-hidden`, pointer-transparent), rendering only while visible
116
+ * (IntersectionObserver) and the tab is shown, with adaptive quality — the
117
+ * render scale drops when frames get slow and recovers when they are fast.
118
+ * Reduced motion: one static frame, no loop.
119
+ */
120
+
121
+ interface GenFrame {
122
+ ctx: CanvasRenderingContext2D;
123
+ /** CSS-pixel size of the canvas. */
124
+ w: number;
125
+ h: number;
126
+ /** Seconds since start (0 for the static reduced-motion frame). */
127
+ t: number;
128
+ /** Render scale 0.35–1 (adaptive quality). */
129
+ quality: number;
130
+ /** Per-effect state, created by `init`. */
131
+ state: any;
132
+ /** Merged options. */
133
+ o: any;
134
+ }
135
+ interface GenerativeSpec {
136
+ init?: (w: number, h: number, o: any) => any;
137
+ draw: (f: GenFrame) => void;
138
+ }
139
+ /** Deterministic smooth pseudo-noise in [-1, 1] (sum of sines — cheap, no tables). */
140
+ declare function noise2(x: number, y: number, t?: number): number;
141
+ /** Hex `#rrggbb` → [r, g, b]. */
142
+ declare function hexRgb(hex: string): [number, number, number];
143
+ /**
144
+ * Mount a generative canvas behind `el` and run `spec` on it. Returns the
145
+ * cleanup. Exposed for custom generative effects.
146
+ */
147
+ declare function canvasBackground(el: HTMLElement, fx: EffectContext, spec: GenerativeSpec, o: any): () => void;
148
+ declare const GENERATIVE_FX: EffectDefinition[];
149
+
150
+ /**
151
+ * 5.6 — sound-reactive effects (Web Audio).
152
+ *
153
+ * - `enableAudio(input)` — start analysing the microphone (`'mic'`), an
154
+ * `<audio>` / `<video>` element (or a selector for one) or a `MediaStream`.
155
+ * Browsers only allow an `AudioContext` to start inside a user gesture, so
156
+ * call it from a click handler (or use `<usa-audio>`, which renders the
157
+ * toggle button for you).
158
+ * - Background effects (kind `background`, Canvas 2D through
159
+ * `canvasBackground()`): `spectrum-bars`, `pulse-ring`, `wave-ring`. Before
160
+ * audio is enabled they idle gently.
161
+ * - Beat detection: `createBeatDetector()` (pure: energy → beat?), `onBeat(cb)`
162
+ * and `bindBeat(el, effect, options)`, which plays any registered effect on
163
+ * every beat. `<usa-audio>` does the same for `[data-usa-beat="effect"]`
164
+ * children and emits `usa-beat`.
165
+ * - While audio runs, `--usa-audio-level` and `--usa-audio-bass` (0–1) are set
166
+ * on `<html>` for CSS-driven reactions.
167
+ *
168
+ * Reduced motion: the visual effects are skipped, beats play no effects and
169
+ * the CSS variables stay at 0 — audio itself keeps playing.
170
+ */
171
+
172
+ type AudioInput = 'mic' | HTMLMediaElement | MediaStream | string;
173
+ interface AudioSample {
174
+ /** Overall loudness (RMS of the waveform), 0–1. */
175
+ level: number;
176
+ /** Low-frequency energy (first ~8 % of the spectrum), 0–1. */
177
+ bass: number;
178
+ /** Frequency bins, 0–255 each. */
179
+ freq: Uint8Array;
180
+ /** Time-domain waveform, 0–255 (128 = silence). */
181
+ wave: Uint8Array;
182
+ }
183
+ interface AudioReactive {
184
+ readonly context: AudioContext;
185
+ readonly analyser: AnalyserNode;
186
+ /** Read the analyser now. */
187
+ sample(): AudioSample;
188
+ /** Stop analysing (media keeps playing; the microphone is released). */
189
+ stop(): void;
190
+ }
191
+ interface BeatOptions {
192
+ /** A beat is energy above `threshold` × the recent average (default 1.35). */
193
+ threshold?: number;
194
+ /** Minimum ms between beats (default 250). */
195
+ cooldown?: number;
196
+ /** Frames of history for the average (default 43 ≈ 0.7 s). */
197
+ history?: number;
198
+ /** Ignore energy below this floor, 0–1 (default 0.08). */
199
+ floor?: number;
200
+ }
201
+ /** The running analyser, if `enableAudio()` was called. */
202
+ declare const getAudio: () => AudioReactive | null;
203
+ /**
204
+ * Start analysing `input` and make it the source of every sound-reactive
205
+ * effect. Call from a user gesture. Replaces a previous source.
206
+ */
207
+ declare function enableAudio(input?: AudioInput, opts?: {
208
+ fftSize?: number;
209
+ smoothing?: number;
210
+ }): Promise<AudioReactive>;
211
+ /** Stop the current audio source (if any). */
212
+ declare function disableAudio(): void;
213
+ /** A pure beat detector: feed it energy (0–1) and a timestamp per frame; it answers "beat?". */
214
+ declare function createBeatDetector(o?: BeatOptions): (energy: number, now: number) => boolean;
215
+ /** Call `cb` on every detected beat of the current audio source. Returns an unsubscribe. */
216
+ declare function onBeat(cb: (detail: {
217
+ energy: number;
218
+ time: number;
219
+ }) => void, o?: BeatOptions): () => void;
220
+ /** Play the registered effect `name` on `el` at every beat (not under reduced motion). Returns an unbind. */
221
+ declare function bindBeat(el: HTMLElement, name: string, options?: Record<string, unknown> & BeatOptions): () => void;
222
+ declare const AUDIO_FX: EffectDefinition[];
223
+ interface UsaAudioElement extends UsaElement {
224
+ /** `true` while this element's audio source is being analysed. */
225
+ readonly active: boolean;
226
+ /** Start (from a user gesture) or stop analysing. */
227
+ toggle(): Promise<void>;
228
+ }
229
+ /**
230
+ * `<usa-audio source="#track | mic" label="…">` — a toggle button (yours, as
231
+ * `[data-audio-toggle]`, or one it renders) that enables the audio source on
232
+ * click; children with `data-usa-beat="effect"` play that effect on every
233
+ * beat (`data-usa-beat-options` JSON; `threshold` / `cooldown` attributes).
234
+ * Emits `usa-beat` and `usa-audio-error`.
235
+ */
236
+ declare function defineAudio(tag?: string): CustomElementConstructor | undefined;
237
+
109
238
  /**
110
239
  * 5.4 — `<usa-story template="…">` scroll-storytelling templates.
111
240
  *
@@ -156,10 +285,14 @@ declare function registerCardClickEffects(): void;
156
285
  declare function registerPhysicsEffects(): void;
157
286
  /** 5.3: page-wide transitions and effects. */
158
287
  declare function registerPageEffects(): void;
288
+ /** 5.5: generative Canvas 2D backgrounds. */
289
+ declare function registerGenerativeEffects(): void;
290
+ /** 5.6: sound-reactive (Web Audio) backgrounds. */
291
+ declare function registerAudioEffects(): void;
159
292
  /** Define the 5.x elements of this entry (`<usa-story>`, …) under their default tags. */
160
293
  declare function defineEffectElements(): void;
161
294
  /** Register the built-ins and every pack (idempotent). */
162
295
  declare function registerAllEffects(): void;
163
296
 
164
- export { CARD_FX, CLICK_FX, EFFECT_PACKS, PAGE_FX, PHYSICS_FX, STORY_TEMPLATES, bounceKeyframes, defineEffectElements, defineStory, formatCount, fxLayer, registerAllEffects, registerCardClickEffects, registerPageEffects, registerPhysicsEffects, solveSpring, springKeyframes, storyProgress };
165
- export type { SpringOptions, StoryTemplate, UsaStoryElement };
297
+ export { AUDIO_FX, CARD_FX, CLICK_FX, EFFECT_PACKS, GENERATIVE_FX, PAGE_FX, PHYSICS_FX, STORY_TEMPLATES, bindBeat, bounceKeyframes, canvasBackground, createBeatDetector, defineAudio, defineEffectElements, defineStory, disableAudio, enableAudio, formatCount, fxLayer, getAudio, hexRgb, noise2, onBeat, registerAllEffects, registerAudioEffects, registerCardClickEffects, registerGenerativeEffects, registerPageEffects, registerPhysicsEffects, solveSpring, springKeyframes, storyProgress };
298
+ export type { AudioInput, AudioReactive, AudioSample, BeatOptions, GenFrame, GenerativeSpec, SpringOptions, StoryTemplate, UsaAudioElement, UsaStoryElement };
@@ -106,6 +106,135 @@ declare const PHYSICS_FX: EffectDefinition[];
106
106
 
107
107
  declare const PAGE_FX: EffectDefinition[];
108
108
 
109
+ /**
110
+ * 5.5 — generative backgrounds on Canvas 2D, registered through
111
+ * `registerEffect()` (kind `background`): `flow-field`, `voronoi`,
112
+ * `mesh-gradient`, `starfield`, `metaballs`, `contours`.
113
+ *
114
+ * Shared runner (`canvasBackground()`): a canvas behind the element's content
115
+ * (`aria-hidden`, pointer-transparent), rendering only while visible
116
+ * (IntersectionObserver) and the tab is shown, with adaptive quality — the
117
+ * render scale drops when frames get slow and recovers when they are fast.
118
+ * Reduced motion: one static frame, no loop.
119
+ */
120
+
121
+ interface GenFrame {
122
+ ctx: CanvasRenderingContext2D;
123
+ /** CSS-pixel size of the canvas. */
124
+ w: number;
125
+ h: number;
126
+ /** Seconds since start (0 for the static reduced-motion frame). */
127
+ t: number;
128
+ /** Render scale 0.35–1 (adaptive quality). */
129
+ quality: number;
130
+ /** Per-effect state, created by `init`. */
131
+ state: any;
132
+ /** Merged options. */
133
+ o: any;
134
+ }
135
+ interface GenerativeSpec {
136
+ init?: (w: number, h: number, o: any) => any;
137
+ draw: (f: GenFrame) => void;
138
+ }
139
+ /** Deterministic smooth pseudo-noise in [-1, 1] (sum of sines — cheap, no tables). */
140
+ declare function noise2(x: number, y: number, t?: number): number;
141
+ /** Hex `#rrggbb` → [r, g, b]. */
142
+ declare function hexRgb(hex: string): [number, number, number];
143
+ /**
144
+ * Mount a generative canvas behind `el` and run `spec` on it. Returns the
145
+ * cleanup. Exposed for custom generative effects.
146
+ */
147
+ declare function canvasBackground(el: HTMLElement, fx: EffectContext, spec: GenerativeSpec, o: any): () => void;
148
+ declare const GENERATIVE_FX: EffectDefinition[];
149
+
150
+ /**
151
+ * 5.6 — sound-reactive effects (Web Audio).
152
+ *
153
+ * - `enableAudio(input)` — start analysing the microphone (`'mic'`), an
154
+ * `<audio>` / `<video>` element (or a selector for one) or a `MediaStream`.
155
+ * Browsers only allow an `AudioContext` to start inside a user gesture, so
156
+ * call it from a click handler (or use `<usa-audio>`, which renders the
157
+ * toggle button for you).
158
+ * - Background effects (kind `background`, Canvas 2D through
159
+ * `canvasBackground()`): `spectrum-bars`, `pulse-ring`, `wave-ring`. Before
160
+ * audio is enabled they idle gently.
161
+ * - Beat detection: `createBeatDetector()` (pure: energy → beat?), `onBeat(cb)`
162
+ * and `bindBeat(el, effect, options)`, which plays any registered effect on
163
+ * every beat. `<usa-audio>` does the same for `[data-usa-beat="effect"]`
164
+ * children and emits `usa-beat`.
165
+ * - While audio runs, `--usa-audio-level` and `--usa-audio-bass` (0–1) are set
166
+ * on `<html>` for CSS-driven reactions.
167
+ *
168
+ * Reduced motion: the visual effects are skipped, beats play no effects and
169
+ * the CSS variables stay at 0 — audio itself keeps playing.
170
+ */
171
+
172
+ type AudioInput = 'mic' | HTMLMediaElement | MediaStream | string;
173
+ interface AudioSample {
174
+ /** Overall loudness (RMS of the waveform), 0–1. */
175
+ level: number;
176
+ /** Low-frequency energy (first ~8 % of the spectrum), 0–1. */
177
+ bass: number;
178
+ /** Frequency bins, 0–255 each. */
179
+ freq: Uint8Array;
180
+ /** Time-domain waveform, 0–255 (128 = silence). */
181
+ wave: Uint8Array;
182
+ }
183
+ interface AudioReactive {
184
+ readonly context: AudioContext;
185
+ readonly analyser: AnalyserNode;
186
+ /** Read the analyser now. */
187
+ sample(): AudioSample;
188
+ /** Stop analysing (media keeps playing; the microphone is released). */
189
+ stop(): void;
190
+ }
191
+ interface BeatOptions {
192
+ /** A beat is energy above `threshold` × the recent average (default 1.35). */
193
+ threshold?: number;
194
+ /** Minimum ms between beats (default 250). */
195
+ cooldown?: number;
196
+ /** Frames of history for the average (default 43 ≈ 0.7 s). */
197
+ history?: number;
198
+ /** Ignore energy below this floor, 0–1 (default 0.08). */
199
+ floor?: number;
200
+ }
201
+ /** The running analyser, if `enableAudio()` was called. */
202
+ declare const getAudio: () => AudioReactive | null;
203
+ /**
204
+ * Start analysing `input` and make it the source of every sound-reactive
205
+ * effect. Call from a user gesture. Replaces a previous source.
206
+ */
207
+ declare function enableAudio(input?: AudioInput, opts?: {
208
+ fftSize?: number;
209
+ smoothing?: number;
210
+ }): Promise<AudioReactive>;
211
+ /** Stop the current audio source (if any). */
212
+ declare function disableAudio(): void;
213
+ /** A pure beat detector: feed it energy (0–1) and a timestamp per frame; it answers "beat?". */
214
+ declare function createBeatDetector(o?: BeatOptions): (energy: number, now: number) => boolean;
215
+ /** Call `cb` on every detected beat of the current audio source. Returns an unsubscribe. */
216
+ declare function onBeat(cb: (detail: {
217
+ energy: number;
218
+ time: number;
219
+ }) => void, o?: BeatOptions): () => void;
220
+ /** Play the registered effect `name` on `el` at every beat (not under reduced motion). Returns an unbind. */
221
+ declare function bindBeat(el: HTMLElement, name: string, options?: Record<string, unknown> & BeatOptions): () => void;
222
+ declare const AUDIO_FX: EffectDefinition[];
223
+ interface UsaAudioElement extends UsaElement {
224
+ /** `true` while this element's audio source is being analysed. */
225
+ readonly active: boolean;
226
+ /** Start (from a user gesture) or stop analysing. */
227
+ toggle(): Promise<void>;
228
+ }
229
+ /**
230
+ * `<usa-audio source="#track | mic" label="…">` — a toggle button (yours, as
231
+ * `[data-audio-toggle]`, or one it renders) that enables the audio source on
232
+ * click; children with `data-usa-beat="effect"` play that effect on every
233
+ * beat (`data-usa-beat-options` JSON; `threshold` / `cooldown` attributes).
234
+ * Emits `usa-beat` and `usa-audio-error`.
235
+ */
236
+ declare function defineAudio(tag?: string): CustomElementConstructor | undefined;
237
+
109
238
  /**
110
239
  * 5.4 — `<usa-story template="…">` scroll-storytelling templates.
111
240
  *
@@ -156,10 +285,14 @@ declare function registerCardClickEffects(): void;
156
285
  declare function registerPhysicsEffects(): void;
157
286
  /** 5.3: page-wide transitions and effects. */
158
287
  declare function registerPageEffects(): void;
288
+ /** 5.5: generative Canvas 2D backgrounds. */
289
+ declare function registerGenerativeEffects(): void;
290
+ /** 5.6: sound-reactive (Web Audio) backgrounds. */
291
+ declare function registerAudioEffects(): void;
159
292
  /** Define the 5.x elements of this entry (`<usa-story>`, …) under their default tags. */
160
293
  declare function defineEffectElements(): void;
161
294
  /** Register the built-ins and every pack (idempotent). */
162
295
  declare function registerAllEffects(): void;
163
296
 
164
- export { CARD_FX, CLICK_FX, EFFECT_PACKS, PAGE_FX, PHYSICS_FX, STORY_TEMPLATES, bounceKeyframes, defineEffectElements, defineStory, formatCount, fxLayer, registerAllEffects, registerCardClickEffects, registerPageEffects, registerPhysicsEffects, solveSpring, springKeyframes, storyProgress };
165
- export type { SpringOptions, StoryTemplate, UsaStoryElement };
297
+ export { AUDIO_FX, CARD_FX, CLICK_FX, EFFECT_PACKS, GENERATIVE_FX, PAGE_FX, PHYSICS_FX, STORY_TEMPLATES, bindBeat, bounceKeyframes, canvasBackground, createBeatDetector, defineAudio, defineEffectElements, defineStory, disableAudio, enableAudio, formatCount, fxLayer, getAudio, hexRgb, noise2, onBeat, registerAllEffects, registerAudioEffects, registerCardClickEffects, registerGenerativeEffects, registerPageEffects, registerPhysicsEffects, solveSpring, springKeyframes, storyProgress };
298
+ export type { AudioInput, AudioReactive, AudioSample, BeatOptions, GenFrame, GenerativeSpec, SpringOptions, StoryTemplate, UsaAudioElement, UsaStoryElement };