motionary 6.7.0 → 6.9.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 (148) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/bin/usa-codemod-7.mjs +91 -0
  3. package/dist/chunks/{base-DchG4q_S.js → base-D5MHqeDd.js} +2 -2
  4. package/dist/chunks/{base-DchG4q_S.js.map → base-D5MHqeDd.js.map} +1 -1
  5. package/dist/chunks/{core-DVyTlo9Q.js → core-DyJu5r5a.js} +2 -2
  6. package/dist/chunks/{core-DVyTlo9Q.js.map → core-DyJu5r5a.js.map} +1 -1
  7. package/dist/chunks/{core-D2vF8kZb.js → core-ZGo4hOEk.js} +2 -2
  8. package/dist/chunks/{core-D2vF8kZb.js.map → core-ZGo4hOEk.js.map} +1 -1
  9. package/dist/chunks/{fx-DUMVKSvg.js → fx-DlGRMJ-Z.js} +2 -2
  10. package/dist/chunks/{fx-DUMVKSvg.js.map → fx-DlGRMJ-Z.js.map} +1 -1
  11. package/dist/chunks/{gpu-BBRLgEzM.cjs → gpu-C2D4T9Q-.cjs} +9 -2
  12. package/dist/chunks/gpu-C2D4T9Q-.cjs.map +1 -0
  13. package/dist/chunks/{gpu-CsP2ZB3x.js → gpu-DPhMkJq6.js} +10 -4
  14. package/dist/chunks/gpu-DPhMkJq6.js.map +1 -0
  15. package/dist/chunks/player-DH3TIz-t.js +516 -0
  16. package/dist/chunks/player-DH3TIz-t.js.map +1 -0
  17. package/dist/chunks/player-PS6_FzNw.cjs +525 -0
  18. package/dist/chunks/player-PS6_FzNw.cjs.map +1 -0
  19. package/dist/chunks/{registry-D23neB4M.js → registry-CTLWeg-J.js} +2 -2
  20. package/dist/chunks/{registry-D23neB4M.js.map → registry-CTLWeg-J.js.map} +1 -1
  21. package/dist/chunks/{spring-BhoT09Qb.js → spring-B-9MZOrW.js} +2 -2
  22. package/dist/chunks/{spring-BhoT09Qb.js.map → spring-B-9MZOrW.js.map} +1 -1
  23. package/dist/chunks/{variants-C_hv_s23.js → variants-CoZn3k_5.js} +2 -2
  24. package/dist/chunks/{variants-C_hv_s23.js.map → variants-CoZn3k_5.js.map} +1 -1
  25. package/dist/components/a11y.js +2 -2
  26. package/dist/components/angular.js +7 -7
  27. package/dist/components/background.js +2 -2
  28. package/dist/components/bridge.js +1 -1
  29. package/dist/components/cards.js +2 -2
  30. package/dist/components/click.js +3 -3
  31. package/dist/components/depth.js +3 -3
  32. package/dist/components/effects.cjs +13 -522
  33. package/dist/components/effects.cjs.map +1 -1
  34. package/dist/components/effects.js +7 -515
  35. package/dist/components/effects.js.map +1 -1
  36. package/dist/components/feedback.js +1 -1
  37. package/dist/components/fx-3d.cjs +8 -2
  38. package/dist/components/fx-3d.cjs.map +1 -1
  39. package/dist/components/fx-3d.d.cts +3 -1
  40. package/dist/components/fx-3d.d.ts +3 -1
  41. package/dist/components/fx-3d.js +9 -4
  42. package/dist/components/fx-3d.js.map +1 -1
  43. package/dist/components/fx-focus.cjs +125 -0
  44. package/dist/components/fx-focus.cjs.map +1 -0
  45. package/dist/components/fx-focus.d.cts +65 -0
  46. package/dist/components/fx-focus.d.ts +65 -0
  47. package/dist/components/fx-focus.js +122 -0
  48. package/dist/components/fx-focus.js.map +1 -0
  49. package/dist/components/fx-gpu.cjs +3 -2
  50. package/dist/components/fx-gpu.cjs.map +1 -1
  51. package/dist/components/fx-gpu.d.cts +3 -1
  52. package/dist/components/fx-gpu.d.ts +3 -1
  53. package/dist/components/fx-gpu.js +3 -3
  54. package/dist/components/fx-light.cjs +8 -2
  55. package/dist/components/fx-light.cjs.map +1 -1
  56. package/dist/components/fx-light.d.cts +3 -1
  57. package/dist/components/fx-light.d.ts +3 -1
  58. package/dist/components/fx-light.js +9 -4
  59. package/dist/components/fx-light.js.map +1 -1
  60. package/dist/components/fx-morph.cjs +8 -2
  61. package/dist/components/fx-morph.cjs.map +1 -1
  62. package/dist/components/fx-morph.d.cts +3 -1
  63. package/dist/components/fx-morph.d.ts +3 -1
  64. package/dist/components/fx-morph.js +9 -4
  65. package/dist/components/fx-morph.js.map +1 -1
  66. package/dist/components/fx-physics.cjs +350 -0
  67. package/dist/components/fx-physics.cjs.map +1 -0
  68. package/dist/components/fx-physics.d.cts +94 -0
  69. package/dist/components/fx-physics.d.ts +94 -0
  70. package/dist/components/fx-physics.js +345 -0
  71. package/dist/components/fx-physics.js.map +1 -0
  72. package/dist/components/fx-text.cjs +8 -2
  73. package/dist/components/fx-text.cjs.map +1 -1
  74. package/dist/components/fx-text.d.cts +3 -1
  75. package/dist/components/fx-text.d.ts +3 -1
  76. package/dist/components/fx-text.js +9 -4
  77. package/dist/components/fx-text.js.map +1 -1
  78. package/dist/components/fx-transitions.cjs +8 -2
  79. package/dist/components/fx-transitions.cjs.map +1 -1
  80. package/dist/components/fx-transitions.d.cts +3 -1
  81. package/dist/components/fx-transitions.d.ts +3 -1
  82. package/dist/components/fx-transitions.js +10 -5
  83. package/dist/components/fx-transitions.js.map +1 -1
  84. package/dist/components/fx-weather.cjs +271 -0
  85. package/dist/components/fx-weather.cjs.map +1 -0
  86. package/dist/components/fx-weather.d.cts +72 -0
  87. package/dist/components/fx-weather.d.ts +72 -0
  88. package/dist/components/fx-weather.js +266 -0
  89. package/dist/components/fx-weather.js.map +1 -0
  90. package/dist/components/fx.js +5 -5
  91. package/dist/components/fx2.cjs +49 -10
  92. package/dist/components/fx2.cjs.map +1 -1
  93. package/dist/components/fx2.d.cts +181 -4
  94. package/dist/components/fx2.d.ts +181 -4
  95. package/dist/components/fx2.js +42 -22
  96. package/dist/components/fx2.js.map +1 -1
  97. package/dist/components/gesture.js +4 -4
  98. package/dist/components/interaction.cjs +1 -0
  99. package/dist/components/interaction.cjs.map +1 -1
  100. package/dist/components/interaction.js +2 -1
  101. package/dist/components/interaction.js.map +1 -1
  102. package/dist/components/layout.js +1 -1
  103. package/dist/components/lite.cjs +2 -0
  104. package/dist/components/lite.cjs.map +1 -1
  105. package/dist/components/lite.js +2 -0
  106. package/dist/components/lite.js.map +1 -1
  107. package/dist/components/marketplace.cjs +82 -0
  108. package/dist/components/marketplace.cjs.map +1 -0
  109. package/dist/components/marketplace.d.cts +108 -0
  110. package/dist/components/marketplace.d.ts +108 -0
  111. package/dist/components/marketplace.js +77 -0
  112. package/dist/components/marketplace.js.map +1 -0
  113. package/dist/components/packs.js +1 -1
  114. package/dist/components/page.js +3 -3
  115. package/dist/components/perf.js +2 -2
  116. package/dist/components/physics.js +3 -3
  117. package/dist/components/reveal.js +1 -1
  118. package/dist/components/solid.js +7 -7
  119. package/dist/components/svelte.js +7 -7
  120. package/dist/components/svg.js +1 -1
  121. package/dist/components/text.js +2 -2
  122. package/dist/components/timeline.js +3 -3
  123. package/dist/components/transitions.js +1 -1
  124. package/dist/components/ui.cjs +1 -0
  125. package/dist/components/ui.cjs.map +1 -1
  126. package/dist/components/ui.js +5 -4
  127. package/dist/components/ui.js.map +1 -1
  128. package/dist/components/vue.js +7 -7
  129. package/dist/components/webgl.js +1 -1
  130. package/dist/components/widgets.cjs +1189 -45
  131. package/dist/components/widgets.cjs.map +1 -1
  132. package/dist/components/widgets.d.cts +177 -2
  133. package/dist/components/widgets.d.ts +177 -2
  134. package/dist/components/widgets.js +1179 -48
  135. package/dist/components/widgets.js.map +1 -1
  136. package/dist/components.js +9 -9
  137. package/dist/components.umd.js +2 -2
  138. package/dist/components.umd.js.map +1 -1
  139. package/dist/index.js +2 -2
  140. package/dist/widgets.umd.js +1 -1
  141. package/dist/widgets.umd.js.map +1 -1
  142. package/docs/ROADMAP.md +2 -2
  143. package/docs/components.md +55 -0
  144. package/docs/deprecations.md +4 -0
  145. package/docs/upgrading-7.md +33 -0
  146. package/package.json +43 -2
  147. package/dist/chunks/gpu-BBRLgEzM.cjs.map +0 -1
  148. package/dist/chunks/gpu-CsP2ZB3x.js.map +0 -1
@@ -1,12 +1,14 @@
1
1
  import { registerBuiltinEffects } from './fx.js';
2
2
  import { P as PALETTE, o as overlay, a as all, b as origin, s as spawn, r as rand, f as fxLayer } from '../chunks/shared-CkKHWrtJ.js';
3
- import { y as defineElement, p as prefersReducedMotion, v as adoptStyles } from '../chunks/base-DchG4q_S.js';
3
+ import { d as defineStory, a as definePlayer } from '../chunks/player-DH3TIz-t.js';
4
+ export { A as ANIMATION_FORMAT, S as STORY_TEMPLATES, c as createPlayer, f as formatCount, n as normalizeAnimation, s as storyProgress } from '../chunks/player-DH3TIz-t.js';
4
5
  import { c as canvasBackground, h as hexRgb, G as GENERATIVE_FX } from '../chunks/generative-2LhxG5BJ.js';
5
6
  export { n as noise2 } from '../chunks/generative-2LhxG5BJ.js';
6
- import { playEffect, bindEffect, registerEffects } from '../chunks/registry-D23neB4M.js';
7
+ import { playEffect, bindEffect, registerEffects } from '../chunks/registry-CTLWeg-J.js';
8
+ import { y as defineElement, p as prefersReducedMotion, x as adoptStyles } from '../chunks/base-D5MHqeDd.js';
7
9
  import { applyMotionTokens, motionTokensToVars, mergeMotionTokens } from './tokens.js';
8
- import { T as TIMELINE_PRESETS } from '../chunks/core-DVyTlo9Q.js';
9
- import '../chunks/fx-DUMVKSvg.js';
10
+ import '../chunks/core-DyJu5r5a.js';
11
+ import '../chunks/fx-DlGRMJ-Z.js';
10
12
 
11
13
  const CARD_FX = [
12
14
  {
@@ -573,216 +575,6 @@ const PAGE_FX = [
573
575
  },
574
576
  ];
575
577
 
576
- /**
577
- * 5.4 — `<usa-story template="…">` scroll-storytelling templates.
578
- *
579
- * - `pin` — a sticky `[data-stage]` while `[data-step]` sections scroll past; the
580
- * step in view gets `data-active`, the stage gets `data-active-step="<index>"`.
581
- * - `gallery` — a horizontal `[data-track]` slides sideways as you scroll down.
582
- * - `zoom` — the `[data-stage]` zooms toward the viewer (`zoom="6"`) and fades.
583
- * - `compare` — before / after (`[data-before]`, `[data-after]`) wipe driven by
584
- * scroll, plus a draggable, keyboard-accessible handle (`role="slider"`).
585
- * - `counter` — `[data-count="1234"]` numbers count up when they enter view.
586
- * - `highlight` — paragraphs dim except the one crossing the viewport center.
587
- *
588
- * Every template sets `--usa-story-progress` (0–1) on the host and dispatches
589
- * `usa-story-step` (`detail: { index }`). Reduced motion: no sliding / zooming
590
- * (the gallery stacks vertically), counters show final values, the rest is
591
- * class changes only.
592
- */
593
- const STORY_TEMPLATES = ['pin', 'gallery', 'zoom', 'compare', 'counter', 'highlight'];
594
- const CSS = `usa-story{display:block;position:relative}
595
- usa-story[template=pin] [data-stage],usa-story[template=gallery] [data-sticky],usa-story[template=zoom] [data-stage],usa-story[template=compare] [data-sticky]{position:sticky;top:0}
596
- usa-story[template=pin] [data-stage]{align-self:start}
597
- usa-story[template=pin] [data-step]{min-height:80vh;opacity:.35;transition:opacity .3s}
598
- usa-story[template=pin] [data-step][data-active]{opacity:1}
599
- usa-story[template=gallery] [data-sticky]{height:100vh;overflow:hidden;display:flex;align-items:center}
600
- usa-story[template=gallery] [data-track]{display:flex;gap:24px;will-change:transform}
601
- usa-story[template=gallery][data-static] [data-sticky]{position:static;height:auto;overflow:visible}
602
- usa-story[template=gallery][data-static] [data-track]{flex-direction:column;transform:none!important}
603
- usa-story[template=zoom] [data-stage]{height:100vh;overflow:hidden;display:grid;place-items:center}
604
- usa-story[template=compare] [data-sticky]{height:var(--usa-story-h,70vh);overflow:hidden}
605
- usa-story[template=compare] [data-before],usa-story[template=compare] [data-after]{position:absolute;inset:0}
606
- usa-story[template=compare] [data-after]{clip-path:inset(0 0 0 var(--usa-split,50%))}
607
- usa-story [data-handle]{position:absolute;top:0;bottom:0;left:var(--usa-split,50%);width:4px;margin-left:-2px;background:#fff;box-shadow:0 0 0 1px #0003;cursor:ew-resize;touch-action:none}
608
- usa-story [data-handle]:focus-visible{outline:3px solid #7c5cff;outline-offset:2px}
609
- usa-story[template=highlight] p,usa-story[template=highlight] [data-step]{opacity:.3;transition:opacity .25s}
610
- usa-story[template=highlight] [data-active]{opacity:1}`;
611
- const clamp = (v, a = 0, b = 1) => Math.min(b, Math.max(a, v));
612
- /** Progress of `el` through the viewport: 0 when its top hits the viewport top, 1 when its bottom hits the viewport bottom. */
613
- function storyProgress(el, vh = typeof innerHeight === 'number' ? innerHeight : 800) {
614
- const r = el.getBoundingClientRect();
615
- const span = r.height - vh;
616
- return span > 0 ? clamp(-r.top / span) : clamp((vh - r.top) / (vh + r.height));
617
- }
618
- /** Format a counted value like the target (`1,234`, `12.5`, prefix / suffix kept). */
619
- function formatCount(target, t) {
620
- const m = target.match(/^(\D*)([\d,]*\.?\d+)(.*)$/);
621
- if (!m)
622
- return target;
623
- const [, pre, num, post] = m;
624
- const n = parseFloat(num.replace(/,/g, ''));
625
- const dec = (num.split('.')[1] || '').length;
626
- let s = (n * t).toFixed(dec);
627
- if (num.includes(','))
628
- s = Number(s).toLocaleString('en-US', { minimumFractionDigits: dec, maximumFractionDigits: dec });
629
- return pre + s + post;
630
- }
631
- function defineStory(tag = 'usa-story') {
632
- return defineElement(tag, (Base) => class UsaStory extends Base {
633
- constructor() {
634
- super(...arguments);
635
- this.progress = 0;
636
- this.step = -1;
637
- this.frame = 0;
638
- }
639
- static get observedAttributes() {
640
- return ['template', 'zoom'];
641
- }
642
- get template() {
643
- const t = this.str('template', 'pin');
644
- return STORY_TEMPLATES.includes(t) ? t : 'pin';
645
- }
646
- steps() {
647
- const own = Array.from(this.querySelectorAll('[data-step]:not([data-stage])'));
648
- return own.length || this.template !== 'highlight' ? own : Array.from(this.querySelectorAll('p'));
649
- }
650
- setStep(i) {
651
- if (i === this.step)
652
- return;
653
- this.step = i;
654
- this.steps().forEach((s, k) => s.toggleAttribute('data-active', k === i));
655
- const stage = this.querySelector('[data-stage]');
656
- if (stage)
657
- stage.dataset.activeStep = String(i);
658
- this.dispatchEvent(new CustomEvent('usa-story-step', { detail: { index: i }, bubbles: true }));
659
- }
660
- /** Recompute from the current scroll position (called on scroll / resize). */
661
- update() {
662
- this.frame = 0;
663
- const p = (this.progress = storyProgress(this));
664
- this.style.setProperty('--usa-story-progress', p.toFixed(4));
665
- const t = this.template;
666
- const vh = innerHeight || 800;
667
- if (t === 'pin' || t === 'highlight') {
668
- const mid = vh / 2;
669
- let best = -1;
670
- let bestD = Infinity;
671
- this.steps().forEach((s, i) => {
672
- const r = s.getBoundingClientRect();
673
- const d = r.top <= mid && r.bottom >= mid ? 0 : Math.min(Math.abs(r.top - mid), Math.abs(r.bottom - mid));
674
- if (d < bestD)
675
- (bestD = d), (best = i);
676
- });
677
- this.setStep(best);
678
- }
679
- else if (t === 'gallery' && !this.reduced) {
680
- const track = this.querySelector('[data-track]');
681
- const box = this.querySelector('[data-sticky]');
682
- if (track && box)
683
- track.style.transform = `translateX(${(-p * Math.max(0, track.scrollWidth - box.clientWidth)).toFixed(1)}px)`;
684
- }
685
- else if (t === 'zoom' && !this.reduced) {
686
- const inner = this.querySelector('[data-stage] > *');
687
- if (inner) {
688
- inner.style.transform = `scale(${(1 + p * (this.num('zoom', 6) - 1)).toFixed(3)})`;
689
- inner.style.opacity = String(clamp(1.4 - p * 1.4).toFixed(3));
690
- }
691
- }
692
- else if (t === 'compare' && !this.hasAttribute('data-dragged')) {
693
- this.setSplit(p * 100);
694
- }
695
- else if (t === 'counter') {
696
- this.querySelectorAll('[data-count]:not([data-counted])').forEach((el) => {
697
- const r = el.getBoundingClientRect();
698
- if (r.top < vh * 0.9 && r.bottom > 0)
699
- this.count(el);
700
- });
701
- }
702
- }
703
- setSplit(pct) {
704
- const v = clamp(pct, 0, 100);
705
- this.style.setProperty('--usa-split', `${v.toFixed(2)}%`);
706
- const h = this.querySelector('[data-handle]');
707
- if (h)
708
- h.setAttribute('aria-valuenow', String(Math.round(v)));
709
- }
710
- count(el) {
711
- el.dataset.counted = '';
712
- const target = el.dataset.count || el.textContent || '0';
713
- el.setAttribute('aria-label', target);
714
- if (this.reduced) {
715
- el.textContent = target;
716
- return;
717
- }
718
- const dur = Number(el.dataset.duration) || 1600;
719
- const t0 = performance.now();
720
- const tick = (now) => {
721
- const k = clamp((now - t0) / dur);
722
- el.textContent = formatCount(target, 1 - (1 - k) ** 3);
723
- if (k < 1)
724
- requestAnimationFrame(tick);
725
- };
726
- requestAnimationFrame(tick);
727
- }
728
- mount() {
729
- this.toggleAttribute('data-static', this.reduced);
730
- if (this.template === 'compare')
731
- this.mountCompare();
732
- const kick = () => {
733
- if (!this.frame)
734
- this.frame = requestAnimationFrame(() => this.update());
735
- };
736
- this.listen(window, 'scroll', kick, { passive: true });
737
- this.listen(window, 'resize', kick);
738
- this.onCleanup(() => cancelAnimationFrame(this.frame));
739
- this.update();
740
- }
741
- mountCompare() {
742
- const box = this.querySelector('[data-sticky]') || this;
743
- let h = this.querySelector('[data-handle]');
744
- if (!h) {
745
- h = document.createElement('div');
746
- h.setAttribute('data-handle', '');
747
- box.appendChild(h);
748
- this.onCleanup(() => h.remove());
749
- }
750
- h.tabIndex = 0;
751
- h.setAttribute('role', 'slider');
752
- h.setAttribute('aria-label', this.str('label', 'Before / after'));
753
- h.setAttribute('aria-valuemin', '0');
754
- h.setAttribute('aria-valuemax', '100');
755
- const at = (e) => {
756
- const r = box.getBoundingClientRect();
757
- this.dataset.dragged = '';
758
- this.setSplit(((e.clientX - r.left) / (r.width || 1)) * 100);
759
- };
760
- let drag = false;
761
- this.listen(h, 'pointerdown', (e) => {
762
- drag = true;
763
- h.setPointerCapture?.(e.pointerId);
764
- });
765
- this.listen(h, 'pointermove', (e) => drag && at(e));
766
- this.listen(h, 'pointerup', () => (drag = false));
767
- this.listen(h, 'keydown', (e) => {
768
- const cur = parseFloat(h.getAttribute('aria-valuenow') || '50');
769
- const step = e.shiftKey ? 10 : 2;
770
- const next = e.key === 'ArrowLeft' || e.key === 'ArrowDown' ? cur - step : e.key === 'ArrowRight' || e.key === 'ArrowUp' ? cur + step : e.key === 'Home' ? 0 : e.key === 'End' ? 100 : null;
771
- if (next == null)
772
- return;
773
- e.preventDefault();
774
- this.dataset.dragged = '';
775
- this.setSplit(next);
776
- });
777
- this.setSplit(50);
778
- }
779
- unmount() {
780
- this.step = -1;
781
- delete this.dataset.dragged;
782
- }
783
- }, { id: 'usa-story', text: CSS });
784
- }
785
-
786
578
  let actx = null;
787
579
  let current = null;
788
580
  const mediaSources = new WeakMap();
@@ -1830,306 +1622,6 @@ function defineTheme(tag = 'usa-theme') {
1830
1622
  }, { id: 'usa-theme-el', text: 'usa-theme{display:block}' });
1831
1623
  }
1832
1624
 
1833
- /**
1834
- * 5.9 — `<usa-player>`: plays JSON animations.
1835
- *
1836
- * Format `use-scroll-animate/animation` v1:
1837
- *
1838
- * ```json
1839
- * { "format": "use-scroll-animate/animation", "version": 1, "name": "Hero",
1840
- * "loop": false,
1841
- * "tracks": [
1842
- * { "target": "h1", "start": 0, "duration": 600, "preset": "fade-up" },
1843
- * { "target": ".cta", "start": 500, "duration": 500, "keyframes": [{ "opacity": 0 }, { "opacity": 1 }], "easing": "ease-out" },
1844
- * { "target": ".cta", "start": 1100, "effect": "jelly", "options": {} }
1845
- * ] }
1846
- * ```
1847
- *
1848
- * A track animates `target` (a selector inside the player; `:scope` for the
1849
- * player itself) with a timeline preset, its own keyframes, or fires any
1850
- * registered effect at `start`. Playground presets (format
1851
- * `use-scroll-animate/playground`) are accepted too — their tracks map to the
1852
- * player's children in order.
1853
- *
1854
- * Keyframe tracks are WAAPI animations driven by one clock, so the player can
1855
- * play, pause, seek, change rate and be scrubbed by scroll
1856
- * (`trigger="scroll"`). Reduced motion: jumps to the end state, effects skipped.
1857
- */
1858
- const ANIMATION_FORMAT = 'use-scroll-animate/animation';
1859
- function decodePlayground(state) {
1860
- try {
1861
- const b64 = state.replace(/-/g, '+').replace(/_/g, '/');
1862
- const json = decodeURIComponent(escape(atob(b64)));
1863
- const t = (JSON.parse(json).t || []);
1864
- return t.map(([preset, start, duration, label], i) => ({ target: `:scope > :nth-child(${i + 1})`, preset, start, duration, label }));
1865
- }
1866
- catch {
1867
- return [];
1868
- }
1869
- }
1870
- /** Validate / normalise an animation (object or JSON text). Throws on anything unusable. */
1871
- function normalizeAnimation(input) {
1872
- const d = typeof input === 'string' ? JSON.parse(input) : input;
1873
- if (!d || typeof d !== 'object')
1874
- throw new Error('[motionary] animation: expected an object');
1875
- let tracks;
1876
- if (d.format === 'use-scroll-animate/playground')
1877
- tracks = decodePlayground(String(d.state || ''));
1878
- else if (Array.isArray(d.tracks))
1879
- tracks = d.tracks;
1880
- else
1881
- throw new Error('[motionary] animation: missing "tracks"');
1882
- if (d.format && d.format !== ANIMATION_FORMAT && d.format !== 'use-scroll-animate/playground')
1883
- throw new Error(`[motionary] animation: unknown format "${d.format}"`);
1884
- if (d.version && d.version > 1 && d.format === ANIMATION_FORMAT)
1885
- throw new Error(`[motionary] animation: version ${d.version} needs a newer motionary`);
1886
- const out = tracks
1887
- .filter((t) => t && (t.effect || t.preset || Array.isArray(t.keyframes)))
1888
- .map((t) => ({ ...t, target: t.target || ':scope', start: Math.max(0, Number(t.start) || 0), duration: t.effect ? 0 : Math.max(1, Number(t.duration) || 600) }));
1889
- const end = out.reduce((m, t) => Math.max(m, t.start + t.duration), 0);
1890
- return { tracks: out, duration: Math.max(end, Number(d.duration) || 0), loop: !!d.loop, name: String(d.name || 'animation') };
1891
- }
1892
- const pick = (root, sel) => {
1893
- if (sel === ':scope')
1894
- return [root];
1895
- try {
1896
- return Array.from(root.querySelectorAll(sel));
1897
- }
1898
- catch {
1899
- return [];
1900
- }
1901
- };
1902
- /** Bind an animation to `root` and return its controller (paused at 0 unless `autoplay`). */
1903
- function createPlayer(root, animation, o = {}) {
1904
- const a = normalizeAnimation(animation);
1905
- const loop = o.loop ?? a.loop;
1906
- const anims = [];
1907
- const effects = [];
1908
- for (const t of a.tracks) {
1909
- const els = pick(root, t.target);
1910
- if (t.effect)
1911
- effects.push({ els, t, fired: false });
1912
- else {
1913
- const kf = t.keyframes || TIMELINE_PRESETS[t.preset] || TIMELINE_PRESETS.fade;
1914
- for (const el of els) {
1915
- if (typeof el.animate !== 'function')
1916
- continue;
1917
- const an = el.animate(kf, { duration: t.duration, delay: t.start, easing: t.easing || 'cubic-bezier(0.22, 1, 0.36, 1)', fill: 'both' });
1918
- an.pause();
1919
- an.currentTime = 0;
1920
- anims.push(an);
1921
- }
1922
- }
1923
- }
1924
- let time = 0;
1925
- let playing = false;
1926
- let raf = 0;
1927
- let last = 0;
1928
- let resolve;
1929
- let finished = new Promise((r) => (resolve = r));
1930
- const set = (ms) => {
1931
- time = Math.min(a.duration, Math.max(0, ms));
1932
- for (const an of anims)
1933
- an.currentTime = time;
1934
- };
1935
- const fireDue = () => {
1936
- if (prefersReducedMotion())
1937
- return;
1938
- for (const e of effects)
1939
- if (!e.fired && time >= e.t.start) {
1940
- e.fired = true;
1941
- for (const el of e.els)
1942
- playEffect(el, e.t.effect, e.t.options || {}).catch(() => undefined);
1943
- }
1944
- };
1945
- const done = () => {
1946
- resolve();
1947
- o.onFinish?.();
1948
- finished = new Promise((r) => (resolve = r));
1949
- };
1950
- const frame = (now) => {
1951
- raf = 0;
1952
- if (!playing)
1953
- return;
1954
- set(time + (now - last) * player.rate);
1955
- last = now;
1956
- fireDue();
1957
- if (time >= a.duration) {
1958
- if (loop) {
1959
- effects.forEach((e) => (e.fired = false));
1960
- set(0);
1961
- }
1962
- else {
1963
- playing = false;
1964
- done();
1965
- return;
1966
- }
1967
- }
1968
- raf = requestAnimationFrame(frame);
1969
- };
1970
- const player = {
1971
- get duration() {
1972
- return a.duration;
1973
- },
1974
- get currentTime() {
1975
- return time;
1976
- },
1977
- get playing() {
1978
- return playing;
1979
- },
1980
- rate: o.rate ?? 1,
1981
- get finished() {
1982
- return finished;
1983
- },
1984
- play() {
1985
- if (prefersReducedMotion()) {
1986
- set(a.duration);
1987
- effects.forEach((e) => (e.fired = true));
1988
- done();
1989
- return;
1990
- }
1991
- if (playing)
1992
- return;
1993
- if (time >= a.duration) {
1994
- effects.forEach((e) => (e.fired = false));
1995
- set(0);
1996
- }
1997
- playing = true;
1998
- last = performance.now();
1999
- fireDue();
2000
- raf = requestAnimationFrame(frame);
2001
- },
2002
- pause() {
2003
- playing = false;
2004
- cancelAnimationFrame(raf);
2005
- raf = 0;
2006
- },
2007
- seek(ms) {
2008
- set(ms);
2009
- effects.forEach((e) => (e.fired = e.t.start < time));
2010
- },
2011
- destroy() {
2012
- player.pause();
2013
- anims.forEach((an) => an.cancel());
2014
- },
2015
- };
2016
- if (o.autoplay)
2017
- player.play();
2018
- return player;
2019
- }
2020
- /**
2021
- * `<usa-player src="hero.json" | <script type="application/json"> child
2022
- * trigger="load | view | scroll | click | manual" loop rate controls>`.
2023
- * Emits `usa-player-ready` and `usa-player-finish`; sets `data-error` when the
2024
- * animation cannot be loaded.
2025
- */
2026
- function definePlayer(tag = 'usa-player') {
2027
- return defineElement(tag, (Base) => class UsaPlayer extends Base {
2028
- constructor() {
2029
- super(...arguments);
2030
- this.player = null;
2031
- this.json = null;
2032
- }
2033
- static get observedAttributes() {
2034
- return ['src', 'trigger', 'loop', 'rate'];
2035
- }
2036
- load(animation) {
2037
- this.json = animation;
2038
- this.start();
2039
- }
2040
- play() {
2041
- this.player?.play();
2042
- }
2043
- pause() {
2044
- this.player?.pause();
2045
- }
2046
- seek(ms) {
2047
- this.player?.seek(ms);
2048
- }
2049
- start() {
2050
- this.player?.destroy();
2051
- this.player = null;
2052
- if (!this.json)
2053
- return;
2054
- try {
2055
- this.player = createPlayer(this, this.json, {
2056
- loop: this.hasAttribute('loop') ? true : undefined,
2057
- rate: this.num('rate', 1),
2058
- onFinish: () => this.dispatchEvent(new CustomEvent('usa-player-finish', { bubbles: true })),
2059
- });
2060
- this.removeAttribute('data-error');
2061
- }
2062
- catch (err) {
2063
- this.setAttribute('data-error', String(err.message || err));
2064
- return;
2065
- }
2066
- const p = this.player;
2067
- this.dispatchEvent(new CustomEvent('usa-player-ready', { detail: { duration: p.duration }, bubbles: true }));
2068
- const trig = this.str('trigger', 'view');
2069
- if (trig === 'load')
2070
- p.play();
2071
- else if (trig === 'view')
2072
- this.inView((v) => v && p.play(), { threshold: 0.25 });
2073
- else if (trig === 'click')
2074
- this.listen(this, 'click', () => (p.playing ? p.pause() : p.play()));
2075
- else if (trig === 'scroll') {
2076
- let f = 0;
2077
- const upd = () => {
2078
- f = 0;
2079
- p.seek(storyProgress(this) * p.duration);
2080
- };
2081
- const kick = () => void (f || (f = requestAnimationFrame(upd)));
2082
- this.listen(window, 'scroll', kick, { passive: true });
2083
- this.listen(window, 'resize', kick);
2084
- this.onCleanup(() => cancelAnimationFrame(f));
2085
- upd();
2086
- }
2087
- if (this.flag('controls'))
2088
- this.mountControls(p);
2089
- }
2090
- mountControls(p) {
2091
- const b = document.createElement('button');
2092
- b.type = 'button';
2093
- b.setAttribute('data-player-toggle', '');
2094
- b.textContent = '▶︎ / ❚❚';
2095
- b.setAttribute('aria-label', 'Play / pause animation');
2096
- this.listen(b, 'click', (e) => {
2097
- e.stopPropagation();
2098
- if (p.playing)
2099
- p.pause();
2100
- else
2101
- p.play();
2102
- b.setAttribute('aria-pressed', String(p.playing));
2103
- });
2104
- this.append(b);
2105
- this.onCleanup(() => b.remove());
2106
- }
2107
- changed(name) {
2108
- if (name === 'src')
2109
- this.json = null;
2110
- super.changed(name);
2111
- }
2112
- mount() {
2113
- this.onCleanup(() => {
2114
- this.player?.destroy();
2115
- this.player = null;
2116
- });
2117
- const inline = this.querySelector('script[type="application/json"]');
2118
- const src = this.str('src');
2119
- if (inline && !this.json)
2120
- this.json = inline.textContent || '';
2121
- if (src && !this.json) {
2122
- fetch(src)
2123
- .then((r) => (r.ok ? r.text() : Promise.reject(new Error(`HTTP ${r.status}`))))
2124
- .then((t) => this.isConnected && this.load(t))
2125
- .catch((err) => this.setAttribute('data-error', String(err.message || err)));
2126
- return;
2127
- }
2128
- this.start();
2129
- }
2130
- }, { id: 'usa-player', text: 'usa-player{display:block;position:relative}usa-player>script{display:none}usa-player [data-player-toggle]{position:absolute;right:8px;bottom:8px}' });
2131
- }
2132
-
2133
1625
  /**
2134
1626
  * motionary/components/effects — the 5.x effect packs, all
2135
1627
  * registered through `registerEffect()` (5.0) and playable with
@@ -2197,5 +1689,5 @@ function registerAllEffects() {
2197
1689
  registerEffects(defs);
2198
1690
  }
2199
1691
 
2200
- export { ANIMATION_FORMAT, AUDIO_FX, CARD_FX, CLICK_FX, CURSOR_FX, EFFECT_PACKS, GENERATIVE_FX, GESTURES, MICRO_FX, PAGE_FX, PHYSICS_FX, STORY_TEMPLATES, THEMES, THEME_FX, THEME_NAMES, THEME_ROLES, angleDelta, applyTheme, bindBeat, bindGesture, bounceKeyframes, bumpCount, canvasBackground, createBeatDetector, createPlayer, defineAudio, defineEffectElements, defineGestureFx, definePlayer, defineStory, defineTheme, disableAudio, enableAudio, flingVelocity, formatCount, fxLayer, getAudio, hexRgb, normalizeAnimation, onBeat, playThemeEffect, registerAllEffects, registerAudioEffects, registerCardClickEffects, registerCursorEffects, registerGenerativeEffects, registerMicroEffects, registerPageEffects, registerPhysicsEffects, solveSpring, springKeyframes, storyProgress, swapLabel, themeCss, themePreset, themeVars, togglePressed };
1692
+ export { AUDIO_FX, CARD_FX, CLICK_FX, CURSOR_FX, EFFECT_PACKS, GENERATIVE_FX, GESTURES, MICRO_FX, PAGE_FX, PHYSICS_FX, THEMES, THEME_FX, THEME_NAMES, THEME_ROLES, angleDelta, applyTheme, bindBeat, bindGesture, bounceKeyframes, bumpCount, canvasBackground, createBeatDetector, defineAudio, defineEffectElements, defineGestureFx, definePlayer, defineStory, defineTheme, disableAudio, enableAudio, flingVelocity, fxLayer, getAudio, hexRgb, onBeat, playThemeEffect, registerAllEffects, registerAudioEffects, registerCardClickEffects, registerCursorEffects, registerGenerativeEffects, registerMicroEffects, registerPageEffects, registerPhysicsEffects, solveSpring, springKeyframes, swapLabel, themeCss, themePreset, themeVars, togglePressed };
2201
1693
  //# sourceMappingURL=effects.js.map