{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "waterfall",
  "title": "Waterfall",
  "description": "A trace, or a page’s requests, as bars on one time axis: ui-sdk’s Waterfall, whose rows open to show the spans inside them. The span under the pointer stays bright while the rest step back, a pill glides along the axis to where it starts, and its tooltip and legend are the charts’.",
  "dependencies": [
    "@ui-sdk/react",
    "@ui-sdk/core"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/announce.json",
    "https://kinoui.com/r/chart-root.json",
    "https://kinoui.com/r/chart-math.json",
    "https://kinoui.com/r/collapsible.json",
    "https://kinoui.com/r/controllable.json",
    "https://kinoui.com/r/glide.json",
    "https://kinoui.com/r/highlight.json",
    "https://kinoui.com/r/list-rows.json",
    "https://kinoui.com/r/notice.json",
    "https://kinoui.com/r/placeholder.json",
    "https://kinoui.com/r/refs.json",
    "https://kinoui.com/r/roll.json",
    "https://kinoui.com/r/scroll.json",
    "https://kinoui.com/r/spinner.json",
    "https://kinoui.com/r/theme.json",
    "https://kinoui.com/r/tooltip.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/waterfall.tsx",
      "content": "'use client'\n\nimport {\n  CollapsibleIndicator,\n  collapsibleRowClassName,\n} from '@/registry/components/kino/collapsible'\nimport { useSpinner } from '@/registry/components/kino/spinner'\nimport { Tooltip } from '@/registry/components/kino/tooltip'\nimport { announce } from '@/registry/lib/announce'\nimport {\n  type ChartConfig,\n  type Span,\n  labelBox,\n  labelLength,\n  labelsMeet,\n  labelStep,\n} from '@/registry/lib/chart-math'\nimport {\n  type ChartFormat,\n  ChartLegendToggles,\n  ChartStyle,\n  ChartTooltipBox,\n  forcedSeriesColor,\n  stepBackInkClassName,\n  stepBackScopeClassName,\n  swatchClassName,\n  formatterOf,\n  seriesColor,\n  swatchStyle,\n  useEntered,\n} from '@/registry/lib/chart-root'\nimport { linearScale, tickCountFor } from '@/registry/lib/chart-scale'\nimport { useControllable } from '@/registry/lib/controllable'\nimport { GlideGroupMemory } from '@/registry/lib/glide'\nimport {\n  followPointer,\n  highlightStep,\n  type HighlightState,\n  type HighlightStep,\n  itemMatching,\n  pickedRowClassName,\n  rowHighlightClassName,\n  tintedRowTextClassName,\n} from '@/registry/lib/highlight'\nimport {\n  menuIndicatorClassName,\n  menuIndicatorSlot,\n  MenuTick,\n} from '@/registry/lib/list-rows'\nimport { NoticeGlyph } from '@/registry/lib/notice'\nimport {\n  placeholderBreatheClassName,\n  placeholderFillClassName,\n} from '@/registry/lib/placeholder'\nimport { markMounted, mergeRefs } from '@/registry/lib/refs'\nimport { Roll } from '@/registry/lib/roll'\nimport { edgeFadeClassName, followEdges } from '@/registry/lib/scroll'\nimport type { OptionsOf } from '@ui-sdk/core'\nimport {\n  visibleWaterfallRows,\n  waterfall,\n  type WaterfallBarLabelDetails,\n  type WaterfallDataItem,\n} from '@ui-sdk/core/waterfall'\nimport { type PrimitiveHandle, usePart, usePrimitive } from '@ui-sdk/react/primitive'\nimport {\n  WaterfallAxis as WaterfallAxisPrimitive,\n  WaterfallBar as WaterfallBarPrimitive,\n  WaterfallColumnHeader as WaterfallColumnHeaderPrimitive,\n  WaterfallHeaderRow as WaterfallHeaderRowPrimitive,\n  WaterfallIndicator as WaterfallIndicatorPrimitive,\n  WaterfallRow as WaterfallRowPrimitive,\n  WaterfallRowHeader as WaterfallRowHeaderPrimitive,\n  WaterfallTick as WaterfallTickPrimitive,\n} from '@ui-sdk/react/waterfall'\nimport {\n  type ComponentProps,\n  createContext,\n  Fragment,\n  type CSSProperties,\n  use,\n  useCallback,\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useMemo,\n  useRef,\n  useState,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * A trace, or a page's requests, as bars on one time axis: ui-sdk's\n * Waterfall, a treegrid that owns the rows' keys, focus, selection and\n * what opens. Kino draws it as the Bar chart's sibling: the span under the\n * pointer or the focus stays bright while the rest step back, a pill glides\n * along the axis to where it starts, and a tooltip and a legend read as the\n * charts'. A span opens to show the spans inside it, which unfold under a\n * rail from its chevron and draw in the order they ran.\n */\n\n/** One span: ui-sdk's, with its kind, which colours its bar, and whether it failed. */\ninterface WaterfallItem extends Omit<WaterfallDataItem, 'children'> {\n  /** Its kind, a key of the Waterfall's `config`. */\n  kind?: string\n  /** It failed: `true`, or what went wrong, which its tooltip shows. */\n  error?: string | boolean\n  /** The spans it started. */\n  children?: WaterfallItem[]\n}\n\n/** What the Waterfall writes, for a page in another language. */\ninterface WaterfallMessages {\n  /** The heading over the spans' names. */\n  span: string\n  /** The heading over their durations. */\n  duration: string\n  /** The name of the column the bars are in. */\n  timeline: string\n  starts: string\n  /** Said of a span that failed, after its times. */\n  failed: string\n  /** The legend's name. */\n  kinds: string\n  empty: string\n  loading: string\n  loaded: string\n  /** How a span's times are read: when it starts and how long it lasts. */\n  times: (start: string, duration: string) => string\n}\n\nconst defaultMessages: WaterfallMessages = {\n  span: 'Span',\n  duration: 'Duration',\n  timeline: 'Timeline',\n  starts: 'Starts',\n  failed: 'Failed',\n  kinds: 'Services',\n  empty: 'No spans to show',\n  loading: 'Loading spans',\n  loaded: 'Spans loaded',\n  times: (start, duration) => `starts at ${start}, lasts ${duration}`,\n}\n\nconst defaultFormat: ChartFormat = {\n  style: 'unit',\n  unit: 'millisecond',\n  maximumFractionDigits: 1,\n}\n\n/** A span with the value of the span it sits in, or null at the top. */\ninterface Placed {\n  item: WaterfallItem\n  up: string | null\n}\n\ninterface WaterfallContextValue {\n  id: string\n  handle: PrimitiveHandle<typeof waterfall>\n  items: readonly WaterfallItem[]\n  /** Every span, by `value`, in the order the rows show. */\n  spans: ReadonlyMap<string, Placed>\n  config: ChartConfig\n  kinds: readonly string[]\n  write: (value: number) => string\n  hidden: readonly string[]\n  setHidden: (hidden: string[]) => void\n  emphasis: string | null\n  setEmphasis: (kind: string | null) => void\n  messages: WaterfallMessages\n  /** Each span's bar, for the tooltip. */\n  bars: Map<string, HTMLElement>\n  setActive: (value: string | null) => void\n  setTrackWidth: (width: number) => void\n}\n\nconst WaterfallContext = createContext<WaterfallContextValue | null>(null)\n\nfunction useWaterfall() {\n  const context = use(WaterfallContext)\n  if (!context) throw new Error('Waterfall parts go inside a `Waterfall`.')\n  return context\n}\n\n/**\n * What changes as the pointer moves, apart from what the rows read, so a\n * span lit or the axis measured re-renders only the axis and the tooltip.\n */\nconst WaterfallActiveContext = createContext<{\n  /** The span under the pointer, the focus or the last touch. */\n  active: string | null\n  /** How wide the bars' column is, in pixels; 0 before it is measured. */\n  trackWidth: number\n}>({ active: null, trackWidth: 0 })\n\n/** The stretch of time the axis shows, from ui-sdk's root. */\nconst RangeContext = createContext<Span>([0, 0])\n\n/**\n * How many ticks the axis marks at most. ui-sdk rounds its step up from the\n * room each tick gets, so it marks about half this many on a long axis.\n */\nconst TICKS = 10\n/** The least room a tick's label needs, in pixels. */\nconst TICK_SPACING = 64\n\ntype WaterfallProps = Omit<OptionsOf<typeof waterfall>, 'items' | 'format' | 'locale'> &\n  Omit<ComponentProps<'div'>, 'defaultValue' | 'onChange' | 'onSelect'> & {\n    /** The spans, each with a `value`, a `label`, a `start`, a `duration`, a `kind` and the spans it started as `children`. */\n    items: WaterfallItem[]\n    /** Each kind of span by its `kind`: its name and colour, as a chart's series. */\n    config?: ChartConfig\n    /** How times are written: in milliseconds by default. */\n    format?: ChartFormat\n    locale?: string\n    /**\n     * How the bars come in when the Waterfall first comes into view: drawn\n     * from their starts in the order the spans ran, or already there, as a\n     * page that loads doesn't animate into place.\n     */\n    entrance?: 'cascade' | 'none'\n    /** The kinds whose bars are hidden, by key, when you hold the state. */\n    hiddenKinds?: string[]\n    defaultHiddenKinds?: string[]\n    onHiddenKindsChange?: (hidden: string[]) => void\n    messages?: Partial<WaterfallMessages>\n  }\n\n/**\n * The trace: ui-sdk's Waterfall, which holds the spans, which are open and\n * which is picked, with the colour of each kind of span and how times are\n * written. Holds a `WaterfallLegend`, a `WaterfallList` and a\n * `WaterfallTooltip`.\n */\nfunction Waterfall({\n  items,\n  range,\n  value,\n  defaultValue,\n  onValueChange,\n  expanded,\n  defaultExpanded,\n  onExpandedChange,\n  onHighlight,\n  getBarLabel,\n  controller,\n  debug,\n  config = {},\n  format = defaultFormat,\n  locale,\n  entrance = 'none',\n  hiddenKinds,\n  defaultHiddenKinds = [],\n  onHiddenKindsChange,\n  messages: ownMessages,\n  className,\n  children,\n  ref,\n  ...props\n}: WaterfallProps) {\n  const id = `waterfall-${useId().replace(/[^a-zA-Z0-9-]/g, '')}`\n  const rootRef = useRef<HTMLDivElement>(null)\n  const refs = useMemo(() => mergeRefs(rootRef, ref, markMounted), [ref])\n  const kinds = useMemo(() => Object.keys(config), [config])\n  const [hidden, setHiddenNow] = useControllable(\n    hiddenKinds,\n    defaultHiddenKinds,\n    onHiddenKindsChange,\n  )\n  // One function for the life of the Waterfall, so the rows' context holds still as the\n  // pointer moves; it always calls the latest setter.\n  const setHiddenRef = useRef(setHiddenNow)\n  useLayoutEffect(() => {\n    setHiddenRef.current = setHiddenNow\n  })\n  const setHidden = useCallback((next: string[]) => setHiddenRef.current(next), [])\n  const [emphasis, setEmphasis] = useState<string | null>(null)\n  const [active, setActive] = useState<string | null>(null)\n  const [width, setWidth] = useState(0)\n  const entered = useEntered(rootRef, entrance === 'none')\n  const [bars] = useState(() => new Map<string, HTMLElement>())\n  const messages = useMemo(() => ({ ...defaultMessages, ...ownMessages }), [ownMessages])\n  const write = useMemo(() => formatterOf(locale, format), [format, locale])\n  const spans = useMemo(() => placeAll(items), [items])\n  const handle = usePrimitive(waterfall, {\n    items,\n    range,\n    value,\n    defaultValue,\n    onValueChange,\n    expanded,\n    defaultExpanded,\n    onExpandedChange,\n    onHighlight,\n    format,\n    locale,\n    // What a screen reader hears on a bar: its kind, its times and what went wrong.\n    getBarLabel:\n      getBarLabel ??\n      ((item, times) => barLabel(spans.get(item.value)?.item, times, config, messages)),\n    controller,\n    debug,\n  })\n  const context = useMemo(\n    () => ({\n      id,\n      handle,\n      items,\n      spans,\n      config,\n      kinds,\n      write,\n      hidden,\n      setHidden,\n      emphasis,\n      setEmphasis,\n      messages,\n      bars,\n      setActive,\n      setTrackWidth: setWidth,\n    }),\n    [\n      id,\n      handle,\n      items,\n      spans,\n      config,\n      kinds,\n      write,\n      hidden,\n      setHidden,\n      emphasis,\n      messages,\n      bars,\n    ],\n  )\n  const live = useMemo(() => ({ active, trackWidth: width }), [active, width])\n\n  return (\n    <WaterfallContext value={context}>\n      <WaterfallActiveContext value={live}>\n        <ChartStyle id={id} config={config} series={kinds} />\n        <div\n          ref={refs}\n          data-waterfall=''\n          data-chart={id}\n          data-entered={entered ? '' : undefined}\n          className={cn(\n            'group/waterfall @container/waterfall flex min-w-0 flex-col bg-inherit text-sm',\n            className,\n          )}\n          {...props}\n        >\n          {children}\n        </div>\n      </WaterfallActiveContext>\n    </WaterfallContext>\n  )\n}\n\n/** Every span by its value, in the order its row shows, with the span it sits in. */\nfunction placeAll(items: readonly WaterfallItem[]) {\n  const spans = new Map<string, Placed>()\n  const visit = (list: readonly WaterfallItem[], up: string | null) => {\n    for (const item of list) {\n      spans.set(item.value, { item, up })\n      if (item.children) visit(item.children, item.value)\n    }\n  }\n  visit(items, null)\n  return spans\n}\n\n/** A bar's name for a screen reader: its kind, when it starts and how long it lasts, and what went wrong. */\nfunction barLabel(\n  item: WaterfallItem | undefined,\n  { start, duration }: WaterfallBarLabelDetails,\n  config: ChartConfig,\n  messages: WaterfallMessages,\n) {\n  const kind = item?.kind\n  const error = item?.error\n  const kindName = kind === undefined ? undefined : config[kind]?.label\n  return [\n    kind === undefined ? null : typeof kindName === 'string' ? kindName : kind,\n    messages.times(start, duration),\n    error === undefined || error === false\n      ? null\n      : error === true\n        ? messages.failed\n        : `${messages.failed}: ${error}`,\n  ]\n    .filter((part) => part !== null)\n    .join(', ')\n}\n\n/**\n * A toggle for each kind of span, as the charts' legend: off, its bars keep\n * only their outline, so the rest read on their own. Pointing at one brings\n * its spans forward.\n */\nfunction WaterfallLegend({\n  className,\n  ...props\n}: Omit<ComponentProps<'div'>, 'children'>) {\n  const { kinds, config, hidden, setHidden, setEmphasis, messages } = useWaterfall()\n  return (\n    <div\n      data-waterfall-legend=''\n      role='group'\n      aria-label={messages.kinds}\n      className={cn('flex flex-wrap items-center gap-x-1 gap-y-0.5 pb-3', className)}\n      {...props}\n    >\n      <ChartLegendToggles\n        series={kinds}\n        labelOf={(kind) => config[kind]?.label ?? kind}\n        patternOf={() => 'solid'}\n        hidden={hidden}\n        onHiddenChange={setHidden}\n        onEmphasisChange={setEmphasis}\n      />\n    </div>\n  )\n}\n\n/**\n * The bars' column: as wide as the row allows past the names' room, so every\n * row's bar starts at the same place whatever its depth. The rows and the\n * axis measure it against the list, the container they share.\n */\nconst trackClassName =\n  'relative shrink-0 w-[max(50cqw,calc(100cqw-var(--waterfall-name-width,24rem)))]'\n\n/**\n * In a narrow list the bars take a line of their own under the names, as wide\n * as the list less the tick's room. Each row's line starts at its depth, so\n * it reaches back by as much to line up with the axis.\n */\nconst narrowTrackClassName =\n  '@max-lg/rows:h-3 @max-lg/rows:w-[calc(100cqw-2*var(--control-padding)-1.5rem)] @max-lg/rows:ms-[calc((var(--waterfall-level)-1)*var(--waterfall-indent)*-1)]'\n\n/** The axis and the grid in a narrow list: the bars' column alone, as wide as the rows'. */\nconst narrowColumnClassName = '@max-lg:w-[calc(100cqw-2*var(--control-padding)-1.5rem)]'\n\n/**\n * The gap above a row, folding with it: a gap between the rows would stay\n * until a folded row leaves, and the rows under it would then jump up.\n */\nconst rowGapClassName =\n  'h-px shrink-0 transition-[height] duration-(--motion-layout-duration) ease-(--motion-layout-easing) motion-reduce:transition-none [&:has(+[hidden])]:h-0'\n\n/** A span's row. */\nconst rowSelector = '[data-slot=waterfall-row]'\n\n/** The span a row, or anything in one, belongs to. */\nfunction spanOf(node: Element | null) {\n  return node?.closest<HTMLElement>('[data-span]')?.dataset.span ?? null\n}\n\n/** The room the row keeps for the tick of a picked row, so the axis lines up with the bars. */\nconst tickRoomClassName = 'size-4 shrink-0'\n\n/**\n * The spans under a time axis that stays in view as they scroll: ui-sdk's\n * treegrid, with a row for every span in the Waterfall's `items`. Give it a\n * height (`max-h-96`) to scroll a long trace. `className` and `style` go to\n * its box, the rest to ui-sdk's root, which needs a name (`aria-label`).\n */\nfunction WaterfallList({\n  className,\n  style,\n  loading = false,\n  ...props\n}: Omit<ComponentProps<'div'>, 'children'> & {\n  /** Shows a placeholder while the spans load, after a moment, and for long enough to read. */\n  loading?: boolean\n}) {\n  const { handle, items, spans, messages, setActive, bars } = useWaterfall()\n  const boxRef = useRef<HTMLDivElement>(null)\n  const scrollerRef = useRef<HTMLDivElement>(null)\n  const rowsRef = useRef<HTMLDivElement>(null)\n  const layerRef = useRef<HTMLSpanElement>(null)\n  const waiting = useSpinner(loading)\n  const hasSpans = items.length > 0\n\n  useEffect(() => {\n    const scroller = scrollerRef.current\n    if (!scroller) return\n    const box = boxRef.current\n    const stopEdges = followEdges(scroller, '--scroll-fade')\n    // The room the scrollbar takes, which the axis keeps clear: none where scrollbars float.\n    const gutter = () =>\n      box?.style.setProperty(\n        '--waterfall-gutter',\n        `${scrollbarRoom(scroller.offsetWidth, scroller.clientWidth)}px`,\n      )\n    gutter()\n    const resized = new ResizeObserver(gutter)\n    resized.observe(scroller)\n    if (scroller.firstElementChild) resized.observe(scroller.firstElementChild)\n    return () => {\n      stopEdges()\n      resized.disconnect()\n    }\n  }, [])\n\n  const wasWaiting = useRef(waiting)\n  useEffect(() => {\n    if (waiting === wasWaiting.current) return\n    wasWaiting.current = waiting\n    announce(waiting ? messages.loading : hasSpans ? messages.loaded : messages.empty)\n  })\n\n  // One highlight for every row, so it glides from row to row.\n  useEffect(() => {\n    const rows = rowsRef.current\n    const layer = layerRef.current\n    if (!rows || !layer) return\n    return followPointer(rows, layer, {\n      itemOf: itemMatching(rows, rowSelector),\n      focus: true,\n    })\n  }, [waiting])\n\n  // The spans a span shows as it opens draw in the order they ran inside it, its open children\n  // with them, where those there from the start draw in the order they ran in the trace.\n  useEffect(() => {\n    const rows = rowsRef.current\n    if (!rows) return\n    const { instance } = handle\n    const showing = (expanded: readonly string[]) =>\n      new Set(visibleWaterfallRows(items, [...expanded]).map((row) => row.item.value))\n    let shown = showing(instance.get().expanded)\n    return instance.subscribe(() => {\n      const now = showing(instance.get().expanded)\n      for (const value of now) {\n        if (shown.has(value)) continue\n        const row = rows.querySelector<HTMLElement>(`[data-span=\"${CSS.escape(value)}\"]`)\n        const opened = spans.get(\n          openedBy(value, (key) => spans.get(key)?.up ?? null, shown) ?? '',\n        )\n        const start = spans.get(value)?.item.start\n        if (!row || !opened || start === undefined) continue\n        const { item } = opened\n        row.style.setProperty(\n          '--waterfall-at-opened',\n          `${fractionOf(start, [item.start, item.start + item.duration])}`,\n        )\n        row.setAttribute('data-revealed', '')\n      }\n      shown = now\n    })\n  }, [handle, items, spans, waiting])\n\n  // The span lit for the tooltip, the pill and Spotlight: the one the highlight is on, or else\n  // the one last pressed by touch, which has no highlight. None while it has scrolled out of sight.\n  useEffect(() => {\n    const scroller = scrollerRef.current\n    const rows = rowsRef.current\n    if (!scroller || !rows) return\n    let glided: string | null = null\n    let touched: string | null = null\n    const sync = () => {\n      const lit = glided ?? touched\n      const bar = lit === null ? null : (bars.get(lit) ?? null)\n      const view = scroller.getBoundingClientRect()\n      const seen =\n        bar !== null &&\n        bar.getClientRects().length > 0 &&\n        inSight(bar.getBoundingClientRect(), view.top, view.bottom)\n      const next = seen ? lit : null\n      // Spotlight reads the lit row from the page, so no row re-renders as the pointer moves.\n      const litRow = next === null ? null : (bar?.closest(rowSelector) ?? null)\n      for (const row of rows.querySelectorAll('[data-lit]')) {\n        if (row !== litRow) row.removeAttribute('data-lit')\n      }\n      litRow?.setAttribute('data-lit', '')\n      // Set here rather than found with `:has()`, which would restyle every bar on each move.\n      rows.toggleAttribute('data-spotlit', next !== null)\n      setActive(next)\n    }\n    const observer = new MutationObserver(() => {\n      glided = spanOf(rows.querySelector(`${rowSelector}[data-glided]`))\n      sync()\n    })\n    observer.observe(rows, { subtree: true, attributeFilter: ['data-glided', 'hidden'] })\n    const press = (event: PointerEvent) => {\n      if (event.pointerType !== 'touch') return\n      touched =\n        event.target instanceof Element && rows.contains(event.target)\n          ? spanOf(event.target)\n          : null\n      sync()\n    }\n    document.addEventListener('pointerdown', press)\n    scroller.addEventListener('scroll', sync, { passive: true })\n    return () => {\n      observer.disconnect()\n      document.removeEventListener('pointerdown', press)\n      scroller.removeEventListener('scroll', sync)\n      setActive(null)\n    }\n  }, [setActive, bars, waiting])\n\n  const root = usePart(\n    handle,\n    'root',\n    {},\n    {\n      ...props,\n      className: 'flex min-h-0 flex-1 flex-col',\n      children: ({ range }: { range: [number, number] }) => (\n        <RangeContext value={range}>\n          {/* The axis sits over the box that scrolls, not in it, so it needs no background of\n              its own to hide the rows, whatever the Waterfall sits on. It keeps the scrollbar's\n              room at its end, so its column lines up with the rows'. */}\n          <WaterfallHeader />\n          <div\n            ref={scrollerRef}\n            data-waterfall-scroller=''\n            className={cn(\n              'scrollbar-thin relative min-h-0 flex-1 overflow-y-auto overscroll-contain',\n              edgeFadeClassName,\n            )}\n          >\n            {/* While a span is lit, every other bar steps back; the lit row sets it back to 0. */}\n            <div className='@container/rows relative min-w-0'>\n              {/* The ticks' lines down the rows: the axis again, drawn as lines, so the first\n                  paint has them too. */}\n              <WaterfallGrid hidden={waiting || (!hasSpans && !loading)} />\n              {waiting ? (\n                <WaterfallPlaceholder />\n              ) : (\n                <div\n                  ref={rowsRef}\n                  className={cn(\n                    'relative isolate flex min-w-0 flex-col data-spotlit:[--mark-step:1]',\n                    // A deeper span steps in, less so in a narrow list.\n                    '[--waterfall-indent:1.5rem] @max-xs/rows:[--waterfall-indent:1rem]',\n                    stepBackScopeClassName,\n                  )}\n                >\n                  {[...spans.values()].map(({ item, up }, at) => (\n                    <Fragment key={item.value}>\n                      {at > 0 && <span aria-hidden className={rowGapClassName} />}\n                      <WaterfallSpanRow item={item} up={up} />\n                    </Fragment>\n                  ))}\n                  <span\n                    ref={layerRef}\n                    aria-hidden\n                    data-waterfall-highlight=''\n                    className={rowHighlightClassName}\n                  />\n                </div>\n              )}\n              {/* Loading with no spans yet is loading, never empty, while the placeholder waits to show. */}\n              {!hasSpans && !loading && (\n                <div className='text-muted-foreground px-(--control-padding) py-8 text-center'>\n                  {messages.empty}\n                </div>\n              )}\n            </div>\n          </div>\n        </RangeContext>\n      ),\n    },\n    'div',\n  )\n\n  return (\n    <div\n      ref={boxRef}\n      data-waterfall-list=''\n      className={cn('flex min-h-0 flex-col overflow-hidden', className)}\n      style={style}\n    >\n      {root}\n    </div>\n  )\n}\n\n/** The columns every row shares: the names, the bars, the tick's room. */\nconst columnsClassName = 'flex gap-2 px-(--control-padding)'\n\n/**\n * The header: the names' and durations' headings, and the time axis over\n * the bars, with a label at each tick and a pill that glides to where the\n * span under the pointer starts, the labels it would cover stepping aside.\n */\nfunction WaterfallHeader() {\n  const { messages, setTrackWidth } = useWaterfall()\n  const trackRef = useRef<HTMLDivElement>(null)\n\n  useLayoutEffect(() => {\n    const track = trackRef.current\n    if (!track) return\n    const observer = new ResizeObserver(([entry]) => {\n      if (entry) setTrackWidth(entry.contentRect.width)\n    })\n    observer.observe(track)\n    return () => observer.disconnect()\n  }, [setTrackWidth])\n\n  return (\n    // The container holds no padding, so its columns are as wide as the rows' below.\n    <div className='@container min-w-0 shrink-0 border-b me-(--waterfall-gutter,0px)'>\n      <WaterfallHeaderRowPrimitive\n        className={cn(\n          columnsClassName,\n          'text-muted-foreground h-(--control-height) items-center text-xs',\n        )}\n      >\n        <WaterfallColumnHeaderPrimitive className='flex min-w-0 flex-1 items-center gap-2 font-medium @max-lg:sr-only'>\n          <span data-waterfall-heading='' className='flex-1 truncate ps-6'>\n            {messages.span}\n          </span>\n          {/* The durations sit in the names' cells, so only the column's name is read. */}\n          <span aria-hidden className='shrink-0'>\n            {messages.duration}\n          </span>\n        </WaterfallColumnHeaderPrimitive>\n        <WaterfallColumnHeaderPrimitive\n          ref={trackRef}\n          className={cn(\n            trackClassName,\n            narrowColumnClassName,\n            '@container/track self-stretch',\n          )}\n        >\n          {/* A column's name is its text, which the ticks drawn over it aren't. */}\n          <span className='sr-only'>{messages.timeline}</span>\n          <WaterfallAxisPrimitive className='absolute inset-0 rtl:[--waterfall-flip:-1] [&>*]:absolute [&>*]:top-1/2'>\n            <WaterfallTicks />\n          </WaterfallAxisPrimitive>\n        </WaterfallColumnHeaderPrimitive>\n        <span aria-hidden className={tickRoomClassName} />\n      </WaterfallHeaderRowPrimitive>\n    </div>\n  )\n}\n\n/** Where a fraction of the axis sits, kept inside it, for a label of its own width. */\nfunction placeAt(fraction: number): CSSProperties {\n  return {\n    insetInlineStart: 0,\n    // The y half is here too: an inline `translate` overrides a class's.\n    translate: `calc(var(--waterfall-flip, 1) * clamp(0px, ${fraction * 100}cqw - 50%, 100cqw - 100%)) -50%`,\n  }\n}\n\n/** The axis's labels and its pill. */\nfunction WaterfallTicks() {\n  const { spans, write } = useWaterfall()\n  const { active, trackWidth } = use(WaterfallActiveContext)\n  const range = use(RangeContext)\n  const ticks = useTicks()\n  const start = active === null ? null : (spans.get(active)?.item.start ?? null)\n  // The pill appears where it is going when it had gone, glides from span to span, and fades\n  // where it is, by the highlight's own steps: brought back while it fades, it glides on.\n  const [pill, setPill] = useState<{\n    state: HighlightState\n    step: HighlightStep\n    at: number | null\n    /** Which way its number rolls: up for a later start, down for an earlier one. */\n    trend: number\n    /** Counts its appearances, so a number that appears in place starts at rest. */\n    shows: number\n  }>({ state: 'hidden', step: 'stay', at: null, trend: 1, shows: 0 })\n  const [seen, setSeen] = useState(start)\n  if (seen !== start) {\n    setSeen(start)\n    const [state, step] = highlightStep(pill.state, start === null ? 'none' : 'item')\n    setPill({\n      state,\n      step,\n      at: start ?? pill.at,\n      trend:\n        start === null || pill.at === null ? pill.trend : Math.sign(start - pill.at) || 1,\n      shows: step === 'appear' ? pill.shows + 1 : pill.shows,\n    })\n  }\n  const faded = () => {\n    const [state, step] = highlightStep(pill.state, 'faded')\n    if (state !== pill.state) setPill({ ...pill, state, step })\n  }\n\n  const shown = pill.state === 'shown'\n  const pillAt = pill.at === null ? null : fractionOf(pill.at, range)\n  const pillText = pill.at === null ? '' : write(pill.at)\n  // Every few ticks keep a label when they all would crowd.\n  const every = labelStep(\n    ticks.length,\n    trackWidth,\n    Math.max(...ticks.map((tick) => labelLength(tick.label))) + 8,\n  )\n  const covered = (tick: { label: string; position: number }) =>\n    shown &&\n    pillAt !== null &&\n    tickCovered(\n      tick.position / 100,\n      labelLength(tick.label),\n      pillAt,\n      labelLength(pillText),\n      trackWidth,\n    )\n\n  return (\n    <>\n      {/* No labels until the axis is measured, so none fade out on load. */}\n      {trackWidth > 0 &&\n        ticks.map((tick, at) => (\n          <WaterfallTickPrimitive\n            key={tick.time}\n            time={tick.time}\n            data-covered={covered(tick) || at % every !== 0 ? '' : undefined}\n            className='px-0.5 tabular-nums transition-opacity duration-(--motion-layout-duration) ease-(--motion-layout-easing) data-covered:opacity-0'\n            style={placeAt(tick.position / 100)}\n          >\n            <bdi>{tick.label}</bdi>\n          </WaterfallTickPrimitive>\n        ))}\n      <span\n        data-waterfall-pill=''\n        data-shown={shown ? '' : undefined}\n        data-instant={pill.step === 'appear' ? '' : undefined}\n        onTransitionEnd={(event) => {\n          if (event.propertyName === 'opacity' && pill.state === 'fading') faded()\n        }}\n        className='bg-foreground text-background rounded-(--control-radius-xs) px-1.5 py-0.5 font-medium tabular-nums opacity-0 [transition:opacity_var(--motion-exit-duration)_var(--motion-exit-easing),translate_var(--motion-layout-duration)_var(--motion-layout-easing)] data-instant:[transition:opacity_var(--motion-enter-duration)_var(--motion-enter-easing)] data-shown:opacity-100 motion-reduce:[transition:opacity_var(--motion-exit-duration)_var(--motion-exit-easing)] forced-colors:bg-[Highlight] forced-colors:text-[HighlightText] forced-colors:forced-color-adjust-none'\n        style={pillAt === null ? undefined : placeAt(pillAt)}\n      >\n        {pill.at !== null && (\n          <bdi>\n            <Roll key={pill.shows} value={pillText} trend={pill.trend} />\n          </bdi>\n        )}\n      </span>\n    </>\n  )\n}\n\n/**\n * The axis's round times, across the whole range to its end, as many as the\n * track has room for. ui-sdk's stop a step short of the end, which leaves\n * the last stretch of a trace with no line.\n */\nfunction useTicks() {\n  const { write } = useWaterfall()\n  const { trackWidth } = use(WaterfallActiveContext)\n  const range = use(RangeContext)\n  return useMemo(\n    () =>\n      linearScale(range, {\n        domain: range,\n        tickCount: tickCountFor(TICKS, trackWidth, TICK_SPACING),\n      }).ticks.map((time) => ({\n        time,\n        label: write(time),\n        position: fractionOf(time, range) * 100,\n      })),\n    [range, trackWidth, write],\n  )\n}\n\n/** The lines down the bars' column at each tick, behind the rows. */\nfunction WaterfallGrid({ hidden }: { hidden: boolean }) {\n  const ticks = useTicks()\n  return (\n    <div\n      hidden={hidden}\n      className={cn(columnsClassName, 'pointer-events-none absolute inset-0')}\n    >\n      <div className='flex min-w-0 flex-1 @max-lg:hidden' />\n      <WaterfallAxisPrimitive className={cn(trackClassName, narrowColumnClassName)}>\n        {ticks.map((tick) => (\n          <span\n            key={tick.time}\n            data-edge={tick.position === 0 ? '' : undefined}\n            className='border-border absolute inset-y-0 border-s border-dashed data-edge:border-solid forced-colors:border-[GrayText]'\n            style={{ insetInlineStart: `${tick.position}%` }}\n          />\n        ))}\n      </WaterfallAxisPrimitive>\n      <span className={tickRoomClassName} />\n    </div>\n  )\n}\n\n/** Rows that wait for the spans: a name and a bar each, stepping on as a trace would. */\nfunction WaterfallPlaceholder() {\n  const rows = [\n    [0, 0.92, 9],\n    [0.04, 0.2, 7],\n    [0.08, 0.1, 6],\n    [0.26, 0.42, 8],\n    [0.3, 0.16, 5],\n    [0.7, 0.22, 7],\n  ] as const\n  return (\n    <div\n      aria-hidden\n      data-waterfall-placeholder=''\n      className={placeholderBreatheClassName}\n    >\n      {rows.map(([from, size, name], at) => (\n        <div\n          key={at}\n          className={cn(\n            columnsClassName,\n            'min-h-(--control-height) items-center @max-lg:flex-wrap @max-lg:gap-y-1 @max-lg:py-2',\n          )}\n        >\n          <div className='flex min-w-0 flex-1 items-center gap-2 @max-lg:basis-full'>\n            <span\n              className={cn('h-2 rounded-full', placeholderFillClassName)}\n              style={{\n                width: `${name}ch`,\n                marginInlineStart: at === 0 ? 0 : '1.5rem',\n              }}\n            />\n          </div>\n          <div className={cn(trackClassName, narrowColumnClassName)}>\n            <span\n              className={cn(\n                'absolute top-1/2 h-2.5 -translate-y-1/2 rounded-[min(var(--waterfall-radius,var(--control-radius-xs)),0.625rem*var(--mark-radius-share))]',\n                placeholderFillClassName,\n              )}\n              style={{\n                insetInlineStart: `${from * 100}%`,\n                width: `${size * 100}%`,\n              }}\n            />\n          </div>\n          <span className={tickRoomClassName} />\n        </div>\n      ))}\n    </div>\n  )\n}\n\n/** The corner of a bar, never past `--mark-radius-share` of its thickness, `h-2.5`. */\nconst barRadius =\n  'min(var(--waterfall-radius,var(--control-radius-xs)),0.625rem*var(--mark-radius-share))'\n\n/** A row that takes focus: the controls' ring, inside it, as rows sit edge to edge. */\nconst focusRingClassName =\n  'ring-ring/50 focus-visible:ring-3 focus-visible:outline-hidden ring-inset forced-colors:focus-visible:outline-2 forced-colors:focus-visible:-outline-offset-2 forced-colors:focus-visible:outline-[CanvasText] forced-colors:focus-visible:outline-solid'\n\n/**\n * A cell that takes focus, as Right moves into a row: the same ring, on the\n * cell's own `:focus-visible` alone, so a state that holds the row's ring\n * (a page showing every state at once) leaves its cells without one.\n */\nconst cellFocusRingClassName =\n  'ring-ring/50 [&:focus-visible]:ring-3 [&:focus-visible]:outline-hidden ring-inset forced-colors:[&:focus-visible]:outline-2 forced-colors:[&:focus-visible]:-outline-offset-2 forced-colors:[&:focus-visible]:outline-[CanvasText] forced-colors:[&:focus-visible]:outline-solid'\n\n/**\n * One span's row: ui-sdk's row, as deep as the span, with the rail of each\n * span it sits in, its name and duration, its bar, and the tick of a picked\n * row. It unfolds on `layout` as the span it sits in opens.\n */\nfunction WaterfallSpanRow({ item }: Placed) {\n  const { kinds, hidden, emphasis, write, bars } = useWaterfall()\n  const range = use(RangeContext)\n  const { value, kind, error, start, duration } = item\n  const failed = error !== undefined && error !== false\n  const slot = kind === undefined ? -1 : kinds.indexOf(kind)\n  const bar = useCallback(\n    (element: HTMLElement | null) => {\n      if (element) bars.set(value, element)\n      else bars.delete(value)\n    },\n    [bars, value],\n  )\n\n  return (\n    <WaterfallRowPrimitive\n      value={value}\n      data-span={value}\n      className={cn(\n        'group/collapsible-trigger relative grid min-w-0 grid-rows-[1fr] rounded-(--control-radius-capped) select-none',\n        // Indented by its depth, so its highlight and its tint start where its name does.\n        'ms-[calc((var(--waterfall-level)-1)*var(--waterfall-indent))]',\n        // It unfolds as the span it sits in opens and folds as it closes, never on load.\n        // Less motion: it fades where it stands, and its colours still fade.\n        '[transition:grid-template-rows_var(--motion-layout-duration)_var(--motion-layout-easing),opacity_var(--motion-layout-duration)_var(--motion-layout-easing),display_var(--motion-layout-duration)_allow-discrete,color_var(--motion-press-duration)_var(--motion-press-fade-easing),background-color_var(--motion-press-duration)_var(--motion-press-fade-easing),box-shadow_var(--motion-press-duration)_var(--motion-press-fade-easing)] motion-reduce:[transition:opacity_var(--motion-layout-duration)_var(--motion-layout-easing),display_var(--motion-layout-duration)_allow-discrete,color_var(--motion-press-duration)_var(--motion-press-fade-easing),background-color_var(--motion-press-duration)_var(--motion-press-fade-easing),box-shadow_var(--motion-press-duration)_var(--motion-press-fade-easing)]',\n        'group-data-mounted/waterfall:starting:grid-rows-[0fr] group-data-mounted/waterfall:starting:opacity-0 [&[hidden]]:grid-rows-[0fr] [&[hidden]]:opacity-0',\n        'text-foreground data-lit:[--mark-step:0]',\n        focusRingClassName,\n        pickedRowClassName,\n        // Muted text in a tinted row is darker, so it keeps 4.5:1 on the tint.\n        tintedRowTextClassName,\n      )}\n    >\n      {({ branch, expanded, selected, level }) => (\n        <>\n          {/* The rail of each span it sits in, under that span's chevron, across the gap above it too. */}\n          {Array.from({ length: level - 1 }, (_, up) => (\n            <span\n              key={up}\n              aria-hidden\n              className='bg-border pointer-events-none absolute -top-px bottom-0 w-px forced-colors:bg-[CanvasText]'\n              style={{\n                insetInlineStart: `calc(var(--control-padding) + 0.5rem - ${up + 1} * var(--waterfall-indent))`,\n              }}\n            />\n          ))}\n          {/* Clipped down only, as it folds: a narrow row's bar reaches back past its start.\n              Its padding is inside, so the row folds all the way. */}\n          <div className='min-h-0 min-w-0 overflow-y-clip'>\n            <div\n              className={cn(\n                collapsibleRowClassName,\n                '@max-lg/rows:flex-wrap @max-lg/rows:gap-y-0.5',\n              )}\n            >\n              <WaterfallRowHeaderPrimitive\n                className={cn(\n                  'flex min-w-0 flex-1 items-start gap-2 @max-lg/rows:basis-full',\n                  cellFocusRingClassName,\n                )}\n              >\n                {branch ? (\n                  // Its target grown to 24px.\n                  <WaterfallIndicatorPrimitive className='relative mt-0.5 flex shrink-0 before:absolute before:-inset-x-1 before:-inset-y-1'>\n                    <CollapsibleIndicator open={expanded} className='size-4' />\n                  </WaterfallIndicatorPrimitive>\n                ) : (\n                  <span aria-hidden className='size-4 shrink-0' />\n                )}\n                <span className='flex min-w-0 flex-1 items-center gap-2'>\n                  {/* Its own direction, so a name in another script reads and cuts short at its end, on the row's start. */}\n                  <span\n                    dir='auto'\n                    className='min-w-0 flex-1 truncate text-left rtl:text-right'\n                  >\n                    {item.label}\n                  </span>\n                  {failed && <NoticeGlyph type='error' className='h-auto' />}\n                  <span\n                    aria-hidden\n                    dir='auto'\n                    className='text-muted-foreground shrink-0 text-xs tabular-nums'\n                  >\n                    {write(duration)}\n                  </span>\n                </span>\n              </WaterfallRowHeaderPrimitive>\n              <WaterfallBarPrimitive\n                className={cn(\n                  trackClassName,\n                  narrowTrackClassName,\n                  'h-lh',\n                  cellFocusRingClassName,\n                )}\n              >\n                <span\n                  ref={bar}\n                  aria-hidden\n                  data-waterfall-span-bar=''\n                  data-error={failed ? '' : undefined}\n                  data-hidden={\n                    kind !== undefined && hidden.includes(kind) ? '' : undefined\n                  }\n                  data-dim={emphasis !== null && emphasis !== kind ? '' : undefined}\n                  className={cn(\n                    'absolute top-1/2 h-2.5 -translate-y-1/2 opacity-100',\n                    // Spotlight: a bar keeps its lightness and loses colour while another span is lit.\n                    'bg-(--mark-ink)',\n                    stepBackInkClassName,\n                    // A hidden kind keeps its outline, which forced colours keep too.\n                    'data-hidden:bg-transparent data-hidden:outline-[1.5px] data-hidden:-outline-offset-[1.5px] data-hidden:outline-(--mark-color) forced-colors:data-hidden:bg-transparent!',\n                    // How far through the draw it waits: into the trace, or into the span it sits in once that opens.\n                    '[--waterfall-at:var(--waterfall-at-trace)] in-data-revealed:[--waterfall-at:var(--waterfall-at-opened)]',\n                    // The cascade fits in one draw: a later span waits longer and draws faster.\n                    '[--waterfall-delay:calc(var(--motion-draw-duration)*var(--waterfall-cascade,0.6)*var(--waterfall-at))] [--waterfall-span:calc(var(--motion-draw-duration)*(1-var(--waterfall-cascade,0.6)*var(--waterfall-at)))]',\n                    // It draws from its start on `draw` once the Waterfall is in view, and as the span it sits in opens.\n                    '[clip-path:inset(0_0_0_0_round_var(--bar-radius))] not-group-data-entered/waterfall:opacity-0 not-group-data-entered/waterfall:[clip-path:inset(0_100%_0_0_round_var(--bar-radius))] rtl:not-group-data-entered/waterfall:[clip-path:inset(0_0_0_100%_round_var(--bar-radius))]',\n                    'group-data-entered/waterfall:[transition:clip-path_var(--waterfall-span)_var(--motion-draw-easing)_var(--waterfall-delay),opacity_var(--waterfall-span)_var(--motion-draw-easing)_var(--waterfall-delay),background-color_var(--motion-layout-duration)_var(--motion-layout-fade-easing)] motion-reduce:group-data-entered/waterfall:[transition:opacity_var(--motion-draw-duration)_var(--motion-draw-easing),background-color_var(--motion-layout-duration)_var(--motion-layout-fade-easing)] motion-reduce:[clip-path:inset(0_0_0_0_round_var(--bar-radius))]!',\n                    // A span that comes in later (the span it sits in opens) draws in too, but never one there on load.\n                    'group-data-mounted/waterfall:starting:opacity-0 group-data-mounted/waterfall:starting:[clip-path:inset(0_100%_0_0_round_var(--bar-radius))] rtl:group-data-mounted/waterfall:starting:[clip-path:inset(0_0_0_100%_round_var(--bar-radius))]',\n                    slot === -1\n                      ? 'forced-colors:bg-[CanvasText]'\n                      : forcedSeriesColor(slot),\n                    // Forced colours: a failed bar is hollow and dashed, apart from a hidden kind's solid outline,\n                    // and a bar on a picked row takes the row's text colour, as its tint is the system's highlight.\n                    'forced-colors:data-error:bg-transparent! forced-colors:data-error:outline-[1.5px] forced-colors:data-error:-outline-offset-[1.5px] forced-colors:data-error:outline-dashed forced-colors:data-error:outline-[CanvasText]',\n                    'forced-colors:in-[[data-selected]]:bg-[HighlightText]! forced-colors:in-[[data-selected]]:outline-[HighlightText]! forced-colors:in-[[data-selected]]:data-error:bg-transparent! forced-colors:in-[[data-selected]]:data-hidden:bg-transparent!',\n                  )}\n                  style={\n                    {\n                      '--mark-color': failed\n                        ? 'var(--destructive)'\n                        : kind === undefined\n                          ? 'var(--foreground)'\n                          : seriesColor(kind),\n                      '--bar-radius': barRadius,\n                      '--waterfall-at-trace': fractionOf(start, range),\n                      insetInlineStart: 'var(--waterfall-start)',\n                      width:\n                        'max(var(--waterfall-min-length, 2px), var(--waterfall-size))',\n                    } as CSSProperties\n                  }\n                />\n              </WaterfallBarPrimitive>\n              {/* Picked shows by more than its tint: the Select's tick, in a slot kept for it. */}\n              <span aria-hidden className={menuIndicatorSlot}>\n                <span\n                  data-ending-style={selected ? undefined : ''}\n                  className={menuIndicatorClassName}\n                >\n                  <MenuTick />\n                </span>\n              </span>\n            </div>\n          </div>\n        </>\n      )}\n    </WaterfallRowPrimitive>\n  )\n}\n\n/**\n * The tooltip of the span under the pointer or the focus, on its bar: its\n * whole name, its kind, when it starts, how long it lasts, and what went\n * wrong. It opens at once and glides from bar to bar, as the charts' does.\n */\nfunction WaterfallTooltip({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof ChartTooltipBox>, 'children' | 'anchor'>) {\n  const { spans, config, kinds, write, messages, id, bars } = useWaterfall()\n  const { active } = use(WaterfallActiveContext)\n  // Escape closes it until another span is lit, or this one again.\n  const [dismissed, setDismissed] = useState<string | null>(null)\n  const [seen, setSeen] = useState(active)\n  if (seen !== active) {\n    setSeen(active)\n    setDismissed(null)\n  }\n  // The span it last showed stays while it closes, so it fades out where it was.\n  const [last, setLast] = useState<string | null>(null)\n  const lit = active === null ? undefined : spans.get(active)\n  if (lit !== undefined && active !== last) setLast(active)\n  const shownValue = lit === undefined ? last : active\n  const span = shownValue === null ? undefined : spans.get(shownValue)?.item\n  const anchor = shownValue === null ? null : (bars.get(shownValue) ?? null)\n  const open = lit !== undefined && dismissed !== active\n  const failed = span?.error !== undefined && span.error !== false\n  return (\n    <GlideGroupMemory>\n      <Tooltip\n        open={open}\n        onOpenChange={(next, details) => {\n          if (next) return\n          // The lit span opens and closes it; of the Tooltip's own closes, only Escape stands.\n          if (details.reason === 'escape-key') setDismissed(active)\n          else details.cancel()\n        }}\n      >\n        {span && anchor && (\n          <ChartTooltipBox\n            side='top'\n            sideOffset={8}\n            anchor={anchor}\n            className={cn('max-w-72 px-2.5 py-2', className)}\n            {...props}\n          >\n            <div data-chart={id} className='grid min-w-40 gap-1'>\n              <div dir='auto' className='text-start font-medium wrap-break-word'>\n                {span.label}\n              </div>\n              {span.kind !== undefined && (\n                <div className='flex items-center gap-2'>\n                  <span\n                    aria-hidden\n                    className={cn(\n                      swatchClassName,\n                      forcedSeriesColor(kinds.indexOf(span.kind)),\n                    )}\n                    style={swatchStyle(span.kind, 'solid')}\n                  />\n                  <span className='text-background/75 forced-colors:text-[CanvasText]'>\n                    {config[span.kind]?.label ?? span.kind}\n                  </span>\n                </div>\n              )}\n              <div className='flex items-center gap-2'>\n                <span className='text-background/75 flex-1 forced-colors:text-[CanvasText]'>\n                  {messages.starts}\n                </span>\n                <span dir='auto' className='font-medium tabular-nums'>\n                  {write(span.start)}\n                </span>\n              </div>\n              <div className='flex items-center gap-2'>\n                <span className='text-background/75 flex-1 forced-colors:text-[CanvasText]'>\n                  {messages.duration}\n                </span>\n                <span dir='auto' className='font-medium tabular-nums'>\n                  {write(span.duration)}\n                </span>\n              </div>\n              {failed && (\n                <div className='border-background/20 mt-0.5 border-t pt-1 wrap-break-word forced-colors:border-[CanvasText]'>\n                  {span.error === true ? messages.failed : span.error}\n                </div>\n              )}\n            </div>\n          </ChartTooltipBox>\n        )}\n      </Tooltip>\n    </GlideGroupMemory>\n  )\n}\n\n/**\n * How far into `span` a time falls, from 0 to 1: where a pill sits on the\n * axis, and how far through its draw a span's bar waits, as far as it starts\n * into the span it sits in (or the trace), so the spans replay in the order\n * they ran.\n */\nfunction fractionOf(time: number, span: Span): number {\n  const length = span[1] - span[0]\n  if (length <= 0) return 0\n  return Math.min(1, Math.max(0, (time - span[0]) / length))\n}\n\n/**\n * Whether a tick's label steps aside for the pill: each is a label `width`\n * px wide centred on its fraction of an axis `length` px long and kept\n * inside it, and they would come too close.\n */\nfunction tickCovered(\n  tick: number,\n  tickWidth: number,\n  pill: number,\n  pillWidth: number,\n  length: number,\n): boolean {\n  if (length <= 0) return false\n  return labelsMeet(labelBox(tick, tickWidth, length), labelBox(pill, pillWidth, length))\n}\n\n/**\n * The span a row that has just come into view is timed against: the nearest\n * one above it that already showed, which is the span that opened, so its\n * children that open with it draw in the order they ran inside it.\n */\nfunction openedBy(\n  value: string,\n  upOf: (value: string) => string | null,\n  shown: ReadonlySet<string>,\n): string | null {\n  let up = upOf(value)\n  while (up !== null && !shown.has(up)) up = upOf(up)\n  return up\n}\n\n/** How many px a box's scrollbar takes beside its content, from its outer and inner widths. */\nfunction scrollbarRoom(offsetWidth: number, clientWidth: number): number {\n  return Math.max(0, offsetWidth - clientWidth)\n}\n\n/** Whether a box, top to bottom, shows any of itself between `top` and `bottom`. */\nfunction inSight(\n  box: { top: number; bottom: number },\n  top: number,\n  bottom: number,\n): boolean {\n  return box.bottom > top && box.top < bottom\n}\n\nexport { Waterfall, WaterfallLegend, WaterfallList, WaterfallTooltip }\nexport { fractionOf, inSight, openedBy, scrollbarRoom, tickCovered }\nexport type { WaterfallItem, WaterfallMessages }\n",
      "type": "registry:component",
      "target": "@components/kino/waterfall.tsx"
    }
  ],
  "type": "registry:component"
}