diff --git a/scripts/generate-icons.mjs b/scripts/generate-icons.mjs index 4b5f0427..3415d278 100644 --- a/scripts/generate-icons.mjs +++ b/scripts/generate-icons.mjs @@ -104,11 +104,18 @@ function convertToSinglePath(elements) { return rectToPath(attrs); case 'circle': return circleToPath(attrs); + case 'ellipse': + return ellipseToPath(attrs); case 'line': return lineToPath(attrs); + case 'polyline': + return polylineToPath(attrs); + case 'polygon': + return polygonToPath(attrs); case 'path': return convertPath(attrs.d, index); default: + console.log(`tag ${type} is skipped`); return ''; } }); @@ -261,10 +268,55 @@ function circleToPath({ cx = 0, cy = 0, r }) { `.trim().replace(/\s+/g, ' '); } +function ellipseToPath({ cx = 0, cy = 0, rx = 0, ry = 0 }) { + // Similar to a circle but using different radii for x and y coordinates + return ` + M${cx - rx},${cy} + a${rx},${ry} 0 1,0 ${rx * 2},0 + a${rx},${ry} 0 1,0 -${rx * 2},0 + Z + `.trim().replace(/\s+/g, ' '); +} + function lineToPath({ x1 = 0, y1 = 0, x2 = 0, y2 = 0 }) { return `M${x1} ${y1} L${x2} ${y2}`; } +function polylineToPath({ points }) { + if (!points) + return ''; + + // Split points string into array of coordinates + const coordinates = points.trim().split(/\s+|,/).map(Number); + + if (coordinates.length < 4) + return ''; // Need at least 2 points + + // Start path at first point + let path = `M${coordinates[0]} ${coordinates[1]}`; + + // Add line segments to remaining points + for (let i = 2; i < coordinates.length; i += 2) { + path += ` L${coordinates[i]} ${coordinates[i + 1]}`; + } + + return path; +} + +function polygonToPath({ points }) { + if (!points) + return ''; + + // Use polylineToPath to create the base path + const basePath = polylineToPath({ points }); + + if (!basePath) + return ''; + + // Close the path by adding 'Z' command + return `${basePath} Z`; +} + async function getLucideSvgDataFromPath(pathDir) { const type = await lstat(pathDir); if (type.isDirectory()) {