feat(studio): a book map can be of a country, a day or one stop, framed by hand

Book schema revision 12 adds five optional fields to the map element:
view (a hand-framed box, east up to 540 for the antimeridian), stop,
country, dayDate and coastDetail. Absent means a map saved before them,
null means not narrowed that way.

routeFor, isStale and refreshPatch honour every scope and never widen a
narrowed map to the whole journey. Country maps from the travel looks
and the entry-page map of the auto layout carried tripId null like a
journey map, so refreshing one from the inspector turned it into the
whole route; maps saved before revision 12 are now read off what they
hold and refresh writes their scope down. The looks and the auto layout
write the scope from now on, so the parity digests of those pages move.

The book engine's add takes a country, a date or an entry as the map's
scope, style takes view and coastDetail, and describe-spread says what a
map is of. Pasting a style never copies a map's view.
This commit is contained in:
Maurice
2026-11-30 14:32:16 +01:00
parent 9b06bb8892
commit d6fd916098
20 changed files with 658 additions and 45 deletions
@@ -273,9 +273,11 @@ function MapContent({ el, set, t, stats, journeyPath }: MapPropsInput) {
* nothing. The roads go with the old legs, since entry i is the
* way from stop i to stop i + 1 of the route that is gone.
*/
// Picking a trip or the whole journey is what the map is of from now on: no country, day or stop left over.
const scope = { tripId, country: null, dayDate: null, stop: null }
set({
...refreshPatch({ ...el, tripId }, stats),
tripId,
...refreshPatch({ ...el, ...scope }, stats),
...scope,
path: tripId == null
? journeyPath.slice(0, MAX_PATH_SEGMENTS).map(seg => seg.slice(0, MAX_PATH_POINTS))
: [],
+3
View File
@@ -332,6 +332,9 @@ export function placeMap(
showRoute: false,
showPins: true,
showLabels: false,
// A map of this stop, said in so many words (revision 12), so bringing it up to date keeps it the stop rather
// than widening it to the whole journey.
stop: { entryId: entry.id, lat: entry.lat, lng: entry.lng },
// weight and tripId are left to the schema's defaults when the book is saved, as the client's layout always did;
// the parity fixture pins this output byte for byte.
} as unknown as BookElement;
+4 -4
View File
@@ -36,10 +36,10 @@
"A/plain/spread/2": "688f4ce239f0eb65",
"A/plain/spread/3": "3bc5ecd3ad02ad83",
"A/plain/spread/4": "6fdb7d865a3534c5",
"A/plain/spread/5": "77241c40787fee23",
"A/plain/spread/5": "637abb25cc53282f",
"A/plain/relayout/5": "dea1552bb3b68330",
"A/plain/spread/6": "71f875eca927c88d",
"A/plain/relayout/6": "a8ee238a620ce6e6",
"A/plain/relayout/6": "ae48944db331fcaf",
"A/plain/spread/7": "eb8defdfae4221c7",
"A/plain/relayout/7": "eb8defdfae4221c7",
"A/plain/spread/8": "34f52cbb4583cf5a",
@@ -51,8 +51,8 @@
"A/plain/spread/11": "7a3bf522f37acca3",
"A/plain/relayout/11": "539de849990c2012",
"A/plain/spread/12": "746c3194e39f13cb",
"A/plain/relayout/12": "80100245e192c30d",
"A/plain/spread/13": "bf5ded4681177685",
"A/plain/relayout/12": "bebaaf8cfe2c7b6c",
"A/plain/spread/13": "fe82fe7e6be3376a",
"A/plain/relayout/13": "ae0a4713176adbc9",
"A/plain/spread/14": "5c92185debe40114",
"A/plain/relayout/14": "e1d6c0ad1c25caf0",
+19 -4
View File
@@ -11,8 +11,10 @@ import {
bookIconNameSchema,
bookListLayoutSchema,
bookMapClipSchema,
bookMapCoastDetailSchema,
bookMapSourceSchema,
bookMapStyleSchema,
bookMapViewSchemaIn,
bookMetricSchema,
bookPhotoFilterSchema,
bookPhotoFitSchema,
@@ -176,6 +178,8 @@ const MAP_PROPS = {
clip: bookMapClipSchema.optional(),
fitPadding: map.fitPadding.unwrap().optional(),
fitToCountries: map.fitToCountries.unwrap().optional(),
view: bookMapViewSchemaIn.nullable().optional(),
coastDetail: bookMapCoastDetailSchema.optional(),
};
const STATS_PROPS = {
...COMMON,
@@ -267,11 +271,22 @@ const listItem = z.strictObject({
});
/**
* Where a map is of: the whole journey or one trip, the two scopes a stored map
* can say (its `tripId`). A map of some entries' stops would be stale the moment
* it was placed and widened to the journey by the first refresh.
* Where a map is of, each a scope a stored map can say, so a refresh keeps
* it: the whole journey, one trip, the stops in one country or on one day
* (either within a trip), or the stop of one entry.
*/
const mapScope = z.union([z.literal('journey'), z.strictObject({ tripId: idSchema })]);
const mapScope = z
.union([
z.literal('journey'),
z.strictObject({ tripId: idSchema }),
z.strictObject({ country: iso2, tripId: idSchema.optional() }),
z.strictObject({
date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
tripId: idSchema.optional(),
}),
z.strictObject({ entryId: idSchema }),
])
.describe('journey, a tripId, a country code, a date (YYYY-MM-DD) or the entryId of one stop.');
/*
* What a new element is, kind by kind: where its content comes from. A text
+61
View File
@@ -364,3 +364,64 @@ describe('a new element and its look', () => {
expect(find(kept, 'kept')).toMatchObject({ size: 30 });
});
});
describe('what a map is of, and the ground it shows', () => {
const mapOf = (el: BookElement | undefined) => (el?.kind === 'map' ? el : null);
it('BOOKEL-020: adds a map of a country, of one entry stop or of a day, and refuses a scope with no stop in it', () => {
const iceland = mapOf(added({ kind: 'map', scope: { country: 'is' } }));
expect(iceland).toMatchObject({ country: 'IS', countries: ['IS'], tripId: null, path: [] });
expect(iceland?.points.map((p) => p.label)).toEqual(['Reykjavik']);
const stop = mapOf(added({ kind: 'map', scope: { entryId: 7 } }));
expect(stop).toMatchObject({ stop: { entryId: 7, lat: 64.14, lng: -21.94 }, countries: ['IS'] });
expect(stop?.points).toHaveLength(1);
expect(addRefusal({ kind: 'map', scope: { entryId: 99 } })).toBe('entry_not_found');
expect(addRefusal({ kind: 'map', scope: { country: 'PT' } })).toBe('travel_unavailable');
const dated = {
...stats,
points: stats.points.map((p, i) => ({ ...p, date: i === 0 ? '2026-06-02' : '2026-06-09T10:00:00Z' })),
};
const onDay = { ...ctx, travel: { ...travel, stats: dated } };
const day = mapOf(added({ kind: 'map', scope: { date: '2026-06-09' } }, onDay));
expect(day).toMatchObject({ dayDate: '2026-06-09', countries: ['NO'] });
expect(day?.points.map((p) => p.label)).toEqual(['Bergen']);
});
it('BOOKEL-021: the page edit takes each scope of a map once, never two at a time', () => {
const edit = (scope: unknown) => ({ spreadId: 'sp-in', ops: [{ op: 'add', element: { kind: 'map', scope } }] });
const good = ['journey', { tripId: 3 }, { country: 'IS' }, { date: '2026-06-02', tripId: 3 }, { entryId: 7 }];
for (const scope of good) {
expect(editBookPageRequestSchema.safeParse(edit(scope)).success, JSON.stringify(scope)).toBe(true);
}
for (const scope of [{ country: 'ISL' }, { date: '2.6.2026' }, { entryId: 7, country: 'IS' }, { stop: 7 }]) {
expect(editBookPageRequestSchema.safeParse(edit(scope)).success, JSON.stringify(scope)).toBe(false);
}
});
it('BOOKEL-022: style frames a map by hand and sets its coast, and null fits it to its route again', () => {
const view = { west: -25, south: 63, east: -13, north: 67 };
const doc = ok(
run(book([]), [
{ op: 'add', element: { kind: 'map', scope: { country: 'IS' } }, id: 'm' },
{ op: 'style', elementId: 'm', set: { kind: 'map', view, coastDetail: 'detailed' } },
]),
);
expect(find(doc, 'm')).toMatchObject({ view, coastDetail: 'detailed' });
const fitted = ok(run(doc, [{ op: 'style', elementId: 'm', set: { kind: 'map', view: null } }]));
expect(find(fitted, 'm')).toMatchObject({ view: null, coastDetail: 'detailed' });
const backwards = { west: 10, south: 0, east: 5, north: 1 };
const refused = run(doc, [{ op: 'style', elementId: 'm', set: { kind: 'map', view: backwards } }]);
expect(refusal(refused)).toBe('invalid_op');
// Across the antimeridian, east runs past 180.
const fiji = { west: 176, south: -20, east: 182, north: -15 };
const across = ok(run(doc, [{ op: 'style', elementId: 'm', set: { kind: 'map', view: fiji } }]));
expect(find(across, 'm')).toMatchObject({ view: fiji });
});
it('BOOKEL-023: refresh_travel keeps a map of a country the country, never the journey', () => {
const doc = ok(run(book([]), [{ op: 'add', element: { kind: 'map', scope: { country: 'IS' } }, id: 'm' }]));
const refreshed = ok(run(doc, [{ op: 'refresh_travel' }]));
expect(find(refreshed, 'm')).toMatchObject({ country: 'IS', countries: ['IS'] });
expect(mapOf(find(refreshed, 'm'))?.points).toHaveLength(1);
});
});
+8
View File
@@ -3,6 +3,7 @@ import { BOOK_ICON_NAMES } from './book-icons';
import {
BOOK_BADGES,
BOOK_FONTS_IDS,
BOOK_MAP_COAST_DETAILS,
BOOK_METRICS,
BOOK_SHAPES,
bookBadgeElementSchema,
@@ -10,6 +11,7 @@ import {
bookCountriesElementSchema,
bookListElementSchema,
bookMapElementSchema,
bookMapViewSchema,
bookPageSetupSchema,
bookPhotoElementSchema,
bookShapeElementSchema,
@@ -114,6 +116,12 @@ export const bookPinStyleSchema = map.pinStyle.unwrap().describe('How the stops
export const bookMapClipSchema = map.clip
.unwrap()
.describe('rect is a map in a box; country cuts it to the outline of its countries.');
export const bookMapCoastDetailSchema = z
.enum(BOOK_MAP_COAST_DETAILS)
.describe('simple leaves out small islands; detailed draws them, Hawaii too; auto picks by how far the map reaches.');
export const bookMapViewSchemaIn = bookMapViewSchema.describe(
'The ground in degrees, framed by hand; east may pass 180 (to 540) across the antimeridian. null fits the route again.',
);
/** Where a new map's ground comes from. */
export const bookMapSourceSchema = z
.enum(['vector', 'relief', 'satellite'])
+17 -1
View File
@@ -28,6 +28,7 @@ import {
bookCountryMark,
bookCountryName,
bookEntryListItems,
bookMapStopFor,
bookTravelBadge,
bookTravelCountries,
bookTravelList,
@@ -35,6 +36,7 @@ import {
bookTravelSize,
bookTravelStats,
refreshPatch,
type BookMapScope,
type BookTravelContext,
} from './book-travel';
import type {
@@ -364,7 +366,8 @@ function newTravel(spec: TravelSpec, at: At, env: ElementOpEnv): BookElement {
switch (spec.kind) {
case 'map': {
const frame = at(bookTravelSize('map', page));
const el = bookTravelMap(travelOf(env), statsOf(env), { id, frame, scope: spec.scope, source: spec.source });
const scope = mapScopeOf(spec.scope, env);
const el = bookTravelMap(travelOf(env), statsOf(env), { id, frame, scope, source: spec.source });
if (el.points.length === 0) {
throw failOp('travel_unavailable', 'no stops of the journey fall in that scope', env.opIndex);
}
@@ -387,6 +390,19 @@ function newTravel(spec: TravelSpec, at: At, env: ElementOpEnv): BookElement {
}
}
/** The scope a new map asked for, as the engine places it: an entry's stop found where the journey has it. */
function mapScopeOf(scope: Extract<TravelSpec, { kind: 'map' }>['scope'], env: ElementOpEnv): BookMapScope {
if (scope === 'journey') return scope;
if ('entryId' in scope) {
const stop = bookMapStopFor(statsOf(env), travelOf(env).entries, scope.entryId);
if (!stop) throw failOp('entry_not_found', `entry ${scope.entryId} is not a stop of this journey`, env.opIndex);
return { stop };
}
if ('country' in scope) return { country: scope.country.toUpperCase(), tripId: scope.tripId ?? null };
if ('date' in scope) return { dayDate: scope.date, tripId: scope.tripId ?? null };
return scope;
}
/** The journey's figures when an entry is named (an entry needs them to be found), else whatever is known. */
const travelFor = (entryId: number | undefined, env: ElementOpEnv) =>
entryId !== undefined ? travelOf(env) : env.ctx.travel;
+31 -1
View File
@@ -11,7 +11,7 @@ import { bookDocumentSchema } from './book.schema';
import { describe, expect, it } from 'vitest';
// BKREV-001 to BKREV-008
// BKREV-001 to BKREV-009
/**
* The reader guard: a document says which revision of the format wrote it, a
@@ -127,3 +127,33 @@ describe('the sticker kind', () => {
expect(readBookDocument(raw, 1).newer).toBe(true);
});
});
describe('what a map is of and shows', () => {
it('BKREV-009: reads whole at revision 12, and a reader of 11 is told the book is newer than it', () => {
expect(BOOK_SCHEMA_REV).toBeGreaterThanOrEqual(12);
const map = {
id: 'm1',
kind: 'map',
frame,
view: { west: 176, south: -20, east: 182, north: -15 },
stop: { entryId: 4, lat: -17.7, lng: 178.1 },
country: 'FJ',
dayDate: '2026-07-01',
coastDetail: 'detailed',
};
const raw = doc({ schemaRev: 12 });
const spread = (raw.spreads as { elements: unknown[] }[])[0];
if (spread) spread.elements.push(map);
const read = readBookDocument(raw);
expect(read.newer).toBe(false);
expect(read.document.spreads[0]?.elements[1]).toMatchObject({
view: map.view,
stop: map.stop,
country: 'FJ',
dayDate: '2026-07-01',
coastDetail: 'detailed',
});
// A reader of 11 would drop the five, so it opens the book without saving it.
expect(readBookDocument(raw, 11).newer).toBe(true);
});
});
+4 -1
View File
@@ -48,8 +48,11 @@ import type { BookDocument } from './book.schema';
* - 11: the newer travel looks: a summary's `look`, a country's `look`, the stamp, tag,
* pill, ribbon, sticker, patch and sketch marks, and the `numbered` and `ends` stops of
* a map.
* - 12: what a map is of and what it shows (`view`, `stop`, `country`, `dayDate`,
* `coastDetail`): a map of one stop, one country or one day, framed by hand, and drawn
* with the finer coast.
*/
export const BOOK_SCHEMA_REV = 11;
export const BOOK_SCHEMA_REV = 12;
/** The `code` a refused save carries in its body when the stored book is newer than the writer. */
export const BOOK_SCHEMA_NEWER_CODE = 'book_schema_newer';
+5
View File
@@ -54,6 +54,11 @@ describe('copy style', () => {
expect(bookElementStyle(route).props).not.toHaveProperty('points');
});
it("BKSTY-006: takes a map's coast with its look and never its own view, which is the ground it shows", () => {
expect(bookStyleKeys('map')).toContain('coastDetail');
expect(bookStyleKeys('map')).not.toContain('view');
});
it('BKSTY-003: pastes all of it onto the same kind, and what both have onto another', () => {
const style = bookElementStyle(text({ size: 24, color: '#ff0000', opacity: 0.5 }));
expect(pastableStyle(style, 'text')).toMatchObject({ kind: 'text', size: 24, color: '#ff0000' });
+3 -2
View File
@@ -20,9 +20,10 @@ export interface BookCopiedStyle {
/**
* Props of `style` that say what an element shows or where it runs, not how it
* looks: a line's points are its course, so pasting a look never redraws one.
* looks: a line's points are its course, so pasting a look never redraws one,
* and a map's own view is the ground it shows, so it never reframes one.
*/
const CONTENT_KEYS: ReadonlySet<string> = new Set(['metrics', 'proLabel', 'conLabel', 'points']);
const CONTENT_KEYS: ReadonlySet<string> = new Set(['metrics', 'proLabel', 'conLabel', 'points', 'view']);
const STYLE_KEYS = new Map<string, string[]>(
bookElementPropsSchema.options.map((o) => [
+139 -1
View File
@@ -7,6 +7,8 @@ import {
bookCountryName,
bookDayText,
bookEntryListItems,
bookMapScopeOf,
bookMapStopFor,
bookTravelCountries,
bookTravelMap,
bookTravelSize,
@@ -17,7 +19,13 @@ import {
routeFor,
type BookTravelContext,
} from './book-travel';
import { bookBadgeElementSchema, bookElementSchema, bookPageSetupSchema, type BookElement } from './book.schema';
import {
bookBadgeElementSchema,
bookElementSchema,
bookMapElementSchema,
bookPageSetupSchema,
type BookElement,
} from './book.schema';
import type { JourneyStats } from './journey-stats.schema';
import { describe, expect, it } from 'vitest';
@@ -247,3 +255,133 @@ describe('book travel', () => {
]);
});
});
/*
* What a map is of (revision 12): a country, a day, a stop, and the maps saved
* before the scope was written down, which must never be widened to the whole
* journey by bringing them up to date.
*/
describe('the scope of a map', () => {
const asMap = (el: Record<string, unknown>) => bookMapElementSchema.parse({ id: 'm', kind: 'map', frame, ...el });
const point = (p: Point) => ({ lat: p.lat, lng: p.lng, label: p.label, photoId: p.photoId });
const [reykjavik, akureyri, lisboa] = stats.points as [Point, Point, Point];
const dated: JourneyStats = {
...stats,
points: stats.points.map((p, i) => ({
...p,
date: ['2026-06-02', '2026-06-06T09:00:00Z', '2026-09-04'][i] ?? null,
})),
};
/** A country map as book-travel-looks placed one before revision 12: tripId null, its own stops, no track. */
const oldCountryMap = asMap({ countries: ['IS'], points: [point(reykjavik), point(akureyri)] });
/** The small map of an entry page as the auto layout placed one before revision 12. */
const oldPlaceMap = asMap({ countries: ['IS'], points: [{ ...point(akureyri), label: 'Akureyri', photoId: null }] });
it('BOOKTRV-011: narrows a route to a country, a day or a stop, and to nothing rather than to everything', () => {
expect(routeFor(stats, { country: 'is' }).map((p) => p.label)).toEqual(['Reykjavík', 'Akureyri']);
expect(routeFor(dated, { dayDate: '2026-06-06' }).map((p) => p.label)).toEqual(['Akureyri']);
expect(routeFor(dated, { dayDate: '2026-06-06', tripId: 22 })).toEqual([]);
expect(routeFor(stats, { country: 'DE' })).toEqual([]);
expect(routeFor(stats, { stop: { entryId: 3, lat: 0, lng: 0 } }).map((p) => p.label)).toEqual(['Lisboa']);
// No entry left with the id: found where it is, or not at all.
expect(routeFor(stats, { stop: { entryId: 99, lat: 65.68, lng: -18.12 } }).map((p) => p.label)).toEqual([
'Akureyri',
]);
expect(routeFor(stats, { stop: { entryId: null, lat: 1, lng: 1 } })).toEqual([]);
expect(routeFor(stats, {})).toHaveLength(3);
});
it('BOOKTRV-012: reads a map saved before revision 12 as what it holds, and a recorded track as the journey', () => {
expect(bookMapScopeOf(oldCountryMap, stats)).toMatchObject({ country: 'IS', inferred: true });
expect(bookMapScopeOf(oldPlaceMap, stats)).toMatchObject({
stop: { entryId: null, lat: 65.68, lng: -18.12 },
inferred: true,
});
const tracked = asMap({ countries: ['IS'], points: [point(reykjavik), point(akureyri)], path: [[[64, -21]]] });
expect(bookMapScopeOf(tracked, stats)).toMatchObject({ country: null, stop: null, inferred: false });
// A journey of one country: a map of it is the journey's.
const oneCountry = { ...stats, countries: stats.countries.slice(0, 1) };
expect(bookMapScopeOf(oldCountryMap, oneCountry)).toMatchObject({ country: null, inferred: false });
// A map that says what it is of is read as it says, the nulls included.
const said = asMap({ countries: ['IS'], points: [point(reykjavik)], stop: null, country: null, dayDate: null });
expect(bookMapScopeOf(said, stats)).toMatchObject({ stop: null, country: null, inferred: false });
expect(bookMapScopeOf(oldCountryMap, null).inferred).toBe(false);
});
it('BOOKTRV-013: never widens an old country map to the journey, and writes its country down', () => {
expect(isStale(oldCountryMap, stats)).toBe(false);
const more = { ...stats, points: [...stats.points, { ...akureyri, lat: 64.0, lng: -16.0, label: 'Vík' }] };
expect(isStale(oldCountryMap, more)).toBe(true);
const patch = refreshPatch(oldCountryMap, more);
expect(patch).toMatchObject({ stale: false, country: 'IS', countries: ['IS'] });
expect((patch as { points: { label: string }[] }).points.map((p) => p.label)).toEqual([
'Reykjavík',
'Akureyri',
'Vík',
]);
});
it('BOOKTRV-014: keeps an old entry-page map on its stop, without going stale over a photograph it never showed', () => {
// The live stop carries a photograph; the dot never did, so nothing is out of date.
const withPhoto = { ...stats, points: stats.points.map((p) => ({ ...p, photoId: 5 })) };
expect(isStale(oldPlaceMap, withPhoto)).toBe(false);
expect(refreshPatch(oldPlaceMap, withPhoto)).toMatchObject({
stop: { entryId: 2, lat: 65.68, lng: -18.12 },
points: [{ lat: 65.68, lng: -18.12, photoId: null }],
});
});
it('BOOKTRV-015: moves a map of a stop with its entry, and leaves it where it was once the stop is gone', () => {
const map = bookTravelMap(ctx, stats, {
id: 'mp-s',
frame,
scope: { stop: { entryId: 1, lat: 64.14, lng: -21.94 } },
});
expect(map).toMatchObject({ stop: { entryId: 1 }, countries: ['IS'], tripId: null, path: [] });
expect(map.points).toEqual([{ lat: 64.14, lng: -21.94, label: 'Reykjavík', photoId: 3 }]);
expect(isStale(map, stats)).toBe(false);
const moved = { ...stats, points: stats.points.map((p) => (p.entryId === 1 ? { ...p, lat: 64.15 } : p)) };
expect(isStale(map, moved)).toBe(true);
expect(refreshPatch(map, moved)).toMatchObject({ stop: { entryId: 1, lat: 64.15 }, points: [{ lat: 64.15 }] });
const gone = { ...stats, points: stats.points.filter((p) => p.entryId !== 1) };
expect(isStale(map, gone)).toBe(false);
expect(refreshPatch(map, gone)).toEqual({ stale: false, stop: map.stop });
// A stop already gone when the map is placed is still a place of its own.
const placed = bookTravelMap(ctx, gone, {
id: 'mp-g',
frame,
scope: { stop: { entryId: 1, lat: 64.14, lng: -21.94 } },
});
expect(placed.points).toEqual([{ lat: 64.14, lng: -21.94, label: '', photoId: null }]);
});
it('BOOKTRV-016: places maps of a country and of a day, and keeps them so on refresh', () => {
const iceland = bookTravelMap(ctx, stats, { id: 'mp-c', frame, scope: { country: 'is' } });
expect(valid(iceland)).toBe(true);
expect(iceland).toMatchObject({ country: 'IS', countries: ['IS'], tripId: null, path: [] });
expect(iceland).not.toHaveProperty('stop');
expect(refreshPatch(iceland, stats)).toMatchObject({ countries: ['IS'] });
expect(refreshPatch(iceland, stats)).not.toHaveProperty('country');
const day = bookTravelMap(ctx, dated, { id: 'mp-d', frame, scope: { dayDate: '2026-06-06', tripId: 11 } });
expect(day).toMatchObject({ dayDate: '2026-06-06', tripId: 11, countries: ['IS'] });
expect(day.points.map((p) => p.label)).toEqual(['Akureyri']);
expect(isStale(day, dated)).toBe(false);
// A map of the whole journey or of a trip writes nothing new: what it wrote before revision 12.
const whole = bookTravelMap(ctx, stats, { id: 'mp-w', frame, scope: 'journey' });
for (const key of ['stop', 'country', 'dayDate', 'view', 'coastDetail']) expect(whole).not.toHaveProperty(key);
});
it('BOOKTRV-017: widens a map to the journey only when it is told it is of the journey', () => {
// The Studio's scope choice sets every part, so an old country map picked as the whole journey becomes it.
const told = { ...oldCountryMap, tripId: null, country: null, dayDate: null, stop: null };
expect(refreshPatch(told, stats)).toMatchObject({ countries: ['IS', 'PT'] });
expect((refreshPatch(told, stats) as { points: unknown[] }).points).toHaveLength(3);
expect(routeFor(stats, null)).toContainEqual(lisboa);
});
it('BOOKTRV-018: finds the stop of an entry on the route, else where the entry says, else none', () => {
expect(bookMapStopFor(stats, [], 3)).toEqual({ entryId: 3, lat: 38.72, lng: -9.14 });
expect(bookMapStopFor(null, [entry], 2)).toEqual({ entryId: 2, lat: 65.68, lng: -18.12 });
expect(bookMapStopFor(stats, [{ ...entry, id: 9, lat: null, lng: null }], 9)).toBeNull();
});
});
+198 -13
View File
@@ -15,6 +15,7 @@ import {
type BookFrame,
type BookListElement,
type BookMapElement,
type BookMapStop,
type BookMetric,
type BookPageSetup,
type BookStatsElement,
@@ -39,14 +40,118 @@ export function liveMetrics(stats: JourneyStats): Record<BookMetric, number> {
return statsValues(stats);
}
/*
* ── What a map is of ─────────────────────────────────────────────────────
*
* The whole journey, one trip, one country, one day, or one stop. A map keeps
* its stops frozen in it, so what it is of has to be written down beside them:
* bringing a map of Iceland up to date must give the stops in Iceland, not the
* journey's whole route. `tripId` said it for a trip from the start; `country`,
* `dayDate` and `stop` say it for the rest since revision 12.
*/
/** What a map is narrowed to, each part null where it is not narrowed that way. */
export interface BookMapScopeParts {
tripId: number | null;
country: string | null;
dayDate: string | null;
stop: BookMapStop | null;
}
const UNSCOPED: BookMapScopeParts = { tripId: null, country: null, dayDate: null, stop: null };
/** The same place: frozen coordinates went through no more than rounding. */
const samePlace = (a: { lat: number; lng: number }, b: { lat: number; lng: number }) =>
Math.abs(a.lat - b.lat) < 1e-6 && Math.abs(a.lng - b.lng) < 1e-6;
const dayOf = (date: string | null) => (date ? date.slice(0, 10) : null);
/** The journey's stop a map of one stop shows: by its entry when it has one, else by where it is. */
function liveStop(stats: JourneyStats, stop: BookMapStop): JourneyStatsPoint | null {
const byEntry = stop.entryId == null ? undefined : stats.points.find((p) => p.entryId === stop.entryId);
return byEntry ?? stats.points.find((p) => samePlace(p, stop)) ?? null;
}
/**
* The stops a map of this scope should draw: `null` is the journey entire, a
* trip id narrows it to that trip's own stops, so two trips of one journey are
* never joined by a leg nobody travelled.
* never joined by a leg nobody travelled. A country or a day narrows it the
* same way, and a stop is that stop alone, or nothing once it has left the
* journey. A narrowed scope nothing falls in draws nothing, never everything.
*/
export function routeFor(stats: JourneyStats, tripId: number | null): JourneyStats['points'] {
if (tripId == null) return stats.points;
return stats.points.filter((p) => p.tripId === tripId);
export function routeFor(
stats: JourneyStats,
scope: number | null | Partial<BookMapScopeParts>,
): JourneyStats['points'] {
const parts: BookMapScopeParts =
scope == null || typeof scope === 'number' ? { ...UNSCOPED, tripId: scope } : { ...UNSCOPED, ...scope };
if (parts.stop) {
const live = liveStop(stats, parts.stop);
return live ? [live] : [];
}
const country = parts.country ? parts.country.toUpperCase() : null;
if (parts.tripId == null && country == null && parts.dayDate == null) return stats.points;
return stats.points.filter(
(p) =>
(parts.tripId == null || p.tripId === parts.tripId) &&
(country == null || p.country === country) &&
(parts.dayDate == null || dayOf(p.date) === parts.dayDate),
);
}
/** Whether a map was saved before revision 12, when what it was of beyond its trip went unrecorded. */
const fromBeforeScopes = (el: BookMapElement) =>
el.stop === undefined && el.country === undefined && el.dayDate === undefined;
/**
* What a map is of. A map saved since revision 12 says so; one saved before
* it carries only `tripId`, and a country map (book-travel-looks.ts) or the
* small map an entry page opens with (`placeMap`) carries `tripId` null like a
* map of the whole journey. For those it is read off what the map holds, on
* the narrow side, since widening a map is the one answer that ruins a page:
*
* - one stop while the journey has more is a map of that stop;
* - one country and no recorded track (a country map never carries one),
* while the journey reaches other countries, is a map of that country.
*
* `inferred` says the answer was read rather than stored, so a refresh writes
* it down and the map says it from then on.
*/
export function bookMapScopeOf(
el: BookMapElement,
stats: JourneyStats | null,
): BookMapScopeParts & { inferred: boolean } {
const stored: BookMapScopeParts = {
tripId: el.tripId ?? null,
country: el.country ? el.country.toUpperCase() : null,
dayDate: el.dayDate ?? null,
stop: el.stop ?? null,
};
if (!fromBeforeScopes(el) || stored.tripId != null || !stats) return { ...stored, inferred: false };
const only = el.points.length === 1 ? el.points[0] : undefined;
if (only && stats.points.length > 1) {
return { ...stored, stop: { entryId: null, lat: only.lat, lng: only.lng }, inferred: true };
}
const code = el.countries.length === 1 ? el.countries[0]?.toUpperCase() : undefined;
const elsewhere = !!code && stats.countries.some((c) => c.code.toUpperCase() !== code);
if (code && elsewhere && el.points.length > 0 && el.path.length === 0) {
return { ...stored, country: code, inferred: true };
}
return { ...stored, inferred: false };
}
/**
* A map of one stop is current while the stop is where it was and shows the
* picture it showed. One that never had a picture (an entry page's dot) does
* not go stale over a photograph, and one whose stop has left the journey
* keeps its place rather than going blank.
*/
function stopIsStale(el: BookMapElement, live: readonly JourneyStatsPoint[]): boolean {
const now = live[0];
const had = el.points[0];
if (!now || !had) return false;
if (now.lat !== had.lat || now.lng !== had.lng) return true;
return had.photoId != null && (now.photoId ?? null) !== had.photoId;
}
const sameEnds = (a: readonly { lat: number; lng: number }[], b: readonly { lat: number; lng: number }[]) => {
@@ -70,7 +175,9 @@ export function isStale(el: BookElement, stats: JourneyStats | null): boolean {
}
if (el.kind === 'countries') return el.codes.join(',') !== stats.countries.map((c) => c.code).join(',');
if (el.kind !== 'map') return false;
const live = routeFor(stats, el.tripId);
const scope = bookMapScopeOf(el, stats);
const live = routeFor(stats, scope);
if (scope.stop) return stopIsStale(el, live);
if (el.points.length !== live.length) return true;
if (!el.points.length) return false;
if (!sameEnds(el.points, live)) return true;
@@ -88,11 +195,38 @@ function mapCountries(stats: JourneyStats, whole: boolean, route: readonly Journ
const mapPoints = (route: readonly JourneyStatsPoint[]) =>
route.map((p) => ({ lat: p.lat, lng: p.lng, label: p.label, photoId: p.photoId ?? null }));
/** What a map of these parts writes down beside its stops: only the parts that narrow it. */
function scopeFields(parts: BookMapScopeParts): Pick<Partial<BookMapElement>, 'country' | 'dayDate' | 'stop'> {
return {
...(parts.country ? { country: parts.country } : {}),
...(parts.dayDate ? { dayDate: parts.dayDate } : {}),
...(parts.stop ? { stop: parts.stop } : {}),
};
}
/** A map of one stop brought up to date: the stop where it is now, and its picture where it had one. */
function stopPatch(el: BookMapElement, stop: BookMapStop, live: readonly JourneyStatsPoint[]): Partial<BookElement> {
const now = live[0];
if (!now) return { stale: false, stop };
const had = el.points[0];
const photoId = had && had.photoId == null ? null : (now.photoId ?? null);
return {
stale: false,
stop: { entryId: now.entryId ?? stop.entryId, lat: now.lat, lng: now.lng },
points: [{ lat: now.lat, lng: now.lng, label: now.label.slice(0, MAX_MAP_POINT_LABEL), photoId }],
};
}
/**
* The patch that takes an element's values from the journey as it stands now,
* or null for an element that carries no journey figures. A country the
* element already had keeps the name it was given (the book's language); a
* new one takes the API's until someone places the element again.
*
* A map stays what it is of: a map of a country, a day or a stop is brought up
* to date inside that scope and never widened to the journey, and a map saved
* before revision 12 that reads as one (`bookMapScopeOf`) has its scope written
* down with the refresh.
*/
export function refreshPatch(el: BookElement, stats: JourneyStats): Partial<BookElement> | null {
if (el.kind === 'stats') return { stale: false, values: liveMetrics(stats) };
@@ -105,8 +239,17 @@ export function refreshPatch(el: BookElement, stats: JourneyStats): Partial<Book
return { stale: false, codes, names };
}
if (el.kind === 'map') {
const live = routeFor(stats, el.tripId);
return { stale: false, countries: mapCountries(stats, el.tripId == null, live), points: mapPoints(live) };
const scope = bookMapScopeOf(el, stats);
const live = routeFor(stats, scope);
if (scope.stop) return stopPatch(el, scope.stop, live);
const whole = scope.tripId == null && !scope.country && !scope.dayDate;
const countries = scope.country ? [scope.country] : mapCountries(stats, whole, live);
return {
stale: false,
...(scope.inferred ? scopeFields(scope) : {}),
countries: countries.slice(0, MAX_BOOK_COUNTRIES),
points: mapPoints(live.slice(0, MAX_MAP_POINTS)),
};
}
return null;
}
@@ -195,20 +338,61 @@ export function bookCountryName(code: string, locale: string, stats: JourneyStat
return (known || code.toUpperCase()).slice(0, MAX_COUNTRY_NAME);
}
/** Where a map is of: the whole journey or one trip, what a stored map's `tripId` can say. */
export type BookMapScope = 'journey' | { tripId: number };
/**
* Where a map is of: the whole journey, one trip, one country or one day (of
* a trip, where the journey has several on it), or one stop.
*/
export type BookMapScope =
| 'journey'
| { tripId: number }
| { country: string; tripId?: number | null }
| { dayDate: string; tripId?: number | null }
| { stop: BookMapStop };
/** A map of the journey or of a trip, drawn the way a new map is drawn. */
/** The parts a scope narrows a map by. */
function partsOf(scope: BookMapScope): BookMapScopeParts {
if (scope === 'journey') return UNSCOPED;
if ('stop' in scope) return { ...UNSCOPED, stop: scope.stop };
if ('country' in scope) return { ...UNSCOPED, tripId: scope.tripId ?? null, country: scope.country.toUpperCase() };
if ('dayDate' in scope) return { ...UNSCOPED, tripId: scope.tripId ?? null, dayDate: scope.dayDate };
return { ...UNSCOPED, tripId: scope.tripId };
}
/**
* The stop of an entry, for a map of it: where the journey's route has it,
* else where the entry itself says it is; null for an entry with no place.
*/
export function bookMapStopFor(
stats: JourneyStats | null,
entries: readonly AutoEntry[],
entryId: number,
): BookMapStop | null {
const onRoute = stats?.points.find((p) => p.entryId === entryId);
if (onRoute) return { entryId, lat: onRoute.lat, lng: onRoute.lng };
const entry = entries.find((e) => e.id === entryId);
return entry && entry.lat != null && entry.lng != null ? { entryId, lat: entry.lat, lng: entry.lng } : null;
}
/** The route of a map of these parts; a stop that has left the journey is still its own place. */
function scopedRoute(stats: JourneyStats, parts: BookMapScopeParts): JourneyStatsPoint[] {
const route = routeFor(stats, parts);
if (route.length || !parts.stop) return route;
const { lat, lng } = parts.stop;
return [{ lat, lng, label: '', date: null, country: null, tripId: null, photoId: null, entryId: parts.stop.entryId }];
}
/** A map of the journey, of a trip, a country, a day or a stop, drawn the way a new map is drawn. */
export function bookTravelMap(
ctx: BookTravelContext,
stats: JourneyStats,
input: { id: string; frame: BookFrame; scope: BookMapScope; source?: 'vector' | 'relief' | 'satellite' },
): BookMapElement {
const tripId = input.scope === 'journey' ? null : input.scope.tripId;
const route = routeFor(stats, tripId);
const parts = partsOf(input.scope);
const tripId = parts.stop ? null : parts.tripId;
const route = scopedRoute(stats, parts);
const imagery = input.source === 'relief' || input.source === 'satellite' ? BOOK_MAP_SOURCES[input.source] : null;
const whole = input.scope === 'journey';
const countries = mapCountries(stats, whole, route).slice(0, MAX_BOOK_COUNTRIES);
const countries = (parts.country ? [parts.country] : mapCountries(stats, whole, route)).slice(0, MAX_BOOK_COUNTRIES);
const path = whole ? ctx.path.slice(0, MAX_PATH_SEGMENTS) : [];
const points = mapPoints(route.slice(0, MAX_MAP_POINTS)).map((p) => ({
...p,
@@ -242,6 +426,7 @@ export function bookTravelMap(
fitToCountries: true,
clip: 'rect',
tripId,
...scopeFields(parts),
};
}
+40
View File
@@ -5,6 +5,7 @@ import {
bookLayoutSchema,
bookBadgeElementSchema,
bookIconElementSchema,
bookMapElementSchema,
bookSpreadSchema,
bookStatsElementSchema,
bookTextElementSchema,
@@ -281,3 +282,42 @@ describe('MAX_SPREAD_ELEMENTS', () => {
expect(bookSpreadSchema.safeParse({ id: 's1', parked: many(MAX_SPREAD_ELEMENTS + 1) }).success).toBe(false);
});
});
describe('what a map is of and shows (revision 12)', () => {
const frame = { x: 0, y: 0, w: 100, h: 80 };
const map = (over: Record<string, unknown> = {}) =>
bookMapElementSchema.parse({ id: 'm', kind: 'map', frame, ...over });
it('leaves the fields out of a map saved before them, so its scope can still be read off what it holds', () => {
const old = map();
for (const key of ['view', 'stop', 'country', 'dayDate', 'coastDetail']) expect(old).not.toHaveProperty(key);
});
it('keeps null as said, and a view across the antimeridian as one box', () => {
expect(map({ view: null, stop: null, country: null, dayDate: null, coastDetail: null })).toMatchObject({
view: null,
stop: null,
country: null,
dayDate: null,
coastDetail: null,
});
const fiji = { west: 176, south: -20, east: 185, north: -15 };
expect(map({ view: fiji }).view).toEqual(fiji);
expect(map({ stop: { lat: 1, lng: 2 } }).stop).toEqual({ entryId: null, lat: 1, lng: 2 });
});
it('drops a field that does not read rather than the map, and so rather than the book', () => {
const odd = map({
view: { west: 20, south: 0, east: 10, north: 5 },
stop: { lat: 200, lng: 0 },
country: 'ISL',
dayDate: '1.7.2026',
coastDetail: 'very',
});
for (const key of ['view', 'stop', 'country', 'dayDate', 'coastDetail']) {
expect(odd[key as keyof typeof odd], key).toBeUndefined();
}
expect(map({ view: { west: -180, south: -10, east: 540, north: 10 } }).view).toBeUndefined();
expect(map({ view: { west: -170, south: -10, east: 190, north: 10 } }).view).toMatchObject({ east: 190 });
});
});
+71
View File
@@ -427,6 +427,41 @@ const typeset = {
/** Kilometres or miles. Stored metric; the element converts when it draws. */
export const bookUnitsSchema = z.enum(['metric', 'imperial']);
/**
* A field a map owns since revision 12: absent on a map saved before it,
* null when it is not used, and dropped rather than failing the map when it
* does not read.
*/
const bookOwnField = <T extends z.ZodType>(schema: T) => schema.nullable().optional().catch(undefined);
/** The longitude a map's own view may run to in the east: one turn past the antimeridian. */
export const MAX_BOOK_VIEW_LNG = 540;
/** How finely a vector map draws the coast, `auto` first: what a map without the field does. */
export const BOOK_MAP_COAST_DETAILS = ['auto', 'simple', 'detailed'] as const;
export type BookMapCoastDetail = (typeof BOOK_MAP_COAST_DETAILS)[number];
/** A map's own view, in degrees, west to east and south to north. */
export const bookMapViewSchema = z
.object({
west: z.number().min(-180).max(MAX_BOOK_VIEW_LNG),
south: z.number().min(-90).max(90),
east: z.number().min(-180).max(MAX_BOOK_VIEW_LNG),
north: z.number().min(-90).max(90),
})
.refine((v) => v.east > v.west && v.east - v.west <= 360 && v.north > v.south, {
message: 'a view runs west to east, at most once round, and south to north',
});
export type BookMapView = z.infer<typeof bookMapViewSchema>;
/** The one stop a map shows: its entry, when it has one, and where it is. */
export const bookMapStopSchema = z.object({
entryId: z.number().int().positive().nullable().default(null),
lat: z.number().min(-90).max(90),
lng: z.number().min(-180).max(180),
});
export type BookMapStop = z.infer<typeof bookMapStopSchema>;
export const bookMapElementSchema = z.object({
...elementBase,
...typeset,
@@ -640,6 +675,42 @@ export const bookMapElementSchema = z.object({
* a map of Iceland back into a map of everywhere.
*/
tripId: z.number().int().positive().nullable().default(null),
/*
* ── What else a map can be of, and what it shows (revision 12) ────────
*
* Absent and null do not mean the same thing here, on purpose. A map saved
* before these fields existed has none of them, and what it was of has to be
* read off what it holds (`bookMapScopeOf` in book-travel.ts): a country map
* or the small map of an entry page carries `tripId` null like a map of the
* whole journey, and bringing it up to date must not turn it into one. A map
* written since says so, and null is then a plain "not narrowed this way".
* A value that does not read is dropped rather than losing the map.
*/
/**
* The ground the map shows, when someone framed it by hand: west, south,
* east and north in degrees. Null fits the map to its route as it always did.
* East may run past 180, up to 540, so a view across the antimeridian (Fiji,
* the Aleutians) is one box rather than two halves of the world.
*/
view: bookOwnField(bookMapViewSchema),
/**
* One stop of the journey alone, the map an entry page opens with: the
* entry it belongs to when it has one, and where it is, so the map keeps its
* place when the entry is gone.
*/
stop: bookOwnField(bookMapStopSchema),
/** The stops in one country (ISO-3166-1 alpha-2), the route there and nowhere else. */
country: bookOwnField(z.string().length(2)),
/** The stops of one day (`YYYY-MM-DD`), with `tripId` when the journey has several trips on it. */
dayDate: bookOwnField(z.string().regex(/^\d{4}-\d{2}-\d{2}$/)),
/**
* How finely the coast is drawn on the vector map. `simple` is the outline
* set every map draws, which leaves out islands below a share of their
* country; `detailed` loads each country's finer outline, Hawaii and the
* small islands included; `auto`, or nothing, takes the finer one when the
* route is regional or lies off the simple outline.
*/
coastDetail: bookOwnField(z.enum(BOOK_MAP_COAST_DETAILS)),
});
/** The looks of a summary, `classic` first: what every summary drew before there were looks. */
+19
View File
@@ -483,6 +483,25 @@ describe('describeSpread', () => {
expect(t).toMatch(/8\. badge b-1 at .*: date mark "13" over "June", plain; /);
expect(t).toMatch(/9\. list l-1 at .*: list of 2 \(1 pros, 1 others\), columns; /);
});
it('BOOKDESC-030: says what a map is of, a country, a day or a stop, and the ground it was framed to', () => {
const at = { x: 230, y: 20, w: 40, h: 30 };
const map = (id: string, over: Record<string, unknown>) =>
bookMapElementSchema.parse({ id, kind: 'map', frame: at, ...over }) as BookElement;
const els = [
map('m-c', { country: 'IS', view: { west: -25, south: 63, east: -13, north: 67 }, coastDetail: 'detailed' }),
map('m-d', { dayDate: '2026-06-06', tripId: 4 }),
map('m-s', { stop: { entryId: 7, lat: 64.1, lng: -21.9 }, coastDetail: 'auto' }),
map('m-o', { stop: { lat: 64.1, lng: -21.9 } }),
];
const t = describeSpread(book(els), 'sp-in', gallery)?.text ?? '';
expect(t).toMatch(
/map m-c at .*: minimal vector map of IS, 0 stops, 0 countries, framed to west -25 south 63 east -13 north 67, detailed coast;/,
);
expect(t).toMatch(/map m-d at .*: minimal vector map of the day 2026-06-06 of trip 4, 0 stops/);
expect(t).toMatch(/map m-s at .*: minimal vector map of the stop of entry 7, 0 stops, 0 countries;/);
expect(t).toMatch(/map m-o at .*: minimal vector map of one stop, /);
});
});
describe('summaries', () => {
+19 -2
View File
@@ -138,12 +138,29 @@ function travelWords(el: TravelElement): string {
return `${travelWhat(el)}; ${set}${stale}`;
}
/** What a map is of, in the words of its `add` scope; a map from before revision 12 by what it stores. */
function mapScopeWords(el: Extract<BookElement, { kind: 'map' }>): string {
const trip = el.tripId != null ? ` of trip ${el.tripId}` : '';
if (el.stop) return el.stop.entryId != null ? `the stop of entry ${el.stop.entryId}` : 'one stop';
if (el.country) return `${el.country}${trip}`;
if (el.dayDate) return `the day ${el.dayDate}${trip}`;
return el.tripId != null ? `trip ${el.tripId}` : 'the whole journey';
}
/** The ground a map was framed to by hand, and how finely it draws the coast when that was chosen. */
function mapViewWords(el: Extract<BookElement, { kind: 'map' }>): string {
const v = el.view;
const framed = v ? `, framed to west ${n(v.west)} south ${n(v.south)} east ${n(v.east)} north ${n(v.north)}` : '';
const coast = el.coastDetail && el.coastDetail !== 'auto' ? `, ${el.coastDetail} coast` : '';
return framed + coast;
}
function travelWhat(el: TravelElement): string {
switch (el.kind) {
case 'map': {
const scope = el.tripId != null ? `trip ${el.tripId}` : 'the whole journey';
const line = el.path.length ? `, a recorded track of ${el.path.length} segments` : '';
return `${el.style} ${el.source} map of ${scope}, ${el.points.length} stops, ${el.countries.length} countries${line}`;
const shown = `${el.points.length} stops, ${el.countries.length} countries${line}${mapViewWords(el)}`;
return `${el.style} ${el.source} map of ${mapScopeWords(el)}, ${shown}`;
}
case 'stats': {
const figures = el.metrics.map((m) => `${m} ${el.values[m] ?? 0}`).join(', ');
@@ -83,7 +83,7 @@
"B/fabric-classic/plan": "cae85517611abbca",
"B/fabric-classic/spread/0": "9da4b641b0f81264",
"B/fabric-classic/spread/1": "b3f8e9c5043f8302",
"B/fabric-classic/spread/2": "5951c4e8d72b4b3f",
"B/fabric-classic/spread/2": "61f0914a7ee1fabf",
"B/fabric-classic/spread/3": "bdb01dc38f94e0d0",
"B/fabric-classic/spread/4": "4e949ebeb4098598",
"B/fabric-classic/spread/5": "fa7289a87111f6a2",
@@ -96,7 +96,7 @@
"B/midnight/spread/0": "ee90988cd45ab2c4",
"B/midnight/spread/1": "d9f5d78659332b45",
"B/midnight/spread/10": "db97ebe8475e0371",
"B/midnight/spread/2": "a094503b82019808",
"B/midnight/spread/2": "4fd4d34f9ab77551",
"B/midnight/spread/3": "b9fb3f915cffb57d",
"B/midnight/spread/4": "9f0467b6921de638",
"B/midnight/spread/5": "7e3d7de6ef19180c",
@@ -108,7 +108,7 @@
"B/riso/plan": "d8906a53b3532db8",
"B/riso/spread/0": "867edf084f05a873",
"B/riso/spread/1": "8de92788de29277b",
"B/riso/spread/2": "40f8d2b093d0fc8d",
"B/riso/spread/2": "66790d2283ba2f77",
"B/riso/spread/3": "1fc8aedc7486cbeb",
"B/riso/spread/4": "cedfcf22d3331d4a",
"B/riso/spread/5": "51562d8f08f46011",
@@ -176,7 +176,7 @@
"D/fabric-classic/spread/15": "b11b5b3fb34a34eb",
"D/fabric-classic/spread/16": "c40cdcb18e2ef0bc",
"D/fabric-classic/spread/2": "86dd9a101af346f4",
"D/fabric-classic/spread/3": "afe19cb105dfefa0",
"D/fabric-classic/spread/3": "1433b8ee15387e1b",
"D/fabric-classic/spread/4": "9fcb7ff2c09e7e05",
"D/fabric-classic/spread/5": "512f64afa749875d",
"D/fabric-classic/spread/6": "d909172ca9306881",
@@ -198,7 +198,7 @@
"D/midnight/spread/18": "eba329fd185958b3",
"D/midnight/spread/19": "6e6e6c877443c5e7",
"D/midnight/spread/2": "cef4235690d44e53",
"D/midnight/spread/3": "cd34cb85119476ee",
"D/midnight/spread/3": "3922eeb7ddb4c95a",
"D/midnight/spread/4": "f332e826ccb518b8",
"D/midnight/spread/5": "545524d900a6d68e",
"D/midnight/spread/6": "ea5db0eab1087429",
@@ -218,7 +218,7 @@
"D/riso/spread/16": "a748ada7a028818e",
"D/riso/spread/17": "ed87c0a4c77f241c",
"D/riso/spread/2": "78f24755fb7ad38a",
"D/riso/spread/3": "047741da3e1adc20",
"D/riso/spread/3": "d26d68d5f33114d7",
"D/riso/spread/4": "42d13c4cc22154a9",
"D/riso/spread/5": "c2dcc1ba31041587",
"D/riso/spread/6": "93846db9c48faa0f",
@@ -1,5 +1,5 @@
import type { AutoEntry } from '../auto/auto-types';
import type { BookTravelContext } from '../book-travel';
import { refreshPatch, type BookTravelContext } from '../book-travel';
import { bookElementSchema, bookPageSetupSchema, type BookElement } from '../book.schema';
import type { JourneyStats } from '../journey-stats.schema';
import { bookThemeColor, bookThemeOf } from '../theme/book-theme';
@@ -161,6 +161,10 @@ describe('the travel looks', () => {
expect(map.points).toHaveLength(2);
expect(map).toMatchObject({ clip: 'country', style: 'dark', pinStyle: 'numbered' });
expect(looks.countryMapEl('IS', 'box')).toMatchObject({ clip: 'rect', style: 'minimal' });
// It says it is of the country, so bringing it up to date keeps the country (revision 12).
expect(map).toMatchObject({ country: 'IS', countries: ['IS'], tripId: null, path: [] });
expect(refreshPatch(map, stats)).toMatchObject({ countries: ['IS'] });
expect((refreshPatch(map, stats) as { points: unknown[] }).points).toHaveLength(2);
expect(looks.countryName('PT')).toBe('Portugal');
});
});
+2 -7
View File
@@ -203,15 +203,10 @@ export function bookTravelLooks({ page, stats, travel, theme, newId, place }: Bo
* satellite picture, or the country in a box.
*/
const countryMapEl = (code: string, kind: 'shape' | 'satellite' | 'box', frame?: BookFrame): BookElement => {
const own: JourneyStats = {
...stats,
points: stats.points.filter((p) => p.country === code),
countries: stats.countries.filter((c) => c.code === code),
};
const ctx: BookTravelContext = { ...travel, stats: own, path: [], entries: [] };
const source = kind === 'satellite' ? 'satellite' : 'vector';
const at = frameFor(bookTravelSize('map', page), frame);
const el = bookTravelMap(ctx, own, { id: newId('mp'), frame: at, scope: 'journey', source });
// A map of the country, so bringing it up to date keeps it the country rather than the journey (revision 12).
const el = bookTravelMap(travel, stats, { id: newId('mp'), frame: at, scope: { country: code }, source });
// Cut to its shape on the paper, the land is dark, so the silhouette reads and the route in the accent stands on it.
const style = kind === 'shape' ? 'dark' : 'minimal';
const shaped = {