use-scroll-animate 4.5.0 → 4.7.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 +17 -0
- package/dist/components/angular.cjs +1 -0
- package/dist/components/angular.cjs.map +1 -1
- package/dist/components/angular.js +1 -0
- package/dist/components/angular.js.map +1 -1
- package/dist/components/bridge.cjs +154 -0
- package/dist/components/bridge.cjs.map +1 -0
- package/dist/components/bridge.d.cts +63 -0
- package/dist/components/bridge.d.ts +63 -0
- package/dist/components/bridge.js +147 -0
- package/dist/components/bridge.js.map +1 -0
- package/dist/components/lite.cjs +149 -0
- package/dist/components/lite.cjs.map +1 -1
- package/dist/components/lite.js +144 -1
- package/dist/components/lite.js.map +1 -1
- package/dist/components/solid.cjs +1 -0
- package/dist/components/solid.cjs.map +1 -1
- package/dist/components/solid.js +1 -0
- package/dist/components/solid.js.map +1 -1
- package/dist/components/svelte.cjs +1 -0
- package/dist/components/svelte.cjs.map +1 -1
- package/dist/components/svelte.js +1 -0
- package/dist/components/svelte.js.map +1 -1
- package/dist/components/vue.cjs +1 -0
- package/dist/components/vue.cjs.map +1 -1
- package/dist/components/vue.js +1 -0
- package/dist/components/vue.js.map +1 -1
- package/dist/components.cjs +7 -0
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +61 -2
- package/dist/components.d.ts +61 -2
- package/dist/components.js +1 -0
- package/dist/components.js.map +1 -1
- package/dist/components.umd.js +3 -2
- package/dist/components.umd.js.map +1 -1
- package/docs/ROADMAP.md +2 -2
- package/docs/hybrid-apps.md +15 -0
- package/package.json +11 -1
package/dist/components/lite.cjs
CHANGED
|
@@ -10094,6 +10094,149 @@ function auditMotionA11y(root) {
|
|
|
10094
10094
|
/** Every `<usa-*>` tag, for sweeping audits. */
|
|
10095
10095
|
const ALL_TAGS = Object.values(COMPONENT_CATEGORIES).flat();
|
|
10096
10096
|
|
|
10097
|
+
/**
|
|
10098
|
+
* use-scroll-animate/components/bridge — native shell bridges (4.7).
|
|
10099
|
+
*
|
|
10100
|
+
* Keeps the web UI in sync with the host app's system settings when it runs
|
|
10101
|
+
* inside **WinUI 3 / WPF (WebView2)**, **.NET MAUI** (WebView / HybridWebView)
|
|
10102
|
+
* or **Flutter** (webview_flutter / flutter_inappwebview): the native side
|
|
10103
|
+
* sends "reduce motion", light / dark / high-contrast theme and accent color;
|
|
10104
|
+
* the page applies them to every `<usa-*>` component.
|
|
10105
|
+
*
|
|
10106
|
+
* Protocol (JSON, both directions):
|
|
10107
|
+
* - native → web `{ "type": "usa:settings", "reducedMotion": true, "theme": "dark", "accent": "#0078d4", "sensitivity": "gentle" }`
|
|
10108
|
+
* - web → native `{ "type": "usa:ready", "version": 1 }` on connect, `{ "type": "usa:request-settings" }`
|
|
10109
|
+
*
|
|
10110
|
+
* Hosts that can only run script call `window.usaNative.apply({...})`.
|
|
10111
|
+
* Samples: examples/native/{winui3,maui,flutter}.
|
|
10112
|
+
*/
|
|
10113
|
+
const BRIDGE_PROTOCOL_VERSION = 1;
|
|
10114
|
+
const win = () => (typeof window === 'undefined' ? null : window);
|
|
10115
|
+
/** Which native shell (if any) hosts this page. */
|
|
10116
|
+
function detectNativeHost(channel = 'UsaBridge') {
|
|
10117
|
+
const w = win();
|
|
10118
|
+
if (!w)
|
|
10119
|
+
return 'browser';
|
|
10120
|
+
if (w.chrome?.webview?.postMessage)
|
|
10121
|
+
return 'webview2';
|
|
10122
|
+
if (w.HybridWebView?.SendRawMessage || w.HybridWebView?.SendRawMessageToDotNet || /\bMAUI\b/i.test(w.navigator?.userAgent || ''))
|
|
10123
|
+
return 'maui';
|
|
10124
|
+
if (w.flutter_inappwebview?.callHandler || w[channel]?.postMessage)
|
|
10125
|
+
return 'flutter';
|
|
10126
|
+
if (w.__TAURI__ || w.__TAURI_INTERNALS__)
|
|
10127
|
+
return 'tauri';
|
|
10128
|
+
if (w.process?.versions?.electron || /Electron\//.test(w.navigator?.userAgent || ''))
|
|
10129
|
+
return 'electron';
|
|
10130
|
+
return 'browser';
|
|
10131
|
+
}
|
|
10132
|
+
/** Send a JSON message to the native host (no-op in a plain browser). Returns whether it was sent. */
|
|
10133
|
+
function postToNative(message, channel = 'UsaBridge') {
|
|
10134
|
+
const w = win();
|
|
10135
|
+
if (!w)
|
|
10136
|
+
return false;
|
|
10137
|
+
const json = JSON.stringify(message);
|
|
10138
|
+
try {
|
|
10139
|
+
if (w.chrome?.webview?.postMessage)
|
|
10140
|
+
return w.chrome.webview.postMessage(message), true;
|
|
10141
|
+
if (w.HybridWebView?.SendRawMessage)
|
|
10142
|
+
return w.HybridWebView.SendRawMessage(json), true;
|
|
10143
|
+
if (w.HybridWebView?.SendRawMessageToDotNet)
|
|
10144
|
+
return w.HybridWebView.SendRawMessageToDotNet(json), true;
|
|
10145
|
+
if (w.flutter_inappwebview?.callHandler)
|
|
10146
|
+
return w.flutter_inappwebview.callHandler(channel, json), true;
|
|
10147
|
+
if (w[channel]?.postMessage)
|
|
10148
|
+
return w[channel].postMessage(json), true;
|
|
10149
|
+
}
|
|
10150
|
+
catch {
|
|
10151
|
+
/* host went away */
|
|
10152
|
+
}
|
|
10153
|
+
return false;
|
|
10154
|
+
}
|
|
10155
|
+
const THEMES = ['light', 'dark', 'high-contrast'];
|
|
10156
|
+
const COLOR = /^(#[0-9a-f]{3,8}|rgba?\([\d\s.,%]+\)|hsla?\([\d\s.,%deg]+\))$/i;
|
|
10157
|
+
/** Validate an incoming message (string or object); unknown fields are dropped. */
|
|
10158
|
+
function parseNativeSettings(data) {
|
|
10159
|
+
let d = data;
|
|
10160
|
+
if (typeof d === 'string') {
|
|
10161
|
+
try {
|
|
10162
|
+
d = JSON.parse(d);
|
|
10163
|
+
}
|
|
10164
|
+
catch {
|
|
10165
|
+
return null;
|
|
10166
|
+
}
|
|
10167
|
+
}
|
|
10168
|
+
if (!d || typeof d !== 'object' || d.type !== 'usa:settings')
|
|
10169
|
+
return null;
|
|
10170
|
+
const out = {};
|
|
10171
|
+
if (typeof d.reducedMotion === 'boolean')
|
|
10172
|
+
out.reducedMotion = d.reducedMotion;
|
|
10173
|
+
if (THEMES.includes(d.theme))
|
|
10174
|
+
out.theme = d.theme;
|
|
10175
|
+
if (typeof d.accent === 'string' && COLOR.test(d.accent.trim()))
|
|
10176
|
+
out.accent = d.accent.trim();
|
|
10177
|
+
if (MOTION_SENSITIVITY_LEVELS.includes(d.sensitivity))
|
|
10178
|
+
out.sensitivity = d.sensitivity;
|
|
10179
|
+
return out;
|
|
10180
|
+
}
|
|
10181
|
+
/**
|
|
10182
|
+
* Apply native settings: reduce motion → `configureComponents({ reducedMotion: 'reduce' })`
|
|
10183
|
+
* (`false` → follow the media query again); theme → `data-theme`, `data-usa-contrast`
|
|
10184
|
+
* and `color-scheme`; accent → `--usa-accent`; sensitivity → `motionSensitivity`.
|
|
10185
|
+
*/
|
|
10186
|
+
function applyNativeSettings(s, root) {
|
|
10187
|
+
if (s.reducedMotion !== undefined)
|
|
10188
|
+
configureComponents({ reducedMotion: s.reducedMotion ? 'reduce' : 'user' });
|
|
10189
|
+
if (s.sensitivity)
|
|
10190
|
+
configureComponents({ motionSensitivity: s.sensitivity });
|
|
10191
|
+
const el = root || (typeof document !== 'undefined' ? document.documentElement : null);
|
|
10192
|
+
if (!el)
|
|
10193
|
+
return;
|
|
10194
|
+
if (s.theme) {
|
|
10195
|
+
el.setAttribute('data-theme', s.theme === 'high-contrast' ? 'dark' : s.theme);
|
|
10196
|
+
el.toggleAttribute('data-usa-contrast', s.theme === 'high-contrast');
|
|
10197
|
+
el.style.colorScheme = s.theme === 'light' ? 'light' : 'dark';
|
|
10198
|
+
}
|
|
10199
|
+
if (s.accent)
|
|
10200
|
+
el.style.setProperty('--usa-accent', s.accent);
|
|
10201
|
+
if (typeof document !== 'undefined')
|
|
10202
|
+
document.dispatchEvent(new CustomEvent('usa:native-settings', { detail: s }));
|
|
10203
|
+
}
|
|
10204
|
+
/**
|
|
10205
|
+
* Connect to the native shell: listens for `usa:settings` messages
|
|
10206
|
+
* (WebView2 `chrome.webview` messages, `window.postMessage`, or
|
|
10207
|
+
* `window.usaNative.apply()`), applies them, then announces `usa:ready` and
|
|
10208
|
+
* asks for the current settings. Returns `{ host, disconnect }`.
|
|
10209
|
+
*/
|
|
10210
|
+
function connectNativeShell(options = {}) {
|
|
10211
|
+
const w = win();
|
|
10212
|
+
const channel = options.channel || 'UsaBridge';
|
|
10213
|
+
const host = detectNativeHost(channel);
|
|
10214
|
+
if (!w)
|
|
10215
|
+
return { host, disconnect: () => undefined };
|
|
10216
|
+
const handle = (data) => {
|
|
10217
|
+
const s = parseNativeSettings(data);
|
|
10218
|
+
if (!s)
|
|
10219
|
+
return;
|
|
10220
|
+
applyNativeSettings(s, options.root);
|
|
10221
|
+
options.onSettings?.(s, host);
|
|
10222
|
+
};
|
|
10223
|
+
const onMessage = (e) => handle(e.data);
|
|
10224
|
+
w.chrome?.webview?.addEventListener?.('message', onMessage);
|
|
10225
|
+
w.addEventListener?.('message', onMessage);
|
|
10226
|
+
const prev = w.usaNative;
|
|
10227
|
+
w.usaNative = { apply: (s) => handle({ ...s, type: 'usa:settings' }), version: BRIDGE_PROTOCOL_VERSION, host };
|
|
10228
|
+
postToNative({ type: 'usa:ready', version: BRIDGE_PROTOCOL_VERSION }, channel);
|
|
10229
|
+
postToNative({ type: 'usa:request-settings' }, channel);
|
|
10230
|
+
return {
|
|
10231
|
+
host,
|
|
10232
|
+
disconnect: () => {
|
|
10233
|
+
w.chrome?.webview?.removeEventListener?.('message', onMessage);
|
|
10234
|
+
w.removeEventListener?.('message', onMessage);
|
|
10235
|
+
w.usaNative = prev;
|
|
10236
|
+
},
|
|
10237
|
+
};
|
|
10238
|
+
}
|
|
10239
|
+
|
|
10097
10240
|
/**
|
|
10098
10241
|
* use-scroll-animate/components
|
|
10099
10242
|
*
|
|
@@ -10163,6 +10306,7 @@ onDemandStyles(STYLE_BASE);
|
|
|
10163
10306
|
exports.ALL_TAGS = ALL_TAGS;
|
|
10164
10307
|
exports.AMBIENT_EFFECTS = AMBIENT_EFFECTS;
|
|
10165
10308
|
exports.ANIM_ICONS = ANIM_ICONS;
|
|
10309
|
+
exports.BRIDGE_PROTOCOL_VERSION = BRIDGE_PROTOCOL_VERSION;
|
|
10166
10310
|
exports.BUTTON_DEFORMS = BUTTON_DEFORMS;
|
|
10167
10311
|
exports.CARD_EFFECTS = CARD_EFFECTS;
|
|
10168
10312
|
exports.CLICK_EFFECTS = CLICK_EFFECTS;
|
|
@@ -10195,6 +10339,7 @@ exports.adoptVariants = adoptVariants;
|
|
|
10195
10339
|
exports.animationBudget = animationBudget;
|
|
10196
10340
|
exports.announce = announce;
|
|
10197
10341
|
exports.applyMotionTokens = applyMotionTokens;
|
|
10342
|
+
exports.applyNativeSettings = applyNativeSettings;
|
|
10198
10343
|
exports.applyPack = applyPack;
|
|
10199
10344
|
exports.auditMotionA11y = auditMotionA11y;
|
|
10200
10345
|
exports.autoAnimate = autoAnimate;
|
|
@@ -10203,6 +10348,7 @@ exports.burst = burst;
|
|
|
10203
10348
|
exports.categoryOf = categoryOf;
|
|
10204
10349
|
exports.confetti = confetti;
|
|
10205
10350
|
exports.configureComponents = configureComponents;
|
|
10351
|
+
exports.connectNativeShell = connectNativeShell;
|
|
10206
10352
|
exports.countUp = countUp;
|
|
10207
10353
|
exports.createSpring = createSpring;
|
|
10208
10354
|
exports.defineAccordion = defineAccordion;
|
|
@@ -10311,6 +10457,7 @@ exports.defineViewSwitch = defineViewSwitch;
|
|
|
10311
10457
|
exports.defineWaterRipple = defineWaterRipple;
|
|
10312
10458
|
exports.defineWaveText = defineWaveText;
|
|
10313
10459
|
exports.defineWebglComponents = defineWebglComponents;
|
|
10460
|
+
exports.detectNativeHost = detectNativeHost;
|
|
10314
10461
|
exports.deviceTilt = deviceTilt;
|
|
10315
10462
|
exports.drawLines = drawLines;
|
|
10316
10463
|
exports.easeOutExpo = easeOutExpo;
|
|
@@ -10350,8 +10497,10 @@ exports.orientationToTilt = orientationToTilt;
|
|
|
10350
10497
|
exports.pageTransition = pageTransition;
|
|
10351
10498
|
exports.parseDuration = parseDuration;
|
|
10352
10499
|
exports.parseEasing = parseEasing;
|
|
10500
|
+
exports.parseNativeSettings = parseNativeSettings;
|
|
10353
10501
|
exports.pathsCompatible = pathsCompatible;
|
|
10354
10502
|
exports.pinchScale = pinchScale;
|
|
10503
|
+
exports.postToNative = postToNative;
|
|
10355
10504
|
exports.prefersReducedMotion = prefersReducedMotion;
|
|
10356
10505
|
exports.projectInertia = projectInertia;
|
|
10357
10506
|
exports.readScrollProgress = readScrollProgress;
|