mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 23:27:31 +00:00
feat(studio): follow-ups from using Studio on a real journey (#1984)
* 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.
This commit is contained in:
@@ -3,6 +3,7 @@ import type {
|
||||
} from '@trek/shared'
|
||||
import { SPREAD_TEMPLATES } from './bookTemplates.data'
|
||||
import { applyTemplate, templateFit } from './applyTemplate'
|
||||
import { formatBookCoords, formatBookDate } from './entryText'
|
||||
|
||||
/**
|
||||
* The auto mode: turn a journey into a book.
|
||||
@@ -84,6 +85,16 @@ export interface AutoInput {
|
||||
stationsLabel: string
|
||||
/** The word before a day number on a chip — "DAY 5". Already translated. */
|
||||
dayLabel: string
|
||||
/**
|
||||
* The real geometry of the route, when the journey has any.
|
||||
*
|
||||
* GPX and KML imports are the only thing in TREK that stores an actual path
|
||||
* — every other route is a straight line between stops. The editor already
|
||||
* fetches it for the Travel panel; an auto-laid-out book used to hard-code an
|
||||
* empty array here and throw it away, which is why the one journey with a
|
||||
* recorded track still printed a map drawn with a ruler.
|
||||
*/
|
||||
path?: [number, number][][]
|
||||
/** "TRIP SUMMARY" over the figures. */
|
||||
summaryLabel: string
|
||||
/** "COUNTRIES" over the outlines. */
|
||||
@@ -243,15 +254,24 @@ function mapEl(
|
||||
showRoute: true,
|
||||
showPins: true,
|
||||
showLabels: false,
|
||||
// The drawn line, for the same reason the panel places one: the contract
|
||||
// stays plain so old books do not change, and new books look like a book.
|
||||
routeStyle: 'drawn',
|
||||
routeArc: 'bow',
|
||||
routeDash: 'arcs',
|
||||
pinStyle: 'photo',
|
||||
countries: stats.countries.map(c => c.code),
|
||||
points: stats.points.map(pt => ({ lat: pt.lat, lng: pt.lng, label: pt.label })),
|
||||
points: stats.points.map(pt => ({
|
||||
lat: pt.lat, lng: pt.lng, label: pt.label, photoId: pt.photoId ?? null,
|
||||
})),
|
||||
/*
|
||||
* The fields the contract would default for a parsed element, spelled out
|
||||
* because this one is cast. `path` in particular is read as an array while
|
||||
* the map draws, so leaving it out is not a cosmetic difference.
|
||||
*/
|
||||
path: [],
|
||||
fitPadding: 0.18,
|
||||
roads: [],
|
||||
fitPadding: 0.5,
|
||||
fitToCountries: true,
|
||||
clip: 'rect',
|
||||
...opts,
|
||||
@@ -300,6 +320,10 @@ function badgeEl(
|
||||
// apply: left out, a mark reads as having been given a colour, and a chip
|
||||
// draws its words in ink on an ink-coloured capsule.
|
||||
autoColor: true,
|
||||
showIcon: true,
|
||||
showLabel: true,
|
||||
autoIconColor: true,
|
||||
iconColor: INK,
|
||||
...opts,
|
||||
} as BookElement
|
||||
}
|
||||
@@ -338,16 +362,8 @@ function coordsMark(
|
||||
lng: number | null | undefined,
|
||||
): BookElement | null {
|
||||
if (lat == null || lng == null) return null
|
||||
const dms = (v: number, positive: string, negative: string) => {
|
||||
const hemisphere = v >= 0 ? positive : negative
|
||||
const abs = Math.abs(v)
|
||||
const deg = Math.floor(abs)
|
||||
const min = Math.floor((abs - deg) * 60)
|
||||
const sec = Math.round((((abs - deg) * 60) - min) * 60)
|
||||
return `${deg}° ${min}' ${sec}" ${hemisphere}`
|
||||
}
|
||||
return badgeEl(frame, 'coords', {
|
||||
text: `${dms(lat, 'N', 'S')} ${dms(lng, 'E', 'W')}`,
|
||||
text: formatBookCoords(lat, lng),
|
||||
}, { style: 'plain', textScale: 0.7 })
|
||||
}
|
||||
|
||||
@@ -425,15 +441,22 @@ function placeMap(
|
||||
id: uid('mp'),
|
||||
kind: 'map',
|
||||
frame,
|
||||
points: [{ lat: entry.lat, lng: entry.lng, label: entry.location ?? '' }],
|
||||
points: [{ lat: entry.lat, lng: entry.lng, label: entry.location ?? '', photoId: null }],
|
||||
countries: entry.country ? [entry.country] : (stats?.countries.map(c => c.code) ?? []),
|
||||
style: 'minimal',
|
||||
source: 'vector',
|
||||
tileUrl: '',
|
||||
attribution: '',
|
||||
zoom: 5,
|
||||
// Deliberately the plain treatment: this is one dot on a country outline,
|
||||
// and a bowed casing around a single stop would be decoration.
|
||||
routeStyle: 'plain',
|
||||
routeArc: 'straight',
|
||||
routeDash: 'solid',
|
||||
pinStyle: 'dot',
|
||||
path: [],
|
||||
fitPadding: 0.18,
|
||||
roads: [],
|
||||
fitPadding: 0.5,
|
||||
/*
|
||||
* This one is the "where in the world was this" mark beside an entry, so it
|
||||
* wants the country whole with a dot in it — the opposite of the route map,
|
||||
@@ -466,13 +489,6 @@ function dateMark(iso: string | null, locale: string, frame: { x: number; y: num
|
||||
}, { style: 'stacked' })
|
||||
}
|
||||
|
||||
function formatDate(iso: string | null, locale: string): string {
|
||||
if (!iso) return ''
|
||||
const d = new Date(iso + 'T00:00:00')
|
||||
if (Number.isNaN(d.getTime())) return ''
|
||||
return d.toLocaleDateString(locale, { day: 'numeric', month: 'long', year: 'numeric' })
|
||||
}
|
||||
|
||||
/** A full-bleed frame: out past the trim on every side the page is cut on. */
|
||||
function bleedFrame(page: BookPageSetup, spread: boolean) {
|
||||
const w = spread ? page.pageWidth * 2 : page.pageWidth
|
||||
@@ -569,11 +585,13 @@ function stationsSpread(entries: AutoEntry[], input: AutoInput, label: string):
|
||||
const w = W - m * 2
|
||||
column.forEach((entry, i) => {
|
||||
const y = top + i * step
|
||||
const date = formatDate(entry.date, input.locale)
|
||||
const date = formatBookDate(entry.date, input.locale)
|
||||
if (date) {
|
||||
// Set in small caps, so the words on the page are not the words in the
|
||||
// journal — and a bound element has to hold exactly its source or
|
||||
// opening the book would quietly rewrite it. See resolveBindings.ts.
|
||||
els.push(text({ x, y, w: w * 0.32, h: 5 }, date.toUpperCase(), {
|
||||
size: 7, weight: 600, tracking: 0.1, color: '#a09a8e', // theme-lint-disable — book ink, not app chrome
|
||||
binding: { source: 'entry.date', entryId: entry.id },
|
||||
}))
|
||||
}
|
||||
const name = entry.title || entry.location || ''
|
||||
@@ -699,16 +717,17 @@ function headingBlock(
|
||||
const ink = opts.ink ?? '#141414' // theme-lint-disable — book ink, not app chrome
|
||||
const muted = opts.muted ?? '#8a8578' // theme-lint-disable — book ink, not app chrome
|
||||
const heading = entry.title || entry.location || ''
|
||||
const meta = [formatDate(entry.date, input.locale), entry.location].filter(Boolean).join(' · ')
|
||||
const meta = [formatBookDate(entry.date, input.locale), entry.location].filter(Boolean).join(' · ')
|
||||
let cy = y
|
||||
|
||||
if (meta || heading) {
|
||||
els.push(shape({ x, y: cy - 6, w: Math.min(14, w * 0.18), h: 0.5 }, ACCENT))
|
||||
}
|
||||
if (meta) {
|
||||
// Two facts run together and upper-cased: neither the date nor the place as
|
||||
// the journal holds them, so this line is not bound to either.
|
||||
els.push(text({ x, y: cy, w, h: 5 }, meta.toUpperCase(), {
|
||||
size: 7.5, weight: 600, tracking: 0.14, color: muted,
|
||||
binding: { source: 'entry.date', entryId: entry.id },
|
||||
}))
|
||||
cy += 8
|
||||
}
|
||||
@@ -1290,7 +1309,9 @@ function summarySpread(input: AutoInput): BookSpread | null {
|
||||
const els: BookElement[] = []
|
||||
|
||||
if (stats.points.length >= 2) {
|
||||
els.push(mapEl({ x: m, y: m, w: W - m * 2, h: H - m * 2 }, stats))
|
||||
// With the recorded track, when the journey has one: the editor fetches it
|
||||
// and this was the line that threw it away.
|
||||
els.push(mapEl({ x: m, y: m, w: W - m * 2, h: H - m * 2 }, stats, { path: input.path ?? [] }))
|
||||
}
|
||||
|
||||
// Which figures are worth the space: everything the journey actually has.
|
||||
@@ -1431,7 +1452,7 @@ function backSpread(input: AutoInput): BookSpread {
|
||||
.filter((d): d is string => !!d)
|
||||
.sort()
|
||||
const span = dates.length
|
||||
? [formatDate(dates[0], input.locale), formatDate(dates[dates.length - 1], input.locale)].filter(Boolean).join(' — ')
|
||||
? [formatBookDate(dates[0], input.locale), formatBookDate(dates[dates.length - 1], input.locale)].filter(Boolean).join(' — ')
|
||||
: ''
|
||||
|
||||
els.push(shape({ x: -page.bleed, y: -page.bleed, w: page.pageWidth + page.bleed * 2, h: page.pageHeight + page.bleed * 2 }, '#141414')) // theme-lint-disable — book ink, not app chrome
|
||||
@@ -1535,6 +1556,31 @@ export function buildBook(input: AutoInput): BookDocument {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A book nobody has laid out yet.
|
||||
*
|
||||
* What a journey with no book now opens on. It used to open on the auto layout,
|
||||
* which was generous and wrong: it decided what the book was before its author
|
||||
* had said anything, and everything after that was undoing rather than making.
|
||||
* The layout is still one click away, on the Auto layout menu, and it reads
|
||||
* very differently when it is offered than when it has already happened.
|
||||
*
|
||||
* The covers are here rather than left out because a book has them and there is
|
||||
* no other way to add one: the pages rail only inserts inner spreads, between
|
||||
* the two. Empty, though, in the same way the page between them is.
|
||||
*/
|
||||
export function emptyBook(input: AutoInput): BookDocument {
|
||||
const blank = (role: BookSpread['role']): BookSpread => ({
|
||||
id: uid('sp'), role, background: null, elements: [], parked: [], entryId: null,
|
||||
})
|
||||
return {
|
||||
version: 1,
|
||||
title: input.title,
|
||||
page: input.page,
|
||||
spreads: [blank('cover'), blank('inner'), blank('back')],
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lay one spread out again, from the entry it came from.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user