{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"glass-focus-field","type":"registry:component","title":"Glass Focus Field","description":"A liquid-glass input whose rim notices the pointer before focus, thickens outward from where you click, ripples from the caret with every keystroke and clouds its frost on an error.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/glass-focus-field.tsx","content":"\"use client\";\n\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport type { ChangeEvent, PointerEvent as ReactPointerEvent } from \"react\";\n\n/**\n * GlassField — a liquid-glass text field that reacts before, during and\n * after you type.\n *\n * Before focus, the rim notices the pointer: within about 140px the stretch\n * of rim nearest it lights up and the bezel thickens a little (in Chromium\n * the edge also starts to bend what is behind it). Focus it and a second,\n * deeper pane blooms outward from the point you clicked (or from where the\n * text starts, when you arrive by keyboard): more blur, more saturation, a\n * brighter rim, and in Chromium a refracting edge. While you type, the rim\n * light rides with the caret, and every keystroke sends a short ripple\n * through the glass from the caret: outward as you type, inward as you\n * delete. An error keeps the warm tint and clouds the glass for a moment,\n * the frost thickening and then clearing, instead of shaking.\n *\n * The label floats up out of the way on focus or once there is a value.\n * `error` tints the glass warm and announces the message; `hint` sits below.\n * Works as a single-line field (a full pill, the kit's control shape) or,\n * with `multiline`, a textarea with 24px corners.\n *\n * The panes are siblings rather than nested, so each one blurs the page\n * behind it rather than another pane. The refracting edges run only in\n * Chromium (detected, not guessed with @supports: Safari and Firefox parse\n * backdrop-filter: url() and draw nothing); elsewhere every reaction is\n * blur, saturation, light and rim. The caret is measured with a hidden\n * mirror in layout pixels, so it lands right inside scaled containers too.\n * Under prefers-reduced-motion the bloom is instant, there are no ripples\n * and no clouding, and the light moves without easing. The loop sleeps\n * when nothing is moving and when the field is off screen.\n *\n * Needs Tailwind v4 (or v3.4+). No dependencies beyond React.\n */\n\ntype Tone = \"dark\" | \"light\";\ntype Api = { focused: boolean; restLens: number; kick: () => void; caret: () => void };\ntype Ripple = { x: number; y: number; t0: number; inward: boolean; big: boolean };\n\nconst noop = () => {};\n/** How close the pointer comes before the rim notices it, px. */\nconst NOTICE = 140;\n/** At most this many ripples in the glass at once. */\nconst MAX_RIPPLES = 4;\n/** The resting glass and its bezel, before anything comes near. */\nconst REST_GLASS = \"blur(6px) saturate(150%) brightness(1.04)\";\nconst BEZEL_REST = \"inset 0 0 0 1px rgba(255,255,255,0.04), inset 0 0 6px rgba(255,255,255,0.02)\";\nconst BULLET = String.fromCharCode(8226);\nconst ZWSP = String.fromCharCode(8203);\n\n/** \"#rrggbb\" to \"r,g,b\", or null. Anything else is ignored, never interpolated. */\nfunction rgbOf(hex?: string): string | null {\n  const m = /^#([0-9a-f]{6})$/i.exec(hex || \"\");\n  if (!m) return null;\n  const n = parseInt(m[1], 16);\n  return ((n >> 16) & 255) + \",\" + ((n >> 8) & 255) + \",\" + (n & 255);\n}\n\nfunction isChromium(): boolean {\n  const ua = (navigator as Navigator & { userAgentData?: { brands?: { brand: string }[] } }).userAgentData;\n  return !!ua && !!ua.brands && ua.brands.some((b) => /Chromium/.test(b.brand));\n}\n\n/** Smoothstep on 0..1. */\nfunction ease(t: number): number {\n  const x = Math.min(1, Math.max(0, t));\n  return x * x * (3 - 2 * x);\n}\n\n/** Signed distance from a point to a rounded box centred on the origin (negative inside). */\nfunction boxDist(x: number, y: number, hw: number, hh: number, r: number): number {\n  const qx = Math.abs(x) - (hw - r);\n  const qy = Math.abs(y) - (hh - r);\n  return Math.hypot(Math.max(qx, 0), Math.max(qy, 0)) + Math.min(Math.max(qx, qy), 0) - r;\n}\n\n/** Displacement map for a rounded rectangle: red = x, green = y, 128 = none. */\nfunction lensMap(w: number, h: number, r: number, bezel: number): string {\n  const c = document.createElement(\"canvas\");\n  c.width = w;\n  c.height = h;\n  const ctx = c.getContext(\"2d\");\n  if (!ctx) return \"\";\n  const img = ctx.createImageData(w, h);\n  const hw = w / 2;\n  const hh = h / 2;\n  const rr = Math.min(r, hw, hh);\n  const sd = (x: number, y: number) => boxDist(x, y, hw, hh, rr);\n  for (let j = 0; j < h; j++) {\n    for (let i = 0; i < w; i++) {\n      const x = i + 0.5 - hw;\n      const y = j + 0.5 - hh;\n      const t = -sd(x, y);\n      let dx = 0;\n      let dy = 0;\n      if (t > 0 && t < bezel) {\n        const nx = sd(x + 0.5, y) - sd(x - 0.5, y);\n        const ny = sd(x, y + 0.5) - sd(x, y - 0.5);\n        const len = Math.hypot(nx, ny) || 1;\n        const m = Math.pow(1 - t / bezel, 2);\n        dx = (-nx / len) * m;\n        dy = (-ny / len) * m;\n      }\n      const k = (j * w + i) * 4;\n      img.data[k] = Math.round(128 + 127 * dx);\n      img.data[k + 1] = Math.round(128 + 127 * dy);\n      img.data[k + 2] = 128;\n      img.data[k + 3] = 255;\n    }\n  }\n  ctx.putImageData(img, 0, 0);\n  return c.toDataURL();\n}\n\nexport function GlassField({\n  label,\n  name,\n  id,\n  type = \"text\",\n  value,\n  defaultValue,\n  onChange,\n  placeholder,\n  multiline = false,\n  rows = 4,\n  hint,\n  error,\n  required,\n  disabled,\n  autoComplete,\n  tone = \"dark\",\n  tint,\n  refraction = 1,\n  className = \"\",\n}: {\n  label: string;\n  name?: string;\n  id?: string;\n  type?: \"text\" | \"email\" | \"password\" | \"search\" | \"tel\" | \"url\";\n  value?: string;\n  defaultValue?: string;\n  onChange?: (value: string) => void;\n  /** Shown only once the label has floated out of the way. */\n  placeholder?: string;\n  multiline?: boolean;\n  rows?: number;\n  hint?: string;\n  /** A message here marks the field invalid, tints the glass warm and clouds it once. */\n  error?: string;\n  required?: boolean;\n  disabled?: boolean;\n  autoComplete?: string;\n  /** Glass over dark content (white text) or light content (ink text). */\n  tone?: Tone;\n  /** Tint of the focused glass, \"#rrggbb\", at 14%. */\n  tint?: string;\n  /** Edge refraction, 0–2 (Chromium only). Above 1 it widens the bent band. */\n  refraction?: number;\n  className?: string;\n}) {\n  const auto = useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const fieldId = id || \"gf\" + auto;\n  const filterId = \"gfl\" + auto;\n  const restId = \"gfr\" + auto;\n  const shellRef = useRef<HTMLDivElement>(null);\n  const restRef = useRef<HTMLSpanElement>(null);\n  const thickRef = useRef<HTMLSpanElement>(null);\n  const cloudRef = useRef<HTMLSpanElement>(null);\n  const bezelRef = useRef<HTMLSpanElement>(null);\n  const rippleRef = useRef<HTMLSpanElement>(null);\n  const mirrorRef = useRef<HTMLDivElement>(null);\n  const mapRef = useRef<SVGFEImageElement>(null);\n  const dispRef = useRef<SVGFEDisplacementMapElement>(null);\n  const restMapRef = useRef<SVGFEImageElement>(null);\n  const restDispRef = useRef<SVGFEDisplacementMapElement>(null);\n  const origin = useRef({ x: 22, y: 0, fromPointer: false });\n  // What the handlers share with the reaction loop.\n  const api = useRef<Api>({ focused: false, restLens: 0, kick: noop, caret: noop });\n  const lastError = useRef(error);\n  const cloudTimer = useRef(0);\n  const [focused, setFocused] = useState(false);\n  const [typed, setTyped] = useState(!!defaultValue);\n  const filled = value !== undefined ? value !== \"\" : typed;\n  const floated = focused || filled;\n  const dark = tone === \"dark\";\n  const radius = multiline ? 24 : 999;\n\n  const thickBase = \"blur(18px) saturate(200%) brightness(\" + (dark ? 1.1 : 1.05) + \")\";\n\n  // The refracting edges, sized to the field, where the engine can run them:\n  // the deep pane's at full strength, the rest pane's ramped by the loop.\n  useEffect(() => {\n    const shell = shellRef.current;\n    const thick = thickRef.current;\n    const A = api.current;\n    if (!shell || !thick) return;\n    if (!isChromium() || refraction <= 0) {\n      thick.style.backdropFilter = thickBase;\n      A.restLens = 0;\n      A.kick();\n      return;\n    }\n    let key = \"\";\n    const apply = () => {\n      const w = Math.round(shell.offsetWidth);\n      const h = Math.round(shell.offsetHeight);\n      if (!w || !h || !mapRef.current || !dispRef.current || !restMapRef.current) return;\n      // Refraction up to 1 strengthens the bend; above 1 it widens the bent\n      // band instead, so the peak offset never passes 0.4 of the bezel.\n      const bezel = Math.min(14 * Math.max(1, refraction), h * 0.3);\n      const k = w + \"x\" + h + \":\" + bezel.toFixed(1);\n      if (k !== key) {\n        key = k;\n        const url = lensMap(w, h, multiline ? 24 : h / 2, bezel);\n        for (const fe of [mapRef.current, restMapRef.current]) {\n          fe.setAttribute(\"href\", url);\n          fe.setAttribute(\"width\", String(w));\n          fe.setAttribute(\"height\", String(h));\n        }\n      }\n      const full = Math.round(0.8 * bezel * Math.min(1, refraction));\n      dispRef.current.setAttribute(\"scale\", String(full));\n      thick.style.backdropFilter = \"url(#\" + filterId + \") \" + thickBase;\n      A.restLens = full;\n      A.kick();\n    };\n    apply();\n    const ro = new ResizeObserver(apply);\n    ro.observe(shell);\n    return () => {\n      ro.disconnect();\n      A.restLens = 0;\n    };\n  }, [filterId, thickBase, refraction, multiline]);\n\n  // The reactions: the rim noticing the pointer, the light riding the caret,\n  // and the keystroke ripples. One loop, asleep when nothing moves.\n  useEffect(() => {\n    const shell = shellRef.current;\n    const rest = restRef.current;\n    const bezel = bezelRef.current;\n    const rip = rippleRef.current;\n    const mirror = mirrorRef.current;\n    const A = api.current;\n    if (!shell || !rest || !bezel || !rip || !mirror || disabled) return;\n    const field = shell.querySelector(\"input, textarea\") as HTMLInputElement | HTMLTextAreaElement | null;\n    if (!field) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    const chromium = isChromium();\n    const crest = dark ? 0.2 : 0.5;\n    const trough = dark ? 0.1 : 0.06;\n    const S = {\n      px: 0,\n      py: 0,\n      has: false,\n      lx: 0,\n      ly: 0,\n      lo: 0,\n      b: 0,\n      cx: 22,\n      cy: 29,\n      dirty: true,\n      raf: 0,\n      last: 0,\n      visible: true,\n      ripples: [] as Ripple[],\n      queue: [] as { inward: boolean; big: boolean }[],\n      restKey: \"\",\n      restScale: -1,\n      rippleKey: \"\",\n    };\n\n    /** The caret's place in the field, in layout pixels, from a hidden mirror of the text before it. */\n    function caret(w: number, h: number) {\n      let at = field!.value.length;\n      try {\n        if (field!.selectionStart !== null) at = field!.selectionStart;\n      } catch {\n        // Some engines throw for fields without a selection API (email): the end will do.\n      }\n      const text = field!.value.slice(0, at);\n      mirror!.textContent = type === \"password\" ? BULLET.repeat(text.length) : text;\n      const mark = document.createElement(\"span\");\n      mark.textContent = ZWSP;\n      mirror!.appendChild(mark);\n      const x = mark.offsetLeft - field!.scrollLeft;\n      const y = mark.offsetTop + 12 - field!.scrollTop;\n      // Emptied at once, so a long value never widens the page.\n      mirror!.textContent = \"\";\n      S.cx = Math.min(w - 14, Math.max(14, x));\n      S.cy = Math.min(h - 10, Math.max(10, y));\n    }\n\n    /** One ripple as a ring of light with a faint trough beside it, or null once it has passed. */\n    function ring(r: Ripple, now: number): string | null {\n      const dur = r.inward ? 640 : r.big ? 900 : 760;\n      const a = (now - r.t0) / dur;\n      if (a >= 1) return null;\n      let rad: number;\n      let amp: number;\n      if (r.inward) {\n        rad = 4 + 110 * (0.5 + 0.5 * Math.cos(Math.PI * a));\n        amp = Math.sin(Math.PI * a);\n      } else {\n        rad = 4 + (r.big ? 190 : 130) * (1 - Math.pow(1 - a, 3));\n        amp = Math.pow(1 - a, 1.5) * Math.min(1, a / 0.08);\n      }\n      const W = 9;\n      const px = (v: number) => Math.max(0, v).toFixed(1) + \"px\";\n      const at = \"circle at \" + r.x.toFixed(1) + \"px \" + r.y.toFixed(1) + \"px, \";\n      const c = \"rgba(255,255,255,\" + (crest * amp * (r.big ? 1.25 : 1)).toFixed(3) + \")\";\n      const t = \"rgba(0,0,0,\" + (trough * amp).toFixed(3) + \")\";\n      const clear = \"rgba(255,255,255,0)\";\n      // Outward, the crest leads and the trough trails inside it; inward, the reverse.\n      return r.inward\n        ? \"radial-gradient(\" + at + clear + \" \" + px(rad - W) + \", \" + c + \" \" + px(rad) + \", \" + t + \" \" + px(rad + W * 0.7) + \", \" + clear + \" \" + px(rad + W * 1.6) + \")\"\n        : \"radial-gradient(\" + at + clear + \" \" + px(rad - W * 1.6) + \", \" + t + \" \" + px(rad - W * 0.7) + \", \" + c + \" \" + px(rad) + \", \" + clear + \" \" + px(rad + W) + \")\";\n    }\n\n    function paint(now: number) {\n      shell!.style.setProperty(\"--gf-lx\", S.lx.toFixed(1) + \"px\");\n      shell!.style.setProperty(\"--gf-ly\", S.ly.toFixed(1) + \"px\");\n      shell!.style.setProperty(\"--gf-lo\", S.lo.toFixed(3));\n      const b = S.b;\n      // The bezel: a wider, brighter band inside the rim as the glass thickens.\n      bezel!.style.boxShadow =\n        \"inset 0 0 0 \" + (1 + 1.5 * b).toFixed(2) + \"px rgba(255,255,255,\" + (0.04 + 0.12 * b).toFixed(3) +\n        \"), inset 0 0 \" + (6 + 12 * b).toFixed(1) + \"px rgba(255,255,255,\" + (0.02 + 0.1 * b).toFixed(3) + \")\";\n      // The resting pane thickens with it; in Chromium its edge starts to bend.\n      const soft = \"blur(\" + (6 + 4 * b).toFixed(1) + \"px) saturate(\" + Math.round(150 + 30 * b) + \"%) brightness(1.04)\";\n      const sc = chromium && A.restLens > 0 ? Math.round(A.restLens * 0.55 * b) : 0;\n      if (sc !== S.restScale && restDispRef.current) {\n        S.restScale = sc;\n        restDispRef.current.setAttribute(\"scale\", String(sc));\n      }\n      const bf = (sc > 0 ? \"url(#\" + restId + \") \" : \"\") + soft;\n      if (bf !== S.restKey) {\n        S.restKey = bf;\n        // Prefixed first: where an engine treats the two as one property, the\n        // unprefixed value (the only one that may carry the url) must win.\n        rest!.style.setProperty(\"-webkit-backdrop-filter\", soft);\n        rest!.style.backdropFilter = bf;\n      }\n      const layers: string[] = [];\n      S.ripples = S.ripples.filter((r) => {\n        const g = ring(r, now);\n        if (g) layers.push(g);\n        return !!g;\n      });\n      const bg = layers.length ? layers.join(\", \") : \"none\";\n      if (bg !== S.rippleKey) {\n        S.rippleKey = bg;\n        rip!.style.backgroundImage = bg;\n      }\n    }\n\n    function step(now: number) {\n      S.raf = 0;\n      const dt = S.last ? Math.min(1 / 30, (now - S.last) / 1000) : 1 / 60;\n      S.last = now;\n      const w = shell!.offsetWidth;\n      const h = shell!.offsetHeight;\n      if (S.dirty) {\n        caret(w, h);\n        S.dirty = false;\n      }\n      if (!reduce.matches) {\n        for (const q of S.queue) S.ripples.push({ x: S.cx, y: S.cy, t0: now, inward: q.inward, big: q.big });\n      }\n      S.queue.length = 0;\n      if (S.ripples.length > MAX_RIPPLES) S.ripples.splice(0, S.ripples.length - MAX_RIPPLES);\n\n      let tx = S.lx;\n      let ty = S.ly;\n      let to = 0;\n      let tb = 0;\n      if (A.focused) {\n        // Typing: the light rides with the caret.\n        tx = S.cx;\n        ty = S.cy;\n        to = 0.7;\n        tb = 1;\n      } else if (S.has) {\n        // At rest: the rim notices the pointer from NOTICE px away. Layout\n        // pixels, even inside a transform-scaled container.\n        const r = shell!.getBoundingClientRect();\n        const k = w / (r.width || 1);\n        const x = (S.px - r.left) * k;\n        const y = (S.py - r.top) * k;\n        const rr = multiline ? Math.min(24, w / 2, h / 2) : h / 2;\n        const q = 1 - ease(Math.max(0, boxDist(x - w / 2, y - h / 2, w / 2, h / 2, rr)) / NOTICE);\n        tx = Math.min(w, Math.max(0, x));\n        ty = Math.min(h, Math.max(0, y));\n        to = q;\n        tb = q;\n      }\n      // A light that is out starts where it is needed instead of streaking there.\n      if (S.lo < 0.02) {\n        S.lx = tx;\n        S.ly = ty;\n      }\n      const still = reduce.matches;\n      S.lx += (tx - S.lx) * (still ? 1 : 1 - Math.exp(-dt / 0.18));\n      S.ly += (ty - S.ly) * (still ? 1 : 1 - Math.exp(-dt / 0.18));\n      S.lo += (to - S.lo) * (still ? 1 : 1 - Math.exp(-dt / 0.22));\n      S.b += (tb - S.b) * (still ? 1 : 1 - Math.exp(-dt / 0.26));\n      paint(now);\n      const busy =\n        Math.abs(tx - S.lx) > 0.3 || Math.abs(ty - S.ly) > 0.3 || Math.abs(to - S.lo) > 0.004 ||\n        Math.abs(tb - S.b) > 0.004 || S.ripples.length > 0;\n      if (busy && S.visible) S.raf = requestAnimationFrame(step);\n      else S.last = 0;\n    }\n\n    const kick = () => {\n      if (!S.raf) S.raf = requestAnimationFrame(step);\n    };\n    A.kick = kick;\n    A.caret = () => {\n      S.dirty = true;\n      kick();\n    };\n\n    function onPointer(e: PointerEvent) {\n      S.px = e.clientX;\n      S.py = e.clientY;\n      S.has = true;\n      if (S.visible) kick();\n    }\n    // The pointer left the page, or a finger lifted: nothing is hovering.\n    function onGone(e: PointerEvent) {\n      if (e.type === \"pointerout\" ? !e.relatedTarget : e.pointerType === \"touch\") {\n        S.has = false;\n        kick();\n      }\n    }\n    function onScroll() {\n      if (S.visible && (S.has || S.lo > 0.005)) kick();\n    }\n    function onInput(e: Event) {\n      const ie = e as InputEvent;\n      const kind = ie.inputType || \"\";\n      if (ie.isComposing || kind === \"insertCompositionText\") return;\n      S.queue.push({ inward: kind.indexOf(\"delete\") === 0, big: kind === \"insertFromPaste\" || kind === \"insertFromDrop\" });\n      S.dirty = true;\n      kick();\n    }\n    function onComposed() {\n      S.queue.push({ inward: false, big: false });\n      S.dirty = true;\n      kick();\n    }\n    const onCaret = A.caret;\n\n    const io = new IntersectionObserver((entries) => {\n      S.visible = entries[entries.length - 1].isIntersecting;\n      if (S.visible) kick();\n    });\n    io.observe(shell);\n    document.addEventListener(\"pointermove\", onPointer, { passive: true });\n    document.addEventListener(\"pointerdown\", onPointer, { passive: true });\n    document.addEventListener(\"pointerup\", onGone);\n    document.addEventListener(\"pointercancel\", onGone);\n    window.addEventListener(\"pointerout\", onGone);\n    window.addEventListener(\"scroll\", onScroll, { capture: true, passive: true });\n    field.addEventListener(\"input\", onInput);\n    field.addEventListener(\"compositionend\", onComposed);\n    field.addEventListener(\"keyup\", onCaret);\n    field.addEventListener(\"select\", onCaret);\n    field.addEventListener(\"pointerup\", onCaret);\n    field.addEventListener(\"scroll\", onCaret);\n    paint(0);\n    return () => {\n      io.disconnect();\n      document.removeEventListener(\"pointermove\", onPointer);\n      document.removeEventListener(\"pointerdown\", onPointer);\n      document.removeEventListener(\"pointerup\", onGone);\n      document.removeEventListener(\"pointercancel\", onGone);\n      window.removeEventListener(\"pointerout\", onGone);\n      window.removeEventListener(\"scroll\", onScroll, { capture: true });\n      field.removeEventListener(\"input\", onInput);\n      field.removeEventListener(\"compositionend\", onComposed);\n      field.removeEventListener(\"keyup\", onCaret);\n      field.removeEventListener(\"select\", onCaret);\n      field.removeEventListener(\"pointerup\", onCaret);\n      field.removeEventListener(\"scroll\", onCaret);\n      if (S.raf) cancelAnimationFrame(S.raf);\n      S.raf = 0;\n      A.kick = noop;\n      A.caret = noop;\n      // Leave the glass at rest.\n      shell.style.setProperty(\"--gf-lo\", \"0\");\n      rip.style.backgroundImage = \"none\";\n      bezel.style.boxShadow = BEZEL_REST;\n      rest.style.setProperty(\"-webkit-backdrop-filter\", REST_GLASS);\n      rest.style.backdropFilter = REST_GLASS;\n    };\n  }, [multiline, type, disabled, dark, restId]);\n\n  // An error clouds the glass once: the frost thickens, holds, then clears.\n  // Only when a message arrives or changes, never on mount.\n  useEffect(() => {\n    const el = cloudRef.current;\n    const prev = lastError.current;\n    lastError.current = error;\n    if (!el || !error || error === prev || typeof el.animate !== \"function\") return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    el.style.visibility = \"visible\";\n    el.animate(\n      [\n        { opacity: 0, easing: \"cubic-bezier(0.22, 1, 0.36, 1)\" },\n        { opacity: 1, offset: 0.3 },\n        { opacity: 1, offset: 0.42, easing: \"cubic-bezier(0.4, 0, 0.2, 1)\" },\n        { opacity: 0 },\n      ],\n      { duration: 900 }\n    );\n    // Ended by a timer of the same length, not the finish event, which only\n    // fires on a rendered frame.\n    window.clearTimeout(cloudTimer.current);\n    cloudTimer.current = window.setTimeout(() => {\n      el.style.visibility = \"hidden\";\n    }, 920);\n  }, [error]);\n\n  /** Grow the deep pane from the origin, or drain it back there. */\n  function bloom(open: boolean) {\n    const el = thickRef.current;\n    const shell = shellRef.current;\n    if (!el || !shell) return;\n    const w = shell.offsetWidth;\n    const h = shell.offsetHeight;\n    const o = origin.current;\n    if (open && !o.fromPointer) {\n      // Arriving by keyboard: start where the text starts.\n      o.x = 22;\n      o.y = multiline ? 30 : h / 2;\n    }\n    o.fromPointer = false;\n    const at = \" at \" + o.x.toFixed(1) + \"px \" + o.y.toFixed(1) + \"px)\";\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    if (open) {\n      const r = Math.hypot(Math.max(o.x, w - o.x), Math.max(o.y, h - o.y)) + 2;\n      el.style.transition = \"none\";\n      el.style.clipPath = \"circle(0px\" + at;\n      // Commit the starting circle, so the transition grows from the origin.\n      el.getBoundingClientRect();\n      el.style.transition = reduce ? \"none\" : \"clip-path 440ms cubic-bezier(0.22, 1, 0.36, 1)\";\n      el.style.clipPath = \"circle(\" + r.toFixed(1) + \"px\" + at;\n    } else {\n      el.style.transition = reduce ? \"none\" : \"clip-path 340ms cubic-bezier(0.4, 0, 1, 1)\";\n      el.style.clipPath = \"circle(0px\" + at;\n    }\n  }\n\n  function onPointerDown(e: ReactPointerEvent<HTMLDivElement>) {\n    const shell = shellRef.current;\n    if (!shell || disabled) return;\n    // Layout pixels, even inside a transform-scaled container.\n    const r = shell.getBoundingClientRect();\n    const k = shell.offsetWidth / (r.width || 1);\n    origin.current = { x: (e.clientX - r.left) * k, y: (e.clientY - r.top) * k, fromPointer: true };\n  }\n\n  function handleChange(e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) {\n    if (value === undefined) setTyped(e.target.value !== \"\");\n    onChange?.(e.target.value);\n  }\n\n  const rgb = error ? \"255,69,58\" : rgbOf(tint);\n  const restFill = rgb ? \"rgba(\" + rgb + \",0.08)\" : dark ? \"rgba(18,18,24,0.22)\" : \"rgba(255,255,255,0.3)\";\n  const thickFill = rgb ? \"rgba(\" + rgb + \",0.14)\" : dark ? \"rgba(18,18,24,0.26)\" : \"rgba(255,255,255,0.5)\";\n  const cloudFilter = \"blur(26px) saturate(125%) brightness(\" + (dark ? 1.14 : 1.06) + \")\";\n  const ink = dark ? \"#ffffff\" : \"#111111\";\n  const ringMask = \"linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0)\";\n  // The error replaces the hint on screen, so it replaces it here too.\n  const describedBy = error ? fieldId + \"-error\" : hint ? fieldId + \"-hint\" : undefined;\n\n  const fieldCls =\n    \"relative z-10 block w-full resize-none bg-transparent px-5 text-[16px] leading-6 outline-none \" +\n    \"placeholder:opacity-0 focus:placeholder:opacity-45 disabled:cursor-not-allowed \" +\n    \"[&:-webkit-autofill]:[-webkit-text-fill-color:currentColor] [&:-webkit-autofill]:[transition:background-color_600000s_0s] \" +\n    (multiline ? \"pb-3 pt-7\" : \"h-[58px] pb-2 pt-[22px]\");\n  const common = {\n    id: fieldId,\n    name,\n    value,\n    defaultValue,\n    placeholder,\n    required,\n    disabled,\n    autoComplete,\n    \"aria-invalid\": error ? true : undefined,\n    \"aria-describedby\": describedBy,\n    onChange: handleChange,\n    onFocus: () => {\n      setFocused(true);\n      bloom(true);\n      api.current.focused = true;\n      api.current.caret();\n    },\n    onBlur: () => {\n      setFocused(false);\n      bloom(false);\n      api.current.focused = false;\n      api.current.kick();\n    },\n    className: fieldCls,\n    style: { color: ink },\n  };\n\n  return (\n    <div className={\"w-full \" + className} style={{ opacity: disabled ? 0.5 : 1 }}>\n      <div ref={shellRef} className=\"relative isolate\" style={{ borderRadius: radius }} onPointerDown={onPointerDown}>\n        {/* Thin, nearly clear glass at rest. It thickens as the pointer nears. */}\n        <span\n          ref={restRef}\n          aria-hidden\n          className=\"pointer-events-none absolute inset-0\"\n          style={{\n            borderRadius: radius,\n            background: restFill,\n            backdropFilter: REST_GLASS,\n            WebkitBackdropFilter: REST_GLASS,\n          }}\n        />\n        {/* The deep pane: it blooms from the focus origin (clip-path). */}\n        <span\n          ref={thickRef}\n          aria-hidden\n          className=\"pointer-events-none absolute inset-0\"\n          style={{\n            borderRadius: radius,\n            background: thickFill,\n            backdropFilter: thickBase,\n            WebkitBackdropFilter: thickBase,\n            clipPath: \"circle(0px at 22px 50%)\",\n          }}\n        />\n        {/* Frost for the error's clouding. Hidden until it plays. */}\n        <span\n          ref={cloudRef}\n          aria-hidden\n          className=\"pointer-events-none absolute inset-0\"\n          style={{\n            borderRadius: radius,\n            opacity: 0,\n            visibility: \"hidden\",\n            background:\n              \"radial-gradient(120% 160% at 50% 50%, rgba(255,255,255,\" + (dark ? 0.16 : 0.34) + \"), rgba(255,255,255,\" +\n              (dark ? 0.06 : 0.16) + \") 70%), rgba(255,69,58,\" + (dark ? 0.12 : 0.08) + \")\",\n            backdropFilter: cloudFilter,\n            WebkitBackdropFilter: cloudFilter,\n          }}\n        />\n        {/* The bezel band inside the rim (thickened by the loop). */}\n        <span\n          ref={bezelRef}\n          aria-hidden\n          className=\"pointer-events-none absolute inset-0\"\n          style={{\n            borderRadius: radius,\n            boxShadow: BEZEL_REST,\n          }}\n        />\n        {/* Keystroke ripples, drawn behind the text. */}\n        <span ref={rippleRef} aria-hidden className=\"pointer-events-none absolute inset-0\" style={{ borderRadius: radius }} />\n        {/* A soft specular in the face, under the light. */}\n        <span\n          aria-hidden\n          className=\"pointer-events-none absolute inset-0\"\n          style={{\n            borderRadius: radius,\n            opacity: \"calc(var(--gf-lo, 0) * 0.8)\",\n            background:\n              \"radial-gradient(220px circle at var(--gf-lx, -999px) var(--gf-ly, -999px), rgba(255,255,255,\" +\n              (dark ? 0.1 : 0.28) + \"), rgba(255,255,255,0) 65%)\",\n            mixBlendMode: dark ? \"screen\" : \"normal\",\n          }}\n        />\n        {/* Rim: graduated at rest, brighter and closed all round while focused. */}\n        <span\n          aria-hidden\n          className=\"pointer-events-none absolute inset-0 transition-shadow duration-[240ms]\"\n          style={{\n            borderRadius: radius,\n            boxShadow: focused\n              ? \"inset 0 1px 0 rgba(255,255,255,0.9), inset 0 -1px 0 rgba(255,255,255,0.32), inset 0 0 0 1.5px rgba(255,255,255,\" +\n                (dark ? 0.55 : 0.85) + \"), 0 12px 40px rgba(0,0,0,\" + (dark ? 0.28 : 0.12) + \")\"\n              : \"inset 0 1px 0 rgba(255,255,255,\" + (dark ? 0.45 : 0.8) + \"), inset 0 -1px 0 rgba(255,255,255,0.14), 0 8px 28px rgba(0,0,0,\" +\n                (dark ? 0.16 : 0.08) + \")\",\n          }}\n        />\n        {/* The rim's light: the stretch nearest the pointer (or the caret) brightens. */}\n        <span\n          aria-hidden\n          className=\"pointer-events-none absolute inset-0\"\n          style={{\n            borderRadius: radius,\n            padding: 1.5,\n            opacity: \"var(--gf-lo, 0)\",\n            background:\n              \"radial-gradient(150px circle at var(--gf-lx, -999px) var(--gf-ly, -999px), rgba(255,255,255,0.95), rgba(255,255,255,0) 70%)\",\n            WebkitMask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n            WebkitMaskComposite: \"xor\",\n            mask: ringMask,\n          }}\n        />\n        <label\n          htmlFor={fieldId}\n          className=\"pointer-events-none absolute left-5 z-20 origin-left font-semibold tracking-[-0.01em] transition-[transform,opacity] duration-[240ms] ease-[cubic-bezier(0.22,1,0.36,1)]\"\n          style={{\n            top: multiline ? 17 : 19,\n            fontSize: 15,\n            lineHeight: \"20px\",\n            color: ink,\n            opacity: floated ? 0.72 : 0.62,\n            transform: floated ? \"translateY(-10px) scale(0.76)\" : \"none\",\n          }}\n        >\n          {label}\n          {required && <span aria-hidden> *</span>}\n        </label>\n        {multiline ? <textarea rows={rows} {...common} /> : <input type={type} {...common} />}\n        {/* A hidden copy of the text before the caret, to find the caret. */}\n        <div\n          ref={mirrorRef}\n          aria-hidden\n          className={\n            \"pointer-events-none invisible absolute left-0 top-0 px-5 text-[16px] leading-6 \" + (multiline ? \"w-full pb-3 pt-7\" : \"pt-[22px]\")\n          }\n          style={{ whiteSpace: multiline ? \"pre-wrap\" : \"pre\", overflowWrap: multiline ? \"break-word\" : \"normal\" }}\n        />\n        <svg aria-hidden width=\"0\" height=\"0\" style={{ position: \"absolute\" }}>\n          <filter id={filterId} x=\"0\" y=\"0\" width=\"100%\" height=\"100%\" colorInterpolationFilters=\"sRGB\">\n            <feImage ref={mapRef} x=\"0\" y=\"0\" preserveAspectRatio=\"none\" result=\"map\" />\n            <feDisplacementMap ref={dispRef} in=\"SourceGraphic\" in2=\"map\" scale=\"0\" xChannelSelector=\"R\" yChannelSelector=\"G\" />\n          </filter>\n          <filter id={restId} x=\"0\" y=\"0\" width=\"100%\" height=\"100%\" colorInterpolationFilters=\"sRGB\">\n            <feImage ref={restMapRef} x=\"0\" y=\"0\" preserveAspectRatio=\"none\" result=\"map\" />\n            <feDisplacementMap ref={restDispRef} in=\"SourceGraphic\" in2=\"map\" scale=\"0\" xChannelSelector=\"R\" yChannelSelector=\"G\" />\n          </filter>\n        </svg>\n      </div>\n      <div aria-live=\"polite\">\n        {error ? (\n          <p id={fieldId + \"-error\"} className=\"mt-2 flex items-center gap-1.5 px-5 text-[13px] font-semibold\" style={{ color: dark ? \"#ffd2cf\" : \"#b3261e\" }}>\n            <svg aria-hidden viewBox=\"0 0 16 16\" className=\"h-3.5 w-3.5 shrink-0\" fill=\"currentColor\">\n              <path d=\"M8 1.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13Zm-.75 3.5h1.5v4.5h-1.5V5Zm0 5.5h1.5V12h-1.5v-1.5Z\" />\n            </svg>\n            {error}\n          </p>\n        ) : null}\n      </div>\n      {hint && !error && (\n        <p id={fieldId + \"-hint\"} className=\"mt-2 px-5 text-[13px]\" style={{ color: ink, opacity: 0.6 }}>\n          {hint}\n        </p>\n      )}\n    </div>\n  );\n}\n","type":"registry:component","target":"components/viberdy/glass-focus-field.tsx"}],"meta":{"tier":"free","tags":["input","form","text field","focus","glass","floating label","validation"],"href":"https://viberdy.dev/library/glass-focus-field","aiPrompt":"Create a React + Tailwind client component, GlassField: a liquid-glass text field that reacts before, during and after typing. Before focus its rim notices the pointer; focus thickens the glass outward from the point you clicked instead of drawing a ring; each keystroke sends a ripple through the glass from the caret; an error clouds the glass once instead of shaking.\n\nProps: label (required), name, id, type (\"text\" | \"email\" | \"password\" | \"search\" | \"tel\" | \"url\"), value / defaultValue / onChange(value: string), placeholder (visible only once the label has floated), multiline + rows (textarea), hint, error (a message marks the field invalid), required, disabled, autoComplete, tone (\"dark\" | \"light\"), tint (\"#rrggbb\", regex-validated, at 14%), refraction (0–2), className. The id defaults to one from useId.\n\nStructure: a relative, isolated shell (full pill for single-line; 24px radius when multiline) that records the pointer position on pointerdown, in layout pixels (rect-to-offsetWidth ratio, so it works inside a transform-scaled container). Inside it, as SIBLINGS, never nested, so each blurs the page and not another pane:\n1. The rest pane: fill rgba(18,18,24,0.22) dark / rgba(255,255,255,0.3) light (or the tint at 8%), backdrop-filter blur(6px) saturate(150%) brightness(1.04).\n2. The deep pane: fill rgba(18,18,24,0.26) / rgba(255,255,255,0.5) (or the tint at 14%), backdrop-filter blur(18px) saturate(200%) brightness(1.1) (1.05 light), starting at clip-path circle(0px). On focus, centre the circle on the recorded pointer point (keyboard focus: x 22px at mid-height, 30px down when multiline), commit it with transition none and a forced layout read, then transition clip-path over 440ms cubic-bezier(0.22,1,0.36,1) to a radius reaching the farthest corner. On blur, shrink it to 0 at the same point over 340ms ease-in. No transition under prefers-reduced-motion.\n3. A cloud pane for errors: hidden (visibility hidden, opacity 0), backdrop-filter blur(26px) saturate(125%) brightness(1.14) (1.06 light), a milky radial fill (white 0.16 → 0.06 dark, 0.34 → 0.16 light) over rgba(255,69,58,0.12).\n4. A bezel band: box-shadow inset 0 0 0 (1 + 1.5b)px white (0.04 + 0.12b) and inset 0 0 (6 + 12b)px white (0.02 + 0.1b), where b is the thickness from the loop.\n5. A ripple layer (background-image set by the loop), then a soft face specular (radial 220px at --gf-lx/--gf-ly, white 0.1 dark screen-blended / 0.28 light, opacity 0.8 × --gf-lo).\n6. The rim: at rest inset 0 1px 0 white 0.45 (0.8 light), inset 0 −1px 0 white 0.14, 0 8px 28px black 0.16; while focused inset top 0.9, inset bottom 0.32, an inset 1.5px ring at white 0.55 (0.85 light) as the visible focus indicator, and 0 12px 40px black 0.28; box-shadow transition 240ms.\n7. The rim light: a 1.5px ring (mask-composite exclude) filled with radial-gradient(150px circle at var(--gf-lx) var(--gf-ly), white 0.95 → transparent 70%), opacity var(--gf-lo).\n8. A floating label (15px, 600, pointer-events none), floated to translateY(−10px) scale(0.76) on focus or value, over 240ms; a required field shows an aria-hidden asterisk.\n9. The input or textarea: transparent, 16px/24px text, 20px side padding, 22px top and 8px bottom on a 58px single line (28 and 12 when multiline), no outline, placeholder transparent until focus, autofill paint neutralised.\n10. An aria-hidden, visibility-hidden mirror div at the same position with the same padding and type (white-space pre, or pre-wrap + break-word at full width when multiline).\n\nThe reaction loop (one effect, plain functions, one requestAnimationFrame loop that sleeps when nothing moves and while an IntersectionObserver says the field is off screen; skipped when disabled):\n- Proximity: document pointermove/pointerdown store the pointer; each frame convert it to layout pixels with the shell's rect and offsetWidth, take the signed distance to the rounded box, q = 1 − smoothstep(distance / 140). Unfocused, the light targets the pointer clamped to the box with opacity q, and the bezel thickness b targets q. Ease the position over 180ms, the opacity over 220ms, b over 260ms; a light that is out jumps to its target. A finger lifting (pointerup/cancel with pointerType touch) or the pointer leaving the window (pointerout with no relatedTarget) clears the pointer; any scroll (capture, passive) re-measures.\n- The rest pane thickens with b: blur(6 + 4b px) saturate(150 + 30b %). In Chromium, while b > 0, prepend url(#rest) to its backdrop-filter, a second displacement filter sharing the deep pane's map at scale round(0.55 × b × full scale). Write -webkit-backdrop-filter (never with url) BEFORE backdrop-filter, so the url version wins where an engine aliases them.\n- Caret: measure it in layout pixels by filling the mirror with the value up to selectionStart (bullets for passwords; fall back to the end for email inputs, in a try/catch), appending a zero-width span, reading its offsetLeft (minus the field's scrollLeft) and offsetTop + 12 (minus scrollTop), then emptying the mirror at once so a long value never widens the page. Re-measure on input, compositionend, keyup, select, pointerup, the field's scroll and focus.\n- Focused: the light rides with the caret at opacity 0.7 and b = 1.\n- Ripples: a native input listener (not React's onBeforeInput) queues one per change, skipping composition updates (one on compositionend instead): inputType starting with \"delete\" ripples inward, insertFromPaste/Drop is a bigger ripple. Each ripple is a radial-gradient ring at the caret with a crest of white (0.2 dark, 0.5 light) and a faint dark trough (0.1 / 0.06) 9px wide: outward the radius grows 4 → 134px (194 for paste) over 760ms (900) with ease-out cubic, amplitude (1 − a)^1.5 with an 8% fade-in, crest leading; inward it shrinks from 114px to 4 over 640ms with a cosine ease and a sin(πa) envelope, crest leading inward. At most 4 at once, drawn behind the text. None under reduced motion.\n\nError: tint both panes with rgb(255,69,58) and set aria-invalid; aria-describedby points at the error, otherwise at the hint; below the field an aria-live polite region shows the error (13px, 600, with an inline icon) or the hint (13px, 60% opacity). When error arrives or changes (compare with the previous value kept in a ref, so a mount with an error does not animate), make the cloud pane visible and animate its opacity 0 → 1 (30%) → hold (42%) → 0 over 900ms with the Web Animations API, then hide it with a 920ms timer (not the finish event). Skip under reduced motion. disabled dims the whole field to 50% and switches the reactions off.\n\nRefraction (Chromium only, detected with navigator.userAgentData brands containing \"Chromium\", never with @supports): an SVG filter (feImage + feDisplacementMap, R = x, G = y, sRGB) whose canvas map is sized to the shell (rounded-rect signed distance, offset along the inward normal by (1 − t/bezel)², encoded 128 + 127·d), regenerated on resize. bezel = min(14 × max(1, refraction), 0.3 × height); scale = round(0.8 × bezel × min(1, refraction)), so refraction up to 1 strengthens the bend and above 1 widens the bent band while the peak offset never passes 0.4 of the bezel. Prepend url(#id) to the deep pane's backdrop-filter.\n\nOutput one self-contained \"use client\" TSX file with no dependencies beyond React. Keep React state to focus and filled; everything that moves is written imperatively from the loop. Build strings with + rather than template literals.","license":"https://viberdy.dev/license"}}