/** * Live H1–H6 scale preview shown under the Headings typography card. * Renders each sample in the actual selected font/weight/letter-spacing and * uses the ratio table for whichever scale (modular/linear) is selected, so * changing any of these controls is visible here immediately. Per-level * `overrides` (see section-fields.tsx) win over the computed scale value, * matching Dynamic_CSS::resolve_heading_sizes() on the PHP side. */ import { HEADING_LEVELS, HEADING_SCALE_RATIOS, scaleLength, toPx, } from './constants'; interface HeadingPreviewProps { baseSize: string; lineHeight: string; scale: string; familyCss: string; weight: string; letterSpacing: string; overrides?: Record< string, string >; } export default function HeadingPreview( { baseSize, lineHeight, scale, familyCss, weight, letterSpacing, overrides, }: HeadingPreviewProps ) { const ratios = HEADING_SCALE_RATIOS[ scale ] ?? HEADING_SCALE_RATIOS.modular; return (
{ HEADING_LEVELS.map( ( level ) => { const override = overrides?.[ level.key ]?.trim(); const size = override ? override : scaleLength( baseSize, ratios[ level.key ] ?? 1 ); const computedLineHeight = ( parseFloat( lineHeight ) + level.lineHeightDelta ).toFixed( 2 ); return (
{ level.label } { `${ Math.round( toPx( size ) ) }px/${ computedLineHeight }` }
); } ) }
); }