Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
},
"dependencies": {
"@shotstack/schemas": "1.11.0",
"@shotstack/shotstack-canvas": "^2.8.3",
"@shotstack/shotstack-canvas": "^2.9.0",
"howler": "^2.2.4",
"mediabunny": "^1.11.2",
"opentype.js": "^1.3.4",
Expand Down
25 changes: 9 additions & 16 deletions src/core/fonts/font-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
* Shared font configuration for text and rich-text players
*/

import { parseFontFamily as parseCanvasFontFamily } from "@shotstack/shotstack-canvas";

import { GOOGLE_FONTS_BY_FILENAME, GOOGLE_FONTS_BY_NAME } from "./google-fonts";

const FONT_CDN = "https://templates.shotstack.io/basic/asset/font";

/** Font family name to file path mapping (variable fonts where available, matching Edit API) */
/** Font family name to its CDN file path (variable fonts where available). */
export const FONT_PATHS: Record<string, string> = {
Arapey: `${FONT_CDN}/arapey-regular.ttf`,
"Clear Sans": `${FONT_CDN}/clearsans-regular.ttf`,
Expand All @@ -31,7 +33,7 @@ export const FONT_ALIASES: Record<string, string> = {
WorkSans: "Work Sans"
};

/** Weight modifier suffixes mapped to CSS font-weight values */
/** Font weight modifier names mapped to their CSS numeric weight (e.g. "ExtraBold" → 800). */
export const WEIGHT_MODIFIERS: Record<string, number> = {
Thin: 100,
ExtraLight: 200,
Expand All @@ -45,22 +47,13 @@ export const WEIGHT_MODIFIERS: Record<string, number> = {
};

/**
* Parse a font family name to extract base family and weight
* e.g., "Montserrat ExtraBold" → { baseFontFamily: "Montserrat", fontWeight: 800 }
* Case-insensitive matching for weight modifiers (handles "Extrabold", "ExtraBold", etc.)
* Parse a font family name into its base family and CSS weight.
* e.g. "Montserrat ExtraBold" → { baseFontFamily: "Montserrat", fontWeight: 800 }.
* Surrounding whitespace is trimmed, so "Montserrat ExtraBold " parses to the same result.
*/
export function parseFontFamily(fontFamily: string): { baseFontFamily: string; fontWeight: number } {
const lowerFamily = fontFamily.toLowerCase();
for (const [modifier, weight] of Object.entries(WEIGHT_MODIFIERS)) {
const lowerModifier = ` ${modifier.toLowerCase()}`;
if (lowerFamily.endsWith(lowerModifier)) {
return {
baseFontFamily: fontFamily.slice(0, -modifier.length - 1),
fontWeight: weight
};
}
}
return { baseFontFamily: fontFamily, fontWeight: 400 };
const { family, weight } = parseCanvasFontFamily(fontFamily);
return { baseFontFamily: family, fontWeight: Number(weight) };
}

/**
Expand Down
Loading