<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Layout Generator</title>
<script src="https://cdn.tailwindcss.com"></script>
<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=Space+Grotesk:wght@300;400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0a0a0f;
--bg-elevated: #12121a;
--fg: #e8e8ec;
--muted: #6b6b7a;
--accent: #00ffc8;
--accent-dim: rgba(0, 255, 200, 0.15);
--border: #2a2a3a;
--card: #16161f;
--danger: #ff4757;
--warning: #ffa502;
}
* {
box-sizing: border-box;
}
body {
font-family: 'Space Grotesk', sans-serif;
background: var(--bg);
color: var(--fg);
min-height: 100vh;
}
.font-mono {
font-family: 'IBM Plex Mono', monospace;
}
/* Background pattern */
.bg-pattern {
background-image:
linear-gradient(rgba(0, 255, 200, 0.03) 1px, transparent 1px),
linear-gradient(90deg, rgba(0, 255, 200, 0.03) 1px, transparent 1px);
background-size: 40px 40px;
}
/* Custom scrollbar */
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar-track {
background: var(--bg);
}
::-webkit-scrollbar-thumb {
background: var(--border);
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: var(--muted);
}
/* Input styles */
input[type="range"] {
-webkit-appearance: none;
background: transparent;
cursor: pointer;
}
input[type="range"]::-webkit-slider-track {
height: 4px;
background: var(--border);
border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
width: 16px;
height: 16px;
background: var(--accent);
border-radius: 50%;
margin-top: -6px;
transition: transform 0.15s ease;
}
input[type="range"]::-webkit-slider-thumb:hover {
transform: scale(1.2);
}
input[type="color"] {
-webkit-appearance: none;
border: none;
cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper {
padding: 0;
}
input[type="color"]::-webkit-color-swatch {
border: 2px solid var(--border);
border-radius: 6px;
}
/* Animations */
@keyframes fadeSlideIn {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes pulseGlow {
0%, 100% { box-shadow: 0 0 20px rgba(0, 255, 200, 0.3); }
50% { box-shadow: 0 0 40px rgba(0, 255, 200, 0.5); }
}
.animate-in {
animation: fadeSlideIn 0.5s ease forwards;
}
.stagger-1 { animation-delay: 0.1s; opacity: 0; }
.stagger-2 { animation-delay: 0.2s; opacity: 0; }
.stagger-3 { animation-delay: 0.3s; opacity: 0; }
.stagger-4 { animation-delay: 0.4s; opacity: 0; }
@media (prefers-reduced-motion: reduce) {
.animate-in {
animation: none;
opacity: 1;
}
.stagger-1, .stagger-2, .stagger-3, .stagger-4 {
opacity: 1;
}
}
/* Grid overlay */
.grid-overlay {
pointer-events: none;
position: absolute;
inset: 0;
display: none;
}
.grid-overlay.visible {
display: block;
}
/* Tab indicator */
.tab-indicator {
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s ease;
}
/* Focus states */
button:focus-visible,
input:focus-visible,
select:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
/* Transitions */
.transition-smooth {
transition: all 0.2s ease;
}
/* Card hover */
.card-hover:hover {
border-color: var(--accent);
transform: translateY(-2px);
}
/* Preview frame */
.preview-frame {
transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
/* Token chip */
.token-chip {
transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.token-chip:hover {
transform: scale(1.05);
}
.token-chip:active {
transform: scale(0.95);
}
</style>
</head>
<body class="bg-pattern">
<div class="min-h-screen flex flex-col">
<!-- Header -->
<header class="border-b border-[--border] bg-[--bg-elevated]/80 backdrop-blur-sm sticky top-0 z-50 animate-in">
<div class="px-4 lg:px-8 py-4 flex items-center justify-between">
<div class="flex items-center gap-3">
<div class="w-10 h-10 rounded-lg bg-[--accent-dim] border border-[--accent]/30 flex items-center justify-center">
<svg class="w-5 h-5 text-[--accent]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="3" y="3" width="7" height="7" rx="1"/>
<rect x="14" y="3" width="7" height="7" rx="1"/>
<rect x="3" y="14" width="7" height="7" rx="1"/>
<rect x="14" y="14" width="7" height="7" rx="1"/>
</svg>
</div>
<div>
<h1 class="text-lg font-semibold tracking-tight">Layout Generator</h1>
<p class="text-xs text-[--muted] font-mono">v2.0</p>
</div>
</div>
<div class="flex items-center gap-2">
<button id="exportBtn" class="px-4 py-2 bg-[--card] border border-[--border] rounded-lg text-sm font-medium hover:border-[--accent] hover:text-[--accent] transition-smooth flex items-center gap-2">
<svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="7 10 12 15 17 10"/>
<line x1="12" y1="15" x2="12" y2="3"/>
</svg>
Export
</button>
<button id="resetBtn" class="px-4 py-2 bg-[--card] border border-[--border] rounded-lg text-sm font-medium hover:border-[--danger] hover:text-[--danger] transition-smooth">
Reset
</button>
</div>
</div>
</header>
<!-- Main Content -->
<main class="flex-1 flex flex-col lg:flex-row">
<!-- Control Panel -->
<aside class="w-full lg:w-[380px] xl:w-[420px] border-b lg:border-b-0 lg:border-r border-[--border] bg-[--bg-elevated]/50 overflow-y-auto">
<!-- Tabs -->
<div class="sticky top-0 bg-[--bg-elevated] z-10 border-b border-[--border]">
<div class="relative flex px-4 pt-4">
<button class="tab-btn flex-1 pb-3 text-sm font-medium text-center transition-smooth" data-tab="tokens">
Design Tokens
</button>
<button class="tab-btn flex-1 pb-3 text-sm font-medium text-center text-[--muted] transition-smooth" data-tab="grid">
Grid System
</button>
<button class="tab-btn flex-1 pb-3 text-sm font-medium text-center text-[--muted] transition-smooth" data-tab="density">
Density
</button>
<div class="tab-indicator absolute bottom-0 h-[2px] bg-[--accent] rounded-full" style="left: 0; width: 33.33%;"></div>
</div>
</div>
<!-- Tab Content -->
<div class="p-4 lg:p-6 space-y-6">
<!-- Tokens Tab -->
<div id="tokensTab" class="tab-content space-y-6">
<!-- Colors Section -->
<section class="animate-in stagger-1">
<h3 class="text-xs font-semibold uppercase tracking-wider text-[--muted] mb-4">Color Palette</h3>
<div class="grid grid-cols-2 gap-3">
<div class="space-y-2">
<label class="text-xs text-[--muted]">Primary</label>
<div class="flex items-center gap-2">
<input type="color" id="colorPrimary" value="#00ffc8" class="w-10 h-10 rounded-lg">
<input type="text" id="colorPrimaryText" value="#00ffc8" class="flex-1 px-3 py-2 bg-[--card] border border-[--border] rounded-lg text-xs font-mono focus:border-[--accent]">
</div>
</div>
<div class="space-y-2">
<label class="text-xs text-[--muted]">Secondary</label>
<div class="flex items-center gap-2">
<input type="color" id="colorSecondary" value="#6366f1" class="w-10 h-10 rounded-lg">
<input type="text" id="colorSecondaryText" value="#6366f1" class="flex-1 px-3 py-2 bg-[--card] border border-[--border] rounded-lg text-xs font-mono focus:border-[--accent]">
</div>
</div>
<div class="space-y-2">
<label class="text-xs text-[--muted]">Background</label>
<div class="flex items-center gap-2">
<input type="color" id="colorBg" value="#0a0a0f" class="w-10 h-10 rounded-lg">
<input type="text" id="colorBgText" value="#0a0a0f" class="flex-1 px-3 py-2 bg-[--card] border border-[--border] rounded-lg text-xs font-mono focus:border-[--accent]">
</div>
</div>
<div class="space-y-2">
<label class="text-xs text-[--muted]">Foreground</label>
<div class="flex items-center gap-2">
<input type="color" id="colorFg" value="#e8e8ec" class="w-10 h-10 rounded-lg">
<input type="text" id="colorFgText" value="#e8e8ec" class="flex-1 px-3 py-2 bg-[--card] border border-[--border] rounded-lg text-xs font-mono focus:border-[--accent]">
</div>
</div>
<div class="space-y-2">
<label class="text-xs text-[--muted]">Muted</label>
<div class="flex items-center gap-2">
<input type="color" id="colorMuted" value="#6b6b7a" class="w-10 h-10 rounded-lg">
<input type="text" id="colorMutedText" value="#6b6b7a" class="flex-1 px-3 py-2 bg-[--card] border border-[--border] rounded-lg text-xs font-mono focus:border-[--accent]">
</div>
</div>
<div class="space-y-2">
<label class="text-xs text-[--muted]">Border</label>
<div class="flex items-center gap-2">
<input type="color" id="colorBorder" value="#2a2a3a" class="w-10 h-10 rounded-lg">
<input type="text" id="colorBorderText" value="#2a2a3a" class="flex-1 px-3 py-2 bg-[--card] border border-[--border] rounded-lg text-xs font-mono focus:border-[--accent]">
</div>
</div>
</div>
</section>
<!-- Typography Section -->
<section class="animate-in stagger-2">
<h3 class="text-xs font-semibold uppercase tracking-wider text-[--muted] mb-4">Typography Scale</h3>
<div class="space-y-4">
<div class="space-y-2">
<div class="flex justify-between">
<label class="text-xs text-[--muted]">Base Font Size</label>
<span id="fontSizeValue" class="text-xs font-mono text-[--accent]">16px</span>
</div>
<input type="range" id="fontSize" min="12" max="20" value="16" class="w-full">
</div>
<div class="space-y-2">
<div class="flex justify-between">
<label class="text-xs text-[--muted]">Scale Ratio</label>
<span id="scaleRatioValue" class="text-xs font-mono text-[--accent]">1.25</span>
</div>
<input type="range" id="scaleRatio" min="1.125" max="1.5" step="0.025" value="1.25" class="w-full">
</div>
<div class="space-y-2">
<div class="flex justify-between">
<label class="text-xs text-[--muted]">Line Height</label>
<span id="lineHeightValue" class="text-xs font-mono text-[--accent]">1.5</span>
</div>
<input type="range" id="lineHeight" min="1.2" max="2" step="0.1" value="1.5" class="w-full">
</div>
</div>
<!-- Type Scale Preview -->
<div class="mt-4 p-4 bg-[--card] rounded-lg border border-[--border] space-y-2">
<div class="text-xs text-[--muted] mb-3">Preview</div>
<div id="typePreview" class="space-y-1">
<p class="font-bold" style="font-size: var(--text-3xl);">Heading 1</p>
<p class="font-semibold" style="font-size: var(--text-2xl);">Heading 2</p>
<p class="font-medium" style="font-size: var(--text-xl);">Heading 3</p>
<p class="font-normal" style="font-size: var(--text-lg);">Body Large</p>
<p class="font-normal" style="font-size: var(--text-base);">Body Regular</p>
<p class="font-normal text-[--muted]" style="font-size: var(--text-sm);">Small Text</p>
</div>
</div>
</section>
<!-- Border Radius -->
<section class="animate-in stagger-3">
<h3 class="text-xs font-semibold uppercase tracking-wider text-[--muted] mb-4">Border Radius</h3>
<div class="space-y-3">
<div class="flex items-center justify-between">
<label class="text-xs text-[--muted]">Radius</label>
<span id="radiusValue" class="text-xs font-mono text-[--accent]">8px</span>
</div>
<input type="range" id="radius" min="0" max="24" value="8" class="w-full">
<div class="flex gap-2">
<button class="radius-preset flex-1 py-2 bg-[--card] border border-[--border] rounded text-xs font-medium hover:border-[--accent] transition-smooth" data-value="0">Sharp</button>
<button class="radius-preset flex-1 py-2 bg-[--card] border border-[--accent] text-[--accent] rounded text-xs font-medium" data-value="8">Soft</button>
<button class="radius-preset flex-1 py-2 bg-[--card] border border-[--border] rounded text-xs font-medium hover:border-[--accent] transition-smooth" data-value="16">Round</button>
<button class="radius-preset flex-1 py-2 bg-[--card] border border-[--border] rounded text-xs font-medium hover:border-[--accent] transition-smooth" data-value="9999">Pill</button>
</div>
</div>
</section>
</div>
<!-- Grid Tab -->
<div id="gridTab" class="tab-content hidden space-y-6">
<!-- Columns -->
<section class="animate-in stagger-1">
<h3 class="text-xs font-semibold uppercase tracking-wider text-[--muted] mb-4">Columns</h3>
<div class="grid grid-cols-4 gap-2">
<button class="col-btn py-3 bg-[--card] border border-[--border] rounded-lg text-sm font-mono hover:border-[--accent] transition-smooth" data-cols="4">4</button>
<button class="col-btn py-3 bg-[--card] border border-[--border] rounded-lg text-sm font-mono hover:border-[--accent] transition-smooth" data-cols="6">6</button>
<button class="col-btn py-3 bg-[--card] border border-[--border] rounded-lg text-sm font-mono hover:border-[--accent] transition-smooth" data-cols="8">8</button>
<button class="col-btn py-3 bg-[--card] border border-[--accent] text-[--accent] rounded-lg text-sm font-mono" data-cols="12">12</button>
<button class="col-btn py-3 bg-[--card] border border-[--border] rounded-lg text-sm font-mono hover:border-[--accent] transition-smooth" data-cols="16">16</button>
<button class="col-btn py-3 bg-[--card] border border-[--border] rounded-lg text-sm font-mono hover:border-[--accent] transition-smooth" data-cols="24">24</button>
</div>
</section>
<!-- Gutters -->
<section class="animate-in stagger-2">
<h3 class="text-xs font-semibold uppercase tracking-wider text-[--muted] mb-4">Gutters</h3>
<div class="space-y-3">
<div class="flex items-center justify-between">
<label class="text-xs text-[--muted]">Gap</label>
<span id="gapValue" class="text-xs font-mono text-[--accent]">24px</span>
</div>
<input type="range" id="gap" min="8" max="48" step="4" value="24" class="w-full">
</div>
</section>
<!-- Margins -->
<section class="animate-in stagger-3">
<h3 class="text-xs font-semibold uppercase tracking-wider text-[--muted] mb-4">Container Margins</h3>
<div class="space-y-3">
<div class="flex items-center justify-between">
<label class="text-xs text-[--muted]">Page Margin</label>
<span id="marginValue" class="text-xs font-mono text-[--accent]">24px</span>
</div>
<input type="range" id="margin" min="8" max="80" step="4" value="24" class="w-full">
</div>
</section>
<!-- Max Width -->
<section class="animate-in stagger-4">
<h3 class="text-xs font-semibold uppercase tracking-wider text-[--muted] mb-4">Container Max Width</h3>
<div class="space-y-3">
<div class="flex items-center justify-between">
<label class="text-xs text-[--muted]">Max Width</label>
<span id="maxWidthValue" class="text-xs font-mono text-[--accent]">1280px</span>
</div>
<input type="range" id="maxWidth" min="960" max="1600" step="40" value="1280" class="w-full">
<div class="flex gap-2">
<button class="mw-preset flex-1 py-2 bg-[--card] border border-[--border] rounded text-xs font-medium hover:border-[--accent] transition-smooth" data-value="960">960</button>
<button class="mw-preset flex-1 py-2 bg-[--card] border border-[--border] rounded text-xs font-medium hover:border-[--accent] transition-smooth" data-value="1140">1140</button>
<button class="mw-preset flex-1 py-2 bg-[--card] border border-[--accent] text-[--accent] rounded text-xs font-medium" data-value="1280">1280</button>
<button class="mw-preset flex-1 py-2 bg-[--card] border border-[--border] rounded text-xs font-medium hover:border-[--accent] transition-smooth" data-value="1440">1440</button>
</div>
</div>
</section>
<!-- Breakpoints -->
<section>
<h3 class="text-xs font-semibold uppercase tracking-wider text-[--muted] mb-4">Breakpoints</h3>
<div class="space-y-2">
<div class="flex items-center justify-between p-3 bg-[--card] rounded-lg border border-[--border]">
<span class="text-xs font-medium">SM</span>
<input type="number" id="bpSm" value="640" class="w-20 px-2 py-1 bg-[--bg] border border-[--border] rounded text-xs font-mono text-center">
</div>
<div class="flex items-center justify-between p-3 bg-[--card] rounded-lg border border-[--border]">
<span class="text-xs font-medium">MD</span>
<input type="number" id="bpMd" value="768" class="w-20 px-2 py-1 bg-[--bg] border border-[--border] rounded text-xs font-mono text-center">
</div>
<div class="flex items-center justify-between p-3 bg-[--card] rounded-lg border border-[--border]">
<span class="text-xs font-medium">LG</span>
<input type="number" id="bpLg" value="1024" class="w-20 px-2 py-1 bg-[--bg] border border-[--border] rounded text-xs font-mono text-center">
</div>
<div class="flex items-center justify-between p-3 bg-[--card] rounded-lg border border-[--border]">
<span class="text-xs font-medium">XL</span>
<input type="number" id="bpXl" value="1280" class="w-20 px-2 py-1 bg-[--bg] border border-[--border] rounded text-xs font-mono text-center">
</div>
<div class="flex items-center justify-between p-3 bg-[--card] rounded-lg border border-[--border]">
<span class="text-xs font-medium">2XL</span>
<input type="number" id="bp2xl" value="1536" class="w-20 px-2 py-1 bg-[--bg] border border-[--border] rounded text-xs font-mono text-center">
</div>
</div>
</section>
</div>
<!-- Density Tab -->
<div id="densityTab" class="tab-content hidden space-y-6">
<!-- Density Presets -->
<section class="animate-in stagger-1">
<h3 class="text-xs font-semibold uppercase tracking-wider text-[--muted] mb-4">Content Density</h3>
<div class="grid grid-cols-3 gap-2">
<button class="density-btn p-4 bg-[--card] border border-[--border] rounded-lg text-center hover:border-[--accent] transition-smooth" data-density="compact">
<svg class="w-5 h-5 mx-auto mb-2 text-[--muted]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<line x1="3" y1="6" x2="21" y2="6"/>
<line x1="3" y1="12" x2="21" y2="12"/>
<line x1="3" y1="18" x2="21" y2="18"/>
</svg>
<span class="text-xs font-medium">Compact</span>
</button>
<button class="density-btn p-4 bg-[--card] border border-[--accent] text-[--accent] rounded-lg text-center" data-density="comfortable">
<svg class="w-5 h-5 mx-auto mb-2" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<line x1="3" y1="6" x2="21" y2="6"/>
<line x1="3" y1="14" x2="21" y2="14"/>
</svg>
<span class="text-xs font-medium">Comfortable</span>
</button>
<button class="density-btn p-4 bg-[--card] border border-[--border] rounded-lg text-center hover:border-[--accent] transition-smooth" data-density="spacious">
<svg class="w-5 h-5 mx-auto mb-2 text-[--muted]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<line x1="3" y1="4" x2="21" y2="4"/>
<line x1="3" y1="12" x2="21" y2="12"/>
<line x1="3" y1="20" x2="21" y2="20"/>
</svg>
<span class="text-xs font-medium">Spacious</span>
</button>
</div>
</section>
<!-- Spacing Scale -->
<section class="animate-in stagger-2">
<h3 class="text-xs font-semibold uppercase tracking-wider text-[--muted] mb-4">Spacing Scale</h3>
<div class="space-y-3">
<div class="flex items-center justify-between">
<label class="text-xs text-[--muted]">Base Unit</label>
<span id="spacingValue" class="text-xs font-mono text-[--accent]">4px</span>
</div>
<input type="range" id="spacingUnit" min="2" max="8" value="4" class="w-full">
</div>
<div class="mt-4 flex gap-1">
<div class="token-chip flex-1 h-6 bg-[--accent] rounded" style="opacity: 0.2;" title="4px"></div>
<div class="token-chip flex-1 h-6 bg-[--accent] rounded" style="opacity: 0.3;" title="8px"></div>
<div class="token-chip flex-1 h-6 bg-[--accent] rounded" style="opacity: 0.4;" title="12px"></div>
<div class="token-chip flex-1 h-6 bg-[--accent] rounded" style="opacity: 0.5;" title="16px"></div>
<div class="token-chip flex-1 h-6 bg-[--accent] rounded" style="opacity: 0.6;" title="24px"></div>
<div class="token-chip flex-1 h-6 bg-[--accent] rounded" style="opacity: 0.7;" title="32px"></div>
<div class="token-chip flex-1 h-6 bg-[--accent] rounded" style="opacity: 0.8;" title="48px"></div>
<div class="token-chip flex-1 h-6 bg-[--accent] rounded" style="opacity: 0.9;" title="64px"></div>
</div>
<div class="mt-2 flex justify-between text-[10px] font-mono text-[--muted]">
<span>4</span>
<span>8</span>
<span>12</span>
<span>16</span>
<span>24</span>
<span>32</span>
<span>48</span>
<span>64</span>
</div>
</section>
<!-- Component Spacing -->
<section class="animate-in stagger-3">
<h3 class="text-xs font-semibold uppercase tracking-wider text-[--muted] mb-4">Component Spacing</h3>
<div class="space-y-4">
<div class="space-y-2">
<div class="flex justify-between">
<label class="text-xs text-[--muted]">Button Padding Y</label>
<span id="btnPadYValue" class="text-xs font-mono text-[--accent]">10px</span>
</div>
<input type="range" id="btnPadY" min="4" max="20" value="10" class="w-full">
</div>
<div class="space-y-2">
<div class="flex justify-between">
<label class="text-xs text-[--muted]">Button Padding X</label>
<span id="btnPadXValue" class="text-xs font-mono text-[--accent]">20px</span>
</div>
<input type="range" id="btnPadX" min="12" max="32" value="20" class="w-full">
</div>
<div class="space-y-2">
<div class="flex justify-between">
<label class="text-xs text-[--muted]">Card Padding</label>
<span id="cardPadValue" class="text-xs font-mono text-[--accent]">24px</span>
</div>
<input type="range" id="cardPad" min="12" max="48" value="24" class="w-full">
</div>
<div class="space-y-2">
<div class="flex justify-between">
<label class="text-xs text-[--muted]">Input Padding</label>
<span id="inputPadValue" class="text-xs font-mono text-[--accent]">12px</span>
</div>
<input type="range" id="inputPad" min="8" max="20" value="12" class="w-full">
</div>
</div>
</section>
</div>
</div>
</aside>
<!-- Preview Area -->
<div class="flex-1 flex flex-col bg-[--bg]">
<!-- Preview Controls -->
<div class="border-b border-[--border] px-4 lg:px-6 py-3 flex items-center justify-between bg-[--bg-elevated]/50">
<div class="flex items-center gap-2">
<span class="text-xs text-[--muted]">Viewport:</span>
<div class="flex gap-1">
<button class="viewport-btn px-3 py-1.5 bg-[--card] border border-[--border] rounded text-xs font-mono hover:border-[--accent] transition-smooth" data-width="375">375</button>
<button class="viewport-btn px-3 py-1.5 bg-[--card] border border-[--border] rounded text-xs font-mono hover:border-[--accent] transition-smooth" data-width="768">768</button>
<button class="viewport-btn px-3 py-1.5 bg-[--card] border border-[--accent] text-[--accent] rounded text-xs font-mono" data-width="1024">1024</button>
<button class="viewport-btn px-3 py-1.5 bg-[--card] border border-[--border] rounded text-xs font-mono hover:border-[--accent] transition-smooth" data-width="full">Full</button>
</div>
</div>
<div class="flex items-center gap-3">
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" id="showGrid" class="sr-only peer">
<div class="w-8 h-4 bg-[--border] rounded-full peer-checked:bg-[--accent] transition-smooth relative">
<div class="absolute top-0.5 left-0.5 w-3 h-3 bg-white rounded-full peer-checked:translate-x-4 transition-smooth"></div>
</div>
<span class="text-xs text-[--muted]">Grid Overlay</span>
</label>
</div>
</div>
<!-- Preview Frame Container -->
<div class="flex-1 flex items-start justify-center p-4 lg:p-8 overflow-auto">
<div id="previewContainer" class="preview-frame relative bg-[--bg] border border-[--border] rounded-lg overflow-hidden" style="width: 1024px; max-width: 100%;">
<!-- Grid Overlay -->
<div id="gridOverlay" class="grid-overlay">
<svg width="100%" height="100%" id="gridSvg"></svg>
</div>
<!-- Preview Content -->
<div id="previewContent" class="min-h-[600px]">
<!-- Header -->
<header class="border-b border-[--border] px-6 py-4">
<div class="flex items-center justify-between">
<div class="flex items-center gap-3">
<div class="w-8 h-8 rounded bg-[--accent]"></div>
<span class="font-semibold">Brand</span>
</div>
<nav class="hidden md:flex items-center gap-6 text-sm text-[--muted]">
<a href="#" class="hover:text-[--fg]">Products</a>
<a href="#" class="hover:text-[--fg]">Solutions</a>
<a href="#" class="hover:text-[--fg]">Pricing</a>
<a href="#" class="hover:text-[--fg]">Docs</a>
</nav>
<button id="previewBtnPrimary" class="px-4 py-2 bg-[--accent] text-[--bg] rounded font-medium text-sm">
Get Started
</button>
</div>
</header>
<!-- Hero Section -->
<section class="px-6 py-12 md:py-20">
<div class="max-w-2xl">
<h1 class="text-3xl md:text-4xl lg:text-5xl font-bold mb-4 leading-tight">
Build better layouts with design tokens
</h1>
<p class="text-lg text-[--muted] mb-8">
A parameterized layout generator that adapts to your design system. Configure tokens, grid, and density in real-time.
</p>
<div class="flex flex-wrap gap-3">
<button id="previewBtnHero" class="px-6 py-3 bg-[--accent] text-[--bg] rounded font-semibold">
Start Building
</button>
<button id="previewBtnSecondary" class="px-6 py-3 bg-[--card] border border-[--border] rounded font-semibold hover:border-[--accent] transition-smooth">
View Documentation
</button>
</div>
</div>
</section>
<!-- Cards Section -->
<section class="px-6 pb-12">
<div id="cardGrid" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<!-- Cards will be rendered by JS -->
</div>
</section>
<!-- Form Section -->
<section class="px-6 pb-12">
<div id="previewFormCard" class="bg-[--card] border border-[--border] rounded-lg">
<div class="border-b border-[--border] px-6 py-4">
<h3 class="font-semibold">Contact Form</h3>
</div>
<div class="p-6">
<form class="space-y-4">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-xs text-[--muted] mb-2">First Name</label>
<input type="text" id="previewInput" class="w-full px-3 py-2 bg-[--bg] border border-[--border] rounded focus:border-[--accent] focus:outline-none" placeholder="John">
</div>
<div>
<label class="block text-xs text-[--muted] mb-2">Last Name</label>
<input type="text" class="w-full px-3 py-2 bg-[--bg] border border-[--border] rounded focus:border-[--accent] focus:outline-none" placeholder="Doe">
</div>
</div>
<div>
<label class="block text-xs text-[--muted] mb-2">Email</label>
<input type="email" class="w-full px-3 py-2 bg-[--bg] border border-[--border] rounded focus:border-[--accent] focus:outline-none" placeholder="john@example.com">
</div>
<div>
<label class="block text-xs text-[--muted] mb-2">Message</label>
<textarea class="w-full px-3 py-2 bg-[--bg] border border-[--border] rounded focus:border-[--accent] focus:outline-none resize-none" rows="3" placeholder="Your message..."></textarea>
</div>
<button type="button" id="previewFormBtn" class="w-full py-2 bg-[--accent] text-[--bg] rounded font-medium">
Send Message
</button>
</form>
</div>
</div>
</section>
</div>
</div>
</div>
<!-- Current Values Display -->
<div class="border-t border-[--border] px-4 lg:px-6 py-3 bg-[--bg-elevated]/50">
<div class="flex items-center gap-6 text-xs font-mono text-[--muted] overflow-x-auto pb-1">
<span>Columns: <span id="displayCols" class="text-[--accent]">12</span></span>
<span>Gap: <span id="displayGap" class="text-[--accent]">24px</span></span>
<span>Margin: <span id="displayMargin" class="text-[--accent]">24px</span></span>
<span>Max-Width: <span id="displayMaxWidth" class="text-[--accent]">1280px</span></span>
<span>Radius: <span id="displayRadius" class="text-[--accent]">8px</span></span>
<span>Density: <span id="displayDensity" class="text-[--accent]">Comfortable</span></span>
</div>
</div>
</div>
</main>
</div>
<!-- Export Modal -->
<div id="exportModal" class="fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 hidden">
<div class="bg-[--card] border border-[--border] rounded-lg w-full max-w-2xl mx-4 max-h-[80vh] overflow-hidden">
<div class="flex items-center justify-between px-6 py-4 border-b border-[--border]">
<h3 class="font-semibold">Export Configuration</h3>
<button id="closeModal" class="p-2 hover:bg-[--bg] rounded transition-smooth">
<svg class="w-5 h-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<line x1="18" y1="6" x2="6" y2="18"/>
<line x1="6" y1="6" x2="18" y2="18"/>
</svg>
</button>
</div>
<div class="p-6 overflow-y-auto max-h-[60vh]">
<div class="flex gap-2 mb-4">
<button class="export-tab-btn px-4 py-2 bg-[--accent] text-[--bg] rounded text-sm font-medium" data-tab="css">CSS Variables</button>
<button class="export-tab-btn px-4 py-2 bg-[--bg] border border-[--border] rounded text-sm font-medium hover:border-[--accent] transition-smooth" data-tab="json">JSON Config</button>
<button class="export-tab-btn px-4 py-2 bg-[--bg] border border-[--border] rounded text-sm font-medium hover:border-[--accent] transition-smooth" data-tab="tailwind">Tailwind</button>
</div>
<pre id="exportContent" class="bg-[--bg] p-4 rounded-lg border border-[--border] text-xs font-mono overflow-x-auto whitespace-pre-wrap"></pre>
</div>
<div class="flex justify-end gap-2 px-6 py-4 border-t border-[--border]">
<button id="copyExport" class="px-4 py-2 bg-[--accent] text-[--bg] rounded font-medium text-sm flex items-center gap-2">
<svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="9" y="9" width="13" height="13" rx="2"/>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
</svg>
Copy to Clipboard
</button>
</div>
</div>
</div>
<script>
// Initialize configuration state FIRST before any functions
const config = {
colors: {
primary: '#00ffc8',
secondary: '#6366f1',
bg: '#0a0a0f',
fg: '#e8e8ec',
muted: '#6b6b7a',
border: '#2a2a3a'
},
typography: {
baseSize: 16,
scaleRatio: 1.25,
lineHeight: 1.5
},
radius: 8,
grid: {
columns: 12,
gap: 24,
margin: 24,
maxWidth: 1280
},
breakpoints: {
sm: 640,
md: 768,
lg: 1024,
xl: 1280,
'2xl': 1536
},
density: 'comfortable',
spacing: {
unit: 4,
btnPadY: 10,
btnPadX: 20,
cardPad: 24,
inputPad: 12
}
};
const densityPresets = {
compact: { btnPadY: 6, btnPadX: 16, cardPad: 16, inputPad: 8, gap: 16, margin: 16 },
comfortable: { btnPadY: 10, btnPadX: 20, cardPad: 24, inputPad: 12, gap: 24, margin: 24 },
spacious: { btnPadY: 14, btnPadX: 28, cardPad: 32, inputPad: 16, gap: 32, margin: 32 }
};
const cardData = [
{ title: 'Design Tokens', desc: 'Centralize your design decisions with CSS custom properties that cascade through your entire system.', icon: 'palette' },
{ title: 'Grid System', desc: 'Flexible column layouts with configurable gutters, margins, and responsive breakpoints.', icon: 'grid' },
{ title: 'Content Density', desc: 'Adapt spacing and sizing to match your content needs and user preferences.', icon: 'layers' }
];
// Icon SVGs
const icons = {
palette: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="w-6 h-6"><circle cx="12" cy="12" r="10"/><path d="M12 2a10 10 0 0 1 0 20 4 4 0 0 1 0-8 2 2 0 0 0 0-4 10 10 0 0 1 0-8"/></svg>',
grid: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="w-6 h-6"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/></svg>',
layers: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="w-6 h-6"><polygon points="12 2 2 7 12 12 22 7 12 2"/><polyline points="2 17 12 22 22 17"/><polyline points="2 12 12 17 22 12"/></svg>'
};
// DOM Elements - cache after DOM is ready
let elements = {};
// Helper Functions
function clamp(val, min, max) {
return Math.max(min, Math.min(max, val));
}
function isValidColor(color) {
const hexRegex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
return hexRegex.test(color);
}
function safeColor(color, fallback) {
return isValidColor(color) ? color : fallback;
}
// Update CSS Variables
function updateCSSVariables() {
const root = document.documentElement;
const { colors, typography, radius, grid, spacing } = config;
// Colors - validate before applying
root.style.setProperty('--accent', safeColor(colors.primary, '#00ffc8'));
root.style.setProperty('--accent-dim', `rgba(0, 255, 200, 0.15)`);
root.style.setProperty('--bg', safeColor(colors.bg, '#0a0a0f'));
root.style.setProperty('--fg', safeColor(colors.fg, '#e8e8ec'));
root.style.setProperty('--muted', safeColor(colors.muted, '#6b6b7a'));
root.style.setProperty('--border', safeColor(colors.border, '#2a2a3a'));
// Typography scale - clamp values
const baseSize = clamp(typography.baseSize, 12, 20);
const ratio = clamp(typography.scaleRatio, 1.125, 1.5);
const lh = clamp(typography.lineHeight, 1.2, 2);
root.style.setProperty('--text-base', `${baseSize}px`);
root.style.setProperty('--text-sm', `${Math.round(baseSize * 0.875)}px`);
root.style.setProperty('--text-lg', `${Math.round(baseSize * ratio)}px`);
root.style.setProperty('--text-xl', `${Math.round(baseSize * ratio * ratio)}px`);
root.style.setProperty('--text-2xl', `${Math.round(baseSize * ratio * ratio * ratio)}px`);
root.style.setProperty('--text-3xl', `${Math.round(baseSize * ratio * ratio * ratio * ratio)}px`);
root.style.setProperty('--line-height', lh.toString());
// Border radius - clamp
const safeRadius = clamp(radius, 0, 9999);
root.style.setProperty('--radius', safeRadius === 9999 ? '9999px' : `${safeRadius}px`);
// Grid - clamp all values
const safeGap = clamp(grid.gap, 8, 48);
const safeMargin = clamp(grid.margin, 8, 80);
const safeMaxWidth = clamp(grid.maxWidth, 960, 1600);
root.style.setProperty('--grid-gap', `${safeGap}px`);
root.style.setProperty('--grid-margin', `${safeMargin}px`);
root.style.setProperty('--max-width', `${safeMaxWidth}px`);
// Spacing - clamp all values
root.style.setProperty('--btn-py', `${clamp(spacing.btnPadY, 4, 20)}px`);
root.style.setProperty('--btn-px', `${clamp(spacing.btnPadX, 12, 32)}px`);
root.style.setProperty('--card-p', `${clamp(spacing.cardPad, 12, 48)}px`);
root.style.setProperty('--input-p', `${clamp(spacing.inputPad, 8, 20)}px`);
// Update display values
updateDisplayValues();
updatePreviewComponents();
updateGridOverlay();
}
function updateDisplayValues() {
if (elements.displayCols) elements.displayCols.textContent = config.grid.columns;
if (elements.displayGap) elements.displayGap.textContent = `${config.grid.gap}px`;
if (elements.displayMargin) elements.displayMargin.textContent = `${config.grid.margin}px`;
if (elements.displayMaxWidth) elements.displayMaxWidth.textContent = `${config.grid.maxWidth}px`;
if (elements.displayRadius) elements.displayRadius.textContent = config.radius === 9999 ? 'pill' : `${config.radius}px`;
if (elements.displayDensity) elements.displayDensity.textContent = config.density.charAt(0).toUpperCase() + config.density.slice(1);
}
function updatePreviewComponents() {
// Update buttons
const buttons = ['previewBtnPrimary', 'previewBtnHero', 'previewBtnSecondary', 'previewBtnFormBtn'];
buttons.forEach(id => {
const btn = elements[id];
if (btn) {
btn.style.padding = `${config.spacing.btnPadY}px ${config.spacing.btnPadX}px`;
btn.style.borderRadius = config.radius === 9999 ? '9999px' : `${config.radius}px`;
}
});
// Update card grid
const cardGrid = elements.cardGrid;
if (cardGrid) {
cardGrid.style.gap = `${config.grid.gap}px`;
}
// Update form card
const formCard = elements.previewFormCard;
if (formCard) {
formCard.style.borderRadius = config.radius === 9999 ? '9999px' : `${config.radius}px`;
const formContent = formCard.querySelector('.p-6');
if (formContent) {
formContent.style.padding = `${config.spacing.cardPad}px`;
}
}
// Update inputs
const inputs = document.querySelectorAll('#previewContent input, #previewContent textarea');
inputs.forEach(input => {
input.style.padding = `${config.spacing.inputPad}px`;
input.style.borderRadius = config.radius === 9999 ? '9999px' : `${Math.min(config.radius, 8)}px`;
});
}
function updateGridOverlay() {
const svg = elements.gridSvg;
const overlay = elements.gridOverlay;
if (!svg || !overlay) return;
const container = overlay.parentElement;
if (!container) return;
const width = container.offsetWidth;
const height = container.offsetHeight;
const { columns, gap, margin } = config.grid;
const colWidth = Math.max(1, (width - margin * 2 - gap * (columns - 1)) / columns);
let paths = '';
for (let i = 0; i < columns; i++) {
const x = margin + i * (colWidth + gap);
paths += `<rect x="${x}" y="0" width="${colWidth}" height="${height}" fill="rgba(0, 255, 200, 0.05)" stroke="rgba(0, 255, 200, 0.2)" stroke-width="1"/>`;
}
svg.innerHTML = paths;
}
function renderCards() {
const cardGrid = elements.cardGrid;
if (!cardGrid) return;
const radius = config.radius === 9999 ? '9999px' : `${config.radius}px`;
const padding = `${config.spacing.cardPad}px`;
cardGrid.innerHTML = cardData.map(card => `
<div class="bg-[--card] border border-[--border] rounded-lg card-hover transition-smooth" style="border-radius: ${radius}; padding: ${padding};">
<div class="w-12 h-12 rounded-lg bg-[--accent-dim] border border-[--accent]/30 flex items-center justify-center mb-4 text-[--accent]">
${icons[card.icon]}
</div>
<h3 class="font-semibold mb-2">${card.title}</h3>
<p class="text-sm text-[--muted] leading-relaxed">${card.desc}</p>
</div>
`).join('');
}
function generateExportContent(type) {
switch(type) {
case 'css':
return generateCSS();
case 'json':
return JSON.stringify(config, null, 2);
case 'tailwind':
return generateTailwind();
default:
return '';
}
}
function generateCSS() {
return `:root {
/* Colors */
--color-primary: ${config.colors.primary};
--color-secondary: ${config.colors.secondary};
--color-bg: ${config.colors.bg};
--color-fg: ${config.colors.fg};
--color-muted: ${config.colors.muted};
--color-border: ${config.colors.border};
/* Typography */
--font-size-base: ${config.typography.baseSize}px;
--font-size-sm: ${Math.round(config.typography.baseSize * 0.875)}px;
--font-size-lg: ${Math.round(config.typography.baseSize * config.typography.scaleRatio)}px;
--font-size-xl: ${Math.round(config.typography.baseSize * Math.pow(config.typography.scaleRatio, 2))}px;
--font-size-2xl: ${Math.round(config.typography.baseSize * Math.pow(config.typography.scaleRatio, 3))}px;
--font-size-3xl: ${Math.round(config.typography.baseSize * Math.pow(config.typography.scaleRatio, 4))}px;
--line-height: ${config.typography.lineHeight};
/* Spacing */
--spacing-unit: ${config.spacing.unit}px;
--spacing-xs: ${config.spacing.unit}px;
--spacing-sm: ${config.spacing.unit * 2}px;
--spacing-md: ${config.spacing.unit * 4}px;
--spacing-lg: ${config.spacing.unit * 6}px;
--spacing-xl: ${config.spacing.unit * 8}px;
--spacing-2xl: ${config.spacing.unit * 12}px;
/* Border Radius */
--radius: ${config.radius === 9999 ? '9999px' : config.radius + 'px'};
/* Grid */
--grid-columns: ${config.grid.columns};
--grid-gap: ${config.grid.gap}px;
--grid-margin: ${config.grid.margin}px;
--container-max-width: ${config.grid.maxWidth}px;
/* Breakpoints */
--breakpoint-sm: ${config.breakpoints.sm}px;
--breakpoint-md: ${config.breakpoints.md}px;
--breakpoint-lg: ${config.breakpoints.lg}px;
--breakpoint-xl: ${config.breakpoints.xl}px;
--breakpoint-2xl: ${config.breakpoints['2xl']}px;
}`;
}
function generateTailwind() {
return `// tailwind.config.js
module.exports = {
theme: {
extend: {
colors: {
primary: '${config.colors.primary}',
secondary: '${config.colors.secondary}',
background: '${config.colors.bg}',
foreground: '${config.colors.fg}',
muted: '${config.colors.muted}',
border: '${config.colors.border}',
},
fontSize: {
sm: '${Math.round(config.typography.baseSize * 0.875)}px',
base: '${config.typography.baseSize}px',
lg: '${Math.round(config.typography.baseSize * config.typography.scaleRatio)}px',
xl: '${Math.round(config.typography.baseSize * Math.pow(config.typography.scaleRatio, 2))}px',
'2xl': '${Math.round(config.typography.baseSize * Math.pow(config.typography.scaleRatio, 3))}px',
'3xl': '${Math.round(config.typography.baseSize * Math.pow(config.typography.scaleRatio, 4))}px',
},
borderRadius: {
DEFAULT: '${config.radius === 9999 ? '9999px' : config.radius + 'px'}',
},
spacing: {
'unit': '${config.spacing.unit}px',
},
gap: {
'grid': '${config.grid.gap}px',
},
maxWidth: {
'container': '${config.grid.maxWidth}px',
},
screens: {
sm: '${config.breakpoints.sm}px',
md: '${config.breakpoints.md}px',
lg: '${config.breakpoints.lg}px',
xl: '${config.breakpoints.xl}px',
'2xl': '${config.breakpoints['2xl']}px',
},
},
},
}`;
}
// Event Handlers
function setupEventListeners() {
// Tab switching
document.querySelectorAll('.tab-btn').forEach(btn => {
btn.addEventListener('click', () => {
const tab = btn.dataset.tab;
switchTab(tab);
});
});
// Color inputs
['Primary', 'Secondary', 'Bg', 'Fg', 'Muted', 'Border'].forEach(name => {
const colorInput = document.getElementById(`color${name}`);
const textInput = document.getElementById(`color${name}Text`);
if (colorInput) {
colorInput.addEventListener('input', (e) => {
const key = name.toLowerCase();
config.colors[key === 'bg' ? 'bg' : key === 'fg' ? 'fg' : key] = e.target.value;
if (textInput) textInput.value = e.target.value;
updateCSSVariables();
});
}
if (textInput) {
textInput.addEventListener('change', (e) => {
if (isValidColor(e.target.value)) {
const key = name.toLowerCase();
config.colors[key === 'bg' ? 'bg' : key === 'fg' ? 'fg' : key] = e.target.value;
if (colorInput) colorInput.value = e.target.value;
updateCSSVariables();
}
});
}
});
// Typography controls
const fontSizeSlider = document.getElementById('fontSize');
const scaleRatioSlider = document.getElementById('scaleRatio');
const lineHeightSlider = document.getElementById('lineHeight');
if (fontSizeSlider) {
fontSizeSlider.addEventListener('input', (e) => {
config.typography.baseSize = parseInt(e.target.value);
if (elements.fontSizeValue) elements.fontSizeValue.textContent = `${e.target.value}px`;
updateCSSVariables();
});
}
if (scaleRatioSlider) {
scaleRatioSlider.addEventListener('input', (e) => {
config.typography.scaleRatio = parseFloat(e.target.value);
if (elements.scaleRatioValue) elements.scaleRatioValue.textContent = e.target.value;
updateCSSVariables();
});
}
if (lineHeightSlider) {
lineHeightSlider.addEventListener('input', (e) => {
config.typography.lineHeight = parseFloat(e.target.value);
if (elements.lineHeightValue) elements.lineHeightValue.textContent = e.target.value;
updateCSSVariables();
});
}
// Radius controls
const radiusSlider = document.getElementById('radius');
if (radiusSlider) {
radiusSlider.addEventListener('input', (e) => {
config.radius = parseInt(e.target.value);
if (elements.radiusValue) elements.radiusValue.textContent = config.radius === 9999 ? 'pill' : `${config.radius}px`;
updateCSSVariables();
});
}
document.querySelectorAll('.radius-preset').forEach(btn => {
btn.addEventListener('click', () => {
config.radius = parseInt(btn.dataset.value);
if (radiusSlider) radiusSlider.value = Math.min(config.radius, 24);
if (elements.radiusValue) elements.radiusValue.textContent = config.radius === 9999 ? 'pill' : `${config.radius}px`;
document.querySelectorAll('.radius-preset').forEach(b => {
b.classList.remove('border-[--accent]', 'text-[--accent]');
b.classList.add('border-[--border]');
});
btn.classList.add('border-[--accent]', 'text-[--accent]');
btn.classList.remove('border-[--border]');
updateCSSVariables();
});
});
// Grid controls
document.querySelectorAll('.col-btn').forEach(btn => {
btn.addEventListener('click', () => {
config.grid.columns = parseInt(btn.dataset.cols);
document.querySelectorAll('.col-btn').forEach(b => {
b.classList.remove('border-[--accent]', 'text-[--accent]');
b.classList.add('border-[--border]');
});
btn.classList.add('border-[--accent]', 'text-[--accent]');
btn.classList.remove('border-[--border]');
updateCSSVariables();
});
});
const gapSlider = document.getElementById('gap');
if (gapSlider) {
gapSlider.addEventListener('input', (e) => {
config.grid.gap = parseInt(e.target.value);
if (elements.gapValue) elements.gapValue.textContent = `${e.target.value}px`;
updateCSSVariables();
});
}
const marginSlider = document.getElementById('margin');
if (marginSlider) {
marginSlider.addEventListener('input', (e) => {
config.grid.margin = parseInt(e.target.value);
if (elements.marginValue) elements.marginValue.textContent = `${e.target.value}px`;
updateCSSVariables();
});
}
const maxWidthSlider = document.getElementById('maxWidth');
if (maxWidthSlider) {
maxWidthSlider.addEventListener('input', (e) => {
config.grid.maxWidth = parseInt(e.target.value);
if (elements.maxWidthValue) elements.maxWidthValue.textContent = `${e.target.value}px`;
updateCSSVariables();
});
}
document.querySelectorAll('.mw-preset').forEach(btn => {
btn.addEventListener('click', () => {
config.grid.maxWidth = parseInt(btn.dataset.value);
if (maxWidthSlider) maxWidthSlider.value = config.grid.maxWidth;
if (elements.maxWidthValue) elements.maxWidthValue.textContent = `${config.grid.maxWidth}px`;
document.querySelectorAll('.mw-preset').forEach(b => {
b.classList.remove('border-[--accent]', 'text-[--accent]');
b.classList.add('border-[--border]');
});
btn.classList.add('border-[--accent]', 'text-[--accent]');
btn.classList.remove('border-[--border]');
updateCSSVariables();
});
});
// Breakpoints
['Sm', 'Md', 'Lg', 'Xl', '2xl'].forEach(name => {
const input = document.getElementById(`bp${name}`);
if (input) {
input.addEventListener('change', (e) => {
const key = name.toLowerCase();
config.breakpoints[key] = parseInt(e.target.value);
});
}
});
// Density controls
document.querySelectorAll('.density-btn').forEach(btn => {
btn.addEventListener('click', () => {
const density = btn.dataset.density;
config.density = density;
const preset = densityPresets[density];
config.spacing.btnPadY = preset.btnPadY;
config.spacing.btnPadX = preset.btnPadX;
config.spacing.cardPad = preset.cardPad;
config.spacing.inputPad = preset.inputPad;
config.grid.gap = preset.gap;
config.grid.margin = preset.margin;
// Update UI
const btnPadY = document.getElementById('btnPadY');
const btnPadX = document.getElementById('btnPadX');
const cardPad = document.getElementById('cardPad');
const inputPad = document.getElementById('inputPad');
const gap = document.getElementById('gap');
const margin = document.getElementById('margin');
if (btnPadY) btnPadY.value = preset.btnPadY;
if (btnPadX) btnPadX.value = preset.btnPadX;
if (cardPad) cardPad.value = preset.cardPad;
if (inputPad) inputPad.value = preset.inputPad;
if (gap) gap.value = preset.gap;
if (margin) margin.value = preset.margin;
if (elements.btnPadYValue) elements.btnPadYValue.textContent = `${preset.btnPadY}px`;
if (elements.btnPadXValue) elements.btnPadXValue.textContent = `${preset.btnPadX}px`;
if (elements.cardPadValue) elements.cardPadValue.textContent = `${preset.cardPad}px`;
if (elements.inputPadValue) elements.inputPadValue.textContent = `${preset.inputPad}px`;
if (elements.gapValue) elements.gapValue.textContent = `${preset.gap}px`;
if (elements.marginValue) elements.marginValue.textContent = `${preset.margin}px`;
document.querySelectorAll('.density-btn').forEach(b => {
b.classList.remove('border-[--accent]', 'text-[--accent]');
b.classList.add('border-[--border]');
const icon = b.querySelector('svg');
if (icon) icon.classList.add('text-[--muted]');
});
btn.classList.add('border-[--accent]', 'text-[--accent]');
btn.classList.remove('border-[--border]');
const icon = btn.querySelector('svg');
if (icon) icon.classList.remove('text-[--muted]');
updateCSSVariables();
});
});
// Spacing sliders
const spacingUnitSlider = document.getElementById('spacingUnit');
if (spacingUnitSlider) {
spacingUnitSlider.addEventListener('input', (e) => {
config.spacing.unit = parseInt(e.target.value);
if (elements.spacingValue) elements.spacingValue.textContent = `${e.target.value}px`;
});
}
const btnPadYS = document.getElementById('btnPadY');
if (btnPadYS) {
btnPadYS.addEventListener('input', (e) => {
config.spacing.btnPadY = parseInt(e.target.value);
if (elements.btnPadYValue) elements.btnPadYValue.textContent = `${e.target.value}px`;
updateCSSVariables();
});
}
const btnPadXS = document.getElementById('btnPadX');
if (btnPadXS) {
btnPadXS.addEventListener('input', (e) => {
config.spacing.btnPadX = parseInt(e.target.value);
if (elements.btnPadXValue) elements.btnPadXValue.textContent = `${e.target.value}px`;
updateCSSVariables();
});
}
const cardPadS = document.getElementById('cardPad');
if (cardPadS) {
cardPadS.addEventListener('input', (e) => {
config.spacing.cardPad = parseInt(e.target.value);
if (elements.cardPadValue) elements.cardPadValue.textContent = `${e.target.value}px`;
updateCSSVariables();
});
}
const inputPadS = document.getElementById('inputPad');
if (inputPadS) {
inputPadS.addEventListener('input', (e) => {
config.spacing.inputPad = parseInt(e.target.value);
if (elements.inputPadValue) elements.inputPadValue.textContent = `${e.target.value}px`;
updateCSSVariables();
});
}
// Viewport controls
document.querySelectorAll('.viewport-btn').forEach(btn => {
btn.addEventListener('click', () => {
const width = btn.dataset.width;
const container = elements.previewContainer;
if (!container) return;
if (width === 'full') {
container.style.width = '100%';
} else {
container.style.width = `${width}px`;
}
document.querySelectorAll('.viewport-btn').forEach(b => {
b.classList.remove('border-[--accent]', 'text-[--accent]');
b.classList.add('border-[--border]');
});
btn.classList.add('border-[--accent]', 'text-[--accent]');
btn.classList.remove('border-[--border]');
setTimeout(updateGridOverlay, 400);
});
});
// Grid overlay toggle
const showGridCheckbox = document.getElementById('showGrid');
if (showGridCheckbox) {
showGridCheckbox.addEventListener('change', (e) => {
const overlay = elements.gridOverlay;
if (overlay) {
overlay.classList.toggle('visible', e.target.checked);
}
});
}
// Export modal
const exportBtn = document.getElementById('exportBtn');
const exportModal = elements.exportModal;
const closeModal = document.getElementById('closeModal');
const copyExport = document.getElementById('copyExport');
if (exportBtn && exportModal) {
exportBtn.addEventListener('click', () => {
exportModal.classList.remove('hidden');
updateExportContent('css');
});
}
if (closeModal && exportModal) {
closeModal.addEventListener('click', () => {
exportModal.classList.add('hidden');
});
}
if (exportModal) {
exportModal.addEventListener('click', (e) => {
if (e.target === exportModal) {
exportModal.classList.add('hidden');
}
});
}
document.querySelectorAll('.export-tab-btn').forEach(btn => {
btn.addEventListener('click', () => {
const tab = btn.dataset.tab;
updateExportContent(tab);
document.querySelectorAll('.export-tab-btn').forEach(b => {
b.classList.remove('bg-[--accent]', 'text-[--bg]');
b.classList.add('bg-[--bg]', 'border', 'border-[--border]');
});
btn.classList.add('bg-[--accent]', 'text-[--bg]');
btn.classList.remove('bg-[--bg]', 'border', 'border-[--border]');
});
});
if (copyExport) {
copyExport.addEventListener('click', () => {
const content = elements.exportContent ? elements.exportContent.textContent : '';
navigator.clipboard.writeText(content).then(() => {
copyExport.innerHTML = `
<svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="20 6 9 17 4 12"/>
</svg>
Copied!
`;
setTimeout(() => {
copyExport.innerHTML = `
<svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="9" y="9" width="13" height="13" rx="2"/>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
</svg>
Copy to Clipboard
`;
}, 2000);
});
});
}
// Reset button
const resetBtn = document.getElementById('resetBtn');
if (resetBtn) {
resetBtn.addEventListener('click', () => {
if (confirm('Reset all settings to default?')) {
location.reload();
}
});
}
// Window resize
window.addEventListener('resize', () => {
updateGridOverlay();
});
}
function switchTab(tab) {
document.querySelectorAll('.tab-btn').forEach(btn => {
if (btn.dataset.tab === tab) {
btn.classList.remove('text-[--muted]');
btn.classList.add('text-[--fg]');
} else {
btn.classList.add('text-[--muted]');
btn.classList.remove('text-[--fg]');
}
});
document.querySelectorAll('.tab-content').forEach(content => {
content.classList.add('hidden');
});
const tabContent = document.getElementById(`${tab}Tab`);
if (tabContent) {
tabContent.classList.remove('hidden');
}
// Update indicator position
const tabs = ['tokens', 'grid', 'density'];
const index = tabs.indexOf(tab);
const indicator = document.querySelector('.tab-indicator');
if (indicator) {
indicator.style.transform = `translateX(${index * 100}%)`;
}
}
function updateExportContent(type) {
if (elements.exportContent) {
elements.exportContent.textContent = generateExportContent(type);
}
}
// Initialize application
function init() {
// Cache DOM elements after DOM is ready
elements = {
cardGrid: document.getElementById('cardGrid'),
previewContainer: document.getElementById('previewContainer'),
previewFormCard: document.getElementById('previewFormCard'),
gridOverlay: document.getElementById('gridOverlay'),
gridSvg: document.getElementById('gridSvg'),
exportModal: document.getElementById('exportModal'),
exportContent: document.getElementById('exportContent'),
previewBtnPrimary: document.getElementById('previewBtnPrimary'),
previewBtnHero: document.getElementById('previewBtnHero'),
previewBtnSecondary: document.getElementById('previewBtnSecondary'),
previewFormBtn: document.getElementById('previewFormBtn'),
// Display elements
displayCols: document.getElementById('displayCols'),
displayGap: document.getElementById('displayGap'),
displayMargin: document.getElementById('displayMargin'),
displayMaxWidth: document.getElementById('displayMaxWidth'),
displayRadius: document.getElementById('displayRadius'),
displayDensity: document.getElementById('displayDensity'),
// Value display elements
fontSizeValue: document.getElementById('fontSizeValue'),
scaleRatioValue: document.getElementById('scaleRatioValue'),
lineHeightValue: document.getElementById('lineHeightValue'),
radiusValue: document.getElementById('radiusValue'),
gapValue: document.getElementById('gapValue'),
marginValue: document.getElementById('marginValue'),
maxWidthValue: document.getElementById('maxWidthValue'),
spacingValue: document.getElementById('spacingValue'),
btnPadYValue: document.getElementById('btnPadYValue'),
btnPadXValue: document.getElementById('btnPadXValue'),
cardPadValue: document.getElementById('cardPadValue'),
inputPadValue: document.getElementById('inputPadValue')
};
renderCards();
updateCSSVariables();
setupEventListeners();
}
// Start when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
</script>
</body>
</html>