From 815a523d1cf4155e3881b881f7c6d07d813fd4e5 Mon Sep 17 00:00:00 2001 From: Maurice Date: Fri, 23 Oct 2026 14:14:55 +0200 Subject: [PATCH] feat(assistant): Studio's assistant may design lively books, not only restrained ones - The design prompt keeps the print rules and adds energy: calm keeps today's rules, lively and loud layer photos, tilt, set oversize display type and block colour. Type sizes come as numbers relative to the page, and the model answers eight silent questions and previews the cover twice before it proposes. - The type scale reaches 2.5 and a display tier sets a cover title up to 200 pt; existing books keep their sizes. - An overlap is severe only where more than half of a photo or a text is covered by accident; a title over a photo, a framed inset or a turned photo is layering. - The assistant may use every icon of the icon tab, checked by name, and every enum of the book tools says what its values mean. --- .../src/components/Studio/iconLibrary.test.ts | 29 + client/src/components/Studio/iconLibrary.ts | 7 +- .../assistant/assistant-book-design.prompt.ts | 38 +- server/src/nest/assistant/assistant.prompt.ts | 2 +- .../book-design/book-design-cards.test.ts | 33 +- shared/scripts/gen-book-icon-names.mjs | 68 ++ shared/src/book/book-element-ops.schema.ts | 128 +-- shared/src/book/book-element-ops.spec.ts | 9 +- shared/src/book/book-findings-design.spec.ts | 7 +- shared/src/book/book-findings-design.ts | 13 +- shared/src/book/book-findings.ts | 93 ++- shared/src/book/book-icon-names-a-e.data.ts | 667 ++++++++++++++++ shared/src/book/book-icon-names-f-p.data.ts | 727 ++++++++++++++++++ shared/src/book/book-icon-names-q-z.data.ts | 577 ++++++++++++++ shared/src/book/book-icons.ts | 35 +- shared/src/book/book-op-enums.spec.ts | 62 ++ shared/src/book/book-op-enums.ts | 141 ++++ shared/src/book/book-op-ids.ts | 6 +- shared/src/book/book-ops.schema.ts | 62 +- shared/src/book/describe-spread.spec.ts | 76 ++ shared/src/book/design/design-book.spec.ts | 28 + shared/src/book/design/design-compose.ts | 7 +- .../book/design/design-directives.schema.ts | 80 +- shared/src/book/design/design-framing.ts | 9 +- shared/src/book/design/design-style.spec.ts | 79 ++ shared/src/book/design/design-style.ts | 18 +- sonar-project.properties | 5 +- 27 files changed, 2883 insertions(+), 123 deletions(-) create mode 100644 client/src/components/Studio/iconLibrary.test.ts create mode 100644 shared/scripts/gen-book-icon-names.mjs create mode 100644 shared/src/book/book-icon-names-a-e.data.ts create mode 100644 shared/src/book/book-icon-names-f-p.data.ts create mode 100644 shared/src/book/book-icon-names-q-z.data.ts create mode 100644 shared/src/book/book-op-enums.spec.ts create mode 100644 shared/src/book/book-op-enums.ts create mode 100644 shared/src/book/design/design-style.spec.ts diff --git a/client/src/components/Studio/iconLibrary.test.ts b/client/src/components/Studio/iconLibrary.test.ts new file mode 100644 index 000000000..2e4b3596a --- /dev/null +++ b/client/src/components/Studio/iconLibrary.test.ts @@ -0,0 +1,29 @@ +/** + * FE-STUDIO-ICON-001 to FE-STUDIO-ICON-002 + * + * The icons the book engine takes (BOOK_ICON_NAMES in @trek/shared) are the + * drawings the Studio's icon tab offers, no more and no fewer: one the engine + * took that this lucide does not have would print as the fallback glyph, and + * one the tab offers that the engine refused would be a drawing a person can + * place and the assistant cannot. When lucide-react moves, run + * `node scripts/gen-book-icon-names.mjs` in shared/ and this passes again. + */ +import { BOOK_DESIGN_ICONS, BOOK_ICON_NAMES } from '@trek/shared'; +import { describe, expect, it } from 'vitest'; + +import { FEATURED_ICONS, ICON_NAMES } from './iconLibrary'; + +describe('the icons the book engine takes', () => { + it('FE-STUDIO-ICON-001: are every drawing the icon tab offers, and nothing it does not', () => { + // `Icon` is the component every drawing is built on, not a drawing. + const offered = ICON_NAMES.filter((name) => name !== 'Icon'); + const missing = offered.filter((name) => !BOOK_ICON_NAMES.has(name)); + const extra = [...BOOK_ICON_NAMES].filter((name) => !offered.includes(name)); + expect({ missing, extra }).toEqual({ missing: [], extra: [] }); + }); + + it('FE-STUDIO-ICON-002: hold the whole travel shelf the tab opens on', () => { + expect(BOOK_DESIGN_ICONS.filter((name) => !BOOK_ICON_NAMES.has(name))).toEqual([]); + expect(FEATURED_ICONS).toEqual([...BOOK_DESIGN_ICONS]); + }); +}); diff --git a/client/src/components/Studio/iconLibrary.ts b/client/src/components/Studio/iconLibrary.ts index a0997a880..892fac5a8 100644 --- a/client/src/components/Studio/iconLibrary.ts +++ b/client/src/components/Studio/iconLibrary.ts @@ -60,9 +60,10 @@ export const ICON_NAMES: string[] = buildNames() * of them quietly drops it instead of drawing a fallback in the shelf. */ /* - * The shelf itself lives in @trek/shared (book-icons.ts), because the book - * engine places icons from the same list: the assistant may only name a - * drawing a person could pick here. + * The shelf itself lives in @trek/shared (book-icons.ts), beside the whole + * list the book engine takes (BOOK_ICON_NAMES): the assistant may name any + * drawing a person could pick here, and iconLibrary.test.ts holds that list + * to ICON_NAMES. */ const FEATURED: readonly string[] = BOOK_DESIGN_ICONS diff --git a/server/src/nest/assistant/assistant-book-design.prompt.ts b/server/src/nest/assistant/assistant-book-design.prompt.ts index a31fe36bc..002fddf61 100644 --- a/server/src/nest/assistant/assistant-book-design.prompt.ts +++ b/server/src/nest/assistant/assistant-book-design.prompt.ts @@ -2,17 +2,37 @@ * How the Studio assistant designs a book (journey-studio-wp13.md 7): the * designer's rules it works by, appended to the Studio's standing * instructions (studioPrompt). Static, so the prompt cache stays stable. + * + * Restraint is one way to design a book, not the only one. The print rules + * (resolution, fold, trim, bleed, binding, legible words) hold for every + * book; how full, layered and loud a page is follows the energy the person + * asked for. The type scale is given in points on a 210 mm page, as + * design-style.ts sets it, so it scales with the page the same way. The + * questions under "Look, judge, revise" are the critique a designer runs on a + * proof, answered silently before every proposal. */ export const BOOK_DESIGN_PROMPT = `How you design: -- Act as a book designer, not a form filler: decide the story first (chapters, pacing), then the pages. -- Map the person's words to design_book's directives: "calm, lots of white" is style minimal and density airy; "like a magazine" is editorial; "bold" is bold and rich; "scrapbook" is scrapbook; a page count is pages.min and pages.max; "only Portugal" is a scope. -- Hierarchy: one dominant element per page; heading, then body, then captions; never two equal heroes on a spread. -- Whitespace is a beat: after a loud spread a quiet one; margins at least the safe area plus 6 mm. -- Rhythm: vary the beats, never three alike in a row; grids for bursts, a quiet page for a long story. -- Alignment: everything on the margin grid and the gutter; align and distribute instead of eyeballing. -- Colour from the photos: one accent, an ink and a paper; at most two typefaces in the whole book. -- Never upscale: under 200 dpi make the frame smaller; keep the focal point visible; no words on a busy part of a photo without a scrim. +- Act as a book designer, not a form filler: decide the story first (chapters, pacing), then the energy of the book, then the pages. +- Map the person's words to design_book's directives: "calm, lots of white" is style minimal and density airy; "like a magazine" is editorial; "bold", "lively" or "loud" is bold and rich; "scrapbook" is scrapbook; a page count is pages.min and pages.max; "only Portugal" is a scope. +- Before you call design_book, state the brief in one line: the energy (calm, lively or loud), the cover photo, the title words and the look. +Always, whatever the energy: +- Never upscale: under 200 dpi make the frame smaller; keep the focal point visible. +- Nothing that matters in the fold, past the trim or outside the safe area; a picture meant to bleed reaches the bleed; mind the binding on a double spread. +- Words on a photo sit on a quiet part of it, a scrim or a colour block; running text at 4.5:1 contrast, display type at 3:1. - Bound texts keep the journal in sync: prefer bindings over copied words; never invent captions or facts. -- Check every changed page with describe_book_page and the designId, look at the ones that matter most with preview_book_page and the designId when you can see images, and fix their findings with revise_book_design before you propose. +The energy decides the rest: +- Calm: one dominant element per page; heading, then body, then captions; whitespace as a beat after a loud spread; margins at least the safe area plus 6 mm; everything on the margin grid and the gutter; one accent from the photos and two typefaces. +- Lively: still one hero per page, now layered: a photo over a colour block or a shape, the title over a photo, photos turned 2 to 6 degrees in a white or polaroid frame, oversize display type, colour blocking in the accent. +- Loud: lively pushed further: bigger type, stronger colour, more layers, a title that fills the cover; never two heroes on one page. +- A deliberate overlap is a design; an accidental one (two straight photos or texts of a size half over each other) is a fault. +- Vary the beats, never three alike in a row; a quiet page for a long story, grids for bursts. +Type scale, in points for a 210 mm page and scaled with the page width: +- Cover title in a display face, 72 to 180 pt, 12 to 30 % of the page height; title to subtitle at least 3:1. For a big cover raise type.display (up to 6.5, about 180 pt); keep type.scale between 0.9 and 1.1 so body stays 9 to 11 pt. +- Date lines in spaced caps, 7 to 9 pt, tracking 0.25 to 0.4; an accent word over a title in the contrasting face (playfair italic or display), 1.2 to 1.6 times its cap height, with contrast, an outline or a shadow. +- Body 9 to 11 pt; captions 6.5 to 8 pt with tracking 0.05 to 0.1; a display face and a body face, two typefaces at most. +Look, judge, revise: +- Check every changed page with describe_book_page and the designId, and look at the pages that matter most with preview_book_page and the designId when you can see images; preview the cover at least twice, the first draft and the final one. +- Before every proposal answer silently: Is there one dominant element? Does the title read at thumbnail size? Does the energy match the brief? Is the palette the book's own? Is anything touching or overlapping by accident? Is text on a busy area without contrast? Does the decoration suit the energy? Does the page differ from the one before? Fix what fails with revise_book_design. +- Fix every severe finding before you propose; an info finding is context, not a fault. - One design, one proposal: apply_book_design for a whole book, never dozens of edit_book_page calls; a single page with edit_book_page. - Keep what the person locked or made by hand unless they ask; say which photos you left out and why.`; diff --git a/server/src/nest/assistant/assistant.prompt.ts b/server/src/nest/assistant/assistant.prompt.ts index 3778c23ba..77aaf0c3f 100644 --- a/server/src/nest/assistant/assistant.prompt.ts +++ b/server/src/nest/assistant/assistant.prompt.ts @@ -58,7 +58,7 @@ How you work: - Read get_book and describe_book_page before you change a page. Page and element ids come from them and from the book card; never invent one. Photo ids come only from {photoSources}. - To change the book, call the tool for the change: the app shows each call to the user as a change card, and nothing happens until they apply it. Do not describe a change in text and ask whether to make it. Make one edit_book_page call per page in a step, with all of that page's operations. - Act, don't announce. Make the reads and changes you need in this reply; never end a reply with "I will now ..." and no calls. Never say a change was made unless its result says it was applied. -- Keep every text inside its frame and nothing important in the fold or past the trim. When a result lists severe findings (overlapping photos, words past their frame, empty frames, content in the fold), fix them with the next change. +- Keep every text inside its frame and nothing important in the fold or past the trim. When a result lists severe findings (photos or texts overlapping by accident, words past their frame, empty frames, content in the fold), fix them with the next change; a layered page (a title over a photo, a turned photo over a shape) is a design, not a finding to fix. - Before you propose an edit_book_page change, look at the page once with preview_book_page and the edit's ops, fix what its findings show, then propose. When a result brings the page as an image, check your work on it too: photos of other contributors are empty frames there on purpose, not missing photos. - Never delete pages unless the user asks for it. Never place a photo at a size its resolution cannot print. - Picking photos works on what TREK knows about them: the day, the place, bursts and near duplicates, sharpness, resolution and whether a photo is in the book already. Nobody can tell from that who or what is in a photo or whether it is beautiful; only a page image shows the photos themselves. Say so when asked. diff --git a/server/tests/unit/nest/assistant/cards/book-design/book-design-cards.test.ts b/server/tests/unit/nest/assistant/cards/book-design/book-design-cards.test.ts index 654a74331..6e2a196a4 100644 --- a/server/tests/unit/nest/assistant/cards/book-design/book-design-cards.test.ts +++ b/server/tests/unit/nest/assistant/cards/book-design/book-design-cards.test.ts @@ -224,11 +224,42 @@ describe('the designer in the Studio', () => { it('ASTBD-008: the Studio instructions end with the design rules, cache-stable and without dashes', () => { const prompt = studioPrompt('German', true); expect(prompt.endsWith(BOOK_DESIGN_PROMPT)).toBe(true); - expect(BOOK_DESIGN_PROMPT.split('\n').length).toBeLessThanOrEqual(14); + // The print rules, the energy, the type scale and the critique, on a budget the cache carries every turn. + expect(BOOK_DESIGN_PROMPT.split('\n').length).toBeLessThanOrEqual(30); + expect(BOOK_DESIGN_PROMPT.length).toBeLessThan(6000); for (const tool of ['design_book', 'revise_book_design', 'apply_book_design', 'preview_book_page']) { expect(BOOK_DESIGN_PROMPT).toContain(tool); } expect(BOOK_DESIGN_PROMPT).not.toMatch(/[\u2013\u2014]/); expect(studioPrompt('German', true)).toBe(prompt); }); + + it('ASTBD-009: restraint is one energy among three, beside print rules that hold for every book', () => { + for (const rule of ['200 dpi', 'fold', 'trim', 'bleed', 'binding', 'safe area']) { + expect(BOOK_DESIGN_PROMPT, rule).toContain(rule); + } + for (const energy of ['- Calm:', '- Lively:', '- Loud:']) expect(BOOK_DESIGN_PROMPT).toContain(energy); + expect(BOOK_DESIGN_PROMPT).toContain('A deliberate overlap is a design'); + }); + + it('ASTBD-010: gives the type scale in numbers against the page, and the critique to answer before a proposal', () => { + for (const figure of ['72 to 180 pt', '12 to 30 % of the page height', 'at least 3:1', 'Body 9 to 11 pt']) { + expect(BOOK_DESIGN_PROMPT, figure).toContain(figure); + } + expect(BOOK_DESIGN_PROMPT).toContain('captions 6.5 to 8 pt'); + // The cover tier carries a big title alone, and the faces named are faces the book has. + expect(BOOK_DESIGN_PROMPT).toContain('type.display (up to 6.5'); + expect(BOOK_DESIGN_PROMPT).toContain('type.scale between 0.9 and 1.1'); + expect(BOOK_DESIGN_PROMPT).not.toMatch(/script/i); + expect(BOOK_DESIGN_PROMPT).toContain('210 mm page and scaled with the page width'); + const rubric = BOOK_DESIGN_PROMPT.slice(BOOK_DESIGN_PROMPT.indexOf('answer silently')); + expect(rubric.slice(0, rubric.indexOf('Fix what fails')).match(/\?/g)).toHaveLength(8); + expect(BOOK_DESIGN_PROMPT).toContain('preview the cover at least twice'); + }); + + it('ASTBD-011: the Studio instructions take a layered page for a design and only an accidental overlap for a fault', () => { + const prompt = studioPrompt('German', true); + expect(prompt).toContain('photos or texts overlapping by accident'); + expect(prompt).toContain('a layered page (a title over a photo, a turned photo over a shape) is a design'); + }); }); diff --git a/shared/scripts/gen-book-icon-names.mjs b/shared/scripts/gen-book-icon-names.mjs new file mode 100644 index 000000000..eaafae45a --- /dev/null +++ b/shared/scripts/gen-book-icon-names.mjs @@ -0,0 +1,68 @@ +// Regenerates src/book/book-icon-names-*.data.ts, the lucide drawings the +// Studio's icon tab offers, from the lucide-react installed at the repo root. +// Run from shared/: `node scripts/gen-book-icon-names.mjs`. +// +// Read from the package's type declarations rather than imported: the shared +// package has no lucide dependency of its own and must not grow one, the +// contract layer stays zod only. The names are taken the way the client's +// iconLibrary.ts takes them from the module: every PascalCase export, less the +// `Lucide*` and `*Icon` aliases of a name that exists bare, and less `Icon`, +// the component every drawing is built on. client/src/components/Studio/ +// iconLibrary.test.ts fails when the files and the shipped library drift apart. +import { readFileSync, writeFileSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const here = dirname(fileURLToPath(import.meta.url)); +const lucide = join(here, '..', '..', 'node_modules', 'lucide-react'); +const { version } = JSON.parse(readFileSync(join(lucide, 'package.json'), 'utf8')); +const declarations = readFileSync(join(lucide, 'dist', 'lucide-react.d.ts'), 'utf8'); + +/** The last `export { ... };` of the declarations, which names every icon and its aliases. */ +const exportLine = declarations + .split('\n') + .filter((line) => line.startsWith('export { ')) + .pop(); +if (!exportLine) throw new Error('no export list in lucide-react.d.ts'); + +const PASCAL_CASE = /^[A-Z][A-Za-z0-9]*$/; +const exported = exportLine + .replace(/^export \{ /, '') + .replace(/ \};\s*$/, '') + .split(',') + .map((part) => + part + .trim() + .split(/\s+as\s+/) + .pop(), + ) + .filter((name) => PASCAL_CASE.test(name)); +const present = new Set(exported); +const names = [...present] + .filter((name) => !(name.startsWith('Lucide') && present.has(name.slice(6)))) + .filter((name) => !(name.endsWith('Icon') && present.has(name.slice(0, -4)))) + .filter((name) => name !== 'Icon') + .sort(); + +/** The three files and the initials each holds, so none of them passes a thousand lines. */ +const PARTS = [ + { suffix: 'a-e', constant: 'BOOK_ICON_NAMES_A_E', label: 'A to E', test: /^[A-E]/ }, + { suffix: 'f-p', constant: 'BOOK_ICON_NAMES_F_P', label: 'F to P', test: /^[F-P]/ }, + { suffix: 'q-z', constant: 'BOOK_ICON_NAMES_Q_Z', label: 'Q to Z', test: /^[Q-Z]/ }, +]; + +for (const part of PARTS) { + const list = names.filter((name) => part.test.test(name)); + const source = `/** + * The lucide drawings the Studio offers, ${part.label}: part of BOOK_ICON_NAMES + * (book-icons.ts). Generated from lucide-react ${version} by + * scripts/gen-book-icon-names.mjs, never edited by hand; the client's + * iconLibrary.test.ts fails when the list and the library it ships drift apart. + */ +export const ${part.constant}: readonly string[] = [ +${list.map((name) => ` '${name}',`).join('\n')} +]; +`; + writeFileSync(join(here, '..', 'src', 'book', `book-icon-names-${part.suffix}.data.ts`), source); +} +console.log(`wrote ${names.length} icon names from lucide-react ${version}`); diff --git a/shared/src/book/book-element-ops.schema.ts b/shared/src/book/book-element-ops.schema.ts index 1657ad665..2140ff2a9 100644 --- a/shared/src/book/book-element-ops.schema.ts +++ b/shared/src/book/book-element-ops.schema.ts @@ -1,17 +1,39 @@ import { idSchema } from '../common/primitives.schema'; -import { BOOK_DESIGN_ICONS } from './book-icons'; +import { + BOOK_BINDING_HINT, + bookBadgeStyleSchema, + bookBadgeVariantSchema, + bookCountriesLayoutSchema, + bookFontIdSchema, + bookFrameStyleSchema, + bookIconNameSchema, + bookListLayoutSchema, + bookMapClipSchema, + bookMapSourceSchema, + bookMapStyleSchema, + bookMetricSchema, + bookPhotoFilterSchema, + bookPhotoFitSchema, + bookPhotoMaskSchema, + bookPinStyleSchema, + bookRouteArcSchema, + bookRouteDashSchema, + bookRouteStyleSchema, + bookShapeGradientSchema, + bookShapeIdSchema, + bookStatsLayoutSchema, + bookStrokeStyleSchema, + bookTextAlignSchema, + bookTypesetFontSchema, +} from './book-op-enums'; import { bookElementIdSchema, bookGridIdSchema, bookSpreadIdSchema } from './book-op-ids'; import { - BOOK_BADGES, - BOOK_METRICS, - BOOK_SHAPES, MAX_BOOK_COUNTRIES, bookBadgeElementSchema, bookCountriesElementSchema, bookIconElementSchema, bookListElementSchema, bookMapElementSchema, - bookPhotoElementSchema, bookShapeElementSchema, bookStatsElementSchema, bookTextElementSchema, @@ -28,7 +50,9 @@ import { z } from 'zod'; * * Same rules as the other operations: strict objects, the fields taken from the * document's own shapes with their defaults removed (an omitted field leaves - * the element as it is), every string, array and number bounded. + * the element as it is), every string, array and number bounded. The enums + * carry a line each on what their values mean (book-op-enums.ts), since the + * tool schema is all a model reads of them. */ /** A position in millimetres, inside the bounds the document takes. */ @@ -40,7 +64,6 @@ const ids30 = z.array(bookElementIdSchema).min(1).max(30); export const bookFrameInSchema = z.strictObject({ x: mmIn, y: mmIn, w: sizeIn, h: sizeIn }); -const photo = bookPhotoElementSchema.shape; const text = bookTextElementSchema.shape; const shape = bookShapeElementSchema.shape; const icon = bookIconElementSchema.shape; @@ -55,7 +78,7 @@ const COMMON = { opacity: unit01.optional() }; /** What the travel kinds share with text: they are typeset. */ const TYPESET = { - font: map.font.unwrap().optional(), + font: bookTypesetFontSchema.optional(), color: map.color.unwrap().optional(), accent: map.accent.unwrap().optional(), textScale: map.textScale.unwrap().optional(), @@ -64,21 +87,21 @@ const TYPESET = { const PHOTO_PROPS = { ...COMMON, - fit: photo.fit.unwrap().optional(), + fit: bookPhotoFitSchema.optional(), focalX: unit01.optional(), focalY: unit01.optional(), - mask: photo.mask.unwrap().optional(), - frameStyle: photo.frameStyle.unwrap().optional(), - filter: photo.filter.unwrap().optional(), + mask: bookPhotoMaskSchema.optional(), + frameStyle: bookFrameStyleSchema.optional(), + filter: bookPhotoFilterSchema.optional(), radius: z.number().finite().min(0).max(500).optional(), }; /** How a text is set, each field left as it is when not named: the style op's and the page edit's text op's. */ export const TEXT_STYLE_FIELDS = { - font: text.font.unwrap().optional(), + font: bookFontIdSchema.optional(), size: text.size.unwrap().optional(), weight: text.weight.unwrap().optional(), italic: text.italic.unwrap().optional(), - align: text.align.unwrap().optional(), + align: bookTextAlignSchema.optional(), leading: text.leading.unwrap().optional(), tracking: text.tracking.unwrap().optional(), color: text.color.unwrap().optional(), @@ -87,10 +110,10 @@ const TEXT_PROPS = { ...COMMON, ...TEXT_STYLE_FIELDS }; const SHAPE_PROPS = { ...COMMON, fill: shape.fill.unwrap().optional(), - gradient: shape.gradient.unwrap().optional(), + gradient: bookShapeGradientSchema.optional(), stroke: shape.stroke.unwrap().optional(), strokeWidth: z.number().finite().min(0).max(20).optional(), - strokeStyle: shape.strokeStyle.unwrap().optional(), + strokeStyle: bookStrokeStyleSchema.optional(), radius: z.number().finite().min(0).max(500).optional(), }; const ICON_PROPS = { @@ -101,39 +124,39 @@ const ICON_PROPS = { const MAP_PROPS = { ...COMMON, ...TYPESET, - style: map.style.unwrap().optional(), + style: bookMapStyleSchema.optional(), showLand: map.showLand.unwrap().optional(), showRoute: map.showRoute.unwrap().optional(), showPins: map.showPins.unwrap().optional(), showLabels: map.showLabels.unwrap().optional(), - routeStyle: map.routeStyle.unwrap().optional(), - routeArc: map.routeArc.unwrap().optional(), - routeDash: map.routeDash.unwrap().optional(), - pinStyle: map.pinStyle.unwrap().optional(), - clip: map.clip.unwrap().optional(), + routeStyle: bookRouteStyleSchema.optional(), + routeArc: bookRouteArcSchema.optional(), + routeDash: bookRouteDashSchema.optional(), + pinStyle: bookPinStyleSchema.optional(), + clip: bookMapClipSchema.optional(), fitPadding: map.fitPadding.unwrap().optional(), fitToCountries: map.fitToCountries.unwrap().optional(), }; const STATS_PROPS = { ...COMMON, ...TYPESET, - layout: stats.layout.unwrap().optional(), + layout: bookStatsLayoutSchema.optional(), showIcons: stats.showIcons.unwrap().optional(), - units: stats.units.unwrap().optional(), + units: stats.units.unwrap().describe('Kilometres (metric) or miles (imperial).').optional(), }; const COUNTRIES_PROPS = { ...COMMON, ...TYPESET, - layout: countries.layout.unwrap().optional(), + layout: bookCountriesLayoutSchema.optional(), showOutline: countries.showOutline.unwrap().optional(), showFlag: countries.showFlag.unwrap().optional(), showName: countries.showName.unwrap().optional(), - align: countries.align.unwrap().optional(), + align: countries.align.unwrap().describe('How the names sit in the frame.').optional(), }; const BADGE_PROPS = { ...COMMON, ...TYPESET, - style: badge.style.unwrap().optional(), + style: bookBadgeStyleSchema.optional(), showIcon: badge.showIcon.unwrap().optional(), showLabel: badge.showLabel.unwrap().optional(), autoColor: badge.autoColor.unwrap().optional(), @@ -143,13 +166,12 @@ const BADGE_PROPS = { const LIST_PROPS = { ...COMMON, ...TYPESET, - layout: list.layout.unwrap().optional(), + layout: bookListLayoutSchema.optional(), showMarks: list.showMarks.unwrap().optional(), proLabel: z.string().max(80).optional(), conLabel: z.string().max(80).optional(), }; -const metric = z.enum(BOOK_METRICS); -const METRICS = z.array(metric).min(1).max(7); +const METRICS = z.array(bookMetricSchema).min(1).max(7); /** * The look of an element, per kind, for `style`. Values the journey owns (a @@ -159,7 +181,7 @@ const METRICS = z.array(metric).min(1).max(7); export const bookElementPropsSchema = z.discriminatedUnion('kind', [ z.strictObject({ kind: z.literal('photo'), ...PHOTO_PROPS }), z.strictObject({ kind: z.literal('text'), ...TEXT_PROPS }), - z.strictObject({ kind: z.literal('shape'), shape: z.enum(BOOK_SHAPES).optional(), ...SHAPE_PROPS }), + z.strictObject({ kind: z.literal('shape'), shape: bookShapeIdSchema.optional(), ...SHAPE_PROPS }), z.strictObject({ kind: z.literal('icon'), ...ICON_PROPS }), z.strictObject({ kind: z.literal('map'), ...MAP_PROPS }), z.strictObject({ kind: z.literal('stats'), metrics: METRICS.optional(), ...STATS_PROPS }), @@ -189,9 +211,15 @@ export function bindingNamesItsSource( const bindingIn = text.binding .unwrap() .unwrap() - .refine(bindingNamesItsSource, { message: 'an entry binding needs its entryId, a photo binding its photoId' }); + .refine(bindingNamesItsSource, { message: 'an entry binding needs its entryId, a photo binding its photoId' }) + .describe(BOOK_BINDING_HINT); const iso2 = z.string().regex(/^[A-Za-z]{2}$/); -const listItem = z.strictObject({ text: z.string().max(400), tone: z.enum(['pro', 'con', 'plain']) }); +const listItem = z.strictObject({ + text: z.string().max(400), + tone: z + .enum(['pro', 'con', 'plain']) + .describe('pro or con sets the line in that column with its mark; plain has none.'), +}); /** * Where a map is of: the whole journey or one trip, the two scopes a stored map @@ -210,18 +238,21 @@ export const bookNewElementSchema = z.discriminatedUnion('kind', [ z .strictObject({ kind: z.literal('text'), - preset: z.enum(BOOK_TEXT_PRESETS).optional(), + preset: z + .enum(BOOK_TEXT_PRESETS) + .describe('A Studio text preset: heading, subheading, body, caption, or quote (the large quotation mark).') + .optional(), text: z.string().max(2000).optional(), binding: bindingIn.optional(), ...TEXT_PROPS, }) .refine((v) => v.text !== undefined || v.binding !== undefined, { message: 'give the words or a binding' }), - z.strictObject({ kind: z.literal('shape'), shape: z.enum(BOOK_SHAPES), ...SHAPE_PROPS }), - z.strictObject({ kind: z.literal('icon'), name: z.enum(BOOK_DESIGN_ICONS), ...ICON_PROPS }), + z.strictObject({ kind: z.literal('shape'), shape: bookShapeIdSchema, ...SHAPE_PROPS }), + z.strictObject({ kind: z.literal('icon'), name: bookIconNameSchema, ...ICON_PROPS }), z.strictObject({ kind: z.literal('map'), scope: mapScope, - source: z.enum(['vector', 'relief', 'satellite']).optional(), + source: bookMapSourceSchema.optional(), ...MAP_PROPS, }), z.strictObject({ kind: z.literal('stats'), metrics: METRICS, ...STATS_PROPS }), @@ -232,7 +263,7 @@ export const bookNewElementSchema = z.discriminatedUnion('kind', [ }), z.strictObject({ kind: z.literal('badge'), - variant: z.enum(BOOK_BADGES), + variant: bookBadgeVariantSchema, entryId: idSchema.optional(), code: z.string().max(24).optional(), text: z.string().max(200).optional(), @@ -274,20 +305,27 @@ export const BOOK_ELEMENT_OP_SCHEMAS = [ z.strictObject({ op: z.literal('arrange'), elementIds: ids30, - to: z.enum(['front', 'forward', 'backward', 'back']), + to: z + .enum(['front', 'forward', 'backward', 'back']) + .describe('front and back go to either end of the paint order; forward and backward one step.'), }), /** Line elements up on an edge or a centre line of the selection, their page, or its safe area. */ z.strictObject({ op: z.literal('align'), elementIds: ids30, - edge: z.enum(['left', 'center', 'right', 'top', 'middle', 'bottom']), - to: z.enum(['selection', 'page', 'safe']).default('selection'), + edge: z + .enum(['left', 'center', 'right', 'top', 'middle', 'bottom']) + .describe('The edge or centre line the elements line up on.'), + to: z + .enum(['selection', 'page', 'safe']) + .describe('Line up within the selection, the page, or its safe area.') + .default('selection'), }), /** Space three or more elements evenly, or by a fixed gap in millimetres. */ z.strictObject({ op: z.literal('distribute'), elementIds: z.array(bookElementIdSchema).min(3).max(30), - axis: z.enum(['horizontal', 'vertical']), + axis: z.enum(['horizontal', 'vertical']).describe('Space them out across the page or down it.'), gap: z.number().finite().min(0).max(200).optional(), }), /** Lock or unlock elements: the one operation a locked element accepts. */ @@ -300,7 +338,11 @@ export const BOOK_ELEMENT_OP_SCHEMAS = [ dy: z.number().finite().min(-500).max(500).optional(), }), /** The Studio's fill: a photo to the bleed of its page or the spread, unturned, cover, at the back. */ - z.strictObject({ op: z.literal('fill'), elementId: bookElementIdSchema, scope: z.enum(['page', 'spread']) }), + z.strictObject({ + op: z.literal('fill'), + elementId: bookElementIdSchema, + scope: z.enum(['page', 'spread']).describe('Fill its own page to the bleed, or both pages of the spread.'), + }), /** Copy elements of another page onto this one, with new ids; photos are checked against the gallery. */ z.strictObject({ op: z.literal('copy_from'), spreadId: bookSpreadIdSchema, elementIds: ids30 }), /** Bring travel figures up to date with the journey: the named elements, or every one on the page. */ diff --git a/shared/src/book/book-element-ops.spec.ts b/shared/src/book/book-element-ops.spec.ts index efff436e6..a99075cde 100644 --- a/shared/src/book/book-element-ops.spec.ts +++ b/shared/src/book/book-element-ops.spec.ts @@ -156,13 +156,18 @@ describe('add', () => { expect(addRefusal({ kind: 'text', binding: { source: 'photo.caption' }, text: 'x' })).toBe('invalid_op'); }); - it('BOOKEL-003: adds a rule as a hairline, a banner wide, and an icon from the shelf only', () => { + it('BOOKEL-003: adds a rule as a hairline, a banner wide, and any icon the Studio offers, by lucide name only', () => { expect(added({ kind: 'shape', shape: 'line' })).toMatchObject({ shape: 'rect', frame: { w: 105, h: 0.5 } }); const banner = added({ kind: 'shape', shape: 'banner-ribbon', fill: null }); expect(banner).toMatchObject({ fill: null, frame: { w: 107.1, h: 34.65 } }); const icon = added({ kind: 'icon', name: 'Compass', color: '#c2410c' }); expect(icon).toMatchObject({ name: 'Compass', color: '#c2410c', frame: { w: 37.8, h: 37.8 } }); - expect(addRefusal({ kind: 'icon', name: 'NotAnIcon' } as unknown as NewElement)).toBe('invalid_op'); + // Past the travel shelf: the whole library, its old names too, as the icon tab lists it. + expect(added({ kind: 'icon', name: 'Pizza' })).toMatchObject({ kind: 'icon', name: 'Pizza' }); + expect(added({ kind: 'icon', name: 'AlertTriangle' })).toMatchObject({ name: 'AlertTriangle' }); + for (const name of ['NotAnIcon', 'PizzaIcon', 'pizza', 'Icon']) { + expect(addRefusal({ kind: 'icon', name } as unknown as NewElement), name).toBe('invalid_op'); + } }); it('BOOKEL-004: adds the travel kinds from the journey, and refuses them without its figures', () => { diff --git a/shared/src/book/book-findings-design.spec.ts b/shared/src/book/book-findings-design.spec.ts index 18a689f4a..4e0568d18 100644 --- a/shared/src/book/book-findings-design.spec.ts +++ b/shared/src/book/book-findings-design.spec.ts @@ -129,12 +129,15 @@ describe('book level and the page in words', () => { return { ...doc, spreads: [doc.spreads[0] as BookSpread, ...inner, doc.spreads[4] as BookSpread] }; } - it('BOOKQA-009: finds more than two typefaces in a book, and says so once', () => { - const fonts = ['sans', 'serif', 'bebas'].map((font, i) => [ + it('BOOKQA-009: finds more than three typefaces in a book, and says so once', () => { + const fonts = ['sans', 'serif', 'bebas', 'playfair'].map((font, i) => [ text(`t-${i}`, 'Hi', { x: 230, y: 20, w: 60, h: 10 }, { font }), ]); const list = bookLevelFindings(bookOf(fonts)); expect(list.filter((f) => f.code === 'font_mix')).toHaveLength(1); + expect(list.find((f) => f.code === 'font_mix')?.message).toMatch(/4 typefaces .*keep to three/); + // A display face, a body face and one more is a book, not a sampler. + expect(bookLevelFindings(bookOf(fonts.slice(0, 3)))).toEqual([]); expect(bookLevelFindings(bookOf(fonts.slice(0, 2)))).toEqual([]); }); diff --git a/shared/src/book/book-findings-design.ts b/shared/src/book/book-findings-design.ts index eab59e0e0..21d3b47d1 100644 --- a/shared/src/book/book-findings-design.ts +++ b/shared/src/book/book-findings-design.ts @@ -340,16 +340,25 @@ function signatureOf(spread: BookSpread): string { return spread.elements.map((e) => `${e.kind}:${cm(e.frame.x)},${cm(e.frame.y)},${cm(e.frame.w)}`).join('|'); } +/** + * How many typefaces a book may be set in before it reads as a type sampler: + * a display face, a body face and one more, a script laid over a title or a + * face for figures. Two was the rule while the book had seven faces and no + * scripts, and it told every lively book that set its title apart to stop. + * Once fonts carry roles, script and mono faces will not count towards it. + */ +const MAX_BOOK_FAMILIES = 3; + /** Findings about the book as a whole: typefaces, colours, and the same page three times running. */ export function bookLevelFindings(doc: BookDocument): BookFinding[] { const out: BookFinding[] = []; const families = familiesOf(doc); - if (families.length > 2) { + if (families.length > MAX_BOOK_FAMILIES) { out.push({ code: 'font_mix', severity: 'warn', elementIds: [], - message: `the book is set in ${families.length} typefaces (${families.join(', ')}); keep to two`, + message: `the book is set in ${families.length} typefaces (${families.join(', ')}); keep to three: a display face, a body face and one more`, }); } const colours = [...coloursOf(doc)].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])); diff --git a/shared/src/book/book-findings.ts b/shared/src/book/book-findings.ts index c90073f48..049d04a1d 100644 --- a/shared/src/book/book-findings.ts +++ b/shared/src/book/book-findings.ts @@ -145,35 +145,106 @@ const placedPhotos = (spread: BookSpread) => spread.elements.filter((e): e is Bo /** * A photo under a quarter of the size of the one it lies on is an inset: the * auto layout sets a small picture over the hero on purpose. Context, not a - * fault; two pictures of a size on top of each other are. + * fault; two pictures of a size on top of each other are. The same holds for + * a small line of type set over display type, never over running text. */ const INSET_RATIO = 0.25; +/** + * Under this many degrees off straight an element reads as unturned; past it, + * as laid down at an angle on purpose. Above the scrapbook style's own tilt of + * 2 degrees, so a page of that style is not layered by its look alone. + */ +const TURNED_DEG = 3; + +/** Past this share of the smaller one covered, two photos or texts are an accident however they are turned or framed. */ +const LAYERED_MAX_SHARE = 0.5; + +/** Display type, which a small line may be set over: a few words at the heading floor of the styles or larger. */ +const DISPLAY_MAX_CHARS = 40; +const DISPLAY_MIN_PT = 14; + +/** The most overlap findings one page reports, the severe ones first. */ +const MAX_OVERLAPS = 6; + +/** How far an element is turned from straight, 0 to 180 degrees, whichever way and however many turns. */ +function turnOf(el: BookElement): number { + const rest = el.rotation % 360; + const turned = rest < 0 ? rest + 360 : rest; + return Math.min(turned, 360 - turned); +} + +/** + * Whether two elements on top of each other read as layered on purpose: either + * of them turned, or the upper one a photo in a frame (a polaroid, a border, a + * shadow), which is how a print laid on a page looks. `upper` is the one + * painted later. + */ +function layered(lower: BookElement, upper: BookElement): boolean { + if (turnOf(lower) >= TURNED_DEG || turnOf(upper) >= TURNED_DEG) return true; + return upper.kind === 'photo' && upper.frameStyle !== 'none'; +} + +/** Whether a text is display type: a few words, set at heading size or larger. */ +function isDisplay(el: BookElement): boolean { + return el.kind === 'text' && el.text.trim().length <= DISPLAY_MAX_CHARS && el.size >= DISPLAY_MIN_PT; +} + +/** Whether the smaller of two is an inset on the larger: any small photo, a small text only over display type. */ +function isInset(small: BookElement, large: BookElement, smaller: number, larger: number): boolean { + if (smaller >= larger * INSET_RATIO) return false; + return small.kind === 'photo' || isDisplay(large); +} + +/** + * Two photos or two texts on top of each other, `a` painted under `b`. + * + * Severe when it looks like an accident: both straight, of a size, the upper + * one unframed, or more than half of the smaller one covered whatever the + * look. A small one set over a large one, a turned or framed picture laid + * partly over another, is how a lively page is made, and is said as context. + * A title over a photo or a photo over a shape is never compared at all: + * different kinds layered are a design. + */ function overlapFinding(a: BookElement, b: BookElement, ba: Box, bb: Box, shared: number): BookFinding { const [small, large] = area(ba) <= area(bb) ? [a, b] : [b, a]; const smaller = Math.min(area(ba), area(bb)); - const pct = Math.round((shared / Math.max(smaller, 1)) * 100); - if (a.kind === 'photo' && smaller < Math.max(area(ba), area(bb)) * INSET_RATIO) { + const share = shared / Math.max(smaller, 1); + const pct = Math.round(share * 100); + const what = a.kind === 'photo' ? 'photo' : 'text'; + if (isInset(small, large, smaller, Math.max(area(ba), area(bb)))) { return { code: 'overlap', severity: 'info', elementIds: [small.id, large.id], - message: `photo ${small.id} is set as an inset over ${large.id} (${pct}% of it on the larger one)`, + message: `${what} ${small.id} is set as an inset over ${large.id} (${pct}% of it on the larger one)`, + }; + } + if (share <= LAYERED_MAX_SHARE && layered(a, b)) { + return { + code: 'overlap', + severity: 'info', + elementIds: [a.id, b.id], + message: `${what}s ${a.id} and ${b.id} are layered on purpose, turned or framed (${pct}% of the smaller one covered); check nothing that matters is hidden`, }; } return { code: 'overlap', severity: 'severe', elementIds: [a.id, b.id], - message: `${a.kind === 'photo' ? 'photos' : 'texts'} ${a.id} and ${b.id} overlap (${pct}% of the smaller one)`, + message: `${what}s ${a.id} and ${b.id} overlap (${pct}% of the smaller one)`, }; } +/** + * Every pair of photos or texts on top of each other, reported severe first up + * to the cap, so pairs layered on purpose never crowd out an accident. + */ function overlaps(ctx: Ctx): void { const content = ctx.spread.elements.filter((e) => e.kind === 'photo' || e.kind === 'text'); - let found = 0; - for (let i = 0; i < content.length && found < 6; i++) { - for (let j = i + 1; j < content.length && found < 6; j++) { + const found: BookFinding[] = []; + for (let i = 0; i < content.length; i++) { + for (let j = i + 1; j < content.length; j++) { const a = content[i] as BookElement; const b = content[j] as BookElement; if (a.kind !== b.kind) continue; @@ -181,10 +252,12 @@ function overlaps(ctx: Ctx): void { const bb = elementBox(b); const shared = overlapArea(ba, bb); if (shared < 4 || shared < Math.min(area(ba), area(bb)) * 0.05) continue; - found += 1; - add(ctx, overlapFinding(a, b, ba, bb, shared)); + found.push(overlapFinding(a, b, ba, bb, shared)); } } + const severe = found.filter((f) => f.severity === 'severe'); + const context = found.filter((f) => f.severity !== 'severe'); + for (const f of [...severe, ...context].slice(0, MAX_OVERLAPS)) add(ctx, f); } /** diff --git a/shared/src/book/book-icon-names-a-e.data.ts b/shared/src/book/book-icon-names-a-e.data.ts new file mode 100644 index 000000000..453b6fd35 --- /dev/null +++ b/shared/src/book/book-icon-names-a-e.data.ts @@ -0,0 +1,667 @@ +/** + * The lucide drawings the Studio offers, A to E: part of BOOK_ICON_NAMES + * (book-icons.ts). Generated from lucide-react 0.577.0 by + * scripts/gen-book-icon-names.mjs, never edited by hand; the client's + * iconLibrary.test.ts fails when the list and the library it ships drift apart. + */ +export const BOOK_ICON_NAMES_A_E: readonly string[] = [ + 'AArrowDown', + 'AArrowUp', + 'ALargeSmall', + 'Accessibility', + 'Activity', + 'ActivitySquare', + 'AirVent', + 'Airplay', + 'AlarmCheck', + 'AlarmClock', + 'AlarmClockCheck', + 'AlarmClockMinus', + 'AlarmClockOff', + 'AlarmClockPlus', + 'AlarmMinus', + 'AlarmPlus', + 'AlarmSmoke', + 'Album', + 'AlertCircle', + 'AlertOctagon', + 'AlertTriangle', + 'AlignCenter', + 'AlignCenterHorizontal', + 'AlignCenterVertical', + 'AlignEndHorizontal', + 'AlignEndVertical', + 'AlignHorizontalDistributeCenter', + 'AlignHorizontalDistributeEnd', + 'AlignHorizontalDistributeStart', + 'AlignHorizontalJustifyCenter', + 'AlignHorizontalJustifyEnd', + 'AlignHorizontalJustifyStart', + 'AlignHorizontalSpaceAround', + 'AlignHorizontalSpaceBetween', + 'AlignJustify', + 'AlignLeft', + 'AlignRight', + 'AlignStartHorizontal', + 'AlignStartVertical', + 'AlignVerticalDistributeCenter', + 'AlignVerticalDistributeEnd', + 'AlignVerticalDistributeStart', + 'AlignVerticalJustifyCenter', + 'AlignVerticalJustifyEnd', + 'AlignVerticalJustifyStart', + 'AlignVerticalSpaceAround', + 'AlignVerticalSpaceBetween', + 'Ambulance', + 'Ampersand', + 'Ampersands', + 'Amphora', + 'Anchor', + 'Angry', + 'Annoyed', + 'Antenna', + 'Anvil', + 'Aperture', + 'AppWindow', + 'AppWindowMac', + 'Apple', + 'Archive', + 'ArchiveRestore', + 'ArchiveX', + 'AreaChart', + 'Armchair', + 'ArrowBigDown', + 'ArrowBigDownDash', + 'ArrowBigLeft', + 'ArrowBigLeftDash', + 'ArrowBigRight', + 'ArrowBigRightDash', + 'ArrowBigUp', + 'ArrowBigUpDash', + 'ArrowDown', + 'ArrowDown01', + 'ArrowDown10', + 'ArrowDownAZ', + 'ArrowDownAz', + 'ArrowDownCircle', + 'ArrowDownFromLine', + 'ArrowDownLeft', + 'ArrowDownLeftFromCircle', + 'ArrowDownLeftFromSquare', + 'ArrowDownLeftSquare', + 'ArrowDownNarrowWide', + 'ArrowDownRight', + 'ArrowDownRightFromCircle', + 'ArrowDownRightFromSquare', + 'ArrowDownRightSquare', + 'ArrowDownSquare', + 'ArrowDownToDot', + 'ArrowDownToLine', + 'ArrowDownUp', + 'ArrowDownWideNarrow', + 'ArrowDownZA', + 'ArrowDownZa', + 'ArrowLeft', + 'ArrowLeftCircle', + 'ArrowLeftFromLine', + 'ArrowLeftRight', + 'ArrowLeftSquare', + 'ArrowLeftToLine', + 'ArrowRight', + 'ArrowRightCircle', + 'ArrowRightFromLine', + 'ArrowRightLeft', + 'ArrowRightSquare', + 'ArrowRightToLine', + 'ArrowUp', + 'ArrowUp01', + 'ArrowUp10', + 'ArrowUpAZ', + 'ArrowUpAz', + 'ArrowUpCircle', + 'ArrowUpDown', + 'ArrowUpFromDot', + 'ArrowUpFromLine', + 'ArrowUpLeft', + 'ArrowUpLeftFromCircle', + 'ArrowUpLeftFromSquare', + 'ArrowUpLeftSquare', + 'ArrowUpNarrowWide', + 'ArrowUpRight', + 'ArrowUpRightFromCircle', + 'ArrowUpRightFromSquare', + 'ArrowUpRightSquare', + 'ArrowUpSquare', + 'ArrowUpToLine', + 'ArrowUpWideNarrow', + 'ArrowUpZA', + 'ArrowUpZa', + 'ArrowsUpFromLine', + 'Asterisk', + 'AsteriskSquare', + 'AtSign', + 'Atom', + 'AudioLines', + 'AudioWaveform', + 'Award', + 'Axe', + 'Axis3D', + 'Axis3d', + 'Baby', + 'Backpack', + 'Badge', + 'BadgeAlert', + 'BadgeCent', + 'BadgeCheck', + 'BadgeDollarSign', + 'BadgeEuro', + 'BadgeHelp', + 'BadgeIndianRupee', + 'BadgeInfo', + 'BadgeJapaneseYen', + 'BadgeMinus', + 'BadgePercent', + 'BadgePlus', + 'BadgePoundSterling', + 'BadgeQuestionMark', + 'BadgeRussianRuble', + 'BadgeSwissFranc', + 'BadgeTurkishLira', + 'BadgeX', + 'BaggageClaim', + 'Balloon', + 'Ban', + 'Banana', + 'Bandage', + 'Banknote', + 'BanknoteArrowDown', + 'BanknoteArrowUp', + 'BanknoteX', + 'BarChart', + 'BarChart2', + 'BarChart3', + 'BarChart4', + 'BarChartBig', + 'BarChartHorizontal', + 'BarChartHorizontalBig', + 'Barcode', + 'Barrel', + 'Baseline', + 'Bath', + 'Battery', + 'BatteryCharging', + 'BatteryFull', + 'BatteryLow', + 'BatteryMedium', + 'BatteryPlus', + 'BatteryWarning', + 'Beaker', + 'Bean', + 'BeanOff', + 'Bed', + 'BedDouble', + 'BedSingle', + 'Beef', + 'Beer', + 'BeerOff', + 'Bell', + 'BellDot', + 'BellElectric', + 'BellMinus', + 'BellOff', + 'BellPlus', + 'BellRing', + 'BetweenHorizonalEnd', + 'BetweenHorizonalStart', + 'BetweenHorizontalEnd', + 'BetweenHorizontalStart', + 'BetweenVerticalEnd', + 'BetweenVerticalStart', + 'BicepsFlexed', + 'Bike', + 'Binary', + 'Binoculars', + 'Biohazard', + 'Bird', + 'Birdhouse', + 'Bitcoin', + 'Blend', + 'Blinds', + 'Blocks', + 'Bluetooth', + 'BluetoothConnected', + 'BluetoothOff', + 'BluetoothSearching', + 'Bold', + 'Bolt', + 'Bomb', + 'Bone', + 'Book', + 'BookA', + 'BookAlert', + 'BookAudio', + 'BookCheck', + 'BookCopy', + 'BookDashed', + 'BookDown', + 'BookHeadphones', + 'BookHeart', + 'BookImage', + 'BookKey', + 'BookLock', + 'BookMarked', + 'BookMinus', + 'BookOpen', + 'BookOpenCheck', + 'BookOpenText', + 'BookPlus', + 'BookSearch', + 'BookTemplate', + 'BookText', + 'BookType', + 'BookUp', + 'BookUp2', + 'BookUser', + 'BookX', + 'Bookmark', + 'BookmarkCheck', + 'BookmarkMinus', + 'BookmarkPlus', + 'BookmarkX', + 'BoomBox', + 'Bot', + 'BotMessageSquare', + 'BotOff', + 'BottleWine', + 'BowArrow', + 'Box', + 'BoxSelect', + 'Boxes', + 'Braces', + 'Brackets', + 'Brain', + 'BrainCircuit', + 'BrainCog', + 'BrickWall', + 'BrickWallFire', + 'BrickWallShield', + 'Briefcase', + 'BriefcaseBusiness', + 'BriefcaseConveyorBelt', + 'BriefcaseMedical', + 'BringToFront', + 'Brush', + 'BrushCleaning', + 'Bubbles', + 'Bug', + 'BugOff', + 'BugPlay', + 'Building', + 'Building2', + 'Bus', + 'BusFront', + 'Cable', + 'CableCar', + 'Cake', + 'CakeSlice', + 'Calculator', + 'Calendar', + 'Calendar1', + 'CalendarArrowDown', + 'CalendarArrowUp', + 'CalendarCheck', + 'CalendarCheck2', + 'CalendarClock', + 'CalendarCog', + 'CalendarDays', + 'CalendarFold', + 'CalendarHeart', + 'CalendarMinus', + 'CalendarMinus2', + 'CalendarOff', + 'CalendarPlus', + 'CalendarPlus2', + 'CalendarRange', + 'CalendarSearch', + 'CalendarSync', + 'CalendarX', + 'CalendarX2', + 'Calendars', + 'Camera', + 'CameraOff', + 'CandlestickChart', + 'Candy', + 'CandyCane', + 'CandyOff', + 'Cannabis', + 'CannabisOff', + 'Captions', + 'CaptionsOff', + 'Car', + 'CarFront', + 'CarTaxiFront', + 'Caravan', + 'CardSim', + 'Carrot', + 'CaseLower', + 'CaseSensitive', + 'CaseUpper', + 'CassetteTape', + 'Cast', + 'Castle', + 'Cat', + 'Cctv', + 'ChartArea', + 'ChartBar', + 'ChartBarBig', + 'ChartBarDecreasing', + 'ChartBarIncreasing', + 'ChartBarStacked', + 'ChartCandlestick', + 'ChartColumn', + 'ChartColumnBig', + 'ChartColumnDecreasing', + 'ChartColumnIncreasing', + 'ChartColumnStacked', + 'ChartGantt', + 'ChartLine', + 'ChartNetwork', + 'ChartNoAxesColumn', + 'ChartNoAxesColumnDecreasing', + 'ChartNoAxesColumnIncreasing', + 'ChartNoAxesCombined', + 'ChartNoAxesGantt', + 'ChartPie', + 'ChartScatter', + 'ChartSpline', + 'Check', + 'CheckCheck', + 'CheckCircle', + 'CheckCircle2', + 'CheckLine', + 'CheckSquare', + 'CheckSquare2', + 'ChefHat', + 'Cherry', + 'ChessBishop', + 'ChessKing', + 'ChessKnight', + 'ChessPawn', + 'ChessQueen', + 'ChessRook', + 'ChevronDown', + 'ChevronDownCircle', + 'ChevronDownSquare', + 'ChevronFirst', + 'ChevronLast', + 'ChevronLeft', + 'ChevronLeftCircle', + 'ChevronLeftSquare', + 'ChevronRight', + 'ChevronRightCircle', + 'ChevronRightSquare', + 'ChevronUp', + 'ChevronUpCircle', + 'ChevronUpSquare', + 'ChevronsDown', + 'ChevronsDownUp', + 'ChevronsLeft', + 'ChevronsLeftRight', + 'ChevronsLeftRightEllipsis', + 'ChevronsRight', + 'ChevronsRightLeft', + 'ChevronsUp', + 'ChevronsUpDown', + 'Chrome', + 'Chromium', + 'Church', + 'Cigarette', + 'CigaretteOff', + 'Circle', + 'CircleAlert', + 'CircleArrowDown', + 'CircleArrowLeft', + 'CircleArrowOutDownLeft', + 'CircleArrowOutDownRight', + 'CircleArrowOutUpLeft', + 'CircleArrowOutUpRight', + 'CircleArrowRight', + 'CircleArrowUp', + 'CircleCheck', + 'CircleCheckBig', + 'CircleChevronDown', + 'CircleChevronLeft', + 'CircleChevronRight', + 'CircleChevronUp', + 'CircleDashed', + 'CircleDivide', + 'CircleDollarSign', + 'CircleDot', + 'CircleDotDashed', + 'CircleEllipsis', + 'CircleEqual', + 'CircleFadingArrowUp', + 'CircleFadingPlus', + 'CircleGauge', + 'CircleHelp', + 'CircleMinus', + 'CircleOff', + 'CircleParking', + 'CircleParkingOff', + 'CirclePause', + 'CirclePercent', + 'CirclePile', + 'CirclePlay', + 'CirclePlus', + 'CirclePoundSterling', + 'CirclePower', + 'CircleQuestionMark', + 'CircleSlash', + 'CircleSlash2', + 'CircleSlashed', + 'CircleSmall', + 'CircleStar', + 'CircleStop', + 'CircleUser', + 'CircleUserRound', + 'CircleX', + 'CircuitBoard', + 'Citrus', + 'Clapperboard', + 'Clipboard', + 'ClipboardCheck', + 'ClipboardClock', + 'ClipboardCopy', + 'ClipboardEdit', + 'ClipboardList', + 'ClipboardMinus', + 'ClipboardPaste', + 'ClipboardPen', + 'ClipboardPenLine', + 'ClipboardPlus', + 'ClipboardSignature', + 'ClipboardType', + 'ClipboardX', + 'Clock', + 'Clock1', + 'Clock10', + 'Clock11', + 'Clock12', + 'Clock2', + 'Clock3', + 'Clock4', + 'Clock5', + 'Clock6', + 'Clock7', + 'Clock8', + 'Clock9', + 'ClockAlert', + 'ClockArrowDown', + 'ClockArrowUp', + 'ClockCheck', + 'ClockFading', + 'ClockPlus', + 'ClosedCaption', + 'Cloud', + 'CloudAlert', + 'CloudBackup', + 'CloudCheck', + 'CloudCog', + 'CloudDownload', + 'CloudDrizzle', + 'CloudFog', + 'CloudHail', + 'CloudLightning', + 'CloudMoon', + 'CloudMoonRain', + 'CloudOff', + 'CloudRain', + 'CloudRainWind', + 'CloudSnow', + 'CloudSun', + 'CloudSunRain', + 'CloudSync', + 'CloudUpload', + 'Cloudy', + 'Clover', + 'Club', + 'Code', + 'Code2', + 'CodeSquare', + 'CodeXml', + 'Codepen', + 'Codesandbox', + 'Coffee', + 'Cog', + 'Coins', + 'Columns', + 'Columns2', + 'Columns3', + 'Columns3Cog', + 'Columns4', + 'ColumnsSettings', + 'Combine', + 'Command', + 'Compass', + 'Component', + 'Computer', + 'ConciergeBell', + 'Cone', + 'Construction', + 'Contact', + 'Contact2', + 'ContactRound', + 'Container', + 'Contrast', + 'Cookie', + 'CookingPot', + 'Copy', + 'CopyCheck', + 'CopyMinus', + 'CopyPlus', + 'CopySlash', + 'CopyX', + 'Copyleft', + 'Copyright', + 'CornerDownLeft', + 'CornerDownRight', + 'CornerLeftDown', + 'CornerLeftUp', + 'CornerRightDown', + 'CornerRightUp', + 'CornerUpLeft', + 'CornerUpRight', + 'Cpu', + 'CreativeCommons', + 'CreditCard', + 'Croissant', + 'Crop', + 'Cross', + 'Crosshair', + 'Crown', + 'Cuboid', + 'CupSoda', + 'CurlyBraces', + 'Currency', + 'Cylinder', + 'Dam', + 'Database', + 'DatabaseBackup', + 'DatabaseSearch', + 'DatabaseZap', + 'DecimalsArrowLeft', + 'DecimalsArrowRight', + 'Delete', + 'Dessert', + 'Diameter', + 'Diamond', + 'DiamondMinus', + 'DiamondPercent', + 'DiamondPlus', + 'Dice1', + 'Dice2', + 'Dice3', + 'Dice4', + 'Dice5', + 'Dice6', + 'Dices', + 'Diff', + 'Disc', + 'Disc2', + 'Disc3', + 'DiscAlbum', + 'Divide', + 'DivideCircle', + 'DivideSquare', + 'Dna', + 'DnaOff', + 'Dock', + 'Dog', + 'DollarSign', + 'Donut', + 'DoorClosed', + 'DoorClosedLocked', + 'DoorOpen', + 'Dot', + 'DotSquare', + 'Download', + 'DownloadCloud', + 'DraftingCompass', + 'Drama', + 'Dribbble', + 'Drill', + 'Drone', + 'Droplet', + 'DropletOff', + 'Droplets', + 'Drum', + 'Drumstick', + 'Dumbbell', + 'Ear', + 'EarOff', + 'Earth', + 'EarthLock', + 'Eclipse', + 'Edit', + 'Edit2', + 'Edit3', + 'Egg', + 'EggFried', + 'EggOff', + 'Ellipse', + 'Ellipsis', + 'EllipsisVertical', + 'Equal', + 'EqualApproximately', + 'EqualNot', + 'EqualSquare', + 'Eraser', + 'EthernetPort', + 'Euro', + 'EvCharger', + 'Expand', + 'ExternalLink', + 'Eye', + 'EyeClosed', + 'EyeOff', +]; diff --git a/shared/src/book/book-icon-names-f-p.data.ts b/shared/src/book/book-icon-names-f-p.data.ts new file mode 100644 index 000000000..2c0cbaac5 --- /dev/null +++ b/shared/src/book/book-icon-names-f-p.data.ts @@ -0,0 +1,727 @@ +/** + * The lucide drawings the Studio offers, F to P: part of BOOK_ICON_NAMES + * (book-icons.ts). Generated from lucide-react 0.577.0 by + * scripts/gen-book-icon-names.mjs, never edited by hand; the client's + * iconLibrary.test.ts fails when the list and the library it ships drift apart. + */ +export const BOOK_ICON_NAMES_F_P: readonly string[] = [ + 'Facebook', + 'Factory', + 'Fan', + 'FastForward', + 'Feather', + 'Fence', + 'FerrisWheel', + 'Figma', + 'File', + 'FileArchive', + 'FileAudio', + 'FileAudio2', + 'FileAxis3D', + 'FileAxis3d', + 'FileBadge', + 'FileBadge2', + 'FileBarChart', + 'FileBarChart2', + 'FileBox', + 'FileBraces', + 'FileBracesCorner', + 'FileChartColumn', + 'FileChartColumnIncreasing', + 'FileChartLine', + 'FileChartPie', + 'FileCheck', + 'FileCheck2', + 'FileCheckCorner', + 'FileClock', + 'FileCode', + 'FileCode2', + 'FileCodeCorner', + 'FileCog', + 'FileCog2', + 'FileDiff', + 'FileDigit', + 'FileDown', + 'FileEdit', + 'FileExclamationPoint', + 'FileHeadphone', + 'FileHeart', + 'FileImage', + 'FileInput', + 'FileJson', + 'FileJson2', + 'FileKey', + 'FileKey2', + 'FileLineChart', + 'FileLock', + 'FileLock2', + 'FileMinus', + 'FileMinus2', + 'FileMinusCorner', + 'FileMusic', + 'FileOutput', + 'FilePen', + 'FilePenLine', + 'FilePieChart', + 'FilePlay', + 'FilePlus', + 'FilePlus2', + 'FilePlusCorner', + 'FileQuestion', + 'FileQuestionMark', + 'FileScan', + 'FileSearch', + 'FileSearch2', + 'FileSearchCorner', + 'FileSignal', + 'FileSignature', + 'FileSliders', + 'FileSpreadsheet', + 'FileStack', + 'FileSymlink', + 'FileTerminal', + 'FileText', + 'FileType', + 'FileType2', + 'FileTypeCorner', + 'FileUp', + 'FileUser', + 'FileVideo', + 'FileVideo2', + 'FileVideoCamera', + 'FileVolume', + 'FileVolume2', + 'FileWarning', + 'FileX', + 'FileX2', + 'FileXCorner', + 'Files', + 'Film', + 'Filter', + 'FilterX', + 'Fingerprint', + 'FingerprintPattern', + 'FireExtinguisher', + 'Fish', + 'FishOff', + 'FishSymbol', + 'FishingHook', + 'FishingRod', + 'Flag', + 'FlagOff', + 'FlagTriangleLeft', + 'FlagTriangleRight', + 'Flame', + 'FlameKindling', + 'Flashlight', + 'FlashlightOff', + 'FlaskConical', + 'FlaskConicalOff', + 'FlaskRound', + 'FlipHorizontal', + 'FlipHorizontal2', + 'FlipVertical', + 'FlipVertical2', + 'Flower', + 'Flower2', + 'Focus', + 'FoldHorizontal', + 'FoldVertical', + 'Folder', + 'FolderArchive', + 'FolderCheck', + 'FolderClock', + 'FolderClosed', + 'FolderCode', + 'FolderCog', + 'FolderCog2', + 'FolderDot', + 'FolderDown', + 'FolderEdit', + 'FolderGit', + 'FolderGit2', + 'FolderHeart', + 'FolderInput', + 'FolderKanban', + 'FolderKey', + 'FolderLock', + 'FolderMinus', + 'FolderOpen', + 'FolderOpenDot', + 'FolderOutput', + 'FolderPen', + 'FolderPlus', + 'FolderRoot', + 'FolderSearch', + 'FolderSearch2', + 'FolderSymlink', + 'FolderSync', + 'FolderTree', + 'FolderUp', + 'FolderX', + 'Folders', + 'Footprints', + 'ForkKnife', + 'ForkKnifeCrossed', + 'Forklift', + 'Form', + 'FormInput', + 'Forward', + 'Frame', + 'Framer', + 'Frown', + 'Fuel', + 'Fullscreen', + 'FunctionSquare', + 'Funnel', + 'FunnelPlus', + 'FunnelX', + 'GalleryHorizontal', + 'GalleryHorizontalEnd', + 'GalleryThumbnails', + 'GalleryVertical', + 'GalleryVerticalEnd', + 'Gamepad', + 'Gamepad2', + 'GamepadDirectional', + 'GanttChart', + 'GanttChartSquare', + 'Gauge', + 'GaugeCircle', + 'Gavel', + 'Gem', + 'GeorgianLari', + 'Ghost', + 'Gift', + 'GitBranch', + 'GitBranchMinus', + 'GitBranchPlus', + 'GitCommit', + 'GitCommitHorizontal', + 'GitCommitVertical', + 'GitCompare', + 'GitCompareArrows', + 'GitFork', + 'GitGraph', + 'GitMerge', + 'GitMergeConflict', + 'GitPullRequest', + 'GitPullRequestArrow', + 'GitPullRequestClosed', + 'GitPullRequestCreate', + 'GitPullRequestCreateArrow', + 'GitPullRequestDraft', + 'Github', + 'Gitlab', + 'GlassWater', + 'Glasses', + 'Globe', + 'Globe2', + 'GlobeLock', + 'GlobeOff', + 'GlobeX', + 'Goal', + 'Gpu', + 'Grab', + 'GraduationCap', + 'Grape', + 'Grid', + 'Grid2X2', + 'Grid2X2Check', + 'Grid2X2Plus', + 'Grid2X2X', + 'Grid2x2', + 'Grid2x2Check', + 'Grid2x2Plus', + 'Grid2x2X', + 'Grid3X3', + 'Grid3x2', + 'Grid3x3', + 'Grip', + 'GripHorizontal', + 'GripVertical', + 'Group', + 'Guitar', + 'Ham', + 'Hamburger', + 'Hammer', + 'Hand', + 'HandCoins', + 'HandFist', + 'HandGrab', + 'HandHeart', + 'HandHelping', + 'HandMetal', + 'HandPlatter', + 'Handbag', + 'Handshake', + 'HardDrive', + 'HardDriveDownload', + 'HardDriveUpload', + 'HardHat', + 'Hash', + 'HatGlasses', + 'Haze', + 'Hd', + 'HdmiPort', + 'Heading', + 'Heading1', + 'Heading2', + 'Heading3', + 'Heading4', + 'Heading5', + 'Heading6', + 'HeadphoneOff', + 'Headphones', + 'Headset', + 'Heart', + 'HeartCrack', + 'HeartHandshake', + 'HeartMinus', + 'HeartOff', + 'HeartPlus', + 'HeartPulse', + 'Heater', + 'Helicopter', + 'HelpCircle', + 'HelpingHand', + 'Hexagon', + 'Highlighter', + 'History', + 'Home', + 'Hop', + 'HopOff', + 'Hospital', + 'Hotel', + 'Hourglass', + 'House', + 'HouseHeart', + 'HousePlug', + 'HousePlus', + 'HouseWifi', + 'IceCream', + 'IceCream2', + 'IceCreamBowl', + 'IceCreamCone', + 'IdCard', + 'IdCardLanyard', + 'Image', + 'ImageDown', + 'ImageMinus', + 'ImageOff', + 'ImagePlay', + 'ImagePlus', + 'ImageUp', + 'ImageUpscale', + 'Images', + 'Import', + 'Inbox', + 'Indent', + 'IndentDecrease', + 'IndentIncrease', + 'IndianRupee', + 'Infinity', + 'Info', + 'Inspect', + 'InspectionPanel', + 'Instagram', + 'Italic', + 'IterationCcw', + 'IterationCw', + 'JapaneseYen', + 'Joystick', + 'Kanban', + 'KanbanSquare', + 'KanbanSquareDashed', + 'Kayak', + 'Key', + 'KeyRound', + 'KeySquare', + 'Keyboard', + 'KeyboardMusic', + 'KeyboardOff', + 'Lamp', + 'LampCeiling', + 'LampDesk', + 'LampFloor', + 'LampWallDown', + 'LampWallUp', + 'LandPlot', + 'Landmark', + 'Languages', + 'Laptop', + 'Laptop2', + 'LaptopMinimal', + 'LaptopMinimalCheck', + 'Lasso', + 'LassoSelect', + 'Laugh', + 'Layers', + 'Layers2', + 'Layers3', + 'LayersPlus', + 'Layout', + 'LayoutDashboard', + 'LayoutGrid', + 'LayoutList', + 'LayoutPanelLeft', + 'LayoutPanelTop', + 'LayoutTemplate', + 'Leaf', + 'LeafyGreen', + 'Lectern', + 'LensConcave', + 'LensConvex', + 'LetterText', + 'Library', + 'LibraryBig', + 'LibrarySquare', + 'LifeBuoy', + 'Ligature', + 'Lightbulb', + 'LightbulbOff', + 'LineChart', + 'LineDotRightHorizontal', + 'LineSquiggle', + 'Link', + 'Link2', + 'Link2Off', + 'Linkedin', + 'List', + 'ListCheck', + 'ListChecks', + 'ListChevronsDownUp', + 'ListChevronsUpDown', + 'ListCollapse', + 'ListEnd', + 'ListFilter', + 'ListFilterPlus', + 'ListIndentDecrease', + 'ListIndentIncrease', + 'ListMinus', + 'ListMusic', + 'ListOrdered', + 'ListPlus', + 'ListRestart', + 'ListStart', + 'ListTodo', + 'ListTree', + 'ListVideo', + 'ListX', + 'Loader', + 'Loader2', + 'LoaderCircle', + 'LoaderPinwheel', + 'Locate', + 'LocateFixed', + 'LocateOff', + 'LocationEdit', + 'Lock', + 'LockKeyhole', + 'LockKeyholeOpen', + 'LockOpen', + 'LogIn', + 'LogOut', + 'Logs', + 'Lollipop', + 'Luggage', + 'MSquare', + 'Magnet', + 'Mail', + 'MailCheck', + 'MailMinus', + 'MailOpen', + 'MailPlus', + 'MailQuestion', + 'MailQuestionMark', + 'MailSearch', + 'MailWarning', + 'MailX', + 'Mailbox', + 'Mails', + 'Map', + 'MapMinus', + 'MapPin', + 'MapPinCheck', + 'MapPinCheckInside', + 'MapPinHouse', + 'MapPinMinus', + 'MapPinMinusInside', + 'MapPinOff', + 'MapPinPen', + 'MapPinPlus', + 'MapPinPlusInside', + 'MapPinX', + 'MapPinXInside', + 'MapPinned', + 'MapPlus', + 'Mars', + 'MarsStroke', + 'Martini', + 'Maximize', + 'Maximize2', + 'Medal', + 'Megaphone', + 'MegaphoneOff', + 'Meh', + 'MemoryStick', + 'Menu', + 'MenuSquare', + 'Merge', + 'MessageCircle', + 'MessageCircleCheck', + 'MessageCircleCode', + 'MessageCircleDashed', + 'MessageCircleHeart', + 'MessageCircleMore', + 'MessageCircleOff', + 'MessageCirclePlus', + 'MessageCircleQuestion', + 'MessageCircleQuestionMark', + 'MessageCircleReply', + 'MessageCircleWarning', + 'MessageCircleX', + 'MessageSquare', + 'MessageSquareCheck', + 'MessageSquareCode', + 'MessageSquareDashed', + 'MessageSquareDiff', + 'MessageSquareDot', + 'MessageSquareHeart', + 'MessageSquareLock', + 'MessageSquareMore', + 'MessageSquareOff', + 'MessageSquarePlus', + 'MessageSquareQuote', + 'MessageSquareReply', + 'MessageSquareShare', + 'MessageSquareText', + 'MessageSquareWarning', + 'MessageSquareX', + 'MessagesSquare', + 'Metronome', + 'Mic', + 'Mic2', + 'MicOff', + 'MicVocal', + 'Microchip', + 'Microscope', + 'Microwave', + 'Milestone', + 'Milk', + 'MilkOff', + 'Minimize', + 'Minimize2', + 'Minus', + 'MinusCircle', + 'MinusSquare', + 'MirrorRectangular', + 'MirrorRound', + 'Monitor', + 'MonitorCheck', + 'MonitorCloud', + 'MonitorCog', + 'MonitorDot', + 'MonitorDown', + 'MonitorOff', + 'MonitorPause', + 'MonitorPlay', + 'MonitorSmartphone', + 'MonitorSpeaker', + 'MonitorStop', + 'MonitorUp', + 'MonitorX', + 'Moon', + 'MoonStar', + 'MoreHorizontal', + 'MoreVertical', + 'Motorbike', + 'Mountain', + 'MountainSnow', + 'Mouse', + 'MouseLeft', + 'MouseOff', + 'MousePointer', + 'MousePointer2', + 'MousePointer2Off', + 'MousePointerBan', + 'MousePointerClick', + 'MousePointerSquareDashed', + 'MouseRight', + 'Move', + 'Move3D', + 'Move3d', + 'MoveDiagonal', + 'MoveDiagonal2', + 'MoveDown', + 'MoveDownLeft', + 'MoveDownRight', + 'MoveHorizontal', + 'MoveLeft', + 'MoveRight', + 'MoveUp', + 'MoveUpLeft', + 'MoveUpRight', + 'MoveVertical', + 'Music', + 'Music2', + 'Music3', + 'Music4', + 'Navigation', + 'Navigation2', + 'Navigation2Off', + 'NavigationOff', + 'Network', + 'Newspaper', + 'Nfc', + 'NonBinary', + 'Notebook', + 'NotebookPen', + 'NotebookTabs', + 'NotebookText', + 'NotepadText', + 'NotepadTextDashed', + 'Nut', + 'NutOff', + 'Octagon', + 'OctagonAlert', + 'OctagonMinus', + 'OctagonPause', + 'OctagonX', + 'Omega', + 'Option', + 'Orbit', + 'Origami', + 'Outdent', + 'Package', + 'Package2', + 'PackageCheck', + 'PackageMinus', + 'PackageOpen', + 'PackagePlus', + 'PackageSearch', + 'PackageX', + 'PaintBucket', + 'PaintRoller', + 'Paintbrush', + 'Paintbrush2', + 'PaintbrushVertical', + 'Palette', + 'Palmtree', + 'Panda', + 'PanelBottom', + 'PanelBottomClose', + 'PanelBottomDashed', + 'PanelBottomInactive', + 'PanelBottomOpen', + 'PanelLeft', + 'PanelLeftClose', + 'PanelLeftDashed', + 'PanelLeftInactive', + 'PanelLeftOpen', + 'PanelLeftRightDashed', + 'PanelRight', + 'PanelRightClose', + 'PanelRightDashed', + 'PanelRightInactive', + 'PanelRightOpen', + 'PanelTop', + 'PanelTopBottomDashed', + 'PanelTopClose', + 'PanelTopDashed', + 'PanelTopInactive', + 'PanelTopOpen', + 'PanelsLeftBottom', + 'PanelsLeftRight', + 'PanelsRightBottom', + 'PanelsTopBottom', + 'PanelsTopLeft', + 'Paperclip', + 'Parentheses', + 'ParkingCircle', + 'ParkingCircleOff', + 'ParkingMeter', + 'ParkingSquare', + 'ParkingSquareOff', + 'PartyPopper', + 'Pause', + 'PauseCircle', + 'PauseOctagon', + 'PawPrint', + 'PcCase', + 'Pen', + 'PenBox', + 'PenLine', + 'PenOff', + 'PenSquare', + 'PenTool', + 'Pencil', + 'PencilLine', + 'PencilOff', + 'PencilRuler', + 'Pentagon', + 'Percent', + 'PercentCircle', + 'PercentDiamond', + 'PercentSquare', + 'PersonStanding', + 'PhilippinePeso', + 'Phone', + 'PhoneCall', + 'PhoneForwarded', + 'PhoneIncoming', + 'PhoneMissed', + 'PhoneOff', + 'PhoneOutgoing', + 'Pi', + 'PiSquare', + 'Piano', + 'Pickaxe', + 'PictureInPicture', + 'PictureInPicture2', + 'PieChart', + 'PiggyBank', + 'Pilcrow', + 'PilcrowLeft', + 'PilcrowRight', + 'PilcrowSquare', + 'Pill', + 'PillBottle', + 'Pin', + 'PinOff', + 'Pipette', + 'Pizza', + 'Plane', + 'PlaneLanding', + 'PlaneTakeoff', + 'Play', + 'PlayCircle', + 'PlaySquare', + 'Plug', + 'Plug2', + 'PlugZap', + 'PlugZap2', + 'Plus', + 'PlusCircle', + 'PlusSquare', + 'Pocket', + 'PocketKnife', + 'Podcast', + 'Pointer', + 'PointerOff', + 'Popcorn', + 'Popsicle', + 'PoundSterling', + 'Power', + 'PowerCircle', + 'PowerOff', + 'PowerSquare', + 'Presentation', + 'Printer', + 'PrinterCheck', + 'PrinterX', + 'Projector', + 'Proportions', + 'Puzzle', + 'Pyramid', +]; diff --git a/shared/src/book/book-icon-names-q-z.data.ts b/shared/src/book/book-icon-names-q-z.data.ts new file mode 100644 index 000000000..2ee2a2a54 --- /dev/null +++ b/shared/src/book/book-icon-names-q-z.data.ts @@ -0,0 +1,577 @@ +/** + * The lucide drawings the Studio offers, Q to Z: part of BOOK_ICON_NAMES + * (book-icons.ts). Generated from lucide-react 0.577.0 by + * scripts/gen-book-icon-names.mjs, never edited by hand; the client's + * iconLibrary.test.ts fails when the list and the library it ships drift apart. + */ +export const BOOK_ICON_NAMES_Q_Z: readonly string[] = [ + 'QrCode', + 'Quote', + 'Rabbit', + 'Radar', + 'Radiation', + 'Radical', + 'Radio', + 'RadioReceiver', + 'RadioTower', + 'Radius', + 'RailSymbol', + 'Rainbow', + 'Rat', + 'Ratio', + 'Receipt', + 'ReceiptCent', + 'ReceiptEuro', + 'ReceiptIndianRupee', + 'ReceiptJapaneseYen', + 'ReceiptPoundSterling', + 'ReceiptRussianRuble', + 'ReceiptSwissFranc', + 'ReceiptText', + 'ReceiptTurkishLira', + 'RectangleCircle', + 'RectangleEllipsis', + 'RectangleGoggles', + 'RectangleHorizontal', + 'RectangleVertical', + 'Recycle', + 'Redo', + 'Redo2', + 'RedoDot', + 'RefreshCcw', + 'RefreshCcwDot', + 'RefreshCw', + 'RefreshCwOff', + 'Refrigerator', + 'Regex', + 'RemoveFormatting', + 'Repeat', + 'Repeat1', + 'Repeat2', + 'Replace', + 'ReplaceAll', + 'Reply', + 'ReplyAll', + 'Rewind', + 'Ribbon', + 'Rocket', + 'RockingChair', + 'RollerCoaster', + 'Rose', + 'Rotate3D', + 'Rotate3d', + 'RotateCcw', + 'RotateCcwKey', + 'RotateCcwSquare', + 'RotateCw', + 'RotateCwSquare', + 'Route', + 'RouteOff', + 'Router', + 'Rows', + 'Rows2', + 'Rows3', + 'Rows4', + 'Rss', + 'Ruler', + 'RulerDimensionLine', + 'RussianRuble', + 'Sailboat', + 'Salad', + 'Sandwich', + 'Satellite', + 'SatelliteDish', + 'SaudiRiyal', + 'Save', + 'SaveAll', + 'SaveOff', + 'Scale', + 'Scale3D', + 'Scale3d', + 'Scaling', + 'Scan', + 'ScanBarcode', + 'ScanEye', + 'ScanFace', + 'ScanHeart', + 'ScanLine', + 'ScanQrCode', + 'ScanSearch', + 'ScanText', + 'ScatterChart', + 'School', + 'School2', + 'Scissors', + 'ScissorsLineDashed', + 'ScissorsSquare', + 'ScissorsSquareDashedBottom', + 'Scooter', + 'ScreenShare', + 'ScreenShareOff', + 'Scroll', + 'ScrollText', + 'Search', + 'SearchAlert', + 'SearchCheck', + 'SearchCode', + 'SearchSlash', + 'SearchX', + 'Section', + 'Send', + 'SendHorizonal', + 'SendHorizontal', + 'SendToBack', + 'SeparatorHorizontal', + 'SeparatorVertical', + 'Server', + 'ServerCog', + 'ServerCrash', + 'ServerOff', + 'Settings', + 'Settings2', + 'Shapes', + 'Share', + 'Share2', + 'Sheet', + 'Shell', + 'ShelvingUnit', + 'Shield', + 'ShieldAlert', + 'ShieldBan', + 'ShieldCheck', + 'ShieldClose', + 'ShieldEllipsis', + 'ShieldHalf', + 'ShieldMinus', + 'ShieldOff', + 'ShieldPlus', + 'ShieldQuestion', + 'ShieldQuestionMark', + 'ShieldUser', + 'ShieldX', + 'Ship', + 'ShipWheel', + 'Shirt', + 'ShoppingBag', + 'ShoppingBasket', + 'ShoppingCart', + 'Shovel', + 'ShowerHead', + 'Shredder', + 'Shrimp', + 'Shrink', + 'Shrub', + 'Shuffle', + 'Sidebar', + 'SidebarClose', + 'SidebarOpen', + 'Sigma', + 'SigmaSquare', + 'Signal', + 'SignalHigh', + 'SignalLow', + 'SignalMedium', + 'SignalZero', + 'Signature', + 'Signpost', + 'SignpostBig', + 'Siren', + 'SkipBack', + 'SkipForward', + 'Skull', + 'Slack', + 'Slash', + 'SlashSquare', + 'Slice', + 'Sliders', + 'SlidersHorizontal', + 'SlidersVertical', + 'Smartphone', + 'SmartphoneCharging', + 'SmartphoneNfc', + 'Smile', + 'SmilePlus', + 'Snail', + 'Snowflake', + 'SoapDispenserDroplet', + 'Sofa', + 'SolarPanel', + 'SortAsc', + 'SortDesc', + 'Soup', + 'Space', + 'Spade', + 'Sparkle', + 'Sparkles', + 'Speaker', + 'Speech', + 'SpellCheck', + 'SpellCheck2', + 'Spline', + 'SplinePointer', + 'Split', + 'SplitSquareHorizontal', + 'SplitSquareVertical', + 'Spool', + 'Spotlight', + 'SprayCan', + 'Sprout', + 'Square', + 'SquareActivity', + 'SquareArrowDown', + 'SquareArrowDownLeft', + 'SquareArrowDownRight', + 'SquareArrowLeft', + 'SquareArrowOutDownLeft', + 'SquareArrowOutDownRight', + 'SquareArrowOutUpLeft', + 'SquareArrowOutUpRight', + 'SquareArrowRight', + 'SquareArrowRightEnter', + 'SquareArrowRightExit', + 'SquareArrowUp', + 'SquareArrowUpLeft', + 'SquareArrowUpRight', + 'SquareAsterisk', + 'SquareBottomDashedScissors', + 'SquareCenterlineDashedHorizontal', + 'SquareCenterlineDashedVertical', + 'SquareChartGantt', + 'SquareCheck', + 'SquareCheckBig', + 'SquareChevronDown', + 'SquareChevronLeft', + 'SquareChevronRight', + 'SquareChevronUp', + 'SquareCode', + 'SquareDashed', + 'SquareDashedBottom', + 'SquareDashedBottomCode', + 'SquareDashedKanban', + 'SquareDashedMousePointer', + 'SquareDashedTopSolid', + 'SquareDivide', + 'SquareDot', + 'SquareEqual', + 'SquareFunction', + 'SquareGanttChart', + 'SquareKanban', + 'SquareLibrary', + 'SquareM', + 'SquareMenu', + 'SquareMinus', + 'SquareMousePointer', + 'SquareParking', + 'SquareParkingOff', + 'SquarePause', + 'SquarePen', + 'SquarePercent', + 'SquarePi', + 'SquarePilcrow', + 'SquarePlay', + 'SquarePlus', + 'SquarePower', + 'SquareRadical', + 'SquareRoundCorner', + 'SquareScissors', + 'SquareSigma', + 'SquareSlash', + 'SquareSplitHorizontal', + 'SquareSplitVertical', + 'SquareSquare', + 'SquareStack', + 'SquareStar', + 'SquareStop', + 'SquareTerminal', + 'SquareUser', + 'SquareUserRound', + 'SquareX', + 'SquaresExclude', + 'SquaresIntersect', + 'SquaresSubtract', + 'SquaresUnite', + 'Squircle', + 'SquircleDashed', + 'Squirrel', + 'Stamp', + 'Star', + 'StarHalf', + 'StarOff', + 'Stars', + 'StepBack', + 'StepForward', + 'Stethoscope', + 'Sticker', + 'StickyNote', + 'Stone', + 'StopCircle', + 'Store', + 'StretchHorizontal', + 'StretchVertical', + 'Strikethrough', + 'Subscript', + 'Subtitles', + 'Sun', + 'SunDim', + 'SunMedium', + 'SunMoon', + 'SunSnow', + 'Sunrise', + 'Sunset', + 'Superscript', + 'SwatchBook', + 'SwissFranc', + 'SwitchCamera', + 'Sword', + 'Swords', + 'Syringe', + 'Table', + 'Table2', + 'TableCellsMerge', + 'TableCellsSplit', + 'TableColumnsSplit', + 'TableConfig', + 'TableOfContents', + 'TableProperties', + 'TableRowsSplit', + 'Tablet', + 'TabletSmartphone', + 'Tablets', + 'Tag', + 'Tags', + 'Tally1', + 'Tally2', + 'Tally3', + 'Tally4', + 'Tally5', + 'Tangent', + 'Target', + 'Telescope', + 'Tent', + 'TentTree', + 'Terminal', + 'TerminalSquare', + 'TestTube', + 'TestTube2', + 'TestTubeDiagonal', + 'TestTubes', + 'Text', + 'TextAlignCenter', + 'TextAlignEnd', + 'TextAlignJustify', + 'TextAlignStart', + 'TextCursor', + 'TextCursorInput', + 'TextInitial', + 'TextQuote', + 'TextSearch', + 'TextSelect', + 'TextSelection', + 'TextWrap', + 'Theater', + 'Thermometer', + 'ThermometerSnowflake', + 'ThermometerSun', + 'ThumbsDown', + 'ThumbsUp', + 'Ticket', + 'TicketCheck', + 'TicketMinus', + 'TicketPercent', + 'TicketPlus', + 'TicketSlash', + 'TicketX', + 'Tickets', + 'TicketsPlane', + 'Timer', + 'TimerOff', + 'TimerReset', + 'ToggleLeft', + 'ToggleRight', + 'Toilet', + 'ToolCase', + 'Toolbox', + 'Tornado', + 'Torus', + 'Touchpad', + 'TouchpadOff', + 'TowelRack', + 'TowerControl', + 'ToyBrick', + 'Tractor', + 'TrafficCone', + 'Train', + 'TrainFront', + 'TrainFrontTunnel', + 'TrainTrack', + 'TramFront', + 'Transgender', + 'Trash', + 'Trash2', + 'TreeDeciduous', + 'TreePalm', + 'TreePine', + 'Trees', + 'Trello', + 'TrendingDown', + 'TrendingUp', + 'TrendingUpDown', + 'Triangle', + 'TriangleAlert', + 'TriangleDashed', + 'TriangleRight', + 'Trophy', + 'Truck', + 'TruckElectric', + 'TurkishLira', + 'Turntable', + 'Turtle', + 'Tv', + 'Tv2', + 'TvMinimal', + 'TvMinimalPlay', + 'Twitch', + 'Twitter', + 'Type', + 'TypeOutline', + 'Umbrella', + 'UmbrellaOff', + 'Underline', + 'Undo', + 'Undo2', + 'UndoDot', + 'UnfoldHorizontal', + 'UnfoldVertical', + 'Ungroup', + 'University', + 'Unlink', + 'Unlink2', + 'Unlock', + 'UnlockKeyhole', + 'Unplug', + 'Upload', + 'UploadCloud', + 'Usb', + 'User', + 'User2', + 'UserCheck', + 'UserCheck2', + 'UserCircle', + 'UserCircle2', + 'UserCog', + 'UserCog2', + 'UserKey', + 'UserLock', + 'UserMinus', + 'UserMinus2', + 'UserPen', + 'UserPlus', + 'UserPlus2', + 'UserRound', + 'UserRoundCheck', + 'UserRoundCog', + 'UserRoundKey', + 'UserRoundMinus', + 'UserRoundPen', + 'UserRoundPlus', + 'UserRoundSearch', + 'UserRoundX', + 'UserSearch', + 'UserSquare', + 'UserSquare2', + 'UserStar', + 'UserX', + 'UserX2', + 'Users', + 'Users2', + 'UsersRound', + 'Utensils', + 'UtensilsCrossed', + 'UtilityPole', + 'Van', + 'Variable', + 'Vault', + 'VectorSquare', + 'Vegan', + 'VenetianMask', + 'Venus', + 'VenusAndMars', + 'Verified', + 'Vibrate', + 'VibrateOff', + 'Video', + 'VideoOff', + 'Videotape', + 'View', + 'Voicemail', + 'Volleyball', + 'Volume', + 'Volume1', + 'Volume2', + 'VolumeOff', + 'VolumeX', + 'Vote', + 'Wallet', + 'Wallet2', + 'WalletCards', + 'WalletMinimal', + 'Wallpaper', + 'Wand', + 'Wand2', + 'WandSparkles', + 'Warehouse', + 'WashingMachine', + 'Watch', + 'Waves', + 'WavesArrowDown', + 'WavesArrowUp', + 'WavesLadder', + 'Waypoints', + 'Webcam', + 'Webhook', + 'WebhookOff', + 'Weight', + 'WeightTilde', + 'Wheat', + 'WheatOff', + 'WholeWord', + 'Wifi', + 'WifiCog', + 'WifiHigh', + 'WifiLow', + 'WifiOff', + 'WifiPen', + 'WifiSync', + 'WifiZero', + 'Wind', + 'WindArrowDown', + 'Wine', + 'WineOff', + 'Workflow', + 'Worm', + 'WrapText', + 'Wrench', + 'X', + 'XCircle', + 'XLineTop', + 'XOctagon', + 'XSquare', + 'Youtube', + 'Zap', + 'ZapOff', + 'ZodiacAquarius', + 'ZodiacAries', + 'ZodiacCancer', + 'ZodiacCapricorn', + 'ZodiacGemini', + 'ZodiacLeo', + 'ZodiacLibra', + 'ZodiacOphiuchus', + 'ZodiacPisces', + 'ZodiacSagittarius', + 'ZodiacScorpio', + 'ZodiacTaurus', + 'ZodiacVirgo', + 'ZoomIn', + 'ZoomOut', +]; diff --git a/shared/src/book/book-icons.ts b/shared/src/book/book-icons.ts index 4b1dde916..8ff4669ce 100644 --- a/shared/src/book/book-icons.ts +++ b/shared/src/book/book-icons.ts @@ -1,12 +1,33 @@ +import { BOOK_ICON_NAMES_A_E } from './book-icon-names-a-e.data'; +import { BOOK_ICON_NAMES_F_P } from './book-icon-names-f-p.data'; +import { BOOK_ICON_NAMES_Q_Z } from './book-icon-names-q-z.data'; + /** - * The drawings the assistant may put on a page, by their lucide names. + * Every drawing the Studio's icon tab offers, by its lucide name: the + * library as the client ships it, its old names included, the way the tab + * lists them (client/src/components/Studio/iconLibrary.ts). The book engine + * takes a new icon by any of these names, so the assistant may place every + * drawing a person could pick by hand. * - * The Studio's icon tab opens on this shelf (client/src/components/Studio/iconLibrary.ts - * filters it against the lucide version it ships), and the book engine takes a - * new icon only from it: an icon element stores a free name the renderer - * resolves, and a model that names a drawing lucide does not have would place - * the fallback glyph. A curated list keeps the assistant to drawings that exist - * and that a travel page actually reaches for. + * A set of names rather than the enum the contract usually spells: the page + * edit's tool schema carries no `$ref`, and some two thousand names written + * into it three times over would take it far past its size ceiling. The names + * are checked against this set instead, which refuses exactly what an enum + * would. A client test holds the set to the lucide version the client runs, + * so an icon is never named here that would draw as the fallback glyph. + */ +export const BOOK_ICON_NAMES: ReadonlySet = new Set([ + ...BOOK_ICON_NAMES_A_E, + ...BOOK_ICON_NAMES_F_P, + ...BOOK_ICON_NAMES_Q_Z, +]); + +/** + * The shelf the Studio's icon tab opens on, by lucide name: the drawings a + * travel page reaches for first, in the order somebody would look for them + * (iconLibrary.ts filters it against the lucide version it ships). The tool + * schema names a few of them as examples, so a model starts from a drawing + * that belongs on a travel page rather than from the alphabet. */ export const BOOK_DESIGN_ICONS = [ 'Plane', diff --git a/shared/src/book/book-op-enums.spec.ts b/shared/src/book/book-op-enums.spec.ts new file mode 100644 index 000000000..a88321d9e --- /dev/null +++ b/shared/src/book/book-op-enums.spec.ts @@ -0,0 +1,62 @@ +import { BOOK_DESIGN_ICONS, BOOK_ICON_NAMES } from './book-icons'; +import * as described from './book-op-enums'; +import { bookPageOpSchema } from './book-ops.schema'; +import { BOOK_FONTS_IDS, BOOK_SHAPES, bookPhotoElementSchema } from './book.schema'; +import { bookDesignDirectivesSchema } from './design/design-directives.schema'; + +import { describe, expect, it } from 'vitest'; +import { z } from 'zod'; + +// BKENUM-001 to BKENUM-004 + +/** + * The enums the book tools show a model: each says what its values mean, the + * values stay the document's own, and an icon is any drawing of the Studio's + * icon tab, refused by name exactly as an enum would refuse it. + */ + +const schemas = Object.entries(described as Record).filter( + (entry): entry is [string, z.ZodType] => entry[1] instanceof z.ZodType, +); + +describe('the described enums', () => { + it('BKENUM-001: say what their values mean in one line each, without dashes', () => { + expect(schemas.length).toBeGreaterThan(20); + for (const [name, schema] of schemas) { + const text = schema.description ?? ''; + expect(text.length, name).toBeGreaterThan(10); + expect(text, name).not.toMatch(/[\u2013\u2014\n]/); + } + expect(described.BOOK_BINDING_HINT).not.toMatch(/[\u2013\u2014\n]/); + }); + + it('BKENUM-002: keep the values of the document they describe', () => { + expect(described.bookFontIdSchema.options).toEqual([...BOOK_FONTS_IDS]); + expect(described.bookShapeIdSchema.options).toEqual([...BOOK_SHAPES]); + const frameStyles = bookPhotoElementSchema.shape.frameStyle.unwrap().options; + expect(described.bookFrameStyleSchema.options).toEqual(frameStyles); + for (const font of BOOK_FONTS_IDS) expect(String(described.bookFontIdSchema.description)).toContain(font); + }); + + it('BKENUM-003: carry their meaning into the page edit and the design directives a model reads', () => { + const page = JSON.stringify(z.toJSONSchema(bookPageOpSchema, { io: 'input' })); + for (const line of [described.bookFontIdSchema, described.bookShapeIdSchema, described.bookFrameStyleSchema]) { + expect(page).toContain(String(line.description)); + } + const design = JSON.stringify(z.toJSONSchema(bookDesignDirectivesSchema, { io: 'input' })); + expect(design).toContain('Photos per spread: airy 1 to 2'); + expect(design).toContain(String(described.bookFontIdSchema.description)); + }); +}); + +describe('the icon names', () => { + it('BKENUM-004: take every drawing of the icon tab, the travel shelf and old names among them, and nothing else', () => { + expect(BOOK_ICON_NAMES.size).toBeGreaterThan(1500); + for (const name of [...BOOK_DESIGN_ICONS, 'Pizza', 'AlertTriangle', 'ZoomOut']) { + expect(described.bookIconNameSchema.safeParse(name).success, name).toBe(true); + } + for (const name of ['NotAnIcon', 'PizzaIcon', 'LucidePizza', 'Icon', 'pizza', '']) { + expect(described.bookIconNameSchema.safeParse(name).success, name).toBe(false); + } + }); +}); diff --git a/shared/src/book/book-op-enums.ts b/shared/src/book/book-op-enums.ts new file mode 100644 index 000000000..48f19c628 --- /dev/null +++ b/shared/src/book/book-op-enums.ts @@ -0,0 +1,141 @@ +import { BOOK_ICON_NAMES } from './book-icons'; +import { + BOOK_BADGES, + BOOK_FONTS_IDS, + BOOK_METRICS, + BOOK_SHAPES, + bookBadgeElementSchema, + bookCountriesElementSchema, + bookListElementSchema, + bookMapElementSchema, + bookPageSetupSchema, + bookPhotoElementSchema, + bookShapeElementSchema, + bookStatsElementSchema, + bookTextElementSchema, +} from './book.schema'; + +import { z } from 'zod'; + +/** + * The enums a model reads in the book tools, each with one line on what its + * values mean. + * + * A JSON schema that lists bare ids leaves the model to guess what `bebas` + * sets or what a `seal` draws, and a guess at a typeface is a page set in the + * wrong one. The values stay those of the document's own schema; only the + * description is added, which changes nothing a parse accepts. + * + * Short on purpose. The tool schemas carry no `$ref`, so a description is + * repeated wherever its field appears, and the page edit's schema is held + * under a size ceiling (MCP-SCHEMA-004 on the server). Where a field repeats + * on every travel element, a shorter line points back at the full one. + */ + +const photo = bookPhotoElementSchema.shape; +const text = bookTextElementSchema.shape; +const shape = bookShapeElementSchema.shape; +const map = bookMapElementSchema.shape; + +/** The book's typefaces, with the face each id sets. */ +export const bookFontIdSchema = z + .enum(BOOK_FONTS_IDS) + .describe( + 'Typeface: sans Poppins, inter Inter, serif Lora, garamond EB Garamond, playfair Playfair Display, display MuseoModerno, bebas Bebas Neue (caps, one weight).', + ); +/** The typeface of a travel element, where the full line above would repeat ten times. */ +export const bookTypesetFontSchema = z.enum(BOOK_FONTS_IDS).describe('Typeface id, as for text.'); + +/** Every shape the Studio draws, and so every mask a photo can be cut to. */ +export const bookShapeIdSchema = z + .enum(BOOK_SHAPES) + .describe( + 'A filled outline: rect, ellipse, line (a rule), polygons, arch and circle parts, stars, burst, seal, sparkle, arrows, chevrons, speech bubbles, nature and travel motifs, blobs and banners.', + ); + +export const bookPhotoFitSchema = photo.fit + .unwrap() + .describe('cover fills the frame, cropped at the focal point; contain shows all of it.'); +export const bookPhotoMaskSchema = photo.mask + .unwrap() + .describe('A shape id to cut the photo to; null is the plain rectangle.'); +export const bookFrameStyleSchema = photo.frameStyle + .unwrap() + .describe('polaroid (deep bottom border), white border, shadow, film or tape around it; none is a plain print.'); +export const bookPhotoFilterSchema = photo.filter + .unwrap() + .describe('bw (black and white), warm, cool, fade (lifted blacks) or contrast; none as shot.'); + +export const bookTextAlignSchema = text.align.unwrap().describe('How the lines sit in the frame.'); + +export const bookShapeGradientSchema = shape.gradient + .unwrap() + .describe('Fade the fill out: up is solid at the top, down solid at the bottom; none is one flat fill.'); +export const bookStrokeStyleSchema = shape.strokeStyle.unwrap().describe('A solid, dashed or dotted outline or rule.'); + +export const bookMapStyleSchema = map.style + .unwrap() + .describe('The map look: minimal, outline, dark (for a dark page) or paper.'); +export const bookRouteStyleSchema = map.routeStyle + .unwrap() + .describe('plain is one stroke; drawn is a light line over a dark casing, as in an atlas.'); +export const bookRouteArcSchema = map.routeArc + .unwrap() + .describe('bow draws the long legs as a curve, the way a flight is shown.'); +export const bookRouteDashSchema = map.routeDash.unwrap().describe('arcs dashes the bowed legs; solid dashes nothing.'); +export const bookPinStyleSchema = map.pinStyle.unwrap().describe('A stop as a dot, or as a small round photo of it.'); +export const bookMapClipSchema = map.clip + .unwrap() + .describe('rect is a map in a box; country cuts it to the outline of its countries.'); +/** Where a new map's ground comes from. */ +export const bookMapSourceSchema = z + .enum(['vector', 'relief', 'satellite']) + .describe('vector outlines print sharp at any size; relief and satellite are imagery from the map provider.'); + +export const bookStatsLayoutSchema = bookStatsElementSchema.shape.layout + .unwrap() + .describe('The figures in a grid, one row or one column.'); +export const bookCountriesLayoutSchema = bookCountriesElementSchema.shape.layout + .unwrap() + .describe('The countries as a list, a grid or one column.'); +export const bookBadgeStyleSchema = bookBadgeElementSchema.shape.style + .unwrap() + .describe('plain words, a chip (filled capsule), an outline, or stacked over its line.'); +export const bookBadgeVariantSchema = z + .enum(BOOK_BADGES) + .describe( + 'What the mark shows: a flag, a date, a day counter, coordinates, a country, a distance, weather, altitude or mood.', + ); +export const bookListLayoutSchema = bookListElementSchema.shape.layout + .unwrap() + .describe('columns sets pros beside cons; stacked sets one column with the marks inline.'); +export const bookMetricSchema = z + .enum(BOOK_METRICS) + .describe( + 'A travel figure: distance, days, steps (journal entries), photos, countries, places or furthest from the start.', + ); + +/** The page sizes a book is set up in. */ +export const bookPagePresetSchema = bookPageSetupSchema.shape.preset + .unwrap() + .describe( + 'The page: square-210 or square-300 (mm), a4-landscape, a4-portrait, a5-landscape; custom keeps its own size.', + ); + +/** + * Any drawing the Studio's icon tab offers, by its lucide name. Checked + * against the set rather than listed, for the size of the schema; refused + * exactly as an enum would refuse a name it does not hold. + */ +export const bookIconNameSchema = z + .string() + .regex(/^[A-Z][A-Za-z0-9]*$/, 'expected a lucide icon name') + .max(60) + .refine((name) => BOOK_ICON_NAMES.has(name), { message: 'not a lucide icon the Studio offers' }) + .describe( + 'A lucide icon name in PascalCase, any the Studio offers: Plane, Compass, MapPin, MountainSnow, Waves, Sun, Camera, Heart, Landmark, Croissant and the rest of lucide.', + ); + +/** What a text's binding means: where its words come from, and what each source needs beside it. */ +export const BOOK_BINDING_HINT = + 'Words read from the journey and kept in sync: journey.title or journey.subtitle; entry.title, entry.story, entry.location (format dms or decimal for coordinates) or entry.date with entryId; photo.caption with photoId.'; diff --git a/shared/src/book/book-op-ids.ts b/shared/src/book/book-op-ids.ts index c428920c6..8bf5ddfb8 100644 --- a/shared/src/book/book-op-ids.ts +++ b/shared/src/book/book-op-ids.ts @@ -14,4 +14,8 @@ export const bookElementIdSchema = z.string().regex(/^[\w-]{1,40}$/); const gridIds = BOOK_GRIDS.map((g) => g.id) as [string, ...string[]]; /** The photo grids, by id. */ -export const bookGridIdSchema = z.enum(gridIds); +export const bookGridIdSchema = z + .enum(gridIds) + .describe( + 'A photo grid by id, named for its cells (two-across, grid-6, hero-three, cols-2-1, filmstrip); its frames come empty.', + ); diff --git a/shared/src/book/book-ops.schema.ts b/shared/src/book/book-ops.schema.ts index 235e77aa6..96ceb6a5b 100644 --- a/shared/src/book/book-ops.schema.ts +++ b/shared/src/book/book-ops.schema.ts @@ -1,6 +1,15 @@ import { idSchema } from '../common/primitives.schema'; import { BOOK_ELEMENT_OP_SCHEMAS, TEXT_STYLE_FIELDS, bindingNamesItsSource } from './book-element-ops.schema'; import { BOOK_COVER_TEMPLATES, BOOK_TEMPLATES } from './book-layouts'; +import { + BOOK_BINDING_HINT, + bookFontIdSchema, + bookFrameStyleSchema, + bookPagePresetSchema, + bookPhotoFilterSchema, + bookPhotoFitSchema, + bookPhotoMaskSchema, +} from './book-op-enums'; import { bookElementIdSchema, bookGridIdSchema, bookSpreadIdSchema } from './book-op-ids'; import { MAX_BOOK_TITLE, @@ -9,7 +18,6 @@ import { bookLayoutSchema, bookPageNumbersSchema, bookPageSetupSchema, - bookPhotoElementSchema, bookSpreadSchema, bookTextElementSchema, } from './book.schema'; @@ -52,13 +60,18 @@ export const BOOK_OP_LIMITS = { const idsOf = (list: readonly { id: string }[]) => list.map((t) => t.id) as [string, ...string[]]; /** The spread layouts, by id. */ -export const bookTemplateIdSchema = z.enum(idsOf(BOOK_TEMPLATES)); +export const bookTemplateIdSchema = z + .enum(idsOf(BOOK_TEMPLATES)) + .describe('A built-in double page layout by id; list_book_layouts says what each one holds.'); /** The single-page (cover and back) layouts, by id. */ -export const bookCoverTemplateIdSchema = z.enum(idsOf(BOOK_COVER_TEMPLATES)); +export const bookCoverTemplateIdSchema = z + .enum(idsOf(BOOK_COVER_TEMPLATES)) + .describe('A built-in cover or back layout by id; list_book_layouts says what each one holds.'); /** Either set: which one fits is the page's question, answered when the operation runs. */ -export const bookAnyTemplateIdSchema = z.enum([...idsOf(BOOK_TEMPLATES), ...idsOf(BOOK_COVER_TEMPLATES)]); +export const bookAnyTemplateIdSchema = z + .enum([...idsOf(BOOK_TEMPLATES), ...idsOf(BOOK_COVER_TEMPLATES)]) + .describe('A built-in layout by id: the cover-* ones fit a single page, the rest a double page.'); -const photo = bookPhotoElementSchema.shape; const text = bookTextElementSchema.shape; /** A position in millimetres, inside the bounds the document takes. */ @@ -107,7 +120,7 @@ export const bookPageOpSchema = z.discriminatedUnion('op', [ }), z.literal('new'), ]), - fit: photo.fit.unwrap().optional(), + fit: bookPhotoFitSchema.optional(), focalX: unit01.optional(), focalY: unit01.optional(), }), @@ -116,12 +129,12 @@ export const bookPageOpSchema = z.discriminatedUnion('op', [ .strictObject({ op: z.literal('photo_look'), elementId: bookElementIdSchema, - fit: photo.fit.unwrap().optional(), + fit: bookPhotoFitSchema.optional(), focalX: unit01.optional(), focalY: unit01.optional(), - mask: photo.mask.unwrap().optional(), - frameStyle: photo.frameStyle.unwrap().optional(), - filter: photo.filter.unwrap().optional(), + mask: bookPhotoMaskSchema.optional(), + frameStyle: bookFrameStyleSchema.optional(), + filter: bookPhotoFilterSchema.optional(), radius: z.number().finite().min(0).max(500).optional(), }) .refine((v) => has(v, LOOK_KEYS), { message: 'name at least one of the look fields' }), @@ -138,9 +151,12 @@ export const bookPageOpSchema = z.discriminatedUnion('op', [ .strictObject({ op: z.literal('text'), elementId: bookElementIdSchema.optional(), - role: z.enum(['heading', 'body', 'meta']).optional(), + role: z + .enum(['heading', 'body', 'meta']) + .describe('heading is the largest type on the page, body the longest of the rest, meta the next.') + .optional(), text: z.string().max(BOOK_OP_LIMITS.text).optional(), - binding: text.binding.unwrap().optional(), + binding: text.binding.unwrap().describe(`${BOOK_BINDING_HINT} Null unbinds.`).optional(), ...TEXT_STYLE_FIELDS, }) .refine((v) => v.elementId !== undefined || v.role !== undefined, { message: 'name an elementId or a role' }) @@ -227,7 +243,7 @@ export const setBookCoverArgs = { }; export const createBookArgs = { title: z.string().max(MAX_BOOK_TITLE).optional(), - preset: bookPageSetupSchema.shape.preset.unwrap().optional(), + preset: bookPagePresetSchema.optional(), }; /** * A page as it was before a write, for the assistant's undo: `index` is where @@ -276,14 +292,21 @@ export const restoreBookPageArgs = { export const bookDesignIdSchema = z.string().regex(/^[\w-]{1,40}$/); export const describeBookPageArgs = { spreadId: bookSpreadIdSchema, designId: bookDesignIdSchema.optional() }; -export const listBookLayoutsArgs = { role: z.enum(['inner', 'single']).optional() }; +export const listBookLayoutsArgs = { + role: z.enum(['inner', 'single']).describe('inner for double pages, single for the cover and back.').optional(), +}; export const suggestBookPhotosArgs = { entryId: idSchema.optional(), date: z .string() .regex(/^\d{4}-\d{2}-\d{2}$/) .optional(), - purpose: z.enum(['page', 'cover']).optional(), + purpose: z + .enum(['page', 'cover']) + .describe( + 'cover prefers wide or square pictures with enough pixels for a whole cover (2400 px on the long edge); page is for an inner page.', + ) + .optional(), limit: z.number().int().min(1).max(PHOTO_PICK.maxLimit).optional(), }; @@ -295,7 +318,7 @@ const pageNumbers = bookPageNumbersSchema.shape; * answer carries `previous_setup` to set it back. */ export const setBookSetupArgs = { - preset: bookPageSetupSchema.shape.preset.unwrap().optional(), + preset: bookPagePresetSchema.optional(), pageWidth: z.number().finite().min(60).max(500).optional(), pageHeight: z.number().finite().min(60).max(500).optional(), bleed: z.number().finite().min(0).max(20).optional(), @@ -304,12 +327,15 @@ export const setBookSetupArgs = { .strictObject({ show: pageNumbers.show.unwrap().optional(), startAt: pageNumbers.startAt.unwrap().optional(), - position: pageNumbers.position.unwrap().optional(), + position: pageNumbers.position + .unwrap() + .describe('outer edge, inner edge by the fold, or centre of the foot.') + .optional(), margin: z.number().finite().min(0).max(60).optional(), size: pageNumbers.size.unwrap().optional(), autoColor: pageNumbers.autoColor.unwrap().optional(), color: pageNumbers.color.unwrap().optional(), - font: pageNumbers.font.unwrap().optional(), + font: bookFontIdSchema.optional(), }) .optional(), /** The assistant's undo sets the setup back only while the book is still at the version the change left. */ diff --git a/shared/src/book/describe-spread.spec.ts b/shared/src/book/describe-spread.spec.ts index 420ee43ef..a18ddbaec 100644 --- a/shared/src/book/describe-spread.spec.ts +++ b/shared/src/book/describe-spread.spec.ts @@ -188,6 +188,82 @@ describe('findings', () => { expect(codes(list)).not.toContain('severe:overlap'); }); + it('BOOKDESC-025: takes photos laid over each other at an angle, or in a frame, as layered on purpose', () => { + const under = photo('p-a', 1, { x: 230, y: 20, w: 80, h: 60 }); + const over = { x: 260, y: 40, w: 80, h: 60 }; + for (const look of [{ rotation: 4 }, { rotation: -3 }, { rotation: 357 }, { frameStyle: 'polaroid' as const }]) { + const list = findings([under, photo('p-b', 1, over, look)]); + expect( + list.find((f) => f.code === 'overlap'), + JSON.stringify(look), + ).toMatchObject({ + severity: 'info', + elementIds: ['p-a', 'p-b'], + }); + } + // A frame on the lower picture does not make the upper one look laid down. + const framedUnder = photo('p-a', 1, { x: 230, y: 20, w: 80, h: 60 }, { frameStyle: 'white' }); + expect(codes(findings([framedUnder, photo('p-b', 1, over)]))).toContain('severe:overlap'); + // Framed as the journal style frames every photo, but four fifths covered: an accident all the same. + const stacked = photo('p-b', 1, { x: 238, y: 26, w: 80, h: 60 }, { frameStyle: 'white', rotation: 4 }); + expect(codes(findings([photo('p-a', 1, { x: 230, y: 20, w: 80, h: 60 }), stacked]))).toContain('severe:overlap'); + }); + + it('BOOKDESC-026: keeps an accident severe: two straight photos of a size, under 3 degrees off, a full turn included', () => { + const under = photo('p-a', 1, { x: 230, y: 20, w: 80, h: 60 }, { rotation: 1.5 }); + // 2 degrees is the scrapbook style's own tilt, so it does not make a pair layered on its own. + for (const rotation of [0, -1, 2, -2.5, 359, 720]) { + const list = findings([under, photo('p-b', 1, { x: 260, y: 40, w: 80, h: 60 }, { rotation })]); + expect(codes(list), String(rotation)).toContain('severe:overlap'); + } + }); + + it('BOOKDESC-027: sets a small line over display type as context, over running text or a text of a size as a fault', () => { + const title = text('t-big', 'Lisbon', { x: 230, y: 40, w: 160, h: 60 }, { size: 60 }); + const accent = text('t-over', 'travel', { x: 240, y: 70, w: 40, h: 12 }); + expect(findings([title, accent]).find((f) => f.code === 'overlap')).toMatchObject({ + severity: 'info', + elementIds: ['t-over', 't-big'], + }); + // The same small line on a story block prints words over words. + const story = text('t-story', 'A long day on the ice, and the harbour after it. '.repeat(3).trim(), { + x: 230, + y: 40, + w: 160, + h: 60, + }); + expect(findings([story, accent]).find((f) => f.code === 'overlap')).toMatchObject({ severity: 'severe' }); + const twin = text('t-twin', 'Porto', { x: 240, y: 60, w: 160, h: 60 }); + expect(codes(findings([title, twin]))).toContain('severe:overlap'); + const tilted = text('t-tilt', 'Porto', { x: 310, y: 90, w: 80, h: 30 }, { rotation: -6 }); + expect(codes(findings([title, tilted]))).toContain('info:overlap'); + }); + + it('BOOKDESC-028: never compares a title over a photo, or a photo over a shape', () => { + const shape = bookShapeElementSchema.parse({ + id: 's-block', + kind: 'shape', + frame: { x: 220, y: 10, w: 120, h: 90 }, + }); + const list = findings([ + shape as BookElement, + photo('p-a', 1, { x: 230, y: 20, w: 80, h: 60 }), + text('t-a', 'Over it', { x: 235, y: 30, w: 70, h: 20 }), + ]); + expect(list.filter((f) => f.code === 'overlap')).toEqual([]); + }); + + it('BOOKDESC-029: reports an accident on a busy layered page, however many insets come before it', () => { + const hero = photo('p-hero', 1, { x: 230, y: 20, w: 180, h: 170 }); + const insets = Array.from({ length: 8 }, (_, i) => + photo(`p-in-${i}`, 1, { x: 235 + (i % 4) * 42, y: 30 + Math.floor(i / 4) * 40, w: 20, h: 15 }), + ); + const pair = [photo('p-a', 1, { x: 20, y: 20, w: 80, h: 60 }), photo('p-b', 1, { x: 50, y: 40, w: 80, h: 60 })]; + const overlaps = findings([hero, ...insets, ...pair]).filter((f) => f.code === 'overlap'); + expect(overlaps).toHaveLength(6); + expect(overlaps.find((f) => f.severity === 'severe')?.elementIds).toEqual(['p-a', 'p-b']); + }); + it('BOOKDESC-013: puts severe first and stops at the cap', () => { // 45 texts past the trim, each too small for its words: 90 severe findings before the cap. const many = Array.from({ length: 45 }, (_, i) => text(`t-${i}`, 'Cut', { x: -10, y: 5 + i * 4, w: 40, h: 3 })); diff --git a/shared/src/book/design/design-book.spec.ts b/shared/src/book/design/design-book.spec.ts index 03843d8c7..fa676b363 100644 --- a/shared/src/book/design/design-book.spec.ts +++ b/shared/src/book/design/design-book.spec.ts @@ -8,6 +8,7 @@ import { MAX_SPREADS, MAX_SPREAD_ELEMENTS, bookDocumentSchema, + bookPhotoElementSchema, bookTextElementSchema, type BookDocument, type BookElement, @@ -761,6 +762,33 @@ describe('design_book', () => { const more = { ...cut, text: `${cut.text} A long day on the ice.` }; expect(textHeightNeeded(more, DESIGN_TEXT_HEADROOM)).toBeGreaterThan(frame.h); }); + + it('BOOKDSN-031: pulls two photos apart that lie mostly on top of each other, framed as the journal style frames them', () => { + const page = input('rich').page; + const look = designLook(bookDesignDirectivesSchema.parse({ style: 'journal' }), page, []); + const framed = (id: string, x: number, y: number) => + bookPhotoElementSchema.parse({ + id, + kind: 'photo', + frame: { x, y, w: 80, h: 60 }, + photoId: 1, + frameStyle: 'white', + }); + const spread: BookSpread = { + id: 'sp-in', + role: 'inner', + background: '#ffffff', + elements: [framed('p-a', 230, 20), framed('p-b', 238, 26)], + parked: [], + entryId: null, + }; + const photos = [{ photoId: 1, width: 4000, height: 3000 }]; + expect(pageFindings(spread, page, photos).map((f) => `${f.severity}:${f.code}`)).toContain('severe:overlap'); + let n = 0; + const fixed = repairSpread(spread, { page, photos, look, newId: (p) => `${p}-${++n}` }); + expect(fixed.findings.filter((f) => f.code === 'overlap')).toEqual([]); + expect(fixed.spread.elements.find((e) => e.id === 'p-b')?.frame.y).toBe(82); + }); }); /** Photos of one shape, ids counted from `from`. */ diff --git a/shared/src/book/design/design-compose.ts b/shared/src/book/design/design-compose.ts index 35319089f..b42e77485 100644 --- a/shared/src/book/design/design-compose.ts +++ b/shared/src/book/design/design-compose.ts @@ -180,7 +180,10 @@ export function textEl(c: ComposeCtx, at: TextAt, words: string, role: TextRole, return { ...el, frame: frameOf(at.x, at.y, at.w, textHeightNeeded(el, DESIGN_TEXT_HEADROOM) + 1.2) }; } -/** A heading that fits `maxH`: set smaller, down to the sub size, until it does. */ +/** + * A heading that fits `maxH`: set at `opts.size` (the heading size when none + * is given), then smaller, down to the sub size, until it does. + */ export function headingEl( c: ComposeCtx, at: TextAt, @@ -188,7 +191,7 @@ export function headingEl( maxH: number, opts: TextOpts = {}, ): BookTextElement { - let size = c.look.sizes.heading; + let size = opts.size ?? c.look.sizes.heading; let el = textEl(c, at, words, 'heading', { ...opts, size }); while (el.frame.h > maxH && size > c.look.sizes.sub) { size = Math.max(c.look.sizes.sub, size - 2); diff --git a/shared/src/book/design/design-directives.schema.ts b/shared/src/book/design/design-directives.schema.ts index 90b438002..62543dcd1 100644 --- a/shared/src/book/design/design-directives.schema.ts +++ b/shared/src/book/design/design-directives.schema.ts @@ -1,6 +1,7 @@ import { idSchema } from '../../common/primitives.schema'; +import { bookFontIdSchema, bookMetricSchema, bookPagePresetSchema } from '../book-op-enums'; import { bookCoverTemplateIdSchema } from '../book-ops.schema'; -import { BOOK_FONTS_IDS, BOOK_METRICS, MAX_BOOK_TITLE, bookPageSetupSchema } from '../book.schema'; +import { MAX_BOOK_TITLE } from '../book.schema'; import { z } from 'zod'; @@ -21,17 +22,31 @@ export const BOOK_DESIGN_STYLES = ['classic', 'minimal', 'editorial', 'journal', export type BookDesignStyle = (typeof BOOK_DESIGN_STYLES)[number]; export const bookDesignDirectivesSchema = z.strictObject({ - style: z.enum(BOOK_DESIGN_STYLES).default('classic'), + style: z + .enum(BOOK_DESIGN_STYLES) + .describe( + 'The look: classic (white, sans, one warm accent), minimal (white, Inter, grey), editorial (cream, Playfair over Garamond), journal (warm paper, framed photos), bold (black paper, Bebas caps, strong accent), scrapbook (cream paper, MuseoModerno headings, polaroids turned a little).', + ) + .default('classic'), /** Photos per spread: airy 1 to 2, balanced 2 to 4, rich 4 to 6. */ - density: z.enum(['airy', 'balanced', 'rich']).default('balanced'), + density: z + .enum(['airy', 'balanced', 'rich']) + .describe('Photos per spread: airy 1 to 2, balanced 2 to 4, rich 4 to 6.') + .default('balanced'), /** Inner spreads, the covers and the first and last page not counted. */ pages: z.strictObject({ min: pageCount.optional(), max: pageCount.optional() }).optional(), scope: z.strictObject({ entryIds: ids200.optional(), from: isoDate.optional(), to: isoDate.optional() }).optional(), - chapters: z.enum(['entry', 'day', 'place']).default('entry'), + chapters: z + .enum(['entry', 'day', 'place']) + .describe('What a chapter is: one journal entry, one day or one place.') + .default('entry'), photos: z .strictObject({ /** best: the photo-pick groups' best, near duplicates and blurry ones left out; all: every photo. */ - pick: z.enum(['best', 'all']).default('best'), + pick: z + .enum(['best', 'all']) + .describe('best leaves out near duplicates and blurry shots; all takes every photo.') + .default('best'), perChapterMax: z.number().int().min(1).max(24).optional(), include: ids300.optional(), exclude: ids300.optional(), @@ -47,17 +62,51 @@ export const bookDesignDirectivesSchema = z.strictObject({ .optional(), type: z .strictObject({ - heading: z.enum(BOOK_FONTS_IDS).optional(), - body: z.enum(BOOK_FONTS_IDS).optional(), - scale: z.number().min(0.8).max(1.3).optional(), + heading: bookFontIdSchema.optional(), + body: bookFontIdSchema.optional(), + /** Every type size at once, 1 the style's own: under 1 a quieter book, up to 2.5 a poster. */ + scale: z + .number() + .min(0.8) + .max(2.5) + .describe('Every type size at once: 1 as the style sets it, 2.5 a poster.') + .optional(), + /** + * The cover title as a multiple of the heading size, on top of `scale`: + * 1, the default, sets it as every book so far was set; 6.5 takes the + * 28 pt heading to about 180 pt, a title that fills the cover, so the + * cover grows without the rest of the book. Words that would not fit + * the cover are set smaller. + */ + display: z + .number() + .min(1) + .max(6.5) + .describe( + 'The cover title as a multiple of the heading size: 1 as before, up to 6.5 (about 180 pt) for a title that fills the cover.', + ) + .optional(), }) .optional(), /** The book's colours: taken from the photos, ink only, or given; the style's own when absent. */ - palette: z.union([z.enum(['from_photos', 'ink']), z.strictObject({ paper: hex, ink: hex, accent: hex })]).optional(), + palette: z + .union([ + z + .enum(['from_photos', 'ink']) + .describe('from_photos takes the accent from the pictures; ink sets every colour in the ink.'), + z.strictObject({ paper: hex, ink: hex, accent: hex }), + ]) + .optional(), text: z .strictObject({ - captions: z.enum(['none', 'entry', 'photo']).default('entry'), - story: z.enum(['full', 'excerpt', 'none']).default('full'), + captions: z + .enum(['none', 'entry', 'photo']) + .describe('Words under the pictures: none, the entry title, or each photo caption.') + .default('entry'), + story: z + .enum(['full', 'excerpt', 'none']) + .describe('The entry story in full, cut to excerptChars, or left out.') + .default('full'), excerptChars: z.number().int().min(80).max(1200).optional(), }) .optional(), @@ -67,13 +116,16 @@ export const bookDesignDirectivesSchema = z.strictObject({ countries: z.boolean().default(true), chapterMaps: z.boolean().default(false), dayBadges: z.boolean().default(true), - metrics: z.array(z.enum(BOOK_METRICS)).min(1).max(7).optional(), + metrics: z.array(bookMetricSchema).min(1).max(7).optional(), }) .optional(), /** What stays: pages holding a locked element, also hand-made pages, or nothing (a fresh book). */ - keep: z.enum(['nothing', 'locked', 'edited']).default('locked'), + keep: z + .enum(['nothing', 'locked', 'edited']) + .describe('What stays: nothing, pages holding a locked element, or also the pages made by hand.') + .default('locked'), /** Only honoured for a blank or a new book. */ - preset: bookPageSetupSchema.shape.preset.unwrap().optional(), + preset: bookPagePresetSchema.optional(), seed: z.number().int().min(0).max(2147483647).optional(), }); export type BookDesignDirectives = z.infer; diff --git a/shared/src/book/design/design-framing.ts b/shared/src/book/design/design-framing.ts index 50a2670de..eb1131654 100644 --- a/shared/src/book/design/design-framing.ts +++ b/shared/src/book/design/design-framing.ts @@ -48,7 +48,11 @@ interface CoverWords { ownSubtitle?: string; } -/** The cover: a photo to the bleed with the title on a scrim at its foot, or the title alone on the paper. */ +/** + * The cover: a photo to the bleed with the title on a scrim at its foot, or + * the title alone on the paper. The title starts at the display size and is + * set smaller only as far as its box needs. + */ export function composeCover(c: ComposeCtx, words: CoverWords, photo: AutoPhoto | null): BookSpread { const { pageWidth: PW, pageHeight: H, bleed: b, margin: m } = c.grid; const els: BookElement[] = []; @@ -64,7 +68,8 @@ export function composeCover(c: ComposeCtx, words: CoverWords, photo: AutoPhoto const y = photo ? box.y : box.y + box.h * 0.35; if (title.words.trim()) { const binding = title.bound ? { source: 'journey.title' as const } : null; - const head = headingEl(c, { x: box.x, y, w: box.w }, title.words, box.h * 0.6, { binding, color: colour }); + const size = c.look.sizes.display; + const head = headingEl(c, { x: box.x, y, w: box.w }, title.words, box.h * 0.6, { binding, color: colour, size }); els.push(head); if (sub.words.trim()) { const subBinding = sub.bound ? { source: 'journey.subtitle' as const } : null; diff --git a/shared/src/book/design/design-style.spec.ts b/shared/src/book/design/design-style.spec.ts new file mode 100644 index 000000000..2e62d41e1 --- /dev/null +++ b/shared/src/book/design/design-style.spec.ts @@ -0,0 +1,79 @@ +import { bookPageSetupSchema, type BookDocument, type BookTextElement } from '../book.schema'; +import { designBook, type BookDesignInput } from './design-book'; +import { bookDesignDirectivesSchema, type BookDesignDirectivesInput } from './design-directives.schema'; +import { designLook } from './design-style'; + +import { readFileSync } from 'node:fs'; +import { fileURLToPath } from 'node:url'; +import { describe, expect, it } from 'vitest'; + +// BOOKSTY-001 to BOOKSTY-004 + +/** + * The type scale of a designed book: `type.scale` reaches a poster's sizes, + * the cover title has a display tier of its own, and a book designed without + * either is set exactly as before. + */ + +const page = bookPageSetupSchema.parse({ preset: 'square-210', pageWidth: 210, pageHeight: 210 }); +const lookOf = (directives: BookDesignDirectivesInput, on = page) => + designLook(bookDesignDirectivesSchema.parse(directives), on, []); + +const here = (file: string) => fileURLToPath(new URL(file, import.meta.url)); +const fixtures = JSON.parse(readFileSync(here('./design-book.fixtures.json'), 'utf8')) as { + rich: { input: BookDesignInput }; +}; + +/** The rich fixture journey, its ids minted by a counter so every run designs the same book. */ +function rich(): BookDesignInput { + let n = 0; + return { ...fixtures.rich.input, newId: (p) => `${p}-${++n}` }; +} + +/** The cover's title: the text bound to the journey's title. */ +function coverTitle(doc: BookDocument): BookTextElement | undefined { + const cover = doc.spreads.find((s) => s.role === 'cover'); + return cover?.elements.find((e): e is BookTextElement => e.kind === 'text' && e.binding?.source === 'journey.title'); +} + +describe('the type scale', () => { + it('BOOKSTY-001: sets the cover title at the heading size when nothing asks for more, as before', () => { + const look = lookOf({ style: 'classic' }); + expect(look.sizes).toEqual({ display: 28, heading: 28, sub: 14, body: 10, caption: 7.5, meta: 7 }); + expect(lookOf({ style: 'classic', type: { scale: 1.3 } }).sizes.heading).toBe(36.4); + }); + + it('BOOKSTY-002: takes a scale up to 2.5 and a display tier up to 6.5, and nothing past either', () => { + const parse = (type: Record) => bookDesignDirectivesSchema.safeParse({ type }).success; + expect([parse({ scale: 2.5 }), parse({ scale: 2.6 }), parse({ scale: 0.7 })]).toEqual([true, false, false]); + expect([parse({ display: 6.5 }), parse({ display: 6.6 }), parse({ display: 0.9 })]).toEqual([true, false, false]); + const poster = lookOf({ style: 'bold', type: { scale: 2.5, display: 2 } }); + expect([poster.sizes.heading, poster.sizes.display, poster.sizes.body]).toEqual([70, 140, 25]); + // The cover tier alone carries a cover-filling title: body stays where the style sets it. + const cover = lookOf({ style: 'bold', type: { display: 6.5 } }); + expect([cover.sizes.heading, cover.sizes.display, cover.sizes.body]).toEqual([28, 182, 10]); + }); + + it('BOOKSTY-003: never sets a size past what a text element takes, on the largest page either', () => { + const large = bookPageSetupSchema.parse({ preset: 'custom', pageWidth: 500, pageHeight: 500 }); + const look = lookOf({ style: 'bold', type: { scale: 2.5, display: 3 } }, large); + expect(look.sizes.display).toBe(200); + expect(Math.max(...Object.values(look.sizes))).toBeLessThanOrEqual(200); + }); +}); + +describe('the cover title', () => { + it('BOOKSTY-004: starts at the display size and comes out larger than the heading, still inside its box', () => { + const plain = coverTitle(designBook(null, rich(), { style: 'classic' }).doc); + const big = coverTitle(designBook(null, rich(), { style: 'classic', type: { display: 3 } }).doc); + expect(plain?.size).toBe(28); + expect(big?.size ?? 0).toBeGreaterThan(plain?.size ?? 0); + expect(big?.size ?? 0).toBeLessThanOrEqual(84); + const largest = coverTitle(designBook(null, rich(), { style: 'classic', type: { display: 6.5 } }).doc); + expect(largest?.size ?? 0).toBeGreaterThanOrEqual(big?.size ?? 0); + expect(largest?.size ?? 0).toBeLessThanOrEqual(182); + expect((largest?.frame.y ?? 0) + (largest?.frame.h ?? 0)).toBeLessThanOrEqual(page.pageHeight); + // The box under the title is the foot of the cover, below its 60 % line. + expect((big?.frame.y ?? 0) + (big?.frame.h ?? 0)).toBeLessThanOrEqual(page.pageHeight); + }); +}); diff --git a/shared/src/book/design/design-style.ts b/shared/src/book/design/design-style.ts index 82cb3073b..f3000d155 100644 --- a/shared/src/book/design/design-style.ts +++ b/shared/src/book/design/design-style.ts @@ -9,9 +9,12 @@ import type { BookDesignDirectives, BookDesignStyle } from './design-directives. * * At most two families per book; badges, figures, maps and lists take the * heading face. Sizes are set for a 210 mm page and scale with the page - * width, times `type.scale`, never under what a reader can read. Every - * colour a text is set in is checked against the paper to WCAG contrast; - * a pair that fails falls back to the ink. + * width, times `type.scale`, never under what a reader can read and never + * over what a text element takes. The cover title has a tier of its own, + * `display`, the heading size times `type.display`: 1 by default, so a book + * designed without it is set exactly as before, and up to 6.5 for a title + * that fills the cover. Every colour a text is set in is checked against the paper + * to WCAG contrast; a pair that fails falls back to the ink. */ export interface BookDesignLook { @@ -28,7 +31,8 @@ export interface BookDesignLook { onScrim: string; heading: BookFontFamily; body: BookFontFamily; - sizes: { heading: number; sub: number; body: number; caption: number; meta: number }; + /** Points. `display` is the cover title's, the heading's unless `type.display` raises it. */ + sizes: { display: number; heading: number; sub: number; body: number; caption: number; meta: number }; /** The frame decoration and the slight turn a scrapbook gives its pictures. */ frameStyle: BookPhotoElement['frameStyle']; tilt: number; @@ -114,6 +118,8 @@ const PRESETS: Record = { const BASE_SIZES = { heading: 28, sub: 14, body: 10, caption: 7.5, meta: 7 }; /** Never under these: running text reads from 7 pt, a caption or meta line from 5.5 pt (with room to spare). */ const FLOOR = { heading: 14, sub: 9, body: 8, caption: 7, meta: 6 }; +/** Never over this: the largest size a text element takes (book.schema.ts). */ +const MAX_PT = 200; const round1 = (v: number) => Math.round(v * 10) / 10; @@ -163,7 +169,8 @@ export function designLook( const softer = mix(ink, colours.paper, 0.3); const muted = contrastRatio(softer, colours.paper) >= 4.6 ? softer : ink; const scale = (page.pageWidth / 210) * (directives.type?.scale ?? 1); - const size = (role: keyof typeof BASE_SIZES) => Math.max(FLOOR[role], round1(BASE_SIZES[role] * scale)); + const size = (role: keyof typeof BASE_SIZES, times = 1) => + Math.min(MAX_PT, Math.max(FLOOR[role], round1(BASE_SIZES[role] * scale * times))); const heading = directives.type?.heading ?? preset.heading; return { style: directives.style, @@ -177,6 +184,7 @@ export function designLook( heading, body: directives.type?.body ?? preset.body, sizes: { + display: size('heading', directives.type?.display ?? 1), heading: size('heading'), sub: size('sub'), body: size('body'), diff --git a/sonar-project.properties b/sonar-project.properties index a7b8a9d27..80071150f 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -71,7 +71,10 @@ sonar.coverage.exclusions=\ # server/src/db/kysely/ is generated from the migrated schema by # server/scripts/generate-db-types.ts (one interface per table, CI checks it with # check:db-types), so a column list two tables share is not copied code. -sonar.cpd.exclusions=shared/src/i18n/**,server/src/db/kysely/** +# shared/src/book/book-icon-names-*.data.ts is the lucide name list the book +# engine takes, generated by shared/scripts/gen-book-icon-names.mjs: three +# files of one quoted name per line, data rather than code. +sonar.cpd.exclusions=shared/src/i18n/**,server/src/db/kysely/**,shared/src/book/book-icon-names-*.data.ts # The full analysis of a push to dev outgrows the JS/TS analyser's default heap # of about 4 GB since the ORM migration and stops with "Analysis of JS/TS files