{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "shared-background",
  "type": "registry:ui",
  "title": "Shared Background",
  "description": "A gliding hover background for quiet lists with keyboard-focus parity and reduced-motion support.",
  "dependencies": [],
  "registryDependencies": [
    "https://ghost-ui.com/r/ghost-tokens.json",
    "https://ghost-ui.com/r/foundation.json"
  ],
  "files": [
    {
      "path": "src/components/ui/shared-background.tsx",
      "type": "registry:component",
      "target": "@ui/shared-background.tsx",
      "content": "\"use client\";\n\nimport \"./foundation.css\";\nimport * as React from \"react\";\nimport \"./shared-background.css\";\n\nexport interface SharedBackgroundProps extends React.HTMLAttributes<HTMLElement> {\n  /** Semantic container for rows. Use li children under ul/ol. */\n  as?: \"div\" | \"ul\" | \"ol\";\n  orientation?: \"vertical\" | \"horizontal\";\n  /** Surface follows hover/focus; line falls back to selection; line-combined retains selection alongside a hover/focus line. */\n  presentation?: \"surface\" | \"line\" | \"line-combined\";\n  /** Surface color owned by this primitive. */\n  surface?: \"card\" | \"secondary\" | \"secondary-hover\";\n  /** Horizontal bleed of the surface past each row, in px. */\n  inset?: number;\n  /** Resolve interactive rows among descendants instead of direct children. */\n  targetSelector?: string;\n}\n\ntype RowRect = { top: number; left: number; height: number; width: number; rtl: boolean; initial: boolean };\nconst ROW = \"[data-ui-shared-background-row]\";\nconst DISABLED = \"[data-disabled], [disabled], [aria-disabled='true']\";\n\n/** Measured feedback layers retain row semantics and selection in their callers. */\nexport const SharedBackground = React.forwardRef<HTMLElement, SharedBackgroundProps>(function SharedBackground({\n  as = \"div\", orientation = \"vertical\", presentation = \"surface\",\n  surface = \"card\",\n  inset = orientation === \"horizontal\" ? 0 : 12,\n  targetSelector,\n  className, children, style: callerStyle, onMouseOver, onMouseLeave, onFocus, onBlur, onScroll, ...rest\n}, forwardedRef) {\n  const containerRef = React.useRef<HTMLElement | null>(null);\n  const activeRef = React.useRef<Element | null>(null);\n  const hoveredRef = React.useRef<Element | null>(null);\n  const focusedRef = React.useRef<Element | null>(null);\n  const [pill, setPill] = React.useState<RowRect | null>(null);\n  const [selectedLine, setSelectedLine] = React.useState<RowRect | null>(null);\n\n  const eligible = React.useCallback((row: Element | null) => {\n    const container = containerRef.current;\n    return row && container && container.contains(row) &&\n      (targetSelector ? row.matches(targetSelector) : row.parentElement === container) &&\n      !row.matches(DISABLED) && (targetSelector || !row.querySelector(DISABLED)) ? row : null;\n  }, [targetSelector]);\n  const rowFrom = React.useCallback((target: EventTarget | null) =>\n    target instanceof Element\n      ? eligible(target.closest(targetSelector ?? ROW))\n      : null, [eligible, targetSelector]);\n\n  const measure = React.useCallback((row: Element | null, setRect: React.Dispatch<React.SetStateAction<RowRect | null>>) => {\n    const container = containerRef.current;\n    if (!container || !row) { setRect(null); return; }\n    const parent = container.getBoundingClientRect();\n    const rect = row.getBoundingClientRect();\n    const next = {\n      top: rect.top - parent.top + container.scrollTop,\n      left: rect.left - parent.left + container.scrollLeft,\n      height: rect.height, width: rect.width,\n      rtl: getComputedStyle(container).direction === \"rtl\",\n    };\n    if (!Number.isFinite(next.top) || !Number.isFinite(next.left) || next.height <= 0 || next.width <= 0) { setRect(null); return; }\n    setRect(previous => previous && Object.keys(next).every(key => previous[key as keyof typeof next] === next[key as keyof typeof next]) ? previous : { ...next, initial: previous === null });\n  }, []);\n\n  const refresh = React.useCallback(() => {\n    const container = containerRef.current;\n    if (!container) return;\n    let row = eligible(activeRef.current);\n    if (presentation === \"line\") {\n      const selected = rowsIn(container, targetSelector).find(child => child.matches(\"[data-active]\") || child.querySelector(\"[data-active]\")) ?? null;\n      row = eligible(focusedRef.current) ?? eligible(hoveredRef.current) ?? eligible(selected);\n      activeRef.current = row;\n      measure(row, setPill);\n      setSelectedLine(null);\n      return;\n    }\n    if (presentation === \"line-combined\") {\n      const selected = rowsIn(container, targetSelector).find(child => child.matches(\"[data-active]\") || child.querySelector(\"[data-active]\")) ?? null;\n      row = eligible(hoveredRef.current) ?? eligible(focusedRef.current);\n      activeRef.current = row;\n      measure(row, setPill);\n      measure(eligible(selected), setSelectedLine);\n      return;\n    }\n    row = eligible(hoveredRef.current) ?? eligible(focusedRef.current);\n    activeRef.current = row;\n    measure(row, setPill);\n    setSelectedLine(null);\n  }, [eligible, measure, presentation, targetSelector]);\n\n  React.useLayoutEffect(() => {\n    const container = containerRef.current;\n    if (!container) return;\n    refresh();\n    let frame = 0;\n    let rowsDirty = false;\n    const schedule = () => {\n      if (frame) return;\n      frame = requestAnimationFrame(() => {\n        frame = 0;\n        if (rowsDirty) { rowsDirty = false; observeRows(); }\n        refresh();\n      });\n    };\n    const resize = typeof ResizeObserver === \"undefined\" ? null : new ResizeObserver(schedule);\n    const observeRows = () => {\n      resize?.disconnect(); resize?.observe(container);\n      for (const child of rowsIn(container, targetSelector)) resize?.observe(child);\n    };\n    observeRows();\n    const mutations = new MutationObserver((records) => {\n      if (records.every(record => record.target instanceof Element && record.target.matches(\".ui-shared-background__pill, .ui-shared-background__line\"))) return;\n      rowsDirty ||= records.some(record => {\n        if (record.type !== \"childList\") return record.target !== container;\n        if (record.target === container) return true;\n        return !!targetSelector && [...record.addedNodes, ...record.removedNodes].some(node =>\n          node instanceof Element && (node.matches(targetSelector) || node.querySelector(targetSelector)),\n        );\n      });\n      schedule();\n    });\n    mutations.observe(container, { childList: true, subtree: true, attributes: true });\n    container.addEventListener(\"scroll\", schedule, true);\n    window.addEventListener(\"resize\", schedule);\n    document.fonts?.addEventListener(\"loadingdone\", schedule);\n    return () => {\n      cancelAnimationFrame(frame);\n      resize?.disconnect(); mutations.disconnect(); container.removeEventListener(\"scroll\", schedule, true);\n      window.removeEventListener(\"resize\", schedule); document.fonts?.removeEventListener(\"loadingdone\", schedule);\n    };\n  }, [refresh, targetSelector]);\n\n  const rows = React.Children.toArray(children).filter(React.isValidElement).map((child, index) => {\n    const element = child as React.ReactElement;\n    return React.cloneElement(element, { key: element.key ?? `row-${index}`, ...({ \"data-ui-shared-background-row\": \"\" } as Record<string, string>) });\n  });\n  const style: React.CSSProperties = !pill ? { opacity: 0 } : presentation === \"line\" || presentation === \"line-combined\" ? {\n    transform: orientation === \"horizontal\"\n      ? `translate(${pill.left}px, ${pill.top + pill.height - 1}px)`\n      : `translate(${pill.left + (pill.rtl ? 0 : pill.width - 1)}px, ${pill.top}px)`,\n    width: orientation === \"horizontal\" ? pill.width : undefined,\n    height: orientation === \"vertical\" ? pill.height : undefined,\n    transition: pill.initial ? \"none\" : undefined,\n  } : {\n    transform: orientation === \"horizontal\" || targetSelector ? `translate(${pill.left}px, ${pill.top}px)` : `translateY(${pill.top}px)`,\n    height: pill.height, width: orientation === \"horizontal\" || targetSelector ? pill.width + inset * 2 : undefined,\n    top: orientation === \"horizontal\" ? 0 : undefined, left: -inset,\n    right: orientation === \"horizontal\" ? undefined : -inset,\n    transition: pill.initial ? \"none\" : undefined,\n  };\n  const selectedLineStyle: React.CSSProperties = !selectedLine ? { opacity: 0 } : {\n    transform: orientation === \"horizontal\"\n      ? `translate(${selectedLine.left}px, ${selectedLine.top + selectedLine.height - 1}px)`\n      : `translate(${selectedLine.left + (selectedLine.rtl ? 0 : selectedLine.width - 1)}px, ${selectedLine.top}px)`,\n    width: orientation === \"horizontal\" ? selectedLine.width : undefined,\n    height: orientation === \"vertical\" ? selectedLine.height : undefined,\n    transition: selectedLine.initial ? \"none\" : undefined,\n  };\n\n  return React.createElement(as, {\n    ...rest,\n    ref: (node: HTMLElement | null) => {\n      containerRef.current = node;\n      if (typeof forwardedRef === \"function\") forwardedRef(node); else if (forwardedRef) forwardedRef.current = node;\n    },\n    className: [\"ui-shared-background\", className].filter(Boolean).join(\" \"),\n    style: {\n      ...callerStyle,\n      ...(pill ? { \"--ui-shared-background-target-height\": `${pill.height}px` } : {}),\n    } as React.CSSProperties,\n    \"data-orientation\": orientation, \"data-presentation\": presentation, \"data-surface\": surface,\n    onMouseOver: (event: React.MouseEvent<HTMLElement>) => {\n      if (event.target !== event.currentTarget) {\n        hoveredRef.current = rowFrom(event.target); activeRef.current = hoveredRef.current;\n      }\n      refresh(); onMouseOver?.(event);\n    },\n    onMouseLeave: (event: React.MouseEvent<HTMLElement>) => {\n      hoveredRef.current = null; activeRef.current = null; refresh(); onMouseLeave?.(event);\n    },\n    onFocus: (event: React.FocusEvent<HTMLElement>) => {\n      focusedRef.current = rowFrom(event.target); activeRef.current = focusedRef.current;\n      if (presentation !== \"line\") hoveredRef.current = null;\n      refresh(); onFocus?.(event);\n    },\n    onBlur: (event: React.FocusEvent<HTMLElement>) => {\n      if (!(event.relatedTarget instanceof Node && event.currentTarget.contains(event.relatedTarget))) {\n        focusedRef.current = null; activeRef.current = null; refresh();\n      }\n      onBlur?.(event);\n    },\n    onScroll,\n  }, <><div aria-hidden=\"true\" className=\"ui-shared-background__pill\" data-visible={pill ? \"\" : undefined} style={style} />{presentation === \"line-combined\" && <div aria-hidden=\"true\" className=\"ui-shared-background__line\" data-visible={selectedLine ? \"\" : undefined} style={selectedLineStyle} />}{rows}</>);\n});\n\nfunction rowsIn(container: HTMLElement, selector?: string): Element[] {\n  if (selector) return [...container.querySelectorAll(selector)];\n  return [...container.children].filter((child) => child.matches(ROW));\n}\n"
    },
    {
      "path": "src/components/ui/shared-background.css",
      "type": "registry:file",
      "target": "@ui/shared-background.css",
      "content": "@import \"./tokens.css\";\n\n/* Shared gliding hover background for quiet lists. One pill follows the\n   hovered or keyboard-focused row; content always paints above it. */\n.ui-shared-background {\n  position: relative;\n  display: flex;\n  flex-direction: column;\n  margin: 0;\n  padding: 0;\n  list-style: none;\n}\n.ui-shared-background[data-orientation=\"horizontal\"] {\n  flex-direction: row;\n  align-items: stretch;\n}\n.ui-shared-background[data-orientation=\"horizontal\"] .ui-shared-background__pill {\n  right: auto;\n}\n/* Internal geometry recipe: floating primitives can retain their own measured\n   surface while sharing the same motion as row feedback. */\n.ui-shared-background__pill,\n.ui-shared-background__line {\n  transition:\n    transform 0.18s var(--ease-standard),\n    width 0.18s var(--ease-standard),\n    height 0.18s var(--ease-standard),\n    opacity 0.12s var(--ease-standard);\n}\n/* Floating owners opt into the same recipe using their positioning properties. */\n.ui-shared-background-motion {\n  transition-property: var(--ui-shared-background-properties, transform, width, height, opacity);\n  transition-duration: var(--ui-shared-background-duration, 0.18s);\n  transition-timing-function: var(--ui-shared-background-ease, var(--ease-standard));\n}\n.ui-shared-background__pill {\n  position: absolute;\n  top: 0;\n  z-index: 0;\n  border-radius: var(--ui-shared-background-radius, var(--radius-lg, 12px));\n  background: var(--card);\n  opacity: 0;\n}\n.ui-shared-background[data-surface=\"secondary-hover\"] .ui-shared-background__pill {\n  background: var(--secondary-hover);\n}\n.ui-shared-background[data-surface=\"secondary\"] .ui-shared-background__pill {\n  background: var(--secondary);\n}\n.ui-shared-background__pill[data-visible] {\n  opacity: 1;\n}\n/* Touch can synthesize hover and focus without keyboard navigation. */\n.ui-shared-background[data-presentation=\"surface\"]:not(:has(:focus-visible)) > .ui-shared-background__pill {\n  opacity: 0;\n}\n@media (hover: hover) {\n  .ui-shared-background[data-presentation=\"surface\"]:hover > .ui-shared-background__pill[data-visible] {\n    opacity: 1;\n  }\n}\n.ui-shared-background > :not(.ui-shared-background__pill):not(.ui-shared-background__line) {\n  position: relative;\n  z-index: 1;\n  margin: 0;\n}\n@media (prefers-reduced-motion: reduce) {\n  .ui-shared-background-motion,\n  .ui-shared-background__pill,\n  .ui-shared-background__line {\n    transition: none;\n  }\n}\n\n/* Line feedback composes ghost Buttons without adding a hover/press surface. */\n.ui-shared-background:is([data-presentation=\"line\"], [data-presentation=\"line-combined\"]) {\n  --quiet-hover: transparent;\n  --quiet-active: transparent;\n}\n.ui-shared-background:is([data-presentation=\"line\"], [data-presentation=\"line-combined\"]) > [data-ui-shared-background-row] > :where([data-variant=\"ghost\"]) {\n  background: transparent;\n}\n.ui-shared-background:is([data-presentation=\"line\"], [data-presentation=\"line-combined\"]) > [data-ui-shared-background-row]:focus-visible,\n.ui-shared-background:is([data-presentation=\"line\"], [data-presentation=\"line-combined\"]) > [data-ui-shared-background-row] > :where([data-variant=\"ghost\"]):focus-visible { outline: none; }\n.ui-shared-background:is([data-presentation=\"line\"], [data-presentation=\"line-combined\"]):has(:focus-visible) > .ui-shared-background__pill { background: var(--foreground); }\n.ui-shared-background[data-presentation=\"line\"] .ui-shared-background__pill {\n  top: 0;\n  left: 0;\n  right: auto;\n  pointer-events: none;\n  border-radius: 0;\n  background: var(--primary);\n  height: 1px;\n}\n.ui-shared-background[data-presentation=\"line\"][data-orientation=\"vertical\"] .ui-shared-background__pill {\n  width: 1px;\n  height: auto;\n}\n.ui-shared-background[data-presentation=\"line-combined\"] .ui-shared-background__pill {\n  top: 0;\n  left: 0;\n  right: auto;\n  pointer-events: none;\n  border-radius: 0;\n  background: var(--muted-foreground);\n  height: 1px;\n}\n.ui-shared-background[data-presentation=\"line-combined\"][data-orientation=\"vertical\"] .ui-shared-background__pill {\n  width: 1px;\n  height: auto;\n}\n.ui-shared-background__line {\n  position: absolute;\n  top: 0;\n  left: 0;\n  z-index: 0;\n  pointer-events: none;\n  border-radius: 0;\n  background: var(--primary);\n  opacity: 0;\n}\n.ui-shared-background__line[data-visible] {\n  opacity: 1;\n}\n.ui-shared-background[data-presentation=\"line-combined\"][data-orientation=\"horizontal\"] .ui-shared-background__line {\n  height: 1px;\n}\n.ui-shared-background[data-presentation=\"line-combined\"][data-orientation=\"vertical\"] .ui-shared-background__line {\n  width: 1px;\n}\n@media (forced-colors: active) {\n  .ui-shared-background:is([data-presentation=\"line\"], [data-presentation=\"line-combined\"]):has(:focus-visible) > .ui-shared-background__pill { background: Highlight; forced-color-adjust: none; }\n}\n"
    }
  ]
}
