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.
Files changed (70) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +31 -2
  3. package/README_ja.md +19 -0
  4. package/README_zh.md +30 -0
  5. package/dist/chunks/base-CJ7XfidP.cjs +233 -0
  6. package/dist/chunks/base-CJ7XfidP.cjs.map +1 -0
  7. package/dist/chunks/base-CuvCgqLy.js +219 -0
  8. package/dist/chunks/base-CuvCgqLy.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/physics.cjs +664 -0
  31. package/dist/components/physics.cjs.map +1 -0
  32. package/dist/components/physics.css +5 -0
  33. package/dist/components/physics.d.cts +216 -0
  34. package/dist/components/physics.d.ts +216 -0
  35. package/dist/components/physics.js +644 -0
  36. package/dist/components/physics.js.map +1 -0
  37. package/dist/components/reveal.cjs +360 -0
  38. package/dist/components/reveal.cjs.map +1 -0
  39. package/dist/components/reveal.css +5 -0
  40. package/dist/components/reveal.d.cts +132 -0
  41. package/dist/components/reveal.d.ts +132 -0
  42. package/dist/components/reveal.js +350 -0
  43. package/dist/components/reveal.js.map +1 -0
  44. package/dist/components/text.cjs +528 -0
  45. package/dist/components/text.cjs.map +1 -0
  46. package/dist/components/text.css +7 -0
  47. package/dist/components/text.d.cts +164 -0
  48. package/dist/components/text.d.ts +164 -0
  49. package/dist/components/text.js +517 -0
  50. package/dist/components/text.js.map +1 -0
  51. package/dist/components/transitions.cjs +546 -0
  52. package/dist/components/transitions.cjs.map +1 -0
  53. package/dist/components/transitions.css +6 -0
  54. package/dist/components/transitions.d.cts +180 -0
  55. package/dist/components/transitions.d.ts +180 -0
  56. package/dist/components/transitions.js +536 -0
  57. package/dist/components/transitions.js.map +1 -0
  58. package/dist/components.cjs +127 -0
  59. package/dist/components.cjs.map +1 -0
  60. package/dist/components.css +33 -0
  61. package/dist/components.d.cts +919 -0
  62. package/dist/components.d.ts +919 -0
  63. package/dist/components.js +65 -0
  64. package/dist/components.js.map +1 -0
  65. package/dist/components.umd.js +22 -0
  66. package/dist/components.umd.js.map +1 -0
  67. package/docs/API.md +2 -0
  68. package/docs/components.md +169 -0
  69. package/docs/windows-apps.md +108 -0
  70. package/package.json +105 -5
@@ -0,0 +1,6 @@
1
+ /* use-scroll-animate/components/transitions */
2
+ .usa-sr{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:nowrap;border:0}
3
+ usa-accordion{display:block}usa-accordion>details>summary{cursor:pointer}usa-accordion>details>summary::-webkit-details-marker{display:none}usa-accordion>details>summary{list-style:none;display:flex;align-items:center;justify-content:space-between;gap:1em}usa-accordion>details>summary::after{content:"";flex:none;width:0.5em;height:0.5em;border-right:2px solid currentColor;border-bottom:2px solid currentColor;transform:translateY(-25%) rotate(45deg);transition:transform 0.3s cubic-bezier(0.22,1,0.36,1);opacity:0.7}usa-accordion>details[open]:not([data-closing])>summary::after{transform:translateY(25%) rotate(-135deg)}@media (prefers-reduced-motion:reduce){usa-accordion>details>summary::after{transition:none}}
4
+ usa-dialog{display:contents}usa-dialog:not(:defined){display:none}
5
+ usa-flip-list{display:block}
6
+ usa-view-switch{display:grid}usa-view-switch>*{grid-area:1 / 1;min-width:0}usa-view-switch>[hidden]:not([data-leaving]){display:none !important}usa-view-switch>[data-leaving]{display:block;pointer-events:none}
@@ -0,0 +1,180 @@
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
+ type DialogVariant = 'modal' | 'drawer-start' | 'drawer-end' | 'drawer-bottom' | 'sheet';
39
+ /**
40
+ * `<usa-dialog>` — an animated modal or drawer built on the native
41
+ * `<dialog>` (top layer, focus trapping, inert page, Esc to close). Its
42
+ * children are slotted into the panel (they stay in the light DOM, so
43
+ * React / Vue / Svelte keep owning them). Style with `::part(panel)`,
44
+ * `::part(backdrop)` and the `--usa-dialog-*` custom properties.
45
+ *
46
+ * Attributes: `open` (reflects; set/remove to open/close), `variant`
47
+ * (`modal` default — Fluent scale + fade; `drawer-start` / `drawer-end`
48
+ * slide from the side, `drawer-bottom` / `sheet` from below), `label`
49
+ * (accessible name), `no-backdrop-close`, `no-esc`. Elements inside
50
+ * with `data-close` close it. Events: `usa:open`, `usa:close` (cancelable
51
+ * `usa:beforeclose`). Reduced motion: fade only.
52
+ */
53
+ interface UsaDialogElement extends UsaElement {
54
+ open: boolean;
55
+ show(): Promise<void>;
56
+ close(returnValue?: string): Promise<void>;
57
+ readonly dialog: HTMLDialogElement | null;
58
+ returnValue: string;
59
+ }
60
+ declare function defineDialog(tag?: string): CustomElementConstructor | undefined;
61
+
62
+ /**
63
+ * `<usa-accordion>` — smooth expand / collapse for the native `<details>`
64
+ * elements inside it (keeps their semantics, keyboard support and
65
+ * find-in-page, and adds no wrapper elements, so framework-rendered content
66
+ * is left alone). Only one stays open unless `multiple` is set.
67
+ *
68
+ * Attributes: `multiple`, `duration` (ms, 300). Event: `usa:toggle`
69
+ * (`detail.details`, `detail.open`). Reduced motion: instant.
70
+ * Heights are measured once per toggle and animated on the `<details>`.
71
+ */
72
+ interface UsaAccordionElement extends UsaElement {
73
+ readonly items: HTMLDetailsElement[];
74
+ toggleItem(details: HTMLDetailsElement, open?: boolean): Promise<void>;
75
+ }
76
+ declare function defineAccordion(tag?: string): CustomElementConstructor | undefined;
77
+
78
+ /**
79
+ * `<usa-flip-list>` — animates its children to their new places whenever
80
+ * they are added, removed or reordered (FLIP: transforms only). Works with
81
+ * any rendering: plain DOM, React keyed lists, Vue `v-for`, Svelte `{#each}`.
82
+ *
83
+ * Attributes: `duration` (ms, 420), `easing`, `disabled`.
84
+ * Method: `flip(mutate)` for explicit changes (also measures resizes).
85
+ * Reduced motion: no animation.
86
+ */
87
+ interface UsaFlipListElement extends UsaElement {
88
+ flip(mutate: () => void | Promise<void>): Promise<void>;
89
+ }
90
+ declare function defineFlipList(tag?: string): CustomElementConstructor | undefined;
91
+
92
+ /**
93
+ * `<usa-view-switch>` — shows one of its children at a time (tabs, wizard
94
+ * steps, app pages) and animates between them. Children are views; name
95
+ * them with `data-view`, or address them by index.
96
+ *
97
+ * Attributes: `active` (view name or index, default the first),
98
+ * `effect` (`fade` | `slide` (default, direction-aware — Fluent "page
99
+ * transition") | `scale` | `drill`), `duration` (ms, 320). Inactive views
100
+ * get `hidden` + `inert`. Event: `usa:change` (`detail.view`,
101
+ * `detail.index`). Reduced motion: a quick fade.
102
+ */
103
+ interface UsaViewSwitchElement extends UsaElement {
104
+ active: string;
105
+ readonly views: HTMLElement[];
106
+ show(view: string | number): Promise<void>;
107
+ }
108
+ declare function defineViewSwitch(tag?: string): CustomElementConstructor | undefined;
109
+
110
+ interface ViewTransitionOptions {
111
+ /**
112
+ * Element to cross-fade when the View Transitions API is missing (default:
113
+ * none — the update is applied without animation).
114
+ */
115
+ fallback?: HTMLElement | null;
116
+ /** Fallback fade duration in ms (default 180 out + 220 in). */
117
+ duration?: number;
118
+ /** View transition types (`document.startViewTransition({ types })`, where supported). */
119
+ types?: string[];
120
+ }
121
+ /**
122
+ * Run `update()` (which changes the DOM) inside a view transition:
123
+ * `document.startViewTransition()` where available (Chrome/Edge 111+, so
124
+ * Electron, WebView2 and Tauri on Windows), otherwise a short cross-fade of
125
+ * `options.fallback`. Instant under reduced motion. Resolves when finished.
126
+ *
127
+ * Give elements a `view-transition-name` in CSS for shared-element morphs.
128
+ */
129
+ declare function viewTransition(update: () => void | Promise<void>, options?: ViewTransitionOptions): Promise<void>;
130
+ interface FlipOptions {
131
+ duration?: number;
132
+ easing?: string;
133
+ /** Fade/scale in elements that did not exist before (default true). */
134
+ animateEnter?: boolean;
135
+ }
136
+ type Targets = Element | Iterable<Element> | ArrayLike<Element>;
137
+ /**
138
+ * FLIP animation for layout changes (list reorder, filter, grid resize):
139
+ * measures `targets` (an element's children, or a list), runs `mutate()`,
140
+ * then animates each element from its old position to its new one with
141
+ * transforms only. Elements added by `mutate()` fade in.
142
+ *
143
+ * ```js
144
+ * await flip(list, () => list.append(...shuffled));
145
+ * ```
146
+ */
147
+ declare function flip(targets: Targets, mutate: () => void | Promise<void>, options?: FlipOptions): Promise<void>;
148
+ interface ConnectedOptions {
149
+ duration?: number;
150
+ easing?: string;
151
+ /** Hide `from` while the animation runs (default true). */
152
+ hideSource?: boolean;
153
+ }
154
+ /**
155
+ * Connected (shared-element) animation, like WinUI's
156
+ * `ConnectedAnimationService`: `to` flies from the position and size of
157
+ * `from` into its own place (e.g. a thumbnail opening into a detail view).
158
+ * Call it right after `to` is shown. Transforms only.
159
+ */
160
+ declare function connectedAnimation(from: Element, to: HTMLElement, options?: ConnectedOptions): Promise<void>;
161
+
162
+ /**
163
+ * use-scroll-animate/components/transitions — view & layout transitions.
164
+ * `<usa-dialog>`, `<usa-accordion>`, `<usa-flip-list>`, `<usa-view-switch>`
165
+ * and the `viewTransition()`, `flip()`, `connectedAnimation()` helpers.
166
+ */
167
+
168
+ /** Register every component of this category under its default tag. */
169
+ declare function defineTransitionComponents(): void;
170
+ declare global {
171
+ interface HTMLElementTagNameMap {
172
+ 'usa-dialog': UsaDialogElement;
173
+ 'usa-accordion': UsaAccordionElement;
174
+ 'usa-flip-list': UsaFlipListElement;
175
+ 'usa-view-switch': UsaViewSwitchElement;
176
+ }
177
+ }
178
+
179
+ export { configureComponents, connectedAnimation, defineAccordion, defineDialog, defineFlipList, defineTransitionComponents, defineViewSwitch, flip, prefersReducedMotion, viewTransition };
180
+ export type { ComponentsConfig, ConnectedOptions, DialogVariant, FlipOptions, UsaAccordionElement, UsaDialogElement, UsaElement, UsaFlipListElement, UsaViewSwitchElement, ViewTransitionOptions };
@@ -0,0 +1,180 @@
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
+ type DialogVariant = 'modal' | 'drawer-start' | 'drawer-end' | 'drawer-bottom' | 'sheet';
39
+ /**
40
+ * `<usa-dialog>` — an animated modal or drawer built on the native
41
+ * `<dialog>` (top layer, focus trapping, inert page, Esc to close). Its
42
+ * children are slotted into the panel (they stay in the light DOM, so
43
+ * React / Vue / Svelte keep owning them). Style with `::part(panel)`,
44
+ * `::part(backdrop)` and the `--usa-dialog-*` custom properties.
45
+ *
46
+ * Attributes: `open` (reflects; set/remove to open/close), `variant`
47
+ * (`modal` default — Fluent scale + fade; `drawer-start` / `drawer-end`
48
+ * slide from the side, `drawer-bottom` / `sheet` from below), `label`
49
+ * (accessible name), `no-backdrop-close`, `no-esc`. Elements inside
50
+ * with `data-close` close it. Events: `usa:open`, `usa:close` (cancelable
51
+ * `usa:beforeclose`). Reduced motion: fade only.
52
+ */
53
+ interface UsaDialogElement extends UsaElement {
54
+ open: boolean;
55
+ show(): Promise<void>;
56
+ close(returnValue?: string): Promise<void>;
57
+ readonly dialog: HTMLDialogElement | null;
58
+ returnValue: string;
59
+ }
60
+ declare function defineDialog(tag?: string): CustomElementConstructor | undefined;
61
+
62
+ /**
63
+ * `<usa-accordion>` — smooth expand / collapse for the native `<details>`
64
+ * elements inside it (keeps their semantics, keyboard support and
65
+ * find-in-page, and adds no wrapper elements, so framework-rendered content
66
+ * is left alone). Only one stays open unless `multiple` is set.
67
+ *
68
+ * Attributes: `multiple`, `duration` (ms, 300). Event: `usa:toggle`
69
+ * (`detail.details`, `detail.open`). Reduced motion: instant.
70
+ * Heights are measured once per toggle and animated on the `<details>`.
71
+ */
72
+ interface UsaAccordionElement extends UsaElement {
73
+ readonly items: HTMLDetailsElement[];
74
+ toggleItem(details: HTMLDetailsElement, open?: boolean): Promise<void>;
75
+ }
76
+ declare function defineAccordion(tag?: string): CustomElementConstructor | undefined;
77
+
78
+ /**
79
+ * `<usa-flip-list>` — animates its children to their new places whenever
80
+ * they are added, removed or reordered (FLIP: transforms only). Works with
81
+ * any rendering: plain DOM, React keyed lists, Vue `v-for`, Svelte `{#each}`.
82
+ *
83
+ * Attributes: `duration` (ms, 420), `easing`, `disabled`.
84
+ * Method: `flip(mutate)` for explicit changes (also measures resizes).
85
+ * Reduced motion: no animation.
86
+ */
87
+ interface UsaFlipListElement extends UsaElement {
88
+ flip(mutate: () => void | Promise<void>): Promise<void>;
89
+ }
90
+ declare function defineFlipList(tag?: string): CustomElementConstructor | undefined;
91
+
92
+ /**
93
+ * `<usa-view-switch>` — shows one of its children at a time (tabs, wizard
94
+ * steps, app pages) and animates between them. Children are views; name
95
+ * them with `data-view`, or address them by index.
96
+ *
97
+ * Attributes: `active` (view name or index, default the first),
98
+ * `effect` (`fade` | `slide` (default, direction-aware — Fluent "page
99
+ * transition") | `scale` | `drill`), `duration` (ms, 320). Inactive views
100
+ * get `hidden` + `inert`. Event: `usa:change` (`detail.view`,
101
+ * `detail.index`). Reduced motion: a quick fade.
102
+ */
103
+ interface UsaViewSwitchElement extends UsaElement {
104
+ active: string;
105
+ readonly views: HTMLElement[];
106
+ show(view: string | number): Promise<void>;
107
+ }
108
+ declare function defineViewSwitch(tag?: string): CustomElementConstructor | undefined;
109
+
110
+ interface ViewTransitionOptions {
111
+ /**
112
+ * Element to cross-fade when the View Transitions API is missing (default:
113
+ * none — the update is applied without animation).
114
+ */
115
+ fallback?: HTMLElement | null;
116
+ /** Fallback fade duration in ms (default 180 out + 220 in). */
117
+ duration?: number;
118
+ /** View transition types (`document.startViewTransition({ types })`, where supported). */
119
+ types?: string[];
120
+ }
121
+ /**
122
+ * Run `update()` (which changes the DOM) inside a view transition:
123
+ * `document.startViewTransition()` where available (Chrome/Edge 111+, so
124
+ * Electron, WebView2 and Tauri on Windows), otherwise a short cross-fade of
125
+ * `options.fallback`. Instant under reduced motion. Resolves when finished.
126
+ *
127
+ * Give elements a `view-transition-name` in CSS for shared-element morphs.
128
+ */
129
+ declare function viewTransition(update: () => void | Promise<void>, options?: ViewTransitionOptions): Promise<void>;
130
+ interface FlipOptions {
131
+ duration?: number;
132
+ easing?: string;
133
+ /** Fade/scale in elements that did not exist before (default true). */
134
+ animateEnter?: boolean;
135
+ }
136
+ type Targets = Element | Iterable<Element> | ArrayLike<Element>;
137
+ /**
138
+ * FLIP animation for layout changes (list reorder, filter, grid resize):
139
+ * measures `targets` (an element's children, or a list), runs `mutate()`,
140
+ * then animates each element from its old position to its new one with
141
+ * transforms only. Elements added by `mutate()` fade in.
142
+ *
143
+ * ```js
144
+ * await flip(list, () => list.append(...shuffled));
145
+ * ```
146
+ */
147
+ declare function flip(targets: Targets, mutate: () => void | Promise<void>, options?: FlipOptions): Promise<void>;
148
+ interface ConnectedOptions {
149
+ duration?: number;
150
+ easing?: string;
151
+ /** Hide `from` while the animation runs (default true). */
152
+ hideSource?: boolean;
153
+ }
154
+ /**
155
+ * Connected (shared-element) animation, like WinUI's
156
+ * `ConnectedAnimationService`: `to` flies from the position and size of
157
+ * `from` into its own place (e.g. a thumbnail opening into a detail view).
158
+ * Call it right after `to` is shown. Transforms only.
159
+ */
160
+ declare function connectedAnimation(from: Element, to: HTMLElement, options?: ConnectedOptions): Promise<void>;
161
+
162
+ /**
163
+ * use-scroll-animate/components/transitions — view & layout transitions.
164
+ * `<usa-dialog>`, `<usa-accordion>`, `<usa-flip-list>`, `<usa-view-switch>`
165
+ * and the `viewTransition()`, `flip()`, `connectedAnimation()` helpers.
166
+ */
167
+
168
+ /** Register every component of this category under its default tag. */
169
+ declare function defineTransitionComponents(): void;
170
+ declare global {
171
+ interface HTMLElementTagNameMap {
172
+ 'usa-dialog': UsaDialogElement;
173
+ 'usa-accordion': UsaAccordionElement;
174
+ 'usa-flip-list': UsaFlipListElement;
175
+ 'usa-view-switch': UsaViewSwitchElement;
176
+ }
177
+ }
178
+
179
+ export { configureComponents, connectedAnimation, defineAccordion, defineDialog, defineFlipList, defineTransitionComponents, defineViewSwitch, flip, prefersReducedMotion, viewTransition };
180
+ export type { ComponentsConfig, ConnectedOptions, DialogVariant, FlipOptions, UsaAccordionElement, UsaDialogElement, UsaElement, UsaFlipListElement, UsaViewSwitchElement, ViewTransitionOptions };