fix(studio): a saved layout's background unlinks the page from its theme colour

This commit is contained in:
Maurice
2026-10-24 09:17:11 +02:00
parent 64edf899ac
commit 1050029842
2 changed files with 20 additions and 1 deletions
+17
View File
@@ -264,6 +264,23 @@ describe('a mark set as text on a page laid out again', () => {
});
});
describe('the page background a saved layout brings', () => {
it("BOOKLAY-030: replaces the page's colour and its link to a theme colour, so a theme cannot paint over it", () => {
const from = bookSpreadSchema.parse({ id: 'a', role: 'inner', background: '#123456', elements: [] });
const layout = bookLayoutFromSpread(from, page, 'Navy');
const linked = bookSpreadSchema.parse({
id: 'b',
role: 'inner',
background: '#ffffff',
backgroundToken: 'paper',
elements: [],
});
const next = applySavedBookLayout(linked, layout, page);
expect(next.background).toBe('#123456');
expect(next).not.toHaveProperty('backgroundToken');
});
});
describe('letters filled with a photo in a saved layout', () => {
const frame = { x: 10, y: 10, w: 80, h: 40 };
const filledWith = (photoId: number) => ({ type: 'photo' as const, photoId, focalX: 0.5, focalY: 0.5, zoom: 1 });
+3 -1
View File
@@ -145,7 +145,9 @@ export function applySavedBookLayout(spread: BookSpread, layout: BookLayout, pag
const used = new Set(wordsFor.values());
const parked = [...photos.slice(pi), ...texts.filter((t) => !used.has(t))].slice(0, MAX_SPREAD_ELEMENTS);
const { backgroundPaint: _old, ...rest } = spread;
// The layout's background replaces the page's, so the page's link to a theme
// colour goes with it: kept, the next theme would paint over the layout's colour.
const { backgroundPaint: _old, backgroundToken: _unlinked, ...rest } = spread;
const backgroundPaint = layout.backgroundPaint ? { backgroundPaint: layout.backgroundPaint } : {};
return { ...rest, background: layout.background, ...backgroundPaint, elements: out, parked };
}