From 23c446b7e9f4bacbff670b731514e3d065b3929d Mon Sep 17 00:00:00 2001 From: Maurice Date: Fri, 23 Oct 2026 19:07:45 +0200 Subject: [PATCH] feat(studio): paint shapes and pages with gradients, alpha and twelve patterns - A shape and a page take a paint: one colour with its own alpha, a linear or radial gradient of two to six stops, or one of twelve patterns (checks, gingham, stripes, pinstripes, dots, polka dots, zigzag, waves, grid, scales, sunburst, confetti). fill, gradient and background keep the colour that stands for the paint, so an older reader still draws something close, and a plain colour or the old cover fade is stored in the old fields alone. - Gradients render as SVG in user space with ids per mounted copy, so the two halves of a spread in page mode never share a defs id; patterns are drawn out as geometry clipped to the outline and capped at 2000 primitives. - The new paint picker has none, solid, gradient and pattern tabs, a stop bar to click, drag and pull stops off, an angle dial, a radial centre pad and pattern tiles drawn by the page's own generator. - Every swatch row gains the book's own colours, colours read from the page's photos, recent colours and, where it applies, an opacity slider. - With nothing selected the inspector sets the page background, gives it to every page of its kind, and lays a photo under the whole page. - The assistant's background operation takes a paint as well as a colour, style and add set a shape's paint, and describe_book_page reads both. - BOOK_SCHEMA_REV goes to 2. --- client/scripts/theme-baseline.json | 2 +- .../src/components/Studio/BookSheetsView.tsx | 2 +- client/src/components/Studio/SpreadView.tsx | 19 +- .../Studio/StudioBackgroundSection.tsx | 130 ++++ .../src/components/Studio/StudioInspector.tsx | 59 +- .../components/Studio/StudioPaintPicker.tsx | 360 ++++++++++ .../components/Studio/StudioShapePaint.tsx | 60 ++ client/src/components/Studio/StudioShell.tsx | 23 +- .../src/components/Studio/StudioSwatches.tsx | 128 +++- .../src/components/Studio/paint/AngleDial.tsx | 91 +++ .../Studio/paint/GradientStopBar.tsx | 129 ++++ .../components/Studio/paint/PaintedShape.tsx | 60 ++ .../Studio/paint/PatternSwatches.tsx | 61 ++ .../src/components/Studio/paint/RadialPad.tsx | 86 +++ .../components/Studio/paint/StudioPalette.tsx | 101 +++ .../Studio/paint/backgroundPhoto.ts | 105 +++ .../src/components/Studio/paint/paintEdit.ts | 200 ++++++ .../components/Studio/paint/paintGeometry.ts | 60 ++ .../components/Studio/paint/paintRender.tsx | 216 ++++++ .../components/Studio/paint/paletteModel.ts | 63 ++ .../src/components/Studio/paint/patterns.ts | 358 ++++++++++ .../components/Studio/paint/photoPalette.ts | 150 ++++ .../Studio/paint/usePaintChannel.ts | 53 ++ .../src/components/Studio/paint/usePaintId.ts | 11 + client/src/styles/studio-paint.css | 641 ++++++++++++++++++ client/tests/unit/studio/inspector.test.tsx | 39 +- .../unit/studio/paintBackground.test.tsx | 248 +++++++ client/tests/unit/studio/paintEdit.test.ts | 176 +++++ .../tests/unit/studio/paintPalette.test.tsx | 234 +++++++ .../tests/unit/studio/paintPatterns.test.ts | 158 +++++ client/tests/unit/studio/paintPicker.test.tsx | 324 +++++++++ client/tests/unit/studio/paintRender.test.tsx | 252 +++++++ .../tests/unit/studio/useBookStore.test.tsx | 4 +- server/src/nest/journey/journey-book.mcp.ts | 2 +- shared/src/book/book-element-ops.schema.ts | 3 + shared/src/book/book-ops-elements.ts | 21 +- shared/src/book/book-ops.schema.ts | 11 +- shared/src/book/book-ops.ts | 6 +- shared/src/book/book-paint.schema.ts | 109 +++ shared/src/book/book-paint.spec.ts | 290 ++++++++ shared/src/book/book-paint.ts | 210 ++++++ shared/src/book/book-saved-layouts.ts | 6 +- shared/src/book/book-schema-rev.spec.ts | 6 +- shared/src/book/book-schema-rev.ts | 8 +- shared/src/book/book.schema.ts | 6 + shared/src/book/describe-spread.ts | 12 +- shared/src/i18n/ar/index.ts | 2 + shared/src/i18n/ar/journey.ts | 4 - shared/src/i18n/ar/studioPaint.ts | 49 ++ shared/src/i18n/az/index.ts | 2 + shared/src/i18n/az/journey.ts | 4 - shared/src/i18n/az/studioPaint.ts | 49 ++ shared/src/i18n/br/index.ts | 2 + shared/src/i18n/br/journey.ts | 4 - shared/src/i18n/br/studioPaint.ts | 49 ++ shared/src/i18n/ca/index.ts | 2 + shared/src/i18n/ca/journey.ts | 4 - shared/src/i18n/ca/studioPaint.ts | 49 ++ shared/src/i18n/cs/index.ts | 2 + shared/src/i18n/cs/journey.ts | 4 - shared/src/i18n/cs/studioPaint.ts | 49 ++ shared/src/i18n/de/index.ts | 2 + shared/src/i18n/de/journey.ts | 4 - shared/src/i18n/de/studioPaint.ts | 49 ++ shared/src/i18n/en/index.ts | 2 + shared/src/i18n/en/journey.ts | 4 - shared/src/i18n/en/studioPaint.ts | 49 ++ shared/src/i18n/es/index.ts | 2 + shared/src/i18n/es/journey.ts | 4 - shared/src/i18n/es/studioPaint.ts | 49 ++ shared/src/i18n/et/index.ts | 2 + shared/src/i18n/et/journey.ts | 4 - shared/src/i18n/et/studioPaint.ts | 49 ++ shared/src/i18n/fr/index.ts | 2 + shared/src/i18n/fr/journey.ts | 4 - shared/src/i18n/fr/studioPaint.ts | 49 ++ shared/src/i18n/gr/index.ts | 2 + shared/src/i18n/gr/journey.ts | 4 - shared/src/i18n/gr/studioPaint.ts | 49 ++ shared/src/i18n/hu/index.ts | 2 + shared/src/i18n/hu/journey.ts | 4 - shared/src/i18n/hu/studioPaint.ts | 49 ++ shared/src/i18n/id/index.ts | 2 + shared/src/i18n/id/journey.ts | 4 - shared/src/i18n/id/studioPaint.ts | 49 ++ shared/src/i18n/it/index.ts | 2 + shared/src/i18n/it/journey.ts | 4 - shared/src/i18n/it/studioPaint.ts | 49 ++ shared/src/i18n/ja/index.ts | 2 + shared/src/i18n/ja/journey.ts | 4 - shared/src/i18n/ja/studioPaint.ts | 49 ++ shared/src/i18n/ko/index.ts | 2 + shared/src/i18n/ko/journey.ts | 4 - shared/src/i18n/ko/studioPaint.ts | 49 ++ shared/src/i18n/nl/index.ts | 2 + shared/src/i18n/nl/journey.ts | 4 - shared/src/i18n/nl/studioPaint.ts | 49 ++ shared/src/i18n/pl/index.ts | 2 + shared/src/i18n/pl/journey.ts | 4 - shared/src/i18n/pl/studioPaint.ts | 49 ++ shared/src/i18n/ru/index.ts | 2 + shared/src/i18n/ru/journey.ts | 4 - shared/src/i18n/ru/studioPaint.ts | 49 ++ shared/src/i18n/sk/index.ts | 2 + shared/src/i18n/sk/journey.ts | 4 - shared/src/i18n/sk/studioPaint.ts | 49 ++ shared/src/i18n/sv/index.ts | 2 + shared/src/i18n/sv/journey.ts | 4 - shared/src/i18n/sv/studioPaint.ts | 49 ++ shared/src/i18n/th/index.ts | 2 + shared/src/i18n/th/journey.ts | 4 - shared/src/i18n/th/studioPaint.ts | 49 ++ shared/src/i18n/tr/index.ts | 2 + shared/src/i18n/tr/journey.ts | 4 - shared/src/i18n/tr/studioPaint.ts | 49 ++ shared/src/i18n/uk/index.ts | 2 + shared/src/i18n/uk/journey.ts | 4 - shared/src/i18n/uk/studioPaint.ts | 49 ++ shared/src/i18n/vi/index.ts | 2 + shared/src/i18n/vi/journey.ts | 4 - shared/src/i18n/vi/studioPaint.ts | 49 ++ shared/src/i18n/zh-TW/index.ts | 2 + shared/src/i18n/zh-TW/journey.ts | 4 - shared/src/i18n/zh-TW/studioPaint.ts | 48 ++ shared/src/i18n/zh/index.ts | 2 + shared/src/i18n/zh/journey.ts | 4 - shared/src/i18n/zh/studioPaint.ts | 48 ++ shared/src/index.ts | 2 + 128 files changed, 6565 insertions(+), 213 deletions(-) create mode 100644 client/src/components/Studio/StudioBackgroundSection.tsx create mode 100644 client/src/components/Studio/StudioPaintPicker.tsx create mode 100644 client/src/components/Studio/StudioShapePaint.tsx create mode 100644 client/src/components/Studio/paint/AngleDial.tsx create mode 100644 client/src/components/Studio/paint/GradientStopBar.tsx create mode 100644 client/src/components/Studio/paint/PaintedShape.tsx create mode 100644 client/src/components/Studio/paint/PatternSwatches.tsx create mode 100644 client/src/components/Studio/paint/RadialPad.tsx create mode 100644 client/src/components/Studio/paint/StudioPalette.tsx create mode 100644 client/src/components/Studio/paint/backgroundPhoto.ts create mode 100644 client/src/components/Studio/paint/paintEdit.ts create mode 100644 client/src/components/Studio/paint/paintGeometry.ts create mode 100644 client/src/components/Studio/paint/paintRender.tsx create mode 100644 client/src/components/Studio/paint/paletteModel.ts create mode 100644 client/src/components/Studio/paint/patterns.ts create mode 100644 client/src/components/Studio/paint/photoPalette.ts create mode 100644 client/src/components/Studio/paint/usePaintChannel.ts create mode 100644 client/src/components/Studio/paint/usePaintId.ts create mode 100644 client/src/styles/studio-paint.css create mode 100644 client/tests/unit/studio/paintBackground.test.tsx create mode 100644 client/tests/unit/studio/paintEdit.test.ts create mode 100644 client/tests/unit/studio/paintPalette.test.tsx create mode 100644 client/tests/unit/studio/paintPatterns.test.ts create mode 100644 client/tests/unit/studio/paintPicker.test.tsx create mode 100644 client/tests/unit/studio/paintRender.test.tsx create mode 100644 shared/src/book/book-paint.schema.ts create mode 100644 shared/src/book/book-paint.spec.ts create mode 100644 shared/src/book/book-paint.ts create mode 100644 shared/src/i18n/ar/studioPaint.ts create mode 100644 shared/src/i18n/az/studioPaint.ts create mode 100644 shared/src/i18n/br/studioPaint.ts create mode 100644 shared/src/i18n/ca/studioPaint.ts create mode 100644 shared/src/i18n/cs/studioPaint.ts create mode 100644 shared/src/i18n/de/studioPaint.ts create mode 100644 shared/src/i18n/en/studioPaint.ts create mode 100644 shared/src/i18n/es/studioPaint.ts create mode 100644 shared/src/i18n/et/studioPaint.ts create mode 100644 shared/src/i18n/fr/studioPaint.ts create mode 100644 shared/src/i18n/gr/studioPaint.ts create mode 100644 shared/src/i18n/hu/studioPaint.ts create mode 100644 shared/src/i18n/id/studioPaint.ts create mode 100644 shared/src/i18n/it/studioPaint.ts create mode 100644 shared/src/i18n/ja/studioPaint.ts create mode 100644 shared/src/i18n/ko/studioPaint.ts create mode 100644 shared/src/i18n/nl/studioPaint.ts create mode 100644 shared/src/i18n/pl/studioPaint.ts create mode 100644 shared/src/i18n/ru/studioPaint.ts create mode 100644 shared/src/i18n/sk/studioPaint.ts create mode 100644 shared/src/i18n/sv/studioPaint.ts create mode 100644 shared/src/i18n/th/studioPaint.ts create mode 100644 shared/src/i18n/tr/studioPaint.ts create mode 100644 shared/src/i18n/uk/studioPaint.ts create mode 100644 shared/src/i18n/vi/studioPaint.ts create mode 100644 shared/src/i18n/zh-TW/studioPaint.ts create mode 100644 shared/src/i18n/zh/studioPaint.ts 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({