forked from
tokono.ma/diffuse
A music player that connects to your cloud/distributed storage.
1/**
2 * @param {{ icons: Array<{ icon: { paths: string[], attrs: object[] }, properties: { name: string } }> }} selection
3 * @returns {Map<string, { paths: string[], attrs: object[] }>}
4 */
5export function buildIconMap(selection) {
6 const map = new Map();
7 for (const icon of selection.icons) {
8 const { name } = icon.properties;
9 // Strip weight suffix to get base name (e.g. "gear-bold" → "gear")
10 // Take only the primary name before any comma-separated aliases
11 const primaryName = name.split(",")[0].trim();
12 const baseName = primaryName.replace(/-(?:bold|fill|light|thin|regular|duotone)$/, "");
13 map.set(baseName, { paths: icon.icon.paths, attrs: icon.icon.attrs });
14 }
15 return map;
16}
17
18/**
19 * @param {string[]} paths
20 * @param {object[]} attrs
21 * @returns {string}
22 */
23export function makeSvgDataUrl(paths, attrs) {
24 const pathEls = paths
25 .map((d, i) => {
26 const a = attrs[i] ?? {};
27 const attrStr = Object.entries(a)
28 .map(([k, v]) => `${k}="${v}"`)
29 .join(" ");
30 return attrStr ? `<path ${attrStr} d="${d}"/>` : `<path d="${d}"/>`;
31 })
32 .join("");
33 return `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" fill="currentColor">${pathEls}</svg>`)}`;
34}