use-scroll-animate 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -0
- package/README_ja.md +1 -0
- package/README_zh.md +1 -0
- package/dist/chunks/{index-tags-DCTX4F9b.cjs → index-tags-Cz4iTBEK.cjs} +2 -1
- package/dist/chunks/{index-tags-DCTX4F9b.cjs.map → index-tags-Cz4iTBEK.cjs.map} +1 -1
- package/dist/chunks/{index-tags-DZ-gjMZc.js → index-tags-Dc_Z4yAY.js} +2 -1
- package/dist/chunks/{index-tags-DZ-gjMZc.js.map → index-tags-Dc_Z4yAY.js.map} +1 -1
- package/dist/components/jsx.d.cts +1 -0
- package/dist/components/jsx.d.ts +1 -0
- package/dist/components/lazy.cjs +2 -1
- package/dist/components/lazy.cjs.map +1 -1
- package/dist/components/lazy.d.cts +1 -0
- package/dist/components/lazy.d.ts +1 -0
- package/dist/components/lazy.js +2 -1
- package/dist/components/lazy.js.map +1 -1
- package/dist/components/react.cjs +1 -1
- package/dist/components/react.js +1 -1
- package/dist/components/svg.cjs +355 -0
- package/dist/components/svg.cjs.map +1 -0
- package/dist/components/svg.css +3 -0
- package/dist/components/svg.d.cts +148 -0
- package/dist/components/svg.d.ts +148 -0
- package/dist/components/svg.js +342 -0
- package/dist/components/svg.js.map +1 -0
- package/dist/components/vue.cjs +2 -1
- package/dist/components/vue.cjs.map +1 -1
- package/dist/components/vue.d.cts +64 -0
- package/dist/components/vue.d.ts +64 -0
- package/dist/components/vue.js +2 -1
- package/dist/components/vue.js.map +1 -1
- package/dist/components.cjs +14 -1
- package/dist/components.cjs.map +1 -1
- package/dist/components.css +1 -0
- package/dist/components.d.cts +104 -2
- package/dist/components.d.ts +104 -2
- package/dist/components.js +5 -2
- 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 +10 -0
- package/package.json +13 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [3.3.0] - 2026-10-07
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- **SVG** — new category `use-scroll-animate/components/svg`:
|
|
14
|
+
- `<usa-draw>` — line drawing for every stroke of the SVG inside (normalised `pathLength`, no `getTotalLength()`): `trigger` (`view` · `hover` · `click` · `scrub`), `duration`, `stagger`, `fill`, `repeat`; `progress`, `play()`, `usa:complete`.
|
|
15
|
+
- `<usa-morph>` — path morph through `paths="A | B | C"` on `click` (keyboard accessible) · `hover` · `view` · `auto`; same-structure paths morph point by point, others switch at the midpoint.
|
|
16
|
+
- `<usa-mask-reveal>` — clip-path mask reveals: `circle`, `diamond`, `star`, `iris`, `wipe`, `wipe-up`, origin `at`, `trigger`, `repeat`.
|
|
17
|
+
- `<usa-anim-icon>` — animated stroke icons (`bell`, `heart`, `check`, `arrow`, `star`, `gear`, `search`, `download`) on hover / focus, click, view or loop; decorative unless `label` is set.
|
|
18
|
+
- Helpers: `morphTo()`, `interpolatePath()`, `pathsCompatible()`, `drawLines()`, `MASK_SHAPES`, `ANIM_ICONS`.
|
|
19
|
+
- Reduced motion: drawings appear complete, morphs switch instantly (`auto` does not cycle), masks are not applied, icons stay still.
|
|
20
|
+
- Showcase: new **SVG** gallery category (draw, morph, mask, icons, `morphTo()` demo).
|
|
21
|
+
|
|
10
22
|
## [3.2.0] - 2026-10-07
|
|
11
23
|
|
|
12
24
|
### Added
|
package/README.md
CHANGED
|
@@ -57,6 +57,7 @@ defineComponents(); // or per category: import { defineTextComponents } from 'us
|
|
|
57
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()` |
|
|
58
58
|
| **Timeline & choreography** (`/components/timeline`) | `timeline()` (chain · overlap · labels · seek · reverse · scrub) · `<usa-timeline>` (`data-tl` steps) |
|
|
59
59
|
| **Gestures** (`/components/gesture`) | `gesture()` (pan · swipe · pinch · long-press · tap · double-tap → springs) · `<usa-swipeable>` · `<usa-pinch-zoom>` |
|
|
60
|
+
| **SVG** (`/components/svg`) | `<usa-draw>` (line drawing) · `<usa-morph>` (path morph) · `<usa-mask-reveal>` · `<usa-anim-icon>` · `morphTo()` · `interpolatePath()` |
|
|
60
61
|
|
|
61
62
|
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.
|
|
62
63
|
|
package/README_ja.md
CHANGED
|
@@ -47,6 +47,7 @@ defineComponents(); // カテゴリ単位: import { defineTextComponents } from
|
|
|
47
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>` |
|
|
48
48
|
| **タイムライン** (`/components/timeline`) | `timeline()`(連結 · 重ね · ラベル · シーク · 逆再生 · スクラブ)· `<usa-timeline>`(`data-tl` ステップ) |
|
|
49
49
|
| **ジェスチャー** (`/components/gesture`) | `gesture()`(パン · スワイプ · ピンチ · 長押し · タップ → スプリング)· `<usa-swipeable>` · `<usa-pinch-zoom>` |
|
|
50
|
+
| **SVG** (`/components/svg`) | `<usa-draw>`(線描画)· `<usa-morph>`(パスモーフ)· `<usa-mask-reveal>` · `<usa-anim-icon>` · `morphTo()` |
|
|
50
51
|
|
|
51
52
|
## ドキュメント
|
|
52
53
|
|
package/README_zh.md
CHANGED
|
@@ -56,6 +56,7 @@ defineComponents(); // 或按分类:import { defineTextComponents } from 'use-
|
|
|
56
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>` 动效强度 |
|
|
57
57
|
| **时间线与编排** (`/components/timeline`) | `timeline()`(串联 · 重叠 · 标签 · 跳转 · 倒放 · 滚动擦洗)· `<usa-timeline>`(`data-tl` 步骤) |
|
|
58
58
|
| **手势** (`/components/gesture`) | `gesture()`(拖动 · 轻扫 · 捏合 · 长按 · 单击 · 双击 → 弹簧)· `<usa-swipeable>` · `<usa-pinch-zoom>` |
|
|
59
|
+
| **SVG 动画** (`/components/svg`) | `<usa-draw>`(线条描绘)· `<usa-morph>`(路径变形)· `<usa-mask-reveal>` · `<usa-anim-icon>` · `morphTo()` · `interpolatePath()` |
|
|
59
60
|
|
|
60
61
|
完整包约 22 kB gzip(JS + CSS);单个分类 3.5–6.4 kB;单个组件约 2 kB。下方的滚动动画核心不受影响。
|
|
61
62
|
|
|
@@ -16,7 +16,8 @@ const COMPONENT_CATEGORIES = {
|
|
|
16
16
|
page: ['usa-cursor', 'usa-fullpage', 'usa-loading-bar', 'usa-back-to-top', 'usa-ambient', 'usa-splash', 'usa-auto-skeleton', 'usa-motion-switch'],
|
|
17
17
|
timeline: ['usa-timeline'],
|
|
18
18
|
gesture: ['usa-swipeable', 'usa-pinch-zoom'],
|
|
19
|
+
svg: ['usa-draw', 'usa-morph', 'usa-mask-reveal', 'usa-anim-icon'],
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
exports.COMPONENT_CATEGORIES = COMPONENT_CATEGORIES;
|
|
22
|
-
//# sourceMappingURL=index-tags-
|
|
23
|
+
//# sourceMappingURL=index-tags-Cz4iTBEK.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-tags-
|
|
1
|
+
{"version":3,"file":"index-tags-Cz4iTBEK.cjs","sources":["../../src/components/index-tags.ts"],"sourcesContent":["// The component categories and their default tags (no imports: safe for lazy loaders).\n/** The component categories and their default tags. */\nexport const COMPONENT_CATEGORIES = {\n reveal: ['usa-reveal', 'usa-stagger', 'usa-scroll-progress', 'usa-scrolly'],\n 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'],\n interaction: ['usa-ripple', 'usa-magnetic', 'usa-tilt', 'usa-spotlight', 'usa-press', 'usa-toggle'],\n feedback: ['usa-spinner', 'usa-skeleton', 'usa-progress', 'usa-toaster', 'usa-check'],\n background: ['usa-aurora', 'usa-particles', 'usa-grain', 'usa-marquee', 'usa-acrylic', 'usa-grid-glow', 'usa-blobs', 'usa-water-ripple', 'usa-dot-network'],\n transitions: ['usa-dialog', 'usa-accordion', 'usa-flip-list', 'usa-view-switch'],\n physics: ['usa-spring', 'usa-draggable', 'usa-overscroll'],\n cards: ['usa-card', 'usa-card-stack', 'usa-sticky-stack', 'usa-carousel-3d'],\n click: ['usa-click', 'usa-button', 'usa-icon-morph', 'usa-like', 'usa-hold', 'usa-double-tap', 'usa-checkbox'],\n 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'],\n page: ['usa-cursor', 'usa-fullpage', 'usa-loading-bar', 'usa-back-to-top', 'usa-ambient', 'usa-splash', 'usa-auto-skeleton', 'usa-motion-switch'],\n timeline: ['usa-timeline'],\n gesture: ['usa-swipeable', 'usa-pinch-zoom'],\n svg: ['usa-draw', 'usa-morph', 'usa-mask-reveal', 'usa-anim-icon'],\n} as const;\n\nexport type ComponentCategory = keyof typeof COMPONENT_CATEGORIES;\n"],"names":[],"mappings":";;AAAA;AACA;AACO,MAAM,oBAAoB,GAAG;IAClC,MAAM,EAAE,CAAC,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,aAAa,CAAC;IAC3E,IAAI,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,sBAAsB,CAAC;AAC/M,IAAA,WAAW,EAAE,CAAC,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,CAAC;IACnG,QAAQ,EAAE,CAAC,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,WAAW,CAAC;AACrF,IAAA,UAAU,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,kBAAkB,EAAE,iBAAiB,CAAC;IAC3J,WAAW,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,iBAAiB,CAAC;AAChF,IAAA,OAAO,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,gBAAgB,CAAC;IAC1D,KAAK,EAAE,CAAC,UAAU,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,iBAAiB,CAAC;AAC5E,IAAA,KAAK,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,cAAc,CAAC;IAC9G,EAAE,EAAE,CAAC,UAAU,EAAE,YAAY,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,kBAAkB,CAAC;AAC1L,IAAA,IAAI,EAAE,CAAC,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa,EAAE,YAAY,EAAE,mBAAmB,EAAE,mBAAmB,CAAC;IACjJ,QAAQ,EAAE,CAAC,cAAc,CAAC;AAC1B,IAAA,OAAO,EAAE,CAAC,eAAe,EAAE,gBAAgB,CAAC;IAC5C,GAAG,EAAE,CAAC,UAAU,EAAE,WAAW,EAAE,iBAAiB,EAAE,eAAe,CAAC;;;;;"}
|
|
@@ -14,7 +14,8 @@ const COMPONENT_CATEGORIES = {
|
|
|
14
14
|
page: ['usa-cursor', 'usa-fullpage', 'usa-loading-bar', 'usa-back-to-top', 'usa-ambient', 'usa-splash', 'usa-auto-skeleton', 'usa-motion-switch'],
|
|
15
15
|
timeline: ['usa-timeline'],
|
|
16
16
|
gesture: ['usa-swipeable', 'usa-pinch-zoom'],
|
|
17
|
+
svg: ['usa-draw', 'usa-morph', 'usa-mask-reveal', 'usa-anim-icon'],
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
export { COMPONENT_CATEGORIES as C };
|
|
20
|
-
//# sourceMappingURL=index-tags-
|
|
21
|
+
//# sourceMappingURL=index-tags-Dc_Z4yAY.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-tags-
|
|
1
|
+
{"version":3,"file":"index-tags-Dc_Z4yAY.js","sources":["../../src/components/index-tags.ts"],"sourcesContent":["// The component categories and their default tags (no imports: safe for lazy loaders).\n/** The component categories and their default tags. */\nexport const COMPONENT_CATEGORIES = {\n reveal: ['usa-reveal', 'usa-stagger', 'usa-scroll-progress', 'usa-scrolly'],\n 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'],\n interaction: ['usa-ripple', 'usa-magnetic', 'usa-tilt', 'usa-spotlight', 'usa-press', 'usa-toggle'],\n feedback: ['usa-spinner', 'usa-skeleton', 'usa-progress', 'usa-toaster', 'usa-check'],\n background: ['usa-aurora', 'usa-particles', 'usa-grain', 'usa-marquee', 'usa-acrylic', 'usa-grid-glow', 'usa-blobs', 'usa-water-ripple', 'usa-dot-network'],\n transitions: ['usa-dialog', 'usa-accordion', 'usa-flip-list', 'usa-view-switch'],\n physics: ['usa-spring', 'usa-draggable', 'usa-overscroll'],\n cards: ['usa-card', 'usa-card-stack', 'usa-sticky-stack', 'usa-carousel-3d'],\n click: ['usa-click', 'usa-button', 'usa-icon-morph', 'usa-like', 'usa-hold', 'usa-double-tap', 'usa-checkbox'],\n 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'],\n page: ['usa-cursor', 'usa-fullpage', 'usa-loading-bar', 'usa-back-to-top', 'usa-ambient', 'usa-splash', 'usa-auto-skeleton', 'usa-motion-switch'],\n timeline: ['usa-timeline'],\n gesture: ['usa-swipeable', 'usa-pinch-zoom'],\n svg: ['usa-draw', 'usa-morph', 'usa-mask-reveal', 'usa-anim-icon'],\n} as const;\n\nexport type ComponentCategory = keyof typeof COMPONENT_CATEGORIES;\n"],"names":[],"mappings":"AAAA;AACA;AACO,MAAM,oBAAoB,GAAG;IAClC,MAAM,EAAE,CAAC,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,aAAa,CAAC;IAC3E,IAAI,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,sBAAsB,CAAC;AAC/M,IAAA,WAAW,EAAE,CA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fullpage", "usa-loading-bar", "usa-back-to-top", "usa-ambient", "usa-splash", "usa-auto-skeleton", "usa-motion-switch"];
|
|
14
14
|
readonly timeline: readonly ["usa-timeline"];
|
|
15
15
|
readonly gesture: readonly ["usa-swipeable", "usa-pinch-zoom"];
|
|
16
|
+
readonly svg: readonly ["usa-draw", "usa-morph", "usa-mask-reveal", "usa-anim-icon"];
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
/**
|
package/dist/components/jsx.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ declare const COMPONENT_CATEGORIES: {
|
|
|
13
13
|
readonly page: readonly ["usa-cursor", "usa-fullpage", "usa-loading-bar", "usa-back-to-top", "usa-ambient", "usa-splash", "usa-auto-skeleton", "usa-motion-switch"];
|
|
14
14
|
readonly timeline: readonly ["usa-timeline"];
|
|
15
15
|
readonly gesture: readonly ["usa-swipeable", "usa-pinch-zoom"];
|
|
16
|
+
readonly svg: readonly ["usa-draw", "usa-morph", "usa-mask-reveal", "usa-anim-icon"];
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
/**
|
package/dist/components/lazy.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var indexTags = require('../chunks/index-tags-
|
|
3
|
+
var indexTags = require('../chunks/index-tags-Cz4iTBEK.cjs');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* use-scroll-animate/components/lazy — lazy, per-category registration (v2.9).
|
|
@@ -29,6 +29,7 @@ const LOADERS = {
|
|
|
29
29
|
page: () => Promise.resolve().then(function () { return require('./page.cjs'); }),
|
|
30
30
|
timeline: () => Promise.resolve().then(function () { return require('./timeline.cjs'); }),
|
|
31
31
|
gesture: () => Promise.resolve().then(function () { return require('./gesture.cjs'); }),
|
|
32
|
+
svg: () => Promise.resolve().then(function () { return require('./svg.cjs'); }),
|
|
32
33
|
};
|
|
33
34
|
const TAG_TO_CAT = new Map();
|
|
34
35
|
for (const [cat, tags] of Object.entries(indexTags.COMPONENT_CATEGORIES))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy.cjs","sources":["../../src/components/lazy.ts"],"sourcesContent":["/**\n * use-scroll-animate/components/lazy — lazy, per-category registration (v2.9).\n *\n * `lazyDefine()` scans the page (and watches it with a MutationObserver) for\n * `<usa-*>` tags that are not registered yet and dynamically imports only the\n * categories they belong to. Bundlers split each category into its own chunk,\n * so a page that only uses `<usa-button>` loads just the click category.\n *\n * ```js\n * import { lazyDefine } from 'use-scroll-animate/components/lazy';\n * lazyDefine(); // returns a stop() function\n * ```\n */\nimport { COMPONENT_CATEGORIES, type ComponentCategory } from './index-tags';\n\nconst LOADERS: Record<ComponentCategory, () => Promise<Record<string, any>>> = {\n reveal: () => import('./reveal/index'),\n text: () => import('./text/index'),\n interaction: () => import('./interaction/index'),\n feedback: () => import('./feedback/index'),\n background: () => import('./background/index'),\n transitions: () => import('./transitions/index'),\n physics: () => import('./physics/index'),\n cards: () => import('./cards/index'),\n click: () => import('./click/index'),\n ui: () => import('./ui/index'),\n page: () => import('./page/index'),\n timeline: () => import('./timeline/index'),\n gesture: () => import('./gesture/index'),\n};\n\nconst TAG_TO_CAT = new Map<string, ComponentCategory>();\nfor (const [cat, tags] of Object.entries(COMPONENT_CATEGORIES)) for (const t of tags) TAG_TO_CAT.set(t, cat as ComponentCategory);\nconst loaded = new Map<ComponentCategory, Promise<void>>();\n\n/** Category of a tag (`usa-button` → `click`), or `null`. */\nexport const categoryOfTag = (tag: string): ComponentCategory | null => TAG_TO_CAT.get(tag.toLowerCase()) ?? null;\n\n/** Load and register one category (once). */\nexport function loadCategory(cat: ComponentCategory): Promise<void> {\n let p = loaded.get(cat);\n if (!p) {\n p = LOADERS[cat]().then((m) => {\n const fn = Object.keys(m).find((k) => /^define[A-Z]\\w*Components$/.test(k));\n if (fn) m[fn]();\n });\n loaded.set(cat, p);\n }\n return p;\n}\n\n/** Register the categories needed by the `<usa-*>` tags under `root`. Resolves when they are defined. */\nexport async function defineUsed(root: ParentNode = document): Promise<ComponentCategory[]> {\n if (typeof customElements === 'undefined') return [];\n const cats = new Set<ComponentCategory>();\n const scan = (el: Element) => {\n const c = el.localName.startsWith('usa-') && !customElements.get(el.localName) ? categoryOfTag(el.localName) : null;\n if (c) cats.add(c);\n };\n if ((root as Element).localName) scan(root as Element);\n root.querySelectorAll('*').forEach(scan);\n await Promise.all([...cats].map(loadCategory));\n return [...cats];\n}\n\n/** `defineUsed()` now and whenever new `<usa-*>` elements are added. Returns a stop function. */\nexport function lazyDefine(root: ParentNode = typeof document !== 'undefined' ? document : (undefined as any)): () => void {\n if (!root || typeof MutationObserver === 'undefined') return () => undefined;\n defineUsed(root);\n const mo = new MutationObserver((records) => {\n for (const r of records) r.addedNodes.forEach((n) => n.nodeType === 1 && defineUsed(n as Element));\n });\n mo.observe(root as Node, { childList: true, subtree: true });\n return () => mo.disconnect();\n}\n"],"names":["COMPONENT_CATEGORIES"],"mappings":";;;;AAAA;;;;;;;;;;;;AAYG;AAGH,MAAM,OAAO,GAAkE;AAC7E,IAAA,MAAM,EAAE,MAAM,oDAAO,cAAgB,KAAC;AACtC,IAAA,IAAI,EAAE,MAAM,oDAAO,YAAc,KAAC;AAClC,IAAA,WAAW,EAAE,MAAM,oDAAO,mBAAqB,KAAC;AAChD,IAAA,QAAQ,EAAE,MAAM,oDAAO,gBAAkB,KAAC;AAC1C,IAAA,UAAU,EAAE,MAAM,oDAAO,kBAAoB,KAAC;AAC9C,IAAA,WAAW,EAAE,MAAM,oDAAO,mBAAqB,KAAC;AAChD,IAAA,OAAO,EAAE,MAAM,oDAAO,eAAiB,KAAC;AACxC,IAAA,KAAK,EAAE,MAAM,oDAAO,aAAe,KAAC;AACpC,IAAA,KAAK,EAAE,MAAM,oDAAO,aAAe,KAAC;AACpC,IAAA,EAAE,EAAE,MAAM,oDAAO,UAAY,KAAC;AAC9B,IAAA,IAAI,EAAE,MAAM,oDAAO,YAAc,KAAC;AAClC,IAAA,QAAQ,EAAE,MAAM,oDAAO,gBAAkB,KAAC;AAC1C,IAAA,OAAO,EAAE,MAAM,oDAAO,eAAiB,KAAC;
|
|
1
|
+
{"version":3,"file":"lazy.cjs","sources":["../../src/components/lazy.ts"],"sourcesContent":["/**\n * use-scroll-animate/components/lazy — lazy, per-category registration (v2.9).\n *\n * `lazyDefine()` scans the page (and watches it with a MutationObserver) for\n * `<usa-*>` tags that are not registered yet and dynamically imports only the\n * categories they belong to. Bundlers split each category into its own chunk,\n * so a page that only uses `<usa-button>` loads just the click category.\n *\n * ```js\n * import { lazyDefine } from 'use-scroll-animate/components/lazy';\n * lazyDefine(); // returns a stop() function\n * ```\n */\nimport { COMPONENT_CATEGORIES, type ComponentCategory } from './index-tags';\n\nconst LOADERS: Record<ComponentCategory, () => Promise<Record<string, any>>> = {\n reveal: () => import('./reveal/index'),\n text: () => import('./text/index'),\n interaction: () => import('./interaction/index'),\n feedback: () => import('./feedback/index'),\n background: () => import('./background/index'),\n transitions: () => import('./transitions/index'),\n physics: () => import('./physics/index'),\n cards: () => import('./cards/index'),\n click: () => import('./click/index'),\n ui: () => import('./ui/index'),\n page: () => import('./page/index'),\n timeline: () => import('./timeline/index'),\n gesture: () => import('./gesture/index'),\n svg: () => import('./svg/index'),\n};\n\nconst TAG_TO_CAT = new Map<string, ComponentCategory>();\nfor (const [cat, tags] of Object.entries(COMPONENT_CATEGORIES)) for (const t of tags) TAG_TO_CAT.set(t, cat as ComponentCategory);\nconst loaded = new Map<ComponentCategory, Promise<void>>();\n\n/** Category of a tag (`usa-button` → `click`), or `null`. */\nexport const categoryOfTag = (tag: string): ComponentCategory | null => TAG_TO_CAT.get(tag.toLowerCase()) ?? null;\n\n/** Load and register one category (once). */\nexport function loadCategory(cat: ComponentCategory): Promise<void> {\n let p = loaded.get(cat);\n if (!p) {\n p = LOADERS[cat]().then((m) => {\n const fn = Object.keys(m).find((k) => /^define[A-Z]\\w*Components$/.test(k));\n if (fn) m[fn]();\n });\n loaded.set(cat, p);\n }\n return p;\n}\n\n/** Register the categories needed by the `<usa-*>` tags under `root`. Resolves when they are defined. */\nexport async function defineUsed(root: ParentNode = document): Promise<ComponentCategory[]> {\n if (typeof customElements === 'undefined') return [];\n const cats = new Set<ComponentCategory>();\n const scan = (el: Element) => {\n const c = el.localName.startsWith('usa-') && !customElements.get(el.localName) ? categoryOfTag(el.localName) : null;\n if (c) cats.add(c);\n };\n if ((root as Element).localName) scan(root as Element);\n root.querySelectorAll('*').forEach(scan);\n await Promise.all([...cats].map(loadCategory));\n return [...cats];\n}\n\n/** `defineUsed()` now and whenever new `<usa-*>` elements are added. Returns a stop function. */\nexport function lazyDefine(root: ParentNode = typeof document !== 'undefined' ? document : (undefined as any)): () => void {\n if (!root || typeof MutationObserver === 'undefined') return () => undefined;\n defineUsed(root);\n const mo = new MutationObserver((records) => {\n for (const r of records) r.addedNodes.forEach((n) => n.nodeType === 1 && defineUsed(n as Element));\n });\n mo.observe(root as Node, { childList: true, subtree: true });\n return () => mo.disconnect();\n}\n"],"names":["COMPONENT_CATEGORIES"],"mappings":";;;;AAAA;;;;;;;;;;;;AAYG;AAGH,MAAM,OAAO,GAAkE;AAC7E,IAAA,MAAM,EAAE,MAAM,oDAAO,cAAgB,KAAC;AACtC,IAAA,IAAI,EAAE,MAAM,oDAAO,YAAc,KAAC;AAClC,IAAA,WAAW,EAAE,MAAM,oDAAO,mBAAqB,KAAC;AAChD,IAAA,QAAQ,EAAE,MAAM,oDAAO,gBAAkB,KAAC;AAC1C,IAAA,UAAU,EAAE,MAAM,oDAAO,kBAAoB,KAAC;AAC9C,IAAA,WAAW,EAAE,MAAM,oDAAO,mBAAqB,KAAC;AAChD,IAAA,OAAO,EAAE,MAAM,oDAAO,eAAiB,KAAC;AACxC,IAAA,KAAK,EAAE,MAAM,oDAAO,aAAe,KAAC;AACpC,IAAA,KAAK,EAAE,MAAM,oDAAO,aAAe,KAAC;AACpC,IAAA,EAAE,EAAE,MAAM,oDAAO,UAA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AE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC5D,IAAA,OAAO,MAAM,EAAE,CAAC,UAAU,EAAE;AAC9B;;;;;;;"}
|
|
@@ -13,6 +13,7 @@ declare const COMPONENT_CATEGORIES: {
|
|
|
13
13
|
readonly page: readonly ["usa-cursor", "usa-fullpage", "usa-loading-bar", "usa-back-to-top", "usa-ambient", "usa-splash", "usa-auto-skeleton", "usa-motion-switch"];
|
|
14
14
|
readonly timeline: readonly ["usa-timeline"];
|
|
15
15
|
readonly gesture: readonly ["usa-swipeable", "usa-pinch-zoom"];
|
|
16
|
+
readonly svg: readonly ["usa-draw", "usa-morph", "usa-mask-reveal", "usa-anim-icon"];
|
|
16
17
|
};
|
|
17
18
|
type ComponentCategory = keyof typeof COMPONENT_CATEGORIES;
|
|
18
19
|
|
|
@@ -13,6 +13,7 @@ declare const COMPONENT_CATEGORIES: {
|
|
|
13
13
|
readonly page: readonly ["usa-cursor", "usa-fullpage", "usa-loading-bar", "usa-back-to-top", "usa-ambient", "usa-splash", "usa-auto-skeleton", "usa-motion-switch"];
|
|
14
14
|
readonly timeline: readonly ["usa-timeline"];
|
|
15
15
|
readonly gesture: readonly ["usa-swipeable", "usa-pinch-zoom"];
|
|
16
|
+
readonly svg: readonly ["usa-draw", "usa-morph", "usa-mask-reveal", "usa-anim-icon"];
|
|
16
17
|
};
|
|
17
18
|
type ComponentCategory = keyof typeof COMPONENT_CATEGORIES;
|
|
18
19
|
|
package/dist/components/lazy.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as COMPONENT_CATEGORIES } from '../chunks/index-tags-
|
|
1
|
+
import { C as COMPONENT_CATEGORIES } from '../chunks/index-tags-Dc_Z4yAY.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* use-scroll-animate/components/lazy — lazy, per-category registration (v2.9).
|
|
@@ -27,6 +27,7 @@ const LOADERS = {
|
|
|
27
27
|
page: () => import('./page.js'),
|
|
28
28
|
timeline: () => import('./timeline.js'),
|
|
29
29
|
gesture: () => import('./gesture.js'),
|
|
30
|
+
svg: () => import('./svg.js'),
|
|
30
31
|
};
|
|
31
32
|
const TAG_TO_CAT = new Map();
|
|
32
33
|
for (const [cat, tags] of Object.entries(COMPONENT_CATEGORIES))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy.js","sources":["../../src/components/lazy.ts"],"sourcesContent":["/**\n * use-scroll-animate/components/lazy — lazy, per-category registration (v2.9).\n *\n * `lazyDefine()` scans the page (and watches it with a MutationObserver) for\n * `<usa-*>` tags that are not registered yet and dynamically imports only the\n * categories they belong to. Bundlers split each category into its own chunk,\n * so a page that only uses `<usa-button>` loads just the click category.\n *\n * ```js\n * import { lazyDefine } from 'use-scroll-animate/components/lazy';\n * lazyDefine(); // returns a stop() function\n * ```\n */\nimport { COMPONENT_CATEGORIES, type ComponentCategory } from './index-tags';\n\nconst LOADERS: Record<ComponentCategory, () => Promise<Record<string, any>>> = {\n reveal: () => import('./reveal/index'),\n text: () => import('./text/index'),\n interaction: () => import('./interaction/index'),\n feedback: () => import('./feedback/index'),\n background: () => import('./background/index'),\n transitions: () => import('./transitions/index'),\n physics: () => import('./physics/index'),\n cards: () => import('./cards/index'),\n click: () => import('./click/index'),\n ui: () => import('./ui/index'),\n page: () => import('./page/index'),\n timeline: () => import('./timeline/index'),\n gesture: () => import('./gesture/index'),\n};\n\nconst TAG_TO_CAT = new Map<string, ComponentCategory>();\nfor (const [cat, tags] of Object.entries(COMPONENT_CATEGORIES)) for (const t of tags) TAG_TO_CAT.set(t, cat as ComponentCategory);\nconst loaded = new Map<ComponentCategory, Promise<void>>();\n\n/** Category of a tag (`usa-button` → `click`), or `null`. */\nexport const categoryOfTag = (tag: string): ComponentCategory | null => TAG_TO_CAT.get(tag.toLowerCase()) ?? null;\n\n/** Load and register one category (once). */\nexport function loadCategory(cat: ComponentCategory): Promise<void> {\n let p = loaded.get(cat);\n if (!p) {\n p = LOADERS[cat]().then((m) => {\n const fn = Object.keys(m).find((k) => /^define[A-Z]\\w*Components$/.test(k));\n if (fn) m[fn]();\n });\n loaded.set(cat, p);\n }\n return p;\n}\n\n/** Register the categories needed by the `<usa-*>` tags under `root`. Resolves when they are defined. */\nexport async function defineUsed(root: ParentNode = document): Promise<ComponentCategory[]> {\n if (typeof customElements === 'undefined') return [];\n const cats = new Set<ComponentCategory>();\n const scan = (el: Element) => {\n const c = el.localName.startsWith('usa-') && !customElements.get(el.localName) ? categoryOfTag(el.localName) : null;\n if (c) cats.add(c);\n };\n if ((root as Element).localName) scan(root as Element);\n root.querySelectorAll('*').forEach(scan);\n await Promise.all([...cats].map(loadCategory));\n return [...cats];\n}\n\n/** `defineUsed()` now and whenever new `<usa-*>` elements are added. Returns a stop function. */\nexport function lazyDefine(root: ParentNode = typeof document !== 'undefined' ? document : (undefined as any)): () => void {\n if (!root || typeof MutationObserver === 'undefined') return () => undefined;\n defineUsed(root);\n const mo = new MutationObserver((records) => {\n for (const r of records) r.addedNodes.forEach((n) => n.nodeType === 1 && defineUsed(n as Element));\n });\n mo.observe(root as Node, { childList: true, subtree: true });\n return () => mo.disconnect();\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;AAYG;AAGH,MAAM,OAAO,GAAkE;AAC7E,IAAA,MAAM,EAAE,MAAM,OAAO,aAAgB,CAAC;AACtC,IAAA,IAAI,EAAE,MAAM,OAAO,WAAc,CAAC;AAClC,IAAA,WAAW,EAAE,MAAM,OAAO,kBAAqB,CAAC;AAChD,IAAA,QAAQ,EAAE,MAAM,OAAO,eAAkB,CAAC;AAC1C,IAAA,UAAU,EAAE,MAAM,OAAO,iBAAoB,CAAC;AAC9C,IAAA,WAAW,EAAE,MAAM,OAAO,kBAAqB,CAAC;AAChD,IAAA,OAAO,EAAE,MAAM,OAAO,cAAiB,CAAC;AACxC,IAAA,KAAK,EAAE,MAAM,OAAO,YAAe,CAAC;AACpC,IAAA,KAAK,EAAE,MAAM,OAAO,YAAe,CAAC;AACpC,IAAA,EAAE,EAAE,MAAM,OAAO,SAAY,CAAC;AAC9B,IAAA,IAAI,EAAE,MAAM,OAAO,WAAc,CAAC;AAClC,IAAA,QAAQ,EAAE,MAAM,OAAO,eAAkB,CAAC;AAC1C,IAAA,OAAO,EAAE,MAAM,OAAO,cAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"lazy.js","sources":["../../src/components/lazy.ts"],"sourcesContent":["/**\n * use-scroll-animate/components/lazy — lazy, per-category registration (v2.9).\n *\n * `lazyDefine()` scans the page (and watches it with a MutationObserver) for\n * `<usa-*>` tags that are not registered yet and dynamically imports only the\n * categories they belong to. Bundlers split each category into its own chunk,\n * so a page that only uses `<usa-button>` loads just the click category.\n *\n * ```js\n * import { lazyDefine } from 'use-scroll-animate/components/lazy';\n * lazyDefine(); // returns a stop() function\n * ```\n */\nimport { COMPONENT_CATEGORIES, type ComponentCategory } from './index-tags';\n\nconst LOADERS: Record<ComponentCategory, () => Promise<Record<string, any>>> = {\n reveal: () => import('./reveal/index'),\n text: () => import('./text/index'),\n interaction: () => import('./interaction/index'),\n feedback: () => import('./feedback/index'),\n background: () => import('./background/index'),\n transitions: () => import('./transitions/index'),\n physics: () => import('./physics/index'),\n cards: () => import('./cards/index'),\n click: () => import('./click/index'),\n ui: () => import('./ui/index'),\n page: () => import('./page/index'),\n timeline: () => import('./timeline/index'),\n gesture: () => import('./gesture/index'),\n svg: () => import('./svg/index'),\n};\n\nconst TAG_TO_CAT = new Map<string, ComponentCategory>();\nfor (const [cat, tags] of Object.entries(COMPONENT_CATEGORIES)) for (const t of tags) TAG_TO_CAT.set(t, cat as ComponentCategory);\nconst loaded = new Map<ComponentCategory, Promise<void>>();\n\n/** Category of a tag (`usa-button` → `click`), or `null`. */\nexport const categoryOfTag = (tag: string): ComponentCategory | null => TAG_TO_CAT.get(tag.toLowerCase()) ?? null;\n\n/** Load and register one category (once). */\nexport function loadCategory(cat: ComponentCategory): Promise<void> {\n let p = loaded.get(cat);\n if (!p) {\n p = LOADERS[cat]().then((m) => {\n const fn = Object.keys(m).find((k) => /^define[A-Z]\\w*Components$/.test(k));\n if (fn) m[fn]();\n });\n loaded.set(cat, p);\n }\n return p;\n}\n\n/** Register the categories needed by the `<usa-*>` tags under `root`. Resolves when they are defined. */\nexport async function defineUsed(root: ParentNode = document): Promise<ComponentCategory[]> {\n if (typeof customElements === 'undefined') return [];\n const cats = new Set<ComponentCategory>();\n const scan = (el: Element) => {\n const c = el.localName.startsWith('usa-') && !customElements.get(el.localName) ? categoryOfTag(el.localName) : null;\n if (c) cats.add(c);\n };\n if ((root as Element).localName) scan(root as Element);\n root.querySelectorAll('*').forEach(scan);\n await Promise.all([...cats].map(loadCategory));\n return [...cats];\n}\n\n/** `defineUsed()` now and whenever new `<usa-*>` elements are added. Returns a stop function. */\nexport function lazyDefine(root: ParentNode = typeof document !== 'undefined' ? document : (undefined as any)): () => void {\n if (!root || typeof MutationObserver === 'undefined') return () => undefined;\n defineUsed(root);\n const mo = new MutationObserver((records) => {\n for (const r of records) r.addedNodes.forEach((n) => n.nodeType === 1 && defineUsed(n as Element));\n });\n mo.observe(root as Node, { childList: true, subtree: true });\n return () => mo.disconnect();\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;AAYG;AAGH,MAAM,OAAO,GAAkE;AAC7E,IAAA,MAAM,EAAE,MAAM,OAAO,aAAgB,CAAC;AACtC,IAAA,IAAI,EAAE,MAAM,OAAO,WAAc,CAAC;AAClC,IAAA,WAAW,EAAE,MAAM,OAAO,kBAAqB,CAAC;AAChD,IAAA,QAAQ,EAAE,MAAM,OAAO,eAAkB,CAAC;AAC1C,IAAA,UAAU,EAAE,MAAM,OAAO,iBAAoB,CAAC;AAC9C,IAAA,WAAW,EAAE,MAAM,OAAO,kBAAqB,CAAC;AAChD,IAAA,OAAO,EAAE,MAAM,OAAO,cAAiB,CAAC;AACxC,IAAA,KAAK,EAAE,MAAM,OAAO,YAAe,CAAC;AACpC,IAAA,KAAK,E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;AACF,IAAA,EAAE,CAAC,OAAO,CAAC,IAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC5D,IAAA,OAAO,MAAM,EAAE,CAAC,UAAU,EAAE;AAC9B;;;;"}
|
package/dist/components/react.js
CHANGED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var base = require('../chunks/base-CXx7jZ-o.cjs');
|
|
4
|
+
|
|
5
|
+
const NUM = /-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?/gi;
|
|
6
|
+
/** `true` when two path strings share the same commands (so their numbers can be interpolated). */
|
|
7
|
+
function pathsCompatible(a, b) {
|
|
8
|
+
return a.replace(NUM, '#').replace(/[\s,]+/g, ' ').trim() === b.replace(NUM, '#').replace(/[\s,]+/g, ' ').trim();
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Path data between `a` and `b` at `t` (0–1). Paths with the same command
|
|
12
|
+
* structure morph number-by-number; others switch at the midpoint.
|
|
13
|
+
*/
|
|
14
|
+
function interpolatePath(a, b, t) {
|
|
15
|
+
if (t <= 0)
|
|
16
|
+
return a;
|
|
17
|
+
if (t >= 1)
|
|
18
|
+
return b;
|
|
19
|
+
if (!pathsCompatible(a, b))
|
|
20
|
+
return t < 0.5 ? a : b;
|
|
21
|
+
const nb = b.match(NUM) || [];
|
|
22
|
+
let i = 0;
|
|
23
|
+
return a.replace(NUM, (n) => {
|
|
24
|
+
const v = Number(n) + (Number(nb[i++]) - Number(n)) * t;
|
|
25
|
+
return String(Math.round(v * 1000) / 1000);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const ease = (t) => 1 - Math.pow(1 - t, 3);
|
|
29
|
+
/** Animate a `<path>`'s `d` to `to`. Resolves when done; instant under reduced motion. */
|
|
30
|
+
function morphTo(path, to, o = {}) {
|
|
31
|
+
const from = path.getAttribute('d') || to;
|
|
32
|
+
const dur = (o.duration ?? 500) * base.motionScale();
|
|
33
|
+
const prev = path.__usaMorph;
|
|
34
|
+
if (prev)
|
|
35
|
+
base.caf(prev);
|
|
36
|
+
if (base.prefersReducedMotion() || dur <= 0 || from === to) {
|
|
37
|
+
path.setAttribute('d', to);
|
|
38
|
+
return Promise.resolve();
|
|
39
|
+
}
|
|
40
|
+
const fn = o.easing || ease;
|
|
41
|
+
const t0 = base.now();
|
|
42
|
+
return new Promise((resolve) => {
|
|
43
|
+
const step = () => {
|
|
44
|
+
const t = base.clamp((base.now() - t0) / dur, 0, 1);
|
|
45
|
+
path.setAttribute('d', interpolatePath(from, to, fn(t)));
|
|
46
|
+
if (t < 1)
|
|
47
|
+
path.__usaMorph = base.raf(step);
|
|
48
|
+
else {
|
|
49
|
+
path.__usaMorph = 0;
|
|
50
|
+
resolve();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
path.__usaMorph = base.raf(step);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const DRAWABLE = 'path, line, polyline, polygon, circle, ellipse, rect';
|
|
57
|
+
/**
|
|
58
|
+
* Prepare every stroke in `root` for line drawing (normalised `pathLength=1`,
|
|
59
|
+
* so no `getTotalLength()` is needed) and return a function that sets
|
|
60
|
+
* progress 0–1, optionally staggered between shapes.
|
|
61
|
+
*/
|
|
62
|
+
function drawLines(root, o = {}) {
|
|
63
|
+
const shapes = Array.from(root.querySelectorAll(DRAWABLE));
|
|
64
|
+
shapes.forEach((s) => {
|
|
65
|
+
s.setAttribute('pathLength', '1');
|
|
66
|
+
s.style.strokeDasharray = '1 1';
|
|
67
|
+
});
|
|
68
|
+
const st = base.clamp(o.stagger ?? 0, 0, 0.9);
|
|
69
|
+
return (p) => {
|
|
70
|
+
const n = shapes.length;
|
|
71
|
+
shapes.forEach((s, i) => {
|
|
72
|
+
const start = n > 1 ? (i / (n - 1)) * st : 0;
|
|
73
|
+
const local = base.clamp((p - start) / (1 - st || 1), 0, 1);
|
|
74
|
+
s.style.strokeDashoffset = String(1 - local);
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var css = "usa-draw{display:inline-block}usa-draw svg :is(path,line,polyline,polygon,circle,ellipse,rect){transition:fill-opacity 0.6s ease}usa-draw[fill]:not([data-drawn]) svg :is(path,polygon,circle,ellipse,rect){fill-opacity:0}usa-morph{display:inline-block;line-height:0}usa-morph svg{width:100%;height:100%;fill:currentColor}usa-morph[role=\"button\"]{cursor:pointer}usa-mask-reveal{display:block}usa-mask-reveal[data-state=\"visible\"]{clip-path:none !important}usa-anim-icon{display:inline-flex;line-height:0;vertical-align:middle}usa-anim-icon svg{overflow:visible}@media (prefers-reduced-motion:reduce){usa-mask-reveal{clip-path:none !important}usa-draw svg *{stroke-dashoffset:0 !important}}";
|
|
80
|
+
|
|
81
|
+
function defineDraw(tag = 'usa-draw') {
|
|
82
|
+
return base.defineElement(tag, (Base) => class UsaDraw extends Base {
|
|
83
|
+
constructor() {
|
|
84
|
+
super(...arguments);
|
|
85
|
+
this._set = () => { };
|
|
86
|
+
this._p = 0;
|
|
87
|
+
this._id = 0;
|
|
88
|
+
}
|
|
89
|
+
get progress() {
|
|
90
|
+
return this._p;
|
|
91
|
+
}
|
|
92
|
+
set progress(p) {
|
|
93
|
+
this._p = base.clamp(p, 0, 1);
|
|
94
|
+
this._set(this._p);
|
|
95
|
+
this.toggleAttribute('data-drawn', this._p >= 1);
|
|
96
|
+
}
|
|
97
|
+
play() {
|
|
98
|
+
base.caf(this._id);
|
|
99
|
+
if (this.reduced) {
|
|
100
|
+
this.progress = 1;
|
|
101
|
+
return void this.emit('complete');
|
|
102
|
+
}
|
|
103
|
+
const dur = this.num('duration', 1600) * base.motionScale();
|
|
104
|
+
const t0 = base.now();
|
|
105
|
+
this.progress = 0;
|
|
106
|
+
const step = () => {
|
|
107
|
+
this.progress = (base.now() - t0) / dur;
|
|
108
|
+
if (this._p < 1)
|
|
109
|
+
this._id = base.raf(step);
|
|
110
|
+
else
|
|
111
|
+
this.emit('complete');
|
|
112
|
+
};
|
|
113
|
+
this._id = base.raf(step);
|
|
114
|
+
}
|
|
115
|
+
mount() {
|
|
116
|
+
this._set = drawLines(this, { stagger: this.num('stagger', 0.2) });
|
|
117
|
+
const trigger = this.str('trigger', 'view');
|
|
118
|
+
if (this.reduced) {
|
|
119
|
+
this.progress = 1;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
this.progress = 0;
|
|
123
|
+
if (trigger === 'scrub') {
|
|
124
|
+
const update = () => {
|
|
125
|
+
const r = this.getBoundingClientRect();
|
|
126
|
+
const vh = window.innerHeight || 1;
|
|
127
|
+
this.progress = (vh - r.top) / (vh * 0.6 + r.height * 0.4 || 1);
|
|
128
|
+
};
|
|
129
|
+
this.listen(window, 'scroll', update, { passive: true });
|
|
130
|
+
update();
|
|
131
|
+
}
|
|
132
|
+
else if (trigger === 'hover')
|
|
133
|
+
this.listen(this, 'pointerenter', () => this.play());
|
|
134
|
+
else if (trigger === 'click')
|
|
135
|
+
this.listen(this, 'click', () => this.play());
|
|
136
|
+
else {
|
|
137
|
+
let done = false;
|
|
138
|
+
this.inView((v) => {
|
|
139
|
+
if (v && (!done || this.flag('repeat'))) {
|
|
140
|
+
done = true;
|
|
141
|
+
this.play();
|
|
142
|
+
}
|
|
143
|
+
else if (!v && this.flag('repeat'))
|
|
144
|
+
this.progress = 0;
|
|
145
|
+
}, { threshold: 0.3 });
|
|
146
|
+
}
|
|
147
|
+
this.onCleanup(() => base.caf(this._id));
|
|
148
|
+
}
|
|
149
|
+
}, { id: 'svg', text: css });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function defineMorph(tag = 'usa-morph') {
|
|
153
|
+
return base.defineElement(tag, (Base) => class UsaMorph extends Base {
|
|
154
|
+
constructor() {
|
|
155
|
+
super(...arguments);
|
|
156
|
+
this._i = 0;
|
|
157
|
+
this._path = null;
|
|
158
|
+
}
|
|
159
|
+
static get observedAttributes() {
|
|
160
|
+
return ['paths', 'trigger'];
|
|
161
|
+
}
|
|
162
|
+
get index() {
|
|
163
|
+
return this._i;
|
|
164
|
+
}
|
|
165
|
+
list() {
|
|
166
|
+
return this.str('paths').split('|').map((s) => s.trim()).filter(Boolean);
|
|
167
|
+
}
|
|
168
|
+
next() {
|
|
169
|
+
const l = this.list();
|
|
170
|
+
if (!this._path || l.length < 2)
|
|
171
|
+
return Promise.resolve();
|
|
172
|
+
this._i = (this._i + 1) % l.length;
|
|
173
|
+
this.emit('change', { index: this._i });
|
|
174
|
+
return morphTo(this._path, l[this._i], { duration: this.num('duration', 600) });
|
|
175
|
+
}
|
|
176
|
+
mount() {
|
|
177
|
+
let path = this.querySelector('path');
|
|
178
|
+
if (!path) {
|
|
179
|
+
this.innerHTML = '<svg viewBox="0 0 100 100" aria-hidden="true"><path></path></svg>';
|
|
180
|
+
path = this.querySelector('path');
|
|
181
|
+
}
|
|
182
|
+
this._path = path;
|
|
183
|
+
const l = this.list();
|
|
184
|
+
if (l[0])
|
|
185
|
+
this._path.setAttribute('d', l[this._i % l.length]);
|
|
186
|
+
const t = this.str('trigger', 'click');
|
|
187
|
+
if (t === 'hover') {
|
|
188
|
+
this.listen(this, 'pointerenter', () => void this.next());
|
|
189
|
+
this.listen(this, 'pointerleave', () => void this.next());
|
|
190
|
+
}
|
|
191
|
+
else if (t === 'auto' || t === 'view') {
|
|
192
|
+
let timer;
|
|
193
|
+
this.inView((v) => {
|
|
194
|
+
clearInterval(timer);
|
|
195
|
+
if (!v || this.reduced)
|
|
196
|
+
return;
|
|
197
|
+
if (t === 'view')
|
|
198
|
+
return void this.next();
|
|
199
|
+
timer = setInterval(() => void this.next(), this.num('interval', 2000));
|
|
200
|
+
});
|
|
201
|
+
this.onCleanup(() => clearInterval(timer));
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
if (!this.hasAttribute('tabindex'))
|
|
205
|
+
this.tabIndex = 0;
|
|
206
|
+
if (!this.hasAttribute('role'))
|
|
207
|
+
this.setAttribute('role', 'button');
|
|
208
|
+
this.listen(this, 'click', () => void this.next());
|
|
209
|
+
this.listen(this, 'keydown', (e) => {
|
|
210
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
211
|
+
e.preventDefault();
|
|
212
|
+
void this.next();
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}, { id: 'svg', text: css });
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Clip-path start / end frames for each reveal shape. */
|
|
221
|
+
const MASK_SHAPES = {
|
|
222
|
+
circle: ['circle(0% at 50% 50%)', 'circle(75% at 50% 50%)'],
|
|
223
|
+
diamond: ['polygon(50% 50%, 50% 50%, 50% 50%, 50% 50%)', 'polygon(50% -50%, 150% 50%, 50% 150%, -50% 50%)'],
|
|
224
|
+
wipe: ['inset(0 100% 0 0)', 'inset(0 0% 0 0)'],
|
|
225
|
+
'wipe-up': ['inset(100% 0 0 0)', 'inset(0% 0 0 0)'],
|
|
226
|
+
iris: ['inset(50% 50% 50% 50% round 50%)', 'inset(0% 0% 0% 0% round 0%)'],
|
|
227
|
+
star: [
|
|
228
|
+
'polygon(50% 50%, 50% 50%, 50% 50%, 50% 50%, 50% 50%, 50% 50%, 50% 50%, 50% 50%, 50% 50%, 50% 50%)',
|
|
229
|
+
'polygon(50% -60%, 80% 20%, 160% 30%, 95% 85%, 115% 170%, 50% 125%, -15% 170%, 5% 85%, -60% 30%, 20% 20%)',
|
|
230
|
+
],
|
|
231
|
+
};
|
|
232
|
+
function defineMaskReveal(tag = 'usa-mask-reveal') {
|
|
233
|
+
return base.defineElement(tag, (Base) => class UsaMaskReveal extends Base {
|
|
234
|
+
frames() {
|
|
235
|
+
const s = MASK_SHAPES[this.str('shape', 'circle')] || MASK_SHAPES.circle;
|
|
236
|
+
const at = this.str('at');
|
|
237
|
+
return at && s[0].startsWith('circle') ? [s[0].replace('50% 50%', at), s[1].replace('50% 50%', at)] : s;
|
|
238
|
+
}
|
|
239
|
+
reveal() {
|
|
240
|
+
const [a, b] = this.frames();
|
|
241
|
+
this.setAttribute('data-state', 'revealing');
|
|
242
|
+
const anim = this.motion(this, [{ clipPath: a }, { clipPath: b }], { duration: this.num('duration', 900), delay: this.num('delay', 0), easing: base.EASE_OUT, fill: 'forwards' });
|
|
243
|
+
const done = () => {
|
|
244
|
+
this.setAttribute('data-state', 'visible');
|
|
245
|
+
this.emit('complete');
|
|
246
|
+
};
|
|
247
|
+
if (!anim)
|
|
248
|
+
return Promise.resolve(done());
|
|
249
|
+
return anim.finished.then(done, () => { });
|
|
250
|
+
}
|
|
251
|
+
mount() {
|
|
252
|
+
if (this.reduced) {
|
|
253
|
+
this.setAttribute('data-state', 'visible');
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
this.setAttribute('data-state', 'hidden');
|
|
257
|
+
this.style.clipPath = this.frames()[0];
|
|
258
|
+
this.onCleanup(() => (this.style.clipPath = ''));
|
|
259
|
+
const t = this.str('trigger', 'view');
|
|
260
|
+
if (t === 'hover')
|
|
261
|
+
this.listen(this, 'pointerenter', () => void this.reveal());
|
|
262
|
+
else if (t === 'click')
|
|
263
|
+
this.listen(this, 'click', () => void this.reveal());
|
|
264
|
+
else {
|
|
265
|
+
let done = false;
|
|
266
|
+
this.inView((v) => {
|
|
267
|
+
if (v && (!done || this.flag('repeat'))) {
|
|
268
|
+
done = true;
|
|
269
|
+
void this.reveal();
|
|
270
|
+
}
|
|
271
|
+
else if (!v && this.flag('repeat')) {
|
|
272
|
+
this.getAnimations?.().forEach((x) => x.cancel());
|
|
273
|
+
this.style.clipPath = this.frames()[0];
|
|
274
|
+
this.setAttribute('data-state', 'hidden');
|
|
275
|
+
}
|
|
276
|
+
}, { threshold: 0.25 });
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}, { id: 'svg', text: css });
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** Built-in animated icons (24×24 strokes) and the motion each one plays. */
|
|
283
|
+
const ANIM_ICONS = {
|
|
284
|
+
bell: { d: 'M6 16V11a6 6 0 0 1 12 0v5l2 2H4l2-2M10 20a2 2 0 0 0 4 0', duration: 800, origin: '50% 10%', frames: [{ rotate: '0deg' }, { rotate: '18deg' }, { rotate: '-14deg' }, { rotate: '9deg' }, { rotate: '-5deg' }, { rotate: '0deg' }] },
|
|
285
|
+
heart: { d: 'M12 20s-7-4.4-7-10a4 4 0 0 1 7-2.6A4 4 0 0 1 19 10c0 5.6-7 10-7 10z', duration: 600, frames: [{ scale: 1 }, { scale: 1.3 }, { scale: 0.92 }, { scale: 1.12 }, { scale: 1 }] },
|
|
286
|
+
check: { d: 'M4 12.5l5 5L20 6.5', duration: 600, frames: [{ strokeDashoffset: 1 }, { strokeDashoffset: 0 }] },
|
|
287
|
+
arrow: { d: 'M4 12h15M13 6l6 6-6 6', duration: 600, frames: [{ translate: '0 0' }, { translate: '5px 0' }, { translate: '0 0' }] },
|
|
288
|
+
star: { d: 'M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z', duration: 700, frames: [{ rotate: '0deg', scale: 1 }, { rotate: '72deg', scale: 1.2 }, { rotate: '144deg', scale: 1 }] },
|
|
289
|
+
gear: { d: 'M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8zM12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M4.9 19.1L7 17M17 7l2.1-2.1', duration: 900, frames: [{ rotate: '0deg' }, { rotate: '180deg' }] },
|
|
290
|
+
search: { d: 'M10.5 4a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13zM15.5 15.5L20 20', duration: 700, frames: [{ rotate: '0deg' }, { rotate: '-15deg' }, { rotate: '10deg' }, { rotate: '0deg' }] },
|
|
291
|
+
download: { d: 'M12 4v11M7 10l5 5 5-5M5 20h14', duration: 700, frames: [{ translate: '0 0' }, { translate: '0 3px' }, { translate: '0 0' }] },
|
|
292
|
+
};
|
|
293
|
+
function defineAnimIcon(tag = 'usa-anim-icon') {
|
|
294
|
+
return base.defineElement(tag, (Base) => class UsaAnimIcon extends Base {
|
|
295
|
+
static get observedAttributes() {
|
|
296
|
+
return ['name', 'size', 'label'];
|
|
297
|
+
}
|
|
298
|
+
icon() {
|
|
299
|
+
return ANIM_ICONS[this.str('name', 'heart')] || ANIM_ICONS.heart;
|
|
300
|
+
}
|
|
301
|
+
play() {
|
|
302
|
+
if (this.reduced)
|
|
303
|
+
return;
|
|
304
|
+
const svg = this.querySelector('svg');
|
|
305
|
+
const i = this.icon();
|
|
306
|
+
const target = i.frames[0].strokeDashoffset !== undefined ? this.querySelector('path') : svg;
|
|
307
|
+
if (target)
|
|
308
|
+
this.motion(target, i.frames, { duration: i.duration, easing: 'ease-in-out', iterations: this.str('trigger') === 'loop' ? Infinity : 1 });
|
|
309
|
+
}
|
|
310
|
+
mount() {
|
|
311
|
+
const i = this.icon();
|
|
312
|
+
const size = this.num('size', 24);
|
|
313
|
+
const label = this.str('label');
|
|
314
|
+
this.innerHTML = `<svg viewBox="0 0 24 24" width="${size}" height="${size}" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="transform-origin:${i.origin || '50% 50%'}"${label ? ` role="img" aria-label="${label.replace(/"/g, '"')}"` : ' aria-hidden="true"'}><path d="${i.d}"${i.frames[0].strokeDashoffset !== undefined ? ' pathLength="1" stroke-dasharray="1"' : ''}></path></svg>`;
|
|
315
|
+
const t = this.str('trigger', 'hover');
|
|
316
|
+
if (t === 'click')
|
|
317
|
+
this.listen(this, 'click', () => this.play());
|
|
318
|
+
else if (t === 'view' || t === 'loop')
|
|
319
|
+
this.inView((v) => v && this.play(), { threshold: 0.5 });
|
|
320
|
+
else {
|
|
321
|
+
this.listen(this, 'pointerenter', () => this.play());
|
|
322
|
+
this.listen(this, 'focusin', () => this.play());
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}, { id: 'svg', text: css });
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* use-scroll-animate/components/svg — SVG animation (v3.3).
|
|
330
|
+
* `<usa-draw>` (line drawing), `<usa-morph>` (path morph), `<usa-mask-reveal>`
|
|
331
|
+
* (mask / clip-path reveals) and `<usa-anim-icon>` (animated icons), plus
|
|
332
|
+
* `interpolatePath()`, `morphTo()`, `drawLines()`.
|
|
333
|
+
*/
|
|
334
|
+
/** Register every component of this category under its default tag. */
|
|
335
|
+
function defineSvgComponents() {
|
|
336
|
+
defineDraw();
|
|
337
|
+
defineMorph();
|
|
338
|
+
defineMaskReveal();
|
|
339
|
+
defineAnimIcon();
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
exports.configureComponents = base.configureComponents;
|
|
343
|
+
exports.prefersReducedMotion = base.prefersReducedMotion;
|
|
344
|
+
exports.ANIM_ICONS = ANIM_ICONS;
|
|
345
|
+
exports.MASK_SHAPES = MASK_SHAPES;
|
|
346
|
+
exports.defineAnimIcon = defineAnimIcon;
|
|
347
|
+
exports.defineDraw = defineDraw;
|
|
348
|
+
exports.defineMaskReveal = defineMaskReveal;
|
|
349
|
+
exports.defineMorph = defineMorph;
|
|
350
|
+
exports.defineSvgComponents = defineSvgComponents;
|
|
351
|
+
exports.drawLines = drawLines;
|
|
352
|
+
exports.interpolatePath = interpolatePath;
|
|
353
|
+
exports.morphTo = morphTo;
|
|
354
|
+
exports.pathsCompatible = pathsCompatible;
|
|
355
|
+
//# sourceMappingURL=svg.cjs.map
|