{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "flame-graph",
  "type": "registry:component",
  "title": "Flame graph",
  "description": "A profiler flame graph with crisp HTML frames, an animated zoom into any call, and search that reports how much of the total it matches.",
  "categories": [
    "operations"
  ],
  "dependencies": [
    "@tabler/icons-react"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/registry/overtrue/flame-graph.tsx",
      "type": "registry:component",
      "target": "components/overtrue/flame-graph.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { IconSearch, IconX, IconZoomReset } from \"@tabler/icons-react\";\n\nimport { cn } from \"@/lib/utils\";\n\n/* ------------------------------------------------------------------------ */\n/* Types                                                                     */\n/* ------------------------------------------------------------------------ */\n\nexport interface FlameNode {\n  /** Stable id. Defaults to the node's position in the tree. Must be unique when set. */\n  id?: string;\n  /** Function or frame name, e.g. \"db.query\" or \"react-dom.renderToString\". */\n  name: string;\n  /** Total (inclusive) cost of the frame. When the children add up to more, their sum is used. */\n  value: number;\n  children?: FlameNode[];\n  /** Color group. Defaults to the name's package prefix, e.g. \"db\" for \"db.query\". */\n  group?: string;\n  /** Anything else your tooltip or handlers need, such as a file and line. */\n  meta?: Record<string, unknown>;\n}\n\nexport type FlameGraphOrientation = \"icicle\" | \"flame\";\n\n/** Everything derived about one frame, passed to `renderTooltip`, `onSelect` and `colorBy`. */\nexport interface FlameFrameInfo {\n  id: string;\n  node: FlameNode;\n  /** 0 for the root. */\n  depth: number;\n  /** Resolved color group. */\n  group: string;\n  /** Inclusive value: the frame and everything it called. */\n  total: number;\n  /** Value spent in the frame itself: total minus children. */\n  self: number;\n  /** Total as a 0–1 share of the root. */\n  share: number;\n  /** Self as a 0–1 share of the root. */\n  selfShare: number;\n  /** Total as a 0–1 share of the parent; 1 for the root. */\n  parentShare: number;\n  parent: FlameNode | null;\n  /** Nodes from the root down to and including this one. */\n  path: FlameNode[];\n  /** Resolved fill and a readable ink for it. */\n  fill: string;\n  ink: string;\n  /** Whether the frame matches the current search. */\n  match: boolean;\n}\n\n/** Context passed to a `colorBy` function. */\nexport interface FlameColorContext {\n  depth: number;\n  group: string;\n  total: number;\n  self: number;\n  /** Total as a 0–1 share of the root. */\n  share: number;\n  /** Self time relative to the hottest frame in the profile, 0–1. */\n  heat: number;\n}\n\nexport type FlameGraphColorBy =\n  | \"group\"\n  | \"self\"\n  | ((node: FlameNode, context: FlameColorContext) => string);\n\nexport interface FlameGraphProps extends Omit<\n  React.ComponentProps<\"div\">,\n  \"title\" | \"children\" | \"onSelect\"\n> {\n  /** The root frame, or several roots that are drawn under one `rootName` frame. */\n  data: FlameNode | FlameNode[];\n  /** Name of the synthetic root when `data` is an array. Defaults to \"all\". */\n  rootName?: string;\n  /** \"icicle\" draws the root on top; \"flame\" draws it at the bottom. Defaults to icicle. */\n  orientation?: FlameGraphOrientation;\n  /** Row height in pixels. Defaults to 22. */\n  rowHeight?: number;\n  /** Frames narrower than this many pixels are skipped. Defaults to 2. */\n  minFrameWidth?: number;\n  /** Maximum height of the frame area in pixels; deeper profiles scroll. Defaults to fitting every row. */\n  height?: number;\n  /** Color by package group, by self time as a heat scale, or with your own function. Defaults to group. */\n  colorBy?: FlameGraphColorBy;\n  /**\n   * Group palette, hashed by group. With `colorBy=\"self\"`, the stops of the heat\n   * scale from cold to hot. Defaults to accent-to-neutral group tones, and to a\n   * neutral, amber and destructive heat ramp.\n   */\n  colors?: string[];\n  /** Controlled zoom: the id of the frame drawn at full width, or null for the root. */\n  zoomedId?: string | null;\n  defaultZoomedId?: string | null;\n  onZoomChange?: (id: string | null, node: FlameNode | null) => void;\n  /** Show the built-in search field. Defaults to true. */\n  showSearch?: boolean;\n  /** Controlled search. Frames whose name contains it are highlighted. */\n  search?: string;\n  defaultSearch?: string;\n  onSearchChange?: (search: string) => void;\n  searchPlaceholder?: string;\n  /** Formats values. Defaults to milliseconds. */\n  valueFormatter?: (value: number) => string;\n  /** Replaces the content of the hover and focus readout. */\n  renderTooltip?: (info: FlameFrameInfo) => React.ReactNode;\n  /** List the heaviest functions by aggregated self time. Pass a number for the count; true shows 8. */\n  showTopFunctions?: boolean | number;\n  /** Called when a frame is clicked or activated with Enter, before it zooms. */\n  onSelect?: (node: FlameNode, info: FlameFrameInfo) => void;\n  title?: React.ReactNode;\n  description?: React.ReactNode;\n  /** Controls placed at the top right, before the total. */\n  actions?: React.ReactNode;\n}\n\n/* ------------------------------------------------------------------------ */\n/* Model                                                                     */\n/* ------------------------------------------------------------------------ */\n\ninterface Frame {\n  id: string;\n  node: FlameNode;\n  name: string;\n  lower: string;\n  group: string;\n  depth: number;\n  /** Start and end as 0–1 fractions of the root. */\n  start: number;\n  end: number;\n  total: number;\n  self: number;\n  heat: number;\n  parent: Frame | null;\n  children: Frame[];\n}\n\ninterface Model {\n  root: Frame | null;\n  byId: Map<string, Frame>;\n  maxDepth: number;\n  count: number;\n}\n\ninterface View {\n  v0: number;\n  vs: number;\n}\n\nconst ROOT_KEY = \"root\";\nconst DURATION = 300;\n/** Horizontal padding plus about four monospace characters: anything less is noise. */\nconst labelFits = (frame: { name: string }, px: number) =>\n  px >= 13 + 6.7 * Math.min(frame.name.length, 4);\nconst FALLBACK_WIDTH = 640;\n\nconst defaultPalette = [\n  \"var(--color-primary)\",\n  \"color-mix(in oklab, var(--color-primary) 80%, var(--color-muted-foreground))\",\n  \"color-mix(in oklab, var(--color-primary) 60%, var(--color-muted-foreground))\",\n  \"color-mix(in oklab, var(--color-primary) 40%, var(--color-muted-foreground))\",\n  \"var(--color-muted-foreground)\",\n];\n\nconst AMBER = \"var(--color-amber-400, oklch(82.8% 0.189 84.429))\";\nconst defaultHeat = [\n  \"color-mix(in oklab, var(--color-muted-foreground) 24%, var(--color-card))\",\n  AMBER,\n  \"var(--color-destructive)\",\n];\n\n/** The package a frame belongs to: \"db\" for \"db.query\", \"react-dom\" for \"react-dom.render\". */\nfunction packageOf(name: string) {\n  const match =\n    /^\\s*(@[\\w.-]+\\/[\\w-]+|[\\w$-]+)(?:\\.|\\/|::|:|#)/.exec(name) ??\n    /^\\s*([\\w$-]+)/.exec(name);\n  return match ? match[1] : name;\n}\n\nfunction hash(text: string) {\n  let h = 0x811c9dc5;\n  for (let i = 0; i < text.length; i++) {\n    h ^= text.charCodeAt(i);\n    h = Math.imul(h, 0x01000193);\n  }\n  return h >>> 0;\n}\n\nfunction buildModel(data: FlameNode | FlameNode[], rootName: string): Model {\n  const byId = new Map<string, Frame>();\n  const order: Frame[] = [];\n  let maxDepth = 0;\n  const rootNode: FlameNode = Array.isArray(data)\n    ? { name: rootName, value: 0, children: data }\n    : data;\n\n  const visit = (\n    node: FlameNode,\n    parent: Frame | null,\n    depth: number,\n    offset: number,\n    key: string,\n  ): Frame | null => {\n    const id = node.id ?? key;\n    const frame: Frame = {\n      id,\n      node,\n      name: node.name,\n      lower: node.name.toLowerCase(),\n      group: node.group ?? packageOf(node.name),\n      depth,\n      start: offset,\n      end: offset,\n      total: 0,\n      self: 0,\n      heat: 0,\n      parent,\n      children: [],\n    };\n    const at = order.length;\n    order.push(frame);\n    let cursor = offset;\n    node.children?.forEach((child, index) => {\n      const built = visit(child, frame, depth + 1, cursor, `${id}/${index}`);\n      if (!built) return;\n      frame.children.push(built);\n      cursor += built.total;\n    });\n    const childSum = cursor - offset;\n    const own = Number(node.value);\n    frame.total = Math.max(Number.isFinite(own) && own > 0 ? own : 0, childSum);\n    frame.self = Math.max(0, frame.total - childSum);\n    frame.end = offset + frame.total;\n    if (!(frame.total > 0)) {\n      order.length = at;\n      return null;\n    }\n    return frame;\n  };\n\n  const root = visit(rootNode, null, 0, 0, ROOT_KEY);\n  if (!root) return { root: null, byId, maxDepth: 0, count: 0 };\n  const scale = root.total;\n  let maxSelf = 0;\n  for (const frame of order) maxSelf = Math.max(maxSelf, frame.self);\n  for (const frame of order) {\n    frame.start /= scale;\n    frame.end /= scale;\n    frame.heat = maxSelf > 0 ? Math.sqrt(frame.self / maxSelf) : 0;\n    maxDepth = Math.max(maxDepth, frame.depth);\n    byId.set(frame.id, frame);\n  }\n  return { root, byId, maxDepth, count: order.length };\n}\n\nfunction lineage(frame: Frame) {\n  const chain: Frame[] = [];\n  for (let current: Frame | null = frame; current; current = current.parent)\n    chain.unshift(current);\n  return chain;\n}\n\n/** Frames wider than `minWidth` pixels inside the view, in depth-first order. */\nfunction visibleFrames(root: Frame, view: View, width: number, min: number) {\n  const out: Frame[] = [];\n  const lo = view.v0;\n  const hi = view.v0 + view.vs;\n  const stack = [root];\n  while (stack.length) {\n    const frame = stack.pop()!;\n    const a = Math.max(frame.start, lo);\n    const b = Math.min(frame.end, hi);\n    if (b <= a || ((b - a) / view.vs) * width < min) continue;\n    out.push(frame);\n    for (let i = frame.children.length - 1; i >= 0; i--)\n      stack.push(frame.children[i]);\n  }\n  return out;\n}\n\nfunction pixelWidth(frame: Frame, view: View, width: number) {\n  const a = Math.max(frame.start, view.v0);\n  const b = Math.min(frame.end, view.v0 + view.vs);\n  return b > a ? ((b - a) / view.vs) * width : 0;\n}\n\n/**\n * Zoom about the one point that stays put on screen, with the scale changing\n * geometrically, so deep zooms feel as steady as shallow ones.\n */\nfunction interpolate(a: View, b: View, t: number): View {\n  if (Math.abs(a.vs - b.vs) < 1e-12)\n    return { v0: a.v0 + (b.v0 - a.v0) * t, vs: a.vs };\n  const vs = a.vs * Math.pow(b.vs / a.vs, t);\n  const fixed = (b.v0 * a.vs - a.v0 * b.vs) / (a.vs - b.vs);\n  return { v0: fixed - (fixed - a.v0) * (vs / a.vs), vs };\n}\n\nconst easeOut = (t: number) => 1 - Math.pow(1 - t, 3);\n\n/* ------------------------------------------------------------------------ */\n/* Formatting and color                                                     */\n/* ------------------------------------------------------------------------ */\n\nfunction formatMs(ms: number) {\n  if (!Number.isFinite(ms)) return \"—\";\n  const a = Math.abs(ms);\n  if (a === 0) return \"0 ms\";\n  if (a < 1) return `${ms.toFixed(2)} ms`;\n  if (a < 10) return `${ms.toFixed(1)} ms`;\n  if (a < 1000) return `${Math.round(ms)} ms`;\n  if (a < 10_000) return `${(ms / 1000).toFixed(2)} s`;\n  return `${(ms / 1000).toFixed(1)} s`;\n}\n\nfunction percent(share: number) {\n  const pct = share * 100;\n  if (!(pct > 0)) return \"0%\";\n  if (pct < 0.1) return \"<0.1%\";\n  if (pct >= 99.95) return \"100%\";\n  return `${+pct.toFixed(1)}%`;\n}\n\n/** Pick black or white from relative luminance (XYZ Y), with D65's white point. */\nfunction inkFor(fill: string) {\n  const light = \"clamp(0, (0.179 - y) * 100000000, 1)\";\n  return `color(from ${fill} xyz-d65 calc(${light} * 0.95047) ${light} calc(${light} * 1.08883))`;\n}\n\nfunction mix(a: string, b: string, t: number) {\n  const pct = Math.round(Math.min(1, Math.max(0, t)) * 100);\n  if (pct <= 0) return b;\n  if (pct >= 100) return a;\n  return `color-mix(in oklab, ${a} ${pct}%, ${b})`;\n}\n\nfunction rampAt(stops: string[], t: number) {\n  if (stops.length === 1) return stops[0];\n  const scaled = Math.min(1, Math.max(0, t)) * (stops.length - 1);\n  const i = Math.min(stops.length - 2, Math.floor(scaled));\n  return mix(stops[i + 1], stops[i], scaled - i);\n}\n\n/** Splits \"482 ms\" into digits and a quieter unit. */\nfunction Figure({ text, className }: { text: string; className?: string }) {\n  const match = /^([-+]?[\\d.,]+)\\s*(\\D.*)$/.exec(text);\n  if (!match) return <span className={className}>{text}</span>;\n  return (\n    <span className={className}>\n      {match[1]}\n      <span className=\"ml-0.5 text-[0.62em] font-medium tracking-normal text-muted-foreground\">\n        {match[2]}\n      </span>\n    </span>\n  );\n}\n\n/* ------------------------------------------------------------------------ */\n/* Hooks                                                                     */\n/* ------------------------------------------------------------------------ */\n\nconst useIsomorphicLayoutEffect =\n  typeof window === \"undefined\" ? React.useEffect : React.useLayoutEffect;\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (onChange) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", onChange);\n      return () => query.removeEventListener(\"change\", onChange);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nfunction useControllable<T>(\n  value: T | undefined,\n  defaultValue: T,\n  onChange?: (value: T) => void,\n) {\n  const [inner, setInner] = React.useState(defaultValue);\n  const controlled = value !== undefined;\n  const current = controlled ? value : inner;\n  const set = React.useCallback(\n    (next: T) => {\n      if (!controlled) setInner(next);\n      onChange?.(next);\n    },\n    [controlled, onChange],\n  );\n  return [current, set] as const;\n}\n\n/* ------------------------------------------------------------------------ */\n/* Frame                                                                     */\n/* ------------------------------------------------------------------------ */\n\ninterface FrameProps {\n  frame: Frame;\n  top: number;\n  height: number;\n  fill: string;\n  label: boolean;\n  query: string;\n  match: boolean;\n  dimmed: boolean;\n  ancestor: boolean;\n  zoomed: boolean;\n  active: boolean;\n  tabStop: boolean;\n  ariaLabel: string;\n  reveal: number | null;\n}\n\nfunction Highlighted({ text, query }: { text: string; query: string }) {\n  const at = query ? text.toLowerCase().indexOf(query) : -1;\n  if (at < 0) return <>{text}</>;\n  return (\n    <>\n      {text.slice(0, at)}\n      <mark className=\"bg-transparent font-bold text-inherit underline decoration-current/70 decoration-[1.5px] underline-offset-[3px]\">\n        {text.slice(at, at + query.length)}\n      </mark>\n      {text.slice(at + query.length)}\n    </>\n  );\n}\n\n/** Memoised so hovering one frame re-renders two, not the whole profile. */\nconst FlameFrame = React.memo(function FlameFrame({\n  frame,\n  top,\n  height,\n  fill: baseFill,\n  label,\n  query,\n  match,\n  dimmed,\n  ancestor,\n  zoomed,\n  active,\n  tabStop,\n  ariaLabel,\n  reveal,\n}: FrameProps) {\n  // Dimming mixes the fill toward the surface instead of fading it, so the ink is\n  // always picked against the color that is actually on screen.\n  const fill = active\n    ? baseFill\n    : dimmed\n      ? `color-mix(in oklab, ${baseFill} 26%, var(--color-muted))`\n      : ancestor\n        ? `color-mix(in oklab, ${baseFill} 48%, var(--color-card))`\n        : baseFill;\n  const ink = inkFor(fill);\n  return (\n    <button\n      type=\"button\"\n      data-slot=\"flame-graph-frame\"\n      data-id={frame.id}\n      data-depth={frame.depth}\n      data-match={match || undefined}\n      data-dimmed={dimmed || undefined}\n      data-ancestor={ancestor || undefined}\n      data-zoomed={zoomed || undefined}\n      data-active={active || undefined}\n      aria-label={ariaLabel}\n      aria-current={zoomed ? \"true\" : undefined}\n      tabIndex={tabStop ? 0 : -1}\n      className={cn(\n        \"group/frame absolute block overflow-hidden rounded-[3px] p-0 text-left outline-none select-none\",\n        ancestor ? \"cursor-zoom-out\" : zoomed ? \"cursor-default\" : \"cursor-zoom-in\",\n        \"data-[active]:z-10 focus-visible:z-20\",\n        reveal != null &&\n          \"motion-safe:animate-[flame-frame-in_720ms_cubic-bezier(0.22,1,0.36,1)_backwards]\",\n      )}\n      style={\n        {\n          \"--x0\": +frame.start.toFixed(9),\n          \"--x1\": +frame.end.toFixed(9),\n          \"--frame-fill\": baseFill,\n          top,\n          height,\n          color: ink,\n          animationDelay: reveal != null ? `${reveal}ms` : undefined,\n        } as React.CSSProperties\n      }\n    >\n      <span\n        aria-hidden=\"true\"\n        data-slot=\"flame-graph-frame-fill\"\n        className={cn(\n          \"absolute inset-0 rounded-[inherit] transition-[background-color,box-shadow] duration-150 motion-reduce:transition-none\",\n          match &&\n            \"shadow-[inset_0_0_0_1px_color-mix(in_oklab,var(--frame-fill)_55%,var(--color-foreground))] dark:shadow-[inset_0_0_0_1px_rgb(255_255_255/0.4),0_0_14px_-3px_var(--frame-fill)]\",\n          \"group-data-[active]/frame:shadow-[inset_0_0_0_1.5px_color-mix(in_oklab,var(--color-foreground)_82%,transparent),0_0_18px_-4px_var(--frame-fill)]\",\n          \"group-focus-visible/frame:shadow-[inset_0_0_0_2px_var(--color-ring),inset_0_0_0_3px_var(--color-card)]\",\n        )}\n        style={{ backgroundColor: fill }}\n      />\n      {label ? (\n        <span\n          aria-hidden=\"true\"\n          className=\"relative block truncate px-1.5 font-mono text-[11px] transition-colors duration-150 motion-reduce:transition-none\"\n          style={{ lineHeight: `${height}px` }}\n        >\n          {match ? <Highlighted text={frame.name} query={query} /> : frame.name}\n        </span>\n      ) : null}\n    </button>\n  );\n});\n\n/* ------------------------------------------------------------------------ */\n/* Tooltip                                                                   */\n/* ------------------------------------------------------------------------ */\n\nfunction DefaultTooltip({\n  info,\n  format,\n}: {\n  info: FlameFrameInfo;\n  format: (value: number) => string;\n}) {\n  return (\n    <div className=\"w-max max-w-72 min-w-52\">\n      <div className=\"flex items-start gap-2 px-3 pt-2.5 pb-2\">\n        <span\n          aria-hidden=\"true\"\n          className=\"mt-[3px] size-2.5 shrink-0 rounded-[3px]\"\n          style={{ backgroundColor: info.fill }}\n        />\n        <div className=\"min-w-0 space-y-0.5\">\n          <p className=\"font-mono text-xs leading-4 font-medium break-all text-foreground\">\n            {info.node.name}\n          </p>\n          <p className=\"text-[11px] leading-4 text-muted-foreground\">\n            {info.group !== info.node.name ? (\n              <>\n                <span className=\"font-mono\">{info.group}</span>\n                {\" · \"}\n              </>\n            ) : null}\n            depth <span className=\"tabular-nums\">{info.depth}</span>\n          </p>\n        </div>\n      </div>\n      <dl className=\"grid grid-cols-[auto_1fr_auto] items-baseline gap-x-4 gap-y-1 border-t border-border/60 px-3 py-2 text-xs tabular-nums\">\n        <dt className=\"text-muted-foreground\">Total</dt>\n        <dd className=\"text-right font-medium text-foreground\">\n          {format(info.total)}\n        </dd>\n        <dd className=\"text-right text-muted-foreground\">\n          {percent(info.share)}\n        </dd>\n        <dt className=\"text-muted-foreground\">Self</dt>\n        <dd className=\"text-right font-medium text-foreground\">\n          {format(info.self)}\n        </dd>\n        <dd className=\"text-right text-muted-foreground\">\n          {percent(info.selfShare)}\n        </dd>\n        {info.parent ? (\n          <>\n            <dt className=\"text-muted-foreground\">Of parent</dt>\n            <dd className=\"col-span-2 flex min-w-0 items-baseline justify-end gap-1 text-right\">\n              <span className=\"font-medium text-foreground\">\n                {percent(info.parentShare)}\n              </span>\n              <span className=\"truncate font-mono text-[11px] text-muted-foreground\">\n                {info.parent.name}\n              </span>\n            </dd>\n          </>\n        ) : null}\n      </dl>\n    </div>\n  );\n}\n\n/* ------------------------------------------------------------------------ */\n/* Component                                                                 */\n/* ------------------------------------------------------------------------ */\n\nconst toolButton =\n  \"inline-flex size-7 shrink-0 items-center justify-center rounded-md text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-40 motion-reduce:transition-none\";\n\n/**\n * A profiler flame graph. Frames are HTML, so labels stay crisp at any zoom.\n * Click or press Enter on a frame to zoom it to full width; Escape zooms out.\n * Search highlights matching frames and reports their share of the total.\n */\nfunction FlameGraph({\n  data,\n  rootName = \"all\",\n  orientation = \"icicle\",\n  rowHeight = 22,\n  minFrameWidth = 2,\n  height,\n  colorBy = \"group\",\n  colors,\n  zoomedId: zoomedIdProp,\n  defaultZoomedId = null,\n  onZoomChange,\n  showSearch = true,\n  search: searchProp,\n  defaultSearch = \"\",\n  onSearchChange,\n  searchPlaceholder = \"Search functions\",\n  valueFormatter = formatMs,\n  renderTooltip,\n  showTopFunctions = false,\n  onSelect,\n  title,\n  description,\n  actions,\n  className,\n  onKeyDown,\n  ...props\n}: FlameGraphProps) {\n  const id = React.useId();\n  const reduced = useReducedMotion();\n  const format = valueFormatter;\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const scrollRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLDivElement>(null);\n  const tipRef = React.useRef<HTMLDivElement>(null);\n  const pointer = React.useRef<{ x: number; y: number } | null>(null);\n  const pendingFocus = React.useRef(false);\n\n  const model = React.useMemo(() => buildModel(data, rootName), [data, rootName]);\n  const { root, byId, maxDepth } = model;\n\n  /* ---------------------------------------------------------- state */\n\n  const [innerZoom, setInnerZoom] = React.useState<string | null>(\n    defaultZoomedId,\n  );\n  const requestedZoom =\n    zoomedIdProp !== undefined ? zoomedIdProp : innerZoom;\n  const focus =\n    (requestedZoom != null ? byId.get(requestedZoom) : undefined) ?? root;\n  const zoomed = focus != null && focus !== root;\n\n  const [search, setSearch] = useControllable(\n    searchProp,\n    defaultSearch,\n    onSearchChange,\n  );\n  const query = search.trim().toLowerCase();\n\n  const [width, setWidth] = React.useState(0);\n  const [hoveredId, setHoveredId] = React.useState<string | null>(null);\n  const [focusedId, setFocusedId] = React.useState<string | null>(null);\n  const [tabStopId, setTabStopId] = React.useState<string | null>(null);\n  const [tween, setTween] = React.useState<{ from: View; to: View } | null>(\n    null,\n  );\n  const [revealed, setRevealed] = React.useState(false);\n\n  const target: View = focus\n    ? { v0: focus.start, vs: focus.end - focus.start || 1 }\n    : { v0: 0, vs: 1 };\n  const [initialView] = React.useState(target);\n  const shown = React.useRef<View>(target);\n\n  const commitZoom = (frame: Frame | null) => {\n    const next = frame && frame !== root ? frame : null;\n    if (zoomedIdProp === undefined) setInnerZoom(next?.id ?? null);\n    onZoomChange?.(next?.id ?? null, next?.node ?? null);\n  };\n\n  /* ---------------------------------------------------------- measure */\n\n  useIsomorphicLayoutEffect(() => {\n    const element = canvasRef.current;\n    if (!element) return;\n    const measure = () => setWidth(element.clientWidth);\n    measure();\n    const observer = new ResizeObserver(measure);\n    observer.observe(element);\n    return () => observer.disconnect();\n  }, [root != null]);\n\n  React.useEffect(() => {\n    const timer = window.setTimeout(() => setRevealed(true), 1400);\n    return () => window.clearTimeout(timer);\n  }, []);\n\n  // Flame graphs grow upward, so a scrolling one starts at the root.\n  useIsomorphicLayoutEffect(() => {\n    const scroller = scrollRef.current;\n    if (scroller && orientation === \"flame\")\n      scroller.scrollTop = scroller.scrollHeight;\n  }, [orientation, height]);\n\n  /* ---------------------------------------------------------- zoom tween */\n\n  useIsomorphicLayoutEffect(() => {\n    const element = canvasRef.current;\n    if (!element) return;\n    const to = target;\n    const from = shown.current;\n    const apply = (view: View) => {\n      element.style.setProperty(\"--flame-v0\", String(view.v0));\n      element.style.setProperty(\"--flame-vs\", String(view.vs));\n      shown.current = view;\n    };\n    const same =\n      Math.abs(from.v0 - to.v0) < 1e-12 && Math.abs(from.vs - to.vs) < 1e-12;\n    if (same || reduced) {\n      apply(to);\n      setTween(null);\n      return;\n    }\n    setTween({ from, to });\n    const startedAt = performance.now();\n    let frame = requestAnimationFrame(function step(now) {\n      const t = Math.min(1, (now - startedAt) / DURATION);\n      apply(interpolate(from, to, easeOut(t)));\n      if (t < 1) frame = requestAnimationFrame(step);\n      else setTween(null);\n    });\n    return () => cancelAnimationFrame(frame);\n  }, [target.v0, target.vs, reduced]);\n\n  /* ---------------------------------------------------------- colors */\n\n  const paletteKey = (colors ?? []).join(\"|\");\n  const colorMap = React.useMemo(() => {\n    const map = new Map<string, string>();\n    if (!root) return map;\n    const custom = paletteKey ? paletteKey.split(\"|\") : null;\n    for (const frame of byId.values()) {\n      let fill: string;\n      if (typeof colorBy === \"function\") {\n        fill = colorBy(frame.node, {\n          depth: frame.depth,\n          group: frame.group,\n          total: frame.total,\n          self: frame.self,\n          share: frame.total / root.total,\n          heat: frame.heat,\n        });\n      } else if (colorBy === \"self\") {\n        fill = rampAt(custom ?? defaultHeat, frame.heat);\n      } else {\n        const palette = custom ?? defaultPalette;\n        const base = palette[hash(frame.group) % palette.length];\n        // Group picks the tone; the function picks one of three tints within it.\n        const tint = hash(frame.name) % 3;\n        fill = `color-mix(in oklab, ${base} var(--flame-tint-${tint}), var(--color-card))`;\n      }\n      map.set(frame.id, fill);\n    }\n    return map;\n    // paletteKey stands in for `colors`, so inline arrays do not recolor.\n  }, [byId, root, colorBy, paletteKey]);\n\n  /* ---------------------------------------------------------- search */\n\n  const matches = React.useMemo(() => {\n    if (!root || !query) return null;\n    const ids = new Set<string>();\n    let covered = 0;\n    const walk = (frame: Frame, inside: boolean) => {\n      const hit = frame.lower.includes(query);\n      if (hit) {\n        ids.add(frame.id);\n        if (!inside) covered += frame.total;\n      }\n      for (const child of frame.children) walk(child, inside || hit);\n    };\n    walk(root, false);\n    return { ids, count: ids.size, share: covered / root.total };\n  }, [root, query]);\n\n  /* ---------------------------------------------------------- frames */\n\n  const measured = width || FALLBACK_WIDTH;\n  const rendered = React.useMemo(() => {\n    if (!root) return [] as Frame[];\n    const now = visibleFrames(root, target, measured, minFrameWidth);\n    if (!tween) return now;\n    const seen = new Set(now);\n    for (const frame of visibleFrames(\n      root,\n      tween.from,\n      measured,\n      minFrameWidth,\n    ))\n      if (!seen.has(frame)) now.push(frame);\n    return now;\n  }, [root, target.v0, target.vs, measured, minFrameWidth, tween]);\n\n  const renderedIds = React.useMemo(\n    () => new Set(rendered.map((frame) => frame.id)),\n    [rendered],\n  );\n  const stopId =\n    tabStopId && renderedIds.has(tabStopId)\n      ? tabStopId\n      : (focus?.id ?? null);\n\n  const infoFor = (frame: Frame): FlameFrameInfo => {\n    const fill = colorMap.get(frame.id) ?? defaultPalette[0];\n    const rootTotal = root?.total || 1;\n    return {\n      id: frame.id,\n      node: frame.node,\n      depth: frame.depth,\n      group: frame.group,\n      total: frame.total,\n      self: frame.self,\n      share: frame.total / rootTotal,\n      selfShare: frame.self / rootTotal,\n      parentShare: frame.parent ? frame.total / frame.parent.total : 1,\n      parent: frame.parent?.node ?? null,\n      path: lineage(frame).map((entry) => entry.node),\n      fill,\n      ink: inkFor(fill),\n      match: matches?.ids.has(frame.id) ?? false,\n    };\n  };\n\n  const describe = (frame: Frame) =>\n    `${frame.name}, ${format(frame.total)}, ${percent(frame.total / (root?.total || 1))} of total` +\n    (frame.children.length ? `, self ${format(frame.self)}` : \"\");\n\n  /* ---------------------------------------------------------- top functions */\n\n  const topCount =\n    showTopFunctions === true\n      ? 8\n      : typeof showTopFunctions === \"number\"\n        ? Math.max(1, Math.floor(showTopFunctions))\n        : 0;\n  const topFunctions = React.useMemo(() => {\n    if (!focus || !topCount) return [];\n    const map = new Map<\n      string,\n      { name: string; self: number; calls: number; sample: Frame }\n    >();\n    const stack = [focus];\n    while (stack.length) {\n      const frame = stack.pop()!;\n      if (frame.self > 0) {\n        const entry = map.get(frame.name);\n        if (entry) {\n          entry.self += frame.self;\n          entry.calls += 1;\n          if (frame.self > entry.sample.self) entry.sample = frame;\n        } else\n          map.set(frame.name, {\n            name: frame.name,\n            self: frame.self,\n            calls: 1,\n            sample: frame,\n          });\n      }\n      stack.push(...frame.children);\n    }\n    return [...map.values()]\n      .sort((a, b) => b.self - a.self)\n      .slice(0, topCount);\n  }, [focus, topCount]);\n\n  /* ---------------------------------------------------------- interaction */\n\n  const activeId = tween ? null : (hoveredId ?? focusedId);\n  const activeFrame = activeId ? (byId.get(activeId) ?? null) : null;\n\n  const placeTip = React.useCallback(() => {\n    const tip = tipRef.current;\n    const host = rootRef.current;\n    if (!tip || !host) return;\n    const box = host.getBoundingClientRect();\n    const w = tip.offsetWidth;\n    const h = tip.offsetHeight;\n    let x: number;\n    let y: number;\n    const p = pointer.current;\n    if (p) {\n      x = p.x - box.left + 14;\n      y = p.y - box.top + 18;\n      if (x + w > box.width - 8) x = p.x - box.left - w - 14;\n      if (y + h > box.height + 24) y = p.y - box.top - h - 14;\n    } else {\n      const id = tip.dataset.for;\n      const element = id\n        ? canvasRef.current?.querySelector<HTMLElement>(\n            `[data-slot=\"flame-graph-frame\"][data-id=\"${CSS.escape(id)}\"]`,\n          )\n        : null;\n      if (!element) return;\n      const r = element.getBoundingClientRect();\n      x = Math.min(r.left - box.left, box.width - w - 8);\n      y = r.bottom - box.top + 6;\n      if (y + h > box.height + 24) y = r.top - box.top - h - 6;\n    }\n    x = Math.max(8, x);\n    tip.style.transform = `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`;\n  }, []);\n\n  useIsomorphicLayoutEffect(() => {\n    if (activeFrame) placeTip();\n  }, [activeFrame, placeTip]);\n\n  const frameFromEvent = (event: React.SyntheticEvent) => {\n    const element = (event.target as HTMLElement).closest<HTMLElement>(\n      '[data-slot=\"flame-graph-frame\"]',\n    );\n    return element ? (byId.get(element.dataset.id ?? \"\") ?? null) : null;\n  };\n\n  const focusFrame = (frame: Frame | null | undefined) => {\n    if (!frame) return;\n    setTabStopId(frame.id);\n    canvasRef.current\n      ?.querySelector<HTMLElement>(\n        `[data-slot=\"flame-graph-frame\"][data-id=\"${CSS.escape(frame.id)}\"]`,\n      )\n      ?.focus({ preventScroll: false });\n  };\n\n  const activate = (frame: Frame, fromKeyboard: boolean) => {\n    onSelect?.(frame.node, infoFor(frame));\n    // Activating the zoomed frame steps out; anything else zooms to it.\n    const next = frame === focus ? (frame.parent ?? null) : frame;\n    commitZoom(next);\n    if (fromKeyboard) setTabStopId(frame.id);\n  };\n\n  const zoomOut = () => {\n    if (focus?.parent) commitZoom(focus.parent);\n  };\n\n  const onCanvasKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n    const frame = frameFromEvent(event);\n    if (!frame || !root) return;\n    const visible = (candidate: Frame | null | undefined) =>\n      candidate && renderedIds.has(candidate.id) ? candidate : null;\n    const firstChild = () =>\n      frame.children.find((child) => renderedIds.has(child.id)) ?? null;\n    const along = (direction: 1 | -1) => {\n      const row = rendered\n        .filter((candidate) => candidate.depth === frame.depth)\n        .sort((a, b) => a.start - b.start);\n      return row[row.indexOf(frame) + direction] ?? null;\n    };\n    const up = orientation === \"icicle\" ? frame.parent : firstChild();\n    const down = orientation === \"icicle\" ? firstChild() : frame.parent;\n    switch (event.key) {\n      case \"ArrowUp\":\n        focusFrame(visible(up));\n        break;\n      case \"ArrowDown\":\n        focusFrame(visible(down));\n        break;\n      case \"ArrowLeft\":\n        focusFrame(along(-1));\n        break;\n      case \"ArrowRight\":\n        focusFrame(along(1));\n        break;\n      case \"Home\":\n        focusFrame(focus);\n        break;\n      case \"Enter\":\n      case \" \":\n        activate(frame, true);\n        break;\n      case \"Escape\":\n        if (zoomed) zoomOut();\n        else if (query) setSearch(\"\");\n        else return;\n        break;\n      default:\n        return;\n    }\n    event.preventDefault();\n  };\n\n  // Keep keyboard focus on a frame that is still drawn after a zoom, and move it\n  // into the graph when the reset button that had it becomes disabled.\n  React.useEffect(() => {\n    const canvas = canvasRef.current;\n    if (!canvas || !focus) return;\n    if (pendingFocus.current) {\n      pendingFocus.current = false;\n      focusFrame(focus);\n      return;\n    }\n    const active = document.activeElement as HTMLElement | null;\n    if (!active || !canvas.contains(active)) return;\n    if (\n      active.dataset.slot === \"flame-graph-frame\" &&\n      renderedIds.has(active.dataset.id ?? \"\")\n    )\n      return;\n    focusFrame(focus);\n    // Only after a zoom settles.\n  }, [focus, tween == null]);\n\n  /* ---------------------------------------------------------- render */\n\n  const rowTop = (depth: number) =>\n    (orientation === \"icicle\" ? depth : maxDepth - depth) * rowHeight;\n  const canvasHeight = (maxDepth + 1) * rowHeight;\n  const focusChain = focus ? new Set(lineage(focus)) : new Set<Frame>();\n  const rootTotal = root?.total ?? 0;\n  const hasHeader = title != null || description != null || actions != null;\n  const graphLabel = typeof title === \"string\" ? title : \"Flame graph\";\n  const activeInfo = activeFrame ? infoFor(activeFrame) : null;\n\n  return (\n    <div\n      ref={rootRef}\n      data-slot=\"flame-graph\"\n      data-orientation={orientation}\n      data-zoomed={zoomed || undefined}\n      data-searching={query ? true : undefined}\n      onKeyDown={(event) => {\n        onKeyDown?.(event);\n        if (event.key !== \"Escape\" || event.defaultPrevented || !zoomed) return;\n        if ((event.target as HTMLElement).tagName === \"INPUT\") return;\n        event.preventDefault();\n        zoomOut();\n      }}\n      className={cn(\n        \"@container/flame relative flex min-w-0 flex-col rounded-2xl border border-border/70 bg-card text-card-foreground shadow-[0_1px_2px_rgb(0_0_0/0.04),0_8px_24px_-12px_rgb(0_0_0/0.10)] dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.05),0_1px_2px_rgb(0_0_0/0.5)]\",\n        \"[--flame-tint-0:70%] [--flame-tint-1:54%] [--flame-tint-2:40%] dark:[--flame-tint-0:92%] dark:[--flame-tint-1:78%] dark:[--flame-tint-2:64%]\",\n        className,\n      )}\n      {...props}\n    >\n      <style href=\"overtrue-flame-graph\" precedence=\"default\">\n        {`[data-slot=flame-graph-frame]{left:max(0%,calc((var(--x0) - var(--flame-v0)) / var(--flame-vs) * 100%));width:max(0px,calc(min(100%,(var(--x1) - var(--flame-v0)) / var(--flame-vs) * 100%) - max(0%,(var(--x0) - var(--flame-v0)) / var(--flame-vs) * 100%) - 1px))}@keyframes flame-frame-in{from{opacity:0;clip-path:inset(0 100% 0 0)}to{clip-path:inset(0 0 0 0)}}`}\n      </style>\n\n      {hasHeader || rootTotal > 0 ? (\n        <div className=\"flex items-start justify-between gap-x-6 gap-y-3 px-5 pt-5\">\n          <div className=\"min-w-0 space-y-1\">\n            {title != null ? (\n              <h3 className=\"truncate text-sm leading-5 font-semibold tracking-tight\">\n                {title}\n              </h3>\n            ) : null}\n            {description != null ? (\n              <p\n                id={`${id}-description`}\n                className=\"text-[13px] leading-5 text-muted-foreground\"\n              >\n                {description}\n              </p>\n            ) : null}\n          </div>\n          <div className=\"flex shrink-0 items-start gap-3\">\n            {actions != null ? (\n              <div className=\"flex items-center gap-1\">{actions}</div>\n            ) : null}\n            {rootTotal > 0 ? (\n              <p\n                data-slot=\"flame-graph-total\"\n                className=\"flex flex-col items-end gap-0.5\"\n              >\n                <span className=\"text-xs leading-4 text-muted-foreground\">\n                  Total\n                </span>\n                <Figure\n                  text={format(rootTotal)}\n                  className=\"text-xl leading-6 font-semibold tracking-[-0.02em] tabular-nums\"\n                />\n              </p>\n            ) : null}\n          </div>\n        </div>\n      ) : null}\n\n      <div\n        data-slot=\"flame-graph-toolbar\"\n        className=\"flex min-h-7 flex-wrap items-center gap-x-3 gap-y-2 px-5 pt-4\"\n      >\n        {showSearch ? (\n          <div className=\"relative min-w-0 flex-1 @lg/flame:w-60 @lg/flame:flex-none\">\n            <IconSearch\n              aria-hidden=\"true\"\n              size={15}\n              className=\"pointer-events-none absolute top-1/2 left-2.5 -translate-y-1/2 text-muted-foreground\"\n            />\n            <input\n              type=\"search\"\n              data-slot=\"flame-graph-search\"\n              value={search}\n              onChange={(event) => setSearch(event.target.value)}\n              onKeyDown={(event) => {\n                if (event.key === \"Escape\" && search) {\n                  event.preventDefault();\n                  setSearch(\"\");\n                }\n              }}\n              placeholder={searchPlaceholder}\n              aria-label=\"Search frames\"\n              aria-describedby={query ? `${id}-matches` : undefined}\n              spellCheck={false}\n              autoComplete=\"off\"\n              className=\"h-8 w-full rounded-lg border border-input/80 bg-transparent pr-8 pl-8 font-mono text-xs shadow-[0_1px_1px_rgb(0_0_0/0.03)] outline-none transition-[border-color,box-shadow] placeholder:font-sans placeholder:text-[13px] placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 motion-reduce:transition-none [&::-webkit-search-cancel-button]:hidden\"\n            />\n            {search ? (\n              <button\n                type=\"button\"\n                aria-label=\"Clear search\"\n                onClick={() => setSearch(\"\")}\n                className=\"absolute top-1/2 right-1 inline-flex size-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50\"\n              >\n                <IconX aria-hidden=\"true\" size={13} />\n              </button>\n            ) : null}\n          </div>\n        ) : null}\n\n        {(query && matches) || zoomed ? (\n          <div className=\"order-2 flex min-w-0 basis-full flex-wrap items-center justify-between gap-x-4 gap-y-1 @lg/flame:order-1 @lg/flame:basis-0 @lg/flame:flex-1\">\n            {query && matches ? (\n              <p\n                id={`${id}-matches`}\n                data-slot=\"flame-graph-matches\"\n                className=\"text-xs text-muted-foreground tabular-nums\"\n              >\n                {matches.count > 0 ? (\n                  <>\n                    <span className=\"font-medium text-foreground\">\n                      {matches.count}\n                    </span>{\" \"}\n                    {matches.count === 1 ? \"match\" : \"matches\"}\n                    <span\n                      aria-hidden=\"true\"\n                      className=\"px-1.5 text-muted-foreground/50\"\n                    >\n                      ·\n                    </span>\n                    <span className=\"font-medium text-foreground\">\n                      {percent(matches.share)}\n                    </span>{\" \"}\n                    of total\n                  </>\n                ) : (\n                  \"No matches\"\n                )}\n              </p>\n            ) : (\n              <span />\n            )}\n            {zoomed && focus ? (\n              <p\n                data-slot=\"flame-graph-zoom\"\n                className=\"flex min-w-0 items-baseline gap-1.5 text-xs text-muted-foreground tabular-nums motion-safe:animate-[flame-fade_200ms_ease-out]\"\n              >\n                <span className=\"max-w-[12rem] truncate font-mono text-foreground\">\n                  {focus.name}\n                </span>\n                <span className=\"shrink-0\">\n                  {format(focus.total)} · {percent(focus.total / rootTotal)}\n                </span>\n              </p>\n            ) : null}\n          </div>\n        ) : null}\n\n        <button\n          type=\"button\"\n          data-slot=\"flame-graph-reset\"\n          className={cn(toolButton, \"order-1 ml-auto @lg/flame:order-2\")}\n          disabled={!zoomed}\n          onClick={(event) => {\n            if (event.detail === 0) pendingFocus.current = true;\n            commitZoom(null);\n          }}\n          title=\"Reset zoom\"\n        >\n          <IconZoomReset aria-hidden=\"true\" size={16} />\n          <span className=\"sr-only\">Reset zoom</span>\n        </button>\n      </div>\n\n      <div className=\"px-5 pt-3 pb-5\">\n        {root ? (\n          <div\n            ref={scrollRef}\n            className={cn(\n              \"relative\",\n              height != null && \"overflow-y-auto overscroll-contain\",\n            )}\n            style={height != null ? { maxHeight: height } : undefined}\n          >\n            <div\n              ref={canvasRef}\n              role=\"group\"\n              aria-roledescription=\"flame graph\"\n              aria-label={`${graphLabel}: ${model.count} frames. Arrow keys move between frames, Enter zooms in, Escape zooms out.`}\n              aria-describedby={\n                description != null ? `${id}-description` : undefined\n              }\n              data-slot=\"flame-graph-canvas\"\n              data-tweening={tween ? true : undefined}\n              className=\"relative w-full overflow-hidden\"\n              style={\n                {\n                  height: canvasHeight,\n                  \"--flame-v0\": initialView.v0,\n                  \"--flame-vs\": initialView.vs,\n                } as React.CSSProperties\n              }\n              onPointerMove={(event) => {\n                if (event.pointerType === \"touch\") return;\n                pointer.current = { x: event.clientX, y: event.clientY };\n                const frame = frameFromEvent(event);\n                const next = frame?.id ?? null;\n                if (next !== hoveredId) setHoveredId(next);\n                else placeTip();\n              }}\n              onPointerLeave={() => {\n                pointer.current = null;\n                setHoveredId(null);\n              }}\n              onClick={(event) => {\n                const frame = frameFromEvent(event);\n                if (frame) activate(frame, false);\n              }}\n              onKeyDown={onCanvasKeyDown}\n              onFocus={(event) => {\n                const frame = frameFromEvent(event);\n                if (!frame) return;\n                setTabStopId(frame.id);\n                const visible = (event.target as HTMLElement).matches(\n                  \":focus-visible\",\n                );\n                setFocusedId(visible ? frame.id : null);\n              }}\n              onBlur={(event) => {\n                if (!event.currentTarget.contains(event.relatedTarget as Node))\n                  setFocusedId(null);\n              }}\n            >\n              {rendered.map((frame) => {\n                const fill = colorMap.get(frame.id) ?? defaultPalette[0];\n                const ancestor = zoomed && focusChain.has(frame) && frame !== focus;\n                const match = matches?.ids.has(frame.id) ?? false;\n                const labelWide =\n                  labelFits(frame, pixelWidth(frame, target, measured)) ||\n                  (tween != null &&\n                    labelFits(frame, pixelWidth(frame, tween.from, measured)));\n                return (\n                  <FlameFrame\n                    key={frame.id}\n                    frame={frame}\n                    top={rowTop(frame.depth)}\n                    height={rowHeight - 1}\n                    fill={fill}\n                    label={labelWide}\n                    query={match ? query : \"\"}\n                    match={match}\n                    dimmed={matches != null && !match}\n                    ancestor={ancestor}\n                    zoomed={frame === focus && zoomed}\n                    active={frame.id === activeId}\n                    tabStop={frame.id === stopId}\n                    ariaLabel={describe(frame)}\n                    reveal={\n                      revealed ? null : Math.min(frame.depth, 16) * 34\n                    }\n                  />\n                );\n              })}\n            </div>\n          </div>\n        ) : (\n          <p className=\"grid h-28 place-items-center rounded-xl bg-muted/40 text-xs text-muted-foreground ring-1 ring-border/60 ring-inset\">\n            No samples to show.\n          </p>\n        )}\n      </div>\n\n      {topCount > 0 && topFunctions.length > 0 && focus ? (\n        <div\n          data-slot=\"flame-graph-top-functions\"\n          className=\"border-t border-border/60 px-5 pt-4 pb-5\"\n        >\n          <div className=\"mb-2.5 flex items-baseline justify-between gap-3\">\n            <h4 className=\"text-xs font-medium text-foreground\">\n              Top functions by self time\n            </h4>\n            <span className=\"truncate text-xs text-muted-foreground\">\n              {zoomed ? (\n                <>\n                  in <span className=\"font-mono\">{focus.name}</span>\n                </>\n              ) : (\n                \"Select one to search\"\n              )}\n            </span>\n          </div>\n          <ol className=\"grid gap-x-6 gap-y-0.5 @4xl/flame:grid-cols-2\">\n            {topFunctions.map((entry, index) => {\n              const share = entry.self / focus.total;\n              const lead = topFunctions[0].self || 1;\n              const pressed = search === entry.name;\n              const fill = colorMap.get(entry.sample.id) ?? defaultPalette[0];\n              return (\n                <li key={entry.name} className=\"min-w-0\">\n                  <button\n                    type=\"button\"\n                    data-slot=\"flame-graph-top-function\"\n                    aria-pressed={pressed}\n                    onClick={() => setSearch(pressed ? \"\" : entry.name)}\n                    className=\"group/top grid h-8 w-full grid-cols-[1rem_minmax(0,1fr)_4rem_3rem] items-center gap-2.5 rounded-lg px-2 text-left text-xs @md/flame:grid-cols-[1rem_minmax(0,1fr)_6rem_4.5rem_3.25rem] @md/flame:gap-3 @2xl/flame:grid-cols-[1rem_minmax(0,1fr)_12rem_4.5rem_3.25rem] outline-none transition-colors hover:bg-muted/70 focus-visible:ring-2 focus-visible:ring-ring/50 aria-pressed:bg-muted motion-reduce:transition-none\"\n                  >\n                    <span className=\"text-right text-[11px] text-muted-foreground tabular-nums\">\n                      {index + 1}\n                    </span>\n                    <span className=\"flex min-w-0 items-center gap-2\">\n                      <span\n                        aria-hidden=\"true\"\n                        className=\"size-2 shrink-0 rounded-[2px]\"\n                        style={{ backgroundColor: fill }}\n                      />\n                      <span className=\"truncate font-mono text-foreground\">\n                        {entry.name}\n                      </span>\n                      {entry.calls > 1 ? (\n                        <span className=\"shrink-0 text-[11px] text-muted-foreground tabular-nums\">\n                          ×{entry.calls}\n                        </span>\n                      ) : null}\n                    </span>\n                    <span\n                      aria-hidden=\"true\"\n                      className=\"relative hidden h-1.5 overflow-hidden rounded-full bg-muted @md/flame:block\"\n                    >\n                      <span\n                        className=\"absolute inset-y-0 left-0 rounded-full motion-safe:animate-[flame-bar-in_700ms_cubic-bezier(0.22,1,0.36,1)_backwards]\"\n                        style={{\n                          width: `${Math.max(4, (entry.self / lead) * 100)}%`,\n                          backgroundImage: `linear-gradient(to right, color-mix(in oklab, ${fill} 72%, transparent), ${fill})`,\n                          animationDelay: `${index * 30}ms`,\n                        }}\n                      />\n                    </span>\n                    <span className=\"text-right font-medium text-foreground tabular-nums\">\n                      {format(entry.self)}\n                    </span>\n                    <span className=\"text-right text-muted-foreground tabular-nums\">\n                      {percent(share)}\n                    </span>\n                  </button>\n                </li>\n              );\n            })}\n          </ol>\n        </div>\n      ) : null}\n\n      {activeFrame && activeInfo ? (\n        <div\n          ref={tipRef}\n          aria-hidden=\"true\"\n          data-slot=\"flame-graph-tooltip\"\n          data-for={activeFrame.id}\n          className=\"pointer-events-none absolute top-0 left-0 z-30 overflow-hidden rounded-xl border border-border/70 bg-popover/90 text-popover-foreground shadow-xl backdrop-blur-md\"\n        >\n          {renderTooltip ? (\n            renderTooltip(activeInfo)\n          ) : (\n            <DefaultTooltip info={activeInfo} format={format} />\n          )}\n        </div>\n      ) : null}\n\n      <p className=\"sr-only\" aria-live=\"polite\">\n        {zoomed && focus\n          ? `Zoomed to ${focus.name}, ${format(focus.total)}, ${percent(focus.total / rootTotal)} of total.`\n          : \"\"}\n        {query && matches\n          ? ` ${matches.count} ${matches.count === 1 ? \"match\" : \"matches\"}, ${percent(matches.share)} of total.`\n          : \"\"}\n      </p>\n      <style href=\"overtrue-flame-graph-motion\" precedence=\"default\">\n        {`@keyframes flame-fade{from{opacity:0}}@keyframes flame-bar-in{from{transform:scaleX(0);transform-origin:left}}`}\n      </style>\n    </div>\n  );\n}\n\nexport { FlameGraph };\n"
    }
  ],
  "docs": "Documentation: https://ui.overtrue.xyz/components/flame-graph. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
