<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Biophilic Email Toolkit</title>
<!-- Google Fonts: Playfair Display (Serif) & Lora (Body) for that Wabi-Sabi feel -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,500;1,400&family=Playfair+Display:wght@400;600;700&display=swap" rel="stylesheet">
<style>
:root {
/* Earthy Palette */
--bg-cream: #F4F1DE;
--paper-white: #FFFCF9;
--charcoal: #363635;
--slate: #5C5858;
--terracotta: #D98E58;
--sage: #8A9B8F;
--moss: #5E705F;
--shadow: rgba(68, 64, 60, 0.15);
/* Spacing & Radius */
--radius-organic: 24px;
--radius-lg: 16px;
--radius-md: 8px;
--radius-sm: 4px;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Lora', serif;
background-color: var(--bg-cream);
color: var(--charcoal);
min-height: 100vh;
overflow-x: hidden;
/* Paper G Noise Texture */
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.08'/%3E%3C/svg%3E");
}
/* Dappled Light Effect (Fixed div updated by JS) */
#dappled-light {
position: fixed;
top: 0; left: 0;
width: 100vw; height: 100vh;
background: radial-gradient(circle at 50% 50%, rgba(212, 198, 165, 0.3) 0%, transparent 60%);
pointer-events: none;
z-index: 0;
mix-blend-mode: overlay;
transition: background 0.2s ease-out;
opacity: 0.6;
}
/* Layout */
.app-container {
position: relative;
z-index: 1;
max-width: 1600px;
margin: 0 auto;
padding: 2rem;
display: grid;
grid-template-columns: 260px 1fr 320px;
gap: 2rem;
height: 100vh;
}
@media (max-width: 1200px) {
.app-container {
grid-template-columns: 240px 1fr;
grid-template-rows: 1fr auto;
}
.inspector-panel {
grid-column: 1 / -1;
height: auto;
border-top: 1px solid rgba(0,0,0,0.05);
}
}
@media (max-width: 900px) {
.app-container {
grid-template-columns: 1fr;
padding: 1rem;
height: auto;
}
.component-panel {
position: static;
margin-bottom: 1rem;
}
.preview-area {
min-height: 600px;
}
}
/* Typography */
h1, h2, h3 { font-family: 'Playfair Display', serif; }
.label {
font-size: 0.85rem;
text-transform: uppercase;
letter-spacing: 0.05em;
color: var(--slate);
margin-bottom: 0.5rem;
display: block;
}
/* Panels: Glassmorphism (Paper-like) */
.panel {
background: rgba(255, 252, 249, 0.9);
backdrop-filter: blur(12px);
border-radius: var(--radius-lg);
border: 1px solid rgba(255,255,255,0.6);
box-shadow: 0 10px 30px var(--shadow);
padding: 1.5rem;
display: flex;
flex-direction: column;
overflow: hidden;
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
/* Component Palette (Sidebar) */
.component-panel .panel-title {
font-size: 1.2rem;
margin-bottom: 1.5rem;
color: var(--moss);
font-weight: 600;
}
.component-list {
display: flex;
flex-direction: column;
gap: 0.75rem;
overflow-y: auto;
flex: 1;
}
.add-btn {
display: flex;
align-items: center;
gap: 0.75rem;
padding: 1rem;
background: var(--paper-white);
border: 1px solid rgba(0,0,0,0.08);
border-radius: var(--radius-md);
cursor: pointer;
color: var(--charcoal);
font-family: 'Lora', serif;
font-size: 0.95rem;
transition: all 0.2s ease-out;
text-align: left;
}
.add-btn:hover {
background: var(--bg-cream);
border-color: var(--terracotta);
transform: translateX(4px);
}
.add-btn .icon {
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
background: var(--terracotta);
color: white;
border-radius: 50%;
font-size: 1.2rem;
}
/* Preview Area (Center) */
.preview-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
padding: 0 0.5rem;
}
.preview-header h2 { font-size: 1.4rem; color: var(--moss); }
.code-tabs {
display: flex;
gap: 0.5rem;
}
.tab {
padding: 0.5rem 1rem;
border: none;
background: transparent;
color: var(--slate);
font-family: 'Lora', serif;
cursor: pointer;
border-radius: var(--radius-sm);
transition: all 0.2s;
border-bottom: 2px solid transparent;
}
.tab.active {
background: rgba(138, 155, 143, 0.1);
color: var(--moss);
border-bottom-color: var(--moss);
font-weight: 600;
}
.viewport-iframe {
flex: 1;
background: white;
border: 1px solid rgba(0,0,0,0.08);
border-radius: var(--radius-md);
overflow: hidden;
position: relative;
/* Inner shadow for depth */
box-shadow: inset 0 0 40px rgba(0,0,0,0.02);
}
.viewport-iframe iframe {
width: 100%;
height: 100%;
border: none;
background: white;
}
.code-display {
flex: 1;
background: var(--charcoal);
color: #ccc;
border-radius: var(--radius-md);
padding: 1rem;
font-family: 'Courier New', monospace;
font-size: 0.85rem;
overflow: auto;
white-space: pre-wrap;
display: none; /* Hidden by default */
line-height: 1.5;
}
.code-display.active { display: block; }
/* Inspector (Right) */
.inspector-panel h3 {
font-size: 1.1rem;
margin-bottom: 1.5rem;
color: var(--terracotta);
}
.component-list-preview {
margin-bottom: 2rem;
max-height: 200px;
overflow-y: auto;
border: 1px solid rgba(0,0,0,0.08);
border-radius: var(--radius-md);
}
.list-item {
padding: 0.75rem 1rem;
cursor: pointer;
border-bottom: 1px solid rgba(0,0,0,0.05);
display: flex;
justify-content: space-between;
align-items: center;
font-size: 0.9rem;
}
.list-item:hover { background: rgba(212, 198, 165, 0.2); }
.list-item.selected { background: rgba(212, 198, 165, 0.4); border-left: 3px solid var(--terracotta); }
.order-controls button {
background: none;
border: none;
cursor: pointer;
color: var(--slate);
padding: 2px;
}
.order-controls button:hover { color: var(--terracotta); }
.form-group { margin-bottom: 1.25rem; }
.form-control {
width: 100%;
padding: 0.75rem;
border: 1px solid rgba(0,0,0,0.1);
border-radius: var(--radius-sm);
font-family: 'Lora', serif;
font-size: 0.95rem;
background: rgba(255,255,255,0.8);
transition: border-color 0.2s;
}
.form-control:focus {
outline: none;
border-color: var(--terracotta);
background: #fff;
}
textarea.form-control {
min-height: 80px;
resize: vertical;
}
.property-group {
display: none;
animation: fadeIn 0.4s ease;
}
.property-group.active { display: block; }
/* Buttons */
.btn-primary {
background: var(--terracotta);
color: white;
border: none;
padding: 0.8rem 1.5rem;
border-radius: 30px; /* Organic pill */
font-family: 'Playfair Display', serif;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
box-shadow: 0 4px 12px rgba(217, 142, 88, 0.3);
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 6px 16px rgba(217, 142, 88, 0.4);
}
/* Toast */
#toast {
position: fixed;
bottom: 2rem;
left: 50%;
transform: translateX(-50%) translateY(100px);
background: var(--charcoal);
color: white;
padding: 1rem 2rem;
border-radius: 50px;
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
font-family: 'Playfair Display', serif;
opacity: 0;
transition: all 0.6s cubic-bezier(0.22, 1, 0.36, 1);
z-index: 1000;
display: flex;
align-items: center;
gap: 0.5rem;
}
#toast.show {
transform: translateX(-50%) translateY(0);
opacity: 1;
}
/* Animations */
@keyframes fadeIn {
from { opacity: 0; transform: translateY(5px); }
to { opacity: 1; transform: translateY(0); }
}
/* Custom scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(90, 112, 95, 0.3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(90, 112, 95, 0.6); }
</style>
</head>
<body>
<div id="dappled-light"></div>
<div class="app-container">
<!-- Sidebar: Components -->
<aside class="panel component-panel">
<h2 class="panel-title">Components</h2>
<div class="component-list">
<button class="add-btn" onclick="addComponent('header')">
<span class="icon">H</span>
Header
</button>
<button class="add-btn" onclick="addComponent('text')">
<span class="icon">T</span>
Text Block
</button>
<button class="add-btn" onclick="addComponent('button')">
<span class="icon">B</span>
Button
</button>
<button class="add-btn" onclick="addComponent('image')">
<span class="icon">I</span>
Image
</button>
<button class="add-btn" onclick="addComponent('divider')">
<span class="icon">—</span>
Divider
</button>
<button class="add-btn" onclick="addComponent('spacer')">
<span class="icon">S</span>
Spacer
</button>
<button class="add-btn" onclick="addComponent('footer')">
<span class="icon">F</span>
Footer
</button>
</div>
</aside>
<!-- Main: Preview & Code -->
<main class="preview-area">
<div class="preview-header">
<h2>Live Preview</h2>
<div class="code-tabs">
<button class="tab active" onclick="switchTab('html')">HTML</button>
<button class="tab" onclick="switchTab('mjml')">MJML</button>
<button class="tab" onclick="switchTab('amp')">AMP</button>
</div>
</div>
<div class="viewport-iframe">
<iframe id="preview-frame"></iframe>
</div>
<!-- Simulated Code Outputs -->
<div id="code-html" class="code-display active"></div>
<div id="code-mjml" class="code-display"></div>
<div id="code-amp" class="code-display"></div>
</main>
<!-- Right: Inspector -->
<aside class="panel inspector-panel" id="inspector">
<h3>Properties</h3>
<!-- Component List within email (Mini-structure) -->
<div class="component-list-preview" id="component-list-inspector">
<!-- Populated by JS -->
</div>
<!-- Dynamic Form Container -->
<div id="dynamic-form">
<p style="color:var(--slate); font-size:0.9rem; text-align:center; margin-top:2rem;">
Select a component to edit its natural attributes.
</p>
</div>
</aside>
</div>
<!-- Toast Notification -->
<div id="toast">
<span>✓</span> <span id="toast-msg">Action completed</span>
</div>
<script>
/**
* Biophilic Email Toolkit Engine
* - State-based rendering
* - Component generation for HTML, MJML, AMP
*/
// --- State Management ---
const state = {
components: [], // { id, type, props: {} }
selectedId: null
};
const defaultProps = {
header: { text: 'The Morning Dew', align: 'center', color: '#363635', font_size: '28px' },
text: { content: 'A moment of calm in the digital storm. Embrace the organic flow of design.', align: 'left', color: '#5C5858', line_height: '1.6' },
button: { text: 'Explore Nature', url: '#', align: 'center', bg_color: '#D98E58', text_color: '#FFFFFF', radius: '30px' },
image: { src: 'https://picsum.photos/seed/nature1/600/300', alt: 'Study of light and shadow', align: 'center', width: '100%' },
divider: { color: '#E5E5E5', spacing: '20px' },
spacer: { height: '30px' },
footer: { text: '© 2023 Biophilic Designs. All rights reserved.', align: 'center', color: '#8A9B8F', font_size: '12px' }
};
// --- DOM Elements ---
const previewFrame = document.getElementById('preview-frame');
const codeHtml = document.getElementById('code-html');
const codeMjml = document.getElementById('code-mjml');
const codeAmp = document.getElementById('code-amp');
const inspectorList = document.getElementById('component-list-inspector');
const dynamicForm = document.getElementById('dynamic-form');
// --- Rendering Engine ---
function renderAll() {
const html = renderHTML();
const mjml = renderMJML();
const amp = renderAMP();
// Update iframe
const doc = previewFrame.contentDocument;
doc.open();
doc.write(`
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body { margin: 0; padding: 0; font-family: 'Lora', serif; -webkit-font-smoothing: antialiased; }
img { max-width: 100%; height: auto; display: block; border: 0; }
table { border-spacing: 0; width: 100%; }
</style>
</head>
<body>${html}</body>
</html>
`);
doc.close();
// Update code views
codeHtml.textContent = formatCode(html);
codeMjml.textContent = formatCode(mjml);
codeAmp.textContent = formatCode(amp);
// Update Inspector List
renderInspectorList();
}
function formatCode(code) {
// Very basic formatting for readability
let formatted = '';
let pad = 0;
const lines = code.split('\n');
for (let line of lines) {
if (line.trim() === '') {
formatted += '\n';
continue;
}
let indent = 0;
if (line.includes('</')) pad -= 1;
indent = pad * 2;
if (line.includes('<') && !line.includes('</') && !line.includes('/>')) pad += 1;
formatted += ' '.repeat(indent) + line + '\n';
}
return formatted;
}
// --- Component Generators ---
function getComponentHTML(comp) {
const p = comp.props;
switch(comp.type) {
case 'header':
return `<table width="100%" cellpadding="0" cellspacing="0"><tr><td align="${p.align}" style="font-family: 'Playfair Display', serif; font-size: ${p.font_size}; color: ${p.color}; padding: 20px 0;">${p.text}</td></tr></table>`;
case 'text':
return `<table width="100%" cellpadding="0" cellspacing="0"><tr><td align="${p.align}" style="font-family: 'Lora', serif; font-size: 16px; line-height: ${p.line_height}; color: ${p.color}; padding-bottom: 20px;">${p.content}</td></tr></table>`;
case 'button':
return `<table width="100%" cellpadding="0" cellspacing="0"><tr><td align="${p.align}" style="padding-bottom: 20px;"><a href="${p.url}" style="background-color: ${p.bg_color}; color: ${p.text_color}; display: inline-block; padding: 12px 30px; border-radius: ${p.radius}; text-decoration: none; font-family: 'Playfair Display', serif; font-weight: 600;">${p.text}</a></td></tr></table>`;
case 'image':
return `<table width="100%" cellpadding="0" cellspacing="0"><tr><td align="${p.align}" style="padding-bottom: 20px;"><img src="${p.src}" alt="${p.alt}" style="width: ${p.width}; border-radius: 8px; display: block;"></td></tr></table>`;
case 'divider':
return `<table width="100%" cellpadding="0" cellspacing="0"><tr><td style="padding: ${p.spacing} 0;"><div style="width: 100%; height: 1px; background-color: ${p.color};"></div></td></tr></table>`;
case 'spacer':
return `<table width="100%" cellpadding="0" cellspacing="0"><tr><td height="${p.height}" style="font-size: 0; line-height: 0;"> </td></tr></table>`;
case 'footer':
return `<table width="100%" cellpadding="0" cellspacing="0"><tr><td align="${p.align}" style="font-family: 'Lora', serif; font-size: ${p.font_size}; color: ${p.color}; padding-top: 30px; border-top: 1px solid #eee;">${p.text}</td></tr></table>`;
default:
return '';
}
}
// Returns the full MJML structure based on state
function renderMJML() {
const body = state.components.map(c => {
const p = c.props;
switch(c.type) {
case 'header': return `<mj-section><mj-column><mj-text font-family="Playfair Display, serif" font-size="${parseInt(p.font_size)}" color="${p.color}" align="${p.align}">${p.text}</mj-text></mj-column></mj-section>`;
case 'text': return `<mj-section><mj-column><mj-text font-family="Lora, serif" line-height="${p.line_height}" color="${p.color}" align="${p.align}">${p.content}</mj-text></mj-column></mj-section>`;
case 'button': return `<mj-section><mj-column><mj-button href="${p.url}" background-color="${p.bg_color}" color="${p.text_color}" align="${p.align}" border-radius="${parseInt(p.radius)}">${p.text}</mj-button></mj-column></mj-section>`;
case 'image': return `<mj-section><mj-column><mj-image src="${p.src}" alt="${p.alt}" align="${p.align}" width="${p.width}" border-radius="8px"></mj-image></mj-column></mj-section>`;
case 'divider': return `<mj-section><mj-column><mj-divider border-color="${p.color}" border-width="1px" padding="${p.spacing} 0"></mj-divider></mj-column></mj-section>`;
case 'spacer': return `<mj-section><mj-column><mj-spacer height="${p.height}"></mj-spacer></mj-column></mj-section>`;
case 'footer': return `<mj-section><mj-column><mj-text font-family="Lora, serif" font-size="${parseInt(p.font_size)}" color="${p.color}" align="${p.align}" padding-top="30px" border-top="1px solid #eeeeee">${p.text}</mj-text></mj-column></mj-section>`;
default: return '';
}
}).join('\n ');
return `<?xml version="1.0" encoding="UTF-8"?>
<mjml>
<mj-head>
<mj-attributes>
<mj-all font-family="'Lora', serif"></mj-all>
</mj-attributes>
<mj-style inline="inline">
h1 { font-family: 'Playfair Display', serif; }
</mj-style>
</mj-head>
<mj-body background-color="#F4F1DE">
<mj-container max-width="600px">
${body}
</mj-container>
</mj-body>
</mjml>`;
}
function renderAMP() {
const head = `<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<style amp-custom>
body { font-family: 'Lora', serif; color: #363635; line-height: 1.6; background: #F4F1DE; margin: 0; padding: 0; }
.container { max-width: 600px; margin: 0 auto; background: white; padding: 20px; box-shadow: 0 4px 10px rgba(0,0,0,0.05); }
h1 { font-family: 'Playfair Display', serif; margin: 0 0 20px; font-size: 28px; }
p { margin: 0 0 20px; }
.btn { display: inline-block; padding: 12px 30px; border-radius: 30px; text-decoration: none; font-weight: bold; font-family: 'Playfair Display', serif; }
img { max-width: 100%; height: auto; border-radius: 8px; }
.footer { margin-top: 30px; padding-top: 20px; border-top: 1px solid #eee; font-size: 12px; color: #8A9B8F; text-align: center; }
</style>
</head>`;
const bodyComponents = state.components.map(c => {
const p = c.props;
switch(c.type) {
case 'header': return `<div style="text-align: ${p.align}"><h1 style="color: ${p.color}; font-size: ${p.font_size}">${p.text}</h1></div>`;
case 'text': return `<p style="color: ${p.color}; line-height: ${p.line_height}; text-align: ${p.align}">${p.content}</p>`;
case 'button': return `<div style="text-align: ${p.align}; margin-bottom: 20px;"><a href="${p.url}" class="btn" style="background-color: ${p.bg_color}; color: ${p.text_color}">${p.text}</a></div>`;
case 'image': return `<div style="text-align: ${p.align}; margin-bottom: 20px;"><img src="${p.src}" alt="${p.alt}" style="width: ${p.width}"></div>`;
case 'divider': return `<div style="height: ${p.spacing}"></div><hr style="border: 0; border-top: 1px solid ${p.color}; margin: 0 0 20px;">`;
case 'spacer': return `<div style="height: ${p.height}"></div>`;
case 'footer': return `<div class="footer" style="text-align: ${p.align}; color: ${p.color}; font-size: ${p.font_size}">${p.text}</div>`;
default: return '';
}
}).join('\n ');
return `<!doctype html>
<html ⚡4email>
${head}
<body>
<div class="container">
${bodyComponents}
</div>
</body>
</html>`;
}
function renderHTML() {
return `<!-- EMILE NATURE TOOLKIT OUTPUT -->
<table width="100%" cellpadding="0" cellspacing="0" style="background-color: #F4F1DE; padding: 40px 0;">
<tr>
<td align="center">
<table width="600" cellpadding="0" cellspacing="0" style="background: #FFFCF9; border-radius: 12px; overflow: hidden; box-shadow: 0 10px 30px rgba(68,64,60,0.1);">
${state.components.map(c => getComponentHTML(c)).join('\n ')}
</table>
</td>
</tr>
</table>
`;
}
// --- Interaction Logic ---
function addComponent(type) {
const newComp = {
id: Date.now().toString(),
type,
props: JSON.parse(JSON.stringify(defaultProps[type])) // Deep copy
};
state.components.push(newComp);
state.selectedId = newComp.id;
renderAll();
showToast(`Added ${type}`);
}
function selectComponent(id) {
state.selectedId = id;
renderInspectorList();
renderForm();
renderAll(); // To highlight selection in preview (logic could be added for visual highlight)
}
function moveComponent(index, direction) {
if (direction === -1 && index > 0) {
[state.components[index], state.components[index-1]] = [state.components[index-1], state.components[index]];
} else if (direction === 1 && index < state.components.length - 1) {
[state.components[index], state.components[index+1]] = [state.components[index+1], state.components[index]];
}
renderInspectorList();
renderAll();
}
function deleteComponent(index) {
if(confirm('Remove this element from the garden?')) {
state.components.splice(index, 1);
if (state.selectedId === state.components[index]?.id) state.selectedId = null;
renderInspectorList();
renderForm();
renderAll();
}
}
function updateProperty(key, value) {
const comp = state.components.find(c => c.id === state.selectedId);
if (comp) {
comp.props[key] = value;
renderAll();
}
}
// --- UI Rendering Functions ---
function renderInspectorList() {
inspectorList.innerHTML = '';
state.components.forEach((comp, index) => {
const el = document.createElement('div');
el.className = `list-item ${state.selectedId === comp.id ? 'selected' : ''}`;
el.onclick = () => selectComponent(comp.id);
el.innerHTML = `
<span>${capitalize(comp.type)}</span>
<div class="order-controls">
<button onclick="event.stopPropagation(); moveComponent(${index}, -1)" title="Move Up">↑</button>
<button onclick="event.stopPropagation(); moveComponent(${index}, 1)" title="Move Down">↓</button>
<button onclick="event.stopPropagation(); deleteComponent(${index})" title="Remove">✕</button>
</div>
`;
inspectorList.appendChild(el);
});
}
function renderForm() {
const comp = state.components.find(c => c.id === state.selectedId);
if (!comp) {
dynamicForm.innerHTML = `<p style="color:var(--slate); font-size:0.9rem; text-align:center; margin-top:2rem;">Select a component to edit its natural attributes.</p>`;
return;
}
let fields = '';
const p = comp.props;
// Generate inputs based on type
const commonInputs = Object.keys(p).map(key => {
let input = '';
const val = p[key];
// Avoid generating complex inputs for non-text props in this simple demo,
// but we basically map keys to inputs.
if (key.includes('color')) {
input = `<input type="color" class="form-control" value="${val}" onchange="updateProperty('${key}', this.value)" style="height:40px; padding:2px;">`;
} else if (key.includes('align')) {
input = `
<select class="form-control" onchange="updateProperty('${key}', this.value)">
<option value="left" ${val === 'left' ? 'selected' : ''}>Left</option>
<option value="center" ${val === 'center' ? 'selected' : ''}>Center</option>
<option value="right" ${val === 'right' ? 'selected' : ''}>Right</option>
</select>`;
} else if (key.includes('url')) {
input = `<input type="url" class="form-control" value="${val}" onchange="updateProperty('${key}', this.value)">`;
} else if (key.includes('content') || key.includes('text') && key !== 'text_color') {
input = `<textarea class="form-control" onchange="updateProperty('${key}', this.value)">${val}</textarea>`;
} else if (key.includes('height') || key.includes('size') || key.includes('radius')) {
input = `<input type="text" class="form-control" value="${val}" onchange="updateProperty('${key}', this.value)">`;
} else if (key.includes('src')) {
input = `<input type="url" class="form-control" value="${val}" onchange="updateProperty('${key}', this.value)">`;
} else if (key.includes('width')) {
input = `<input type="text" class="form-control" value="${val}" onchange="updateProperty('${key}', this.value)">`;
}
return `
<div class="form-group">
<label class="label">${formatLabel(key)}</label>
${input}
</div>
`;
}).join('');
dynamicForm.innerHTML = `
<div class="property-group active">
<span class="label">Component Type</span>
<div style="margin-bottom:1.5rem; color:var(--terracotta); font-weight:600;">${capitalize(comp.type)}</div>
${commonInputs}
<button class="btn-primary" style="width:100%; margin-top:1rem;" onclick="showToast('Properties saved!')">Apply</button>
</div>
`;
}
function formatLabel(key) {
return key.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase());
}
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
// --- Tab Switching ---
function switchTab(lang) {
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
document.querySelector(`.tab[onclick="switchTab('${lang}')"]`).classList.add('active');
codeHtml.classList.remove('active');
codeMjml.classList.remove('active');
codeAmp.classList.remove('active');
document.getElementById(`code-${lang}`).classList.add('active');
// Adjust textarea colors if needed
}
// --- Dappled Light Effect ---
const dappledLight = document.getElementById('dappled-light');
document.addEventListener('mousemove', (e) => {
// Use requestAnimationFrame for smoothness
requestAnimationFrame(() => {
const x = e.clientX;
const y = e.clientY;
dappledLight.style.background = `radial-gradient(circle at ${x}px ${y}px, rgba(212, 198, 165, 0.25) 0%, transparent 60%)`;
});
});
// --- Toast ---
function showToast(message) {
const toast = document.getElementById('toast');
document.getElementById('toast-msg').innerText = message;
toast.classList.add('show');
setTimeout(() => toast.classList.remove('show'), 3000);
}
// --- Init ---
// Add a default component to start
addComponent('header');
state.components[0].props.text = "The Biophilic Digest";
state.selectedId = null;
renderAll();
</script>
</body>
</html>