@ssgoi/core
Version:
Core animation engine for SSGOI - Native app-like page transitions with spring physics
73 lines (72 loc) • 1.57 kB
JavaScript
function p(t) {
return ("tick" in t || "css" in t) && !("items" in t);
}
function u(t) {
return "items" in t;
}
function f(t) {
return "css" in t && typeof t.css == "function";
}
function y(t) {
return "tick" in t && typeof t.tick == "function";
}
async function h(t) {
const e = await t;
return u(e) ? {
prepare: e.prepare,
wait: e.wait,
onReady: e.onReady,
onStart: e.onStart,
onEnd: e.onEnd,
items: e.items,
schedule: e.schedule
} : {
prepare: e.prepare,
wait: e.wait,
onReady: e.onReady,
onStart: e.onStart,
onEnd: e.onEnd,
items: [
{
physics: e.physics,
tick: e.tick,
css: e.css
}
],
schedule: "parallel"
};
}
function k(t, e) {
const a = t.schedule ?? "parallel", r = t.items.map(
(i) => {
let n;
switch (a) {
case "parallel":
n = 0;
break;
case "sequential":
n = 1;
break;
case "stagger":
n = Math.max(0, Math.min(1, i.offset ?? 0));
break;
default:
n = 0;
}
const { css: s, offset: m, ...c } = i, l = s ? typeof s == "function" ? e ? { element: e, style: s } : void 0 : { element: s.element, style: s.style } : void 0;
return { ...c, css: l, normalizedOffset: n };
}
), { schedule: d, ...o } = t;
return {
...o,
items: r
};
}
export {
f as isCssAnimation,
u as isMultiAnimation,
p as isSingleAnimation,
y as isTickAnimation,
k as normalizeSchedule,
h as normalizeToMultiAnimation
};