-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstandalone-demo.html
More file actions
275 lines (252 loc) · 12.3 KB
/
standalone-demo.html
File metadata and controls
275 lines (252 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>Cera - Lyria RealTime Music (Standalone Demo)</title>
<script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
colors: {
accent: {
light: '#A78BFA',
DEFAULT: '#8B5CF6',
dark: '#6D28D9',
}
}
}
}
}
</script>
<style>
body {
background: radial-gradient(circle at 15% 50%, rgba(139, 92, 246, 0.15), transparent 25%),
radial-gradient(circle at 85% 30%, rgba(167, 139, 250, 0.1), transparent 25%);
background-color: #0A0A0F;
background-attachment: fixed;
color: white;
margin: 0;
font-family: 'Inter', system-ui, sans-serif;
}
.glass-panel {
background-color: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(12px);
border: 1px solid rgba(255, 255, 255, 0.1);
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}
input[type=range] {
-webkit-appearance: none;
width: 100%;
height: 4px;
background: rgba(255, 255, 255, 0.2);
border-radius: 9999px;
outline: none;
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
width: 16px;
height: 16px;
border-radius: 50%;
background: #8B5CF6;
cursor: pointer;
box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
transition: transform 0.2s;
}
input[type=range]::-webkit-slider-thumb:hover {
transform: scale(1.1);
}
</style>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
const { useState, useEffect, useRef, createContext, useContext } = React;
// ----- SVG ICONS -----
const IconSparkles = () => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"/><path d="M20 3v4"/><path d="M22 5h-4"/><path d="M4 17v2"/><path d="M5 18H3"/></svg>;
const IconSend = () => <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>;
const IconPlay = () => <svg width="32" height="32" viewBox="0 0 24 24" fill="currentColor"><polygon points="5 3 19 12 5 21 5 3"/></svg>;
const IconPause = () => <svg width="32" height="32" viewBox="0 0 24 24" fill="currentColor"><rect x="6" y="4" width="4" height="16"/><rect x="14" y="4" width="4" height="16"/></svg>;
const IconSkipBack = () => <svg width="28" height="28" viewBox="0 0 24 24" fill="currentColor"><polygon points="19 20 9 12 19 4 19 20"/><line x1="5" y1="19" x2="5" y2="5" stroke="currentColor" strokeWidth="2"/></svg>;
const IconSkipForward = () => <svg width="28" height="28" viewBox="0 0 24 24" fill="currentColor"><polygon points="5 4 15 12 5 20 5 4"/><line x1="19" y1="5" x2="19" y2="19" stroke="currentColor" strokeWidth="2"/></svg>;
const IconHeart = () => <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></svg>;
// ----- CONTEXT -----
const PlayerContext = createContext();
const PlayerProvider = ({ children }) => {
const [isPlaying, setIsPlaying] = useState(false);
const [currentTime, setCurrentTime] = useState(0);
const [mood, setMood] = useState(50);
const [tempo, setTempo] = useState(50);
const [currentTrack, setCurrentTrack] = useState({
title: 'Waiting for prompt...',
artist: 'Lyria AI',
artwork: 'https://images.unsplash.com/photo-1614149162883-504ce4d13909?q=80&w=300&auto=format&fit=crop'
});
const [queue, setQueue] = useState([]);
const togglePlay = () => setIsPlaying(!isPlaying);
return (
<PlayerContext.Provider value={{
isPlaying, setIsPlaying, togglePlay,
currentTime, setCurrentTime,
mood, setMood,
tempo, setTempo,
currentTrack, setCurrentTrack,
queue, setQueue
}}>
{children}
</PlayerContext.Provider>
);
}
// ----- COMPONENTS -----
function ControlPanel() {
const { mood, setMood, tempo, setTempo, setCurrentTrack } = useContext(PlayerContext);
const [prompt, setPrompt] = useState('');
const handleGenerate = (e) => {
e.preventDefault();
if(!prompt.trim()) return;
setCurrentTrack({
title: 'Generating: ' + prompt.substring(0, 10) + '...',
artist: 'Lyria AI',
artwork: 'https://images.unsplash.com/photo-1614149162883-504ce4d13909?q=80&w=300&auto=format&fit=crop'
});
setTimeout(() => {
setCurrentTrack({
title: prompt,
artist: 'Lyria AI Generated',
artwork: 'https://images.unsplash.com/photo-1614149162883-504ce4d13909?q=80&w=300&auto=format&fit=crop'
});
setPrompt('');
}, 1500);
}
return (
<div className="w-full flex flex-col gap-4 mt-2">
<div className="glass-panel p-4 rounded-2xl flex flex-col gap-4">
<div className="space-y-2">
<div className="flex justify-between text-xs font-semibold text-white/80 uppercase tracking-wider">
<span>Chill</span><span>Mood</span><span>Energetic</span>
</div>
<input type="range" min="0" max="100" value={mood} onChange={(e)=>setMood(e.target.value)} />
</div>
<div className="space-y-2">
<div className="flex justify-between text-xs font-semibold text-white/80 uppercase tracking-wider">
<span>Slow</span><span>Tempo</span><span>Fast</span>
</div>
<input type="range" min="0" max="100" value={tempo} onChange={(e)=>setTempo(e.target.value)} />
</div>
</div>
<form onSubmit={handleGenerate} className="glass-panel p-2 pl-4 rounded-full flex items-center justify-between gap-2 border border-accent/30 focus-within:border-accent">
<IconSparkles />
<input type="text" placeholder="Describe your next track..." value={prompt} onChange={(e)=>setPrompt(e.target.value)} className="bg-transparent border-none outline-none flex-1 text-sm text-white" />
<button type="submit" disabled={!prompt.trim()} className="w-10 h-10 rounded-full bg-accent/20 flex items-center justify-center text-accent-light">
<IconSend />
</button>
</form>
</div>
)
}
function Visualizer() {
const canvasRef = useRef(null);
const { isPlaying } = useContext(PlayerContext);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas) return;
const ctx = canvas.getContext('2d');
let animationId;
let time = 0;
const draw = () => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
const barWidth = 4, gap = 4;
const totalBars = Math.floor(canvas.width / (barWidth + gap));
const centerY = canvas.height / 2;
for (let i = 0; i < totalBars; i++) {
const x = i * (barWidth + gap);
const heightMultiplier = isPlaying ? Math.sin(time + i * 0.2) * 0.5 + 0.5 : 0.1;
const height = 4 + (isPlaying ? (Math.random() * 20 + 10) * heightMultiplier : 0);
const gradient = ctx.createLinearGradient(0, centerY - height, 0, centerY + height);
gradient.addColorStop(0, 'rgba(167, 139, 250, 0.2)');
gradient.addColorStop(0.5, 'rgba(139, 92, 246, 0.8)');
gradient.addColorStop(1, 'rgba(167, 139, 250, 0.2)');
ctx.fillStyle = gradient;
ctx.beginPath();
ctx.roundRect(x, centerY - height, barWidth, height * 2, 2);
ctx.fill();
}
time += 0.1;
animationId = requestAnimationFrame(draw);
};
draw();
return () => cancelAnimationFrame(animationId);
}, [isPlaying]);
return (
<div className="w-full h-16 rounded-2xl overflow-hidden px-4 flex items-center justify-center opacity-80 mt-2 mb-2">
<canvas ref={canvasRef} width={300} height={60} className="w-full h-full" />
</div>
);
}
function Player() {
const { isPlaying, togglePlay, currentTrack, currentTime } = useContext(PlayerContext);
return (
<div className="glass-panel rounded-3xl p-6 w-full flex flex-col items-center gap-6">
<div className="w-full aspect-square rounded-2xl overflow-hidden relative group">
<img src={currentTrack.artwork} className="w-full h-full object-cover" />
<div className="absolute inset-0 bg-gradient-to-t from-black/60 to-transparent pointer-events-none"></div>
</div>
<div className="w-full flex items-center justify-between px-2">
<div className="flex flex-col">
<h2 className="text-xl font-bold tracking-tight text-white/90 truncate max-w-[200px]">{currentTrack.title}</h2>
<p className="text-sm font-medium text-white/50">{currentTrack.artist}</p>
</div>
<button className="text-white/50 hover:text-white"><IconHeart /></button>
</div>
<div className="w-full space-y-2 flex flex-col items-center">
<input type="range" min="0" max="100" value={currentTime} onChange={()=>{}} className="w-full" />
<div className="flex justify-between w-full text-[11px] text-white/50 font-medium px-1">
<span>0:00</span><span>-:-</span>
</div>
</div>
<div className="flex items-center justify-center gap-8 w-full mt-2">
<button className="text-white/60 hover:text-white"><IconSkipBack /></button>
<button onClick={togglePlay} className="w-16 h-16 rounded-full bg-accent flex items-center justify-center text-white hover:scale-105 transition-transform active:scale-95 shadow-[0_0_20px_rgba(139,92,246,0.4)]">
{isPlaying ? <IconPause /> : <IconPlay />}
</button>
<button className="text-white/60 hover:text-white"><IconSkipForward /></button>
</div>
</div>
)
}
function Layout({ children }) {
return (
<div className="relative min-h-screen w-full overflow-hidden flex flex-col items-center justify-between">
<div className="absolute top-0 left-0 w-full h-24 bg-gradient-to-b from-[#0A0A0F] to-transparent z-10 pointer-events-none" />
<main className="flex-1 w-full max-w-md mx-auto relative flex flex-col z-20 pb-24 pt-6 px-4 gap-6">
{children}
</main>
<div className="absolute bottom-0 left-0 w-full mb-0 bg-white/5 backdrop-blur-xl border-t border-white/10 z-30 flex justify-around items-center h-20 px-6">
<div className="w-8 h-8 rounded-full bg-white/20"></div>
<div className="w-12 h-12 rounded-full bg-accent text-white flex items-center justify-center cursor-pointer hover:scale-105 shadow-[0_0_15px_rgba(139,92,246,0.6)]">
<svg className="w-6 h-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 4v16m8-8H4" /></svg>
</div>
<div className="w-8 h-8 rounded-full bg-white/20"></div>
</div>
</div>
)
}
function App() {
return (
<PlayerProvider>
<Layout>
<Visualizer />
<Player />
<ControlPanel />
</Layout>
</PlayerProvider>
)
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
</script>
</body>
</html>