use-scroll-animate 2.0.1 → 2.2.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 (66) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +31 -1
  3. package/README_ja.md +18 -0
  4. package/README_zh.md +31 -0
  5. package/dist/chunks/base-BiTc85p_.cjs +232 -0
  6. package/dist/chunks/base-BiTc85p_.cjs.map +1 -0
  7. package/dist/chunks/base-CFtnmfli.js +219 -0
  8. package/dist/chunks/base-CFtnmfli.js.map +1 -0
  9. package/dist/components/background.cjs +395 -0
  10. package/dist/components/background.cjs.map +1 -0
  11. package/dist/components/background.css +7 -0
  12. package/dist/components/background.d.cts +132 -0
  13. package/dist/components/background.d.ts +132 -0
  14. package/dist/components/background.js +387 -0
  15. package/dist/components/background.js.map +1 -0
  16. package/dist/components/feedback.cjs +444 -0
  17. package/dist/components/feedback.cjs.map +1 -0
  18. package/dist/components/feedback.css +7 -0
  19. package/dist/components/feedback.d.cts +170 -0
  20. package/dist/components/feedback.d.ts +170 -0
  21. package/dist/components/feedback.js +434 -0
  22. package/dist/components/feedback.js.map +1 -0
  23. package/dist/components/interaction.cjs +426 -0
  24. package/dist/components/interaction.cjs.map +1 -0
  25. package/dist/components/interaction.css +8 -0
  26. package/dist/components/interaction.d.cts +142 -0
  27. package/dist/components/interaction.d.ts +142 -0
  28. package/dist/components/interaction.js +417 -0
  29. package/dist/components/interaction.js.map +1 -0
  30. package/dist/components/reveal.cjs +360 -0
  31. package/dist/components/reveal.cjs.map +1 -0
  32. package/dist/components/reveal.css +5 -0
  33. package/dist/components/reveal.d.cts +132 -0
  34. package/dist/components/reveal.d.ts +132 -0
  35. package/dist/components/reveal.js +350 -0
  36. package/dist/components/reveal.js.map +1 -0
  37. package/dist/components/text.cjs +528 -0
  38. package/dist/components/text.cjs.map +1 -0
  39. package/dist/components/text.css +7 -0
  40. package/dist/components/text.d.cts +164 -0
  41. package/dist/components/text.d.ts +164 -0
  42. package/dist/components/text.js +517 -0
  43. package/dist/components/text.js.map +1 -0
  44. package/dist/components/transitions.cjs +546 -0
  45. package/dist/components/transitions.cjs.map +1 -0
  46. package/dist/components/transitions.css +6 -0
  47. package/dist/components/transitions.d.cts +180 -0
  48. package/dist/components/transitions.d.ts +180 -0
  49. package/dist/components/transitions.js +536 -0
  50. package/dist/components/transitions.js.map +1 -0
  51. package/dist/components.cjs +106 -0
  52. package/dist/components.cjs.map +1 -0
  53. package/dist/components.css +30 -0
  54. package/dist/components.d.cts +741 -0
  55. package/dist/components.d.ts +741 -0
  56. package/dist/components.js +61 -0
  57. package/dist/components.js.map +1 -0
  58. package/dist/components.umd.js +22 -0
  59. package/dist/components.umd.js.map +1 -0
  60. package/docs/API.md +2 -0
  61. package/docs/components.md +155 -0
  62. package/docs/images/showcase-detail.png +0 -0
  63. package/docs/images/showcase-grid.png +0 -0
  64. package/docs/images/showcase-mobile.png +0 -0
  65. package/docs/windows-apps.md +108 -0
  66. package/package.json +93 -5
@@ -0,0 +1,164 @@
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-typewriter>` — types text character by character, optionally cycling
40
+ * through several phrases (typing, pausing, deleting).
41
+ *
42
+ * Attributes: `text` (default: the element's text), `words` (phrases
43
+ * separated by `|`, overrides `text`), `speed` (ms per character, 55),
44
+ * `delete-speed` (ms, 30), `pause` (ms before deleting, 1400), `delay`
45
+ * (ms, 0), `loop`, `cursor="false"` to hide the caret, `start`
46
+ * (`view` | `load` | `manual`, default `view`). The full text is exposed to
47
+ * assistive tech via `aria-label`. Event: `usa:complete` (one pass done).
48
+ * Reduced motion: the text appears at once.
49
+ */
50
+ interface UsaTypewriterElement extends UsaElement {
51
+ /** Phrases being typed. */
52
+ readonly phrases: string[];
53
+ start(): void;
54
+ stop(): void;
55
+ restart(): void;
56
+ }
57
+ declare function defineTypewriter(tag?: string): CustomElementConstructor | undefined;
58
+
59
+ /**
60
+ * `<usa-split-text>` — splits its text into words or characters and reveals
61
+ * them in a cascade (pure CSS animation per unit, transform / opacity /
62
+ * filter only). Words never break across lines.
63
+ *
64
+ * Attributes: `by` (`chars` | `words`, default `chars`), `effect`
65
+ * (`rise` | `fade` | `blur` | `flip` | `pop`, default `rise`), `stagger`
66
+ * (ms between units, 28 for chars / 70 for words), `duration` (ms, 620),
67
+ * `delay` (ms, 0), `trigger` (`view` | `load` | `manual`, default `view`),
68
+ * `repeat`. The original text stays readable via `aria-label`.
69
+ * Event: `usa:complete`.
70
+ */
71
+ interface UsaSplitTextElement extends UsaElement {
72
+ readonly units: HTMLElement[];
73
+ play(): void;
74
+ reset(): void;
75
+ }
76
+ declare function defineSplitText(tag?: string): CustomElementConstructor | undefined;
77
+
78
+ /**
79
+ * `<usa-scramble>` — "decodes" text out of random glyphs, left to right.
80
+ *
81
+ * Attributes: `text` (default: the element's text), `duration` (ms, 900),
82
+ * `chars` (glyph set), `trigger` (`view` | `hover` | `load` | `manual`,
83
+ * default `view`). Spaces and punctuation stay in place. Uses a monospace-
84
+ * friendly fixed width per glyph only if you style it so; the element sets
85
+ * nothing that causes reflow beyond its own text. Event: `usa:complete`.
86
+ * Reduced motion: shows the final text.
87
+ */
88
+ interface UsaScrambleElement extends UsaElement {
89
+ play(): Promise<void>;
90
+ }
91
+ /** One frame of the scramble: the first `progress` share is resolved. */
92
+ declare function scrambleFrame(text: string, progress: number, glyphs?: string, rnd?: () => number): string;
93
+ declare function defineScramble(tag?: string): CustomElementConstructor | undefined;
94
+
95
+ /**
96
+ * `<usa-counter>` — counts up (or down) to a number when it scrolls into view.
97
+ *
98
+ * Attributes: `to` (target, required), `from` (0), `duration` (ms, 1600),
99
+ * `decimals` (0), `locale` (default: the document language), `prefix`,
100
+ * `suffix`, `grouping="false"` (no thousands separators), `start`
101
+ * (`view` | `load` | `manual`). Setting the `value` property animates from
102
+ * the current value — handy for live dashboards. Uses tabular digits so
103
+ * the width does not jump. Event: `usa:complete`. Reduced motion: jumps.
104
+ */
105
+ interface UsaCounterElement extends UsaElement {
106
+ /** Current target; setting it animates to the new number. */
107
+ value: number;
108
+ /** Animate to `to` (default: the `to` attribute). */
109
+ play(to?: number): Promise<void>;
110
+ format(n: number): string;
111
+ }
112
+ /** easeOutExpo */
113
+ declare const easeOutExpo: (t: number) => number;
114
+ declare function defineCounter(tag?: string): CustomElementConstructor | undefined;
115
+
116
+ /**
117
+ * `<usa-shimmer-text>` — a light sweep across gradient-filled text (CSS
118
+ * only; the element just maps attributes to custom properties).
119
+ *
120
+ * Attributes: `duration` (ms, 2600), `color` (base text colour), `shine`
121
+ * (highlight colour), `angle` (deg, 110). Or style `--usa-shimmer-*`
122
+ * directly. Reduced motion: static gradient text.
123
+ */
124
+ type UsaShimmerTextElement = UsaElement;
125
+ declare function defineShimmerText(tag?: string): CustomElementConstructor | undefined;
126
+
127
+ /**
128
+ * `<usa-text-rotate>` — cycles through words in place ("Build *fast* /
129
+ * *small* / *typed* apps"). All words share one grid cell, so the width is
130
+ * that of the longest word and nothing around it reflows.
131
+ *
132
+ * Attributes: `words` (separated by `|`, default: the element's text split
133
+ * on `|`), `interval` (ms, 2200), `effect` (`slide` | `fade` | `flip` |
134
+ * `blur`, default `slide`), `paused`. Pauses while off-screen and on hover
135
+ * is not needed. Event: `usa:change` (`detail.index`, `detail.word`).
136
+ * Reduced motion: words still change, without movement (fade only).
137
+ */
138
+ interface UsaTextRotateElement extends UsaElement {
139
+ readonly index: number;
140
+ next(): void;
141
+ }
142
+ declare function defineTextRotate(tag?: string): CustomElementConstructor | undefined;
143
+
144
+ /**
145
+ * use-scroll-animate/components/text — text effects.
146
+ * `<usa-typewriter>`, `<usa-split-text>`, `<usa-scramble>`, `<usa-counter>`,
147
+ * `<usa-shimmer-text>`, `<usa-text-rotate>`.
148
+ */
149
+
150
+ /** Register every component of this category under its default tag. */
151
+ declare function defineTextComponents(): void;
152
+ declare global {
153
+ interface HTMLElementTagNameMap {
154
+ 'usa-typewriter': UsaTypewriterElement;
155
+ 'usa-split-text': UsaSplitTextElement;
156
+ 'usa-scramble': UsaScrambleElement;
157
+ 'usa-counter': UsaCounterElement;
158
+ 'usa-shimmer-text': UsaShimmerTextElement;
159
+ 'usa-text-rotate': UsaTextRotateElement;
160
+ }
161
+ }
162
+
163
+ export { configureComponents, defineCounter, defineScramble, defineShimmerText, defineSplitText, defineTextComponents, defineTextRotate, defineTypewriter, easeOutExpo, prefersReducedMotion, scrambleFrame };
164
+ export type { ComponentsConfig, UsaCounterElement, UsaElement, UsaScrambleElement, UsaShimmerTextElement, UsaSplitTextElement, UsaTextRotateElement, UsaTypewriterElement };
@@ -0,0 +1,164 @@
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-typewriter>` — types text character by character, optionally cycling
40
+ * through several phrases (typing, pausing, deleting).
41
+ *
42
+ * Attributes: `text` (default: the element's text), `words` (phrases
43
+ * separated by `|`, overrides `text`), `speed` (ms per character, 55),
44
+ * `delete-speed` (ms, 30), `pause` (ms before deleting, 1400), `delay`
45
+ * (ms, 0), `loop`, `cursor="false"` to hide the caret, `start`
46
+ * (`view` | `load` | `manual`, default `view`). The full text is exposed to
47
+ * assistive tech via `aria-label`. Event: `usa:complete` (one pass done).
48
+ * Reduced motion: the text appears at once.
49
+ */
50
+ interface UsaTypewriterElement extends UsaElement {
51
+ /** Phrases being typed. */
52
+ readonly phrases: string[];
53
+ start(): void;
54
+ stop(): void;
55
+ restart(): void;
56
+ }
57
+ declare function defineTypewriter(tag?: string): CustomElementConstructor | undefined;
58
+
59
+ /**
60
+ * `<usa-split-text>` — splits its text into words or characters and reveals
61
+ * them in a cascade (pure CSS animation per unit, transform / opacity /
62
+ * filter only). Words never break across lines.
63
+ *
64
+ * Attributes: `by` (`chars` | `words`, default `chars`), `effect`
65
+ * (`rise` | `fade` | `blur` | `flip` | `pop`, default `rise`), `stagger`
66
+ * (ms between units, 28 for chars / 70 for words), `duration` (ms, 620),
67
+ * `delay` (ms, 0), `trigger` (`view` | `load` | `manual`, default `view`),
68
+ * `repeat`. The original text stays readable via `aria-label`.
69
+ * Event: `usa:complete`.
70
+ */
71
+ interface UsaSplitTextElement extends UsaElement {
72
+ readonly units: HTMLElement[];
73
+ play(): void;
74
+ reset(): void;
75
+ }
76
+ declare function defineSplitText(tag?: string): CustomElementConstructor | undefined;
77
+
78
+ /**
79
+ * `<usa-scramble>` — "decodes" text out of random glyphs, left to right.
80
+ *
81
+ * Attributes: `text` (default: the element's text), `duration` (ms, 900),
82
+ * `chars` (glyph set), `trigger` (`view` | `hover` | `load` | `manual`,
83
+ * default `view`). Spaces and punctuation stay in place. Uses a monospace-
84
+ * friendly fixed width per glyph only if you style it so; the element sets
85
+ * nothing that causes reflow beyond its own text. Event: `usa:complete`.
86
+ * Reduced motion: shows the final text.
87
+ */
88
+ interface UsaScrambleElement extends UsaElement {
89
+ play(): Promise<void>;
90
+ }
91
+ /** One frame of the scramble: the first `progress` share is resolved. */
92
+ declare function scrambleFrame(text: string, progress: number, glyphs?: string, rnd?: () => number): string;
93
+ declare function defineScramble(tag?: string): CustomElementConstructor | undefined;
94
+
95
+ /**
96
+ * `<usa-counter>` — counts up (or down) to a number when it scrolls into view.
97
+ *
98
+ * Attributes: `to` (target, required), `from` (0), `duration` (ms, 1600),
99
+ * `decimals` (0), `locale` (default: the document language), `prefix`,
100
+ * `suffix`, `grouping="false"` (no thousands separators), `start`
101
+ * (`view` | `load` | `manual`). Setting the `value` property animates from
102
+ * the current value — handy for live dashboards. Uses tabular digits so
103
+ * the width does not jump. Event: `usa:complete`. Reduced motion: jumps.
104
+ */
105
+ interface UsaCounterElement extends UsaElement {
106
+ /** Current target; setting it animates to the new number. */
107
+ value: number;
108
+ /** Animate to `to` (default: the `to` attribute). */
109
+ play(to?: number): Promise<void>;
110
+ format(n: number): string;
111
+ }
112
+ /** easeOutExpo */
113
+ declare const easeOutExpo: (t: number) => number;
114
+ declare function defineCounter(tag?: string): CustomElementConstructor | undefined;
115
+
116
+ /**
117
+ * `<usa-shimmer-text>` — a light sweep across gradient-filled text (CSS
118
+ * only; the element just maps attributes to custom properties).
119
+ *
120
+ * Attributes: `duration` (ms, 2600), `color` (base text colour), `shine`
121
+ * (highlight colour), `angle` (deg, 110). Or style `--usa-shimmer-*`
122
+ * directly. Reduced motion: static gradient text.
123
+ */
124
+ type UsaShimmerTextElement = UsaElement;
125
+ declare function defineShimmerText(tag?: string): CustomElementConstructor | undefined;
126
+
127
+ /**
128
+ * `<usa-text-rotate>` — cycles through words in place ("Build *fast* /
129
+ * *small* / *typed* apps"). All words share one grid cell, so the width is
130
+ * that of the longest word and nothing around it reflows.
131
+ *
132
+ * Attributes: `words` (separated by `|`, default: the element's text split
133
+ * on `|`), `interval` (ms, 2200), `effect` (`slide` | `fade` | `flip` |
134
+ * `blur`, default `slide`), `paused`. Pauses while off-screen and on hover
135
+ * is not needed. Event: `usa:change` (`detail.index`, `detail.word`).
136
+ * Reduced motion: words still change, without movement (fade only).
137
+ */
138
+ interface UsaTextRotateElement extends UsaElement {
139
+ readonly index: number;
140
+ next(): void;
141
+ }
142
+ declare function defineTextRotate(tag?: string): CustomElementConstructor | undefined;
143
+
144
+ /**
145
+ * use-scroll-animate/components/text — text effects.
146
+ * `<usa-typewriter>`, `<usa-split-text>`, `<usa-scramble>`, `<usa-counter>`,
147
+ * `<usa-shimmer-text>`, `<usa-text-rotate>`.
148
+ */
149
+
150
+ /** Register every component of this category under its default tag. */
151
+ declare function defineTextComponents(): void;
152
+ declare global {
153
+ interface HTMLElementTagNameMap {
154
+ 'usa-typewriter': UsaTypewriterElement;
155
+ 'usa-split-text': UsaSplitTextElement;
156
+ 'usa-scramble': UsaScrambleElement;
157
+ 'usa-counter': UsaCounterElement;
158
+ 'usa-shimmer-text': UsaShimmerTextElement;
159
+ 'usa-text-rotate': UsaTextRotateElement;
160
+ }
161
+ }
162
+
163
+ export { configureComponents, defineCounter, defineScramble, defineShimmerText, defineSplitText, defineTextComponents, defineTextRotate, defineTypewriter, easeOutExpo, prefersReducedMotion, scrambleFrame };
164
+ export type { ComponentsConfig, UsaCounterElement, UsaElement, UsaScrambleElement, UsaShimmerTextElement, UsaSplitTextElement, UsaTextRotateElement, UsaTypewriterElement };