<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rollout Choreographer</title>
<!-- Fonts: Inter (UI) & Playfair Display (Headers) -->
<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=Inter:wght@300;400;500;600&family=Playfair+Display:ital,wght@0,400;0,700;1,400&display=swap" rel="stylesheet">
<!-- Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
fontFamily: {
sans: ['Inter', 'sans-serif'],
serif: ['Playfair Display', 'serif'],
},
colors: {
brand: {
dark: '#050505',
panel: 'rgba(20, 20, 25, 0.6)',
accent: '#00f2ea', // Cyan
accentHover: '#00c7c0',
text: '#e5e5e5',
muted: '#6b7280',
border: 'rgba(255, 255, 255, 0.1)'
}
},
boxShadow: {
'glow': '0 0 20px rgba(0, 242, 234, 0.15)',
'inner-glow': 'inset 0 0 10px rgba(0, 242, 234, 0.2)',
}
}
}
}
</script>
<!-- GSAP -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/ScrollTrigger.min.js"></script>
<!-- Three.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<style>
/* Custom Styles & Overrides */
body {
background-color: #050505;
color: #e5e5e5;
overflow: hidden; /* App-like feel */
}
/* Background Canvas */
#bg-canvas {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
opacity: 0.6;
pointer-events: none;
}
/* Glassmorphism Utilities */
.glass-panel {
background: rgba(255, 255, 255, 0.03);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border: 1px solid rgba(255, 255, 255, 0.08);
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}
/* Timeline Specific */
.timeline-track {
background: rgba(255, 255, 255, 0.02);
position: relative;
min-height: 50px;
}
.timeline-block {
position: absolute;
top: 8px;
height: 34px;
border-radius: 6px;
cursor: grab;
display: flex;
align-items: center;
padding: 0 10px;
font-size: 12px;
color: white;
overflow: hidden;
white-space: nowrap;
transition: box-shadow 0.2s, transform 0.1s;
user-select: none;
z-index: 10;
}
.timeline-block:active {
cursor: grabbing;
z-index: 20;
transform: scale(1.02);
box-shadow: 0 0 15px rgba(0,0,0,0.5);
}
.timeline-block.type-image { background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%); }
.timeline-block.type-text { background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%); }
.timeline-block.type-toggle { background: linear-gradient(135deg, #db2777 0%, #be185d 100%); }
/* Playhead */
#playhead {
position: absolute;
top: 0;
bottom: 0;
width: 2px;
background-color: #00f2ea;
z-index: 40;
pointer-events: none;
left: 0; /* JS will control */
}
#playhead::after {
content: '';
position: absolute;
top: -4px;
left: -5px;
width: 12px;
height: 12px;
border-radius: 50%;
background: #00f2ea;
box-shadow: 0 0 10px #00f2ea;
}
/* Ruller */
.time-ruler {
display: flex;
position: absolute;
top: 0;
left: 0;
right: 0;
height: 24px;
border-bottom: 1px solid rgba(255,255,255,0.1);
pointer-events: none;
user-select: none;
}
.time-marker {
position: absolute;
bottom: 0;
font-size: 10px;
color: #6b7280;
border-left: 1px solid rgba(255,255,255,0.1);
padding-left: 2px;
height: 100%;
}
/* Scrollbar Hide */
.no-scrollbar::-webkit-scrollbar {
display: none;
}
.no-scrollbar {
-ms-overflow-style: none;
scrollbar-width: none;
}
/* Preview Container */
.preview-stage {
background: radial-gradient(circle at center, rgba(20,20,25,0.8) 0%, rgba(5,5,5,1) 100%);
display: flex;
align-items: center;
justify-content: center;
position: relative;
overflow: hidden;
}
.preview-content {
transition: opacity 0.1s ease;
max-width: 80%;
max-height: 80%;
}
.preview-image {
max-width: 100%;
max-height: 70vh;
border-radius: 8px;
box-shadow: 0 20px 50px rgba(0,0,0,0.5);
object-fit: contain;
}
.preview-text {
position: absolute;
bottom: 10%;
left: 50%;
transform: translateX(-50%);
text-align: center;
width: 90%;
pointer-events: none;
}
/* Toast */
.toast {
position: fixed;
bottom: 30px;
right: 30px;
background: rgba(20, 20, 25, 0.9);
border-left: 4px solid #00f2ea;
padding: 16px 24px;
border-radius: 4px;
box-shadow: 0 10px 30px rgba(0,0,0,0.5);
transform: translateY(100px);
opacity: 0;
transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
z-index: 100;
backdrop-filter: blur(5px);
}
</style>
</head>
<body class="antialiased selection:bg-brand-accent selection:text-black">
<!-- Three.js Background -->
<canvas id="bg-canvas"></canvas>
<!-- App Container -->
<div class="h-screen w-screen flex flex-col p-4 gap-4 overflow-hidden">
<!-- Header -->
<header class="flex justify-between items-center glass-panel p-4 rounded-xl z-10 shrink-0">
<div class="flex items-center gap-3">
<div class="w-10 h-10 bg-brand-accent rounded-lg flex items-center justify-center text-black font-bold text-lg shadow-glow">
C
</div>
<div>
<h1 class="text-xl font-serif font-bold tracking-tight text-white">Choreographer</h1>
<p class="text-xs text-brand-muted uppercase tracking-widest">Content Rollout System</p>
</div>
</div>
<div class="flex items-center gap-4">
<!-- Zoom Controls (Visual only) -->
<div class="flex items-center bg-black/30 rounded-lg p-1 border border-brand-border">
<button class="w-8 h-8 flex items-center justify-center hover:bg-white/10 rounded text-xs transition text-brand-muted hover:text-white"><i class="fas fa-search-minus"></i></button>
<span class="text-xs mx-2 text-white font-medium self-center">100%</span>
<button class="w-8 h-8 flex items-center justify-center hover:bg-white/10 rounded text-xs transition text-brand-muted hover:text-white"><i class="fas fa-search-plus"></i></button>
</div>
<button id="btn-export" class="px-6 py-2 bg-brand-accent text-black font-semibold rounded-lg hover:bg-brand-accentHover transition shadow-glow flex items-center gap-2">
<i class="fas fa-download"></i> Export Plan
</button>
</div>
</header>
<!-- Main Workspace -->
<div class="flex flex-1 gap-4 min-h-0">
<!-- Sidebar: Track List & Controls -->
<aside class="w-72 glass-panel rounded-xl p-4 flex flex-col gap-6 z-10 shrink-0">
<!-- Section: Active Tracks -->
<div class="space-y-3">
<h2 class="text-xs font-bold text-brand-muted uppercase tracking-wider flex items-center gap-2">
<span class="w-2 h-2 bg-brand-accent rounded-full animate-pulse"></span> Tracks
</h2>
<div class="space-y-2">
<div class="flex justify-between items-center text-sm">
<span class="text-brand-text"><i class="fas fa-image mr-2 text-blue-400"></i>Hero Assets</span>
<span id="count-assets" class="text-xs bg-white/10 px-2 py-0.5 rounded text-brand-muted">0</span>
</div>
<div class="flex justify-between items-center text-sm">
<span class="text-brand-text"><i class="fas fa-font mr-2 text-purple-400"></i>Translations</span>
<span id="count-text" class="text-xs bg-white/10 px-2 py-0.5 rounded text-brand-muted">0</span>
</div>
<div class="flex justify-between items-center text-sm">
<span class="text-brand-text"><i class="fas fa-toggle-on mr-2 text-pink-400"></i>Personalization</span>
<span id="count-toggles" class="text-xs bg-white/10 px-2 py-0.5 rounded text-brand-muted">0</span>
</div>
</div>
</div>
<hr class="border-brand-border">
<!-- Section: Add Blocks (Magnetic Buttons) -->
<div class="space-y-3">
<h2 class="text-xs font-bold text-brand-muted uppercase tracking-wider">Add Content</h2>
<div class="grid grid-cols-1 gap-2">
<button onclick="app.addBlock('image')" class="magnetic-btn group relative overflow-hidden py-2 px-4 bg-blue-600/20 border border-blue-500/30 rounded-lg hover:bg-blue-600/30 transition text-sm text-blue-100 flex items-center justify-center gap-2">
<i class="fas fa-plus group-hover:rotate-90 transition-transform duration-300"></i> Image Asset
</button>
<button onclick="app.addBlock('text')" class="magnetic-btn group relative overflow-hidden py-2 px-4 bg-purple-600/20 border border-purple-500/30 rounded-lg hover:bg-purple-600/30 transition text-sm text-purple-100 flex items-center justify-center gap-2">
<i class="fas fa-plus group-hover:rotate-90 transition-transform duration-300"></i> Text Copy
</button>
<button onclick="app.addBlock('toggle')" class="magnetic-btn group relative overflow-hidden py-2 px-4 bg-pink-600/20 border border-pink-500/30 rounded-lg hover:bg-pink-600/30 transition text-sm text-pink-100 flex items-center justify-center gap-2">
<i class="fas fa-plus group-hover:rotate-90 transition-transform duration-300"></i> Personalization Toggle
</button>
</div>
</div>
<!-- Section: Global Settings -->
<div class="mt-auto space-y-4">
<h2 class="text-xs font-bold text-brand-muted uppercase tracking-wider">Global Duration</h2>
<div class="flex items-center gap-3">
<input type="range" min="10" max="120" value="60" id="duration-slider" class="w-full accent-brand-accent h-1 bg-gray-700 rounded-lg appearance-none cursor-pointer">
<span class="text-sm font-mono text-white w-10 text-right" id="duration-val">60s</span>
</div>
</div>
</aside>
<!-- Main Content Area -->
<main class="flex-1 flex flex-col gap-4 min-w-0">
<!-- Preview Stage -->
<div class="flex-1 glass-panel rounded-xl relative overflow-hidden flex flex-col">
<!-- Top Bar of Preview -->
<div class="absolute top-4 left-4 z-10 flex gap-2">
<span class="px-3 py-1 bg-black/50 border border-white/10 rounded text-xs text-brand-muted uppercase tracking-wider backdrop-blur-md">
live preview
</span>
<span id="preview-time" class="px-3 py-1 bg-black/50 border border-white/10 rounded text-xs font-mono text-white backdrop-blur-md">00:00.0</span>
</div>
<!-- The Visual Canvas -->
<div id="preview-container" class="preview-stage w-full h-full flex items-center justify-center p-4">
<!-- Dynamic Content Injected Here -->
<div class="text-center text-brand-muted italic">
<p>Add blocks to the timeline to start choreographing.</p>
</div>
</div>
</div>
<!-- Timeline Control Bar -->
<div class="h-40 glass-panel rounded-xl p-0 flex flex-col relative overflow-hidden">
<!-- Toolbar -->
<div class="absolute top-0 left-0 right-0 h-8 bg-black/20 border-b border-white/5 flex items-center px-4 gap-4 z-20">
<button id="btn-play" class="w-6 h-6 flex items-center justify-center text-white hover:text-brand-accent transition">
<i class="fas fa-play"></i>
</button>
<button id="btn-stop" class="w-6 h-6 flex items-center justify-center text-white/60 hover:text-white transition text-sm">
<i classfas fa-stop"></i>
</button>
<div class="h-3 w-px bg-white/10 mx-1"></div>
<span class="text-[10px] text-brand-muted uppercase font-bold tracking-widest">Timeline</span>
<!-- Playhead Time Input (Visual) -->
<div class="ml-auto flex items-center gap-2">
<span class="text-xs text-brand-muted">Snapping:</span>
<button id="btn-snap" class="w-16 text-xs px-2 py-0.5 rounded border border-white/20 bg-white/5 hover:bg-white/10 transition text-white">ON</button>
</div>
</div>
<!-- Scrollable Timeline Area -->
<div class="flex-1 relative overflow-x-auto overflow-y-hidden custom-scrollbar pt-8 pl-0" id="timeline-scroll">
<!-- Time Ruler -->
<div class="time-ruler w-[2000px] h-6" id="time-ruler">
<!-- Markers generated by JS -->
</div>
<!-- Timeline Tracks Container -->
<div class="space-y-1 pr-4 pb-4 w-[2000px]" id="tracks-container">
<!-- Tracks injected via JS -->
</div>
<!-- Global Playhead -->
<div id="playhead-container" class="absolute top-8 bottom-0 left-0 w-full pointer-events-none" style="width: 2000px;">
<div id="playhead"></div>
</div>
</div>
</div>
</main>
</div>
</div>
<!-- Translation Editor Modal -->
<div id="modal-text" class="fixed inset-0 z-50 flex items-center justify-center bg-black/80 backdrop-blur-sm opacity-0 pointer-events-none transition-opacity duration-300">
<div class="glass-panel border border-brand-border p-6 rounded-xl w-96 transform scale-95 transition-transform duration-300 shadow-2xl">
<h3 class="text-xl font-serif text-white mb-4">Edit Translation</h3>
<div class="space-y-4">
<div>
<label class="block text-xs font-bold text-brand-muted uppercase mb-1">Target Language</label>
<select class="w-full bg-black/30 border border-white/20 rounded p-2 text-white text-sm focus:border-brand-accent outline-none">
<option>English (US)</option>
<option>Spanish (ES)</option>
<option>French (FR)</option>
<option>German (DE)</option>
<option>Japanese (JP)</option>
</select>
</div>
<div>
<label class="block text-xs font-bold text-brand-muted uppercase mb-1">Headline</label>
<input type="text" id="edit-input-headline" class="w-full bg-black/30 border border-white/20 rounded p-2 text-white text-sm focus:border-brand-accent outline-none" placeholder="Enter headline...">
</div>
<div>
<label class="block text-xs font-bold text-brand-muted uppercase mb-1">Sub-headline</label>
<textarea id="edit-input-sub" class="w-full bg-black/30 border border-white/20 rounded p-2 text-white text-sm h-20 focus:border-brand-accent outline-none resize-none" placeholder="Enter sub-text..."></textarea>
</div>
</div>
<div class="flex justify-end gap-3 mt-6">
<button onclick="app.closeModal()" class="px-4 py-2 text-sm text-brand-muted hover:text-white transition">Cancel</button>
<button onclick="app.saveText()" class="px-4 py-2 text-sm bg-brand-accent text-black font-bold rounded hover:bg-brand-accentHover transition">Apply</button>
</div>
</div>
</div>
<!-- Toggle Editor Modal -->
<div id="modal-toggle" class="fixed inset-0 z-50 flex items-center justify-center bg-black/80 backdrop-blur-sm opacity-0 pointer-events-none transition-opacity duration-300">
<div class="glass-panel border border-brand-border p-6 rounded-xl w-80 transform scale-95 transition-transform duration-300 shadow-2xl">
<h3 class="text-xl font-serif text-white mb-4">Personalization Rule</h3>
<div class="space-y-4">
<div>
<label class="block text-xs font-bold text-brand-muted uppercase mb-1">Audience Segment</label>
<select id="toggle-segment" class="w-full bg-black/30 border border-white/20 rounded p-2 text-white text-sm focus:border-brand-accent outline-none">
<option value="all">All Users</option>
<option value="new">New Visitors</option>
<option value="returning">Returning Customers</option>
<option value="vip">VIP Status</option>
<option value="mobile">Mobile Device</option>
</select>
</div>
<div>
<label class="block text-xs font-bold text-brand-muted uppercase mb-1">Effect</label>
<select id="toggle-effect" class="w-full bg-black/30 border border-white/20 rounded p-2 text-white text-sm focus:border-brand-accent outline-none">
<option value="blur">Highlight Blur</option>
<option value="grayscale">Desaturate Others</option>
<option value="overlay">Dark Overlay</option>
<option value="zoom">Zoom Scale</option>
</select>
</div>
</div>
<div class="flex justify-end gap-3 mt-6">
<button onclick="app.closeModal()" class="px-4 py-2 text-sm text-brand-muted hover:text-white transition">Cancel</button>
<button onclick="app.saveToggle()" class="px-4 py-2 text-sm bg-brand-accent text-black font-bold rounded hover:bg-brand-accentHover transition">Apply</button>
</div>
</div>
</div>
<!-- Toast Notification -->
<div id="toast" class="toast">
<div class="flex items-center gap-3">
<i class="fas fa-check-circle text-brand-accent"></i>
<span class="text-sm font-medium text-white">Action Successful</span>
</div>
</div>
<script>
/**
* 1. BACKGROUND: Three.js Particle System
* Creates a slow-moving, organic mesh of particles to add depth and atmosphere.
*/
const initBackground = () => {
const canvas = document.getElementById('bg-canvas');
const renderer = new THREE.WebGLRenderer({ canvas, alpha: true, antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
const scene = new THREE.Scene();
// Fog for depth
scene.fog = new THREE.FogExp2(0x050505, 0.002);
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 50;
// Particles
const particlesGeometry = new THREE.BufferGeometry();
const count = 2000;
const positions = new Float32Array(count * 3);
const sizes = new Float32Array(count);
for(let i = 0; i < count; i++) {
positions[i * 3] = (Math.random() - 0.5) * 150; // x
positions[i * 3 + 1] = (Math.random() - 0.5) * 150; // y
positions[i * 3 + 2] = (Math.random() - 0.5) * 150; // z
sizes[i] = Math.random() * 2;
}
particlesGeometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
particlesGeometry.setAttribute('size', new THREE.BufferAttribute(sizes, 1));
// Shader Material for dots
const material = new THREE.PointsMaterial({
size: 1.5,
color: 0x00f2ea,
transparent: true,
opacity: 0.8,
blending: THREE.AdditiveBlending
});
const particleSystem = new THREE.Points(particlesGeometry, material);
scene.add(particleSystem);
// Connecting lines geometry (a "net")
const lineMaterial = new THREE.LineBasicMaterial({
color: 0x2563eb,
transparent: true,
opacity: 0.15
});
const lineGeometry = new THREE.BufferGeometry();
// We'll create a simple grid wireframe around the field
const gridHelper = new THREE.GridHelper(200, 20, 0x00f2ea, 0x111111);
gridHelper.position.y = -30;
scene.add(gridHelper);
// Animation Loop
let mouseX = 0;
document.addEventListener('mousemove', (e) => {
mouseX = (e.clientX / window.innerWidth) * 2 - 1;
});
const animate = () => {
requestAnimationFrame(animate);
const time = Date.now() * 0.0005;
// Rotate particle system slowly
particleSystem.rotation.y = time * 0.1;
particleSystem.rotation.x = Math.sin(time * 0.2) * 0.1;
// Mouse parallax
camera.position.x += (mouseX * 5 - camera.position.x) * 0.05;
camera.lookAt(scene.position);
renderer.render(scene, camera);
};
animate();
// Resize handler
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
};
/**
* 2. APPLICATION LOGIC
*/
class ChoreographerApp {
constructor() {
// Configuration
this.pixelsPerSecond = 20; // Zoom level
this.totalDuration = 60; // Seconds
this.currentTime = 0;
this.isPlaying = false;
this.snapEnabled = true;
this.snapThreshold = 0.5; // seconds
// Data State
this.tracks = [
{ id: 'assets', name: 'Hero Assets', color: 'bg-blue-500', blocks: [] },
{ id: 'text', name: 'Translations', color: 'bg-purple-500', blocks: [] },
{ id: 'toggles', name: 'Personalization', color: 'bg-pink-500', blocks: [] }
];
this.nextBlockId = 1;
this.selectedBlock = null; // For editing
this.dragState = null;
// DOM Elements
this.tracksContainer = document.getElementById('tracks-container');
this.playheadContainer = document.getElementById('playhead-container');
this.playhead = document.getElementById('playhead');
this.previewContainer = document.getElementById('preview-container');
this.timeRuler = document.getElementById('time-ruler');
this.snapBtn = document.getElementById('btn-snap');
this.init();
}
init() {
this.renderRuler();
this.renderTracks();
this.updatePlayhead();
this.setupEventListeners();
this.setupModals();
this.startLoop();
this.showToast('System ready. Start adding content blocks.');
}
// --- RENDERING ---
renderRuler() {
this.timeRuler.innerHTML = '';
for (let i = 0; i <= this.totalDuration; i++) {
const marker = document.createElement('div');
marker.className = 'time-marker';
marker.style.left = `${i * this.pixelsPerSecond}px`;
marker.innerText = `${i}s`;
this.timeRuler.appendChild(marker);
}
}
renderTracks() {
this.tracksContainer.innerHTML = '';
this.tracks.forEach(track => {
const trackEl = document.createElement('div');
trackEl.className = 'timeline-track mb-2 border border-white/5 rounded bg-black/20 relative';
trackEl.dataset.trackId = track.id;
// Render blocks
track.blocks.forEach(block => {
const blockEl = document.createElement('div');
blockEl.className = `timeline-block type-${block.type} px-3 h-[34px] top-[8px]`;
blockEl.style.left = `${block.start * this.pixelsPerSecond}px`;
blockEl.style.width = `${block.duration * this.pixelsPerSecond}px`;
blockEl.innerText = block.name || `Block ${block.id}`;
blockEl.dataset.blockId = block.id;
// Events for interaction
blockEl.addEventListener('mousedown', (e) => this.handleBlockMouseDown(e, block, track));
blockEl.addEventListener('dblclick', () => this.openEditor(block));
trackEl.appendChild(blockEl);
});
this.tracksContainer.appendChild(trackEl);
});
this.updateCounts();
}
updateCounts() {
const countA = this.tracks.find(t => t.id === 'assets').blocks.length;
const countT = this.tracks.find(t => t.id === 'text').blocks.length;
const countG = this.tracks.find(t => t.id === 'toggles').blocks.length;
document.getElementById('count-assets').innerText = countA;
document.getElementById('count-text').innerText = countT;
document.getElementById('count-toggles').innerText = countG;
}
// --- CORE LOGIC: Playback & Preview ---
startLoop() {
const loop = () => {
if (this.isPlaying) {
this.currentTime += 0.016; // approx 60fps
if (this.currentTime >= this.totalDuration) {
this.currentTime = 0; // Loop for demo
// this.isPlaying = false; // Or stop
}
this.updatePlayhead();
this.updatePreview();
}
requestAnimationFrame(loop);
};
loop();
}
updatePlayhead() {
const leftPos = this.currentTime * this.pixelsPerSecond;
this.playhead.style.left = `${leftPos}px`;
// Format time label
const min = Math.floor(this.currentTime / 60).toString().padStart(2, '0');
const sec = Math.floor(this.currentTime % 60).toString().padStart(2, '0');
const ms = Math.floor((this.currentTime % 1) * 10).toString();
document.getElementById('preview-time').innerText = `${min}:${sec}.${ms}`;
}
updatePreview() {
// Identify active blocks at current time
// We need to layer them: Assets (bg), Text (overlay), Toggles (filter)
const activeAssets = this.getActiveBlocks('assets');
const activeTexts = this.getActiveBlocks('text');
const activeToggles = this.getActiveBlocks('toggles');
this.renderPreviewState(activeAssets, activeTexts, activeToggles);
}
getActiveBlocks(trackId) {
const track = this.tracks.find(t => t.id === trackId);
return track.blocks.filter(b => this.currentTime >= b.start && this.currentTime < (b.start + b.duration));
}
renderPreviewState(assets, texts, toggles) {
// Note: In a real app we'd interpolate values. Here we snap instantly or fade.
// Since we're updating 60fps, we might want to debounce DOM updates, but for simplicity:
let previewHTML = '';
let styleFilters = '';
// 1. Apply Toggles (Filters)
if (toggles.length > 0) {
const toggle = toggles[0]; // Use topmost active toggle
switch (toggle.effect) {
case 'blur': styleFilters += 'blur(4px) '; break;
case 'grayscale': styleFilters += 'grayscale(100%) '; break;
case 'overlay': styleFilters += 'brightness(0.5) '; break;
case 'zoom': styleFilters += 'scale(0.95)'; break;
}
}
// 2. Render Assets
let currentBg = '';
if (assets.length > 0) {
const asset = assets[0]; // Top layer
currentBg = asset.url;
}
// 3. Render Text (Combined)
let textHTML = '';
if (texts.length > 0) {
const textBlock = texts[0];
// Styling based on design tokens
textHTML = `
<div class="preview-text" style="${styleFilters ? `filter: ${styleFilters}` : ''}">
<h2 class="text-4xl md:text-6xl font-serif text-white mb-2 drop-shadow-lg fade-in">${textBlock.headline}</h2>
<p class="text-lg md:text-xl text-gray-300 font-light max-w-2xl mx-auto drop-shadow-md">${textBlock.sub}</p>
</div>
`;
}
// Rebuild DOM intelligently to avoid flicker (better diffing would be used in prod)
// Simple approach: only update innerHTML if data changed, or use CSS transitions.
const stage = this.previewContainer;
// Check if we need an image update
const existingImg = stage.querySelector('img.preview-image');
if (currentBg) {
if (!existingImg || existingImg.dataset.src !== currentBg) {
stage.innerHTML = `<img src="${currentBg}" class="preview-image fade-in" data-src="${currentBg}">`;
stage.insertAdjacentHTML('beforeend', textHTML);
} else if (textHTML) {
// text might have changed, check roughly or just update text container
const textDiv = stage.querySelector('.preview-text');
if (!textDiv) stage.appendChild(textHTML);
else {
// Simple text update without full re-render could be done, but full replace is fine here for demo
const newTextDiv = document.createElement('div');
newTextDiv.innerHTML = textHTML;
stage.replaceChild(newTextDiv.firstElementChild, textDiv);
}
}
} else {
if (stage.innerHTML !== '') {
stage.innerHTML = `<div class="text-center text-brand-muted italic"><p>No active content at this time.</p></div>`;
}
}
}
// --- BLOCK MANAGEMENT ---
addBlock(type) {
// Find the first track
const track = this.tracks.find(t => t.id === (type === 'image' ? 'assets' : type === 'text' ? 'text' : 'toggles'));
const newBlock = {
id: this.nextBlockId++,
type: type,
start: Math.floor(this.currentTime), // Start at playback head
duration: 5, // Default 5s
name: `${type === 'image' ? 'Image' : type === 'text' ? 'Text' : 'Segment'} ${this.nextBlockId - 1}`
};
// Default data for block
if (type === 'image') {
newBlock.url = `https://picsum.photos/seed/${this.nextBlockId}/800/600.jpg`;
newBlock.headline = 'New Creative Asset';
newBlock.sub = 'Generated placeholder Asset';
}
if (type === 'text') {
newBlock.headline = 'Sample Headline';
newBlock.sub = 'Sample sub-headline translation goes here.';
}
if (type === 'toggle') {
newBlock.segment = 'all';
newBlock.effect = 'blur';
}
track.blocks.push(newBlock);
this.renderTracks();
this.showToast(`${type} block added at ${newBlock.start}s`);
// Auto move playhead start time of new block so user sees it
if (newBlock.start > this.currentTime) {
this.currentTime = newBlock.start;
this.updatePlayhead();
}
}
// --- INTERACTION: Drag & Drop ---
handleBlockMouseDown(e, block, track) {
e.stopPropagation(); // prevent timeline drag if any
this.dragState = {
block,
track,
startX: e.clientX,
originalStart: block.start
};
const onMouseMove = (moveEvent) => {
if (!this.dragState) return;
const deltaPx = moveEvent.clientX - this.dragState.startX;
const deltaSec = deltaPx / this.pixelsPerSecond;
let newStart = this.dragState.originalStart + deltaSec;
if (this.snapEnabled) {
// Snap to nearest 1 second grid
newStart = Math.round(newStart);
}
// Boundaries
newStart = Math.max(0, Math.min(newStart, this.totalDuration - block.duration));
// Visual Feedback
block.start = newStart;
this.updateBlockPosition(block);
};
const onMouseUp = () => {
document.removeEventListener('mousemove', onMouseMove);
document.removeEventListener('mouseup', onMouseUp);
// Final Snap check if dragging was raw (not handled in move)
if (!this.snapEnabled) {
block.start = Math.round(block.start);
this.updateBlockPosition(block);
}
this.dragState = null;
// Optionally trigger save here
};
document.addEventListener('mousemove', onMouseMove);
document.addEventListener('mouseup', onMouseUp);
}
updateBlockPosition(block) {
const el = document.querySelector(`.timeline-block[data-block-id="${block.id}"]`);
if (el) {
el.style.left = `${block.start * this.pixelsPerSecond}px`;
}
}
// --- PLAYBACK CONTROLS ---
togglePlay() {
this.isPlaying = !this.isPlaying;
const btn = document.getElementById('btn-play');
btn.innerHTML = this.isPlaying ? '<i class="fas fa-pause"></i>' : '<i class="fas fa-play"></i>';
btn.classList.toggle('text-brand-accent');
}
stop() {
this.isPlaying = false;
this.currentTime = 0;
document.getElementById('btn-play').innerHTML = '<i class="fas fa-play"></i>';
this.updatePlayhead();
this.updatePreview();
}
// --- EDITOR MODALS ---
openEditor(block) {
this.selectedBlock = block;
const modalId = block.type === 'text' ? 'modal-text' : 'modal-toggle';
const modal = document.getElementById(modalId);
modal.classList.remove('opacity-0', 'pointer-events-none');
modal.querySelector('.glass-panel').classList.remove('scale-95');
modal.querySelector('.glass-panel').classList.add('scale-100');
if (block.type === 'text') {
document.getElementById('edit-input-headline').value = block.headline;
document.getElementById('edit-input-sub').value = block.sub;
} else if (block.type === 'toggle') {
document.getElementById('toggle-segment').value = block.segment;
document.getElementById('toggle-effect').value = block.effect;
}
}
closeModal() {
document.querySelectorAll('.fixed.z-50').forEach(m => {
m.classList.add('opacity-0', 'pointer-events-none');
m.querySelector('.glass-panel').classList.remove('scale-100');
m.querySelector('.glass-panel').classList.add('scale-95');
});
this.selectedBlock = null;
}
saveText() {
if (!this.selectedBlock) return;
this.selectedBlock.headline = document.getElementById('edit-input-headline').value;
this.selectedBlock.sub = document.getElementById('edit-input-sub').value;
// Refresh block name in timeline
this.selectedBlock.name = this.selectedBlock.headline.substring(0, 10) + '...';
this.renderTracks();
this.closeModal();
this.showToast('Translation updated.');
// Update preview now if active
this.updatePreview();
}
saveToggle() {
if (!this.selectedBlock) return;
this.selectedBlock.segment = document.getElementById('toggle-segment').value;
this.selectedBlock.effect = document.getElementById('toggle-effect').value;
this.selectedBlock.name = `Target: ${this.selectedBlock.segment.toUpperCase()}`;
this.renderTracks();
this.closeModal();
this.showToast('Personalization rule saved.');
this.updatePreview();
}
setupModals() {
// Close on click outside
document.querySelectorAll('.fixed.z-50').forEach(modal => {
modal.addEventListener('click', (e) => {
if (e.target === modal) this.closeModal();
});
});
}
setupEventListeners() {
document.getElementById('btn-play').addEventListener('click', () => this.togglePlay());
document.getElementById('btn-stop').addEventListener('click', () => this.stop());
document.getElementById('duration-slider').addEventListener('input', (e) => {
this.totalDuration = parseInt(e.target.value);
document.getElementById('duration-val').innerText = `${this.totalDuration}s`;
// Re-render timeline width and ruler
this.timeRuler.style.width = `${this.totalDuration * this.pixelsPerSecond}px`;
this.tracksContainer.style.width = `${this.totalDuration * this.pixelsPerSecond}px`;
this.playheadContainer.style.width = `${this.totalDuration * this.pixelsPerSecond}px`;
this.renderRuler();
});
this.snapBtn.addEventListener('click', () => {
this.snapEnabled = !this.snapEnabled;
this.snapBtn.innerText = this.snapEnabled ? 'ON' : 'OFF';
this.snapBtn.classList.toggle('bg-brand-accent/20', this.snapEnabled);
});
document.getElementById('btn-export').addEventListener('click', () => {
// Simulate export
const btn = document.getElementById('btn-export');
const originalText = btn.innerHTML;
btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Processing...';
btn.classList.add('cursor-wait');
setTimeout(() => {
btn.innerHTML = originalText;
btn.classList.remove('cursor-wait');
this.showToast('Rollout Plan exported successfully!');
}, 1500);
});
// Interactive timeline scrubbing
const scrollArea = document.getElementById('timeline-scroll');
scrollArea.addEventListener('mousedown', (e) => {
if (e.target === scrollArea || e.target.classList.contains('timeline-track') || e.target.classList.contains('time-ruler')) {
const rect = scrollArea.getBoundingClientRect();
const x = e.clientX - rect.left + scrollArea.scrollLeft;
this.currentTime = x / this.pixelsPerSecond;
if (!this.isPlaying) this.updatePlayhead();
this.updatePreview();
}
});
}
showToast(msg) {
const toast = document.getElementById('toast');
toast.querySelector('span').innerText = msg;
toast.style.transform = 'translateY(0)';
toast.style.opacity = '1';
setTimeout(() => {
toast.style.opacity = '0';
toast.style.transform = 'translateY(100px)';
}, 3000);
}
}
// --- MAGNETIC BUTTON EFFECT ---
// Adds a subtle pull towards the mouse when hovering buttons
const initMagneticButtons = () => {
const buttons = document.querySelectorAll('.magnetic-btn');
buttons.forEach(btn => {
btn.addEventListener('mousemove', (e) => {
const rect = btn.getBoundingClientRect();
const x = e.clientX - rect.left - rect.width / 2;
const y = e.clientY - rect.top - rect.height / 2;
gsap.to(btn, {
duration: 0.3,
x: x * 0.2,
y: y * 0.2,
ease: 'power2.out'
});
});
btn.addEventListener('mouseleave', () => {
gsap.to(btn, {
duration: 0.5,
x: 0,
y: 0,
ease: 'elastic.out(1, 0.3)'
});
});
});
};
// --- INITIALIZATION ---
window.addEventListener('DOMContentLoaded', () => {
initBackground();
window.app = new ChoreographerApp();
initMagneticButtons();
// Intro Animation for bars
gsap.from('header', { y: -50, opacity: 0, duration: 0.8, ease: 'power3.out', delay: 0.2 });
gsap.from('aside', { x: -50, opacity: 0, duration: 0.8, ease: 'power3.out', delay: 0.4 });
gsap.from('main', { y: 50, opacity: 0, duration: 0.8, ease: 'power3.out', delay: 0.6 });
});
</script>
</body>
</html>