{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "message",
  "title": "Message",
  "description": "A sender's run in a conversation, on one reading edge: the header (name, time), every bubble's text, the file glyphs and the receipt start on the same line. Consecutive bubbles stack on shared keylines; the avatar sits in the gutter level with the first bubble. align=\"end\" is the reader's own run, at the end of the log, mirrored with the writing direction.",
  "dependencies": [
    "@base-ui/react@1.9.0"
  ],
  "registryDependencies": [
    "@keyline-ui/keyline",
    "utils",
    "@keyline-ui/keyline-render"
  ],
  "files": [
    {
      "path": "src/registry/keyline/ui/message.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { mergeProps } from \"@base-ui/react/merge-props\";\nimport { useRender } from \"@base-ui/react/use-render\";\n\nimport { cn } from \"@/lib/utils\";\nimport { resolveClassName, resolveStyle, type PartProps } from \"../lib/keyline-render\";\n\n/* A message is one sender's run in the conversation: consecutive messages from the same person, close in time.\n   A run hangs from its own side of the log as one stack (the bubbles share keylines):\n   - align=\"start\": the other party, at the start of the log, with an avatar in the gutter, level with the\n     first bubble's top keyline. The header, every bubble and the receipt line up on the start edge;\n   - align=\"end\": the reader's own run, at the end of the log (the left in RTL). It needs no avatar. Every\n     bubble is flush to the end edge, and the header and receipt sit over the bubbles' end text inset.\n   Put every consecutive message of the run in one Message: Header, then Bubbles (attachments go inside the\n   bubble), then a Footer for the delivery state of the bubble right above it.\n\n   Each run hangs from its own side of the log. --kl-msg-x is the text inset; the header and footer sit one frame\n   border plus that inset in from the run's outer edge: the start edge for theirs (where a bubble's text begins),\n   the end edge for yours (bubbles flush to the end, the header and receipt over their end inset). A narrow log (the\n   kl-log container, MessageScrollerContent) gets a smaller face and a little more of the row for the words. */\n\ntype Align = \"start\" | \"end\";\n\n/* ------------------------------------------------------------------ *\n * CLASSES\n * ------------------------------------------------------------------ */\n\nconst group = \"kl-type flex min-w-0 flex-col gap-[calc(var(--kl-gutter)+8px)]\";\n\nconst root = cn(\n  \"kl-type group/message flex w-full min-w-0 gap-(--kl-gutter) data-[align=end]:flex-row-reverse\",\n  \"[--kl-msg-av:32px] [--kl-msg-gap:6px] [--kl-msg-head:18px] [--kl-msg-x:var(--kl-inset)]\",\n  // the row reads its own parts (a :has() on the row itself) and hands the avatar's drop and the column's measure to\n  // them: a :has() outside a rule's subject restyles the whole document on any DOM change\n  \"[--kl-msg-av-mt:initial] [--kl-msg-measure:initial]\",\n  \"has-[>[data-slot=message-content]>[data-slot=message-header]:first-child]:[--kl-msg-av-mt:calc(var(--kl-msg-head)+var(--kl-msg-gap))]\",\n  \"not-has-[>[data-slot=message-avatar]]:[--kl-msg-measure:min(82%,36rem)]\",\n  \"[@container_kl-log_(max-width:420px)]:not-has-[>[data-slot=message-avatar]]:[--kl-msg-measure:88%]\",\n  \"[@container_kl-log_(max-width:420px)]:[--kl-msg-av:24px]\",\n  \"[@container_kl-log_(max-width:420px)]:[--kl-msg-x:max(8px,var(--kl-inset)_-_2px)]\",\n);\n\n/** the gutter: level with the first bubble's top keyline, so the face and the first frame read as one row. It sizes\n *  its avatar (one attribute more specific than the avatar's own size classes). */\nconst avatar = cn(\n  \"flex w-(--kl-msg-av) flex-none self-start empty:h-0\",\n  \"mt-[var(--kl-msg-av-mt,0px)]\",\n  \"*:data-[slot=avatar]:[--kl-av:var(--kl-msg-av)]\",\n  \"[@container_kl-log_(max-width:420px)]:*:data-[slot=avatar]:[--kl-av-fs:10px]\",\n);\n\n/** the column: as wide as its widest bubble, never wider than most of the row, so each side keeps its side */\nconst content = cn(\n  \"flex min-w-0 flex-[0_1_auto] flex-col items-start *:max-w-full group-data-[align=end]/message:items-end\",\n  \"max-w-[var(--kl-msg-measure,min(100%_-_var(--kl-msg-av)_-_var(--kl-gutter),36rem))]\",\n);\n\nconst edge = cn(\n  \"min-w-0 ps-[calc(var(--kl-k2)+var(--kl-msg-x))]\",\n  \"group-data-[align=end]/message:justify-end group-data-[align=end]/message:ps-0\",\n  \"group-data-[align=end]/message:pe-[calc(var(--kl-k2)+var(--kl-msg-x))]\",\n);\n\n/** the name in the UI voice; the time (and any code) in the Code voice, never squeezed */\nconst header = cn(\n  edge,\n  \"mb-(--kl-msg-gap) flex h-(--kl-msg-head) items-baseline gap-2 whitespace-nowrap\",\n  \"text-[13px]/[var(--kl-msg-head)] font-(--kl-weight-strong)\",\n  \"[&>:not(time,.kl-code)]:min-w-0 [&>:not(time,.kl-code)]:overflow-hidden [&>:not(time,.kl-code)]:text-ellipsis\",\n  \"[&_:is(time,.kl-code)]:flex-none [&_:is(time,.kl-code)]:font-(family-name:--kl-font-mono)\",\n  \"[&_:is(time,.kl-code)]:text-[11px]/none [&_:is(time,.kl-code)]:font-medium [&_:is(time,.kl-code)]:not-italic\",\n  \"[&_:is(time,.kl-code)]:text-kl-ink-2 [&_:is(time,.kl-code)]:tabular-nums\",\n);\n\n/** the receipt belongs to the bubble right above it */\nconst footer = cn(\n  edge,\n  \"mt-(--kl-msg-gap) flex flex-wrap items-baseline gap-x-2\",\n  \"font-(family-name:--kl-font-mono) text-[11px]/[16px] font-medium text-kl-ink-2 not-italic tabular-nums\",\n  \"data-[tone=attention]:text-kl-red-text\",\n  \"[&+:not([data-slot=message-footer])]:mt-[calc(var(--kl-msg-gap)*2)]\",\n  \"[&>button]:cursor-pointer [&>button]:font-(family-name:--kl-font) [&>button]:text-[12px]\",\n  \"[&>button]:font-(--kl-weight-strong) [&>button]:text-kl-cobalt-text\",\n  \"[&>button]:underline [&>button]:underline-offset-2\",\n  \"[&>button]:focus-visible:outline-(length:--kl-ring) [&>button]:focus-visible:outline-offset-2\",\n  \"[&>button]:focus-visible:outline-kl-focus [&>button]:focus-visible:outline-solid\",\n  \"[&>button:active>*]:translate-y-px\",\n);\n\n/* ------------------------------------------------------------------ *\n * PARTS\n * ------------------------------------------------------------------ */\n\ntype MessageState = { align: Align };\ntype MessagePartState = Record<string, never>;\ntype MessageFooterState = { tone: \"attention\" | undefined };\nconst PART_STATE: MessagePartState = {};\n\nfunction part<State extends object>(\n  slot: string,\n  base: string,\n  state: State,\n  { render, className, style, ...props }: PartProps<\"div\", State>,\n  own: React.ComponentProps<\"div\"> & Record<`data-${string}`, unknown> = {},\n) {\n  return {\n    defaultTagName: \"div\" as const,\n    render,\n    state,\n    props: mergeProps<\"div\">(props, {\n      ...own,\n      className: resolveClassName(base, className)(state),\n      style: resolveStyle(undefined, style)(state),\n      \"data-slot\": slot,\n    } as React.ComponentProps<\"div\">),\n  };\n}\n\n/** Runs one after another, one gutter and a half apart (a log's content is already one). */\nfunction MessageGroup(props: PartProps<\"div\", MessagePartState>): React.ReactElement {\n  return useRender(part(\"message-group\", group, PART_STATE, props));\n}\n\ntype MessageProps = PartProps<\"div\", MessageState> & {\n  /** start: the other party. end: the reader's own messages. */\n  align?: Align;\n};\n\nfunction Message({ align = \"start\", ...props }: MessageProps): React.ReactElement {\n  return useRender(part(\"message\", root, { align }, props, { \"data-align\": align }));\n}\n\n/** The avatar gutter. Put a size=\"md\" Avatar in it (decorative when the header prints the name). The reader's own run leaves it out. */\nfunction MessageAvatar(props: PartProps<\"div\", MessagePartState>): React.ReactElement {\n  return useRender(part(\"message-avatar\", avatar, PART_STATE, props));\n}\n\n/** The run's column: header, bubbles, footers. It is as wide as its widest bubble, and everything in it hangs from the run's outer edge (start for theirs, end for yours). */\nfunction MessageContent(props: PartProps<\"div\", MessagePartState>): React.ReactElement {\n  return useRender(part(\"message-content\", content, PART_STATE, props));\n}\n\n/** Sender and time, over the bubbles' text inset on the run's outer edge: the name in the UI voice, the time in the Code voice (pass a <time>). */\nfunction MessageHeader(props: PartProps<\"div\", MessagePartState>): React.ReactElement {\n  return useRender(part(\"message-header\", header, PART_STATE, props));\n}\n\ntype MessageFooterProps = PartProps<\"div\", MessageFooterState> & {\n  /** attention: the bubble above was not sent (the reason, then a Retry button). */\n  tone?: \"attention\";\n};\n\n/** Delivery state of the bubble right above it (\"Sent\", \"Read 14:22\", \"Not sent: no signal.\" + a Retry button), on the run's outer edge, in the Code voice. */\nfunction MessageFooter({ tone, ...props }: MessageFooterProps): React.ReactElement {\n  return useRender(part(\"message-footer\", footer, { tone }, props, { \"data-tone\": tone, \"aria-live\": \"polite\" }));\n}\n\nexport { MessageGroup, Message, MessageAvatar, MessageContent, MessageHeader, MessageFooter };\nexport type { MessageProps, MessageFooterProps, MessageState };\n",
      "type": "registry:ui",
      "target": "components/keyline/ui/message.tsx"
    }
  ],
  "type": "registry:ui"
}