/** * A page sketch: a page written as indented text, with four primitives. * * ``` * --- /about a route: what follows is the page at /about * # Our people text (a heading: #, ## or ###) * We are 40 people in Oslo. text (a paragraph) * [image: Team photo] placeholder: [kind] or [kind: label] * [hero: Roof](image: /a.jpg) a placeholder with an image (or video) in it * icon hero M3 5h18v14H3z how every [hero] box is drawn: SVG path data * row its children side by side * col its children stacked; columns share a row * ## Design equally * col * [button: Join us] * ``` * * A sketchpad is not one page's: a route divider starts the part about a * page, so one sketch can cover a page and the two it links to. * * It is a scratch pad, not a layout language: it says WHAT is on a page and * roughly WHERE, so an assistant and a person can agree on a page's content * before anyone worries about how it looks. The person never sees this text, * only the page it describes; the assistant never sees the page, only this. * So the two have to be the same thing, and the format is STRICT: there is * exactly one way to write what is on the screen. `checkSketch` is that * rule, and the server refuses a write that breaks it, with the line to fix. * * Parsing is still forgiving, so a sketch that breaks the rule shows what it * can rather than nothing; that is for reading, never for accepting. * * A placeholder's kind is any word, and nothing here knows what one means. The * assistant that writes the sketch also draws each kind's icon, as path data * in a 24 by 24 box, so a kind nobody thought of looks as deliberate as an * image. Media put in a box is written into the text too, so the assistant * that builds the page reads it exactly as the person left it. */ export type SketchNode = SketchRoute | SketchRow | SketchCol | SketchText | SketchPlaceholder; /** The start of the part about one page. Only at the top level. */ export type SketchRoute = { type: "route"; line: number; /** The page's route as the site serves it: `/about`, `/blog/[slug]`. */ route: string; }; export type SketchRow = { type: "row"; line: number; children: SketchNode[]; }; /** Columns share their row equally: a sketch says what, not how wide. */ export type SketchCol = { type: "col"; line: number; children: SketchNode[]; }; export type SketchText = { type: "text"; line: number; /** 0 is a paragraph; 1-3 are headings. */ level: 0 | 1 | 2 | 3; text: string; }; export type SketchPlaceholder = { type: "placeholder"; line: number; kind: string; label: string | null; media: SketchMedia | null; }; /** * `src` names a file the project has, never a guess: its `path` exactly as * the content has it (`/public/val/hero.webp`, or its remote URL), or an * image uploaded to the assistant's session, `session:`. Which files * those are is the Studio's to check; the text only holds the name. */ export type SketchMedia = { type: "image" | "video"; src: string; }; /** The prefix of a `src` that is an image in the assistant's session. */ export declare const SESSION_MEDIA_PREFIX = "session:"; export type SketchError = { /** 1-based, like an editor's gutter. */ line: number; message: string; }; export type ParsedSketch = { /** The page itself is a column. */ blocks: SketchNode[]; /** * SVG path data by kind, lower case. Drawn as a 24 by 24 line icon: stroked * in the text colour, not filled. */ icons: Record; errors: SketchError[]; }; export declare function parseSketch(source: string): ParsedSketch; /** * The line a text block is written as. Line breaks become spaces, and a * paragraph that would read as something else is kept as text with `\`. */ export declare function formatSketchText(level: SketchText["level"], text: string): string; /** The line a placeholder is written as. */ export declare function formatSketchBox(placeholder: Pick): string; /** * The ONE way of writing `blocks` and `icons`: what `checkSketch` holds every * other text to, and what the Studio's editor writes (its own serializer is * tested against this one). Two spaces per level; an empty row gets an empty * col, so it has somewhere to type; a col outside a row is written as its * contents, which is all it shows; the icons last, after one blank line, and * no blank line anywhere else; a final newline. Empty text is not written -- * it is not on the page. */ export declare function formatSketch(blocks: SketchNode[], icons: Record): string; /** The pages a sketch is about, in the order it gives them. */ export declare function sketchRoutes(blocks: SketchNode[]): string[]; /** * What a list names a sketch by: its first top-level heading, the biggest * one first. Null for a sketch with no heading, which a list then names by * its page. */ export declare function sketchTitle(blocks: SketchNode[]): string | null; /** * Everything wrong with `source`, or nothing when it is a sketch exactly as * `formatSketch` writes it. * * Strict on purpose. The person sees the page and the assistant sees the * text, so a text with two spellings of one page -- a tab or two spaces, an * icon line here or there, a blank line or none -- is a text the assistant * cannot trust to be what is on the screen, and that would show it a change * nobody made the next time the Studio writes it back. Holding every write * to the one spelling rules all of that out at once. * * The parse errors come first; past those, the first line that is spelled * differently, with how it should be spelled. */ export declare function checkSketch(source: string): SketchError[];