{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "highlight",
  "title": "Highlight",
  "description": "A Motion-powered highlight effect that allows you to highlight elements on hover, click or with a controlled value.",
  "dependencies": ["motion"],
  "registryDependencies": ["utils"],
  "files": [
    {
      "path": "registry/primitives/effects/highlight/index.tsx",
      "content": "/* eslint-disable eqeqeq, no-eq-null -- highlight overlay bounds calculation */\n\"use client\";\nimport { cn } from \"@/lib/utils\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport type { Transition } from \"motion/react\";\nimport {\n  Children,\n  cloneElement,\n  createContext,\n  Fragment,\n  isValidElement,\n  useCallback,\n  useContext,\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useMemo,\n  useRef,\n  useState,\n} from \"react\";\nimport type {\n  ComponentPropsWithoutRef,\n  CSSProperties,\n  MouseEvent,\n  ReactElement,\n  ReactNode,\n  Ref,\n  RefCallback,\n  RefObject,\n} from \"react\";\n\n// ─── Types ────────────────────────────────────────────────────────────────────\ntype HighlightMode = \"children\" | \"parent\";\ntype HighlightTrigger = \"hover\" | \"click\";\ninterface Bounds {\n  height: number;\n  left: number;\n  top: number;\n  width: number;\n}\ninterface HighlightContextValue {\n  activeClassName: string;\n  activeValue: string | null;\n  className?: string;\n  clearBounds: () => void;\n  disabled: boolean;\n  enabled: boolean;\n  exitDelay: number;\n  id: string;\n  mode: HighlightMode;\n  setActiveClassName: (className: string) => void;\n  setActiveValue: (value: string | null) => void;\n  setBounds: (bounds: DOMRect) => void;\n  style?: CSSProperties;\n  transition: Transition;\n  trigger: HighlightTrigger;\n}\ntype HandlerName = \"onClick\" | \"onMouseEnter\" | \"onMouseLeave\";\ntype OwnHandlers = Partial<\n  Record<HandlerName, (event: MouseEvent<HTMLElement>) => void>\n>;\nconst HANDLER_KEYS = [\"onClick\", \"onMouseEnter\", \"onMouseLeave\"] as const;\n/** Hoisted so the default keeps a stable identity across renders. */\nconst DEFAULT_TRANSITION: Transition = {\n  type: \"spring\",\n  stiffness: 350,\n  damping: 35,\n};\nconst INSTANT_TRANSITION: Transition = { duration: 0 };\ntype ExtendedChildProps = ComponentPropsWithoutRef<\"div\"> & {\n  \"data-highlight-value\"?: string;\n  ref?: Ref<HTMLElement>;\n};\n// ─── Helpers ──────────────────────────────────────────────────────────────────\nconst useIsomorphicLayoutEffect =\n  typeof window === \"undefined\" ? useEffect : useLayoutEffect;\n/** Collapse to an instant transition for `prefers-reduced-motion: reduce`. */\nfunction resolveTransition(\n  transition: Transition,\n  prefersReducedMotion: boolean | null\n): Transition {\n  return prefersReducedMotion ? { duration: 0 } : transition;\n}\nfunction isEqualTransition(a: Transition, b: Transition): boolean {\n  if (a === b) {\n    return true;\n  }\n  if (!(a && b)) {\n    return false;\n  }\n  const left = a as Record<string, unknown>;\n  const right = b as Record<string, unknown>;\n  const keys = Object.keys(left);\n  return (\n    keys.length === Object.keys(right).length &&\n    keys.every((key) => left[key] === right[key])\n  );\n}\n/**\n * Keeps a stable object identity while the resolved transition is shallow-equal.\n * Without this an inline `transition={{ ... }}` prop yields a new object every\n * render, which re-triggers the measuring effects — and their `setState` calls —\n * on every single pass.\n */\nfunction useStableTransition(\n  transition: Transition,\n  prefersReducedMotion: boolean | null\n): Transition {\n  const cache = useRef<Transition | null>(null);\n  const next = resolveTransition(transition, prefersReducedMotion);\n  if (cache.current === null || !isEqualTransition(cache.current, next)) {\n    cache.current = next;\n  }\n  return cache.current;\n}\nfunction assignRef<T>(\n  ref: Ref<T> | undefined,\n  node: T | null\n): (() => void) | undefined {\n  if (typeof ref === \"function\") {\n    const cleanup = ref(node);\n    return typeof cleanup === \"function\" ? cleanup : undefined;\n  }\n  if (ref) {\n    (ref as RefObject<T | null>).current = node;\n  }\n}\n/**\n * Merge the child's own ref, our measurement ref and the forwarded ref into a\n * single callback. Without this a child ref (Radix/cmdk items rely on theirs)\n * would be overwritten and the child would stop measuring itself.\n *\n * Callback-ref cleanup functions are preserved for React 19. Refs that do not\n * provide cleanup are reset to null when the composed ref detaches.\n */\nfunction useComposedRefs<T>(\n  childRef: Ref<T> | undefined,\n  localRef: Ref<T> | undefined,\n  forwardedRef: Ref<T> | undefined\n): RefCallback<T> {\n  return useCallback(\n    (node) => {\n      const refs = [childRef, localRef, forwardedRef];\n      if (node === null) {\n        for (const ref of refs) {\n          assignRef(ref, null);\n        }\n        return;\n      }\n      const cleanups = refs.map((ref) => assignRef(ref, node));\n      return () => {\n        for (const [index, ref] of refs.entries()) {\n          const cleanup = cleanups[index];\n          if (cleanup) {\n            cleanup();\n          } else {\n            assignRef(ref, null);\n          }\n        }\n      };\n    },\n    [childRef, localRef, forwardedRef]\n  );\n}\nfunction omitKeys<T extends Record<string, unknown>>(\n  source: T,\n  keys: readonly string[]\n): Record<string, unknown> {\n  const result: Record<string, unknown> = {};\n  for (const [key, value] of Object.entries(source)) {\n    if (!keys.includes(key)) {\n      result[key] = value;\n    }\n  }\n  return result;\n}\n/**\n * Only inject the data attributes the child did not set itself, so components\n * that manage their own `data-active` state keep control of it. Selection ARIA\n * is intentionally left to the consumer because this primitive is not limited\n * to tabs or listbox options.\n */\nfunction getNonOverridingDataAttributes<T extends Record<string, unknown>>(\n  element: ReactElement<T>,\n  dataAttrs: T\n): T {\n  const result: Record<string, unknown> = { ...dataAttrs };\n  for (const key of Object.keys(dataAttrs)) {\n    const own = element.props[key];\n    if (own !== undefined) {\n      result[key] = own;\n    }\n  }\n  return result as T;\n}\n/** Run every upstream handler first so the child's own handlers always fire. */\nfunction chainHandlers(\n  own: OwnHandlers,\n  ...sources: Record<string, unknown>[]\n): OwnHandlers {\n  const chained: OwnHandlers = {};\n  for (const name of HANDLER_KEYS) {\n    const handler = own[name];\n    const previous = sources\n      .map((source) => source[name])\n      .filter(\n        (fn): fn is (event: MouseEvent<HTMLElement>) => void =>\n          typeof fn === \"function\"\n      );\n    if (!handler && previous.length === 0) {\n      continue;\n    }\n    if (handler) {\n      chained[name] =\n        previous.length === 0\n          ? handler\n          : (event) => {\n              for (const fn of previous) {\n                fn(event);\n              }\n              if (!event.defaultPrevented) {\n                handler(event);\n              }\n            };\n    } else {\n      chained[name] =\n        previous.length === 1\n          ? previous[0]\n          : (event) => {\n              for (const fn of previous) {\n                fn(event);\n              }\n            };\n    }\n  }\n  return chained;\n}\nconst HighlightContext = createContext<HighlightContextValue | undefined>(\n  undefined\n);\nfunction useHighlight(): HighlightContextValue {\n  const ctx = useContext(HighlightContext);\n  if (!ctx) {\n    throw new Error(\"useHighlight must be used within a Highlight\");\n  }\n  return ctx;\n}\n// ─── Highlight ────────────────────────────────────────────────────────────────\ninterface HighlightBaseProps<T extends string> {\n  /**\n   * Automatically wrap child elements in `HighlightItem`.\n   * Defaults to `false` (or `true` if `itemsClassName` is provided) so container\n   * elements (like `<ul>`, `<NavigationMenuList>`) aren't treated as a single giant item.\n   * @default false\n   */\n  autoWrap?: boolean;\n  children: ReactNode;\n  /** Classes merged onto the highlight overlay element. */\n  className?: string;\n  /** Uncontrolled initial active value. */\n  defaultValue?: T | null;\n  /** Disables every item in the group. */\n  disabled?: boolean;\n  /** Renders `children` untouched — no container, no wrappers, no overlay. */\n  enabled?: boolean;\n  /**\n   * Milliseconds to hold the highlight before it starts fading out. Leave at `0`\n   * unless a fast hover flickers: holding it also keeps the outgoing background\n   * at full opacity while the next one slides in, and two stacked translucent\n   * backgrounds read as a darker pill.\n   */\n  exitDelay?: number;\n  /** Class applied to each auto-generated `HighlightItem` wrapper. */\n  itemsClassName?: string;\n  mode?: HighlightMode;\n  /** Called when the active value changes. */\n  onValueChange?: (value: T | null) => void;\n  /** Inline styles on the highlight overlay. */\n  style?: CSSProperties;\n  /** Motion transition for the highlight animation. */\n  transition?: Transition;\n  /** What user interaction activates an item. */\n  trigger?: HighlightTrigger;\n  /** Controlled active value. Pass `null` to clear. */\n  value?: T | null;\n}\ninterface HighlightParentOnlyProps {\n  /** Pixel offsets applied to the measured item bounds before positioning the highlight. */\n  boundsOffset?: Partial<Bounds>;\n  /** Classes on the relative container `div`. */\n  containerClassName?: string;\n}\ntype HighlightDivProps = Omit<\n  ComponentPropsWithoutRef<\"div\">,\n  \"children\" | \"className\" | \"style\"\n> & {\n  /** The container `div` in `mode=\"parent\"`. Always `null` in `mode=\"children\"`. */\n  ref?: Ref<HTMLDivElement>;\n};\nexport type HighlightProps<T extends string = string> = HighlightDivProps &\n  HighlightBaseProps<T> &\n  (({ mode: \"parent\" } & HighlightParentOnlyProps) | { mode?: \"children\" });\nexport function Highlight<T extends string = string>({\n  ref,\n  children,\n  mode = \"children\",\n  trigger = \"click\",\n  value: valueProp,\n  defaultValue,\n  onValueChange,\n  className,\n  style,\n  transition = DEFAULT_TRANSITION,\n  exitDelay = 0,\n  disabled = false,\n  enabled = true,\n  itemsClassName,\n  autoWrap,\n  ...rest\n}: HighlightProps<T>) {\n  const { boundsOffset, containerClassName } = rest as HighlightParentOnlyProps;\n  const containerProps = omitKeys(rest, [\n    \"boundsOffset\",\n    \"containerClassName\",\n    \"data-slot\",\n  ]);\n  const localRef = useRef<HTMLDivElement | null>(null);\n  const setContainerRef = useComposedRefs<HTMLDivElement>(\n    undefined,\n    localRef,\n    ref\n  );\n  const prefersReducedMotion = useReducedMotion();\n  const resolvedTransition = useStableTransition(\n    transition,\n    prefersReducedMotion\n  );\n  // `value` makes the component fully controlled: interaction only reports\n  // through `onValueChange` and never moves the highlight on its own.\n  const isControlled = valueProp !== undefined;\n  const [uncontrolledValue, setUncontrolledValue] = useState<string | null>(\n    defaultValue ?? null\n  );\n  const activeValue = isControlled ? valueProp : uncontrolledValue;\n  // Mirrors the effective value so uncontrolled interactions can bail out before\n  // React commits the next render. In controlled mode, the prop remains the source\n  // of truth and this ref must never record a selection the parent rejected.\n  const activeValueRef = useRef(activeValue);\n  activeValueRef.current = activeValue;\n  const [boundsState, setBoundsState] = useState<Bounds | null>(null);\n  const [activeClassName, setActiveClassName] = useState(\"\");\n  const [pillTransition, setPillTransition] =\n    useState<Transition>(resolvedTransition);\n  /** Bails out when nothing changed so an equal transition never re-renders. */\n  const updatePillTransition = useCallback((next: Transition) => {\n    setPillTransition((prev) => (isEqualTransition(prev, next) ? prev : next));\n  }, []);\n  useEffect(() => {\n    if (activeValue === null) {\n      setActiveClassName(\"\");\n    }\n  }, [activeValue]);\n  useEffect(() => {\n    updatePillTransition(resolvedTransition);\n  }, [resolvedTransition, updatePillTransition]);\n  const setActiveValue = useCallback(\n    (next: string | null) => {\n      const currentValue = isControlled ? activeValue : activeValueRef.current;\n      if (currentValue === next) {\n        return;\n      }\n      if (!isControlled) {\n        activeValueRef.current = next;\n        setUncontrolledValue(next);\n      }\n      onValueChange?.(next as T | null);\n    },\n    [activeValue, isControlled, onValueChange]\n  );\n  // Keep boundsOffset always fresh without re-creating setBounds\n  const boundsOffsetRef = useRef<Partial<Bounds>>(boundsOffset ?? {});\n  useIsomorphicLayoutEffect(() => {\n    boundsOffsetRef.current = boundsOffset ?? {};\n  }, [boundsOffset]);\n  const setBounds = useCallback((bounds: DOMRect) => {\n    if (!localRef.current) {\n      return;\n    }\n    const container = localRef.current;\n    const cr = container.getBoundingClientRect();\n    const o = boundsOffsetRef.current;\n    const next: Bounds = {\n      top:\n        bounds.top -\n        cr.top +\n        container.scrollTop -\n        container.clientTop +\n        (o.top ?? 0),\n      left:\n        bounds.left -\n        cr.left +\n        container.scrollLeft -\n        container.clientLeft +\n        (o.left ?? 0),\n      width: bounds.width + (o.width ?? 0),\n      height: bounds.height + (o.height ?? 0),\n    };\n    setBoundsState((prev) => {\n      if (\n        prev &&\n        prev.top === next.top &&\n        prev.left === next.left &&\n        prev.width === next.width &&\n        prev.height === next.height\n      ) {\n        return prev;\n      }\n      return next;\n    });\n  }, []);\n  const clearBounds = useCallback(\n    () => setBoundsState((prev) => (prev === null ? prev : null)),\n    []\n  );\n  const measureActiveItem = useCallback(\n    (layout = false) => {\n      if (mode !== \"parent\" || activeValue == null || !localRef.current) {\n        return;\n      }\n      const el = localRef.current.querySelector<HTMLElement>(\n        `[data-highlight-value=\"${CSS.escape(activeValue)}\"]`\n      );\n      if (el) {\n        if (layout) {\n          updatePillTransition(INSTANT_TRANSITION);\n        }\n        setBounds(el.getBoundingClientRect());\n      } else {\n        // The active item may have been removed without its value changing.\n        clearBounds();\n      }\n    },\n    [mode, activeValue, setBounds, clearBounds, updatePillTransition]\n  );\n  // Parent mode: measure when controlled selection changes (e.g. cmdk keyboard init)\n  useIsomorphicLayoutEffect(() => {\n    if (mode !== \"parent\") {\n      return;\n    }\n    if (activeValue == null) {\n      clearBounds();\n      return;\n    }\n    updatePillTransition(resolvedTransition);\n    measureActiveItem();\n    const frame = requestAnimationFrame(() => measureActiveItem());\n    return () => cancelAnimationFrame(frame);\n  }, [\n    mode,\n    activeValue,\n    measureActiveItem,\n    clearBounds,\n    resolvedTransition,\n    updatePillTransition,\n    boundsOffset,\n  ]);\n  // Parent mode: keep pill aligned while the list layout animates or resizes\n  useEffect(() => {\n    if (mode !== \"parent\" || activeValue == null) {\n      return;\n    }\n    const container = localRef.current;\n    if (!container) {\n      return;\n    }\n    const onLayout = () => measureActiveItem(true);\n    const observer = new ResizeObserver(onLayout);\n    observer.observe(container);\n    const activeEl = container.querySelector<HTMLElement>(\n      `[data-highlight-value=\"${CSS.escape(activeValue)}\"]`\n    );\n    if (activeEl) {\n      observer.observe(activeEl);\n    }\n    return () => observer.disconnect();\n  }, [mode, activeValue, measureActiveItem]);\n  // Re-measure active item on scroll (parent mode only)\n  useEffect(() => {\n    if (mode !== \"parent\") {\n      return;\n    }\n    const container = localRef.current;\n    if (!container) {\n      return;\n    }\n    const onScroll = () => {\n      if (activeValue == null) {\n        return;\n      }\n      measureActiveItem(true);\n    };\n    container.addEventListener(\"scroll\", onScroll, { passive: true });\n    return () => container.removeEventListener(\"scroll\", onScroll);\n  }, [mode, activeValue, measureActiveItem]);\n  const id = useId();\n  const ctx = useMemo<HighlightContextValue>(\n    () => ({\n      mode,\n      trigger,\n      activeValue,\n      setActiveValue,\n      setBounds,\n      clearBounds,\n      id,\n      className,\n      style,\n      activeClassName,\n      setActiveClassName,\n      transition: resolvedTransition,\n      disabled,\n      enabled,\n      exitDelay,\n    }),\n    [\n      mode,\n      trigger,\n      activeValue,\n      setActiveValue,\n      setBounds,\n      clearBounds,\n      id,\n      className,\n      style,\n      activeClassName,\n      resolvedTransition,\n      disabled,\n      enabled,\n      exitDelay,\n    ]\n  );\n  const shouldAutoWrap = autoWrap ?? Boolean(itemsClassName);\n  const content = shouldAutoWrap\n    ? Children.map(children, (child) => {\n        // Never re-wrap a child that is already a HighlightItem — nesting two\n        // wrappers puts the overlay inside a content-sized box and lets the outer\n        // item's click handler win over the real one.\n        if (isValidElement(child) && child.type !== HighlightItem) {\n          return (\n            <HighlightItem className={itemsClassName}>{child}</HighlightItem>\n          );\n        }\n        return child;\n      })\n    : children;\n  const droppedPropKeys = Object.keys(containerProps).join(\",\");\n  useEffect(() => {\n    if (process.env.NODE_ENV === \"production\" || mode !== \"children\") {\n      return;\n    }\n    if (droppedPropKeys) {\n      console.warn(\n        `[Highlight] Ignored ${droppedPropKeys} — div props are only applied to the container, which \\`mode=\"children\"\\` does not render. Use \\`mode=\"parent\"\\`, or \\`enabled={false}\\` to opt out entirely.`\n      );\n    }\n  }, [droppedPropKeys, mode]);\n  let renderedChildren: ReactNode = children;\n  if (enabled) {\n    if (mode === \"parent\") {\n      renderedChildren = (\n        <div\n          {...containerProps}\n          className={cn(\"relative isolate\", containerClassName)}\n          data-slot=\"highlight-container\"\n          ref={setContainerRef}\n        >\n          <AnimatePresence initial={false}>\n            {boundsState && (\n              <motion.div\n                animate={{\n                  top: boundsState.top,\n                  left: boundsState.left,\n                  width: boundsState.width,\n                  height: boundsState.height,\n                  opacity: 1,\n                }}\n                className={cn(\n                  \"pointer-events-none\",\n                  className,\n                  activeClassName\n                )}\n                data-slot=\"highlight\"\n                exit={{\n                  opacity: 0,\n                  transition: {\n                    ...resolvedTransition,\n                    delay: prefersReducedMotion\n                      ? 0\n                      : (resolvedTransition?.delay ?? 0) + exitDelay / 1000,\n                  },\n                }}\n                initial={{\n                  top: boundsState.top,\n                  left: boundsState.left,\n                  width: boundsState.width,\n                  height: boundsState.height,\n                  opacity: 0,\n                }}\n                style={{ position: \"absolute\", zIndex: -1, ...style }}\n                transition={pillTransition}\n              />\n            )}\n          </AnimatePresence>\n          {content}\n        </div>\n      );\n    } else {\n      renderedChildren = content;\n    }\n  }\n  return (\n    <HighlightContext.Provider value={ctx}>\n      {renderedChildren}\n    </HighlightContext.Provider>\n  );\n}\n// ─── HighlightItem ────────────────────────────────────────────────────────────\ninterface ItemOverlayProps {\n  activeClassName?: string;\n  className?: string;\n  contextId: string;\n  contextStyle?: CSSProperties;\n  style?: CSSProperties;\n  transition: Transition;\n}\n/**\n * The decorative background for one item in `mode=\"children\"`.\n *\n * Only the active item renders one, and it is always fully opaque. There is\n * deliberately no `initial`/`exit` fade here: crossfading two translucent\n * backgrounds never sums back to a single 8% layer, so the pill visibly shifts\n * shade mid-flight. With one opaque element carrying the shared `layoutId`,\n * Motion slides it from the previous item's bounds and the colour stays exact.\n *\n * The previous item unmounts in the same commit, which is fine — shared-layout\n * projection reads the outgoing bounds from Motion's previous-layout snapshot.\n */\nfunction ItemOverlay({\n  activeClassName,\n  className,\n  contextId,\n  contextStyle,\n  style,\n  transition,\n}: ItemOverlayProps) {\n  return (\n    <motion.div\n      className={cn(\"pointer-events-none\", className, activeClassName)}\n      data-slot=\"highlight\"\n      layoutId={`highlight-${contextId}`}\n      style={{\n        position: \"absolute\",\n        inset: 0,\n        zIndex: -1,\n        ...contextStyle,\n        ...style,\n      }}\n      transition={transition}\n    />\n  );\n}\nexport interface HighlightItemProps extends Omit<\n  ComponentPropsWithoutRef<\"div\">,\n  \"children\" | \"className\" | \"style\"\n> {\n  /** Extra class applied to the highlight overlay while this item is active. */\n  activeClassName?: string;\n  /** Merge event handlers and refs into the child element instead of wrapping it in a `div`. */\n  asChild?: boolean;\n  children: ReactNode;\n  /** Classes on the generated wrapper `div`, merged into the child when `asChild`. */\n  className?: string;\n  /** `undefined` inherits the group value; `false` keeps this item interactive. */\n  disabled?: boolean;\n  ref?: Ref<HTMLElement>;\n  /** Inline styles on this item's local highlight overlay. */\n  style?: CSSProperties;\n  /** Override transition for this item's local highlight overlay. */\n  transition?: Transition;\n  /** Unique value identifying this item. Falls back to the child's `data-highlight-value`, then its `id`. */\n  value?: string;\n}\nexport function HighlightItem({\n  ref,\n  children,\n  value,\n  className,\n  activeClassName,\n  style,\n  transition,\n  disabled,\n  asChild = false,\n  ...props\n}: HighlightItemProps) {\n  const {\n    activeValue,\n    className: contextClassName,\n    disabled: contextDisabled,\n    enabled,\n    id: contextId,\n    mode,\n    setActiveClassName,\n    setActiveValue,\n    setBounds,\n    style: contextStyle,\n    transition: contextTransition,\n    trigger,\n  } = useHighlight();\n  const generatedId = useId();\n  const prefersReducedMotion = useReducedMotion();\n  // A Fragment cannot receive a ref, so `asChild` must bail out on it too —\n  // otherwise React logs \"Invalid prop `ref` supplied to `React.Fragment`\".\n  const isValidChild =\n    isValidElement<ExtendedChildProps>(children) && children.type !== Fragment;\n  const element = isValidChild ? children : null;\n  const childValue =\n    value ??\n    element?.props[\"data-highlight-value\"] ??\n    element?.props.id ??\n    generatedId;\n  const isActive = activeValue === childValue;\n  const isDisabled = disabled ?? contextDisabled;\n  const itemTransition = useStableTransition(\n    transition ?? contextTransition,\n    prefersReducedMotion\n  );\n  const localRef = useRef<HTMLElement | null>(null);\n  // Only merge the child's own ref in the `asChild` path, where we render into\n  // the child itself. In the default wrapper path the child is a plain descendant\n  // and must keep its own ref — handing it the wrapper node would silently\n  // change what the consumer's ref points at.\n  const childRef = useComposedRefs<HTMLElement>(\n    element?.props.ref,\n    localRef,\n    ref as Ref<HTMLElement> | undefined\n  );\n  const wrapperRef = useComposedRefs<HTMLElement>(\n    undefined,\n    localRef,\n    ref as Ref<HTMLElement> | undefined\n  );\n  // Parent mode: report this item's bounds before paint so the pill never flashes\n  useIsomorphicLayoutEffect(() => {\n    if (mode !== \"parent\") {\n      return;\n    }\n    if (!isActive) {\n      return;\n    }\n    const measure = () => {\n      if (localRef.current) {\n        setBounds(localRef.current.getBoundingClientRect());\n        setActiveClassName(activeClassName ?? \"\");\n      }\n    };\n    measure();\n    const frame = requestAnimationFrame(measure);\n    return () => cancelAnimationFrame(frame);\n  }, [mode, isActive, setBounds, activeClassName, setActiveClassName]);\n  if (!(enabled && isValidChild && element)) {\n    return children;\n  }\n  const dataAttrs = {\n    \"data-active\": isActive ? \"true\" : \"false\",\n    \"data-disabled\": isDisabled || undefined,\n    \"data-highlight-value\": childValue,\n  };\n  let ownHandlers: OwnHandlers = {};\n  if (!isDisabled) {\n    ownHandlers =\n      trigger === \"hover\"\n        ? {\n            onMouseEnter: () => setActiveValue(childValue),\n            onMouseLeave: () => setActiveValue(null),\n          }\n        : { onClick: () => setActiveValue(childValue) };\n  }\n  // In wrapper mode the child's handlers already run on the child and bubble up.\n  // Re-chaining them onto the wrapper would invoke them a second time.\n  const handlers = asChild\n    ? chainHandlers(\n        ownHandlers,\n        element.props as Record<string, unknown>,\n        props as Record<string, unknown>\n      )\n    : chainHandlers(ownHandlers, props as Record<string, unknown>);\n  const restProps = omitKeys(props, HANDLER_KEYS);\n  // Shared highlight overlay (children mode only)\n  const overlay =\n    mode === \"children\" && isActive && !isDisabled ? (\n      <ItemOverlay\n        activeClassName={activeClassName}\n        className={contextClassName}\n        contextId={contextId}\n        contextStyle={contextStyle}\n        style={style}\n        transition={itemTransition}\n      />\n    ) : null;\n  // asChild: inject directly into the child element\n  if (asChild) {\n    if (mode === \"children\") {\n      return cloneElement(\n        element,\n        {\n          ...restProps,\n          className: cn(\"relative isolate\", element.props.className, className),\n          ref: childRef,\n          ...getNonOverridingDataAttributes(element, dataAttrs),\n          ...handlers,\n        },\n        overlay,\n        element.props.children\n      );\n    }\n    return cloneElement(element, {\n      ...restProps,\n      ref: childRef,\n      ...getNonOverridingDataAttributes(element, dataAttrs),\n      ...handlers,\n    });\n  }\n  // Default: wrapper div\n  return (\n    <div\n      className={cn(mode === \"children\" && \"relative isolate flex\", className)}\n      data-slot=\"highlight-item\"\n      ref={wrapperRef as RefCallback<HTMLDivElement>}\n      {...dataAttrs}\n      {...restProps}\n      {...handlers}\n    >\n      {overlay}\n      {mode === \"children\" ? (\n        // `w-full` matters: the wrapper is a flex container, so without it this\n        // inner box would size to its content and any `w-full` / `justify-*`\n        // utility on the child would collapse instead of filling the row.\n        <div className=\"relative z-1 w-full\">{children}</div>\n      ) : (\n        children\n      )}\n    </div>\n  );\n}\nexport { useHighlight };\n",
      "type": "registry:ui",
      "target": "components/sora-ui/effects/highlight.tsx"
    }
  ],
  "type": "registry:ui"
}
