Spaces:
Sleeping

olokaflow / apps /server /src /services /fontService.ts
phucsd's picture
Deploy OlokaFlow Studio (Fliki Light UI + HyperFrames + OlokaTTS + Modal Cloud)
9713441 verified
Raw History Blame Contribute Delete
5.61 kB
export interface VietnameseFontSpec {
id: string;
family: string;
category: 'sans-serif' | 'display' | 'serif' | 'monospace';
weights: number[];
googleCssUrl: string;
recommendedLineHeightHeading: number;
recommendedLineHeightBody: number;
description: string;
}
export const VIETNAMESE_FONTS: VietnameseFontSpec[] = [
{
id: 'be-vietnam-pro',
family: 'Be Vietnam Pro',
category: 'sans-serif',
weights: [400, 500, 600, 700, 800],
googleCssUrl: 'https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:ital,wght@0,400;0,500;0,600;0,700;0,800;1,400&subset=vietnamese&display=block',
recommendedLineHeightHeading: 1.28,
recommendedLineHeightBody: 1.55,
description: 'Font thiết kế riêng cho Tiếng Việt — dấu thanh cân đối hoàn hảo cho cả tiêu đề & phụ đề',
},
{
id: 'plus-jakarta-sans',
family: 'Plus Jakarta Sans',
category: 'sans-serif',
weights: [400, 500, 600, 700, 800],
googleCssUrl: 'https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&subset=vietnamese&display=block',
recommendedLineHeightHeading: 1.26,
recommendedLineHeightBody: 1.55,
description: 'Phong cách SaaS & Công nghệ hiện đại, hình học sắc nét',
},
{
id: 'space-grotesk',
family: 'Space Grotesk',
category: 'display',
weights: [500, 600, 700],
googleCssUrl: 'https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&subset=vietnamese&display=block',
recommendedLineHeightHeading: 1.25,
recommendedLineHeightBody: 1.5,
description: 'Tiêu đề số liệu, biểu đồ, công nghệ & AI cực kỳ nổi bật',
},
{
id: 'inter',
family: 'Inter',
category: 'sans-serif',
weights: [400, 500, 600, 700, 800],
googleCssUrl: 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&subset=vietnamese&display=block',
recommendedLineHeightHeading: 1.25,
recommendedLineHeightBody: 1.55,
description: 'Chuẩn giao diện UI/UX trung tính, dễ đọc trên mọi kích thước màn hình',
},
{
id: 'montserrat',
family: 'Montserrat',
category: 'display',
weights: [600, 700, 800, 900],
googleCssUrl: 'https://fonts.googleapis.com/css2?family=Montserrat:wght@600;700;800;900&subset=vietnamese&display=block',
recommendedLineHeightHeading: 1.28,
recommendedLineHeightBody: 1.5,
description: 'Mạnh mẽ, dày dặn, cực hợp cho Hook TikTok/Reels và Poster quảng cáo',
},
{
id: 'playfair-display',
family: 'Playfair Display',
category: 'serif',
weights: [600, 700, 800],
googleCssUrl: 'https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,600;0,700;0,800;1,600&subset=vietnamese&display=block',
recommendedLineHeightHeading: 1.32,
recommendedLineHeightBody: 1.6,
description: 'Sang trọng, cổ điển (Editorial, Mỹ phẩm, Thời trang, Bất động sản cao cấp)',
},
{
id: 'jetbrains-mono',
family: 'JetBrains Mono',
category: 'monospace',
weights: [400, 600, 700],
googleCssUrl: 'https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;700&subset=vietnamese&display=block',
recommendedLineHeightHeading: 1.3,
recommendedLineHeightBody: 1.5,
description: 'Font lập trình, Terminal, thông số kỹ thuật & nhãn dữ liệu',
},
{
id: 'oswald',
family: 'Oswald',
category: 'display',
weights: [500, 600, 700],
googleCssUrl: 'https://fonts.googleapis.com/css2?family=Oswald:wght@500;600;700&subset=vietnamese&display=block',
recommendedLineHeightHeading: 1.28,
recommendedLineHeightBody: 1.45,
description: 'Chữ cao hẹp, tối ưu không gian cho màn hình dọc 9:16',
},
{
id: 'chakra-petch',
family: 'Chakra Petch',
category: 'display',
weights: [500, 600, 700],
googleCssUrl: 'https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@500;600;700&subset=vietnamese&display=block',
recommendedLineHeightHeading: 1.26,
recommendedLineHeightBody: 1.5,
description: 'Phong cách Gaming, Cyberpunk, Phần cứng & Xe công nghệ',
},
];
export function getFontHeadLinksHtml(families: string[] = ['Be Vietnam Pro', 'Space Grotesk', 'JetBrains Mono']): string {
const normalized = new Set(families.map((f) => f.toLowerCase().trim()));
normalized.add('be vietnam pro');
const selected = VIETNAMESE_FONTS.filter((f) => normalized.has(f.family.toLowerCase()));
const links = selected
.map((f) => `<link rel="stylesheet" href="${f.googleCssUrl}" crossorigin="anonymous" />`)
.join('\n ');
return `<!-- Render-Safe Vietnamese Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="anonymous" />
${links}`;
}
export function getVietnameseTypographyGuardCss(headingFont = 'Space Grotesk', bodyFont = 'Be Vietnam Pro'): string {
return `
:root {
--font-heading: '${headingFont}', 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
--font-body: '${bodyFont}', 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
--font-mono: 'JetBrains Mono', monospace;
}
/* Guard Vietnamese Stacked Diacritics (Ấ, Ể, Ỗ, Ự) from clipping */
h1, h2, h3, .vn-heading {
font-family: var(--font-heading);
line-height: 1.28 !important;
padding-top: 0.06em;
padding-bottom: 0.06em;
overflow: visible;
}
body, p, span, div, .vn-body {
font-family: var(--font-body);
}
`.trim();
}