{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"rising-incense-smoke-background-with-curling-wisps-on-charcoal","type":"registry:block","title":"Rising Incense Smoke","description":"","dependencies":[],"files":[{"path":"components/we-inc/rising-incense-smoke-background-with-curling-wisps-on-charcoal.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\n// The values worth changing.\nconst SETTINGS = {\n  smoke: [214, 210, 204], // colour of the smoke as [red, green, blue]\n  ember: \"#ff9a4d\", // the glowing tip of the incense stick\n  rise: 38, // how fast the smoke climbs, in pixels per second\n  curl: 1, // how much the wisps twist; 0.5 is a still room, 1.6 a draughty one\n  puffs: 900, // how many puffs make up the smoke; fewer is cheaper and thinner\n};\n\nfunction smokeSprite() {\n  const c = document.createElement(\"canvas\");\n  c.width = c.height = 64;\n  const g = c.getContext(\"2d\");\n  const [r, gr, b] = SETTINGS.smoke;\n  const grad = g.createRadialGradient(32, 32, 0, 32, 32, 32);\n  grad.addColorStop(0, `rgba(${r},${gr},${b},1)`);\n  grad.addColorStop(0.4, `rgba(${r},${gr},${b},0.45)`);\n  grad.addColorStop(1, `rgba(${r},${gr},${b},0)`);\n  g.fillStyle = grad;\n  g.fillRect(0, 0, 64, 64);\n  return c;\n}\n\nconst SCENE: any = {\n  start: 0,\n  still: 0,\n  scale: 0.75,\n  init(ctx: any, w: any, h: any) {\n    const narrow = w < 700;\n    const src = { x: w * (narrow ? 0.72 : 0.68), y: h * (narrow ? 0.9 : 0.82) };\n    const st: any = { ps: [], src, sprite: smokeSprite(), t: 0, narrow };\n    // Let the incense burn for a while first so the column is already tall on the first frame.\n    for (let i = 0; i < 600; i++) SCENE.step(st, 1 / 60, h);\n    return st;\n  },\n  step(st: any, dt: any, h: any) {\n    st.t += dt;\n    const t = st.t;\n    const life = (st.src.y + 40) / SETTINGS.rise;\n    const spawn = (SETTINGS.puffs / life) * dt;\n    st.carry = (st.carry || 0) + spawn;\n    while (st.carry >= 1) {\n      st.carry -= 1;\n      st.ps.push({ x: st.src.x + (Math.random() - 0.5) * 1.5, y: st.src.y - 4, vx: 0, age: 0, seed: Math.random() * 6.28 });\n    }\n    const c = SETTINGS.curl;\n    for (const p of st.ps) {\n      p.age += dt;\n      const up = st.src.y - p.y;\n      // Near the stick the smoke rises as a thin laminar thread, then breaks into curls higher up.\n      const turb = Math.min(1, up / (h * 0.25));\n      const sway = Math.sin(t * 0.35 + up * 0.004) * 30 * turb;\n      const curlx = (Math.sin(up * 0.021 - t * 1.1 + p.seed * 0.15) * 22 + Math.sin(up * 0.047 + t * 0.7) * 9) * turb * turb * c;\n      p.vx += ((sway + curlx) - p.vx) * Math.min(1, dt * 2.2);\n      p.x += p.vx * dt + Math.sin(t * 0.9 + p.seed) * 0.08 * turb * c;\n      p.x += (Math.random() - 0.5) * turb * 0.9;\n      p.y -= SETTINGS.rise * dt * (1 + 0.3 * turb);\n    }\n    st.ps = st.ps.filter((p: any) => p.y > -60);\n  },\n  draw(ctx: any, w: any, h: any, t: any, st: any, ptr: any, dt: any) {\n    if (dt > 0) SCENE.step(st, dt, h);\n    const bg = ctx.createRadialGradient(st.src.x, h * 0.45, 0, st.src.x, h * 0.45, Math.max(w, h) * 0.8);\n    bg.addColorStop(0, \"#26211d\");\n    bg.addColorStop(1, \"#0f0d0c\");\n    ctx.fillStyle = bg;\n    ctx.fillRect(0, 0, w, h);\n    const sy = st.src.y;\n    for (const p of st.ps) {\n      const up = sy - p.y;\n      const k = up / sy;\n      const size = 3 + up * 0.09;\n      const a = Math.min(1, up / 18) * Math.pow(Math.max(0, 1 - k), 1.6) * (0.16 - Math.min(0.1, up * 0.0004));\n      if (a <= 0.002) continue;\n      ctx.globalAlpha = a;\n      ctx.drawImage(st.sprite, p.x - size, p.y - size, size * 2, size * 2);\n    }\n    ctx.globalAlpha = 1;\n    // The incense stick and its ember.\n    ctx.strokeStyle = \"#5a4636\";\n    ctx.lineWidth = 2;\n    ctx.beginPath();\n    ctx.moveTo(st.src.x, sy);\n    ctx.lineTo(st.src.x + 18, h + 4);\n    ctx.stroke();\n    const glow = ctx.createRadialGradient(st.src.x, sy, 0, st.src.x, sy, 16);\n    glow.addColorStop(0, \"rgba(255,170,90,0.9)\");\n    glow.addColorStop(0.25, \"rgba(255,120,50,0.35)\");\n    glow.addColorStop(1, \"rgba(255,120,50,0)\");\n    ctx.fillStyle = glow;\n    ctx.fillRect(st.src.x - 16, sy - 16, 32, 32);\n    ctx.fillStyle = SETTINGS.ember;\n    ctx.beginPath();\n    ctx.arc(st.src.x, sy, 1.8, 0, 6.29);\n    ctx.fill();\n  },\n};\n\n// Runs a scene on a canvas: sizes it to the block, pauses off screen and in hidden tabs, cleans up after itself.\nfunction runScene(root: any, canvas: any, scene: any, reduced: boolean) {\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) return () => {};\n  let w = 0;\n  let h = 0;\n  let st: any = null;\n  let raf = 0;\n  let last = 0;\n  let acc = 0;\n  let onScreen = true;\n  let time = reduced ? (scene.still ?? scene.start ?? 0) : (scene.start ?? 0);\n  const ptr: any = { x: 0, y: 0, on: false, down: 0 };\n  const step = 1 / (scene.fps || 60);\n  const resize = () => {\n    const r = root.getBoundingClientRect();\n    const nw = Math.max(1, Math.round(r.width));\n    const nh = Math.max(1, Math.round(r.height));\n    if (nw === w && nh === h && st) return;\n    w = nw;\n    h = nh;\n    // Device pixels are capped at 1.5 and scaled by the scene's own quality factor.\n    const d = Math.min(window.devicePixelRatio || 1, 1.5) * (scene.scale || 1);\n    canvas.width = Math.max(1, Math.round(w * d));\n    canvas.height = Math.max(1, Math.round(h * d));\n    ctx.setTransform(canvas.width / w, 0, 0, canvas.height / h, 0, 0);\n    st = scene.init(ctx, w, h, canvas.width / w);\n    scene.draw(ctx, w, h, time, st, ptr, 0);\n  };\n  const tick = (now: number) => {\n    raf = requestAnimationFrame(tick);\n    const dt = last ? Math.min(0.1, (now - last) / 1000) : step;\n    last = now;\n    acc += dt;\n    if (acc < step * 0.95) return;\n    const used = Math.min(acc, 0.1);\n    acc = 0;\n    time += used;\n    scene.draw(ctx, w, h, time, st, ptr, used);\n  };\n  const play = () => {\n    if (raf || reduced || !onScreen || document.hidden) return;\n    last = 0;\n    raf = requestAnimationFrame(tick);\n  };\n  const stop = () => {\n    cancelAnimationFrame(raf);\n    raf = 0;\n  };\n  const ro = new ResizeObserver(resize);\n  ro.observe(root);\n  const io = new IntersectionObserver((entries: any) => {\n    onScreen = entries[0].isIntersecting;\n    if (onScreen) play();\n    else stop();\n  });\n  io.observe(root);\n  const onVis = () => (document.hidden ? stop() : play());\n  const onMove = (e: any) => {\n    const r = root.getBoundingClientRect();\n    ptr.x = e.clientX - r.left;\n    ptr.y = e.clientY - r.top;\n    ptr.on = true;\n  };\n  const onLeave = () => {\n    ptr.on = false;\n  };\n  const onDown = (e: any) => {\n    onMove(e);\n    ptr.down += 1;\n  };\n  document.addEventListener(\"visibilitychange\", onVis);\n  root.addEventListener(\"pointermove\", onMove);\n  root.addEventListener(\"pointerleave\", onLeave);\n  root.addEventListener(\"pointerdown\", onDown);\n  resize();\n  play();\n  return () => {\n    stop();\n    ro.disconnect();\n    io.disconnect();\n    document.removeEventListener(\"visibilitychange\", onVis);\n    root.removeEventListener(\"pointermove\", onMove);\n    root.removeEventListener(\"pointerleave\", onLeave);\n    root.removeEventListener(\"pointerdown\", onDown);\n  };\n}\n\nexport default function IncenseSmokeBackground() {\n  const rootRef = useRef<HTMLElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  useEffect(() => {\n    const root = rootRef.current;\n    const canvas = canvasRef.current;\n    if (!root || !canvas) return;\n    // Visitors who prefer reduced motion get one settled frame and no loop.\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    return runScene(root, canvas, SCENE, reduced);\n  }, []);\n\n  return (\n    <section ref={rootRef} className=\"relative h-[640px] w-full overflow-hidden bg-[#141110] text-[#f3ede6]\">\n      <canvas ref={canvasRef} aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 block h-full w-full\" />\n      <div className=\"relative z-10 mx-auto flex h-full max-w-6xl flex-col justify-center items-start text-left px-6 py-14 sm:px-10\">\n        <div className=\"max-w-xl\">\n          <p className=\"text-xs font-semibold uppercase tracking-[0.2em] text-[#e7b98c]\">Juniper Hall Incense Works</p>\n          <h2 className=\"font-serif mt-4 text-4xl font-semibold leading-[1.05] tracking-tight sm:text-5xl lg:text-6xl\">Cedar and hinoki, rolled by hand.</h2>\n          <p className=\"mt-5 text-base leading-relaxed text-[#cfc6bc] sm:text-lg\">Slow-burning sticks made in small batches, with no added perfume and nothing that catches in the throat.</p>\n          <a href=\"#\" className=\"mt-8 inline-flex h-12 items-center rounded-[2px] bg-[#e9dccb] px-6 text-sm font-semibold text-[#1c1612] transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#e9dccb] focus-visible:ring-offset-2 focus-visible:ring-offset-[#141110]\">Shop the sampler</a>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
