mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
8c6f5deab2
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.
27 lines
1.3 KiB
TypeScript
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 };
|
|
}
|