♻️ remove csso dependency

do a custom css optimization instead
This commit is contained in:
platane
2022-11-03 08:25:35 +01:00
committed by Platane
parent f83b9ab0c3
commit b40f17a02e
10 changed files with 654 additions and 611 deletions

View File

@@ -1,7 +1,8 @@
import { getSnakeLength, snakeToCells } from "@snk/types/snake";
import type { Snake } from "@snk/types/snake";
import type { Point } from "@snk/types/point";
import { h } from "./utils";
import { h } from "./xml-utils";
import { createAnimation } from "./css-utils";
export type Options = {
colorSnake: string;
@@ -9,8 +10,6 @@ export type Options = {
sizeDot: number;
};
const percent = (x: number) => (x * 100).toFixed(2);
const lerp = (k: number, a: number, b: number) => (1 - k) * a + k * b;
export const createSnake = (
@@ -55,8 +54,8 @@ export const createSnake = (
const styles = [
`.s{
shape-rendering:geometricPrecision;
fill:var(--cs);
shape-rendering: geometricPrecision;
fill: var(--cs);
animation: none linear ${duration}ms infinite
}`,
@@ -64,16 +63,17 @@ export const createSnake = (
const id = `s${i}`;
const animationName = id;
return [
`@keyframes ${animationName} {` +
removeInterpolatedPositions(
positions.map((tr, i, { length }) => ({ ...tr, t: i / length }))
)
.map((p) => `${percent(p.t)}%{${transform(p)}}`)
.join("") +
"}",
const keyframes = removeInterpolatedPositions(
positions.map((tr, i, { length }) => ({ ...tr, t: i / length }))
).map(({ t, ...p }) => ({ t, style: transform(p) }));
`.s.${id}{${transform(positions[0])};animation-name: ${animationName}}`,
return [
createAnimation(animationName, keyframes),
`.s.${id}{
${transform(positions[0])};
animation-name: ${animationName}
}`,
];
}),
].flat();