{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sql-viewer",
  "type": "registry:ui",
  "title": "SQL Viewer",
  "description": "Explore tables, keys, and the joins between them.",
  "categories": [
    "data-display"
  ],
  "dependencies": [
    "@hugeicons/core-free-icons@4.4.0",
    "@hugeicons/react@1.1.10",
    "@xyflow/react@13.0.3"
  ],
  "registryDependencies": [
    "https://sprout.tulipfarm.ai/r/sprout-base.json",
    "https://sprout.tulipfarm.ai/r/button.json"
  ],
  "files": [
    {
      "path": "registry/sprout/components/ui/sql-viewer.tsx",
      "type": "registry:ui",
      "target": "components/ui/sql-viewer.tsx",
      "content": "'use client';\n\nimport {\n  Background,\n  getSmoothStepPath,\n  Handle,\n  Panel,\n  Position,\n  ReactFlow,\n  ReactFlowProvider,\n  useInternalNode,\n  useNodesState,\n  type Edge,\n  type EdgeProps,\n  type FitViewOptions,\n  type InternalNode,\n  type Node,\n  type NodeMouseHandler,\n  type NodeProps,\n} from '@xyflow/react';\nimport {\n  createContext,\n  useCallback,\n  useContext,\n  useEffect,\n  useId,\n  useMemo,\n  useState,\n  type FocusEvent,\n  type HTMLAttributes,\n  type KeyboardEvent,\n} from 'react';\nimport { FingerprintIcon } from '@/lib/sprout/icons/fingerprint-icon';\nimport { KeyIcon } from '@/lib/sprout/icons/key-icon';\nimport { LayersIcon } from '@/lib/sprout/icons/layers-icon';\nimport { LinkIcon } from '@/lib/sprout/icons/link-icon';\nimport { cn } from '@/lib/sprout/classes';\nimport {\n  FitOnResize,\n  flowMaxZoom,\n  flowMinZoom,\n  useKeyboardView,\n  useViewportMobile,\n  ZoomControls,\n} from '@/lib/sprout/flow';\nimport { Button } from '@/components/ui/button';\n\nexport const sqlViewerLayoutNames = ['auto', 'horizontal', 'vertical'] as const;\nexport type SqlViewerLayout = (typeof sqlViewerLayoutNames)[number];\nexport type SqlViewerCardinality = 'one' | 'many';\n\nexport interface SqlViewerOption {\n  id: string;\n  label: string;\n  retired: boolean;\n}\n\nexport type SqlViewerField = {\n  id: string;\n  label: string;\n  required: boolean;\n} & (\n  | { kind: 'text'; maxLength: number }\n  | { kind: 'numeric'; precision: number; scale: number }\n  | { kind: 'boolean' }\n  | { kind: 'date' }\n  | { kind: 'timestamp'; timezone?: 'UTC' }\n  | {\n      kind: 'single-select' | 'multi-select';\n      options: readonly SqlViewerOption[];\n    }\n  | {\n      kind: 'relationship';\n      targetTableId: string;\n      cardinality: SqlViewerCardinality;\n      inverseCardinality: SqlViewerCardinality;\n      reverse?: { fieldId: string; label: string } | null;\n      onDelete?: 'restrict';\n    }\n  | {\n      kind: 'file';\n      cardinality: SqlViewerCardinality;\n      access?: 'independent';\n    }\n);\n\nexport interface SqlViewerUniqueKey {\n  id: string;\n  fieldIds: readonly string[];\n}\n\nexport interface SqlViewerTable {\n  id: string;\n  label: string;\n  owningTeamId?: string;\n  fields: readonly SqlViewerField[];\n  uniqueKeys?: readonly SqlViewerUniqueKey[];\n}\n\ntype Direction = 'horizontal' | 'vertical';\ntype Side = 'left' | 'right';\ntype TableNode = Node<{ table: SqlViewerTable; tone: number }, 'table'>;\ntype GroupNode = Node<{ label: string; tone: number; count: number }, 'group'>;\ntype MoreNode = Node<{ tables: SqlViewerTable[] }, 'more'>;\ntype ViewerNode = TableNode | GroupNode | MoreNode;\ntype JoinEdge = Edge<\n  {\n    join: string;\n    description: string;\n    sourceMany: boolean;\n    targetMany: boolean;\n  },\n  'join'\n>;\n\ninterface Focus {\n  table: string;\n  field?: string | undefined;\n}\n\nconst moreId = '~more';\nconst groupId = (key: string) => `~group:${key}`;\n\nconst cardWidth = 272;\nconst cardChrome = 4;\nconst headerHeight = 40;\nconst rowHeight = 28;\nconst keysChrome = 36;\nconst keyHeight = 26;\nconst colGap = 104;\nconst rowGap = 32;\nconst groupPad = 20;\nconst groupHeader = 44;\nconst groupGap = 56;\nconst wrapWidth = 1400;\nconst tones = 5;\n\nconst fitAll: FitViewOptions = { padding: '5.4%', maxZoom: 1 };\n\nconst compositeKeys = (table: SqlViewerTable) => (table.uniqueKeys ?? []).filter(key => key.fieldIds.length > 1);\n\nconst cardHeight = (table: SqlViewerTable) => {\n  const keys = compositeKeys(table).length;\n  return cardChrome + headerHeight + (table.fields.length + 1) * rowHeight + (keys ? keysChrome + keys * keyHeight : 0);\n};\n\nfunction columnType(field: SqlViewerField) {\n  switch (field.kind) {\n    case 'text':\n      return `varchar(${field.maxLength})`;\n    case 'numeric':\n      return `numeric(${field.precision},${field.scale})`;\n    case 'timestamp':\n      return 'timestamptz';\n    case 'single-select':\n      return 'enum';\n    case 'multi-select':\n      return 'enum[]';\n    case 'relationship':\n      return field.cardinality === 'one' ? 'uuid' : 'uuid[]';\n    case 'file':\n      return field.cardinality === 'one' ? 'file' : 'file[]';\n    default:\n      return field.kind;\n  }\n}\n\nfunction joinText(from: string, field: string, to: string, many: boolean): string {\n  return many ? `${to}.id = ANY(${from}.${field})` : `${from}.${field} = ${to}.id`;\n}\n\ninterface Block {\n  key: string | null;\n  label: string;\n  tables: SqlViewerTable[];\n}\n\nfunction arrange(\n  visible: readonly SqlViewerTable[],\n  hidden: readonly SqlViewerTable[],\n  groups: Readonly<Record<string, string>> | undefined,\n  direction: Direction,\n): ViewerNode[] {\n  const blocks: Block[] = [];\n  for (const table of visible) {\n    const team = table.owningTeamId;\n    const key = team !== undefined && groups?.[team] ? team : null;\n    let block = blocks.find(candidate => candidate.key === key);\n    if (!block) {\n      block = { key, label: key ? groups![key]! : '', tables: [] };\n      blocks.push(block);\n    }\n    block.tables.push(table);\n  }\n\n  const nodes: ViewerNode[] = [];\n  let cursorX = 0;\n  let cursorY = 0;\n  let lineHeight = 0;\n  let right = 0;\n  let bottom = 0;\n  let tone = 0;\n\n  for (const block of blocks) {\n    const ids = new Set(block.tables.map(table => table.id));\n    const depth = new Map(block.tables.map(table => [table.id, 0]));\n    if (direction === 'horizontal') {\n      for (let pass = 0; pass < block.tables.length; pass++) {\n        let moved = false;\n        for (const table of block.tables)\n          for (const field of table.fields) {\n            if (field.kind !== 'relationship') continue;\n            const target = field.targetTableId;\n            const next = depth.get(table.id)! + 1;\n            if (target !== table.id && ids.has(target) && next > depth.get(target)! && next < block.tables.length) {\n              depth.set(target, next);\n              moved = true;\n            }\n          }\n        if (!moved) break;\n      }\n    }\n    const columnBottoms = new Map<number, number>();\n    const placed = block.tables.map(table => {\n      const column = depth.get(table.id)!;\n      const y = columnBottoms.get(column) ?? 0;\n      columnBottoms.set(column, y + cardHeight(table) + rowGap);\n      return { table, x: column * (cardWidth + colGap), y };\n    });\n    const innerWidth = Math.max(...placed.map(item => item.x)) + cardWidth;\n    const innerHeight = Math.max(...columnBottoms.values()) - rowGap;\n    const framed = block.key !== null;\n    const width = framed ? innerWidth + groupPad * 2 : innerWidth;\n    const height = framed ? innerHeight + groupHeader + groupPad : innerHeight;\n\n    if (direction === 'horizontal' && cursorX > 0 && cursorX + width > wrapWidth) {\n      cursorX = 0;\n      cursorY += lineHeight + groupGap;\n      lineHeight = 0;\n    }\n    const blockTone = framed ? (tone++ % tones) + 1 : 0;\n    const parent = framed ? groupId(block.key!) : undefined;\n    if (framed)\n      nodes.push({\n        id: parent!,\n        type: 'group',\n        position: { x: cursorX, y: cursorY },\n        width,\n        height,\n        data: {\n          label: block.label,\n          tone: blockTone,\n          count: block.tables.length,\n        },\n        dragHandle: '.sprout-sql-group-label',\n        focusable: false,\n        selectable: false,\n      });\n    for (const item of placed)\n      nodes.push({\n        id: item.table.id,\n        type: 'table',\n        position: framed\n          ? { x: groupPad + item.x, y: groupHeader + item.y }\n          : { x: cursorX + item.x, y: cursorY + item.y },\n        ...(parent ? { parentId: parent, expandParent: true } : {}),\n        data: { table: item.table, tone: blockTone },\n        ariaRole: 'group',\n        ariaLabel: `${item.table.label} table, ${item.table.fields.length + 1} columns`,\n        domAttributes: { 'aria-roledescription': 'table card' },\n      });\n\n    right = Math.max(right, cursorX + width);\n    bottom = Math.max(bottom, cursorY + height);\n    if (direction === 'horizontal') {\n      cursorX += width + groupGap;\n      lineHeight = Math.max(lineHeight, height);\n    } else {\n      cursorY += height + groupGap;\n    }\n  }\n\n  if (hidden.length)\n    nodes.push({\n      id: moreId,\n      type: 'more',\n      position: direction === 'horizontal' ? { x: right + colGap, y: 0 } : { x: 0, y: bottom + groupGap },\n      data: { tables: [...hidden] },\n      focusable: false,\n    });\n  return nodes;\n}\n\nfunction joins(visible: readonly SqlViewerTable[], hidden: readonly SqlViewerTable[]): JoinEdge[] {\n  const shown = new Set(visible.map(table => table.id));\n  const collapsed = new Set(hidden.map(table => table.id));\n  const labels = new Map([...visible, ...hidden].map(table => [table.id, table.label]));\n  const node = (id: string) => (shown.has(id) ? id : collapsed.has(id) ? moreId : null);\n  const edges: JoinEdge[] = [];\n  for (const table of [...visible, ...hidden])\n    for (const field of table.fields) {\n      if (field.kind !== 'relationship') continue;\n      const source = node(table.id);\n      const target = node(field.targetTableId);\n      if (!source || !target || (source === moreId && target === moreId)) continue;\n      const to = labels.get(field.targetTableId)!;\n      const sourceMany = field.inverseCardinality === 'many';\n      const targetMany = field.cardinality === 'many';\n      edges.push({\n        id: `${table.id}/${field.id}`,\n        type: 'join',\n        source,\n        sourceHandle: source === moreId ? 'out:right' : `${field.id}:right`,\n        target,\n        targetHandle: target === moreId ? 'in:left' : 'id:left',\n        data: {\n          join: joinText(table.label, field.label, to, targetMany),\n          description: `${table.label}.${field.label} joins ${to}.id, ${\n            sourceMany ? 'many' : 'one'\n          } to ${targetMany ? 'many' : 'one'}`,\n          sourceMany,\n          targetMany,\n        },\n      });\n    }\n  return edges;\n}\n\ninterface ViewerState {\n  focus: Focus | null;\n  related: ReadonlySet<string>;\n  activeEdges: ReadonlySet<string>;\n  hover: (focus: Focus | null) => void;\n  pin: (focus: Focus) => void;\n  expand: () => void;\n}\n\nconst ViewerContext = createContext<ViewerState | null>(null);\nconst useViewer = () => useContext(ViewerContext)!;\n\nfunction sideHandles(type: 'source' | 'target', id: string) {\n  return (\n    <>\n      <Handle\n        id={`${id}:left`}\n        type={type}\n        position={Position.Left}\n        isConnectable={false}\n        className=\"sprout-sql-handle\"\n      />\n      <Handle\n        id={`${id}:right`}\n        type={type}\n        position={Position.Right}\n        isConnectable={false}\n        className=\"sprout-sql-handle\"\n      />\n    </>\n  );\n}\n\nfunction TableCard({ id, data: { table, tone } }: NodeProps<TableNode>) {\n  const viewer = useViewer();\n  const composite = compositeKeys(table);\n  const unique = new Set((table.uniqueKeys ?? []).filter(key => key.fieldIds.length === 1).map(key => key.fieldIds[0]));\n  const labels = new Map(table.fields.map(field => [field.id, field.label]));\n  const focused = viewer.focus?.table === id;\n  return (\n    <section\n      data-slot=\"sql-table\"\n      data-tone={tone}\n      data-dimmed={viewer.focus && !viewer.related.has(id) ? '' : undefined}\n      data-active={focused ? '' : undefined}\n      className=\"sprout-sql-table\"\n      onMouseLeave={() => viewer.hover(null)}\n    >\n      <header className=\"sprout-sql-table-header\">\n        <h3 className=\"sprout-sql-table-title\" title={table.label}>\n          {table.label}\n        </h3>\n      </header>\n      <ul className=\"sprout-sql-columns\">\n        <li className=\"sprout-sql-column\" data-key=\"primary\">\n          {sideHandles('target', 'id')}\n          <span className=\"sprout-sql-column-icon\">\n            <KeyIcon size=\"xs\" role=\"img\" aria-label=\"Primary key\" />\n          </span>\n          <span className=\"sprout-sql-column-name\">id</span>\n          <span className=\"sprout-sql-column-type\">uuid</span>\n        </li>\n        {table.fields.map(field => {\n          const join = field.kind === 'relationship';\n          const type = columnType(field);\n          return (\n            <li\n              key={field.id}\n              className=\"sprout-sql-column\"\n              data-join={join ? '' : undefined}\n              data-active={focused && viewer.focus?.field === field.id ? '' : undefined}\n              title={\n                field.kind === 'single-select' || field.kind === 'multi-select'\n                  ? field.options\n                      .filter(option => !option.retired)\n                      .map(option => option.label)\n                      .join(' · ')\n                  : undefined\n              }\n              onMouseEnter={join ? () => viewer.hover({ table: id, field: field.id }) : undefined}\n              onMouseLeave={join ? () => viewer.hover({ table: id }) : undefined}\n              onClick={\n                join\n                  ? event => {\n                      event.stopPropagation();\n                      viewer.pin({ table: id, field: field.id });\n                    }\n                  : undefined\n              }\n            >\n              {join && sideHandles('source', field.id)}\n              <span className=\"sprout-sql-column-icon\">\n                {join ? (\n                  <LinkIcon size=\"xs\" role=\"img\" aria-label=\"Foreign key\" />\n                ) : unique.has(field.id) ? (\n                  <FingerprintIcon size=\"xs\" role=\"img\" aria-label=\"Unique\" />\n                ) : null}\n              </span>\n              <span className=\"sprout-sql-column-name\" title={field.label}>\n                {field.label}\n              </span>\n              <span className=\"sprout-sql-column-type\">\n                {type}\n                {!field.required && (\n                  <>\n                    <span aria-hidden=\"true\">?</span>\n                    <span className=\"sprout-sql-sr-only\">, nullable</span>\n                  </>\n                )}\n              </span>\n            </li>\n          );\n        })}\n      </ul>\n      {composite.length > 0 && (\n        <div className=\"sprout-sql-keys\">\n          <p className=\"sprout-sql-keys-title\">Unique keys</p>\n          <ul className=\"sprout-sql-keys-list\">\n            {composite.map(key => (\n              <li key={key.id} className=\"sprout-sql-key\">\n                <FingerprintIcon size=\"xs\" aria-hidden=\"true\" />\n                <span>{key.fieldIds.map(field => labels.get(field) ?? field).join(', ')}</span>\n              </li>\n            ))}\n          </ul>\n        </div>\n      )}\n    </section>\n  );\n}\n\nfunction GroupFrame({ data: { label, tone, count } }: NodeProps<GroupNode>) {\n  return (\n    <section\n      data-slot=\"sql-group\"\n      data-tone={tone}\n      aria-label={`${label}, ${count} ${count === 1 ? 'table' : 'tables'}`}\n      className=\"sprout-sql-group\"\n    >\n      <header className=\"sprout-sql-group-label\">\n        <LayersIcon size=\"sm\" aria-hidden=\"true\" />\n        <span className=\"sprout-sql-group-name\">{label}</span>\n        <span className=\"sprout-sql-group-count\">{count}</span>\n      </header>\n    </section>\n  );\n}\n\nfunction MoreCard({ data: { tables } }: NodeProps<MoreNode>) {\n  const { expand } = useViewer();\n  const names = tables.slice(0, 3).map(table => table.label);\n  const rest = tables.length - names.length;\n  return (\n    <div data-slot=\"sql-more\" className=\"sprout-sql-more\">\n      {sideHandles('target', 'in')}\n      {sideHandles('source', 'out')}\n      <span aria-hidden=\"true\" className=\"sprout-sql-more-sheet\" />\n      <span aria-hidden=\"true\" className=\"sprout-sql-more-sheet\" />\n      <button\n        type=\"button\"\n        className=\"nodrag sprout-sql-more-button\"\n        onClick={expand}\n        aria-label={`Show ${tables.length} more ${\n          tables.length === 1 ? 'table' : 'tables'\n        }: ${tables.map(table => table.label).join(', ')}`}\n      >\n        <span className=\"sprout-sql-more-count\">\n          +{tables.length} {tables.length === 1 ? 'table' : 'tables'}\n        </span>\n        <span className=\"sprout-sql-more-names\">\n          {names.join(', ')}\n          {rest > 0 && ` and ${rest} more`}\n        </span>\n        <span className=\"sprout-sql-more-action\">Show all</span>\n      </button>\n    </div>\n  );\n}\n\nfunction handlePoint(node: InternalNode, type: 'source' | 'target', id: string) {\n  const handle = node.internals.handleBounds?.[type]?.find(candidate => candidate.id === id);\n  if (!handle) return null;\n  return {\n    x: node.internals.positionAbsolute.x + handle.x + handle.width / 2,\n    y: node.internals.positionAbsolute.y + handle.y + handle.height / 2,\n  };\n}\n\nfunction endMark(x: number, y: number, side: Side, many: boolean) {\n  const out = side === 'right' ? 1 : -1;\n  return many\n    ? `M ${x + out * 12} ${y} L ${x} ${y - 6} M ${x + out * 12} ${y} L ${x} ${y + 6}`\n    : `M ${x + out * 9} ${y - 5} L ${x + out * 9} ${y + 5}`;\n}\n\nfunction JoinLine({ id, source, target, sourceHandleId, targetHandleId, data }: EdgeProps<JoinEdge>) {\n  const from = useInternalNode(source);\n  const to = useInternalNode(target);\n  const viewer = useViewer();\n  if (!from || !to || !data || !sourceHandleId || !targetHandleId) return null;\n  const fromLeft = from.internals.positionAbsolute.x;\n  const toLeft = to.internals.positionAbsolute.x;\n  const fromRight = fromLeft + (from.measured.width ?? 0);\n  const toRight = toLeft + (to.measured.width ?? 0);\n  const [sourceSide, targetSide]: [Side, Side] =\n    fromRight + 24 <= toLeft ? ['right', 'left'] : toRight + 24 <= fromLeft ? ['left', 'right'] : ['right', 'right'];\n  const base = (handle: string) => handle.slice(0, handle.lastIndexOf(':'));\n  const start = handlePoint(from, 'source', `${base(sourceHandleId)}:${sourceSide}`);\n  const end = handlePoint(to, 'target', `${base(targetHandleId)}:${targetSide}`);\n  if (!start || !end) return null;\n  const position = (side: Side) => (side === 'right' ? Position.Right : Position.Left);\n  const [path] = getSmoothStepPath({\n    sourceX: start.x,\n    sourceY: start.y,\n    sourcePosition: position(sourceSide),\n    targetX: end.x,\n    targetY: end.y,\n    targetPosition: position(targetSide),\n    borderRadius: 10,\n    offset: 28,\n  });\n  const active = viewer.activeEdges.has(id);\n  return (\n    <path\n      d={`${path} ${endMark(start.x, start.y, sourceSide, data.sourceMany)} ${endMark(\n        end.x,\n        end.y,\n        targetSide,\n        data.targetMany,\n      )}`}\n      className=\"react-flow__edge-path sprout-sql-join\"\n      data-active={active ? '' : undefined}\n      data-dimmed={viewer.focus && !active ? '' : undefined}\n    />\n  );\n}\n\nconst nodeTypes = { table: TableCard, group: GroupFrame, more: MoreCard };\nconst edgeTypes = { join: JoinLine };\n\nconst keyboardHint =\n  \"Arrow keys pan, plus and minus zoom, and 0 fits the diagram. Tab moves between tables; Enter pins a table's joins.\";\n\nfunction ViewerFlow({\n  layoutNodes,\n  edges,\n  direction,\n  label,\n  hintId,\n  expanded,\n  setExpanded,\n  collapsible,\n  maxVisible,\n}: {\n  layoutNodes: ViewerNode[];\n  edges: JoinEdge[];\n  direction: Direction;\n  label: string;\n  hintId: string;\n  expanded: boolean;\n  setExpanded: (expanded: boolean) => void;\n  collapsible: boolean;\n  maxVisible: number;\n}) {\n  const [nodes, setNodes, onNodesChange] = useNodesState<ViewerNode>(layoutNodes);\n  useEffect(() => setNodes(layoutNodes), [layoutNodes, setNodes]);\n\n  const [hovered, setHovered] = useState<Focus | null>(null);\n  const [pinned, setPinned] = useState<Focus | null>(null);\n  const focus = hovered ?? pinned;\n  const pin = useCallback(\n    (next: Focus) =>\n      setPinned(current => (current?.table === next.table && current.field === next.field ? null : next)),\n    [],\n  );\n  const state = useMemo<ViewerState>(() => {\n    const activeEdges = new Set<string>();\n    const related = new Set<string>();\n    if (focus) {\n      related.add(focus.table);\n      for (const edge of edges) {\n        const hit = focus.field\n          ? edge.id === `${focus.table}/${focus.field}`\n          : edge.source === focus.table || edge.target === focus.table;\n        if (!hit) continue;\n        activeEdges.add(edge.id);\n        related.add(edge.source).add(edge.target);\n      }\n    }\n    return {\n      focus,\n      related,\n      activeEdges,\n      hover: setHovered,\n      pin,\n      expand: () => setExpanded(true),\n    };\n  }, [focus, edges, pin, setExpanded]);\n\n  const shownEdges = useMemo(\n    () =>\n      state.activeEdges.size\n        ? edges.map(edge => (state.activeEdges.has(edge.id) ? { ...edge, zIndex: 1000 } : edge))\n        : edges,\n    [edges, state.activeEdges],\n  );\n\n  const fitFirst = useMemo<FitViewOptions>(\n    () =>\n      direction === 'vertical' && layoutNodes[0]\n        ? { padding: '2.8%', maxZoom: 1, nodes: [{ id: layoutNodes[0].id }] }\n        : fitAll,\n    [direction, layoutNodes],\n  );\n\n  const keyboardView = useKeyboardView(fitAll);\n  const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n    const target = event.target as HTMLElement;\n    const id = target.dataset['id'];\n    if ((event.key === 'Enter' || event.key === ' ') && target.classList.contains('react-flow__node-table') && id) {\n      event.preventDefault();\n      pin({ table: id });\n      return;\n    }\n    if (event.key === 'Escape' && pinned) {\n      setPinned(null);\n      return;\n    }\n    keyboardView(event);\n  };\n  const onFocus = (event: FocusEvent<HTMLDivElement>) => {\n    const id = event.target.dataset['id'];\n    if (event.target.classList.contains('react-flow__node-table') && id) setHovered({ table: id });\n  };\n  const onNodeMouseEnter: NodeMouseHandler<ViewerNode> = (_, node) => {\n    if (node.type === 'table') setHovered({ table: node.id });\n  };\n  const onNodeClick: NodeMouseHandler<ViewerNode> = (_, node) => {\n    if (node.type === 'table') pin({ table: node.id });\n  };\n\n  return (\n    <ViewerContext.Provider value={state}>\n      <ReactFlow<ViewerNode, JoinEdge>\n        className=\"sprout-schema-flow sprout-sql-flow\"\n        data-slot=\"sql-viewer-viewport\"\n        data-focus={focus ? '' : undefined}\n        aria-label={label}\n        aria-describedby={hintId}\n        tabIndex={0}\n        onKeyDown={onKeyDown}\n        onFocus={onFocus}\n        onBlur={() => setHovered(null)}\n        nodes={nodes}\n        edges={shownEdges}\n        onNodesChange={onNodesChange}\n        nodeTypes={nodeTypes}\n        edgeTypes={edgeTypes}\n        onNodeMouseEnter={onNodeMouseEnter}\n        onNodeClick={onNodeClick}\n        onPaneClick={() => setPinned(null)}\n        fitView\n        fitViewOptions={fitFirst}\n        minZoom={flowMinZoom}\n        maxZoom={flowMaxZoom}\n        nodesConnectable={false}\n        elementsSelectable={false}\n        edgesFocusable={false}\n        ariaLabelConfig={{\n          'node.a11yDescription.default': keyboardHint,\n          'node.a11yDescription.keyboardDisabled': keyboardHint,\n        }}\n        proOptions={{ hideAttribution: true }}\n      >\n        <Background gap={16} size={1} />\n        <FitOnResize nodes={layoutNodes} fit={fitFirst} />\n        {collapsible && expanded && (\n          <Panel position=\"top-left\" data-slot=\"sql-viewer-collapse\">\n            <Button\n              variant=\"secondary\"\n              size=\"sm\"\n              onClick={() => {\n                setPinned(null);\n                setExpanded(false);\n              }}\n            >\n              Show {maxVisible} tables\n            </Button>\n          </Panel>\n        )}\n        {state.activeEdges.size > 0 && (\n          <Panel position=\"bottom-left\" data-slot=\"sql-viewer-joins\" aria-hidden=\"true\" className=\"sprout-sql-joins\">\n            {edges\n              .filter(edge => state.activeEdges.has(edge.id))\n              .slice(0, 3)\n              .map(edge => (\n                <code key={edge.id} className=\"sprout-sql-join-text\">\n                  {edge.data!.join}\n                </code>\n              ))}\n            {state.activeEdges.size > 3 && (\n              <span className=\"sprout-sql-joins-more\">and {state.activeEdges.size - 3} more</span>\n            )}\n          </Panel>\n        )}\n        <ZoomControls\n          position={direction === 'vertical' ? 'top-right' : 'bottom-right'}\n          fit={fitAll}\n          className=\"sprout-schema-controls\"\n          slot=\"sql-viewer-controls\"\n        />\n      </ReactFlow>\n    </ViewerContext.Provider>\n  );\n}\n\nexport interface SqlViewerProps extends Omit<HTMLAttributes<HTMLDivElement>, 'role' | 'children'> {\n  tables: readonly SqlViewerTable[];\n  label: string;\n  groups?: Readonly<Record<string, string>> | undefined;\n  maxVisible?: number | undefined;\n  layout?: SqlViewerLayout | undefined;\n}\n\nexport function SqlViewer({\n  tables,\n  label,\n  groups,\n  maxVisible = 4,\n  layout = 'auto',\n  className,\n  ...props\n}: SqlViewerProps) {\n  const mobile = useViewportMobile();\n  const direction: Direction = layout === 'auto' ? (mobile ? 'vertical' : 'horizontal') : layout;\n  const hintId = useId();\n  const [expanded, setExpanded] = useState(false);\n  const limit = Math.max(1, Math.floor(maxVisible));\n  const collapsible = tables.length > limit;\n  const [visible, hidden] = useMemo(\n    () => (collapsible && !expanded ? [tables.slice(0, limit), tables.slice(limit)] : [tables, []]),\n    [tables, limit, collapsible, expanded],\n  );\n  const layoutNodes = useMemo(() => arrange(visible, hidden, groups, direction), [visible, hidden, groups, direction]);\n  const edges = useMemo(() => joins(visible, hidden), [visible, hidden]);\n  const descriptions = joins(tables, []);\n  return (\n    <div\n      {...props}\n      role=\"figure\"\n      aria-label={label}\n      data-slot=\"sql-viewer\"\n      data-layout={direction}\n      className={cn('sprout-sql-viewer', className)}\n    >\n      <p id={hintId} className=\"sprout-sql-sr-only\">\n        {keyboardHint}\n      </p>\n      {descriptions.length > 0 && (\n        <ul aria-label=\"Joins\" className=\"sprout-sql-sr-only\">\n          {descriptions.map(edge => (\n            <li key={edge.id}>{edge.data!.description}</li>\n          ))}\n        </ul>\n      )}\n      {tables.length === 0 ? (\n        <p className=\"sprout-sql-empty\">No tables to show</p>\n      ) : (\n        <ReactFlowProvider key={direction}>\n          <ViewerFlow\n            layoutNodes={layoutNodes}\n            edges={edges}\n            direction={direction}\n            label={label}\n            hintId={hintId}\n            expanded={expanded}\n            setExpanded={setExpanded}\n            collapsible={collapsible}\n            maxVisible={limit}\n          />\n        </ReactFlowProvider>\n      )}\n    </div>\n  );\n}\n"
    },
    {
      "path": "registry/sprout/lib/sprout/icons/add-icon.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/icons/add-icon.tsx",
      "content": "import { Add01Icon as glyph } from '@hugeicons/core-free-icons';\nimport { createIcon } from '@/lib/sprout/icons/create-icon';\n\nexport const AddIcon = /* @__PURE__ */ createIcon(glyph, 'AddIcon');\n"
    },
    {
      "path": "registry/sprout/lib/sprout/icons/create-icon.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/icons/create-icon.tsx",
      "content": "import { HugeiconsIcon, type IconSvgElement } from '@hugeicons/react';\nimport type { ReactElement, Ref, SVGProps } from 'react';\n\nexport const iconSizes = {\n  xs: 12,\n  sm: 14,\n  md: 16,\n  lg: 18,\n  xl: 20,\n  '2xl': 24,\n} as const;\n\nexport type IconSize = keyof typeof iconSizes;\n\nexport const iconStrokeWidth = 1.5;\n\nexport type IconProps = Omit<SVGProps<SVGSVGElement>, 'ref'> & {\n  size?: IconSize | number;\n  ref?: Ref<SVGSVGElement>;\n};\n\nexport type IconComponent = (props: IconProps) => ReactElement;\n\nexport function createIcon(glyph: IconSvgElement, name: string): IconComponent {\n  const Icon = ({ size = '2xl', strokeWidth = iconStrokeWidth, ...props }: IconProps) => (\n    <HugeiconsIcon\n      icon={glyph}\n      size={typeof size === 'number' ? size : iconSizes[size]}\n      strokeWidth={Number(strokeWidth)}\n      {...props}\n    />\n  );\n  Icon.displayName = name;\n  return Icon;\n}\n"
    },
    {
      "path": "registry/sprout/lib/sprout/icons/fingerprint-icon.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/icons/fingerprint-icon.tsx",
      "content": "import { FingerPrintIcon as glyph } from '@hugeicons/core-free-icons';\nimport { createIcon } from '@/lib/sprout/icons/create-icon';\n\nexport const FingerprintIcon = /* @__PURE__ */ createIcon(glyph, 'FingerprintIcon');\n"
    },
    {
      "path": "registry/sprout/lib/sprout/icons/key-icon.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/icons/key-icon.tsx",
      "content": "import { KeyIcon as glyph } from '@hugeicons/core-free-icons';\nimport { createIcon } from '@/lib/sprout/icons/create-icon';\n\nexport const KeyIcon = /* @__PURE__ */ createIcon(glyph, 'KeyIcon');\n"
    },
    {
      "path": "registry/sprout/lib/sprout/icons/layers-icon.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/icons/layers-icon.tsx",
      "content": "import { Layers01Icon as glyph } from '@hugeicons/core-free-icons';\nimport { createIcon } from '@/lib/sprout/icons/create-icon';\n\nexport const LayersIcon = /* @__PURE__ */ createIcon(glyph, 'LayersIcon');\n"
    },
    {
      "path": "registry/sprout/lib/sprout/icons/link-icon.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/icons/link-icon.tsx",
      "content": "import { Link01Icon as glyph } from '@hugeicons/core-free-icons';\nimport { createIcon } from '@/lib/sprout/icons/create-icon';\n\nexport const LinkIcon = /* @__PURE__ */ createIcon(glyph, 'LinkIcon');\n"
    },
    {
      "path": "registry/sprout/lib/sprout/icons/minus-icon.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/icons/minus-icon.tsx",
      "content": "import { MinusSignIcon as glyph } from '@hugeicons/core-free-icons';\nimport { createIcon } from '@/lib/sprout/icons/create-icon';\n\nexport const MinusIcon = /* @__PURE__ */ createIcon(glyph, 'MinusIcon');\n"
    },
    {
      "path": "registry/sprout/lib/sprout/icons/scan-icon.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/icons/scan-icon.tsx",
      "content": "import { ScanIcon as glyph } from '@hugeicons/core-free-icons';\nimport { createIcon } from '@/lib/sprout/icons/create-icon';\n\nexport const ScanIcon = /* @__PURE__ */ createIcon(glyph, 'ScanIcon');\n"
    },
    {
      "path": "registry/sprout/lib/sprout/flow.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/flow.tsx",
      "content": "'use client';\n\nimport {\n  Panel,\n  useNodesStore,\n  useReactFlow,\n  useViewportStore,\n  type FitViewOptions,\n  type Node,\n  type NodesStore,\n} from '@xyflow/react';\nimport { useEffect, useSyncExternalStore, type KeyboardEvent } from 'react';\nimport { AddIcon } from '@/lib/sprout/icons/add-icon';\nimport { MinusIcon } from '@/lib/sprout/icons/minus-icon';\nimport { ScanIcon } from '@/lib/sprout/icons/scan-icon';\nimport { Button } from '@/components/ui/button';\n\nexport const flowMinZoom = 0.2;\nexport const flowMaxZoom = 1.5;\nconst panStep = 48;\n\nconst mobileQuery = '(max-width: 767px)';\nconst motionQuery = '(prefers-reduced-motion: reduce)';\n\nfunction subscribeMobile(callback: () => void) {\n  const media = window.matchMedia(mobileQuery);\n  media.addEventListener('change', callback);\n  return () => media.removeEventListener('change', callback);\n}\n\nexport function useViewportMobile() {\n  return useSyncExternalStore(\n    subscribeMobile,\n    () => window.matchMedia(mobileQuery).matches,\n    () => false,\n  );\n}\n\nexport const motion = (ms: number) =>\n  typeof window !== 'undefined' && window.matchMedia(motionQuery).matches ? 0 : ms;\n\nfunction nodesMeasured(state: NodesStore) {\n  if (state.nodeLookup.size === 0) return false;\n  for (const node of state.nodeLookup.values()) {\n    if (node.hidden) continue;\n    if (!node.measured.width || !node.measured.height || !node.internals.handleBounds) return false;\n  }\n  return true;\n}\n\nexport function FitOnResize({ nodes, fit }: { nodes: readonly Node[]; fit: FitViewOptions }) {\n  const { fitView } = useReactFlow();\n  const width = useViewportStore(state => state.width);\n  const height = useViewportStore(state => state.height);\n  const measured = useNodesStore(nodesMeasured);\n  useEffect(() => {\n    if (!measured) return;\n    const frame = requestAnimationFrame(() => void fitView(fit));\n    return () => cancelAnimationFrame(frame);\n  }, [fitView, fit, width, height, measured, nodes]);\n  return null;\n}\n\nexport function ZoomControls({\n  position,\n  fit,\n  className,\n  slot,\n}: {\n  position: 'top-right' | 'bottom-right';\n  fit: FitViewOptions;\n  className: string;\n  slot: string;\n}) {\n  const { zoomIn, zoomOut, fitView } = useReactFlow();\n  const zoom = useViewportStore(state => state.transform[2]);\n  return (\n    <Panel\n      position={position}\n      className={className}\n      data-slot={slot}\n      role=\"toolbar\"\n      aria-label=\"Diagram view\"\n      aria-orientation=\"vertical\"\n    >\n      <Button\n        variant=\"ghost\"\n        size=\"icon-sm\"\n        aria-label=\"Zoom in\"\n        title=\"Zoom in\"\n        disabled={zoom >= flowMaxZoom}\n        onClick={() => void zoomIn({ duration: motion(160) })}\n      >\n        <AddIcon size=\"md\" aria-hidden=\"true\" />\n      </Button>\n      <Button\n        variant=\"ghost\"\n        size=\"icon-sm\"\n        aria-label=\"Zoom out\"\n        title=\"Zoom out\"\n        disabled={zoom <= flowMinZoom}\n        onClick={() => void zoomOut({ duration: motion(160) })}\n      >\n        <MinusIcon size=\"md\" aria-hidden=\"true\" />\n      </Button>\n      <Button\n        variant=\"ghost\"\n        size=\"icon-sm\"\n        aria-label=\"Fit to view\"\n        title=\"Fit to view\"\n        onClick={() => void fitView({ ...fit, duration: motion(180) })}\n      >\n        <ScanIcon size=\"md\" aria-hidden=\"true\" />\n      </Button>\n    </Panel>\n  );\n}\n\nexport function useKeyboardView(fit: FitViewOptions) {\n  const { getViewport, setViewport, zoomIn, zoomOut, fitView } = useReactFlow();\n  return (event: KeyboardEvent<HTMLDivElement>) => {\n    const target = event.target as HTMLElement;\n    if (event.altKey || event.ctrlKey || event.metaKey) return;\n    if (target !== event.currentTarget && !target.classList.contains('react-flow__node')) return;\n    const step = panStep * (event.shiftKey ? 4 : 1);\n    const pan: Record<string, [number, number]> = {\n      ArrowLeft: [step, 0],\n      ArrowRight: [-step, 0],\n      ArrowUp: [0, step],\n      ArrowDown: [0, -step],\n    };\n    const move = pan[event.key];\n    if (move) {\n      const { x, y, zoom } = getViewport();\n      void setViewport({ x: x + move[0], y: y + move[1], zoom }, { duration: motion(120) });\n    } else if (event.key === '+' || event.key === '=') {\n      void zoomIn({ duration: motion(160) });\n    } else if (event.key === '-' || event.key === '_') {\n      void zoomOut({ duration: motion(160) });\n    } else if (event.key === '0') {\n      void fitView({ ...fit, duration: motion(180) });\n    } else return;\n    event.preventDefault();\n  };\n}\n"
    }
  ],
  "css": {
    "@layer components": {
      ".sprout-sql-viewer": {
        "--sprout-sql-mono": "ui-monospace, SFMono-Regular, Menlo, monospace",
        "box-sizing": "border-box",
        "border": "1px solid var(--sprout-line)",
        "border-radius": "var(--sprout-radius-panel)",
        "background": "var(--sprout-canvas)",
        "width": "100%",
        "min-width": "0",
        "height": "100%",
        "min-height": "24rem",
        "color": "var(--sprout-text)",
        "font-family": "var(--sprout-font)",
        "flex": "1",
        "display": "flex",
        "position": "relative",
        "overflow": "hidden"
      },
      ".sprout-sql-flow.light, .sprout-sql-flow.dark": {
        "--sprout-indigo": "inherit",
        "--sprout-green": "inherit",
        "--sprout-orange": "inherit",
        "--sprout-red": "inherit",
        "--sprout-sky": "inherit",
        "--sprout-purple": "inherit",
        "--sprout-yellow": "inherit",
        "--sprout-teal": "inherit",
        "--sprout-blue": "inherit",
        "--sprout-tan": "inherit",
        "--sprout-chart-1": "inherit",
        "--sprout-chart-2": "inherit",
        "--sprout-chart-3": "inherit",
        "--sprout-chart-4": "inherit",
        "--sprout-chart-5": "inherit",
        "--sprout-chart-6": "inherit",
        "--sprout-chart-7": "inherit",
        "--sprout-chart-8": "inherit",
        "--sprout-chart-9": "inherit",
        "--sprout-chart-10": "inherit"
      },
      ".sprout-sql-viewer [data-tone]": {
        "--sprout-sql-tone": "var(--sprout-primary)"
      },
      ".sprout-sql-viewer [data-tone=\"1\"]": {
        "--sprout-sql-tone": "var(--sprout-chart-1)"
      },
      ".sprout-sql-viewer [data-tone=\"2\"]": {
        "--sprout-sql-tone": "var(--sprout-chart-2)"
      },
      ".sprout-sql-viewer [data-tone=\"3\"]": {
        "--sprout-sql-tone": "var(--sprout-chart-3)"
      },
      ".sprout-sql-viewer [data-tone=\"4\"]": {
        "--sprout-sql-tone": "var(--sprout-chart-4)"
      },
      ".sprout-sql-viewer [data-tone=\"5\"]": {
        "--sprout-sql-tone": "var(--sprout-chart-5)"
      },
      ".sprout-sql-flow .react-flow__node-group": {
        "pointer-events": "none"
      },
      ".sprout-sql-handle.react-flow__handle": {
        "opacity": "0",
        "pointer-events": "none",
        "border": "0",
        "width": "6px",
        "min-width": "0",
        "height": "6px",
        "min-height": "0",
        "position": "absolute",
        "top": "50%"
      },
      ".sprout-sql-handle.react-flow__handle-left": {
        "left": "0",
        "transform": "translate(-50%, -50%)"
      },
      ".sprout-sql-handle.react-flow__handle-right": {
        "right": "0",
        "transform": "translate(50%, -50%)"
      },
      ".sprout-sql-group": {
        "box-sizing": "border-box",
        "border": "1px solid color-mix(in oklab, var(--sprout-sql-tone) 45%, var(--sprout-line))",
        "background": "color-mix(in oklab, var(--sprout-sql-tone) 6%, transparent)",
        "border-radius": "14px",
        "width": "100%",
        "height": "100%"
      },
      ".sprout-sql-group-label": {
        "height": "44px",
        "color": "color-mix(in oklab, var(--sprout-sql-tone) 70%, var(--sprout-text))",
        "font-size": "var(--sprout-text-xs)",
        "letter-spacing": ".06em",
        "text-transform": "uppercase",
        "pointer-events": "all",
        "cursor": "grab",
        "align-items": "center",
        "gap": "8px",
        "padding": "0 20px",
        "font-weight": "600",
        "line-height": "1rem",
        "display": "inline-flex"
      },
      ".sprout-sql-group-count": {
        "background": "color-mix(in oklab, var(--sprout-sql-tone) 14%, transparent)",
        "font-variant-numeric": "tabular-nums",
        "letter-spacing": "0",
        "text-align": "center",
        "border-radius": "999px",
        "min-width": "18px",
        "padding": "0 6px"
      },
      ".sprout-sql-table": {
        "box-sizing": "border-box",
        "border": "1px solid var(--sprout-line)",
        "border-top": "3px solid var(--sprout-sql-tone)",
        "background": "var(--sprout-surface)",
        "width": "272px",
        "color": "var(--sprout-text)",
        "box-shadow": "var(--sprout-shadow-control)",
        "transition": "opacity var(--sprout-motion-normal) var(--sprout-motion-ease),\n      box-shadow var(--sprout-motion-fast) var(--sprout-motion-ease),\n      border-color var(--sprout-motion-fast) var(--sprout-motion-ease)",
        "border-radius": "10px",
        "overflow": "hidden"
      },
      ".sprout-sql-table[data-dimmed]": {
        "opacity": ".38"
      },
      ".sprout-sql-table[data-active], .react-flow__node.dragging .sprout-sql-table": {
        "box-shadow": "var(--sprout-shadow-panel)"
      },
      ".sprout-sql-table[data-active]": {
        "border-color": "color-mix(in oklab, var(--sprout-sql-tone) 55%, var(--sprout-line))"
      },
      ".sprout-sql-table-header": {
        "box-sizing": "border-box",
        "border-bottom": "1px solid var(--sprout-line)",
        "background": "color-mix(in oklab, var(--sprout-sql-tone) 9%, var(--sprout-surface))",
        "justify-content": "center",
        "align-items": "center",
        "height": "40px",
        "padding": "0 12px",
        "display": "flex"
      },
      ".sprout-sql-table-title": {
        "min-width": "0",
        "color": "var(--sprout-text)",
        "font-size": "var(--sprout-text-sm)",
        "text-overflow": "ellipsis",
        "white-space": "nowrap",
        "margin": "0",
        "font-weight": "600",
        "line-height": "1.25rem",
        "overflow": "hidden"
      },
      ".sprout-sql-columns, .sprout-sql-keys-list": {
        "margin": "0",
        "padding": "0",
        "list-style": "none"
      },
      ".sprout-sql-column": {
        "box-sizing": "border-box",
        "align-items": "center",
        "gap": "8px",
        "height": "28px",
        "padding": "0 12px",
        "font-size": ".8125rem",
        "line-height": "1.25rem",
        "display": "flex",
        "position": "relative"
      },
      ".sprout-sql-column + .sprout-sql-column": {
        "box-shadow": "inset 0 1px 0 color-mix(in oklab, var(--sprout-line) 60%, transparent)"
      },
      ".sprout-sql-column[data-join]": {
        "cursor": "pointer"
      },
      ".sprout-sql-column[data-active]": {
        "background": "color-mix(in oklab, var(--sprout-primary) 8%, transparent)"
      },
      "@media (hover: hover)": {
        ".sprout-sql-column[data-join]:hover": {
          "background": "color-mix(in oklab, var(--sprout-primary) 8%, transparent)"
        },
        ".sprout-sql-more-button:hover": {
          "border-color": "var(--sprout-primary)",
          "transform": "translate(-2px, -2px)"
        }
      },
      ".sprout-sql-column-icon": {
        "width": "12px",
        "color": "var(--sprout-muted)",
        "flex-shrink": "0",
        "justify-content": "center",
        "display": "flex"
      },
      ".sprout-sql-column[data-key=\"primary\"] .sprout-sql-column-icon": {
        "color": "var(--sprout-warning)"
      },
      ".sprout-sql-column[data-join] .sprout-sql-column-icon": {
        "color": "var(--sprout-primary)"
      },
      ".sprout-sql-column-name": {
        "text-overflow": "ellipsis",
        "white-space": "nowrap",
        "flex": "1",
        "min-width": "0",
        "overflow": "hidden"
      },
      ".sprout-sql-column[data-key=\"primary\"] .sprout-sql-column-name": {
        "font-weight": "600"
      },
      ".sprout-sql-column-type": {
        "max-width": "50%",
        "color": "var(--sprout-muted)",
        "font-family": "var(--sprout-sql-mono)",
        "text-overflow": "ellipsis",
        "white-space": "nowrap",
        "flex-shrink": "0",
        "font-size": ".6875rem",
        "overflow": "hidden"
      },
      ".sprout-sql-keys": {
        "border-top": "1px solid var(--sprout-line)",
        "background": "color-mix(in oklab, var(--sprout-hover) 40%, var(--sprout-surface))"
      },
      ".sprout-sql-keys-title": {
        "box-sizing": "border-box",
        "height": "35px",
        "color": "var(--sprout-muted)",
        "letter-spacing": ".06em",
        "text-transform": "uppercase",
        "margin": "0",
        "padding": "12px 12px 0",
        "font-size": ".6875rem",
        "font-weight": "600",
        "line-height": "1rem"
      },
      ".sprout-sql-key": {
        "box-sizing": "border-box",
        "height": "26px",
        "color": "var(--sprout-muted)",
        "font-size": "var(--sprout-text-xs)",
        "align-items": "center",
        "gap": "8px",
        "padding": "0 12px",
        "display": "flex"
      },
      ".sprout-sql-key > span": {
        "color": "var(--sprout-text)",
        "text-overflow": "ellipsis",
        "white-space": "nowrap",
        "overflow": "hidden"
      },
      ".sprout-sql-join": {
        "transition": "stroke var(--sprout-motion-fast) var(--sprout-motion-ease),\n      opacity var(--sprout-motion-normal) var(--sprout-motion-ease)"
      },
      ".sprout-sql-flow .sprout-sql-join[data-active]": {
        "stroke": "var(--sprout-primary)",
        "stroke-width": "1.75px"
      },
      ".sprout-sql-join[data-dimmed]": {
        "opacity": ".25"
      },
      ".sprout-sql-joins": {
        "box-sizing": "border-box",
        "border": "1px solid color-mix(in oklab, var(--sprout-primary) 40%, var(--sprout-line))",
        "background": "var(--sprout-surface)",
        "max-width": "calc(100% - 88px)",
        "box-shadow": "var(--sprout-shadow-control)",
        "pointer-events": "none",
        "border-radius": "8px",
        "flex-direction": "column",
        "gap": "4px",
        "padding": "8px 10px",
        "display": "flex"
      },
      ".sprout-sql-viewer[data-layout=\"vertical\"] .sprout-sql-joins": {
        "max-width": "calc(100% - 24px)"
      },
      ".sprout-sql-join-text": {
        "color": "var(--sprout-text)",
        "font-family": "var(--sprout-sql-mono)",
        "font-size": "var(--sprout-text-xs)",
        "text-overflow": "ellipsis",
        "white-space": "nowrap",
        "line-height": "1rem",
        "overflow": "hidden"
      },
      ".sprout-sql-joins-more": {
        "color": "var(--sprout-muted)",
        "font-size": "var(--sprout-text-xs)",
        "line-height": "1rem"
      },
      ".sprout-sql-more": {
        "width": "240px",
        "height": "132px",
        "position": "relative"
      },
      ".sprout-sql-more-sheet": {
        "border": "1px solid var(--sprout-line)",
        "background": "var(--sprout-surface)",
        "border-radius": "10px",
        "position": "absolute",
        "inset": "0"
      },
      ".sprout-sql-more-sheet:first-of-type": {
        "opacity": ".5",
        "transform": "translate(10px, 10px)"
      },
      ".sprout-sql-more-sheet:nth-of-type(2)": {
        "opacity": ".8",
        "transform": "translate(5px, 5px)"
      },
      ".sprout-sql-more-button": {
        "box-sizing": "border-box",
        "border": "1px dashed var(--sprout-border-strong)",
        "background": "var(--sprout-surface)",
        "color": "var(--sprout-text)",
        "font": "inherit",
        "text-align": "left",
        "cursor": "pointer",
        "box-shadow": "var(--sprout-shadow-control)",
        "transition": "transform var(--sprout-motion-fast) var(--sprout-motion-ease),\n      border-color var(--sprout-motion-fast) var(--sprout-motion-ease)",
        "border-radius": "10px",
        "flex-direction": "column",
        "justify-content": "center",
        "align-items": "flex-start",
        "gap": "4px",
        "padding": "16px 18px",
        "display": "flex",
        "position": "absolute",
        "inset": "0"
      },
      ".sprout-sql-more-button:focus-visible": {
        "outline": "var(--sprout-focus-width) solid var(--sprout-focus-ring)",
        "outline-offset": "2px"
      },
      ".sprout-sql-more-count": {
        "font-variant-numeric": "tabular-nums",
        "font-size": "1.125rem",
        "font-weight": "600",
        "line-height": "1.5rem"
      },
      ".sprout-sql-more-names": {
        "color": "var(--sprout-muted)",
        "font-size": "var(--sprout-text-xs)",
        "-webkit-line-clamp": "2",
        "-webkit-box-orient": "vertical",
        "line-height": "1rem",
        "display": "-webkit-box",
        "overflow": "hidden"
      },
      ".sprout-sql-more-action": {
        "color": "var(--sprout-primary)",
        "font-size": "var(--sprout-text-xs)",
        "margin-top": "6px",
        "font-weight": "600",
        "line-height": "1rem"
      },
      ".sprout-sql-empty": {
        "color": "var(--sprout-muted)",
        "font-size": "var(--sprout-text-sm)",
        "margin": "auto"
      },
      ".sprout-sql-sr-only": {
        "clip-path": "inset(50%)",
        "white-space": "nowrap",
        "border": "0",
        "width": "1px",
        "height": "1px",
        "margin": "-1px",
        "padding": "0",
        "position": "absolute",
        "overflow": "hidden"
      },
      "@media (prefers-reduced-motion: reduce)": {
        ".sprout-sql-table, .sprout-sql-join": {
          "transition": "opacity var(--sprout-motion-normal) linear"
        },
        ".sprout-sql-more-button": {
          "transition": "none"
        },
        ".sprout-sql-more-button:hover": {
          "transform": "none"
        }
      },
      ".sprout-schema-diagram": {
        "box-sizing": "border-box",
        "border": "1px solid var(--sprout-line)",
        "border-radius": "var(--sprout-radius-panel)",
        "background": "var(--sprout-canvas)",
        "width": "100%",
        "min-width": "0",
        "height": "100%",
        "min-height": "24rem",
        "color": "var(--sprout-text)",
        "font-family": "var(--sprout-font)",
        "flex": "1",
        "display": "flex",
        "position": "relative",
        "overflow": "hidden"
      },
      ".sprout-schema-flow.light, .sprout-schema-flow.dark": {
        "--sprout-canvas": "inherit",
        "--sprout-surface": "inherit",
        "--sprout-hover": "inherit",
        "--sprout-active": "inherit",
        "--sprout-text": "inherit",
        "--sprout-muted": "inherit",
        "--sprout-line": "inherit",
        "--sprout-border": "inherit",
        "--sprout-border-strong": "inherit",
        "--sprout-input": "inherit",
        "--sprout-primary": "inherit",
        "--sprout-primary-hover": "inherit",
        "--sprout-primary-active": "inherit",
        "--sprout-primary-subtle": "inherit",
        "--sprout-on-primary": "inherit",
        "--sprout-focus": "inherit",
        "--sprout-danger": "inherit",
        "--sprout-danger-hover": "inherit",
        "--sprout-danger-subtle": "inherit",
        "--sprout-on-danger": "inherit",
        "--sprout-info": "inherit",
        "--sprout-info-subtle": "inherit",
        "--sprout-secondary": "inherit",
        "--sprout-success": "inherit",
        "--sprout-success-subtle": "inherit",
        "--sprout-warning": "inherit",
        "--sprout-warning-subtle": "inherit",
        "--sprout-overlay": "inherit"
      },
      ".sprout-schema-flow": {
        "direction": "ltr",
        "background": "none",
        "outline": "none",
        "flex": "1",
        "width": "100%",
        "height": "100%",
        "min-height": "24rem",
        "position": "relative",
        "overflow": "hidden"
      },
      ".sprout-schema-flow:focus-visible": {
        "outline": "var(--sprout-focus-width) solid var(--sprout-focus-ring)",
        "outline-offset": "-1px",
        "border-radius": "inherit"
      },
      ".sprout-schema-flow .react-flow__container": {
        "width": "100%",
        "height": "100%",
        "position": "absolute",
        "top": "0",
        "left": "0"
      },
      ".sprout-schema-flow .react-flow__pane": {
        "z-index": "1",
        "touch-action": "none"
      },
      ".sprout-schema-flow .react-flow__pane.draggable": {
        "cursor": "grab"
      },
      ".sprout-schema-flow .react-flow__pane.dragging": {
        "cursor": "grabbing"
      },
      ".sprout-schema-flow .react-flow__viewport": {
        "z-index": "2",
        "transform-origin": "0 0",
        "pointer-events": "none"
      },
      ".sprout-schema-flow .react-flow__renderer": {
        "z-index": "4"
      },
      ".sprout-schema-flow .react-flow__background": {
        "z-index": "-1",
        "pointer-events": "none"
      },
      ".sprout-schema-flow .react-flow__background-pattern.dots": {
        "fill": "var(--sprout-line)"
      },
      ".sprout-schema-flow .react-flow__edges": {
        "position": "absolute"
      },
      ".sprout-schema-flow .react-flow__edges svg": {
        "pointer-events": "none",
        "position": "absolute",
        "overflow": "visible"
      },
      ".sprout-schema-flow .react-flow__edge-path": {
        "fill": "none",
        "stroke": "var(--sprout-muted)",
        "stroke-width": "1.25px"
      },
      ".sprout-schema-flow .react-flow__edgelabel-renderer, .sprout-schema-flow .react-flow__viewport-portal": {
        "pointer-events": "none",
        "user-select": "none",
        "width": "100%",
        "height": "100%",
        "position": "absolute",
        "top": "0",
        "left": "0"
      },
      ".sprout-schema-flow .react-flow__nodes": {
        "transform-origin": "0 0",
        "pointer-events": "none"
      },
      ".sprout-schema-flow .react-flow__node": {
        "box-sizing": "border-box",
        "transform-origin": "0 0",
        "user-select": "none",
        "pointer-events": "all",
        "cursor": "default",
        "border-radius": "8px",
        "outline": "none",
        "position": "absolute"
      },
      ".sprout-schema-flow .react-flow__node.draggable": {
        "cursor": "grab"
      },
      ".sprout-schema-flow .react-flow__node.dragging": {
        "cursor": "grabbing"
      },
      ".sprout-schema-flow .react-flow__node:focus-visible": {
        "outline": "var(--sprout-focus-width) solid var(--sprout-focus-ring)",
        "outline-offset": "0"
      },
      ".sprout-schema-flow .react-flow__panel": {
        "z-index": "5",
        "margin": "12px",
        "position": "absolute"
      },
      ".sprout-schema-flow .react-flow__panel.top": {
        "top": "0"
      },
      ".sprout-schema-flow .react-flow__panel.bottom": {
        "bottom": "0"
      },
      ".sprout-schema-flow .react-flow__panel.right": {
        "right": "0"
      },
      ".sprout-schema-flow .react-flow__panel.left": {
        "left": "0"
      },
      ".sprout-schema-handle.react-flow__handle": {
        "opacity": "0",
        "pointer-events": "none",
        "border": "0",
        "width": "6px",
        "min-width": "0",
        "height": "6px",
        "min-height": "0",
        "position": "absolute"
      },
      ".sprout-schema-handle.react-flow__handle-left": {
        "top": "50%",
        "left": "0",
        "transform": "translate(-50%, -50%)"
      },
      ".sprout-schema-handle.react-flow__handle-right": {
        "top": "50%",
        "right": "0",
        "transform": "translate(50%, -50%)"
      },
      ".sprout-schema-handle.react-flow__handle-top": {
        "top": "0",
        "left": "50%",
        "transform": "translate(-50%, -50%)"
      },
      ".sprout-schema-handle.react-flow__handle-bottom": {
        "bottom": "0",
        "left": "50%",
        "transform": "translate(-50%, 50%)"
      },
      ".sprout-schema-handle-target.react-flow__handle-left": {
        "top": "22px"
      },
      ".sprout-schema-table": {
        "box-sizing": "border-box",
        "border": "1px solid var(--sprout-line)",
        "background": "var(--sprout-surface)",
        "width": "264px",
        "color": "var(--sprout-text)",
        "box-shadow": "var(--sprout-shadow-control)",
        "border-top-width": "2px",
        "border-radius": "8px",
        "overflow": "hidden"
      },
      ".sprout-schema-table[data-state=\"new\"]": {
        "border-top-color": "var(--sprout-success)"
      },
      ".sprout-schema-table[data-state=\"changed\"]": {
        "border-top-color": "var(--sprout-warning)"
      },
      ".sprout-schema-table[data-state=\"linked\"]": {
        "border-style": "dashed",
        "border-top-color": "var(--sprout-line)"
      },
      ".react-flow__node.dragging .sprout-schema-table": {
        "box-shadow": "var(--sprout-shadow-panel)"
      },
      ".sprout-schema-table-header": {
        "box-sizing": "border-box",
        "border-bottom": "1px solid var(--sprout-line)",
        "background": "color-mix(in oklab, var(--sprout-hover) 45%, var(--sprout-surface))",
        "align-items": "center",
        "gap": "8px",
        "height": "44px",
        "padding": "0 12px",
        "display": "flex"
      },
      ".sprout-schema-table-title": {
        "min-width": "0",
        "color": "var(--sprout-text)",
        "font-size": "var(--sprout-text-sm)",
        "text-overflow": "ellipsis",
        "white-space": "nowrap",
        "flex": "1",
        "margin": "0",
        "font-weight": "500",
        "line-height": "1.25rem",
        "overflow": "hidden"
      },
      ".sprout-schema-table-empty": {
        "color": "var(--sprout-muted)",
        "font-size": "var(--sprout-text-xs)",
        "margin": "0",
        "padding": "8px 12px",
        "line-height": "1rem"
      },
      ".sprout-schema-fields": {
        "margin": "0",
        "padding": "0",
        "list-style": "none"
      },
      ".sprout-schema-field": {
        "border-bottom": "1px solid var(--sprout-line)",
        "padding": "6px 12px",
        "position": "relative"
      },
      ".sprout-schema-field:last-child": {
        "border-bottom": "0"
      },
      ".sprout-schema-field[data-change=\"added\"]": {
        "background": "var(--sprout-success-subtle)"
      },
      ".sprout-schema-field[data-change=\"changed\"]": {
        "background": "var(--sprout-warning-subtle)"
      },
      ".sprout-schema-field[data-change=\"removed\"]": {
        "background": "var(--sprout-danger-subtle)"
      },
      ".sprout-schema-field-line": {
        "align-items": "center",
        "gap": "8px",
        "height": "20px",
        "font-size": ".8125rem",
        "line-height": "1.25rem",
        "display": "flex"
      },
      ".sprout-schema-field[data-change=\"removed\"] .sprout-schema-field-line": {
        "text-decoration": "line-through"
      },
      ".sprout-schema-field-key": {
        "width": "12px",
        "color": "var(--sprout-muted)",
        "flex-shrink": "0",
        "justify-content": "center",
        "display": "flex"
      },
      ".sprout-schema-field-name": {
        "min-width": "0",
        "color": "var(--sprout-text)",
        "text-overflow": "ellipsis",
        "white-space": "nowrap",
        "flex": "1",
        "overflow": "hidden"
      },
      ".sprout-schema-field-required": {
        "color": "var(--sprout-muted)"
      },
      ".sprout-schema-field-type": {
        "max-width": "45%",
        "color": "var(--sprout-muted)",
        "font-size": "var(--sprout-text-xs)",
        "text-overflow": "ellipsis",
        "white-space": "nowrap",
        "flex-shrink": "0",
        "overflow": "hidden"
      },
      ".sprout-schema-field-detail": {
        "color": "var(--sprout-muted)",
        "font-size": "var(--sprout-text-xs)",
        "text-overflow": "ellipsis",
        "white-space": "nowrap",
        "margin": "0",
        "padding-left": "20px",
        "line-height": "1rem",
        "overflow": "hidden"
      },
      ".sprout-schema-link-label": {
        "box-sizing": "border-box",
        "border": "1px solid var(--sprout-line)",
        "background": "var(--sprout-surface)",
        "max-width": "180px",
        "color": "var(--sprout-muted)",
        "font-family": "var(--sprout-font)",
        "font-size": "var(--sprout-text-xs)",
        "text-overflow": "ellipsis",
        "white-space": "nowrap",
        "pointer-events": "none",
        "border-radius": "6px",
        "padding": "0 6px",
        "line-height": "1rem",
        "position": "absolute",
        "overflow": "hidden"
      },
      ".sprout-schema-controls": {
        "border": "1px solid var(--sprout-line)",
        "background": "var(--sprout-surface)",
        "box-shadow": "var(--sprout-shadow-control)",
        "border-radius": "8px",
        "flex-direction": "column",
        "gap": "2px",
        "padding": "2px",
        "display": "flex"
      },
      ".sprout-schema-legend": {
        "color": "var(--sprout-muted)",
        "font-family": "var(--sprout-font)",
        "font-size": "var(--sprout-text-xs)",
        "flex-wrap": "wrap",
        "align-items": "center",
        "gap": "4px 16px",
        "margin": "0",
        "padding": "0",
        "line-height": "1rem",
        "list-style": "none",
        "display": "flex"
      },
      ".sprout-schema-legend-item": {
        "align-items": "center",
        "gap": "6px",
        "display": "flex"
      },
      ".sprout-schema-legend-swatch": {
        "border-radius": "2px",
        "flex-shrink": "0",
        "width": "10px",
        "height": "10px"
      },
      ".sprout-schema-legend-swatch[data-change=\"added\"]": {
        "background": "var(--sprout-success-subtle)",
        "box-shadow": "0 0 0 1px var(--sprout-success)"
      },
      ".sprout-schema-legend-swatch[data-change=\"changed\"]": {
        "background": "var(--sprout-warning-subtle)",
        "box-shadow": "0 0 0 1px var(--sprout-warning)"
      },
      ".sprout-schema-legend-swatch[data-change=\"removed\"]": {
        "background": "var(--sprout-danger-subtle)",
        "box-shadow": "0 0 0 1px var(--sprout-danger)"
      },
      ".sprout-schema-sr-only": {
        "clip-path": "inset(50%)",
        "white-space": "nowrap",
        "border": "0",
        "width": "1px",
        "height": "1px",
        "margin": "-1px",
        "padding": "0",
        "position": "absolute",
        "overflow": "hidden"
      },
      "@media (prefers-reduced-motion: no-preference)": {
        ".sprout-schema-table": {
          "transition": "box-shadow var(--sprout-motion-normal) var(--sprout-motion-ease)"
        },
        ".sprout-schema-flow .react-flow__node": {
          "transition": "outline-color var(--sprout-motion-fast) ease-out"
        }
      }
    }
  },
  "docs": "Docs and examples: https://sprout.tulipfarm.ai/components/sql-viewer/",
  "meta": {
    "source": "packages/sprout/src/components/sql-viewer.tsx"
  }
}
