{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"frost-cloud","type":"registry:block","title":"Frost Cloud","description":"A frosted white cloud with eyes cut out of it, on a blue or red-orange sky – it floats, turns to look around, blinks, follows the pointer and bounces with a wink when clicked","dependencies":[],"files":[{"path":"illustrations/frost-cloud/frost-cloud.tsx","type":"registry:block","content":"\"use client\";\n\nimport { useEffect, useId, useRef } from \"react\";\n\n/*\n * Frost Cloud – a little cloud with eyes on a colored sky, in a single self-contained file.\n * Frosted white and a little see-through, the sky shining through softly towards the bottom, eyes cut out of it.\n * It floats and breathes, turns a little to look left and right, blinks now and then,\n * follows the pointer with its eyes and gives a squishy bounce and a wink when clicked.\n * Everything moves on soft springs; it runs only while on screen and keeps still with prefers-reduced-motion.\n */\n\nexport type FrostCloudProps = {\n  /** Fill the whole illustration with the sky gradient; false leaves the cloud on a transparent background */\n  background?: boolean;\n  /** \"blue\": a blue-to-cyan sky · \"orange\": a red-to-orange sky */\n  color?: \"blue\" | \"orange\";\n  /** The eyes follow the pointer while it's over the illustration */\n  followPointer?: boolean;\n  className?: string;\n  /** Accessible description of the illustration */\n  label?: string;\n};\n\n/* The cloud: puffs that melt into one shape through a soft \"goo\" filter */\nconst PUFFS = [\n  { cx: 115, cy: 93, r: 43 }, // the big puff on top\n  { cx: 163, cy: 111, r: 39 }, // right\n  { cx: 156, cy: 155, r: 31 }, // bottom right\n  { cx: 107, cy: 155, r: 35 }, // bottom\n  { cx: 72, cy: 126, r: 34 }, // left\n];\n/** Fills the middle between the puffs */\nconst CORE = { x: 80, y: 100, width: 80, height: 65 };\n/** Two wide pills, close together, a little below the middle */\nconst EYES = { y: 106, w: 18, h: 31, left: 96.5, right: 127.5 };\nconst CX = 120;\nconst CY = 120;\nconst BOTTOM = 180;\n\n/** Idle glances: straight, left, right, up and to the side, down and to the side */\nconst GLANCES = [\n  { x: 0, y: 0 },\n  { x: -1, y: 0.05 },\n  { x: 1, y: -0.05 },\n  { x: 0, y: 0 },\n  { x: 0.65, y: -0.55 },\n  { x: -0.7, y: 0.35 },\n];\n\nconst about = (x: number, y: number, t: string) => `translate(${x} ${y}) ${t} translate(${-x} ${-y})`;\n/** A gradient stop whose color comes from a CSS variable, so the palette can change */\nconst Stop = ({ offset, color, opacity }: { offset: number; color: string; opacity?: number }) => (\n  <stop offset={offset} style={{ stopColor: `var(--ui-fc-${color})`, stopOpacity: opacity }} />\n);\n\nexport function FrostCloud({\n  background = true,\n  color = \"blue\",\n  followPointer = true,\n  className,\n  label = \"A frosted white cloud with eyes that floats, looks around and blinks\",\n}: FrostCloudProps) {\n  const uid = useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const id = (name: string) => `fc${uid}-${name}`;\n\n  const root = useRef<HTMLDivElement>(null);\n  const floatRef = useRef<SVGGElement>(null);\n  const turnRef = useRef<SVGGElement>(null);\n  const eyesRef = useRef<SVGGElement>(null);\n  const leftEye = useRef<SVGGElement>(null);\n  const rightEye = useRef<SVGGElement>(null);\n  const shineRef = useRef<SVGEllipseElement>(null);\n  const shadowRef = useRef<SVGEllipseElement>(null);\n\n  useEffect(() => {\n    const el = root.current;\n    if (!el) return;\n    const still = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n\n    const look = { x: 0, y: 0, vx: 0, vy: 0 };\n    const target = { x: 0, y: 0 };\n    const squish = { p: 0, v: 0 }; // click bounce\n    let pointer = false;\n    let nextGlance = 1.2;\n    let nextBlink = 1.8;\n    let blinkAt = -1;\n    let blinkTwice = false;\n    let winkAt = -1;\n    let frame = 0;\n    let last = 0;\n    let time = 0;\n\n    const blinkScale = (since: number, length = 0.16) => (since < 0 || since > length ? 1 : 1 - 0.9 * Math.sin((since / length) * Math.PI));\n\n    const draw = () => {\n      const float = still ? 0 : Math.sin(time * 1.1) * 5;\n      const breathe = still ? 0 : Math.sin(time * 1.1 + Math.PI / 2) * 0.012;\n      const sy = 1 + breathe - squish.p * 0.12;\n      const sx = 1 - breathe + squish.p * 0.1;\n      floatRef.current?.setAttribute(\"transform\", `translate(0 ${float.toFixed(2)}) ${about(CX, BOTTOM, `scale(${sx.toFixed(4)} ${sy.toFixed(4)})`)}`);\n      // Turning: the body shifts and tilts a little, the eyes move further, the shine slides the other way\n      turnRef.current?.setAttribute(\"transform\", `translate(${(look.x * 4).toFixed(2)} ${(look.y * 2).toFixed(2)}) ${about(CX, CY, `rotate(${(look.x * 2.5).toFixed(2)}) scale(${(1 - Math.abs(look.x) * 0.025).toFixed(4)} 1)`)}`);\n      eyesRef.current?.setAttribute(\"transform\", `translate(${(look.x * 12).toFixed(2)} ${(look.y * 7).toFixed(2)})`);\n      shineRef.current?.setAttribute(\"transform\", `translate(${(-look.x * 7).toFixed(2)} ${(-look.y * 3).toFixed(2)})`);\n      const both = blinkAt < 0 ? 1 : Math.min(blinkScale(time - blinkAt), blinkTwice ? blinkScale(time - blinkAt - 0.26) : 1);\n      const wink = blinkScale(time - winkAt, 0.34);\n      const eyeY = EYES.y + EYES.h / 2;\n      leftEye.current?.setAttribute(\"transform\", about(EYES.left + EYES.w / 2, eyeY, `scale(1 ${both.toFixed(3)})`));\n      rightEye.current?.setAttribute(\"transform\", about(EYES.right + EYES.w / 2, eyeY, `scale(1 ${Math.min(both, wink).toFixed(3)})`));\n      // The shadow shrinks and fades as the cloud rises\n      const lift = (float + 5) / 10;\n      shadowRef.current?.setAttribute(\"transform\", about(CX, 210, `scale(${(1 - lift * 0.12).toFixed(3)} 1)`));\n      shadowRef.current?.setAttribute(\"opacity\", (0.34 - lift * 0.1).toFixed(3));\n    };\n\n    const tick = (now: number) => {\n      const dt = Math.min(0.05, (now - (last || now)) / 1000);\n      last = now;\n      time += dt;\n\n      if (!pointer && time > nextGlance) {\n        const g = GLANCES[Math.floor(Math.random() * GLANCES.length)];\n        target.x = g.x;\n        target.y = g.y;\n        nextGlance = time + 1.4 + Math.random() * 2.2;\n      }\n      if (time > nextBlink) {\n        blinkAt = time;\n        blinkTwice = Math.random() < 0.25;\n        nextBlink = time + 2.4 + Math.random() * 3;\n      }\n\n      // Springs: the gaze settles softly, the bounce wobbles out\n      look.vx += ((target.x - look.x) * 70 - look.vx * 13) * dt;\n      look.vy += ((target.y - look.y) * 70 - look.vy * 13) * dt;\n      look.x += look.vx * dt;\n      look.y += look.vy * dt;\n      squish.v += (-squish.p * 220 - squish.v * 9) * dt;\n      squish.p += squish.v * dt;\n\n      draw();\n      frame = requestAnimationFrame(tick);\n    };\n\n    const start = () => {\n      if (frame || still) return;\n      last = 0;\n      frame = requestAnimationFrame(tick);\n    };\n    const stop = () => {\n      cancelAnimationFrame(frame);\n      frame = 0;\n    };\n\n    const io = new IntersectionObserver(([e]) => (e.isIntersecting ? start() : stop()));\n    io.observe(el);\n\n    const onMove = (e: PointerEvent) => {\n      if (!followPointer) return;\n      const r = el.getBoundingClientRect();\n      pointer = true;\n      target.x = Math.max(-1, Math.min(1, ((e.clientX - r.left) / r.width - 0.5) * 2.4));\n      target.y = Math.max(-1, Math.min(1, ((e.clientY - r.top) / r.height - 0.5) * 2.4));\n    };\n    const onLeave = () => {\n      pointer = false;\n      target.x = 0;\n      target.y = 0;\n      nextGlance = time + 1.2;\n    };\n    const onDown = () => {\n      squish.p = 0.9;\n      squish.v = 0;\n      winkAt = time + 0.12;\n      if (still) {\n        start();\n        window.setTimeout(stop, 1200);\n      }\n    };\n    el.addEventListener(\"pointermove\", onMove);\n    el.addEventListener(\"pointerleave\", onLeave);\n    el.addEventListener(\"pointerdown\", onDown);\n    draw();\n\n    return () => {\n      stop();\n      io.disconnect();\n      el.removeEventListener(\"pointermove\", onMove);\n      el.removeEventListener(\"pointerleave\", onLeave);\n      el.removeEventListener(\"pointerdown\", onDown);\n    };\n  }, [followPointer]);\n\n  const puffs = PUFFS.map((p, i) => <circle key={i} {...p} />);\n  const eye = (x: number, ref: typeof leftEye, side: string) => {\n    const pill = { x, y: EYES.y, width: EYES.w, height: EYES.h, rx: EYES.w / 2 };\n    return (\n      <g ref={ref}>\n        {/* A soft shade around the hole, then the sky color inside with a slightly darker inner edge at the top */}\n        <rect {...pill} x={x - 1.5} y={EYES.y - 1} width={EYES.w + 3} height={EYES.h + 3} rx={EYES.w / 2 + 1.5} className=\"ui-fc__eye-drop\" filter={`url(#${id(\"edge\")})`} />\n        <rect {...pill} fill={`url(#${id(\"hole\")})`} />\n        <clipPath id={id(`clip-${side}`)}>\n          <rect {...pill} />\n        </clipPath>\n        <rect {...pill} y={EYES.y + 2.5} className=\"ui-fc__eye-shade\" fill=\"none\" strokeWidth=\"5\" filter={`url(#${id(\"edge\")})`} clipPath={`url(#${id(`clip-${side}`)})`} />\n      </g>\n    );\n  };\n\n  return (\n    <div\n      ref={root}\n      className={[\"ui-fc\", className].filter(Boolean).join(\" \")}\n      data-bg={background || undefined}\n      data-color={color}\n      role=\"img\"\n      aria-label={label}\n    >\n      {/* React 19 hoists this into <head> once, no matter how many clouds render */}\n      <style href=\"ui-frost-cloud\" precedence=\"default\">\n        {css}\n      </style>\n      <svg viewBox=\"0 0 240 240\" aria-hidden=\"true\">\n        <defs>\n          {/* Blur, then sharpen the edge again: the puffs melt into one soft cloud */}\n          <filter id={id(\"goo\")} x=\"0\" y=\"0\" width=\"240\" height=\"240\" filterUnits=\"userSpaceOnUse\">\n            <feGaussianBlur stdDeviation=\"3.5\" />\n            <feColorMatrix values=\"1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 28 -12\" />\n          </filter>\n          <filter id={id(\"soft\")} x=\"0\" y=\"0\" width=\"240\" height=\"240\" filterUnits=\"userSpaceOnUse\">\n            <feGaussianBlur stdDeviation=\"12\" />\n          </filter>\n          <filter id={id(\"halo\")} x=\"0\" y=\"0\" width=\"240\" height=\"240\" filterUnits=\"userSpaceOnUse\">\n            <feGaussianBlur stdDeviation=\"9\" />\n          </filter>\n          <filter id={id(\"edge\")} x=\"0\" y=\"0\" width=\"240\" height=\"240\" filterUnits=\"userSpaceOnUse\">\n            <feGaussianBlur stdDeviation=\"1.6\" />\n          </filter>\n          <filter id={id(\"shade\")} x=\"0\" y=\"0\" width=\"240\" height=\"240\" filterUnits=\"userSpaceOnUse\">\n            <feGaussianBlur stdDeviation=\"5\" />\n          </filter>\n          <g id={id(\"shape\")} filter={`url(#${id(\"goo\")})`}>\n            {puffs}\n            <rect {...CORE} />\n          </g>\n          <mask id={id(\"mask\")} maskUnits=\"userSpaceOnUse\" x=\"0\" y=\"0\" width=\"240\" height=\"240\">\n            <use href={`#${id(\"shape\")}`} fill=\"#fff\" />\n          </mask>\n          <linearGradient id={id(\"frost\")} x1=\"0\" y1=\"50\" x2=\"0\" y2=\"192\" gradientUnits=\"userSpaceOnUse\">\n            <Stop offset={0} color=\"white\" />\n            <Stop offset={1} color=\"frost\" opacity={0.97} />\n          </linearGradient>\n          <linearGradient id={id(\"hole\")} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n            <Stop offset={0} color=\"hole-1\" />\n            <Stop offset={1} color=\"hole-2\" />\n          </linearGradient>\n        </defs>\n\n        <ellipse ref={shadowRef} className=\"ui-fc__shadow\" cx={CX} cy=\"210\" rx=\"54\" ry=\"7\" filter={`url(#${id(\"shade\")})`} />\n\n        <g ref={floatRef}>\n          <g ref={turnRef}>\n            {/* A soft halo around the cloud, and a fine edge right around it that keeps it crisp on white */}\n            <use href={`#${id(\"shape\")}`} className=\"ui-fc__halo\" filter={`url(#${id(\"halo\")})`} />\n            <use href={`#${id(\"shape\")}`} className=\"ui-fc__edge\" filter={`url(#${id(\"edge\")})`} />\n            <g mask={`url(#${id(\"mask\")})`}>\n              <rect width=\"240\" height=\"240\" fill={`url(#${id(\"frost\")})`} />\n              {/* The sky shines through softly towards the bottom left; the edge stays bright white all around */}\n              <g filter={`url(#${id(\"soft\")})`} className=\"ui-fc__tint\" transform={`translate(-6 18) ${about(CX, CY, \"scale(0.84 0.78)\")}`}>\n                {puffs}\n                <rect {...CORE} />\n              </g>\n              <ellipse ref={shineRef} cx=\"108\" cy=\"78\" rx=\"34\" ry=\"14\" fill=\"#fff\" opacity=\"0.75\" filter={`url(#${id(\"shade\")})`} />\n            </g>\n            <g ref={eyesRef}>\n              {eye(EYES.left, leftEye, \"l\")}\n              {eye(EYES.right, rightEye, \"r\")}\n            </g>\n          </g>\n        </g>\n      </svg>\n    </div>\n  );\n}\n\n/* ---------- Styles ---------- */\n\nconst css = /* css */ `\n/* Palette as variables – blue, or red-orange via data-color=\"orange\" */\n.ui-fc {\n  --ui-fc-sky-top: #2475ea;\n  --ui-fc-sky-bottom: #4ac8f5;\n  --ui-fc-sky-light: rgba(110, 225, 255, 0.55);\n  --ui-fc-white: #ffffff;\n  --ui-fc-frost: #eef8ff;\n  --ui-fc-tint: rgba(70, 165, 235, 0.2);\n  --ui-fc-hole-1: #3aaef2;\n  --ui-fc-hole-2: #62cdfa;\n  --ui-fc-eye-drop: rgba(40, 130, 210, 0.1);\n  --ui-fc-eye-shade: rgba(10, 90, 190, 0.24);\n  --ui-fc-halo: rgba(30, 150, 255, 0.2);\n  --ui-fc-edge: rgba(20, 120, 240, 0.4);\n  --ui-fc-shadow: rgba(10, 90, 200, 0.55);\n  --ui-fc-ground: rgba(10, 80, 190, 0.4);\n  position: relative;\n  display: grid;\n  place-items: center;\n  width: 100%;\n  aspect-ratio: 1;\n  cursor: pointer;\n  user-select: none;\n  -webkit-tap-highlight-color: transparent;\n  touch-action: manipulation;\n}\n.ui-fc[data-color=\"orange\"] {\n  --ui-fc-sky-top: #e94135;\n  --ui-fc-sky-bottom: #fa9842;\n  --ui-fc-sky-light: rgba(255, 205, 150, 0.5);\n  --ui-fc-frost: #fff5f0;\n  --ui-fc-tint: rgba(235, 110, 70, 0.2);\n  --ui-fc-hole-1: #f05f42;\n  --ui-fc-hole-2: #fba05b;\n  --ui-fc-eye-drop: rgba(200, 70, 40, 0.1);\n  --ui-fc-eye-shade: rgba(170, 40, 20, 0.24);\n  --ui-fc-halo: rgba(240, 100, 60, 0.2);\n  --ui-fc-edge: rgba(220, 80, 40, 0.4);\n  --ui-fc-shadow: rgba(170, 50, 20, 0.5);\n  --ui-fc-ground: rgba(150, 30, 10, 0.36);\n}\n.ui-fc svg { display: block; width: 100%; max-width: 320px; overflow: visible; }\n.ui-fc__halo { fill: var(--ui-fc-halo); }\n.ui-fc__edge { fill: var(--ui-fc-edge); }\n.ui-fc__shadow { fill: var(--ui-fc-shadow); }\n.ui-fc__tint { fill: var(--ui-fc-tint); }\n.ui-fc__eye-drop { fill: var(--ui-fc-eye-drop); }\n.ui-fc__eye-shade { stroke: var(--ui-fc-eye-shade); }\n\n/* The sky: darker at the top, lighter at the bottom, a brighter patch behind the cloud – fills the whole box */\n.ui-fc[data-bg] {\n  --ui-fc-halo: rgba(255, 255, 255, 0.75);\n  --ui-fc-edge: rgba(255, 255, 255, 0.5);\n  --ui-fc-shadow: var(--ui-fc-ground);\n  background:\n    radial-gradient(60% 55% at 62% 42%, var(--ui-fc-sky-light), transparent 70%),\n    linear-gradient(180deg, var(--ui-fc-sky-top), var(--ui-fc-sky-bottom));\n}\n\n/* Dark mode: follows a .dark class or data-theme=\"dark\" on any ancestor, e.g. <html> – a deeper sky */\n:where(.dark, [data-theme=\"dark\"]) .ui-fc {\n  --ui-fc-sky-top: #1659c8;\n  --ui-fc-sky-bottom: #2aa6e6;\n  --ui-fc-sky-light: rgba(90, 205, 255, 0.45);\n  --ui-fc-ground: rgba(5, 50, 140, 0.5);\n}\n:where(.dark, [data-theme=\"dark\"]) .ui-fc[data-color=\"orange\"] {\n  --ui-fc-sky-top: #bf2722;\n  --ui-fc-sky-bottom: #ed701d;\n  --ui-fc-sky-light: rgba(255, 175, 120, 0.42);\n  --ui-fc-ground: rgba(110, 15, 5, 0.5);\n}\n:where(.dark, [data-theme=\"dark\"]) .ui-fc:not([data-bg]) {\n  --ui-fc-halo: rgba(255, 255, 255, 0.35);\n  --ui-fc-edge: rgba(255, 255, 255, 0.25);\n}\n`;\n"}]}