{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "toast",
  "title": "Toast",
  "description": "One line rises from the bottom-left; a fermata held over its last word empties while it stays.",
  "registryDependencies": [
    "https://thedirectors.agency/ui/r/0nlytype.json",
    "https://thedirectors.agency/ui/r/button.json"
  ],
  "files": [
    {
      "path": "registry/0nlytype/ui/toast.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { Button } from \"@/components/ui/button\"\n\ntype ToastOptions = {\n  /** An action keeps its name: \"Undo\", then the toast says what happened. */\n  action?: { label: string; onClick: () => void }\n  /** How long it stays, in milliseconds. Pointing at it holds the pause. */\n  duration?: number\n}\n\ntype ToastVariant = \"fermata\" | \"footnote\" | \"dateline\"\n\ntype ToastItem = {\n  id: string\n  message: React.ReactNode\n  action?: ToastOptions[\"action\"]\n  duration: number\n  leaving: boolean\n  /** The footnote's number: counts up while notes stand, and starts again at 1 on an empty page. */\n  n: number\n  at: number\n}\n\n// A tiny module-level store: toast() can be called from anywhere, <Toaster /> renders it.\nlet items: ToastItem[] = []\nlet count = 0\n// Every mounted Toaster, in mount order. Only the latest one shows and announces the toasts, so a page that\n// mounts its own Toaster inside an app that already has one doesn't say everything twice.\nlet toasters: string[] = []\nconst listeners = new Set<() => void>()\nconst none: ToastItem[] = []\n\nfunction set(next: ToastItem[]) {\n  items = next\n  listeners.forEach((l) => l())\n}\n\n/** Say one thing, once. Returns the id, for dismiss(). At most three stay on screen. */\nfunction toast(message: React.ReactNode, opts: ToastOptions = {}): string {\n  const id = `toast-${++count}`\n  const n = (items.at(-1)?.n ?? 0) + 1\n  set([...items, { id, message, action: opts.action, duration: opts.duration ?? 5000, leaving: false, n, at: Date.now() }].slice(-3))\n  return id\n}\n\n/** Send one toast away (or all of them). It sinks, then it is removed. */\nfunction dismiss(id?: string) {\n  set(items.map((t) => (id === undefined || t.id === id ? { ...t, leaving: true } : t)))\n}\n\nconst remove = (id: string) => set(items.filter((t) => t.id !== id))\nconst subscribe = (l: () => void) => (listeners.add(l), () => void listeners.delete(l))\nconst speaker = () => toasters.at(-1)\nconst clock = (at: number) => new Intl.DateTimeFormat(undefined, { hour: \"2-digit\", minute: \"2-digit\" }).format(at)\n\ntype ToastProps = Omit<React.ComponentProps<\"div\">, \"id\"> &\n  Partial<Omit<ToastItem, \"message\">> & { message: React.ReactNode; variant?: ToastVariant }\n\n/** One toast. <Toaster /> renders these from the store; render one yourself only to show it still (documentation). */\nfunction Toast({ id = \"\", message, action, duration = 5000, leaving = false, n = 1, at, variant = \"fermata\", className, style, ...props }: ToastProps) {\n  return (\n    <div\n      data-slot=\"toast\"\n      data-leaving={leaving || undefined}\n      className={cn(\"ot-toast\", className)}\n      style={{ \"--life\": `${duration}ms`, ...style } as React.CSSProperties}\n      onAnimationEnd={(e) => {\n        if (leaving && e.target === e.currentTarget) remove(id)\n      }}\n      {...props}\n    >\n      {variant === \"footnote\" ? <sup className=\"ot-toast-n\" aria-hidden=\"true\">{n}</sup> : null}\n      <p data-slot=\"toast-message\">{message}</p>\n      {/* The timer is a fermata held over the sentence's last note: its arc empties, and when it's gone so is the toast.\n          The footnote and the dateline keep it, unseen, as their clock. */}\n      <svg\n        data-slot=\"toast-timer\"\n        className=\"ot-toast-timer\"\n        viewBox=\"0 0 22 14\"\n        aria-hidden=\"true\"\n        onAnimationEnd={() => dismiss(id)}\n      >\n        <path d=\"M2 12.5 A9 9 0 0 1 20 12.5\" pathLength=\"1\" strokeDasharray=\"1\" />\n        <circle cx=\"11\" cy=\"10.4\" r=\"1.9\" />\n      </svg>\n      {variant === \"dateline\" ? (\n        <>\n          <span className=\"ot-toast-rule\" aria-hidden=\"true\" />\n          <time className=\"ot-toast-time\" suppressHydrationWarning dateTime={new Date(at ?? 0).toISOString()}>{at === undefined ? \"\" : clock(at)}</time>\n        </>\n      ) : null}\n      {action ? (\n        <Button\n          data-slot=\"toast-action\"\n          variant=\"bracket\"\n          onClick={() => {\n            dismiss(id)\n            action.onClick()\n          }}\n        >\n          {action.label}\n        </Button>\n      ) : null}\n    </div>\n  )\n}\n\ntype ToasterProps = React.ComponentProps<\"section\"> & {\n  /**\n   * fermata: each toast is framed, with a fermata over its last word whose arc empties while it stays.\n   * footnote: notes at the foot of the page under a short rule, numbered as they come.\n   * dateline: the sentence and the time it happened on one hairline, which runs out toward the time.\n   */\n  variant?: ToastVariant\n}\n\n/** Render once, near the root. Toasts rise from the bottom-left and are announced politely. If more than one is mounted, the latest speaks and the rest stay quiet. */\nfunction Toaster({ className, variant = \"fermata\", ...props }: ToasterProps) {\n  const me = React.useId()\n  React.useEffect(() => {\n    toasters = [...toasters, me]\n    listeners.forEach((l) => l())\n    return () => {\n      toasters = toasters.filter((t) => t !== me)\n      listeners.forEach((l) => l())\n    }\n  }, [me])\n  const all = React.useSyncExternalStore(subscribe, () => items, () => none)\n  const list = React.useSyncExternalStore(subscribe, speaker, () => undefined) === me ? all : none\n  return (\n    <section\n      data-slot=\"toaster\"\n      data-variant={variant === \"fermata\" ? undefined : variant}\n      role=\"status\"\n      aria-live=\"polite\"\n      aria-label=\"Notifications\"\n      className={cn(\"ot-toaster\", className)}\n      {...props}\n    >\n      {list.map((item) => (\n        <Toast key={item.id} {...item} variant={variant} />\n      ))}\n    </section>\n  )\n}\n\nexport { toast, dismiss, Toast, Toaster, type ToastOptions, type ToastVariant }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/0nlytype/styles/toast.css",
      "content": "@layer components {\n  /* ── ot-toast ── one line rises; a fermata held over its last word empties while it stays */\n  .ot-toaster { position: fixed; z-index: 50; inset-inline-start: var(--ot-margin); inset-block-end: var(--ot-space-6); display: grid; justify-items: start; gap: var(--ot-space-2); pointer-events: none; }\n  .ot-toast {\n    position: relative; pointer-events: auto;\n    display: flex; flex-wrap: wrap; align-items: baseline; column-gap: var(--ot-space-5); row-gap: var(--ot-space-2);\n    max-inline-size: min(34rem, calc(100vw - 2 * var(--ot-margin)));\n    padding: var(--ot-space-4) var(--ot-space-5) calc(var(--ot-space-4) + 2px);\n    background: var(--ot-paper); box-shadow: inset 0 0 0 var(--ot-hairline) var(--ot-rule);\n    color: var(--ot-ink);\n    animation: ot-toast-rise var(--ot-andante) var(--ot-exhale);\n  }\n  /* The timer is a fermata over the sentence's last note: its arc empties while the toast stays. Point at the\n     toast and the pause is held, which is what a fermata means. It hangs up against the full stop, the way the\n     sign is written over the note it holds. */\n  .ot-toast-timer { flex: none; align-self: flex-start; width: 22px; height: 14px; margin-inline-start: calc(var(--ot-space-1) - var(--ot-space-5)); margin-block-start: -0.1em; overflow: visible; }\n  .ot-toast-timer path { fill: none; stroke: var(--ot-ink); stroke-width: 1.5; stroke-linecap: round; animation: ot-toast-deplete var(--life, 5s) linear forwards; }\n  .ot-toast-timer circle { fill: var(--ot-accent); }\n  .ot-toast:is(:hover, :focus-within, [data-force~=\"hover\"]) :is(.ot-toast-timer path, .ot-toast-rule) { animation-play-state: paused; }\n  .ot-toast > p { animation: ot-toast-write var(--ot-andante) var(--ot-exhale) 140ms backwards; }\n  .ot-toast[data-leaving] { overflow: clip; animation: ot-toast-sink var(--ot-andante) var(--ot-breath) forwards; }\n  @keyframes ot-toast-rise { from { opacity: 0; translate: 0 12px; } }\n  @keyframes ot-toast-write { from { clip-path: inset(0 100% 0 0); } }\n  :is([dir=\"rtl\"], [dir=\"rtl\"] *).ot-toast > p { animation-name: ot-toast-write-rtl; }\n  @keyframes ot-toast-write-rtl { from { clip-path: inset(0 0 0 100%); } }\n  @keyframes ot-toast-sink {\n    45%  { opacity: 0; translate: 0 8px; }\n    100% { opacity: 0; translate: 0 8px; block-size: 0; padding-block: 0; margin-block-start: calc(-1 * var(--gap, var(--ot-space-2))); }\n  }\n  @keyframes ot-toast-deplete { to { stroke-dashoffset: -1; } }\n\n  /* The footnote and the dateline keep the fermata as their clock, unseen. */\n  .ot-toaster[data-variant] .ot-toast-timer { position: absolute; inset: 0 auto auto 0; width: 1px; height: 1px; margin: 0; opacity: 0; }\n\n  /* Footnote: the book's note at the foot of the page. One frame holds the foot: a short rule, then the notes,\n     numbered as they come; each number hangs in the margin so the sentences keep one edge under the rule. The\n     newest number takes the accent. */\n  .ot-toaster[data-variant=\"footnote\"] { --gap: 0px; gap: 0; }\n  .ot-toaster[data-variant=\"footnote\"]:has(> .ot-toast) { padding: var(--ot-space-4) var(--ot-space-5) var(--ot-space-4) var(--ot-space-6); background: var(--ot-paper); box-shadow: inset 0 0 0 var(--ot-hairline) var(--ot-rule); max-inline-size: min(34rem, calc(100vw - 2 * var(--ot-margin))); }\n  .ot-toaster[data-variant=\"footnote\"]:has(> .ot-toast)::before { content: \"\"; inline-size: var(--ot-space-8); block-size: var(--ot-hairline); margin-block-end: var(--ot-space-3); background: var(--ot-ink); transform-origin: 0 50%; animation: ot-draw-x var(--ot-andante) var(--ot-exhale) backwards; }\n  :is([dir=\"rtl\"], [dir=\"rtl\"] *).ot-toaster[data-variant=\"footnote\"]::before { transform-origin: 100% 50%; }\n  .ot-toaster[data-variant=\"footnote\"] .ot-toast { column-gap: var(--ot-space-4); padding: var(--ot-space-1) 0; box-shadow: none; background: none; color: var(--ot-graphite); }\n  .ot-toast-n { position: absolute; inset-inline-end: calc(100% + 0.35em); inset-block-start: calc(var(--ot-space-1) + 0.1em); font-size: var(--ot-pp); line-height: 1; font-feature-settings: \"lnum\", \"tnum\"; color: var(--ot-pencil); animation: ot-land var(--ot-moderato) var(--ot-spiccato) 160ms backwards; }\n  .ot-toast:last-child .ot-toast-n { color: var(--ot-accent); }\n\n  /* Dateline: the frame row of a poster. The sentence, a hairline, the time it happened; the hairline runs out\n     toward the time while the toast stays, and holds while you point at it. */\n  .ot-toaster[data-variant=\"dateline\"] { grid-template-columns: minmax(0, 1fr); }\n  .ot-toaster[data-variant=\"dateline\"] .ot-toast { column-gap: var(--ot-space-4); inline-size: min(30rem, calc(100vw - 2 * var(--ot-margin))); max-inline-size: 100%; }\n  .ot-toaster[data-variant=\"dateline\"] .ot-toast > p { flex: none; max-inline-size: 70%; }\n  .ot-toast-rule { flex: 1; min-inline-size: var(--ot-space-5); block-size: var(--ot-hairline); align-self: center; background: var(--ot-rule-strong); transform-origin: 100% 50%; animation: ot-toast-run var(--life, 5s) linear forwards; }\n  :is([dir=\"rtl\"], [dir=\"rtl\"] *) .ot-toast-rule { transform-origin: 0 50%; }\n  .ot-toast-time { flex: none; font-size: var(--ot-pp); font-variant-numeric: tabular-nums lining-nums; color: var(--ot-graphite); }\n  @keyframes ot-toast-run { to { scale: 0 1; } }\n\n  @media (forced-colors: active) {\n    .ot-toast { border: var(--ot-hairline) solid CanvasText; }\n    .ot-toaster[data-variant=\"footnote\"] .ot-toast { border: 0; }\n    .ot-toaster[data-variant=\"footnote\"]:has(> .ot-toast) { border: var(--ot-hairline) solid CanvasText; }\n    .ot-toast-rule { forced-color-adjust: none; background: CanvasText; }\n    .ot-toaster[data-variant=\"footnote\"]::before { forced-color-adjust: none; background: CanvasText; }\n  }\n}\n",
      "type": "registry:file",
      "target": "styles/0nlytype/toast.css"
    }
  ],
  "css": {
    "@import \"../styles/0nlytype/toast.css\"": {}
  },
  "meta": {
    "movement": "VII",
    "underneath": "hook",
    "contract": "ot-toast"
  },
  "type": "registry:ui"
}
