{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"tour-line","type":"registry:component","title":"Tour line","description":"A product tour drawn with one hairline frame: it draws itself round the first thing you’re shown, then glides and reshapes itself onto each next one, the card riding along.","author":"Hairline UI","dependencies":["lucide-react"],"registryDependencies":["https://hairlineui.com/r/text-morph.json?as=dependency"],"files":[{"path":"registry/tour-line.tsx","type":"registry:component","content":"// Hairline UI · tour-line · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\nimport * as React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { X } from \"lucide-react\";\nimport { TextMorph } from \"./text-morph\";\nimport { createSpring, type Spring } from \"./ui-interaction-motion\";\n\n/* ─────────────────────────────────────────────────────────\n * TOUR LINE: a product tour drawn with one hairline frame\n *\n *   open      the frame draws itself round the first thing you're\n *             shown, the rest of the page dims a little, and the\n *             step card settles beside it\n *   next      the same frame glides and reshapes itself onto the next\n *             element on springs, corners and all, the dimmed window\n *             cut from it every frame and the card riding along\n *   close     the frame unwinds to nothing and the page comes back\n *\n * Non-blocking: the page stays usable, so people can try the thing\n * they're being shown. Esc closes, ← → step. Targets are CSS\n * selectors or elements; the frame follows them on scroll and\n * resize.\n * ───────────────────────────────────────────────────────── */\n\nexport interface TourStep {\n  /** A CSS selector, or a function returning the element. */\n  target: string | (() => Element | null);\n  title: string;\n  body?: React.ReactNode;\n}\n\nexport interface TourLineProps {\n  steps: TourStep[];\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  step?: number;\n  defaultStep?: number;\n  onStepChange?: (step: number) => void;\n  /** The thread's colour: any CSS colour. Defaults to --primary. */\n  color?: string;\n  /** The last step's button. */\n  doneLabel?: string;\n}\n\ntype Rect = { x: number; y: number; w: number; h: number; r: number };\n\nconst EASE = \"cubic-bezier(0.16,1,0.3,1)\";\nconst FOCUS = \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:ring-offset-2 focus-visible:ring-offset-popover\";\nconst PAD = 6;\nconst CARD_W = 300;\nconst GAP = 14;\n\ninterface Engine {\n  rect: Rect | null;\n  frame: number;\n  moving: boolean;\n  springs: { x: Spring; y: Spring; w: Spring; h: Spring; r: Spring } | null;\n}\n\n/** The frame's five springs, made once; a little under critical so it settles with the smallest give. */\nfunction springsFor(e: Engine, paint: () => void) {\n  if (!e.springs) {\n    const make = () => createSpring(0, { stiffness: 190, damping: 24 }, paint, 0.05);\n    e.springs = { x: make(), y: make(), w: make(), h: make(), r: make() };\n  }\n  return e.springs;\n}\n\nconst reducedQuery = \"(prefers-reduced-motion: reduce)\";\nconst subscribeReduced = (onChange: () => void) => {\n  const query = window.matchMedia(reducedQuery);\n  query.addEventListener(\"change\", onChange);\n  return () => query.removeEventListener(\"change\", onChange);\n};\nconst useReducedMotion = () =>\n  React.useSyncExternalStore(subscribeReduced, () => window.matchMedia(reducedQuery).matches, () => false);\nconst subscribeNothing = () => () => {};\nconst useMounted = () => React.useSyncExternalStore(subscribeNothing, () => true, () => false);\n\nconst inOut = (t: number) => (t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2);\n\nfunction resolve(target: TourStep[\"target\"]) {\n  if (typeof target === \"function\") return target();\n  return document.querySelector(target);\n}\n\nfunction rectOf(el: Element | null): Rect | null {\n  if (!el) return null;\n  const b = el.getBoundingClientRect();\n  const radius = parseFloat(getComputedStyle(el).borderTopLeftRadius) || 0;\n  return { x: b.left - PAD, y: b.top - PAD, w: b.width + PAD * 2, h: b.height + PAD * 2, r: Math.min(radius + PAD, (b.height + PAD * 2) / 2, 24) };\n}\n\n/** A rounded rect as one closed path, from the top-left corner's end. */\nconst outline = (r: Rect) => {\n  const k = Math.max(0, Math.min(r.r, r.w / 2, r.h / 2));\n  return `M ${r.x + k} ${r.y} H ${r.x + r.w - k} A ${k} ${k} 0 0 1 ${r.x + r.w} ${r.y + k} V ${r.y + r.h - k} A ${k} ${k} 0 0 1 ${r.x + r.w - k} ${r.y + r.h} H ${r.x + k} A ${k} ${k} 0 0 1 ${r.x} ${r.y + r.h - k} V ${r.y + k} A ${k} ${k} 0 0 1 ${r.x + k} ${r.y} Z`;\n};\n\nexport function TourLine({\n  steps,\n  open: openProp,\n  defaultOpen = false,\n  onOpenChange,\n  step: stepProp,\n  defaultStep = 0,\n  onStepChange,\n  color = \"var(--primary)\",\n  doneLabel = \"Done\",\n}: TourLineProps) {\n  const reduced = useReducedMotion();\n  const mounted = useMounted();\n  const [ownOpen, setOwnOpen] = React.useState(defaultOpen);\n  const [ownStep, setOwnStep] = React.useState(defaultStep);\n  const open = openProp ?? ownOpen;\n  const index = Math.max(0, Math.min(steps.length - 1, stepProp ?? ownStep));\n  const step = steps[index];\n  const titleId = React.useId();\n\n  const [shown, setShown] = React.useState(false); // the layer stays while the thread unwinds on close\n  const [card, setCard] = React.useState<{ x: number; y: number; above: boolean } | null>(null);\n  const threadRef = React.useRef<SVGPathElement>(null);\n  const dimRef = React.useRef<SVGPathElement>(null);\n  const svgRef = React.useRef<SVGSVGElement>(null);\n  const cardRef = React.useRef<HTMLDivElement>(null);\n  const now = React.useRef<Engine>({ rect: null, frame: 0, moving: false, springs: null });\n\n  const setOpen = (next: boolean) => {\n    if (openProp === undefined) setOwnOpen(next);\n    onOpenChange?.(next);\n  };\n  const goTo = (next: number) => {\n    if (next < 0 || next >= steps.length) return;\n    if (stepProp === undefined) setOwnStep(next);\n    onStepChange?.(next);\n  };\n\n  const place = React.useCallback((r: Rect) => {\n    const vw = window.innerWidth;\n    const vh = window.innerHeight;\n    const width = Math.min(CARD_W, vw - 24);\n    const height = cardRef.current?.offsetHeight ?? 150;\n    const above = r.y + r.h + GAP + height > vh - 12 && r.y - GAP - height > 12;\n    const x = Math.max(12, Math.min(r.x, vw - width - 12));\n    const y = above ? r.y - GAP - height : Math.min(r.y + r.h + GAP, vh - height - 12);\n    setCard((c) => (c && c.x === x && c.y === y && c.above === above ? c : { x, y, above }));\n  }, []);\n\n  // Draw the thread at rest round one rect, and the dimmed window.\n  const rest = React.useCallback((r: Rect) => {\n    const thread = threadRef.current;\n    const dim = dimRef.current;\n    const svg = svgRef.current;\n    if (svg) svg.setAttribute(\"viewBox\", `0 0 ${window.innerWidth} ${window.innerHeight}`);\n    if (thread) {\n      thread.setAttribute(\"d\", outline(r));\n      thread.style.strokeDasharray = \"none\";\n    }\n    if (dim) dim.setAttribute(\"d\", `M 0 0 H ${window.innerWidth} V ${window.innerHeight} H 0 Z ${outline(r)}`);\n  }, []);\n\n  // One frame of the glide: the frame and the dimmed window at the springs' rect; at rest it hands back to `rest`.\n  const paintFrame = React.useCallback(() => {\n    const e = now.current;\n    const sp = e.springs;\n    if (!sp) return;\n    const r = { x: sp.x.get(), y: sp.y.get(), w: Math.max(4, sp.w.get()), h: Math.max(4, sp.h.get()), r: Math.max(0, sp.r.get()) };\n    const thread = threadRef.current;\n    const dim = dimRef.current;\n    if (thread) {\n      thread.setAttribute(\"d\", outline(r));\n      thread.style.strokeDasharray = \"none\";\n    }\n    if (dim) {\n      dim.setAttribute(\"d\", `M 0 0 H ${window.innerWidth} V ${window.innerHeight} H 0 Z ${outline(r)}`);\n      dim.style.opacity = \"1\";\n    }\n    const still = [sp.x, sp.y, sp.w, sp.h, sp.r].every((s) => s.getVelocity() === 0 && s.get() === s.getTarget());\n    if (still && e.moving && e.rect) {\n      e.moving = false;\n      rest(e.rect);\n    }\n  }, [rest]);\n\n  // Open, step and close: one animation each, written straight to the SVG.\n  React.useEffect(() => {\n    if (!open) return;\n    const e = now.current;\n    const el = step ? resolve(step.target) : null;\n    if (!el) return;\n    let cancelled = false;\n    const run = () => {\n      if (cancelled) return;\n      const to = rectOf(el);\n      if (!to) return;\n      const from = e.rect;\n      setShown(true);\n      place(to);\n      cancelAnimationFrame(e.frame);\n      const thread = threadRef.current;\n      const dim = dimRef.current;\n      if (!thread || !dim || reduced) {\n        e.rect = to;\n        rest(to);\n        return;\n      }\n      svgRef.current?.setAttribute(\"viewBox\", `0 0 ${window.innerWidth} ${window.innerHeight}`);\n      if (from) {\n        // Next: the same frame glides and reshapes itself onto the new target on springs, the dimmed window with it.\n        const sp = springsFor(e, paintFrame);\n        e.moving = true;\n        sp.x.set(to.x);\n        sp.y.set(to.y);\n        sp.w.set(to.w);\n        sp.h.set(to.h);\n        sp.r.set(to.r);\n        e.rect = to;\n        return;\n      }\n      // Open: the frame draws itself round the first target while the page dims.\n      const sp = springsFor(e, paintFrame);\n      [sp.x, sp.y, sp.w, sp.h, sp.r].forEach((s, i) => s.jump([to.x, to.y, to.w, to.h, to.r][i]));\n      thread.setAttribute(\"d\", outline(to));\n      const total = thread.getTotalLength();\n      // Set the dash before the first frame paints, or the whole outline flashes for a frame.\n      thread.style.strokeDasharray = `0.01 ${total + 20}`;\n      dim.style.opacity = \"0\";\n      e.moving = true;\n      const start = performance.now();\n      const tick = (t: number) => {\n        const k = inOut(Math.min(1, (t - start) / 620));\n        thread.style.strokeDasharray = `${Math.max(0.01, total * k)} ${total + 20}`;\n        dim.style.opacity = String(k);\n        if (k < 1) e.frame = requestAnimationFrame(tick);\n        else {\n          e.moving = false;\n          e.rect = to;\n          rest(to);\n        }\n      };\n      e.frame = requestAnimationFrame(tick);\n    };\n    // Bring the target into view first, then draw.\n    const b = el.getBoundingClientRect();\n    const inView = b.top >= 0 && b.bottom <= window.innerHeight && b.left >= 0 && b.right <= window.innerWidth;\n    if (inView) run();\n    else {\n      el.scrollIntoView({ block: \"center\", inline: \"nearest\", behavior: reduced ? \"auto\" : \"smooth\" });\n      const timer = window.setTimeout(run, reduced ? 0 : 420);\n      return () => {\n        cancelled = true;\n        window.clearTimeout(timer);\n      };\n    }\n    return () => {\n      cancelled = true;\n    };\n  }, [open, step, reduced, place, rest, paintFrame]);\n\n  // Close: the thread unwinds to nothing, then the layer goes.\n  React.useEffect(() => {\n    if (open || !shown) return;\n    const e = now.current;\n    const thread = threadRef.current;\n    const dim = dimRef.current;\n    cancelAnimationFrame(e.frame);\n    if (e.springs) Object.values(e.springs).forEach((sp) => sp.stop());\n    e.moving = false;\n    if (!thread || !dim || reduced || !e.rect) {\n      e.rect = null;\n      const t = window.setTimeout(() => setShown(false), 0);\n      return () => window.clearTimeout(t);\n    }\n    const total = thread.getTotalLength();\n    const start = performance.now();\n    const tick = (t: number) => {\n      const k = inOut(Math.min(1, (t - start) / 420));\n      thread.style.strokeDasharray = `0 ${total * k} ${Math.max(0.01, total * (1 - k))} ${total + 20}`;\n      dim.style.opacity = String(1 - k);\n      if (k < 1) e.frame = requestAnimationFrame(tick);\n      else {\n        e.rect = null;\n        setShown(false);\n      }\n    };\n    e.frame = requestAnimationFrame(tick);\n    return () => cancelAnimationFrame(e.frame);\n  }, [open, shown, reduced]);\n\n  // Follow the target on scroll and resize.\n  React.useEffect(() => {\n    if (!open) return;\n    const follow = () => {\n      const e = now.current;\n      if (e.moving || !step) return;\n      const r = rectOf(resolve(step.target));\n      if (!r) return;\n      e.rect = r;\n      rest(r);\n      place(r);\n    };\n    window.addEventListener(\"scroll\", follow, { passive: true, capture: true });\n    window.addEventListener(\"resize\", follow);\n    return () => {\n      window.removeEventListener(\"scroll\", follow, { capture: true });\n      window.removeEventListener(\"resize\", follow);\n    };\n  }, [open, step, rest, place]);\n\n  // Keyboard: Esc closes, arrows step. Focus goes to the card when the tour opens.\n  React.useEffect(() => {\n    if (!open) return;\n    const key = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") setOpen(false);\n      else if (e.key === \"ArrowRight\") goTo(index + 1);\n      else if (e.key === \"ArrowLeft\") goTo(index - 1);\n    };\n    window.addEventListener(\"keydown\", key);\n    return () => window.removeEventListener(\"keydown\", key);\n  });\n  // Focus moves to the card once, when the tour opens and the card has its place.\n  const focusPending = React.useRef(false);\n  React.useEffect(() => {\n    if (open) focusPending.current = true;\n  }, [open]);\n  React.useEffect(() => {\n    if (!open || !card || !focusPending.current) return;\n    focusPending.current = false;\n    cardRef.current?.focus({ preventScroll: true });\n  }, [open, card]);\n\n  React.useEffect(() => {\n    const e = now.current;\n    return () => {\n      cancelAnimationFrame(e.frame);\n      if (e.springs) Object.values(e.springs).forEach((sp) => sp.stop());\n      e.springs = null;\n    };\n  }, []);\n\n  if (!mounted || (!open && !shown)) return null;\n  const last = index === steps.length - 1;\n  const dimFill = `color-mix(in oklab, black ${26}%, transparent)`;\n\n  return createPortal(\n    <div className=\"pointer-events-none fixed inset-0 z-[90]\">\n      <svg ref={svgRef} aria-hidden=\"true\" className=\"absolute inset-0 size-full overflow-visible\">\n        <path ref={dimRef} fillRule=\"evenodd\" style={{ fill: dimFill, opacity: 0 }} />\n        <path ref={threadRef} fill=\"none\" stroke={color} strokeWidth={1.75} strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n      </svg>\n      {step && (\n        <div\n          ref={cardRef}\n          role=\"dialog\"\n          aria-modal=\"false\"\n          aria-labelledby={titleId}\n          tabIndex={-1}\n          className=\"pointer-events-auto absolute left-0 top-0 rounded-[16px] bg-popover p-4 text-popover-foreground shadow-[0_0_0_1px_var(--border)] outline-none\"\n          style={{\n            width: `min(${CARD_W}px, calc(100vw - 24px))`,\n            transform: card ? `translate3d(${card.x}px, ${card.y}px, 0)` : \"translate3d(-9999px,0,0)\",\n            opacity: open && card ? 1 : 0,\n            transition: reduced ? \"none\" : `transform 620ms ${EASE}, opacity 260ms ${EASE}`,\n          }}\n        >\n          <div className=\"flex items-start justify-between gap-3\">\n            <p className=\"text-[11.5px] font-medium tabular-nums\" style={{ color }}>\n              <TextMorph>{`Step ${index + 1} of ${steps.length}`}</TextMorph>\n            </p>\n            <button\n              type=\"button\"\n              aria-label=\"Close tour\"\n              onClick={() => setOpen(false)}\n              className={`-m-1 flex size-6 cursor-pointer items-center justify-center rounded-full text-muted-foreground transition-colors hover:text-foreground ${FOCUS}`}\n            >\n              <X className=\"size-3.5\" />\n            </button>\n          </div>\n          <h2 id={titleId} className=\"mt-1 text-[15px] font-medium tracking-[-0.01em] text-foreground\">\n            <TextMorph>{step.title}</TextMorph>\n          </h2>\n          {step.body && (\n            <div key={index} className=\"mt-1 text-[13px] leading-[1.5] text-muted-foreground motion-safe:animate-[ui-fade-in_320ms_ease-out_80ms_backwards]\">\n              {step.body}\n            </div>\n          )}\n          <div className=\"mt-3.5 flex items-center justify-between gap-2\">\n            <div className=\"flex gap-1\" aria-hidden=\"true\">\n              {steps.map((_, i) => (\n                <span\n                  key={i}\n                  className=\"h-1 rounded-full transition-[width,background-color] duration-500\"\n                  style={{ width: i === index ? 14 : 4, background: i <= index ? color : \"color-mix(in oklab, var(--foreground) 16%, transparent)\", transitionTimingFunction: EASE }}\n                />\n              ))}\n            </div>\n            <div className=\"flex gap-1.5\">\n              {index > 0 && (\n                <button\n                  type=\"button\"\n                  onClick={() => goTo(index - 1)}\n                  className={`h-8 cursor-pointer rounded-full px-3 text-[12.5px] text-muted-foreground transition-colors hover:text-foreground ${FOCUS}`}\n                >\n                  Back\n                </button>\n              )}\n              <button\n                type=\"button\"\n                onClick={() => (last ? setOpen(false) : goTo(index + 1))}\n                className={`h-8 cursor-pointer rounded-full bg-primary px-3.5 text-[12.5px] font-medium text-primary-foreground transition-[scale] duration-200 active:scale-[0.97] ${FOCUS}`}\n              >\n                <TextMorph>{last ? doneLabel : \"Next\"}</TextMorph>\n              </button>\n            </div>\n          </div>\n        </div>\n      )}\n    </div>,\n    document.body,\n  );\n}\n"},{"path":"registry/ui-interaction-motion.ts","type":"registry:component","content":"// Hairline UI · tour-line · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n'use client';\n\nimport * as React from 'react';\n\nexport const EASE_OUT = 'cubic-bezier(0.16, 1, 0.3, 1)';\nexport const EASE_SETTLE = 'cubic-bezier(0.22, 1.18, 0.36, 1)';\n/** Thrown things (indicators, thumbs): a slight overshoot on transform only. */\nexport const EASE_THROW = 'cubic-bezier(0.34, 1.36, 0.64, 1)';\n/**\n * The press every button primitive shares: a 3% give that eases in and settles back.\n * Tailwind v4's scale-* writes the `scale` property, so `scale` has to be in the list\n * or the press snaps.\n */\nexport const INTERACTION_PRESS =\n  'transition-[background-color,color,box-shadow,opacity,scale] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] active:scale-[0.97] motion-reduce:transition-none motion-reduce:active:scale-100';\nexport const INTERACTION_FOCUS ='focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background';\n\nconst query = '(prefers-reduced-motion: reduce)';\nconst subscribe = (notify: () => void) => {\n  const media = window.matchMedia(query);\n  media.addEventListener('change', notify);\n  return () => media.removeEventListener('change', notify);\n};\nexport const useInteractionReducedMotion = () => React.useSyncExternalStore(subscribe, () => window.matchMedia(query).matches, () => false);\n\nexport function useInteractionActivity<T extends Element>() {\n  const ref = React.useRef<T>(null);\n  const [visible, setVisible] = React.useState(false);\n  const [hidden, setHidden] = React.useState(false);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const observer = new IntersectionObserver(([entry]) => setVisible(entry.isIntersecting));\n    observer.observe(el);\n    const visibility = () => setHidden(document.hidden);\n    visibility(); document.addEventListener('visibilitychange', visibility);\n    return () => { observer.disconnect(); document.removeEventListener('visibilitychange', visibility); };\n  }, []);\n  return { ref, active: visible && !hidden };\n}\n\nexport function interactionIcon(on: boolean, reduced: boolean): React.CSSProperties {\n  return { opacity: on ? 1 : 0, transform: on ? 'none' : 'scale(0.6)', filter: on ? 'blur(0px)' : 'blur(3px)', transition: reduced ? 'none' : `opacity 220ms ${EASE_OUT}, transform 380ms ${EASE_OUT}, filter 220ms ${EASE_OUT}` };\n}\n\n/** A raised object: one tight contact shadow, one short ambient, a hairline of light on its top edge. */\nexport const MATERIAL_LIFT =\n  'shadow-[0_1px_1.5px_rgb(0_0_0/0.07),0_3px_8px_-2px_rgb(0_0_0/0.1),inset_0_0.5px_0_rgb(255_255_255/0.8)] dark:shadow-[0_1px_2px_rgb(0_0_0/0.5),0_4px_10px_-2px_rgb(0_0_0/0.35),inset_0_0.5px_0_rgb(255_255_255/0.1)]';\n/** A trough something sits in, shaded from above, lit along its bottom edge. */\nexport const MATERIAL_RECESS =\n  'shadow-[inset_0_1px_2.5px_rgb(0_0_0/0.09),inset_0_-0.5px_0_rgb(255_255_255/0.7)] dark:shadow-[inset_0_1px_3px_rgb(0_0_0/0.45),inset_0_-0.5px_0_rgb(255_255_255/0.07)]';\n\nexport type SpringConfig = { stiffness: number; damping: number; mass?: number };\nexport interface Spring {\n  get(): number;\n  getVelocity(): number;\n  getTarget(): number;\n  /** Aim somewhere new from wherever it is now, keeping its speed. */\n  set(target: number): void;\n  /** Add speed (units per second), on top of what it already has. */\n  push(velocity: number): void;\n  /** Be there now, at rest. */\n  jump(value: number): void;\n  configure(config: SpringConfig): void;\n  stop(): void;\n}\n\n// Every moving spring on the page shares one frame loop, which sleeps when the last one rests. Each spring's onFrame runs\n// once per frame after all of them have stepped, so several springs that draw one shape paint it once.\nconst SPRING_STEP = 1 / 240;\ntype Running = { step: () => void };\nconst runningSprings = new Set<Running>();\nconst springPainters = new Set<() => void>();\nlet springFrame = 0;\nlet springLast = 0;\nlet springSpare = 0;\n\nfunction springTick(now: number) {\n  // A hidden tab stops the frames, so the first one back must not count the whole gap as time passed.\n  springSpare += Math.min((now - springLast) / 1000, 0.05);\n  springLast = now;\n  while (springSpare >= SPRING_STEP) {\n    runningSprings.forEach((spring) => spring.step());\n    springSpare -= SPRING_STEP;\n  }\n  const painters = [...springPainters];\n  springPainters.clear();\n  painters.forEach((paint) => paint());\n  springFrame = runningSprings.size ? requestAnimationFrame(springTick) : 0;\n}\n\nfunction wakeSprings(spring: Running) {\n  runningSprings.add(spring);\n  if (springFrame) return;\n  springSpare = 0;\n  springFrame = requestAnimationFrame((now) => {\n    springLast = now - 1000 / 60;\n    springTick(now);\n  });\n}\n\n/**\n * A spring that carries its speed: re-aim it mid-flight and it curves on from where it is, push it while it swings and the\n * push adds to the swing. Use it for anything that can be interrupted; a curve restarts from a standstill every time.\n * `onFrame` should write straight to the DOM. `precision` is how close counts as there, in the value's own units.\n */\nexport function createSpring(initial: number, config: SpringConfig, onFrame: () => void, precision = 0.01): Spring {\n  let value = initial;\n  let velocity = 0;\n  let target = initial;\n  let { stiffness, damping, mass = 1 } = config;\n  const running: Running = {\n    step() {\n      velocity += ((-stiffness * (value - target) - damping * velocity) / mass) * SPRING_STEP;\n      value += velocity * SPRING_STEP;\n      if (Math.abs(value - target) < precision && Math.abs(velocity) < precision * 10) {\n        value = target;\n        velocity = 0;\n        runningSprings.delete(running);\n      }\n      springPainters.add(onFrame);\n    },\n  };\n  return {\n    get: () => value,\n    getVelocity: () => velocity,\n    getTarget: () => target,\n    set(next) {\n      if (next === target && !runningSprings.has(running)) return;\n      target = next;\n      wakeSprings(running);\n    },\n    push(speed) {\n      velocity += speed;\n      wakeSprings(running);\n    },\n    jump(next) {\n      value = next;\n      target = next;\n      velocity = 0;\n      runningSprings.delete(running);\n      onFrame();\n    },\n    configure(next) {\n      ({ stiffness, damping, mass = 1 } = next);\n    },\n    stop() {\n      runningSprings.delete(running);\n    },\n  };\n}\n\n/** Sample recent movement rather than averaging a long drag and losing its release velocity. */\nexport type PointerSample = { x: number; time: number };\nexport function samplePointer(samples: PointerSample[], x: number, time: number) {\n  samples.push({ x, time });\n  while (samples.length > 2 && time - samples[0].time > 100) samples.shift();\n}\nexport function releaseVelocity(samples: PointerSample[], now: number) {\n  if (samples.length < 2 || now - samples[samples.length - 1].time > 100) return 0;\n  const first = samples[0], last = samples[samples.length - 1];\n  return (last.x - first.x) / Math.max(1, last.time - first.time);\n}\n\n/** Smooth Apple/rational rubber-band curve: continuous exponential-like resistance without linear kinks. */\nexport function rubberBand(overshoot: number, dimension = 320, constant = 0.55): number {\n  const d = dimension || 320;\n  const abs = Math.abs(overshoot);\n  return Math.sign(overshoot) * (1 - 1 / ((abs * constant) / d + 1)) * d;\n}\n\n/** Projects resting travel from release velocity (velocity in px/ms; time in seconds). */\nexport function projectInertia(distance: number, velocity: number, time = 0.12): number {\n  return distance + velocity * 1000 * time;\n}\n\n/** Smooths incoming release velocity toward a boundary so springs don't slam or clip into walls. */\nexport function softenVelocity(velocity: number, distanceToTarget: number, factor = 10): number {\n  const maxAllowed = Math.abs(distanceToTarget) * factor;\n  return Math.sign(velocity) * Math.min(Math.abs(velocity), maxAllowed);\n}\n\n/** A damped spring sampled by WAAPI: tuned for organic lightness with a hint of life (3% breath). */\nexport function springFrames(\n  from: number,\n  to: number,\n  velocity = 0,\n  duration = 480,\n  config: { omega?: number; damping?: number; steps?: number } = {},\n) {\n  const { omega = 16, damping = 0.74, steps = 36 } = config;\n  const damped = omega * Math.sqrt(Math.max(0.001, 1 - damping * damping));\n  const displacement = from - to;\n  const coefficient = (velocity * 1000 + damping * omega * displacement) / damped;\n  return Array.from({ length: steps + 1 }, (_, i) => {\n    const t = (i / steps) * (duration / 1000);\n    const value = to + Math.exp(-damping * omega * t) * (displacement * Math.cos(damped * t) + coefficient * Math.sin(damped * t));\n    return { value: i === steps ? to : value, offset: i / steps };\n  });\n}\n\n"}],"css":{"@keyframes ui-fade-in":{"from":{"opacity":"0"},"to":{"opacity":"1"}}},"docs":"Docs and live preview: https://hairlineui.com/ui/tour-line. MIT licensed: https://hairlineui.com/license#components","meta":{"license":"MIT"}}