Files
pixelserver2/html/gallery.html
2026-01-27 22:42:37 +01:00

192 lines
5.4 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pixel Art Gallery</title>
<style>
/* --- CSS styles are identical to the previous version --- */
:root {
--bg-color: #f7fafc;
--text-color: #2d3748;
--grid-border: #cbd5e0;
--header-color: #1a202c;
--subheader-color: #718096;
--card-bg: #ffffff;
--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}
@media (prefers-color-scheme: dark) {
:root {
--bg-color: #1a202c;
--text-color: #e2e8f0;
--grid-border: #4a5568;
--header-color: #ffffff;
--subheader-color: #a0aec0;
--card-bg: #2d3748;
}
}
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
background-color: var(--bg-color);
color: var(--text-color);
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
padding: 1rem;
box-sizing: border-box;
}
.main-container {
width: 100%;
max-width: 1200px;
display: flex;
flex-direction: column;
align-items: center;
}
header {
text-align: center;
margin-bottom: 2rem;
}
h1 {
font-size: 2.25rem;
font-weight: 700;
color: var(--header-color);
margin: 0;
}
header p {
margin-top: 0.25rem;
color: var(--subheader-color);
}
header p a {
color: var(--subheader-color);
font-weight: 500;
}
#gallery-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
gap: 1.5rem;
width: 100%;
}
.gallery-item {
background-color: var(--card-bg);
border-radius: 0.5rem;
box-shadow: var(--shadow-md);
padding: 1rem;
display: flex;
flex-direction: column;
align-items: center;
text-decoration: none;
color: var(--text-color);
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}
.gallery-item:hover {
transform: translateY(-5px);
box-shadow: var(--shadow-lg);
cursor: pointer;
}
.gallery-item img {
width: 100%;
height: auto;
border: 1px solid var(--grid-border);
border-radius: 0.25rem;
image-rendering: pixelated;
image-rendering: -moz-crisp-edges;
image-rendering: crisp-edges;
}
.gallery-item .caption {
margin-top: 0.75rem;
font-weight: 500;
font-size: 0.9rem;
text-align: center;
}
.gallery-message {
grid-column: 1 / -1;
text-align: center;
color: var(--subheader-color);
}
</style>
</head>
<body>
<div class="main-container">
<header>
<h1>Pixel Art Gallery</h1>
<p><a href="./draw.html">Back to Drawing.</a></p>
</header>
<div id="gallery-grid"></div>
</div>
<template id="gallery-item-template">
<a href="#" class="gallery-item">
<img src="" alt="">
<span class="caption"></span>
</a>
</template>
<script>
document.addEventListener('DOMContentLoaded', async () => {
const grid = document.getElementById('gallery-grid');
const template = document.getElementById('gallery-item-template');
grid.innerHTML = `<p class="gallery-message">Loading frames ...</p>`;
const response = await fetch('/gallery_frames');
if (!response.ok) {
grid.innerHTML = `<p class="gallery-message">Could not load frames</p>`;
return;
}
const images = await response.json();
if (images.length === 0) {
grid.innerHTML = `<p class="gallery-message">No frames found</p>`;
return;
}
grid.innerHTML = '';
images.forEach(image => {
const clone = document.importNode(template.content, true);
const link = clone.querySelector('a');
const img = clone.querySelector('img');
const caption = clone.querySelector('.caption');
link.href = '#';
link.addEventListener('click', async () => {
await fetch('/load_frame', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({"src": image.src})
});
});
img.src = image.src;
img.alt = image.alt || image.caption || image.dt;
caption.textContent = image.caption || image.dt;
// Add the populated clone to the grid
grid.appendChild(clone);
});
});
</script>
</body>
</html>