Skip to content

A personal assistant that lives on your desktop, remembers what matters, and can use your Mac for you.

TypeScript
1.8 KB
Raw Blame
// Builds packages/ui/src/rose/strokes.ts from rose-lines.svg (traced by trace_rose.py): every
// traced stroke and sparkle, longest stroke first, for the Dot's inline SVG rose.
// Usage: node docs/brand/tools/build-rose-strokes.mjs
import { readFileSync, writeFileSync } from "node:fs";
import { fileURLToPath } from "node:url";

const here = (path) => fileURLToPath(new URL(path, import.meta.url));
const svg = readFileSync(here("../rose-lines.svg"), "utf8");
const strokes = [...svg.matchAll(/<path data-length="(\d+)" d="([^"]+)"\/>/g)]
	.map((m) => ({ length: Number(m[1]), d: m[2] }))
	.sort((a, b) => b.length - a.length);
const sparkles = [...svg.matchAll(/<circle cx="([\d.]+)" cy="([\d.]+)" r="([\d.]+)"\/>/g)].map((m) =>
	m.slice(1, 4).map(Number),
);

// The sheet's crop (rose-design.html): the flower with room for its glow.
const viewBox = "200 60 860 1130";

const ts = `// Generated by docs/brand/tools/build-rose-strokes.mjs from docs/brand/rose-lines.svg. Do not edit.

/** A traced centerline of the neon rose; \`length\` is in source pixels (1254 × 1254). */
export interface RoseStroke {
	length: number;
	d: string;
}

/** The crop that holds the whole rose, in source pixels. */
export const ROSE_VIEWBOX = "${viewBox}";

/** Every traced stroke, longest first. */
// biome-ignore format: generated
export const ROSE_STROKES: readonly RoseStroke[] = [
${strokes.map(({ length, d }) => `\t{ length: ${length}, d: "${d}" },`).join("\n")}
];

/** Sparkles around the rose as [cx, cy, r]. */
// biome-ignore format: generated
export const ROSE_SPARKLES: readonly (readonly [number, number, number])[] = [
${sparkles.map((c) => `\t[${c.join(", ")}],`).join("\n")}
];
`;
writeFileSync(here("../../../packages/ui/src/rose/strokes.ts"), ts);

console.log(`strokes=${strokes.length} sparkles=${sparkles.length}`);