{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bar-list",
  "title": "Bar list",
  "description": "A ranked list with a bar behind each row, as long as its value against the largest, such as a site’s top pages, with an icon, a link or a pick per row, each row’s share, where each stood before with its change, and Show more. The row under the pointer stays bright while the rest step back, and new values swap the rows into their new order where they are while each value rolls.",
  "dependencies": [
    "@ui-sdk/react",
    "@ui-sdk/core"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/animated-number.json",
    "https://kinoui.com/r/button.json",
    "https://kinoui.com/r/chart-core.json",
    "https://kinoui.com/r/chart-root.json",
    "https://kinoui.com/r/chart-math.json",
    "https://kinoui.com/r/controllable.json",
    "https://kinoui.com/r/cut.json",
    "https://kinoui.com/r/flow.json",
    "https://kinoui.com/r/placeholder.json",
    "https://kinoui.com/r/refs.json",
    "https://kinoui.com/r/sort.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/bar-list.tsx",
      "content": "'use client'\n\nimport { AnimatedNumber } from '@/registry/components/kino/animated-number'\nimport { Button } from '@/registry/components/kino/button'\nimport {\n  type CategoryChartProps,\n  figureProps,\n  IndexActive,\n  useChartActive,\n  useChartLife,\n  useChartLoad,\n  useChartPick,\n  useIndexFocus,\n} from '@/registry/lib/chart-base'\nimport {\n  allWhole,\n  cascadeAt,\n  type ChartDatum,\n  numberOf,\n  type ReadingDirection,\n} from '@/registry/lib/chart-math'\nimport {\n  ChartFrame,\n  type ChartFormat,\n  type ChartItem,\n  type ChartMessages,\n  ChartNumber,\n  type ChartReader,\n  type ChartRootValue,\n  formatterOf,\n  seriesColor,\n  signedWriter,\n  stepBackInkClassName,\n  useChartRoot,\n  useChartRootValue,\n} from '@/registry/lib/chart-root'\nimport { linearScale } from '@/registry/lib/chart-scale'\nimport type { ChartTarget } from '@/registry/lib/chart-state'\nimport { useControllable } from '@/registry/lib/controllable'\nimport { CutTooltip } from '@/registry/lib/cut'\nimport { flowItemClassName, useFlow } from '@/registry/lib/flow'\nimport {\n  placeholderBreatheClassName,\n  placeholderFillClassName,\n} from '@/registry/lib/placeholder'\nimport { markMounted, mergeRefs } from '@/registry/lib/refs'\nimport { sameOrder } from '@/registry/lib/sort'\nimport { mergeProps, renderElement } from '@ui-sdk/react/primitive'\nimport { Toggle as TogglePrimitive } from '@ui-sdk/react/toggle'\nimport {\n  type ComponentProps,\n  type CSSProperties,\n  type FocusEvent,\n  memo,\n  type PointerEvent,\n  type ReactElement,\n  type ReactNode,\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useMemo,\n  useRef,\n  useState,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * The Bar list: a ranked list with a bar behind each row, as long as its\n * value against the largest, such as a site's top pages. Each row writes its\n * value, so there is no tooltip: the row under the pointer or the focus stays\n * bright while the rest step back. A row can be a link or a pick. New values\n * swap the rows into their new order where they are, roll each value and\n * slide each bar to its new length; rows past `limit` wait behind Show more.\n * With `previous`, the row writes its change after its value, and a line\n * along its foot runs as far as it stood before, unless `previousLine` is off.\n */\n\n/** Every word the list says, the chart's and its Show more button's. */\ninterface BarListMessages extends ChartMessages {\n  /** The button that shows the rows past `limit`, with how many there are. */\n  showMore: (count: number) => string\n  /** The same button once they show. */\n  showLess: string\n  /** What a row's change is read with, after it: the value it changed from, written. */\n  changedFrom: (value: string) => string\n}\n\n/** How the rows are ordered: largest first, smallest first, or as the data has them. */\ntype BarListSort = 'descending' | 'ascending' | 'none'\n\ninterface BarListProps extends Omit<\n  CategoryChartProps,\n  | 'ordered'\n  | 'tickCount'\n  | 'tickValues'\n  | 'allowDecimals'\n  | 'patterns'\n  | 'hiddenSeries'\n  | 'defaultHiddenSeries'\n  | 'onHiddenSeriesChange'\n  | 'messages'\n  | 'color'\n> {\n  /** How the rows are ordered; largest first by default. */\n  sort?: BarListSort\n  /** A picture before each row's name, such as a site's icon or a flag, sized by the row. */\n  icon?: (row: ChartDatum) => ReactNode\n  /** Where each row leads: with one, the row is a link. */\n  href?: (row: ChartDatum) => string | undefined\n  /** The element a row's link renders, such as your router's `Link`, which takes the row's `href`. */\n  linkRender?: ReactElement\n  /** A row's own bar colour, in place of the config's. */\n  color?: (row: ChartDatum, index: number) => string | undefined\n  /** Writes each row's share of the total after its value. */\n  share?: boolean\n  /**\n   * The key of each row's earlier value, such as the month before: a line\n   * along the foot of the row runs as far as it, and the row writes its\n   * change after its value.\n   */\n  previous?: string\n  /** Whether the line along a row's foot shows its earlier value, with `previous`: on by default, and off for a list that only writes the change. */\n  previousLine?: boolean\n  /** How a row's change is written, with `previous`: as `format` by default, or a rate's in points. */\n  changeFormat?: ChartFormat\n  /** How many rows show until Show more is pressed; every row by default. */\n  limit?: number\n  /** Whether the rows past `limit` show, for a list you control. */\n  expanded?: boolean\n  defaultExpanded?: boolean\n  onExpandedChange?: (expanded: boolean) => void\n  /**\n   * How the bars arrive the first time the list comes into view: growing\n   * from the start one after another, or simply there, the default, since a\n   * page that loads doesn't animate into place.\n   */\n  entrance?: 'draw' | 'none'\n  /** Every word the list says or reads out, for a list in another language. */\n  messages?: Partial<BarListMessages>\n}\n\nconst barListKeys = [\n  'sort',\n  'icon',\n  'href',\n  'linkRender',\n  'color',\n  'share',\n  'previous',\n  'previousLine',\n  'changeFormat',\n  'limit',\n  'expanded',\n  'defaultExpanded',\n  'onExpandedChange',\n  'entrance',\n]\n\n/** How long the placeholder's bars are, as fractions of the row: a typical ranking, knowing nothing of the data. */\nconst PLACEHOLDER_LENGTHS = [0.92, 0.7, 0.54, 0.4, 0.3] as const\n\n/** A row of the data, as the list keeps it. */\ntype BarListItem = ChartItem & { datum: ChartDatum }\n\n/** What a row shows, worked out once by the root. */\ninterface BarListRowData {\n  item: BarListItem\n  /** Its place in the list, from the top. */\n  rank: number\n  value: number | null\n  /** Its share of the total, from 0 to 1. */\n  share: number\n  clip: string\n  from: string\n  color: string\n  /** Whether the list writes changes, with `previous`: then every row holds the change's column. */\n  compared: boolean\n  /** Its earlier value, with `previous`. */\n  before: number | null\n  /** How far the line that marks its earlier value runs, as a `transform`, or null with none. */\n  previousLine: string | null\n  icon: ReactNode\n  href: string | undefined\n  delay: string | undefined\n}\n\n/** The rows of a list that loads or failed: one array, so what compares rows sees no change. */\nconst NO_ROWS: readonly ChartDatum[] = []\n\n/**\n * The list's root: it orders the rows, scales the bars to the largest value\n * (or the end of `domain`), and lays out the frame its rows draw in. It sits\n * on the chart root with no browse layer: each row is a link or a button of\n * its own, which the pointer and the keys reach as they are.\n */\nfunction BarList(props: BarListProps) {\n  const {\n    data,\n    index,\n    config,\n    domain,\n    categoryFormat = String,\n    sort = 'descending',\n    icon,\n    href,\n    linkRender,\n    color,\n    share = false,\n    previous,\n    previousLine: drawPrevious = true,\n    changeFormat,\n    limit,\n    expanded: expandedProp,\n    defaultExpanded = false,\n    onExpandedChange,\n    entrance = 'none',\n    messages,\n    activeIndex,\n    defaultActiveIndex = null,\n    onActiveIndexChange,\n    description,\n    empty,\n    className,\n    ref,\n  } = props\n  const dataKey = Object.keys(config)[0] ?? ''\n  const { showMore, showLess, changedFrom, ...chartMessages } = messages ?? {}\n  const state = useChartRoot(\n    { ...props, messages: { empty: 'No data yet', ...chartMessages } },\n    { entrance: entrance !== 'none', heightFromData: true },\n  )\n  const load = useChartLoad(props)\n  const drawn = load.placeholder || load.failed ? NO_ROWS : data\n  const shownSeries = state.series.filter((key) => !state.hidden.includes(key))\n  const { status, fromPlaceholder, phase } = useChartLife(\n    props,\n    state,\n    load,\n    { rows: drawn.length, shown: shownSeries.length, drawn: drawn.length },\n    {\n      entrance: entrance !== 'none',\n      cascade: { variable: '--bar-list-cascade', fallback: 0.8 },\n    },\n  )\n  const current: BarListItem[] = drawn.map((datum, at) => ({\n    key: String(datum[index]),\n    value: datum[index],\n    datum,\n    index: at,\n  }))\n  const keys = current.map((item) => item.key)\n  const pick = useChartPick(props, keys)\n  const scale = linearScale(\n    [0, barListReach(drawn, previous && drawPrevious ? [dataKey, previous] : [dataKey])],\n    {\n      domain,\n      tickCount: 5,\n      nice: false,\n      allowDecimals: !allWhole(drawn, shownSeries),\n    },\n  )\n  const reader = barListReader(current)\n  const root: ChartRootValue = {\n    ...state,\n    status,\n    reader,\n    markerOf: noMarker,\n    selectable: pick.selectable,\n    picked: pick.picked === null ? null : { kind: 'x', key: pick.picked },\n    togglePicked: (target) => {\n      if (reader.holds(target) && target.kind === 'x') pick.toggle(target.key)\n    },\n  }\n  const active = { activeIndex, defaultActiveIndex, onActiveIndexChange }\n  const { focusProps, toldRef } = useIndexFocus(reader.items, active)\n  const [expanded, setExpanded] = useControllable(\n    expandedProp,\n    defaultExpanded,\n    onExpandedChange,\n  )\n  const listId = `${useId()}-rows`\n\n  const values = current.map((item) => numberOf(item.datum[dataKey]))\n  const order = barListOrder(values, sort)\n  const shares = barListShares(values)\n  const most = limit === undefined ? order.length : Math.max(0, Math.floor(limit))\n  const shownCount = expanded ? order.length : Math.min(order.length, most)\n  const waiting = phase === 'waiting'\n  const drawing = phase === 'entering'\n  const rows: BarListRowData[] = order.slice(0, shownCount).map((at, rank) => {\n    const item = current[at]!\n    const value = values[at] ?? null\n    const fraction = value === null || value <= 0 ? 0 : scale.place(value)\n    const before = previous === undefined ? null : numberOf(item.datum[previous])\n    const zero = barListClip(0, state.direction)\n    const startAt = PLACEHOLDER_LENGTHS[Math.min(rank, PLACEHOLDER_LENGTHS.length - 1)]!\n    return {\n      item,\n      rank,\n      value,\n      share: shares[at] ?? 0,\n      clip: waiting ? zero : barListClip(fraction, state.direction),\n      // A bar that arrives grows out of the placeholder in its place, or from the start.\n      from: fromPlaceholder ? barListClip(startAt, state.direction) : zero,\n      color: color?.(item.datum, at) ?? seriesColor(dataKey),\n      before,\n      // The earlier value's line waits at the start while the bars do, and grows with them.\n      compared: previous !== undefined,\n      previousLine:\n        before === null || !drawPrevious\n          ? null\n          : barListPreviousLine(waiting || before <= 0 ? 0 : scale.place(before)),\n      icon: icon?.(item.datum),\n      href: href?.(item.datum),\n      delay: drawing\n        ? `calc(var(--motion-draw-duration) * var(--bar-list-cascade, 0.8) * ${cascadeAt(rank, shownCount)})`\n        : undefined,\n    }\n  })\n  const hiddenCount = order.length - Math.min(order.length, most)\n\n  // Rows that swap places move in the DOM, and a moved element is styled\n  // afresh, so its bar's slide would be lost. New values first land on the\n  // rows where they are, so each bar's slide is running, then the rows move,\n  // taking their slides with them.\n  const rowKeys = rows.map((row) => row.item.key)\n  const [placed, setPlaced] = useState(rowKeys)\n  const shown = barListPlacing(placed, rowKeys)\n  const settled = sameOrder(shown, rowKeys)\n  if (settled && !sameOrder(placed, rowKeys)) setPlaced(rowKeys)\n  const keysKey = rowKeys.join('\\u0000')\n  useEffect(() => {\n    if (settled) return\n    let frame = requestAnimationFrame(() => {\n      frame = requestAnimationFrame(() => setPlaced(keysKey.split('\\u0000')))\n    })\n    return () => cancelAnimationFrame(frame)\n  }, [settled, keysKey])\n  const byKey = new Map(rows.map((row) => [row.item.key, row]))\n  const placedRows = settled ? rows : shown.map((key) => byKey.get(key)!)\n  const valueLabel = config[dataKey]?.label\n\n  return (\n    <ChartFrame\n      root={root}\n      focus={focusProps}\n      ref={ref}\n      slot='bar-list'\n      description={description}\n      empty={empty}\n      measuring={false}\n      inset={0}\n      data-orientation='horizontal'\n      className={cn('h-auto min-h-(--control-height) text-sm', className)}\n      {...figureProps({ ...props, color: undefined }, barListKeys)}\n    >\n      <IndexActive items={reader.items} active={active} toldRef={toldRef}>\n        <BarListRows\n          id={listId}\n          rows={placedRows}\n          nameOf={(item) => categoryFormat(item.value)}\n          valueLabel={typeof valueLabel === 'string' ? valueLabel : undefined}\n          share={share}\n          linkRender={linkRender}\n          entering={drawing}\n          changedFrom={changedFrom ?? changedFromDefault}\n          changeFormat={changeFormat}\n        />\n        {status === 'ready' && hiddenCount > 0 && (\n          <Button\n            size='sm'\n            variant='ghost'\n            aria-expanded={expanded}\n            aria-controls={listId}\n            className='mt-1 justify-self-start [grid-area:bottom]'\n            onClick={() => setExpanded(!expanded)}\n          >\n            {expanded\n              ? (showLess ?? 'Show fewer')\n              : (showMore?.(hiddenCount) ?? `Show ${hiddenCount} more`)}\n          </Button>\n        )}\n        {load.placeholder && (\n          <BarListPlaceholder\n            count={Math.min(\n              limit ?? PLACEHOLDER_LENGTHS.length,\n              PLACEHOLDER_LENGTHS.length,\n            )}\n          />\n        )}\n      </IndexActive>\n    </ChartFrame>\n  )\n}\n\n/** The list draws no legend, so its series take no marker. */\nfunction noMarker() {\n  return null\n}\n\n/** What a row's change is read with by default, after it. */\nfunction changedFromDefault(value: string) {\n  return `from ${value}`\n}\n\n/** How far the bars reach: the largest value above zero under any of `keys`, such as a row's value and its earlier one, or zero. */\nfunction barListReach(rows: readonly ChartDatum[], keys: readonly string[]) {\n  return Math.max(\n    0,\n    ...rows.flatMap((row) => keys.map((key) => Math.max(0, numberOf(row[key]) ?? 0))),\n  )\n}\n\n/**\n * The list's reader: each row still in the data is held by its key, as an\n * `x` target, and brings no series forward. It has no browse layer, since\n * its rows are links and buttons of their own.\n */\nfunction barListReader(current: readonly ChartItem[]): ChartReader {\n  const keys = current.map((item) => item.key)\n  const at = (target: { kind: string; key?: string }) =>\n    target.kind === 'x' && target.key !== undefined ? keys.indexOf(target.key) : -1\n  return {\n    holds: (target) => at(target) !== -1,\n    lights: () => null,\n    item: (target) => current[at(target)] ?? null,\n    items: keys.map((key) => ({ kind: 'x', key })),\n    browse: null,\n  }\n}\n\n/**\n * The rows, in a box that moves to their height as rows come and go, and\n * each row gliding to its new place when the order changes.\n */\nfunction BarListRows({\n  id,\n  rows,\n  nameOf,\n  valueLabel,\n  share,\n  linkRender,\n  entering,\n  changedFrom,\n  changeFormat,\n}: {\n  id: string\n  rows: readonly BarListRowData[]\n  nameOf: (item: BarListItem) => string\n  /** What the values are, read after each one; none when the config's label isn't text. */\n  valueLabel: string | undefined\n  share: boolean\n  linkRender: ReactElement | undefined\n  entering: boolean\n  changedFrom: (value: string) => string\n  changeFormat: ChartFormat | undefined\n}) {\n  const { plot, status, picked, selectable, togglePicked, format, locale, messages } =\n    useChartRootValue()\n  const writeChange = signedWriter(locale, changeFormat ?? format)\n  const { spotlit, setActive } = useChartActive()\n  const { frame, row: list } = useFlow<HTMLDivElement, HTMLOListElement>(\n    '[data-slot=bar-list-row]',\n  )\n  const own = useRef<HTMLOListElement>(null)\n  const listRef = useMemo(() => mergeRefs(list, plot, own, markMounted), [list, plot])\n  const ready = status === 'ready'\n  // A focused row that goes, past the limit or out of the data, hands the\n  // focus to the list rather than to the page, and lets its light go.\n  const holding = useRef(false)\n  useEffect(() => {\n    const element = own.current\n    if (!element) return\n    const hold = () => {\n      holding.current = true\n    }\n    const release = (event: globalThis.FocusEvent) => {\n      const target = event.target as Node\n      const to = event.relatedTarget as Node | null\n      // A row taken out of the page blurs as it goes, while still in it:\n      // told apart once React has finished, by being gone.\n      queueMicrotask(() => {\n        if (target.isConnected && !element.contains(to)) holding.current = false\n      })\n    }\n    element.addEventListener('focusin', hold)\n    element.addEventListener('focusout', release)\n    return () => {\n      element.removeEventListener('focusin', hold)\n      element.removeEventListener('focusout', release)\n    }\n  }, [])\n  useLayoutEffect(() => {\n    const element = own.current\n    if (!holding.current || !element || element.contains(document.activeElement)) return\n    setActive(null)\n    element.focus({ preventScroll: true })\n  })\n  return (\n    <div\n      ref={frame}\n      className='relative overflow-clip transition-[height] duration-(--motion-layout-duration) ease-(--motion-layout-easing) [grid-area:plot] motion-reduce:transition-none'\n    >\n      <ol\n        ref={listRef}\n        id={id}\n        tabIndex={-1}\n        data-chart-plot=''\n        data-slot='bar-list-rows'\n        className='group/flow focus-visible:ring-ring/50 relative isolate flex min-w-0 flex-col gap-1 rounded-(--item-radius) focus-visible:ring-3 focus-visible:outline-hidden focus-visible:ring-inset'\n      >\n        {ready &&\n          rows.map((row) => (\n            <BarListRow\n              key={row.item.key}\n              index={row.item.index}\n              itemKey={row.item.key}\n              name={nameOf(row.item)}\n              value={row.value}\n              share={share ? (row.value === null ? 'none' : row.share) : null}\n              valueLabel={valueLabel}\n              clip={row.clip}\n              from={row.from}\n              color={row.color}\n              compared={row.compared}\n              before={row.before}\n              previousLine={row.previousLine}\n              changedFrom={changedFrom}\n              writeChange={writeChange}\n              icon={row.icon}\n              href={row.href}\n              linkRender={linkRender}\n              delay={row.delay}\n              entering={entering}\n              dim={spotlit !== null && spotlit !== row.item.index}\n              picked={picked?.kind === 'x' && picked.key === row.item.key}\n              selectable={selectable}\n              setActive={setActive}\n              togglePicked={togglePicked}\n              format={format}\n              locale={locale}\n              noValue={messages.noValue}\n            />\n          ))}\n      </ol>\n    </div>\n  )\n}\n\n/**\n * One row: its bar, its icon, its name, its value and its share. A link\n * with an `href`, a toggle on a list whose rows can be picked, or else\n * text. Memoised, so a pointer moving between rows redraws only the rows it\n * lights or dims.\n */\nconst BarListRow = memo(function BarListRow({\n  index,\n  itemKey,\n  name,\n  value,\n  share,\n  valueLabel,\n  clip,\n  from,\n  color,\n  compared,\n  before,\n  previousLine,\n  changedFrom,\n  writeChange,\n  icon,\n  href,\n  linkRender,\n  delay,\n  entering,\n  dim,\n  picked,\n  selectable,\n  setActive,\n  togglePicked,\n  format,\n  locale,\n  noValue,\n}: {\n  index: number\n  itemKey: string\n  name: string\n  value: number | null\n  /** Its share of the total, `none` for a missing value, or null when shares aren't written. */\n  share: number | 'none' | null\n  valueLabel: string | undefined\n  clip: string\n  from: string\n  color: string\n  compared: boolean\n  before: number | null\n  previousLine: string | null\n  changedFrom: (value: string) => string\n  /** A row's change, written with its sign. */\n  writeChange: (difference: number) => string\n  icon: ReactNode\n  href: string | undefined\n  linkRender: ReactElement | undefined\n  delay: string | undefined\n  entering: boolean\n  dim: boolean\n  picked: boolean\n  selectable: boolean\n  setActive: (index: number | null) => void\n  togglePicked: (target: ChartTarget) => void\n  format: ChartFormat | undefined\n  locale: Intl.LocalesArgument\n  noValue: string\n}) {\n  const link = href !== undefined\n  const pressable = !link && selectable\n  const interactive = link || pressable\n  const events = {\n    // Only a mouse lights a row: a tap has no way to leave it.\n    onPointerEnter: (event: PointerEvent) => {\n      if (event.pointerType === 'mouse') setActive(index)\n    },\n    onPointerLeave: (event: PointerEvent) => {\n      if (event.pointerType === 'mouse') setActive(null)\n    },\n    onFocus: (event: FocusEvent<HTMLElement>) => {\n      if (event.currentTarget.matches(':focus-visible')) setActive(index)\n    },\n    onBlur: () => setActive(null),\n  }\n  const content = (\n    <>\n      <span\n        aria-hidden\n        data-slot='bar-list-bar'\n        data-dim={dim ? '' : undefined}\n        data-entering={entering ? '' : undefined}\n        className={cn(barClassName, stepBackInkClassName)}\n        style={\n          {\n            '--mark-color': color,\n            '--bar-from': from,\n            // A variable, not `clipPath`, so the class's starting shape isn't overruled by an inline style.\n            '--bar-clip': clip,\n            transitionDelay: delay,\n          } as CSSProperties\n        }\n      />\n      {previousLine !== null && (\n        // The row's corners clip the line: a clip on the line itself would scale with it.\n        <span\n          aria-hidden\n          className='pointer-events-none absolute inset-0 -z-10 overflow-hidden rounded-(--item-radius)'\n        >\n          <span\n            data-slot='bar-list-previous'\n            data-dim={dim ? '' : undefined}\n            data-entering={entering ? '' : undefined}\n            className={previousLineClassName}\n            style={\n              {\n                // A variable, not `transform`, so the class's starting scale isn't overruled by an inline style.\n                '--bar-list-previous': previousLine,\n                transitionDelay: delay,\n              } as CSSProperties\n            }\n          />\n        </span>\n      )}\n      {icon !== undefined && icon !== null && (\n        <span\n          aria-hidden\n          data-slot='bar-list-icon'\n          className='flex size-4 shrink-0 items-center justify-center [&_img]:size-4 [&_img]:object-contain [&_svg]:size-4'\n        >\n          {icon}\n        </span>\n      )}\n      {interactive ? (\n        <span\n          data-cut\n          data-slot='bar-list-name'\n          className={cn(nameClassName, 'truncate')}\n        >\n          <bdi>{name}</bdi>\n        </span>\n      ) : (\n        <CutTooltip\n          labels={NAME}\n          render={\n            <span\n              data-cut\n              data-slot='bar-list-name'\n              className={cn(nameClassName, 'truncate')}\n            >\n              <bdi>{name}</bdi>\n            </span>\n          }\n        />\n      )}\n      <span className='sr-only'>, </span>\n      <span data-slot='bar-list-value' className={valueClassName}>\n        {value === null ? (\n          <span className='text-muted-foreground'>{noValue}</span>\n        ) : (\n          <ChartNumber value={value} format={format} locale={locale} />\n        )}\n        {/* A value written its own way says what it is; a missing one has nothing to name. */}\n        {valueLabel && value !== null && typeof format !== 'function' && (\n          <span className='sr-only'> {valueLabel}</span>\n        )}\n      </span>\n      {compared && (\n        <>\n          {value !== null && before !== null && <span className='sr-only'>, </span>}\n          {/* In the text colour, as the share: a muted colour over a bar falls below 4.5:1. */}\n          <span\n            data-slot='bar-list-change'\n            className='min-w-12 shrink-0 text-end tabular-nums forced-colors:text-[CanvasText]!'\n          >\n            {value !== null && before !== null && (\n              <>\n                <bdi>{writeChange(value - before)}</bdi>\n                <span className='sr-only'>\n                  {' '}\n                  {changedFrom(formatterOf(locale, format)(before))}\n                </span>\n              </>\n            )}\n          </span>\n        </>\n      )}\n      {share !== null && (\n        <>\n          {share !== 'none' && <span className='sr-only'>, </span>}\n          {/* In the text colour, lighter than the value: a muted colour over a bar falls below 4.5:1. */}\n          <span\n            data-slot='bar-list-share'\n            className='min-w-12 shrink-0 text-end tabular-nums forced-colors:text-[CanvasText]!'\n          >\n            {share !== 'none' && (\n              <AnimatedNumber value={share} locale={locale} format={SHARE_FORMAT} />\n            )}\n          </span>\n        </>\n      )}\n    </>\n  )\n  const rowClassName = cn(\n    'relative isolate flex h-(--control-height) w-full min-w-0 items-center gap-2 text-start rounded-(--item-radius) px-(--control-padding) select-none',\n    interactive &&\n      'focus-visible:ring-ring/50 focus-visible:ring-3 focus-visible:outline-hidden focus-visible:ring-inset',\n    pressable &&\n      'aria-pressed:font-medium forced-colors:aria-pressed:outline-2 forced-colors:aria-pressed:outline-[Highlight] forced-colors:aria-pressed:outline-solid',\n  )\n  return (\n    <li\n      data-slot='bar-list-row'\n      data-dim={dim ? '' : undefined}\n      className={cn(flowItemClassName, 'min-w-0')}\n    >\n      {link ? (\n        <BarListLink\n          href={href}\n          linkRender={linkRender}\n          className={rowClassName}\n          {...events}\n        >\n          {content}\n        </BarListLink>\n      ) : pressable ? (\n        <CutTooltip\n          labels={NAME}\n          render={\n            <TogglePrimitive\n              pressed={picked}\n              onPressedChange={() => togglePicked({ kind: 'x', key: itemKey })}\n              className={rowClassName}\n              {...events}\n            >\n              {content}\n            </TogglePrimitive>\n          }\n        />\n      ) : (\n        <div className={rowClassName} {...events}>\n          {content}\n        </div>\n      )}\n    </li>\n  )\n})\n\n/** A share is written to a tenth of a percent. */\nconst SHARE_FORMAT: Intl.NumberFormatOptions = {\n  style: 'percent',\n  maximumFractionDigits: 1,\n}\n\n/** A row as a link: the list's own `linkRender`, such as a router's, or an `<a>`, with the row's name shown whole while it is cut. */\nfunction BarListLink({\n  linkRender,\n  ...props\n}: ComponentProps<'a'> & { linkRender: ReactElement | undefined }) {\n  const element = renderElement(\n    'a',\n    mergeProps({ 'data-slot': 'bar-list-link' }, props),\n    linkRender,\n  )\n  return <CutTooltip labels={NAME} render={element} />\n}\n\n/** A row's name, the one label in it that can be cut short: its value and share never are. */\nconst NAME = '[data-slot=bar-list-name]'\n\n/** What waits in the rows' place while the data loads: bars of a typical ranking, breathing. */\nfunction BarListPlaceholder({ count }: { count: number }) {\n  return (\n    <div\n      aria-hidden\n      data-slot='bar-list-placeholder'\n      className='pointer-events-none flex min-w-0 flex-col gap-1 [grid-area:plot]'\n    >\n      {PLACEHOLDER_LENGTHS.slice(0, Math.max(1, count)).map((length) => (\n        <span\n          key={length}\n          className={cn(\n            'block h-(--control-height) rounded-(--item-radius)',\n            placeholderFillClassName,\n            placeholderBreatheClassName,\n          )}\n          style={{ width: `${length * 100}%` }}\n        />\n      ))}\n    </div>\n  )\n}\n\n/**\n * A bar: a tint of its colour behind the row, as long as `--bar-clip` lets\n * it be, stepping back to a greyer tint while another row is lit. In forced\n * colours, a line under the row's text.\n */\nconst barClassName =\n  'pointer-events-none absolute inset-0 -z-10 rounded-(--item-radius) bg-[color-mix(in_oklab,var(--mark-ink)_var(--bar-list-tint,22%),transparent)] [clip-path:var(--bar-clip)] transition-none group-data-mounted/chart:transition-[background-color,clip-path] duration-(--motion-layout-duration) ease-[var(--motion-layout-fade-easing),var(--motion-layout-easing)] group-data-mounted/chart:starting:[clip-path:var(--bar-from)] data-entering:duration-(--motion-draw-duration) data-entering:ease-[var(--motion-draw-fade-easing),var(--motion-draw-easing)] motion-reduce:group-data-mounted/chart:transition-[background-color] motion-reduce:ease-(--motion-layout-fade-easing) forced-colors:top-auto forced-colors:h-1 forced-colors:bg-[CanvasText]! forced-colors:data-dim:bg-[GrayText]!'\n\n/**\n * The line at a row's earlier value: along the foot of the row, under its\n * words, from the reading start, in the muted grey a chart's previous period\n * takes, so the comparison stays the quieter mark. It is as wide as the row\n * and scales (`transform`, from `--bar-list-previous`, so a row that arrives\n * grows it from nothing as its bar grows) to the value on `layout`, and the\n * row's corners clip it. In forced colours, where the bar is a line at the\n * foot, it runs along the top in the text colour.\n */\nconst previousLineClassName =\n  'absolute inset-x-0 bottom-0 h-0.5 origin-left rtl:origin-right bg-muted-foreground [transform:var(--bar-list-previous)] group-data-mounted/chart:starting:[transform:scaleX(0)] transition-none group-data-mounted/chart:transition-[background-color,transform] duration-(--motion-layout-duration) ease-[var(--motion-layout-fade-easing),var(--motion-layout-easing)] data-entering:duration-(--motion-draw-duration) data-entering:ease-[var(--motion-draw-fade-easing),var(--motion-draw-easing)] motion-reduce:group-data-mounted/chart:transition-[background-color] motion-reduce:ease-(--motion-layout-fade-easing) forced-colors:top-0 forced-colors:bottom-auto forced-colors:bg-[CanvasText]! forced-colors:data-dim:bg-[GrayText]!'\n\n/**\n * A row's name: cut short (`truncate`) with the rest of it in a tooltip. It\n * keeps its full colour while another row is lit, as the value does: only the\n * bar steps back, since muted text over a bar falls below 4.5:1.\n */\nconst nameClassName = 'min-w-0 flex-1 forced-colors:text-[CanvasText]!'\n\n/** A row's value, after its name. */\nconst valueClassName =\n  'shrink-0 font-medium whitespace-nowrap tabular-nums forced-colors:text-[CanvasText]!'\n\n/**\n * The order the rows show in, as places in `values`: largest first,\n * smallest first, or as given. A missing value goes last either way, and\n * rows with the same value keep the data's order, so a tie never swaps.\n */\nfunction barListOrder(values: readonly (number | null)[], sort: BarListSort): number[] {\n  const places = values.map((_, at) => at)\n  if (sort === 'none') return places\n  const sign = sort === 'descending' ? -1 : 1\n  return places.toSorted((a, b) => {\n    const left = values[a] ?? null\n    const right = values[b] ?? null\n    if (left === null || right === null) {\n      if (left === right) return a - b\n      return left === null ? 1 : -1\n    }\n    return (left - right) * sign || a - b\n  })\n}\n\n/**\n * The rows to draw, by key, while they move from `placed` to `next`: `next`\n * itself when the rows that stay keep their order, or else only those rows,\n * still in `placed`'s order, until they have taken their new values.\n */\nfunction barListPlacing(\n  placed: readonly string[],\n  next: readonly string[],\n): readonly string[] {\n  const now = new Set(next)\n  const was = new Set(placed)\n  const staying = placed.filter((key) => now.has(key))\n  return sameOrder(\n    staying,\n    next.filter((key) => was.has(key)),\n  )\n    ? next\n    : staying\n}\n\n/** Each value's share of the total of every value above zero, from 0 to 1; none when there is nothing to share. */\nfunction barListShares(values: readonly (number | null)[]): number[] {\n  const total = values.reduce<number>((sum, value) => sum + Math.max(0, value ?? 0), 0)\n  return values.map((value) => (total === 0 ? 0 : Math.max(0, value ?? 0) / total))\n}\n\n/**\n * How far the line at a row's earlier value runs, `fraction` of the row from\n * the reading start, as the `transform` of a line as wide as the row: never\n * past either end.\n */\nfunction barListPreviousLine(fraction: number): string {\n  return `scaleX(${Math.round(Math.min(1, Math.max(0, fraction)) * 1e4) / 1e4})`\n}\n\n/**\n * The `clip-path` that shows a bar `fraction` of its row long from the\n * reading start, with its corners rounded. Above nothing, a bar is never\n * shorter than `--bar-list-least`, so the smallest value still shows; at\n * nothing, it shows none.\n */\nfunction barListClip(fraction: number, direction: ReadingDirection): string {\n  const share = Math.round(Math.min(1, Math.max(0, fraction)) * 1e6) / 1e4\n  const cut =\n    share === 0 ? '100%' : `calc(100% - max(var(--bar-list-least, 0.375rem), ${share}%))`\n  return direction === 'rtl'\n    ? `inset(0 0 0 ${cut} round var(--item-radius))`\n    : `inset(0 ${cut} 0 0 round var(--item-radius))`\n}\n\nexport {\n  BarList,\n  barListReader,\n  type BarListMessages,\n  type BarListProps,\n  type BarListSort,\n  barListClip,\n  barListPreviousLine,\n  barListReach,\n  barListOrder,\n  barListPlacing,\n  barListShares,\n}\n",
      "type": "registry:component",
      "target": "@components/kino/bar-list.tsx"
    }
  ],
  "type": "registry:component"
}