Infers which font classes to apply by default based on the fonts that have been loaded.
(document: Document)
| 744 | |
| 745 | /** Infers which font classes to apply by default based on the fonts that have been loaded. */ |
| 746 | function inferDefaultFontSetClass(document: Document): string[] { |
| 747 | let materialSymbolsVariation: 'outlined' | 'rounded' | 'sharp' | null = null; |
| 748 | let hasLegacyMaterialIcons = false; |
| 749 | |
| 750 | // Note that this approach only detects the fonts that are link tags at the time of calling |
| 751 | // so we may miss some fonts that are loaded later. That should be a minority and the logic |
| 752 | // below still falls back to the old behavior if that happens. |
| 753 | if (document.fonts && typeof document.fonts.forEach === 'function') { |
| 754 | document.fonts.forEach(font => { |
| 755 | const family = font.family.replace(/['"]/g, '').trim().toLowerCase(); |
| 756 | |
| 757 | if (family === 'material icons' || family.startsWith('material icons ')) { |
| 758 | hasLegacyMaterialIcons = true; |
| 759 | } |
| 760 | |
| 761 | if (family.startsWith('material symbols rounded')) { |
| 762 | materialSymbolsVariation = 'rounded'; |
| 763 | } else if (family.startsWith('material symbols sharp')) { |
| 764 | materialSymbolsVariation = 'sharp'; |
| 765 | } else if (family.startsWith('material symbols')) { |
| 766 | // This should mostly catch `Material Symbols Outlined`, |
| 767 | // but we keep it a bit broader just in case. |
| 768 | materialSymbolsVariation = 'outlined'; |
| 769 | } |
| 770 | }); |
| 771 | } |
| 772 | |
| 773 | return [ |
| 774 | // Ideally we would add both `material-symbols-*` and `material-icons` if we detect both fonts, |
| 775 | // however this ends up being very breaking internally, because some apps were loading both |
| 776 | // without setting the correct class. We play it safe here so we can at least handle the class |
| 777 | // automatically for new apps. |
| 778 | materialSymbolsVariation && !hasLegacyMaterialIcons |
| 779 | ? `material-symbols-${materialSymbolsVariation}` |
| 780 | : 'material-icons', |
| 781 | 'mat-ligature-font', |
| 782 | ]; |
| 783 | } |
no outgoing calls
no test coverage detected