/
Gabryelf
/
Icons-Customize-Gen
Обзор
Документация
Войти
/
Gabryelf
/
Icons-Customize-Gen
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
js/services/IconLibraryService.js
65 строк
2 KB
Valeev Serj
running_start_version
10 июл 2026, 22:15
10 июл 2026, 22:15
5234bd4
Код
Авторство
О чём код?
import { Icon } from '../models/Icon.js'; export class IconLibraryService { constructor() { this._icons = []; this._categories = new Map(); this._basePath = 'assets/icons/'; this._initFromConstants(); } _initFromConstants() { // Список имён файлов (без расширения) const iconNames = [ 'star', 'circle', 'car' //'star', 'heart', 'gear', 'home', 'user', 'settings', //'camera', 'bell', 'bookmark', 'calendar', 'chart', 'chat', //'check', 'clock', 'cloud', 'code', 'compass', 'cube', //'download', 'edit', 'eye', 'fire', 'flag', 'folder', //'gift', 'globe', 'headphones', 'image', 'key', 'lightbulb', //'link', 'lock', 'mail', 'map', 'message', 'microphone', //'moon', 'music', 'notification', 'pencil', 'phone', 'pin', //'play', 'plus', 'power', 'printer', 'rocket', 'search', //'shield', 'shopping', 'star', 'sun', 'tag', 'target', //'trash', 'umbrella', 'video', 'volume', 'weather', 'wifi' ]; const categories = { basic: ['star', 'heart', 'gear', 'home', 'user', 'settings'], media: ['camera', 'image', 'video', 'music', 'microphone', 'headphones'], social: ['chat', 'message', 'mail', 'globe', 'share'], tools: ['edit', 'pencil', 'search', 'lock', 'key', 'shield'], misc: ['bell', 'bookmark', 'calendar', 'chart', 'clock', 'cloud'] }; for (const name of iconNames) { const src = `${this._basePath}${name}.svg`; const category = this._getCategory(name, categories); const icon = new Icon(name, name.charAt(0).toUpperCase() + name.slice(1), src, category); this._icons.push(icon); if (!this._categories.has(category)) { this._categories.set(category, []); } this._categories.get(category).push(icon); } } _getCategory(name, categories) { for (const [cat, items] of Object.entries(categories)) { if (items.includes(name)) return cat; } return 'other'; } getIcons() { return this._icons; } getCategories() { return Array.from(this._categories.keys()); } getIconsByCategory(category) { return this._categories.get(category) || []; } }