APP-Backend / src /utils /icons.js
Luca448's picture
Update independent app to newest state with LFS and binary removals
ff36e71
Raw History Blame Contribute Delete
3.17 kB
import {
Book, GraduationCap, Microscope, FlaskConical, Calculator, Globe, Music,
Palette, PenTool, Pencil, Ruler, Shapes, BookOpen, Library,
Code, Cpu, Database, Monitor, Smartphone, Laptop, Server, Terminal,
Folder, FileText, File, Image as ImageIcon, Video, Mic, Camera, Archive, Box, Clipboard,
Calendar, Clock, CheckCircle, CheckSquare, List, ListTodo,
Heart, Star, Award, Zap, Flame, Droplet, Sun, Moon, Cloud, Anchor, Flag,
Briefcase, ShoppingCart, Gift, User, Users,
Activity, AlertTriangle, MessageCircle, Info, Hash, Link, LogOut
} from 'lucide';
// Explicit map to enable tree-shaking while providing string-based access
export const AVAILABLE_ICONS = {
'book': Book,
'graduation-cap': GraduationCap,
'microscope': Microscope,
'flask-conical': FlaskConical,
'calculator': Calculator,
'globe': Globe,
'music': Music,
'palette': Palette,
'pen-tool': PenTool,
'pencil': Pencil,
'ruler': Ruler,
'shapes': Shapes,
'book-open': BookOpen,
'library': Library,
'code': Code,
'cpu': Cpu,
'database': Database,
'monitor': Monitor,
'smartphone': Smartphone,
'laptop': Laptop,
'server': Server,
'terminal': Terminal,
'folder': Folder,
'file-text': FileText,
'file': File,
'image': ImageIcon,
'video': Video,
'mic': Mic,
'camera': Camera,
'archive': Archive,
'box': Box,
'clipboard': Clipboard,
'calendar': Calendar,
'clock': Clock,
'check-circle': CheckCircle,
'check-square': CheckSquare,
'list': List,
'list-todo': ListTodo,
'heart': Heart,
'star': Star,
'award': Award,
'zap': Zap,
'flame': Flame,
'droplet': Droplet,
'sun': Sun,
'moon': Moon,
'cloud': Cloud,
'anchor': Anchor,
'flag': Flag,
'briefcase': Briefcase,
'shopping-cart': ShoppingCart,
'gift': Gift,
'user': User,
'users': Users,
'activity': Activity,
'alert-triangle': AlertTriangle,
'message-circle': MessageCircle,
'info': Info,
'hash': Hash,
'link': Link,
'log-out': LogOut
};
// Returns an array of all available icon names for the AI to choose from
export const ICON_NAMES = Object.keys(AVAILABLE_ICONS);
/**
* Renders a Lucide AST node to an SVG string.
* Lucide AST format: ['tag', { attributes }, [children]]
*/
function renderAst(node) {
if (!node) return '';
const [tag, attrs, children] = node;
const attrsString = Object.entries(attrs || {})
.map(([key, value]) => `${key}="${value}"`)
.join(' ');
const childrenString = (children || [])
.map(child => renderAst(child))
.join('');
return `<${tag} ${attrsString}>${childrenString}</${tag}>`;
}
export function getIconSvg(name, customAttrs = {}) {
const iconDef = AVAILABLE_ICONS[name] || AVAILABLE_ICONS['folder'];
// In 'lucide' package, the exported icon is an array of child nodes: [ ['path', {d: '...'}], ... ]
const rootAttrs = {
xmlns: 'http://www.w3.org/2000/svg',
width: '24',
height: '24',
viewBox: '0 0 24 24',
fill: 'none',
stroke: 'currentColor',
'stroke-width': '2',
'stroke-linecap': 'round',
'stroke-linejoin': 'round',
...customAttrs
};
return renderAst(['svg', rootAttrs, iconDef]);
}