Penpot importer: enforce paint order so backgrounds sit under content
Mirror to Gitea / mirror (push) Skipped

This commit is contained in:
Johan Sandoval committed 2026-10-08 20:28:22 +00:00
1 parent 0681ea5e18
commit 27c4cad24e
1 file changed
+14
+14
View File
@@ -132,6 +132,8 @@ async function importBoard(b, images) {
board.clipContent = true;
// Full-page screenshot of the real site: hidden + locked, toggle it on to compare/trace.
/** @type {any} */
let refShape = null;
if (images[b.reference]) {
try {
const ref = await makeImage({ name: 'Reference screenshot', x: 0, y: 0, w: b.width, h: b.height }, ox, rowY, images[b.reference]);
@@ -139,12 +141,15 @@ async function importBoard(b, images) {
ref.name = '⧉ Reference screenshot (toggle to compare)';
ref.hidden = true;
ref.blocked = true;
refShape = ref;
} catch (e) {
errors.push('reference: ' + String(e));
}
}
let made = 0;
/** @type {any[]} */
const sections = [];
for (const sec of b.sections) {
/** @type {any[]} */
const shapes = [];
@@ -162,12 +167,21 @@ async function importBoard(b, images) {
if (errors.length < 5) errors.push(`${l.type} "${String(l.name).slice(0, 30)}": ${String(e)}`);
}
}
/** @type {any} */
let top = shapes[0];
if (shapes.length > 1) {
const g = penpot.group(shapes);
if (g) g.name = sec.name;
top = g;
} else if (shapes[0]) shapes[0].name = sec.name;
// Enforce DOM paint order explicitly (append/group don't guarantee it):
// each later layer goes in front, so backgrounds sit under their content.
for (const s of shapes) s.bringToFront();
if (top) sections.push(top);
penpot.ui.sendMessage({ type: 'progress', board: b.name, section: sec.name });
}
for (const g of sections) g.bringToFront();
if (refShape) refShape.bringToFront();
errors.unshift(`images: ${imagesMade}/${wanted + (images[b.reference] ? 1 : 0)} placed${missing ? `, ${missing} never reached the plugin` : ''}${diag ? ' · ' + diag : ''}`);
return { made, failed, errors };
}