use-scroll-animate 2.5.0 → 2.7.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 +37 -0
- package/README.md +2 -0
- package/README_ja.md +2 -0
- package/README_zh.md +2 -0
- package/dist/chunks/{base-CJ7XfidP.cjs → base-BR6fYLBA.cjs} +25 -2
- package/dist/chunks/base-BR6fYLBA.cjs.map +1 -0
- package/dist/chunks/{base-CuvCgqLy.js → base-D6zLiNGH.js} +21 -3
- package/dist/chunks/base-D6zLiNGH.js.map +1 -0
- package/dist/chunks/{spring-BKUU7-Xm.js → spring-C2Megtcf.js} +3 -3
- package/dist/chunks/spring-C2Megtcf.js.map +1 -0
- package/dist/chunks/{spring-CGO9Jd9b.cjs → spring-DyHe1Hfa.cjs} +3 -3
- package/dist/chunks/spring-DyHe1Hfa.cjs.map +1 -0
- package/dist/components/background.cjs +1 -1
- package/dist/components/background.d.cts +8 -0
- package/dist/components/background.d.ts +8 -0
- package/dist/components/background.js +2 -2
- package/dist/components/cards.cjs +2 -2
- package/dist/components/cards.d.cts +8 -0
- package/dist/components/cards.d.ts +8 -0
- package/dist/components/cards.js +3 -3
- package/dist/components/click.cjs +2 -2
- package/dist/components/click.d.cts +8 -0
- package/dist/components/click.d.ts +8 -0
- package/dist/components/click.js +3 -3
- package/dist/components/feedback.cjs +2 -2
- package/dist/components/feedback.css +1 -1
- package/dist/components/feedback.d.cts +8 -0
- package/dist/components/feedback.d.ts +8 -0
- package/dist/components/feedback.js +3 -3
- package/dist/components/interaction.cjs +2 -2
- package/dist/components/interaction.css +1 -1
- package/dist/components/interaction.d.cts +8 -0
- package/dist/components/interaction.d.ts +8 -0
- package/dist/components/interaction.js +3 -3
- package/dist/components/page.cjs +801 -0
- package/dist/components/page.cjs.map +1 -0
- package/dist/components/page.css +11 -0
- package/dist/components/page.d.cts +275 -0
- package/dist/components/page.d.ts +275 -0
- package/dist/components/page.js +776 -0
- package/dist/components/page.js.map +1 -0
- package/dist/components/physics.cjs +2 -2
- package/dist/components/physics.d.cts +8 -0
- package/dist/components/physics.d.ts +8 -0
- package/dist/components/physics.js +4 -4
- package/dist/components/reveal.cjs +1 -1
- package/dist/components/reveal.d.cts +8 -0
- package/dist/components/reveal.d.ts +8 -0
- package/dist/components/reveal.js +2 -2
- package/dist/components/text.cjs +1 -1
- package/dist/components/text.d.cts +8 -0
- package/dist/components/text.d.ts +8 -0
- package/dist/components/text.js +2 -2
- package/dist/components/transitions.cjs +1 -1
- package/dist/components/transitions.d.cts +8 -0
- package/dist/components/transitions.d.ts +8 -0
- package/dist/components/transitions.js +2 -2
- package/dist/components/ui.cjs +1082 -0
- package/dist/components/ui.cjs.map +1 -0
- package/dist/components/ui.css +14 -0
- package/dist/components/ui.d.cts +259 -0
- package/dist/components/ui.d.ts +259 -0
- package/dist/components/ui.js +1064 -0
- package/dist/components/ui.js.map +1 -0
- package/dist/components.cjs +51 -4
- package/dist/components.cjs.map +1 -1
- package/dist/components.css +23 -2
- package/dist/components.d.cts +452 -2
- package/dist/components.d.ts +452 -2
- package/dist/components.js +14 -3
- package/dist/components.js.map +1 -1
- package/dist/components.umd.js +2 -2
- package/dist/components.umd.js.map +1 -1
- package/docs/components.md +37 -0
- package/package.json +24 -2
- package/dist/chunks/base-CJ7XfidP.cjs.map +0 -1
- package/dist/chunks/base-CuvCgqLy.js.map +0 -1
- package/dist/chunks/spring-BKUU7-Xm.js.map +0 -1
- package/dist/chunks/spring-CGO9Jd9b.cjs.map +0 -1
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* use-scroll-animate/components — shared base for the `<usa-*>` custom elements.
|
|
3
|
+
*
|
|
4
|
+
* Everything here is lazy: nothing touches `window`, `document`,
|
|
5
|
+
* `HTMLElement` or `matchMedia` at import time, so the components can be
|
|
6
|
+
* imported during SSR (Next, Nuxt, Astro…) and in Electron/Tauri preload
|
|
7
|
+
* scripts. Classes are created the first time a `define*()` function runs.
|
|
8
|
+
*/
|
|
9
|
+
interface ComponentsConfig {
|
|
10
|
+
/**
|
|
11
|
+
* Inject each component's CSS when it is defined (default `true`). Uses a
|
|
12
|
+
* constructable stylesheet (`document.adoptedStyleSheets`, which a strict
|
|
13
|
+
* `style-src` CSP does not block) and falls back to a `<style>` tag. Set
|
|
14
|
+
* to `false` when you load `use-scroll-animate/components.css` yourself.
|
|
15
|
+
*/
|
|
16
|
+
injectStyles?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* `'user'` (default) follows `prefers-reduced-motion`; `'reduce'` always
|
|
19
|
+
* uses the reduced variants (e.g. a kiosk / battery-saver mode);
|
|
20
|
+
* `'no-preference'` ignores the OS setting (only for demos — respect your users).
|
|
21
|
+
*/
|
|
22
|
+
reducedMotion?: 'user' | 'reduce' | 'no-preference';
|
|
23
|
+
/**
|
|
24
|
+
* Global motion intensity (v2.7): `'off'` (same as reduced motion),
|
|
25
|
+
* `'low'` (shorter, calmer), `'normal'` (default) or `'high'`. Scales every
|
|
26
|
+
* component animation's duration and sets `--usa-motion` (0 / 0.6 / 1 /
|
|
27
|
+
* 1.25) on `<html>` for your own CSS. See `setMotionIntensity()`.
|
|
28
|
+
*/
|
|
29
|
+
motionIntensity?: MotionIntensity;
|
|
30
|
+
}
|
|
31
|
+
type MotionIntensity = 'off' | 'low' | 'normal' | 'high';
|
|
32
|
+
declare const MOTION_SCALE: Record<MotionIntensity, number>;
|
|
33
|
+
/** Change global component settings (call before `define*()` for `injectStyles`). */
|
|
34
|
+
declare function configureComponents(options: ComponentsConfig): void;
|
|
35
|
+
/** The current global motion intensity. */
|
|
36
|
+
declare function getMotionIntensity(): MotionIntensity;
|
|
37
|
+
/** `true` when animations should be reduced (OS setting or `configureComponents`). */
|
|
38
|
+
declare function prefersReducedMotion(): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Members shared by every `<usa-*>` element. Attribute helpers, a cleanup
|
|
41
|
+
* bag that is emptied on disconnect, and motion helpers that degrade to the
|
|
42
|
+
* final state without WAAPI or under reduced motion.
|
|
43
|
+
*/
|
|
44
|
+
interface UsaElement extends HTMLElement {
|
|
45
|
+
/** `true` while reduced motion applies to this element. */
|
|
46
|
+
readonly reduced: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
declare const CURSOR_MODES: readonly ["dot", "trail", "magnetic", "glow"];
|
|
50
|
+
type CursorMode = (typeof CURSOR_MODES)[number];
|
|
51
|
+
/**
|
|
52
|
+
* `<usa-cursor mode="dot | trail | magnetic | glow">` — a custom cursor for
|
|
53
|
+
* the page (place it once, e.g. at the end of `<body>`).
|
|
54
|
+
* - `dot` — a ring that follows with spring lag around the real pointer;
|
|
55
|
+
* - `trail` — a comet tail of dots;
|
|
56
|
+
* - `magnetic` — the ring snaps onto and wraps hovered targets (`a`,
|
|
57
|
+
* `button`, `[data-cursor]`);
|
|
58
|
+
* - `glow` — a large soft light following the pointer (great on dark UIs).
|
|
59
|
+
* Attributes: `mode`, `color`, `size` (px, 28), `hide-native` (hide the
|
|
60
|
+
* system cursor), `targets` (selector, magnetic). Only for fine pointers
|
|
61
|
+
* (mouse / pen); never on touch. Reduced motion: not rendered.
|
|
62
|
+
*/
|
|
63
|
+
interface UsaCursorElement extends UsaElement {
|
|
64
|
+
readonly active: boolean;
|
|
65
|
+
}
|
|
66
|
+
declare function defineCursor(tag?: string): CustomElementConstructor | undefined;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* `<usa-fullpage>` — full-screen sections (its element children) that snap
|
|
70
|
+
* one at a time (CSS scroll snap), with keyboard paging (PageUp/PageDown,
|
|
71
|
+
* arrows, Home/End), optional dot navigation and the current section in
|
|
72
|
+
* `aria-current` + `usa:section`.
|
|
73
|
+
* Attributes: `dots` (show the dot nav), `axis` (`y` default, `x`).
|
|
74
|
+
* Methods: `go(i)`, `next()`, `prev()`. Reduced motion: snapping stays,
|
|
75
|
+
* jumps are instant.
|
|
76
|
+
*/
|
|
77
|
+
interface UsaFullpageElement extends UsaElement {
|
|
78
|
+
readonly index: number;
|
|
79
|
+
go(i: number): void;
|
|
80
|
+
next(): void;
|
|
81
|
+
prev(): void;
|
|
82
|
+
}
|
|
83
|
+
declare function defineFullpage(tag?: string): CustomElementConstructor | undefined;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* `<usa-loading-bar>` — a slim top loading bar for route changes and fetches
|
|
87
|
+
* (NProgress-style): `start()` trickles towards 90 %, `done()` completes and
|
|
88
|
+
* fades out, `set(0–1)` for real progress. `loadingBar` drives the first bar
|
|
89
|
+
* on the page (created on demand). `role="progressbar"`, `aria-busy`.
|
|
90
|
+
* Attributes: `color`, `height` (px, 3), `position` (`top` default, `bottom`).
|
|
91
|
+
* Reduced motion: no trickle animation — the bar shows / hides.
|
|
92
|
+
*/
|
|
93
|
+
interface UsaLoadingBarElement extends UsaElement {
|
|
94
|
+
readonly progress: number;
|
|
95
|
+
start(): void;
|
|
96
|
+
set(p: number): void;
|
|
97
|
+
done(): void;
|
|
98
|
+
}
|
|
99
|
+
declare function defineLoadingBar(tag?: string): CustomElementConstructor | undefined;
|
|
100
|
+
/** Drive the page's `<usa-loading-bar>` (created on first use). */
|
|
101
|
+
declare const loadingBar: {
|
|
102
|
+
start: () => void;
|
|
103
|
+
set: (p: number) => void;
|
|
104
|
+
done: () => void;
|
|
105
|
+
/** Run `task` with the bar shown; resolves with its result. */
|
|
106
|
+
track<T>(task: Promise<T> | (() => Promise<T>)): Promise<T>;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* `<usa-back-to-top>` — a floating button that appears after `offset` px
|
|
111
|
+
* (300) of scrolling, shows page progress as a ring and springs the page
|
|
112
|
+
* back to the top (then focuses `focus-target`, default `#main` / `body`).
|
|
113
|
+
* Attributes: `offset`, `label` ("Back to top"), `focus-target`, `position`
|
|
114
|
+
* (`bottom-right` default, `bottom-left`). Reduced motion: instant jump.
|
|
115
|
+
*/
|
|
116
|
+
interface UsaBackToTopElement extends UsaElement {
|
|
117
|
+
readonly visible: boolean;
|
|
118
|
+
}
|
|
119
|
+
declare function defineBackToTop(tag?: string): CustomElementConstructor | undefined;
|
|
120
|
+
|
|
121
|
+
declare const AMBIENT_EFFECTS: readonly ["particles", "snow", "stars", "noise", "gradient"];
|
|
122
|
+
type AmbientEffect = (typeof AMBIENT_EFFECTS)[number];
|
|
123
|
+
/**
|
|
124
|
+
* `<usa-ambient effect="particles | snow | stars | noise | gradient">` — a
|
|
125
|
+
* fixed, page-wide ambient layer behind (or, with `layer="front"`, over)
|
|
126
|
+
* the content, never catching the pointer.
|
|
127
|
+
* - `particles` — slow drifting dots; `snow` — falling flakes with sway;
|
|
128
|
+
* `stars` — twinkling starfield (canvas, paused in hidden tabs, DPR ≤ 2);
|
|
129
|
+
* - `noise` — animated film grain (CSS, SVG turbulence);
|
|
130
|
+
* - `gradient` — a gradient whose hue shifts with the scroll position.
|
|
131
|
+
* Attributes: `effect`, `density` (0.2–3, 1), `color`, `opacity` (0.6),
|
|
132
|
+
* `layer` (`back` default, `front`), `speed` (1). Reduced motion: one
|
|
133
|
+
* static frame (no falling, twinkling or grain flicker).
|
|
134
|
+
*/
|
|
135
|
+
interface UsaAmbientElement extends UsaElement {
|
|
136
|
+
}
|
|
137
|
+
declare function defineAmbient(tag?: string): CustomElementConstructor | undefined;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* `<usa-splash>` — an app splash / launch screen: shows its content (logo,
|
|
141
|
+
* spinner) over the page, then leaves with `exit` (`fade` default, `scale`,
|
|
142
|
+
* `slide-up`, `circle`) once the page has loaded (or when you call
|
|
143
|
+
* `done()`), but never sooner than `min` ms (600) — no flash.
|
|
144
|
+
* Attributes: `min`, `exit`, `manual` (wait for `done()`), `label`.
|
|
145
|
+
* Events: `usa:done`. The page underneath is `aria-busy` until then.
|
|
146
|
+
* Reduced motion: fades.
|
|
147
|
+
*/
|
|
148
|
+
interface UsaSplashElement extends UsaElement {
|
|
149
|
+
done(): Promise<void>;
|
|
150
|
+
}
|
|
151
|
+
declare function defineSplash(tag?: string): CustomElementConstructor | undefined;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* `<usa-auto-skeleton loading>` — automatic skeletons: while `loading` is
|
|
155
|
+
* set, every text block, image, button and input inside is drawn as a
|
|
156
|
+
* shimmering placeholder of its own size — no separate skeleton markup.
|
|
157
|
+
* Remove `loading` (or set `.loading = false`) and the content fades in.
|
|
158
|
+
* `aria-busy` while loading. Opt elements out with `data-no-skeleton`.
|
|
159
|
+
* Reduced motion: static placeholders, no shimmer or fade.
|
|
160
|
+
*/
|
|
161
|
+
interface UsaAutoSkeletonElement extends UsaElement {
|
|
162
|
+
loading: boolean;
|
|
163
|
+
}
|
|
164
|
+
declare function defineAutoSkeleton(tag?: string): CustomElementConstructor | undefined;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Set the global motion intensity for every `<usa-*>` component:
|
|
168
|
+
* `'off'` (like reduced motion), `'low'`, `'normal'` (default), `'high'`.
|
|
169
|
+
* Sets `--usa-motion` and `data-usa-motion` on `<html>`; with `persist`
|
|
170
|
+
* the choice is remembered (localStorage) and restored by `restoreMotionIntensity()`.
|
|
171
|
+
*/
|
|
172
|
+
declare function setMotionIntensity(level: MotionIntensity, persist?: boolean): void;
|
|
173
|
+
/** Re-apply a persisted intensity (call early on page load). Returns it. */
|
|
174
|
+
declare function restoreMotionIntensity(): MotionIntensity;
|
|
175
|
+
/**
|
|
176
|
+
* `<usa-motion-switch>` — a segmented control letting users choose the
|
|
177
|
+
* app's motion intensity (Off · Low · Normal · High), persisted.
|
|
178
|
+
* `role="radiogroup"`; arrow keys move. Attributes: `labels` (comma list),
|
|
179
|
+
* `label` ("Motion"). Events: `usa:change` (`{ level }`).
|
|
180
|
+
*/
|
|
181
|
+
interface UsaMotionSwitchElement extends UsaElement {
|
|
182
|
+
value: MotionIntensity;
|
|
183
|
+
}
|
|
184
|
+
declare function defineMotionSwitch(tag?: string): CustomElementConstructor | undefined;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Page & app-wide transitions (v2.7), built on the View Transitions API
|
|
188
|
+
* (Chromium: Chrome, Edge, Electron, WebView2) with graceful fallbacks.
|
|
189
|
+
*
|
|
190
|
+
* - `pageTransition(update, { effect })` — SPA route changes: `fade`,
|
|
191
|
+
* `slide` (`slide-left` / `slide-right` / `slide-up`), `circle` (reveal
|
|
192
|
+
* from `x`, `y`), `blinds`, `pixel` (stepped dissolve), `zoom`.
|
|
193
|
+
* - `enableMpaTransitions(effect)` — the same effects for multi-page sites
|
|
194
|
+
* (`@view-transition { navigation: auto }`); call it on every page.
|
|
195
|
+
* - `themeTransition(apply, { x, y })` — a circle-reveal theme switch.
|
|
196
|
+
*
|
|
197
|
+
* Without View Transitions (Firefox, older Safari) or under reduced motion
|
|
198
|
+
* the update runs immediately (`fade` falls back to a short cross-fade of
|
|
199
|
+
* `fallback` when given).
|
|
200
|
+
*/
|
|
201
|
+
declare const PAGE_EFFECTS: readonly ["fade", "slide", "slide-left", "slide-right", "slide-up", "circle", "blinds", "pixel", "zoom"];
|
|
202
|
+
type PageEffect = (typeof PAGE_EFFECTS)[number];
|
|
203
|
+
interface PageTransitionOptions {
|
|
204
|
+
effect?: PageEffect;
|
|
205
|
+
/** Circle origin in client px (default: viewport centre / last pointer). */
|
|
206
|
+
x?: number;
|
|
207
|
+
y?: number;
|
|
208
|
+
/** Duration in ms (default 600). */
|
|
209
|
+
duration?: number;
|
|
210
|
+
/** Element to cross-fade when View Transitions are unavailable. */
|
|
211
|
+
fallback?: Element | null;
|
|
212
|
+
}
|
|
213
|
+
/** `true` when `document.startViewTransition` exists. */
|
|
214
|
+
declare const supportsViewTransitions: () => boolean;
|
|
215
|
+
/** Run `update` (sync or async) as an animated page transition. Resolves when it is done. */
|
|
216
|
+
declare function pageTransition(update: () => unknown, options?: PageTransitionOptions): Promise<void>;
|
|
217
|
+
/** Opt a multi-page site into cross-document view transitions with `effect`. */
|
|
218
|
+
declare function enableMpaTransitions(effect?: PageEffect, duration?: number): void;
|
|
219
|
+
/**
|
|
220
|
+
* Switch theme with a circle reveal from (`x`, `y`) (default: last pointer).
|
|
221
|
+
* `apply` flips your theme (e.g. toggles a class / `data-theme`).
|
|
222
|
+
*/
|
|
223
|
+
declare function themeTransition(apply: () => unknown, options?: Omit<PageTransitionOptions, 'effect'>): Promise<void>;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* `smoothScroll()` — inertial wheel smoothing for the page (or a scroll
|
|
227
|
+
* container): wheel deltas are eased with a lerp each frame. Touch and
|
|
228
|
+
* keyboard scrolling stay native. Returns a function that turns it off.
|
|
229
|
+
* No-op under reduced motion, on touch-only devices and on the server.
|
|
230
|
+
*/
|
|
231
|
+
interface SmoothScrollOptions {
|
|
232
|
+
/** Scroll container (default: the page). */
|
|
233
|
+
target?: HTMLElement | null;
|
|
234
|
+
/** 0–1, lower = smoother / longer glide (default 0.12). */
|
|
235
|
+
lerp?: number;
|
|
236
|
+
/** Wheel multiplier (default 1). */
|
|
237
|
+
wheelMultiplier?: number;
|
|
238
|
+
}
|
|
239
|
+
declare function smoothScroll(options?: SmoothScrollOptions): () => void;
|
|
240
|
+
/**
|
|
241
|
+
* Scroll to a y position, element or selector with spring timing (or
|
|
242
|
+
* instantly under reduced motion). Resolves when done.
|
|
243
|
+
*/
|
|
244
|
+
declare function scrollToTarget(to: number | Element | string, options?: {
|
|
245
|
+
offset?: number;
|
|
246
|
+
target?: HTMLElement | null;
|
|
247
|
+
preset?: string;
|
|
248
|
+
}): Promise<void>;
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* use-scroll-animate/components/page — page & app-wide effects (v2.7).
|
|
252
|
+
* Page transitions (`pageTransition()`, `enableMpaTransitions()`,
|
|
253
|
+
* `themeTransition()`), `<usa-cursor>`, `smoothScroll()` / `scrollToTarget()`,
|
|
254
|
+
* `<usa-fullpage>`, `<usa-loading-bar>` + `loadingBar`, `<usa-back-to-top>`,
|
|
255
|
+
* `<usa-ambient>`, `<usa-splash>`, `<usa-auto-skeleton>` and the global motion
|
|
256
|
+
* intensity (`setMotionIntensity()`, `<usa-motion-switch>`).
|
|
257
|
+
*/
|
|
258
|
+
|
|
259
|
+
/** Register every component of this category under its default tag. */
|
|
260
|
+
declare function definePageComponents(): void;
|
|
261
|
+
declare global {
|
|
262
|
+
interface HTMLElementTagNameMap {
|
|
263
|
+
'usa-cursor': UsaCursorElement;
|
|
264
|
+
'usa-fullpage': UsaFullpageElement;
|
|
265
|
+
'usa-loading-bar': UsaLoadingBarElement;
|
|
266
|
+
'usa-back-to-top': UsaBackToTopElement;
|
|
267
|
+
'usa-ambient': UsaAmbientElement;
|
|
268
|
+
'usa-splash': UsaSplashElement;
|
|
269
|
+
'usa-auto-skeleton': UsaAutoSkeletonElement;
|
|
270
|
+
'usa-motion-switch': UsaMotionSwitchElement;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export { AMBIENT_EFFECTS, CURSOR_MODES, MOTION_SCALE, PAGE_EFFECTS, configureComponents, defineAmbient, defineAutoSkeleton, defineBackToTop, defineCursor, defineFullpage, defineLoadingBar, defineMotionSwitch, definePageComponents, defineSplash, enableMpaTransitions, getMotionIntensity, loadingBar, pageTransition, prefersReducedMotion, restoreMotionIntensity, scrollToTarget, setMotionIntensity, smoothScroll, supportsViewTransitions, themeTransition };
|
|
275
|
+
export type { AmbientEffect, ComponentsConfig, CursorMode, MotionIntensity, PageEffect, PageTransitionOptions, SmoothScrollOptions, UsaAmbientElement, UsaAutoSkeletonElement, UsaBackToTopElement, UsaCursorElement, UsaElement, UsaFullpageElement, UsaLoadingBarElement, UsaMotionSwitchElement, UsaSplashElement };
|