feat: redesign UI with themes, animations, procedural ASCII engine
Build and Deploy / Build Image (push) Successful in 31s
Build and Deploy / Deploy to Portainer (push) Successful in 6s

- Split app.py into routes + ascii_engine.py (stdlib-only procedural
  generation: figlet banners, creatures, patterns, scenes, classics)
- API: /api/random?category=..., /api/categories, richer JSON payload
- New frontend: templates/index.html + static/ (vanilla JS/CSS)
- 4 themes (graphite/paper/phosphor/amber), localStorage persist,
  no-flash boot, prefers-color-scheme default
- Scramble-resolve art transition, reduced-motion support
- Responsive: rail collapses to chips <760px, art auto-fits width
- Fix grid blowout on mobile (min-width: 0 on stage children)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-11 22:18:14 -07:00
co-authored by Claude Fable 5
parent fdd7f9d751
commit 5e33a38dbb
8 changed files with 1230 additions and 198 deletions
+556
View File
@@ -0,0 +1,556 @@
/* ==========================================================================
asciigen — terminal instrument UI
Themes are token sets on <html data-theme="...">.
========================================================================== */
:root {
--font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas,
"DejaVu Sans Mono", monospace;
--ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
--art-base: 15px;
}
/* --------------------------------------------------------------------------
Theme tokens
-------------------------------------------------------------------------- */
/* graphite — modern dark: warm near-black, bone ink, ember accent */
:root,
[data-theme="graphite"] {
--bg: #101211;
--panel: #0a0c0b;
--ink: #e9e4d6;
--dim: #98937f;
--accent: #ff6b35;
--accent-ink: #14100c;
--line: #2b2f2c;
--dot: rgba(233, 228, 214, 0.05);
--glow: none;
--scan: 0;
--sel: rgba(255, 107, 53, 0.28);
}
/* paper — modern light: warm paper, near-black ink, persimmon accent */
[data-theme="paper"] {
--bg: #f2eee3;
--panel: #faf7ee;
--ink: #211f18;
--dim: #6e6a5c;
--accent: #b93a20;
--accent-ink: #faf7ee;
--line: #d5cfba;
--dot: rgba(33, 31, 24, 0.07);
--glow: none;
--scan: 0;
--sel: rgba(185, 58, 32, 0.2);
}
/* phosphor — P1 green terminal */
[data-theme="phosphor"] {
--bg: #041007;
--panel: #020a04;
--ink: #46e883;
--dim: #2f9e5c;
--accent: #46e883;
--accent-ink: #041007;
--line: #10381e;
--dot: rgba(70, 232, 131, 0.05);
--glow: 0 0 6px rgba(70, 232, 131, 0.55);
--scan: 0.14;
--sel: rgba(70, 232, 131, 0.25);
}
/* amber — P3 amber CRT */
[data-theme="amber"] {
--bg: #150d02;
--panel: #0e0801;
--ink: #ffb300;
--dim: #b57f14;
--accent: #ffb300;
--accent-ink: #150d02;
--line: #453006;
--dot: rgba(255, 179, 0, 0.05);
--glow: 0 0 6px rgba(255, 179, 0, 0.5);
--scan: 0.14;
--sel: rgba(255, 179, 0, 0.25);
}
/* --------------------------------------------------------------------------
Base
-------------------------------------------------------------------------- */
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
height: 100%;
}
body {
min-height: 100dvh;
font-family: var(--font-mono);
font-size: 14px;
line-height: 1.5;
background-color: var(--bg);
/* subtle dot-grid texture */
background-image: radial-gradient(var(--dot) 1px, transparent 1px);
background-size: 22px 22px;
color: var(--ink);
transition: background-color 0.25s ease, color 0.25s ease;
overflow-x: hidden;
}
::selection {
background: var(--sel);
}
button {
font-family: inherit;
}
:focus-visible {
outline: 2px dashed var(--accent);
outline-offset: 3px;
}
/* --------------------------------------------------------------------------
Ambient layers: scanlines (CRT themes) + drifting glyphs
-------------------------------------------------------------------------- */
.scan {
position: fixed;
inset: 0;
z-index: 50;
pointer-events: none;
opacity: var(--scan);
background:
repeating-linear-gradient(
0deg,
rgba(0, 0, 0, 0.55) 0 1px,
transparent 1px 3px
),
radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.35) 100%);
transition: opacity 0.25s ease;
}
.drift {
position: fixed;
inset: 0;
z-index: 0;
pointer-events: none;
overflow: hidden;
}
.drift span {
position: absolute;
top: 105%;
left: var(--x);
font-size: calc(14px * var(--s));
color: var(--ink);
opacity: 0.07;
animation: rise var(--d) linear var(--dl) infinite;
text-shadow: var(--glow);
}
@keyframes rise {
to {
transform: translateY(-130vh) rotate(8deg);
}
}
/* --------------------------------------------------------------------------
Shell
-------------------------------------------------------------------------- */
.app {
position: relative;
z-index: 1;
max-width: 1060px;
margin: 0 auto;
padding: 0 clamp(16px, 4vw, 40px);
min-height: 100dvh;
display: flex;
flex-direction: column;
}
/* topbar ------------------------------------------------------------------ */
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
flex-wrap: wrap;
padding: 18px 0 14px;
border-bottom: 1px solid var(--line);
}
.brand {
display: flex;
align-items: baseline;
gap: 10px;
}
.brand-mark {
color: var(--accent);
font-size: 18px;
text-shadow: var(--glow);
}
.brand-name {
font-size: 17px;
font-weight: 700;
letter-spacing: 0.22em;
text-transform: uppercase;
text-shadow: var(--glow);
}
.brand-tag {
font-size: 11px;
color: var(--dim);
letter-spacing: 0.08em;
}
.themes {
display: flex;
gap: 8px;
}
.theme-btn {
width: 26px;
height: 26px;
padding: 4px;
background: transparent;
border: 1px solid var(--line);
cursor: pointer;
transition: border-color 0.15s ease, transform 0.15s var(--ease-out-expo);
}
.theme-btn:hover {
transform: translateY(-2px);
border-color: var(--dim);
}
.theme-btn.is-active {
border-color: var(--accent);
}
.theme-btn .sw {
display: block;
width: 100%;
height: 100%;
}
.theme-btn[data-set-theme="graphite"] .sw { background: linear-gradient(135deg, #101211 55%, #ff6b35 55%); }
.theme-btn[data-set-theme="paper"] .sw { background: linear-gradient(135deg, #f2eee3 55%, #b93a20 55%); }
.theme-btn[data-set-theme="phosphor"] .sw { background: linear-gradient(135deg, #041007 55%, #46e883 55%); }
.theme-btn[data-set-theme="amber"] .sw { background: linear-gradient(135deg, #150d02 55%, #ffb300 55%); }
/* stage: asymmetric rail + canvas ----------------------------------------- */
.stage {
flex: 1;
display: grid;
grid-template-columns: 190px minmax(0, 1fr);
gap: clamp(24px, 5vw, 56px);
align-items: start;
padding: clamp(24px, 5vh, 48px) 0;
}
.stage > * {
min-width: 0;
}
.rail-label {
font-size: 10px;
letter-spacing: 0.35em;
text-transform: uppercase;
color: var(--dim);
margin-bottom: 12px;
}
.cats {
display: flex;
flex-direction: column;
border-left: 1px solid var(--line);
}
.cat {
display: flex;
align-items: center;
gap: 8px;
padding: 9px 12px;
background: transparent;
border: none;
border-left: 2px solid transparent;
margin-left: -1px;
color: var(--dim);
font-size: 13px;
letter-spacing: 0.12em;
text-transform: uppercase;
text-align: left;
cursor: pointer;
transition: color 0.15s ease, transform 0.2s var(--ease-out-expo),
border-color 0.15s ease;
}
.cat:hover {
color: var(--ink);
transform: translateX(3px);
}
.cat-cursor {
opacity: 0;
transform: translateX(-4px);
transition: opacity 0.15s ease, transform 0.2s var(--ease-out-expo);
color: var(--accent);
}
.cat.is-active {
color: var(--ink);
border-left-color: var(--accent);
}
.cat.is-active .cat-cursor,
.cat:hover .cat-cursor {
opacity: 1;
transform: translateX(0);
}
.hints {
margin-top: 36px;
font-size: 11px;
color: var(--dim);
display: flex;
flex-direction: column;
gap: 6px;
}
kbd {
font-family: inherit;
border: 1px solid var(--line);
padding: 1px 5px;
font-size: 10px;
color: var(--ink);
}
/* canvas ------------------------------------------------------------------ */
.canvas {
min-width: 0;
}
.frame {
position: relative;
background: var(--panel);
border: 1px solid var(--line);
padding: clamp(18px, 3.5vw, 40px);
transition: background-color 0.25s ease, border-color 0.25s ease;
}
.corner {
position: absolute;
width: 14px;
height: 14px;
border-color: var(--accent);
border-style: solid;
border-width: 0;
}
.c-tl { top: -1px; left: -1px; border-top-width: 2px; border-left-width: 2px; }
.c-tr { top: -1px; right: -1px; border-top-width: 2px; border-right-width: 2px; }
.c-bl { bottom: -1px; left: -1px; border-bottom-width: 2px; border-left-width: 2px; }
.c-br { bottom: -1px; right: -1px; border-bottom-width: 2px; border-right-width: 2px; }
.art-scroll {
overflow-x: auto;
display: grid;
justify-items: center;
min-height: 240px;
align-items: center;
}
#art {
font-family: var(--font-mono);
font-size: var(--art-base);
line-height: 1.25;
white-space: pre;
text-shadow: var(--glow);
}
/* status readout ----------------------------------------------------------- */
.status {
display: flex;
align-items: baseline;
gap: 10px;
padding: 10px 2px;
font-size: 11px;
letter-spacing: 0.1em;
text-transform: uppercase;
color: var(--dim);
}
.st-title {
color: var(--ink);
}
.st-msg {
margin-left: auto;
transition: color 0.2s ease;
}
.st-msg.is-hot {
color: var(--accent);
text-shadow: var(--glow);
}
/* actions ------------------------------------------------------------------ */
.actions {
display: flex;
gap: 12px;
margin-top: 8px;
}
.btn {
display: inline-flex;
align-items: center;
gap: 10px;
padding: 13px 26px;
font-size: 13px;
letter-spacing: 0.18em;
text-transform: uppercase;
background: transparent;
color: var(--accent);
border: 1px solid var(--accent);
border-radius: 0;
cursor: pointer;
transition: transform 0.18s var(--ease-out-expo), background-color 0.15s ease,
color 0.15s ease, box-shadow 0.18s ease;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 4px 0 -1px var(--accent);
}
.btn:active {
transform: translateY(1px) scale(0.98);
box-shadow: none;
}
.btn-glyph {
transition: transform 0.2s var(--ease-out-expo);
}
.btn:hover .btn-glyph {
transform: translateX(3px);
}
.btn-primary {
background: var(--accent);
color: var(--accent-ink);
}
.btn[disabled] {
opacity: 0.55;
cursor: wait;
transform: none;
box-shadow: none;
}
/* footer ------------------------------------------------------------------- */
.foot {
display: flex;
justify-content: space-between;
gap: 12px;
flex-wrap: wrap;
padding: 14px 0 18px;
border-top: 1px solid var(--line);
font-size: 11px;
letter-spacing: 0.08em;
color: var(--dim);
}
/* --------------------------------------------------------------------------
Responsive
-------------------------------------------------------------------------- */
@media (max-width: 760px) {
.stage {
grid-template-columns: 1fr;
gap: 20px;
padding-top: 20px;
}
.rail-label {
margin-bottom: 8px;
}
.cats {
flex-direction: row;
overflow-x: auto;
border-left: none;
border-bottom: 1px solid var(--line);
padding-bottom: 8px;
gap: 4px;
scrollbar-width: thin;
}
.cat {
border-left: none;
border-bottom: 2px solid transparent;
margin-left: 0;
white-space: nowrap;
padding: 7px 10px;
}
.cat.is-active {
border-bottom-color: var(--accent);
}
.cat:hover {
transform: none;
}
.hints {
display: none;
}
.actions {
flex-direction: column;
}
.btn {
justify-content: center;
}
.art-scroll {
min-height: 180px;
}
}
/* --------------------------------------------------------------------------
Reduced motion
-------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
.drift {
display: none;
}
}
+227
View File
@@ -0,0 +1,227 @@
/* asciigen frontend — vanilla JS, no dependencies. */
(function () {
"use strict";
var artEl = document.getElementById("art");
var scrollEl = document.getElementById("artScroll");
var stTitle = document.getElementById("stTitle");
var stDims = document.getElementById("stDims");
var stMsg = document.getElementById("stMsg");
var genBtn = document.getElementById("genBtn");
var copyBtn = document.getElementById("copyBtn");
var copyLabel = document.getElementById("copyLabel");
var current = window.__initial || { art: artEl.textContent, title: "", cols: 0, rows: 0 };
var activeCat = "any";
var busy = false;
var msgTimer = null;
var reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)");
/* ---------------------------------------------------------------------
Fit-to-width: scale art font down so the widest line fits the frame,
flooring at a readable minimum (horizontal scroll takes over below).
--------------------------------------------------------------------- */
var ART_BASE = 15;
var ART_MIN = 7;
function fitArt() {
artEl.style.fontSize = ART_BASE + "px";
var avail = scrollEl.clientWidth;
var need = artEl.scrollWidth;
if (need > avail && need > 0) {
var size = Math.max(ART_MIN, Math.floor(ART_BASE * (avail / need) * 10) / 10);
artEl.style.fontSize = size + "px";
}
}
var resizeTimer = null;
window.addEventListener("resize", function () {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(fitArt, 120);
});
/* ---------------------------------------------------------------------
Scramble-resolve transition. Whitespace stays fixed so the silhouette
appears instantly; visible characters resolve at staggered times.
--------------------------------------------------------------------- */
var GLYPHS = "#@%&$?!<>[]{}/\\|=+*~^;:";
function setArt(text) {
artEl.textContent = text;
fitArt();
if (reduceMotion.matches) {
return Promise.resolve();
}
var chars = Array.from(text);
var resolveAt = chars.map(function (c) {
return c === "\n" || c === " " ? 0 : 120 + Math.random() * 480;
});
var t0 = performance.now();
return new Promise(function (done) {
function frame(t) {
var dt = t - t0;
var out = "";
var pending = false;
for (var i = 0; i < chars.length; i++) {
var c = chars[i];
if (c === "\n" || c === " " || dt >= resolveAt[i]) {
out += c;
} else {
pending = true;
out += GLYPHS[(Math.random() * GLYPHS.length) | 0];
}
}
artEl.textContent = out;
if (pending) {
requestAnimationFrame(frame);
} else {
artEl.textContent = text;
done();
}
}
requestAnimationFrame(frame);
});
}
/* ---------------------------------------------------------------------
Status readout
--------------------------------------------------------------------- */
function msg(text, hot) {
clearTimeout(msgTimer);
stMsg.textContent = text;
stMsg.classList.toggle("is-hot", !!hot);
if (hot) {
msgTimer = setTimeout(function () {
stMsg.textContent = "ready";
stMsg.classList.remove("is-hot");
}, 1600);
}
}
/* ---------------------------------------------------------------------
Generate
--------------------------------------------------------------------- */
function generate() {
if (busy) return;
busy = true;
genBtn.disabled = true;
msg("tuning…", true);
var q = activeCat === "any" ? "" : "?category=" + encodeURIComponent(activeCat);
fetch("/api/random" + q)
.then(function (r) {
if (!r.ok) throw new Error("http " + r.status);
return r.json();
})
.then(function (d) {
current = d;
stTitle.textContent = d.title;
stDims.textContent = d.cols + "×" + d.rows;
return setArt(d.art);
})
.then(function () {
msg("ready");
})
.catch(function () {
msg("signal lost", true);
})
.then(function () {
busy = false;
genBtn.disabled = false;
});
}
/* ---------------------------------------------------------------------
Copy to clipboard (with execCommand fallback for non-secure contexts)
--------------------------------------------------------------------- */
function copyArt() {
var text = current.art || artEl.textContent;
var ok = function () {
copyLabel.textContent = "copied ✓";
msg("copied", true);
setTimeout(function () { copyLabel.textContent = "copy"; }, 1400);
};
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(text).then(ok, function () { fallbackCopy(text, ok); });
} else {
fallbackCopy(text, ok);
}
}
function fallbackCopy(text, ok) {
var ta = document.createElement("textarea");
ta.value = text;
ta.style.position = "fixed";
ta.style.opacity = "0";
document.body.appendChild(ta);
ta.select();
try {
document.execCommand("copy");
ok();
} catch (e) {
msg("copy failed", true);
}
document.body.removeChild(ta);
}
/* ---------------------------------------------------------------------
Categories
--------------------------------------------------------------------- */
var catBtns = Array.prototype.slice.call(document.querySelectorAll(".cat"));
catBtns.forEach(function (btn) {
btn.addEventListener("click", function () {
activeCat = btn.dataset.cat;
catBtns.forEach(function (b) { b.classList.toggle("is-active", b === btn); });
generate();
});
});
/* ---------------------------------------------------------------------
Themes
--------------------------------------------------------------------- */
var THEMES = ["graphite", "paper", "phosphor", "amber"];
var themeBtns = Array.prototype.slice.call(document.querySelectorAll(".theme-btn"));
function applyTheme(name) {
document.documentElement.dataset.theme = name;
try { localStorage.setItem("asciigen.theme", name); } catch (e) {}
themeBtns.forEach(function (b) {
b.classList.toggle("is-active", b.dataset.setTheme === name);
});
}
themeBtns.forEach(function (btn) {
btn.addEventListener("click", function () { applyTheme(btn.dataset.setTheme); });
});
function cycleTheme() {
var cur = document.documentElement.dataset.theme;
var idx = THEMES.indexOf(cur);
applyTheme(THEMES[(idx + 1) % THEMES.length]);
}
/* mark the boot theme's button as active */
applyTheme(document.documentElement.dataset.theme || "graphite");
/* ---------------------------------------------------------------------
Keyboard: space = generate, c = copy, t = cycle theme
--------------------------------------------------------------------- */
document.addEventListener("keydown", function (e) {
if (e.repeat || e.metaKey || e.ctrlKey || e.altKey) return;
var tag = (e.target.tagName || "").toLowerCase();
var interactive = tag === "button" || tag === "input" || tag === "textarea" || tag === "select";
if (e.code === "Space" && !interactive) {
e.preventDefault();
generate();
} else if (e.key === "c" && !interactive) {
copyArt();
} else if (e.key === "t" && !interactive) {
cycleTheme();
}
});
genBtn.addEventListener("click", generate);
copyBtn.addEventListener("click", copyArt);
fitArt();
})();