import React from 'react'; import { cn } from '../../ui/utils'; import { buildNutritionFactsViewModel, DEFAULT_NUTRITION_FOOTER_NOTE, NUTRITION_AMOUNT_COL_WIDTH, NUTRITION_BODY_FONT_SIZE, NUTRITION_PCT_COL_WIDTH, type NutritionDivider, type NutritionFactsViewModel, } from '../../../lib/nutritionFactsLayout'; /** 双下划线两线之间的间距(px) */ const DOUBLE_LINE_GAP_PX = 3; /** FreightSans 仅有 Bold 字重;正文区改用常规字体以保证 12px 非加粗展示 */ function nutritionPanelBodyFontFamily(configured: string): string { const lower = String(configured ?? '').toLowerCase(); if (lower.includes('freightsans') || lower.includes('bold')) { return 'Roboto, Arial, sans-serif'; } return configured || 'Roboto, Arial, sans-serif'; } /** 单/双下划线:双线之间留空,不重叠 */ function NutritionDivider({ kind }: { kind: Exclude }) { if (kind === 'thin') { return
; } return (
); } export function NutritionFactsPanel({ cfg, fontFamily, className, }: { cfg: Record; fontFamily: string; className?: string; }) { const model = buildNutritionFactsViewModel(cfg); const bodyFont = nutritionPanelBodyFontFamily(fontFamily); const bodySize = NUTRITION_BODY_FONT_SIZE; const footerSize = Math.max(8, Math.round(bodySize * 0.67)); return (
Nutrition Facts
{model.caloriesLabel} {model.caloriesAmountText || model.caloriesValue}
{model.rows.map((row) => ( ))}

{DEFAULT_NUTRITION_FOOTER_NOTE.split(/(\b2000\b)/).map((part, i) => part === '2000' ? ( 2000 ) : ( part ), )}

); } function NutrientRow({ row, bodySize, }: { row: { key: string; label: string; amountText: string; dailyValueText: string; labelBold: boolean; indent: boolean; dividerAfter: NutritionDivider; }; bodySize: number; }) { return (
{row.label} {row.amountText} {row.dailyValueText}
{row.dividerAfter !== 'none' ? : null}
); } function HeaderRow({ label, value, size, divider, }: { label: string; value: string; size: number; divider: NutritionDivider; }) { return (
{label} {value}
{divider !== 'none' ? : null}
); } export { buildNutritionFactsViewModel, type NutritionFactsViewModel };