import type { BookElement } from '@trek/shared'; import { RotateCcw, RotateCw } from 'lucide-react'; import { NumField, Section, Switch } from '../StudioControls'; import { turned } from '../stickerLibrary'; import { positionInUse } from './inspectorModel'; /** * Where the selected element sits, how big it is, how it is turned and how * strongly it shows: one group, the same for every kind. * * Folded unless the element is turned or faded, or is a sticker: everything in * here can be done by dragging, which is how it is actually done, and the * numbers are for the one time in ten you need the same margin on two pages. * The turn buttons tip the element a step at a time, which a sticker or a * photo set at an angle wants more often than a typed figure. A sticker's * mirror is here as well, since it is how the drawing lies on the page. * * With several selected the group keeps the angle, the opacity, the turn and, * when they are all stickers, the mirror, and each writes to every one of * them. Only the frame's numbers go: one x for four elements would stack them * on top of each other. The sticker inspector used to carry its own turn, * angle and opacity beside these, so a sticker had two of each. */ /** A quarter of a right angle and a little: what the turn buttons tip an element by. */ const TURN_STEP = 15; export function StudioPositionSection({ el, sel, set, t, }: { /** The first of the selection, whose figures the group shows. */ el: BookElement; /** The whole selection, `el` among it. */ sel: readonly BookElement[]; set: (patch: Partial) => void; t: (k: string) => string; }) { const { frame } = el; const one = sel.length <= 1; const turnLeft = t('journey.studio.stickerTurnLeft'); const turnRight = t('journey.studio.stickerTurnRight'); const mirror = el.kind === 'sticker' && sel.every((e) => e.kind === 'sticker'); return (
positionInUse(e))}> {one && (
set({ frame: { ...frame, x: v } })} /> set({ frame: { ...frame, y: v } })} /> set({ frame: { ...frame, w: v } })} /> set({ frame: { ...frame, h: v } })} />
)}
set({ rotation: v })} /> set({ opacity: Math.min(1, Math.max(0, v / 100)) })} />
{mirror && ( set({ flipX: !el.flipX })} /> )}
); }