mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +00:00
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:
@@ -0,0 +1,214 @@
|
||||
import {
|
||||
BOOK_LINE_CAPS,
|
||||
BOOK_LINE_ORNAMENTS,
|
||||
type BookLineCap,
|
||||
type BookLineElement,
|
||||
type BookLineOrnament,
|
||||
bookLineStyled,
|
||||
} from '@trek/shared';
|
||||
import { ArrowLeftRight } from 'lucide-react';
|
||||
|
||||
import { useStudioStore } from '../../store/studioStore';
|
||||
import { LinePaths } from './LineView';
|
||||
import { Choice, Line, NumField, Section } from './StudioControls';
|
||||
import { Swatches } from './StudioSwatches';
|
||||
import { lineGeometry } from './lineRender';
|
||||
|
||||
/**
|
||||
* The inspector of a drawn line: its colour and weight, dashes, the course it
|
||||
* takes, a wave or a zigzag, the hand-drawn wobble, what sits on each end and
|
||||
* in the middle.
|
||||
*
|
||||
* Every change goes through `bookLineStyled`, the book engine's own restyle,
|
||||
* so a wider stroke or a new head refits the frame exactly as the assistant's
|
||||
* `style` does, and the ends stay where they were drawn.
|
||||
*/
|
||||
|
||||
type Look = Partial<Omit<BookLineElement, 'id' | 'kind' | 'frame' | 'points'>>;
|
||||
|
||||
type GlyphLook = Parameters<typeof lineGeometry>[0];
|
||||
|
||||
/** A tiny level line for the pickers: a plain rule, with what the picker is choosing set on it. */
|
||||
function MiniLine({ over }: { over: Partial<GlyphLook> }) {
|
||||
const el: GlyphLook = {
|
||||
points: [
|
||||
{ x: 0.08, y: 0.5 },
|
||||
{ x: 0.92, y: 0.5 },
|
||||
],
|
||||
curve: 'straight',
|
||||
strokeWidth: 1.4,
|
||||
dash: 'solid',
|
||||
squiggle: 'none',
|
||||
startCap: 'none',
|
||||
endCap: 'none',
|
||||
wobble: 0,
|
||||
ornament: 'none',
|
||||
...over,
|
||||
};
|
||||
const g = lineGeometry(el, 28, 12, 'glyph');
|
||||
return (
|
||||
<svg viewBox="0 0 28 12" width="28" height="12" aria-hidden style={{ overflow: 'visible' }}>
|
||||
<LinePaths g={g} color="currentColor" width={el.strokeWidth} />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
/** A tiny line with this end on it, for the end pickers. */
|
||||
const CapGlyph = ({ cap, start }: { cap: BookLineCap; start: boolean }) => (
|
||||
<MiniLine over={start ? { startCap: cap } : { endCap: cap }} />
|
||||
);
|
||||
|
||||
/** A tiny rule with this ornament in its middle. */
|
||||
const OrnamentGlyph = ({ ornament }: { ornament: BookLineOrnament }) => (
|
||||
<MiniLine over={{ ornament, strokeWidth: 0.7 }} />
|
||||
);
|
||||
|
||||
export function LineInspector({
|
||||
el,
|
||||
spreadIndex,
|
||||
t,
|
||||
}: {
|
||||
el: BookLineElement;
|
||||
spreadIndex: number;
|
||||
t: (k: string) => string;
|
||||
}) {
|
||||
const commit = useStudioStore((s) => s.commit);
|
||||
const selection = useStudioStore((s) => s.selection);
|
||||
|
||||
/** Restyle every selected line, each refitted around its own points. */
|
||||
const set = (look: Look) =>
|
||||
commit((d) => ({
|
||||
...d,
|
||||
spreads: d.spreads.map((sp, i) =>
|
||||
i !== spreadIndex
|
||||
? sp
|
||||
: {
|
||||
...sp,
|
||||
elements: sp.elements.map((e) =>
|
||||
e.kind === 'line' && selection.includes(e.id) && !e.locked ? bookLineStyled(e, look) : e
|
||||
),
|
||||
}
|
||||
),
|
||||
}));
|
||||
|
||||
/** The line turned round: its points in the other order and its two ends swapped with them. */
|
||||
const swapEnds = () =>
|
||||
commit((d) => ({
|
||||
...d,
|
||||
spreads: d.spreads.map((sp, i) =>
|
||||
i !== spreadIndex
|
||||
? sp
|
||||
: {
|
||||
...sp,
|
||||
elements: sp.elements.map((e) =>
|
||||
e.kind === 'line' && selection.includes(e.id) && !e.locked
|
||||
? { ...e, points: [...e.points].reverse(), startCap: e.endCap, endCap: e.startCap }
|
||||
: e
|
||||
),
|
||||
}
|
||||
),
|
||||
}));
|
||||
|
||||
const caps = (start: boolean) =>
|
||||
BOOK_LINE_CAPS.map((c) => ({
|
||||
value: c,
|
||||
label: <CapGlyph cap={c} start={start} />,
|
||||
title: t(`journey.studio.cap.${c}`),
|
||||
}));
|
||||
|
||||
return (
|
||||
<>
|
||||
<Section label={t('journey.studio.kind.line')}>
|
||||
<Line label={t('journey.studio.stroke')} wide>
|
||||
<Swatches value={el.stroke} onPick={(c) => set({ stroke: c })} />
|
||||
</Line>
|
||||
<div className="st-grid2" style={{ marginTop: 10 }}>
|
||||
<NumField
|
||||
label={t('journey.studio.strokeWidth')}
|
||||
value={el.strokeWidth}
|
||||
min={0.05}
|
||||
max={20}
|
||||
step={0.05}
|
||||
unit="mm"
|
||||
onChange={(v) => set({ strokeWidth: v })}
|
||||
/>
|
||||
<NumField
|
||||
label={t('journey.studio.wobble')}
|
||||
value={Math.round(el.wobble * 100)}
|
||||
min={0}
|
||||
max={100}
|
||||
step={10}
|
||||
unit="%"
|
||||
onChange={(v) => set({ wobble: Math.min(1, Math.max(0, v / 100)) })}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ marginTop: 10 }}>
|
||||
<Line label={t('journey.studio.strokeStyle')} wide>
|
||||
<Choice
|
||||
value={el.dash}
|
||||
options={(
|
||||
[
|
||||
['solid', 'strokeSolid'],
|
||||
['dashed', 'strokeDashed'],
|
||||
['dotted', 'strokeDotted'],
|
||||
] as const
|
||||
).map(([value, key]) => ({ value, label: t(`journey.studio.${key}`) }))}
|
||||
onPick={(dash) => set({ dash })}
|
||||
/>
|
||||
</Line>
|
||||
<Line label={t('journey.studio.lineCourseTitle')} wide>
|
||||
<Choice
|
||||
value={el.curve}
|
||||
options={(['straight', 'smooth'] as const).map((value) => ({
|
||||
value,
|
||||
label: t(`journey.studio.lineCourse.${value}`),
|
||||
}))}
|
||||
onPick={(curve) => set({ curve })}
|
||||
/>
|
||||
</Line>
|
||||
<Line label={t('journey.studio.lineBodyTitle')} wide>
|
||||
<Choice
|
||||
value={el.squiggle}
|
||||
options={(['none', 'wave', 'zigzag'] as const).map((value) => ({
|
||||
value,
|
||||
label: t(`journey.studio.lineBody.${value}`),
|
||||
}))}
|
||||
onPick={(squiggle) => set({ squiggle })}
|
||||
/>
|
||||
</Line>
|
||||
</div>
|
||||
<p className="st-hint" style={{ paddingTop: 8 }}>
|
||||
{t('journey.studio.linePointsHint')}
|
||||
</p>
|
||||
</Section>
|
||||
|
||||
<Section label={t('journey.studio.lineEnds')}>
|
||||
<Line label={t('journey.studio.lineStart')} wide>
|
||||
<Choice value={el.startCap} options={caps(true)} onPick={(startCap) => set({ startCap })} />
|
||||
</Line>
|
||||
<Line label={t('journey.studio.lineEnd')} wide>
|
||||
<Choice value={el.endCap} options={caps(false)} onPick={(endCap) => set({ endCap })} />
|
||||
</Line>
|
||||
<div className="st-row" style={{ marginTop: 6 }}>
|
||||
<button type="button" className="st-chip" onClick={swapEnds}>
|
||||
<ArrowLeftRight size={13} />
|
||||
{t('journey.studio.swapEnds')}
|
||||
</button>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
<Section label={t('journey.studio.ornamentTitle')} defaultOpen={el.ornament !== 'none'}>
|
||||
<Choice
|
||||
value={el.ornament}
|
||||
options={BOOK_LINE_ORNAMENTS.map((o) => ({
|
||||
value: o,
|
||||
label: <OrnamentGlyph ornament={o} />,
|
||||
title: t(`journey.studio.ornament.${o}`),
|
||||
}))}
|
||||
onPick={(ornament) => set({ ornament })}
|
||||
ariaLabel={t('journey.studio.ornamentTitle')}
|
||||
/>
|
||||
</Section>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user