Files
TREK/shared/src/book/book-ops-sticker.ts
T
Maurice 8c6f5deab2 feat(studio): a sticker library of 148 hand-drawn illustrations, placed, recoloured and searched by people and the assistant
A new element kind, sticker, draws layered vector illustrations from a library in twelve themes, behind its own entry point @trek/shared/stickers. Studio gets a Stickers rail section (themes, localized search, recently used, click or drag to place) and an inspector for colour slots, mirroring, turning and opacity. The assistant gets list_book_assets, add and style of stickers in edit_book_page, stickers in describe_book_page and an overlap warning for a sticker over words. BOOK_SCHEMA_REV goes to 2.
2026-10-23 21:06:09 +02:00

27 lines
1.3 KiB
TypeScript

import type { BookNewElement } from './book-element-ops.schema';
import { failOp, type BookOpsContext } from './book-ops-core';
import { bookStickerColors, bookStickerElement, bookStickerSize } from './book-sticker';
import type { BookFrame, BookPageSetup, BookStickerElement } from './book.schema';
/**
* `add` of a sticker: the Studio panel's placement, through the library the
* context hands in. The sticker arrives at the panel's size (book-sticker.ts)
* centred on the page unless the operation gives a frame, in its own colours
* unless it names some, cut to the slots the drawing has.
*/
export function newStickerElement(
spec: Extract<BookNewElement, { kind: 'sticker' }>,
at: (size: { w: number; h: number }) => BookFrame,
env: { page: BookPageSetup; ctx: BookOpsContext; newId: (prefix: string) => string; opIndex: number },
): BookStickerElement {
const meta = env.ctx.stickers?.(spec.stickerId);
if (!meta) {
const why = env.ctx.stickers
? 'list_book_assets names the stickers there are'
: 'the sticker library is not available here';
throw failOp('sticker_unknown', `no sticker ${spec.stickerId}; ${why}`, env.opIndex);
}
const el = bookStickerElement(meta, at(bookStickerSize(meta.box, env.page)), env.newId('k'));
return { ...el, colors: bookStickerColors(meta, spec.colors), flipX: spec.flipX ?? false };
}