fix(studio): the book tools state every field once, and the server typechecks within its memory again

- The element, spread, document, page operation and card unions carry a
  name of their own, so the declarations of every schema that holds them
  refer to them instead of spelling them out again. The shared declarations
  shrink from 9 to 5.5 MB and the server's typecheck from 4.4 to 2.9 GB, so
  the build fits the image's 4 GB again.
- edit_book_page and revise_book_design take add by what the element is,
  with an id of its own; its look follows with style by that id in the same
  call, every look field described once. A change an assistant card kept
  with its look on add still reads and runs.
- restore_book_page states what every element has once, then each kind's
  own fields and the type the five travel kinds share, without defaults; the
  page is read as a spread again before it goes back.
- The theme links are explained once in the page edit's description, and
  style points a text's face, a shape's paint and outline and a photo's crop
  look at their one full description.
- The lockup roles live in a module of their own, so the operation schemas
  no longer import the lockup engine, whose cycle left the operations unset
  in the shared tests.
- The theme switches no longer fall through a comment, the newer document
  test follows the current revision, the line inspector names its stroke
  keys, a text's anchor reads no physical side, two shapes record the
  proportions they are drawn at, and the photo look and line tests follow
  the slider and the folded ornaments.
This commit is contained in:
Maurice
2026-10-23 22:03:51 +00:00
parent a32465ad32
commit cbf9325e7e
27 changed files with 447 additions and 142 deletions
+3 -3
View File
@@ -59,9 +59,9 @@ function previousToken(hex: string, prev: BookTheme | null): BookColorToken | un
/** The coloured inks an element is drawn in, as adoption would read them. */
function chromaticInks(el: BookElement): string[] {
switch (el.kind) {
// A line keeps the colour it was drawn in (book-line.schema.ts has no theme link).
case 'photo':
case 'sticker':
// A line keeps the colour it was drawn in (book-line.schema.ts has no theme link).
case 'line':
return [];
case 'text':
@@ -156,10 +156,10 @@ function adoptElement(
): BookElement {
if (el.locked) return el;
switch (el.kind) {
// A sticker keeps the colours of its slots: they are a drawing, not the page's inks.
// A sticker keeps the colours of its slots: they are a drawing, not the page's inks. A line
// keeps the colour it was drawn in (book-line.schema.ts has no theme link).
case 'photo':
case 'sticker':
// A line keeps the colour it was drawn in (book-line.schema.ts has no theme link).
case 'line':
return el;
case 'text': {
@@ -121,8 +121,10 @@ describe('adopting what is not linked', () => {
const sp = page([photo(), scrim, white, locked]);
const done = adoptSpread(sp, adoptionMap(book([sp]), null), null);
const byId = new Map(done.elements.map((e) => [e.id, e]));
expect(byId.get('sc')).toBe(scrim);
expect(byId.get('l')).toBe(locked);
// The page's own objects come back, the parse having copied the ones handed in.
const own = new Map(sp.elements.map((e) => [e.id, e]));
expect(byId.get('sc')).toBe(own.get('sc'));
expect(byId.get('l')).toBe(own.get('l'));
expect((byId.get('w') as BookElement & { token?: string }).token).toBeUndefined();
expect('token' in (byId.get('w') as object)).toBe(false);
});
+1 -1
View File
@@ -64,9 +64,9 @@ export function themedElement<E extends BookElement>(el: E, theme: BookTheme): E
if (el.locked) return el;
const next: Record<string, unknown> = { ...el };
switch (el.kind) {
// A line keeps the colour it was drawn in (book-line.schema.ts has no theme link).
case 'photo':
case 'sticker':
// A line keeps the colour it was drawn in (book-line.schema.ts has no theme link).
case 'line':
return el;
case 'text': {
+10 -15
View File
@@ -149,24 +149,19 @@ export const bookFontSlotFieldSchema = z.enum(BOOK_FONT_SLOTS).optional().catch(
/*
* ── As the operations take them ─────────────────────────────────────────
*
* Strict and described, as every operation is: the tool schema is all a
* model reads. Null on a link takes it away, so the element keeps its colour
* and stops following the theme.
* Strict, as every operation is. Null on a link takes it away, so the element
* keeps its colour and stops following the theme.
*/
export const bookColorTokenInSchema = z
.enum(BOOK_COLOR_TOKENS)
.nullable()
.describe(
"Link the colour to the book's theme: paper, ink, muted (the softer ink of captions), accent, accent2 or accent3. The colour is taken from the theme and follows it when the theme changes; null unlinks it and keeps the colour.",
);
export const bookColorTokenInSchema = z.enum(BOOK_COLOR_TOKENS).nullable();
export const bookFontSlotInSchema = z.enum(BOOK_FONT_SLOTS).nullable();
export const bookFontSlotInSchema = z
.enum(BOOK_FONT_SLOTS)
.nullable()
.describe(
"Link the typeface to the theme's display (cover titles), heading, body or script face; it is set in that face now and whenever the theme changes. Null unlinks it.",
);
/**
* What the links mean, said once in the page edit's description rather than
* on each of the fourteen fields that carry one (the tool schema's size).
*/
export const BOOK_THEME_LINK_HINT =
"token, strokeToken and accentToken link a colour to the book's theme (paper, ink, muted for captions, accent, accent2, accent3): it takes the theme's colour and follows it; fontRole links the typeface to the theme's display, heading, body or script face. null unlinks and keeps the colour or face.";
const paletteIn = z.strictObject({
paper: hex.optional(),