m3-svelte
Version:
M3 Svelte implements the Material 3 design system in Svelte. See the [website](https://ktibow.github.io/m3-svelte/) for demos and usage instructions.
79 lines (78 loc) • 1.76 kB
JavaScript
// TODO: update for Expressive
const createBezierLUT = (points, pointCount = 100) => {
const lut = [];
for (let t = 0; t < 1; t += 1 / pointCount) {
const a = (1 - t) * (1 - t) * (1 - t);
const b = (1 - t) * (1 - t) * t;
const c = (1 - t) * t * t;
const d = t * t * t;
const x = a * points[0][0] + 3 * b * points[1][0] + 3 * c * points[2][0] + d * points[3][0];
const y = a * points[0][1] + 3 * b * points[1][1] + 3 * c * points[2][1] + d * points[3][1];
lut.push([x, y]);
}
return lut;
};
const createEase = (lutOptions) => {
let lut;
return (t) => {
if (!lut)
lut = lutOptions.map((args) => createBezierLUT(args)).flat();
const closestPoint = lut.find((p) => p[0] >= t);
const closestY = closestPoint ? closestPoint[1] : 1;
return closestY;
};
};
export const easeEmphasized = createEase([
[
[ ],
[ ],
[ ],
[ ],
],
[
[ ],
[ ],
[ ],
[ ],
],
]);
export const easeEmphasizedDecel = createEase([
[
[ ],
[ ],
[ ],
[ ],
],
]);
export const easeEmphasizedAccel = createEase([
[
[ ],
[ ],
[ ],
[ ],
],
]);
export const easeStandard = createEase([
[
[ ],
[ ],
[ ],
[ ],
],
]);
export const easeStandardDecel = createEase([
[
[ ],
[ ],
[ ],
[ ],
],
]);
export const easeStandardAccel = createEase([
[
[ ],
[ ],
[ ],
[ ],
],
]);