diff --git a/tools/penpot/plugin/plugin.js b/tools/penpot/plugin/plugin.js index 76d2526..da3ac30 100644 --- a/tools/penpot/plugin/plugin.js +++ b/tools/penpot/plugin/plugin.js @@ -95,9 +95,17 @@ async function makeImage(l, ox, oy, b64) { r.y = oy + l.y; r.resize(Math.max(l.w, 1), Math.max(l.h, 1)); 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; } +let diag = ''; +let imagesMade = 0; + /** @type {Record} */ let nextX = { mobile: 0, desktop: 0 }; @@ -107,6 +115,10 @@ async function importBoard(b, images) { const failed = {}; /** @type {string[]} */ 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 ox = nextX[b.viewport]; nextX[b.viewport] += b.width + 200; @@ -156,6 +168,7 @@ async function importBoard(b, images) { } else if (shapes[0]) shapes[0].name = 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 }; }