import { BOOK_LINE_CAPS, BOOK_LINE_ORNAMENTS, type BookLineCap, type BookLineElement, type BookLineOrnament, bookLineStyled, } from '@trek/shared'; import { ArrowLeftRight } from 'lucide-react'; import type { ReactNode } from 'react'; import { useStudioStore } from '../../store/studioStore'; import { ornamentInUse } from './inspector/inspectorModel'; import { lineGeometry } from './lineRender'; import { LinePaths } from './LineView'; import { Choice, Line, NumField, Section } from './StudioControls'; import { STROKE_STYLE_OPTIONS } from './studioOptions'; import { Swatches } from './StudioSwatches'; /** * The inspector of a drawn line: the course it takes first (straight or * smooth, a wave or a zigzag, the hand-drawn wobble), then where it sits, then * its look (colour, weight, dashes) and what sits on each end, and folded * under those the ornament in its middle, open on a line that has one. * * 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>; type GlyphLook = Parameters[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 }) { 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 ( ); } /** A tiny line with this end on it, for the end pickers. */ const CapGlyph = ({ cap, start }: { cap: BookLineCap; start: boolean }) => ( ); /** A tiny rule with this ornament in its middle. */ const OrnamentGlyph = ({ ornament }: { ornament: BookLineOrnament }) => ( ); export function LineInspector({ el, spreadIndex, position, t, }: { el: BookLineElement; spreadIndex: number; /** The position and size group, which every kind places after what it is. */ position: ReactNode; 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: , title: t(`journey.studio.cap.${c}`), })); return ( <>
({ value, label: t(`journey.studio.lineCourse.${value}`), }))} onPick={(curve) => set({ curve })} /> ({ value, label: t(`journey.studio.lineBody.${value}`), }))} onPick={(squiggle) => set({ squiggle })} />
set({ wobble: Math.min(1, Math.max(0, v / 100)) })} />

{t('journey.studio.linePointsHint')}

{position}
set({ stroke: c })} />
set({ strokeWidth: v })} />
({ value: o.value, label: t(o.labelKey) }))} onPick={(dash) => set({ dash })} />
set({ startCap })} /> set({ endCap })} />
({ value: o, label: , title: t(`journey.studio.ornament.${o}`), }))} onPick={(ornament) => set({ ornament })} ariaLabel={t('journey.studio.ornamentTitle')} />
); }