Penpot importer: send images as base64, add reference layer and error report
Mirror to Gitea / mirror (push) Skipped

This commit is contained in:
Johan Sandoval committed 2026-10-08 20:08:30 +00:00
1 parent bf0d1efa2c
commit 2a11a1006a
2 files changed
+56 -10

No files matched your search

+13 -2
View File
@@ -39,16 +39,27 @@
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] = new Uint8Array(await (await fetch('/baseline/' + l.src)).arrayBuffer());
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') { log(`✓ ${m.board} (${m.layers} layers)`); next(); }
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 = () => {