@alea-design/motion 0.7.0 → 0.7.2

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,20 +1,20 @@
1
1
  "use client";
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";
2
+ import { jsx as M, jsxs as C } from "react/jsx-runtime";
3
+ import { useRef as w, useState as L, useEffect as h, createElement as $, Children as U, isValidElement as V, cloneElement as Y, useCallback as F, Fragment as J, useLayoutEffect as Q, version as Z } from "react";
4
4
  function K(e, t) {
5
5
  if (!e) return { enter: !1, leave: !1 };
6
6
  if (e === !0) return { enter: !0, leave: !0 };
7
7
  const n = e.max === void 0 || t <= e.max;
8
8
  return { enter: n && e.enter !== !1, leave: n && e.leave !== !1 };
9
9
  }
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) {
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])), X = 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, H = (e, t) => e === "none" ? "none" : `alea-m-${e}-${t}`;
11
+ function z(e) {
12
12
  if (e === void 0) return;
13
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;
14
+ return t.enter ? (n["--alea-enter"] = H(t.enter, "in"), n["--alea-exit"] = H(t.exit || t.enter, "out")) : t.exit && (n["--alea-exit"] = H(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;
15
15
  }
16
16
  function we(e, t) {
17
- const n = V(t);
17
+ const n = z(t);
18
18
  return n ? typeof e == "function" ? ((r) => ({ ...n, ...e(r) })) : { ...n, ...e } : e;
19
19
  }
20
20
  const re = {
@@ -29,13 +29,13 @@ const re = {
29
29
  hovercard: ".alea-hovercard",
30
30
  datepicker: ".alea-cal-popover",
31
31
  tour: ".alea-tour-card"
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 };
32
+ }, ae = { instant: 120, fast: 200, base: 320, slow: 480, slower: 720 }, oe = { sm: 8, md: 12, lg: 24 }, ie = { sm: 4, md: 8, lg: 16 };
33
33
  function he(e = {}) {
34
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`;
35
+ if (n != null && n !== 1) for (const [i, a] of Object.entries(ae)) t[`--alea-motion-duration-${i}`] = `${Math.round(a * n)}ms`;
36
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`;
37
+ for (const [i, a] of Object.entries(oe)) t[`--alea-motion-distance-${i}`] = `${+(a * r).toFixed(2)}px`;
38
+ for (const [i, a] of Object.entries(ie)) t[`--alea-motion-blur-${i}`] = `${+(a * r).toFixed(2)}px`;
39
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`;
40
40
  }
41
41
  return t;
@@ -46,21 +46,21 @@ function ye(e = {}) {
46
46
  }
47
47
  function xe(e = {}, t = ":root") {
48
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(" ")} }`;
49
+ const i = z(r), a = re[n];
50
+ return !i || !a ? "" : `${t} ${a} { ${Object.entries(i).map(([o, s]) => `${o}: ${s};`).join(" ")} }`;
51
51
  }).filter(Boolean).join(`
52
52
  `);
53
53
  }
54
54
  function W() {
55
55
  const [e, t] = L(!1);
56
56
  return h(() => {
57
- var o, a;
57
+ var a, o;
58
58
  if (typeof window > "u") return;
59
- const n = (o = window.matchMedia) == null ? void 0 : o.call(window, "(prefers-reduced-motion: reduce)"), r = () => {
59
+ const n = (a = window.matchMedia) == null ? void 0 : a.call(window, "(prefers-reduced-motion: reduce)"), r = () => {
60
60
  const s = document.documentElement, d = s.getAttribute("data-alea-reduced"), l = s.getAttribute("data-alea-motion");
61
61
  t(l === "off" || l === "reduced" || d === "always" || d !== "never" && !!(n != null && n.matches));
62
62
  };
63
- r(), (a = n == null ? void 0 : n.addEventListener) == null || a.call(n, "change", r);
63
+ r(), (o = n == null ? void 0 : n.addEventListener) == null || o.call(n, "change", r);
64
64
  const i = new MutationObserver(r);
65
65
  return i.observe(document.documentElement, { attributes: !0, attributeFilter: ["data-alea-motion", "data-alea-reduced"] }), () => {
66
66
  var s;
@@ -69,18 +69,18 @@ function W() {
69
69
  }, []), e;
70
70
  }
71
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);
72
+ const { once: t = !0, margin: n = "0px 0px -10% 0px", threshold: r = 0.1 } = e, i = w(null), [a, o] = L(!1);
73
73
  return h(() => {
74
74
  const s = i.current;
75
75
  if (!s || typeof IntersectionObserver > "u") {
76
- a(!0);
76
+ o(!0);
77
77
  return;
78
78
  }
79
79
  const d = new IntersectionObserver(([l]) => {
80
- l.isIntersecting ? (a(!0), t && d.disconnect()) : t || a(!1);
80
+ l.isIntersecting ? (o(!0), t && d.disconnect()) : t || o(!1);
81
81
  }, { rootMargin: n, threshold: r });
82
82
  return d.observe(s), () => d.disconnect();
83
- }, [t, n, r]), [i, o];
83
+ }, [t, n, r]), [i, a];
84
84
  }
85
85
  let P = null;
86
86
  function le(e) {
@@ -100,50 +100,50 @@ function Ee(e = 8) {
100
100
  return h(() => {
101
101
  let r = window.scrollY;
102
102
  const i = () => {
103
- const o = window.scrollY;
104
- Math.abs(o - r) < e || (n(o > r && o > 64 ? "down" : "up"), r = o);
103
+ const a = window.scrollY;
104
+ Math.abs(a - r) < e || (n(a > r && a > 64 ? "down" : "up"), r = a);
105
105
  };
106
106
  return window.addEventListener("scroll", i, { passive: !0 }), () => window.removeEventListener("scroll", i);
107
107
  }, [e]), t;
108
108
  }
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);
109
+ function Ne() {
110
+ return { onPointerDown: F((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, a = document.createElement("span");
112
+ a.className = "alea-ripple", a.setAttribute("aria-hidden", "true"), a.style.setProperty("--alea-ripple-x", `${t.clientX - r.left}px`), a.style.setProperty("--alea-ripple-y", `${t.clientY - r.top}px`), a.style.setProperty("--alea-ripple-size", `${i}px`), n.appendChild(a), a.addEventListener("animationend", () => a.remove()), window.setTimeout(() => a.remove(), 1200);
113
113
  }, []), className: "alea-ripple-host" };
114
114
  }
115
- function Ne(e) {
115
+ function Se(e) {
116
116
  const t = typeof document < "u" ? document : null;
117
117
  t != null && t.startViewTransition ? t.startViewTransition(e) : e();
118
118
  }
119
- function Me({ as: e = "div", motion: t = "rise", delay: n, once: r = !0, stagger: i, className: o, style: a, children: s, ...d }) {
119
+ function Me({ as: e = "div", motion: t = "rise", delay: n, once: r = !0, stagger: i, className: a, style: o, children: s, ...d }) {
120
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);
121
+ X(() => {
122
+ const m = l.current;
123
+ m && m.getBoundingClientRect().top > window.innerHeight && v(!0);
124
124
  }, []);
125
125
  const g = typeof t == "string" ? { enter: t } : t;
126
126
  return $(e, {
127
127
  ...d,
128
128
  ref: l,
129
- className: o,
129
+ className: a,
130
130
  "data-reveal": u && !c ? "pending" : u ? "in" : void 0,
131
131
  "data-stagger": i ? "reveal" : void 0,
132
- style: { ...i ? {} : V({ ...g, delay: n ?? g.delay }), ...a }
132
+ style: { ...i ? {} : z({ ...g, delay: n ?? g.delay }), ...o }
133
133
  }, s);
134
134
  }
135
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);
136
+ const [r, i] = L(e), [a, o] = L(!1), s = w(null);
137
137
  return h(() => {
138
138
  var u;
139
139
  if (e) {
140
- i(!0), a(!1);
140
+ i(!0), o(!1);
141
141
  return;
142
142
  }
143
143
  if (!r) return;
144
- a(!0);
144
+ o(!0);
145
145
  const d = s.current, l = () => {
146
- i(!1), a(!1);
146
+ i(!1), o(!1);
147
147
  }, c = ((u = d == null ? void 0 : d.getAnimations) == null ? void 0 : u.call(d)) || [];
148
148
  if (!d || !c.length) {
149
149
  const v = window.setTimeout(l, 0);
@@ -153,106 +153,112 @@ function Le({ show: e, exitClassName: t = "alea-dissolve-out", children: n }) {
153
153
  }))).then(l);
154
154
  }, [e]), h(() => {
155
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(" ") });
156
+ a && s.current && !((l = (d = s.current).getAnimations) != null && l.call(d).length) && (i(!1), o(!1));
157
+ }, [a]), !r || !V(n) ? null : Y(n, { ref: s, className: [n.props.className, a && t].filter(Boolean).join(" ") });
158
158
  }
159
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) => {
160
+ const [a, o] = L([{ id: 0, node: e }]), s = w(e), d = w(0), l = (c) => {
161
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) ?? "") : "";
162
+ return typeof c == "string" || typeof c == "number" ? String(c) : V(c) ? String(c.key ?? "") + JSON.stringify(((u = c.props) == null ? void 0 : u.children) ?? "") : "";
163
163
  };
164
164
  return h(() => {
165
165
  if (l(e) === l(s.current)) {
166
- a((c) => c.map((u) => u.out ? u : { ...u, node: e }));
166
+ o((c) => c.map((u) => u.out ? u : { ...u, node: e }));
167
167
  return;
168
168
  }
169
- s.current = e, d.current += 1, a((c) => [...c.filter((u) => !u.out).map((u) => ({ ...u, out: !0 })), { id: d.current, node: e }]);
169
+ s.current = e, d.current += 1, o((c) => [...c.filter((u) => !u.out).map((u) => ({ ...u, out: !0 })), { id: d.current, node: e }]);
170
170
  }, [e]), $(
171
171
  t,
172
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))
173
+ a.map((c) => /* @__PURE__ */ M("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 ? () => o((u) => u.filter((v) => v.id !== c.id)) : void 0, children: c.node }, c.id))
174
174
  );
175
175
  }
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}`)) })
176
+ function ke({ value: e, format: t, locale: n, className: r, live: i = !0, label: a }) {
177
+ const o = new Intl.NumberFormat(n, t).format(e);
178
+ return /* @__PURE__ */ C("span", { className: ["alea-roll", r].filter(Boolean).join(" "), children: [
179
+ /* @__PURE__ */ C("span", { className: "alea-roll-text", "aria-live": i ? "polite" : void 0, children: [
180
+ a && /* @__PURE__ */ C("span", { className: "alea-roll-label", children: [
181
+ a,
182
+ " "
183
+ ] }),
184
+ o
185
+ ] }),
186
+ /* @__PURE__ */ M("span", { className: "alea-roll-digits", "aria-hidden": "true", children: [...o].map((s, d) => /\d/.test(s) ? /* @__PURE__ */ M("span", { className: "alea-roll-digit", children: /* @__PURE__ */ M("span", { className: "alea-roll-strip", style: { "--alea-roll-n": s }, children: "0123456789".split("").map((l) => /* @__PURE__ */ M("span", { children: l }, l)) }) }, o.length - d) : /* @__PURE__ */ M("span", { children: s }, `s${o.length - d}`)) })
181
187
  ] });
182
188
  }
183
189
  function Ae({ children: e, className: t, as: n = "div" }) {
184
- const r = w(null), [i, o] = L(void 0);
190
+ const r = w(null), [i, a] = L(void 0);
185
191
  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 }));
192
+ const o = r.current;
193
+ if (!o || typeof ResizeObserver > "u") return;
194
+ const s = new ResizeObserver(() => a(o.offsetHeight));
195
+ return s.observe(o), () => s.disconnect();
196
+ }, []), $(n, { className: ["alea-autoheight", t].filter(Boolean).join(" "), style: i != null ? { height: i } : void 0 }, /* @__PURE__ */ M("div", { ref: r, children: e }));
191
197
  }
192
198
  function Ie({ className: e }) {
193
199
  const t = w(null), [n, r] = L(!1);
194
200
  return h(() => {
195
- var o;
196
- if (typeof CSS < "u" && ((o = CSS.supports) != null && o.call(CSS, "animation-timeline: scroll()"))) {
201
+ var a;
202
+ if (typeof CSS < "u" && ((a = CSS.supports) != null && a.call(CSS, "animation-timeline: scroll()"))) {
197
203
  r(!0);
198
204
  return;
199
205
  }
200
206
  const i = () => {
201
207
  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));
208
+ const o = document.documentElement.scrollHeight - window.innerHeight;
209
+ (s = t.current) == null || s.style.setProperty("--alea-scroll", String(o > 0 ? Math.min(1, window.scrollY / o) : 0));
204
210
  };
205
211
  return i(), window.addEventListener("scroll", i, { passive: !0 }), window.addEventListener("resize", i), () => {
206
212
  window.removeEventListener("scroll", i), window.removeEventListener("resize", i);
207
213
  };
208
- }, []), /* @__PURE__ */ S("div", { ref: t, className: ["alea-scroll-progress", e].filter(Boolean).join(" "), "data-css": n || void 0, "aria-hidden": "true" });
214
+ }, []), /* @__PURE__ */ M("div", { ref: t, className: ["alea-scroll-progress", e].filter(Boolean).join(" "), "data-css": n || void 0, "aria-hidden": "true" });
209
215
  }
210
216
  function je({ chunks: e, streaming: t = !1, className: n, as: r = "p" }) {
211
217
  return $(
212
218
  r,
213
219
  { 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)))
220
+ U.toArray(e.map((i, a) => /* @__PURE__ */ M("span", { className: "alea-stream-chunk", children: i }, a)))
215
221
  );
216
222
  }
217
- const R = /* @__PURE__ */ new Map(), X = (e) => {
223
+ const R = /* @__PURE__ */ new Map(), _ = (e) => {
218
224
  const t = e.getBoundingClientRect();
219
225
  return { x: t.left + window.scrollX, y: t.top + window.scrollY, w: t.width, h: t.height, radius: getComputedStyle(e).borderRadius, time: performance.now() };
220
226
  };
221
- function Oe({ id: e, as: t = "div", duration: n, easing: r, fadeContent: i = !0, className: o, style: a, children: s, ...d }) {
227
+ function Oe({ id: e, as: t = "div", duration: n, easing: r, fadeContent: i = !0, className: a, style: o, children: s, ...d }) {
222
228
  const l = w(null), c = W();
223
- return Y(() => {
229
+ return X(() => {
224
230
  const u = l.current;
225
231
  if (!u) return;
226
- const v = R.get(e), g = X(u);
232
+ const v = R.get(e), g = _(u);
227
233
  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);
234
+ 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), p = v.h / Math.max(1, g.h);
229
235
  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 },
236
+ { transformOrigin: "0 0", transform: `translate(${v.x - g.x}px, ${v.y - g.y}px) scale(${f}, ${p})`, borderRadius: v.radius },
231
237
  { transformOrigin: "0 0", transform: "none", borderRadius: g.radius }
232
238
  ], { 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" });
233
239
  }
234
240
  R.set(e, g);
235
241
  const y = () => {
236
- u.isConnected && R.set(e, X(u));
242
+ u.isConnected && R.set(e, _(u));
237
243
  };
238
244
  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();
245
+ const m = typeof ResizeObserver < "u" ? new ResizeObserver(y) : null;
246
+ return m == null || m.observe(u), () => {
247
+ y(), R.set(e, { ...R.get(e) || g, time: performance.now() }), window.removeEventListener("scroll", y), m == null || m.disconnect();
242
248
  };
243
- }, [e]), $(t, { ...d, ref: l, className: o, style: a, "data-morph": e }, s);
249
+ }, [e]), $(t, { ...d, ref: l, className: a, style: o, "data-morph": e }, s);
244
250
  }
245
251
  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 })
252
+ return /* @__PURE__ */ C("span", { className: ["alea-morph-icon", r].filter(Boolean).join(" "), "data-active": n || void 0, "aria-hidden": "true", children: [
253
+ /* @__PURE__ */ M("span", { className: "alea-morph-icon-a", children: e }),
254
+ /* @__PURE__ */ M("span", { className: "alea-morph-icon-b", children: t })
249
255
  ] });
250
256
  }
251
257
  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);
258
+ function ue(e, { on: t = "mount", value: n, delay: r, duration: i, once: a = !0 } = {}) {
259
+ const o = w(null);
254
260
  h(() => {
255
- const c = a.current;
261
+ const c = o.current;
256
262
  if (t !== "visible" || !c) return;
257
263
  if (typeof IntersectionObserver > "u") {
258
264
  c.setAttribute("data-m-in", "");
@@ -260,31 +266,31 @@ function ue(e, { on: t = "mount", value: n, delay: r, duration: i, once: o = !0
260
266
  }
261
267
  const u = new IntersectionObserver((v) => {
262
268
  for (const g of v)
263
- g.isIntersecting ? (c.setAttribute("data-m-in", ""), o && u.disconnect()) : o || c.removeAttribute("data-m-in");
269
+ g.isIntersecting ? (c.setAttribute("data-m-in", ""), a && u.disconnect()) : a || c.removeAttribute("data-m-in");
264
270
  }, { rootMargin: "0px 0px -8% 0px" });
265
271
  return u.observe(c), () => u.disconnect();
266
- }, [t, o]);
272
+ }, [t, a]);
267
273
  const s = w(n);
268
274
  h(() => {
269
275
  if (t !== "change" || Object.is(s.current, n)) return;
270
276
  s.current = n;
271
- const c = a.current;
277
+ const c = o.current;
272
278
  c && (c.removeAttribute("data-m-run"), c.offsetWidth, c.setAttribute("data-m-run", ""));
273
279
  }, [t, n]);
274
280
  const 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 };
281
+ if (r != null && (d["--alea-m-delay"] = `${r}ms`), i != null && (d["--alea-m-duration"] = `${i}ms`), e === "stagger") return { ref: o, "data-stagger": "", style: d };
276
282
  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 };
283
+ return l ? { ref: o, className: l, style: d } : { ref: o, className: "alea-m", "data-m": e, "data-m-on": t, ...t === "loop" ? { "data-alea-loop": "" } : {}, style: d };
278
284
  }
279
285
  function Pe({ pattern: e, children: t, ...n }) {
280
286
  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);
287
+ if (!V(i)) return t;
288
+ const a = i.props.ref, o = (u) => {
289
+ r.ref.current = u, typeof a == "function" ? a(u) : a && typeof a == "object" && (a.current = u);
284
290
  }, { 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 } });
291
+ return Y(i, { ...c, ref: o, className: [i.props.className, d].filter(Boolean).join(" ") || void 0, style: { ...i.props.style, ...l } });
286
292
  }
287
- function Re({ as: e = "div", strength: t = 16, scroll: n = !1, className: r, style: i, children: o, ...a }) {
293
+ function Re({ as: e = "div", strength: t = 16, scroll: n = !1, className: r, style: i, children: a, ...o }) {
288
294
  const s = w(null), d = W();
289
295
  return h(() => {
290
296
  var k;
@@ -297,28 +303,28 @@ function Re({ as: e = "div", strength: t = 16, scroll: n = !1, className: r, sty
297
303
  u(((b.clientX - f.left) / f.width - 0.5) * 2, ((b.clientY - f.top) / f.height - 0.5) * 2);
298
304
  }, g = () => u(0, 0);
299
305
  let y = 0;
300
- const p = () => {
306
+ const m = () => {
301
307
  cancelAnimationFrame(y), y = requestAnimationFrame(() => {
302
308
  const b = l.getBoundingClientRect(), f = b.top + b.height / 2 - window.innerHeight / 2;
303
309
  l.style.setProperty("--alea-par-s", Math.max(-1, Math.min(1, f / window.innerHeight)).toFixed(3));
304
310
  });
305
311
  };
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);
312
+ return c && (l.addEventListener("pointermove", v), l.addEventListener("pointerleave", g)), n && (window.addEventListener("scroll", m, { passive: !0 }), m()), () => {
313
+ l.removeEventListener("pointermove", v), l.removeEventListener("pointerleave", g), window.removeEventListener("scroll", m), cancelAnimationFrame(y);
308
314
  };
309
- }, [d, n]), $(e, { ...a, ref: s, className: ["alea-parallax", r].filter(Boolean).join(" "), style: { "--alea-par-strength": `${t}px`, ...i } }, o);
315
+ }, [d, n]), $(e, { ...o, ref: s, className: ["alea-parallax", r].filter(Boolean).join(" "), style: { "--alea-par-strength": `${t}px`, ...i } }, a);
310
316
  }
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);
317
+ function Be({ as: e = "div", depth: t = 0.5, className: n, style: r, children: i, ...a }) {
318
+ return $(e, { ...a, className: ["alea-parallax-layer", n].filter(Boolean).join(" "), style: { "--alea-depth": t, ...r } }, i);
313
319
  }
314
320
  const de = parseInt(Z, 10) >= 19 ? !0 : "";
315
321
  function fe({ layer: e, leaving: t, entering: n, style: r, onDone: i }) {
316
- const o = w(null);
322
+ const a = w(null);
317
323
  return h(() => {
318
324
  var l;
319
325
  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) {
326
+ const o = a.current, s = ((l = o == null ? void 0 : o.getAnimations) == null ? void 0 : l.call(o)) || [];
327
+ if (!o || !s.length) {
322
328
  const c = window.setTimeout(() => i(e.key), 0);
323
329
  return () => window.clearTimeout(c);
324
330
  }
@@ -329,51 +335,51 @@ function fe({ layer: e, leaving: t, entering: n, style: r, onDone: i }) {
329
335
  }), () => {
330
336
  d = !1;
331
337
  };
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);
338
+ }, [t]), $("div", { ref: a, 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);
333
339
  }
334
- function Ce({ routeKey: e, pattern: t = "fade", duration: n, exitDuration: r, as: i = "div", className: o, style: a, children: s, ...d }) {
340
+ function Ce({ routeKey: e, pattern: t = "fade", duration: n, exitDuration: r, as: i = "div", className: a, style: o, children: s, ...d }) {
335
341
  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 }];
342
+ l.key !== e ? c({ key: e, leaving: [...l.leaving.filter((m) => m.key !== e), { key: l.key, node: u.current }], changed: !0 }) : u.current = s;
343
+ const v = F((m) => c((k) => ({ ...k, leaving: k.leaving.filter((b) => b.key !== m) })), []), g = z({ enter: t, exit: t, duration: n, exitDuration: r }), y = [...l.leaving.map((m) => ({ ...m, leaving: !0 })), { key: e, node: s, leaving: !1 }];
338
344
  return $(
339
345
  i,
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 }))
346
+ { ...d, className: ["alea-page-transition", a].filter(Boolean).join(" "), style: o },
347
+ y.map((m) => $(fe, { key: m.key, layer: m, leaving: m.leaving, entering: !m.leaving && l.changed, style: g, onDone: v }))
342
348
  );
343
349
  }
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;
350
+ const G = "alea-row-leave", me = 1e3;
351
+ function pe(e, t, n = !0) {
352
+ const r = e ?? [], { enter: i, leave: a } = K(n, r.length), o = q(n), [s, d] = L(() => r.map((f, p) => ({ item: f, key: t(f), leaving: !1, entering: !1, enterIndex: p }))), l = w(e), c = w(o), u = w(/* @__PURE__ */ new Map()), v = !ee(c.current, o);
353
+ (l.current !== e || v) && (l.current = e, c.current = o, d((f) => {
354
+ const p = r.map(t);
355
+ if (v) return r.map((x, E) => ({ item: x, key: p[E], leaving: !1, entering: !1, enterIndex: E }));
356
+ const N = new Set(p), A = new Map(f.map((x) => [x.key, x]));
357
+ let D = 0;
352
358
  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 };
359
+ const j = p[E], S = A.get(j), O = !S || S.leaving;
360
+ return { item: x, key: j, leaving: !1, entering: i && (O || !!(S != null && S.entering)), enterIndex: O ? D++ : (S == null ? void 0 : S.enterIndex) ?? 0 };
355
361
  });
356
- return o && f.forEach((x, E) => {
362
+ return a && f.forEach((x, E) => {
357
363
  N.has(x.key) || I.splice(Math.min(E, I.length), 0, { ...x, leaving: !0, entering: !1 });
358
364
  }), I;
359
365
  }));
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(() => {
366
+ const g = F((f) => d((p) => p.filter((N) => !(N.key === f && N.leaving))), []), y = s.filter((f) => f.leaving).map((f) => String(f.key)).join("|");
367
+ X(() => {
362
368
  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`);
369
+ const p = u.current.get(f.key);
370
+ p && p.style.setProperty("--alea-row-h", `${p.offsetHeight}px`);
365
371
  }
366
372
  }, [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));
373
+ const m = w(/* @__PURE__ */ new Map()), k = (f) => {
374
+ let p = !0, N = 0, A;
375
+ const D = performance.now(), I = () => {
376
+ p && (p = !1, window.clearTimeout(A), m.current.delete(f), g(f));
371
377
  }, x = () => {
372
- var M;
373
- if (!m) return;
378
+ var S;
379
+ if (!p) return;
374
380
  const E = u.current.get(f);
375
381
  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");
382
+ const j = (((S = E.getAnimations) == null ? void 0 : S.call(E)) ?? []).filter((O) => O.playState !== "finished");
377
383
  if (j.length) {
378
384
  const O = Math.max(0, ...j.map((T) => {
379
385
  var B;
@@ -382,36 +388,36 @@ function me(e, t, n = !0) {
382
388
  A = window.setTimeout(I, O + 100), Promise.allSettled(j.map((T) => T.finished)).then((T) => {
383
389
  window.clearTimeout(A), T.some((B) => B.status === "fulfilled") ? I() : x();
384
390
  });
385
- } else !E.classList.contains(G) && performance.now() - z < pe ? A = window.setTimeout(x, 16) : ++N > 4 ? I() : A = window.setTimeout(x, 16);
391
+ } else !E.classList.contains(G) && performance.now() - D < me ? A = window.setTimeout(x, 16) : ++N > 4 ? I() : A = window.setTimeout(x, 16);
386
392
  };
387
393
  return x(), () => {
388
- m = !1, window.clearTimeout(A);
394
+ p = !1, window.clearTimeout(A);
389
395
  };
390
396
  };
391
397
  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));
398
+ const f = new Set(s.filter((p) => p.leaving).map((p) => p.key));
399
+ m.current.forEach((p, N) => {
400
+ f.has(N) || (p(), m.current.delete(N));
401
+ }), f.forEach((p) => {
402
+ m.current.has(p) || m.current.set(p, k(p));
397
403
  });
398
404
  }, [y]), h(() => () => {
399
- p.current.forEach((f) => f()), p.current.clear();
405
+ m.current.forEach((f) => f()), m.current.clear();
400
406
  }, []);
401
- const b = C((f) => (m) => {
402
- m ? u.current.set(f, m) : u.current.delete(f);
407
+ const b = F((f) => (p) => {
408
+ p ? u.current.set(f, p) : u.current.delete(f);
403
409
  }, []);
404
410
  return { entries: s, ref: b };
405
411
  }
406
412
  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);
413
+ const { entries: i, ref: a } = pe(e, t, r);
414
+ return $(J, null, i.map((o) => {
415
+ const s = n(o.item, { leaving: o.leaving, entering: o.entering });
416
+ if (!V(s)) return null;
417
+ const d = [s.props.className, o.leaving ? G : o.entering ? "alea-row-enter" : ""].filter(Boolean).join(" "), l = s.props.ref, c = (u) => {
418
+ a(o.key)(u), typeof l == "function" ? l(u) : l && typeof l == "object" && (l.current = u);
413
419
  };
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 });
420
+ return Y(s, { key: o.key, className: d, ref: c, "data-leaving": o.leaving || void 0, style: o.entering ? { ...s.props.style, "--alea-i": Math.min(o.enterIndex, 11) } : s.props.style });
415
421
  }));
416
422
  }
417
423
  export {
@@ -432,17 +438,17 @@ export {
432
438
  $e as TextSwap,
433
439
  ye as motionAttributes,
434
440
  xe as motionComponentCss,
435
- V as motionStyle,
441
+ z as motionStyle,
436
442
  he as motionVariables,
437
443
  le as pauseWhenOffscreen,
438
444
  K as resolveRowMotion,
439
- Ne as startViewTransition,
445
+ Se as startViewTransition,
440
446
  se as useInView,
441
447
  ue as useMotion,
442
448
  be as useOffscreenPause,
443
- me as usePresenceList,
449
+ pe as usePresenceList,
444
450
  W as useReducedMotion,
445
- Se as useRipple,
451
+ Ne as useRipple,
446
452
  Ee as useScrollDirection,
447
453
  we as withMotionStyle
448
454
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alea-design/motion",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
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/patterns.css CHANGED
@@ -28,7 +28,11 @@
28
28
  @keyframes alea-swap-out { to { opacity: 0.01; filter: blur(var(--alea-motion-blur-sm)); transform: translateY(calc(var(--alea-motion-distance-sm) * var(--alea-swap-dir, 1) * -1)); } }
29
29
 
30
30
  /* ------------------------------------------------------------------ roll */
31
- .alea-roll { display: inline-flex; font-variant-numeric: tabular-nums; white-space: nowrap; }
31
+ .alea-roll { position: relative; display: inline-flex; font-variant-numeric: tabular-nums; white-space: nowrap; }
32
+ .alea-roll-digits { display: inline-flex; user-select: none; } /* the strips hold 0 to 9 in every column: never part of a selection */
33
+ /* the figure itself sits invisible over the digits, so selecting the number highlights it and copying gives "1,204", not "0123456789" */
34
+ .alea-roll-text { position: absolute; inset: 0; color: transparent; forced-color-adjust: none; }
35
+ .alea-roll-label { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); user-select: none; } /* spoken before the figure, never copied */
32
36
  .alea-roll-digit { display: inline-block; height: 1lh; overflow: hidden; }
33
37
  .alea-roll-strip { display: flex; flex-direction: column; transform: translateY(calc(var(--alea-roll-n, 0) * -1lh)); transition: transform var(--alea-motion-duration-slow) var(--alea-motion-ease-emphasized); }
34
38
  .alea-roll-strip > span { height: 1lh; }