@alea-design/motion 0.6.0 → 0.7.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/dist/index.js CHANGED
@@ -1,17 +1,23 @@
1
1
  "use client";
2
- import { jsx as b, jsxs as V } from "react/jsx-runtime";
3
- import { useState as k, useEffect as w, useRef as h, useCallback as j, createElement as E, isValidElement as P, cloneElement as A, Children as z, Fragment as H, useLayoutEffect as Y } from "react";
4
- const R = typeof window > "u" ? w : Y, X = ["out", "in", "in-out", "standard", "emphasized", "spring"], U = (t) => X.includes(t) ? `var(--alea-motion-${t === "spring" ? "spring" : "ease-" + t})` : t, O = (t, e) => t === "none" ? "none" : `alea-m-${t}-${e}`;
5
- function I(t) {
6
- if (t === void 0) return;
7
- const e = t === !1 ? { enter: "none" } : typeof t == "string" ? { enter: t } : t, n = {};
8
- return e.enter ? (n["--alea-enter"] = O(e.enter, "in"), n["--alea-exit"] = O(e.exit || e.enter, "out")) : e.exit && (n["--alea-exit"] = O(e.exit, "out")), e.duration != null ? (n["--alea-enter-duration"] = `${e.duration}ms`, n["--alea-exit-duration"] = `${e.exitDuration ?? Math.round(e.duration * 0.6)}ms`) : e.exitDuration != null && (n["--alea-exit-duration"] = `${e.exitDuration}ms`), e.easing && (n["--alea-enter-ease"] = U(e.easing)), e.delay != null && (n["--alea-enter-delay"] = `${e.delay}ms`), n;
2
+ import { jsx as S, jsxs as _ } from "react/jsx-runtime";
3
+ import { useRef as w, useState as L, useEffect as h, createElement as $, Children as U, isValidElement as F, cloneElement as H, useCallback as C, Fragment as J, useLayoutEffect as Q, version as Z } from "react";
4
+ function K(e, t) {
5
+ if (!e) return { enter: !1, leave: !1 };
6
+ if (e === !0) return { enter: !0, leave: !0 };
7
+ const n = e.max === void 0 || t <= e.max;
8
+ return { enter: n && e.enter !== !1, leave: n && e.leave !== !1 };
9
9
  }
10
- function oe(t, e) {
11
- const n = I(e);
12
- return n ? typeof t == "function" ? ((a) => ({ ...n, ...t(a) })) : { ...n, ...t } : t;
10
+ const q = (e) => typeof e == "object" ? e.resetOn ?? [] : [], ee = (e, t) => e.length === t.length && e.every((n, r) => Object.is(n, t[r])), Y = typeof window > "u" ? h : Q, te = ["out", "in", "in-out", "standard", "emphasized", "spring"], ne = (e) => te.includes(e) ? `var(--alea-motion-${e === "spring" ? "spring" : "ease-" + e})` : e, D = (e, t) => e === "none" ? "none" : `alea-m-${e}-${t}`;
11
+ function V(e) {
12
+ if (e === void 0) return;
13
+ const t = e === !1 ? { enter: "none" } : typeof e == "string" ? { enter: e } : e, n = {};
14
+ return t.enter ? (n["--alea-enter"] = D(t.enter, "in"), n["--alea-exit"] = D(t.exit || t.enter, "out")) : t.exit && (n["--alea-exit"] = D(t.exit, "out")), t.duration != null ? (n["--alea-enter-duration"] = `${t.duration}ms`, n["--alea-exit-duration"] = `${t.exitDuration ?? Math.round(t.duration * 0.6)}ms`) : t.exitDuration != null && (n["--alea-exit-duration"] = `${t.exitDuration}ms`), t.easing && (n["--alea-enter-ease"] = ne(t.easing)), t.delay != null && (n["--alea-enter-delay"] = `${t.delay}ms`), n;
13
15
  }
14
- const W = {
16
+ function we(e, t) {
17
+ const n = V(t);
18
+ return n ? typeof e == "function" ? ((r) => ({ ...n, ...e(r) })) : { ...n, ...e } : e;
19
+ }
20
+ const re = {
15
21
  popover: ".alea-popover",
16
22
  select: ".alea-select-popover",
17
23
  menu: ".alea-menu-popover",
@@ -23,402 +29,420 @@ const W = {
23
29
  hovercard: ".alea-hovercard",
24
30
  datepicker: ".alea-cal-popover",
25
31
  tour: ".alea-tour-card"
26
- }, _ = { instant: 120, fast: 200, base: 320, slow: 480, slower: 720 }, G = { sm: 8, md: 12, lg: 24 }, J = { sm: 4, md: 8, lg: 16 };
27
- function ae(t = {}) {
28
- const e = {}, n = t.speed, a = t.intensity;
29
- if (n != null && n !== 1) for (const [i, r] of Object.entries(_)) e[`--alea-motion-duration-${i}`] = `${Math.round(r * n)}ms`;
30
- if (a != null && a !== 1) {
31
- for (const [i, r] of Object.entries(G)) e[`--alea-motion-distance-${i}`] = `${+(r * a).toFixed(2)}px`;
32
- for (const [i, r] of Object.entries(J)) e[`--alea-motion-blur-${i}`] = `${+(r * a).toFixed(2)}px`;
33
- e["--alea-motion-scale-from"] = String(+(1 - 0.08 * a).toFixed(3)), e["--alea-motion-scale-press"] = String(+(1 - 0.04 * a).toFixed(3)), e["--alea-motion-lift"] = `${+(-4 * a).toFixed(2)}px`;
32
+ }, oe = { instant: 120, fast: 200, base: 320, slow: 480, slower: 720 }, ae = { sm: 8, md: 12, lg: 24 }, ie = { sm: 4, md: 8, lg: 16 };
33
+ function he(e = {}) {
34
+ const t = {}, n = e.speed, r = e.intensity;
35
+ if (n != null && n !== 1) for (const [i, o] of Object.entries(oe)) t[`--alea-motion-duration-${i}`] = `${Math.round(o * n)}ms`;
36
+ if (r != null && r !== 1) {
37
+ for (const [i, o] of Object.entries(ae)) t[`--alea-motion-distance-${i}`] = `${+(o * r).toFixed(2)}px`;
38
+ for (const [i, o] of Object.entries(ie)) t[`--alea-motion-blur-${i}`] = `${+(o * r).toFixed(2)}px`;
39
+ t["--alea-motion-scale-from"] = String(+(1 - 0.08 * r).toFixed(3)), t["--alea-motion-scale-press"] = String(+(1 - 0.04 * r).toFixed(3)), t["--alea-motion-lift"] = `${+(-4 * r).toFixed(2)}px`;
34
40
  }
35
- return e;
41
+ return t;
36
42
  }
37
- function ie(t = {}) {
38
- const e = {};
39
- return t.mode && t.mode !== "expressive" && (e["data-alea-motion"] = t.mode), t.reduced && t.reduced !== "system" && (e["data-alea-reduced"] = t.reduced), e;
43
+ function ye(e = {}) {
44
+ const t = {};
45
+ return e.mode && e.mode !== "expressive" && (t["data-alea-motion"] = e.mode), e.reduced && e.reduced !== "system" && (t["data-alea-reduced"] = e.reduced), t;
40
46
  }
41
- function se(t = {}, e = ":root") {
42
- return Object.entries(t).map(([n, a]) => {
43
- const i = I(a), r = W[n];
44
- return !i || !r ? "" : `${e} ${r} { ${Object.entries(i).map(([s, l]) => `${s}: ${l};`).join(" ")} }`;
47
+ function xe(e = {}, t = ":root") {
48
+ return Object.entries(e).map(([n, r]) => {
49
+ const i = V(r), o = re[n];
50
+ return !i || !o ? "" : `${t} ${o} { ${Object.entries(i).map(([a, s]) => `${a}: ${s};`).join(" ")} }`;
45
51
  }).filter(Boolean).join(`
46
52
  `);
47
53
  }
48
- function D() {
49
- const [t, e] = k(!1);
50
- return w(() => {
51
- var r, s;
54
+ function W() {
55
+ const [e, t] = L(!1);
56
+ return h(() => {
57
+ var o, a;
52
58
  if (typeof window > "u") return;
53
- const n = (r = window.matchMedia) == null ? void 0 : r.call(window, "(prefers-reduced-motion: reduce)"), a = () => {
54
- const l = document.documentElement, d = l.getAttribute("data-alea-reduced"), c = l.getAttribute("data-alea-motion");
55
- e(c === "off" || c === "reduced" || d === "always" || d !== "never" && !!(n != null && n.matches));
59
+ const n = (o = window.matchMedia) == null ? void 0 : o.call(window, "(prefers-reduced-motion: reduce)"), r = () => {
60
+ const s = document.documentElement, d = s.getAttribute("data-alea-reduced"), l = s.getAttribute("data-alea-motion");
61
+ t(l === "off" || l === "reduced" || d === "always" || d !== "never" && !!(n != null && n.matches));
56
62
  };
57
- a(), (s = n == null ? void 0 : n.addEventListener) == null || s.call(n, "change", a);
58
- const i = new MutationObserver(a);
63
+ r(), (a = n == null ? void 0 : n.addEventListener) == null || a.call(n, "change", r);
64
+ const i = new MutationObserver(r);
59
65
  return i.observe(document.documentElement, { attributes: !0, attributeFilter: ["data-alea-motion", "data-alea-reduced"] }), () => {
60
- var l;
61
- (l = n == null ? void 0 : n.removeEventListener) == null || l.call(n, "change", a), i.disconnect();
66
+ var s;
67
+ (s = n == null ? void 0 : n.removeEventListener) == null || s.call(n, "change", r), i.disconnect();
62
68
  };
63
- }, []), t;
69
+ }, []), e;
64
70
  }
65
- function Q(t = {}) {
66
- const { once: e = !0, margin: n = "0px 0px -10% 0px", threshold: a = 0.1 } = t, i = h(null), [r, s] = k(!1);
67
- return w(() => {
68
- const l = i.current;
69
- if (!l || typeof IntersectionObserver > "u") {
70
- s(!0);
71
+ function se(e = {}) {
72
+ const { once: t = !0, margin: n = "0px 0px -10% 0px", threshold: r = 0.1 } = e, i = w(null), [o, a] = L(!1);
73
+ return h(() => {
74
+ const s = i.current;
75
+ if (!s || typeof IntersectionObserver > "u") {
76
+ a(!0);
71
77
  return;
72
78
  }
73
- const d = new IntersectionObserver(([c]) => {
74
- c.isIntersecting ? (s(!0), e && d.disconnect()) : e || s(!1);
75
- }, { rootMargin: n, threshold: a });
76
- return d.observe(l), () => d.disconnect();
77
- }, [e, n, a]), [i, r];
79
+ const d = new IntersectionObserver(([l]) => {
80
+ l.isIntersecting ? (a(!0), t && d.disconnect()) : t || a(!1);
81
+ }, { rootMargin: n, threshold: r });
82
+ return d.observe(s), () => d.disconnect();
83
+ }, [t, n, r]), [i, o];
78
84
  }
79
- let S = null;
80
- function Z(t) {
85
+ let P = null;
86
+ function le(e) {
81
87
  return typeof IntersectionObserver > "u" ? () => {
82
- } : (S ?? (S = new IntersectionObserver((e) => {
83
- for (const n of e) n.target.toggleAttribute("data-alea-offscreen", !n.isIntersecting);
84
- }, { rootMargin: "64px" })), S.observe(t), () => {
85
- S == null || S.unobserve(t), t.removeAttribute("data-alea-offscreen");
88
+ } : (P ?? (P = new IntersectionObserver((t) => {
89
+ for (const n of t) n.target.toggleAttribute("data-alea-offscreen", !n.isIntersecting);
90
+ }, { rootMargin: "64px" })), P.observe(e), () => {
91
+ P == null || P.unobserve(e), e.removeAttribute("data-alea-offscreen");
86
92
  });
87
93
  }
88
- function le() {
89
- const t = h(null);
90
- return w(() => t.current ? Z(t.current) : void 0, []), t;
94
+ function be() {
95
+ const e = w(null);
96
+ return h(() => e.current ? le(e.current) : void 0, []), e;
91
97
  }
92
- function ce(t = 8) {
93
- const [e, n] = k("up");
94
- return w(() => {
95
- let a = window.scrollY;
98
+ function Ee(e = 8) {
99
+ const [t, n] = L("up");
100
+ return h(() => {
101
+ let r = window.scrollY;
96
102
  const i = () => {
97
- const r = window.scrollY;
98
- Math.abs(r - a) < t || (n(r > a && r > 64 ? "down" : "up"), a = r);
103
+ const o = window.scrollY;
104
+ Math.abs(o - r) < e || (n(o > r && o > 64 ? "down" : "up"), r = o);
99
105
  };
100
106
  return window.addEventListener("scroll", i, { passive: !0 }), () => window.removeEventListener("scroll", i);
101
- }, [t]), e;
107
+ }, [e]), t;
102
108
  }
103
- function ue() {
104
- return { onPointerDown: j((e) => {
105
- const n = e.currentTarget, a = n.getBoundingClientRect(), i = Math.hypot(Math.max(e.clientX - a.left, a.right - e.clientX), Math.max(e.clientY - a.top, a.bottom - e.clientY)) * 2, r = document.createElement("span");
106
- r.className = "alea-ripple", r.setAttribute("aria-hidden", "true"), r.style.setProperty("--alea-ripple-x", `${e.clientX - a.left}px`), r.style.setProperty("--alea-ripple-y", `${e.clientY - a.top}px`), r.style.setProperty("--alea-ripple-size", `${i}px`), n.appendChild(r), r.addEventListener("animationend", () => r.remove()), window.setTimeout(() => r.remove(), 1200);
109
+ function Se() {
110
+ return { onPointerDown: C((t) => {
111
+ const n = t.currentTarget, r = n.getBoundingClientRect(), i = Math.hypot(Math.max(t.clientX - r.left, r.right - t.clientX), Math.max(t.clientY - r.top, r.bottom - t.clientY)) * 2, o = document.createElement("span");
112
+ o.className = "alea-ripple", o.setAttribute("aria-hidden", "true"), o.style.setProperty("--alea-ripple-x", `${t.clientX - r.left}px`), o.style.setProperty("--alea-ripple-y", `${t.clientY - r.top}px`), o.style.setProperty("--alea-ripple-size", `${i}px`), n.appendChild(o), o.addEventListener("animationend", () => o.remove()), window.setTimeout(() => o.remove(), 1200);
107
113
  }, []), className: "alea-ripple-host" };
108
114
  }
109
- function de(t) {
110
- const e = typeof document < "u" ? document : null;
111
- e != null && e.startViewTransition ? e.startViewTransition(t) : t();
115
+ function Ne(e) {
116
+ const t = typeof document < "u" ? document : null;
117
+ t != null && t.startViewTransition ? t.startViewTransition(e) : e();
112
118
  }
113
- function fe({ as: t = "div", motion: e = "rise", delay: n, once: a = !0, stagger: i, className: r, style: s, children: l, ...d }) {
114
- const [c, u] = Q({ once: a }), [o, f] = k(!1);
115
- R(() => {
116
- const m = c.current;
117
- m && m.getBoundingClientRect().top > window.innerHeight && f(!0);
119
+ function Me({ as: e = "div", motion: t = "rise", delay: n, once: r = !0, stagger: i, className: o, style: a, children: s, ...d }) {
120
+ const [l, c] = se({ once: r }), [u, v] = L(!1);
121
+ Y(() => {
122
+ const p = l.current;
123
+ p && p.getBoundingClientRect().top > window.innerHeight && v(!0);
118
124
  }, []);
119
- const p = typeof e == "string" ? { enter: e } : e;
120
- return E(t, {
125
+ const g = typeof t == "string" ? { enter: t } : t;
126
+ return $(e, {
121
127
  ...d,
122
- ref: c,
123
- className: r,
124
- "data-reveal": o && !u ? "pending" : o ? "in" : void 0,
128
+ ref: l,
129
+ className: o,
130
+ "data-reveal": u && !c ? "pending" : u ? "in" : void 0,
125
131
  "data-stagger": i ? "reveal" : void 0,
126
- style: { ...i ? {} : I({ ...p, delay: n ?? p.delay }), ...s }
127
- }, l);
132
+ style: { ...i ? {} : V({ ...g, delay: n ?? g.delay }), ...a }
133
+ }, s);
128
134
  }
129
- function pe({ show: t, exitClassName: e = "alea-dissolve-out", children: n }) {
130
- const [a, i] = k(t), [r, s] = k(!1), l = h(null);
131
- return w(() => {
132
- var o;
133
- if (t) {
134
- i(!0), s(!1);
135
+ function Le({ show: e, exitClassName: t = "alea-dissolve-out", children: n }) {
136
+ const [r, i] = L(e), [o, a] = L(!1), s = w(null);
137
+ return h(() => {
138
+ var u;
139
+ if (e) {
140
+ i(!0), a(!1);
135
141
  return;
136
142
  }
137
- if (!a) return;
138
- s(!0);
139
- const d = l.current, c = () => {
140
- i(!1), s(!1);
141
- }, u = ((o = d == null ? void 0 : d.getAnimations) == null ? void 0 : o.call(d)) || [];
142
- if (!d || !u.length) {
143
- const f = window.setTimeout(c, 0);
144
- return () => window.clearTimeout(f);
143
+ if (!r) return;
144
+ a(!0);
145
+ const d = s.current, l = () => {
146
+ i(!1), a(!1);
147
+ }, c = ((u = d == null ? void 0 : d.getAnimations) == null ? void 0 : u.call(d)) || [];
148
+ if (!d || !c.length) {
149
+ const v = window.setTimeout(l, 0);
150
+ return () => window.clearTimeout(v);
145
151
  }
146
- Promise.all(u.map((f) => f.finished.catch(() => {
147
- }))).then(c);
148
- }, [t]), w(() => {
149
- var d, c;
150
- r && l.current && !((c = (d = l.current).getAnimations) != null && c.call(d).length) && (i(!1), s(!1));
151
- }, [r]), !a || !P(n) ? null : A(n, { ref: l, className: [n.props.className, r && e].filter(Boolean).join(" ") });
152
+ Promise.all(c.map((v) => v.finished.catch(() => {
153
+ }))).then(l);
154
+ }, [e]), h(() => {
155
+ var d, l;
156
+ o && s.current && !((l = (d = s.current).getAnimations) != null && l.call(d).length) && (i(!1), a(!1));
157
+ }, [o]), !r || !F(n) ? null : H(n, { ref: s, className: [n.props.className, o && t].filter(Boolean).join(" ") });
152
158
  }
153
- function me({ children: t, as: e = "span", className: n, direction: a = "up", variant: i = "blur" }) {
154
- const [r, s] = k([{ id: 0, node: t }]), l = h(t), d = h(0), c = (u) => {
155
- var o;
156
- return typeof u == "string" || typeof u == "number" ? String(u) : P(u) ? String(u.key ?? "") + JSON.stringify(((o = u.props) == null ? void 0 : o.children) ?? "") : "";
159
+ function $e({ children: e, as: t = "span", className: n, direction: r = "up", variant: i = "blur" }) {
160
+ const [o, a] = L([{ id: 0, node: e }]), s = w(e), d = w(0), l = (c) => {
161
+ var u;
162
+ return typeof c == "string" || typeof c == "number" ? String(c) : F(c) ? String(c.key ?? "") + JSON.stringify(((u = c.props) == null ? void 0 : u.children) ?? "") : "";
157
163
  };
158
- return w(() => {
159
- if (c(t) === c(l.current)) {
160
- s((u) => u.map((o) => o.out ? o : { ...o, node: t }));
164
+ return h(() => {
165
+ if (l(e) === l(s.current)) {
166
+ a((c) => c.map((u) => u.out ? u : { ...u, node: e }));
161
167
  return;
162
168
  }
163
- l.current = t, d.current += 1, s((u) => [...u.filter((o) => !o.out).map((o) => ({ ...o, out: !0 })), { id: d.current, node: t }]);
164
- }, [t]), E(
165
- e,
166
- { className: ["alea-swap", n].filter(Boolean).join(" "), "data-variant": i === "scale" ? "scale" : void 0, style: { "--alea-swap-dir": a === "up" ? 1 : -1 }, "aria-live": "polite" },
167
- r.map((u) => /* @__PURE__ */ b("span", { className: u.id === 0 && !u.out ? void 0 : u.out ? "alea-swap-out" : "alea-swap-in", "aria-hidden": u.out || void 0, onAnimationEnd: u.out ? () => s((o) => o.filter((f) => f.id !== u.id)) : void 0, children: u.node }, u.id))
169
+ s.current = e, d.current += 1, a((c) => [...c.filter((u) => !u.out).map((u) => ({ ...u, out: !0 })), { id: d.current, node: e }]);
170
+ }, [e]), $(
171
+ t,
172
+ { className: ["alea-swap", n].filter(Boolean).join(" "), "data-variant": i === "scale" ? "scale" : void 0, style: { "--alea-swap-dir": r === "up" ? 1 : -1 }, "aria-live": "polite" },
173
+ o.map((c) => /* @__PURE__ */ S("span", { className: c.id === 0 && !c.out ? void 0 : c.out ? "alea-swap-out" : "alea-swap-in", "aria-hidden": c.out || void 0, onAnimationEnd: c.out ? () => a((u) => u.filter((v) => v.id !== c.id)) : void 0, children: c.node }, c.id))
168
174
  );
169
175
  }
170
- function ge({ value: t, format: e, locale: n, className: a, live: i = !0, label: r }) {
171
- const s = new Intl.NumberFormat(n, e).format(t);
172
- return /* @__PURE__ */ V("span", { className: ["alea-roll", a].filter(Boolean).join(" "), children: [
173
- /* @__PURE__ */ b("span", { className: "alea-visually-hidden", "aria-live": i ? "polite" : void 0, children: r ? `${r} ${s}` : s }),
174
- /* @__PURE__ */ b("span", { "aria-hidden": "true", style: { display: "inline-flex" }, children: [...s].map((l, d) => /\d/.test(l) ? /* @__PURE__ */ b("span", { className: "alea-roll-digit", children: /* @__PURE__ */ b("span", { className: "alea-roll-strip", style: { "--alea-roll-n": l }, children: "0123456789".split("").map((c) => /* @__PURE__ */ b("span", { children: c }, c)) }) }, s.length - d) : /* @__PURE__ */ b("span", { children: l }, `s${s.length - d}`)) })
176
+ function ke({ value: e, format: t, locale: n, className: r, live: i = !0, label: o }) {
177
+ const a = new Intl.NumberFormat(n, t).format(e);
178
+ return /* @__PURE__ */ _("span", { className: ["alea-roll", r].filter(Boolean).join(" "), children: [
179
+ /* @__PURE__ */ S("span", { className: "alea-visually-hidden", "aria-live": i ? "polite" : void 0, children: o ? `${o} ${a}` : a }),
180
+ /* @__PURE__ */ S("span", { "aria-hidden": "true", style: { display: "inline-flex" }, children: [...a].map((s, d) => /\d/.test(s) ? /* @__PURE__ */ S("span", { className: "alea-roll-digit", children: /* @__PURE__ */ S("span", { className: "alea-roll-strip", style: { "--alea-roll-n": s }, children: "0123456789".split("").map((l) => /* @__PURE__ */ S("span", { children: l }, l)) }) }, a.length - d) : /* @__PURE__ */ S("span", { children: s }, `s${a.length - d}`)) })
175
181
  ] });
176
182
  }
177
- function ve({ children: t, className: e, as: n = "div" }) {
178
- const a = h(null), [i, r] = k(void 0);
179
- return w(() => {
180
- const s = a.current;
181
- if (!s || typeof ResizeObserver > "u") return;
182
- const l = new ResizeObserver(() => r(s.offsetHeight));
183
- return l.observe(s), () => l.disconnect();
184
- }, []), E(n, { className: ["alea-autoheight", e].filter(Boolean).join(" "), style: i != null ? { height: i } : void 0 }, /* @__PURE__ */ b("div", { ref: a, children: t }));
183
+ function Ae({ children: e, className: t, as: n = "div" }) {
184
+ const r = w(null), [i, o] = L(void 0);
185
+ return h(() => {
186
+ const a = r.current;
187
+ if (!a || typeof ResizeObserver > "u") return;
188
+ const s = new ResizeObserver(() => o(a.offsetHeight));
189
+ return s.observe(a), () => s.disconnect();
190
+ }, []), $(n, { className: ["alea-autoheight", t].filter(Boolean).join(" "), style: i != null ? { height: i } : void 0 }, /* @__PURE__ */ S("div", { ref: r, children: e }));
185
191
  }
186
- function ye({ className: t }) {
187
- const e = h(null), [n, a] = k(!1);
188
- return w(() => {
189
- var r;
190
- if (typeof CSS < "u" && ((r = CSS.supports) != null && r.call(CSS, "animation-timeline: scroll()"))) {
191
- a(!0);
192
+ function Ie({ className: e }) {
193
+ const t = w(null), [n, r] = L(!1);
194
+ return h(() => {
195
+ var o;
196
+ if (typeof CSS < "u" && ((o = CSS.supports) != null && o.call(CSS, "animation-timeline: scroll()"))) {
197
+ r(!0);
192
198
  return;
193
199
  }
194
200
  const i = () => {
195
- var l;
196
- const s = document.documentElement.scrollHeight - window.innerHeight;
197
- (l = e.current) == null || l.style.setProperty("--alea-scroll", String(s > 0 ? Math.min(1, window.scrollY / s) : 0));
201
+ var s;
202
+ const a = document.documentElement.scrollHeight - window.innerHeight;
203
+ (s = t.current) == null || s.style.setProperty("--alea-scroll", String(a > 0 ? Math.min(1, window.scrollY / a) : 0));
198
204
  };
199
205
  return i(), window.addEventListener("scroll", i, { passive: !0 }), window.addEventListener("resize", i), () => {
200
206
  window.removeEventListener("scroll", i), window.removeEventListener("resize", i);
201
207
  };
202
- }, []), /* @__PURE__ */ b("div", { ref: e, className: ["alea-scroll-progress", t].filter(Boolean).join(" "), "data-css": n || void 0, "aria-hidden": "true" });
208
+ }, []), /* @__PURE__ */ S("div", { ref: t, className: ["alea-scroll-progress", e].filter(Boolean).join(" "), "data-css": n || void 0, "aria-hidden": "true" });
203
209
  }
204
- function we({ chunks: t, streaming: e = !1, className: n, as: a = "p" }) {
205
- return E(
206
- a,
207
- { className: ["alea-stream", n].filter(Boolean).join(" "), "data-streaming": e || void 0, "aria-busy": e || void 0 },
208
- z.toArray(t.map((i, r) => /* @__PURE__ */ b("span", { className: "alea-stream-chunk", children: i }, r)))
210
+ function je({ chunks: e, streaming: t = !1, className: n, as: r = "p" }) {
211
+ return $(
212
+ r,
213
+ { className: ["alea-stream", n].filter(Boolean).join(" "), "data-streaming": t || void 0, "aria-busy": t || void 0 },
214
+ U.toArray(e.map((i, o) => /* @__PURE__ */ S("span", { className: "alea-stream-chunk", children: i }, o)))
209
215
  );
210
216
  }
211
- const M = /* @__PURE__ */ new Map(), F = (t) => {
212
- const e = t.getBoundingClientRect();
213
- return { x: e.left + window.scrollX, y: e.top + window.scrollY, w: e.width, h: e.height, radius: getComputedStyle(t).borderRadius, time: performance.now() };
217
+ const R = /* @__PURE__ */ new Map(), X = (e) => {
218
+ const t = e.getBoundingClientRect();
219
+ return { x: t.left + window.scrollX, y: t.top + window.scrollY, w: t.width, h: t.height, radius: getComputedStyle(e).borderRadius, time: performance.now() };
214
220
  };
215
- function he({ id: t, as: e = "div", duration: n, easing: a, fadeContent: i = !0, className: r, style: s, children: l, ...d }) {
216
- const c = h(null), u = D();
217
- return R(() => {
218
- const o = c.current;
219
- if (!o) return;
220
- const f = M.get(t), p = F(o);
221
- if (f && !u && performance.now() - f.time < 1500 && (f.w !== p.w || f.h !== p.h || f.x !== p.x || f.y !== p.y) && typeof o.animate == "function") {
222
- const y = n ?? (parseFloat(getComputedStyle(o).getPropertyValue("--alea-motion-duration-slow")) || 480), g = a ?? (getComputedStyle(o).getPropertyValue("--alea-motion-ease-standard").trim() || "cubic-bezier(0.2, 0, 0, 1)"), x = f.w / Math.max(1, p.w), N = f.h / Math.max(1, p.h);
223
- if (o.animate([
224
- { transformOrigin: "0 0", transform: `translate(${f.x - p.x}px, ${f.y - p.y}px) scale(${x}, ${N})`, borderRadius: f.radius },
225
- { transformOrigin: "0 0", transform: "none", borderRadius: p.radius }
226
- ], { duration: y, easing: g }), i) for (const L of Array.from(o.children)) L.animate([{ opacity: 0 }, { opacity: 0, offset: 0.35 }, { opacity: 1 }], { duration: y, easing: "ease-out" });
221
+ function Oe({ id: e, as: t = "div", duration: n, easing: r, fadeContent: i = !0, className: o, style: a, children: s, ...d }) {
222
+ const l = w(null), c = W();
223
+ return Y(() => {
224
+ const u = l.current;
225
+ if (!u) return;
226
+ const v = R.get(e), g = X(u);
227
+ if (v && !c && performance.now() - v.time < 1500 && (v.w !== g.w || v.h !== g.h || v.x !== g.x || v.y !== g.y) && typeof u.animate == "function") {
228
+ const k = n ?? (parseFloat(getComputedStyle(u).getPropertyValue("--alea-motion-duration-slow")) || 480), b = r ?? (getComputedStyle(u).getPropertyValue("--alea-motion-ease-standard").trim() || "cubic-bezier(0.2, 0, 0, 1)"), f = v.w / Math.max(1, g.w), m = v.h / Math.max(1, g.h);
229
+ if (u.animate([
230
+ { transformOrigin: "0 0", transform: `translate(${v.x - g.x}px, ${v.y - g.y}px) scale(${f}, ${m})`, borderRadius: v.radius },
231
+ { transformOrigin: "0 0", transform: "none", borderRadius: g.radius }
232
+ ], { duration: k, easing: b }), i) for (const N of Array.from(u.children)) N.animate([{ opacity: 0 }, { opacity: 0, offset: 0.35 }, { opacity: 1 }], { duration: k, easing: "ease-out" });
227
233
  }
228
- M.set(t, p);
229
- const v = () => {
230
- o.isConnected && M.set(t, F(o));
234
+ R.set(e, g);
235
+ const y = () => {
236
+ u.isConnected && R.set(e, X(u));
231
237
  };
232
- window.addEventListener("scroll", v, { passive: !0 });
233
- const m = typeof ResizeObserver < "u" ? new ResizeObserver(v) : null;
234
- return m == null || m.observe(o), () => {
235
- v(), M.set(t, { ...M.get(t) || p, time: performance.now() }), window.removeEventListener("scroll", v), m == null || m.disconnect();
238
+ window.addEventListener("scroll", y, { passive: !0 });
239
+ const p = typeof ResizeObserver < "u" ? new ResizeObserver(y) : null;
240
+ return p == null || p.observe(u), () => {
241
+ y(), R.set(e, { ...R.get(e) || g, time: performance.now() }), window.removeEventListener("scroll", y), p == null || p.disconnect();
236
242
  };
237
- }, [t]), E(e, { ...d, ref: c, className: r, style: s, "data-morph": t }, l);
243
+ }, [e]), $(t, { ...d, ref: l, className: o, style: a, "data-morph": e }, s);
238
244
  }
239
- function xe({ from: t, to: e, active: n, className: a }) {
240
- return /* @__PURE__ */ V("span", { className: ["alea-morph-icon", a].filter(Boolean).join(" "), "data-active": n || void 0, "aria-hidden": "true", children: [
241
- /* @__PURE__ */ b("span", { className: "alea-morph-icon-a", children: t }),
242
- /* @__PURE__ */ b("span", { className: "alea-morph-icon-b", children: e })
245
+ function Te({ from: e, to: t, active: n, className: r }) {
246
+ return /* @__PURE__ */ _("span", { className: ["alea-morph-icon", r].filter(Boolean).join(" "), "data-active": n || void 0, "aria-hidden": "true", children: [
247
+ /* @__PURE__ */ S("span", { className: "alea-morph-icon-a", children: e }),
248
+ /* @__PURE__ */ S("span", { className: "alea-morph-icon-b", children: t })
243
249
  ] });
244
250
  }
245
- const K = { lift: "alea-hover-lift", press: "alea-press", tint: "alea-hover-tint", glow: "alea-hover-glow", hint: "alea-hint" };
246
- function q(t, { on: e = "mount", value: n, delay: a, duration: i, once: r = !0 } = {}) {
247
- const s = h(null);
248
- w(() => {
249
- const u = s.current;
250
- if (e !== "visible" || !u) return;
251
+ const ce = { lift: "alea-hover-lift", press: "alea-press", tint: "alea-hover-tint", glow: "alea-hover-glow", hint: "alea-hint" };
252
+ function ue(e, { on: t = "mount", value: n, delay: r, duration: i, once: o = !0 } = {}) {
253
+ const a = w(null);
254
+ h(() => {
255
+ const c = a.current;
256
+ if (t !== "visible" || !c) return;
251
257
  if (typeof IntersectionObserver > "u") {
252
- u.setAttribute("data-m-in", "");
258
+ c.setAttribute("data-m-in", "");
253
259
  return;
254
260
  }
255
- const o = new IntersectionObserver((f) => {
256
- for (const p of f)
257
- p.isIntersecting ? (u.setAttribute("data-m-in", ""), r && o.disconnect()) : r || u.removeAttribute("data-m-in");
261
+ const u = new IntersectionObserver((v) => {
262
+ for (const g of v)
263
+ g.isIntersecting ? (c.setAttribute("data-m-in", ""), o && u.disconnect()) : o || c.removeAttribute("data-m-in");
258
264
  }, { rootMargin: "0px 0px -8% 0px" });
259
- return o.observe(u), () => o.disconnect();
260
- }, [e, r]);
261
- const l = h(n);
262
- w(() => {
263
- if (e !== "change" || Object.is(l.current, n)) return;
264
- l.current = n;
265
- const u = s.current;
266
- u && (u.removeAttribute("data-m-run"), u.offsetWidth, u.setAttribute("data-m-run", ""));
267
- }, [e, n]);
265
+ return u.observe(c), () => u.disconnect();
266
+ }, [t, o]);
267
+ const s = w(n);
268
+ h(() => {
269
+ if (t !== "change" || Object.is(s.current, n)) return;
270
+ s.current = n;
271
+ const c = a.current;
272
+ c && (c.removeAttribute("data-m-run"), c.offsetWidth, c.setAttribute("data-m-run", ""));
273
+ }, [t, n]);
268
274
  const d = {};
269
- if (a != null && (d["--alea-m-delay"] = `${a}ms`), i != null && (d["--alea-m-duration"] = `${i}ms`), t === "stagger") return { ref: s, "data-stagger": "", style: d };
270
- const c = K[t];
271
- return c ? { ref: s, className: c, style: d } : { ref: s, className: "alea-m", "data-m": t, "data-m-on": e, ...e === "loop" ? { "data-alea-loop": "" } : {}, style: d };
275
+ if (r != null && (d["--alea-m-delay"] = `${r}ms`), i != null && (d["--alea-m-duration"] = `${i}ms`), e === "stagger") return { ref: a, "data-stagger": "", style: d };
276
+ const l = ce[e];
277
+ return l ? { ref: a, className: l, style: d } : { ref: a, className: "alea-m", "data-m": e, "data-m-on": t, ...t === "loop" ? { "data-alea-loop": "" } : {}, style: d };
272
278
  }
273
- function be({ pattern: t, children: e, ...n }) {
274
- const a = q(t, n), i = z.only(e);
275
- if (!P(i)) return e;
276
- const r = i.props.ref, s = (o) => {
277
- a.ref.current = o, typeof r == "function" ? r(o) : r && typeof r == "object" && (r.current = o);
278
- }, { ref: l, className: d, style: c, ...u } = a;
279
- return A(i, { ...u, ref: s, className: [i.props.className, d].filter(Boolean).join(" ") || void 0, style: { ...i.props.style, ...c } });
279
+ function Pe({ pattern: e, children: t, ...n }) {
280
+ const r = ue(e, n), i = U.only(t);
281
+ if (!F(i)) return t;
282
+ const o = i.props.ref, a = (u) => {
283
+ r.ref.current = u, typeof o == "function" ? o(u) : o && typeof o == "object" && (o.current = u);
284
+ }, { ref: s, className: d, style: l, ...c } = r;
285
+ return H(i, { ...c, ref: a, className: [i.props.className, d].filter(Boolean).join(" ") || void 0, style: { ...i.props.style, ...l } });
280
286
  }
281
- function ke({ as: t = "div", strength: e = 16, scroll: n = !1, className: a, style: i, children: r, ...s }) {
282
- const l = h(null), d = D();
283
- return w(() => {
284
- var y;
285
- const c = l.current;
286
- if (!c || d || typeof window > "u") return;
287
- const u = (y = window.matchMedia) == null ? void 0 : y.call(window, "(pointer: fine)").matches, o = (g, x) => {
288
- c.style.setProperty("--alea-par-x", g.toFixed(3)), c.style.setProperty("--alea-par-y", x.toFixed(3));
289
- }, f = (g) => {
290
- const x = c.getBoundingClientRect();
291
- o(((g.clientX - x.left) / x.width - 0.5) * 2, ((g.clientY - x.top) / x.height - 0.5) * 2);
292
- }, p = () => o(0, 0);
293
- let v = 0;
294
- const m = () => {
295
- cancelAnimationFrame(v), v = requestAnimationFrame(() => {
296
- const g = c.getBoundingClientRect(), x = g.top + g.height / 2 - window.innerHeight / 2;
297
- c.style.setProperty("--alea-par-s", Math.max(-1, Math.min(1, x / window.innerHeight)).toFixed(3));
287
+ function Re({ as: e = "div", strength: t = 16, scroll: n = !1, className: r, style: i, children: o, ...a }) {
288
+ const s = w(null), d = W();
289
+ return h(() => {
290
+ var k;
291
+ const l = s.current;
292
+ if (!l || d || typeof window > "u") return;
293
+ const c = (k = window.matchMedia) == null ? void 0 : k.call(window, "(pointer: fine)").matches, u = (b, f) => {
294
+ l.style.setProperty("--alea-par-x", b.toFixed(3)), l.style.setProperty("--alea-par-y", f.toFixed(3));
295
+ }, v = (b) => {
296
+ const f = l.getBoundingClientRect();
297
+ u(((b.clientX - f.left) / f.width - 0.5) * 2, ((b.clientY - f.top) / f.height - 0.5) * 2);
298
+ }, g = () => u(0, 0);
299
+ let y = 0;
300
+ const p = () => {
301
+ cancelAnimationFrame(y), y = requestAnimationFrame(() => {
302
+ const b = l.getBoundingClientRect(), f = b.top + b.height / 2 - window.innerHeight / 2;
303
+ l.style.setProperty("--alea-par-s", Math.max(-1, Math.min(1, f / window.innerHeight)).toFixed(3));
298
304
  });
299
305
  };
300
- return u && (c.addEventListener("pointermove", f), c.addEventListener("pointerleave", p)), n && (window.addEventListener("scroll", m, { passive: !0 }), m()), () => {
301
- c.removeEventListener("pointermove", f), c.removeEventListener("pointerleave", p), window.removeEventListener("scroll", m), cancelAnimationFrame(v);
306
+ return c && (l.addEventListener("pointermove", v), l.addEventListener("pointerleave", g)), n && (window.addEventListener("scroll", p, { passive: !0 }), p()), () => {
307
+ l.removeEventListener("pointermove", v), l.removeEventListener("pointerleave", g), window.removeEventListener("scroll", p), cancelAnimationFrame(y);
302
308
  };
303
- }, [d, n]), E(t, { ...s, ref: l, className: ["alea-parallax", a].filter(Boolean).join(" "), style: { "--alea-par-strength": `${e}px`, ...i } }, r);
309
+ }, [d, n]), $(e, { ...a, ref: s, className: ["alea-parallax", r].filter(Boolean).join(" "), style: { "--alea-par-strength": `${t}px`, ...i } }, o);
304
310
  }
305
- function Ee({ as: t = "div", depth: e = 0.5, className: n, style: a, children: i, ...r }) {
306
- return E(t, { ...r, className: ["alea-parallax-layer", n].filter(Boolean).join(" "), style: { "--alea-depth": e, ...a } }, i);
311
+ function Be({ as: e = "div", depth: t = 0.5, className: n, style: r, children: i, ...o }) {
312
+ return $(e, { ...o, className: ["alea-parallax-layer", n].filter(Boolean).join(" "), style: { "--alea-depth": t, ...r } }, i);
307
313
  }
308
- function ee({ layer: t, leaving: e, entering: n, style: a, onDone: i }) {
309
- const r = h(null);
310
- return w(() => {
311
- var c;
312
- if (!e) return;
313
- const s = r.current, l = ((c = s == null ? void 0 : s.getAnimations) == null ? void 0 : c.call(s)) || [];
314
- if (!s || !l.length) {
315
- const u = window.setTimeout(() => i(t.key), 0);
316
- return () => window.clearTimeout(u);
314
+ const de = parseInt(Z, 10) >= 19 ? !0 : "";
315
+ function fe({ layer: e, leaving: t, entering: n, style: r, onDone: i }) {
316
+ const o = w(null);
317
+ return h(() => {
318
+ var l;
319
+ if (!t) return;
320
+ const a = o.current, s = ((l = a == null ? void 0 : a.getAnimations) == null ? void 0 : l.call(a)) || [];
321
+ if (!a || !s.length) {
322
+ const c = window.setTimeout(() => i(e.key), 0);
323
+ return () => window.clearTimeout(c);
317
324
  }
318
325
  let d = !0;
319
- return Promise.all(l.map((u) => u.finished.catch(() => {
326
+ return Promise.all(s.map((c) => c.finished.catch(() => {
320
327
  }))).then(() => {
321
- d && i(t.key);
328
+ d && i(e.key);
322
329
  }), () => {
323
330
  d = !1;
324
331
  };
325
- }, [e]), E("div", { ref: r, className: "alea-page-layer", "data-leaving": e || void 0, "data-entering": n || void 0, style: a, inert: e || void 0, "aria-hidden": e || void 0 }, t.node);
332
+ }, [t]), $("div", { ref: o, className: "alea-page-layer", "data-leaving": t || void 0, "data-entering": n || void 0, style: r, inert: t ? de : void 0, "aria-hidden": t || void 0 }, e.node);
326
333
  }
327
- function Ne({ routeKey: t, pattern: e = "fade", duration: n, exitDuration: a, as: i = "div", className: r, style: s, children: l, ...d }) {
328
- const [c, u] = k({ key: t, leaving: [], changed: !1 }), o = h(l);
329
- c.key !== t ? u({ key: t, leaving: [...c.leaving.filter((m) => m.key !== t), { key: c.key, node: o.current }], changed: !0 }) : o.current = l;
330
- const f = j((m) => u((y) => ({ ...y, leaving: y.leaving.filter((g) => g.key !== m) })), []), p = I({ enter: e, exit: e, duration: n, exitDuration: a }), v = [...c.leaving.map((m) => ({ ...m, leaving: !0 })), { key: t, node: l, leaving: !1 }];
331
- return E(
334
+ function Ce({ routeKey: e, pattern: t = "fade", duration: n, exitDuration: r, as: i = "div", className: o, style: a, children: s, ...d }) {
335
+ const [l, c] = L({ key: e, leaving: [], changed: !1 }), u = w(s);
336
+ l.key !== e ? c({ key: e, leaving: [...l.leaving.filter((p) => p.key !== e), { key: l.key, node: u.current }], changed: !0 }) : u.current = s;
337
+ const v = C((p) => c((k) => ({ ...k, leaving: k.leaving.filter((b) => b.key !== p) })), []), g = V({ enter: t, exit: t, duration: n, exitDuration: r }), y = [...l.leaving.map((p) => ({ ...p, leaving: !0 })), { key: e, node: s, leaving: !1 }];
338
+ return $(
332
339
  i,
333
- { ...d, className: ["alea-page-transition", r].filter(Boolean).join(" "), style: s },
334
- v.map((m) => E(ee, { key: m.key, layer: m, leaving: m.leaving, entering: !m.leaving && c.changed, style: p, onDone: f }))
340
+ { ...d, className: ["alea-page-transition", o].filter(Boolean).join(" "), style: a },
341
+ y.map((p) => $(fe, { key: p.key, layer: p, leaving: p.leaving, entering: !p.leaving && l.changed, style: g, onDone: v }))
335
342
  );
336
343
  }
337
- function te(t, e, n = !0) {
338
- const a = t ?? [], [i, r] = k(() => a.map((o, f) => ({ item: o, key: e(o), leaving: !1, entering: !1, enterIndex: f }))), s = h(t), l = h(/* @__PURE__ */ new Map());
339
- s.current !== t && (s.current = t, r((o) => {
340
- const f = a.map(e), p = new Set(f), v = new Set(o.map((g) => g.key));
341
- let m = 0;
342
- const y = a.map((g, x) => {
343
- var B, T, C;
344
- const N = f[x], L = !v.has(N) || ((B = o.find(($) => $.key === N)) == null ? void 0 : B.leaving) === !0;
345
- return { item: g, key: N, leaving: !1, entering: n && (L || !!((T = o.find(($) => $.key === N)) != null && T.entering)), enterIndex: L ? m++ : ((C = o.find(($) => $.key === N)) == null ? void 0 : C.enterIndex) ?? 0 };
344
+ const G = "alea-row-leave", pe = 1e3;
345
+ function me(e, t, n = !0) {
346
+ const r = e ?? [], { enter: i, leave: o } = K(n, r.length), a = q(n), [s, d] = L(() => r.map((f, m) => ({ item: f, key: t(f), leaving: !1, entering: !1, enterIndex: m }))), l = w(e), c = w(a), u = w(/* @__PURE__ */ new Map()), v = !ee(c.current, a);
347
+ (l.current !== e || v) && (l.current = e, c.current = a, d((f) => {
348
+ const m = r.map(t);
349
+ if (v) return r.map((x, E) => ({ item: x, key: m[E], leaving: !1, entering: !1, enterIndex: E }));
350
+ const N = new Set(m), A = new Map(f.map((x) => [x.key, x]));
351
+ let z = 0;
352
+ const I = r.map((x, E) => {
353
+ const j = m[E], M = A.get(j), O = !M || M.leaving;
354
+ return { item: x, key: j, leaving: !1, entering: i && (O || !!(M != null && M.entering)), enterIndex: O ? z++ : (M == null ? void 0 : M.enterIndex) ?? 0 };
346
355
  });
347
- return n && o.forEach((g, x) => {
348
- p.has(g.key) || y.splice(Math.min(x, y.length), 0, { ...g, leaving: !0, entering: !1 });
349
- }), y;
356
+ return o && f.forEach((x, E) => {
357
+ N.has(x.key) || I.splice(Math.min(E, I.length), 0, { ...x, leaving: !0, entering: !1 });
358
+ }), I;
350
359
  }));
351
- const d = j((o) => r((f) => f.filter((p) => !(p.key === o && p.leaving))), []), c = i.filter((o) => o.leaving).map((o) => String(o.key)).join("|");
352
- R(() => {
353
- for (const o of i) if (o.leaving) {
354
- const f = l.current.get(o.key);
355
- f && f.style.setProperty("--alea-row-h", `${f.offsetHeight}px`);
360
+ const g = C((f) => d((m) => m.filter((N) => !(N.key === f && N.leaving))), []), y = s.filter((f) => f.leaving).map((f) => String(f.key)).join("|");
361
+ Y(() => {
362
+ for (const f of s) if (f.leaving) {
363
+ const m = u.current.get(f.key);
364
+ m && m.style.setProperty("--alea-row-h", `${m.offsetHeight}px`);
356
365
  }
357
- }, [c]), w(() => {
358
- var f;
359
- const o = [];
360
- for (const p of i) {
361
- if (!p.leaving) continue;
362
- const v = l.current.get(p.key), m = ((f = v == null ? void 0 : v.getAnimations) == null ? void 0 : f.call(v)) || [];
363
- if (!v || !m.length) {
364
- const g = window.setTimeout(() => d(p.key), 0);
365
- o.push(() => window.clearTimeout(g));
366
- continue;
367
- }
368
- let y = !0;
369
- Promise.all(m.map((g) => g.finished.catch(() => {
370
- }))).then(() => {
371
- y && d(p.key);
372
- }), o.push(() => {
373
- y = !1;
374
- });
375
- }
376
- return () => o.forEach((p) => p());
377
- }, [c]);
378
- const u = j((o) => (f) => {
379
- f ? l.current.set(o, f) : l.current.delete(o);
366
+ }, [y]);
367
+ const p = w(/* @__PURE__ */ new Map()), k = (f) => {
368
+ let m = !0, N = 0, A;
369
+ const z = performance.now(), I = () => {
370
+ m && (m = !1, window.clearTimeout(A), p.current.delete(f), g(f));
371
+ }, x = () => {
372
+ var M;
373
+ if (!m) return;
374
+ const E = u.current.get(f);
375
+ if (!E || E.closest('[data-alea-motion="off"]')) return I();
376
+ const j = (((M = E.getAnimations) == null ? void 0 : M.call(E)) ?? []).filter((O) => O.playState !== "finished");
377
+ if (j.length) {
378
+ const O = Math.max(0, ...j.map((T) => {
379
+ var B;
380
+ return Number((B = T.effect) == null ? void 0 : B.getComputedTiming().endTime) || 0;
381
+ }));
382
+ A = window.setTimeout(I, O + 100), Promise.allSettled(j.map((T) => T.finished)).then((T) => {
383
+ window.clearTimeout(A), T.some((B) => B.status === "fulfilled") ? I() : x();
384
+ });
385
+ } else !E.classList.contains(G) && performance.now() - z < pe ? A = window.setTimeout(x, 16) : ++N > 4 ? I() : A = window.setTimeout(x, 16);
386
+ };
387
+ return x(), () => {
388
+ m = !1, window.clearTimeout(A);
389
+ };
390
+ };
391
+ h(() => {
392
+ const f = new Set(s.filter((m) => m.leaving).map((m) => m.key));
393
+ p.current.forEach((m, N) => {
394
+ f.has(N) || (m(), p.current.delete(N));
395
+ }), f.forEach((m) => {
396
+ p.current.has(m) || p.current.set(m, k(m));
397
+ });
398
+ }, [y]), h(() => () => {
399
+ p.current.forEach((f) => f()), p.current.clear();
400
+ }, []);
401
+ const b = C((f) => (m) => {
402
+ m ? u.current.set(f, m) : u.current.delete(f);
380
403
  }, []);
381
- return { entries: i, ref: u };
404
+ return { entries: s, ref: b };
382
405
  }
383
- function $e({ items: t, getKey: e, children: n, animate: a = !0 }) {
384
- const { entries: i, ref: r } = te(t, e, a);
385
- return E(H, null, i.map((s) => {
386
- const l = n(s.item, { leaving: s.leaving, entering: s.entering });
387
- if (!P(l)) return null;
388
- const d = [l.props.className, s.leaving ? "alea-row-leave" : s.entering ? "alea-row-enter" : ""].filter(Boolean).join(" "), c = l.props.ref, u = (o) => {
389
- r(s.key)(o), typeof c == "function" ? c(o) : c && typeof c == "object" && (c.current = o);
406
+ function Fe({ items: e, getKey: t, children: n, animate: r = !0 }) {
407
+ const { entries: i, ref: o } = me(e, t, r);
408
+ return $(J, null, i.map((a) => {
409
+ const s = n(a.item, { leaving: a.leaving, entering: a.entering });
410
+ if (!F(s)) return null;
411
+ const d = [s.props.className, a.leaving ? G : a.entering ? "alea-row-enter" : ""].filter(Boolean).join(" "), l = s.props.ref, c = (u) => {
412
+ o(a.key)(u), typeof l == "function" ? l(u) : l && typeof l == "object" && (l.current = u);
390
413
  };
391
- return A(l, { key: s.key, className: d, ref: u, "data-leaving": s.leaving || void 0, style: s.entering ? { ...l.props.style, "--alea-i": Math.min(s.enterIndex, 11) } : l.props.style });
414
+ return H(s, { key: a.key, className: d, ref: c, "data-leaving": a.leaving || void 0, style: a.entering ? { ...s.props.style, "--alea-i": Math.min(a.enterIndex, 11) } : s.props.style });
392
415
  }));
393
416
  }
394
417
  export {
395
- ve as AutoHeight,
396
- W as MOTION_SELECTORS,
397
- he as Morph,
398
- xe as MorphIcon,
399
- be as Motion,
400
- ge as NumberRoll,
401
- Ne as PageTransition,
402
- ke as Parallax,
403
- Ee as ParallaxLayer,
404
- pe as Presence,
405
- $e as PresenceList,
406
- fe as Reveal,
407
- ye as ScrollProgress,
408
- we as StreamingText,
409
- me as TextSwap,
410
- ie as motionAttributes,
411
- se as motionComponentCss,
412
- I as motionStyle,
413
- ae as motionVariables,
414
- Z as pauseWhenOffscreen,
415
- de as startViewTransition,
416
- Q as useInView,
417
- q as useMotion,
418
- le as useOffscreenPause,
419
- te as usePresenceList,
420
- D as useReducedMotion,
421
- ue as useRipple,
422
- ce as useScrollDirection,
423
- oe as withMotionStyle
418
+ Ae as AutoHeight,
419
+ re as MOTION_SELECTORS,
420
+ Oe as Morph,
421
+ Te as MorphIcon,
422
+ Pe as Motion,
423
+ ke as NumberRoll,
424
+ Ce as PageTransition,
425
+ Re as Parallax,
426
+ Be as ParallaxLayer,
427
+ Le as Presence,
428
+ Fe as PresenceList,
429
+ Me as Reveal,
430
+ Ie as ScrollProgress,
431
+ je as StreamingText,
432
+ $e as TextSwap,
433
+ ye as motionAttributes,
434
+ xe as motionComponentCss,
435
+ V as motionStyle,
436
+ he as motionVariables,
437
+ le as pauseWhenOffscreen,
438
+ K as resolveRowMotion,
439
+ Ne as startViewTransition,
440
+ se as useInView,
441
+ ue as useMotion,
442
+ be as useOffscreenPause,
443
+ me as usePresenceList,
444
+ W as useReducedMotion,
445
+ Se as useRipple,
446
+ Ee as useScrollDirection,
447
+ we as withMotionStyle
424
448
  };
package/dist/react.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { type CSSProperties, type ElementType, type PointerEvent as ReactPointerEvent, type ReactElement, type ReactNode } from 'react';
2
+ import { type RowMotion } from './row-motion.js';
3
+ export { resolveRowMotion, type RowMotion, type RowMotionOptions } from './row-motion.js';
2
4
  /** The enter/exit presets. Each maps to the keyframes alea-m-<preset>-in and -out in motion.css. */
3
5
  export type MotionPreset = 'fade' | 'scale' | 'pop' | 'rise' | 'drop' | 'slide-up' | 'slide-down' | 'slide-left' | 'slide-right' | 'blur' | 'zoom' | 'flip' | 'morph' | 'none';
4
6
  /** The easing tokens, or any CSS easing. */
@@ -104,7 +106,7 @@ export declare function TextSwap({ children, as, className, direction, variant }
104
106
  }): ReactElement<any, string | import("react").JSXElementConstructor<any>>;
105
107
  /** A number whose digits roll to the new value (the roll pattern). Screen readers get the formatted value once. */
106
108
  export declare function NumberRoll({ value, format, locale, className, live, label }: {
107
- value: number; /** Intl.NumberFormat options: currency, percent, compact. */
109
+ value: number | string; /** Intl.NumberFormat options: currency, percent, compact. */
108
110
  format?: Intl.NumberFormatOptions; /** A BCP 47 locale. Default the browser's. */
109
111
  locale?: string;
110
112
  className?: string; /** Announce each change to screen readers (default true). Set false when the number sits inside a heading or another live region, so it does not change that name and speak on every update. */
@@ -185,7 +187,7 @@ export declare function useMotion<T extends HTMLElement = HTMLElement>(pattern:
185
187
  'data-alea-loop'?: string | undefined;
186
188
  ref: import("react").RefObject<T | null>;
187
189
  className: string;
188
- 'data-m': "fade" | "scale" | "pop" | "rise" | "drop" | "slide-up" | "slide-down" | "slide-left" | "slide-right" | "blur" | "zoom" | "flip" | "badge" | "nudge" | "pulse" | "draw" | "lift" | "press" | "tint" | "glow" | "hint";
190
+ 'data-m': "pop" | "fade" | "scale" | "rise" | "drop" | "slide-up" | "slide-down" | "slide-left" | "slide-right" | "blur" | "zoom" | "flip" | "badge" | "nudge" | "pulse" | "draw" | "lift" | "press" | "tint" | "glow" | "hint";
189
191
  'data-m-on': MotionTrigger;
190
192
  'data-stagger'?: undefined;
191
193
  };
@@ -232,8 +234,8 @@ export interface PresenceEntry<T> {
232
234
  /** Position among the items added in the same update (the stagger), 0 for the first. */
233
235
  enterIndex: number;
234
236
  }
235
- /** The items of a list with the removed ones kept mounted until their exit animation ends. Hand `entries` to your list, put `ref(key)` on each row, and style `leaving` and `entering` rows (the class names alea-row-enter and alea-row-leave do it). */
236
- export declare function usePresenceList<T>(items: readonly T[] | undefined, getKey: (item: T) => string | number, enabled?: boolean): {
237
+ /** The items of a list with the removed ones kept mounted until their exit animation ends. Hand `entries` to your list, put `ref(key)` on each row, and style `leaving` and `entering` rows (the class names alea-row-enter and alea-row-leave do it). `motion` is true (default), false, or a policy: see RowMotionOptions. */
238
+ export declare function usePresenceList<T>(items: readonly T[] | undefined, getKey: (item: T) => string | number, motion?: RowMotion): {
237
239
  entries: PresenceEntry<T>[];
238
240
  ref: (key: string | number) => (node: HTMLElement | null) => void;
239
241
  };
@@ -251,7 +253,6 @@ export declare function PresenceList<T>({ items, getKey, children, animate }: {
251
253
  style?: CSSProperties;
252
254
  ref?: unknown;
253
255
  }>;
254
- /** false renders the items as they are, with no entrance and no exit. Default true. */
255
- animate?: boolean;
256
+ /** false renders the items as they are, with no entrance and no exit. An object chooses what animates and when the list starts over (max, resetOn, enter, leave). Default true. */
257
+ animate?: RowMotion;
256
258
  }): import("react").FunctionComponentElement<import("react").FragmentProps>;
257
- export {};
@@ -0,0 +1,22 @@
1
+ /** Which changes of a list are news worth animating. */
2
+ export interface RowMotionOptions {
3
+ /** Above this many rows nothing animates: a long list stays still. No limit by default. */
4
+ max?: number;
5
+ /** Values that decide which rows exist without being an add or a remove (a search text, a filter, a page). When any of them changes the list starts over: the rows now in it are not animated in, and the rows that left do not play their exit. */
6
+ resetOn?: readonly unknown[];
7
+ /** Rows added to the list rise in. Default true. */
8
+ enter?: boolean;
9
+ /** Rows removed from the list dissolve before they go. Default true. */
10
+ leave?: boolean;
11
+ }
12
+ /** `true` animates every add and remove, `false` nothing; an object says which ones and when to forget the rows it had. */
13
+ export type RowMotion = boolean | RowMotionOptions;
14
+ /** What a list animates right now, given how many rows it holds. */
15
+ export declare function resolveRowMotion(motion: RowMotion | undefined, count: number): {
16
+ enter: boolean;
17
+ leave: boolean;
18
+ };
19
+ /** The `resetOn` values of a policy (none for a boolean). */
20
+ export declare const resetValues: (motion: RowMotion | undefined) => readonly unknown[];
21
+ /** Same values in the same order, compared one by one with Object.is: a new array with equal contents is not a change. */
22
+ export declare const sameValues: (a: readonly unknown[], b: readonly unknown[]) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alea-design/motion",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Alea Motion: a motion system for interfaces. Tokens, named patterns, microinteractions and effects in CSS for any stack, plus small React helpers. Reduced motion built in.",
5
5
  "keywords": [
6
6
  "motion",
package/src/motion.css CHANGED
@@ -224,12 +224,12 @@
224
224
  /* ------------------------------------------------------------------ reduced motion: fade, don't move; stop decorative loops.
225
225
  Applies with the OS setting (unless data-alea-reduced="never"), or always with data-alea-reduced="always" or data-alea-motion="reduced". */
226
226
  @media (prefers-reduced-motion: reduce) {
227
- :root:not([data-alea-reduced='never']), :root:not([data-alea-reduced='never']) :is(.alea-root, [data-theme], [data-alea-motion]) {
227
+ :root:not([data-alea-reduced='never']), :root:not([data-alea-reduced='never']) :is(.alea-root, [data-theme], [data-alea-motion]):not([data-alea-reduced='never']) {
228
228
  --alea-motion-distance-sm: 0px; --alea-motion-distance-md: 0px; --alea-motion-distance-lg: 0px; --alea-motion-rotate: 0deg;
229
229
  --alea-motion-scale-from: 1; --alea-motion-scale-press: 1; --alea-motion-lift: 0px; --alea-motion-stagger: 0ms; --alea-motion-slide: 0%; --alea-slide-distance: 0px;
230
230
  --alea-motion-blur-sm: 0px; --alea-motion-blur-md: 0px; --alea-motion-blur-lg: 0px;
231
231
  --alea-motion-ease-emphasized: var(--alea-motion-ease-out); --alea-motion-ease-spring: var(--alea-motion-ease-out); --alea-motion-spring: var(--alea-motion-ease-out);
232
- --alea-motion-duration-slow: var(--alea-motion-duration-base); --alea-motion-duration-slower: var(--alea-motion-duration-base);
232
+ --alea-motion-duration-instant: var(--alea-motion-reduced-duration, 1ms); --alea-motion-duration-fast: var(--alea-motion-reduced-duration, 1ms); --alea-motion-duration-base: var(--alea-motion-reduced-duration, 1ms); --alea-motion-duration-slow: var(--alea-motion-reduced-duration, 1ms); --alea-motion-duration-slower: var(--alea-motion-reduced-duration, 1ms);
233
233
  }
234
234
  :root:not([data-alea-reduced='never']) :is(.alea-field[data-invalid] :is(.alea-input-wrap, .alea-select-trigger, .alea-textarea, .alea-date-wrap), [data-alea-loop], .alea-image[data-state='loading'], .alea-orb, .alea-orbs *) { animation: none !important; }
235
235
  /* decorative loops stop (a pseudo-element cannot sit inside :is(), so these are listed on their own) */
@@ -245,13 +245,18 @@
245
245
  :root:not([data-alea-reduced='never']) :is(.alea-chart-line, .alea-success-check path) { stroke-dashoffset: 0; }
246
246
  :root:not([data-alea-reduced='never']) .alea-ripple { display: none; }
247
247
  :root:not([data-alea-reduced='never'])[data-motion='morph'], :root:not([data-alea-reduced='never']) [data-motion='morph'] { --alea-enter: alea-m-fade-in; --alea-exit: alea-m-fade-out; }
248
+ /* the sweep: an animation or transition that is left (a duration set inline, a literal one, a keyframe nobody listed) is cut to a blink, a loop plays once and scrolling jumps. Spinners and
249
+ indeterminate bars keep turning because they say "working"; the rules above already slowed them */
250
+ :root:not([data-alea-reduced='never']) :not([data-alea-reduced='never'], [data-alea-reduced='never'] *):not(:is(.alea-spinner svg, .alea-dot-loader i, .alea-progress-circle svg[data-indeterminate], .alea-progress-fill[data-indeterminate], .alea-agentrun-status svg, .alea-tool-status svg), :is(.alea-spinner svg, .alea-dot-loader i, .alea-progress-circle svg[data-indeterminate], .alea-progress-fill[data-indeterminate], .alea-agentrun-status svg, .alea-tool-status svg) *),
251
+ :root:not([data-alea-reduced='never']) :not([data-alea-reduced='never'], [data-alea-reduced='never'] *):not(:is(.alea-spinner svg, .alea-dot-loader i, .alea-progress-circle svg[data-indeterminate], .alea-progress-fill[data-indeterminate], .alea-agentrun-status svg, .alea-tool-status svg), :is(.alea-spinner svg, .alea-dot-loader i, .alea-progress-circle svg[data-indeterminate], .alea-progress-fill[data-indeterminate], .alea-agentrun-status svg, .alea-tool-status svg) *)::before,
252
+ :root:not([data-alea-reduced='never']) :not([data-alea-reduced='never'], [data-alea-reduced='never'] *):not(:is(.alea-spinner svg, .alea-dot-loader i, .alea-progress-circle svg[data-indeterminate], .alea-progress-fill[data-indeterminate], .alea-agentrun-status svg, .alea-tool-status svg), :is(.alea-spinner svg, .alea-dot-loader i, .alea-progress-circle svg[data-indeterminate], .alea-progress-fill[data-indeterminate], .alea-agentrun-status svg, .alea-tool-status svg) *)::after { animation-duration: var(--alea-motion-reduced-duration, 1ms) !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: var(--alea-motion-reduced-duration, 1ms) !important; scroll-behavior: auto !important; }
248
253
  }
249
254
  :is([data-alea-motion='reduced'], [data-alea-reduced='always']), :is([data-alea-motion='reduced'], [data-alea-reduced='always']) :is(.alea-root, [data-theme]) {
250
255
  --alea-motion-distance-sm: 0px; --alea-motion-distance-md: 0px; --alea-motion-distance-lg: 0px; --alea-motion-rotate: 0deg;
251
256
  --alea-motion-scale-from: 1; --alea-motion-scale-press: 1; --alea-motion-lift: 0px; --alea-motion-stagger: 0ms; --alea-motion-slide: 0%; --alea-slide-distance: 0px;
252
257
  --alea-motion-blur-sm: 0px; --alea-motion-blur-md: 0px; --alea-motion-blur-lg: 0px;
253
258
  --alea-motion-ease-emphasized: var(--alea-motion-ease-out); --alea-motion-ease-spring: var(--alea-motion-ease-out); --alea-motion-spring: var(--alea-motion-ease-out);
254
- --alea-motion-duration-slow: var(--alea-motion-duration-base); --alea-motion-duration-slower: var(--alea-motion-duration-base);
259
+ --alea-motion-duration-instant: var(--alea-motion-reduced-duration, 1ms); --alea-motion-duration-fast: var(--alea-motion-reduced-duration, 1ms); --alea-motion-duration-base: var(--alea-motion-reduced-duration, 1ms); --alea-motion-duration-slow: var(--alea-motion-reduced-duration, 1ms); --alea-motion-duration-slower: var(--alea-motion-reduced-duration, 1ms);
255
260
  }
256
261
  :is([data-alea-motion='reduced'], [data-alea-reduced='always']) :is(.alea-field[data-invalid] :is(.alea-input-wrap, .alea-select-trigger, .alea-textarea, .alea-date-wrap), [data-alea-loop], .alea-image[data-state='loading'], .alea-orb, .alea-orbs *) { animation: none !important; }
257
262
  :is([data-alea-motion='reduced'], [data-alea-reduced='always']) :is(.alea-avatar-status[data-pulse], .alea-status-dot[data-pulse], .alea-indicator[data-processing])::before,
@@ -265,6 +270,11 @@
265
270
  :is([data-alea-motion='reduced'], [data-alea-reduced='always']) :is(.alea-chart-line, .alea-success-check path) { stroke-dashoffset: 0; }
266
271
  :is([data-alea-motion='reduced'], [data-alea-reduced='always']) .alea-ripple { display: none; }
267
272
  :is([data-alea-motion='reduced'], [data-alea-reduced='always'])[data-motion='morph'], :is([data-alea-motion='reduced'], [data-alea-reduced='always']) [data-motion='morph'] { --alea-enter: alea-m-fade-in; --alea-exit: alea-m-fade-out; }
273
+ /* the sweep: an animation or transition that is left (a duration set inline, a literal one, a keyframe nobody listed) is cut to a blink, a loop plays once and scrolling jumps. Spinners and
274
+ indeterminate bars keep turning because they say "working"; the rules above already slowed them */
275
+ :is([data-alea-motion='reduced'], [data-alea-reduced='always']) :not(:is(.alea-spinner svg, .alea-dot-loader i, .alea-progress-circle svg[data-indeterminate], .alea-progress-fill[data-indeterminate], .alea-agentrun-status svg, .alea-tool-status svg), :is(.alea-spinner svg, .alea-dot-loader i, .alea-progress-circle svg[data-indeterminate], .alea-progress-fill[data-indeterminate], .alea-agentrun-status svg, .alea-tool-status svg) *),
276
+ :is([data-alea-motion='reduced'], [data-alea-reduced='always']) :not(:is(.alea-spinner svg, .alea-dot-loader i, .alea-progress-circle svg[data-indeterminate], .alea-progress-fill[data-indeterminate], .alea-agentrun-status svg, .alea-tool-status svg), :is(.alea-spinner svg, .alea-dot-loader i, .alea-progress-circle svg[data-indeterminate], .alea-progress-fill[data-indeterminate], .alea-agentrun-status svg, .alea-tool-status svg) *)::before,
277
+ :is([data-alea-motion='reduced'], [data-alea-reduced='always']) :not(:is(.alea-spinner svg, .alea-dot-loader i, .alea-progress-circle svg[data-indeterminate], .alea-progress-fill[data-indeterminate], .alea-agentrun-status svg, .alea-tool-status svg), :is(.alea-spinner svg, .alea-dot-loader i, .alea-progress-circle svg[data-indeterminate], .alea-progress-fill[data-indeterminate], .alea-agentrun-status svg, .alea-tool-status svg) *)::after { animation-duration: var(--alea-motion-reduced-duration, 1ms) !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: var(--alea-motion-reduced-duration, 1ms) !important; scroll-behavior: auto !important; }
268
278
 
269
279
  /* ------------------------------------------------------------------ the patterns, applied to the rest of the kit */
270
280
  /* rise: content that appears as a state of its own */