{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"pillar-chart","type":"registry:component","title":"Pillar chart","description":"A period of activity as glass pillars on dark lacquer: point at one and it turns white, switch the range and the new pillars rise in a wave.","author":"Hairline UI","dependencies":["lucide-react"],"registryDependencies":["https://hairlineui.com/r/number-roll.json?as=dependency","https://hairlineui.com/r/text-morph.json?as=dependency"],"files":[{"path":"registry/pillar-chart.tsx","type":"registry:component","content":"// Hairline UI · pillar-chart · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\nimport * as React from \"react\";\nimport { ArrowDownRight, ArrowUpRight } from \"lucide-react\";\nimport { lacquer, type LacquerTone } from \"./lacquer\";\nimport { NumberRoll } from \"./number-roll\";\nimport { TextMorph } from \"./text-morph\";\nimport { EASE_OUT, EASE_THROW, useInteractionReducedMotion } from \"./ui-interaction-motion\";\n\n/* ─────────────────────────────────────────────────────────\n * PILLAR CHART: a period of activity as glass pillars\n *\n *   pillars  each day (or week, or month) is a frosted glass\n *            capsule; the one you point at turns solid white and\n *            a small marker glides above it; the line under the\n *            total says what it is\n *   range    the switch slides to the new range; the pillars on\n *            show sink away and the new ones rise in a wave from\n *            the side you moved toward, the curve over them draws\n *            itself again, and the total and the change roll\n *\n * An object with its own dark lacquer finish: the same on a light\n * page or a dark one.\n *\n * Reduced motion: no rise, sink or roll; everything changes in place.\n * ───────────────────────────────────────────────────────── */\n\nexport interface PillarBar {\n  label: string;\n  value: number;\n  /** The line under the total for this pillar; by default its label and value. */\n  detail?: string;\n}\n\nexport interface PillarRange {\n  id: string;\n  /** On the switch: W, M, Y. */\n  label: string;\n  /** Read out for the switch, \"Week\". */\n  name?: string;\n  total: number;\n  /** Percent against the previous period: 12.4 for +12.4%. */\n  change?: number;\n  bars: PillarBar[];\n  /** Which pillar is picked when the range opens; the tallest by default. */\n  focus?: number;\n}\n\nexport interface PillarChartProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\" | \"defaultValue\" | \"onChange\"> {\n  ranges: PillarRange[];\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (id: string) => void;\n  title?: string;\n  icon?: React.ReactNode;\n  /** After every figure: \" hrs\", \" km\". */\n  unit?: string;\n  format?: Intl.NumberFormatOptions;\n  locales?: string | string[];\n  /** The lacquer: a named tone or any CSS colour. */\n  tone?: LacquerTone | (string & {});\n  /** The marker and the change pill. */\n  accent?: string;\n}\n\nconst AREA = 108;\nconst subscribeNothing = () => () => {};\n/** False while hydrating: text formatted with the visitor's locale waits for it, so the server's HTML matches. */\nconst useHydrated = () => React.useSyncExternalStore(subscribeNothing, () => true, () => false);\nconst FORMAT: Intl.NumberFormatOptions = { maximumFractionDigits: 1 };\n\ntype Column = { x: number; top: number };\n\nfunction Pillars({\n  range,\n  selected,\n  onSelect,\n  enter,\n  leaving,\n  reduced,\n  accent,\n}: {\n  range: PillarRange;\n  selected: number;\n  onSelect: (i: number) => void;\n  enter: number;\n  leaving: boolean;\n  reduced: boolean;\n  accent: string;\n}) {\n  const row = React.useRef<HTMLDivElement>(null);\n  const pillars = React.useRef<(HTMLSpanElement | null)[]>([]);\n  const curve = React.useRef<SVGPathElement>(null);\n  const marker = React.useRef<HTMLSpanElement>(null);\n  const [cols, setCols] = React.useState<Column[]>([]);\n  const [size, setSize] = React.useState({ w: 0, h: 0 });\n  const max = Math.max(...range.bars.map((b) => b.value), 1);\n  const heights = range.bars.map((b) => Math.max(0.18, b.value / max) * 0.96);\n\n  // Where each pillar's middle and top sit, for the marker and the curve: measured, and again when the card resizes.\n  React.useLayoutEffect(() => {\n    const el = row.current;\n    if (!el) return;\n    const measure = () => {\n      const next = Array.from(el.children)\n        .filter((c): c is HTMLElement => c instanceof HTMLElement && c.dataset.col !== undefined)\n        .map((c, i) => ({ x: c.offsetLeft + c.offsetWidth / 2, top: c.offsetTop + c.offsetHeight - 22 - AREA * heights[i] }));\n      setCols((p) => (p.length === next.length && p.every((c, i) => c.x === next[i].x && c.top === next[i].top) ? p : next));\n      setSize((p) => (p.w === el.offsetWidth && p.h === el.offsetHeight ? p : { w: el.offsetWidth, h: el.offsetHeight }));\n    };\n    measure();\n    const ro = new ResizeObserver(measure);\n    ro.observe(el);\n    return () => ro.disconnect();\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [range]);\n\n  // The new pillars rise from the floor in a wave from the side you moved toward, and the curve draws itself.\n  React.useLayoutEffect(() => {\n    if (reduced || !enter) return;\n    const n = pillars.current.length;\n    pillars.current.forEach((el, i) => {\n      const order = enter > 0 ? i : n - 1 - i;\n      el?.animate([{ transform: \"translateY(100%)\" }, { transform: `translateY(${(1 - heights[i]) * 100}%)` }], {\n        duration: 720,\n        delay: 60 + order * 42,\n        easing: EASE_OUT,\n        fill: \"backwards\",\n      });\n    });\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, []);\n  React.useEffect(() => {\n    if (reduced || !cols.length) return;\n    curve.current?.animate([{ strokeDashoffset: 1 }, { strokeDashoffset: 0 }], { duration: 900, delay: 120, easing: EASE_OUT, fill: \"backwards\" });\n    // On a new range the marker settles in once its pillar has risen, rather than waiting in the air.\n    if (enter) marker.current?.animate([{ opacity: 0, translate: \"0 6px\" }, { opacity: 1, translate: \"0 0\" }], { duration: 320, delay: 560, easing: EASE_OUT, fill: \"backwards\" });\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [cols.length > 0]);\n\n  const path = React.useMemo(() => {\n    if (cols.length < 2) return \"\";\n    const pts = cols.map((c) => ({ x: c.x, y: c.top - 16 }));\n    let d = `M ${pts[0].x.toFixed(1)} ${pts[0].y.toFixed(1)}`;\n    for (let i = 0; i < pts.length - 1; i++) {\n      const a = pts[i];\n      const b = pts[i + 1];\n      const mx = ((a.x + b.x) / 2).toFixed(1);\n      d += ` C ${mx} ${a.y.toFixed(1)}, ${mx} ${b.y.toFixed(1)}, ${b.x.toFixed(1)} ${b.y.toFixed(1)}`;\n    }\n    return d;\n  }, [cols]);\n\n  const mark = cols[selected];\n\n  return (\n    <div\n      className=\"absolute inset-0\"\n      style={{\n        opacity: leaving ? 0 : 1,\n        transform: leaving ? \"translateY(10px)\" : \"none\",\n        filter: leaving ? \"blur(4px)\" : \"none\",\n        transition: reduced ? \"none\" : `opacity 260ms ease-out, transform 320ms ${EASE_OUT}, filter 260ms ease-out`,\n        pointerEvents: leaving ? \"none\" : undefined,\n      }}\n      aria-hidden={leaving || undefined}\n    >\n      {size.w > 0 && path && (\n        <svg aria-hidden className=\"pointer-events-none absolute inset-0 overflow-visible\" width={size.w} height={size.h} viewBox={`0 0 ${size.w} ${size.h}`}>\n          <path ref={curve} d={path} pathLength={1} strokeDasharray=\"1 1\" fill=\"none\" stroke=\"rgb(255 255 255 / 0.42)\" strokeWidth=\"1.2\" strokeLinecap=\"round\" />\n        </svg>\n      )}\n      {mark && (\n        <span\n          ref={marker}\n          aria-hidden\n          className=\"pointer-events-none absolute left-0 top-0 size-1.5 rounded-full\"\n          style={{\n            background: accent,\n            transform: `translate(${mark.x - 3}px, ${mark.top - 12}px)`,\n            transition: reduced ? \"none\" : `transform 380ms ${EASE_THROW}`,\n          }}\n        />\n      )}\n      <div ref={row} role=\"radiogroup\" aria-label=\"Pick a bar\" className=\"relative flex h-full items-end justify-between gap-2.5\">\n        {range.bars.map((bar, i) => {\n          const on = i === selected;\n          return (\n            <button\n              key={bar.label}\n              data-col=\"\"\n              type=\"button\"\n              role=\"radio\"\n              aria-checked={on}\n              tabIndex={on ? 0 : -1}\n              aria-label={bar.detail ?? bar.label}\n              onClick={() => onSelect(i)}\n              onPointerMove={(e) => e.pointerType === \"mouse\" && !on && onSelect(i)}\n              onKeyDown={(e) => {\n                const step = { ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1 }[e.key];\n                const to = step ? Math.max(0, Math.min(range.bars.length - 1, i + step)) : e.key === \"Home\" ? 0 : e.key === \"End\" ? range.bars.length - 1 : -1;\n                if (to < 0) return;\n                e.preventDefault();\n                onSelect(to);\n                (e.currentTarget.parentElement?.children[to] as HTMLElement | undefined)?.focus();\n              }}\n              className=\"group flex h-full min-w-0 flex-1 cursor-pointer flex-col items-center justify-end gap-2 rounded-xl outline-none focus-visible:ring-2 focus-visible:ring-white/60\"\n            >\n              <span className=\"relative block w-full max-w-[26px] overflow-clip rounded-full\" style={{ height: AREA }}>\n                <span\n                  ref={(el) => {\n                    pillars.current[i] = el;\n                  }}\n                  className=\"absolute inset-0 rounded-full\"\n                  style={{ transform: `translateY(${(1 - heights[i]) * 100}%)`, transition: reduced ? \"none\" : `transform 640ms ${EASE_OUT}`, willChange: \"transform\" }}\n                >\n                  <span\n                    className=\"absolute inset-0 rounded-full\"\n                    style={{\n                      background: \"linear-gradient(180deg, rgb(255 255 255 / 0.3) 0%, rgb(255 255 255 / 0.12) 62%, rgb(255 255 255 / 0.04) 100%)\",\n                      boxShadow: \"inset 0 1px 0 rgb(255 255 255 / 0.22)\",\n                    }}\n                  />\n                  <span\n                    className=\"absolute inset-0 rounded-full transition-opacity duration-200\"\n                    style={{ opacity: on ? 1 : 0, background: \"linear-gradient(180deg, #fff 0%, rgb(255 255 255 / 0.94) 78%, rgb(255 255 255 / 0.82) 100%)\" }}\n                  />\n                </span>\n              </span>\n              <span className={`text-[10.5px] font-medium transition-colors duration-150 ${on ? \"text-white\" : \"text-white/50 group-hover:text-white/80\"}`}>{bar.label}</span>\n            </button>\n          );\n        })}\n      </div>\n    </div>\n  );\n}\n\nexport function PillarChart({\n  ranges,\n  value,\n  defaultValue,\n  onValueChange,\n  title = \"Activity\",\n  icon,\n  unit = \"\",\n  format = FORMAT,\n  locales,\n  tone = \"cobalt\",\n  accent = \"#dcfc4e\",\n  className = \"\",\n  style,\n  ...props\n}: PillarChartProps) {\n  const reduced = useInteractionReducedMotion();\n  const [own, setOwn] = React.useState(defaultValue ?? ranges[0]?.id);\n  const current = ranges.find((r) => r.id === (value ?? own)) ?? ranges[0];\n  const tallest = (r: PillarRange) => r.focus ?? r.bars.reduce((best, b, i, all) => (b.value > all[best].value ? i : best), 0);\n  const [picked, setPicked] = React.useState<{ range: string; index: number }>({ range: current.id, index: tallest(current) });\n  const selected = picked.range === current.id ? Math.min(picked.index, current.bars.length - 1) : tallest(current);\n  const bar = current.bars[selected];\n  const hydrated = useHydrated();\n  const lang = hydrated ? locales : (locales ?? \"en-US\");\n  const nf = React.useMemo(() => new Intl.NumberFormat(lang, format), [lang, format]);\n\n  // The range on show and the one sinking away; a change is spotted while rendering, so both draw in the same frame.\n  const [shown, setShown] = React.useState({ id: current.id, enter: 0, key: 0 });\n  const [leaving, setLeaving] = React.useState<{ id: string; key: number } | null>(null);\n  if (shown.id !== current.id) {\n    const from = ranges.findIndex((r) => r.id === shown.id);\n    const to = ranges.findIndex((r) => r.id === current.id);\n    setLeaving({ id: shown.id, key: shown.key });\n    setShown({ id: current.id, enter: to >= from ? 1 : -1, key: shown.key + 1 });\n  }\n  React.useEffect(() => {\n    if (!leaving) return;\n    const t = window.setTimeout(() => setLeaving(null), 340);\n    return () => window.clearTimeout(t);\n  }, [leaving]);\n\n  const choose = (id: string) => {\n    if (id === current.id) return;\n    if (value === undefined) setOwn(id);\n    onValueChange?.(id);\n  };\n\n  // The switch's pill slides to the choice; placed without a transition the first time.\n  const switchRef = React.useRef<HTMLDivElement>(null);\n  const [pill, setPill] = React.useState<{ x: number; w: number; ready: boolean } | null>(null);\n  React.useLayoutEffect(() => {\n    const el = switchRef.current?.querySelector<HTMLElement>(`[data-range=\"${CSS.escape(current.id)}\"]`);\n    if (!el) return;\n    setPill((p) => (p && p.x === el.offsetLeft && p.w === el.offsetWidth ? p : { x: el.offsetLeft, w: el.offsetWidth, ready: !!p }));\n  }, [current.id]);\n\n  const up = (current.change ?? 0) >= 0;\n  const leavingRange = leaving ? ranges.find((r) => r.id === leaving.id) : undefined;\n\n  return (\n    <div\n      className={`relative flex w-full flex-col overflow-clip rounded-[22px] p-5 select-none ${className}`}\n      style={{ ...lacquer(tone), ...style }}\n      {...props}\n    >\n      <div className=\"flex items-center justify-between gap-3\">\n        <div className=\"flex items-center gap-1.5 text-[12.5px] font-medium text-white/85\">\n          {icon}\n          <span>{title}</span>\n        </div>\n        {ranges.length > 1 && (\n          <div\n            ref={switchRef}\n            role=\"radiogroup\"\n            aria-label=\"Range\"\n            className=\"relative inline-flex items-center gap-0.5 rounded-full p-0.5\"\n            style={{ background: \"rgb(0 0 0 / 0.25)\", boxShadow: \"inset 0 0 0 1px rgb(255 255 255 / 0.14)\" }}\n          >\n            {pill && (\n              <span\n                aria-hidden\n                className=\"absolute left-0 top-0.5 h-6 rounded-full bg-white\"\n                style={{ width: pill.w, transform: `translateX(${pill.x}px)`, transition: pill.ready && !reduced ? `transform 420ms ${EASE_THROW}, width 300ms ${EASE_OUT}` : \"none\" }}\n              />\n            )}\n            {ranges.map((r) => {\n              const on = r.id === current.id;\n              return (\n                <button\n                  key={r.id}\n                  data-range={r.id}\n                  type=\"button\"\n                  role=\"radio\"\n                  aria-checked={on}\n                  aria-label={r.name ?? r.label}\n                  tabIndex={on ? 0 : -1}\n                  onClick={() => choose(r.id)}\n                  onKeyDown={(e) => {\n                    const i = ranges.indexOf(r);\n                    const step = { ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1 }[e.key];\n                    if (!step) return;\n                    e.preventDefault();\n                    const next = ranges[(i + step + ranges.length) % ranges.length];\n                    choose(next.id);\n                    (switchRef.current?.querySelector(`[data-range=\"${CSS.escape(next.id)}\"]`) as HTMLElement | null)?.focus();\n                  }}\n                  className={`relative z-10 grid h-6 min-w-6 cursor-pointer place-items-center rounded-full px-1.5 text-[11px] font-semibold outline-none transition-colors duration-200 focus-visible:ring-2 focus-visible:ring-white/70 ${\n                    on ? \"text-[#0b0b10]\" : \"text-white/65 hover:text-white\"\n                  }`}\n                >\n                  {r.label}\n                </button>\n              );\n            })}\n          </div>\n        )}\n      </div>\n\n      <div className=\"mt-3\">\n        <div className=\"flex items-center gap-2.5\">\n          <span className=\"text-[34px] font-normal leading-none tracking-[-0.03em] tabular-nums text-white\">\n            <NumberRoll value={current.total} format={format} locales={lang} suffix={unit} />\n          </span>\n          {current.change !== undefined && (\n            <span\n              className=\"inline-flex items-center gap-0.5 rounded-full px-2 py-0.5 text-[11px] font-semibold leading-tight tabular-nums\"\n              style={up ? { background: accent, color: \"#11140a\" } : { background: \"rgb(255 255 255 / 0.14)\", color: \"#fff\" }}\n            >\n              {up ? <ArrowUpRight className=\"size-3\" strokeWidth={2.6} aria-hidden /> : <ArrowDownRight className=\"size-3\" strokeWidth={2.6} aria-hidden />}\n              <NumberRoll value={Math.abs(current.change)} format={{ maximumFractionDigits: 1 }} locales={lang} suffix=\"%\" />\n            </span>\n          )}\n        </div>\n        <p className=\"mt-1.5 h-[18px] text-[12px] tabular-nums text-white/65\">\n          <TextMorph>{bar ? (bar.detail ?? `${bar.label} · ${nf.format(bar.value)}${unit}`) : \"\"}</TextMorph>\n        </p>\n      </div>\n\n      <div className=\"relative mt-4 h-[148px]\">\n        {leavingRange && (\n          <Pillars key={`out-${leaving!.key}`} range={leavingRange} selected={-1} onSelect={() => {}} enter={0} leaving reduced={reduced} accent={accent} />\n        )}\n        <Pillars\n          key={`in-${shown.key}`}\n          range={current}\n          selected={selected}\n          onSelect={(i) => setPicked({ range: current.id, index: i })}\n          enter={shown.enter}\n          leaving={false}\n          reduced={reduced}\n          accent={accent}\n        />\n      </div>\n\n      <table className=\"sr-only\">\n        <caption>\n          {title}, {current.name ?? current.label}: {nf.format(current.total)}\n          {unit}\n        </caption>\n        <tbody>\n          {current.bars.map((b) => (\n            <tr key={b.label}>\n              <th scope=\"row\">{b.label}</th>\n              <td>\n                {nf.format(b.value)}\n                {unit}\n              </td>\n            </tr>\n          ))}\n        </tbody>\n      </table>\n    </div>\n  );\n}\n"},{"path":"registry/lacquer.ts","type":"registry:component","content":"// Hairline UI · pillar-chart · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n/* ─────────────────────────────────────────────────────────\n * LACQUER: the dark surface of Pillar chart, Stage timeline and\n * Track player\n *\n * These cards are objects with their own finish, like a device\n * screen or a lacquered box: always dark, the same on a light page\n * or a dark one. The colour pools in from two corners over a near\n * black, with a fine light along the top edge and a dark one along\n * the bottom; no drop shadow.\n *\n * Named tones are mixed here into plain rgba() so every browser\n * paints them (Safari dropped color-mix() inside these gradients);\n * a solid near-black sits under the gradients either way, so the\n * card can never come out light.\n * ───────────────────────────────────────────────────────── */\n\nimport type * as React from \"react\";\n\nexport type LacquerTone = \"cobalt\" | \"ember\" | \"rose\" | \"emerald\" | \"midnight\" | \"violet\";\n\nexport const LACQUER: Record<LacquerTone, string> = {\n  cobalt: \"#3462eb\",\n  ember: \"#ce3e1a\",\n  rose: \"#d0306c\",\n  emerald: \"#0f9f74\",\n  midnight: \"#3a4fd6\",\n  violet: \"#7e22f5\",\n};\n\n/** Any named tone or CSS colour, as the colour the lacquer is mixed from. */\nexport const toneColor = (tone: LacquerTone | (string & {})) => (tone in LACQUER ? LACQUER[tone as LacquerTone] : tone);\n\nconst BASE = \"#060609\";\n\ntype Rgb = [number, number, number];\nconst hex = (h: string): Rgb | null => {\n  const m = /^#([0-9a-f]{6})$/i.exec(h.trim());\n  return m ? [parseInt(m[1].slice(0, 2), 16), parseInt(m[1].slice(2, 4), 16), parseInt(m[1].slice(4, 6), 16)] : null;\n};\nconst rgba = ([r, g, b]: Rgb, a = 1) => `rgba(${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)}, ${a})`;\nconst blend = (a: Rgb, b: Rgb, t: number): Rgb => [a[0] * t + b[0] * (1 - t), a[1] * t + b[1] * (1 - t), a[2] * t + b[2] * (1 - t)];\n\n/**\n * A tone mixed with another colour: `share` of the tone (0 to 1). Plain rgba() for hex colours (named tones included);\n * anything else (oklch(), a theme variable) falls back to color-mix(), which needs a browser that paints it.\n */\nexport function mixTone(tone: LacquerTone | (string & {}), share: number, other: \"transparent\" | (string & {}) = \"transparent\") {\n  const t = hex(toneColor(tone));\n  const o = other === \"transparent\" ? null : hex(other);\n  if (t && other === \"transparent\") return rgba(t, share);\n  if (t && o) return rgba(blend(t, o, share));\n  return `color-mix(in oklab, ${toneColor(tone)} ${Math.round(share * 100)}%, ${other})`;\n}\n\n/** The lacquer as inline styles: background, the lit top edge and a hairline border. Text on it is white. */\nexport function lacquer(tone: LacquerTone | (string & {})): React.CSSProperties {\n  const m = (share: number, over: \"transparent\" | (string & {}) = \"transparent\") => mixTone(tone, share, over);\n  return {\n    background: [\n      `radial-gradient(88% 78% at 10% 8%, ${m(0.74)} 0%, ${m(0.32)} 46%, transparent 76%)`,\n      `radial-gradient(82% 76% at 92% 96%, ${m(0.6)} 0%, ${m(0.26)} 52%, transparent 80%)`,\n      `linear-gradient(150deg, ${m(0.34, BASE)} 0%, ${m(0.09, BASE)} 52%, ${m(0.28, BASE)} 100%)`,\n    ].join(\", \"),\n    // Set after the shorthand, so a gradient a browser can't paint still leaves the card dark.\n    backgroundColor: BASE,\n    boxShadow: \"inset 0 1px 0 rgb(255 255 255 / 0.26), inset 0 -1px 0 rgb(0 0 0 / 0.35)\",\n    border: \"1px solid rgb(255 255 255 / 0.14)\",\n    color: \"#fff\",\n    colorScheme: \"dark\",\n  };\n}\n"},{"path":"registry/ui-interaction-motion.ts","type":"registry:component","content":"// Hairline UI · pillar-chart · 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":{},"docs":"Docs and live preview: https://hairlineui.com/ui/pillar-chart. MIT licensed: https://hairlineui.com/license#components","meta":{"license":"MIT"}}