use-scroll-animate 2.5.0 → 2.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.
- package/CHANGELOG.md +20 -0
- package/README.md +1 -0
- package/README_ja.md +1 -0
- package/README_zh.md +1 -0
- package/dist/chunks/{base-CuvCgqLy.js → base-08OYzphB.js} +2 -2
- package/dist/chunks/{base-CuvCgqLy.js.map → base-08OYzphB.js.map} +1 -1
- package/dist/chunks/{base-CJ7XfidP.cjs → base-5DFCAnvH.cjs} +3 -1
- package/dist/chunks/{base-CJ7XfidP.cjs.map → base-5DFCAnvH.cjs.map} +1 -1
- package/dist/chunks/{spring-CGO9Jd9b.cjs → spring-Bi4qY0pL.cjs} +2 -2
- package/dist/chunks/{spring-CGO9Jd9b.cjs.map → spring-Bi4qY0pL.cjs.map} +1 -1
- package/dist/chunks/{spring-BKUU7-Xm.js → spring-CpeFkxNd.js} +2 -2
- package/dist/chunks/{spring-BKUU7-Xm.js.map → spring-CpeFkxNd.js.map} +1 -1
- package/dist/components/background.cjs +1 -1
- package/dist/components/background.js +2 -2
- package/dist/components/cards.cjs +2 -2
- package/dist/components/cards.js +3 -3
- package/dist/components/click.cjs +2 -2
- 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.js +3 -3
- package/dist/components/interaction.cjs +2 -2
- package/dist/components/interaction.css +1 -1
- package/dist/components/interaction.js +3 -3
- package/dist/components/physics.cjs +2 -2
- package/dist/components/physics.js +4 -4
- package/dist/components/reveal.cjs +1 -1
- package/dist/components/reveal.js +2 -2
- package/dist/components/text.cjs +1 -1
- package/dist/components/text.js +2 -2
- package/dist/components/transitions.cjs +1 -1
- 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 +251 -0
- package/dist/components/ui.d.ts +251 -0
- package/dist/components/ui.js +1064 -0
- package/dist/components/ui.js.map +1 -0
- package/dist/components.cjs +25 -4
- package/dist/components.cjs.map +1 -1
- package/dist/components.css +14 -2
- package/dist/components.d.cts +215 -2
- package/dist/components.d.ts +215 -2
- package/dist/components.js +10 -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 +20 -0
- package/package.json +13 -2
|
@@ -0,0 +1,251 @@
|
|
|
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
|
+
/** Change global component settings (call before `define*()` for `injectStyles`). */
|
|
25
|
+
declare function configureComponents(options: ComponentsConfig): void;
|
|
26
|
+
/** `true` when animations should be reduced (OS setting or `configureComponents`). */
|
|
27
|
+
declare function prefersReducedMotion(): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Members shared by every `<usa-*>` element. Attribute helpers, a cleanup
|
|
30
|
+
* bag that is emptied on disconnect, and motion helpers that degrade to the
|
|
31
|
+
* final state without WAAPI or under reduced motion.
|
|
32
|
+
*/
|
|
33
|
+
interface UsaElement extends HTMLElement {
|
|
34
|
+
/** `true` while reduced motion applies to this element. */
|
|
35
|
+
readonly reduced: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* `<usa-tabs>` — accessible tabs with a sliding (spring) indicator.
|
|
40
|
+
* Tabs: `[data-tab]` children (buttons); panels: `[data-panel]` children, in
|
|
41
|
+
* the same order. Arrow keys / Home / End move between tabs (roving tabindex).
|
|
42
|
+
*
|
|
43
|
+
* Attributes: `selected` (index, 0), `indicator` (`line` default, `pill`),
|
|
44
|
+
* `variant`. Events: `usa:change` (`{ index }`). Panels fade/slide in;
|
|
45
|
+
* reduced motion: the indicator jumps and panels switch instantly.
|
|
46
|
+
*/
|
|
47
|
+
interface UsaTabsElement extends UsaElement {
|
|
48
|
+
selected: number;
|
|
49
|
+
select(i: number, focus?: boolean): void;
|
|
50
|
+
}
|
|
51
|
+
declare function defineTabs(tag?: string): CustomElementConstructor | undefined;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* `<usa-drawer>` — a side panel that slides in with a spring and can be
|
|
55
|
+
* dragged / swiped closed. Modal: backdrop, Esc, focus returns on close.
|
|
56
|
+
* Attributes: `open`, `side` (`left` default, `right`, `top`, `bottom`),
|
|
57
|
+
* `label`, `variant`. Events: `usa:open`, `usa:close`. `[data-close]` closes.
|
|
58
|
+
* Reduced motion: opens and closes instantly.
|
|
59
|
+
*/
|
|
60
|
+
interface UsaDrawerElement extends UsaElement {
|
|
61
|
+
open: boolean;
|
|
62
|
+
show(): void;
|
|
63
|
+
close(): void;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* `<usa-bottom-sheet>` — a draggable bottom sheet with snap points
|
|
67
|
+
* (`snap="0.3,0.6,0.92"`, fractions of the viewport height; default
|
|
68
|
+
* `0.5,0.92`; `start` = index of the snap it opens at, default 0), inertia and drag-down-to-dismiss. `[data-handle]` (or the
|
|
69
|
+
* built-in grabber) drags it. Attributes: `open`, `snap`, `start` (initial
|
|
70
|
+
* snap index), `label`, `variant`. Events: `usa:open`, `usa:close`, `usa:snap`.
|
|
71
|
+
*/
|
|
72
|
+
interface UsaBottomSheetElement extends UsaDrawerElement {
|
|
73
|
+
}
|
|
74
|
+
declare function defineDrawer(tag?: string): CustomElementConstructor | undefined;
|
|
75
|
+
declare function defineBottomSheet(tag?: string): CustomElementConstructor | undefined;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* `<usa-pull-refresh>` — pull-to-refresh for a scroll container (itself):
|
|
79
|
+
* pull down at the top (touch / pointer) and a spinner stretches in; past
|
|
80
|
+
* `threshold` (px, 70) releasing fires `usa:refresh` — call
|
|
81
|
+
* `event.detail.done()` (or return a promise to `onrefresh`) to finish.
|
|
82
|
+
* Also exposes `refresh()` for a keyboard / button path.
|
|
83
|
+
* Attributes: `threshold`, `disabled`, `label` (status text, "Refreshing").
|
|
84
|
+
* Reduced motion: no stretch; the spinner simply appears while refreshing.
|
|
85
|
+
*/
|
|
86
|
+
interface UsaPullRefreshElement extends UsaElement {
|
|
87
|
+
readonly refreshing: boolean;
|
|
88
|
+
refresh(): Promise<void>;
|
|
89
|
+
}
|
|
90
|
+
declare function definePullRefresh(tag?: string): CustomElementConstructor | undefined;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* `<usa-fab>` — floating action button with a speed dial. The first element
|
|
94
|
+
* child is the main button; the others are actions that fan out with a
|
|
95
|
+
* staggered spring when it opens (`direction="up"` default, `down`, `left`,
|
|
96
|
+
* `right`, `radial`). Esc / outside click closes; `aria-expanded` on the
|
|
97
|
+
* main button; actions are hidden from AT while closed.
|
|
98
|
+
* Attributes: `open`, `direction`, `position` (`bottom-right` default, `bottom-left`,
|
|
99
|
+
* `inline`), `gap` (px, 56), `variant`. Events: `usa:toggle` (`{ open }`).
|
|
100
|
+
* Reduced motion: actions appear without travel.
|
|
101
|
+
*/
|
|
102
|
+
interface UsaFabElement extends UsaElement {
|
|
103
|
+
open: boolean;
|
|
104
|
+
toggle(force?: boolean): void;
|
|
105
|
+
}
|
|
106
|
+
declare function defineFab(tag?: string): CustomElementConstructor | undefined;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* `<usa-navbar>` — an app bar that hides while you scroll down and returns
|
|
110
|
+
* as soon as you scroll up (or reach the top); `shrink` makes it compact
|
|
111
|
+
* once scrolled. Focus inside always reveals it.
|
|
112
|
+
* Attributes: `threshold` (px of scroll before hiding, 64), `shrink`,
|
|
113
|
+
* `target` (selector of a scroll container instead of the page), `variant`.
|
|
114
|
+
* State attributes: `data-hidden`, `data-scrolled`. Events: `usa:hide`, `usa:show`.
|
|
115
|
+
* Reduced motion: hides/shows without sliding (instant).
|
|
116
|
+
*/
|
|
117
|
+
interface UsaNavbarElement extends UsaElement {
|
|
118
|
+
readonly hiddenByScroll: boolean;
|
|
119
|
+
show(): void;
|
|
120
|
+
}
|
|
121
|
+
declare function defineNavbar(tag?: string): CustomElementConstructor | undefined;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* `<usa-slider>` — a form-associated range slider (`role="slider"`). The
|
|
125
|
+
* thumb follows with a spring, grows while dragged and shows a value bubble.
|
|
126
|
+
* Keyboard: arrows (step), PageUp/PageDown (10 steps), Home/End.
|
|
127
|
+
* Attributes: `value`, `min` (0), `max` (100), `step` (1), `name`, `label`,
|
|
128
|
+
* `bubble` (show the value while dragging), `disabled`, `variant`.
|
|
129
|
+
* Events: `input` + `usa:input` while moving, `change` + `usa:change` on release.
|
|
130
|
+
* Reduced motion: the thumb jumps (no spring).
|
|
131
|
+
*/
|
|
132
|
+
interface UsaSliderElement extends UsaElement {
|
|
133
|
+
value: number;
|
|
134
|
+
}
|
|
135
|
+
declare function defineSlider(tag?: string): CustomElementConstructor | undefined;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* `<usa-rating>` — star rating with hover preview and a springy pop when a
|
|
139
|
+
* value is chosen. `role="slider"` (arrow keys, Home/End, number keys).
|
|
140
|
+
* Attributes: `value` (0), `max` (5), `icon` (★), `readonly`, `label`
|
|
141
|
+
* ("Rating"), `name` (form value), `variant`. Events: `change`, `usa:change` (`{ value }`).
|
|
142
|
+
* Reduced motion: no pop.
|
|
143
|
+
*/
|
|
144
|
+
interface UsaRatingElement extends UsaElement {
|
|
145
|
+
value: number;
|
|
146
|
+
}
|
|
147
|
+
declare function defineRating(tag?: string): CustomElementConstructor | undefined;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* `<usa-tooltip text="…">` — a tooltip for the element it wraps, shown on
|
|
151
|
+
* hover (after `delay` ms, 300) and on keyboard focus, hidden on Esc / blur.
|
|
152
|
+
* It springs in from its placement side and flips to stay on screen; the
|
|
153
|
+
* trigger gets `aria-describedby`.
|
|
154
|
+
* Attributes: `text`, `placement` (`top` default, `bottom`, `left`, `right`),
|
|
155
|
+
* `delay`, `variant`. Reduced motion: fades only.
|
|
156
|
+
*/
|
|
157
|
+
interface UsaTooltipElement extends UsaElement {
|
|
158
|
+
show(): void;
|
|
159
|
+
hide(): void;
|
|
160
|
+
}
|
|
161
|
+
declare function defineTooltip(tag?: string): CustomElementConstructor | undefined;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* `<usa-popover>` — a click-to-open popover: the first element child is the
|
|
165
|
+
* trigger, `[data-popover]` is the content. Springs open from the trigger,
|
|
166
|
+
* flips to stay on screen; Esc or an outside click closes and focus returns
|
|
167
|
+
* to the trigger. `aria-expanded` / `aria-controls` on the trigger.
|
|
168
|
+
* Attributes: `open`, `placement` (`bottom` default), `variant`. Events:
|
|
169
|
+
* `usa:open`, `usa:close`. Reduced motion: fades only.
|
|
170
|
+
*/
|
|
171
|
+
interface UsaPopoverElement extends UsaElement {
|
|
172
|
+
open: boolean;
|
|
173
|
+
toggle(force?: boolean): void;
|
|
174
|
+
}
|
|
175
|
+
declare function definePopover(tag?: string): CustomElementConstructor | undefined;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* `<usa-badge>` — a count / dot badge on whatever it wraps; bumps with a
|
|
179
|
+
* spring whenever the value changes and pulses with `pulse`.
|
|
180
|
+
* Attributes: `value` (number or text; 0 / empty hides it unless
|
|
181
|
+
* `show-zero`), `max` (99 → "99+"), `dot`, `pulse`, `label` (accessible
|
|
182
|
+
* text, default "{n} new"), `variant`. Reduced motion: no bump or pulse.
|
|
183
|
+
*/
|
|
184
|
+
interface UsaBadgeElement extends UsaElement {
|
|
185
|
+
value: string;
|
|
186
|
+
}
|
|
187
|
+
declare function defineBadge(tag?: string): CustomElementConstructor | undefined;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* `<usa-avatar-stack>` — overlapping avatars (its children: `<img>` or any
|
|
191
|
+
* element) that spread apart with a spring on hover / focus; extra ones
|
|
192
|
+
* collapse into a "+N" chip.
|
|
193
|
+
* Attributes: `max` (visible avatars, 5), `size` (px, 36), `overlap` (0–1,
|
|
194
|
+
* 0.35), `label` (group name), `variant`. Reduced motion: no spreading.
|
|
195
|
+
*/
|
|
196
|
+
interface UsaAvatarStackElement extends UsaElement {
|
|
197
|
+
}
|
|
198
|
+
declare function defineAvatarStack(tag?: string): CustomElementConstructor | undefined;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Style variants (v2.6): `variant="minimal | neon | glass | brutalist |
|
|
202
|
+
* fluent | material"` on any `<usa-*>` element — or on any ancestor as
|
|
203
|
+
* `data-usa-variant`, or page-wide with `setVariant()` — sets the shared
|
|
204
|
+
* design tokens every component reads:
|
|
205
|
+
*
|
|
206
|
+
* `--usa-accent`, `--usa-accent-text`, `--usa-surface`, `--usa-text`,
|
|
207
|
+
* `--usa-radius`, `--usa-border`, `--usa-shadow`, `--usa-blur`, `--usa-font`.
|
|
208
|
+
*
|
|
209
|
+
* (`<usa-spinner>`, `<usa-check>` and `<usa-dialog>` already use `variant`
|
|
210
|
+
* for their kind; the token names never clash with those values except
|
|
211
|
+
* `fluent`, which means the same thing there.)
|
|
212
|
+
*/
|
|
213
|
+
declare const VARIANTS: readonly ["minimal", "neon", "glass", "brutalist", "fluent", "material"];
|
|
214
|
+
type Variant = (typeof VARIANTS)[number];
|
|
215
|
+
/** Inject the variant token sheet (done automatically by every `ui` component). */
|
|
216
|
+
declare function adoptVariants(): void;
|
|
217
|
+
/** Apply a variant to the whole page (or `root`); `null` removes it. */
|
|
218
|
+
declare function setVariant(variant: Variant | null, root?: Element | null): void;
|
|
219
|
+
|
|
220
|
+
type Placement = 'top' | 'bottom' | 'left' | 'right';
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* use-scroll-animate/components/ui — animated UI components + style variants (v2.6).
|
|
224
|
+
* `<usa-tabs>`, `<usa-drawer>`, `<usa-bottom-sheet>`, `<usa-pull-refresh>`,
|
|
225
|
+
* `<usa-fab>`, `<usa-navbar>`, `<usa-slider>`, `<usa-rating>`,
|
|
226
|
+
* `<usa-tooltip>`, `<usa-popover>`, `<usa-badge>`, `<usa-avatar-stack>`,
|
|
227
|
+
* and `variant="minimal | neon | glass | brutalist | fluent | material"`
|
|
228
|
+
* design tokens (`setVariant()`, `VARIANTS`).
|
|
229
|
+
*/
|
|
230
|
+
|
|
231
|
+
/** Register every component of this category under its default tag. */
|
|
232
|
+
declare function defineUiComponents(): void;
|
|
233
|
+
declare global {
|
|
234
|
+
interface HTMLElementTagNameMap {
|
|
235
|
+
'usa-tabs': UsaTabsElement;
|
|
236
|
+
'usa-drawer': UsaDrawerElement;
|
|
237
|
+
'usa-bottom-sheet': UsaBottomSheetElement;
|
|
238
|
+
'usa-pull-refresh': UsaPullRefreshElement;
|
|
239
|
+
'usa-fab': UsaFabElement;
|
|
240
|
+
'usa-navbar': UsaNavbarElement;
|
|
241
|
+
'usa-slider': UsaSliderElement;
|
|
242
|
+
'usa-rating': UsaRatingElement;
|
|
243
|
+
'usa-tooltip': UsaTooltipElement;
|
|
244
|
+
'usa-popover': UsaPopoverElement;
|
|
245
|
+
'usa-badge': UsaBadgeElement;
|
|
246
|
+
'usa-avatar-stack': UsaAvatarStackElement;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export { VARIANTS, adoptVariants, configureComponents, defineAvatarStack, defineBadge, defineBottomSheet, defineDrawer, defineFab, defineNavbar, definePopover, definePullRefresh, defineRating, defineSlider, defineTabs, defineTooltip, defineUiComponents, prefersReducedMotion, setVariant };
|
|
251
|
+
export type { ComponentsConfig, Placement, UsaAvatarStackElement, UsaBadgeElement, UsaBottomSheetElement, UsaDrawerElement, UsaElement, UsaFabElement, UsaNavbarElement, UsaPopoverElement, UsaPullRefreshElement, UsaRatingElement, UsaSliderElement, UsaTabsElement, UsaTooltipElement, Variant };
|