import React from 'react' const RESOLUTION_TIERS = [ { label: '8K', width: 7680, height: 4320, tone: 'amber' }, { label: '5K', width: 5120, height: 2880, tone: 'violet' }, { label: '4K', width: 3840, height: 2160, tone: 'sky' }, { label: 'QHD', width: 2560, height: 1440, tone: 'emerald' }, { label: 'Full HD', width: 1920, height: 1080, tone: 'cyan' }, { label: 'HD', width: 1280, height: 720, tone: 'slate' }, ] const ASPECT_RATIOS = [ { label: '21:9', ratio: 21 / 9 }, { label: '16:10', ratio: 16 / 10 }, { label: '16:9', ratio: 16 / 9 }, { label: '3:2', ratio: 3 / 2 }, { label: '4:3', ratio: 4 / 3 }, { label: '1:1', ratio: 1 }, { label: '4:5', ratio: 4 / 5 }, { label: '3:4', ratio: 3 / 4 }, { label: '9:16', ratio: 9 / 16 }, ] const TONE_CLASSES = { amber: 'border-amber-400/25 bg-amber-400/10 text-amber-100', violet: 'border-violet-400/25 bg-violet-400/10 text-violet-100', sky: 'border-sky-400/25 bg-sky-400/10 text-sky-100', emerald: 'border-emerald-400/25 bg-emerald-400/10 text-emerald-100', cyan: 'border-cyan-400/25 bg-cyan-400/10 text-cyan-100', slate: 'border-white/10 bg-white/[0.04] text-white/80', } function ScreenIcon({ className }) { return ( ) } function RatioIcon({ className }) { return ( ) } function FormatIcon({ className, variant }) { if (variant === 'ultrawide') { return ( ) } if (variant === 'vertical') { return ( ) } return ( ) } function OrientationIcon({ className, orientation }) { if (orientation === 'square') { return ( ) } if (orientation === 'portrait') { return ( ) } return ( ) } function Badge({ label, tone, icon }) { return ( {icon} {label} ) } function pickResolutionTier(width, height) { const longSide = Math.max(width, height) const shortSide = Math.min(width, height) for (const tier of RESOLUTION_TIERS) { if (longSide >= tier.width && shortSide >= tier.height) { return tier } } return null } function pickOrientation(width, height) { if (width === height) { return { key: 'orientation-square', label: 'Square', tone: 'amber', icon: , isSquare: true, } } if (width > height) { return { key: 'orientation-landscape', label: 'Landscape', tone: 'emerald', icon: , isSquare: false, } } return { key: 'orientation-portrait', label: 'Portrait', tone: 'violet', icon: , isSquare: false, } } function pickAspectRatio(width, height) { const ratio = width / height let best = null for (const candidate of ASPECT_RATIOS) { const delta = Math.abs(ratio - candidate.ratio) / candidate.ratio if (delta > 0.03) { continue } if (best === null || delta < best.delta) { best = { ...candidate, delta } } } return best } function pickSemanticFormat(width, height, aspectRatio, orientation) { if (!orientation || orientation.isSquare) { return null } const ratio = width / height if (ratio >= 2.1) { return { key: 'semantic-ultrawide', label: 'Ultrawide', tone: 'sky', icon: , } } if (ratio <= 0.75) { return { key: 'semantic-vertical', label: 'Vertical', tone: 'violet', icon: , } } if (aspectRatio && ['4:3', '3:2', '16:10'].includes(aspectRatio.label)) { return { key: 'semantic-classic', label: 'Classic', tone: 'amber', icon: , } } return null } export function getArtworkFormatBadges(width, height) { if (!(width > 0 && height > 0)) { return [] } const badges = [] const orientation = pickOrientation(width, height) const resolutionTier = pickResolutionTier(width, height) if (resolutionTier) { badges.push({ key: `resolution-${resolutionTier.label}`, label: resolutionTier.label, tone: resolutionTier.tone, icon: , }) } if (orientation) { badges.push(orientation) } const aspectRatio = pickAspectRatio(width, height) const semanticFormat = pickSemanticFormat(width, height, aspectRatio, orientation) if (semanticFormat) { badges.push(semanticFormat) } if (aspectRatio && !orientation?.isSquare) { badges.push({ key: `ratio-${aspectRatio.label}`, label: aspectRatio.label, tone: 'slate', icon: , }) } return badges } export default function ArtworkFormatBadges({ width, height, className = '' }) { const badges = getArtworkFormatBadges(width, height) if (badges.length === 0) { return null } return (
{badges.map((badge) => ( ))}
) }