use-scroll-animate 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +30 -2
  3. package/README_ja.md +18 -0
  4. package/README_zh.md +29 -0
  5. package/dist/chunks/base-BiTc85p_.cjs +232 -0
  6. package/dist/chunks/base-BiTc85p_.cjs.map +1 -0
  7. package/dist/chunks/base-CFtnmfli.js +219 -0
  8. package/dist/chunks/base-CFtnmfli.js.map +1 -0
  9. package/dist/components/background.cjs +395 -0
  10. package/dist/components/background.cjs.map +1 -0
  11. package/dist/components/background.css +7 -0
  12. package/dist/components/background.d.cts +132 -0
  13. package/dist/components/background.d.ts +132 -0
  14. package/dist/components/background.js +387 -0
  15. package/dist/components/background.js.map +1 -0
  16. package/dist/components/feedback.cjs +444 -0
  17. package/dist/components/feedback.cjs.map +1 -0
  18. package/dist/components/feedback.css +7 -0
  19. package/dist/components/feedback.d.cts +170 -0
  20. package/dist/components/feedback.d.ts +170 -0
  21. package/dist/components/feedback.js +434 -0
  22. package/dist/components/feedback.js.map +1 -0
  23. package/dist/components/interaction.cjs +426 -0
  24. package/dist/components/interaction.cjs.map +1 -0
  25. package/dist/components/interaction.css +8 -0
  26. package/dist/components/interaction.d.cts +142 -0
  27. package/dist/components/interaction.d.ts +142 -0
  28. package/dist/components/interaction.js +417 -0
  29. package/dist/components/interaction.js.map +1 -0
  30. package/dist/components/reveal.cjs +360 -0
  31. package/dist/components/reveal.cjs.map +1 -0
  32. package/dist/components/reveal.css +5 -0
  33. package/dist/components/reveal.d.cts +132 -0
  34. package/dist/components/reveal.d.ts +132 -0
  35. package/dist/components/reveal.js +350 -0
  36. package/dist/components/reveal.js.map +1 -0
  37. package/dist/components/text.cjs +528 -0
  38. package/dist/components/text.cjs.map +1 -0
  39. package/dist/components/text.css +7 -0
  40. package/dist/components/text.d.cts +164 -0
  41. package/dist/components/text.d.ts +164 -0
  42. package/dist/components/text.js +517 -0
  43. package/dist/components/text.js.map +1 -0
  44. package/dist/components/transitions.cjs +546 -0
  45. package/dist/components/transitions.cjs.map +1 -0
  46. package/dist/components/transitions.css +6 -0
  47. package/dist/components/transitions.d.cts +180 -0
  48. package/dist/components/transitions.d.ts +180 -0
  49. package/dist/components/transitions.js +536 -0
  50. package/dist/components/transitions.js.map +1 -0
  51. package/dist/components.cjs +106 -0
  52. package/dist/components.cjs.map +1 -0
  53. package/dist/components.css +30 -0
  54. package/dist/components.d.cts +741 -0
  55. package/dist/components.d.ts +741 -0
  56. package/dist/components.js +61 -0
  57. package/dist/components.js.map +1 -0
  58. package/dist/components.umd.js +22 -0
  59. package/dist/components.umd.js.map +1 -0
  60. package/docs/API.md +2 -0
  61. package/docs/components.md +155 -0
  62. package/docs/windows-apps.md +108 -0
  63. package/package.json +93 -5
@@ -0,0 +1,132 @@
1
+ /**
2
+ * use-scroll-animate/components — shared base for the `<usa-*>` custom elements.
3
+ *
4
+ * Everything here is lazy: nothing touches `window`, `document`,
5
+ * `HTMLElement` or `matchMedia` at import time, so the components can be
6
+ * imported during SSR (Next, Nuxt, Astro…) and in Electron/Tauri preload
7
+ * scripts. Classes are created the first time a `define*()` function runs.
8
+ */
9
+ interface ComponentsConfig {
10
+ /**
11
+ * Inject each component's CSS when it is defined (default `true`). Uses a
12
+ * constructable stylesheet (`document.adoptedStyleSheets`, which a strict
13
+ * `style-src` CSP does not block) and falls back to a `<style>` tag. Set
14
+ * to `false` when you load `use-scroll-animate/components.css` yourself.
15
+ */
16
+ injectStyles?: boolean;
17
+ /**
18
+ * `'user'` (default) follows `prefers-reduced-motion`; `'reduce'` always
19
+ * uses the reduced variants (e.g. a kiosk / battery-saver mode);
20
+ * `'no-preference'` ignores the OS setting (only for demos — respect your users).
21
+ */
22
+ reducedMotion?: 'user' | 'reduce' | 'no-preference';
23
+ }
24
+ /** Change global component settings (call before `define*()` for `injectStyles`). */
25
+ declare function configureComponents(options: ComponentsConfig): void;
26
+ /** `true` when animations should be reduced (OS setting or `configureComponents`). */
27
+ declare function prefersReducedMotion(): boolean;
28
+ /**
29
+ * Members shared by every `<usa-*>` element. Attribute helpers, a cleanup
30
+ * bag that is emptied on disconnect, and motion helpers that degrade to the
31
+ * final state without WAAPI or under reduced motion.
32
+ */
33
+ interface UsaElement extends HTMLElement {
34
+ /** `true` while reduced motion applies to this element. */
35
+ readonly reduced: boolean;
36
+ }
37
+
38
+ /**
39
+ * `<usa-aurora>` — a slow, drifting aurora / gradient-mesh backdrop behind
40
+ * its content. Soft radial gradients moved with `transform` only (no
41
+ * animated blur), paused while off-screen.
42
+ *
43
+ * Attributes: `colors` (comma-separated, default violet / cyan / pink),
44
+ * `speed` (multiplier, 1), `intensity` (0–1 opacity, 0.7), `paused`.
45
+ * Reduced motion: a still gradient.
46
+ */
47
+ type UsaAuroraElement = UsaElement;
48
+ declare function defineAurora(tag?: string): CustomElementConstructor | undefined;
49
+
50
+ /**
51
+ * `<usa-particles>` — a canvas of drifting particles, optionally linked by
52
+ * lines when close (a "constellation"), that drift away from the pointer.
53
+ * Fills its own box (place it as a background with
54
+ * `position: absolute; inset: 0`, or give it a height).
55
+ *
56
+ * Attributes: `count` (60; scaled down on small boxes), `color`
57
+ * (default `currentColor`), `size` (max radius px, 2.2), `speed` (0.35),
58
+ * `links` (max link distance px, 110; `0` disables), `interactive`,
59
+ * `paused`. Renders only while visible and the tab is shown, at device
60
+ * pixel ratio ≤ 2. Reduced motion: one still frame.
61
+ */
62
+ interface UsaParticlesElement extends UsaElement {
63
+ /** Re-seed the particles. */
64
+ reset(): void;
65
+ }
66
+ declare function defineParticles(tag?: string): CustomElementConstructor | undefined;
67
+
68
+ /**
69
+ * `<usa-grain>` — a film-grain / noise overlay on top of its content
70
+ * (SVG `feTurbulence` texture, no images to ship). With `animated`, the
71
+ * grain jitters like film (stepped `transform`, ~12 fps).
72
+ *
73
+ * Attributes: `opacity` (0.12), `animated`, `blend` (`mix-blend-mode`,
74
+ * default `overlay`), `scale` (texture size px, 180). Never intercepts
75
+ * pointer events. Reduced motion: static grain.
76
+ */
77
+ type UsaGrainElement = UsaElement;
78
+ declare function defineGrain(tag?: string): CustomElementConstructor | undefined;
79
+
80
+ /**
81
+ * `<usa-marquee>` — an infinite, seamless ticker of its children (logos,
82
+ * testimonials, tags). The content is cloned (clones are `aria-hidden` and
83
+ * `inert`) and the track slides with one WAAPI `transform` animation whose
84
+ * duration follows the measured width, so the speed is constant.
85
+ *
86
+ * Attributes: `speed` (px/s, 50), `direction` (`left` default | `right` |
87
+ * `up` | `down`), `gap` (px, 32), `pause-on-hover`, `fade` (soft edges),
88
+ * `paused`. Pauses off-screen. Reduced motion: no movement; the row
89
+ * becomes scrollable instead.
90
+ */
91
+ interface UsaMarqueeElement extends UsaElement {
92
+ pause(): void;
93
+ resume(): void;
94
+ }
95
+ declare function defineMarquee(tag?: string): CustomElementConstructor | undefined;
96
+
97
+ /**
98
+ * `<usa-acrylic>` — Windows Fluent materials for the web: `acrylic`
99
+ * (frosted glass: backdrop blur + saturation + tint + subtle noise) and
100
+ * `mica` (an opaque, wallpaper-tinted base for app backgrounds; on the web it
101
+ * tints from `--usa-mica-source`, a gradient you control). Optional
102
+ * `shimmer` adds a light sweep when it appears or on hover.
103
+ *
104
+ * Attributes: `variant` (`acrylic` default | `mica`), `tint` (colour),
105
+ * `tint-opacity` (0–1, 0.55), `blur` (px, 30), `shimmer`
106
+ * (`hover` | `load` | `none`, default `none`). Falls back to a solid tint
107
+ * without `backdrop-filter` and under `prefers-reduced-transparency` or
108
+ * forced colours, like Windows does when transparency effects are off.
109
+ */
110
+ type UsaAcrylicElement = UsaElement;
111
+ declare function defineAcrylic(tag?: string): CustomElementConstructor | undefined;
112
+
113
+ /**
114
+ * use-scroll-animate/components/background — backgrounds & decoration.
115
+ * `<usa-aurora>`, `<usa-particles>`, `<usa-grain>`, `<usa-marquee>`,
116
+ * `<usa-acrylic>`.
117
+ */
118
+
119
+ /** Register every component of this category under its default tag. */
120
+ declare function defineBackgroundComponents(): void;
121
+ declare global {
122
+ interface HTMLElementTagNameMap {
123
+ 'usa-aurora': UsaAuroraElement;
124
+ 'usa-particles': UsaParticlesElement;
125
+ 'usa-grain': UsaGrainElement;
126
+ 'usa-marquee': UsaMarqueeElement;
127
+ 'usa-acrylic': UsaAcrylicElement;
128
+ }
129
+ }
130
+
131
+ export { configureComponents, defineAcrylic, defineAurora, defineBackgroundComponents, defineGrain, defineMarquee, defineParticles, prefersReducedMotion };
132
+ export type { ComponentsConfig, UsaAcrylicElement, UsaAuroraElement, UsaElement, UsaGrainElement, UsaMarqueeElement, UsaParticlesElement };
@@ -0,0 +1,132 @@
1
+ /**
2
+ * use-scroll-animate/components — shared base for the `<usa-*>` custom elements.
3
+ *
4
+ * Everything here is lazy: nothing touches `window`, `document`,
5
+ * `HTMLElement` or `matchMedia` at import time, so the components can be
6
+ * imported during SSR (Next, Nuxt, Astro…) and in Electron/Tauri preload
7
+ * scripts. Classes are created the first time a `define*()` function runs.
8
+ */
9
+ interface ComponentsConfig {
10
+ /**
11
+ * Inject each component's CSS when it is defined (default `true`). Uses a
12
+ * constructable stylesheet (`document.adoptedStyleSheets`, which a strict
13
+ * `style-src` CSP does not block) and falls back to a `<style>` tag. Set
14
+ * to `false` when you load `use-scroll-animate/components.css` yourself.
15
+ */
16
+ injectStyles?: boolean;
17
+ /**
18
+ * `'user'` (default) follows `prefers-reduced-motion`; `'reduce'` always
19
+ * uses the reduced variants (e.g. a kiosk / battery-saver mode);
20
+ * `'no-preference'` ignores the OS setting (only for demos — respect your users).
21
+ */
22
+ reducedMotion?: 'user' | 'reduce' | 'no-preference';
23
+ }
24
+ /** Change global component settings (call before `define*()` for `injectStyles`). */
25
+ declare function configureComponents(options: ComponentsConfig): void;
26
+ /** `true` when animations should be reduced (OS setting or `configureComponents`). */
27
+ declare function prefersReducedMotion(): boolean;
28
+ /**
29
+ * Members shared by every `<usa-*>` element. Attribute helpers, a cleanup
30
+ * bag that is emptied on disconnect, and motion helpers that degrade to the
31
+ * final state without WAAPI or under reduced motion.
32
+ */
33
+ interface UsaElement extends HTMLElement {
34
+ /** `true` while reduced motion applies to this element. */
35
+ readonly reduced: boolean;
36
+ }
37
+
38
+ /**
39
+ * `<usa-aurora>` — a slow, drifting aurora / gradient-mesh backdrop behind
40
+ * its content. Soft radial gradients moved with `transform` only (no
41
+ * animated blur), paused while off-screen.
42
+ *
43
+ * Attributes: `colors` (comma-separated, default violet / cyan / pink),
44
+ * `speed` (multiplier, 1), `intensity` (0–1 opacity, 0.7), `paused`.
45
+ * Reduced motion: a still gradient.
46
+ */
47
+ type UsaAuroraElement = UsaElement;
48
+ declare function defineAurora(tag?: string): CustomElementConstructor | undefined;
49
+
50
+ /**
51
+ * `<usa-particles>` — a canvas of drifting particles, optionally linked by
52
+ * lines when close (a "constellation"), that drift away from the pointer.
53
+ * Fills its own box (place it as a background with
54
+ * `position: absolute; inset: 0`, or give it a height).
55
+ *
56
+ * Attributes: `count` (60; scaled down on small boxes), `color`
57
+ * (default `currentColor`), `size` (max radius px, 2.2), `speed` (0.35),
58
+ * `links` (max link distance px, 110; `0` disables), `interactive`,
59
+ * `paused`. Renders only while visible and the tab is shown, at device
60
+ * pixel ratio ≤ 2. Reduced motion: one still frame.
61
+ */
62
+ interface UsaParticlesElement extends UsaElement {
63
+ /** Re-seed the particles. */
64
+ reset(): void;
65
+ }
66
+ declare function defineParticles(tag?: string): CustomElementConstructor | undefined;
67
+
68
+ /**
69
+ * `<usa-grain>` — a film-grain / noise overlay on top of its content
70
+ * (SVG `feTurbulence` texture, no images to ship). With `animated`, the
71
+ * grain jitters like film (stepped `transform`, ~12 fps).
72
+ *
73
+ * Attributes: `opacity` (0.12), `animated`, `blend` (`mix-blend-mode`,
74
+ * default `overlay`), `scale` (texture size px, 180). Never intercepts
75
+ * pointer events. Reduced motion: static grain.
76
+ */
77
+ type UsaGrainElement = UsaElement;
78
+ declare function defineGrain(tag?: string): CustomElementConstructor | undefined;
79
+
80
+ /**
81
+ * `<usa-marquee>` — an infinite, seamless ticker of its children (logos,
82
+ * testimonials, tags). The content is cloned (clones are `aria-hidden` and
83
+ * `inert`) and the track slides with one WAAPI `transform` animation whose
84
+ * duration follows the measured width, so the speed is constant.
85
+ *
86
+ * Attributes: `speed` (px/s, 50), `direction` (`left` default | `right` |
87
+ * `up` | `down`), `gap` (px, 32), `pause-on-hover`, `fade` (soft edges),
88
+ * `paused`. Pauses off-screen. Reduced motion: no movement; the row
89
+ * becomes scrollable instead.
90
+ */
91
+ interface UsaMarqueeElement extends UsaElement {
92
+ pause(): void;
93
+ resume(): void;
94
+ }
95
+ declare function defineMarquee(tag?: string): CustomElementConstructor | undefined;
96
+
97
+ /**
98
+ * `<usa-acrylic>` — Windows Fluent materials for the web: `acrylic`
99
+ * (frosted glass: backdrop blur + saturation + tint + subtle noise) and
100
+ * `mica` (an opaque, wallpaper-tinted base for app backgrounds; on the web it
101
+ * tints from `--usa-mica-source`, a gradient you control). Optional
102
+ * `shimmer` adds a light sweep when it appears or on hover.
103
+ *
104
+ * Attributes: `variant` (`acrylic` default | `mica`), `tint` (colour),
105
+ * `tint-opacity` (0–1, 0.55), `blur` (px, 30), `shimmer`
106
+ * (`hover` | `load` | `none`, default `none`). Falls back to a solid tint
107
+ * without `backdrop-filter` and under `prefers-reduced-transparency` or
108
+ * forced colours, like Windows does when transparency effects are off.
109
+ */
110
+ type UsaAcrylicElement = UsaElement;
111
+ declare function defineAcrylic(tag?: string): CustomElementConstructor | undefined;
112
+
113
+ /**
114
+ * use-scroll-animate/components/background — backgrounds & decoration.
115
+ * `<usa-aurora>`, `<usa-particles>`, `<usa-grain>`, `<usa-marquee>`,
116
+ * `<usa-acrylic>`.
117
+ */
118
+
119
+ /** Register every component of this category under its default tag. */
120
+ declare function defineBackgroundComponents(): void;
121
+ declare global {
122
+ interface HTMLElementTagNameMap {
123
+ 'usa-aurora': UsaAuroraElement;
124
+ 'usa-particles': UsaParticlesElement;
125
+ 'usa-grain': UsaGrainElement;
126
+ 'usa-marquee': UsaMarqueeElement;
127
+ 'usa-acrylic': UsaAcrylicElement;
128
+ }
129
+ }
130
+
131
+ export { configureComponents, defineAcrylic, defineAurora, defineBackgroundComponents, defineGrain, defineMarquee, defineParticles, prefersReducedMotion };
132
+ export type { ComponentsConfig, UsaAcrylicElement, UsaAuroraElement, UsaElement, UsaGrainElement, UsaMarqueeElement, UsaParticlesElement };
@@ -0,0 +1,387 @@
1
+ import { d as defineElement, b as caf, r as raf } from '../chunks/base-CFtnmfli.js';
2
+ export { c as configureComponents, p as prefersReducedMotion } from '../chunks/base-CFtnmfli.js';
3
+
4
+ var css$4 = "usa-aurora{position:relative;display:block;isolation:isolate;overflow:hidden}usa-aurora .usa-aurora-layer{position:absolute;inset:0;z-index:-1;pointer-events:none;opacity:var(--usa-aurora-opacity,0.7);overflow:hidden;contain:strict}usa-aurora .usa-aurora-layer i{position:absolute;display:block;width:70%;aspect-ratio:1;border-radius:50%;background:radial-gradient(closest-side,var(--c),transparent);will-change:transform;animation:usa-aurora-a var(--usa-aurora-speed,18s) ease-in-out infinite alternate}usa-aurora .usa-aurora-layer i:nth-child(1){left:-15%;top:-30%}usa-aurora .usa-aurora-layer i:nth-child(2){right:-20%;top:-10%;animation-name:usa-aurora-b;animation-duration:calc(var(--usa-aurora-speed,18s) * 1.3)}usa-aurora .usa-aurora-layer i:nth-child(3){left:10%;bottom:-45%;animation-name:usa-aurora-c;animation-duration:calc(var(--usa-aurora-speed,18s) * 0.9)}usa-aurora .usa-aurora-layer i:nth-child(4){right:0;bottom:-30%;width:50%;animation-name:usa-aurora-b;animation-direction:alternate-reverse}usa-aurora[paused] .usa-aurora-layer i,usa-aurora[data-offscreen] .usa-aurora-layer i{animation-play-state:paused}@keyframes usa-aurora-a{from{transform:translate3d(0,0,0) scale(1)}to{transform:translate3d(30%,20%,0) scale(1.25)}}@keyframes usa-aurora-b{from{transform:translate3d(0,0,0) scale(1.1)}to{transform:translate3d(-35%,25%,0) scale(0.85)}}@keyframes usa-aurora-c{from{transform:translate3d(0,0,0) rotate(0deg) scale(1)}to{transform:translate3d(25%,-30%,0) rotate(40deg) scale(1.2)}}@media (prefers-reduced-motion:reduce){usa-aurora .usa-aurora-layer i,usa-grain .usa-grain-layer,usa-acrylic::after{animation:none !important}}";
5
+
6
+ function defineAurora(tag = 'usa-aurora') {
7
+ return defineElement(tag, (Base) => class UsaAurora extends Base {
8
+ constructor() {
9
+ super(...arguments);
10
+ this._layer = null;
11
+ }
12
+ static get observedAttributes() {
13
+ return ['colors', 'speed', 'intensity'];
14
+ }
15
+ mount() {
16
+ if (!this._layer) {
17
+ this._layer = document.createElement('div');
18
+ this._layer.className = 'usa-aurora-layer';
19
+ this._layer.setAttribute('aria-hidden', 'true');
20
+ this._layer.innerHTML = '<i></i><i></i><i></i><i></i>';
21
+ this.prepend(this._layer);
22
+ }
23
+ const colors = this.str('colors', '#7c5cff,#22d3ee,#f472b6,#34d399').split(',').map((c) => c.trim()).filter(Boolean);
24
+ Array.from(this._layer.children).forEach((blob, i) => {
25
+ blob.style.setProperty('--c', colors[i % colors.length]);
26
+ });
27
+ const speed = this.num('speed', 1);
28
+ this.style.setProperty('--usa-aurora-speed', `${(18 / Math.max(0.05, speed)).toFixed(2)}s`);
29
+ this.style.setProperty('--usa-aurora-opacity', String(this.num('intensity', 0.7)));
30
+ this.inView((v) => this.toggleAttribute('data-offscreen', !v));
31
+ }
32
+ }, { id: 'aurora', text: css$4 });
33
+ }
34
+
35
+ var css$3 = "usa-particles{position:relative;display:block;min-height:120px;overflow:hidden}usa-particles>canvas{position:absolute;inset:0;width:100%;height:100%;pointer-events:none}";
36
+
37
+ function defineParticles(tag = 'usa-particles') {
38
+ return defineElement(tag, (Base) => class UsaParticles extends Base {
39
+ constructor() {
40
+ super(...arguments);
41
+ this._canvas = null;
42
+ this._ctx = null;
43
+ this._ps = [];
44
+ this._frame = 0;
45
+ this._w = 0;
46
+ this._h = 0;
47
+ this._visible = false;
48
+ this._mx = -1e4;
49
+ this._color = '#888';
50
+ this._my = -1e4;
51
+ }
52
+ static get observedAttributes() {
53
+ return ['count', 'color', 'size', 'speed', 'links', 'interactive', 'paused'];
54
+ }
55
+ mount() {
56
+ if (!this._canvas) {
57
+ this._canvas = document.createElement('canvas');
58
+ this._canvas.setAttribute('aria-hidden', 'true');
59
+ this.prepend(this._canvas);
60
+ }
61
+ this._ctx = this._canvas.getContext?.('2d') ?? null;
62
+ if (!this._ctx)
63
+ return;
64
+ this.resize();
65
+ if (typeof ResizeObserver !== 'undefined') {
66
+ const ro = new ResizeObserver(() => {
67
+ this.resize();
68
+ if (!this._frame)
69
+ this.draw();
70
+ });
71
+ ro.observe(this);
72
+ this.onCleanup(() => ro.disconnect());
73
+ }
74
+ this.inView((v) => {
75
+ this._visible = v;
76
+ this.loop();
77
+ });
78
+ this.listen(document, 'visibilitychange', () => this.loop());
79
+ if (this.flag('interactive')) {
80
+ this.listen(window, 'pointermove', (e) => {
81
+ const r = this.getBoundingClientRect();
82
+ this._mx = e.clientX - r.left;
83
+ this._my = e.clientY - r.top;
84
+ }, { passive: true });
85
+ }
86
+ this.draw();
87
+ }
88
+ unmount() {
89
+ caf(this._frame);
90
+ this._frame = 0;
91
+ }
92
+ reset() {
93
+ this._ps = [];
94
+ this.resize();
95
+ this.draw();
96
+ }
97
+ resize() {
98
+ const c = this._canvas;
99
+ if (!c || !this._ctx)
100
+ return;
101
+ const w = this.clientWidth || 300;
102
+ const h = this.clientHeight || 150;
103
+ const dpr = Math.min(2, (typeof devicePixelRatio === 'number' && devicePixelRatio) || 1);
104
+ c.width = Math.round(w * dpr);
105
+ c.height = Math.round(h * dpr);
106
+ this._ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
107
+ this._w = w;
108
+ this._h = h;
109
+ this._color = this.getAttribute('color') || (typeof getComputedStyle === 'function' ? getComputedStyle(this).color : '') || '#888';
110
+ const want = Math.round(Math.min(1, (w * h) / (900 * 500)) * Math.max(1, this.num('count', 60))) || 1;
111
+ const speed = this.num('speed', 0.35);
112
+ const size = this.num('size', 2.2);
113
+ while (this._ps.length < want) {
114
+ const a = Math.random() * Math.PI * 2;
115
+ const s = speed * (0.3 + Math.random() * 0.7);
116
+ this._ps.push({ x: Math.random() * w, y: Math.random() * h, vx: Math.cos(a) * s, vy: Math.sin(a) * s, r: 0.6 + Math.random() * (size - 0.6) });
117
+ }
118
+ this._ps.length = want;
119
+ }
120
+ loop() {
121
+ const run = this._visible && !this.reduced && !this.flag('paused') && !(typeof document !== 'undefined' && document.hidden);
122
+ if (run && !this._frame) {
123
+ const tick = () => {
124
+ this.step();
125
+ this.draw();
126
+ this._frame = raf(tick);
127
+ };
128
+ this._frame = raf(tick);
129
+ }
130
+ else if (!run && this._frame) {
131
+ caf(this._frame);
132
+ this._frame = 0;
133
+ }
134
+ }
135
+ step() {
136
+ const { _w: w, _h: h } = this;
137
+ for (const p of this._ps) {
138
+ const dx = p.x - this._mx;
139
+ const dy = p.y - this._my;
140
+ const d2 = dx * dx + dy * dy;
141
+ if (d2 < 8100 && d2 > 0.01) {
142
+ const f = (1 - Math.sqrt(d2) / 90) * 0.6;
143
+ p.x += (dx / Math.sqrt(d2)) * f;
144
+ p.y += (dy / Math.sqrt(d2)) * f;
145
+ }
146
+ p.x += p.vx;
147
+ p.y += p.vy;
148
+ if (p.x < -5)
149
+ p.x = w + 5;
150
+ else if (p.x > w + 5)
151
+ p.x = -5;
152
+ if (p.y < -5)
153
+ p.y = h + 5;
154
+ else if (p.y > h + 5)
155
+ p.y = -5;
156
+ }
157
+ }
158
+ draw() {
159
+ const ctx = this._ctx;
160
+ if (!ctx)
161
+ return;
162
+ const color = this._color;
163
+ ctx.clearRect(0, 0, this._w, this._h);
164
+ ctx.fillStyle = color;
165
+ ctx.strokeStyle = color;
166
+ const ps = this._ps;
167
+ const link = this.num('links', 110);
168
+ if (link > 0) {
169
+ const l2 = link * link;
170
+ ctx.lineWidth = 0.6;
171
+ for (let i = 0; i < ps.length; i++) {
172
+ for (let j = i + 1; j < ps.length; j++) {
173
+ const dx = ps[i].x - ps[j].x;
174
+ const dy = ps[i].y - ps[j].y;
175
+ const d2 = dx * dx + dy * dy;
176
+ if (d2 < l2) {
177
+ ctx.globalAlpha = (1 - d2 / l2) * 0.35;
178
+ ctx.beginPath();
179
+ ctx.moveTo(ps[i].x, ps[i].y);
180
+ ctx.lineTo(ps[j].x, ps[j].y);
181
+ ctx.stroke();
182
+ }
183
+ }
184
+ }
185
+ }
186
+ ctx.globalAlpha = 0.85;
187
+ for (const p of ps) {
188
+ ctx.beginPath();
189
+ ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2);
190
+ ctx.fill();
191
+ }
192
+ ctx.globalAlpha = 1;
193
+ }
194
+ }, { id: 'particles', text: css$3 });
195
+ }
196
+
197
+ var css$2 = "usa-grain{position:relative;display:block;isolation:isolate;overflow:hidden}usa-grain .usa-grain-layer{position:absolute;inset:-100%;z-index:1;pointer-events:none}usa-grain[animated] .usa-grain-layer{animation:usa-grain 0.8s steps(10) infinite}@keyframes usa-grain{0%,100%{transform:translate(0,0)}10%{transform:translate(-5%,-8%)}20%{transform:translate(-12%,4%)}30%{transform:translate(6%,-16%)}40%{transform:translate(-4%,18%)}50%{transform:translate(-12%,8%)}60%{transform:translate(14%,0)}70%{transform:translate(0,12%)}80%{transform:translate(3%,25%)}90%{transform:translate(-8%,8%)}}";
198
+
199
+ const noise = (freq) => `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='256' height='256'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='${freq}' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 1.6 -0.3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")`;
200
+ function defineGrain(tag = 'usa-grain') {
201
+ return defineElement(tag, (Base) => class UsaGrain extends Base {
202
+ constructor() {
203
+ super(...arguments);
204
+ this._layer = null;
205
+ }
206
+ static get observedAttributes() {
207
+ return ['opacity', 'blend', 'scale'];
208
+ }
209
+ mount() {
210
+ if (!this._layer) {
211
+ this._layer = document.createElement('div');
212
+ this._layer.className = 'usa-grain-layer';
213
+ this._layer.setAttribute('aria-hidden', 'true');
214
+ this.append(this._layer);
215
+ }
216
+ const s = this._layer.style;
217
+ s.backgroundImage = noise(0.8);
218
+ s.backgroundSize = `${this.num('scale', 180)}px`;
219
+ s.opacity = String(this.num('opacity', 0.12));
220
+ s.mixBlendMode = this.str('blend', 'overlay');
221
+ }
222
+ }, { id: 'grain', text: css$2 });
223
+ }
224
+
225
+ var css$1 = "usa-marquee{--usa-marquee-gap:32px;display:block;overflow:hidden;contain:content}usa-marquee[fade]{-webkit-mask:linear-gradient(90deg,transparent,#000 10%,#000 90%,transparent);mask:linear-gradient(90deg,transparent,#000 10%,#000 90%,transparent)}usa-marquee[fade][data-vertical]{-webkit-mask:linear-gradient(180deg,transparent,#000 12%,#000 88%,transparent);mask:linear-gradient(180deg,transparent,#000 12%,#000 88%,transparent)}usa-marquee .usa-marquee-track{display:flex;width:max-content;gap:var(--usa-marquee-gap);will-change:transform}usa-marquee .usa-marquee-group{display:flex;flex:none;align-items:center;gap:var(--usa-marquee-gap)}usa-marquee[data-vertical] .usa-marquee-track,usa-marquee[data-vertical] .usa-marquee-group{flex-direction:column;width:auto}usa-marquee[data-vertical]{height:var(--usa-marquee-height,240px)}usa-marquee[data-static]{overflow:auto;scrollbar-width:thin}";
226
+
227
+ function defineMarquee(tag = 'usa-marquee') {
228
+ return defineElement(tag, (Base) => class UsaMarquee extends Base {
229
+ constructor() {
230
+ super(...arguments);
231
+ this._track = null;
232
+ this._anim = null;
233
+ this._hover = false;
234
+ this._visible = true;
235
+ this._size = 0;
236
+ }
237
+ static get observedAttributes() {
238
+ return ['speed', 'direction', 'gap', 'paused'];
239
+ }
240
+ get vertical() {
241
+ const d = this.str('direction', 'left');
242
+ return d === 'up' || d === 'down';
243
+ }
244
+ mount() {
245
+ if (!this._track) {
246
+ const track = document.createElement('div');
247
+ track.className = 'usa-marquee-track';
248
+ const group = document.createElement('div');
249
+ group.className = 'usa-marquee-group';
250
+ group.append(...Array.from(this.childNodes));
251
+ track.append(group);
252
+ this.append(track);
253
+ this._track = track;
254
+ }
255
+ this.toggleAttribute('data-vertical', this.vertical);
256
+ this.style.setProperty('--usa-marquee-gap', `${this.num('gap', 32)}px`);
257
+ if (this.reduced) {
258
+ this.setAttribute('data-static', '');
259
+ this.syncClones(1);
260
+ return;
261
+ }
262
+ this.removeAttribute('data-static');
263
+ this.build();
264
+ if (typeof ResizeObserver !== 'undefined') {
265
+ const ro = new ResizeObserver(() => this.build());
266
+ ro.observe(this._track.firstElementChild);
267
+ this.onCleanup(() => ro.disconnect());
268
+ }
269
+ this.inView((v) => {
270
+ this._visible = v;
271
+ this.sync();
272
+ });
273
+ this.listen(this, 'pointerenter', () => ((this._hover = true), this.sync()));
274
+ this.listen(this, 'pointerleave', () => ((this._hover = false), this.sync()));
275
+ this.listen(this, 'focusin', () => ((this._hover = true), this.sync()));
276
+ this.listen(this, 'focusout', () => ((this._hover = false), this.sync()));
277
+ }
278
+ unmount() {
279
+ this._anim?.cancel();
280
+ this._anim = null;
281
+ this._size = 0;
282
+ }
283
+ syncClones(n) {
284
+ const track = this._track;
285
+ const group = track.firstElementChild;
286
+ while (track.children.length > n)
287
+ track.lastElementChild.remove();
288
+ while (track.children.length < n) {
289
+ const clone = group.cloneNode(true);
290
+ clone.setAttribute('aria-hidden', 'true');
291
+ clone.setAttribute('inert', '');
292
+ track.append(clone);
293
+ }
294
+ }
295
+ build() {
296
+ const track = this._track;
297
+ const group = track.firstElementChild;
298
+ const vertical = this.vertical;
299
+ const gap = this.num('gap', 32);
300
+ const measured = vertical ? group.offsetHeight : group.offsetWidth;
301
+ if (!measured)
302
+ return; // not laid out yet: the ResizeObserver calls back
303
+ const size = measured + gap;
304
+ if (this._anim && this._size === size)
305
+ return;
306
+ this._size = size;
307
+ const box = (vertical ? this.clientHeight : this.clientWidth) || size;
308
+ // Enough copies to cover the box twice
309
+ this.syncClones(Math.min(50, Math.max(2, Math.ceil(box / size) + 1)));
310
+ const progress = this._anim?.effect?.getComputedTiming().progress ?? 0;
311
+ this._anim?.cancel();
312
+ const axis = vertical ? 'Y' : 'X';
313
+ const reverse = ['right', 'down'].includes(this.str('direction', 'left'));
314
+ const frames = [{ transform: `translate${axis}(0)` }, { transform: `translate${axis}(${-size}px)` }];
315
+ this._anim = this.motion(track, reverse ? frames.reverse() : frames, {
316
+ duration: (Math.max(1, size) / Math.max(1, this.num('speed', 50))) * 1000,
317
+ iterations: Infinity,
318
+ });
319
+ if (this._anim && progress)
320
+ this._anim.currentTime = progress * Number(this._anim.effect?.getTiming().duration || 0);
321
+ this.sync();
322
+ }
323
+ sync() {
324
+ const a = this._anim;
325
+ if (!a)
326
+ return;
327
+ const stop = this.flag('paused') || !this._visible || (this._hover && this.flag('pause-on-hover'));
328
+ if (stop && a.playState === 'running')
329
+ a.pause();
330
+ else if (!stop && a.playState === 'paused')
331
+ a.play();
332
+ }
333
+ pause() {
334
+ this.setAttribute('paused', '');
335
+ }
336
+ resume() {
337
+ this.removeAttribute('paused');
338
+ }
339
+ changed(name) {
340
+ if (name === 'paused')
341
+ this.sync();
342
+ else
343
+ super.changed(name);
344
+ }
345
+ }, { id: 'marquee', text: css$1 });
346
+ }
347
+
348
+ var css = "usa-acrylic{--usa-acrylic-tint:#f3f3f3;--usa-acrylic-opacity:55%;--usa-acrylic-blur:30px;position:relative;display:block;isolation:isolate;overflow:hidden;background-color:color-mix(in srgb,var(--usa-acrylic-tint) var(--usa-acrylic-opacity),transparent);-webkit-backdrop-filter:blur(var(--usa-acrylic-blur)) saturate(1.6);backdrop-filter:blur(var(--usa-acrylic-blur)) saturate(1.6);border:1px solid color-mix(in srgb,#fff 22%,transparent)}@media (prefers-color-scheme:dark){usa-acrylic{--usa-acrylic-tint:#2c2c2c}}usa-acrylic::before{content:\"\";position:absolute;inset:0;z-index:-1;pointer-events:none;opacity:0.035;background-image:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='128' height='128'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\")}usa-acrylic::after{content:\"\";position:absolute;inset:0;z-index:1;pointer-events:none;transform:translateX(-120%);background:linear-gradient(105deg,transparent 30%,rgb(255 255 255 / 0.28) 50%,transparent 70%)}usa-acrylic[shimmer=\"hover\"]:hover::after,usa-acrylic[data-shine]::after{animation:usa-acrylic-shine 1.1s cubic-bezier(0.22,1,0.36,1) both}@keyframes usa-acrylic-shine{from{transform:translateX(-120%)}to{transform:translateX(120%)}}usa-acrylic[variant=\"mica\"]{--usa-acrylic-opacity:80%;-webkit-backdrop-filter:none;backdrop-filter:none;background:linear-gradient(color-mix(in srgb,var(--usa-acrylic-tint) var(--usa-acrylic-opacity),transparent),color-mix(in srgb,var(--usa-acrylic-tint) var(--usa-acrylic-opacity),transparent)),var(--usa-mica-source,linear-gradient(135deg,#b8c6ff,#ffd6e8));border-color:transparent}@supports not ((backdrop-filter:blur(1px)) or (-webkit-backdrop-filter:blur(1px))){usa-acrylic{background-color:var(--usa-acrylic-tint)}}@media (prefers-reduced-transparency:reduce){usa-acrylic{background:var(--usa-acrylic-tint);-webkit-backdrop-filter:none;backdrop-filter:none}}@media (forced-colors:active){usa-acrylic{background:Canvas;-webkit-backdrop-filter:none;backdrop-filter:none;border-color:CanvasText}usa-acrylic::before,usa-acrylic::after{display:none}}";
349
+
350
+ function defineAcrylic(tag = 'usa-acrylic') {
351
+ return defineElement(tag, (Base) => class UsaAcrylic extends Base {
352
+ static get observedAttributes() {
353
+ return ['tint', 'tint-opacity', 'blur', 'shimmer'];
354
+ }
355
+ mount() {
356
+ const tint = this.getAttribute('tint');
357
+ if (tint)
358
+ this.style.setProperty('--usa-acrylic-tint', tint);
359
+ else
360
+ this.style.removeProperty('--usa-acrylic-tint');
361
+ this.style.setProperty('--usa-acrylic-opacity', `${Math.round(this.num('tint-opacity', 0.55) * 100)}%`);
362
+ this.style.setProperty('--usa-acrylic-blur', `${this.num('blur', 30)}px`);
363
+ if (this.str('shimmer') === 'load' && !this.reduced) {
364
+ this.removeAttribute('data-shine');
365
+ void this.offsetWidth;
366
+ this.setAttribute('data-shine', '');
367
+ }
368
+ }
369
+ }, { id: 'acrylic', text: css });
370
+ }
371
+
372
+ /**
373
+ * use-scroll-animate/components/background — backgrounds & decoration.
374
+ * `<usa-aurora>`, `<usa-particles>`, `<usa-grain>`, `<usa-marquee>`,
375
+ * `<usa-acrylic>`.
376
+ */
377
+ /** Register every component of this category under its default tag. */
378
+ function defineBackgroundComponents() {
379
+ defineAurora();
380
+ defineParticles();
381
+ defineGrain();
382
+ defineMarquee();
383
+ defineAcrylic();
384
+ }
385
+
386
+ export { defineAcrylic, defineAurora, defineBackgroundComponents, defineGrain, defineMarquee, defineParticles };
387
+ //# sourceMappingURL=background.js.map