⬆️ update prettier
This commit is contained in:
4
bun.lock
4
bun.lock
@@ -5,7 +5,7 @@
|
||||
"name": "snk",
|
||||
"devDependencies": {
|
||||
"@types/bun": "1.2.2",
|
||||
"prettier": "2.8.8",
|
||||
"prettier": "3.5.1",
|
||||
"typescript": "5.7.3",
|
||||
},
|
||||
},
|
||||
@@ -1001,7 +1001,7 @@
|
||||
|
||||
"prepend-http": ["prepend-http@1.0.4", "", {}, "sha512-PhmXi5XmoyKw1Un4E+opM2KcsJInDvKyuOumcjjw3waw86ZNjHwVUOOWLc4bCzLdcKNaWBH9e99sbWzDQsVaYg=="],
|
||||
|
||||
"prettier": ["prettier@2.8.8", "", { "bin": { "prettier": "bin-prettier.js" } }, "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q=="],
|
||||
"prettier": ["prettier@3.5.1", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-hPpFQvHwL3Qv5AdRvBFMhnKo4tYxp0ReXiPn2bxkiohEX6mBeBwEpBSQTkD458RaaDKQMYSp4hX4UtfUTA5wDw=="],
|
||||
|
||||
"pretty-error": ["pretty-error@4.0.0", "", { "dependencies": { "lodash": "^4.17.20", "renderkid": "^3.0.0" } }, "sha512-AoJ5YMAcXKYxKhuJGdcvse+Voc6v1RgnsR3nWcYU7q4t6z0Q6T86sv5Zq8VIRbOWWFpvdGE83LtdSMNd+6Y0xw=="],
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"repository": "github:platane/snk",
|
||||
"devDependencies": {
|
||||
"@types/bun": "1.2.2",
|
||||
"prettier": "2.8.8",
|
||||
"prettier": "3.5.1",
|
||||
"typescript": "5.7.3"
|
||||
},
|
||||
"workspaces": [
|
||||
|
||||
@@ -41,5 +41,5 @@ it(
|
||||
fs.writeFileSync(outputs[1]!.filename, results[1]!);
|
||||
fs.writeFileSync(outputs[2]!.filename, results[2]!);
|
||||
}),
|
||||
{ timeout: 2 * 60 * 1000 }
|
||||
{ timeout: 2 * 60 * 1000 },
|
||||
);
|
||||
|
||||
@@ -3,42 +3,42 @@ import { it, expect } from "bun:test";
|
||||
|
||||
it("should parse options as json", () => {
|
||||
expect(
|
||||
parseEntry(`/out.svg {"color_snake":"yellow"}`)?.drawOptions
|
||||
parseEntry(`/out.svg {"color_snake":"yellow"}`)?.drawOptions,
|
||||
).toHaveProperty("colorSnake", "yellow");
|
||||
|
||||
expect(
|
||||
parseEntry(`/out.svg?{"color_snake":"yellow"}`)?.drawOptions
|
||||
parseEntry(`/out.svg?{"color_snake":"yellow"}`)?.drawOptions,
|
||||
).toHaveProperty("colorSnake", "yellow");
|
||||
|
||||
expect(
|
||||
parseEntry(`/out.svg?{"color_dots":["#000","#111","#222","#333","#444"]}`)
|
||||
?.drawOptions.colorDots
|
||||
?.drawOptions.colorDots,
|
||||
).toEqual(["#000", "#111", "#222", "#333", "#444"]);
|
||||
});
|
||||
|
||||
it("should parse options as searchparams", () => {
|
||||
expect(parseEntry(`/out.svg?color_snake=yellow`)?.drawOptions).toHaveProperty(
|
||||
"colorSnake",
|
||||
"yellow"
|
||||
"yellow",
|
||||
);
|
||||
|
||||
expect(
|
||||
parseEntry(`/out.svg?color_dots=#000,#111,#222,#333,#444`)?.drawOptions
|
||||
.colorDots
|
||||
.colorDots,
|
||||
).toEqual(["#000", "#111", "#222", "#333", "#444"]);
|
||||
});
|
||||
|
||||
it("should parse filename", () => {
|
||||
expect(parseEntry(`/a/b/c.svg?{"color_snake":"yellow"}`)).toHaveProperty(
|
||||
"filename",
|
||||
"/a/b/c.svg"
|
||||
"/a/b/c.svg",
|
||||
);
|
||||
expect(
|
||||
parseEntry(`/a/b/out.svg?.gif.svg?{"color_snake":"yellow"}`)
|
||||
parseEntry(`/a/b/out.svg?.gif.svg?{"color_snake":"yellow"}`),
|
||||
).toHaveProperty("filename", "/a/b/out.svg?.gif.svg");
|
||||
|
||||
expect(
|
||||
parseEntry(`/a/b/{[-1].svg?.gif.svg?{"color_snake":"yellow"}`)
|
||||
parseEntry(`/a/b/{[-1].svg?.gif.svg?{"color_snake":"yellow"}`),
|
||||
).toHaveProperty("filename", "/a/b/{[-1].svg?.gif.svg");
|
||||
});
|
||||
|
||||
@@ -57,5 +57,5 @@ it("should parse filename", () => {
|
||||
].forEach((entry) =>
|
||||
it(`should parse ${entry}`, () => {
|
||||
expect(parseEntry(entry)).toMatchSnapshot();
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -13,7 +13,7 @@ export const generateContributionSnake = async (
|
||||
drawOptions: DrawOptions;
|
||||
animationOptions: AnimationOptions;
|
||||
} | null)[],
|
||||
options: { githubToken: string }
|
||||
options: { githubToken: string },
|
||||
) => {
|
||||
console.log("🎣 fetching github user contribution");
|
||||
const cells = await getGithubUserContribution(userName, options);
|
||||
@@ -43,10 +43,10 @@ export const generateContributionSnake = async (
|
||||
cells,
|
||||
chain,
|
||||
drawOptions,
|
||||
animationOptions
|
||||
animationOptions,
|
||||
);
|
||||
}
|
||||
}
|
||||
})
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@ import { parseOutputsOption } from "./outputsOptions";
|
||||
core.getMultilineInput("outputs") ?? [
|
||||
core.getInput("gif_out_path"),
|
||||
core.getInput("svg_out_path"),
|
||||
]
|
||||
],
|
||||
);
|
||||
const githubToken =
|
||||
process.env.GITHUB_TOKEN ?? core.getInput("github_token");
|
||||
|
||||
@@ -76,7 +76,7 @@ export const createCanvas = ({
|
||||
snake0: Snake,
|
||||
snake1: Snake,
|
||||
stack: Color[],
|
||||
k: number
|
||||
k: number,
|
||||
) => {
|
||||
ctx.clearRect(0, 0, 9999, 9999);
|
||||
drawLerpWorld(ctx, grid, null, snake0, snake1, stack, k, drawOptions);
|
||||
|
||||
@@ -26,7 +26,7 @@ const tunnels = ones.map(({ x, y }) => ({
|
||||
x,
|
||||
y,
|
||||
3 as Color,
|
||||
getSnakeLength(snake)
|
||||
getSnakeLength(snake),
|
||||
),
|
||||
}));
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ const { canvas, ctx, draw, highlightCell } = createCanvas(grid);
|
||||
canvas.style.pointerEvents = "auto";
|
||||
|
||||
const target = createSnakeFromCells(
|
||||
snakeToCells(snake).map((p) => ({ ...p, x: p.x - 1 }))
|
||||
snakeToCells(snake).map((p) => ({ ...p, x: p.x - 1 })),
|
||||
);
|
||||
|
||||
let chain = [snake, ...getPathToPose(snake, target)!];
|
||||
|
||||
@@ -253,7 +253,7 @@ const createViewer = ({
|
||||
: "") +
|
||||
`<a href="${svgLink.href}" download="github-user-contribution.svg">` +
|
||||
svgString +
|
||||
"<a/>"
|
||||
"<a/>",
|
||||
);
|
||||
e.preventDefault();
|
||||
});
|
||||
@@ -277,7 +277,7 @@ const createViewer = ({
|
||||
|
||||
const onSubmit = async (userName: string) => {
|
||||
const res = await fetch(
|
||||
process.env.GITHUB_USER_CONTRIBUTION_API_ENDPOINT + userName
|
||||
process.env.GITHUB_USER_CONTRIBUTION_API_ENDPOINT + userName,
|
||||
);
|
||||
const cells = (await res.json()) as Res;
|
||||
|
||||
@@ -294,8 +294,8 @@ const worker = new Worker(
|
||||
new URL(
|
||||
"./demo.interactive.worker.ts",
|
||||
// @ts-ignore
|
||||
import.meta.url
|
||||
)
|
||||
import.meta.url,
|
||||
),
|
||||
);
|
||||
|
||||
const { getChain } = createRpcClient<WorkerAPI>(worker);
|
||||
|
||||
@@ -25,7 +25,7 @@ const onChange = () => {
|
||||
|
||||
const url = new URL(
|
||||
config.demo + ".html?" + search,
|
||||
window.location.href
|
||||
window.location.href,
|
||||
).toString();
|
||||
|
||||
window.location.href = url;
|
||||
|
||||
@@ -15,7 +15,7 @@ const stepSpringOne = (
|
||||
maxVelocity = Infinity,
|
||||
}: { tension: number; friction: number; maxVelocity?: number },
|
||||
target: number,
|
||||
dt = 1 / 60
|
||||
dt = 1 / 60,
|
||||
) => {
|
||||
const a = -tension * (s.x - target) - friction * s.v;
|
||||
|
||||
@@ -31,13 +31,13 @@ const stepSpringOne = (
|
||||
export const isStable = (
|
||||
s: { x: number; v: number },
|
||||
target: number,
|
||||
dt = 1 / 60
|
||||
dt = 1 / 60,
|
||||
) => Math.abs(s.x - target) < epsilon && Math.abs(s.v * dt) < epsilon;
|
||||
|
||||
export const isStableAndBound = (
|
||||
s: { x: number; v: number },
|
||||
target: number,
|
||||
dt?: number
|
||||
dt?: number,
|
||||
) => {
|
||||
const stable = isStable(s, target, dt);
|
||||
if (stable) {
|
||||
@@ -51,7 +51,7 @@ export const stepSpring = (
|
||||
s: { x: number; v: number },
|
||||
params: { tension: number; friction: number; maxVelocity?: number },
|
||||
target: number,
|
||||
dt = 1 / 60
|
||||
dt = 1 / 60,
|
||||
) => {
|
||||
const interval = 1 / 60;
|
||||
|
||||
|
||||
@@ -18,13 +18,13 @@ const webpackDevServerConfiguration: WebpackDevServerConfiguration = {
|
||||
...ms,
|
||||
(async (req, res, next) => {
|
||||
const userName = req.url.match(
|
||||
/\/api\/github-user-contribution\/(\w+)/
|
||||
/\/api\/github-user-contribution\/(\w+)/,
|
||||
)?.[1];
|
||||
if (userName)
|
||||
res.send(
|
||||
await getGithubUserContribution(userName, {
|
||||
githubToken: process.env.GITHUB_TOKEN!,
|
||||
})
|
||||
}),
|
||||
);
|
||||
else next();
|
||||
}) as ExpressRequestHandler,
|
||||
@@ -34,7 +34,7 @@ const webpackDevServerConfiguration: WebpackDevServerConfiguration = {
|
||||
const webpackConfiguration: WebpackConfiguration = {
|
||||
mode: "development",
|
||||
entry: Object.fromEntries(
|
||||
demos.map((demo: string) => [demo, `./demo.${demo}`])
|
||||
demos.map((demo: string) => [demo, `./demo.${demo}`]),
|
||||
),
|
||||
target: ["web", "es2019"],
|
||||
resolve: { extensions: [".ts", ".js"] },
|
||||
@@ -65,7 +65,7 @@ const webpackConfiguration: WebpackConfiguration = {
|
||||
title: "snk - " + demo,
|
||||
filename: `${demo}.html`,
|
||||
chunks: [demo],
|
||||
})
|
||||
}),
|
||||
),
|
||||
new HtmlWebpackPlugin({
|
||||
title: "snk - " + demos[0],
|
||||
|
||||
@@ -54,6 +54,6 @@ export const createRpcClient = <API_ extends API>(worker: Worker) => {
|
||||
worker.addEventListener("terminate", onTerminate);
|
||||
worker.postMessage({ symbol, key, methodName, args });
|
||||
}),
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -59,7 +59,7 @@ export const getCircleSize = (n: number) => {
|
||||
export const drawCircleStack = (
|
||||
ctx: CanvasRenderingContext2D,
|
||||
stack: Color[],
|
||||
o: Options
|
||||
o: Options,
|
||||
) => {
|
||||
for (let i = stack.length; i--; ) {
|
||||
const { x, y } = cellPath[i];
|
||||
@@ -67,7 +67,7 @@ export const drawCircleStack = (
|
||||
ctx.save();
|
||||
ctx.translate(
|
||||
x * o.sizeCell + (o.sizeCell - o.sizeDot) / 2,
|
||||
y * o.sizeCell + (o.sizeCell - o.sizeDot) / 2
|
||||
y * o.sizeCell + (o.sizeCell - o.sizeDot) / 2,
|
||||
);
|
||||
|
||||
//@ts-ignore
|
||||
|
||||
@@ -16,7 +16,7 @@ export const drawGrid = (
|
||||
ctx: CanvasRenderingContext2D,
|
||||
grid: Grid,
|
||||
cells: Point[] | null,
|
||||
o: Options
|
||||
o: Options,
|
||||
) => {
|
||||
for (let x = grid.width; x--; )
|
||||
for (let y = grid.height; y--; ) {
|
||||
@@ -27,7 +27,7 @@ export const drawGrid = (
|
||||
ctx.save();
|
||||
ctx.translate(
|
||||
x * o.sizeCell + (o.sizeCell - o.sizeDot) / 2,
|
||||
y * o.sizeCell + (o.sizeCell - o.sizeDot) / 2
|
||||
y * o.sizeCell + (o.sizeCell - o.sizeDot) / 2,
|
||||
);
|
||||
|
||||
ctx.fillStyle = color;
|
||||
|
||||
@@ -10,7 +10,7 @@ type Options = {
|
||||
export const drawSnake = (
|
||||
ctx: CanvasRenderingContext2D,
|
||||
snake: Snake,
|
||||
o: Options
|
||||
o: Options,
|
||||
) => {
|
||||
const cells = snakeToCells(snake);
|
||||
|
||||
@@ -25,7 +25,7 @@ export const drawSnake = (
|
||||
ctx,
|
||||
o.sizeCell - u * 2,
|
||||
o.sizeCell - u * 2,
|
||||
(o.sizeCell - u * 2) * 0.25
|
||||
(o.sizeCell - u * 2) * 0.25,
|
||||
);
|
||||
ctx.fill();
|
||||
ctx.restore();
|
||||
@@ -40,7 +40,7 @@ export const drawSnakeLerp = (
|
||||
snake0: Snake,
|
||||
snake1: Snake,
|
||||
k: number,
|
||||
o: Options
|
||||
o: Options,
|
||||
) => {
|
||||
const m = 0.8;
|
||||
const n = snake0.length / 2;
|
||||
@@ -61,7 +61,7 @@ export const drawSnakeLerp = (
|
||||
ctx,
|
||||
o.sizeCell - u * 2,
|
||||
o.sizeCell - u * 2,
|
||||
(o.sizeCell - u * 2) * 0.25
|
||||
(o.sizeCell - u * 2) * 0.25,
|
||||
);
|
||||
ctx.fill();
|
||||
ctx.restore();
|
||||
|
||||
@@ -19,7 +19,7 @@ export const drawStack = (
|
||||
stack: Color[],
|
||||
max: number,
|
||||
width: number,
|
||||
o: { colorDots: Record<Color, string> }
|
||||
o: { colorDots: Record<Color, string> },
|
||||
) => {
|
||||
ctx.save();
|
||||
|
||||
@@ -39,7 +39,7 @@ export const drawWorld = (
|
||||
cells: Point[] | null,
|
||||
snake: Snake,
|
||||
stack: Color[],
|
||||
o: Options
|
||||
o: Options,
|
||||
) => {
|
||||
ctx.save();
|
||||
|
||||
@@ -73,7 +73,7 @@ export const drawLerpWorld = (
|
||||
snake1: Snake,
|
||||
stack: Color[],
|
||||
k: number,
|
||||
o: Options
|
||||
o: Options,
|
||||
) => {
|
||||
ctx.save();
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ export const pathRoundedRect = (
|
||||
ctx: CanvasRenderingContext2D,
|
||||
width: number,
|
||||
height: number,
|
||||
borderRadius: number
|
||||
borderRadius: number,
|
||||
) => {
|
||||
ctx.moveTo(borderRadius, 0);
|
||||
ctx.arcTo(width, 0, width, height, borderRadius);
|
||||
|
||||
@@ -8,7 +8,7 @@ import { getPathToPose } from "@snk/solver/getPathToPose";
|
||||
import type { Options as DrawOptions } from "@snk/draw/drawWorld";
|
||||
|
||||
let snake = createSnakeFromCells(
|
||||
Array.from({ length: 4 }, (_, i) => ({ x: i, y: -1 }))
|
||||
Array.from({ length: 4 }, (_, i) => ({ x: i, y: -1 })),
|
||||
);
|
||||
|
||||
// const chain = [snake];
|
||||
@@ -55,7 +55,7 @@ const animationOptions: AnimationOptions = { frameDuration: 100, step: 1 };
|
||||
null,
|
||||
chainL,
|
||||
drawOptions,
|
||||
animationOptions
|
||||
animationOptions,
|
||||
);
|
||||
stats.push(performance.now() - s);
|
||||
}
|
||||
@@ -73,12 +73,12 @@ const animationOptions: AnimationOptions = { frameDuration: 100, step: 1 };
|
||||
})}ms`,
|
||||
"",
|
||||
].join("\n"),
|
||||
stats
|
||||
stats,
|
||||
);
|
||||
|
||||
fs.writeFileSync(
|
||||
`__tests__/__snapshots__/benchmark-output-${length}.gif`,
|
||||
buffer!
|
||||
buffer!,
|
||||
);
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -46,14 +46,14 @@ for (const key of [
|
||||
null,
|
||||
chain,
|
||||
drawOptions,
|
||||
animationOptions
|
||||
animationOptions,
|
||||
);
|
||||
|
||||
expect(gif).toBeDefined();
|
||||
|
||||
fs.writeFileSync(path.resolve(dir, key + ".gif"), gif);
|
||||
},
|
||||
{ timeout: 20 * 1000 }
|
||||
{ timeout: 20 * 1000 },
|
||||
);
|
||||
|
||||
it(
|
||||
@@ -61,7 +61,7 @@ it(
|
||||
async () => {
|
||||
const grid = grids.smallFull;
|
||||
let snk = createSnakeFromCells(
|
||||
Array.from({ length: 6 }, (_, i) => ({ x: i, y: -1 }))
|
||||
Array.from({ length: 6 }, (_, i) => ({ x: i, y: -1 })),
|
||||
);
|
||||
|
||||
const chain = [snk];
|
||||
@@ -80,12 +80,12 @@ it(
|
||||
null,
|
||||
chain,
|
||||
drawOptions,
|
||||
animationOptions
|
||||
animationOptions,
|
||||
);
|
||||
|
||||
expect(gif).toBeDefined();
|
||||
|
||||
fs.writeFileSync(path.resolve(dir, "swipper.gif"), gif);
|
||||
},
|
||||
{ timeout: 20 * 1000 }
|
||||
{ timeout: 20 * 1000 },
|
||||
);
|
||||
|
||||
@@ -17,7 +17,7 @@ import gifsicle from "gifsicle";
|
||||
import GIFEncoder from "gif-encoder-2";
|
||||
|
||||
const withTmpDir = async <T>(
|
||||
handler: (dir: string) => Promise<T>
|
||||
handler: (dir: string) => Promise<T>,
|
||||
): Promise<T> => {
|
||||
const { name: dir, removeCallback: cleanUp } = tmp.dirSync({
|
||||
unsafeCleanup: true,
|
||||
@@ -37,7 +37,7 @@ export const createGif = async (
|
||||
cells: Point[] | null,
|
||||
chain: Snake[],
|
||||
drawOptions: DrawOptions,
|
||||
animationOptions: AnimationOptions
|
||||
animationOptions: AnimationOptions,
|
||||
) =>
|
||||
withTmpDir(async (dir) => {
|
||||
const { width, height } = getCanvasWorldSize(grid0, drawOptions);
|
||||
@@ -70,7 +70,7 @@ export const createGif = async (
|
||||
snake1,
|
||||
stack,
|
||||
k / animationOptions.step,
|
||||
drawOptions
|
||||
drawOptions,
|
||||
);
|
||||
|
||||
encoder.addFrame(ctx);
|
||||
@@ -92,7 +92,7 @@ export const createGif = async (
|
||||
"--colors=18",
|
||||
outFileName,
|
||||
["--output", optimizedFileName],
|
||||
].flat()
|
||||
].flat(),
|
||||
);
|
||||
|
||||
return new Uint8Array(fs.readFileSync(optimizedFileName));
|
||||
|
||||
@@ -13,7 +13,7 @@ export default async (req: VercelRequest, res: VercelResponse) => {
|
||||
];
|
||||
|
||||
const allowedOrigin = allowedOrigins.find(
|
||||
(o) => o === req.headers.origin
|
||||
(o) => o === req.headers.origin,
|
||||
);
|
||||
if (allowedOrigin)
|
||||
res.setHeader("Access-Control-Allow-Origin", allowedOrigin);
|
||||
@@ -23,7 +23,7 @@ export default async (req: VercelRequest, res: VercelResponse) => {
|
||||
res.json(
|
||||
await getGithubUserContribution(userName as string, {
|
||||
githubToken: process.env.GITHUB_TOKEN!,
|
||||
})
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
export const getGithubUserContribution = async (
|
||||
userName: string,
|
||||
o: { githubToken: string }
|
||||
o: { githubToken: string },
|
||||
) => {
|
||||
const query = /* GraphQL */ `
|
||||
query ($login: String!) {
|
||||
@@ -69,7 +69,7 @@ export const getGithubUserContribution = async (
|
||||
(d.contributionLevel === "SECOND_QUARTILE" && 2) ||
|
||||
(d.contributionLevel === "FIRST_QUARTILE" && 1) ||
|
||||
0,
|
||||
}))
|
||||
})),
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ for (const { width, height, snake } of [
|
||||
{ width: 5, height: 5, snake: snake4 },
|
||||
])
|
||||
it(`should find solution for ${n} ${width}x${height} generated grids for ${getSnakeLength(
|
||||
snake
|
||||
snake,
|
||||
)} length snake`, () => {
|
||||
const results = Array.from({ length: n }, (_, seed) => {
|
||||
const grid = createFromSeed(seed, width, height);
|
||||
|
||||
@@ -24,7 +24,7 @@ export const clearCleanColoredLayer = (
|
||||
grid: Grid,
|
||||
outside: Outside,
|
||||
snake0: Snake,
|
||||
color: Color
|
||||
color: Color,
|
||||
) => {
|
||||
const snakeN = getSnakeLength(snake0);
|
||||
|
||||
@@ -55,7 +55,7 @@ const getPathToNextPoint = (
|
||||
grid: Grid,
|
||||
snake0: Snake,
|
||||
color: Color,
|
||||
points: Point[]
|
||||
points: Point[],
|
||||
) => {
|
||||
const closeList: Snake[] = [];
|
||||
const openList: M[] = [{ snake: snake0 } as any];
|
||||
@@ -96,7 +96,7 @@ export const getTunnellablePoints = (
|
||||
grid: Grid,
|
||||
outside: Outside,
|
||||
snakeN: number,
|
||||
color: Color
|
||||
color: Color,
|
||||
) => {
|
||||
const points: Point[] = [];
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ export const clearResidualColoredLayer = (
|
||||
grid: Grid,
|
||||
outside: Outside,
|
||||
snake0: Snake,
|
||||
color: Color
|
||||
color: Color,
|
||||
) => {
|
||||
const snakeN = getSnakeLength(snake0);
|
||||
|
||||
@@ -99,7 +99,7 @@ export const getTunnellablePoints = (
|
||||
grid: Grid,
|
||||
outside: Outside,
|
||||
snakeN: number,
|
||||
color: Color
|
||||
color: Color,
|
||||
) => {
|
||||
const points: T[] = [];
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ export const getBestRoute = (grid0: Grid, snake0: Snake) => {
|
||||
for (const color of extractColors(grid)) {
|
||||
if (color > 1)
|
||||
chain.unshift(
|
||||
...clearResidualColoredLayer(grid, outside, chain[0], color)
|
||||
...clearResidualColoredLayer(grid, outside, chain[0], color),
|
||||
);
|
||||
chain.unshift(...clearCleanColoredLayer(grid, outside, chain[0], color));
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ const getSnakeEscapePath = (
|
||||
grid: Grid,
|
||||
outside: Outside,
|
||||
snake0: Snake,
|
||||
color: Color
|
||||
color: Color,
|
||||
) => {
|
||||
const openList: M[] = [{ snake: snake0, w: 0 } as any];
|
||||
const closeList: Snake[] = [];
|
||||
@@ -79,7 +79,7 @@ export const getBestTunnel = (
|
||||
x: number,
|
||||
y: number,
|
||||
color: Color,
|
||||
snakeN: number
|
||||
snakeN: number,
|
||||
) => {
|
||||
const c = { x, y };
|
||||
const snake0 = createSnakeFromCells(Array.from({ length: snakeN }, () => c));
|
||||
|
||||
@@ -24,7 +24,7 @@ export const createOutside = (grid: Grid, color: Color = 0 as Color) => {
|
||||
export const fillOutside = (
|
||||
outside: Outside,
|
||||
grid: Grid,
|
||||
color: Color = 0 as Color
|
||||
color: Color = 0 as Color,
|
||||
) => {
|
||||
let changed = true;
|
||||
while (changed) {
|
||||
|
||||
@@ -27,7 +27,7 @@ export const getTunnelPath = (snake0: Snake, tunnel: Point[]) => {
|
||||
export const updateTunnel = (
|
||||
grid: Grid,
|
||||
tunnel: Point[],
|
||||
toDelete: Point[]
|
||||
toDelete: Point[],
|
||||
) => {
|
||||
while (tunnel.length) {
|
||||
const { x, y } = tunnel[0];
|
||||
|
||||
@@ -38,7 +38,7 @@ for (const [key, grid] of Object.entries(grids))
|
||||
null,
|
||||
chain,
|
||||
drawOptions,
|
||||
animationOptions
|
||||
animationOptions,
|
||||
);
|
||||
|
||||
expect(svg).toBeDefined();
|
||||
|
||||
@@ -8,7 +8,7 @@ it("should minify css", () => {
|
||||
color : red ;
|
||||
}
|
||||
|
||||
`)
|
||||
`),
|
||||
).toBe(".c{color:red}");
|
||||
|
||||
expect(
|
||||
@@ -22,6 +22,6 @@ it("should minify css", () => {
|
||||
animation: linear 10;
|
||||
}
|
||||
|
||||
`)
|
||||
`),
|
||||
).toBe(".c{top:0;color:red}#{animation:linear 10}");
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ const mergeKeyFrames = (keyframes: { t: number; style: string }[]) => {
|
||||
*/
|
||||
export const createAnimation = (
|
||||
name: string,
|
||||
keyframes: { t: number; style: string }[]
|
||||
keyframes: { t: number; style: string }[],
|
||||
) =>
|
||||
`@keyframes ${name}{` +
|
||||
mergeKeyFrames(keyframes)
|
||||
|
||||
@@ -15,7 +15,7 @@ export type Options = {
|
||||
export const createGrid = (
|
||||
cells: (Point & { t: number | null; color: Color | Empty })[],
|
||||
{ sizeDotBorderRadius, sizeDot, sizeCell }: Options,
|
||||
duration: number
|
||||
duration: number,
|
||||
) => {
|
||||
const svgElements: string[] = [];
|
||||
const styles = [
|
||||
@@ -48,7 +48,7 @@ export const createGrid = (
|
||||
`.c.${id}{
|
||||
fill: var(--c${color});
|
||||
animation-name: ${animationName}
|
||||
}`
|
||||
}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ export const createGrid = (
|
||||
y: y * sizeCell + m,
|
||||
rx: sizeDotBorderRadius,
|
||||
ry: sizeDotBorderRadius,
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,13 +34,13 @@ export type DrawOptions = {
|
||||
|
||||
const getCellsFromGrid = ({ width, height }: Grid) =>
|
||||
Array.from({ length: width }, (_, x) =>
|
||||
Array.from({ length: height }, (_, y) => ({ x, y }))
|
||||
Array.from({ length: height }, (_, y) => ({ x, y })),
|
||||
).flat();
|
||||
|
||||
const createLivingCells = (
|
||||
grid0: Grid,
|
||||
chain: Snake[],
|
||||
cells: Point[] | null
|
||||
cells: Point[] | null,
|
||||
) => {
|
||||
const livingCells: (Point & {
|
||||
t: number | null;
|
||||
@@ -73,7 +73,7 @@ export const createSvg = (
|
||||
cells: Point[] | null,
|
||||
chain: Snake[],
|
||||
drawOptions: DrawOptions,
|
||||
animationOptions: Pick<AnimationOptions, "frameDuration">
|
||||
animationOptions: Pick<AnimationOptions, "frameDuration">,
|
||||
) => {
|
||||
const width = (grid.width + 2) * drawOptions.sizeCell;
|
||||
const height = (grid.height + 5) * drawOptions.sizeCell;
|
||||
@@ -89,7 +89,7 @@ export const createSvg = (
|
||||
drawOptions,
|
||||
grid.width * drawOptions.sizeCell,
|
||||
(grid.height + 2) * drawOptions.sizeCell,
|
||||
duration
|
||||
duration,
|
||||
),
|
||||
createSnake(chain, drawOptions, duration),
|
||||
];
|
||||
|
||||
@@ -15,7 +15,7 @@ const lerp = (k: number, a: number, b: number) => (1 - k) * a + k * b;
|
||||
export const createSnake = (
|
||||
chain: Snake[],
|
||||
{ sizeCell, sizeDot }: Options,
|
||||
duration: number
|
||||
duration: number,
|
||||
) => {
|
||||
const snakeN = chain[0] ? getSnakeLength(chain[0]) : 0;
|
||||
|
||||
@@ -64,7 +64,7 @@ export const createSnake = (
|
||||
const animationName = id;
|
||||
|
||||
const keyframes = removeInterpolatedPositions(
|
||||
positions.map((tr, i, { length }) => ({ ...tr, t: i / length }))
|
||||
positions.map((tr, i, { length }) => ({ ...tr, t: i / length })),
|
||||
).map(({ t, ...p }) => ({ t, style: transform(p) }));
|
||||
|
||||
return [
|
||||
|
||||
@@ -11,7 +11,7 @@ export const createStack = (
|
||||
{ sizeDot }: Options,
|
||||
width: number,
|
||||
y: number,
|
||||
duration: number
|
||||
duration: number,
|
||||
) => {
|
||||
const svgElements: string[] = [];
|
||||
const styles = [
|
||||
@@ -51,7 +51,7 @@ export const createStack = (
|
||||
width: (ts.length * m + 0.6).toFixed(1),
|
||||
x,
|
||||
y,
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
styles.push(
|
||||
@@ -68,7 +68,7 @@ export const createStack = (
|
||||
].map(({ scale, t }) => ({
|
||||
t,
|
||||
style: `transform:scale(${scale.toFixed(3)},1)`,
|
||||
}))
|
||||
})),
|
||||
),
|
||||
|
||||
`.u.${id} {
|
||||
@@ -76,7 +76,7 @@ export const createStack = (
|
||||
animation-name: ${animationName};
|
||||
transform-origin: ${x}px 0
|
||||
}
|
||||
`
|
||||
`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ it("should return next snake", () => {
|
||||
];
|
||||
|
||||
expect(snakeToCells(nextSnake(createSnakeFromCells(snk0), 1, 0))).toEqual(
|
||||
snk1
|
||||
snk1,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ export const setColor = (
|
||||
grid: Grid,
|
||||
x: number,
|
||||
y: number,
|
||||
color: Color | Empty
|
||||
color: Color | Empty,
|
||||
) => {
|
||||
grid.data[getIndex(grid, x, y)] = color || 0;
|
||||
};
|
||||
|
||||
@@ -9,7 +9,7 @@ export const randomlyFillGrid = (
|
||||
colors = [1, 2, 3] as Color[],
|
||||
emptyP = 2,
|
||||
}: { colors?: Color[]; emptyP?: number } = {},
|
||||
rand = defaultRand
|
||||
rand = defaultRand,
|
||||
) => {
|
||||
for (let x = grid.width; x--; )
|
||||
for (let y = grid.height; y--; ) {
|
||||
|
||||
Reference in New Issue
Block a user