use-scroll-animate 2.6.0 → 2.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.
- package/CHANGELOG.md +27 -0
- package/README.md +3 -2
- package/README_ja.md +3 -2
- package/README_zh.md +3 -2
- package/dist/chunks/{base-5DFCAnvH.cjs → base-BR6fYLBA.cjs} +23 -2
- package/dist/chunks/base-BR6fYLBA.cjs.map +1 -0
- package/dist/chunks/{base-08OYzphB.js → base-C_w9ibbn.js} +21 -3
- package/dist/chunks/base-C_w9ibbn.js.map +1 -0
- package/dist/chunks/{spring-CpeFkxNd.js → spring-Dc8ZqDWE.js} +3 -3
- package/dist/chunks/spring-Dc8ZqDWE.js.map +1 -0
- package/dist/chunks/{spring-Bi4qY0pL.cjs → spring-DyHe1Hfa.cjs} +3 -3
- package/dist/chunks/spring-DyHe1Hfa.cjs.map +1 -0
- package/dist/chunks/variants-Bbatdq8d.cjs +39 -0
- package/dist/chunks/variants-Bbatdq8d.cjs.map +1 -0
- package/dist/chunks/variants-idgMVXhE.js +35 -0
- package/dist/chunks/variants-idgMVXhE.js.map +1 -0
- package/dist/components/background.cjs +277 -11
- package/dist/components/background.cjs.map +1 -1
- package/dist/components/background.css +2 -0
- package/dist/components/background.d.cts +71 -2
- package/dist/components/background.d.ts +71 -2
- package/dist/components/background.js +274 -13
- package/dist/components/background.js.map +1 -1
- package/dist/components/cards.cjs +2 -2
- package/dist/components/cards.d.cts +8 -0
- package/dist/components/cards.d.ts +8 -0
- package/dist/components/cards.js +3 -3
- package/dist/components/click.cjs +2 -2
- package/dist/components/click.d.cts +8 -0
- package/dist/components/click.d.ts +8 -0
- package/dist/components/click.js +3 -3
- package/dist/components/feedback.cjs +1 -1
- package/dist/components/feedback.d.cts +8 -0
- package/dist/components/feedback.d.ts +8 -0
- package/dist/components/feedback.js +2 -2
- package/dist/components/interaction.cjs +1 -1
- package/dist/components/interaction.d.cts +8 -0
- package/dist/components/interaction.d.ts +8 -0
- package/dist/components/interaction.js +2 -2
- package/dist/components/page.cjs +801 -0
- package/dist/components/page.cjs.map +1 -0
- package/dist/components/page.css +11 -0
- package/dist/components/page.d.cts +275 -0
- package/dist/components/page.d.ts +275 -0
- package/dist/components/page.js +776 -0
- package/dist/components/page.js.map +1 -0
- package/dist/components/physics.cjs +2 -2
- package/dist/components/physics.d.cts +8 -0
- package/dist/components/physics.d.ts +8 -0
- package/dist/components/physics.js +4 -4
- package/dist/components/reveal.cjs +1 -1
- package/dist/components/reveal.d.cts +8 -0
- package/dist/components/reveal.d.ts +8 -0
- package/dist/components/reveal.js +2 -2
- package/dist/components/text.cjs +180 -11
- package/dist/components/text.cjs.map +1 -1
- package/dist/components/text.css +1 -0
- package/dist/components/text.d.cts +62 -2
- package/dist/components/text.d.ts +62 -2
- package/dist/components/text.js +177 -13
- package/dist/components/text.js.map +1 -1
- package/dist/components/transitions.cjs +1 -1
- package/dist/components/transitions.d.cts +8 -0
- package/dist/components/transitions.d.ts +8 -0
- package/dist/components/transitions.js +2 -2
- package/dist/components/ui.cjs +18 -48
- package/dist/components/ui.cjs.map +1 -1
- package/dist/components/ui.d.cts +8 -0
- package/dist/components/ui.d.ts +8 -0
- package/dist/components/ui.js +6 -35
- package/dist/components/ui.js.map +1 -1
- package/dist/components.cjs +45 -8
- package/dist/components.cjs.map +1 -1
- package/dist/components.css +12 -0
- package/dist/components.d.cts +354 -4
- package/dist/components.d.ts +354 -4
- package/dist/components.js +16 -10
- package/dist/components.js.map +1 -1
- package/dist/components.umd.js +2 -2
- package/dist/components.umd.js.map +1 -1
- package/docs/components.md +34 -0
- package/docs/windows-apps.md +11 -0
- package/package.json +13 -2
- package/dist/chunks/base-08OYzphB.js.map +0 -1
- package/dist/chunks/base-5DFCAnvH.cjs.map +0 -1
- package/dist/chunks/spring-Bi4qY0pL.cjs.map +0 -1
- package/dist/chunks/spring-CpeFkxNd.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [2.8.0] - 2026-10-07
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- **Text effects** (in `components/text`): `<usa-wave-text>` (travelling letter wave), `<usa-glitch>` (RGB-split slice glitch, always / hover), `<usa-gradient-text>` (flowing multi-colour gradient fill), `<usa-handwriting>` (text draws itself stroke by stroke, then fills; `usa:complete`), `<usa-scroll-highlight>` (words light up as you read down the page, or `mode="marker"` highlighter sweep). Animated copies are `aria-hidden` with a plain screen-reader copy.
|
|
14
|
+
- **Backgrounds** (in `components/background`): `<usa-grid-glow>` (line grid lit around the pointer), `<usa-blobs>` (fluid morphing colour blobs), `<usa-water-ripple>` (interactive canvas water ripples, `drop(x, y)`), `<usa-dot-network>` (dot grid that swells and links to the pointer). Canvas effects run only while visible and the tab is shown, DPR ≤ 2.
|
|
15
|
+
- **Windows Fluent preset** `fluentPreset({ reveal, mica, selector })` (in `components/background`): `fluent` variant page-wide (Segoe UI Variable, Windows 11 accent, radii), Mica-style window tint, Acrylic on `.usa-acrylic` / `[data-acrylic]`, and **Reveal highlight** on buttons / `[data-fluent-reveal]`; returns an undo function.
|
|
16
|
+
- **WinUI 3 + WebView2 sample app** in [`examples/webview2-winui/`](./examples/webview2-winui/) (Windows App SDK, native Mica backdrop, `SetVirtualHostNameToFolderMapping`, `components.umd.js` + `fluentPreset()`), documented in `docs/windows-apps.md`.
|
|
17
|
+
- Reduced motion: wave / glitch / gradient flow stop, handwriting and highlights appear complete, backgrounds are static, no Reveal tracking; reduced transparency keeps materials solid.
|
|
18
|
+
- Showcase: the new text and background demos in their categories, plus a `fluentPreset()` card.
|
|
19
|
+
|
|
20
|
+
## [2.7.0] - 2026-10-07
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
- **Page & app-wide effects** — new category `use-scroll-animate/components/page` (+ `components/page.css`):
|
|
24
|
+
- **Page transitions** on the View Transitions API: `pageTransition(update, { effect })` for SPA route changes — `fade`, `slide` / `slide-left` / `slide-right` / `slide-up`, `circle` (reveal from the click point), `blinds`, `pixel` (stepped dissolve), `zoom`; `enableMpaTransitions(effect)` for multi-page sites (`@view-transition { navigation: auto }`); `themeTransition(apply)` circle-reveal theme switch. Falls back to an instant update (optional cross-fade) without View Transitions.
|
|
25
|
+
- `<usa-cursor mode="dot | trail | magnetic | glow">` custom cursors (fine pointers only, `hide-native`).
|
|
26
|
+
- `smoothScroll()` (inertial wheel smoothing, touch/keyboard stay native) and `scrollToTarget()` (spring timing).
|
|
27
|
+
- `<usa-fullpage>` full-screen snapping sections with keyboard paging and dot navigation.
|
|
28
|
+
- `<usa-loading-bar>` + `loadingBar.start() / set() / done() / track(promise)` top loading bar (the scroll progress bar remains `<usa-scroll-progress>`).
|
|
29
|
+
- `<usa-back-to-top>` with a reading-progress ring, spring scroll and focus return.
|
|
30
|
+
- `<usa-ambient effect="particles | snow | stars | noise | gradient">` page-wide ambient layer (scroll-driven gradient, canvas paused in hidden tabs).
|
|
31
|
+
- `<usa-splash>` launch / splash screen (`fade`, `scale`, `slide-up`, `circle` exit; `min` duration; `manual` + `done()`).
|
|
32
|
+
- `<usa-auto-skeleton loading>` automatic skeletons from the existing markup.
|
|
33
|
+
- **Global motion intensity**: `setMotionIntensity('off' | 'low' | 'normal' | 'high', persist?)`, `restoreMotionIntensity()`, `getMotionIntensity()`, `configureComponents({ motionIntensity })` and the `<usa-motion-switch>` control. It scales every component animation (and `spring()`), sets `--usa-motion` / `data-usa-motion` on `<html>`, and `off` behaves like `prefers-reduced-motion`.
|
|
34
|
+
- Reduced motion: transitions update instantly, no cursor / smooth scrolling / ambient animation, instant jumps.
|
|
35
|
+
- Showcase: **Page & app-wide** category with live page-transition, theme reveal, cursor, ambient, splash, loading-bar, auto-skeleton, fullpage and motion-intensity demos.
|
|
36
|
+
|
|
10
37
|
## [2.6.0] - 2026-10-07
|
|
11
38
|
|
|
12
39
|
### Added
|
package/README.md
CHANGED
|
@@ -45,15 +45,16 @@ defineComponents(); // or per category: import { defineTextComponents } from 'us
|
|
|
45
45
|
| Category (import) | Components |
|
|
46
46
|
|---|---|
|
|
47
47
|
| **Entrance & scroll** (`/components/reveal`) | `<usa-reveal>` (12 effects) · `<usa-stagger>` · `<usa-scroll-progress>` · `<usa-scrolly>` (sticky scrollytelling) |
|
|
48
|
-
| **Text** (`/components/text`) | `<usa-typewriter>` · `<usa-split-text>` · `<usa-scramble>` · `<usa-counter>` · `<usa-shimmer-text>` · `<usa-text-rotate>` |
|
|
48
|
+
| **Text** (`/components/text`) | `<usa-typewriter>` · `<usa-split-text>` · `<usa-scramble>` · `<usa-counter>` · `<usa-shimmer-text>` · `<usa-text-rotate>` · `<usa-wave-text>` · `<usa-glitch>` · `<usa-gradient-text>` · `<usa-handwriting>` · `<usa-scroll-highlight>` |
|
|
49
49
|
| **Interaction** (`/components/interaction`) | `<usa-ripple>` · `<usa-magnetic>` · `<usa-tilt>` · `<usa-spotlight>` (Fluent reveal highlight) · `<usa-press>` · `<usa-toggle>` |
|
|
50
50
|
| **Loading & feedback** (`/components/feedback`) | `<usa-spinner>` (WinUI ring, Windows dots, ring, dots, pulse, bars) · `<usa-skeleton>` · `<usa-progress>` · `<usa-toaster>` + `toast()` · `<usa-check>` |
|
|
51
|
-
| **Background & decoration** (`/components/background`) | `<usa-aurora>` · `<usa-particles>` · `<usa-grain>` · `<usa-marquee>` · `<usa-acrylic>` (Acrylic / Mica) |
|
|
51
|
+
| **Background & decoration** (`/components/background`) | `<usa-aurora>` · `<usa-particles>` · `<usa-grain>` · `<usa-marquee>` · `<usa-acrylic>` (Acrylic / Mica) · `<usa-grid-glow>` · `<usa-blobs>` · `<usa-water-ripple>` · `<usa-dot-network>` · `fluentPreset()` (Mica · Acrylic · Reveal) |
|
|
52
52
|
| **Transitions** (`/components/transitions`) | `<usa-dialog>` (modal / drawer / sheet) · `<usa-accordion>` · `<usa-flip-list>` · `<usa-view-switch>` · `viewTransition()` · `flip()` · `connectedAnimation()` |
|
|
53
53
|
| **Spring & physics** (`/components/physics`) | `<usa-spring>` (bounce-in · pop · drop · jelly · rubber-band) · `<usa-draggable>` (spring-back · inertia · snap) · `<usa-overscroll>` · `spring()` · `createSpring()` · `SPRING_PRESETS` |
|
|
54
54
|
| **Card effects** (`/components/cards`) | `<usa-card>` (flip · holo · glass · border-glow · conic-border · lift · spotlight · sheen · parallax-layers · expand — combinable) · `<usa-card-stack>` (swipe) · `<usa-sticky-stack>` · `<usa-carousel-3d>` |
|
|
55
55
|
| **Click & tap** (`/components/click`) | `<usa-button>` **button click deformation** (squash · wobble · gooey · dent · shape morph · submit→loading→success) · `<usa-icon-morph>` · `<usa-click>` (ripple · burst · confetti · squish · press-spring · shake) · `<usa-like>` · `<usa-hold>` · `<usa-double-tap>` · `<usa-checkbox>` · `confetti()` · `haptic()` |
|
|
56
56
|
| **UI components & variants** (`/components/ui`) | `<usa-tabs>` · `<usa-drawer>` · `<usa-bottom-sheet>` · `<usa-pull-refresh>` · `<usa-fab>` · `<usa-navbar>` · `<usa-slider>` · `<usa-rating>` · `<usa-tooltip>` · `<usa-popover>` · `<usa-badge>` · `<usa-avatar-stack>` · `variant="minimal \| neon \| glass \| brutalist \| fluent \| material"` on every component |
|
|
57
|
+
| **Page & app-wide** (`/components/page`) | `pageTransition()` (fade · slide · circle · blinds · pixel · zoom; SPA + MPA) · `themeTransition()` · `<usa-cursor>` · `smoothScroll()` · `<usa-fullpage>` · `<usa-loading-bar>` · `<usa-back-to-top>` · `<usa-ambient>` (particles · snow · stars · noise · gradient) · `<usa-splash>` · `<usa-auto-skeleton>` · `<usa-motion-switch>` / `setMotionIntensity()` |
|
|
57
58
|
|
|
58
59
|
Whole bundle ≈ 22 kB gzip (JS + CSS); one category 3.5–6.4 kB; a single component ≈ 2 kB. The scroll-animation core below is unaffected.
|
|
59
60
|
|
package/README_ja.md
CHANGED
|
@@ -35,15 +35,16 @@ defineComponents(); // カテゴリ単位: import { defineTextComponents } from
|
|
|
35
35
|
| カテゴリ(インポート) | コンポーネント |
|
|
36
36
|
|---|---|
|
|
37
37
|
| **入場・スクロール**(`/components/reveal`) | `<usa-reveal>` · `<usa-stagger>` · `<usa-scroll-progress>` · `<usa-scrolly>` |
|
|
38
|
-
| **テキスト**(`/components/text`) | `<usa-typewriter>` · `<usa-split-text>` · `<usa-scramble>` · `<usa-counter>` · `<usa-shimmer-text>` · `<usa-text-rotate>` |
|
|
38
|
+
| **テキスト**(`/components/text`) | `<usa-typewriter>` · `<usa-split-text>` · `<usa-scramble>` · `<usa-counter>` · `<usa-shimmer-text>` · `<usa-text-rotate>` · `<usa-wave-text>` · `<usa-glitch>` · `<usa-gradient-text>` · `<usa-handwriting>` · `<usa-scroll-highlight>` |
|
|
39
39
|
| **インタラクション**(`/components/interaction`) | `<usa-ripple>` · `<usa-magnetic>` · `<usa-tilt>` · `<usa-spotlight>`(Fluent Reveal)· `<usa-press>` · `<usa-toggle>` |
|
|
40
40
|
| **ローディング・フィードバック**(`/components/feedback`) | `<usa-spinner>` · `<usa-skeleton>` · `<usa-progress>` · `<usa-toaster>` + `toast()` · `<usa-check>` |
|
|
41
|
-
| **背景・装飾**(`/components/background`) | `<usa-aurora>` · `<usa-particles>` · `<usa-grain>` · `<usa-marquee>` · `<usa-acrylic>`(Acrylic / Mica) |
|
|
41
|
+
| **背景・装飾**(`/components/background`) | `<usa-aurora>` · `<usa-particles>` · `<usa-grain>` · `<usa-marquee>` · `<usa-acrylic>`(Acrylic / Mica) · `<usa-grid-glow>` · `<usa-blobs>` · `<usa-water-ripple>` · `<usa-dot-network>` · `fluentPreset()` |
|
|
42
42
|
| **トランジション**(`/components/transitions`) | `<usa-dialog>` · `<usa-accordion>` · `<usa-flip-list>` · `<usa-view-switch>` · `viewTransition()` · `flip()` · `connectedAnimation()` |
|
|
43
43
|
| **スプリング・物理**(`/components/physics`) | `<usa-spring>`(bounce-in · pop · drop · jelly · rubber-band)· `<usa-draggable>` · `<usa-overscroll>` · `spring()` · `createSpring()` |
|
|
44
44
|
| **カード効果**(`/components/cards`) | `<usa-card>`(flip · holo · glass · border-glow · conic-border · lift · spotlight · sheen · parallax-layers · expand)· `<usa-card-stack>` · `<usa-sticky-stack>` · `<usa-carousel-3d>` |
|
|
45
45
|
| **クリック・タップ**(`/components/click`) | `<usa-button>`(squash · wobble · gooey · dent · shape morph · submit)· `<usa-icon-morph>` · `<usa-click>` · `<usa-like>` · `<usa-hold>` · `<usa-double-tap>` · `<usa-checkbox>` |
|
|
46
46
|
| **UI コンポーネント・バリアント**(`/components/ui`) | `<usa-tabs>` · `<usa-drawer>` · `<usa-bottom-sheet>` · `<usa-pull-refresh>` · `<usa-fab>` · `<usa-navbar>` · `<usa-slider>` · `<usa-rating>` · `<usa-tooltip>` · `<usa-popover>` · `<usa-badge>` · `<usa-avatar-stack>` · 全コンポーネントで `variant` |
|
|
47
|
+
| **ページ・アプリ全体**(`/components/page`) | `pageTransition()` · `themeTransition()` · `<usa-cursor>` · `smoothScroll()` · `<usa-fullpage>` · `<usa-loading-bar>` · `<usa-back-to-top>` · `<usa-ambient>` · `<usa-splash>` · `<usa-auto-skeleton>` · `<usa-motion-switch>` |
|
|
47
48
|
|
|
48
49
|
## ドキュメント
|
|
49
50
|
|
package/README_zh.md
CHANGED
|
@@ -44,15 +44,16 @@ defineComponents(); // 或按分类:import { defineTextComponents } from 'use-
|
|
|
44
44
|
| 分类(导入路径) | 组件 |
|
|
45
45
|
|---|---|
|
|
46
46
|
| **入场与滚动**(`/components/reveal`) | `<usa-reveal>` 滚动揭示(12 种效果)· `<usa-stagger>` 错峰列表 · `<usa-scroll-progress>` 阅读进度条 · `<usa-scrolly>` 粘性滚动叙事 |
|
|
47
|
-
| **文字**(`/components/text`) | `<usa-typewriter>` 打字机 · `<usa-split-text>` 逐字揭示 · `<usa-scramble>` 乱码解码 · `<usa-counter>` 数字滚动 · `<usa-shimmer-text>` 流光文字 · `<usa-text-rotate>` 轮换词语 |
|
|
47
|
+
| **文字**(`/components/text`) | `<usa-typewriter>` 打字机 · `<usa-split-text>` 逐字揭示 · `<usa-scramble>` 乱码解码 · `<usa-counter>` 数字滚动 · `<usa-shimmer-text>` 流光文字 · `<usa-text-rotate>` 轮换词语 · `<usa-wave-text>` 波浪 · `<usa-glitch>` 故障 · `<usa-gradient-text>` 流动渐变 · `<usa-handwriting>` 手写 · `<usa-scroll-highlight>` 滚动高亮 |
|
|
48
48
|
| **交互反馈**(`/components/interaction`) | `<usa-ripple>` 水波纹 · `<usa-magnetic>` 磁吸按钮 · `<usa-tilt>` 3D 倾斜卡片 · `<usa-spotlight>` Fluent 光照高亮 · `<usa-press>` 按压反馈 · `<usa-toggle>` 切换开关 |
|
|
49
49
|
| **加载与反馈**(`/components/feedback`) | `<usa-spinner>`(WinUI 进度环、Windows 圆点等 6 种)· `<usa-skeleton>` 骨架屏 · `<usa-progress>` 进度条 · `<usa-toaster>` + `toast()` 通知 · `<usa-check>` 结果图标 |
|
|
50
|
-
| **背景与装饰**(`/components/background`) | `<usa-aurora>` 极光 · `<usa-particles>` 粒子 · `<usa-grain>` 胶片颗粒 · `<usa-marquee>` 无限跑马灯 · `<usa-acrylic>` 亚克力 / 云母材质 |
|
|
50
|
+
| **背景与装饰**(`/components/background`) | `<usa-aurora>` 极光 · `<usa-particles>` 粒子 · `<usa-grain>` 胶片颗粒 · `<usa-marquee>` 无限跑马灯 · `<usa-acrylic>` 亚克力 / 云母材质 · `<usa-grid-glow>` 网格光晕 · `<usa-blobs>` 流体色块 · `<usa-water-ripple>` 水波 · `<usa-dot-network>` 点阵 · `fluentPreset()` Fluent 预设 |
|
|
51
51
|
| **过渡动画**(`/components/transitions`) | `<usa-dialog>` 弹窗 / 抽屉 / 底部面板 · `<usa-accordion>` 手风琴 · `<usa-flip-list>` FLIP 列表 · `<usa-view-switch>` 视图切换 · `viewTransition()` · `flip()` · `connectedAnimation()` |
|
|
52
52
|
| **弹簧与物理**(`/components/physics`) | `<usa-spring>` 弹入 / 弹出 / 掉落 / 果冻 / 橡皮筋 · `<usa-draggable>` 拖拽回弹、惯性、吸附 · `<usa-overscroll>` 弹性越界 · `spring()` · `createSpring()` · 预设 gentle / wobbly / stiff / bouncy |
|
|
53
53
|
| **卡片效果**(`/components/cards`) | `<usa-card>` 翻转 · 全息 · 玻璃 · 边框光晕 · 流光边框 · 悬浮 · 聚光 · 扫光 · 视差分层 · 展开详情(可组合)· `<usa-card-stack>` 滑动卡堆 · `<usa-sticky-stack>` 滚动堆叠 · `<usa-carousel-3d>` 3D 轮播 |
|
|
54
54
|
| **点击与轻触**(`/components/click`) | `<usa-button>` 按钮点击形变(挤压拉伸 · 弹性圆角 · 液态粘滞 · 按压凹陷 · 形状变形 · 提交→加载→成功)· `<usa-icon-morph>` 图标变形 · `<usa-click>` 水波纹 / 迸发 / 彩带 / 抖动 · `<usa-like>` · `<usa-hold>` · `<usa-double-tap>` · `<usa-checkbox>` |
|
|
55
55
|
| **UI 组件与风格变体**(`/components/ui`) | `<usa-tabs>` 标签页 · `<usa-drawer>` 抽屉 · `<usa-bottom-sheet>` 底部面板 · `<usa-pull-refresh>` 下拉刷新 · `<usa-fab>` 悬浮按钮 · `<usa-navbar>` 自动隐藏导航栏 · `<usa-slider>` 滑块 · `<usa-rating>` 评分 · `<usa-tooltip>` · `<usa-popover>` · `<usa-badge>` · `<usa-avatar-stack>` · 所有组件均支持 `variant`(极简 / 霓虹 / 玻璃 / 粗野 / Fluent / Material) |
|
|
56
|
+
| **页面与全局效果**(`/components/page`) | `pageTransition()` 页面切换(淡入 · 滑动 · 圆形揭示 · 百叶窗 · 像素溶解,单页 + 多页)· `themeTransition()` 主题圆形切换 · `<usa-cursor>` 自定义光标 · `smoothScroll()` · `<usa-fullpage>` 整屏 · `<usa-loading-bar>` · `<usa-back-to-top>` · `<usa-ambient>` 雪花 / 星空 / 噪点 · `<usa-splash>` 启动屏 · `<usa-auto-skeleton>` 自动骨架屏 · `<usa-motion-switch>` 动效强度 |
|
|
56
57
|
|
|
57
58
|
完整包约 22 kB gzip(JS + CSS);单个分类 3.5–6.4 kB;单个组件约 2 kB。下方的滚动动画核心不受影响。
|
|
58
59
|
|
|
@@ -8,14 +8,29 @@
|
|
|
8
8
|
* imported during SSR (Next, Nuxt, Astro…) and in Electron/Tauri preload
|
|
9
9
|
* scripts. Classes are created the first time a `define*()` function runs.
|
|
10
10
|
*/
|
|
11
|
-
const
|
|
11
|
+
const MOTION_SCALE = { off: 0, low: 0.6, normal: 1, high: 1.25 };
|
|
12
|
+
const config = { injectStyles: true, reducedMotion: 'user', motionIntensity: 'normal' };
|
|
12
13
|
/** Change global component settings (call before `define*()` for `injectStyles`). */
|
|
13
14
|
function configureComponents(options) {
|
|
14
15
|
Object.assign(config, options);
|
|
16
|
+
if (options.motionIntensity && typeof document !== 'undefined') {
|
|
17
|
+
document.documentElement.style.setProperty('--usa-motion', String(MOTION_SCALE[options.motionIntensity] ?? 1));
|
|
18
|
+
document.documentElement.setAttribute('data-usa-motion', options.motionIntensity);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** The current global motion intensity. */
|
|
22
|
+
function getMotionIntensity() {
|
|
23
|
+
return config.motionIntensity;
|
|
24
|
+
}
|
|
25
|
+
/** Duration multiplier for the current intensity (1 when `normal`). */
|
|
26
|
+
function motionScale() {
|
|
27
|
+
return MOTION_SCALE[config.motionIntensity] ?? 1;
|
|
15
28
|
}
|
|
16
29
|
const canDefine = () => typeof customElements !== 'undefined' && typeof HTMLElement !== 'undefined';
|
|
17
30
|
/** `true` when animations should be reduced (OS setting or `configureComponents`). */
|
|
18
31
|
function prefersReducedMotion() {
|
|
32
|
+
if (config.motionIntensity === 'off')
|
|
33
|
+
return true;
|
|
19
34
|
if (config.reducedMotion !== 'user')
|
|
20
35
|
return config.reducedMotion === 'reduce';
|
|
21
36
|
return typeof matchMedia === 'function' && !!matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
@@ -156,6 +171,9 @@ function getBase() {
|
|
|
156
171
|
applyFrame(el, keyframes[keyframes.length - 1]);
|
|
157
172
|
return null;
|
|
158
173
|
}
|
|
174
|
+
const k = motionScale();
|
|
175
|
+
if (k !== 1 && k > 0 && typeof options.duration === 'number')
|
|
176
|
+
options = { ...options, duration: options.duration * k, delay: (options.delay || 0) * k };
|
|
159
177
|
return el.animate(keyframes, options);
|
|
160
178
|
}
|
|
161
179
|
emit(type, detail) {
|
|
@@ -220,6 +238,7 @@ const clamp = (v, min, max) => Math.min(max, Math.max(min, v));
|
|
|
220
238
|
exports.EASE_OUT = EASE_OUT;
|
|
221
239
|
exports.EASE_SPRING = EASE_SPRING;
|
|
222
240
|
exports.FLUENT_DECELERATE = FLUENT_DECELERATE;
|
|
241
|
+
exports.MOTION_SCALE = MOTION_SCALE;
|
|
223
242
|
exports.adoptStyles = adoptStyles;
|
|
224
243
|
exports.applyFrame = applyFrame;
|
|
225
244
|
exports.caf = caf;
|
|
@@ -227,9 +246,11 @@ exports.canDefine = canDefine;
|
|
|
227
246
|
exports.clamp = clamp;
|
|
228
247
|
exports.configureComponents = configureComponents;
|
|
229
248
|
exports.defineElement = defineElement;
|
|
249
|
+
exports.getMotionIntensity = getMotionIntensity;
|
|
250
|
+
exports.motionScale = motionScale;
|
|
230
251
|
exports.now = now;
|
|
231
252
|
exports.prefersReducedMotion = prefersReducedMotion;
|
|
232
253
|
exports.raf = raf;
|
|
233
254
|
exports.shadowStyles = shadowStyles;
|
|
234
255
|
exports.srText = srText;
|
|
235
|
-
//# sourceMappingURL=base-
|
|
256
|
+
//# sourceMappingURL=base-BR6fYLBA.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-BR6fYLBA.cjs","sources":["../../src/components/base.ts"],"sourcesContent":["/**\n * use-scroll-animate/components — shared base for the `<usa-*>` custom elements.\n *\n * Everything here is lazy: nothing touches `window`, `document`,\n * `HTMLElement` or `matchMedia` at import time, so the components can be\n * imported during SSR (Next, Nuxt, Astro…) and in Electron/Tauri preload\n * scripts. Classes are created the first time a `define*()` function runs.\n */\n\nexport interface ComponentsConfig {\n /**\n * Inject each component's CSS when it is defined (default `true`). Uses a\n * constructable stylesheet (`document.adoptedStyleSheets`, which a strict\n * `style-src` CSP does not block) and falls back to a `<style>` tag. Set\n * to `false` when you load `use-scroll-animate/components.css` yourself.\n */\n injectStyles?: boolean;\n /**\n * `'user'` (default) follows `prefers-reduced-motion`; `'reduce'` always\n * uses the reduced variants (e.g. a kiosk / battery-saver mode);\n * `'no-preference'` ignores the OS setting (only for demos — respect your users).\n */\n reducedMotion?: 'user' | 'reduce' | 'no-preference';\n /**\n * Global motion intensity (v2.7): `'off'` (same as reduced motion),\n * `'low'` (shorter, calmer), `'normal'` (default) or `'high'`. Scales every\n * component animation's duration and sets `--usa-motion` (0 / 0.6 / 1 /\n * 1.25) on `<html>` for your own CSS. See `setMotionIntensity()`.\n */\n motionIntensity?: MotionIntensity;\n}\n\nexport type MotionIntensity = 'off' | 'low' | 'normal' | 'high';\nexport const MOTION_SCALE: Record<MotionIntensity, number> = { off: 0, low: 0.6, normal: 1, high: 1.25 };\n\nconst config: Required<ComponentsConfig> = { injectStyles: true, reducedMotion: 'user', motionIntensity: 'normal' };\n\n/** Change global component settings (call before `define*()` for `injectStyles`). */\nexport function configureComponents(options: ComponentsConfig): void {\n Object.assign(config, options);\n if (options.motionIntensity && typeof document !== 'undefined') {\n document.documentElement.style.setProperty('--usa-motion', String(MOTION_SCALE[options.motionIntensity] ?? 1));\n document.documentElement.setAttribute('data-usa-motion', options.motionIntensity);\n }\n}\n\n/** The current global motion intensity. */\nexport function getMotionIntensity(): MotionIntensity {\n return config.motionIntensity;\n}\n\n/** Duration multiplier for the current intensity (1 when `normal`). */\nexport function motionScale(): number {\n return MOTION_SCALE[config.motionIntensity] ?? 1;\n}\n\nexport const canDefine = (): boolean => typeof customElements !== 'undefined' && typeof HTMLElement !== 'undefined';\n\n/** `true` when animations should be reduced (OS setting or `configureComponents`). */\nexport function prefersReducedMotion(): boolean {\n if (config.motionIntensity === 'off') return true;\n if (config.reducedMotion !== 'user') return config.reducedMotion === 'reduce';\n return typeof matchMedia === 'function' && !!matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n\nconst injected = new Set<string>();\n\n/** Add a component's stylesheet to the document once. */\nexport function adoptStyles(id: string, css: string): void {\n if (!config.injectStyles || !css || injected.has(id) || typeof document === 'undefined') return;\n injected.add(id);\n try {\n if (typeof CSSStyleSheet === 'function' && 'adoptedStyleSheets' in document) {\n const sheet = new CSSStyleSheet();\n sheet.replaceSync(css);\n document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];\n return;\n }\n } catch {\n /* fall through to <style> */\n }\n const style = document.createElement('style');\n style.setAttribute('data-usa', id);\n style.textContent = css;\n (document.head || document.documentElement).appendChild(style);\n}\n\n/** Attach `css` to a shadow root (constructable sheet where supported, else `<style>`). */\nexport function shadowStyles(root: ShadowRoot, css: string): void {\n try {\n if (typeof CSSStyleSheet === 'function' && 'adoptedStyleSheets' in root) {\n const sheet = new CSSStyleSheet();\n sheet.replaceSync(css);\n root.adoptedStyleSheets = [sheet];\n return;\n }\n } catch {\n /* fall through */\n }\n const style = document.createElement('style');\n style.textContent = css;\n root.prepend(style);\n}\n\nexport type Cleanup = () => void;\n\n/**\n * Members shared by every `<usa-*>` element. Attribute helpers, a cleanup\n * bag that is emptied on disconnect, and motion helpers that degrade to the\n * final state without WAAPI or under reduced motion.\n */\nexport interface UsaElement extends HTMLElement {\n /** `true` while reduced motion applies to this element. */\n readonly reduced: boolean;\n}\n\nexport interface UsaBase extends UsaElement {\n mount(): void;\n changed(name: string): void;\n unmount(): void;\n str(name: string, fallback?: string): string;\n num(name: string, fallback: number): number;\n flag(name: string): boolean;\n setFlag(name: string, on: boolean): void;\n onCleanup(fn: Cleanup): void;\n listen<K extends keyof HTMLElementEventMap>(\n target: EventTarget,\n type: K | string,\n fn: (e: any) => void,\n options?: AddEventListenerOptions\n ): void;\n inView(cb: (visible: boolean, entry?: IntersectionObserverEntry) => void, init?: IntersectionObserverInit, target?: Element): void;\n motion(el: Element, keyframes: Keyframe[], options: KeyframeAnimationOptions): Animation | null;\n emit(type: string, detail?: unknown): boolean;\n}\n\ntype BaseCtor = new () => UsaBase;\nlet baseClass: BaseCtor | null = null;\n\n/** The lazily created base class (needs `HTMLElement`). */\nexport function getBase(): BaseCtor {\n if (baseClass) return baseClass;\n class Base extends HTMLElement {\n private _cleanups: Cleanup[] = [];\n private _connected = false;\n\n get reduced(): boolean {\n return prefersReducedMotion();\n }\n\n connectedCallback(): void {\n if (this._connected) return;\n this._connected = true;\n // Upgraded while the parser is still inside us (a <script> in <head>\n // defined the element): children/text are not there yet, so wait.\n if (typeof document !== 'undefined' && document.readyState === 'loading' && !this.nextSibling && !this.childNodes.length) {\n const go = () => {\n if (this._connected && this.isConnected) this.mount();\n };\n document.addEventListener('DOMContentLoaded', go, { once: true });\n this._cleanups.push(() => document.removeEventListener('DOMContentLoaded', go));\n return;\n }\n this.mount();\n }\n\n disconnectedCallback(): void {\n this._connected = false;\n this.teardown();\n }\n\n attributeChangedCallback(_name: string, oldValue: string | null, value: string | null): void {\n if (!this._connected || oldValue === value) return;\n this.changed(_name);\n }\n\n /** Re-mount on attribute change (override for finer updates). */\n changed(_name: string): void {\n this.teardown();\n this.mount();\n }\n\n private teardown(): void {\n this._cleanups.splice(0).reverse().forEach((fn) => fn());\n this.unmount();\n }\n\n mount(): void {}\n unmount(): void {}\n\n str(name: string, fallback = ''): string {\n const v = this.getAttribute(name);\n return v === null ? fallback : v;\n }\n\n num(name: string, fallback: number): number {\n const v = this.getAttribute(name);\n const n = v === null || v.trim() === '' ? NaN : Number(v);\n return Number.isFinite(n) ? n : fallback;\n }\n\n /** Boolean attribute: present and not `\"false\"`. */\n flag(name: string): boolean {\n const v = this.getAttribute(name);\n return v !== null && v !== 'false';\n }\n\n setFlag(name: string, on: boolean): void {\n if (on) this.setAttribute(name, '');\n else this.removeAttribute(name);\n }\n\n onCleanup(fn: Cleanup): void {\n this._cleanups.push(fn);\n }\n\n listen(target: EventTarget, type: string, fn: (e: any) => void, options?: AddEventListenerOptions): void {\n target.addEventListener(type, fn, options);\n this.onCleanup(() => target.removeEventListener(type, fn, options));\n }\n\n /** Calls `cb(true/false)` as the element enters / leaves the viewport. */\n inView(cb: (visible: boolean, entry?: IntersectionObserverEntry) => void, init?: IntersectionObserverInit, target: Element = this): void {\n if (typeof IntersectionObserver === 'undefined') {\n cb(true);\n return;\n }\n const io = new IntersectionObserver((entries) => {\n for (const e of entries) cb(e.isIntersecting, e);\n }, init);\n io.observe(target);\n this.onCleanup(() => io.disconnect());\n }\n\n /** `el.animate()` that returns `null` (and applies the last frame) without WAAPI. */\n motion(el: Element, keyframes: Keyframe[], options: KeyframeAnimationOptions): Animation | null {\n if (typeof (el as HTMLElement).animate !== 'function') {\n applyFrame(el as HTMLElement, keyframes[keyframes.length - 1]);\n return null;\n }\n const k = motionScale();\n if (k !== 1 && k > 0 && typeof options.duration === 'number') options = { ...options, duration: options.duration * k, delay: (options.delay || 0) * k };\n return (el as HTMLElement).animate(keyframes, options);\n }\n\n emit(type: string, detail?: unknown): boolean {\n return this.dispatchEvent(new CustomEvent(`usa:${type}`, { detail, bubbles: true, cancelable: true }));\n }\n }\n baseClass = Base as unknown as BaseCtor;\n return baseClass;\n}\n\n/** Write a keyframe's properties as inline styles (no-WAAPI fallback). */\nexport function applyFrame(el: HTMLElement, frame?: Keyframe): void {\n if (!frame) return;\n for (const [k, v] of Object.entries(frame)) {\n if (k === 'offset' || k === 'easing' || k === 'composite' || v == null) continue;\n (el.style as any)[k] = String(v);\n }\n}\n\n/**\n * Register `tag` with the class built by `make(Base)`. Returns the\n * constructor, the already registered one, or `undefined` without DOM.\n */\nexport function defineElement(\n tag: string,\n make: (Base: BaseCtor) => CustomElementConstructor,\n css?: { id: string; text: string }\n): CustomElementConstructor | undefined {\n if (!canDefine()) return undefined;\n adoptStyles('base', BASE_CSS);\n if (css) adoptStyles(css.id, css.text);\n const existing = customElements.get(tag);\n if (existing) return existing;\n const ctor = make(getBase());\n customElements.define(tag, ctor);\n return ctor;\n}\n\nconst BASE_CSS = '.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}';\n\n/** A visually hidden copy of `text` for screen readers (the animated copy is `aria-hidden`). */\nexport function srText(text: string): HTMLSpanElement {\n const s = document.createElement('span');\n s.className = 'usa-sr';\n s.textContent = text;\n return s;\n}\n\n/** requestAnimationFrame with a timeout fallback (jsdom / hidden documents). */\nexport const raf = (cb: FrameRequestCallback): number =>\n typeof requestAnimationFrame === 'function' ? requestAnimationFrame(cb) : (setTimeout(() => cb(Date.now()), 16) as unknown as number);\n/** Monotonic time in ms (rAF callback timestamps differ between environments, so loops use this). */\nexport const now = (): number => (typeof performance !== 'undefined' ? performance.now() : Date.now());\nexport const caf = (id: number): void => {\n if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(id);\n else clearTimeout(id);\n};\n\n/** Spring-ish easing used across the components. */\nexport const EASE_OUT = 'cubic-bezier(0.22, 1, 0.36, 1)';\nexport const EASE_SPRING = 'cubic-bezier(0.34, 1.56, 0.64, 1)';\n/** Windows Fluent \"decelerate\" / \"point-to-point\" curves. */\nexport const FLUENT_DECELERATE = 'cubic-bezier(0.1, 0.9, 0.2, 1)';\n\nexport const clamp = (v: number, min: number, max: number): number => Math.min(max, Math.max(min, v));\n"],"names":[],"mappings":";;AAAA;;;;;;;AAOG;MA0BU,YAAY,GAAoC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI;AAEtG,MAAM,MAAM,GAA+B,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE;AAEnH;AACM,SAAU,mBAAmB,CAAC,OAAyB,E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AQ,GAAG,2JAA2J;AAE5K;AACM,SAAU,MAAM,CAAC,IAAY,EAAA;IACjC,MAAM,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC;AACxC,IAAA,CAAC,CAAC,SAAS,GAAG,QAAQ;AACtB,IAAA,CAAC,CAAC,WAAW,GAAG,IAAI;AACpB,IAAA,OAAO,CAAC;AACV;AAEA;AACO,MAAM,GAAG,GAAG,CAAC,EAAwB,KAC1C,OAAO,qBAAqB,KAAK,UAAU,GAAG,qBAAqB,CAAC,EAAE,CAAC,GAAI,UAAU,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;AAChH;AACO,MAAM,GAAG,GAAG,OAAe,OAAO,WAAW,KAAK,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE;AAC9F,MAAM,GAAG,GAAG,CAAC,EAAU,KAAU;IACtC,IAAI,OAAO,oBAAoB,KAAK,UAAU;QAAE,oBAAoB,CAAC,EAAE,CAAC;;QACnE,YAAY,CAAC,EAAE,CAAC;AACvB;AAEA;AACO,MAAM,QAAQ,GAAG;AACjB,MAAM,WAAW,GAAG;AAC3B;AACO,MAAM,iBAAiB,GAAG;AAE1B,MAAM,KAAK,GAAG,CAAC,CAAS,EAAE,GAAW,EAAE,GAAW,KAAa,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -6,14 +6,29 @@
|
|
|
6
6
|
* imported during SSR (Next, Nuxt, Astro…) and in Electron/Tauri preload
|
|
7
7
|
* scripts. Classes are created the first time a `define*()` function runs.
|
|
8
8
|
*/
|
|
9
|
-
const
|
|
9
|
+
const MOTION_SCALE = { off: 0, low: 0.6, normal: 1, high: 1.25 };
|
|
10
|
+
const config = { injectStyles: true, reducedMotion: 'user', motionIntensity: 'normal' };
|
|
10
11
|
/** Change global component settings (call before `define*()` for `injectStyles`). */
|
|
11
12
|
function configureComponents(options) {
|
|
12
13
|
Object.assign(config, options);
|
|
14
|
+
if (options.motionIntensity && typeof document !== 'undefined') {
|
|
15
|
+
document.documentElement.style.setProperty('--usa-motion', String(MOTION_SCALE[options.motionIntensity] ?? 1));
|
|
16
|
+
document.documentElement.setAttribute('data-usa-motion', options.motionIntensity);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** The current global motion intensity. */
|
|
20
|
+
function getMotionIntensity() {
|
|
21
|
+
return config.motionIntensity;
|
|
22
|
+
}
|
|
23
|
+
/** Duration multiplier for the current intensity (1 when `normal`). */
|
|
24
|
+
function motionScale() {
|
|
25
|
+
return MOTION_SCALE[config.motionIntensity] ?? 1;
|
|
13
26
|
}
|
|
14
27
|
const canDefine = () => typeof customElements !== 'undefined' && typeof HTMLElement !== 'undefined';
|
|
15
28
|
/** `true` when animations should be reduced (OS setting or `configureComponents`). */
|
|
16
29
|
function prefersReducedMotion() {
|
|
30
|
+
if (config.motionIntensity === 'off')
|
|
31
|
+
return true;
|
|
17
32
|
if (config.reducedMotion !== 'user')
|
|
18
33
|
return config.reducedMotion === 'reduce';
|
|
19
34
|
return typeof matchMedia === 'function' && !!matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
@@ -154,6 +169,9 @@ function getBase() {
|
|
|
154
169
|
applyFrame(el, keyframes[keyframes.length - 1]);
|
|
155
170
|
return null;
|
|
156
171
|
}
|
|
172
|
+
const k = motionScale();
|
|
173
|
+
if (k !== 1 && k > 0 && typeof options.duration === 'number')
|
|
174
|
+
options = { ...options, duration: options.duration * k, delay: (options.delay || 0) * k };
|
|
157
175
|
return el.animate(keyframes, options);
|
|
158
176
|
}
|
|
159
177
|
emit(type, detail) {
|
|
@@ -215,5 +233,5 @@ const EASE_SPRING = 'cubic-bezier(0.34, 1.56, 0.64, 1)';
|
|
|
215
233
|
const FLUENT_DECELERATE = 'cubic-bezier(0.1, 0.9, 0.2, 1)';
|
|
216
234
|
const clamp = (v, min, max) => Math.min(max, Math.max(min, v));
|
|
217
235
|
|
|
218
|
-
export { EASE_OUT as E, FLUENT_DECELERATE as F, configureComponents as a, clamp as b, canDefine as c, defineElement as d, caf as e, EASE_SPRING as f,
|
|
219
|
-
//# sourceMappingURL=base-
|
|
236
|
+
export { EASE_OUT as E, FLUENT_DECELERATE as F, MOTION_SCALE as M, configureComponents as a, clamp as b, canDefine as c, defineElement as d, caf as e, EASE_SPRING as f, getMotionIntensity as g, adoptStyles as h, shadowStyles as i, applyFrame as j, motionScale as m, now as n, prefersReducedMotion as p, raf as r, srText as s };
|
|
237
|
+
//# sourceMappingURL=base-C_w9ibbn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-C_w9ibbn.js","sources":["../../src/components/base.ts"],"sourcesContent":["/**\n * use-scroll-animate/components — shared base for the `<usa-*>` custom elements.\n *\n * Everything here is lazy: nothing touches `window`, `document`,\n * `HTMLElement` or `matchMedia` at import time, so the components can be\n * imported during SSR (Next, Nuxt, Astro…) and in Electron/Tauri preload\n * scripts. Classes are created the first time a `define*()` function runs.\n */\n\nexport interface ComponentsConfig {\n /**\n * Inject each component's CSS when it is defined (default `true`). Uses a\n * constructable stylesheet (`document.adoptedStyleSheets`, which a strict\n * `style-src` CSP does not block) and falls back to a `<style>` tag. Set\n * to `false` when you load `use-scroll-animate/components.css` yourself.\n */\n injectStyles?: boolean;\n /**\n * `'user'` (default) follows `prefers-reduced-motion`; `'reduce'` always\n * uses the reduced variants (e.g. a kiosk / battery-saver mode);\n * `'no-preference'` ignores the OS setting (only for demos — respect your users).\n */\n reducedMotion?: 'user' | 'reduce' | 'no-preference';\n /**\n * Global motion intensity (v2.7): `'off'` (same as reduced motion),\n * `'low'` (shorter, calmer), `'normal'` (default) or `'high'`. Scales every\n * component animation's duration and sets `--usa-motion` (0 / 0.6 / 1 /\n * 1.25) on `<html>` for your own CSS. See `setMotionIntensity()`.\n */\n motionIntensity?: MotionIntensity;\n}\n\nexport type MotionIntensity = 'off' | 'low' | 'normal' | 'high';\nexport const MOTION_SCALE: Record<MotionIntensity, number> = { off: 0, low: 0.6, normal: 1, high: 1.25 };\n\nconst config: Required<ComponentsConfig> = { injectStyles: true, reducedMotion: 'user', motionIntensity: 'normal' };\n\n/** Change global component settings (call before `define*()` for `injectStyles`). */\nexport function configureComponents(options: ComponentsConfig): void {\n Object.assign(config, options);\n if (options.motionIntensity && typeof document !== 'undefined') {\n document.documentElement.style.setProperty('--usa-motion', String(MOTION_SCALE[options.motionIntensity] ?? 1));\n document.documentElement.setAttribute('data-usa-motion', options.motionIntensity);\n }\n}\n\n/** The current global motion intensity. */\nexport function getMotionIntensity(): MotionIntensity {\n return config.motionIntensity;\n}\n\n/** Duration multiplier for the current intensity (1 when `normal`). */\nexport function motionScale(): number {\n return MOTION_SCALE[config.motionIntensity] ?? 1;\n}\n\nexport const canDefine = (): boolean => typeof customElements !== 'undefined' && typeof HTMLElement !== 'undefined';\n\n/** `true` when animations should be reduced (OS setting or `configureComponents`). */\nexport function prefersReducedMotion(): boolean {\n if (config.motionIntensity === 'off') return true;\n if (config.reducedMotion !== 'user') return config.reducedMotion === 'reduce';\n return typeof matchMedia === 'function' && !!matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n\nconst injected = new Set<string>();\n\n/** Add a component's stylesheet to the document once. */\nexport function adoptStyles(id: string, css: string): void {\n if (!config.injectStyles || !css || injected.has(id) || typeof document === 'undefined') return;\n injected.add(id);\n try {\n if (typeof CSSStyleSheet === 'function' && 'adoptedStyleSheets' in document) {\n const sheet = new CSSStyleSheet();\n sheet.replaceSync(css);\n document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];\n return;\n }\n } catch {\n /* fall through to <style> */\n }\n const style = document.createElement('style');\n style.setAttribute('data-usa', id);\n style.textContent = css;\n (document.head || document.documentElement).appendChild(style);\n}\n\n/** Attach `css` to a shadow root (constructable sheet where supported, else `<style>`). */\nexport function shadowStyles(root: ShadowRoot, css: string): void {\n try {\n if (typeof CSSStyleSheet === 'function' && 'adoptedStyleSheets' in root) {\n const sheet = new CSSStyleSheet();\n sheet.replaceSync(css);\n root.adoptedStyleSheets = [sheet];\n return;\n }\n } catch {\n /* fall through */\n }\n const style = document.createElement('style');\n style.textContent = css;\n root.prepend(style);\n}\n\nexport type Cleanup = () => void;\n\n/**\n * Members shared by every `<usa-*>` element. Attribute helpers, a cleanup\n * bag that is emptied on disconnect, and motion helpers that degrade to the\n * final state without WAAPI or under reduced motion.\n */\nexport interface UsaElement extends HTMLElement {\n /** `true` while reduced motion applies to this element. */\n readonly reduced: boolean;\n}\n\nexport interface UsaBase extends UsaElement {\n mount(): void;\n changed(name: string): void;\n unmount(): void;\n str(name: string, fallback?: string): string;\n num(name: string, fallback: number): number;\n flag(name: string): boolean;\n setFlag(name: string, on: boolean): void;\n onCleanup(fn: Cleanup): void;\n listen<K extends keyof HTMLElementEventMap>(\n target: EventTarget,\n type: K | string,\n fn: (e: any) => void,\n options?: AddEventListenerOptions\n ): void;\n inView(cb: (visible: boolean, entry?: IntersectionObserverEntry) => void, init?: IntersectionObserverInit, target?: Element): void;\n motion(el: Element, keyframes: Keyframe[], options: KeyframeAnimationOptions): Animation | null;\n emit(type: string, detail?: unknown): boolean;\n}\n\ntype BaseCtor = new () => UsaBase;\nlet baseClass: BaseCtor | null = null;\n\n/** The lazily created base class (needs `HTMLElement`). */\nexport function getBase(): BaseCtor {\n if (baseClass) return baseClass;\n class Base extends HTMLElement {\n private _cleanups: Cleanup[] = [];\n private _connected = false;\n\n get reduced(): boolean {\n return prefersReducedMotion();\n }\n\n connectedCallback(): void {\n if (this._connected) return;\n this._connected = true;\n // Upgraded while the parser is still inside us (a <script> in <head>\n // defined the element): children/text are not there yet, so wait.\n if (typeof document !== 'undefined' && document.readyState === 'loading' && !this.nextSibling && !this.childNodes.length) {\n const go = () => {\n if (this._connected && this.isConnected) this.mount();\n };\n document.addEventListener('DOMContentLoaded', go, { once: true });\n this._cleanups.push(() => document.removeEventListener('DOMContentLoaded', go));\n return;\n }\n this.mount();\n }\n\n disconnectedCallback(): void {\n this._connected = false;\n this.teardown();\n }\n\n attributeChangedCallback(_name: string, oldValue: string | null, value: string | null): void {\n if (!this._connected || oldValue === value) return;\n this.changed(_name);\n }\n\n /** Re-mount on attribute change (override for finer updates). */\n changed(_name: string): void {\n this.teardown();\n this.mount();\n }\n\n private teardown(): void {\n this._cleanups.splice(0).reverse().forEach((fn) => fn());\n this.unmount();\n }\n\n mount(): void {}\n unmount(): void {}\n\n str(name: string, fallback = ''): string {\n const v = this.getAttribute(name);\n return v === null ? fallback : v;\n }\n\n num(name: string, fallback: number): number {\n const v = this.getAttribute(name);\n const n = v === null || v.trim() === '' ? NaN : Number(v);\n return Number.isFinite(n) ? n : fallback;\n }\n\n /** Boolean attribute: present and not `\"false\"`. */\n flag(name: string): boolean {\n const v = this.getAttribute(name);\n return v !== null && v !== 'false';\n }\n\n setFlag(name: string, on: boolean): void {\n if (on) this.setAttribute(name, '');\n else this.removeAttribute(name);\n }\n\n onCleanup(fn: Cleanup): void {\n this._cleanups.push(fn);\n }\n\n listen(target: EventTarget, type: string, fn: (e: any) => void, options?: AddEventListenerOptions): void {\n target.addEventListener(type, fn, options);\n this.onCleanup(() => target.removeEventListener(type, fn, options));\n }\n\n /** Calls `cb(true/false)` as the element enters / leaves the viewport. */\n inView(cb: (visible: boolean, entry?: IntersectionObserverEntry) => void, init?: IntersectionObserverInit, target: Element = this): void {\n if (typeof IntersectionObserver === 'undefined') {\n cb(true);\n return;\n }\n const io = new IntersectionObserver((entries) => {\n for (const e of entries) cb(e.isIntersecting, e);\n }, init);\n io.observe(target);\n this.onCleanup(() => io.disconnect());\n }\n\n /** `el.animate()` that returns `null` (and applies the last frame) without WAAPI. */\n motion(el: Element, keyframes: Keyframe[], options: KeyframeAnimationOptions): Animation | null {\n if (typeof (el as HTMLElement).animate !== 'function') {\n applyFrame(el as HTMLElement, keyframes[keyframes.length - 1]);\n return null;\n }\n const k = motionScale();\n if (k !== 1 && k > 0 && typeof options.duration === 'number') options = { ...options, duration: options.duration * k, delay: (options.delay || 0) * k };\n return (el as HTMLElement).animate(keyframes, options);\n }\n\n emit(type: string, detail?: unknown): boolean {\n return this.dispatchEvent(new CustomEvent(`usa:${type}`, { detail, bubbles: true, cancelable: true }));\n }\n }\n baseClass = Base as unknown as BaseCtor;\n return baseClass;\n}\n\n/** Write a keyframe's properties as inline styles (no-WAAPI fallback). */\nexport function applyFrame(el: HTMLElement, frame?: Keyframe): void {\n if (!frame) return;\n for (const [k, v] of Object.entries(frame)) {\n if (k === 'offset' || k === 'easing' || k === 'composite' || v == null) continue;\n (el.style as any)[k] = String(v);\n }\n}\n\n/**\n * Register `tag` with the class built by `make(Base)`. Returns the\n * constructor, the already registered one, or `undefined` without DOM.\n */\nexport function defineElement(\n tag: string,\n make: (Base: BaseCtor) => CustomElementConstructor,\n css?: { id: string; text: string }\n): CustomElementConstructor | undefined {\n if (!canDefine()) return undefined;\n adoptStyles('base', BASE_CSS);\n if (css) adoptStyles(css.id, css.text);\n const existing = customElements.get(tag);\n if (existing) return existing;\n const ctor = make(getBase());\n customElements.define(tag, ctor);\n return ctor;\n}\n\nconst BASE_CSS = '.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}';\n\n/** A visually hidden copy of `text` for screen readers (the animated copy is `aria-hidden`). */\nexport function srText(text: string): HTMLSpanElement {\n const s = document.createElement('span');\n s.className = 'usa-sr';\n s.textContent = text;\n return s;\n}\n\n/** requestAnimationFrame with a timeout fallback (jsdom / hidden documents). */\nexport const raf = (cb: FrameRequestCallback): number =>\n typeof requestAnimationFrame === 'function' ? requestAnimationFrame(cb) : (setTimeout(() => cb(Date.now()), 16) as unknown as number);\n/** Monotonic time in ms (rAF callback timestamps differ between environments, so loops use this). */\nexport const now = (): number => (typeof performance !== 'undefined' ? performance.now() : Date.now());\nexport const caf = (id: number): void => {\n if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(id);\n else clearTimeout(id);\n};\n\n/** Spring-ish easing used across the components. */\nexport const EASE_OUT = 'cubic-bezier(0.22, 1, 0.36, 1)';\nexport const EASE_SPRING = 'cubic-bezier(0.34, 1.56, 0.64, 1)';\n/** Windows Fluent \"decelerate\" / \"point-to-point\" curves. */\nexport const FLUENT_DECELERATE = 'cubic-bezier(0.1, 0.9, 0.2, 1)';\n\nexport const clamp = (v: number, min: number, max: number): number => Math.min(max, Math.max(min, v));\n"],"names":[],"mappings":"AAAA;;;;;;;AAOG;MA0BU,YAAY,GAAoC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI;AAEtG,MAAM,MAAM,GAA+B,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE;AAEnH;AACM,SAAU,mBAAmB,CAAC,OAAyB,EAAA;AAC3D,IAAA,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC9B,IAAI,OAAO,CAAC,eAAe,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;QAC9D,QAAQ,CAAC,eAAe,CAAC,KAAK,CAAC,WAAW,CAAC,cAAc,EAAE,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;QAC9G,QAAQ,CAAC,eAAe,CAAC,YAAY,CAAC,iBAAiB,EAAE,OAAO,CAAC,eAAe,CAAC;IACnF;AACF;AAEA;SACgB,kBAAkB,GAAA;IAChC,OAAO,MAAM,CAAC,eAAe;AAC/B;AAEA;SACgB,WAAW,GAAA;IACzB,OAAO,YAAY,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC;AAClD;AAEO,MAAM,SAAS,GAAG,MAAe,OAAO,cAAc,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G,CAAC,EAAU,KAAU;IACtC,IAAI,OAAO,oBAAoB,KAAK,UAAU;QAAE,oBAAoB,CAAC,EAAE,CAAC;;QACnE,YAAY,CAAC,EAAE,CAAC;AACvB;AAEA;AACO,MAAM,QAAQ,GAAG;AACjB,MAAM,WAAW,GAAG;AAC3B;AACO,MAAM,iBAAiB,GAAG;AAE1B,MAAM,KAAK,GAAG,CAAC,CAAS,EAAE,GAAW,EAAE,GAAW,KAAa,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { p as prefersReducedMotion,
|
|
1
|
+
import { p as prefersReducedMotion, j as applyFrame, m as motionScale, f as EASE_SPRING, n as now, r as raf, e as caf } from './base-C_w9ibbn.js';
|
|
2
2
|
|
|
3
3
|
const SPRING_PRESETS = {
|
|
4
4
|
default: { stiffness: 170, damping: 26, mass: 1 },
|
|
@@ -99,7 +99,7 @@ function spring(el, keyframes, input, options = {}) {
|
|
|
99
99
|
return null;
|
|
100
100
|
}
|
|
101
101
|
const { easing, duration } = springEasing(input);
|
|
102
|
-
return target.animate(keyframes, { duration, easing, fill: 'both', ...options });
|
|
102
|
+
return target.animate(keyframes, { duration: duration * motionScale(), easing, fill: 'both', ...options });
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
105
|
* An interruptible spring-animated number: call `set()` as often as you like,
|
|
@@ -216,4 +216,4 @@ function rubberBand(distance, dimension, constant = 0.55) {
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
export { SPRING_PRESETS as S, rubberBand as a, spring as b, createSpring as c, springEasing as d, springSamples as e, stepSpring as f, supportsLinearEasing as g, linearEasing as l, projectInertia as p, resolveSpring as r, snapTo as s };
|
|
219
|
-
//# sourceMappingURL=spring-
|
|
219
|
+
//# sourceMappingURL=spring-Dc8ZqDWE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spring-Dc8ZqDWE.js","sources":["../../src/components/physics/spring.ts"],"sourcesContent":["import { prefersReducedMotion, motionScale, raf, caf, now, applyFrame, EASE_SPRING } from '../base';\n\n/**\n * Spring physics core (v2.3). A damped harmonic oscillator integrated in\n * 1 ms steps: `stiffness` (k, N/m), `damping` (c) and `mass` (m). Used by\n * the `<usa-spring>`, `<usa-draggable>` and `<usa-overscroll>` elements and\n * exported for your own animations:\n *\n * - `springEasing()` turns a spring into a CSS `linear()` easing + duration\n * for WAAPI / CSS (falls back to a cubic-bezier overshoot where `linear()`\n * is unsupported);\n * - `spring(el, keyframes, cfg)` animates with it;\n * - `createSpring()` is an interruptible, velocity-preserving value for\n * gestures (drag, inertia, snap).\n */\nexport interface SpringConfig {\n /** Spring stiffness (default 170). Higher = faster, snappier. */\n stiffness?: number;\n /** Damping / friction (default 26). Lower = more bounces. */\n damping?: number;\n /** Mass (default 1). Higher = slower, heavier. */\n mass?: number;\n /** Initial velocity in progress units per second (default 0). */\n velocity?: number;\n /** Rest threshold (default 0.001). */\n precision?: number;\n}\n\nexport type SpringPreset = 'default' | 'gentle' | 'wobbly' | 'stiff' | 'bouncy' | 'slow' | 'molasses';\n\nexport const SPRING_PRESETS: Record<SpringPreset, Required<Pick<SpringConfig, 'stiffness' | 'damping' | 'mass'>>> = {\n default: { stiffness: 170, damping: 26, mass: 1 },\n gentle: { stiffness: 120, damping: 14, mass: 1 },\n wobbly: { stiffness: 180, damping: 12, mass: 1 },\n stiff: { stiffness: 210, damping: 20, mass: 1 },\n bouncy: { stiffness: 300, damping: 10, mass: 1 },\n slow: { stiffness: 280, damping: 60, mass: 1 },\n molasses: { stiffness: 280, damping: 120, mass: 1 },\n};\n\nexport type SpringInput = SpringPreset | SpringConfig | string | undefined;\n\n/** Resolve a preset name or a partial config to a full config. */\nexport function resolveSpring(input?: SpringInput): Required<SpringConfig> {\n const base = typeof input === 'string' ? SPRING_PRESETS[input as SpringPreset] || SPRING_PRESETS.default : { ...SPRING_PRESETS.default, ...(input || {}) };\n const pos = (v: unknown, d: number) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : d);\n const o = (typeof input === 'object' && input) || {};\n return {\n stiffness: pos(base.stiffness, 170),\n damping: Math.max(0, Number.isFinite(base.damping) ? base.damping : 26),\n mass: pos(base.mass, 1),\n velocity: Number.isFinite(o.velocity) ? (o.velocity as number) : 0,\n precision: pos(o.precision, 0.001),\n };\n}\n\n/** One integration step (semi-implicit Euler) towards `to`. Returns [x, v]. */\nexport function stepSpring(cfg: Required<SpringConfig>, x: number, v: number, to: number, dt: number): [number, number] {\n const a = (-cfg.stiffness * (x - to) - cfg.damping * v) / cfg.mass;\n const nv = v + a * dt;\n return [x + nv * dt, nv];\n}\n\nconst cache = new Map<string, { values: number[]; duration: number }>();\n\n/**\n * Sample the spring from 0 to 1 at `fps` (default 60). `values` may exceed 1\n * (overshoot); `duration` is the time to rest, in ms (max 10 s).\n */\nexport function springSamples(input?: SpringInput, fps = 60): { values: number[]; duration: number } {\n const cfg = resolveSpring(input);\n const key = `${cfg.stiffness}|${cfg.damping}|${cfg.mass}|${cfg.velocity}|${cfg.precision}|${fps}`;\n const hit = cache.get(key);\n if (hit) return hit;\n const values = [0];\n let x = 0;\n let v = cfg.velocity;\n const frame = 1000 / fps;\n let t = 0;\n let next = frame;\n while (t < 10000) {\n [x, v] = stepSpring(cfg, x, v, 1, 0.001);\n t += 1;\n if (t >= next) {\n values.push(x);\n next += frame;\n if (Math.abs(1 - x) < cfg.precision && Math.abs(v) < cfg.precision * 10) break;\n }\n }\n values[values.length - 1] = 1;\n const out = { values, duration: Math.round(t) };\n if (cache.size > 64) cache.clear();\n cache.set(key, out);\n return out;\n}\n\n/** `true` when CSS `linear()` easing is supported. */\nexport function supportsLinearEasing(): boolean {\n return typeof CSS !== 'undefined' && typeof CSS.supports === 'function' && CSS.supports('animation-timing-function', 'linear(0, 1)');\n}\n\n/**\n * The spring as `{ easing, duration }` for `el.animate()` / CSS. `easing` is\n * a `linear(…)` function with at most `points` stops (default 48), or a\n * cubic-bezier overshoot where `linear()` is unsupported.\n */\nexport function springEasing(input?: SpringInput, points = 48): { easing: string; duration: number } {\n const { values, duration } = springSamples(input);\n if (!supportsLinearEasing()) return { easing: EASE_SPRING, duration: Math.min(duration, 1200) };\n return { easing: linearEasing(values, points), duration };\n}\n\n/** Build a CSS `linear()` easing from samples (down-sampled to `points`). */\nexport function linearEasing(values: number[], points = 48): string {\n const n = values.length;\n const step = Math.max(1, Math.ceil((n - 1) / Math.max(2, points - 1)));\n const out: string[] = [];\n for (let i = 0; i < n - 1; i += step) out.push(String(Math.round(values[i] * 1000) / 1000));\n out.push('1');\n return `linear(${out.join(', ')})`;\n}\n\n/**\n * Animate `el` between keyframes with spring timing (WAAPI). Under reduced\n * motion the final frame is applied immediately. Returns the Animation (or\n * `null` without WAAPI / under reduced motion).\n */\nexport function spring(el: Element, keyframes: Keyframe[], input?: SpringInput, options: KeyframeAnimationOptions = {}): Animation | null {\n const target = el as HTMLElement;\n if (prefersReducedMotion() || typeof target.animate !== 'function') {\n applyFrame(target, keyframes[keyframes.length - 1]);\n return null;\n }\n const { easing, duration } = springEasing(input);\n return target.animate(keyframes, { duration: duration * motionScale(), easing, fill: 'both', ...options });\n}\n\n/* ------------------------------------------------------------------ */\n/* Interactive springs */\n/* ------------------------------------------------------------------ */\n\nexport interface SpringValueOptions {\n /** Start value (default 0). */\n value?: number;\n /** Spring config or preset (default `'default'`). */\n spring?: SpringInput;\n /** Called with the value every frame (and on `jump()`). */\n onUpdate?: (value: number, velocity: number) => void;\n /** Called when the value comes to rest at its target. */\n onRest?: (value: number) => void;\n}\n\nexport interface SpringValue {\n readonly value: number;\n /** Units per second. */\n readonly velocity: number;\n readonly target: number;\n readonly animating: boolean;\n /** Animate to `target`, optionally with a new initial velocity (units/s). */\n set(target: number, velocity?: number): void;\n /** Jump to `value` with no animation. */\n jump(value: number): void;\n /** Stop where it is. */\n stop(): void;\n /** Change the spring config. */\n configure(spring: SpringInput): void;\n}\n\n/**\n * An interruptible spring-animated number: call `set()` as often as you like,\n * the motion keeps its velocity (like iOS / Framer springs). Reduced motion\n * jumps straight to the target.\n */\nexport function createSpring(opts: SpringValueOptions = {}): SpringValue {\n let cfg = resolveSpring(opts.spring);\n let x = opts.value ?? 0;\n let v = 0;\n let to = x;\n let id = 0;\n let last = 0;\n let running = false;\n const stop = () => {\n if (running) caf(id);\n running = false;\n };\n const loop = () => {\n const t = now();\n let dt = Math.min(64, Math.max(1, t - last));\n last = t;\n while (dt > 0) {\n const s = Math.min(dt, 4);\n [x, v] = stepSpring(cfg, x, v, to, s / 1000);\n dt -= s;\n }\n const scale = Math.max(1, Math.abs(to) * 0.0005);\n if (Math.abs(to - x) < cfg.precision * scale * 10 && Math.abs(v) < cfg.precision * scale * 100) {\n x = to;\n v = 0;\n running = false;\n opts.onUpdate?.(x, 0);\n opts.onRest?.(x);\n return;\n }\n opts.onUpdate?.(x, v);\n id = raf(loop);\n };\n const api: SpringValue = {\n get value() {\n return x;\n },\n get velocity() {\n return v;\n },\n get target() {\n return to;\n },\n get animating() {\n return running;\n },\n set(target, velocity) {\n to = target;\n if (velocity !== undefined && Number.isFinite(velocity)) v = velocity;\n if (prefersReducedMotion()) {\n api.jump(target);\n opts.onRest?.(target);\n return;\n }\n if (!running) {\n running = true;\n last = now();\n id = raf(loop);\n }\n },\n jump(value) {\n stop();\n x = to = value;\n v = 0;\n opts.onUpdate?.(x, 0);\n },\n stop() {\n stop();\n v = 0;\n to = x;\n },\n configure(input) {\n cfg = resolveSpring(input);\n },\n };\n return api;\n}\n\n/* ------------------------------------------------------------------ */\n/* Inertia + snapping */\n/* ------------------------------------------------------------------ */\n\n/**\n * Where a flick at `velocity` (units/s) comes to rest with exponential\n * decay: `value + velocity · timeConstant` (default 0.325 s, iOS-like).\n */\nexport function projectInertia(value: number, velocity: number, timeConstant = 0.325): number {\n return value + velocity * timeConstant;\n}\n\n/** Snap to a grid (`number`) or the nearest of a list of points. */\nexport function snapTo(value: number, to: number | number[] | null | undefined): number {\n if (Array.isArray(to)) {\n if (!to.length) return value;\n return to.reduce((best, p) => (Math.abs(p - value) < Math.abs(best - value) ? p : best), to[0]);\n }\n if (typeof to === 'number' && to > 0) return Math.round(value / to) * to;\n return value;\n}\n\n/** iOS-style rubber-band resistance: how far content moves when pulled `distance` past an edge. */\nexport function rubberBand(distance: number, dimension: number, constant = 0.55): number {\n if (dimension <= 0) return 0;\n const sign = distance < 0 ? -1 : 1;\n const d = Math.abs(distance);\n return sign * (1 - 1 / ((d * constant) / dimension + 1)) * dimension;\n}\n"],"names":[],"mappings":";;AA8BO,MAAM,cAAc,GAAyF;AAClH,IAAA,OAAO,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AACjD,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,KAAK,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAC/C,IAAA,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAChD,IAAA,IAAI,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;AAC9C,IAAA,QAAQ,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE;;AAKrD;AACM,SAAU,aAAa,CAAC,KAAmB,EAAA;AAC/C,IAAA,MAAM,IAAI,GAAG,OAAO,KAAK,KAAK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-
|
|
3
|
+
var base = require('./base-BR6fYLBA.cjs');
|
|
4
4
|
|
|
5
5
|
const SPRING_PRESETS = {
|
|
6
6
|
default: { stiffness: 170, damping: 26, mass: 1 },
|
|
@@ -101,7 +101,7 @@ function spring(el, keyframes, input, options = {}) {
|
|
|
101
101
|
return null;
|
|
102
102
|
}
|
|
103
103
|
const { easing, duration } = springEasing(input);
|
|
104
|
-
return target.animate(keyframes, { duration, easing, fill: 'both', ...options });
|
|
104
|
+
return target.animate(keyframes, { duration: duration * base.motionScale(), easing, fill: 'both', ...options });
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
107
|
* An interruptible spring-animated number: call `set()` as often as you like,
|
|
@@ -229,4 +229,4 @@ exports.springEasing = springEasing;
|
|
|
229
229
|
exports.springSamples = springSamples;
|
|
230
230
|
exports.stepSpring = stepSpring;
|
|
231
231
|
exports.supportsLinearEasing = supportsLinearEasing;
|
|
232
|
-
//# sourceMappingURL=spring-
|
|
232
|
+
//# sourceMappingURL=spring-DyHe1Hfa.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spring-DyHe1Hfa.cjs","sources":["../../src/components/physics/spring.ts"],"sourcesContent":["import { prefersReducedMotion, motionScale, raf, caf, now, applyFrame, EASE_SPRING } from '../base';\n\n/**\n * Spring physics core (v2.3). A damped harmonic oscillator integrated in\n * 1 ms steps: `stiffness` (k, N/m), `damping` (c) and `mass` (m). Used by\n * the `<usa-spring>`, `<usa-draggable>` and `<usa-overscroll>` elements and\n * exported for your own animations:\n *\n * - `springEasing()` turns a spring into a CSS `linear()` easing + duration\n * for WAAPI / CSS (falls back to a cubic-bezier overshoot where `linear()`\n * is unsupported);\n * - `spring(el, keyframes, cfg)` animates with it;\n * - `createSpring()` is an interruptible, velocity-preserving value for\n * gestures (drag, inertia, snap).\n */\nexport interface SpringConfig {\n /** Spring stiffness (default 170). Higher = faster, snappier. */\n stiffness?: number;\n /** Damping / friction (default 26). Lower = more bounces. */\n damping?: number;\n /** Mass (default 1). Higher = slower, heavier. */\n mass?: number;\n /** Initial velocity in progress units per second (default 0). */\n velocity?: number;\n /** Rest threshold (default 0.001). */\n precision?: number;\n}\n\nexport type SpringPreset = 'default' | 'gentle' | 'wobbly' | 'stiff' | 'bouncy' | 'slow' | 'molasses';\n\nexport const SPRING_PRESETS: Record<SpringPreset, Required<Pick<SpringConfig, 'stiffness' | 'damping' | 'mass'>>> = {\n default: { stiffness: 170, damping: 26, mass: 1 },\n gentle: { stiffness: 120, damping: 14, mass: 1 },\n wobbly: { stiffness: 180, damping: 12, mass: 1 },\n stiff: { stiffness: 210, damping: 20, mass: 1 },\n bouncy: { stiffness: 300, damping: 10, mass: 1 },\n slow: { stiffness: 280, damping: 60, mass: 1 },\n molasses: { stiffness: 280, damping: 120, mass: 1 },\n};\n\nexport type SpringInput = SpringPreset | SpringConfig | string | undefined;\n\n/** Resolve a preset name or a partial config to a full config. */\nexport function resolveSpring(input?: SpringInput): Required<SpringConfig> {\n const base = typeof input === 'string' ? SPRING_PRESETS[input as SpringPreset] || SPRING_PRESETS.default : { ...SPRING_PRESETS.default, ...(input || {}) };\n const pos = (v: unknown, d: number) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : d);\n const o = (typeof input === 'object' && input) || {};\n return {\n stiffness: pos(base.stiffness, 170),\n damping: Math.max(0, Number.isFinite(base.damping) ? base.damping : 26),\n mass: pos(base.mass, 1),\n velocity: Number.isFinite(o.velocity) ? (o.velocity as number) : 0,\n precision: pos(o.precision, 0.001),\n };\n}\n\n/** One integration step (semi-implicit Euler) towards `to`. Returns [x, v]. */\nexport function stepSpring(cfg: Required<SpringConfig>, x: number, v: number, to: number, dt: number): [number, number] {\n const a = (-cfg.stiffness * (x - to) - cfg.damping * v) / cfg.mass;\n const nv = v + a * dt;\n return [x + nv * dt, nv];\n}\n\nconst cache = new Map<string, { values: number[]; duration: number }>();\n\n/**\n * Sample the spring from 0 to 1 at `fps` (default 60). `values` may exceed 1\n * (overshoot); `duration` is the time to rest, in ms (max 10 s).\n */\nexport function springSamples(input?: SpringInput, fps = 60): { values: number[]; duration: number } {\n const cfg = resolveSpring(input);\n const key = `${cfg.stiffness}|${cfg.damping}|${cfg.mass}|${cfg.velocity}|${cfg.precision}|${fps}`;\n const hit = cache.get(key);\n if (hit) return hit;\n const values = [0];\n let x = 0;\n let v = cfg.velocity;\n const frame = 1000 / fps;\n let t = 0;\n let next = frame;\n while (t < 10000) {\n [x, v] = stepSpring(cfg, x, v, 1, 0.001);\n t += 1;\n if (t >= next) {\n values.push(x);\n next += frame;\n if (Math.abs(1 - x) < cfg.precision && Math.abs(v) < cfg.precision * 10) break;\n }\n }\n values[values.length - 1] = 1;\n const out = { values, duration: Math.round(t) };\n if (cache.size > 64) cache.clear();\n cache.set(key, out);\n return out;\n}\n\n/** `true` when CSS `linear()` easing is supported. */\nexport function supportsLinearEasing(): boolean {\n return typeof CSS !== 'undefined' && typeof CSS.supports === 'function' && CSS.supports('animation-timing-function', 'linear(0, 1)');\n}\n\n/**\n * The spring as `{ easing, duration }` for `el.animate()` / CSS. `easing` is\n * a `linear(…)` function with at most `points` stops (default 48), or a\n * cubic-bezier overshoot where `linear()` is unsupported.\n */\nexport function springEasing(input?: SpringInput, points = 48): { easing: string; duration: number } {\n const { values, duration } = springSamples(input);\n if (!supportsLinearEasing()) return { easing: EASE_SPRING, duration: Math.min(duration, 1200) };\n return { easing: linearEasing(values, points), duration };\n}\n\n/** Build a CSS `linear()` easing from samples (down-sampled to `points`). */\nexport function linearEasing(values: number[], points = 48): string {\n const n = values.length;\n const step = Math.max(1, Math.ceil((n - 1) / Math.max(2, points - 1)));\n const out: string[] = [];\n for (let i = 0; i < n - 1; i += step) out.push(String(Math.round(values[i] * 1000) / 1000));\n out.push('1');\n return `linear(${out.join(', ')})`;\n}\n\n/**\n * Animate `el` between keyframes with spring timing (WAAPI). Under reduced\n * motion the final frame is applied immediately. Returns the Animation (or\n * `null` without WAAPI / under reduced motion).\n */\nexport function spring(el: Element, keyframes: Keyframe[], input?: SpringInput, options: KeyframeAnimationOptions = {}): Animation | null {\n const target = el as HTMLElement;\n if (prefersReducedMotion() || typeof target.animate !== 'function') {\n applyFrame(target, keyframes[keyframes.length - 1]);\n return null;\n }\n const { easing, duration } = springEasing(input);\n return target.animate(keyframes, { duration: duration * motionScale(), easing, fill: 'both', ...options });\n}\n\n/* ------------------------------------------------------------------ */\n/* Interactive springs */\n/* ------------------------------------------------------------------ */\n\nexport interface SpringValueOptions {\n /** Start value (default 0). */\n value?: number;\n /** Spring config or preset (default `'default'`). */\n spring?: SpringInput;\n /** Called with the value every frame (and on `jump()`). */\n onUpdate?: (value: number, velocity: number) => void;\n /** Called when the value comes to rest at its target. */\n onRest?: (value: number) => void;\n}\n\nexport interface SpringValue {\n readonly value: number;\n /** Units per second. */\n readonly velocity: number;\n readonly target: number;\n readonly animating: boolean;\n /** Animate to `target`, optionally with a new initial velocity (units/s). */\n set(target: number, velocity?: number): void;\n /** Jump to `value` with no animation. */\n jump(value: number): void;\n /** Stop where it is. */\n stop(): void;\n /** Change the spring config. */\n configure(spring: SpringInput): void;\n}\n\n/**\n * An interruptible spring-animated number: call `set()` as often as you like,\n * the motion keeps its velocity (like iOS / Framer springs). Reduced motion\n * jumps straight to the target.\n */\nexport function createSpring(opts: SpringValueOptions = {}): SpringValue {\n let cfg = resolveSpring(opts.spring);\n let x = opts.value ?? 0;\n let v = 0;\n let to = x;\n let id = 0;\n let last = 0;\n let running = false;\n const stop = () => {\n if (running) caf(id);\n running = false;\n };\n const loop = () => {\n const t = now();\n let dt = Math.min(64, Math.max(1, t - last));\n last = t;\n while (dt > 0) {\n const s = Math.min(dt, 4);\n [x, v] = stepSpring(cfg, x, v, to, s / 1000);\n dt -= s;\n }\n const scale = Math.max(1, Math.abs(to) * 0.0005);\n if (Math.abs(to - x) < cfg.precision * scale * 10 && Math.abs(v) < cfg.precision * scale * 100) {\n x = to;\n v = 0;\n running = false;\n opts.onUpdate?.(x, 0);\n opts.onRest?.(x);\n return;\n }\n opts.onUpdate?.(x, v);\n id = raf(loop);\n };\n const api: SpringValue = {\n get value() {\n return x;\n },\n get velocity() {\n return v;\n },\n get target() {\n return to;\n },\n get animating() {\n return running;\n },\n set(target, velocity) {\n to = target;\n if (velocity !== undefined && Number.isFinite(velocity)) v = velocity;\n if (prefersReducedMotion()) {\n api.jump(target);\n opts.onRest?.(target);\n return;\n }\n if (!running) {\n running = true;\n last = now();\n id = raf(loop);\n }\n },\n jump(value) {\n stop();\n x = to = value;\n v = 0;\n opts.onUpdate?.(x, 0);\n },\n stop() {\n stop();\n v = 0;\n to = x;\n },\n configure(input) {\n cfg = resolveSpring(input);\n },\n };\n return api;\n}\n\n/* ------------------------------------------------------------------ */\n/* Inertia + snapping */\n/* ------------------------------------------------------------------ */\n\n/**\n * Where a flick at `velocity` (units/s) comes to rest with exponential\n * decay: `value + velocity · timeConstant` (default 0.325 s, iOS-like).\n */\nexport function projectInertia(value: number, velocity: number, timeConstant = 0.325): number {\n return value + velocity * timeConstant;\n}\n\n/** Snap to a grid (`number`) or the nearest of a list of points. */\nexport function snapTo(value: number, to: number | number[] | null | undefined): number {\n if (Array.isArray(to)) {\n if (!to.length) return value;\n return to.reduce((best, p) => (Math.abs(p - value) < Math.abs(best - value) ? p : best), to[0]);\n }\n if (typeof to === 'number' && to > 0) return Math.round(value / to) * to;\n return value;\n}\n\n/** iOS-style rubber-band resistance: how far content moves when pulled `distance` past an edge. */\nexport function rubberBand(distance: number, dimension: number, constant = 0.55): number {\n if (dimension <= 0) return 0;\n const sign = distance < 0 ? -1 : 1;\n const d = Math.abs(distance);\n return sign * (1 - 1 / ((d * constant) / dimension + 1)) * dimension;\n}\n"],"names":["EASE_SPRING","prefersReducedMotion","applyFrame","motionScale","caf","now","raf"],"mappings":";;;;AA8BO,MAAM,cAAc,GAAyF;AAClH,IAAA,OAAO,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,E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AG,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IACjG;AACA,IAAA,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,GAAG,EAAE;AACxE,IAAA,OAAO,KAAK;AACd;AAEA;AACM,SAAU,UAAU,CAAC,QAAgB,EAAE,SAAiB,EAAE,QAAQ,GAAG,IAAI,EAAA;IAC7E,IAAI,SAAS,IAAI,CAAC;AAAE,QAAA,OAAO,CAAC;AAC5B,IAAA,MAAM,IAAI,GAAG,QAAQ,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC;IAClC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC5B,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,QAAQ,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS;AACtE;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var base = require('./base-BR6fYLBA.cjs');
|
|
4
|
+
|
|
5
|
+
var css = ":root{--usa-accent:#7c5cff;--usa-accent-text:#fff;--usa-surface:#1b1e27;--usa-text:inherit;--usa-radius:14px;--usa-border:1px solid rgb(127 127 127 / 0.25);--usa-shadow:0 10px 30px -12px rgb(0 0 0 / 0.45);--usa-blur:0px;--usa-font:inherit}:where([variant=\"minimal\"],[data-usa-variant=\"minimal\"]){--usa-accent:currentColor;--usa-accent-text:Canvas;--usa-surface:transparent;--usa-radius:6px;--usa-border:1px solid color-mix(in srgb,currentColor 22%,transparent);--usa-shadow:none;--usa-blur:0px}:where([variant=\"neon\"],[data-usa-variant=\"neon\"]){--usa-accent:#00f0ff;--usa-accent-text:#04121a;--usa-surface:#0a0b14;--usa-text:#e6fbff;--usa-radius:10px;--usa-border:1px solid #00f0ff;--usa-shadow:0 0 6px #00f0ff,0 0 22px rgb(0 240 255 / 0.45);--usa-blur:0px}:where([variant=\"glass\"],[data-usa-variant=\"glass\"]){--usa-accent:#a78bfa;--usa-accent-text:#fff;--usa-surface:rgb(255 255 255 / 0.12);--usa-radius:18px;--usa-border:1px solid rgb(255 255 255 / 0.28);--usa-shadow:0 12px 40px -12px rgb(0 0 0 / 0.35);--usa-blur:16px}:where([variant=\"brutalist\"],[data-usa-variant=\"brutalist\"]){--usa-accent:#ff3d00;--usa-accent-text:#000;--usa-surface:#fff;--usa-text:#000;--usa-radius:0px;--usa-border:3px solid #000;--usa-shadow:5px 5px 0 #000;--usa-blur:0px;--usa-font:ui-monospace,\"SFMono-Regular\",Menlo,monospace}:where([variant=\"fluent\"],[data-usa-variant=\"fluent\"]){--usa-accent:#0067c0;--usa-accent-text:#fff;--usa-surface:rgb(249 249 249 / 0.82);--usa-text:#1a1a1a;--usa-radius:8px;--usa-border:1px solid rgb(0 0 0 / 0.08);--usa-shadow:0 2px 4px rgb(0 0 0 / 0.14),0 0 2px rgb(0 0 0 / 0.12);--usa-blur:30px;--usa-font:\"Segoe UI Variable\",\"Segoe UI\",system-ui,sans-serif}:where([variant=\"material\"],[data-usa-variant=\"material\"]){--usa-accent:#6750a4;--usa-accent-text:#fff;--usa-surface:#fffbfe;--usa-text:#1c1b1f;--usa-radius:20px;--usa-border:0 solid transparent;--usa-shadow:0 1px 3px rgb(0 0 0 / 0.3),0 4px 8px 3px rgb(0 0 0 / 0.15);--usa-blur:0px;--usa-font:Roboto,system-ui,sans-serif}@media (prefers-color-scheme:dark){:where([variant=\"fluent\"],[data-usa-variant=\"fluent\"]){--usa-accent:#4cc2ff;--usa-accent-text:#000;--usa-surface:rgb(44 44 44 / 0.8);--usa-text:#fff;--usa-border:1px solid rgb(255 255 255 / 0.08)}:where([variant=\"material\"],[data-usa-variant=\"material\"]){--usa-accent:#d0bcff;--usa-accent-text:#381e72;--usa-surface:#1c1b1f;--usa-text:#e6e1e5}}.usa-surface{background:var(--usa-surface);color:var(--usa-text);border:var(--usa-border);border-radius:var(--usa-radius);box-shadow:var(--usa-shadow);font-family:var(--usa-font);-webkit-backdrop-filter:blur(var(--usa-blur));backdrop-filter:blur(var(--usa-blur))}@media (prefers-reduced-transparency:reduce){.usa-surface{-webkit-backdrop-filter:none;backdrop-filter:none}}";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Style variants (v2.6): `variant="minimal | neon | glass | brutalist |
|
|
9
|
+
* fluent | material"` on any `<usa-*>` element — or on any ancestor as
|
|
10
|
+
* `data-usa-variant`, or page-wide with `setVariant()` — sets the shared
|
|
11
|
+
* design tokens every component reads:
|
|
12
|
+
*
|
|
13
|
+
* `--usa-accent`, `--usa-accent-text`, `--usa-surface`, `--usa-text`,
|
|
14
|
+
* `--usa-radius`, `--usa-border`, `--usa-shadow`, `--usa-blur`, `--usa-font`.
|
|
15
|
+
*
|
|
16
|
+
* (`<usa-spinner>`, `<usa-check>` and `<usa-dialog>` already use `variant`
|
|
17
|
+
* for their kind; the token names never clash with those values except
|
|
18
|
+
* `fluent`, which means the same thing there.)
|
|
19
|
+
*/
|
|
20
|
+
const VARIANTS = ['minimal', 'neon', 'glass', 'brutalist', 'fluent', 'material'];
|
|
21
|
+
/** Inject the variant token sheet (done automatically by every `ui` component). */
|
|
22
|
+
function adoptVariants() {
|
|
23
|
+
base.adoptStyles('variants', css);
|
|
24
|
+
}
|
|
25
|
+
/** Apply a variant to the whole page (or `root`); `null` removes it. */
|
|
26
|
+
function setVariant(variant, root = typeof document !== 'undefined' ? document.documentElement : null) {
|
|
27
|
+
if (!root)
|
|
28
|
+
return;
|
|
29
|
+
adoptVariants();
|
|
30
|
+
if (variant)
|
|
31
|
+
root.setAttribute('data-usa-variant', variant);
|
|
32
|
+
else
|
|
33
|
+
root.removeAttribute('data-usa-variant');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
exports.VARIANTS = VARIANTS;
|
|
37
|
+
exports.adoptVariants = adoptVariants;
|
|
38
|
+
exports.setVariant = setVariant;
|
|
39
|
+
//# sourceMappingURL=variants-Bbatdq8d.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variants-Bbatdq8d.cjs","sources":["../../src/components/ui/variants.ts"],"sourcesContent":["import { adoptStyles } from '../base';\nimport css from './variants.css?raw';\n\n/**\n * Style variants (v2.6): `variant=\"minimal | neon | glass | brutalist |\n * fluent | material\"` on any `<usa-*>` element — or on any ancestor as\n * `data-usa-variant`, or page-wide with `setVariant()` — sets the shared\n * design tokens every component reads:\n *\n * `--usa-accent`, `--usa-accent-text`, `--usa-surface`, `--usa-text`,\n * `--usa-radius`, `--usa-border`, `--usa-shadow`, `--usa-blur`, `--usa-font`.\n *\n * (`<usa-spinner>`, `<usa-check>` and `<usa-dialog>` already use `variant`\n * for their kind; the token names never clash with those values except\n * `fluent`, which means the same thing there.)\n */\nexport const VARIANTS = ['minimal', 'neon', 'glass', 'brutalist', 'fluent', 'material'] as const;\nexport type Variant = (typeof VARIANTS)[number];\n\n/** Inject the variant token sheet (done automatically by every `ui` component). */\nexport function adoptVariants(): void {\n adoptStyles('variants', css);\n}\n\n/** Apply a variant to the whole page (or `root`); `null` removes it. */\nexport function setVariant(variant: Variant | null, root: Element | null = typeof document !== 'undefined' ? document.documentElement : null): void {\n if (!root) return;\n adoptVariants();\n if (variant) root.setAttribute('data-usa-variant', variant);\n else root.removeAttribute('data-usa-variant');\n}\n"],"names":["adoptStyles"],"mappings":";;;;;;AAGA;;;;;;;;;;;;AAYG;AACI,MAAM,QAAQ,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU;AAGtF;SACgB,aAAa,GAAA;AAC3B,IAAAA,gBAAW,CAAC,UAAU,EAAE,GAAG,CAAC;AAC9B;AAEA;SACgB,UAAU,CAAC,OAAuB,EAAE,IAAA,GAAuB,OAAO,QAAQ,KAAK,WAAW,GAAG,QAAQ,CAAC,eAAe,GAAG,IAAI,EAAA;AAC1I,IAAA,IAAI,CAAC,IAAI;QAAE;AACX,IAAA,aAAa,EAAE;AACf,IAAA,IAAI,OAAO;AAAE,QAAA,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,OAAO,CAAC;;AACtD,QAAA,IAAI,CAAC,eAAe,CAAC,kBAAkB,CAAC;AAC/C;;;;;;"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { h as adoptStyles } from './base-C_w9ibbn.js';
|
|
2
|
+
|
|
3
|
+
var css = ":root{--usa-accent:#7c5cff;--usa-accent-text:#fff;--usa-surface:#1b1e27;--usa-text:inherit;--usa-radius:14px;--usa-border:1px solid rgb(127 127 127 / 0.25);--usa-shadow:0 10px 30px -12px rgb(0 0 0 / 0.45);--usa-blur:0px;--usa-font:inherit}:where([variant=\"minimal\"],[data-usa-variant=\"minimal\"]){--usa-accent:currentColor;--usa-accent-text:Canvas;--usa-surface:transparent;--usa-radius:6px;--usa-border:1px solid color-mix(in srgb,currentColor 22%,transparent);--usa-shadow:none;--usa-blur:0px}:where([variant=\"neon\"],[data-usa-variant=\"neon\"]){--usa-accent:#00f0ff;--usa-accent-text:#04121a;--usa-surface:#0a0b14;--usa-text:#e6fbff;--usa-radius:10px;--usa-border:1px solid #00f0ff;--usa-shadow:0 0 6px #00f0ff,0 0 22px rgb(0 240 255 / 0.45);--usa-blur:0px}:where([variant=\"glass\"],[data-usa-variant=\"glass\"]){--usa-accent:#a78bfa;--usa-accent-text:#fff;--usa-surface:rgb(255 255 255 / 0.12);--usa-radius:18px;--usa-border:1px solid rgb(255 255 255 / 0.28);--usa-shadow:0 12px 40px -12px rgb(0 0 0 / 0.35);--usa-blur:16px}:where([variant=\"brutalist\"],[data-usa-variant=\"brutalist\"]){--usa-accent:#ff3d00;--usa-accent-text:#000;--usa-surface:#fff;--usa-text:#000;--usa-radius:0px;--usa-border:3px solid #000;--usa-shadow:5px 5px 0 #000;--usa-blur:0px;--usa-font:ui-monospace,\"SFMono-Regular\",Menlo,monospace}:where([variant=\"fluent\"],[data-usa-variant=\"fluent\"]){--usa-accent:#0067c0;--usa-accent-text:#fff;--usa-surface:rgb(249 249 249 / 0.82);--usa-text:#1a1a1a;--usa-radius:8px;--usa-border:1px solid rgb(0 0 0 / 0.08);--usa-shadow:0 2px 4px rgb(0 0 0 / 0.14),0 0 2px rgb(0 0 0 / 0.12);--usa-blur:30px;--usa-font:\"Segoe UI Variable\",\"Segoe UI\",system-ui,sans-serif}:where([variant=\"material\"],[data-usa-variant=\"material\"]){--usa-accent:#6750a4;--usa-accent-text:#fff;--usa-surface:#fffbfe;--usa-text:#1c1b1f;--usa-radius:20px;--usa-border:0 solid transparent;--usa-shadow:0 1px 3px rgb(0 0 0 / 0.3),0 4px 8px 3px rgb(0 0 0 / 0.15);--usa-blur:0px;--usa-font:Roboto,system-ui,sans-serif}@media (prefers-color-scheme:dark){:where([variant=\"fluent\"],[data-usa-variant=\"fluent\"]){--usa-accent:#4cc2ff;--usa-accent-text:#000;--usa-surface:rgb(44 44 44 / 0.8);--usa-text:#fff;--usa-border:1px solid rgb(255 255 255 / 0.08)}:where([variant=\"material\"],[data-usa-variant=\"material\"]){--usa-accent:#d0bcff;--usa-accent-text:#381e72;--usa-surface:#1c1b1f;--usa-text:#e6e1e5}}.usa-surface{background:var(--usa-surface);color:var(--usa-text);border:var(--usa-border);border-radius:var(--usa-radius);box-shadow:var(--usa-shadow);font-family:var(--usa-font);-webkit-backdrop-filter:blur(var(--usa-blur));backdrop-filter:blur(var(--usa-blur))}@media (prefers-reduced-transparency:reduce){.usa-surface{-webkit-backdrop-filter:none;backdrop-filter:none}}";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Style variants (v2.6): `variant="minimal | neon | glass | brutalist |
|
|
7
|
+
* fluent | material"` on any `<usa-*>` element — or on any ancestor as
|
|
8
|
+
* `data-usa-variant`, or page-wide with `setVariant()` — sets the shared
|
|
9
|
+
* design tokens every component reads:
|
|
10
|
+
*
|
|
11
|
+
* `--usa-accent`, `--usa-accent-text`, `--usa-surface`, `--usa-text`,
|
|
12
|
+
* `--usa-radius`, `--usa-border`, `--usa-shadow`, `--usa-blur`, `--usa-font`.
|
|
13
|
+
*
|
|
14
|
+
* (`<usa-spinner>`, `<usa-check>` and `<usa-dialog>` already use `variant`
|
|
15
|
+
* for their kind; the token names never clash with those values except
|
|
16
|
+
* `fluent`, which means the same thing there.)
|
|
17
|
+
*/
|
|
18
|
+
const VARIANTS = ['minimal', 'neon', 'glass', 'brutalist', 'fluent', 'material'];
|
|
19
|
+
/** Inject the variant token sheet (done automatically by every `ui` component). */
|
|
20
|
+
function adoptVariants() {
|
|
21
|
+
adoptStyles('variants', css);
|
|
22
|
+
}
|
|
23
|
+
/** Apply a variant to the whole page (or `root`); `null` removes it. */
|
|
24
|
+
function setVariant(variant, root = typeof document !== 'undefined' ? document.documentElement : null) {
|
|
25
|
+
if (!root)
|
|
26
|
+
return;
|
|
27
|
+
adoptVariants();
|
|
28
|
+
if (variant)
|
|
29
|
+
root.setAttribute('data-usa-variant', variant);
|
|
30
|
+
else
|
|
31
|
+
root.removeAttribute('data-usa-variant');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { VARIANTS as V, adoptVariants as a, setVariant as s };
|
|
35
|
+
//# sourceMappingURL=variants-idgMVXhE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variants-idgMVXhE.js","sources":["../../src/components/ui/variants.ts"],"sourcesContent":["import { adoptStyles } from '../base';\nimport css from './variants.css?raw';\n\n/**\n * Style variants (v2.6): `variant=\"minimal | neon | glass | brutalist |\n * fluent | material\"` on any `<usa-*>` element — or on any ancestor as\n * `data-usa-variant`, or page-wide with `setVariant()` — sets the shared\n * design tokens every component reads:\n *\n * `--usa-accent`, `--usa-accent-text`, `--usa-surface`, `--usa-text`,\n * `--usa-radius`, `--usa-border`, `--usa-shadow`, `--usa-blur`, `--usa-font`.\n *\n * (`<usa-spinner>`, `<usa-check>` and `<usa-dialog>` already use `variant`\n * for their kind; the token names never clash with those values except\n * `fluent`, which means the same thing there.)\n */\nexport const VARIANTS = ['minimal', 'neon', 'glass', 'brutalist', 'fluent', 'material'] as const;\nexport type Variant = (typeof VARIANTS)[number];\n\n/** Inject the variant token sheet (done automatically by every `ui` component). */\nexport function adoptVariants(): void {\n adoptStyles('variants', css);\n}\n\n/** Apply a variant to the whole page (or `root`); `null` removes it. */\nexport function setVariant(variant: Variant | null, root: Element | null = typeof document !== 'undefined' ? document.documentElement : null): void {\n if (!root) return;\n adoptVariants();\n if (variant) root.setAttribute('data-usa-variant', variant);\n else root.removeAttribute('data-usa-variant');\n}\n"],"names":[],"mappings":";;;;AAGA;;;;;;;;;;;;AAYG;AACI,MAAM,QAAQ,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU;AAGtF;SACgB,aAAa,GAAA;AAC3B,IAAA,WAAW,CAAC,UAAU,EAAE,GAAG,CAAC;AAC9B;AAEA;SACgB,UAAU,CAAC,OAAuB,EAAE,IAAA,GAAuB,OAAO,QAAQ,KAAK,WAAW,GAAG,QAAQ,CAAC,eAAe,GAAG,IAAI,EAAA;AAC1I,IAAA,IAAI,CAAC,IAAI;QAAE;AACX,IAAA,aAAa,EAAE;AACf,IAAA,IAAI,OAAO;AAAE,QAAA,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,OAAO,CAAC;;AACtD,QAAA,IAAI,CAAC,eAAe,CAAC,kBAAkB,CAAC;AAC/C;;;;"}
|