export interface EditorFontOption { /** Translation key resolved via useLabels().getLabel(). */ labelKey: string /** Stable select option value (no commas — safe for Element Plus). */ value: string /** Valid CSS font-family stack applied to TipTap content. */ css: string } /** Fonts available in IvyEditor. */ export const EDITOR_FONT_FAMILIES: EditorFontOption[] = [ { labelKey: 'editor_font_inter', value: 'inter', css: 'Inter' }, { labelKey: 'editor_font_comic_sans_ms', value: 'comic-sans-ms', css: 'Comic Sans MS' }, { labelKey: 'editor_font_sans_serif', value: 'sans-serif', css: 'sans-serif' }, { labelKey: 'editor_font_serif', value: 'serif', css: 'serif' }, { labelKey: 'editor_font_monospace', value: 'monospace', css: 'monospace' }, { labelKey: 'editor_font_cursive', value: 'cursive', css: 'cursive' }, ] export const DEFAULT_EDITOR_FONT_FAMILY = 'sans-serif' export function getEditorFontCss(value: string): string | undefined { return EDITOR_FONT_FAMILIES.find((option) => option.value === value)?.css } export function getDefaultEditorFontCss(): string { return getEditorFontCss(DEFAULT_EDITOR_FONT_FAMILY) ?? DEFAULT_EDITOR_FONT_FAMILY } /** Match a stored font-family attribute to a toolbar option (legacy values included). */ export function resolveEditorFontOption( fontFamily: string | null | undefined, ): EditorFontOption | null { if (!fontFamily) { return null } const normalized = normalizeEditorFontKey(fontFamily) const exact = EDITOR_FONT_FAMILIES.find( (option) => normalizeEditorFontKey(option.css) === normalized || option.value === normalized, ) if (exact) { return exact } const legacyMap: Record = { inter: 'inter', 'comic sans ms': 'comic-sans-ms', 'sans serif': 'sans-serif', } const legacyValue = legacyMap[normalized] if (legacyValue) { return EDITOR_FONT_FAMILIES.find((option) => option.value === legacyValue) ?? null } return null } function normalizeEditorFontKey(value: string): string { return value.trim().replace(/['"]/g, '').toLowerCase() }