Penpot importer: report placed images and verify image fills
Mirror to Gitea / mirror (push) Skipped

This commit is contained in:
Johan Sandoval committed 2026-10-08 20:20:15 +00:00
1 parent 2a11a1006a
commit 0681ea5e18
1 file changed
+13
+13
View File
@@ -95,9 +95,17 @@ async function makeImage(l, ox, oy, b64) {
r.y = oy + l.y; r.y = oy + l.y;
r.resize(Math.max(l.w, 1), Math.max(l.h, 1)); r.resize(Math.max(l.w, 1), Math.max(l.h, 1));
r.fills = [{ fillOpacity: 1, fillImage: img }]; r.fills = [{ fillOpacity: 1, fillImage: img }];
// Readback: Penpot sometimes accepts the upload but drops the fill silently.
const got = /** @type {any} */ (r.fills)[0]?.fillImage;
if (!got) throw new Error('fill dropped after upload (uploaded id ' + (img && img.id) + ')');
if (!diag) diag = `first image: id ${got.id}, ${got.width}×${got.height}, ${got.mtype}`;
imagesMade++;
return r; return r;
} }
let diag = '';
let imagesMade = 0;
/** @type {Record<string, number>} */ /** @type {Record<string, number>} */
let nextX = { mobile: 0, desktop: 0 }; let nextX = { mobile: 0, desktop: 0 };
@@ -107,6 +115,10 @@ async function importBoard(b, images) {
const failed = {}; const failed = {};
/** @type {string[]} */ /** @type {string[]} */
const errors = []; const errors = [];
diag = '';
imagesMade = 0;
const wanted = b.sections.reduce((/** @type {number} */ n, /** @type {any} */ s) => n + s.layers.filter((/** @type {any} */ l) => l.type === 'image').length, 0);
const missing = b.sections.flatMap((/** @type {any} */ s) => s.layers).filter((/** @type {any} */ l) => l.type === 'image' && !images[l.src]).length;
const rowY = b.viewport === 'mobile' ? 0 : 7000; const rowY = b.viewport === 'mobile' ? 0 : 7000;
const ox = nextX[b.viewport]; const ox = nextX[b.viewport];
nextX[b.viewport] += b.width + 200; nextX[b.viewport] += b.width + 200;
@@ -156,6 +168,7 @@ async function importBoard(b, images) {
} else if (shapes[0]) shapes[0].name = sec.name; } else if (shapes[0]) shapes[0].name = sec.name;
penpot.ui.sendMessage({ type: 'progress', board: b.name, section: sec.name }); penpot.ui.sendMessage({ type: 'progress', board: b.name, section: sec.name });
} }
errors.unshift(`images: ${imagesMade}/${wanted + (images[b.reference] ? 1 : 0)} placed${missing ? `, ${missing} never reached the plugin` : ''}${diag ? ' · ' + diag : ''}`);
return { made, failed, errors }; return { made, failed, errors };
} }