{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "base-styled",
  "type": "registry:lib",
  "title": "Base UI styling helper",
  "description": "Preserve Base UI props and refs while adding owned classes.",
  "dependencies": [],
  "registryDependencies": [
    "https://ghost-ui.com/r/foundation.json"
  ],
  "files": [
    {
      "path": "src/components/ui/base-styled.tsx",
      "type": "registry:component",
      "target": "@ui/base-styled.tsx",
      "content": "\"use client\";\n\nimport \"./foundation.css\";\nimport * as React from \"react\";\n\n/**\n * Internal adapter shared by Ghost components that compose Base UI behavior.\n * It owns no public component names and is not a registry item.\n */\ntype RenderProp<C extends React.ElementType> = React.ComponentProps<C> extends { render?: infer Render } ? Render : never;\n\nexport function styled<C extends React.ElementType>(Component: C, classes: string, defaultRender?: RenderProp<C>): C {\n  const Part = React.forwardRef<unknown, Record<string, unknown>>(\n    function StyledPart(props, ref) {\n      const { className, ...rest } = props;\n      if (defaultRender !== undefined && rest.render === undefined) rest.render = defaultRender;\n      const merged =\n        typeof className === \"function\"\n          ? (state: unknown) => [classes, className(state)].filter(Boolean).join(\" \")\n          : [classes, className].filter(Boolean).join(\" \");\n      return React.createElement(Component as React.ElementType, {\n        ...rest,\n        ref,\n        className: merged,\n      });\n    },\n  );\n  Part.displayName = `Styled(${typeof Component === \"string\" ? Component : ((Component as { displayName?: string }).displayName ?? \"BasePart\")})`;\n  return Part as unknown as C;\n}\n\n/** Track clipped options without changing the list's rendering or scroll owner. */\nexport function scrollFadeStyled<C extends React.ElementType>(Component: C, classes: string): C {\n  const List = styled(Component, classes);\n  const Part = React.forwardRef<HTMLElement, React.HTMLAttributes<HTMLElement>>(function ScrollFadeList(props, ref) {\n    const [node, setNode] = React.useState<HTMLElement | null>(null);\n    const setRef = React.useCallback((element: HTMLElement | null) => {\n      setNode(element);\n      if (typeof ref === \"function\") return ref(element);\n      if (ref) ref.current = element;\n    }, [ref]);\n    React.useLayoutEffect(() => {\n      if (!node) return;\n      const update = () => {\n        node.toggleAttribute(\"data-scroll-fade-start\", node.scrollTop > 1);\n        node.toggleAttribute(\"data-scroll-fade-end\", node.scrollHeight - node.clientHeight - node.scrollTop > 1);\n      };\n      update();\n      node.addEventListener(\"scroll\", update, { passive: true });\n      const resize = typeof ResizeObserver === \"undefined\" ? null : new ResizeObserver(update);\n      resize?.observe(node);\n      const changes = new MutationObserver(update);\n      changes.observe(node, { childList: true, subtree: true, characterData: true });\n      return () => {\n        node.removeEventListener(\"scroll\", update);\n        resize?.disconnect();\n        changes.disconnect();\n      };\n    }, [node]);\n    return React.createElement(List as React.ElementType, { ...props, ref: setRef });\n  });\n  return Part as unknown as C;\n}\n\nfunction hasFeedbackContent(children: React.ReactNode): boolean | undefined {\n  if (children == null || typeof children === \"boolean\" || children === \"\") return false;\n  if (Array.isArray(children)) {\n    const content = children.map(hasFeedbackContent);\n    return content.includes(true) ? true : content.includes(undefined) ? undefined : false;\n  }\n  if (React.isValidElement<{ children?: React.ReactNode }>(children)) {\n    if (children.type === React.Fragment) return hasFeedbackContent(children.props.children);\n    return typeof children.type === \"string\" ? true : undefined;\n  }\n  return typeof children === \"string\" || typeof children === \"number\" || typeof children === \"bigint\" ? true : undefined;\n}\n\n/** Shared content geometry; Base UI retains the live region and ref. */\nexport function renderListFeedback({ children, ...props }: React.ComponentPropsWithRef<\"div\">) {\n  // Opaque components retain DOM-based emptiness detection: they may render null.\n  const content = hasFeedbackContent(children);\n  return <div {...props} data-list-feedback-empty={content === undefined ? undefined : String(!content)}><div className=\"ui-list-feedback-content\">{children}</div></div>;\n}\n\nexport type ChoiceVariant = \"default\" | \"interactive\";\n\n/** Rows and controls inherit the group style unless explicitly overridden. */\nexport function choiceStyled<C extends React.ElementType>(Component: C, classes: string, defaultVariant?: ChoiceVariant) {\n  type Props = React.ComponentPropsWithoutRef<C> & { variant?: ChoiceVariant };\n  const Part = styled(Component, classes);\n  const Choice = React.forwardRef<React.ComponentRef<C>, Props>(function Choice({ variant = defaultVariant, ...props }, ref) {\n    return React.createElement(Part as React.ElementType, { ...props, ref, \"data-choice-variant\": variant });\n  });\n  Choice.displayName = `Choice(${classes})`;\n  return Choice;\n}\n\n/**\n * Menu rows need a real element around their label: CSS cannot see text nodes, so a\n * bare `<Icon />Label` row would be indistinguishable from a trailing `Label<Icon />`.\n * Wrapping the label keeps `svg:first-child` an honest \"leading icon\" signal.\n * Text is grouped into runs so rich labels (`Add <strong>node</strong>`) stay one\n * flex item instead of gaining a gap between every text segment.\n */\nconst INLINE_TAGS = new Set([\"a\", \"abbr\", \"b\", \"bdi\", \"bdo\", \"br\", \"cite\", \"code\", \"data\", \"del\", \"dfn\", \"em\", \"i\", \"ins\", \"kbd\", \"label\", \"mark\", \"q\", \"s\", \"samp\", \"small\", \"span\", \"strong\", \"sub\", \"sup\", \"time\", \"u\", \"var\", \"wbr\"]);\nconst SLOT_CLASSES = [\"ui-kbd\", \"ui-kbd-group\", \"ui-menu-item-text\", \"ui-menu-item-icon\", \"ui-menu-item-indicator\", \"ui-select-item-indicator\"];\n\nfunction isTextNode(node: React.ReactNode): node is string | number {\n  return typeof node === \"string\" || typeof node === \"number\";\n}\n\nfunction isSlotPart(node: React.ReactNode) {\n  if (!React.isValidElement<{ className?: unknown; \"data-menu-trailing\"?: unknown; \"data-submenu-icon\"?: unknown }>(node)) return false;\n  if (node.type === \"svg\" || node.type === \"img\") return true;\n  const { className, ...data } = node.props;\n  return (typeof className === \"string\" && className.split(/\\s+/).some(name => SLOT_CLASSES.includes(name)))\n    || data[\"data-menu-trailing\"] !== undefined\n    || data[\"data-submenu-icon\"] !== undefined;\n}\n\nfunction isInlineElement(node: React.ReactNode) {\n  return React.isValidElement(node) && typeof node.type === \"string\" && INLINE_TAGS.has(node.type);\n}\n\nfunction flattenChildren(children: React.ReactNode): React.ReactNode[] {\n  const nodes: React.ReactNode[] = [];\n  React.Children.forEach(children, (child) => {\n    if (React.isValidElement<{ children?: React.ReactNode }>(child) && child.type === React.Fragment) {\n      nodes.push(...flattenChildren(child.props.children));\n    } else {\n      nodes.push(child);\n    }\n  });\n  return nodes;\n}\n\nfunction wrapItemText(children: React.ReactNode): React.ReactNode {\n  const output: React.ReactNode[] = [];\n  let run: React.ReactNode[] = [];\n  const flush = () => {\n    if (!run.length) return;\n    output.push(run.some(isTextNode)\n      ? <span key={`label-${output.length}`} className=\"ui-menu-item-text\">{run}</span>\n      : run);\n    run = [];\n  };\n  for (const node of flattenChildren(children)) {\n    if (isSlotPart(node)) { flush(); output.push(node); continue; }\n    if (isTextNode(node)) {\n      // Whitespace between elements is JSX formatting, not label content.\n      if (typeof node === \"string\" && !node.trim() && !run.length) continue;\n      run.push(node);\n      continue;\n    }\n    if (isInlineElement(node)) { run.push(node); continue; }\n    flush();\n    output.push(node);\n  }\n  flush();\n  return output;\n}\n\nexport function menuItemStyled<C extends React.ElementType>(Component: C, classes: string): C {\n  const Part = styled(Component, classes);\n  const LabelledPart = React.forwardRef<unknown, Record<string, unknown>>(\n    function MenuItemPart({ children, ...props }, ref) {\n      return React.createElement(Part as React.ElementType, { ...props, ref }, wrapItemText(children as React.ReactNode));\n    },\n  );\n  LabelledPart.displayName = `MenuItem(${classes})`;\n  return LabelledPart as unknown as C;\n}\n"
    }
  ]
}
