cookie-glass-valenced/tools/icons.py
2026-12-02 03:35:55 -06:00

47 lines
3.5 KiB
Python

"""Fetches Material Symbols (Rounded, Apache-2.0) and renders the icon pack to themes/cookie-glass/assets/icons.
Keys are Discord design-system asset names; values are Material Symbol names. Unknown keys are ignored by Discord.
"""
import json, pathlib, subprocess, urllib.request
MAP = {
'HomeIcon': 'home', 'ChatIcon': 'chat_bubble', 'BellIcon': 'notifications', 'SettingsIcon': 'settings',
'FriendsIcon': 'group', 'UserIcon': 'person', 'MagnifyingGlassIcon': 'search', 'PlusSmallIcon': 'add',
'PlusLargeIcon': 'add', 'MicrophoneIcon': 'mic', 'MicrophoneSlashIcon': 'mic_off', 'HeadphonesIcon': 'headphones',
'HeadphonesSlashIcon': 'headset_off', 'GiftIcon': 'redeem', 'ReactionIcon': 'add_reaction', 'ImageIcon': 'image',
'ImagePlusIcon': 'add_photo_alternate', 'ImageFileIcon': 'image', 'AtIcon': 'alternate_email', 'PinIcon': 'push_pin',
'ThreadIcon': 'forum', 'ThreadPlusIcon': 'add_comment', 'TextIcon': 'tag', 'VoiceNormalIcon': 'volume_up',
'CopyIcon': 'content_copy', 'TrashIcon': 'delete', 'StarIcon': 'star', 'HeartIcon': 'favorite', 'EyeIcon': 'visibility',
'PencilIcon': 'edit', 'LinkIcon': 'link', 'ArrowLargeLeftIcon': 'arrow_back', 'ArrowLargeRightIcon': 'arrow_forward',
'ArrowLargeUpIcon': 'arrow_upward', 'ArrowLargeDownIcon': 'arrow_downward', 'ChevronSmallRightIcon': 'chevron_right',
'ChevronSmallDownIcon': 'expand_more', 'ChevronSmallLeftIcon': 'chevron_left', 'ChevronSmallUpIcon': 'expand_less',
'XSmallIcon': 'close', 'XLargeIcon': 'close', 'CircleCheckIcon': 'check_circle', 'CircleInformationIcon': 'info',
'CircleErrorIcon': 'error', 'KeyboardIcon': 'keyboard', 'LanguageIcon': 'translate', 'GlobeEarthIcon': 'public',
'LightbulbIcon': 'lightbulb', 'GameControllerIcon': 'sports_esports', 'PaperIcon': 'description',
'PuzzlePieceIcon': 'extension', 'RetryIcon': 'refresh', 'ShieldUserIcon': 'shield_person', 'SendMessageIcon': 'send',
'PhoneCallIcon': 'call', 'VideoIcon': 'videocam', 'ScreenArrowIcon': 'screen_share', 'MoreHorizontalIcon': 'more_horiz',
'MoreVerticalIcon': 'more_vert', 'InboxIcon': 'inbox', 'BookmarkIcon': 'bookmark', 'ReplyIcon': 'reply',
'DenyIcon': 'block', 'AppsIcon': 'apps', 'CameraIcon': 'photo_camera', 'FileIcon': 'draft', 'CheckmarkLargeIcon': 'check',
'CheckmarkSmallIcon': 'check', 'LockIcon': 'lock', 'DownloadIcon': 'download', 'UploadIcon': 'upload',
'ShareIcon': 'share', 'FlagIcon': 'flag', 'UserPlusIcon': 'person_add', 'EmojiIcon': 'mood',
}
ROOT = pathlib.Path(__file__).resolve().parent.parent
OUT = ROOT / 'themes/cookie-glass/assets/icons'
CACHE = pathlib.Path.home() / '.cache/valenced/msym'
SIZE = 72 # 24dp at 3x
URL = 'https://raw.githubusercontent.com/google/material-design-icons/master/symbols/web/{0}/materialsymbolsrounded/{0}_24px.svg'
OUT.mkdir(parents=True, exist_ok=True)
CACHE.mkdir(parents=True, exist_ok=True)
for key, sym in MAP.items():
svg = CACHE / f'{sym}.svg'
if not svg.exists():
svg.write_bytes(urllib.request.urlopen(URL.format(sym)).read())
white = svg.read_text().replace('<path ', '<path fill="#ffffff" ')
subprocess.run(['rsvg-convert', '-w', str(SIZE), '-h', str(SIZE), '-o', str(OUT / f'{key}.png')],
input=white.encode(), check=True)
(ROOT / 'themes/cookie-glass/js/icons.ts').write_text(
'// Generated by tools/icons.py. Do not edit by hand.\n\nexport const Icons: Record<string, string> = '
+ json.dumps({k: f'assets/icons/{k}.png' for k in MAP}, indent='\t') + '\n')
print(len(MAP), 'icons')