master @ 23 LINES
[ HISTORY ] [ UP ]
┌─ TS ───────────────────────────────────────────────────────────────────────┐
│ // Toast frame builder. Runs in the browser (bundled into the Toast │
│ // component script), so it stays pure and small. │
│ import { box, len, wrap } from "../../lib/ascii"; │
│ import { STATUS_TAG, type StatusVariant } from "../Status/Status"; │
│ │
│ export const TOAST_W = 36; │
│ │
│ declare global { │
│ interface Window { │
│ ooknetToast?: (message: string, variant?: StatusVariant) => void; │
│ } │
│ } │
│ │
│ export function buildToast(message: string, variant: StatusVariant = "ok"): string │
│ { │
│ const tag = STATUS_TAG[variant]; │
│ const msg = message.replace(/\s+/g, " ").trim().toUpperCase(); │
│ const bodyW = TOAST_W - 4 - len(tag) - 1; │
│ const lines = wrap(msg, bodyW) │
│ .split("\n") │
│ .map((l, i) => (i === 0 ? ` ${tag} ${l}` : ` ${" ".repeat(len(tag))} ${l}`)); │
│ return box({ width: TOAST_W, lines, align: "end" }); │
│ } │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ TS ─────────────────────────────────┐
│ // Toast frame builder. Runs in the browser │
│ (bundled into the Toast │
│ // component script), so it stays pure and s │
│ mall. │
│ import { box, len, wrap } from "../../lib/as │
│ cii"; │
│ import { STATUS_TAG, type StatusVariant } fr │
│ om "../Status/Status"; │
│ │
│ export const TOAST_W = 36; │
│ │
│ declare global { │
│ interface Window { │
│ ooknetToast?: (message: string, variant? │
│ : StatusVariant) => void; │
│ } │
│ } │
│ │
│ export function buildToast(message: string, │
│ variant: StatusVariant = "ok"): string { │
│ const tag = STATUS_TAG[variant]; │
│ const msg = message.replace(/\s+/g, " ").t │
│ rim().toUpperCase(); │
│ const bodyW = TOAST_W - 4 - len(tag) - 1; │
│ const lines = wrap(msg, bodyW) │
│ .split("\n") │
│ .map((l, i) => (i === 0 ? ` ${tag} ${l}` │
│ : ` ${" ".repeat(len(tag))} ${l}`)); │
│ return box({ width: TOAST_W, lines, align: │
│ "end" }); │
│ } │
└──────────────────────────────────────────────┘
──────────────────────────────────────────────────────────────────────────────────────
OOKNET
────────────────────────────────────────────────
OOKNET