splitflap/index.html

633 lines
20 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Split-Flap Board</title>
<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=Roboto+Mono:wght@400;700&display=swap" rel="stylesheet">
<style>
*, *::before, *::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html, body {
width: 100%;
height: 100%;
background: #111;
font-family: 'Roboto Mono', 'Courier New', monospace;
overflow-x: auto;
overflow-y: auto;
}
body {
display: flex;
justify-content: center;
align-items: flex-start;
padding: 30px 20px;
min-height: 100vh;
}
#board-wrapper {
transform-origin: top center;
}
#board {
background: #151515;
padding: 24px 28px;
border: 3px solid #444;
border-radius: 4px;
box-shadow:
inset 0 2px 8px rgba(0,0,0,0.5),
0 0 30px rgba(0,0,0,0.6),
0 4px 16px rgba(0,0,0,0.4);
position: relative;
min-width: fit-content;
}
/* Metallic border overlay */
#board::before {
content: '';
position: absolute;
inset: -3px;
border-radius: 6px;
border: 3px solid transparent;
background: linear-gradient(to bottom, #666, #333, #555) border-box;
-webkit-mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
-webkit-mask-composite: xor;
mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
mask-composite: exclude;
pointer-events: none;
}
/* Date header */
#date-header {
text-align: center;
margin-bottom: 20px;
padding-bottom: 16px;
border-bottom: 2px solid #252525;
}
#date-row {
display: inline-flex;
justify-content: center;
flex-wrap: nowrap;
}
/* Section labels */
.section-label {
color: #ffb300;
font-weight: 700;
font-size: 16px;
letter-spacing: 2px;
margin: 18px 0 8px 0;
font-family: 'Roboto Mono', 'Courier New', monospace;
}
/* Column headers */
.header-row {
display: flex;
margin-bottom: 2px;
}
.header-cell {
background: #252525;
color: #999;
font-family: 'Roboto Mono', 'Courier New', monospace;
font-size: 13px;
font-weight: 700;
padding: 4px 0;
text-align: center;
letter-spacing: 1px;
border-radius: 2px;
margin-right: 2px;
}
.header-cell:last-child {
margin-right: 0;
}
/* Data rows */
.data-row {
display: flex;
margin-bottom: 1px;
height: 30px;
align-items: center;
}
/* Flap character unit */
.flap {
display: inline-block;
width: 18px;
height: 28px;
position: relative;
margin: 0 0.5px;
font-family: 'Roboto Mono', 'Courier New', monospace;
}
.flap-top, .flap-bottom {
position: absolute;
left: 0;
right: 0;
height: 50%;
overflow: hidden;
background: #1a1a1a;
color: #e8e0c8;
text-align: center;
}
.flap-top {
top: 0;
border-bottom: 1px solid #111;
}
.flap-bottom {
bottom: 0;
}
.flap-top .flap-char,
.flap-bottom .flap-char {
display: block;
font-size: 18px;
line-height: 28px;
}
.flap-bottom .flap-char {
margin-top: -14px;
}
/* Date header flaps are larger */
#date-row .flap {
width: 27px;
height: 42px;
}
#date-row .flap-top .flap-char,
#date-row .flap-bottom .flap-char {
font-size: 27px;
line-height: 42px;
}
#date-row .flap-bottom .flap-char {
margin-top: -21px;
}
/* Color classes for special characters */
.flap-green .flap-char { color: #4caf50 !important; }
.flap-red .flap-char { color: #f44336 !important; }
/* Navigation */
#nav {
text-align: center;
margin-top: 20px;
padding-top: 16px;
border-top: 2px solid #252525;
}
#nav span {
color: #ffb300;
font-family: 'Roboto Mono', 'Courier New', monospace;
font-size: 15px;
font-weight: 700;
cursor: pointer;
padding: 6px 14px;
user-select: none;
letter-spacing: 1px;
transition: color 0.15s;
}
#nav span:hover {
color: #ffd54f;
}
#nav .sep {
color: #555;
cursor: default;
padding: 0 4px;
}
#nav .sep:hover {
color: #555;
}
</style>
</head>
<body>
<div id="board-wrapper">
<div id="board">
<div id="date-header">
<div id="date-row"></div>
</div>
<div id="sections"></div>
<div id="nav">
<span id="btn-prev">&lt; PREV</span>
<span class="sep">|</span>
<span id="btn-today">TODAY</span>
<span class="sep">|</span>
<span id="btn-next">NEXT &gt;</span>
</div>
</div>
</div>
<script>
(function() {
'use strict';
// ─── Constants ──────────────────────────────────────────────────────
const CHARSET = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:.-/,&()+\u2713\u2717';
const COLS = [
{ key: 'time', width: 7, header: 'TIME' },
{ key: 'type', width: 10, header: 'TYPE' },
{ key: 'title', width: 22, header: 'TITLE' },
{ key: 'src', width: 5, header: 'SRC' },
{ key: 'body_part', width: 20, header: 'BODY PART' },
{ key: 'pt', width: 4, header: 'PT' },
{ key: 'scr', width: 1, header: 'S' },
{ key: 'ins', width: 1, header: 'I' },
];
const TOTAL_CHARS = COLS.reduce((s, c) => s + c.width, 0);
const MAX_ROWS = 20;
const FLIP_STEP_MS = 200;
const STAGGER_MS = 20;
const CHAR_WIDTH = 18;
// ─── State ──────────────────────────────────────────────────────────
const flapChars = new Map();
// ─── Flap Element Creation ─────────────────────────────────────────
function createFlap(ch) {
ch = ch || ' ';
const el = document.createElement('div');
el.className = 'flap';
flapChars.set(el, ch);
const top = document.createElement('div');
top.className = 'flap-top';
const topChar = document.createElement('span');
topChar.className = 'flap-char';
topChar.textContent = ch;
top.appendChild(topChar);
const bottom = document.createElement('div');
bottom.className = 'flap-bottom';
const bottomChar = document.createElement('span');
bottomChar.className = 'flap-char';
bottomChar.textContent = ch;
bottom.appendChild(bottomChar);
el.appendChild(top);
el.appendChild(bottom);
applyCharColor(el, ch);
return el;
}
function applyCharColor(flapEl, ch) {
flapEl.classList.remove('flap-green', 'flap-red');
if (ch === '\u2713') flapEl.classList.add('flap-green');
else if (ch === '\u2717') flapEl.classList.add('flap-red');
}
// ─── Sound ─────────────────────────────────────────────────────────
const flipAudio = new Audio('/split.mp3');
flipAudio.loop = true;
flipAudio.volume = 0;
let fadeInterval = null;
function startFlipSound() {
clearInterval(fadeInterval);
flipAudio.currentTime = 3;
flipAudio.volume = 0;
flipAudio.play().catch(() => {});
const target = 0.5;
const step = target / 8;
fadeInterval = setInterval(() => {
flipAudio.volume = Math.min(flipAudio.volume + step, target);
if (flipAudio.volume >= target) clearInterval(fadeInterval);
}, 10);
}
function stopFlipSound() {
clearInterval(fadeInterval);
const step = flipAudio.volume / 12;
fadeInterval = setInterval(() => {
flipAudio.volume = Math.max(flipAudio.volume - step, 0);
if (flipAudio.volume <= 0) {
clearInterval(fadeInterval);
flipAudio.pause();
}
}, 10);
}
// ─── Batch Flip Animation Engine ────────────────────────────────────
const activeFlips = [];
let animRunning = false;
function buildSteps(oldChar, newChar) {
const oldIdx = CHARSET.indexOf(oldChar);
const newIdx = CHARSET.indexOf(newChar);
if (oldIdx === -1 || newIdx === -1) return [newChar];
const steps = [];
if (newIdx >= oldIdx) {
for (let i = oldIdx + 1; i <= newIdx; i++) steps.push(CHARSET[i]);
} else {
for (let i = oldIdx + 1; i < CHARSET.length; i++) steps.push(CHARSET[i]);
for (let i = 0; i <= newIdx; i++) steps.push(CHARSET[i]);
}
if (steps.length === 0) return [newChar];
const maxSteps = 12;
if (steps.length <= maxSteps) return steps;
const sampled = [];
for (let i = 0; i < maxSteps - 1; i++) {
sampled.push(steps[Math.floor(i * (steps.length - 1) / (maxSteps - 1))]);
}
sampled.push(steps[steps.length - 1]);
return sampled;
}
function scheduleFlip(flapEl, newChar, delay) {
const oldChar = flapChars.get(flapEl) || ' ';
if (oldChar === newChar) return;
const topSpan = flapEl.querySelector('.flap-top .flap-char');
const bottomSpan = flapEl.querySelector('.flap-bottom .flap-char');
const steps = buildSteps(oldChar, newChar);
const startTime = performance.now() + delay;
activeFlips.push({
flapEl, topSpan, bottomSpan, steps,
stepIdx: 0,
nextTime: startTime
});
if (!animRunning) {
animRunning = true;
startFlipSound();
requestAnimationFrame(animLoop);
}
}
function animLoop(timestamp) {
let stillActive = false;
for (let i = 0; i < activeFlips.length; i++) {
const flip = activeFlips[i];
if (flip.stepIdx >= flip.steps.length) continue;
stillActive = true;
if (timestamp >= flip.nextTime) {
const ch = flip.steps[flip.stepIdx];
flip.topSpan.textContent = ch;
flip.bottomSpan.textContent = ch;
flapChars.set(flip.flapEl, ch);
flip.stepIdx++;
flip.nextTime = timestamp + FLIP_STEP_MS;
if (flip.stepIdx >= flip.steps.length) {
applyCharColor(flip.flapEl, ch);
}
}
}
if (stillActive) {
requestAnimationFrame(animLoop);
} else {
activeFlips.length = 0;
animRunning = false;
stopFlipSound();
}
}
// ─── Row helpers ───────────────────────────────────────────────────
function createFlapRow(container, numChars) {
const row = document.createElement('div');
row.className = 'data-row';
for (let i = 0; i < numChars; i++) {
row.appendChild(createFlap(' '));
}
container.appendChild(row);
return row;
}
function setRowText(rowEl, text) {
const flaps = rowEl.children;
const padded = text.padEnd(flaps.length);
for (let i = 0; i < flaps.length; i++) {
scheduleFlip(flaps[i], padded[i], i * STAGGER_MS);
}
}
// ─── Header Row ───────────────────────────────────────────────────
function createHeaderRow(container) {
const row = document.createElement('div');
row.className = 'header-row';
for (const col of COLS) {
const cell = document.createElement('div');
cell.className = 'header-cell';
cell.style.width = (col.width * (CHAR_WIDTH + 1) + 2) + 'px';
cell.textContent = col.header;
row.appendChild(cell);
}
container.appendChild(row);
}
// ─── Date Row ─────────────────────────────────────────────────────
function setDateText(text) {
const container = document.getElementById('date-row');
const upper = text.toUpperCase();
// Rebuild if length changed
if (container.children.length !== upper.length) {
container.innerHTML = '';
for (let i = 0; i < upper.length; i++) {
container.appendChild(createFlap(' '));
}
}
for (let i = 0; i < upper.length; i++) {
scheduleFlip(container.children[i], upper[i], i * STAGGER_MS);
}
}
// ─── Format Row ───────────────────────────────────────────────────
function formatRow(item) {
let result = '';
for (const col of COLS) {
let val;
if (col.key === 'scr' || col.key === 'ins') {
val = item[col.key] === true ? '\u2713' : item[col.key] === false ? '\u2717' : ' ';
} else {
val = (item[col.key] || '').toUpperCase();
}
result += val.padEnd(col.width);
}
return result;
}
// ─── Build Sections ───────────────────────────────────────────────
function buildSection(parent, label) {
const labelEl = document.createElement('div');
labelEl.className = 'section-label';
labelEl.textContent = label;
parent.appendChild(labelEl);
createHeaderRow(parent);
const rowContainer = document.createElement('div');
parent.appendChild(rowContainer);
const rows = [];
for (let r = 0; r < MAX_ROWS; r++) {
rows.push(createFlapRow(rowContainer, TOTAL_CHARS));
}
return rows;
}
// ─── Date Helpers ──────────────────────────────────────────────────
let currentDate = null;
function todayEastern() {
const now = new Date();
const eastern = new Date(now.toLocaleString('en-US', { timeZone: 'America/New_York' }));
return new Date(eastern.getFullYear(), eastern.getMonth(), eastern.getDate());
}
function formatDateStr(d) {
const y = d.getFullYear();
const m = String(d.getMonth() + 1).padStart(2, '0');
const day = String(d.getDate()).padStart(2, '0');
return `${y}-${m}-${day}`;
}
function addDays(d, n) {
const result = new Date(d);
result.setDate(result.getDate() + n);
return result;
}
// ─── Demo Data ──────────────────────────────────────────────────────
const DEMO_P1 = [
{ time: '7:00A', type: 'MRI', title: 'BRAIN W/O CONTRAST', src: 'OP', body_part: 'BRAIN', pt: 'J.D.', scr: true, ins: true },
{ time: '7:30A', type: 'MRI', title: 'C-SPINE W/ CONTRAST', src: 'ER', body_part: 'CERVICAL SPINE', pt: 'K.L.', scr: true, ins: true },
{ time: '8:00A', type: 'CT', title: 'CHEST W/ CONTRAST', src: 'ER', body_part: 'CHEST', pt: 'M.S.', scr: true, ins: false },
{ time: '8:30A', type: 'CT', title: 'ABD/PELVIS W/O', src: 'IP', body_part: 'ABDOMEN/PELVIS', pt: 'R.T.', scr: true, ins: true },
{ time: '9:00A', type: 'XRAY', title: 'LEFT HAND 3 VIEW', src: 'OP', body_part: 'LEFT HAND', pt: 'A.B.', scr: false, ins: true },
{ time: '9:15A', type: 'XRAY', title: 'CHEST PA+LAT', src: 'OP', body_part: 'CHEST', pt: 'C.W.', scr: true, ins: true },
{ time: '9:30A', type: 'US', title: 'ABDOMEN COMPLETE', src: 'OP', body_part: 'ABDOMEN', pt: 'D.F.', scr: true, ins: true },
{ time: '10:00', type: 'MRI', title: 'KNEE W/O CONTRAST', src: 'OP', body_part: 'RIGHT KNEE', pt: 'E.G.', scr: true, ins: false },
{ time: '10:30', type: 'CT', title: 'HEAD W/O CONTRAST', src: 'ER', body_part: 'HEAD', pt: 'H.J.', scr: true, ins: true },
{ time: '11:00', type: 'FLUOR', title: 'BARIUM SWALLOW', src: 'OP', body_part: 'ESOPHAGUS', pt: 'P.Q.', scr: true, ins: true },
];
const DEMO_P2 = [
{ time: '7:00A', type: 'MRI', title: 'LUMBAR SPINE W/O', src: 'OP', body_part: 'LUMBAR SPINE', pt: 'L.M.', scr: true, ins: true },
{ time: '7:45A', type: 'MRI', title: 'SHOULDER W/ CONTRAST', src: 'OP', body_part: 'LEFT SHOULDER', pt: 'N.O.', scr: true, ins: true },
{ time: '8:30A', type: 'CT', title: 'CHEST/ABD/PEL W/', src: 'ER', body_part: 'CHEST+ABD+PEL', pt: 'S.T.', scr: false, ins: true },
{ time: '9:00A', type: 'US', title: 'THYROID COMPLETE', src: 'OP', body_part: 'THYROID', pt: 'U.V.', scr: true, ins: true },
{ time: '9:30A', type: 'XRAY', title: 'ANKLE 3 VIEW', src: 'ER', body_part: 'RIGHT ANKLE', pt: 'W.X.', scr: true, ins: false },
{ time: '10:00', type: 'MRI', title: 'BRAIN W/ + W/O', src: 'IP', body_part: 'BRAIN', pt: 'Y.Z.', scr: true, ins: true },
{ time: '10:45', type: 'CT', title: 'SINUSES W/O', src: 'OP', body_part: 'SINUSES', pt: 'B.C.', scr: true, ins: true },
];
// ─── Load Day Data ─────────────────────────────────────────────────
let p1Rows = [];
let p2Rows = [];
function loadDay(dateStr) {
const d = new Date(dateStr + 'T00:00:00');
const days = ['SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY'];
const months = ['JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE',
'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER'];
const dayName = days[d.getDay()];
const monthName = months[d.getMonth()];
const dateNum = String(d.getDate()).padStart(2, '0');
const displayDate = `${dayName}, ${monthName} ${dateNum}, ${d.getFullYear()}`;
setDateText(displayDate);
// Seed a simple RNG from the date so each day looks different but is stable
let seed = 0;
for (let i = 0; i < dateStr.length; i++) seed = ((seed << 5) - seed + dateStr.charCodeAt(i)) | 0;
function rand() { seed = (seed * 16807 + 0) % 2147483647; return (seed & 0x7fffffff) / 2147483647; }
// Shuffle and slice demo data per day
function pick(arr) {
const shuffled = arr.slice().sort(() => rand() - 0.5);
const count = 3 + Math.floor(rand() * (shuffled.length - 2));
return shuffled.slice(0, count);
}
const p1Items = pick(DEMO_P1);
for (let r = 0; r < MAX_ROWS; r++) {
const text = r < p1Items.length ? formatRow(p1Items[r]) : ''.padEnd(TOTAL_CHARS);
setTimeout(() => setRowText(p1Rows[r], text), r * 20);
}
const p2Items = pick(DEMO_P2);
for (let r = 0; r < MAX_ROWS; r++) {
const text = r < p2Items.length ? formatRow(p2Items[r]) : ''.padEnd(TOTAL_CHARS);
setTimeout(() => setRowText(p2Rows[r], text), 80 + r * 20);
}
}
// ─── Navigation ────────────────────────────────────────────────────
function goToDate(d) {
currentDate = d;
loadDay(formatDateStr(d));
}
// ─── Init ─────────────────────────────────────────────────────────
function init() {
const sections = document.getElementById('sections');
p1Rows = buildSection(sections, 'P1 PRISMA');
const spacer = document.createElement('div');
spacer.style.marginTop = '24px';
sections.appendChild(spacer);
p2Rows = buildSection(sections, 'P2 PRISMA FIT');
// Navigation
document.getElementById('btn-prev').addEventListener('click', () => goToDate(addDays(currentDate, -1)));
document.getElementById('btn-today').addEventListener('click', () => goToDate(todayEastern()));
document.getElementById('btn-next').addEventListener('click', () => goToDate(addDays(currentDate, 1)));
document.addEventListener('keydown', (e) => {
if (e.key === 'ArrowLeft') { e.preventDefault(); goToDate(addDays(currentDate, -1)); }
else if (e.key === 'ArrowRight') { e.preventDefault(); goToDate(addDays(currentDate, 1)); }
});
// Auto-scale board to fit viewport
function scaleBoard() {
const wrapper = document.getElementById('board-wrapper');
const board = document.getElementById('board');
wrapper.style.transform = 'none';
const boardWidth = board.offsetWidth + 60;
const viewportWidth = window.innerWidth;
if (boardWidth > viewportWidth) {
wrapper.style.transform = `scale(${viewportWidth / boardWidth})`;
}
}
scaleBoard();
window.addEventListener('resize', scaleBoard);
// Load today
goToDate(todayEastern());
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();
</script>
</body>
</html>