logo.js
1.0 kB · javascript · 35 lines
1import FONT from './font.json' with { type: 'json' };23const MASK = FONT.X.rows;45export function grid(level = 1) {6 let rows = MASK;7 for (let k = 1; k < level; k++) {8 rows = rows.flatMap((row) => MASK.map((inner) => [...row].map((cell) => (cell === '1' ? inner : '00000')).join('')));9 }10 return rows;11}1213function path(rows) {14 const parts = [];15 rows.forEach((row, y) => {16 let x = 0;17 while (x < row.length) {18 if (row[x] !== '1') {19 x++;20 continue;21 }22 let w = 0;23 while (row[x + w] === '1') w++;24 parts.push(`M${x} ${y}h${w}v1h-${w}z`);25 x += w;26 }27 });28 return parts.join('');29}3031export function logoSvg(level = 1, fill = 'currentColor', ground = '') {32 const rows = grid(level);33 const back = ground ? `<rect width="${rows.length}" height="${rows.length}" fill="${ground}"/>` : '';34 return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${rows.length} ${rows.length}" role="img" aria-label="MrlyProd">${back}<path fill="${fill}" d="${path(rows)}"/></svg>`;35}