forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBba1e370Tahinli21 days ago1036 commits

prep_icons.py33 lines, 1.3 KiBHistoryRawDownload
1#!/usr/bin/env python3
2"""Fetch the Lucide icons edith uses (pinned tag) and bake them for gpui's svg().
3
4gpui rasterises an SVG through resvg to an alpha mask and tints it with the
5element's text colour, so the stroke is baked white. width/height are dropped
6(the element sizes it; viewBox stays 24x24) and the stroke is thinned from 2 to
7STROKE so a 16px icon is not heavy.
8
9Usage: scripts/prep_icons.py [name ...] (no names: re-fetch every icons/*.svg
10that is already vendored, plus any new name given). Licence: assets/icons/LICENSE-lucide.txt.
11"""
12import re, sys, urllib.request, pathlib
13
14TAG = "0.468.0"
15STROKE = "1.75"
16DIR = pathlib.Path(__file__).resolve().parent.parent / "assets" / "icons"
17
18def bake(svg: str) -> str:
19 svg = re.sub(r'\n\s*width="24"', "", svg)
20 svg = re.sub(r'\n\s*height="24"', "", svg)
21 svg = svg.replace("currentColor", "#ffffff")
22 svg = svg.replace('stroke-width="2"', f'stroke-width="{STROKE}"')
23 return svg
24
25def main() -> None:
26 names = set(sys.argv[1:]) or {p.stem for p in DIR.glob("*.svg")}
27 names |= {p.stem for p in DIR.glob("*.svg")} if sys.argv[1:] else set()
28 for n in sorted(names):
29 url = f"https://raw.githubusercontent.com/lucide-icons/lucide/{TAG}/icons/{n}.svg"
30 (DIR / f"{n}.svg").write_text(bake(urllib.request.urlopen(url).read().decode()))
31 print("baked", n)
32
33main()