{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"shadcnblocks/background","title":"Background - Layered section background","description":"A section wrapper with editorial borders, patterns, and mesh gradients that sit behind content using named presets.","dependencies":["cn"],"registryDependencies":[],"files":[{"path":"components/shadcnblocks/background.tsx","content":"import { useId } from \"react\";\nimport { cn } from \"cn\";\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport type BorderComponent =\n  | \"none\"\n  | \"solid-line\"\n  | \"dashed-line\"\n  | \"diagonal-pattern\"\n  | \"dots\"\n  | \"gradient-fade\";\n\nexport type PatternComponent = \"none\" | \"plus-signs\" | \"dots\" | \"noise\" | \"grid\";\n\nexport type MeshComponent = \"none\" | \"plasma-gradient\" | \"subtle-gradient\";\n\nexport interface BackgroundStyle {\n  // Preset (applies a bundle of defaults)\n  preset?:\n    | \"mainline\"\n    | \"mainline-bordered\"\n    | \"charter\"\n    | \"scalar\"\n    | \"plasma\"\n    | \"none\";\n\n  // === Section-level (full viewport width) ===\n\n  // Section wrapper styling\n  gradient?: \"top\" | \"bottom\" | \"both\" | \"none\";\n  rounded?: \"none\" | \"md\" | \"lg\" | \"xl\" | \"2xl\" | \"3xl\" | \"4xl\";\n  margin?: \"none\" | \"sm\" | \"md\" | \"lg\";\n  \n  // Additional className (for padding, etc.)\n  className?: string;\n\n  // Section border components (full viewport width)\n  sectionBorderTop?: BorderComponent;\n  sectionBorderBottom?: BorderComponent;\n\n  // Section background patterns (absolute positioned)\n  pattern?: PatternComponent;\n  patternMask?: \"none\" | \"radial\" | \"left\" | \"right\" | \"top\" | \"bottom\";\n  mesh?: MeshComponent;\n\n  // === Container-level (container width) ===\n\n  // Container border components\n  containerBorderLeft?: BorderComponent;\n  containerBorderRight?: BorderComponent;\n  containerBorderTop?: BorderComponent;\n  containerBorderBottom?: BorderComponent;\n\n  // Container padding (inside borders)\n  containerPadding?: \"none\" | \"sm\" | \"md\" | \"lg\";\n\n  // === Viewport fills (beyond container) ===\n\n  // Decorations extending to viewport edges\n  viewportFillLeft?: PatternComponent;\n  viewportFillRight?: PatternComponent;\n}\n\n// ============================================================================\n// Preset Definitions\n// ============================================================================\n\nconst PRESETS: Record<string, Partial<BackgroundStyle>> = {\n  none: {},\n  mainline: {\n    gradient: \"top\",\n    rounded: \"4xl\",\n    margin: \"md\",\n  },\n  \"mainline-bordered\": {\n    gradient: \"top\",\n    rounded: \"4xl\",\n    margin: \"md\",\n    sectionBorderTop: \"dashed-line\",\n    sectionBorderBottom: \"dashed-line\",\n    containerBorderLeft: \"dashed-line\",\n    containerBorderRight: \"dashed-line\",\n  },\n  charter: {\n    pattern: \"plus-signs\",\n    patternMask: \"radial\",\n  },\n  scalar: {\n    sectionBorderTop: \"solid-line\",\n    sectionBorderBottom: \"solid-line\",\n    containerBorderLeft: \"solid-line\",\n    containerBorderRight: \"solid-line\",\n    viewportFillLeft: \"plus-signs\",\n    viewportFillRight: \"plus-signs\",\n  },\n  plasma: {\n    mesh: \"plasma-gradient\",\n  },\n};\n\n// ============================================================================\n// Border Components (inline for portability)\n// ============================================================================\n\ninterface BorderProps {\n  orientation?: \"horizontal\" | \"vertical\";\n  className?: string;\n}\n\nconst DashedLine = ({ orientation = \"horizontal\", className }: BorderProps) => {\n  const isHorizontal = orientation === \"horizontal\";\n  return (\n    <div\n      className={cn(\n        \"text-muted-foreground relative\",\n        isHorizontal ? \"h-px w-full\" : \"h-full w-px\",\n        className\n      )}\n    >\n      <div\n        className={cn(\n          isHorizontal\n            ? [\n                \"h-px w-full\",\n                \"bg-[repeating-linear-gradient(90deg,transparent,transparent_4px,currentColor_4px,currentColor_10px)]\",\n                \"[mask-image:linear-gradient(90deg,transparent,black_25%,black_75%,transparent)]\",\n              ]\n            : [\n                \"h-full w-px\",\n                \"bg-[repeating-linear-gradient(180deg,transparent,transparent_4px,currentColor_4px,currentColor_10px)]\",\n                \"[mask-image:linear-gradient(180deg,transparent,black_25%,black_75%,transparent)]\",\n              ]\n        )}\n      />\n    </div>\n  );\n};\n\nconst SolidLine = ({ orientation = \"horizontal\", className }: BorderProps) => (\n  <div\n    className={cn(\n      \"bg-border\",\n      orientation === \"horizontal\" ? \"h-px w-full\" : \"h-full w-px\",\n      className\n    )}\n  />\n);\n\nconst DiagonalPattern = ({\n  orientation = \"horizontal\",\n  className,\n}: BorderProps) => (\n  <div\n    className={cn(\n      \"text-muted-foreground\",\n      orientation === \"horizontal\" ? \"h-2 w-full\" : \"h-full w-2\",\n      className\n    )}\n    style={{\n      backgroundImage: `repeating-linear-gradient(\n        ${orientation === \"horizontal\" ? \"45deg\" : \"135deg\"},\n        transparent,\n        transparent 4px,\n        currentColor 4px,\n        currentColor 5px\n      )`,\n    }}\n  />\n);\n\nconst DottedBorder = ({\n  orientation = \"horizontal\",\n  className,\n}: BorderProps) => (\n  <div\n    className={cn(\n      \"text-muted-foreground\",\n      orientation === \"horizontal\" ? \"h-px w-full\" : \"h-full w-px\",\n      className\n    )}\n    style={{\n      backgroundImage:\n        \"radial-gradient(circle, currentColor 1px, transparent 1px)\",\n      backgroundSize: orientation === \"horizontal\" ? \"8px 1px\" : \"1px 8px\",\n    }}\n  />\n);\n\nconst GradientFade = ({\n  orientation = \"horizontal\",\n  className,\n}: BorderProps) => (\n  <div\n    className={cn(\n      orientation === \"horizontal\"\n        ? \"h-8 w-full bg-gradient-to-b from-primary/20 to-transparent\"\n        : \"h-full w-8 bg-gradient-to-r from-primary/20 to-transparent\",\n      className\n    )}\n  />\n);\n\n// Border component lookup\nconst BORDER_COMPONENTS: Record<\n  BorderComponent,\n  React.FC<BorderProps> | null\n> = {\n  none: null,\n  \"solid-line\": SolidLine,\n  \"dashed-line\": DashedLine,\n  \"diagonal-pattern\": DiagonalPattern,\n  dots: DottedBorder,\n  \"gradient-fade\": GradientFade,\n};\n\n// ============================================================================\n// Pattern Components (inline for portability)\n// ============================================================================\n\ninterface PatternProps {\n  className?: string;\n}\n\nconst PlusSigns = ({ className }: PatternProps) => {\n  const GAP = 16;\n  const STROKE_WIDTH = 1;\n  const PLUS_SIZE = 6;\n  const id = useId();\n  const patternId = `plus-pattern-${id}`;\n\n  return (\n    <svg\n      width=\"100%\"\n      height=\"100%\"\n      className={cn(\"text-foreground/5\", className)}\n    >\n      <defs>\n        <pattern\n          id={patternId}\n          x=\"0\"\n          y=\"0\"\n          width={GAP}\n          height={GAP}\n          patternUnits=\"userSpaceOnUse\"\n        >\n          <line\n            x1={GAP / 2}\n            y1={(GAP - PLUS_SIZE) / 2}\n            x2={GAP / 2}\n            y2={(GAP + PLUS_SIZE) / 2}\n            stroke=\"currentColor\"\n            strokeWidth={STROKE_WIDTH}\n          />\n          <line\n            x1={(GAP - PLUS_SIZE) / 2}\n            y1={GAP / 2}\n            x2={(GAP + PLUS_SIZE) / 2}\n            y2={GAP / 2}\n            stroke=\"currentColor\"\n            strokeWidth={STROKE_WIDTH}\n          />\n        </pattern>\n      </defs>\n      <rect width=\"100%\" height=\"100%\" fill={`url(#${patternId})`} />\n    </svg>\n  );\n};\n\nconst DotsPattern = ({ className }: PatternProps) => (\n  <div\n    className={cn(\"size-full text-foreground/5\", className)}\n    style={{\n      backgroundImage:\n        \"radial-gradient(circle at 1px 1px, currentColor 1px, transparent 0)\",\n      backgroundSize: \"20px 20px\",\n    }}\n  />\n);\n\nconst NoisePattern = ({ className }: PatternProps) => (\n  <div\n    className={cn(\"size-full text-foreground/10\", className)}\n    style={{\n      backgroundImage: `url(\"data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E\")`,\n      opacity: 0.4,\n    }}\n  />\n);\n\nconst GridPattern = ({ className }: PatternProps) => {\n  const id = useId();\n  const patternId = `grid-pattern-${id}`;\n\n  return (\n    <svg\n      width=\"100%\"\n      height=\"100%\"\n      className={cn(\"text-foreground/5\", className)}\n    >\n      <defs>\n        <pattern\n          id={patternId}\n          x=\"0\"\n          y=\"0\"\n          width=\"40\"\n          height=\"40\"\n          patternUnits=\"userSpaceOnUse\"\n        >\n          <path\n            d=\"M 40 0 L 0 0 0 40\"\n            fill=\"none\"\n            stroke=\"currentColor\"\n            strokeWidth=\"1\"\n          />\n        </pattern>\n      </defs>\n      <rect width=\"100%\" height=\"100%\" fill={`url(#${patternId})`} />\n    </svg>\n  );\n};\n\n// Pattern component lookup\nconst PATTERN_COMPONENTS: Record<\n  PatternComponent,\n  React.FC<PatternProps> | null\n> = {\n  none: null,\n  \"plus-signs\": PlusSigns,\n  dots: DotsPattern,\n  noise: NoisePattern,\n  grid: GridPattern,\n};\n\n// ============================================================================\n// Mesh/Gradient Components (inline for portability)\n// ============================================================================\n\nconst PlasmaGradient = ({ className }: PatternProps) => {\n  const id = useId();\n\n  return (\n    <svg\n      className={cn(\"size-full\", className)}\n      viewBox=\"0 0 1342 1199\"\n      fill=\"none\"\n      preserveAspectRatio=\"xMidYMid slice\"\n    >\n      <path\n        fill={`url(#plasma-a-${id})`}\n        d=\"M914.912 1197.77 747.793 808.811l115.698-221.478 334.239 73.826 109.08 196.135-391.898 340.476Z\"\n      />\n      <path\n        fill={`url(#plasma-c-${id})`}\n        d=\"m875.715 420.318 203.405-357.96c50.52-10.487-50.57 96.246 0 186.332 80.45 143.304 298.36 312.903 256.86 419.243-67.58 173.19-306.7 49.523-396.529 0-71.863-39.618-72.434-181.585-63.736-247.615Z\"\n      />\n      <path\n        fill={`url(#plasma-d-${id})`}\n        d=\"m46.623 746.37 908.336-619.388 130.381-66.714-46.89 196.709-156.685 413.622c-27.829 50.066-111.545 120.16-223.775 0-98.592-105.557-466.882-3.975-611.367 75.771L.814 777.607c10.115-9.59 25.82-20.205 45.809-31.237Z\"\n      />\n      <defs>\n        <linearGradient\n          id={`plasma-a-${id}`}\n          x1={1027.3}\n          x2={1027.73}\n          y1={587.333}\n          y2={1198.11}\n          gradientUnits=\"userSpaceOnUse\"\n        >\n          <stop offset={0} stopColor=\"#9D83E7\" />\n          <stop offset={0.516} stopColor=\"#D445E7\" />\n        </linearGradient>\n        <linearGradient\n          id={`plasma-c-${id}`}\n          x1={871.897}\n          x2={1188.44}\n          y1={575.509}\n          y2={575.628}\n          gradientUnits=\"userSpaceOnUse\"\n        >\n          <stop stopColor=\"#9259ED\" />\n          <stop offset={0.514} stopColor=\"#CF54EE\" />\n          <stop offset={1} stopColor=\"#FB8684\" />\n        </linearGradient>\n        <linearGradient\n          id={`plasma-d-${id}`}\n          x1={676.669}\n          x2={677.051}\n          y1={60.268}\n          y2={757.516}\n          gradientUnits=\"userSpaceOnUse\"\n        >\n          <stop stopColor=\"#B956EE\" />\n          <stop offset={1} stopColor=\"#9672FF\" />\n        </linearGradient>\n      </defs>\n    </svg>\n  );\n};\n\nconst SubtleGradient = ({ className }: PatternProps) => (\n  <div\n    className={cn(\n      \"size-full bg-gradient-to-br from-primary/10 via-transparent to-secondary/10\",\n      className\n    )}\n  />\n);\n\n// Mesh component lookup\nconst MESH_COMPONENTS: Record<MeshComponent, React.FC<PatternProps> | null> = {\n  none: null,\n  \"plasma-gradient\": PlasmaGradient,\n  \"subtle-gradient\": SubtleGradient,\n};\n\n// ============================================================================\n// Background Component\n// ============================================================================\n\ninterface BackgroundProps {\n  style?: BackgroundStyle;\n  children: React.ReactNode;\n  className?: string;\n}\n\nexport const Background = ({ style, children, className }: BackgroundProps) => {\n  // Resolve preset + overrides\n  const resolved = { ...PRESETS[style?.preset ?? \"none\"], ...style };\n  \n  // Merge className from props and style\n  const mergedClassName = cn(className, resolved.className);\n\n  // Get border components\n  const SectionBorderTop =\n    BORDER_COMPONENTS[resolved.sectionBorderTop ?? \"none\"];\n  const SectionBorderBottom =\n    BORDER_COMPONENTS[resolved.sectionBorderBottom ?? \"none\"];\n  const ContainerBorderLeft =\n    BORDER_COMPONENTS[resolved.containerBorderLeft ?? \"none\"];\n  const ContainerBorderRight =\n    BORDER_COMPONENTS[resolved.containerBorderRight ?? \"none\"];\n  const ContainerBorderTop =\n    BORDER_COMPONENTS[resolved.containerBorderTop ?? \"none\"];\n  const ContainerBorderBottom =\n    BORDER_COMPONENTS[resolved.containerBorderBottom ?? \"none\"];\n\n  // Get pattern components\n  const PatternComp = PATTERN_COMPONENTS[resolved.pattern ?? \"none\"];\n  const MeshComp = MESH_COMPONENTS[resolved.mesh ?? \"none\"];\n  const ViewportFillLeftComp =\n    PATTERN_COMPONENTS[resolved.viewportFillLeft ?? \"none\"];\n  const ViewportFillRightComp =\n    PATTERN_COMPONENTS[resolved.viewportFillRight ?? \"none\"];\n\n  // If no styling is applied, just render children\n  const hasAnyStyle =\n    mergedClassName ||\n    resolved.gradient ||\n    resolved.rounded ||\n    resolved.margin ||\n    resolved.sectionBorderTop ||\n    resolved.sectionBorderBottom ||\n    resolved.containerBorderLeft ||\n    resolved.containerBorderRight ||\n    resolved.containerBorderTop ||\n    resolved.containerBorderBottom ||\n    resolved.pattern ||\n    resolved.mesh ||\n    resolved.viewportFillLeft ||\n    resolved.viewportFillRight;\n\n  if (!hasAnyStyle) {\n    return <>{children}</>;\n  }\n\n  return (\n    <div\n      className={cn(\n        \"relative overflow-hidden\",\n        // Margin\n        resolved.margin === \"sm\" && \"mx-1.5 mt-1.5 lg:mx-2\",\n        resolved.margin === \"md\" && \"mx-2.5 mt-2.5 lg:mx-4\",\n        resolved.margin === \"lg\" && \"mx-4 mt-4 lg:mx-6\",\n        // Rounded corners\n        resolved.rounded === \"md\" && \"rounded-md\",\n        resolved.rounded === \"lg\" && \"rounded-lg\",\n        resolved.rounded === \"xl\" && \"rounded-xl\",\n        resolved.rounded === \"2xl\" && \"rounded-2xl\",\n        resolved.rounded === \"3xl\" && \"rounded-3xl\",\n        resolved.rounded === \"4xl\" && \"rounded-t-4xl rounded-b-2xl\",\n        // Gradient\n        resolved.gradient === \"top\" &&\n          \"bg-linear-to-b from-primary/50 via-background to-background/80 via-20%\",\n        resolved.gradient === \"bottom\" &&\n          \"bg-linear-to-b from-background via-background to-primary/50\",\n        resolved.gradient === \"both\" &&\n          \"bg-linear-to-b from-primary/30 via-background to-primary/30\",\n        mergedClassName\n      )}\n    >\n      {/* Section border top (full width) */}\n      {SectionBorderTop && (\n        <div className=\"absolute inset-x-0 top-0 z-10\">\n          <SectionBorderTop orientation=\"horizontal\" />\n        </div>\n      )}\n\n      {/* Section border bottom (full width) */}\n      {SectionBorderBottom && (\n        <div className=\"absolute inset-x-0 bottom-0 z-10\">\n          <SectionBorderBottom orientation=\"horizontal\" />\n        </div>\n      )}\n\n      {/* Background pattern layer */}\n      {PatternComp && (\n        <div\n          className={cn(\n            \"pointer-events-none absolute inset-0\",\n            resolved.patternMask === \"radial\" &&\n              \"[mask-image:radial-gradient(circle_at_center,black_0%,black_20%,transparent_75%)]\",\n            resolved.patternMask === \"left\" &&\n              \"[mask-image:linear-gradient(to_right,black_0%,black_30%,transparent_70%)]\",\n            resolved.patternMask === \"right\" &&\n              \"[mask-image:linear-gradient(to_left,black_0%,black_30%,transparent_70%)]\",\n            resolved.patternMask === \"top\" &&\n              \"[mask-image:linear-gradient(to_bottom,black_0%,black_30%,transparent_70%)]\",\n            resolved.patternMask === \"bottom\" &&\n              \"[mask-image:linear-gradient(to_top,black_0%,black_30%,transparent_70%)]\"\n          )}\n        >\n          <PatternComp className=\"size-full\" />\n        </div>\n      )}\n\n      {/* Mesh gradient layer */}\n      {MeshComp && (\n        <div className=\"pointer-events-none absolute inset-0 opacity-30\">\n          <MeshComp className=\"size-full\" />\n        </div>\n      )}\n\n      {/* Content wrapper with container borders */}\n      <div className=\"relative\">\n        {/* Container left border */}\n        {ContainerBorderLeft && (\n          <div className=\"absolute bottom-0 top-0 left-4 z-10 hidden lg:left-[max(1rem,calc((100%-1400px)/2+1rem))] lg:block\">\n            <ContainerBorderLeft orientation=\"vertical\" className=\"h-full\" />\n          </div>\n        )}\n\n        {/* Container right border */}\n        {ContainerBorderRight && (\n          <div className=\"absolute bottom-0 top-0 right-4 z-10 hidden lg:right-[max(1rem,calc((100%-1400px)/2+1rem))] lg:block\">\n            <ContainerBorderRight orientation=\"vertical\" className=\"h-full\" />\n          </div>\n        )}\n\n        {/* Container top border */}\n        {ContainerBorderTop && (\n          <div className=\"absolute inset-x-4 top-0 z-10 lg:inset-x-[max(1rem,calc((100%-1400px)/2+1rem))]\">\n            <ContainerBorderTop orientation=\"horizontal\" />\n          </div>\n        )}\n\n        {/* Container bottom border */}\n        {ContainerBorderBottom && (\n          <div className=\"absolute inset-x-4 bottom-0 z-10 lg:inset-x-[max(1rem,calc((100%-1400px)/2+1rem))]\">\n            <ContainerBorderBottom orientation=\"horizontal\" />\n          </div>\n        )}\n\n        {/* Viewport fill left */}\n        {ViewportFillLeftComp && (\n          <div className=\"pointer-events-none absolute bottom-0 top-0 right-full hidden w-screen border-y lg:block\">\n            <ViewportFillLeftComp className=\"size-full\" />\n          </div>\n        )}\n\n        {/* Viewport fill right */}\n        {ViewportFillRightComp && (\n          <div className=\"pointer-events-none absolute bottom-0 top-0 left-full hidden w-screen border-y lg:block\">\n            <ViewportFillRightComp className=\"size-full\" />\n          </div>\n        )}\n\n        {children}\n      </div>\n    </div>\n  );\n};\n\nexport default Background;\n","type":"registry:component"}],"type":"registry:component","meta":{"license":"https://www.shadcnblocks.com/license"}}