Files
TREK/shared/src/book/book-ops-lockup.ts
T
Maurice 75d0593198 feat(studio): text effects, fit to frame and 24 lockups in a Text styles shelf
- A text can be cased (capitals, lower case, small caps), placed at the top,
  middle or foot of its frame, outlined, given a hard shadow or a marker band,
  bent on an arc or round a circle, filled with a gallery photo or left
  hollow, and shrunk to fit its frame. Every effect prints as vector: copies
  and strokes for HTML type, textPath and a clip over an <image> for SVG.
- Fitting is solved when the text is edited, in the Studio and in the edit
  engine, and stored; the chosen size is kept as the ceiling.
- Text sizes reach 400 pt and tracking 1.5 em.
- The Elements panel opens on a Text tab: the plain styles and 24 lockups
  (titles, badges and stamps, chapter marks, quotes, captions, places), each
  drawn with the book's own title and placed as one group.
- The assistant sets every effect through style and add, places a lockup with
  add_lockup, reads the effects in describe_book_page and gets two new
  findings (curve_overflow, effect_heavy) beside photo-fill and band checks.
- Book format revision 6.
2026-10-23 22:08:13 +00:00

41 lines
1.8 KiB
TypeScript

import { addBookLockup, buildBookLockup, bookLockupBox, findBookLockup } from './book-lockups';
import { failOp, galleryPhoto, roomFor, type BookOpsContext } from './book-ops-core';
import type { BookAddLockupOp } from './book-text-ops.schema';
import type { BookElement, BookPageSetup, BookSpread } from './book.schema';
/**
* `add_lockup`: the Studio's Text styles shelf, for the assistant. The same
* builder sets the same lockup from the same words, so a lockup the assistant
* placed looks exactly like one somebody picked from the shelf.
*/
interface LockupEnv {
page: BookPageSetup;
ctx: BookOpsContext;
newId: (prefix: string) => string;
opIndex: number;
}
export function opAddLockup(spread: BookSpread, op: BookAddLockupOp, env: LockupEnv): BookSpread {
const lockup = findBookLockup(op.lockup);
if (!lockup) throw failOp('invalid_op', `no lockup ${op.lockup}`, env.opIndex);
if (op.photoId !== undefined) galleryPhoto(op.photoId, env.ctx, env.opIndex);
const box = op.box ?? bookLockupBox(lockup, env.page, spread.role !== 'inner');
const made = buildBookLockup(lockup, box, {
words: op.words,
palette: { ...(op.ink ? { ink: op.ink } : {}), ...(op.accent ? { accent: op.accent } : {}) },
photoId: op.photoId ?? null,
newId: env.newId,
});
if (!made.length) {
throw failOp('text_required', `give the words for at least one of the texts of ${lockup.id}`, env.opIndex);
}
roomFor(spread, made.length, env.opIndex);
return addBookLockup(spread, made, env.newId('g'));
}
/** A text's photo fill names a gallery photo, checked as a photo frame's photo is. */
export function checkTextFillPhoto(el: BookElement, env: { ctx: BookOpsContext; opIndex: number }): void {
if (el.kind === 'text' && el.fillPaint?.type === 'photo') galleryPhoto(el.fillPaint.photoId, env.ctx, env.opIndex);
}