{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "spotlight",
  "title": "Spotlight",
  "type": "registry:ui",
  "files": [
    {
      "path": "packages/registry-native/components/spotlight/Spotlight.tsx",
      "content": "import * as React from 'react'\nimport {\n  Keyboard,\n  Modal,\n  Pressable,\n  ScrollView,\n  StyleSheet,\n  View,\n  useWindowDimensions,\n  type ViewProps,\n} from 'react-native'\nimport Svg, { Path } from 'react-native-svg'\nimport { useSafeAreaInsets } from 'react-native-safe-area-context'\nimport { useReducedMotion } from 'react-native-reanimated'\nimport { Button, type ButtonProps } from '@/components/ui/button'\nimport { renderTextChildren } from '@/lib/label-children'\nimport { useTheme, useThemeColors } from '@/lib/theme'\nimport { cn } from '@/lib/utils'\nimport { spotlightMaskPath, visibleSpotlightRect, type SpotlightRect } from './spotlight.utils'\n\nexport interface SpotlightHandle {\n  /** Call from the owning scroll view's onScroll when its target can move. */\n  update: () => void\n}\n\nexport interface SpotlightProps extends ViewProps {\n  anchorRef: React.RefObject<Pick<React.ComponentRef<typeof View>, 'measureInWindow'> | null>\n  open?: boolean\n  defaultOpen?: boolean\n  onOpenChange?: (open: boolean) => void\n  disabled?: boolean\n  padding?: number\n  className?: string\n}\n\nconst CloseContext = React.createContext<(() => void) | null>(null)\n\n/** One measured target and caller-composed content. Sequenced tours belong in a block. */\nexport const Spotlight = React.forwardRef<SpotlightHandle, SpotlightProps>(\n  (\n    {\n      anchorRef,\n      open,\n      defaultOpen = false,\n      onOpenChange,\n      disabled = false,\n      padding = 8,\n      children,\n      className,\n      style,\n      onLayout,\n      ...props\n    },\n    ref,\n  ) => {\n    const [internal, setInternal] = React.useState(defaultOpen)\n    const [measurement, setMeasurement] = React.useState<{\n      rect: SpotlightRect\n      anchor: Pick<React.ComponentRef<typeof View>, 'measureInWindow'>\n      width: number\n      height: number\n    } | null>(null)\n    const [bodyHeight, setBodyHeight] = React.useState(0)\n    const { width, height } = useWindowDimensions()\n    const insets = useSafeAreaInsets()\n    const reduced = useReducedMotion()\n    const colors = useThemeColors()\n    const { resolvedTheme } = useTheme()\n    const resolvedOpen = !disabled && (open ?? internal)\n    const current = React.useRef({ open: resolvedOpen, width, height })\n    current.current = { open: resolvedOpen, width, height }\n    const epoch = React.useRef(0)\n    const mounted = React.useRef(true)\n\n    React.useEffect(() => {\n      const requests = epoch\n      mounted.current = true\n      return () => {\n        mounted.current = false\n        requests.current++\n      }\n    }, [])\n\n    const update = React.useCallback(() => {\n      const request = ++epoch.current\n      const anchor = anchorRef.current\n      if (!mounted.current) return\n      if (!current.current.open || !anchor) {\n        setMeasurement(null)\n        return\n      }\n      const requestedWidth = width\n      const requestedHeight = height\n      anchor.measureInWindow((x, y, targetWidth, targetHeight) => {\n        if (\n          !mounted.current ||\n          request !== epoch.current ||\n          !current.current.open ||\n          anchorRef.current !== anchor ||\n          current.current.width !== requestedWidth ||\n          current.current.height !== requestedHeight\n        )\n          return\n        const rect = visibleSpotlightRect(\n          { x, y, width: targetWidth, height: targetHeight },\n          requestedWidth,\n          requestedHeight,\n          padding,\n        )\n        setMeasurement(rect ? { rect, anchor, width: requestedWidth, height: requestedHeight } : null)\n      })\n    }, [anchorRef, width, height, padding])\n\n    React.useImperativeHandle(ref, () => ({ update }), [update])\n    React.useEffect(() => {\n      const requests = epoch\n      update()\n      if (!resolvedOpen) return\n      const show = Keyboard.addListener('keyboardDidShow', update)\n      const hide = Keyboard.addListener('keyboardDidHide', update)\n      return () => {\n        requests.current++\n        show.remove()\n        hide.remove()\n      }\n    }, [resolvedOpen, update])\n\n    const close = React.useCallback(() => {\n      if (!current.current.open) return\n      if (open === undefined) {\n        current.current.open = false\n        epoch.current++\n        setInternal(false)\n        setMeasurement(null)\n      }\n      onOpenChange?.(false)\n    }, [open, onOpenChange])\n\n    if (\n      !resolvedOpen ||\n      !measurement ||\n      measurement.anchor !== anchorRef.current ||\n      measurement.width !== width ||\n      measurement.height !== height\n    )\n      return null\n\n    const { rect } = measurement\n    const gap = 12\n    const above = Math.max(0, rect.y - insets.top - gap * 2)\n    const below = Math.max(0, height - insets.bottom - rect.y - rect.height - gap * 2)\n    const placeBelow = below >= Math.min(bodyHeight || 160, above) || below >= above\n    const available = Math.max(48, placeBelow ? below : above)\n    const top = placeBelow\n      ? Math.min(height - insets.bottom - 48, rect.y + rect.height + gap)\n      : Math.max(insets.top + gap, rect.y - gap - (bodyHeight || 160))\n\n    return (\n      <Modal\n        visible\n        transparent\n        animationType={reduced ? 'none' : 'fade'}\n        presentationStyle=\"overFullScreen\"\n        supportedOrientations={['portrait', 'portrait-upside-down', 'landscape-left', 'landscape-right']}\n        statusBarTranslucent\n        navigationBarTranslucent\n        onRequestClose={close}\n      >\n        <View style={{ flex: 1 }} accessibilityViewIsModal onAccessibilityEscape={close}>\n          <Pressable\n            accessible={false}\n            focusable={false}\n            style={StyleSheet.absoluteFill}\n            onPress={(event) => {\n              const { locationX: x, locationY: y } = event.nativeEvent\n              if (x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height) return\n              close()\n            }}\n          >\n            <Svg width={width} height={height} pointerEvents=\"none\">\n              <Path\n                d={spotlightMaskPath(rect, width, height)}\n                fill={resolvedTheme === 'dark' ? colors.background : colors.foreground}\n                fillOpacity={0.65}\n                fillRule=\"evenodd\"\n              />\n            </Svg>\n          </Pressable>\n          <CloseContext.Provider value={close}>\n            <View\n              {...props}\n              className={cn('gap-[12px] rounded-xl border border-border bg-card p-[16px]', className)}\n              style={[\n                { position: 'absolute', top, left: insets.left + 16, right: insets.right + 16, maxHeight: available },\n                style,\n              ]}\n              onLayout={(event) => {\n                setBodyHeight(event.nativeEvent.layout.height)\n                onLayout?.(event)\n              }}\n            >\n              <ScrollView\n                keyboardShouldPersistTaps=\"handled\"\n                style={{ flexGrow: 0 }}\n                contentContainerStyle={{ gap: 12 }}\n              >\n                {renderTextChildren(children)}\n              </ScrollView>\n            </View>\n          </CloseContext.Provider>\n        </View>\n      </Modal>\n    )\n  },\n)\nSpotlight.displayName = 'Spotlight'\n\nexport const SpotlightClose = React.forwardRef<React.ComponentRef<typeof Pressable>, ButtonProps>(\n  ({ onPress, disabled, loading, children = 'Close highlight', ...props }, ref) => {\n    const close = React.useContext(CloseContext)\n    if (!close) throw new Error('SpotlightClose must be inside Spotlight')\n    return (\n      <Button\n        {...props}\n        ref={ref}\n        disabled={disabled}\n        loading={loading}\n        onPress={(event) => {\n          if (disabled || loading) return\n          onPress?.(event)\n          if (!event.isDefaultPrevented()) close()\n        }}\n      >\n        {children}\n      </Button>\n    )\n  },\n)\nSpotlightClose.displayName = 'SpotlightClose'\n",
      "type": "registry:ui",
      "target": "~/components/ui/spotlight/Spotlight.tsx"
    },
    {
      "path": "packages/registry-native/components/spotlight/spotlight.utils.ts",
      "content": "export interface SpotlightRect {\n  x: number\n  y: number\n  width: number\n  height: number\n}\n\n/** A missing/offscreen target must not leave an invisible modal above the app. */\nexport function visibleSpotlightRect(rect: SpotlightRect, width: number, height: number, padding = 8) {\n  if (![rect.x, rect.y, rect.width, rect.height, width, height].every(Number.isFinite)) return null\n  if (rect.width <= 0 || rect.height <= 0 || width <= 0 || height <= 0) return null\n  if (rect.x >= width || rect.y >= height || rect.x + rect.width <= 0 || rect.y + rect.height <= 0) return null\n  const inset = Number.isFinite(padding) ? Math.max(0, padding) : 8\n  const x = Math.max(0, rect.x - inset)\n  const y = Math.max(0, rect.y - inset)\n  return {\n    x,\n    y,\n    width: Math.min(width, rect.x + rect.width + inset) - x,\n    height: Math.min(height, rect.y + rect.height + inset) - y,\n  }\n}\n\nexport function spotlightMaskPath(rect: SpotlightRect, width: number, height: number) {\n  return `M0 0H${width}V${height}H0Z M${rect.x} ${rect.y}H${rect.x + rect.width}V${rect.y + rect.height}H${rect.x}Z`\n}\n",
      "type": "registry:ui",
      "target": "~/components/ui/spotlight/spotlight.utils.ts"
    },
    {
      "path": "packages/registry-native/components/spotlight/index.ts",
      "content": "export * from './Spotlight'\nexport { visibleSpotlightRect, type SpotlightRect } from './spotlight.utils'\n",
      "type": "registry:ui",
      "target": "~/components/ui/spotlight/index.ts"
    }
  ],
  "dependencies": [
    "react-native-svg",
    "react-native-safe-area-context",
    "react-native-reanimated"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/button.json",
    "https://native.uipkge.dev/r/native/label-children.json",
    "https://native.uipkge.dev/r/native/theme.json",
    "https://native.uipkge.dev/r/native/utils.json"
  ],
  "description": "Measured single-target highlight with stale-measurement protection and caller-composed content.",
  "categories": [
    "overlay"
  ]
}