76 lines
2.1 KiB
TypeScript
76 lines
2.1 KiB
TypeScript
/** Shared font catalog safe for client and server bundles (no Node APIs). */
|
|
|
|
/** Max custom font upload size (10 MB). */
|
|
export const FONT_UPLOAD_MAX_BYTES = 10 * 1024 * 1024;
|
|
|
|
export const CURATED_FONTS = [
|
|
{
|
|
key: "inter",
|
|
label: "Inter",
|
|
cssFamily: "Inter",
|
|
googleCss: "Inter:wght@400;600",
|
|
file: "Inter-Regular.ttf",
|
|
},
|
|
{
|
|
key: "montserrat",
|
|
label: "Montserrat",
|
|
cssFamily: "Montserrat",
|
|
googleCss: "Montserrat:wght@400;600",
|
|
file: "Montserrat-Regular.ttf",
|
|
},
|
|
{
|
|
key: "roboto",
|
|
label: "Roboto",
|
|
cssFamily: "Roboto",
|
|
googleCss: "Roboto:wght@400;500",
|
|
file: "Roboto-Regular.ttf",
|
|
},
|
|
{
|
|
key: "oswald",
|
|
label: "Oswald",
|
|
cssFamily: "Oswald",
|
|
googleCss: "Oswald:wght@400;500",
|
|
file: "Oswald-Regular.ttf",
|
|
},
|
|
{
|
|
key: "playfair",
|
|
label: "Playfair Display",
|
|
cssFamily: "Playfair Display",
|
|
googleCss: "Playfair+Display:wght@400;600",
|
|
file: "PlayfairDisplay-Regular.ttf",
|
|
},
|
|
] as const;
|
|
|
|
export type CuratedFontKey = (typeof CURATED_FONTS)[number]["key"];
|
|
export type WatermarkFontKey = CuratedFontKey | "custom" | "system";
|
|
|
|
const CURATED_KEYS = new Set<string>(CURATED_FONTS.map((f) => f.key));
|
|
|
|
export function isCuratedFontKey(v: unknown): v is CuratedFontKey {
|
|
return typeof v === "string" && CURATED_KEYS.has(v);
|
|
}
|
|
|
|
export function isWatermarkFontKey(v: unknown): v is WatermarkFontKey {
|
|
return v === "custom" || v === "system" || isCuratedFontKey(v);
|
|
}
|
|
|
|
/**
|
|
* Escape an absolute font path for use inside an FFmpeg filtergraph `fontfile=` value.
|
|
* Paths are never passed through a shell; this only escapes filter special chars.
|
|
*/
|
|
export function sanitizeFontfileForFilter(absPath: string): string {
|
|
return absPath
|
|
.replace(/\\/g, "/")
|
|
.replace(/:/g, "\\:")
|
|
.replace(/'/g, "\\'")
|
|
.replace(/\[/g, "\\[")
|
|
.replace(/\]/g, "\\]");
|
|
}
|
|
|
|
export function googleFontsStylesheetUrl(keys: CuratedFontKey[]): string {
|
|
const families = CURATED_FONTS.filter((f) => keys.includes(f.key))
|
|
.map((f) => `family=${f.googleCss}`)
|
|
.join("&");
|
|
return `https://fonts.googleapis.com/css2?${families}&display=swap`;
|
|
}
|