mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 05:26:47 +00:00
eae8480728
* feat(studio): widen the document, and stop a save from losing it The schema gains what the elements coming after it need: an icon element, a badge that can be restyled rather than only placed, a date and a pair of coordinates on a text binding, and the map's route, pin and road settings. Widening it turned up two ways a book could fail to come back. The mood badge writes its code into the document, and the schema said that code was exactly two characters, from a first draft where it was a country. The real codes are words, so every save was rejected and the read that followed parsed to an empty document: seventeen spreads in, nothing out. Widened to what the badge actually writes, and normalizeBookDocument now drops the elements it cannot read rather than the whole book, so one bad element costs a picture frame instead of a year of work. The other was the body limit. The parser allowed 100kb for everything, and a book with a routed map measures past that, so the save came back 413 and the editor sat on "not saved" with no way forward. Book writes get their own parser at 8mb; everything else keeps the limit it had. * feat(studio): a date, a pair of coordinates and an icon library Three things that had to be drawn by hand before. A journal entry knows when it happened and where, and neither could be put on a page: you read the date off the entry and typed it into a text box, where it then stayed while the entry moved. Both are chips now, next to the title and the story, and both follow their entry the way the others do. The formatting lives in one place so the chip, the template and the resolver cannot drift by a character — coordinates in degrees or decimals, the date in the reader's language. The icons are the whole Lucide set, searchable, placed as a real element with its own colour and stroke rather than as a character in a font. The stroke is deliberately not called strokeWidth: three separate places rescale a field of that name by page width, and an icon whose line thins as the book grows is not what anyone asked for. And the badges finally have their settings. A mood or weather badge could be placed and then only moved: the icon's colour was fixed, the icon could not be turned off, and there was no way to keep the icon and drop the words. All three are switches now, with the colour following the badge unless you say otherwise. * fix(studio): let a placed entry field follow its journal entry again The inspector says a bound field follows the journal entry and that editing it here breaks the link. The first half was not true: nothing ever re-read the entry, so renaming a title in Journey left the old words on the page for good, and the same went for every other bound field. The resolver runs where the journey is loaded and re-reads the fields that still point at an entry. What it will not do is as important as what it does. A field somebody has typed over stays typed over, an entry that is gone leaves its element alone rather than blanking it, and an entry that answers with nothing never wipes what is already on the page. Formatted fields — the date, the coordinates — are only re-read when the format itself changed, which is what keeps this from quietly rewriting books that already exist: an entry whose date was placed as a heading and then set in capitals keeps its capitals. Checked against the real database before it shipped, where the first version overwrote three of them. * feat(studio): start a new book empty, with six layouts to choose from A new journey opened onto a book that had already been laid out, which is the wrong first move: it decides the shape of somebody's book before they have seen it, and undoing it means deleting pages one at a time. A new book starts empty now, and the auto layout runs when it is asked to. The layouts themselves went from two to six, so choosing one is a real choice: what was there covered a photo-heavy spread and a text-heavy one and nothing in between. * fix(studio): hyphenate the export the way the editor does, and set the bleed Two things the press sees and the editor did not. A paragraph broke in different places in the PDF than on screen. The print document is written from scratch and never carried a language, so the browser hyphenated the editor's German and the export's nothing-in- particular. It takes the page's own language now. The wait for the sheet to be ready also covers the images inside SVG, with a ceiling, so a map that is slow to draw does not print half-finished. And the bleed and the safe margin are typeable. Both were baked into every page preset at what a photo-book vendor usually asks for, 3mm and 5mm, with no control anywhere. That is fine until a printer asks for 5 and 10, at which point the book cannot be made here at all: the export carries the wrong bleed and the crop marks sit in the wrong place, which nobody finds until the guillotine has run. * feat(studio): rebuild the inspector The panel on the right had grown by accretion: every element type had added its own controls in whatever shape suited it that day, so the same idea — a colour, a size, a toggle — looked different depending on what you had selected, and long panels were a wall of unlabelled fields. It is one set of controls now, used by every element: foldable sections, a line that holds a label and its control, radio choices, checkboxes, the app's own toggle, and a number field that holds a draft so typing "500" is not read as "5", clamped and written back under the cursor. Duplicated controls were merged rather than deleted; nothing an element could do before it cannot do now. The head carries the element's identity and its actions, so what you have selected is readable without counting fields, and the sections have room to breathe: what was there was correct and unreadable. * feat(studio): a route map worth printing The map in a book was a straight grey line between grey dots on a tile that was chosen for a screen. At print size those tiles are read at roughly four times the resolution they were fetched for, which is why it looked soft next to everything around it. The imagery comes from sources that hold up on paper: NASA's shaded relief and EOX's cloudless Sentinel-2, both licensed for it, picked at a zoom that matches the printer rather than the screen. Tiles are fetched at twice the density where the source offers it, and the seam between them scales with the tile instead of sitting at a fixed fraction of a millimetre, which under editor zoom fell below one device pixel and showed as white threads. The route is drawn rather than plotted. A leg that was never recorded bows, by an amount that grows with its length and turns away from the pole, and it dashes, because an inferred line should not claim to be a track — a recorded track never bows. Both strokes are laid down in two passes, casing then core, so the line stays legible over dark sea and bright desert alike. Legs can follow roads instead, routed leg by leg with the geometry thinned before it is stored, which is the setting a road trip wants and the one a flight cannot have. Stops carry their own first photograph, cut to a circle by a stencil that exists — the first one was written into a defs block that only appears on a map clipped to a coastline, so on an ordinary map it clipped nothing and the photographs sat square on the page. A stop with no photograph of its own is numbered rather than handed one from elsewhere in the journey: a marker at one place showing a picture taken at another is a caption that lies. Whatever the frame, the whole route is inside it. The window takes the frame's aspect, so the fit and the imagery agree instead of one containing what the other covers, and a map dragged narrow no longer cuts off its end. Each linked trip can carry its own map, and a map notices a photograph added to a stop afterwards rather than having to be placed again. * i18n(journey): the new Studio strings, in all 23 locales * test(journey): pin the coverage the map work brought with it The journey domain measures higher than its floor after this round, so the floor follows it up. Only journey moved; the generator's suggestion would have taken memories' functions down a point, and a ratchet that can fall is not a ratchet. * test(studio): cover the thinning that keeps a road route saveable The one path in roadRoute nothing exercised, and the one that matters most: a router answers a long drive with thousands of points at a precision no press can resolve, and all of it goes into the document. Keeping a leg whole is what pushed a real book past the body limit. Both ends have to survive so the line still meets its stops, and the spacing has to stay even, because cutting a run out of the middle would straighten exactly the bends somebody wanted to see.
211 lines
9.0 KiB
TypeScript
211 lines
9.0 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import type { BookElement, BookPageSetup, BookSpread } from '@trek/shared'
|
|
import { bookBadgeElementSchema, bookPageSetupSchema, normalizeBookDocument } from '@trek/shared'
|
|
import { render } from '../../helpers/render'
|
|
import { SpreadView } from '../../../src/components/Studio/SpreadView'
|
|
|
|
/**
|
|
* The picture on a mood or weather mark (#1973).
|
|
*
|
|
* These are the only marks whose drawing comes from the journal rather than from
|
|
* the book, and the field that says which mood it is used to be capped at two
|
|
* characters, from back when nothing but a country code went in it. A mark
|
|
* reading "amazing" therefore failed the contract, which failed its spread,
|
|
* which failed the document, and what the editor handed back was an empty book.
|
|
* The first thing kept here is that a mood key survives a round trip with the
|
|
* book still around it.
|
|
*
|
|
* The rest is the controls built on the widened field: whether the mark draws
|
|
* its picture, whether it draws its words, and what colour the picture is. The
|
|
* default reading is the one that matters most. Every book written before these
|
|
* fields existed carries none of them, and every element the panels build is
|
|
* cast rather than parsed, so the renderer has to read an absent flag as what it
|
|
* always meant: draw it.
|
|
*/
|
|
|
|
const page: BookPageSetup = bookPageSetupSchema.parse({
|
|
preset: 'square-210', pageWidth: 210, pageHeight: 210, bleed: 3, safe: 5,
|
|
})
|
|
|
|
const typeset = {
|
|
font: 'sans' as const, color: '#1a1a1a', accent: '#c2410c', textScale: 1, weight: 700, stale: false,
|
|
}
|
|
const common = { rotation: 0, opacity: 1, locked: false, frame: { x: 10, y: 20, w: 90, h: 40 } }
|
|
|
|
/**
|
|
* A badge built the way the panels build one: cast, not parsed, so nothing the
|
|
* contract would default is filled in unless a test fills it. That is also what
|
|
* a mark out of a book written before the icon fields existed looks like, which
|
|
* is why the absent case below is worth a test at all.
|
|
*/
|
|
const badge = (over: Record<string, unknown>): BookElement => ({
|
|
...common, ...typeset, id: 'b1', kind: 'badge',
|
|
variant: 'mood', text: '', sub: '', code: null, style: 'plain', ...over,
|
|
} as unknown as BookElement)
|
|
|
|
function draw(elements: BookElement[]) {
|
|
const spread: BookSpread = {
|
|
id: 's1', role: 'inner', background: null, elements, parked: [], entryId: null,
|
|
}
|
|
return render(<SpreadView spread={spread} page={page} />)
|
|
}
|
|
|
|
/** A document around a single mark, as it arrives from storage. */
|
|
function documentAround(el: Record<string, unknown>, title = 'Iceland') {
|
|
return {
|
|
version: 1,
|
|
title,
|
|
page: { preset: 'square-210', pageWidth: 210, pageHeight: 210, bleed: 3, safe: 5 },
|
|
spreads: [{
|
|
id: 's1', role: 'inner', entryId: null, background: null, parked: [],
|
|
elements: [
|
|
{ id: 'p1', kind: 'photo', frame: { x: 0, y: 0, w: 50, h: 50 }, photoId: 3 },
|
|
el,
|
|
],
|
|
}],
|
|
}
|
|
}
|
|
|
|
describe('a mark made before the icon controls existed', () => {
|
|
it('still draws its icon in the mood palette the journal uses', () => {
|
|
const { container } = draw([badge({ variant: 'mood', code: 'amazing', text: 'Amazing' })])
|
|
const icon = container.querySelector('svg')
|
|
expect(icon).not.toBeNull()
|
|
// The pink of "amazing" on the journey page, not the element's accent.
|
|
expect(icon!.getAttribute('stroke')).toBe('#BE185D')
|
|
})
|
|
|
|
it('still draws its words and the line under them', () => {
|
|
const { container } = draw([badge({
|
|
variant: 'mood', code: 'amazing', text: 'Amazing', sub: 'Reykjavik',
|
|
})])
|
|
expect(container.textContent).toContain('Amazing')
|
|
expect(container.textContent).toContain('Reykjavik')
|
|
})
|
|
|
|
/*
|
|
* A parsed badge carries the default of `iconColor` whether or not anybody
|
|
* chose it, so reading the colour on its own rather than the flag beside it
|
|
* would repaint every mood mark in the field to a flat near-black.
|
|
*/
|
|
it('ignores the icon colour while Automatic is still on', () => {
|
|
const { container } = draw([badge({
|
|
variant: 'mood', code: 'amazing', text: 'Amazing',
|
|
autoIconColor: true, iconColor: '#111111',
|
|
})])
|
|
expect(container.querySelector('svg')!.getAttribute('stroke')).toBe('#BE185D')
|
|
})
|
|
})
|
|
|
|
describe('choosing the icon colour', () => {
|
|
/*
|
|
* Asserted on the stroke because that is where it has to land: lucide takes
|
|
* its colour as a prop and writes it onto the SVG, so `currentColor` from the
|
|
* wrapper never reaches it, which is why the swatch used to look dead.
|
|
*/
|
|
it('paints a mood icon that colour instead of the journal palette', () => {
|
|
const { container } = draw([badge({
|
|
variant: 'mood', code: 'amazing', text: 'Amazing',
|
|
autoIconColor: false, iconColor: '#0EA5E9',
|
|
})])
|
|
expect(container.querySelector('svg')!.getAttribute('stroke')).toBe('#0EA5E9')
|
|
})
|
|
|
|
it('paints a weather icon that colour instead of the element accent', () => {
|
|
const { container } = draw([badge({
|
|
variant: 'weather', code: 'partly', text: 'Partly cloudy',
|
|
autoIconColor: false, iconColor: '#0EA5E9',
|
|
})])
|
|
expect(container.querySelector('svg')!.getAttribute('stroke')).toBe('#0EA5E9')
|
|
})
|
|
|
|
it('leaves a weather icon on the accent when Automatic is left alone', () => {
|
|
const { container } = draw([badge({ variant: 'weather', code: 'partly', text: 'Partly cloudy' })])
|
|
expect(container.querySelector('svg')!.getAttribute('stroke')).toBe('#c2410c')
|
|
})
|
|
})
|
|
|
|
describe('showing the picture and the words', () => {
|
|
it('drops the icon and keeps the words when the icon is switched off', () => {
|
|
const { container } = draw([badge({
|
|
variant: 'mood', code: 'amazing', text: 'Amazing', sub: 'Reykjavik', showIcon: false,
|
|
})])
|
|
expect(container.querySelector('svg')).toBeNull()
|
|
expect(container.textContent).toContain('Amazing')
|
|
expect(container.textContent).toContain('Reykjavik')
|
|
})
|
|
|
|
it('drops the words and the line under them when the label is switched off', () => {
|
|
const { container } = draw([badge({
|
|
variant: 'mood', code: 'amazing', text: 'Amazing', sub: 'Reykjavik', showLabel: false,
|
|
})])
|
|
expect(container.querySelector('svg')).not.toBeNull()
|
|
expect(container.textContent).not.toContain('Amazing')
|
|
expect(container.textContent).not.toContain('Reykjavik')
|
|
})
|
|
|
|
/*
|
|
* A mark with no words is a pictogram, and a pictogram should fill the box it
|
|
* was given. The frame here is 90 by 40, so beside a label the icon is 0.46 of
|
|
* the height and on its own it is 0.8 of the shorter side: 18.4mm against
|
|
* 32mm. Left at the label size it would float in the middle of a frame that
|
|
* was measured for words no longer on the page.
|
|
*/
|
|
it('draws the icon larger once there are no words beside it', () => {
|
|
const withLabel = draw([badge({ variant: 'mood', code: 'amazing', text: 'Amazing' })])
|
|
expect(withLabel.container.querySelector('svg')!.style.width).toBe('18.4mm')
|
|
|
|
const alone = draw([badge({ variant: 'mood', code: 'amazing', text: 'Amazing', showLabel: false })])
|
|
const icon = alone.container.querySelector('svg')!
|
|
expect(icon.style.width).toBe('32mm')
|
|
expect(icon.style.height).toBe('32mm')
|
|
})
|
|
})
|
|
|
|
describe('the badge contract', () => {
|
|
it('defaults a mark that predates the icon fields to drawing both parts', () => {
|
|
const parsed = bookBadgeElementSchema.parse({
|
|
id: 'b1', kind: 'badge', frame: { x: 0, y: 0, w: 40, h: 20 },
|
|
variant: 'mood', code: 'amazing',
|
|
})
|
|
expect(parsed.showIcon).toBe(true)
|
|
expect(parsed.showLabel).toBe(true)
|
|
expect(parsed.autoIconColor).toBe(true)
|
|
})
|
|
|
|
/*
|
|
* The bug this all started from. A mood key is longer than a country code, the
|
|
* field was capped at two characters, and the element failing the union took
|
|
* its spread, its document and the whole book down with it.
|
|
*/
|
|
it('keeps the book when a mark carries a mood key rather than a country code', () => {
|
|
const doc = normalizeBookDocument(documentAround({
|
|
id: 'b1', kind: 'badge', frame: { x: 10, y: 20, w: 90, h: 40 },
|
|
variant: 'mood', code: 'amazing', text: 'Amazing',
|
|
}))
|
|
|
|
expect(doc.title).toBe('Iceland')
|
|
expect(doc.spreads).toHaveLength(1)
|
|
// Both elements, in order: the mark was not quietly salvaged away either.
|
|
expect(doc.spreads[0].elements.map(e => e.kind)).toEqual(['photo', 'badge'])
|
|
const mark = doc.spreads[0].elements[1]
|
|
expect(mark.kind === 'badge' && mark.code).toBe('amazing')
|
|
})
|
|
|
|
it('carries all four icon fields through a round trip with the spread intact', () => {
|
|
const doc = normalizeBookDocument(documentAround({
|
|
id: 'b1', kind: 'badge', frame: { x: 10, y: 20, w: 90, h: 40 },
|
|
variant: 'weather', code: 'partly', text: 'Partly cloudy',
|
|
showIcon: true, showLabel: false, autoIconColor: false, iconColor: '#0EA5E9',
|
|
}))
|
|
|
|
expect(doc.spreads[0].elements).toHaveLength(2)
|
|
const mark = doc.spreads[0].elements[1]
|
|
expect(mark.kind).toBe('badge')
|
|
expect(mark.kind === 'badge' && mark.showIcon).toBe(true)
|
|
expect(mark.kind === 'badge' && mark.showLabel).toBe(false)
|
|
expect(mark.kind === 'badge' && mark.autoIconColor).toBe(false)
|
|
expect(mark.kind === 'badge' && mark.iconColor).toBe('#0EA5E9')
|
|
})
|
|
})
|