motionary 6.8.0 → 7.0.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 +39 -0
- package/README.md +2 -2
- package/README_ja.md +2 -2
- package/README_zh.md +2 -2
- package/bin/usa-codemod-7.mjs +91 -0
- package/dist/chunks/{gpu-CsP2ZB3x.js → gpu-Bkw605Ds.js} +183 -5
- package/dist/chunks/gpu-Bkw605Ds.js.map +1 -0
- package/dist/chunks/{gpu-BBRLgEzM.cjs → gpu-Dx0H875w.cjs} +187 -4
- package/dist/chunks/gpu-Dx0H875w.cjs.map +1 -0
- package/dist/chunks/{index-tags-wv0R_vkO.cjs → index-tags-BTMwrfgV.cjs} +3 -3
- package/dist/chunks/index-tags-BTMwrfgV.cjs.map +1 -0
- package/dist/chunks/{index-tags-DucKMQr_.js → index-tags-C04JP8g4.js} +3 -3
- package/dist/chunks/index-tags-C04JP8g4.js.map +1 -0
- package/dist/chunks/player-C-TwEEy6.js +516 -0
- package/dist/chunks/player-C-TwEEy6.js.map +1 -0
- package/dist/chunks/player-PS6_FzNw.cjs +525 -0
- package/dist/chunks/player-PS6_FzNw.cjs.map +1 -0
- package/dist/components/a11y.cjs +1 -1
- package/dist/components/a11y.d.cts +2 -2
- package/dist/components/a11y.d.ts +2 -2
- package/dist/components/a11y.js +1 -1
- package/dist/components/angular.cjs +2 -2
- package/dist/components/angular.cjs.map +1 -1
- package/dist/components/angular.d.cts +5 -36
- package/dist/components/angular.d.ts +5 -36
- package/dist/components/angular.js +2 -2
- package/dist/components/angular.js.map +1 -1
- package/dist/components/effects.cjs +13 -522
- package/dist/components/effects.cjs.map +1 -1
- package/dist/components/effects.js +5 -513
- package/dist/components/effects.js.map +1 -1
- package/dist/components/fx-3d.cjs +2 -2
- package/dist/components/fx-3d.cjs.map +1 -1
- package/dist/components/fx-3d.d.cts +2 -2
- package/dist/components/fx-3d.d.ts +2 -2
- package/dist/components/fx-3d.js +2 -2
- package/dist/components/fx-3d.js.map +1 -1
- package/dist/components/fx-focus.cjs +125 -0
- package/dist/components/fx-focus.cjs.map +1 -0
- package/dist/components/fx-focus.d.cts +65 -0
- package/dist/components/fx-focus.d.ts +65 -0
- package/dist/components/fx-focus.js +122 -0
- package/dist/components/fx-focus.js.map +1 -0
- package/dist/components/fx-gpu.cjs +2 -2
- package/dist/components/fx-gpu.d.cts +2 -2
- package/dist/components/fx-gpu.d.ts +2 -2
- package/dist/components/fx-gpu.js +1 -1
- package/dist/components/fx-light.cjs +2 -2
- package/dist/components/fx-light.cjs.map +1 -1
- package/dist/components/fx-light.d.cts +2 -2
- package/dist/components/fx-light.d.ts +2 -2
- package/dist/components/fx-light.js +2 -2
- package/dist/components/fx-light.js.map +1 -1
- package/dist/components/fx-morph.cjs +2 -2
- package/dist/components/fx-morph.cjs.map +1 -1
- package/dist/components/fx-morph.d.cts +2 -2
- package/dist/components/fx-morph.d.ts +2 -2
- package/dist/components/fx-morph.js +2 -2
- package/dist/components/fx-morph.js.map +1 -1
- package/dist/components/fx-physics.cjs +2 -2
- package/dist/components/fx-physics.cjs.map +1 -1
- package/dist/components/fx-physics.d.cts +2 -2
- package/dist/components/fx-physics.d.ts +2 -2
- package/dist/components/fx-physics.js +2 -2
- package/dist/components/fx-physics.js.map +1 -1
- package/dist/components/fx-text.cjs +2 -2
- package/dist/components/fx-text.cjs.map +1 -1
- package/dist/components/fx-text.d.cts +2 -2
- package/dist/components/fx-text.d.ts +2 -2
- package/dist/components/fx-text.js +2 -2
- package/dist/components/fx-text.js.map +1 -1
- package/dist/components/fx-transitions.cjs +2 -2
- package/dist/components/fx-transitions.cjs.map +1 -1
- package/dist/components/fx-transitions.d.cts +2 -2
- package/dist/components/fx-transitions.d.ts +2 -2
- package/dist/components/fx-transitions.js +2 -2
- package/dist/components/fx-transitions.js.map +1 -1
- package/dist/components/fx-weather.cjs +2 -2
- package/dist/components/fx-weather.cjs.map +1 -1
- package/dist/components/fx-weather.d.cts +2 -2
- package/dist/components/fx-weather.d.ts +2 -2
- package/dist/components/fx-weather.js +2 -2
- package/dist/components/fx-weather.js.map +1 -1
- package/dist/components/fx2.cjs +37 -22
- package/dist/components/fx2.cjs.map +1 -1
- package/dist/components/fx2.d.cts +135 -14
- package/dist/components/fx2.d.ts +135 -14
- package/dist/components/fx2.js +25 -21
- package/dist/components/fx2.js.map +1 -1
- package/dist/components/interaction.cjs +11 -94
- package/dist/components/interaction.cjs.map +1 -1
- package/dist/components/interaction.css +0 -1
- package/dist/components/interaction.d.cts +3 -21
- package/dist/components/interaction.d.ts +3 -21
- package/dist/components/interaction.js +12 -94
- package/dist/components/interaction.js.map +1 -1
- package/dist/components/jsx.d.cts +2 -2
- package/dist/components/jsx.d.ts +2 -2
- package/dist/components/lazy.cjs +1 -1
- package/dist/components/lazy.d.cts +2 -2
- package/dist/components/lazy.d.ts +2 -2
- package/dist/components/lazy.js +1 -1
- package/dist/components/lite.cjs +115 -256
- package/dist/components/lite.cjs.map +1 -1
- package/dist/components/lite.js +116 -255
- package/dist/components/lite.js.map +1 -1
- package/dist/components/marketplace.cjs +82 -0
- package/dist/components/marketplace.cjs.map +1 -0
- package/dist/components/marketplace.d.cts +108 -0
- package/dist/components/marketplace.d.ts +108 -0
- package/dist/components/marketplace.js +77 -0
- package/dist/components/marketplace.js.map +1 -0
- package/dist/components/perf.cjs +1 -1
- package/dist/components/perf.d.cts +2 -2
- package/dist/components/perf.d.ts +2 -2
- package/dist/components/perf.js +1 -1
- package/dist/components/react.cjs +2 -2
- package/dist/components/react.cjs.map +1 -1
- package/dist/components/react.js +2 -2
- package/dist/components/react.js.map +1 -1
- package/dist/components/solid.cjs +2 -2
- package/dist/components/solid.cjs.map +1 -1
- package/dist/components/solid.d.cts +4 -35
- package/dist/components/solid.d.ts +4 -35
- package/dist/components/solid.js +2 -2
- package/dist/components/solid.js.map +1 -1
- package/dist/components/svelte.cjs +2 -2
- package/dist/components/svelte.cjs.map +1 -1
- package/dist/components/svelte.d.cts +5 -36
- package/dist/components/svelte.d.ts +5 -36
- package/dist/components/svelte.js +2 -2
- package/dist/components/svelte.js.map +1 -1
- package/dist/components/ui.cjs +16 -74
- package/dist/components/ui.cjs.map +1 -1
- package/dist/components/ui.css +0 -1
- package/dist/components/ui.d.cts +3 -18
- package/dist/components/ui.d.ts +3 -18
- package/dist/components/ui.js +17 -74
- package/dist/components/ui.js.map +1 -1
- package/dist/components/vue.cjs +2 -2
- package/dist/components/vue.cjs.map +1 -1
- package/dist/components/vue.d.cts +5 -36
- package/dist/components/vue.d.ts +5 -36
- package/dist/components/vue.js +2 -2
- package/dist/components/vue.js.map +1 -1
- package/dist/components/widgets.cjs +622 -53
- package/dist/components/widgets.cjs.map +1 -1
- package/dist/components/widgets.d.cts +106 -2
- package/dist/components/widgets.d.ts +106 -2
- package/dist/components/widgets.js +615 -54
- package/dist/components/widgets.js.map +1 -1
- package/dist/components.cjs +1 -3
- package/dist/components.cjs.map +1 -1
- package/dist/components.css +0 -2
- package/dist/components.d.cts +6 -39
- package/dist/components.d.ts +6 -39
- package/dist/components.js +3 -3
- package/dist/components.umd.js +2 -2
- package/dist/components.umd.js.map +1 -1
- package/dist/widgets.umd.js +1 -1
- package/dist/widgets.umd.js.map +1 -1
- package/docs/ROADMAP.md +12 -12
- package/docs/accessibility.md +2 -2
- package/docs/components.md +41 -2
- package/docs/deprecations.md +4 -0
- package/docs/frameworks-ssr.md +4 -4
- package/docs/hybrid-apps.md +2 -2
- package/docs/upgrading-7.md +43 -0
- package/docs/windows-apps.md +1 -1
- package/package.json +133 -2
- package/dist/chunks/gpu-BBRLgEzM.cjs.map +0 -1
- package/dist/chunks/gpu-CsP2ZB3x.js.map +0 -1
- package/dist/chunks/index-tags-DucKMQr_.js.map +0 -1
- package/dist/chunks/index-tags-wv0R_vkO.cjs.map +0 -1
|
@@ -1,11 +1,13 @@
|
|
|
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 {
|
|
3
|
+
import { d as defineStory, a as definePlayer } from '../chunks/player-C-TwEEy6.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-C-TwEEy6.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
7
|
import { playEffect, bindEffect, registerEffects } from '../chunks/registry-D23neB4M.js';
|
|
8
|
+
import { y as defineElement, p as prefersReducedMotion, v as adoptStyles } from '../chunks/base-DchG4q_S.js';
|
|
7
9
|
import { applyMotionTokens, motionTokensToVars, mergeMotionTokens } from './tokens.js';
|
|
8
|
-
import
|
|
10
|
+
import '../chunks/core-DVyTlo9Q.js';
|
|
9
11
|
import '../chunks/fx-DUMVKSvg.js';
|
|
10
12
|
|
|
11
13
|
const CARD_FX = [
|
|
@@ -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 {
|
|
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
|