use-scroll-animate 2.4.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +2 -0
  3. package/README_ja.md +2 -0
  4. package/README_zh.md +2 -0
  5. package/dist/chunks/{base-CuvCgqLy.js → base-08OYzphB.js} +2 -2
  6. package/dist/chunks/{base-CuvCgqLy.js.map → base-08OYzphB.js.map} +1 -1
  7. package/dist/chunks/{base-CJ7XfidP.cjs → base-5DFCAnvH.cjs} +3 -1
  8. package/dist/chunks/{base-CJ7XfidP.cjs.map → base-5DFCAnvH.cjs.map} +1 -1
  9. package/dist/chunks/{spring-CGO9Jd9b.cjs → spring-Bi4qY0pL.cjs} +2 -2
  10. package/dist/chunks/{spring-CGO9Jd9b.cjs.map → spring-Bi4qY0pL.cjs.map} +1 -1
  11. package/dist/chunks/{spring-BKUU7-Xm.js → spring-CpeFkxNd.js} +2 -2
  12. package/dist/chunks/{spring-BKUU7-Xm.js.map → spring-CpeFkxNd.js.map} +1 -1
  13. package/dist/components/background.cjs +1 -1
  14. package/dist/components/background.js +2 -2
  15. package/dist/components/cards.cjs +2 -2
  16. package/dist/components/cards.js +3 -3
  17. package/dist/components/click.cjs +985 -0
  18. package/dist/components/click.cjs.map +1 -0
  19. package/dist/components/click.css +9 -0
  20. package/dist/components/click.d.cts +250 -0
  21. package/dist/components/click.d.ts +250 -0
  22. package/dist/components/click.js +967 -0
  23. package/dist/components/click.js.map +1 -0
  24. package/dist/components/feedback.cjs +2 -2
  25. package/dist/components/feedback.css +1 -1
  26. package/dist/components/feedback.js +3 -3
  27. package/dist/components/interaction.cjs +2 -2
  28. package/dist/components/interaction.css +1 -1
  29. package/dist/components/interaction.js +3 -3
  30. package/dist/components/physics.cjs +2 -2
  31. package/dist/components/physics.js +4 -4
  32. package/dist/components/reveal.cjs +1 -1
  33. package/dist/components/reveal.js +2 -2
  34. package/dist/components/text.cjs +1 -1
  35. package/dist/components/text.js +2 -2
  36. package/dist/components/transitions.cjs +1 -1
  37. package/dist/components/transitions.js +2 -2
  38. package/dist/components/ui.cjs +1082 -0
  39. package/dist/components/ui.cjs.map +1 -0
  40. package/dist/components/ui.css +14 -0
  41. package/dist/components/ui.d.cts +251 -0
  42. package/dist/components/ui.d.ts +251 -0
  43. package/dist/components/ui.js +1064 -0
  44. package/dist/components/ui.js.map +1 -0
  45. package/dist/components.cjs +44 -4
  46. package/dist/components.cjs.map +1 -1
  47. package/dist/components.css +21 -2
  48. package/dist/components.d.cts +427 -2
  49. package/dist/components.d.ts +427 -2
  50. package/dist/components.js +14 -3
  51. package/dist/components.js.map +1 -1
  52. package/dist/components.umd.js +2 -2
  53. package/dist/components.umd.js.map +1 -1
  54. package/docs/components.md +33 -0
  55. package/package.json +24 -2
@@ -0,0 +1,250 @@
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
+ declare const CLICK_EFFECTS: readonly ["ripple", "burst", "confetti", "squish", "press-spring", "shake"];
39
+ type ClickEffect = (typeof CLICK_EFFECTS)[number];
40
+ /**
41
+ * `<usa-click>` — click / tap effects on whatever it wraps (combinable:
42
+ * `effect="press-spring burst"`).
43
+ *
44
+ * - `ripple` — an ink wave from the pointer (enhanced: `color`, soft edge);
45
+ * - `burst` — particles radiating from the pointer (`shape`: circle, square, star, heart, emoji);
46
+ * - `confetti` — a confetti cannon from the click point;
47
+ * - `squish` — squash on press, stretch on release (spring);
48
+ * - `press-spring` — dips while pressed, springs back with overshoot;
49
+ * - `shake` — horizontal error shake; plays on `invalid` events from a form
50
+ * inside, on `shake()`, or on click when `trigger="click"`.
51
+ *
52
+ * Attributes: `effect`, `color`, `shape`, `count`, `haptic` (vibrate ms,
53
+ * where supported), `disabled`. Keyboard (Space/Enter) triggers the effects
54
+ * from the centre. Reduced motion: no particles or movement; press dims.
55
+ */
56
+ interface UsaClickElement extends UsaElement {
57
+ readonly effects: string[];
58
+ play(x?: number, y?: number): void;
59
+ shake(): void;
60
+ }
61
+ declare function defineClick(tag?: string): CustomElementConstructor | undefined;
62
+
63
+ declare const BUTTON_DEFORMS: readonly ["squash", "wobble", "gooey", "dent"];
64
+ type ButtonDeform = (typeof BUTTON_DEFORMS)[number];
65
+ type ButtonShape = 'pill' | 'circle' | 'icon';
66
+ type ButtonState = 'idle' | 'loading' | 'success' | 'error';
67
+ /**
68
+ * `<usa-button>` — **button click deformation** (按钮点击形变) around a
69
+ * native `<button>` (or `<a>`) child — or the element itself becomes a button.
70
+ *
71
+ * `deform` (combinable, e.g. `deform="squash wobble"`):
72
+ * - `squash` — squash on press, stretch-and-settle on release (spring);
73
+ * - `wobble` — elastic border-radius wobble after a click;
74
+ * - `gooey` — liquid blob: droplets squeeze out from the press point and
75
+ * merge back (SVG goo filter);
76
+ * - `dent` — the surface dents toward the pressed point (3D tilt + inner shade).
77
+ *
78
+ * `shape="pill | circle | icon"` morphs the outline with a spring (label =
79
+ * `[data-label]`, icon = `[data-icon]` children); `morphTo(shape)`.
80
+ *
81
+ * `morph="submit"` — click → `loading` (shrinks to a circle with a spinner,
82
+ * `aria-busy`), then `success` (check) or `error` (shake + cross), and back
83
+ * to `idle` after `reset` ms (1800). Drive it with `state="…"` / `.state`, or
84
+ * call `event.detail.done(ok)` from a `usa:submit` listener.
85
+ *
86
+ * Attributes: `deform`, `shape`, `morph`, `state`, `reset`, `haptic`,
87
+ * `disabled`. Events: `usa:submit`, `usa:state`. Reduced motion: no
88
+ * deformation; shape and state changes are instant; status still announced.
89
+ */
90
+ interface UsaButtonElement extends UsaElement {
91
+ readonly target: HTMLElement;
92
+ shape: ButtonShape;
93
+ state: ButtonState;
94
+ morphTo(shape: ButtonShape): Promise<void>;
95
+ }
96
+ declare function defineButton(tag?: string): CustomElementConstructor | undefined;
97
+
98
+ type Pt = [number, number];
99
+ type Quad = [Pt, Pt, Pt, Pt];
100
+ /**
101
+ * Morphable icons: every icon is three quads (four points each) on a 24×24
102
+ * grid, so any icon can morph into any other by interpolating points.
103
+ */
104
+ declare const MORPH_ICONS: Record<string, [Quad, Quad, Quad]>;
105
+ /** SVG path data for an icon, or for the interpolation `t` (0–1) between two. */
106
+ declare function morphPath(from: string, to?: string, t?: number): string;
107
+ /**
108
+ * `<usa-icon-morph>` — an icon that morphs between shapes with a spring:
109
+ * play ↔ pause, menu ↔ close, plus ↔ minus, check, arrow-right…
110
+ *
111
+ * Attributes: `icons` (comma list, cycled; default `play,pause`), `index`
112
+ * (current, 0), `size` (px, 24), `toggle` (makes it a button that cycles
113
+ * on click / Enter / Space), `labels` (comma list of accessible names per
114
+ * icon, e.g. `Play,Pause`), `preset` (spring, `wobbly`). Methods:
115
+ * `next()`, `show(nameOrIndex)`. Events: `usa:change` (`{ index, icon }`).
116
+ * Inside a `<usa-button>` or `<button>` it is decorative. Reduced motion:
117
+ * the icon switches instantly.
118
+ */
119
+ interface UsaIconMorphElement extends UsaElement {
120
+ index: number;
121
+ readonly icon: string;
122
+ next(): void;
123
+ show(icon: string | number): void;
124
+ }
125
+ declare function defineIconMorph(tag?: string): CustomElementConstructor | undefined;
126
+
127
+ /**
128
+ * `<usa-like>` — a like / favourite toggle: the heart pops with a spring and
129
+ * bursts into particles when liked. `role="button"` + `aria-pressed`.
130
+ *
131
+ * Attributes: `liked`, `count` (shown next to the heart, updated ±1),
132
+ * `label` (accessible name, default "Like"), `color`, `size` (px, 24),
133
+ * `haptic`, `disabled`. Events: `change`, `usa:change` (`{ liked, count }`).
134
+ * Reduced motion: colour change only.
135
+ */
136
+ interface UsaLikeElement extends UsaElement {
137
+ liked: boolean;
138
+ count: number | null;
139
+ toggle(force?: boolean): void;
140
+ }
141
+ declare function defineLike(tag?: string): CustomElementConstructor | undefined;
142
+
143
+ /**
144
+ * `<usa-hold>` — hold-to-confirm: press and hold (pointer, Space or Enter)
145
+ * while a progress ring fills; releasing early rewinds it. Good for
146
+ * destructive actions.
147
+ *
148
+ * Attributes: `duration` (ms, 1200), `label` (accessible name), `color`,
149
+ * `disabled`. CSS variable `--usa-hold` (0–1). Events: `usa:progress`,
150
+ * `usa:confirm`, `usa:cancel`. Reduced motion: same timing, the ring fills
151
+ * without the scale pulse.
152
+ */
153
+ interface UsaHoldElement extends UsaElement {
154
+ readonly progress: number;
155
+ cancel(): void;
156
+ }
157
+ declare function defineHold(tag?: string): CustomElementConstructor | undefined;
158
+
159
+ /**
160
+ * `<usa-double-tap>` — detects a double tap / double click on its content
161
+ * (photos, posts) and pops a heart (or `icon`) at the tap point.
162
+ *
163
+ * Attributes: `icon` (text / emoji, default ♥), `color`, `delay` (max ms
164
+ * between taps, 300), `haptic`, `disabled`. Events: `usa:double-tap`
165
+ * (`{ x, y }`, element-relative). Keyboard users: press `L` while focused.
166
+ * Reduced motion: the icon fades in and out without scaling or particles.
167
+ */
168
+ interface UsaDoubleTapElement extends UsaElement {
169
+ pop(x?: number, y?: number): void;
170
+ }
171
+ declare function defineDoubleTap(tag?: string): CustomElementConstructor | undefined;
172
+
173
+ /**
174
+ * `<usa-checkbox>` — an animated, form-associated checkbox: the box springs
175
+ * and the check mark draws itself. `role="checkbox"` + `aria-checked`
176
+ * (`mixed` with `indeterminate`).
177
+ *
178
+ * Attributes: `checked`, `indeterminate`, `disabled`, `name`, `value`
179
+ * (`on`), `label`, `shape` (`square` default, `circle`). Events: `change`,
180
+ * `usa:change` (`{ checked }`). Reduced motion: no spring or drawing.
181
+ */
182
+ interface UsaCheckboxElement extends UsaElement {
183
+ checked: boolean;
184
+ indeterminate: boolean;
185
+ toggle(force?: boolean): void;
186
+ }
187
+ declare function defineCheckbox(tag?: string): CustomElementConstructor | undefined;
188
+
189
+ interface BurstOptions {
190
+ /** Number of particles (default 12). */
191
+ count?: number;
192
+ /** Colours to pick from (default: accent palette). */
193
+ colors?: string[];
194
+ /** Travel distance in px (default 48). */
195
+ distance?: number;
196
+ /** Particle size in px (default 6). */
197
+ size?: number;
198
+ /** `circle` (default), `square`, `star`, `heart` or any text / emoji. */
199
+ shape?: 'circle' | 'square' | 'star' | 'heart' | string;
200
+ /** Duration in ms (default 600). */
201
+ duration?: number;
202
+ }
203
+ /** Particles radiating from client point (x, y). Returns the number spawned. */
204
+ declare function burst(x: number, y: number, options?: BurstOptions): number;
205
+ interface ConfettiOptions {
206
+ /** Origin in client px (default: centre-bottom third of the viewport). */
207
+ x?: number;
208
+ y?: number;
209
+ /** Pieces (default 80). */
210
+ count?: number;
211
+ /** Spread angle in degrees (default 70). */
212
+ spread?: number;
213
+ /** Launch speed multiplier (default 1). */
214
+ velocity?: number;
215
+ colors?: string[];
216
+ /** Duration in ms (default 1600). */
217
+ duration?: number;
218
+ }
219
+ /** A confetti cannon (paper pieces with gravity, drift and spin). */
220
+ declare function confetti(options?: ConfettiOptions): number;
221
+ /** Horizontal error shake (`intensity` px, default 8). Reduced motion: a red outline flash. */
222
+ declare function shake(el: Element, intensity?: number, duration?: number): Animation | null;
223
+ /** `navigator.vibrate()` where supported (Android Chrome, some WebViews). Returns whether it ran. */
224
+ declare function haptic(pattern?: number | number[]): boolean;
225
+
226
+ /**
227
+ * use-scroll-animate/components/click — click & tap effects (v2.5).
228
+ * `<usa-click>` (ripple, burst, confetti, squish, press-spring, shake),
229
+ * `<usa-button>` (button click deformation: squash, wobble, gooey, dent;
230
+ * shape morph; submit → loading → success), `<usa-icon-morph>`,
231
+ * `<usa-like>`, `<usa-hold>`, `<usa-double-tap>`, `<usa-checkbox>`, plus
232
+ * `burst()`, `confetti()`, `shake()` and `haptic()`.
233
+ */
234
+
235
+ /** Register every component of this category under its default tag. */
236
+ declare function defineClickComponents(): void;
237
+ declare global {
238
+ interface HTMLElementTagNameMap {
239
+ 'usa-click': UsaClickElement;
240
+ 'usa-button': UsaButtonElement;
241
+ 'usa-icon-morph': UsaIconMorphElement;
242
+ 'usa-like': UsaLikeElement;
243
+ 'usa-hold': UsaHoldElement;
244
+ 'usa-double-tap': UsaDoubleTapElement;
245
+ 'usa-checkbox': UsaCheckboxElement;
246
+ }
247
+ }
248
+
249
+ export { BUTTON_DEFORMS, CLICK_EFFECTS, MORPH_ICONS, burst, confetti, configureComponents, defineButton, defineCheckbox, defineClick, defineClickComponents, defineDoubleTap, defineHold, defineIconMorph, defineLike, haptic, morphPath, prefersReducedMotion, shake };
250
+ export type { BurstOptions, ButtonDeform, ButtonShape, ButtonState, ClickEffect, ComponentsConfig, ConfettiOptions, UsaButtonElement, UsaCheckboxElement, UsaClickElement, UsaDoubleTapElement, UsaElement, UsaHoldElement, UsaIconMorphElement, UsaLikeElement };