Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192#!/usr/bin/env node// Generates css/icons.css: a curated set of Lucide icons (ISC licence) as// CSS mask classes, so a page uses them as <i class="icon icon-save"></i>// with no JavaScript and no SVG sprite to serve. Each icon is the SVG as a// data URL; the colour comes from currentColor through the mask.// Run with `npm run icons` after changing ICONS.
import { readFileSync, writeFileSync } from "node:fs";import { join, resolve } from "node:path";
const root = resolve(new URL("..", import.meta.url).pathname);const lucide = join(root, "node_modules", "lucide-static");const version = JSON.parse(readFileSync(join(lucide, "package.json"), "utf8")).version;
// Lucide names (the file names under lucide-static/icons), grouped by use.export const ICONS = [ // outcomes and editing "check", "check-check", "x", "plus", "minus", "trash-2", "pencil", "undo-2", "redo-2", "copy", "clipboard", "clipboard-check", "scissors", // files "save", "folder", "folder-open", "folder-plus", "file", "file-plus", "file-text", "file-down", "file-up", "download", "upload", "paperclip", "printer", "archive", "inbox", // links and sharing "link", "unlink", "external-link", "share-2", "send", "mail", "globe", "at-sign", "hash", "tag", "bookmark", "pin", // finding and settings "search", "filter", "settings", "sliders-horizontal", "wrench", "eye", "eye-off", "lock", "lock-open", "key", "shield", // scheme and people "sun", "moon", "sun-moon", "palette", "user", "users", "user-plus", "bot", "sparkles", "wand-sparkles", "zap", "star", "heart", "flag", "bell", // reading and writing "book", "book-open", "library", "quote", "text-quote", "message-square", "message-square-plus", "message-circle", "pilcrow", "type", "heading", "bold", "italic", "underline", "strikethrough", "code", "code-xml", "list", "list-ordered", "list-checks", "indent-increase", "indent-decrease", "subscript", "superscript", "sigma", "image", "table", "align-left", "align-center", "align-right", "text", "spell-check", // version control "git-commit-horizontal", "git-branch", "git-branch-plus", "git-merge", "git-pull-request", "history", // navigation "chevron-up", "chevron-down", "chevron-left", "chevron-right", "chevrons-left", "chevrons-right", "chevrons-up-down", "arrow-up", "arrow-down", "arrow-left", "arrow-right", "arrow-up-right", "ellipsis", "ellipsis-vertical", "menu", "grip-vertical", "move", "maximize-2", "minimize-2", "panel-left", "panel-right", "layout-grid", "house", "log-in", "log-out", "refresh-cw", "loader-circle", // status "info", "circle-alert", "triangle-alert", "circle-check", "circle-x", "circle-help", "circle-plus", "circle-minus", "clock", "calendar", "play", "pause", "square", "terminal",];
function dataUrl(name) { let svg; try { svg = readFileSync(join(lucide, "icons", `${name}.svg`), "utf8"); } catch { throw new Error(`no Lucide icon named "${name}"`); } // Keep the geometry; drop the licence comment, the class and the fixed size. // A mask only reads alpha, so the stroke colour is anything opaque. const body = svg .replace(/<!--[\s\S]*?-->/g, "") .replace(/\s+class="[^"]*"/, "") .replace(/\s+width="24"\s+height="24"/, "") .replace(/stroke="currentColor"/, 'stroke="black"') .replace(/\s*\n\s*/g, " ") .replace(/>\s+</g, "><") .replace(/\s+\/>/g, "/>") .trim(); const encoded = body.replace(/"/g, "'").replace(/</g, "%3C").replace(/>/g, "%3E").replace(/#/g, "%23"); return `url("data:image/svg+xml,${encoded}")`;}
const lines = [ "/* ==========================================================================", " supram · icons", ` Lucide ${version} (ISC), a curated set as CSS masks. Generated by`, " scripts/icons.mjs: edit ICONS there and run `npm run icons`.", "", ' <i class="icon icon-save" aria-hidden="true"></i>', "", " An icon is 1em square, takes the text colour (currentColor), and sits", " on the baseline like a letter; a button hides it from screen readers", " and keeps its meaning in the label or a title.", " ========================================================================== */", "", ".icon {", " display: inline-block;", " inline-size: 1em;", " block-size: 1em;", " flex: none;", " vertical-align: -0.15em;", " background-color: currentColor;", " -webkit-mask: var(--icon) center / contain no-repeat;", " mask: var(--icon) center / contain no-repeat;", "}", "", "/* A step larger or smaller than the text, when an icon stands alone. */", ".icon-lg { font-size: 1.5em; }", ".icon-sm { font-size: 0.85em; }", "",];for (const name of ICONS) lines.push(`.icon-${name} { --icon: ${dataUrl(name)}; }`);lines.push("");writeFileSync(join(root, "css", "icons.css"), lines.join("\n"));console.log(`css/icons.css: ${ICONS.length} icons from Lucide ${version}`);