feat(studio): a second shelf of shapes, cut edges and a drawn line with heads and ornaments

- Fifty more shapes: arches, paper cut-outs (leaves, coral, weed, organic
  circles, a wonky star and sun), stamps, a postmark, a rosette, tags and
  ticket stubs, sunbursts, ribbons and bands, speech bubbles, drawn arrows,
  hearts, stars, photo frames and ornaments (scroll, laurel, fleuron, corner).
  The broad ones are photo frames too, and each tile is drawn at its shape's
  own proportions, which a new shape is also placed at.
- A cut edge on rectangles, circles, arches and the other broad shapes, painted
  or not, and on a photo's cut: zigzag, scallop, a postage stamp's perforation,
  wavy, torn and deckle, with a depth in millimetres. Cut in millimetres, so
  holes stay round on a wide frame.
- A line element: two to 32 points dragged on the canvas (a handle pulled from
  the middle adds one, a double-click removes it), straight or curved, solid,
  dashed or dotted, a wave or a zigzag, a hand-drawn wobble, a head on either
  end and an ornament in the middle. A shelf of lines and dividers places them.
- The assistant reaches all of it: add and style take the line (its points on
  the spread in mm) and the edges, describe_book_page says them, and two new
  findings say when a line is too thin to print and when an edge is set on a
  shape that takes none. A photo's mask is checked against the shape set
  rather than listed again, which keeps the page edit's schema smaller.
- BOOK_SCHEMA_REV goes to 6.
This commit is contained in:
Maurice
2026-10-23 21:36:08 +02:00
parent 7a7876b9f4
commit ce9c94a77b
102 changed files with 5960 additions and 140 deletions
@@ -0,0 +1,86 @@
import { type BookElement, type BookPageSetup, bookElementId, bookNewLine } from '@trek/shared';
import { LinePaths } from './LineView';
import { DIVIDER_PRESETS, LINE_PRESETS, type LinePreset as Preset, presetPoints } from './linePresets';
import { lineGeometry } from './lineRender';
/**
* The drawn lines and dividers of the Elements panel: a straight rule, arrows,
* dashes and dots, a curve, a wave, a zigzag, a line drawn by hand, a dotted
* route, and the rules a title sits between.
*
* Each tile is drawn by the same geometry the page uses, so the tile is the
* line you get. They arrive half a page wide on the right-hand page, where the
* assistant's `add` puts them too, and their ends are moved on the canvas.
*/
/** A line as the page draws it, as a tile. */
function LineGlyph({ preset }: { preset: Preset }) {
const W = 40;
const H = 24;
const el = bookNewLine(
{
...preset.look,
strokeWidth: Math.max(1.2, (preset.look.strokeWidth ?? 0.5) * 2.4),
points: presetPoints(preset, 4, H / 2, W - 8),
},
{ id: preset.id, frame: null, inner: false, page: { pageWidth: W, pageHeight: H } as BookPageSetup }
);
const g = lineGeometry(el, el.frame.w, el.frame.h, preset.id);
return (
<svg viewBox={`${-el.frame.x} ${-el.frame.y} ${W} ${H}`} width="100%" height="100%" aria-hidden>
<LinePaths g={g} color="currentColor" width={el.strokeWidth} />
</svg>
);
}
export function StudioLineShelf({
page,
single,
onAdd,
t,
}: {
page: BookPageSetup;
single: boolean;
onAdd: (el: BookElement) => void;
t: (k: string) => string;
}) {
const add = (preset: Preset) => {
const origin = single ? 0 : page.pageWidth;
const w = page.pageWidth * (preset.id.startsWith('divider') ? 0.4 : 0.5);
const x = origin + (page.pageWidth - w) / 2;
const points = presetPoints(preset, x, page.pageHeight / 2, w);
onAdd(bookNewLine({ ...preset.look, points }, { id: bookElementId('l'), frame: null, inner: !single, page }));
};
const tiles = (list: readonly Preset[]) => (
<div className="st-shape-grid">
{list.map((p) => {
const label = t(`journey.studio.linePreset.${p.id}`);
return (
<button
type="button"
key={p.id}
className="st-shape-btn is-glyph"
onClick={() => add(p)}
title={label}
aria-label={label}
>
<LineGlyph preset={p} />
</button>
);
})}
</div>
);
return (
<>
<div className="st-section">
<div className="st-section-label">{t('journey.studio.drawnLines')}</div>
{tiles(LINE_PRESETS)}
</div>
<div className="st-section">
<div className="st-section-label">{t('journey.studio.dividers')}</div>
{tiles(DIVIDER_PRESETS)}
</div>
</>
);
}