{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"cursor-lens-magnifier","type":"registry:component","title":"Cursor Lens Magnifier","description":"A glass lens that springs after the pointer and magnifies a live copy of the content beneath it, with a refraction rim, chromatic edge and soft shadow. Press and hold on touch, arrow keys on a keyboard. No dependencies.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/cursor-lens-magnifier.tsx","content":"\"use client\";\n\nimport { useEffect, useId, useRef, useState, type CSSProperties, type ReactNode } from \"react\";\n\nexport type CursorLensMagnifierProps = {\n  children: ReactNode;\n  /** Magnification, 1 to 8. */\n  zoom?: number;\n  /** Lens diameter in px. */\n  size?: number;\n  /** Invert everything inside the glass, so the lens reads as a filter. */\n  invert?: boolean;\n  /** Fill behind the magnified copy. Default: read from the nearest opaque ancestor. */\n  background?: string;\n  /** [x, y] as 0-1 fractions: park an idling lens here until the pointer takes over. */\n  rest?: readonly [number, number];\n  /** Let the mouse wheel change the magnification while the lens is out. */\n  wheelZoom?: boolean;\n  /** Show the small magnification readout under the lens (default off). */\n  showZoom?: boolean;\n  /** Make the region focusable (default off): arrows move the lens, + and - zoom, Escape hides. */\n  keyboard?: boolean;\n  /** Accessible name of the magnifiable region (when keyboard is on). */\n  label?: string;\n  className?: string;\n  style?: CSSProperties;\n};\n\ntype Sim = {\n  x: number; y: number; vx: number; vy: number;\n  s: number; vs: number;\n  z: number; vz: number;\n  tx: number; ty: number; zt: number;\n  active: boolean;\n  src: \"pointer\" | \"touch\" | \"key\" | \"rest\";\n  touchOn: boolean;\n  reduced: boolean;\n  copyOn: boolean;\n  kx: number; ky: number; hasK: boolean;\n  ox: number; oy: number;\n};\n\nconst MIN_ZOOM = 1;\nconst MAX_ZOOM = 8;\nconst HOLD_MS = 380;\nconst clamp = (v: number, a: number, b: number) => Math.min(b, Math.max(a, v));\nconst OPAQUE = /^rgba?\\(\\s*\\d+[\\s,]+\\d+[\\s,]+\\d+\\s*(?:[,/]\\s*(?:1|0?\\.[1-9]\\d*|[1-9]\\d*%)\\s*)?\\)$/i;\nconst DRAFT = \"rgba(0, 0, 0, 0)\";\n\nfunction findBackground(el: HTMLElement | null): string {\n  let n: HTMLElement | null = el;\n  while (n) {\n    const c = getComputedStyle(n).backgroundColor;\n    if (c && c !== DRAFT && c !== \"transparent\" && OPAQUE.test(c)) return c;\n    n = n.parentElement;\n  }\n  return \"#ffffff\";\n}\n\nexport function CursorLensMagnifier({\n  children,\n  zoom = 2,\n  size = 104,\n  invert = false,\n  background,\n  rest,\n  wheelZoom = false,\n  showZoom = false,\n  keyboard = false,\n  label = \"Magnifiable content\",\n  className,\n  style,\n}: CursorLensMagnifierProps) {\n  const rootRef = useRef<HTMLDivElement>(null);\n  const groupRef = useRef<HTMLDivElement>(null);\n  const lensRef = useRef<HTMLDivElement>(null);\n  const innerRef = useRef<HTMLDivElement>(null);\n  const badgeRef = useRef<HTMLSpanElement>(null);\n  const wakeRef = useRef<() => void>(() => {});\n  const holdRef = useRef(0);\n  const sim = useRef<Sim>({\n    x: 0, y: 0, vx: 0, vy: 0, s: 0, vs: 0,\n    z: clamp(zoom, MIN_ZOOM, MAX_ZOOM), vz: 0,\n    tx: 0, ty: 0, zt: clamp(zoom, MIN_ZOOM, MAX_ZOOM),\n    active: false, src: \"pointer\", touchOn: false, reduced: false, copyOn: false,\n    kx: 0, ky: 0, hasK: false, ox: 0, oy: 0,\n  });\n  const cfg = useRef({ size, rest, background, wheelZoom });\n  const [mounted, setMounted] = useState(false);\n  const showCopy = mounted || !!rest;\n  const uid = useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const descId = \"clm\" + uid;\n  const restKey = rest ? rest[0] + \",\" + rest[1] : \"\";\n\n  useEffect(() => {\n    cfg.current = { size, rest, background, wheelZoom };\n  });\n\n  useEffect(() => {\n    sim.current.zt = clamp(zoom, MIN_ZOOM, MAX_ZOOM);\n    wakeRef.current();\n  }, [zoom]);\n\n  useEffect(() => {\n    groupRef.current?.toggleAttribute(\"inert\", true);\n  }, [showCopy]);\n\n  /* One loop, DOM writes only: springs for position, presence and zoom. */\n  useEffect(() => {\n    const root = rootRef.current;\n    if (!root) return;\n    const S = sim.current;\n    let raf = 0;\n    let last = 0;\n    let running = false;\n    let visible = true;\n    let clock = 0;\n    let badgeText = \"\";\n    let boxW = 0;\n    let boxH = 0;\n    let lastGroup: HTMLDivElement | null = null;\n\n    const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    const onMq = () => { S.reduced = mq.matches; wake(); };\n    S.reduced = mq.matches;\n    mq.addEventListener(\"change\", onMq);\n\n    const frame = (ts: number) => {\n      raf = 0;\n      const dt = Math.min(0.05, Math.max(0.001, (ts - last) / 1000));\n      last = ts;\n      const w = root.offsetWidth;\n      const h = root.offsetHeight;\n      const r = cfg.current.rest;\n      const sz = cfg.current.size;\n      let drifting = false;\n      if (S.active && S.src === \"rest\" && r) {\n        clock += dt;\n        const amp = S.reduced ? 0 : 0.045;\n        S.tx = clamp((r[0] + Math.sin(clock * 0.7) * amp) * w, 0, w);\n        S.ty = clamp((r[1] + Math.cos(clock * 0.53) * amp * 0.8) * h, 0, h);\n        drifting = !S.reduced;\n      }\n      const st = S.active ? 1 : 0;\n      if (S.reduced) {\n        S.x = S.tx; S.y = S.ty; S.s = st; S.z = S.zt;\n        S.vx = S.vy = S.vs = S.vz = 0;\n      } else {\n        const n = Math.max(1, Math.ceil(dt / (1 / 120)));\n        const hh = dt / n;\n        const cs = S.active ? 21 : 30;\n        for (let i = 0; i < n; i++) {\n          S.vx += (380 * (S.tx - S.x) - 34 * S.vx) * hh; S.x += S.vx * hh;\n          S.vy += (380 * (S.ty - S.y) - 34 * S.vy) * hh; S.y += S.vy * hh;\n          S.vs += (240 * (st - S.s) - cs * S.vs) * hh; S.s += S.vs * hh;\n          S.vz += (200 * (S.zt - S.z) - 24 * S.vz) * hh; S.z += S.vz * hh;\n        }\n      }\n      const group = groupRef.current;\n      const inner = innerRef.current;\n      let ready = false;\n      if (group && inner) {\n        ready = true;\n        if (group !== lastGroup) { lastGroup = group; boxW = 0; boxH = 0; badgeText = \"\"; }\n        const sc = Math.max(0, S.s);\n        const z = Math.max(1, S.z);\n        group.style.visibility = sc > 0.01 ? \"visible\" : \"hidden\";\n        group.style.opacity = String(Math.min(1, sc * 1.6));\n        group.style.transform = \"translate3d(\" + (S.x - sz / 2).toFixed(2) + \"px,\" + (S.y - sz / 2).toFixed(2) + \"px,0) scale(\" + sc.toFixed(4) + \")\";\n        if (w !== boxW || h !== boxH) {\n          boxW = w; boxH = h;\n          inner.style.width = w + \"px\";\n          inner.style.height = h + \"px\";\n        }\n        inner.style.transform = \"translate3d(\" + (sz / 2 - S.x * z).toFixed(2) + \"px,\" + (sz / 2 - S.y * z).toFixed(2) + \"px,0) scale(\" + z.toFixed(4) + \")\";\n        group.style.setProperty(\"--clm-dx\", (clamp(S.x / (w || 1) - 0.5, -0.5, 0.5) * 6).toFixed(2) + \"%\");\n        group.style.setProperty(\"--clm-dy\", (clamp(S.y / (h || 1) - 0.5, -0.5, 0.5) * 6).toFixed(2) + \"%\");\n        const bt = z.toFixed(1) + \"×\";\n        if (badgeRef.current && bt !== badgeText) { badgeText = bt; badgeRef.current.textContent = bt; }\n      }\n      const rest0 =\n        Math.abs(S.x - S.tx) < 0.05 && Math.abs(S.y - S.ty) < 0.05 && Math.abs(S.s - st) < 0.002 &&\n        Math.abs(S.z - S.zt) < 0.002 && Math.abs(S.vx) + Math.abs(S.vy) + Math.abs(S.vs) + Math.abs(S.vz) < 0.01;\n      if (!S.active && rest0 && ready && S.copyOn) { S.copyOn = false; setMounted(false); }\n      if ((!rest0 || drifting || (!ready && (S.active || S.copyOn))) && visible && !document.hidden) {\n        raf = requestAnimationFrame(frame);\n      } else running = false;\n    };\n    function wake() {\n      if (running && raf) return;\n      if (!visible || document.hidden) return;\n      running = true;\n      last = performance.now();\n      raf = requestAnimationFrame(frame);\n    }\n    wakeRef.current = wake;\n\n    const io = new IntersectionObserver(([e]) => { visible = !!e?.isIntersecting; if (visible) wake(); }, { rootMargin: \"200px\" });\n    io.observe(root);\n    const onVis = () => { if (!document.hidden) wake(); };\n    document.addEventListener(\"visibilitychange\", onVis);\n\n    const onTouchMove = (e: TouchEvent) => { if (S.touchOn && e.cancelable) e.preventDefault(); };\n    const onWheel = (e: WheelEvent) => {\n      if (!cfg.current.wheelZoom || !S.active || S.src !== \"pointer\") return;\n      e.preventDefault();\n      S.zt = clamp(S.zt - e.deltaY * 0.004, MIN_ZOOM, MAX_ZOOM);\n      wake();\n    };\n    root.addEventListener(\"touchmove\", onTouchMove, { passive: false });\n    root.addEventListener(\"wheel\", onWheel, { passive: false });\n\n    return () => {\n      cancelAnimationFrame(raf);\n      running = false;\n      mq.removeEventListener(\"change\", onMq);\n      io.disconnect();\n      document.removeEventListener(\"visibilitychange\", onVis);\n      root.removeEventListener(\"touchmove\", onTouchMove);\n      root.removeEventListener(\"wheel\", onWheel);\n      window.clearTimeout(holdRef.current);\n    };\n  }, []);\n\n  /* Parked lens: show it at the rest position while nobody is driving it. */\n  useEffect(() => {\n    const S = sim.current;\n    const root = rootRef.current;\n    if (!root || !restKey) return;\n    if (S.active && S.src !== \"rest\") return;\n    const [fx, fy] = restKey.split(\",\").map(Number);\n    S.active = true; S.src = \"rest\"; S.copyOn = true;\n    S.tx = (fx ?? 0.5) * root.offsetWidth; S.ty = (fy ?? 0.5) * root.offsetHeight;\n    if (S.s < 0.02) { S.x = S.tx; S.y = S.ty; }\n    if (lensRef.current) lensRef.current.style.background = cfg.current.background ?? findBackground(root);\n    wakeRef.current();\n  }, [restKey]);\n\n  function local(e: { clientX: number; clientY: number }) {\n    const el = rootRef.current;\n    if (!el) return null;\n    const r = el.getBoundingClientRect();\n    const sx = r.width ? el.offsetWidth / r.width : 1;\n    const sy = r.height ? el.offsetHeight / r.height : 1;\n    return { x: (e.clientX - r.left) * sx, y: (e.clientY - r.top) * sy, w: el.offsetWidth, h: el.offsetHeight };\n  }\n\n  function activate(src: Sim[\"src\"]) {\n    const S = sim.current;\n    const root = rootRef.current;\n    if (!root) return;\n    if (!S.active || S.src === \"rest\") {\n      if (lensRef.current) lensRef.current.style.background = cfg.current.background ?? findBackground(root);\n    }\n    if (S.s < 0.02) { S.x = S.tx; S.y = S.ty; }\n    S.active = true;\n    S.src = src;\n    S.copyOn = true;\n    setMounted(true);\n  }\n\n  function release() {\n    const S = sim.current;\n    const root = rootRef.current;\n    window.clearTimeout(holdRef.current);\n    S.touchOn = false;\n    if (root) root.style.cursor = \"\";\n    if (cfg.current.rest) {\n      S.src = \"rest\";\n      S.active = true;\n    } else S.active = false;\n    wakeRef.current();\n  }\n\n  function aim(p: { x: number; y: number; w: number; h: number }, touch: boolean) {\n    const S = sim.current;\n    const sz = cfg.current.size;\n    let ty = p.y;\n    if (touch) {\n      const lift = sz / 2 + 36;\n      ty = p.y - lift < sz * 0.3 ? p.y + lift : p.y - lift;\n    }\n    S.tx = clamp(p.x, 0, p.w);\n    S.ty = clamp(ty, 0, p.h);\n  }\n\n  function onPointerMove(e: React.PointerEvent<HTMLDivElement>) {\n    const S = sim.current;\n    const p = local(e);\n    if (!p) return;\n    if (e.pointerType === \"touch\") {\n      if (!S.touchOn) {\n        const dx = p.x - S.ox, dy = p.y - S.oy;\n        if (dx * dx + dy * dy > 100) window.clearTimeout(holdRef.current);\n        return;\n      }\n      aim(p, true);\n      wakeRef.current();\n      return;\n    }\n    aim(p, false);\n    if (!S.active || S.src !== \"pointer\") activate(\"pointer\");\n    if (rootRef.current) rootRef.current.style.cursor = \"none\";\n    wakeRef.current();\n  }\n\n  function onPointerDown(e: React.PointerEvent<HTMLDivElement>) {\n    if (e.pointerType !== \"touch\") return;\n    const p = local(e);\n    if (!p) return;\n    const S = sim.current;\n    S.ox = p.x; S.oy = p.y;\n    window.clearTimeout(holdRef.current);\n    holdRef.current = window.setTimeout(() => {\n      S.touchOn = true;\n      aim(p, true);\n      activate(\"touch\");\n      if (typeof navigator !== \"undefined\" && \"vibrate\" in navigator) navigator.vibrate(8);\n      wakeRef.current();\n    }, HOLD_MS);\n  }\n\n  function onPointerEnd(e: React.PointerEvent<HTMLDivElement>) {\n    if (e.pointerType === \"touch\" || sim.current.src === \"pointer\") release();\n  }\n\n  function onKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {\n    if (!keyboard || e.target !== e.currentTarget) return;\n    const S = sim.current;\n    const root = e.currentTarget;\n    const w = root.offsetWidth, h = root.offsetHeight;\n    if (!S.hasK) { S.kx = w / 2; S.ky = h / 2; S.hasK = true; }\n    const step = e.shiftKey ? 80 : 20;\n    let used = true;\n    if (e.key === \"ArrowLeft\") S.kx -= step;\n    else if (e.key === \"ArrowRight\") S.kx += step;\n    else if (e.key === \"ArrowUp\") S.ky -= step;\n    else if (e.key === \"ArrowDown\") S.ky += step;\n    else if (e.key === \"+\" || e.key === \"=\") S.zt = clamp(S.zt + 0.25, MIN_ZOOM, MAX_ZOOM);\n    else if (e.key === \"-\" || e.key === \"_\") S.zt = clamp(S.zt - 0.25, MIN_ZOOM, MAX_ZOOM);\n    else if (e.key === \"Escape\" && S.active && S.src === \"key\") { release(); return; }\n    else used = false;\n    if (!used) return;\n    e.preventDefault();\n    S.kx = clamp(S.kx, 0, w); S.ky = clamp(S.ky, 0, h);\n    S.tx = S.kx; S.ty = S.ky;\n    if (!S.active || S.src !== \"key\") activate(\"key\");\n    wakeRef.current();\n  }\n\n  function onFocus(e: React.FocusEvent<HTMLDivElement>) {\n    if (!keyboard || e.target !== e.currentTarget) return;\n    if (!e.currentTarget.matches(\":focus-visible\")) return;\n    const S = sim.current;\n    const root = e.currentTarget;\n    if (!S.hasK) { S.kx = root.offsetWidth / 2; S.ky = root.offsetHeight / 2; S.hasK = true; }\n    S.tx = S.kx; S.ty = S.ky;\n    activate(\"key\");\n    wakeRef.current();\n  }\n\n  function onBlur(e: React.FocusEvent<HTMLDivElement>) {\n    if (e.target === e.currentTarget && sim.current.src === \"key\") release();\n  }\n\n  const lensBg = background ?? \"#ffffff\";\n  const ring: CSSProperties = {\n    background: \"conic-gradient(from 200deg, rgba(255,255,255,0.8), rgba(255,255,255,0.14) 26%, rgba(255,255,255,0.55) 52%, rgba(255,255,255,0.1) 76%, rgba(255,255,255,0.8))\",\n    WebkitMask: \"radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px))\",\n    mask: \"radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px))\",\n  };\n\n  return (\n    <div\n      ref={rootRef}\n      onPointerMove={onPointerMove}\n      onPointerDown={onPointerDown}\n      onPointerUp={onPointerEnd}\n      onPointerCancel={onPointerEnd}\n      onPointerLeave={onPointerEnd}\n      onContextMenu={(e) => { if (sim.current.touchOn) e.preventDefault(); }}\n      onKeyDown={onKeyDown}\n      onFocus={onFocus}\n      onBlur={onBlur}\n      tabIndex={keyboard ? 0 : undefined}\n      role={keyboard ? \"group\" : undefined}\n      aria-label={keyboard ? label : undefined}\n      aria-describedby={keyboard ? descId : undefined}\n      className={\n        \"relative overflow-hidden [@media(pointer:coarse)]:select-none [@media(pointer:coarse)]:[-webkit-touch-callout:none] focus-visible:!outline-2 focus-visible:!outline-offset-2 focus-visible:!outline-[#5b9dff]\" +\n        (className ? \" \" + className : \"\")\n      }\n      style={style}\n    >\n      {children}\n\n      {keyboard && (\n        <span id={descId} className=\"sr-only\">\n          Magnifier. Arrow keys move the lens, plus and minus change the magnification, Escape hides it.\n        </span>\n      )}\n\n      {showCopy && (\n        <div\n          ref={groupRef}\n          aria-hidden=\"true\"\n          className=\"pointer-events-none absolute left-0 top-0\"\n          style={{ width: size, height: size, visibility: \"hidden\", opacity: 0, willChange: \"transform, opacity\" }}\n        >\n          <div\n            ref={lensRef}\n            className=\"absolute inset-0 overflow-hidden rounded-full\"\n            style={{\n              background: lensBg,\n              boxShadow: \"0 0 0 1px rgba(0,0,0,0.3), 0 24px 40px -14px rgba(0,0,0,0.55), 0 8px 16px -6px rgba(0,0,0,0.3)\",\n              isolation: \"isolate\",\n            }}\n          >\n            {/* A second render of the same children, scaled about the lens centre so the magnified point stays under it. */}\n            <div\n              ref={innerRef}\n              className=\"absolute left-0 top-0 origin-top-left\"\n              style={{ filter: invert ? \"invert(1)\" : undefined }}\n            >\n              {children}\n            </div>\n            <div className=\"absolute inset-0 rounded-full\" style={{ background: \"radial-gradient(circle closest-side, rgba(255,255,255,0.04) 0%, rgba(0,0,0,0) 56%, rgba(150,185,255,0.12) 86%, rgba(0,0,0,0.2) 100%)\" }} />\n            <div className=\"absolute inset-0 rounded-full\" style={{ background: \"radial-gradient(circle farthest-side at calc(50% + var(--clm-dx, 0%)) calc(50% + var(--clm-dy, 0%)), rgba(255,60,60,0) 89%, rgba(255,70,70,0.5) 97%, rgba(255,70,70,0) 100%)\" }} />\n            <div className=\"absolute inset-0 rounded-full\" style={{ background: \"radial-gradient(circle farthest-side at calc(50% - var(--clm-dx, 0%)) calc(50% - var(--clm-dy, 0%)), rgba(60,190,255,0) 89%, rgba(70,190,255,0.5) 97%, rgba(70,190,255,0) 100%)\" }} />\n            <div className=\"absolute inset-0 rounded-full\" style={{ background: \"radial-gradient(ellipse 60% 36% at 34% 14%, rgba(255,255,255,0.26), rgba(255,255,255,0) 72%), radial-gradient(ellipse 48% 26% at 68% 93%, rgba(255,255,255,0.16), rgba(255,255,255,0) 72%)\" }} />\n            <div className=\"absolute inset-0 rounded-full\" style={ring} />\n          </div>\n          {showZoom && (\n            <span\n              ref={badgeRef}\n              className=\"absolute left-1/2 whitespace-nowrap rounded-full px-2 py-0.5 text-[10px] leading-4 tabular-nums\"\n              style={{\n                top: \"calc(100% + 10px)\",\n                transform: \"translateX(-50%)\",\n                background: \"rgba(10,12,16,0.86)\",\n                color: \"#fff\",\n                fontFamily: \"ui-monospace, SFMono-Regular, Menlo, monospace\",\n                boxShadow: \"inset 0 0 0 1px rgba(255,255,255,0.16), 0 6px 14px -6px rgba(0,0,0,0.5)\",\n              }}\n            >\n            </span>\n          )}\n        </div>\n      )}\n    </div>\n  );\n}\n","type":"registry:component","target":"components/viberdy/cursor-lens-magnifier.tsx"}],"meta":{"tier":"free","tags":["cursor","lens","magnify","zoom","glass","inspect"],"href":"https://viberdy.dev/library/cursor-lens-magnifier","aiPrompt":"Create a single-file React + Tailwind component named CursorLensMagnifier (a \"use client\" file, React only, no animation library): a glass lens that follows the pointer and magnifies a live second render of its children.\n\nProps: children (ReactNode, required); zoom 2 (1-8); size 104 (lens diameter px); invert false (CSS invert(1) on the magnified layer only); background (lens fill behind the copy; default = first opaque computed background-color found walking up from the root, else white); rest ([x, y] 0-1 fractions: park an idling lens there, drifting +-4.5% of width on slow sines (0.7 and 0.53 rad/s) until the pointer takes over; release returns to it); wheelZoom false (wheel changes zoom by -deltaY*0.004 while the pointer lens is out, clamped 1-8, non-passive listener); showZoom false (mono \"2.0x\" pill under the lens); keyboard false (root tabIndex 0, role group, aria-label from `label` \"Magnifiable content\", aria-describedby an sr-only line explaining the keys); className; style.\n\nStructure: root div \"relative overflow-hidden\" (block, width from its parent, as before) > children, sr-only help, and a lens group (absolute left 0 top 0, size x size, pointer-events none, aria-hidden, inert via toggleAttribute) > a circle (rounded-full, overflow hidden, isolation isolate, background as above, shadow 0 0 0 1px rgba(0,0,0,.3), 0 24px 40px -14px rgba(0,0,0,.55), 0 8px 16px -6px rgba(0,0,0,.3)) holding [inner layer: the children again, absolute, origin top-left, width/height = root's offsetWidth/offsetHeight, transform translate3d(size/2 - x*z, size/2 - y*z, 0) scale(z) where (x, y) is the lens centre in root layout px and z the live zoom], then overlays: edge vignette radial-gradient(circle closest-side, transparent 58%, rgba(255,255,255,.07) 80%, rgba(0,0,0,.34) 100%); red fringe radial-gradient(circle farthest-side at (50% + dx, 50% + dy), transparent 89%, rgba(255,70,70,.5) 97%, transparent 100%); cyan fringe the same mirrored (50% - dx) with rgba(70,190,255,.5); specular crescent ellipse 60% 36% at 34% 14% white .4 plus a faint one at 68% 93% white .16; a conic-gradient rim (from 200deg, white .8 / .14 / .55 / .1 / .8) masked to a 2.5px ring. dx, dy = (x/w - .5) * 6% and (y/h - .5) * 6% (CSS vars --clm-dx, --clm-dy on the group). The group itself is translate3d(x - size/2, y - size/2, 0) scale(s).\n\nMotion: ONE requestAnimationFrame loop in a mount effect writing styles directly (never React state per frame). Semi-implicit Euler springs in 1/120 s substeps: position x, y k=380 c=34; presence s k=240 c=21 in (slight overshoot), c=30 out; zoom k=200 c=24. Opacity = min(1, 1.6 s), visibility hidden when s < 0.01. Snap to the target when appearing from hidden. The loop sleeps when everything is at rest, and when the root is off-screen (IntersectionObserver, rootMargin 200px) or the tab is hidden. The copy unmounts once the lens is fully hidden (unless rest is set). Pointer coordinates are mapped to layout px: (clientX - rect.left) * offsetWidth / rect.width, clamped to the root box.\n\nInput: mouse and pen show the lens on pointermove (cursor none on the root) and hide on leave. Touch: pointerdown starts a 380ms hold (cancelled if the finger moves 10px); then the lens appears, 36px + size/2 above the finger (below it if that would leave the top), follows the drag, a native non-passive touchmove listener preventDefaults while it is out, a vibrate(8) tick, contextmenu suppressed; coarse pointers get select-none and no touch-callout. Keyboard (when keyboard is on and the root itself is focused): on focus-visible the lens appears at the centre; arrows move 20px (Shift 80), + / = and - / _ change zoom by 0.25, Escape hides; keys are ignored when a child has focus. Focus ring: focus-visible:!outline-2 !outline-offset-2 !outline-[#5b9dff].\n\nprefers-reduced-motion (matchMedia, live): no springs, no scale, no drift: the lens snaps to the pointer and fades. Duplicate ids inside children are the user's to avoid (document it). Output one self-contained file.","license":"https://viberdy.dev/license"}}