Files
anidev-design-system/scripts/build-icons.mjs
T

78 lines
3.4 KiB
JavaScript

import { mkdir, writeFile } from "node:fs/promises";
import { icons, iconNames, iconSvg } from "../icons/icons.js";
const root = new URL("../icons/", import.meta.url);
await mkdir(new URL("svg/", root), { recursive: true });
for (const name of iconNames)
await writeFile(
new URL(`svg/${name}.svg`, root),
iconSvg(name, { label: icons[name].label }) + "\n",
);
await writeFile(
new URL("sprite.svg", root),
`<svg xmlns="http://www.w3.org/2000/svg">${iconNames.map((name) => `<symbol id="${name}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">${icons[name].paths}</symbol>`).join("")}</svg>\n`,
);
await writeFile(
new URL("manifest.json", root),
JSON.stringify(
{
name: "Anidev Dock Icons",
version: "1.0.0",
grid: 24,
stroke: 1.5,
count: iconNames.length,
icons: iconNames.map((name) => ({
name,
label: icons[name].label,
category: icons[name].category,
file: `svg/${name}.svg`,
})),
},
null,
2,
) + "\n",
);
const categories = [...new Set(iconNames.map((name) => icons[name].category))];
const groupNames = {
navigation: "Навигация",
keyboard: "Клавиатура и платформы",
account: "Аккаунт",
security: "Безопасность",
actions: "Действия",
files: "Файлы",
system: "Система",
status: "Состояния",
direction: "Направления",
};
for (const theme of ["dark", "light"]) {
const [bg, ink, muted, line, accent] =
theme === "dark"
? ["#111f26", "#e3f2f3", "#a5bec5", "#3b535c", "#77cbbb"]
: ["#edf3f3", "#173239", "#4c666d", "#c6d7da", "#12616a"];
let rowY = 178;
const rows = categories
.map((category) => {
const names = iconNames.filter(
(name) => icons[name].category === category,
),
y = rowY;
const rowCount = Math.ceil(names.length / 8);
rowY += rowCount * 100 + 32;
return `<text x="56" y="${y}" fill="${muted}" font-size="12">${groupNames[category]}</text>${names
.map((name, index) => {
const x = 56 + (index % 8) * 106,
top = y + Math.floor(index / 8) * 100;
return `<svg x="${x + 35}" y="${top + 18}" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="${ink}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">${icons[name].paths}</svg><text x="${x + 51}" y="${top + 76}" text-anchor="middle" fill="${muted}" font-size="10">${name}</text>`;
})
.join("")}<path d="M56 ${rowY - 18}H904" stroke="${line}"/>`;
})
.join("");
const height = rowY + 40;
await writeFile(
new URL(`preview-${theme}.svg`, root),
`<svg xmlns="http://www.w3.org/2000/svg" width="960" height="${height}" viewBox="0 0 960 ${height}"><rect width="960" height="${height}" fill="${bg}"/><g font-family="Trebuchet MS,Arial,sans-serif"><text x="56" y="66" font-size="25" font-weight="bold" fill="${accent}">a/</text><text x="56" y="110" font-size="32" font-weight="bold" fill="${ink}">Dock Icons</text><text x="904" y="108" text-anchor="end" font-size="13" fill="${muted}">${iconNames.length} SVG · 24 px · 1.5 px stroke</text><path d="M56 136H904" stroke="${line}"/>${rows}<text x="56" y="${height - 18}" font-size="11" fill="${muted}">ANIDEV / DESIGN SYSTEM</text></g></svg>\n`,
);
}
console.log(
`Built ${iconNames.length} icons, sprite, manifest and two contact sheets.`,
);