{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "micro-dodge-field",
  "type": "registry:component",
  "title": "Dodge Field",
  "description": "A text field with a glowing dot that slips away from the pointer on a spring and tucks into the corner on focus. The input underneath is a plain accessible input.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "input",
    "field",
    "pointer",
    "spring",
    "form",
    "micro"
  ],
  "docs": "https://hyperblur.dev/effects/micro-dodge-field",
  "files": [
    {
      "path": "registry/hyperblur/micro-dodge-field.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/micro-dodge-field.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface MicroDodgeFieldProps\n  extends Omit<React.InputHTMLAttributes<HTMLInputElement>, \"className\" | \"style\" | \"size\"> {\n  label?: string;\n  accent?: string;\n  idle?: boolean;\n  className?: string;\n  style?: React.CSSProperties;\n}\n\nconst css = `\n.hb-ql2 {\n  display: flex;\n  flex-direction: column;\n  gap: 8px;\n  width: 100%;\n  box-sizing: border-box;\n  font-family: inherit;\n  --hb-ql2-c: #2f7bff;\n}\n.hb-ql2 *, .hb-ql2 *::before, .hb-ql2 *::after { box-sizing: border-box; }\n.hb-ql2-l {\n  font-size: 0.8em;\n  font-weight: 500;\n  letter-spacing: 0.01em;\n  color: #a1a1a1;\n}\n.hb-ql2-f {\n  position: relative;\n  height: 52px;\n  overflow: hidden;\n  container-type: inline-size;\n  background: #111111;\n  border: 1px solid #262626;\n  border-radius: 14px;\n  transition: border-color 0.25s ease, box-shadow 0.25s ease;\n}\n.hb-ql2-f:hover { border-color: #343434; }\n.hb-ql2-f[data-focus=\"true\"] {\n  border-color: var(--hb-ql2-c);\n  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-ql2-c) 22%, transparent);\n}\n.hb-ql2-d {\n  position: absolute;\n  left: 0;\n  top: 0;\n  z-index: 0;\n  width: 14px;\n  height: 14px;\n  border-radius: 50%;\n  background: radial-gradient(circle at 35% 30%, #fff 0%, color-mix(in srgb, var(--hb-ql2-c) 70%, #fff) 28%, var(--hb-ql2-c) 70%);\n  box-shadow: 0 0 14px 2px color-mix(in srgb, var(--hb-ql2-c) 55%, transparent);\n  transform: translate(calc(100cqw - 33px), 19px);\n  pointer-events: none;\n  will-change: transform;\n}\n.hb-ql2-g {\n  position: absolute;\n  left: 0;\n  top: 0;\n  z-index: 2;\n  width: 16px;\n  height: 16px;\n  border: 1.5px solid rgba(255, 255, 255, 0.38);\n  border-radius: 50%;\n  opacity: 0;\n  pointer-events: none;\n  transition: opacity 0.3s ease;\n  will-change: transform;\n}\n.hb-ql2-g[data-on=\"true\"] { opacity: 1; }\n.hb-ql2-i {\n  position: relative;\n  z-index: 1;\n  display: block;\n  width: 100%;\n  height: 100%;\n  margin: 0;\n  padding: 0 16px;\n  font: inherit;\n  color: #ededed;\n  background: transparent;\n  border: 0;\n  outline: 0;\n}\n.hb-ql2-i::placeholder { color: #6b6b6b; }\n.hb-ql2-i:disabled { cursor: not-allowed; opacity: 0.5; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-ql2-f, .hb-ql2-g { transition: none; }\n}\n`;\n\nexport function MicroDodgeField({\n  label,\n  accent = \"#2f7bff\",\n  idle = true,\n  className = \"\",\n  style,\n  id,\n  onFocus,\n  onBlur,\n  ...rest\n}: MicroDodgeFieldProps) {\n  const autoId = React.useId();\n  const inputId = id ?? autoId;\n  const fieldRef = React.useRef<HTMLDivElement>(null);\n  const dotRef = React.useRef<HTMLSpanElement>(null);\n  const ghostRef = React.useRef<HTMLSpanElement>(null);\n  const [focused, setFocused] = React.useState(false);\n  const state = React.useRef({\n    x: -1,\n    y: -1,\n    vx: 0,\n    vy: 0,\n    px: 0,\n    py: 0,\n    inside: false,\n    focused: false,\n    resumeAt: 0,\n    idle,\n  });\n  const api = React.useRef({ wake: () => {} });\n\n  React.useEffect(() => {\n    state.current.idle = idle;\n    state.current.focused = focused;\n    api.current.wake();\n  }, [idle, focused]);\n\n  React.useEffect(() => {\n    const field = fieldRef.current;\n    const dot = dotRef.current;\n    const ghost = ghostRef.current;\n    if (!field || !dot || !ghost) return;\n    const s = state.current;\n    const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    let reduced = mq.matches;\n    let raf = 0;\n    let last = 0;\n    let visible = true;\n\n    const restPoint = (w: number, h: number) =>\n      s.focused ? { x: w - 18, y: 14 } : { x: w - 26, y: h / 2 };\n\n    const draw = () => {\n      const speed = Math.hypot(s.vx, s.vy);\n      const sx = 1 + Math.min(0.55, speed / 1500);\n      const sy = 1 / sx;\n      const ang = Math.atan2(s.vy, s.vx);\n      const base = s.focused ? 0.7 : 1;\n      dot.style.transform = `translate3d(${(s.x - 7).toFixed(2)}px,${(s.y - 7).toFixed(2)}px,0) rotate(${ang.toFixed(3)}rad) scale(${(sx * base).toFixed(3)},${(sy * base).toFixed(3)})`;\n    };\n\n    const place = () => {\n      const w = field.clientWidth;\n      const h = field.clientHeight;\n      const r = restPoint(w, h);\n      s.x = r.x;\n      s.y = r.y;\n      s.vx = 0;\n      s.vy = 0;\n      draw();\n    };\n\n    const tick = (now: number) => {\n      raf = 0;\n      if (!visible) return;\n      const dt = Math.min(0.05, Math.max(0.001, (now - last) / 1000));\n      last = now;\n      const w = field.clientWidth;\n      const h = field.clientHeight;\n      if (s.x < 0) {\n        const r0 = restPoint(w, h);\n        s.x = r0.x;\n        s.y = r0.y;\n      }\n      const r = restPoint(w, h);\n      let hasPointer = false;\n      let px = 0;\n      let py = 0;\n      if (s.inside) {\n        hasPointer = true;\n        px = s.px;\n        py = s.py;\n        ghost.dataset.on = \"false\";\n      } else if (s.idle && !reduced && now >= s.resumeAt) {\n        hasPointer = true;\n        px = w * (0.5 + 0.44 * Math.sin(now * 0.0011));\n        py = h * (0.5 + 0.5 * Math.sin(now * 0.0019 + 1));\n        ghost.dataset.on = \"true\";\n        ghost.style.transform = `translate3d(${(px - 8).toFixed(1)}px,${(py - 8).toFixed(1)}px,0)`;\n      } else {\n        ghost.dataset.on = \"false\";\n      }\n      let rem = dt;\n      while (rem > 0) {\n        const step = Math.min(rem, 1 / 120);\n        let ax = 110 * (r.x - s.x) - 13 * s.vx;\n        let ay = 110 * (r.y - s.y) - 13 * s.vy;\n        if (hasPointer) {\n          const dx = s.x - px;\n          const dy = s.y - py;\n          const dist = Math.hypot(dx, dy);\n          const reach = 96;\n          if (dist < reach) {\n            const f = 1 - dist / reach;\n            const nx = dist > 0.01 ? dx / dist : 1;\n            const ny = dist > 0.01 ? dy / dist : 0;\n            ax += nx * f * f * 9000;\n            ay += ny * f * f * 9000;\n          }\n        }\n        s.vx += ax * step;\n        s.vy += ay * step;\n        s.x += s.vx * step;\n        s.y += s.vy * step;\n        const minX = 12;\n        const maxX = w - 12;\n        const minY = 12;\n        const maxY = h - 12;\n        if (s.x < minX) {\n          s.x = minX;\n          s.vx = Math.abs(s.vx) * 0.3;\n        } else if (s.x > maxX) {\n          s.x = maxX;\n          s.vx = -Math.abs(s.vx) * 0.3;\n        }\n        if (s.y < minY) {\n          s.y = minY;\n          s.vy = Math.abs(s.vy) * 0.3;\n        } else if (s.y > maxY) {\n          s.y = maxY;\n          s.vy = -Math.abs(s.vy) * 0.3;\n        }\n        rem -= step;\n      }\n      draw();\n      raf = requestAnimationFrame(tick);\n    };\n\n    const wake = () => {\n      if (reduced) {\n        place();\n        return;\n      }\n      if (!raf && visible) {\n        last = performance.now();\n        raf = requestAnimationFrame(tick);\n      }\n    };\n\n    api.current.wake = wake;\n    place();\n    wake();\n\n    const io = new IntersectionObserver((entries) => {\n      visible = entries[entries.length - 1]?.isIntersecting ?? true;\n      if (visible) wake();\n      else {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n    });\n    io.observe(field);\n    const ro = new ResizeObserver(() => {\n      if (reduced) place();\n    });\n    ro.observe(field);\n    const onMq = () => {\n      reduced = mq.matches;\n      if (reduced) {\n        cancelAnimationFrame(raf);\n        raf = 0;\n        ghost.dataset.on = \"false\";\n        place();\n      } else wake();\n    };\n    mq.addEventListener(\"change\", onMq);\n\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      ro.disconnect();\n      mq.removeEventListener(\"change\", onMq);\n    };\n  }, []);\n\n  function track(e: React.PointerEvent<HTMLDivElement>) {\n    const rect = e.currentTarget.getBoundingClientRect();\n    const s = state.current;\n    s.px = e.clientX - rect.left;\n    s.py = e.clientY - rect.top;\n    s.inside = true;\n  }\n\n  const vars = { \"--hb-ql2-c\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-micro-dodge-field\" precedence=\"default\">{css}</style>\n      <div className={`hb-ql2 ${className}`} style={vars}>\n        {label ? (\n          <label className=\"hb-ql2-l\" htmlFor={inputId}>\n            {label}\n          </label>\n        ) : null}\n        <div\n          ref={fieldRef}\n          className=\"hb-ql2-f\"\n          data-focus={focused}\n          onPointerEnter={track}\n          onPointerMove={track}\n          onPointerLeave={() => {\n            state.current.inside = false;\n            state.current.resumeAt = performance.now() + 1600;\n            api.current.wake();\n          }}\n        >\n          <span ref={dotRef} className=\"hb-ql2-d\" aria-hidden=\"true\" />\n          <span ref={ghostRef} className=\"hb-ql2-g\" data-on=\"false\" aria-hidden=\"true\" />\n          <input\n            {...rest}\n            id={inputId}\n            className=\"hb-ql2-i\"\n            onFocus={(e) => {\n              onFocus?.(e);\n              setFocused(true);\n            }}\n            onBlur={(e) => {\n              onBlur?.(e);\n              setFocused(false);\n            }}\n          />\n        </div>\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}