use-scroll-animate 2.1.0 → 2.3.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 +33 -0
- package/README.md +31 -2
- package/README_ja.md +19 -0
- package/README_zh.md +30 -0
- package/dist/chunks/base-CJ7XfidP.cjs +233 -0
- package/dist/chunks/base-CJ7XfidP.cjs.map +1 -0
- package/dist/chunks/base-CuvCgqLy.js +219 -0
- package/dist/chunks/base-CuvCgqLy.js.map +1 -0
- package/dist/components/background.cjs +395 -0
- package/dist/components/background.cjs.map +1 -0
- package/dist/components/background.css +7 -0
- package/dist/components/background.d.cts +132 -0
- package/dist/components/background.d.ts +132 -0
- package/dist/components/background.js +387 -0
- package/dist/components/background.js.map +1 -0
- package/dist/components/feedback.cjs +444 -0
- package/dist/components/feedback.cjs.map +1 -0
- package/dist/components/feedback.css +7 -0
- package/dist/components/feedback.d.cts +170 -0
- package/dist/components/feedback.d.ts +170 -0
- package/dist/components/feedback.js +434 -0
- package/dist/components/feedback.js.map +1 -0
- package/dist/components/interaction.cjs +426 -0
- package/dist/components/interaction.cjs.map +1 -0
- package/dist/components/interaction.css +8 -0
- package/dist/components/interaction.d.cts +142 -0
- package/dist/components/interaction.d.ts +142 -0
- package/dist/components/interaction.js +417 -0
- package/dist/components/interaction.js.map +1 -0
- package/dist/components/physics.cjs +664 -0
- package/dist/components/physics.cjs.map +1 -0
- package/dist/components/physics.css +5 -0
- package/dist/components/physics.d.cts +216 -0
- package/dist/components/physics.d.ts +216 -0
- package/dist/components/physics.js +644 -0
- package/dist/components/physics.js.map +1 -0
- package/dist/components/reveal.cjs +360 -0
- package/dist/components/reveal.cjs.map +1 -0
- package/dist/components/reveal.css +5 -0
- package/dist/components/reveal.d.cts +132 -0
- package/dist/components/reveal.d.ts +132 -0
- package/dist/components/reveal.js +350 -0
- package/dist/components/reveal.js.map +1 -0
- package/dist/components/text.cjs +528 -0
- package/dist/components/text.cjs.map +1 -0
- package/dist/components/text.css +7 -0
- package/dist/components/text.d.cts +164 -0
- package/dist/components/text.d.ts +164 -0
- package/dist/components/text.js +517 -0
- package/dist/components/text.js.map +1 -0
- package/dist/components/transitions.cjs +546 -0
- package/dist/components/transitions.cjs.map +1 -0
- package/dist/components/transitions.css +6 -0
- package/dist/components/transitions.d.cts +180 -0
- package/dist/components/transitions.d.ts +180 -0
- package/dist/components/transitions.js +536 -0
- package/dist/components/transitions.js.map +1 -0
- package/dist/components.cjs +127 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.css +33 -0
- package/dist/components.d.cts +919 -0
- package/dist/components.d.ts +919 -0
- package/dist/components.js +65 -0
- package/dist/components.js.map +1 -0
- package/dist/components.umd.js +22 -0
- package/dist/components.umd.js.map +1 -0
- package/docs/API.md +2 -0
- package/docs/components.md +169 -0
- package/docs/windows-apps.md +108 -0
- package/package.json +105 -5
|
@@ -0,0 +1,142 @@
|
|
|
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-ripple>` — an ink ripple from the pointer (or the centre, for
|
|
40
|
+
* keyboard presses) on whatever it wraps: buttons, list items, cards.
|
|
41
|
+
*
|
|
42
|
+
* Attributes: `color` (default `currentColor`), `opacity` (0.22),
|
|
43
|
+
* `duration` (ms, 550), `centered`, `disabled`. Clips its content to its
|
|
44
|
+
* own border radius. Reduced motion: a brief highlight instead of the wave.
|
|
45
|
+
*/
|
|
46
|
+
interface UsaRippleElement extends UsaElement {
|
|
47
|
+
/** Spawn a ripple at client coordinates (default: centre). */
|
|
48
|
+
ripple(x?: number, y?: number): void;
|
|
49
|
+
}
|
|
50
|
+
declare function defineRipple(tag?: string): CustomElementConstructor | undefined;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* `<usa-magnetic>` — its content leans toward the pointer when the pointer
|
|
54
|
+
* comes near, and springs back when it leaves (great for CTAs and icons).
|
|
55
|
+
*
|
|
56
|
+
* Attributes: `strength` (0–1 share of the pointer offset, 0.35), `radius`
|
|
57
|
+
* (px of attraction beyond the element's edge, 60), `disabled`. Only on
|
|
58
|
+
* devices with a fine pointer that hovers; off under reduced motion.
|
|
59
|
+
* Writes one `transform` per frame through `--usa-mx` / `--usa-my`.
|
|
60
|
+
*/
|
|
61
|
+
type UsaMagneticElement = UsaElement;
|
|
62
|
+
declare function defineMagnetic(tag?: string): CustomElementConstructor | undefined;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* `<usa-tilt>` — a 3D card that tilts toward the pointer, with an optional
|
|
66
|
+
* glare highlight that follows it.
|
|
67
|
+
*
|
|
68
|
+
* Attributes: `max` (deg, 10), `scale` (1.03 while hovered), `perspective`
|
|
69
|
+
* (px, 900), `glare` (add the light reflection), `reverse` (tilt away),
|
|
70
|
+
* `disabled`. Off under reduced motion. Exposes `--usa-tilt-x` /
|
|
71
|
+
* `--usa-tilt-y` (−1…1) for parallax layers inside the card.
|
|
72
|
+
*/
|
|
73
|
+
type UsaTiltElement = UsaElement;
|
|
74
|
+
declare function defineTilt(tag?: string): CustomElementConstructor | undefined;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* `<usa-spotlight>` — the Windows Fluent "Reveal highlight": a soft light
|
|
78
|
+
* follows the pointer across a group of items, lighting up their borders
|
|
79
|
+
* (even of neighbours) and the background of the hovered one. Put buttons,
|
|
80
|
+
* tiles or menu items inside; each direct child is an item (or mark items
|
|
81
|
+
* with `data-spotlight` to pick them yourself).
|
|
82
|
+
*
|
|
83
|
+
* Attributes: `size` (px, radius of the light, 160), `color` (default a
|
|
84
|
+
* translucent white), `border` (px width of the lit border, 1),
|
|
85
|
+
* `no-fill` (only light the borders). Not a motion effect, so it stays on
|
|
86
|
+
* under reduced motion; off on touch-only devices.
|
|
87
|
+
*/
|
|
88
|
+
type UsaSpotlightElement = UsaElement;
|
|
89
|
+
declare function defineSpotlight(tag?: string): CustomElementConstructor | undefined;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* `<usa-press>` — tactile press feedback: content dips while pressed and
|
|
93
|
+
* springs back on release (the Fluent "pointer down" scale), or bounces once
|
|
94
|
+
* on click with `bounce`.
|
|
95
|
+
*
|
|
96
|
+
* Attributes: `scale` (pressed scale, 0.95), `bounce` (overshoot on
|
|
97
|
+
* release), `disabled`. Works with mouse, touch, pen and Space/Enter.
|
|
98
|
+
* Reduced motion: a subtle dim instead of scaling.
|
|
99
|
+
*/
|
|
100
|
+
interface UsaPressElement extends UsaElement {
|
|
101
|
+
readonly pressed: boolean;
|
|
102
|
+
}
|
|
103
|
+
declare function definePress(tag?: string): CustomElementConstructor | undefined;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* `<usa-toggle>` — an accessible switch whose knob stretches while pressed
|
|
107
|
+
* and glides across (the Windows 11 / iOS toggle). `role="switch"`,
|
|
108
|
+
* keyboard (Space / Enter), and form-associated where `ElementInternals`
|
|
109
|
+
* exists (submits `value`, default `"on"`, under `name` when checked).
|
|
110
|
+
*
|
|
111
|
+
* Attributes: `checked`, `disabled`, `name`, `value`, `label`
|
|
112
|
+
* (accessible name if there is no `aria-label` / `<label>`). Events:
|
|
113
|
+
* `change` and `usa:change` (`detail.checked`). Reduced motion: no glide.
|
|
114
|
+
*/
|
|
115
|
+
interface UsaToggleElement extends UsaElement {
|
|
116
|
+
checked: boolean;
|
|
117
|
+
disabled: boolean;
|
|
118
|
+
toggle(force?: boolean): void;
|
|
119
|
+
}
|
|
120
|
+
declare function defineToggle(tag?: string): CustomElementConstructor | undefined;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* use-scroll-animate/components/interaction — micro-interactions.
|
|
124
|
+
* `<usa-ripple>`, `<usa-magnetic>`, `<usa-tilt>`, `<usa-spotlight>`,
|
|
125
|
+
* `<usa-press>`, `<usa-toggle>`.
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
/** Register every component of this category under its default tag. */
|
|
129
|
+
declare function defineInteractionComponents(): void;
|
|
130
|
+
declare global {
|
|
131
|
+
interface HTMLElementTagNameMap {
|
|
132
|
+
'usa-ripple': UsaRippleElement;
|
|
133
|
+
'usa-magnetic': UsaMagneticElement;
|
|
134
|
+
'usa-tilt': UsaTiltElement;
|
|
135
|
+
'usa-spotlight': UsaSpotlightElement;
|
|
136
|
+
'usa-press': UsaPressElement;
|
|
137
|
+
'usa-toggle': UsaToggleElement;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export { configureComponents, defineInteractionComponents, defineMagnetic, definePress, defineRipple, defineSpotlight, defineTilt, defineToggle, prefersReducedMotion };
|
|
142
|
+
export type { ComponentsConfig, UsaElement, UsaMagneticElement, UsaPressElement, UsaRippleElement, UsaSpotlightElement, UsaTiltElement, UsaToggleElement };
|
|
@@ -0,0 +1,142 @@
|
|
|
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-ripple>` — an ink ripple from the pointer (or the centre, for
|
|
40
|
+
* keyboard presses) on whatever it wraps: buttons, list items, cards.
|
|
41
|
+
*
|
|
42
|
+
* Attributes: `color` (default `currentColor`), `opacity` (0.22),
|
|
43
|
+
* `duration` (ms, 550), `centered`, `disabled`. Clips its content to its
|
|
44
|
+
* own border radius. Reduced motion: a brief highlight instead of the wave.
|
|
45
|
+
*/
|
|
46
|
+
interface UsaRippleElement extends UsaElement {
|
|
47
|
+
/** Spawn a ripple at client coordinates (default: centre). */
|
|
48
|
+
ripple(x?: number, y?: number): void;
|
|
49
|
+
}
|
|
50
|
+
declare function defineRipple(tag?: string): CustomElementConstructor | undefined;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* `<usa-magnetic>` — its content leans toward the pointer when the pointer
|
|
54
|
+
* comes near, and springs back when it leaves (great for CTAs and icons).
|
|
55
|
+
*
|
|
56
|
+
* Attributes: `strength` (0–1 share of the pointer offset, 0.35), `radius`
|
|
57
|
+
* (px of attraction beyond the element's edge, 60), `disabled`. Only on
|
|
58
|
+
* devices with a fine pointer that hovers; off under reduced motion.
|
|
59
|
+
* Writes one `transform` per frame through `--usa-mx` / `--usa-my`.
|
|
60
|
+
*/
|
|
61
|
+
type UsaMagneticElement = UsaElement;
|
|
62
|
+
declare function defineMagnetic(tag?: string): CustomElementConstructor | undefined;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* `<usa-tilt>` — a 3D card that tilts toward the pointer, with an optional
|
|
66
|
+
* glare highlight that follows it.
|
|
67
|
+
*
|
|
68
|
+
* Attributes: `max` (deg, 10), `scale` (1.03 while hovered), `perspective`
|
|
69
|
+
* (px, 900), `glare` (add the light reflection), `reverse` (tilt away),
|
|
70
|
+
* `disabled`. Off under reduced motion. Exposes `--usa-tilt-x` /
|
|
71
|
+
* `--usa-tilt-y` (−1…1) for parallax layers inside the card.
|
|
72
|
+
*/
|
|
73
|
+
type UsaTiltElement = UsaElement;
|
|
74
|
+
declare function defineTilt(tag?: string): CustomElementConstructor | undefined;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* `<usa-spotlight>` — the Windows Fluent "Reveal highlight": a soft light
|
|
78
|
+
* follows the pointer across a group of items, lighting up their borders
|
|
79
|
+
* (even of neighbours) and the background of the hovered one. Put buttons,
|
|
80
|
+
* tiles or menu items inside; each direct child is an item (or mark items
|
|
81
|
+
* with `data-spotlight` to pick them yourself).
|
|
82
|
+
*
|
|
83
|
+
* Attributes: `size` (px, radius of the light, 160), `color` (default a
|
|
84
|
+
* translucent white), `border` (px width of the lit border, 1),
|
|
85
|
+
* `no-fill` (only light the borders). Not a motion effect, so it stays on
|
|
86
|
+
* under reduced motion; off on touch-only devices.
|
|
87
|
+
*/
|
|
88
|
+
type UsaSpotlightElement = UsaElement;
|
|
89
|
+
declare function defineSpotlight(tag?: string): CustomElementConstructor | undefined;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* `<usa-press>` — tactile press feedback: content dips while pressed and
|
|
93
|
+
* springs back on release (the Fluent "pointer down" scale), or bounces once
|
|
94
|
+
* on click with `bounce`.
|
|
95
|
+
*
|
|
96
|
+
* Attributes: `scale` (pressed scale, 0.95), `bounce` (overshoot on
|
|
97
|
+
* release), `disabled`. Works with mouse, touch, pen and Space/Enter.
|
|
98
|
+
* Reduced motion: a subtle dim instead of scaling.
|
|
99
|
+
*/
|
|
100
|
+
interface UsaPressElement extends UsaElement {
|
|
101
|
+
readonly pressed: boolean;
|
|
102
|
+
}
|
|
103
|
+
declare function definePress(tag?: string): CustomElementConstructor | undefined;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* `<usa-toggle>` — an accessible switch whose knob stretches while pressed
|
|
107
|
+
* and glides across (the Windows 11 / iOS toggle). `role="switch"`,
|
|
108
|
+
* keyboard (Space / Enter), and form-associated where `ElementInternals`
|
|
109
|
+
* exists (submits `value`, default `"on"`, under `name` when checked).
|
|
110
|
+
*
|
|
111
|
+
* Attributes: `checked`, `disabled`, `name`, `value`, `label`
|
|
112
|
+
* (accessible name if there is no `aria-label` / `<label>`). Events:
|
|
113
|
+
* `change` and `usa:change` (`detail.checked`). Reduced motion: no glide.
|
|
114
|
+
*/
|
|
115
|
+
interface UsaToggleElement extends UsaElement {
|
|
116
|
+
checked: boolean;
|
|
117
|
+
disabled: boolean;
|
|
118
|
+
toggle(force?: boolean): void;
|
|
119
|
+
}
|
|
120
|
+
declare function defineToggle(tag?: string): CustomElementConstructor | undefined;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* use-scroll-animate/components/interaction — micro-interactions.
|
|
124
|
+
* `<usa-ripple>`, `<usa-magnetic>`, `<usa-tilt>`, `<usa-spotlight>`,
|
|
125
|
+
* `<usa-press>`, `<usa-toggle>`.
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
/** Register every component of this category under its default tag. */
|
|
129
|
+
declare function defineInteractionComponents(): void;
|
|
130
|
+
declare global {
|
|
131
|
+
interface HTMLElementTagNameMap {
|
|
132
|
+
'usa-ripple': UsaRippleElement;
|
|
133
|
+
'usa-magnetic': UsaMagneticElement;
|
|
134
|
+
'usa-tilt': UsaTiltElement;
|
|
135
|
+
'usa-spotlight': UsaSpotlightElement;
|
|
136
|
+
'usa-press': UsaPressElement;
|
|
137
|
+
'usa-toggle': UsaToggleElement;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export { configureComponents, defineInteractionComponents, defineMagnetic, definePress, defineRipple, defineSpotlight, defineTilt, defineToggle, prefersReducedMotion };
|
|
142
|
+
export type { ComponentsConfig, UsaElement, UsaMagneticElement, UsaPressElement, UsaRippleElement, UsaSpotlightElement, UsaTiltElement, UsaToggleElement };
|