mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 18:13:29 +00:00
34 lines
859 B
TypeScript
34 lines
859 B
TypeScript
import stylesMap from './data/styles-map.json';
|
|
import { IconName, IconStyle } from './types';
|
|
|
|
const cache = new Map<IconName, Map<IconStyle, [string, IconName]>>();
|
|
|
|
/**
|
|
* Return the style to load an icon from by its name.
|
|
* Some icons are only available for certain styles.
|
|
*/
|
|
export function getIconStyle(style: IconStyle, icon: IconName): [string, IconName] {
|
|
const cached = cache.get(icon)?.get(style);
|
|
|
|
if (cached) {
|
|
return cached;
|
|
}
|
|
|
|
// Check for exceptions
|
|
let result = [style, icon] as [string, IconName];
|
|
|
|
for (const [onlyStyle, icons] of Object.entries(stylesMap)) {
|
|
if (icons.includes(icon)) {
|
|
result = [onlyStyle, icon];
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!cache.has(icon)) {
|
|
cache.set(icon, new Map());
|
|
}
|
|
cache.get(icon)!.set(style, result);
|
|
|
|
return result;
|
|
}
|