Files

73 lines
3.7 KiB
HTML

<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<style>
body { font: 13px system-ui, sans-serif; margin: 0; padding: 12px; color: #e8e8e8; background: #18181a; }
h1 { font-size: 14px; margin: 0 0 8px; }
label { display: flex; gap: 6px; align-items: center; padding: 3px 0; }
button { margin-top: 10px; width: 100%; padding: 8px; font-weight: 700; border: 0; border-radius: 6px; background: #31efb8; color: #000; cursor: pointer; }
button[disabled] { opacity: .5; }
#log { margin-top: 10px; font: 11px ui-monospace, monospace; white-space: pre-wrap; max-height: 150px; overflow: auto; color: #aaa; }
.row { display: flex; gap: 8px; font-size: 12px; }
.row a { color: #31efb8; cursor: pointer; }
</style>
</head>
<body>
<h1>Import yoyos.sh baseline</h1>
<div class="row"><a id="all">all</a><a id="none">none</a><a id="mob">phone only</a><a id="desk">desktop only</a></div>
<div id="list">Loading boards…</div>
<button id="go" disabled>Import selected</button>
<div id="log"></div>
<script>
const log = (m) => { const el = document.getElementById('log'); el.textContent += m + '\n'; el.scrollTop = 1e9; };
let boards = [];
fetch('/baseline/index.json').then((r) => r.json()).then((idx) => {
boards = idx;
document.getElementById('list').innerHTML = idx.map((b, i) =>
`<label><input type="checkbox" data-i="${i}" checked> ${b.name} <small>(${b.layers})</small></label>`).join('');
document.getElementById('go').disabled = false;
}).catch((e) => log('Could not load /baseline/index.json — is tools/penpot/serve.py running? ' + e));
const boxes = () => [...document.querySelectorAll('input[type=checkbox]')];
document.getElementById('all').onclick = () => boxes().forEach((b) => (b.checked = true));
document.getElementById('none').onclick = () => boxes().forEach((b) => (b.checked = false));
document.getElementById('mob').onclick = () => boxes().forEach((b) => (b.checked = boards[b.dataset.i].slug.endsWith('mobile')));
document.getElementById('desk').onclick = () => boxes().forEach((b) => (b.checked = boards[b.dataset.i].slug.endsWith('desktop')));
let queue = [];
async function next() {
const item = queue.shift();
if (!item) { log('All done.'); document.getElementById('go').disabled = false; return; }
const board = await (await fetch('/baseline/' + item.file)).json();
// Images travel as base64 strings: plain strings survive the plugin message bridge.
const toB64 = async (url) => {
const blob = await (await fetch(url)).blob();
return await new Promise((ok) => { const r = new FileReader(); r.onload = () => ok(String(r.result).split(',')[1]); r.readAsDataURL(blob); });
};
const images = {};
for (const sec of board.sections) for (const l of sec.layers) {
if (l.type === 'image' && l.src && !images[l.src]) images[l.src] = await toB64('/baseline/' + l.src);
}
if (board.reference) images[board.reference] = await toB64('/baseline/' + board.reference);
log('Importing ' + board.name + '…');
parent.postMessage({ type: 'board', board, images }, '*');
}
window.addEventListener('message', (e) => {
const m = e.data;
if (m.type === 'done') {
const f = Object.entries(m.failed || {}).map(([k, v]) => `${v} ${k}`).join(', ');
log(`${f ? '⚠' : '✓'} ${m.board} (${m.layers} layers${f ? ', failed: ' + f : ''})`);
(m.errors || []).forEach((e) => log(' ' + e));
next();
}
if (m.type === 'error') { log(`✗ ${m.board}: ${m.error}`); next(); }
});
document.getElementById('go').onclick = () => {
queue = boxes().filter((b) => b.checked).map((b) => boards[b.dataset.i]);
document.getElementById('go').disabled = true;
next();
};
</script>
</body>
</html>