font-registry.js (7.9 KB)


 1 // Font registry - maps font-family names to their file paths and styles
 2 // Fonts are registered using the family names embedded in the font files
 3 
 4 const FONT_ENTRIES = [
 5 	{ family: 'Baskervville', file: 'resources/fonts/baskervvile/Baskervville-Regular.ttf', weight: 400, style: 'normal' },
 6 	{ family: 'Baskervville', file: 'resources/fonts/baskervvile/Baskervville-Italic.ttf', weight: 400, style: 'italic' },
 7 	{ family: 'Baskervville', file: 'resources/fonts/baskervvile/Baskervville-Bold.ttf', weight: 700, style: 'normal' },
 8 	{ family: 'Baskervville', file: 'resources/fonts/baskervvile/Baskervville-BoldItalic.ttf', weight: 700, style: 'italic' },
 9 	{ family: 'Baskervville SemiBold', file: 'resources/fonts/baskervvile/Baskervville-SemiBold.ttf', weight: 600, style: 'normal' },
10 	{ family: 'Baskervville SemiBold', file: 'resources/fonts/baskervvile/Baskervville-SemiBoldItalic.ttf', weight: 600, style: 'italic' },
11 	{ family: 'Basteleur Bold', file: 'resources/fonts/basteleur-master/Basteleur-Bold.ttf', weight: 700, style: 'normal' },
12 	{ family: 'Basteleur Moonlight', file: 'resources/fonts/basteleur-master/Basteleur-Moonlight.ttf', weight: 400, style: 'normal' },
13 	{ family: 'Avara', file: 'resources/fonts/Avara-master/Avara-Bold.otf', weight: 700, style: 'normal' },
14 	{ family: 'Avara', file: 'resources/fonts/Avara-master/Avara-BoldItalic.otf', weight: 700, style: 'italic' },
15 	{ family: 'Avara Black', file: 'resources/fonts/Avara-master/Avara-Black.otf', weight: 900, style: 'normal' },
16 	{ family: 'Ballet', file: 'resources/fonts/Ballet/Ballet_28pt-Regular.ttf', weight: 400, style: 'normal' },
17 	{ family: 'Bitcount Single', file: 'resources/fonts/Bitcount_Single/BitcountSingle-Regular.ttf', weight: 400, style: 'normal' },
18 	{ family: 'Cut Me Out 2', file: 'resources/fonts/CutMeOut/CutMeOut2.ttf', weight: 400, style: 'normal' },
19 	{ family: 'Elb-Tunnel', file: 'resources/fonts/ElbtunnelTT/Elb-Tunnel.ttf', weight: 400, style: 'normal' },
20 	{ family: 'Elb-Tunnel Schatten', file: 'resources/fonts/ElbtunnelTT/Elb-Tunnel Schatten.ttf', weight: 400, style: 'normal' },
21 	{ family: 'Eagle Lake', file: 'resources/fonts/Eagle_Lake/EagleLake-Regular.ttf', weight: 400, style: 'normal' },
22 	{ family: 'Eureka', file: 'resources/fonts/Eureka/Eureka.ttf', weight: 400, style: 'normal' },
23 	{ family: 'Feroniapi', file: 'resources/fonts/feroniapi-main/Feroniapi-MediumItalic.otf', weight: 500, style: 'italic' },
24 	{ family: 'Geostar Fill', file: 'resources/fonts/Geostar_Fill/GeostarFill-Regular.ttf', weight: 400, style: 'normal' },
25 	{ family: 'Hyper Scrypt', file: 'resources/fonts/Hyper-Scrypt-master/HyperScrypt.otf', weight: 400, style: 'normal' },
26 	{ family: 'IBM Plex Serif', file: 'resources/fonts/IBM_Plex_Serif/IBMPlexSerif-Regular.ttf', weight: 400, style: 'normal' },
27 	{ family: 'IBM Plex Serif', file: 'resources/fonts/IBM_Plex_Serif/IBMPlexSerif-Italic.ttf', weight: 400, style: 'italic' },
28 	{ family: 'IBM Plex Serif', file: 'resources/fonts/IBM_Plex_Serif/IBMPlexSerif-Bold.ttf', weight: 700, style: 'normal' },
29 	{ family: 'IBM Plex Serif', file: 'resources/fonts/IBM_Plex_Serif/IBMPlexSerif-BoldItalic.ttf', weight: 700, style: 'italic' },
30 	{ family: 'Indira K', file: 'resources/fonts/Indira_K/Indira_K.ttf', weight: 400, style: 'normal' },
31 	{ family: 'Instrument Serif', file: 'resources/fonts/Instrument_Serif/InstrumentSerif-Regular.ttf', weight: 400, style: 'normal' },
32 	{ family: 'Instrument Serif', file: 'resources/fonts/Instrument_Serif/InstrumentSerif-Italic.ttf', weight: 400, style: 'italic' },
33 	{ family: 'Jacquard 12', file: 'resources/fonts/Jacquard_12/Jacquard12-Regular.ttf', weight: 400, style: 'normal' },
34 	{ family: 'Jacquarda Bastarda 9', file: 'resources/fonts/Jacquarda_Bastarda_9/JacquardaBastarda9-Regular.ttf', weight: 400, style: 'normal' },
35 	{ family: 'Jgs Font', file: 'resources/fonts/jgs-main/jgs_Font.ttf', weight: 400, style: 'normal' },
36 	{ family: 'Jgs 5', file: 'resources/fonts/jgs-main/jgs5.ttf', weight: 400, style: 'normal' },
37 	{ family: 'Jgs 7', file: 'resources/fonts/jgs-main/jgs7.ttf', weight: 400, style: 'normal' },
38 	{ family: 'Jgs 9', file: 'resources/fonts/jgs-main/jgs9.ttf', weight: 400, style: 'normal' },
39 	{ family: 'Kaeru Kaeru', file: 'resources/fonts/kaerukaeru-master/kaerukaeru-Regular.otf', weight: 400, style: 'normal' },
40 	{ family: 'Kanalisirung', file: 'resources/fonts/Kanalisirung/Kanalisirung.otf', weight: 400, style: 'normal' },
41 	{ family: 'Karrik', file: 'resources/fonts/karrik_fonts-main/Karrik-Regular.ttf', weight: 400, style: 'normal' },
42 	{ family: 'Karrik', file: 'resources/fonts/karrik_fonts-main/Karrik-Italic.ttf', weight: 400, style: 'italic' },
43 	{ family: 'Kings', file: 'resources/fonts/Kings/Kings-Regular.ttf', weight: 400, style: 'normal' },
44 	{ family: 'Matemasie', file: 'resources/fonts/Matemasie/Matemasie-Regular.ttf', weight: 400, style: 'normal' },
45 	{ family: 'Mess', file: 'resources/fonts/Mess-master/Mess.otf', weight: 300, style: 'normal' },
46 	{ family: 'Mon Hugo', file: 'resources/fonts/Mon_Hugo_freefont/MonHugo-in.ttf', weight: 400, style: 'normal' },
47 	{ family: 'Mon Hugo Out', file: 'resources/fonts/Mon_Hugo_freefont/MonHugo-out.ttf', weight: 400, style: 'normal' },
48 	{ family: 'Murrx', file: 'resources/fonts/Murrx/Murrx.ttf', weight: 400, style: 'normal' },
49 	{ family: 'Neo-castel', file: 'resources/fonts/Neo-castel/webfont/Neo-castel.woff2', weight: 400, style: 'normal' },
50 	{ family: 'Ouest', file: 'resources/fonts/OUEST/Ouest-Regular.ttf', weight: 400, style: 'normal' },
51 	{ family: 'Princess Sofia', file: 'resources/fonts/Princess_Sofia/PrincessSofia-Regular.ttf', weight: 400, style: 'normal' },
52 	{ family: 'Resistance', file: 'resources/fonts/resistance-generale-master/Resistance-generale.otf', weight: 400, style: 'normal' },
53 	{ family: 'Snowburst One', file: 'resources/fonts/Snowburst_One/SnowburstOne-Regular.ttf', weight: 400, style: 'normal' },
54 	{ family: 'Special Elite', file: 'resources/fonts/Special_Elite/SpecialElite-Regular.ttf', weight: 400, style: 'normal' },
55 	{ family: 'Special Gothic Expanded One', file: 'resources/fonts/Special_Gothic_Expanded_One/SpecialGothicExpandedOne-Regular.ttf', weight: 400, style: 'normal' },
56 	{ family: 'Steps Mono', file: 'resources/fonts/steps-mono-main/Steps-Mono.otf', weight: 400, style: 'normal' },
57 	{ family: 'Steps Mono Thin', file: 'resources/fonts/steps-mono-main/Steps-Mono-Thin.otf', weight: 100, style: 'normal' },
58 	{ family: 'Terminal Grotesque', file: 'resources/fonts/Terminal-Grotesque-master/terminal-grotesque.ttf', weight: 400, style: 'normal' },
59 	{ family: 'Terminal Grotesque Open', file: 'resources/fonts/Terminal-Grotesque-master/terminal-grotesque_open.otf', weight: 400, style: 'normal' },
60 	{ family: 'Tiny5', file: 'resources/fonts/Tiny5/Tiny5-Regular.ttf', weight: 400, style: 'normal' },
61 	{ family: 'Trickster', file: 'resources/fonts/Trickster-master/Trickster-Reg.otf', weight: 400, style: 'normal' },
62 ];
63 
64 function formatForCSS(file) {
65 	if (file.endsWith('.woff2')) return `url('${file}') format('woff2')`;
66 	if (file.endsWith('.woff')) return `url('${file}') format('woff')`;
67 	if (file.endsWith('.otf')) return `url('${file}') format('opentype')`;
68 	return `url('${file}') format('truetype')`;
69 }
70 
71 // Generate @font-face CSS for all registered fonts
72 export function generateFontFaceCSS() {
73 	return FONT_ENTRIES.map(entry =>
74 		`@font-face {
75 	font-family: '${entry.family}';
76 	src: ${formatForCSS(entry.file)};
77 	font-weight: ${entry.weight};
78 	font-style: ${entry.style};
79 	font-display: swap;
80 }`
81 	).join('\n');
82 }
83 
84 // Get list of available font family names (deduplicated)
85 export function getAvailableFontFamilies() {
86 	return [...new Set(FONT_ENTRIES.map(e => e.family))];
87 }
88 
89 // Preload all fonts so they're immediately available when used
90 export function preloadAllFonts() {
91 	for (const entry of FONT_ENTRIES) {
92 		const src = formatForCSS(entry.file);
93 		const font = new FontFace(entry.family, src, {
94 			weight: String(entry.weight),
95 			style: entry.style,
96 		});
97 		font.load().then(loaded => document.fonts.add(loaded)).catch(() => {});
98 	}
99 }