use-scroll-animate 5.6.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 +23 -0
- package/dist/components/effects.cjs +758 -1
- package/dist/components/effects.cjs.map +1 -1
- package/dist/components/effects.d.cts +185 -2
- package/dist/components/effects.d.ts +185 -2
- package/dist/components/effects.js +739 -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 +2 -2
- package/docs/components.md +36 -0
- package/package.json +1 -1
|
@@ -235,6 +235,185 @@ interface UsaAudioElement extends UsaElement {
|
|
|
235
235
|
*/
|
|
236
236
|
declare function defineAudio(tag?: string): CustomElementConstructor | undefined;
|
|
237
237
|
|
|
238
|
+
/**
|
|
239
|
+
* 5.7 — cursor & gesture packs.
|
|
240
|
+
*
|
|
241
|
+
* Cursor effects (kind `cursor`, persistent, scoped to the element they are
|
|
242
|
+
* bound to; skipped under reduced motion and — unless `touch: true` — for
|
|
243
|
+
* touch pointers): `comet-trail`, `sparkle-trail`, `ribbon-trail`,
|
|
244
|
+
* `magnetic-dots`, `spotlight-cursor`.
|
|
245
|
+
*
|
|
246
|
+
* Gestures → effects: `bindGesture(el, 'fling' | 'twist' | 'long-press',
|
|
247
|
+
* effectOrCallback, options)` and `<usa-gesture-fx gesture effect>`. A fling
|
|
248
|
+
* is a fast release, a twist a two-finger rotation past `angle` degrees, a
|
|
249
|
+
* long press "charges" `--usa-charge` 0 → 1 and fires when full. Every fire
|
|
250
|
+
* dispatches `usa-gesture` (`detail: { gesture, … }`). The effect itself goes
|
|
251
|
+
* through `playEffect()`, so reduced motion is honoured there.
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
type Pt = {
|
|
255
|
+
x: number;
|
|
256
|
+
y: number;
|
|
257
|
+
t: number;
|
|
258
|
+
};
|
|
259
|
+
declare const CURSOR_FX: EffectDefinition[];
|
|
260
|
+
declare const GESTURES: readonly ["fling", "twist", "long-press"];
|
|
261
|
+
type GestureName = (typeof GESTURES)[number];
|
|
262
|
+
interface GestureFxOptions {
|
|
263
|
+
/** fling: minimum release speed in px/ms (default 0.8). */
|
|
264
|
+
velocity?: number;
|
|
265
|
+
/** twist: degrees of rotation that fire (default 30). */
|
|
266
|
+
angle?: number;
|
|
267
|
+
/** long-press: ms to fully charge (default 650). */
|
|
268
|
+
duration?: number;
|
|
269
|
+
/** long-press: px the pointer may move before the press is cancelled (default 10). */
|
|
270
|
+
tolerance?: number;
|
|
271
|
+
/** Options passed to the effect. */
|
|
272
|
+
effectOptions?: Record<string, unknown>;
|
|
273
|
+
}
|
|
274
|
+
interface GestureDetail {
|
|
275
|
+
gesture: GestureName;
|
|
276
|
+
/** fling */
|
|
277
|
+
vx?: number;
|
|
278
|
+
vy?: number;
|
|
279
|
+
speed?: number;
|
|
280
|
+
direction?: 'left' | 'right' | 'up' | 'down' | 'cw' | 'ccw';
|
|
281
|
+
/** twist: signed degrees since the last fire. */
|
|
282
|
+
angle?: number;
|
|
283
|
+
/** long-press: 1 when fired. */
|
|
284
|
+
charge?: number;
|
|
285
|
+
}
|
|
286
|
+
/** Release velocity (px/ms) from recent pointer samples: uses the last `window` ms (pure). */
|
|
287
|
+
declare function flingVelocity(pts: Pt[], window?: number): {
|
|
288
|
+
vx: number;
|
|
289
|
+
vy: number;
|
|
290
|
+
speed: number;
|
|
291
|
+
};
|
|
292
|
+
/** Signed smallest difference between two angles in degrees, in (-180, 180] (pure). */
|
|
293
|
+
declare function angleDelta(a: number, b: number): number;
|
|
294
|
+
/**
|
|
295
|
+
* Fire `effect` (a registered effect name, or a callback) when `gesture`
|
|
296
|
+
* happens on `el`. Returns an unbind.
|
|
297
|
+
*/
|
|
298
|
+
declare function bindGesture(el: HTMLElement, gesture: GestureName, effect: string | ((d: GestureDetail, e: Event) => void), o?: GestureFxOptions): () => void;
|
|
299
|
+
interface UsaGestureFxElement extends UsaElement {
|
|
300
|
+
readonly gesture: GestureName;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* `<usa-gesture-fx gesture="fling | twist | long-press" effect="tada"
|
|
304
|
+
* options='{"…"}' velocity angle duration>` — plays `effect` on its first
|
|
305
|
+
* child (or itself with `self`) when the gesture happens.
|
|
306
|
+
*/
|
|
307
|
+
declare function defineGestureFx(tag?: string): CustomElementConstructor | undefined;
|
|
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
|
+
|
|
238
417
|
/**
|
|
239
418
|
* 5.4 — `<usa-story template="…">` scroll-storytelling templates.
|
|
240
419
|
*
|
|
@@ -289,10 +468,14 @@ declare function registerPageEffects(): void;
|
|
|
289
468
|
declare function registerGenerativeEffects(): void;
|
|
290
469
|
/** 5.6: sound-reactive (Web Audio) backgrounds. */
|
|
291
470
|
declare function registerAudioEffects(): void;
|
|
471
|
+
/** 5.7: cursor trails, magnetic dots, spotlight cursor. */
|
|
472
|
+
declare function registerCursorEffects(): void;
|
|
473
|
+
/** 5.8: micro-interactions + theme-pack effects. */
|
|
474
|
+
declare function registerMicroEffects(): void;
|
|
292
475
|
/** Define the 5.x elements of this entry (`<usa-story>`, …) under their default tags. */
|
|
293
476
|
declare function defineEffectElements(): void;
|
|
294
477
|
/** Register the built-ins and every pack (idempotent). */
|
|
295
478
|
declare function registerAllEffects(): void;
|
|
296
479
|
|
|
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 };
|
|
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 };
|
|
@@ -235,6 +235,185 @@ interface UsaAudioElement extends UsaElement {
|
|
|
235
235
|
*/
|
|
236
236
|
declare function defineAudio(tag?: string): CustomElementConstructor | undefined;
|
|
237
237
|
|
|
238
|
+
/**
|
|
239
|
+
* 5.7 — cursor & gesture packs.
|
|
240
|
+
*
|
|
241
|
+
* Cursor effects (kind `cursor`, persistent, scoped to the element they are
|
|
242
|
+
* bound to; skipped under reduced motion and — unless `touch: true` — for
|
|
243
|
+
* touch pointers): `comet-trail`, `sparkle-trail`, `ribbon-trail`,
|
|
244
|
+
* `magnetic-dots`, `spotlight-cursor`.
|
|
245
|
+
*
|
|
246
|
+
* Gestures → effects: `bindGesture(el, 'fling' | 'twist' | 'long-press',
|
|
247
|
+
* effectOrCallback, options)` and `<usa-gesture-fx gesture effect>`. A fling
|
|
248
|
+
* is a fast release, a twist a two-finger rotation past `angle` degrees, a
|
|
249
|
+
* long press "charges" `--usa-charge` 0 → 1 and fires when full. Every fire
|
|
250
|
+
* dispatches `usa-gesture` (`detail: { gesture, … }`). The effect itself goes
|
|
251
|
+
* through `playEffect()`, so reduced motion is honoured there.
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
type Pt = {
|
|
255
|
+
x: number;
|
|
256
|
+
y: number;
|
|
257
|
+
t: number;
|
|
258
|
+
};
|
|
259
|
+
declare const CURSOR_FX: EffectDefinition[];
|
|
260
|
+
declare const GESTURES: readonly ["fling", "twist", "long-press"];
|
|
261
|
+
type GestureName = (typeof GESTURES)[number];
|
|
262
|
+
interface GestureFxOptions {
|
|
263
|
+
/** fling: minimum release speed in px/ms (default 0.8). */
|
|
264
|
+
velocity?: number;
|
|
265
|
+
/** twist: degrees of rotation that fire (default 30). */
|
|
266
|
+
angle?: number;
|
|
267
|
+
/** long-press: ms to fully charge (default 650). */
|
|
268
|
+
duration?: number;
|
|
269
|
+
/** long-press: px the pointer may move before the press is cancelled (default 10). */
|
|
270
|
+
tolerance?: number;
|
|
271
|
+
/** Options passed to the effect. */
|
|
272
|
+
effectOptions?: Record<string, unknown>;
|
|
273
|
+
}
|
|
274
|
+
interface GestureDetail {
|
|
275
|
+
gesture: GestureName;
|
|
276
|
+
/** fling */
|
|
277
|
+
vx?: number;
|
|
278
|
+
vy?: number;
|
|
279
|
+
speed?: number;
|
|
280
|
+
direction?: 'left' | 'right' | 'up' | 'down' | 'cw' | 'ccw';
|
|
281
|
+
/** twist: signed degrees since the last fire. */
|
|
282
|
+
angle?: number;
|
|
283
|
+
/** long-press: 1 when fired. */
|
|
284
|
+
charge?: number;
|
|
285
|
+
}
|
|
286
|
+
/** Release velocity (px/ms) from recent pointer samples: uses the last `window` ms (pure). */
|
|
287
|
+
declare function flingVelocity(pts: Pt[], window?: number): {
|
|
288
|
+
vx: number;
|
|
289
|
+
vy: number;
|
|
290
|
+
speed: number;
|
|
291
|
+
};
|
|
292
|
+
/** Signed smallest difference between two angles in degrees, in (-180, 180] (pure). */
|
|
293
|
+
declare function angleDelta(a: number, b: number): number;
|
|
294
|
+
/**
|
|
295
|
+
* Fire `effect` (a registered effect name, or a callback) when `gesture`
|
|
296
|
+
* happens on `el`. Returns an unbind.
|
|
297
|
+
*/
|
|
298
|
+
declare function bindGesture(el: HTMLElement, gesture: GestureName, effect: string | ((d: GestureDetail, e: Event) => void), o?: GestureFxOptions): () => void;
|
|
299
|
+
interface UsaGestureFxElement extends UsaElement {
|
|
300
|
+
readonly gesture: GestureName;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* `<usa-gesture-fx gesture="fling | twist | long-press" effect="tada"
|
|
304
|
+
* options='{"…"}' velocity angle duration>` — plays `effect` on its first
|
|
305
|
+
* child (or itself with `self`) when the gesture happens.
|
|
306
|
+
*/
|
|
307
|
+
declare function defineGestureFx(tag?: string): CustomElementConstructor | undefined;
|
|
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
|
+
|
|
238
417
|
/**
|
|
239
418
|
* 5.4 — `<usa-story template="…">` scroll-storytelling templates.
|
|
240
419
|
*
|
|
@@ -289,10 +468,14 @@ declare function registerPageEffects(): void;
|
|
|
289
468
|
declare function registerGenerativeEffects(): void;
|
|
290
469
|
/** 5.6: sound-reactive (Web Audio) backgrounds. */
|
|
291
470
|
declare function registerAudioEffects(): void;
|
|
471
|
+
/** 5.7: cursor trails, magnetic dots, spotlight cursor. */
|
|
472
|
+
declare function registerCursorEffects(): void;
|
|
473
|
+
/** 5.8: micro-interactions + theme-pack effects. */
|
|
474
|
+
declare function registerMicroEffects(): void;
|
|
292
475
|
/** Define the 5.x elements of this entry (`<usa-story>`, …) under their default tags. */
|
|
293
476
|
declare function defineEffectElements(): void;
|
|
294
477
|
/** Register the built-ins and every pack (idempotent). */
|
|
295
478
|
declare function registerAllEffects(): void;
|
|
296
479
|
|
|
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 };
|
|
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 };
|