/** * Block Renderer - Project Friction * Converts a block array into HTML strings. * Used by both the main exhibit (app.js) and the builder preview. */ class BlockRenderer { static render(blocks) { if (!Array.isArray(blocks)) return ''; return blocks.map(function(block) { return BlockRenderer.renderBlock(block); }).join('\n'); } static renderBlock(block) { if (!block || !block.type) return ''; switch (block.type) { case 'heading': return BlockRenderer.renderHeading(block); case 'paragraph': return BlockRenderer.renderParagraph(block); case 'image': return BlockRenderer.renderImage(block); case 'quote': return BlockRenderer.renderQuote(block); case 'gallery': return BlockRenderer.renderGallery(block); case 'grid4': return BlockRenderer.renderGrid4(block); case 'statistics': return BlockRenderer.renderStatistics(block); case 'map-button': return BlockRenderer.renderMapButton(block); default: return ''; } } static renderHeading(block) { var level = Math.min(Math.max(parseInt(block.level) || 2, 1), 6); return '' + (block.text || '') + ''; } static renderParagraph(block) { return '

' + (block.text || '') + '

'; } static renderImage(block) { return '
' + '' + (block.alt || '') + '' + (block.caption ? '
' + block.caption + '
' : '') + '
'; } static renderQuote(block) { return '
' + '

' + (block.text || '') + '

' + (block.author ? '— ' + block.author + '' : '') + '
'; } static renderGallery(block) { var images = block.images || []; var items = images.map(function(img) { return ''; }).join(''); return ''; } static renderGrid4(block) { var images = (block.images || []).slice(0, 4); var items = images.map(function(img) { return '
' + '' + (img.alt || '') + '' + (img.caption ? '
' + img.caption + '
' : '') + '
'; }).join(''); return '
' + items + '
'; } static renderStatistics(block) { var stats = block.stats || []; var items = stats.map(function(s) { return '
' + '
' + (s.number || '') + '
' + '
' + (s.label || '') + '
' + '
'; }).join(''); return '
' + items + '
'; } static renderMapButton(block) { return '
' + '
'; } }