Files
Rosea/tools/art-prep/board/index.html
T
mnovak f24597dfdb [art-prep] ArtBoard: Build prompts, stand-ins and the art board from the manifest, and accept pictures into art/final
tools/art-prep reads art/STYLE.md (draft) and art/manifest.json (25 Phase 1
pictures), refuses forbidden words in any prompt, writes 29 stand-ins and the
board files, and cuts and encodes accepted pictures as WebP within budget.
2026-11-01 20:16:59 +01:00

1109 lines
65 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<title>%PRODUCT_NAME% Art Board</title>
<meta name="claude:viewport-fit-sides" content="cover">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Young+Serif&family=Nunito:wght@400;600;700&family=JetBrains+Mono:wght@400;600&display=swap">
<style>
/* Layout: a gardener's potting bench. One column of kinds, each a wrap of picture cards;
the stand-in and your picture side by side, so every judgement is a comparison. */
:root {
--paper: #fbf6f1; /* the app's --paper token */
--card: #fffaf7;
--ink: #2b2324; /* the app's --ink */
--ink-soft: #6b5d5e;
--accent: #b4485e; /* the app's --rose: the hero colour */
--moss: #4f6e52; /* STYLE.md §2 deep leaves */
--sage: #7fa07a;
--gold: #e0a84a;
--rose: #f2b5be; /* STYLE.md §2 pale petal: another try */
--line: color-mix(in srgb, var(--ink) 22%, transparent);
--check-a: #f1e6e2;
--check-b: #fbf5f2;
--ok: #4f6e52;
--warn: #8f5416; /* 5.6:1 on the card */
--accept: #4f6e52; /* the card on it: 5.9:1 */
--on-pill: #2b2324;
--display: "Young Serif", Georgia, "Times New Roman", serif;
--body: "Nunito", ui-rounded, "Segoe UI", system-ui, sans-serif;
--mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
--radius: 18px;
}
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) {
--paper: #1d1819; --card: #2a2224; --ink: #f1e8e6; --ink-soft: #b8a9a8;
--accent: #e8899b; --moss: #a9c99a; --sage: #8db37a; --gold: #f2c66d; --rose: #e9a9b4;
--line: color-mix(in srgb, var(--ink) 20%, transparent);
--check-a: #352b2e; --check-b: #40353a; --ok: #a9d39a; --warn: #f2c66d; --accept: #a9c99a; --on-pill: #2b2324;
color-scheme: dark;
}
}
:root[data-theme="dark"] {
--paper: #1d1819; --card: #2a2224; --ink: #f1e8e6; --ink-soft: #b8a9a8;
--accent: #e8899b; --moss: #a9c99a; --sage: #8db37a; --gold: #f2c66d; --rose: #e9a9b4;
--line: color-mix(in srgb, var(--ink) 20%, transparent);
--check-a: #352b2e; --check-b: #40353a; --ok: #a9d39a; --warn: #f2c66d; --accept: #a9c99a; --on-pill: #2b2324;
color-scheme: dark;
}
* { box-sizing: border-box; }
body {
background: var(--paper);
color: var(--ink);
font: 400 16px/1.55 var(--body);
padding-left: max(16px, env(safe-area-inset-left, 0px));
padding-right: max(16px, env(safe-area-inset-right, 0px));
padding-block: 24px 64px;
}
.wrap { max-width: 1180px; margin: 0 auto; display: grid; gap: 28px; }
h1, h2, h3 { font-family: var(--display); font-weight: 400; line-height: 1.1; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(2rem, 5vw, 3rem); }
h2 { font-size: 1.6rem; }
.muted { color: var(--ink-soft); }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
header { display: grid; gap: 14px; }
.lede { max-width: 62ch; margin: 0; }
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin: 0; padding: 0; list-style: none; counter-reset: step; }
.steps li { counter-increment: step; display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; }
.steps li::before {
content: counter(step); font: 700 1.25rem/1 var(--display); /* large text: cream on rust (4.3:1) needs 3:1 */ width: 30px; height: 30px; display: grid; place-items: center;
border-radius: 50%; background: var(--accent); color: var(--card);
}
.progress { display: grid; gap: 8px; }
.bar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--check-a); border: 2px solid var(--ink); }
.bar span { display: block; height: 100%; transition: width .3s; }
.bar .s-accepted { background: var(--moss); }
.bar .s-uploaded { background: var(--gold); }
.bar .s-retry { background: var(--rose); }
.progress p { margin: 0; font-variant-numeric: tabular-nums; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
border: 2px solid var(--ink); background: var(--card); border-radius: 999px; padding: 6px 14px; min-height: 40px;
font-weight: 700; cursor: pointer; font-variant-numeric: tabular-nums;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.notice { margin: 0; padding: 12px 16px; border-radius: 12px; background: var(--check-a); }
.notice[hidden] { display: none; }
section.group { display: grid; gap: 14px; }
.group > p { margin: -6px 0 0; max-width: 70ch; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 16px; align-items: start; }
article.asset {
background: var(--card); border: 2px solid var(--ink); border-radius: var(--radius); padding: 14px;
display: grid; gap: 12px; min-width: 0; position: relative;
}
article.asset::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 6px; border-radius: var(--radius) 0 0 var(--radius); background: transparent; }
article.asset[data-status="accepted"]::before { background: var(--moss); }
article.asset[data-status="uploaded"]::before { background: var(--gold); }
article.asset[data-status="retry"]::before { background: var(--rose); }
.head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: baseline; justify-content: space-between; }
.id { font: 600 0.95rem/1.3 var(--mono); overflow-wrap: anywhere; }
.pill { font-size: .8rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; border: 2px solid var(--ink); white-space: nowrap; }
.pill.todo { background: transparent; }
.pill.uploaded { background: var(--gold); color: var(--on-pill); }
.pill.retry { background: var(--rose); color: var(--on-pill); }
.pill.accepted { background: var(--accept); color: var(--card); }
.meta { font-size: .85rem; color: var(--ink-soft); margin: -6px 0 0; font-variant-numeric: tabular-nums; }
.used { margin: 0; padding-left: 18px; font-size: .88rem; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: start; }
figure { margin: 0; display: grid; gap: 4px; min-width: 0; }
figcaption { font-size: .78rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft); }
.frame {
aspect-ratio: var(--ar); width: 100%; max-width: 100%; border-radius: 10px; border: 2px solid var(--line); overflow: hidden;
display: grid; place-items: center; position: relative;
}
.frame.alpha { background: repeating-conic-gradient(var(--check-a) 0 25%, var(--check-b) 0 50%) 0 0 / 16px 16px; }
.frame.full { background: var(--check-b); }
.frame img { width: 100%; height: 100%; object-fit: contain; display: block; }
.drop { cursor: pointer; text-align: center; padding: 8px; font-size: .88rem; font-weight: 700; color: var(--ink-soft); }
.drop.over { outline: 3px dashed var(--accent); outline-offset: -6px; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop input:disabled { cursor: not-allowed; }
.pastebox {
min-height: 64px; padding: 10px 12px; border: 2px dashed var(--accent); border-radius: 10px;
font-size: .88rem; font-weight: 700; color: var(--ink-soft); caret-color: transparent; outline: none;
}
.pastebox:focus-visible, .pastebox:focus { background: var(--check-a); }
.pastebox:empty::before { content: attr(data-hint); }
.auto { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: .88rem; }
.auto li::before { content: "○ "; }
.auto li.ok { color: var(--ok); }
.auto li.ok::before { content: "✓ "; }
.auto li.warn { color: var(--warn); }
.auto li.warn::before { content: "! "; font-weight: 700; }
.auto li.info { color: var(--ink-soft); }
.claude { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--check-a); font-size: .9rem; }
.small { display: flex; gap: 10px; align-items: center; font-size: .85rem; }
.small .frame { width: auto; aspect-ratio: auto; border-radius: 6px; }
details.prompt summary, details.review summary { cursor: pointer; font-weight: 700; }
details.review fieldset { margin-top: 8px; }
details.prompt pre {
margin: 8px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--check-a); white-space: pre-wrap;
font: 400 .78rem/1.5 var(--mono); max-height: 260px; overflow: auto;
}
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 6px; }
legend { font-weight: 700; margin-bottom: 4px; }
fieldset label { display: grid; grid-template-columns: 22px 1fr; gap: 8px; align-items: start; font-size: .9rem; cursor: pointer; }
fieldset input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--moss); }
textarea {
width: 100%; min-height: 64px; resize: vertical; border: 2px solid var(--line); border-radius: 10px; padding: 8px 10px;
background: var(--paper);
}
.btn {
border: 2px solid var(--ink); border-radius: 999px; padding: 8px 16px; min-height: 44px; font-weight: 700; cursor: pointer;
background: var(--card);
}
.btn.primary { background: var(--accept); color: var(--card); border-color: var(--accept); }
.btn.primary:disabled { background: transparent; color: var(--ink-soft); border-color: var(--line); cursor: not-allowed; }
.btn.quiet { border-color: var(--line); }
.btn:disabled { cursor: not-allowed; opacity: .6; }
/* Sprite sheets and maps: wide cards, the cut grid laid over the upload, the pictures it makes. */
article.asset.wide { grid-column: 1 / -1; }
.attach { margin: -6px 0 0; font-size: .88rem; }
.yields { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 4px 6px; font: 400 .76rem/1.5 var(--mono); }
.yields li { padding: 1px 9px; border-radius: 999px; background: var(--check-a); }
.yields li b { font-weight: 600; color: var(--ink-soft); margin-right: 4px; }
.yields li.bad { background: var(--rose); color: var(--on-pill); }
.yields li.bad b { color: var(--on-pill); }
.yields li.edge { box-shadow: inset 0 0 0 2px var(--warn); }
@media (max-width: 640px) { article.asset.wide .compare { grid-template-columns: 1fr; } }
.overlay { position: absolute; inset: 0; display: grid; pointer-events: none; }
.overlay span { border: 1px dashed color-mix(in srgb, var(--accent) 75%, transparent); font: 600 .7rem/1 var(--mono); color: var(--accent); padding: 4px; }
.overlay span.bad { background: color-mix(in srgb, var(--rose) 50%, transparent); }
.overlay span.edge { border: 2px solid var(--warn); }
/* One cell at a time: a slot per picture of a sprite sheet. */
details.cells-one > summary { cursor: pointer; font-weight: 700; }
.cellgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 12px; margin-top: 10px; }
.cell { display: grid; gap: 8px; padding: 10px; border: 2px solid var(--line); border-radius: 14px; background: var(--paper); min-width: 0; position: relative; }
.cell[data-status="accepted"] { border-color: var(--accept); }
.cell[data-status="uploaded"] { border-color: var(--gold); }
.cell[data-status="retry"] { border-color: var(--rose); }
.cell .head .id { font-size: .82rem; }
.cell .head b { font: 600 .82rem/1.3 var(--mono); color: var(--ink-soft); margin-right: 4px; }
.cell .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cell .frame { border-radius: 8px; }
.cell .drop { font-size: .78rem; padding: 4px; }
.cell .btn { min-height: 44px; padding: 6px 12px; font-size: .88rem; }
.cell .pastebox { min-height: 48px; font-size: .8rem; }
.cell .auto { font-size: .8rem; }
#toast {
position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; font-weight: 700; max-width: calc(100% - 32px);
box-shadow: 0 6px 18px rgba(0,0,0,.2);
}
@media (prefers-reduced-motion: reduce) { .bar span { transition: none; } }
/* All at once: every picture still to make in one prompt (or a few), and one drop for all of them. */
section.batch { display: grid; gap: 14px; margin: 0 0 36px; padding: 18px; border: 2px solid var(--line); border-radius: 18px; background: var(--card); }
section.batch h2 { margin: 0; }
.batch .row label { display: flex; gap: 8px; align-items: center; font-weight: 700; font-size: .9rem; }
.batch select { min-height: 40px; border: 2px solid var(--line); border-radius: 10px; padding: 4px 8px; background: var(--paper); font: inherit; }
.batch ol.prompts { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.batch ol.prompts li { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.batch .bulk { position: relative; border: 2px dashed var(--line); border-radius: 14px; padding: 18px; text-align: center; font-weight: 700; color: var(--ink-soft); cursor: pointer; }
.batch .bulk.over { border-color: var(--accent); color: var(--ink); }
.batch .bulk input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.batch .bulk input:disabled { cursor: not-allowed; }
.batch ul.matches { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.batch ul.matches li { display: grid; grid-template-columns: 56px 1fr; gap: 10px; align-items: center; }
.batch ul.matches img { width: 56px; height: 56px; object-fit: contain; border-radius: 8px; background: var(--check-a); }
.batch ul.matches .name { font-size: .82rem; color: var(--ink-soft); overflow-wrap: anywhere; }
</style>
<div class="wrap">
<header>
<h1>Art board</h1>
<p class="lede">Every picture %PRODUCT_NAME% needs, with the prompt that makes it. The app shows a simple stand-in for each until a picture here is accepted.</p>
<ol class="steps">
<li><span>Copy a prompt into your image generator. Start with the rose's character sheet: every later rose prompt asks for it as the reference picture. A <em>sprite sheet</em> is one prompt that draws several pictures at once on a grid whose every cell is given in pixels; upload it whole and Claude cuts it apart. If a sheet will not keep to its grid, open <em>One at a time</em> on its card and make each picture with its own prompt.</span></li>
<li><span>Upload or paste what it made: <em>Paste picture</em> on its card, or point at the card and press Ctrl+V (⌘V on a Mac). Compare it with the stand-in. The review points from <code>art/STYLE.md</code> are under each card if you want them; you don't have to tick them.</span></li>
<li><span>Accept it right away, or ask for another try with a note. Claude moves accepted pictures into the app.</span></li>
</ol>
<div class="progress" aria-live="polite">
<div class="bar" id="bar" role="img" aria-label="Progress"></div>
<p id="progressText" class="muted">Loading the board…</p>
</div>
<p class="notice" id="readonly" hidden></p>
<div class="filters" id="filters" role="group" aria-label="Show"></div>
</header>
<section class="batch" id="batch" aria-labelledby="batch-h">
<h2 id="batch-h">All at once</h2>
<p class="muted">Every picture still to make, written as one prompt: the style once, then each picture by name, size and background, in the order to make them. Paste it into your image generator and let it make them one after another, attaching the accepted character sheets it names. A long list is split into a few prompts, because generators cut off very long ones.</p>
<div class="row">
<label>Pictures <select id="batchScope">
<option value="todo">Still to make and another try</option>
<option value="open">Everything not accepted yet</option>
</select></label>
<label>Per prompt <select id="batchSize">
<option value="5">5</option><option value="10">10</option><option value="20">20</option><option value="0">All in one</option>
</select></label>
</div>
<p id="batchSummary" class="muted" aria-live="polite"></p>
<ol class="prompts" id="batchPrompts"></ol>
<h3>Upload them all together</h3>
<p class="muted">Drop every picture it made here at once. Each file finds its picture by its name (for example <code>rose-sheet.png</code>); files named otherwise are matched in the order of the prompt you choose below. Check the matches, then upload.</p>
<div class="row"><label>Files without a matching name follow <select id="batchOrder"></select></label></div>
<div class="bulk" id="bulk"><span id="bulkText">Drop all the pictures here, or choose them</span><input type="file" id="bulkFile" multiple accept="image/png,image/webp,image/jpeg" aria-label="Choose all the pictures to upload"></div>
<ul class="matches" id="matches" aria-label="Which picture each file is for"></ul>
<div class="row" id="matchActions" hidden>
<button class="btn primary" type="button" id="uploadAll">Upload</button>
<button class="btn quiet" type="button" id="clearAll">Clear</button>
</div>
</section>
<main id="groups"></main>
</div>
<div id="toast" role="status" hidden></div>
<script>
(() => {
const GROUPS = [
{ type: 'sheet', title: 'Character sheet', note: 'Make this first. Every rose prompt asks for it as the reference picture, so give your generator the accepted sheet when you make the rest.' },
{ type: 'spritesheet', title: 'Sprite sheets', note: 'One prompt, one image, several pictures. The prompt gives the grid in pixels: where every cell starts, its centre, and the safe box its drawing must stay inside. Upload the whole sheet as it came out: the dashed grid shows where the cuts fall, and each cell must hold its own drawing. When a sheet keeps drifting off its grid, open One at a time and make each picture on its own, with its own prompt: each is accepted separately. Attach the character sheet the card names.' },
{ type: 'layer', title: 'Garden layers', note: 'The same garden at four times of day. The sky stays transparent: the app draws the real sky, sun and stars behind it.' },
{ type: 'sprite', title: 'Single pictures', note: 'One thing on a transparent background, placed over the garden in the app.' },
{ type: 'icon', title: 'App icon', note: 'The home-screen icon. Keep the bloom inside the middle 70%; phones cut the corners.' },
];
const FILTERS = [['all', 'All'], ['todo', 'To make'], ['uploaded', 'To review'], ['retry', 'Another try'], ['accepted', 'Accepted']];
const STATUS_TEXT = { todo: 'To make', uploaded: 'To review', retry: 'Another try', accepted: 'Accepted' };
const EMPTY_TEXT = 'Drop, paste or choose your picture';
const NO_PICTURE = 'There is no picture on the clipboard. Copy the image itself (right-click it → Copy image), then paste again.';
let hovered = null; // asset id under the pointer: where a bare Ctrl+V goes
let data = null;
const rows = {}; // asset id -> stored row
const cards = {}; // asset id -> {el, refs}
const cellCards = {}; // cell id -> {el, refs, cell, sheet}: a sprite sheet's pictures made one at a time
const sheetOf = {}; // cell id -> its sheet's board row
const chains = {}; // asset id -> promise: one write at a time per document
let db = null, assets = null, canWrite = false;
let filter = 'all';
try { filter = localStorage.getItem('rosea-art-board-filter') || 'all'; } catch (e) { /* storage unavailable: default filter */ }
const $ = (sel, el = document) => el.querySelector(sel);
const h = (tag, attrs = {}, ...kids) => {
const el = document.createElement(tag);
for (const [k, v] of Object.entries(attrs)) {
if (v === false || v == null) continue;
if (k === 'class') el.className = v; else if (k === 'text') el.textContent = v;
else if (k.startsWith('on')) el.addEventListener(k.slice(2), v); else el.setAttribute(k, v === true ? '' : v);
}
for (const kid of kids.flat()) if (kid != null) el.append(kid);
return el;
};
let toastTimer;
function toast(msg) {
const t = $('#toast');
t.textContent = msg; t.hidden = false;
clearTimeout(toastTimer); toastTimer = setTimeout(() => (t.hidden = true), 3200);
}
const statusOf = (id) => {
const r = rows[id];
if (!r) return 'todo';
if (r.status === 'accepted' || r.status === 'retry') return r.status;
return r.image ? 'uploaded' : 'todo';
};
const imgUrl = (r) => (r && r.image ? '/_blob/' + r.image : null);
const cellsIn = (a) => (a.cells ? a.cells.filter(Boolean) : []);
/** A sprite sheet's card: accepted whole or cell by cell; to review when any of its pictures waits. */
function cardStatus(a) {
const own = statusOf(a.id);
if (a.type !== 'spritesheet') return own;
const cells = cellsIn(a).map((c) => statusOf(c.id));
if (own === 'accepted' || (cells.length && cells.every((c) => c === 'accepted'))) return 'accepted';
if (own === 'uploaded' || cells.includes('uploaded')) return 'uploaded';
if (own === 'retry' || cells.includes('retry')) return 'retry';
return cells.includes('accepted') ? 'uploaded' : own;
}
/** How many of a card's pictures are accepted: a whole sheet counts all its cells. */
function picturesDone(a) {
if (a.type !== 'spritesheet') return statusOf(a.id) === 'accepted' ? 1 : 0;
if (statusOf(a.id) === 'accepted') return cellsIn(a).length;
return cellsIn(a).filter((c) => statusOf(c.id) === 'accepted').length;
}
// ---------- rendering ----------
function renderFilters() {
const counts = { all: data.assets.length, todo: 0, uploaded: 0, retry: 0, accepted: 0 };
for (const a of data.assets) counts[cardStatus(a)]++;
const wrap = $('#filters');
wrap.replaceChildren(...FILTERS.map(([key, label]) =>
h('button', { class: 'chip', type: 'button', 'aria-pressed': String(filter === key), onclick: () => setFilter(key) }, `${label} · ${counts[key]}`)));
const bar = $('#bar');
const total = data.assets.length;
bar.replaceChildren(...['accepted', 'uploaded', 'retry'].map((s) => h('span', { class: 's-' + s, style: `width:${(counts[s] / total) * 100}%` })));
bar.setAttribute('aria-label', `${counts.accepted} of ${total} accepted, ${counts.uploaded} to review, ${counts.retry} for another try`);
// A sprite sheet is one card but several pictures in the app.
const pics = (a) => (a.cells ? a.cells.filter(Boolean).length : 1);
const allPics = data.assets.reduce((n, a) => n + pics(a), 0);
const donePics = data.assets.reduce((n, a) => n + picturesDone(a), 0);
$('#progressText').textContent = `${donePics} of ${allPics} pictures accepted · ${counts.uploaded} to review · ${counts.retry} for another try · ${counts.todo} prompts still to make`;
}
function setFilter(key) {
filter = key;
try { localStorage.setItem('rosea-art-board-filter', key); } catch (e) { /* storage unavailable: filter just won't be remembered */ }
applyFilter(); renderFilters();
}
function applyFilter() {
for (const g of GROUPS) {
const sec = document.getElementById('group-' + g.type);
if (!sec) continue;
let shown = 0;
for (const a of data.assets.filter((x) => x.type === g.type)) {
const show = filter === 'all' || cardStatus(a) === filter;
cards[a.id].el.hidden = !show;
if (show) shown++;
}
sec.hidden = shown === 0;
}
}
function buildCard(a) {
const ar = `${a.width} / ${a.height}`;
const frameClass = a.background === 'transparent' ? 'frame alpha' : 'frame full';
const refs = {};
refs.pill = h('span', { class: 'pill todo', text: 'To make' });
refs.mine = h('div', { class: frameClass + ' drop', style: `--ar:${ar}` });
refs.file = h('input', { type: 'file', accept: 'image/png,image/webp,image/jpeg', 'aria-label': `Upload your picture for ${a.id}`, id: 'file-' + a.id });
refs.dropText = h('span', { text: EMPTY_TEXT });
refs.mine.append(refs.dropText, refs.file);
refs.file.addEventListener('change', () => refs.file.files[0] && upload(a, refs.file.files[0]));
refs.mine.addEventListener('dragover', (e) => { e.preventDefault(); refs.mine.classList.add('over'); });
refs.mine.addEventListener('dragleave', () => refs.mine.classList.remove('over'));
refs.mine.addEventListener('drop', (e) => {
e.preventDefault(); refs.mine.classList.remove('over');
const f = e.dataTransfer.files[0]; if (f && canUpload()) upload(a, f);
});
refs.paste = h('button', { class: 'btn', type: 'button', 'aria-label': `Paste your picture for ${a.id}`, onclick: () => pasteFromButton(a) }, 'Paste picture');
// Fallback where the page may not read the clipboard itself: the browser's own paste lands here.
refs.pasteBox = h('div', {
class: 'pastebox', contenteditable: 'true', role: 'textbox', inputmode: 'none', hidden: true,
'aria-label': `Paste your picture for ${a.id} here`, 'data-hint': 'Press Ctrl+V (⌘V on a Mac), or long-press here and choose Paste. Esc closes this.',
});
refs.pasteBox.addEventListener('beforeinput', (e) => e.preventDefault()); // nothing gets typed in; paste is handled below
refs.pasteBox.addEventListener('keydown', (e) => { if (e.key === 'Escape') { refs.pasteBox.hidden = true; refs.paste.focus(); } });
const sheet = a.type === 'spritesheet';
if (sheet) {
refs.overlay = h('div', { class: 'overlay', 'aria-hidden': 'true', hidden: true,
style: `grid-template-columns:repeat(${a.grid.cols},1fr);grid-template-rows:repeat(${a.grid.rows},1fr)` },
a.cells.map((c, i) => h('span', { text: c ? String(i + 1) : '' })));
refs.mine.append(refs.overlay);
refs.yields = h('ol', { class: 'yields', 'aria-label': `The ${a.cells.filter(Boolean).length} pictures this sheet makes, in reading order` },
a.cells.map((c, i) => (c ? h('li', {}, h('b', { text: String(i + 1) }), c.id) : h('li', {}, h('b', { text: String(i + 1) }), '(empty)'))));
refs.oneSummary = h('summary', { text: 'One at a time' });
refs.one = h('details', { class: 'cells-one' }, refs.oneSummary,
h('p', { class: 'muted', text: 'When the whole sheet will not keep to its grid, make each picture on its own: copy its prompt, attach the same reference picture, and upload what it made into its slot. Each is accepted on its own; the sheet is done when all its pictures are in.' }),
h('div', { class: 'cellgrid' }, a.cells.map((c, i) => (c ? buildCell(a, c, i) : null))));
}
refs.auto = h('ul', { class: 'auto', 'aria-label': 'Automatic checks' });
refs.small = h('div', { class: 'small', hidden: true });
refs.claude = h('p', { class: 'claude', hidden: true });
refs.checks = a.checks.map((i) => {
const box = h('input', { type: 'checkbox', id: `chk-${a.id}-${i}` });
box.addEventListener('change', () => saveChecks(a));
return { i, box, label: h('label', { for: `chk-${a.id}-${i}` }, box, h('span', { text: data.checklist[i] })) };
});
refs.note = h('textarea', { id: 'note-' + a.id, placeholder: 'What to change next time (optional)', 'aria-label': `Note for ${a.id}` });
refs.note.addEventListener('change', () => save(a.id, { note: refs.note.value.trim() }));
const acceptedText = sheet ? `Accepted. Claude will cut it into ${a.cells.filter(Boolean).length} pictures.` : 'Accepted. Claude will move it into the app.';
refs.accept = h('button', { class: 'btn primary', type: 'button', onclick: () => save(a.id, { status: 'accepted' }, acceptedText) }, 'Accept');
refs.retry = h('button', { class: 'btn', type: 'button', onclick: () => save(a.id, { status: 'retry' }, 'Marked for another try.') }, 'Another try');
refs.reopen = h('button', { class: 'btn quiet', type: 'button', hidden: true, onclick: () => save(a.id, { status: 'review' }, 'Back to review.') }, 'Review again');
const copyBtn = h('button', { class: 'btn', type: 'button' }, 'Copy prompt');
const pre = h('pre', { text: a.prompt });
const details = h('details', { class: 'prompt' }, h('summary', { text: 'Show the prompt' }), pre);
copyBtn.addEventListener('click', () => {
const done = () => toast('Prompt copied.');
const fallback = () => {
details.open = true;
const range = document.createRange(); range.selectNodeContents(pre);
const sel = getSelection(); sel.removeAllRanges(); sel.addRange(range);
toast('Prompt selected: copy it with your keyboard or the menu.');
};
try { navigator.clipboard.writeText(a.prompt).then(done, fallback); } catch (e) { fallback(); }
});
const bg = a.background === 'transparent' ? 'transparent background' : 'full background';
const meta = sheet
? `sprite sheet · ${a.grid.cols} × ${a.grid.rows} grid · ${a.width} × ${a.height} px · ${bg} · makes ${a.cells.filter(Boolean).length} pictures`
: `${a.type} · ${a.width} × ${a.height} px · ${bg}${a.shipped || a.usedBy.some((u) => u.startsWith('Not in the app yet')) ? '' : ' · reference only, not in the app'}`;
const el = h('article', { class: 'asset' + (sheet || a.type === 'map' ? ' wide' : ''), id: a.id, 'data-status': 'todo' },
h('div', { class: 'head' }, h('h3', { class: 'id', text: a.id }), refs.pill),
h('p', { class: 'meta', text: meta }),
a.attach && a.attach.length ? h('p', { class: 'attach' }, 'Attach as the reference picture: ', h('strong', { text: a.attach.join(', ') })) : null,
h('ul', { class: 'used' }, a.usedBy.map((u) => h('li', { text: u }))),
refs.yields || null,
refs.one || null,
h('div', { class: 'compare' },
h('figure', {}, h('figcaption', { text: 'Stand-in' }), h('div', { class: frameClass, style: `--ar:${ar}` }, h('img', { src: 'placeholders/' + a.id + '.svg', alt: `Stand-in for ${a.id}`, loading: 'lazy' }))),
h('figure', {}, h('figcaption', { text: 'Your picture' }), refs.mine, h('div', { class: 'row' }, refs.paste), refs.pasteBox)),
refs.auto, refs.small, refs.claude,
h('div', { class: 'row' }, copyBtn), details,
h('details', { class: 'review' }, h('summary', { text: 'Review points (optional)' }),
h('fieldset', {}, h('legend', { text: 'art/STYLE.md §7' }), refs.checks.map((c) => c.label))),
refs.note,
h('div', { class: 'row' }, refs.accept, refs.retry, refs.reopen));
el.addEventListener('pointerenter', () => (hovered = a.id));
el.addEventListener('pointerleave', () => { if (hovered === a.id) hovered = null; });
cards[a.id] = { el, refs, a };
return el;
}
function copyText(text, pre, details) {
const done = () => toast('Prompt copied.');
const fallback = () => {
if (details) details.open = true;
const range = document.createRange(); range.selectNodeContents(pre);
const sel = getSelection(); sel.removeAllRanges(); sel.addRange(range);
toast('Prompt selected: copy it with your keyboard or the menu.');
};
try { navigator.clipboard.writeText(text).then(done, fallback); } catch (e) { fallback(); }
}
// One picture of a sprite sheet, made on its own: its prompt, its upload, its own Accept.
function buildCell(a, c, i) {
const target = { id: c.id, width: c.width, height: c.height, background: c.background || a.background, cell: true };
sheetOf[c.id] = a;
const ar = `${c.width} / ${c.height}`;
const fc = target.background === 'transparent' ? 'frame alpha' : 'frame full';
const refs = {};
refs.pill = h('span', { class: 'pill todo', text: 'To make' });
refs.mine = h('div', { class: fc + ' drop', style: `--ar:${ar}` });
refs.file = h('input', { type: 'file', accept: 'image/png,image/webp,image/jpeg', 'aria-label': `Upload your picture for ${c.id}` });
refs.dropText = h('span', { text: 'Drop or choose' });
refs.mine.append(refs.dropText, refs.file);
refs.file.addEventListener('change', () => refs.file.files[0] && upload(target, refs.file.files[0]));
refs.mine.addEventListener('dragover', (e) => { e.preventDefault(); refs.mine.classList.add('over'); });
refs.mine.addEventListener('dragleave', () => refs.mine.classList.remove('over'));
refs.mine.addEventListener('drop', (e) => {
e.preventDefault(); refs.mine.classList.remove('over');
const f = e.dataTransfer.files[0]; if (f && canUpload()) upload(target, f);
});
refs.paste = h('button', { class: 'btn', type: 'button', 'aria-label': `Paste your picture for ${c.id}`, onclick: () => pasteFromButton(target) }, 'Paste');
refs.pasteBox = h('div', {
class: 'pastebox', contenteditable: 'true', role: 'textbox', inputmode: 'none', hidden: true,
'aria-label': `Paste your picture for ${c.id} here`, 'data-hint': 'Press Ctrl+V (⌘V on a Mac), or long-press here and choose Paste. Esc closes this.',
});
refs.pasteBox.addEventListener('beforeinput', (e) => e.preventDefault());
refs.pasteBox.addEventListener('keydown', (e) => { if (e.key === 'Escape') { refs.pasteBox.hidden = true; refs.paste.focus(); } });
refs.auto = h('ul', { class: 'auto', 'aria-label': `Automatic checks for ${c.id}` });
const pre = h('pre', { text: c.prompt });
const details = h('details', { class: 'prompt' }, h('summary', { text: 'Show its prompt' }), pre);
const copyBtn = h('button', { class: 'btn', type: 'button', 'aria-label': `Copy the prompt for ${c.id}`, onclick: () => copyText(c.prompt, pre, details) }, 'Copy prompt');
refs.accept = h('button', { class: 'btn primary', type: 'button', 'aria-label': `Accept ${c.id}`, onclick: () => save(c.id, { status: 'accepted', sheet: a.id }, `Accepted. Claude will move ${c.id} into the app.`) }, 'Accept');
refs.retry = h('button', { class: 'btn', type: 'button', 'aria-label': `Another try for ${c.id}`, onclick: () => save(c.id, { status: 'retry', sheet: a.id }, 'Marked for another try.') }, 'Another try');
refs.reopen = h('button', { class: 'btn quiet', type: 'button', hidden: true, 'aria-label': `Review ${c.id} again`, onclick: () => save(c.id, { status: 'review' }, 'Back to review.') }, 'Review again');
const el = h('div', { class: 'cell', id: 'cell-' + c.id, 'data-cell': c.id, 'data-status': 'todo' },
h('div', { class: 'head' }, h('span', { class: 'id' }, h('b', { text: String(i + 1) }), c.id), refs.pill),
h('div', { class: 'pair' },
h('div', { class: fc, style: `--ar:${ar}` }, h('img', { src: 'placeholders/' + c.id + '.svg', alt: `Stand-in for ${c.id}`, loading: 'lazy' })),
refs.mine),
refs.pasteBox, refs.auto,
h('div', { class: 'row' }, copyBtn, refs.paste), details,
h('div', { class: 'row' }, refs.accept, refs.retry, refs.reopen));
el.addEventListener('pointerenter', () => (hovered = c.id));
el.addEventListener('pointerleave', () => { if (hovered === c.id) hovered = null; });
cellCards[c.id] = { el, refs, cell: target, sheet: a };
return el;
}
function updateCell(id) {
const { el, refs, cell, sheet } = cellCards[id];
const r = rows[id] || {};
// A cell with no picture of its own is in when its whole sheet was accepted.
const withSheet = !r.image && statusOf(sheet.id) === 'accepted';
const status = withSheet ? 'accepted' : statusOf(id);
el.dataset.status = status;
refs.pill.className = 'pill ' + status; refs.pill.textContent = withSheet ? 'In with the sheet' : STATUS_TEXT[status];
const url = imgUrl(r);
let img = $('img', refs.mine);
if (url) {
if (!img) { img = h('img', { alt: `Your picture for ${id}` }); refs.mine.prepend(img); }
if (img.getAttribute('src') !== url) img.src = url;
refs.dropText.hidden = true;
img.onerror = () => { refs.dropText.hidden = false; refs.dropText.textContent = 'Could not load: upload again'; img.remove(); };
} else {
if (img) img.remove();
refs.dropText.hidden = false;
refs.dropText.textContent = canUpload() ? 'Drop or choose' : 'No picture yet';
}
refs.file.disabled = !canUpload();
refs.paste.disabled = !canUpload();
if (!canUpload()) refs.pasteBox.hidden = true;
const items = [];
if (r.image) {
if (cell.background === 'transparent') items.push(r.alpha === true ? ['ok', 'Transparent'] : ['warn', r.alpha === false ? 'Not transparent: ask for a transparent PNG' : 'Transparency not measured']);
if (r.edge === true) items.push(['warn', 'The drawing touches the edge: something may be cut off']);
else if (r.edge === false) items.push(['ok', 'Whole, clear of the edges']);
if (r.width && r.width < cell.width / 2) items.push(['info', `Only ${r.width} px wide; it will stay that small`]);
}
refs.auto.replaceChildren(...items.map(([cls, text]) => h('li', { class: cls, text })));
refs.auto.hidden = items.length === 0;
const decided = status === 'accepted' || status === 'retry';
refs.accept.hidden = decided; refs.retry.hidden = decided; refs.reopen.hidden = !decided || withSheet;
refs.accept.disabled = !canWrite || !r.image;
refs.accept.title = !r.image ? 'Upload a picture first' : '';
refs.retry.disabled = !canWrite || !r.image;
refs.reopen.disabled = !canWrite;
}
function updateCard(id) {
const { el, refs, a } = cards[id];
const r = rows[id] || {};
const status = statusOf(id);
const shown = cardStatus(a);
el.dataset.status = shown;
refs.pill.className = 'pill ' + shown; refs.pill.textContent = STATUS_TEXT[shown];
if (refs.one) {
for (const c of cellsIn(a)) updateCell(c.id);
const done = picturesDone(a);
const waiting = cellsIn(a).filter((c) => statusOf(c.id) === 'uploaded').length;
refs.oneSummary.textContent = `One at a time · ${done} of ${cellsIn(a).length} accepted${waiting ? ` · ${waiting} to review` : ''}`;
}
const url = imgUrl(r);
let img = $('img', refs.mine);
if (url) {
if (!img) { img = h('img', { alt: `Your picture for ${id}` }); refs.mine.prepend(img); }
if (img.getAttribute('src') !== url) img.src = url;
refs.dropText.hidden = true;
img.onerror = () => { refs.dropText.hidden = false; refs.dropText.textContent = 'This picture could not be loaded. Upload it again.'; img.remove(); };
} else {
if (img) img.remove();
refs.dropText.hidden = false;
refs.dropText.textContent = canUpload() ? EMPTY_TEXT : 'No picture yet';
}
if (a.type === 'spritesheet') {
// The cut divides the image as it is, so show it at its own shape with the grid on top.
refs.mine.style.setProperty('--ar', r.image && r.width && r.height ? `${r.width} / ${r.height}` : `${a.width} / ${a.height}`);
refs.overlay.hidden = !url;
const report = r.image ? r.cellChecks || [] : [];
refs.overlay.querySelectorAll('span').forEach((sp, i) => {
const c = report[i];
sp.className = c && a.cells[i] && (!c.filled || c.seeThrough < 5) ? 'bad' : c && c.touches ? 'edge' : '';
});
refs.yields.querySelectorAll('li').forEach((li, i) => {
const c = report[i];
li.className = c && a.cells[i] && (!c.filled || c.seeThrough < 5) ? 'bad' : c && c.touches ? 'edge' : '';
});
}
refs.file.disabled = !canUpload();
refs.paste.disabled = !canUpload();
if (!canUpload()) refs.pasteBox.hidden = true;
// Automatic checks, measured on upload.
const items = [];
if (r.image && a.type === 'spritesheet') items.push(...sheetChecks(a, r));
else if (r.image) {
const want = a.width / a.height, got = r.width && r.height ? r.width / r.height : null;
if (got) {
const shapeOk = Math.abs(got - want) < 0.02;
items.push([shapeOk ? 'ok' : 'warn', shapeOk ? `Shape fits (${r.width} × ${r.height})` : `Shape is ${r.width} × ${r.height}; it should be ${a.width} × ${a.height} (it would be cropped)`]);
const bigEnough = r.width >= a.width;
items.push([bigEnough ? 'ok' : 'warn', bigEnough ? 'Big enough' : `Smaller than ${a.width} px wide; it may look soft`]);
}
if (a.background === 'transparent') {
items.push(r.alpha === true ? ['ok', 'Background is transparent'] : ['warn', r.alpha === false ? 'Background is not transparent; ask for a transparent PNG' : 'Transparency not measured']);
}
}
refs.auto.replaceChildren(...items.map(([cls, text]) => h('li', { class: cls, text })));
refs.auto.hidden = items.length === 0;
if (url && a.smallest) {
refs.small.hidden = false;
refs.small.replaceChildren(
h('div', { class: frameClassFor(a) }, h('img', { src: url, alt: '', style: `width:${a.smallest}px;height:${Math.round(a.smallest * a.height / a.width)}px;object-fit:contain` })),
h('span', { text: `At ${a.smallest} px, the smallest size in the app. Still clear?` }));
} else refs.small.hidden = true;
// Claude's review (STYLE.md §8) and the move into art/final/, both written into the row by Claude.
const said = [r.claude ? `Claude's review: ${r.claude}` : '', r.final ? `In art/final/: ${[].concat(r.final).join(', ')}.` : ''].filter(Boolean).join(' ');
refs.claude.textContent = said; refs.claude.hidden = !said;
const checks = r.checks || {};
for (const c of refs.checks) { c.box.checked = !!checks[c.i]; c.box.disabled = !canWrite; }
if (document.activeElement !== refs.note) refs.note.value = r.note || '';
refs.note.disabled = !canWrite;
const decided = status === 'accepted' || status === 'retry';
refs.accept.hidden = decided; refs.retry.hidden = decided; refs.reopen.hidden = !decided;
// Accept is one tap once a picture is up: the review points are a help, not a gate.
refs.accept.disabled = !canWrite || !r.image;
refs.accept.title = !r.image ? 'Upload a picture first' : '';
refs.retry.disabled = !canWrite || !r.image;
refs.reopen.disabled = !canWrite;
}
// What pnpm art:accept will say, measured here first: it divides the image by the grid
// whatever its size, refuses the whole sheet for an empty cell or a cell painted on a
// background, and warns when a drawing touches its cell's edge.
function sheetChecks(a, r) {
const items = [];
const { cols, rows } = a.grid;
if (r.width && r.height) {
const shapeOk = Math.abs(r.width / r.height - a.width / a.height) < 0.02;
items.push(shapeOk ? ['ok', `Shape fits (${r.width} × ${r.height})`]
: ['info', `Shape is ${r.width} × ${r.height}, not ${a.width} × ${a.height}. That is fine: the cut divides it by the ${cols} × ${rows} grid. Check that every drawing sits inside its own dashed cell.`]);
const cw = Math.floor(r.width / cols), ch = Math.floor(r.height / rows);
const want = a.width / cols;
if (cw < want * 0.98) items.push(['info', `Each cell is ${cw} × ${ch} px; pictures are kept at that size, never blown up.`]);
}
items.push(r.alpha === true ? ['ok', 'Background is transparent'] : ['warn', r.alpha === false ? 'Background is not transparent; ask for a transparent PNG. The cut refuses cells painted on a background.' : 'Transparency not measured']);
const report = r.cellChecks;
if (!report) { items.push(['info', 'Cells not measured; upload the sheet again to check them.']); return items; }
const name = (i) => `cell ${i + 1} (${a.cells[i].id})`;
const empty = [], painted = [], touching = [];
report.forEach((c, i) => {
if (!a.cells[i]) return;
if (!c.filled) empty.push(name(i)); else if (c.seeThrough < 5) painted.push(name(i)); else if (c.touches) touching.push(name(i));
});
if (!empty.length && !painted.length) items.push(['ok', `All ${a.cells.filter(Boolean).length} cells have their own drawing`]);
if (empty.length) items.push(['warn', `Nothing drawn in ${empty.join(', ')}. The cut would refuse the whole sheet.`]);
if (painted.length) items.push(['warn', `Painted on a background: ${painted.join(', ')}. The cut would refuse the whole sheet.`]);
if (touching.length) items.push(['warn', `Touching the cell edge: ${touching.join(', ')}. A neighbour may spill in, or a tail be cut off.`]);
return items;
}
const frameClassFor = (a) => (a.background === 'transparent' ? 'frame alpha' : 'frame full');
function renderAll() {
const main = $('#groups');
main.replaceChildren(...GROUPS.map((g) => {
const list = data.assets.filter((a) => a.type === g.type);
if (!list.length) return null;
return h('section', { class: 'group', id: 'group-' + g.type, 'aria-labelledby': 'gh-' + g.type },
h('h2', { id: 'gh-' + g.type, text: `${g.title} · ${list.length}` }),
h('p', { class: 'muted', text: g.note }),
h('div', { class: 'grid' }, list.map(buildCard)));
}).filter(Boolean));
main.style.display = 'grid'; main.style.gap = '36px';
for (const a of data.assets) updateCard(a.id);
applyFilter(); renderFilters(); renderBatch();
}
// ---------- all at once ----------
// The style paragraph every prompt opens with (everything before "Asset:"), written once at the top.
const styleOf = (prompt) => { const i = prompt.indexOf('Asset:'); return i > 0 ? prompt.slice(0, i).trim() : ''; };
const bodyOf = (prompt, style) => (style && prompt.startsWith(style) ? prompt.slice(style.length).trim() : prompt.trim());
let batchScope = 'todo';
let batchSize = 10;
try { batchSize = Number(localStorage.getItem('rosea-art-board-batch') ?? 10); } catch (e) { /* storage unavailable: ten per prompt */ }
let batches = []; // [[item]]: the prompts as last drawn
let pending = []; // {file, url, id, byOrder}
/** The pictures to make, in the board's order (character sheets first: the rest refer to them).
* A sprite sheet comes whole until any of its pictures has been made on its own; then only its
* missing pictures come, each with its own prompt. */
function batchItems(scope) {
const want = (st) => (scope === 'todo' ? st === 'todo' || st === 'retry' : st !== 'accepted');
const items = [];
const item = (id, target, prompt, w, hgt, bg, attach) => {
const r = rows[id];
items.push({ id, target, prompt, width: w, height: hgt, background: bg, attach: attach || [], note: statusOf(id) === 'retry' && r && r.note ? r.note : '' });
};
for (const g of GROUPS) for (const a of data.assets.filter((x) => x.type === g.type)) {
if (a.type !== 'spritesheet') { if (want(statusOf(a.id))) item(a.id, a, a.prompt, a.width, a.height, a.background, a.attach); continue; }
if (cardStatus(a) === 'accepted') continue;
const cells = cellsIn(a);
const oneByOne = cells.some((c) => statusOf(c.id) !== 'todo');
if (!oneByOne) { if (want(statusOf(a.id))) item(a.id, a, a.prompt, a.width, a.height, a.background, a.attach); continue; }
for (const c of cells) if (want(statusOf(c.id))) item(c.id, cellCards[c.id] ? cellCards[c.id].cell : null, c.prompt, c.width, c.height, c.background || a.background, a.attach);
}
return items;
}
function composePrompt(items, n, of) {
const style = items.length ? styleOf(items[0].prompt) : '';
const refs = [...new Set(items.flatMap((i) => i.attach))];
const head = [
`Make the ${items.length} picture${items.length === 1 ? '' : 's'} below${of > 1 ? ` (part ${n} of ${of})` : ''}, each as its own separate image, one after another in the order given. Never put two of them in one image. Before each image, write its number and name exactly as given (for example "1. ${items[0] ? items[0].id : 'name'}"), so each file can be matched to its picture.`,
'',
'Every picture uses this same style:',
'',
style,
'',
'For each picture keep its exact canvas size and background (transparent means a real transparent background, no paper, no checkerboard). A sprite sheet keeps its exact grid: every drawing stays inside its own cell\'s safe box.',
];
if (refs.length) head.push('', `Use the reference pictures I attached for the characters: ${refs.join(', ')}. Match them exactly in every picture.`);
const parts = items.map((it, i) => [
'---',
`${i + 1}. ${it.id} (${it.width} × ${it.height} px, ${it.background === 'transparent' ? 'transparent background' : 'full background'})`,
bodyOf(it.prompt, style),
it.note ? `Last time this was not right: ${it.note}` : '',
].filter(Boolean).join('\n'));
return [...head, '', ...parts].join('\n');
}
function renderBatch() {
if (!data) return;
const items = batchItems(batchScope);
const size = batchSize > 0 ? batchSize : items.length || 1;
batches = [];
for (let i = 0; i < items.length; i += size) batches.push(items.slice(i, i + size));
const list = $('#batchPrompts');
$('#batchSummary').textContent = items.length
? `${items.length} picture${items.length === 1 ? '' : 's'} to make, in ${batches.length} prompt${batches.length === 1 ? '' : 's'}.`
: 'Nothing left to make here.';
list.replaceChildren(...batches.map((b, k) => {
const text = composePrompt(b, k + 1, batches.length);
const pre = h('pre', { text });
const details = h('details', { class: 'prompt' }, h('summary', { text: 'Show the prompt' }), pre);
const long = text.length > 30000 ? ' · very long: choose fewer per prompt if your generator cuts it off' : '';
return h('li', {},
h('div', { class: 'row' },
h('strong', { text: `Prompt ${k + 1}` }),
h('span', { class: 'muted', text: `${b.length} picture${b.length === 1 ? '' : 's'}: ${b[0].id}${b.length > 1 ? ` … ${b[b.length - 1].id}` : ''} · ${text.length.toLocaleString()} characters${long}` })),
h('div', { class: 'row' }, h('button', { class: 'btn', type: 'button', onclick: () => copyText(text, pre, details) }, `Copy prompt ${k + 1}`)),
details);
}));
const order = $('#batchOrder');
const was = order.value;
order.replaceChildren(...batches.map((b, k) => h('option', { value: String(k) }, `Prompt ${k + 1}`)));
if (was && Number(was) < batches.length) order.value = was;
if (pending.length) matchPending();
}
/** Each file to its picture: an exact or contained id in its name first, then the chosen prompt's
* order for the rest. Nothing is uploaded until the person checks the list. */
function matchPending() {
const items = batchItems('open');
const ids = items.map((i) => i.id);
const longestFirst = [...ids].sort((x, y) => y.length - x.length);
const taken = new Set();
for (const m of pending) {
const base = m.file.name.toLowerCase().replace(/\.[a-z0-9]+$/, '');
let id = ids.find((i) => i === base) || longestFirst.find((i) => base.includes(i)) || null;
if (id && taken.has(id)) id = null;
m.id = id; m.byOrder = false;
if (id) taken.add(id);
}
const chosen = batches[Number($('#batchOrder').value) || 0] || [];
const free = chosen.map((i) => i.id).filter((id) => !taken.has(id));
let k = 0;
for (const m of pending) if (!m.id && k < free.length) { m.id = free[k++]; m.byOrder = true; taken.add(m.id); }
drawMatches(ids);
}
function drawMatches(ids) {
const ul = $('#matches');
ul.replaceChildren(...pending.map((m, i) => {
const sel = h('select', { 'aria-label': `Picture for ${m.file.name}`, onchange: () => { m.id = sel.value || null; m.byOrder = false; countMatches(); } },
h('option', { value: '' }, 'Skip this file'),
ids.map((id) => h('option', { value: id }, id)));
sel.value = m.id || '';
return h('li', {}, h('img', { src: m.url, alt: '' }),
h('div', {}, sel, h('div', { class: 'name', text: m.file.name + (m.byOrder ? ' · matched by the prompt\'s order' : m.id ? ' · matched by its name' : ' · no match') })));
}));
countMatches();
}
function countMatches() {
const n = pending.filter((m) => m.id).length;
const ids = pending.map((m) => m.id).filter(Boolean);
const twice = ids.length !== new Set(ids).size;
$('#matchActions').hidden = !pending.length;
const btn = $('#uploadAll');
btn.disabled = !n || twice || !canUpload();
btn.textContent = twice ? 'Two files point at one picture' : `Upload ${n} picture${n === 1 ? '' : 's'}`;
}
function takeFiles(list) {
if (!canUpload()) { toast('Uploading needs editor access to this board.'); return; }
const files = [...list].filter((f) => PASTE_TYPES.test(f.type));
if (files.length < list.length) toast('Only PNG, WebP and JPEG pictures are taken; the rest were left out.');
files.sort((x, y) => x.name.localeCompare(y.name, undefined, { numeric: true }) || x.lastModified - y.lastModified);
clearPending();
pending = files.map((file) => ({ file, url: URL.createObjectURL(file), id: null, byOrder: false }));
matchPending();
}
function clearPending() {
for (const m of pending) URL.revokeObjectURL(m.url);
pending = [];
$('#matches').replaceChildren();
$('#matchActions').hidden = true;
}
async function uploadAll() {
const todo = pending.filter((m) => m.id);
const btn = $('#uploadAll');
btn.disabled = true;
let done = 0;
for (const m of todo) {
const target = cards[m.id] ? cards[m.id].a : cellCards[m.id] ? cellCards[m.id].cell : null;
if (!target) continue;
btn.textContent = `Uploading ${done + 1} of ${todo.length}…`;
await upload(target, asFile(m.file, m.id)); // one at a time: the store limits bursts
done++;
}
clearPending();
toast(`${done} picture${done === 1 ? '' : 's'} uploaded. Review them on their cards.`);
}
function wireBatch() {
const scope = $('#batchScope'), size = $('#batchSize');
size.value = String([5, 10, 20, 0].includes(batchSize) ? batchSize : 10);
scope.addEventListener('change', () => { batchScope = scope.value; renderBatch(); });
size.addEventListener('change', () => {
batchSize = Number(size.value);
try { localStorage.setItem('rosea-art-board-batch', size.value); } catch (e) { /* storage unavailable: size not remembered */ }
renderBatch();
});
$('#batchOrder').addEventListener('change', () => pending.length && matchPending());
const bulk = $('#bulk'), input = $('#bulkFile');
input.addEventListener('change', () => { if (input.files.length) takeFiles(input.files); input.value = ''; });
bulk.addEventListener('dragover', (e) => { e.preventDefault(); bulk.classList.add('over'); });
bulk.addEventListener('dragleave', () => bulk.classList.remove('over'));
bulk.addEventListener('drop', (e) => { e.preventDefault(); bulk.classList.remove('over'); if (e.dataTransfer.files.length) takeFiles(e.dataTransfer.files); });
$('#uploadAll').addEventListener('click', uploadAll);
$('#clearAll').addEventListener('click', clearPending);
}
wireBatch();
// ---------- writes ----------
const canUpload = () => !!assets && canWrite;
function save(id, patch, okMessage) {
if (!db || !canWrite) return;
const body = { ...(rows[id] || {}), ...patch, updatedAt: new Date().toISOString() };
if (patch.status === 'review') delete body.status;
rows[id] = body; // optimistic
updateCard(cards[id] ? id : sheetOf[id].id); applyFilter(); renderFilters();
chains[id] = (chains[id] || Promise.resolve()).then(() => db.collection('art').doc(id).set(body)).then(
() => okMessage && toast(okMessage),
(e) => {
console.error('saving', id, e);
toast(e && e.code === 'quota_exceeded' ? 'The board is full and could not save this.' : 'That could not be saved. Check your connection and try again.');
});
return chains[id];
}
function saveChecks(a) {
const { refs } = cards[a.id];
const checks = {};
for (const c of refs.checks) checks[c.i] = c.box.checked;
save(a.id, { checks });
}
// For a sprite sheet, each grid cell at up to 1024 px across: how much is drawn, how much is
// see-through, and whether the drawing reaches the cell's edge (two pixels or more, so one speck
// of noise does not count). Cell edges are rounded once and shared, as in art:accept (cutLines).
function cellReport(ctx, w, h, grid) {
const px = ctx.getImageData(0, 0, w, h).data;
const xs = Array.from({ length: grid.cols + 1 }, (_, i) => Math.round((i * w) / grid.cols));
const ys = Array.from({ length: grid.rows + 1 }, (_, i) => Math.round((i * h) / grid.rows));
const out = [];
for (let row = 0; row < grid.rows; row++) for (let col = 0; col < grid.cols; col++) {
const x0 = xs[col], x1 = xs[col + 1], y0 = ys[row], y1 = ys[row + 1];
let drawn = 0, edge = 0;
for (let y = y0; y < y1; y++) for (let x = x0; x < x1; x++) {
if (px[(y * w + x) * 4 + 3] >= 16) {
drawn++;
if (x === x0 || x === x1 - 1 || y === y0 || y === y1 - 1) edge++;
}
}
const area = (x1 - x0) * (y1 - y0);
out.push({ filled: drawn >= area * 0.005, seeThrough: Math.round(100 * (1 - drawn / area)), touches: edge >= 2 });
}
return out;
}
function measure(file, grid) {
return new Promise((resolve) => {
const url = URL.createObjectURL(file);
const img = new Image();
img.onload = () => {
let alpha = null;
try {
const c = document.createElement('canvas');
c.width = Math.min(img.naturalWidth, 256); c.height = Math.round(c.width * img.naturalHeight / img.naturalWidth);
const ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0, c.width, c.height);
const px = (x, y) => ctx.getImageData(x, y, 1, 1).data[3];
const corners = [px(0, 0), px(c.width - 1, 0), px(0, c.height - 1), px(c.width - 1, c.height - 1)];
alpha = corners.every((v) => v < 16);
} catch (e) { console.error('could not measure transparency', e); }
// A single transparent picture: does the drawing reach the image's edge (cut off)?
let edge = null;
if (!grid) {
try {
const c = document.createElement('canvas');
c.width = Math.min(img.naturalWidth, 512); c.height = Math.round(c.width * img.naturalHeight / img.naturalWidth);
const ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0, c.width, c.height);
const px = ctx.getImageData(0, 0, c.width, c.height).data;
let n = 0;
for (let x = 0; x < c.width; x++) for (const y of [0, c.height - 1]) if (px[(y * c.width + x) * 4 + 3] >= 16) n++;
for (let y = 0; y < c.height; y++) for (const x of [0, c.width - 1]) if (px[(y * c.width + x) * 4 + 3] >= 16) n++;
edge = n >= 3;
} catch (e) { console.error('could not measure the edges', e); }
}
let cellChecks = null;
if (grid) {
try {
const c = document.createElement('canvas');
c.width = Math.min(img.naturalWidth, 1024); c.height = Math.round(c.width * img.naturalHeight / img.naturalWidth);
const ctx = c.getContext('2d'); ctx.drawImage(img, 0, 0, c.width, c.height);
cellChecks = cellReport(ctx, c.width, c.height, grid);
} catch (e) { console.error('could not measure the sheet cells', e); }
}
URL.revokeObjectURL(url);
resolve({ width: img.naturalWidth, height: img.naturalHeight, alpha, cellChecks, edge });
};
img.onerror = () => { URL.revokeObjectURL(url); resolve(null); };
img.src = url;
});
}
async function upload(a, file) {
if (!canUpload()) return;
if (!/^image\/(png|webp|jpeg)$/.test(file.type)) { toast('Please upload a PNG, WebP or JPEG picture.'); return; }
const owner = a.cell ? cellCards[a.id] : cards[a.id];
const refresh = () => (a.cell ? updateCard(cellCards[a.id].sheet.id) : updateCard(a.id));
const { refs } = owner;
refs.dropText.hidden = false; refs.dropText.textContent = 'Uploading…'; refs.file.disabled = true;
const size = await measure(file, a.type === 'spritesheet' ? a.grid : null);
if (!size) { toast('That file could not be read as a picture.'); refresh(); return; }
try {
const res = await assets.upload(file);
const old = rows[a.id] || {};
await save(a.id, {
image: res.id, contentType: res.contentType, width: size.width, height: size.height, alpha: size.alpha, cellChecks: size.cellChecks,
...(a.cell ? { edge: size.edge, sheet: cellCards[a.id].sheet.id } : {}),
status: 'review', checks: {}, previousImages: old.image ? [...(old.previousImages || []), old.image] : old.previousImages || [],
}, 'Uploaded. Accept it, or ask for another try.');
} catch (e) {
console.error('upload failed', e);
const msg = { too_large: 'That picture is over 20 MB. Export a smaller one.', unsupported_type: 'That file type is not accepted. Use PNG, WebP or JPEG.', quota_or_state: 'The board has no room for more pictures.', rate_limited: 'Too many uploads at once. Wait a moment and try again.' }[e && e.code];
toast(msg || 'The upload did not work. Try again.');
refresh();
}
}
// ---------- paste ----------
const PASTE_TYPES = /^image\/(png|webp|jpeg)$/;
const asFile = (blob, id) => new File([blob], `${id}.${blob.type.split('/')[1] || 'png'}`, { type: blob.type });
function openPasteBox(a) {
const { refs } = a.cell ? cellCards[a.id] : cards[a.id];
refs.pasteBox.hidden = false;
refs.pasteBox.focus();
}
// The button reads the clipboard directly where the browser allows it; elsewhere it opens a
// box the browser's own paste (keyboard or long-press menu) can land in.
async function pasteFromButton(a) {
if (!canUpload()) return;
if (navigator.clipboard && navigator.clipboard.read) {
try {
const items = await navigator.clipboard.read();
for (const item of items) {
const type = item.types.find((t) => PASTE_TYPES.test(t));
if (type) { (a.cell ? cellCards[a.id] : cards[a.id]).refs.pasteBox.hidden = true; await upload(a, asFile(await item.getType(type), a.id)); return; }
}
toast(NO_PICTURE);
return;
} catch (e) {
console.warn('reading the clipboard directly is not allowed here; opening the paste box', e);
}
}
openPasteBox(a);
}
function pictureIn(clipboardData) {
if (!clipboardData) return null;
for (const item of clipboardData.items || []) {
if (item.kind === 'file' && item.type.startsWith('image/')) return item.getAsFile();
}
return null;
}
document.addEventListener('paste', (e) => {
const inBox = e.target instanceof Element && e.target.closest('.pastebox');
const focusedCell = e.target instanceof Element ? e.target.closest('.cell[data-cell]') : null;
const focusedCard = focusedCell || (e.target instanceof Element ? e.target.closest('article.asset') : null);
const file = pictureIn(e.clipboardData);
if (!file) {
if (inBox) { e.preventDefault(); toast(NO_PICTURE); }
return; // plain text keeps pasting into notes as usual
}
e.preventDefault();
if (!canUpload()) { toast('Pasting needs editor access to this board.'); return; }
const id = focusedCell ? focusedCell.dataset.cell : focusedCard ? focusedCard.id : hovered;
if (id && cellCards[id]) {
if (!focusedCell && rows[id] && rows[id].image) { toast(`${id} already has a picture. Use its Paste button to replace it.`); return; }
if (!PASTE_TYPES.test(file.type)) { toast('Please paste a PNG, WebP or JPEG picture.'); return; }
cellCards[id].refs.pasteBox.hidden = true;
upload(cellCards[id].cell, asFile(file, id));
return;
}
if (!id || !cards[id]) { toast('Point at the card this picture is for, or use its Paste picture button, then paste again.'); return; }
// A picture only under the pointer must not silently replace one already there.
if (!focusedCard && rows[id] && rows[id].image) { toast(`${id} already has a picture. Use its Paste picture button to replace it.`); return; }
if (!PASTE_TYPES.test(file.type)) { toast('Please paste a PNG, WebP or JPEG picture.'); return; }
cards[id].refs.pasteBox.hidden = true;
upload(cards[id].a, asFile(file, id));
});
// ---------- start ----------
async function start() {
try {
const res = await fetch('board-data.json');
data = await res.json();
} catch (e) {
console.error('board data', e);
$('#progressText').textContent = 'The list of pictures could not be loaded. Reload the page.';
return;
}
renderAll();
const use = window.claude && window.claude.use ? (n) => window.claude.use(n) : async () => null;
const [dbNs, assetsNs, userNs] = await Promise.all([use('db'), use('assets'), use('user')]);
db = dbNs; assets = assetsNs;
const ro = $('#readonly');
if (!db) {
ro.hidden = false; ro.textContent = 'Progress cannot be saved in this view. Open the board signed in to claude.ai to upload and review pictures.';
for (const a of data.assets) updateCard(a.id);
$('#bulkFile').disabled = true; $('#bulkText').textContent = 'Uploading needs the board opened signed in to claude.ai.';
return;
}
const can = userNs ? await userNs.can('data.write') : null;
canWrite = can !== false;
if (!canWrite) { ro.hidden = false; ro.textContent = 'You can look, but only the board’s editors can upload and review pictures.'; }
else if (!assets) { ro.hidden = false; ro.textContent = 'Uploading needs editor access to this board. You can still review and add notes.'; }
$('#bulkFile').disabled = !canUpload();
if (!canUpload()) $('#bulkText').textContent = 'Uploading all at once needs editor access to this board.';
db.collection('art').onSnapshot((snap) => {
for (const d of snap.docs) {
// Keep this page's own pending writes; take everything else from the store.
if (!d.metadata.hasPendingWrites) rows[d.id] = d.data();
}
for (const ch of snap.docChanges()) if (ch.type === 'removed') delete rows[ch.doc.id];
for (const a of data.assets) if (cards[a.id]) updateCard(a.id);
applyFilter(); renderFilters(); renderBatch();
}, (e) => {
console.error('board subscription', e);
ro.hidden = false; ro.textContent = 'Live updates stopped. Reload the page to see the latest progress.';
});
}
start();
})();
</script>