// An app's frame, as its app file's `frame` declares it (docs/views.md, // "The frame"; HUD checks it as it loads the file, schemas/ // place.hud.frame.json): the app's tabs as its destinations, its one // primary action, the account's area (its picture on a tab, its items, // signing out and in), the links at its foot, an aside, and how wide its // column and its navigation's bands are. An app with none is drawn with // every default, its tabs alone. // // Navigation follows the window's width, in three bands: a bar along the // foot under `bands.rail`, an icon rail from there, a sidebar with words // from `bands.sidebar`. The band is the stylesheet's to decide (`frameCss`, // custom properties by media query, which the components read), never // code's, so the page the server draws is the one the browser hydrates, // whatever the window. The screen on top says how wide it is drawn (its // view's `measure`): the column (`sizes.content`), all the room right of // the navigation up to `sizes.wide`, or that to the window's edge; an // aside is drawn right of the column only where the window holds the // navigation, the screen's measure and the aside. import type { Call } from '@hud/shared/result'; import type { IconName } from '@hud/renderer'; import type { Measure } from './app'; /** What the host does itself, as an account item: sign the account out, or (signed out) in. */ export type HostItem = { host: 'signOut' | 'signIn'; label?: string; icon?: IconName; about?: string }; /** A screen of the app's in the account's area (Settings), drawn signed in. */ export type CallItem = { label: string; icon: IconName; call: Call }; export type AccountItem = HostItem | CallItem; export type Frame = { /** The destinations: the app's tabs. */ destinations?: 'tabs'; /** The app's one primary action: a call whose screen opens at a form (a query's `compose`), that form alone opened over the screen on show; else its screen, opened on the tab on show. */ action?: { label: string; icon: IconName; call: Call }; account?: { /** The account's picture, on the tab `tab` in place of its icon: a query's answer (`call`, made as each of the browser's accounts), the picture's URL at `at` in it, and the account's name and handle at `name` and `handle`, for its row among the accounts (a view's `Accounts`). */ picture?: { tab: string; call: Call; at: string; name?: string; handle?: string }; items?: AccountItem[]; }; /** Links at the navigation's foot: a path of the app's, or an https URL, opened as a page. */ links?: { label: string; href: string }[]; /** A screen drawn beside the column, where it fits: its call, and how wide it is (320). */ aside?: { call: Call; width?: number }; /** How wide the column is (`content`, 600) and a wide screen at most (`wide`, 935), in CSS pixels. */ sizes?: { content?: number; wide?: number }; /** The window widths the navigation becomes a rail at (600) and a sidebar at (1200). */ bands?: { rail?: number; sidebar?: number }; }; /** How wide the rail and the sidebar are. */ export const RAIL = 72; export const SIDEBAR = 245; /** A frame's every size, its defaults filled, and the host's bands over its own. */ export type Layout = { rail: number; sidebar: number; content: number; wide: number; aside: number | null }; /** A frame's layout: the host's `bands` (a host may draw its navigation at its own widths), else the frame's, else the defaults. */ export function layoutOf(frame: Frame | undefined, bands?: Frame['bands']): Layout { const content = frame?.sizes?.content ?? 600; return { rail: bands?.rail ?? frame?.bands?.rail ?? 600, sidebar: bands?.sidebar ?? frame?.bands?.sidebar ?? 1200, content, wide: Math.max(content, frame?.sizes?.wide ?? 935), aside: frame?.aside ? (frame.aside.width ?? 320) : null }; } /** The room right of the navigation at most: a wide screen's, or the column's and the aside's where that is more. */ const roomOf = (layout: Layout) => Math.max(layout.wide, layout.content + (layout.aside ?? 0)); /** The navigation's bands, each from where it starts to before the next: its width, and whether the tab bar or the side navigation draws. */ function bands(layout: Layout) { return [ { from: 0, to: layout.rail, nav: 0 }, { from: layout.rail, to: layout.sidebar, nav: RAIL }, { from: layout.sidebar, to: Infinity, nav: SIDEBAR } ]; } /** A media query of a range of window widths. */ function media(from: number, to: number): string { const parts = [from > 0 ? `(min-width: ${from}px)` : '', to < Infinity ? `(max-width: ${to - 0.02}px)` : ''].filter(Boolean); return `@media ${parts.join(' and ')}`; } /** A string as CSS writes one, quoted: its quote, backslash, line breaks and `<` (the sheet is the page's own `