const GENERIC_FAMILIES = new Set([ "cursive", "emoji", "fangsong", "fantasy", "inherit", "initial", "math", "monospace", "revert", "revert-layer", "sans-serif", "serif", "system-ui", "ui-monospace", "ui-rounded", "ui-sans-serif", "ui-serif", "unset", ]); const isQuotedFamily = (family: string): boolean => /^(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')$/u.test(family); const quoteFamily = (family: string): string => { const trimmed = family.trim(); const normalized = trimmed.toLowerCase(); if (!trimmed) return "inherit"; if (GENERIC_FAMILIES.has(normalized)) return normalized; if (isQuotedFamily(trimmed)) return trimmed; return `"${trimmed .replace(/\\/gu, "\\\\") .replace(/"/gu, '\\"') .replace(/[\n\r\f]/gu, " ")}"`; }; /** Quote reviewed font-family values before they enter CSS text or variables. */ export const cssFontFamily = (value: unknown): string => { const source = typeof value === "string" ? value.trim() : ""; if (!source) return "inherit"; return source.split(",").map(quoteFamily).join(", "); };