mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 13:23:04 +00:00
a7b53988ff
The travel tab is four tabs now, figures, maps, countries and marks, and offers only the newer looks, each dressed in the book's theme and linked to it. The looks books already hold still draw on their pages exactly as before; they are just no longer offered. - Figures: a summary as a poster, a ticket, tiles, a road sign, an odometer, a handwritten note, a pencil sketch or a band, and each figure on its own as a medal, on odometer drums or ringed by hand. - Maps: the route with its photographs, its stops numbered, its two ends marked or on a dark ground, over satellite or relief imagery, a map per trip, and a map of each country with its stops alone, cut to its shape. - Countries: each country as a passport stamp, a visa, an airmail postcard, its flag in cloth, a map pin, a luggage label or a sketch. - Marks: the date, the day, the distance, the coordinates and the flag as stamps, tags, pills, ribbons, die-cut stickers, embroidered patches and sketches. The schema gains a summary's and a country's look, seven mark styles and the numbered and ends stops of a map, all additive, as revision 11. Also in Studio: the save state is a tile beside who is here, a book a newer Studio saved is said by an overlay that holds the whole Studio until it reloads, and the page rail draws the first and the last page beside the blank inside of their cover. The notifications page and the bell's panel take the dialogs' look: a head with a tile, cards with an unread dot, and tools that come forward on hover.
98 lines
5.1 KiB
TypeScript
98 lines
5.1 KiB
TypeScript
import { normalizeBookDocument } from './book-normalize';
|
|
import type { BookDocument } from './book.schema';
|
|
|
|
/**
|
|
* Which revision of the book format a document was written by, and what a
|
|
* reader does with one that is newer than it knows.
|
|
*
|
|
* ── Why a revision beside `version` ──────────────────────────────────────
|
|
*
|
|
* `version` is the format itself and stays 1: every document ever saved
|
|
* reads under it, and nothing here asks for a migration. What grows is the
|
|
* vocabulary inside it, a new element kind, a new font, a new field the
|
|
* renderer draws, and an older reader cannot tell any of those from noise.
|
|
* `normalizeBookDocument` drops an element it cannot read and the contract
|
|
* strips a field it does not know, both on purpose, so a damaged book still
|
|
* opens. Saving what is left is the part that must not happen: an old tab, an
|
|
* offline copy or a replayed request would write the loss down for everyone.
|
|
*
|
|
* So the document says which revision wrote it. A reader that meets a newer
|
|
* one opens it read-only and asks for a reload, and the server refuses a save
|
|
* from a writer older than the book it would replace.
|
|
*
|
|
* ── When to bump ─────────────────────────────────────────────────────────
|
|
*
|
|
* `BOOK_SCHEMA_REV` goes up by one in the change that adds an element kind,
|
|
* an enum value or a drawn field to book.schema.ts, never for a change an
|
|
* older reader survives whole. A writer stamps its own revision on what it
|
|
* saves only once that is above 1, so a book saved today stores exactly what
|
|
* it stored before this existed.
|
|
*/
|
|
/**
|
|
* The revisions so far:
|
|
*
|
|
* - 2: the wider type, new families and weights (book-fonts.data.ts).
|
|
* - 3: paint on shapes and pages (`paint`, `backgroundPaint`, book-paint.schema.ts).
|
|
* - 4: the sticker kind (book-sticker.ts, stickers/).
|
|
* - 5: groups, names and hidden layers (`group`, `name`, `hidden`, a spread's `groups`).
|
|
* - 6: the photo look (`border`, `shadow`, `zoom`, `flipX`, `adjust`, `duotone`, `cutout`, book-photo-look.schema.ts).
|
|
* - 7: the second shelf of shapes, the cut edge of a shape and a photo (`edge`, `edgeSize`,
|
|
* book-shapes-more.ts) and the line kind (book-line.schema.ts).
|
|
* - 8: themes (the document's `theme`, and the `token`, `strokeToken`, `accentToken`,
|
|
* `fontRole` and `backgroundToken` links, theme/book-theme.schema.ts).
|
|
* - 9: text effects and fitting (`transform`, `vAlign`, `outline`, `shadow`, `highlight`,
|
|
* `curve`, `fillPaint`, `fit`, `fitMax`, book-text-effects.schema.ts), text up to 400 pt and
|
|
* tracking up to 1.5 em.
|
|
* - 10: letters filled with a gradient or a pattern (`fillPaint` of type `linear`, `radial`,
|
|
* `pattern`, book-text-effects.schema.ts).
|
|
* - 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.
|
|
*/
|
|
export const BOOK_SCHEMA_REV = 11;
|
|
|
|
/** 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';
|
|
|
|
/**
|
|
* The revision a document says it was written by, read from the raw value
|
|
* rather than the parsed one: a document so new that it fails to parse whole
|
|
* still says how new it is. Anything that is not a whole number from 1 up,
|
|
* and every document from before the field, reads as 1.
|
|
*/
|
|
export function bookSchemaRev(raw: unknown): number {
|
|
if (!raw || typeof raw !== 'object') return 1;
|
|
const rev = (raw as { schemaRev?: unknown }).schemaRev;
|
|
return typeof rev === 'number' && Number.isInteger(rev) && rev >= 1 ? rev : 1;
|
|
}
|
|
|
|
/** Whether a document was written by a newer revision than `readerRev` (this build's by default). */
|
|
export function isBookNewerThanReader(raw: unknown, readerRev: number = BOOK_SCHEMA_REV): boolean {
|
|
return bookSchemaRev(raw) > readerRev;
|
|
}
|
|
|
|
/**
|
|
* The document as a writer of `writerRev` saves it: stamped with that
|
|
* revision, unless it already says as much or more. A document at revision 1
|
|
* is handed back as it is, so nothing changes on disk until the first bump.
|
|
*/
|
|
export function stampBookSchemaRev<T extends BookDocument>(doc: T, writerRev: number = BOOK_SCHEMA_REV): T {
|
|
return bookSchemaRev(doc) >= writerRev ? doc : { ...doc, schemaRev: writerRev };
|
|
}
|
|
|
|
/** A stored document as a reader holds it: normalised, and whether it was written by a newer revision. */
|
|
export interface BookRead {
|
|
document: BookDocument;
|
|
/** True when the document is newer than the reader: show it, never save it. */
|
|
newer: boolean;
|
|
}
|
|
|
|
/**
|
|
* Read a stored document the way normalizeBookDocument does, and say whether
|
|
* it is newer than this reader. The normalised copy of a newer book has lost
|
|
* what this build cannot read, which is why `newer` has to travel with it.
|
|
*/
|
|
export function readBookDocument(raw: unknown, readerRev: number = BOOK_SCHEMA_REV): BookRead {
|
|
return { document: normalizeBookDocument(raw), newer: isBookNewerThanReader(raw, readerRev) };
|
|
}
|