{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"ember-gradient","type":"registry:ui","title":"Ember gradient","description":"Warm surface of drifting copper, forest and rust fields with film grain. Three earthy presets or your own colors, optional slow palette cycling.","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"registry/items/ember-gradient/ember-gradient.tsx","type":"registry:ui","target":"components/facade/ember-gradient.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { useReducedMotion } from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nexport type EmberPreset = \"ember\" | \"moss\" | \"dusk\";\n\nexport interface EmberPalette {\n  /** Solid base under the fields. Keep it dark so white text stays readable. */\n  base: string;\n  /** Up to five field colors, placed top left, bottom left, center, bottom right, top right. */\n  fields: string[];\n}\n\n/** A preset name, a palette object, or an array whose first entry is the base. */\nexport type EmberPaletteInput = EmberPreset | EmberPalette | string[];\n\nexport interface EmberGradientProps extends React.HTMLAttributes<HTMLElement> {\n  children?: React.ReactNode;\n  /** Element to render. Defaults to \"div\". */\n  as?: \"div\" | \"section\" | \"header\" | \"aside\" | \"footer\";\n  /** Colors of the surface. Defaults to \"ember\" (copper, forest, olive and rust on near black). */\n  palette?: EmberPaletteInput;\n  /** Slowly cross-fade through `cyclePalettes`. Off by default. Ignored with reduced motion. */\n  cycle?: boolean;\n  /** Palettes to cycle through, starting after `palette`. Defaults to the other two presets. */\n  cyclePalettes?: EmberPaletteInput[];\n  /** Seconds each palette stays before the next fades in. Defaults to 30. */\n  cycleDuration?: number;\n  /** Seconds per drift cycle of the fields. Higher is calmer. Defaults to 26. */\n  speed?: number;\n  /** Film grain. `true` for the default strength, a number from 0 to 1 for a custom opacity, `false` for none. */\n  grain?: boolean | number;\n  /** Opacity of the color fields over the base, 0 to 1. Defaults to 1. */\n  intensity?: number;\n  /** Class for the layer that holds children. */\n  contentClassName?: string;\n}\n\n/* ---------- Ember surface engine (shared by all ember items, keep in sync) ---------- */\n\nexport const emberPalettes: Record<EmberPreset, EmberPalette> = {\n  ember: { base: \"#17130F\", fields: [\"#895735\", \"#193D25\", \"#444A29\", \"#943C27\", \"#895735\"] },\n  moss: { base: \"#10140F\", fields: [\"#5A6B32\", \"#1F4A2C\", \"#3E4A2A\", \"#7A5A2E\", \"#26402F\"] },\n  dusk: { base: \"#16121A\", fields: [\"#7A3F2F\", \"#2C2F4A\", \"#4A2E44\", \"#9A5A33\", \"#3A2A3E\"] },\n};\n\nfunction resolvePalette(input: EmberPaletteInput): EmberPalette {\n  if (typeof input === \"string\") return emberPalettes[input] ?? emberPalettes.ember;\n  if (Array.isArray(input)) return { base: input[0] ?? emberPalettes.ember.base, fields: input.slice(1) };\n  return input;\n}\n\n/* Field placement. Sizes use container units: wide surfaces get wide bands\n   (like a 52px bar), tall ones get round pools instead of vertical stripes.\n   `w` and `h` are percent of the surface, `cap` limits height to cap x width,\n   `push` moves a field past its anchored edge by that share of its own size. */\ntype Field = {\n  x: \"left\" | \"right\" | \"center\";\n  y: \"top\" | \"bottom\" | \"center\";\n  w: number;\n  h: number;\n  cap: number;\n  push: [number, number];\n  opacity: number;\n  drift: \"a\" | \"b\" | \"c\";\n  factor: number;\n  delay: number;\n};\n\nconst FIELDS: Field[] = [\n  { x: \"left\", y: \"top\", w: 70, h: 100, cap: 1.1, push: [0.25, 0.35], opacity: 0.85, drift: \"a\", factor: 1, delay: 0 },\n  { x: \"left\", y: \"bottom\", w: 62, h: 95, cap: 1.1, push: [0.25, 0.3], opacity: 0.9, drift: \"b\", factor: 1.27, delay: -0.3 },\n  { x: \"center\", y: \"center\", w: 52, h: 84, cap: 1, push: [0, 0], opacity: 0.4, drift: \"c\", factor: 0.86, delay: -0.55 },\n  { x: \"right\", y: \"bottom\", w: 72, h: 100, cap: 1.1, push: [0.22, 0.3], opacity: 0.9, drift: \"b\", factor: 1.13, delay: -0.7 },\n  { x: \"right\", y: \"top\", w: 50, h: 84, cap: 1, push: [0.2, 0.4], opacity: 0.5, drift: \"a\", factor: 0.94, delay: -0.2 },\n];\n\nfunction fieldBox(f: Field): React.CSSProperties {\n  const width = `max(${f.w}cqw, ${f.w * 0.55}cqh)`;\n  const height = `min(${f.h}cqh, max(${f.w * f.cap}cqw, ${f.w * 0.55 * f.cap}cqh))`;\n  const box: React.CSSProperties = { width, height };\n  if (f.x === \"center\") box.left = `calc(50% - ${width} / 2)`;\n  else box[f.x] = `calc(${width} * ${-f.push[0]})`;\n  if (f.y === \"center\") box.top = `calc(50% - ${height} / 2)`;\n  else box[f.y] = `calc(${height} * ${-f.push[1]})`;\n  return box;\n}\n\n/* Transform and opacity only, so the drift runs on the compositor. The fields\n   are soft radial gradients, no blur filter is repainted per frame. */\nconst EMBER_CSS = `\n@keyframes facade-ember-a{0%{transform:translate3d(0,0,0) scale(1);opacity:1}50%{transform:translate3d(10%,14%,0) scale(1.08);opacity:.78}100%{transform:translate3d(-6%,6%,0) scale(.95);opacity:1}}\n@keyframes facade-ember-b{0%{transform:translate3d(0,0,0) scale(1.04)}50%{transform:translate3d(-12%,-6%,0) scale(.94)}100%{transform:translate3d(6%,-12%,0) scale(1.1)}}\n@keyframes facade-ember-c{0%{transform:translate3d(0,0,0) scale(.95);opacity:.6}50%{transform:translate3d(14%,-10%,0) scale(1.12);opacity:1}100%{transform:translate3d(-10%,8%,0) scale(1);opacity:.7}}\n.facade-ember-field{position:absolute;border-radius:9999px;will-change:transform,opacity;animation-timing-function:ease-in-out;animation-iteration-count:infinite;animation-direction:alternate}\n.facade-ember[data-paused] .facade-ember-field{animation-play-state:paused}\n.facade-ember-stack{position:absolute;inset:0;transition-property:opacity;transition-timing-function:ease-in-out}\n@media (prefers-reduced-motion:reduce){.facade-ember-field{animation:none!important}.facade-ember-stack{transition:none!important}}\n`;\n\nconst GRAIN =\n  \"url(\\\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\\\")\";\n\ninterface EmberLayerProps {\n  palette: EmberPaletteInput;\n  cycle?: boolean;\n  cyclePalettes?: EmberPaletteInput[];\n  cycleDuration?: number;\n  speed?: number;\n  grain?: boolean | number;\n  intensity?: number;\n  /** Pauses drift and cycling, e.g. while the surface is off screen. */\n  paused?: boolean;\n}\n\nfunction EmberLayer({\n  palette,\n  cycle = false,\n  cyclePalettes,\n  cycleDuration = 30,\n  speed = 26,\n  grain = true,\n  intensity = 1,\n  paused = false,\n}: EmberLayerProps) {\n  const reduce = useReducedMotion();\n  const first = resolvePalette(palette);\n  const others = (cyclePalettes ?? (Object.keys(emberPalettes) as EmberPreset[]).filter((k) => k !== palette)).map(\n    resolvePalette,\n  );\n  const stacks = cycle ? [first, ...others] : [first];\n  const [active, setActive] = React.useState(0);\n  const running = cycle && !reduce && !paused && stacks.length > 1;\n\n  React.useEffect(() => {\n    if (!running) return;\n    const id = window.setInterval(() => setActive((i) => (i + 1) % stacks.length), cycleDuration * 1000);\n    return () => window.clearInterval(id);\n  }, [running, stacks.length, cycleDuration]);\n\n  const fade = Math.min(8, cycleDuration / 3);\n  const grainOpacity = grain === true ? 0.16 : typeof grain === \"number\" ? grain : 0;\n\n  return (\n    <div\n      aria-hidden\n      className=\"facade-ember pointer-events-none absolute inset-0 -z-10 overflow-hidden\"\n      data-paused={paused || undefined}\n      style={{ backgroundColor: `var(--ember-base, ${first.base})`, containerType: \"size\" }}\n    >\n      <style href=\"facade-ember-v1\" precedence=\"medium\">\n        {EMBER_CSS}\n      </style>\n      {stacks.map((p, s) => (\n        <div\n          key={s}\n          className=\"facade-ember-stack\"\n          style={{\n            opacity: s === active ? 1 : 0,\n            transitionDuration: `${fade}s`,\n            backgroundColor: s === 0 ? undefined : p.base,\n          }}\n        >\n          <div className=\"absolute inset-0\" style={{ opacity: intensity }}>\n            {FIELDS.map((f, i) => {\n              const raw = p.fields[i % Math.max(1, p.fields.length)];\n              if (!raw) return null;\n              // The first palette reads CSS variables, so a theme can override colors without props.\n              const color = s === 0 ? `var(--ember-${i + 1}, ${raw})` : raw;\n              const duration = speed * f.factor;\n              return (\n                <span\n                  key={i}\n                  className=\"facade-ember-field\"\n                  style={{\n                    ...fieldBox(f),\n                    opacity: f.opacity,\n                    // A short plateau before the falloff keeps small surfaces from showing hot spots.\n                    background: `radial-gradient(closest-side, ${color} 0%, ${color} 22%, color-mix(in srgb, ${color} 50%, transparent) 62%, transparent 100%)`,\n                    animationName: `facade-ember-${f.drift}`,\n                    animationDuration: `${duration}s`,\n                    animationDelay: `${f.delay * duration}s`,\n                  }}\n                />\n              );\n            })}\n          </div>\n        </div>\n      ))}\n      {grainOpacity > 0 && (\n        <div\n          className=\"absolute inset-0 mix-blend-overlay\"\n          style={{ opacity: grainOpacity, backgroundImage: GRAIN, backgroundSize: \"160px 160px\" }}\n        />\n      )}\n    </div>\n  );\n}\n\n/** Pauses the surface while it is scrolled out of view. */\nfunction useOffscreen<T extends Element>(ref: React.RefObject<T | null>) {\n  const [off, setOff] = React.useState(false);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el || typeof IntersectionObserver === \"undefined\") return;\n    const io = new IntersectionObserver(([e]) => setOff(!e.isIntersecting), { rootMargin: \"120px\" });\n    io.observe(el);\n    return () => io.disconnect();\n  }, [ref]);\n  return off;\n}\n\n/* ---------- end of engine ---------- */\n\nexport function EmberGradient({\n  children,\n  as: Tag = \"div\",\n  palette = \"ember\",\n  cycle = false,\n  cyclePalettes,\n  cycleDuration = 30,\n  speed = 26,\n  grain = true,\n  intensity = 1,\n  className,\n  contentClassName,\n  ...rest\n}: EmberGradientProps) {\n  const ref = React.useRef<HTMLElement>(null);\n  const offscreen = useOffscreen(ref);\n\n  return (\n    <Tag\n      {...rest}\n      ref={ref as React.Ref<never>}\n      className={cn(\"relative isolate overflow-hidden text-white\", className)}\n    >\n      <EmberLayer\n        palette={palette}\n        cycle={cycle}\n        cyclePalettes={cyclePalettes}\n        cycleDuration={cycleDuration}\n        speed={speed}\n        grain={grain}\n        intensity={intensity}\n        paused={offscreen}\n      />\n      <div className={cn(\"relative\", contentClassName)}>{children}</div>\n    </Tag>\n  );\n}\n\nexport default EmberGradient;\n"}],"categories":["layout"],"meta":{"tier":"free","demo":"import { ArrowRight, Phone } from \"lucide-react\";\nimport { EmberGradient, type EmberPreset } from \"./ember-gradient\";\n\nconst presets: { name: EmberPreset; note: string }[] = [\n  { name: \"ember\", note: \"Copper, forest, rust\" },\n  { name: \"moss\", note: \"Olive, pine, amber\" },\n  { name: \"dusk\", note: \"Clay, slate, plum\" },\n];\n\nexport default function Demo() {\n  return (\n    <div className=\"w-full space-y-3\">\n      <EmberGradient\n        cycle\n        cycleDuration={14}\n        className=\"rounded-[28px]\"\n        contentClassName=\"px-6 py-14 sm:px-12 sm:py-20\"\n      >\n        <p className=\"text-[13px] font-medium uppercase tracking-[0.08em] text-white/65\">Cedar Hollow Landscaping, Asheville</p>\n        <h2 className=\"mt-4 max-w-xl text-balance text-[34px] font-semibold leading-[1.05] tracking-[-0.03em] sm:text-[52px]\">\n          Fall cleanup crews are booking into December.\n        </h2>\n        <p className=\"mt-5 max-w-md text-[16px] leading-relaxed text-white/75 sm:text-[17px]\">\n          Leaf removal, bed mulching and a last mow, done in one visit with a written price before we start.\n        </p>\n        <div className=\"mt-8 flex flex-col gap-3 sm:flex-row\">\n          <a\n            href=\"#quote\"\n            className=\"group inline-flex h-11 items-center justify-center gap-2 rounded-full bg-white px-6 text-[15px] font-medium text-[#17130F] transition-colors hover:bg-white/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-offset-2 focus-visible:ring-offset-[#17130F]\"\n          >\n            Get a cleanup quote\n            <ArrowRight className=\"size-4 transition-transform duration-300 group-hover:translate-x-0.5\" aria-hidden />\n          </a>\n          <a\n            href=\"tel:+18285550142\"\n            className=\"inline-flex h-11 items-center justify-center gap-2 rounded-full px-5 text-[15px] font-medium text-white ring-1 ring-white/30 transition-colors hover:bg-white/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white\"\n          >\n            <Phone className=\"size-4\" aria-hidden />\n            (828) 555-0142\n          </a>\n        </div>\n      </EmberGradient>\n\n      <div className=\"grid grid-cols-3 gap-3\">\n        {presets.map((p) => (\n          <EmberGradient key={p.name} palette={p.name} className=\"rounded-[20px]\" contentClassName=\"px-4 pb-4 pt-14 sm:px-5 sm:pt-20\">\n            <p className=\"text-[14px] font-semibold capitalize\">{p.name}</p>\n            <p className=\"mt-0.5 hidden text-[12px] text-white/70 sm:block\">{p.note}</p>\n          </EmberGradient>\n        ))}\n      </div>\n    </div>\n  );\n}\n"}}