diff --git a/client/scripts/theme-baseline.json b/client/scripts/theme-baseline.json index 74cf5cc22..525e60739 100644 --- a/client/scripts/theme-baseline.json +++ b/client/scripts/theme-baseline.json @@ -102,7 +102,7 @@ "components/Studio/BookSheetsView.tsx": 2, "components/Studio/SpreadView.tsx": 3, "components/Studio/StudioElementsPanel.tsx": 8, - "components/Studio/StudioInspector.tsx": 2, + "components/Studio/StudioInspector.tsx": 1, "components/Studio/StudioShell.tsx": 2, "components/Studio/StudioSidebar.tsx": 2, "components/Studio/TravelElements.tsx": 5, diff --git a/client/src/components/Studio/BookSheetsView.tsx b/client/src/components/Studio/BookSheetsView.tsx index 3c872d331..18100cd35 100644 --- a/client/src/components/Studio/BookSheetsView.tsx +++ b/client/src/components/Studio/BookSheetsView.tsx @@ -91,7 +91,7 @@ function SheetView({ height: `${sheet.height + box.bleed * 2}mm`, // The spread's own paper colour, carried out into the bleed. Without // it a coloured page would be cut with a white edge on three sides. - background: sheet.spread.background ?? '#ffffff', // theme-lint-disable — paper, not app chrome + background: (sheet.spread.backgroundPaint ? null : sheet.spread.background) ?? '#ffffff', // theme-lint-disable: paper, not app chrome overflow: 'hidden', }} > diff --git a/client/src/components/Studio/SpreadView.tsx b/client/src/components/Studio/SpreadView.tsx index a79d2ca66..eda929cf0 100644 --- a/client/src/components/Studio/SpreadView.tsx +++ b/client/src/components/Studio/SpreadView.tsx @@ -8,6 +8,9 @@ import { iconComponent } from './iconLibrary' import { HOLED_SHAPES, SHAPE_PATHS, scalePath, unitPath } from './shapes' import { TravelElementView } from './TravelElements' import { PageNumbers } from './PageNumbers' +import { PaintedShapeView } from './paint/PaintedShape' +import { SpreadPaint } from './paint/paintRender' +import { usePaintId } from './paint/usePaintId' /** * One spread, drawn. @@ -86,7 +89,8 @@ const FRAME_INSET: Record = { */ function ShapeView({ el }: { el: BookShapeElement }) { const fill = el.fill ?? 'transparent' - const gradientId = `g-${el.id}` + // Per mounted copy: page mode draws a spread twice (paint/paintRender.tsx). + const gradientId = usePaintId(`g-${el.id}`) const gradient = el.gradient !== 'none' && el.fill if (el.shape === 'rect' || el.shape === 'ellipse') { @@ -171,7 +175,7 @@ function PhotoView({ el, big, print, dropLabel }: { // stylesheet that a person may well end up reading. const pad = round2(deco.pad * side) const bottom = round2(deco.bottom * side) - const clipId = `c-${el.id}` + const clipId = usePaintId(`c-${el.id}`) const clipped = el.mask && el.mask !== 'rect' /* @@ -394,7 +398,9 @@ export function ElementView({ return } - if (el.kind === 'shape') return + if (el.kind === 'shape') { + return el.paint ? : + } // Above the catch-all below, which routes everything that is not text into // the travel elements and draws null for anything they do not know. @@ -474,7 +480,8 @@ export function SpreadView({ style={{ position: 'absolute', inset: 0, - background: spread.background ?? '#ffffff', // theme-lint-disable — paper, not app chrome + // Under a paint the sheet is the paper, which a see-through paint lets show. + background: (spread.backgroundPaint ? null : spread.background) ?? '#ffffff', // theme-lint-disable: paper, not app chrome /* * On screen the page ends at the trim, so anything past it is clipped. * In print it must not be: the bleed is the part that runs off the edge @@ -485,6 +492,10 @@ export function SpreadView({ overflow: print ? 'visible' : 'hidden', }} > + {spread.backgroundPaint && ( + + )} + {spread.elements.map(el => ( s.doc?.spreads[spreadIndex]); + const commit = useStudioStore((s) => s.commit); + const channel = usePaintChannel((paint) => (doc) => ({ + ...doc, + spreads: doc.spreads.map((sp, i) => (i === spreadIndex ? withSpreadPaint(sp, paint) : sp)), + })); + + // "Applied" stands in the button for a moment, so a press that changed pages out of sight is seen to have worked. + const [applied, setApplied] = useState(false); + useEffect(() => { + if (!applied) return; + const timer = window.setTimeout(() => setApplied(false), 1600); + return () => window.clearTimeout(timer); + }, [applied]); + + const current = backgroundPhotoOf(spread, page); + const candidates = useMemo(() => { + if (!spread) return []; + const entry = source.entries.find((e) => e.id === spread.entryId); + return backgroundCandidates( + spreadPhotoIds(spread), + entry?.photoIds ?? [], + source.photos.map((p) => p.photoId) + ); + }, [spread, source]); + + if (!spread) return null; + + const setPhoto = (photoId: number) => + commit((doc) => ({ + ...doc, + spreads: doc.spreads.map((sp, i) => { + if (i !== spreadIndex) return sp; + return withBackgroundPhoto(sp, page, photoId, () => bookElementId('p')) ?? sp; + }), + })); + const clearPhoto = () => + commit((doc) => ({ + ...doc, + spreads: doc.spreads.map((sp, i) => (i === spreadIndex ? withoutBackgroundPhoto(sp, page) : sp)), + })); + const applyToAll = () => { + commit((doc) => backgroundToAll(doc, spreadIndex)); + setApplied(true); + }; + + return ( +
+ + + + +
+ {t('journey.studio.paint.photoBackground')} + {candidates.length ? ( + <> +
+ {candidates.map((id) => ( + + ))} +
+

{t('journey.studio.paint.photoBackgroundHint')}

+ {current && ( + + )} + + ) : ( +

{t('journey.studio.paint.noPhotos')}

+ )} +
+
+ ); +} diff --git a/client/src/components/Studio/StudioInspector.tsx b/client/src/components/Studio/StudioInspector.tsx index 06ca92830..7e6ef7e9f 100644 --- a/client/src/components/Studio/StudioInspector.tsx +++ b/client/src/components/Studio/StudioInspector.tsx @@ -10,6 +10,8 @@ import { FRAME_SHAPES, SHAPE_GROUPS } from './shapes' import { ShapeGlyph } from './StudioElementsPanel' import { TravelInspector } from './StudioTravelInspector' import { Swatches } from './StudioSwatches' +import { StudioBackgroundSection } from './StudioBackgroundSection' +import { StudioShapePaint } from './StudioShapePaint' import { formatBookCoords } from '@trek/shared' import { iconComponent, iconLabel, searchIcons } from './iconLibrary' import { Choice, Line, NumField, Section, Switch } from './StudioControls' @@ -102,6 +104,8 @@ export function StudioInspector({