use-scroll-animate 3.6.0 → 3.8.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.
@@ -0,0 +1,55 @@
1
+ import { defineComponents } from '../components.js';
2
+ import { b as bindUsa } from '../chunks/bind-B_CTL6Qn.js';
3
+ export { u as usaEventName } from '../chunks/bind-B_CTL6Qn.js';
4
+ import './reveal.js';
5
+ import '../chunks/base-BpROOcey.js';
6
+ import './text.js';
7
+ import './interaction.js';
8
+ import './feedback.js';
9
+ import './background.js';
10
+ import '../chunks/variants-CHe1VbSn.js';
11
+ import './transitions.js';
12
+ import './physics.js';
13
+ import '../chunks/spring-C-fw7_9f.js';
14
+ import './cards.js';
15
+ import './click.js';
16
+ import './ui.js';
17
+ import './page.js';
18
+ import './timeline.js';
19
+ import './gesture.js';
20
+ import '../chunks/core-uxs3ETou.js';
21
+ import './svg.js';
22
+ import './webgl.js';
23
+ import './depth.js';
24
+ import './layout.js';
25
+ import '../chunks/index-tags-BANJ-e4H.js';
26
+
27
+ /**
28
+ * use-scroll-animate/components/svelte — Svelte integration (v3.8).
29
+ * Svelte (3, 4, 5) renders `<usa-*>` tags natively; `use:usa` sets
30
+ * **properties** and `usa:*` listeners in one place, and `defineUsa()`
31
+ * registers the elements on the client only (safe in SvelteKit SSR).
32
+ *
33
+ * ```svelte
34
+ * <script>
35
+ * import { usa, defineUsa } from 'use-scroll-animate/components/svelte';
36
+ * import { onMount } from 'svelte';
37
+ * onMount(() => defineUsa(['click', 'ui']));
38
+ * let on = false;
39
+ * </script>
40
+ * <usa-toggle use:usa={{ props: { checked: on }, on: { change: (e) => (on = e.detail.checked) } }}></usa-toggle>
41
+ * ```
42
+ * Plain `on:usa:change` does not compile in Svelte 3/4 (colon); use the action or `onusa:change` in Svelte 5.
43
+ */
44
+ /** Svelte action: `use:usa={{ props, on }}`. */
45
+ function usa(node, binding = {}) {
46
+ return bindUsa(node, binding);
47
+ }
48
+ /** Register the elements (all, or some categories) — call from `onMount` for SSR apps. */
49
+ function defineUsa(categories) {
50
+ if (typeof window !== 'undefined')
51
+ defineComponents(categories);
52
+ }
53
+
54
+ export { bindUsa, defineUsa, usa };
55
+ //# sourceMappingURL=svelte.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svelte.js","sources":["../../src/components/frameworks/svelte.ts"],"sourcesContent":["/**\n * use-scroll-animate/components/svelte — Svelte integration (v3.8).\n * Svelte (3, 4, 5) renders `<usa-*>` tags natively; `use:usa` sets\n * **properties** and `usa:*` listeners in one place, and `defineUsa()`\n * registers the elements on the client only (safe in SvelteKit SSR).\n *\n * ```svelte\n * <script>\n * import { usa, defineUsa } from 'use-scroll-animate/components/svelte';\n * import { onMount } from 'svelte';\n * onMount(() => defineUsa(['click', 'ui']));\n * let on = false;\n * </script>\n * <usa-toggle use:usa={{ props: { checked: on }, on: { change: (e) => (on = e.detail.checked) } }}></usa-toggle>\n * ```\n * Plain `on:usa:change` does not compile in Svelte 3/4 (colon); use the action or `onusa:change` in Svelte 5.\n */\nimport { defineComponents, type ComponentCategory } from '../index';\nimport { bindUsa, type UsaBinding } from './bind';\n\nexport { bindUsa, usaEventName } from './bind';\nexport type { UsaBinding } from './bind';\n\n/** Svelte action: `use:usa={{ props, on }}`. */\nexport function usa(node: HTMLElement, binding: UsaBinding = {}): { update(b: UsaBinding): void; destroy(): void } {\n return bindUsa(node, binding);\n}\n\n/** Register the elements (all, or some categories) — call from `onMount` for SSR apps. */\nexport function defineUsa(categories?: ComponentCategory[]): void {\n if (typeof window !== 'undefined') defineComponents(categories);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;AAgBG;AAOH;SACgB,GAAG,CAAC,IAAiB,EAAE,UAAsB,EAAE,EAAA;AAC7D,IAAA,OAAO,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;AAC/B;AAEA;AACM,SAAU,SAAS,CAAC,UAAgC,EAAA;IACxD,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,gBAAgB,CAAC,UAAU,CAAC;AACjE;;;;"}
@@ -289,6 +289,20 @@ Fallbacks set `data-fallback` (`webgl` · `image` · `no-image`); cross-origin i
289
289
 
290
290
  Also see `flip()` / `connectedAnimation()` / `<usa-flip-list>` in `components/transitions`.
291
291
 
292
+ ### v3.7 Visual playground
293
+
294
+ [`showcase/playground.html`](../showcase/playground.html) — stack `<usa-*>` effects around sample content, tweak every attribute live, and export HTML / ES module / React / Vue code or a share link (state in the URL hash).
295
+
296
+ ### v3.8 Svelte, Solid & Angular
297
+
298
+ | Entry | API |
299
+ |---|---|
300
+ | `components/svelte` | `use:usa={{ props, on }}`, `defineUsa()` |
301
+ | `components/solid` | `use:usa` directive, `defineUsa()`, JSX types (`prop:` / `on:usa:*` natively) |
302
+ | `components/angular` | `usaInitializer()` (`APP_INITIALIZER`), `defineUsa()`, `usaDetail()`; `CUSTOM_ELEMENTS_SCHEMA` |
303
+
304
+ Hybrid / desktop hosts (MAUI, Flutter WebView, Electron, Tauri): [hybrid-apps.md](./hybrid-apps.md).
305
+
292
306
  ## Frameworks
293
307
 
294
308
  Custom elements work in every framework. Register once (e.g. in your entry file), then use the tags.
@@ -62,3 +62,39 @@ Custom elements work as-is: Svelte (`on:usa:change`), Solid (`on:usa:change`, `p
62
62
 
63
63
  ## Lazy registration
64
64
  `lazyDefine()` (from `use-scroll-animate/components/lazy`) watches the DOM and dynamically imports only the categories whose tags appear — a page with just `<usa-button>` loads the click chunk only.
65
+
66
+ ## Svelte / SvelteKit (v3.8)
67
+
68
+ ```svelte
69
+ <script>
70
+ import { onMount } from 'svelte';
71
+ import { usa, defineUsa } from 'use-scroll-animate/components/svelte';
72
+ onMount(() => defineUsa());
73
+ let on = false;
74
+ </script>
75
+ <usa-toggle use:usa={{ props: { checked: on }, on: { change: (e) => (on = e.detail.checked) } }}></usa-toggle>
76
+ ```
77
+
78
+ ## Solid / SolidStart (v3.8)
79
+
80
+ ```tsx
81
+ import { onMount } from 'solid-js';
82
+ import { defineUsa } from 'use-scroll-animate/components/solid';
83
+ onMount(() => defineUsa());
84
+ <usa-toggle prop:checked={on()} on:usa:change={(e) => setOn(e.detail.checked)} />;
85
+ ```
86
+
87
+ ## Angular (v3.8)
88
+
89
+ ```ts
90
+ import { APP_INITIALIZER, CUSTOM_ELEMENTS_SCHEMA, Component } from '@angular/core';
91
+ import { usaInitializer, usaDetail } from 'use-scroll-animate/components/angular';
92
+ // app.config.ts
93
+ providers: [{ provide: APP_INITIALIZER, multi: true, useFactory: usaInitializer() }];
94
+ // component
95
+ @Component({ standalone: true, schemas: [CUSTOM_ELEMENTS_SCHEMA],
96
+ template: `<usa-toggle [checked]="on" (usa:change)="on = detail($event).checked"></usa-toggle>` })
97
+ export class Settings { on = false; detail = usaDetail; }
98
+ ```
99
+
100
+ MAUI, Flutter WebView, Electron and Tauri: see [hybrid-apps.md](./hybrid-apps.md).
@@ -0,0 +1,130 @@
1
+ # Hybrid & desktop apps: MAUI, Flutter WebView, Electron, Tauri
2
+
3
+ `<usa-*>` components are plain Web Components (Custom Elements + CSS + Web Animations): anything that hosts a modern web view can run them, with **no bundler** if you want — copy `dist/components.umd.js` (and optionally `dist/components.css`) next to your HTML. For WinUI 3 / WPF / WinForms with WebView2 see [windows-apps.md](./windows-apps.md).
4
+
5
+ General rules for every host:
6
+
7
+ - **Load locally, not from a CDN**, so the app works offline and passes store review: ship `components.umd.js` as an asset and reference it with a relative URL.
8
+ - **Strict CSP is fine**: styles are adopted as constructable stylesheets. If you load `components.css` yourself, call `configureComponents({ injectStyles: false })`.
9
+ - **Reduced motion follows the OS** (`prefers-reduced-motion`) inside every web view listed here. To mirror an in-app setting, call `setMotionIntensity('off' | 'low' | 'normal' | 'high')` (or `configureComponents({ reducedMotion: 'reduce' })`) from the native side.
10
+ - **Performance**: canvas / WebGL effects (`<usa-shader>`, `<usa-liquid>`, backgrounds) render only while visible and cap DPR at 2; they fall back to CSS where WebGL is unavailable (some Android web views).
11
+ - **Native ↔ web**: listen to `usa:*` events in JS and forward them over the host bridge (examples below).
12
+
13
+ ## .NET MAUI
14
+
15
+ MAUI 9+ has `HybridWebView` (raw HTML + JS bridge); `BlazorWebView` also works (Razor renders the tags; enable the elements in `wwwroot/index.html`).
16
+
17
+ ```text
18
+ Resources/Raw/wwwroot/
19
+ index.html
20
+ components.umd.js ← copied from node_modules/use-scroll-animate/dist/
21
+ ```
22
+
23
+ ```xml
24
+ <!-- MainPage.xaml -->
25
+ <HybridWebView x:Name="Web" DefaultFile="index.html" RawMessageReceived="OnMessage" />
26
+ ```
27
+
28
+ ```html
29
+ <!-- Resources/Raw/wwwroot/index.html -->
30
+ <script src="components.umd.js"></script>
31
+ <script src="_framework/hybridwebview.js"></script>
32
+ <usa-toggle id="t"></usa-toggle>
33
+ <script>
34
+ document.getElementById('t').addEventListener('usa:change', (e) =>
35
+ window.HybridWebView.SendRawMessage(JSON.stringify({ checked: e.detail.checked })));
36
+ </script>
37
+ ```
38
+
39
+ ```csharp
40
+ void OnMessage(object s, HybridWebViewRawMessageReceivedEventArgs e) => Debug.WriteLine(e.Message);
41
+ // native → web
42
+ await Web.EvaluateJavaScriptAsync("UsaComponents.setMotionIntensity('low')");
43
+ ```
44
+
45
+ Notes: Android uses the system WebView (Chromium) — keep it updated; iOS / Mac Catalyst use WKWebView (Safari engine), where `linear()` spring easings fall back to cubic-bezier automatically.
46
+
47
+ ## Flutter (webview_flutter / flutter_inappwebview)
48
+
49
+ ```yaml
50
+ # pubspec.yaml
51
+ dependencies:
52
+ webview_flutter: ^4.10.0
53
+ flutter:
54
+ assets:
55
+ - assets/web/index.html
56
+ - assets/web/components.umd.js
57
+ ```
58
+
59
+ ```dart
60
+ final controller = WebViewController()
61
+ ..setJavaScriptMode(JavaScriptMode.unrestricted)
62
+ ..addJavaScriptChannel('Usa', onMessageReceived: (m) => debugPrint(m.message))
63
+ ..loadFlutterAsset('assets/web/index.html');
64
+
65
+ // native → web (e.g. follow the platform's "reduce motion" setting)
66
+ final reduce = MediaQuery.of(context).disableAnimations;
67
+ controller.runJavaScript("UsaComponents.setMotionIntensity('${reduce ? 'off' : 'normal'}')");
68
+ ```
69
+
70
+ ```html
71
+ <!-- assets/web/index.html -->
72
+ <script src="components.umd.js"></script>
73
+ <usa-like id="like"></usa-like>
74
+ <script>
75
+ document.getElementById('like').addEventListener('usa:change', (e) => Usa.postMessage(JSON.stringify(e.detail)));
76
+ </script>
77
+ ```
78
+
79
+ `loadFlutterAsset` serves from a `file://`-like origin; ES-module builds (`components.js`) need an HTTP origin, so prefer the UMD file here. On Flutter Web you can use the components directly in `web/index.html` via `HtmlElementView`.
80
+
81
+ ## Electron
82
+
83
+ The renderer is Chromium — use the npm package with your bundler, or the UMD file without one.
84
+
85
+ ```js
86
+ // renderer.js (bundled)
87
+ import { defineComponents, configureComponents } from 'use-scroll-animate/components';
88
+ configureComponents({ injectStyles: true });
89
+ defineComponents();
90
+ ```
91
+
92
+ ```js
93
+ // main.js — keep contextIsolation on; expose only what you need
94
+ new BrowserWindow({ webPreferences: { preload: path.join(__dirname, 'preload.js'), contextIsolation: true, sandbox: true } });
95
+ ```
96
+
97
+ ```js
98
+ // preload.js — forward component events to the main process
99
+ const { contextBridge, ipcRenderer } = require('electron');
100
+ contextBridge.exposeInMainWorld('usaBridge', { send: (type, detail) => ipcRenderer.send('usa', type, detail) });
101
+ ```
102
+
103
+ Imports are SSR-safe (no `window` access at import time), so the same modules can be imported in preload scripts.
104
+
105
+ ## Tauri (v2)
106
+
107
+ ```js
108
+ // src/main.js (Vite)
109
+ import { defineComponents } from 'use-scroll-animate/components';
110
+ import { invoke } from '@tauri-apps/api/core';
111
+ defineComponents();
112
+ document.querySelector('usa-toggle').addEventListener('usa:change', (e) => invoke('set_setting', { on: e.detail.checked }));
113
+ ```
114
+
115
+ ```json
116
+ // tauri.conf.json — a strict CSP works (constructable stylesheets)
117
+ { "app": { "security": { "csp": "default-src 'self'; style-src 'self'; script-src 'self'" } } }
118
+ ```
119
+
120
+ Tauri uses WebView2 on Windows, WKWebView on macOS / iOS and WebKitGTK on Linux. WebKitGTK may disable WebGL on some drivers: WebGL components then set `data-fallback="webgl"` and show their CSS fallback.
121
+
122
+ ## Framework wrappers
123
+
124
+ | Framework | Entry | What it gives you |
125
+ |---|---|---|
126
+ | React | `use-scroll-animate/components/react` | `createUsaComponents(React)` typed wrappers |
127
+ | Vue | `use-scroll-animate/components/vue` | `UsaPlugin`, `isUsaElement` |
128
+ | Svelte | `use-scroll-animate/components/svelte` | `use:usa={{ props, on }}` action, `defineUsa()` |
129
+ | Solid | `use-scroll-animate/components/solid` | `use:usa` directive, `defineUsa()`, JSX types |
130
+ | Angular | `use-scroll-animate/components/angular` | `usaInitializer()` for `APP_INITIALIZER`, `usaDetail()`; use `CUSTOM_ELEMENTS_SCHEMA` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-scroll-animate",
3
- "version": "3.6.0",
3
+ "version": "3.8.0",
4
4
  "description": "A lightweight, high-performance, dependency-free scroll animation library and animated UI components (Web Components) for the web and Windows web-view apps.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -268,6 +268,36 @@
268
268
  "default": "./dist/components/vue.cjs"
269
269
  }
270
270
  },
271
+ "./components/svelte": {
272
+ "import": {
273
+ "types": "./dist/components/svelte.d.ts",
274
+ "default": "./dist/components/svelte.js"
275
+ },
276
+ "require": {
277
+ "types": "./dist/components/svelte.d.cts",
278
+ "default": "./dist/components/svelte.cjs"
279
+ }
280
+ },
281
+ "./components/solid": {
282
+ "import": {
283
+ "types": "./dist/components/solid.d.ts",
284
+ "default": "./dist/components/solid.js"
285
+ },
286
+ "require": {
287
+ "types": "./dist/components/solid.d.cts",
288
+ "default": "./dist/components/solid.cjs"
289
+ }
290
+ },
291
+ "./components/angular": {
292
+ "import": {
293
+ "types": "./dist/components/angular.d.ts",
294
+ "default": "./dist/components/angular.js"
295
+ },
296
+ "require": {
297
+ "types": "./dist/components/angular.d.cts",
298
+ "default": "./dist/components/angular.cjs"
299
+ }
300
+ },
271
301
  "./components/jsx": {
272
302
  "import": {
273
303
  "types": "./dist/components/jsx.d.ts",