// SPDX-License-Identifier: MIT // Copyright (C) 2026 Pooya Parsa // The page's alerts, sheets and cards, in the manner of macOS alerts // (style.css .alert, .btn): a flat surface with a thin // even edge, a soft shadow and a 16 px radius; the unkernel mark on top (with // a caution, error or pause badge), a semibold centred title, a smaller muted // message, an optional detail line (a URL, in mono), an optional body, and // rounded buttons side by side, stacked once their labels do not fit (the // default one on top). Geist Sans at 13 px; 44 px buttons on coarse pointers. // - Dialog: a native modal (the top layer, the page under it inert, // focus kept in it and given back when it closes, ::backdrop a light dim): // open follows the prop, pointer lock is released first (the pointer must // reach the buttons), Esc (and a close the browser forces) calls onCancel, // and keys typed in it go no further (no terminal, display or guest sees // them; the page's capture listeners leave dialogs alone). // - Alert: a question in a Dialog with OK and Cancel, as ui.ask() asks it // (Overlays.tsx Confirm). OK has the focus; Enter on anything but another // button, and y with `yesNo`, confirm; n and Esc cancel. A held key's // repeats and a Space released that was pressed before the question // appeared do nothing. `untrusted` (the guest asks): OK, Enter and y work // only UNTRUSTED_MS after the question appeared (OK is dimmed, not disabled, // which would lose the focus), so a key or a click meant for the terminal // cannot confirm it. // - AlertContent, AlertIconView, AlertButton: the parts, for cards that are // not modal: the Resume card and the toast (Overlays.tsx), and ErrorCard, // a failure with its hint and actions (the boot failure's card). import { useEffect, useRef, useState, type ComponentProps, type KeyboardEvent, type ReactNode } from "react"; import { capitalize } from "../format.ts"; import { Mark } from "./icons.tsx"; /** The icon over the title: the mark, or the mark with a badge. */ export type AlertIcon = "mark" | "caution" | "error" | "pause"; /** Widths: alert 280 px (a question), wide 360 px (a URL, a failure), sheet 440 px (a body to type in). */ export type AlertSize = "alert" | "wide" | "sheet"; /** How long OK waits before it confirms, for a question from the guest. */ export const UNTRUSTED_MS = 700; const SIZE: Record = { alert: "", wide: "alert-wide", sheet: "alert-sheet" }; const BADGES: Record, ReactNode> = { caution: <> , error: <> , pause: <> , }; /** The mark, 48 px, with its badge at the bottom right. */ export function AlertIconView({ icon, size = 48 }: { icon: AlertIcon; size?: number }) { return ( ); } /** A button of an alert or card: primary (white, or black), danger (red) or secondary (quiet). */ export function AlertButton({ kind = "secondary", className = "", ...rest }: ComponentProps<"button"> & { kind?: "primary" | "danger" | "secondary" }) { const tone = kind === "primary" ? "btn-primary" : kind === "danger" ? "btn-danger" : ""; return