use-scroll-animate 5.7.0 → 5.8.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/CHANGELOG.md +12 -0
- package/dist/components/effects.cjs +363 -1
- package/dist/components/effects.cjs.map +1 -1
- package/dist/components/effects.d.cts +112 -2
- package/dist/components/effects.d.ts +112 -2
- package/dist/components/effects.js +351 -4
- package/dist/components/effects.js.map +1 -1
- package/dist/components.umd.js +2 -2
- package/dist/components.umd.js.map +1 -1
- package/docs/ROADMAP.md +1 -1
- package/docs/components.md +20 -0
- package/package.json +1 -1
|
@@ -306,6 +306,114 @@ interface UsaGestureFxElement extends UsaElement {
|
|
|
306
306
|
*/
|
|
307
307
|
declare function defineGestureFx(tag?: string): CustomElementConstructor | undefined;
|
|
308
308
|
|
|
309
|
+
/**
|
|
310
|
+
* 5.8 — micro-interaction library (23 effects, registered through
|
|
311
|
+
* `registerEffect()`). Each one does the small piece of UI work as well as the
|
|
312
|
+
* motion — toggling `aria-pressed`, swapping a label, bumping a count, copying
|
|
313
|
+
* to the clipboard — so the state change still happens under reduced motion;
|
|
314
|
+
* only the animation is dropped (`ctx.animate` returns `null` there).
|
|
315
|
+
*
|
|
316
|
+
* Click: `copy-success`, `toggle-morph`, `password-reveal`, `favorite-star`,
|
|
317
|
+
* `like-heart`, `bookmark-flip`, `download-progress`, `submit-loading`,
|
|
318
|
+
* `send-plane`, `add-to-cart`, `counter-bump`, `upvote`, `clap`,
|
|
319
|
+
* `emoji-react`, `refresh-spin`, `trash-shake`, `check-toggle`.
|
|
320
|
+
* Attention: `input-shake`, `error-flash`, `success-check`, `nudge-hint`,
|
|
321
|
+
* `focus-pulse`, `notify-badge`.
|
|
322
|
+
*/
|
|
323
|
+
|
|
324
|
+
/** Toggle `aria-pressed` (or set it) and return the new state. */
|
|
325
|
+
declare function togglePressed(el: HTMLElement, force?: boolean): boolean;
|
|
326
|
+
/** Swap `el`'s label for `ms` (polite live region), then restore it. */
|
|
327
|
+
declare function swapLabel(el: HTMLElement, text: string, ms: number): Promise<void>;
|
|
328
|
+
/** Add `delta` to the number in `[data-count]` (or `el`), keeping it in `data-count`. Returns the new value. */
|
|
329
|
+
declare function bumpCount(el: HTMLElement, delta: number, ctx?: EffectContext): number;
|
|
330
|
+
declare const MICRO_FX: EffectDefinition[];
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* use-scroll-animate/components/tokens — motion design tokens (4.2).
|
|
334
|
+
*
|
|
335
|
+
* One source of truth for durations, easings and springs: as CSS custom
|
|
336
|
+
* properties (`--usa-duration-fast`, `--usa-easing-emphasized`,
|
|
337
|
+
* `--usa-spring-bouncy-stiffness`…), as W3C Design Tokens JSON, and importable
|
|
338
|
+
* from Figma Tokens (Tokens Studio) or Style Dictionary exports.
|
|
339
|
+
*
|
|
340
|
+
* ```ts
|
|
341
|
+
* import { applyMotionTokens, importMotionTokens, motionToken } from 'use-scroll-animate/components/tokens';
|
|
342
|
+
* applyMotionTokens(importMotionTokens(await (await fetch('/tokens.json')).json()));
|
|
343
|
+
* el.animate(frames, { duration: motionToken('duration', 'slow'), easing: motionToken('easing', 'emphasized') });
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
interface SpringToken {
|
|
347
|
+
stiffness: number;
|
|
348
|
+
damping: number;
|
|
349
|
+
mass: number;
|
|
350
|
+
}
|
|
351
|
+
interface MotionTokens {
|
|
352
|
+
/** Durations in ms. */
|
|
353
|
+
duration: Record<string, number>;
|
|
354
|
+
/** CSS easing strings. */
|
|
355
|
+
easing: Record<string, string>;
|
|
356
|
+
/** Spring physics parameters. */
|
|
357
|
+
spring: Record<string, SpringToken>;
|
|
358
|
+
}
|
|
359
|
+
type DeepPartialTokens = {
|
|
360
|
+
[K in keyof MotionTokens]?: Partial<MotionTokens[K]>;
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* 5.8 — theme packs: `neon`, `paper`, `glass`, `retro`, `brutalist`.
|
|
365
|
+
*
|
|
366
|
+
* A theme pack is design tokens (`--usa-theme-*` custom properties), motion
|
|
367
|
+
* tokens (merged over the 3.x motion scale) and effect presets per role
|
|
368
|
+
* (`enter`, `hover`, `click`, `attention`, `background`). Five theme effects
|
|
369
|
+
* ship with them: `neon-flicker`, `paper-fold`, `glass-shine`,
|
|
370
|
+
* `retro-scanlines`, `brutal-shift`.
|
|
371
|
+
*
|
|
372
|
+
* - `applyTheme(name, root?)` — on `<html>` (default) it also makes the motion
|
|
373
|
+
* tokens active for `motionToken()`; on any other element the tokens are
|
|
374
|
+
* only written as variables there. Returns an undo.
|
|
375
|
+
* - `themePreset(name, role)`, `playThemeEffect(el, role)` (theme of the
|
|
376
|
+
* closest `[data-usa-theme]`).
|
|
377
|
+
* - `<usa-theme name="neon">` — scopes a theme to its subtree and binds the
|
|
378
|
+
* presets to children with `data-theme-fx="click | hover | enter | attention"`.
|
|
379
|
+
*/
|
|
380
|
+
|
|
381
|
+
declare const THEME_ROLES: readonly ["enter", "hover", "click", "attention", "background"];
|
|
382
|
+
type ThemeRole = (typeof THEME_ROLES)[number];
|
|
383
|
+
interface ThemePack {
|
|
384
|
+
name: string;
|
|
385
|
+
/** Design tokens, written as `--usa-theme-<key>`. */
|
|
386
|
+
vars: Record<'bg' | 'fg' | 'accent' | 'accent-2' | 'surface' | 'border' | 'radius' | 'shadow' | 'font', string>;
|
|
387
|
+
/** Motion tokens merged over the defaults. */
|
|
388
|
+
motion: DeepPartialTokens;
|
|
389
|
+
/** Effect preset per role. */
|
|
390
|
+
presets: Record<ThemeRole, {
|
|
391
|
+
effect: string;
|
|
392
|
+
options?: Record<string, unknown>;
|
|
393
|
+
}>;
|
|
394
|
+
}
|
|
395
|
+
declare const THEMES: Record<string, ThemePack>;
|
|
396
|
+
declare const THEME_NAMES: string[];
|
|
397
|
+
/** The CSS custom properties of a theme (design + motion tokens). */
|
|
398
|
+
declare function themeVars(t: string | ThemePack): Record<string, string>;
|
|
399
|
+
/** A theme as a CSS rule (`selector` default `[data-usa-theme=<name>]`) — for SSR / static CSS. */
|
|
400
|
+
declare function themeCss(t: string | ThemePack, selector?: string): string;
|
|
401
|
+
/** Apply a theme to `root` (default `<html>`). Returns an undo. */
|
|
402
|
+
declare function applyTheme(t: string | ThemePack, root?: HTMLElement): () => void;
|
|
403
|
+
/** The effect preset of a theme for a role. */
|
|
404
|
+
declare function themePreset(t: string | ThemePack, role: ThemeRole): {
|
|
405
|
+
effect: string;
|
|
406
|
+
options?: Record<string, unknown>;
|
|
407
|
+
};
|
|
408
|
+
/** Play the preset for `role` of the theme on the closest `[data-usa-theme]` (or `theme`). */
|
|
409
|
+
declare function playThemeEffect(el: HTMLElement, role: ThemeRole, theme?: string): Promise<void>;
|
|
410
|
+
declare const THEME_FX: EffectDefinition[];
|
|
411
|
+
interface UsaThemeElement extends UsaElement {
|
|
412
|
+
readonly theme: string;
|
|
413
|
+
}
|
|
414
|
+
/** `<usa-theme name="neon | paper | glass | retro | brutalist">` — a themed subtree. */
|
|
415
|
+
declare function defineTheme(tag?: string): CustomElementConstructor | undefined;
|
|
416
|
+
|
|
309
417
|
/**
|
|
310
418
|
* 5.4 — `<usa-story template="…">` scroll-storytelling templates.
|
|
311
419
|
*
|
|
@@ -362,10 +470,12 @@ declare function registerGenerativeEffects(): void;
|
|
|
362
470
|
declare function registerAudioEffects(): void;
|
|
363
471
|
/** 5.7: cursor trails, magnetic dots, spotlight cursor. */
|
|
364
472
|
declare function registerCursorEffects(): void;
|
|
473
|
+
/** 5.8: micro-interactions + theme-pack effects. */
|
|
474
|
+
declare function registerMicroEffects(): void;
|
|
365
475
|
/** Define the 5.x elements of this entry (`<usa-story>`, …) under their default tags. */
|
|
366
476
|
declare function defineEffectElements(): void;
|
|
367
477
|
/** Register the built-ins and every pack (idempotent). */
|
|
368
478
|
declare function registerAllEffects(): void;
|
|
369
479
|
|
|
370
|
-
export { AUDIO_FX, CARD_FX, CLICK_FX, CURSOR_FX, EFFECT_PACKS, GENERATIVE_FX, GESTURES, PAGE_FX, PHYSICS_FX, STORY_TEMPLATES, angleDelta, bindBeat, bindGesture, bounceKeyframes, canvasBackground, createBeatDetector, defineAudio, defineEffectElements, defineGestureFx, defineStory, disableAudio, enableAudio, flingVelocity, formatCount, fxLayer, getAudio, hexRgb, noise2, onBeat, registerAllEffects, registerAudioEffects, registerCardClickEffects, registerCursorEffects, registerGenerativeEffects, registerPageEffects, registerPhysicsEffects, solveSpring, springKeyframes, storyProgress };
|
|
371
|
-
export type { AudioInput, AudioReactive, AudioSample, BeatOptions, GenFrame, GenerativeSpec, GestureDetail, GestureFxOptions, GestureName, SpringOptions, StoryTemplate, UsaAudioElement, UsaGestureFxElement, UsaStoryElement };
|
|
480
|
+
export { AUDIO_FX, CARD_FX, CLICK_FX, CURSOR_FX, EFFECT_PACKS, GENERATIVE_FX, GESTURES, MICRO_FX, PAGE_FX, PHYSICS_FX, STORY_TEMPLATES, THEMES, THEME_FX, THEME_NAMES, THEME_ROLES, angleDelta, applyTheme, bindBeat, bindGesture, bounceKeyframes, bumpCount, canvasBackground, createBeatDetector, defineAudio, defineEffectElements, defineGestureFx, defineStory, defineTheme, disableAudio, enableAudio, flingVelocity, formatCount, fxLayer, getAudio, hexRgb, noise2, onBeat, playThemeEffect, registerAllEffects, registerAudioEffects, registerCardClickEffects, registerCursorEffects, registerGenerativeEffects, registerMicroEffects, registerPageEffects, registerPhysicsEffects, solveSpring, springKeyframes, storyProgress, swapLabel, themeCss, themePreset, themeVars, togglePressed };
|
|
481
|
+
export type { AudioInput, AudioReactive, AudioSample, BeatOptions, GenFrame, GenerativeSpec, GestureDetail, GestureFxOptions, GestureName, SpringOptions, StoryTemplate, ThemePack, ThemeRole, UsaAudioElement, UsaGestureFxElement, UsaStoryElement, UsaThemeElement };
|
|
@@ -306,6 +306,114 @@ interface UsaGestureFxElement extends UsaElement {
|
|
|
306
306
|
*/
|
|
307
307
|
declare function defineGestureFx(tag?: string): CustomElementConstructor | undefined;
|
|
308
308
|
|
|
309
|
+
/**
|
|
310
|
+
* 5.8 — micro-interaction library (23 effects, registered through
|
|
311
|
+
* `registerEffect()`). Each one does the small piece of UI work as well as the
|
|
312
|
+
* motion — toggling `aria-pressed`, swapping a label, bumping a count, copying
|
|
313
|
+
* to the clipboard — so the state change still happens under reduced motion;
|
|
314
|
+
* only the animation is dropped (`ctx.animate` returns `null` there).
|
|
315
|
+
*
|
|
316
|
+
* Click: `copy-success`, `toggle-morph`, `password-reveal`, `favorite-star`,
|
|
317
|
+
* `like-heart`, `bookmark-flip`, `download-progress`, `submit-loading`,
|
|
318
|
+
* `send-plane`, `add-to-cart`, `counter-bump`, `upvote`, `clap`,
|
|
319
|
+
* `emoji-react`, `refresh-spin`, `trash-shake`, `check-toggle`.
|
|
320
|
+
* Attention: `input-shake`, `error-flash`, `success-check`, `nudge-hint`,
|
|
321
|
+
* `focus-pulse`, `notify-badge`.
|
|
322
|
+
*/
|
|
323
|
+
|
|
324
|
+
/** Toggle `aria-pressed` (or set it) and return the new state. */
|
|
325
|
+
declare function togglePressed(el: HTMLElement, force?: boolean): boolean;
|
|
326
|
+
/** Swap `el`'s label for `ms` (polite live region), then restore it. */
|
|
327
|
+
declare function swapLabel(el: HTMLElement, text: string, ms: number): Promise<void>;
|
|
328
|
+
/** Add `delta` to the number in `[data-count]` (or `el`), keeping it in `data-count`. Returns the new value. */
|
|
329
|
+
declare function bumpCount(el: HTMLElement, delta: number, ctx?: EffectContext): number;
|
|
330
|
+
declare const MICRO_FX: EffectDefinition[];
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* use-scroll-animate/components/tokens — motion design tokens (4.2).
|
|
334
|
+
*
|
|
335
|
+
* One source of truth for durations, easings and springs: as CSS custom
|
|
336
|
+
* properties (`--usa-duration-fast`, `--usa-easing-emphasized`,
|
|
337
|
+
* `--usa-spring-bouncy-stiffness`…), as W3C Design Tokens JSON, and importable
|
|
338
|
+
* from Figma Tokens (Tokens Studio) or Style Dictionary exports.
|
|
339
|
+
*
|
|
340
|
+
* ```ts
|
|
341
|
+
* import { applyMotionTokens, importMotionTokens, motionToken } from 'use-scroll-animate/components/tokens';
|
|
342
|
+
* applyMotionTokens(importMotionTokens(await (await fetch('/tokens.json')).json()));
|
|
343
|
+
* el.animate(frames, { duration: motionToken('duration', 'slow'), easing: motionToken('easing', 'emphasized') });
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
interface SpringToken {
|
|
347
|
+
stiffness: number;
|
|
348
|
+
damping: number;
|
|
349
|
+
mass: number;
|
|
350
|
+
}
|
|
351
|
+
interface MotionTokens {
|
|
352
|
+
/** Durations in ms. */
|
|
353
|
+
duration: Record<string, number>;
|
|
354
|
+
/** CSS easing strings. */
|
|
355
|
+
easing: Record<string, string>;
|
|
356
|
+
/** Spring physics parameters. */
|
|
357
|
+
spring: Record<string, SpringToken>;
|
|
358
|
+
}
|
|
359
|
+
type DeepPartialTokens = {
|
|
360
|
+
[K in keyof MotionTokens]?: Partial<MotionTokens[K]>;
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* 5.8 — theme packs: `neon`, `paper`, `glass`, `retro`, `brutalist`.
|
|
365
|
+
*
|
|
366
|
+
* A theme pack is design tokens (`--usa-theme-*` custom properties), motion
|
|
367
|
+
* tokens (merged over the 3.x motion scale) and effect presets per role
|
|
368
|
+
* (`enter`, `hover`, `click`, `attention`, `background`). Five theme effects
|
|
369
|
+
* ship with them: `neon-flicker`, `paper-fold`, `glass-shine`,
|
|
370
|
+
* `retro-scanlines`, `brutal-shift`.
|
|
371
|
+
*
|
|
372
|
+
* - `applyTheme(name, root?)` — on `<html>` (default) it also makes the motion
|
|
373
|
+
* tokens active for `motionToken()`; on any other element the tokens are
|
|
374
|
+
* only written as variables there. Returns an undo.
|
|
375
|
+
* - `themePreset(name, role)`, `playThemeEffect(el, role)` (theme of the
|
|
376
|
+
* closest `[data-usa-theme]`).
|
|
377
|
+
* - `<usa-theme name="neon">` — scopes a theme to its subtree and binds the
|
|
378
|
+
* presets to children with `data-theme-fx="click | hover | enter | attention"`.
|
|
379
|
+
*/
|
|
380
|
+
|
|
381
|
+
declare const THEME_ROLES: readonly ["enter", "hover", "click", "attention", "background"];
|
|
382
|
+
type ThemeRole = (typeof THEME_ROLES)[number];
|
|
383
|
+
interface ThemePack {
|
|
384
|
+
name: string;
|
|
385
|
+
/** Design tokens, written as `--usa-theme-<key>`. */
|
|
386
|
+
vars: Record<'bg' | 'fg' | 'accent' | 'accent-2' | 'surface' | 'border' | 'radius' | 'shadow' | 'font', string>;
|
|
387
|
+
/** Motion tokens merged over the defaults. */
|
|
388
|
+
motion: DeepPartialTokens;
|
|
389
|
+
/** Effect preset per role. */
|
|
390
|
+
presets: Record<ThemeRole, {
|
|
391
|
+
effect: string;
|
|
392
|
+
options?: Record<string, unknown>;
|
|
393
|
+
}>;
|
|
394
|
+
}
|
|
395
|
+
declare const THEMES: Record<string, ThemePack>;
|
|
396
|
+
declare const THEME_NAMES: string[];
|
|
397
|
+
/** The CSS custom properties of a theme (design + motion tokens). */
|
|
398
|
+
declare function themeVars(t: string | ThemePack): Record<string, string>;
|
|
399
|
+
/** A theme as a CSS rule (`selector` default `[data-usa-theme=<name>]`) — for SSR / static CSS. */
|
|
400
|
+
declare function themeCss(t: string | ThemePack, selector?: string): string;
|
|
401
|
+
/** Apply a theme to `root` (default `<html>`). Returns an undo. */
|
|
402
|
+
declare function applyTheme(t: string | ThemePack, root?: HTMLElement): () => void;
|
|
403
|
+
/** The effect preset of a theme for a role. */
|
|
404
|
+
declare function themePreset(t: string | ThemePack, role: ThemeRole): {
|
|
405
|
+
effect: string;
|
|
406
|
+
options?: Record<string, unknown>;
|
|
407
|
+
};
|
|
408
|
+
/** Play the preset for `role` of the theme on the closest `[data-usa-theme]` (or `theme`). */
|
|
409
|
+
declare function playThemeEffect(el: HTMLElement, role: ThemeRole, theme?: string): Promise<void>;
|
|
410
|
+
declare const THEME_FX: EffectDefinition[];
|
|
411
|
+
interface UsaThemeElement extends UsaElement {
|
|
412
|
+
readonly theme: string;
|
|
413
|
+
}
|
|
414
|
+
/** `<usa-theme name="neon | paper | glass | retro | brutalist">` — a themed subtree. */
|
|
415
|
+
declare function defineTheme(tag?: string): CustomElementConstructor | undefined;
|
|
416
|
+
|
|
309
417
|
/**
|
|
310
418
|
* 5.4 — `<usa-story template="…">` scroll-storytelling templates.
|
|
311
419
|
*
|
|
@@ -362,10 +470,12 @@ declare function registerGenerativeEffects(): void;
|
|
|
362
470
|
declare function registerAudioEffects(): void;
|
|
363
471
|
/** 5.7: cursor trails, magnetic dots, spotlight cursor. */
|
|
364
472
|
declare function registerCursorEffects(): void;
|
|
473
|
+
/** 5.8: micro-interactions + theme-pack effects. */
|
|
474
|
+
declare function registerMicroEffects(): void;
|
|
365
475
|
/** Define the 5.x elements of this entry (`<usa-story>`, …) under their default tags. */
|
|
366
476
|
declare function defineEffectElements(): void;
|
|
367
477
|
/** Register the built-ins and every pack (idempotent). */
|
|
368
478
|
declare function registerAllEffects(): void;
|
|
369
479
|
|
|
370
|
-
export { AUDIO_FX, CARD_FX, CLICK_FX, CURSOR_FX, EFFECT_PACKS, GENERATIVE_FX, GESTURES, PAGE_FX, PHYSICS_FX, STORY_TEMPLATES, angleDelta, bindBeat, bindGesture, bounceKeyframes, canvasBackground, createBeatDetector, defineAudio, defineEffectElements, defineGestureFx, defineStory, disableAudio, enableAudio, flingVelocity, formatCount, fxLayer, getAudio, hexRgb, noise2, onBeat, registerAllEffects, registerAudioEffects, registerCardClickEffects, registerCursorEffects, registerGenerativeEffects, registerPageEffects, registerPhysicsEffects, solveSpring, springKeyframes, storyProgress };
|
|
371
|
-
export type { AudioInput, AudioReactive, AudioSample, BeatOptions, GenFrame, GenerativeSpec, GestureDetail, GestureFxOptions, GestureName, SpringOptions, StoryTemplate, UsaAudioElement, UsaGestureFxElement, UsaStoryElement };
|
|
480
|
+
export { AUDIO_FX, CARD_FX, CLICK_FX, CURSOR_FX, EFFECT_PACKS, GENERATIVE_FX, GESTURES, MICRO_FX, PAGE_FX, PHYSICS_FX, STORY_TEMPLATES, THEMES, THEME_FX, THEME_NAMES, THEME_ROLES, angleDelta, applyTheme, bindBeat, bindGesture, bounceKeyframes, bumpCount, canvasBackground, createBeatDetector, defineAudio, defineEffectElements, defineGestureFx, defineStory, defineTheme, disableAudio, enableAudio, flingVelocity, formatCount, fxLayer, getAudio, hexRgb, noise2, onBeat, playThemeEffect, registerAllEffects, registerAudioEffects, registerCardClickEffects, registerCursorEffects, registerGenerativeEffects, registerMicroEffects, registerPageEffects, registerPhysicsEffects, solveSpring, springKeyframes, storyProgress, swapLabel, themeCss, themePreset, themeVars, togglePressed };
|
|
481
|
+
export type { AudioInput, AudioReactive, AudioSample, BeatOptions, GenFrame, GenerativeSpec, GestureDetail, GestureFxOptions, GestureName, SpringOptions, StoryTemplate, ThemePack, ThemeRole, UsaAudioElement, UsaGestureFxElement, UsaStoryElement, UsaThemeElement };
|