import QRCode from 'qrcode'; import { appearanceStyle, cssText, frameStyle, initialFrame } from './free-layout.js'; export const blockTypes = { text: 'Text', image: 'Bild', gallery: 'Galerie', button: 'Button', qr: 'QR-Code', video: 'Video', social: 'Social-Media-Link', shape: 'Form', html: 'HTML & CSS', }; export function makeBlock(type) { const defaults = { text: { text: 'Hier steht dein Text.', style: 'body', align: 'left' }, image: { mediaId: '', alt: '', height: 46 }, gallery: { mediaIds: [], height: 29 }, button: { text: 'Mehr erfahren', url: '' }, qr: { text: '', url: '' }, video: { mediaId: '', posterMediaId: '', text: '' }, social: { text: 'Instagram', url: '' }, shape: { shape: 'rectangle', appearance: { fill: '#ddd7ff' } }, html: { markup: '
Hier kannst du HTML und CSS einfügen.
' }, }; return { id: crypto.randomUUID(), type, width: 'full', ...defaults[type] }; } export function makePage(title = 'Neue Seite') { return { id: crypto.randomUUID(), title, layout: 'free', background: '#fffefa', color: '#20202b', blocks: [] }; } export function escapeHtml(value = '') { return String(value).replace(/[&<>"']/g, (character) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''', })[character]); } export function safeUrl(value, webOnly = false) { try { const parsed = new URL(value); return (webOnly ? ['https:', 'http:'] : ['https:', 'http:', 'mailto:', 'tel:']).includes(parsed.protocol) ? parsed.href : ''; } catch { return ''; } } export function mediaRefs(draft) { return [draft.cover, ...draft.pages.flatMap((page) => page.blocks.flatMap((block) => block.type === 'gallery' ? block.mediaIds : [block.mediaId, block.posterMediaId]))].filter(Boolean); } export function pageStyle(page) { return `--paper:${page.background};--ink:${page.color}`; } export async function renderBlock(block, mediaUrl, forPdf = false) { const text = escapeHtml(block.text); const media = (id) => escapeHtml(mediaUrl(id)); const href = escapeHtml(safeUrl(block.url, block.type === 'social')); const link = (label, kind) => href ? `${label}` : `${label || 'Link hinzufügen'}`; const placeholder = (label) => `