Skip to content

Commit cd8145e

Browse files
author
ChetanSenta
committed
update lib/svg/fonts.ts
1 parent 66a3672 commit cd8145e

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

lib/svg/fonts.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
11
import { sanitizeFont } from './sanitizer';
22

3+
/**
4+
* Maps lowercase font shorthand keys to their full CSS font-family strings.
5+
*
6+
* Fonts listed here are treated as "predefined" — the generator resolves them
7+
* directly without emitting a second dynamic Google Fonts @import. Only add a
8+
* font here if it is ALREADY loaded by the unconditional @import in generator.ts
9+
* (Fira Code, JetBrains Mono, Roboto, Syncopate, Space Grotesk).
10+
*
11+
* Fonts NOT in this map (e.g. "Inter", "Orbitron") correctly fall through to
12+
* the dynamic @import path, fetching them from Google Fonts on demand.
13+
*/
314
export const FONT_MAP = {
15+
// ── Pre-existing entries ────────────────────────────────────────────────
416
jetbrains: '"JetBrains Mono", monospace',
517
fira: '"Fira Code", monospace',
618
roboto: '"Roboto", sans-serif',
19+
20+
// ── Previously missing — both fonts are in the unconditional @import ───
21+
// Without these entries, passing ?font=syncopate or ?font=spacegrotesk
22+
// incorrectly triggers a duplicate dynamic Google Fonts fetch.
23+
syncopate: '"Syncopate", sans-serif',
24+
spacegrotesk: '"Space Grotesk", sans-serif',
25+
'space grotesk': '"Space Grotesk", sans-serif', // handles spaced user input
26+
27+
// ── Aliases for common variations ───────────────────────────────────────
28+
firacode: '"Fira Code", monospace', // alias: fira is the canonical key
29+
'jetbrains mono': '"JetBrains Mono", monospace', // handles spaced user input
730
} as const;
831

932
/**

lib/svg/generator.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,25 @@ import { GRID_ORIGIN_X, GRID_ORIGIN_Y, TILE_HEIGHT_HALF, TILE_WIDTH_HALF } from
2020
import { SVG_WIDTH, SVG_HEIGHT } from './generatorConstants';
2121

2222
const FONT_MAP = {
23-
inter: '"Inter", sans-serif',
24-
roboto: '"Roboto", sans-serif',
23+
// ── Pre-existing entries ────────────────────────────────────────────────
2524
jetbrains: '"JetBrains Mono", monospace',
2625
fira: '"Fira Code", monospace',
26+
roboto: '"Roboto", sans-serif',
27+
28+
// ── Previously missing — both fonts are in the unconditional @import ───
29+
// Without these entries, passing ?font=syncopate or ?font=spacegrotesk
30+
// incorrectly triggers a duplicate dynamic Google Fonts fetch.
2731
syncopate: '"Syncopate", sans-serif',
28-
space: '"Space Grotesk", sans-serif',
32+
spacegrotesk: '"Space Grotesk", sans-serif',
33+
'space grotesk': '"Space Grotesk", sans-serif', // handles spaced user input
34+
35+
// ── Aliases for common variations ───────────────────────────────────────
36+
firacode: '"Fira Code", monospace', // alias: fira is the canonical key
37+
'jetbrains mono': '"JetBrains Mono", monospace', // handles spaced user input
38+
39+
// ── Legacy keys for backward compatibility ──────────────────────────────
40+
inter: '"Inter", sans-serif',
41+
space: '"Space Grotesk", sans-serif', // old key for spacegrotesk
2942
} as const;
3043

3144
export function resolveFont(sanitizedFont?: string | null): string | null {

0 commit comments

Comments
 (0)