{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-line",
  "title": "Chart line",
  "description": "The series of a chart drawn as lines, on the chart core: each line and its fill moving from where it is on one transition, the window that keeps the lit category bright while the rest steps back, the dots that mark it, and the placeholder. Line chart, Area chart, Bump chart and Sparkline share it.",
  "dependencies": [],
  "registryDependencies": [
    "https://kinoui.com/r/chart-frame.json",
    "https://kinoui.com/r/chart-line-marks.json",
    "https://kinoui.com/r/area-fill.json",
    "https://kinoui.com/r/chart-core.json",
    "https://kinoui.com/r/chart-live.json",
    "https://kinoui.com/r/chart-root.json",
    "https://kinoui.com/r/chart-math.json",
    "https://kinoui.com/r/line-path.json",
    "https://kinoui.com/r/live.json",
    "https://kinoui.com/r/placeholder.json",
    "https://kinoui.com/r/run-progress.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/lib/chart-line.tsx",
      "content": "'use client'\n\nimport {\n  AreaFill,\n  type AreaFillElements,\n  areaPathThrough,\n  fillPeak,\n  paintFill,\n} from '@/registry/lib/area-fill'\nimport { type EntrancePhase, useChartActive } from '@/registry/lib/chart-base'\nimport {\n  CartesianChartFrame,\n  type CartesianChartFrameProps,\n  type CartesianChartValue,\n  type CartesianStop,\n  useCartesian,\n} from '@/registry/lib/chart-cartesian'\nimport { type CartesianModel, markLayer } from '@/registry/lib/chart-frame'\nimport { seriesPoints } from '@/registry/lib/chart-line-marks'\nimport { type ChartLive, ChartLiveLayer } from '@/registry/lib/chart-live-clock'\nimport type { ChartDatum, ReadingDirection } from '@/registry/lib/chart-math'\nimport {\n  forcedSeriesColor,\n  forcedSeriesTextColor,\n  plotLayerClassName,\n  type MoveRole,\n  seriesColor,\n  stepBackInkClassName,\n  useFromRest,\n  usePointsMove,\n} from '@/registry/lib/chart-root'\nimport { bandCentre } from '@/registry/lib/chart-scale'\nimport {\n  alignLines,\n  holdArrivals,\n  bridgesThrough,\n  type LineCurve,\n  type LinePoint,\n  lonePointsThrough,\n  pathThrough,\n  type PathCurve,\n  pointsAt,\n} from '@/registry/lib/line-path'\nimport { LivePulse } from '@/registry/lib/live'\nimport { placeholderBreatheClassName } from '@/registry/lib/placeholder'\nimport { registerProperties } from '@/registry/lib/run-progress'\nimport {\n  type ComponentProps,\n  createContext,\n  type CSSProperties,\n  memo,\n  type ReactNode,\n  type RefObject,\n  use,\n  useId,\n  useLayoutEffect,\n  useMemo,\n  useRef,\n  useState,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * What the charts drawn as lines share, on the chart core: the Line chart's\n * lines, the Area chart's areas and the Bump chart's ranks. Each series is a line drawn by d3-shape\n * from its points, with a fill under it for an area, and its points move on\n * one CSS transition of a number, `--line-progress`, so the feel, reduced\n * motion and a slowed playback time it as they time everything else. A frame\n * of that transition redraws the paths straight in the page, so nothing\n * re-renders while a line moves. Its paths are drawn in fractions of the\n * plot, in an SVG one unit square stretched over it, with strokes that keep\n * their width, so the server draws the lines the browser does and a plot\n * that changes size never redraws them.\n *\n * When a category is lit, a dot on each series marks it, gliding with the\n * axis's pill. A series brought forward, from the legend or the Bump\n * chart's pointer, stays as it is while every other one steps back whole.\n *\n * Each chart names the variables a buyer tunes after itself\n * (`--line-chart-width`, `--area-chart-width`): the root of each series reads\n * them into the `--trace-*` variables its parts draw with.\n */\n\n/** Which chart a series belongs to, which names the variables it reads. */\ntype LineFamilyName = 'line-chart' | 'area-chart' | 'bump-chart' | 'composed-chart'\n\ninterface LineFamilyValue {\n  name: LineFamilyName\n  phase: EntrancePhase\n  entrance: 'rise' | 'draw' | 'none'\n  /** The lit category's dot on each series, by series, which a series' move carries with it. */\n  litDots: RefObject<Map<string, HTMLElement>>\n  /**\n   * A series' points for the categories shown, with their baselines for an\n   * area; along zero when `rising`, before the chart's entrance.\n   */\n  pointsOf: (key: string, rising: boolean) => LinePoint[]\n  /** Where a series' lit dot sits on `category`, as a fraction of the plot from its top, or null with no value. */\n  topOf: (key: string, stop: CartesianStop) => number | null\n  /** Where a second lit dot marks the bottom of a value given as a range, as `topOf` does its top; null for a single value. */\n  bottomOf?: (key: string, stop: CartesianStop) => number | null\n  /** Where a series lies flat, such as one that arrives on an empty chart, as a fraction of the plot from its top: its axis's baseline. */\n  restOf: (key: string) => number\n}\n\n/** The key the lit dot on the bottom of a series' range goes by among the lit dots. */\nfunction bottomDotKey(key: string) {\n  return `${key}\\u0000bottom`\n}\n\nconst LineFamilyContext = createContext<LineFamilyValue | null>(null)\n\nfunction useLineFamily() {\n  const family = use(LineFamilyContext)\n  if (!family) throw new Error('`Line` and `Area` go inside their chart.')\n  return family\n}\n\n/**\n * A series' points through the stops shown where it has a row, read\n * against its own value axis, as fractions of the plot: an area's baseline\n * too `withBase`, and all along its axis's baseline when it lies `flat`.\n * A stop where only another dataset has a row is skipped, never a gap.\n */\nfunction framePoints(\n  chart: Pick<CartesianChartValue, 'current' | 'rowOf'>,\n  model: CartesianModel,\n  key: string,\n  flat: boolean,\n  withBase: boolean,\n): LinePoint[] {\n  const { scale, baseline } = model.valueAxisOf(key)\n  return seriesPoints(\n    chart.current.filter((stop) => chart.rowOf(key, stop) !== null),\n    model.spans[key] ?? [],\n    scale,\n    baseline,\n    flat,\n    withBase,\n  )\n}\n\n/** Where a series' span on `category` ends, its value's far end or with `near` its near end, as a fraction of the plot from its top; null with no value. */\nfunction frameTop(\n  model: CartesianModel,\n  key: string,\n  stop: CartesianStop,\n  near = false,\n): number | null {\n  const span = model.spans[key]?.[stop.index]\n  const { scale } = model.valueAxisOf(key)\n  return span ? 1 - scale.place(near ? span[0] : span[1]) : null\n}\n\n/** Where a series lies flat, as a fraction of the plot from its top: on its axis's baseline. */\nfunction frameRest(model: CartesianModel, key: string): number {\n  return 1 - model.valueAxisOf(key).baseline\n}\n\n/** The variables a series draws with, read from its chart's own. */\nfunction traceVariables(name: LineFamilyName) {\n  return {\n    '--trace-width': `var(--${name}-width, 2px)`,\n    '--trace-fill-top': `var(--${name}-fill-top, 0.32)`,\n    '--trace-fill-bottom': `var(--${name}-fill-bottom, 0.04)`,\n  } as CSSProperties\n}\n\n/**\n * The frame of a chart drawn as lines: the cartesian frame, with room\n * beside the plot for a dot on the first or last point, the placeholder\n * while it loads, and the dots that mark the lit category.\n */\nfunction LineFamilyFrame({\n  family,\n  className,\n  children,\n  ...props\n}: Omit<CartesianChartFrameProps, 'slot'> & {\n  family: Omit<LineFamilyValue, 'litDots'>\n}) {\n  const litDots = useRef(new Map<string, HTMLElement>())\n  useLayoutEffect(registerLineProperties, [])\n  return (\n    <LineFamilyContext value={{ ...family, litDots }}>\n      <CartesianChartFrame\n        slot={family.name}\n        // The columns beside the plot keep room for a dot on the first or the last point, half of\n        // which reaches past the plot, even with no axis there; the pointer finds it there too.\n        className={cn(\n          'grid-cols-[minmax(0.375rem,auto)_minmax(0,1fr)_minmax(0.375rem,auto)] **:data-[slot=chart-columns]:before:absolute **:data-[slot=chart-columns]:before:inset-y-0 **:data-[slot=chart-columns]:before:-inset-x-1.5',\n          className,\n        )}\n        {...props}\n      >\n        {children}\n        <LineLitMarks />\n      </CartesianChartFrame>\n    </LineFamilyContext>\n  )\n}\n\n/** The properties the series move on, so their transitions can run them. Once per page. */\nfunction registerLineProperties() {\n  registerProperties([\n    // Where the lit dots sit across the plot, as a fraction, so they glide between categories.\n    {\n      name: '--lit-dot-x',\n      syntax: '<number>',\n      inherits: true,\n      initialValue: '0',\n    },\n  ])\n}\n\n/** Everything a series draws for one set of points: the line, the bridges over its gaps, its lone points, its fill, and where its forecast starts. */\ninterface LineDrawing {\n  line: string\n  bridges: string\n  lone: string\n  /** The fill under the line, for an area; empty for a bare line. */\n  area: string\n  /** Where the fill is strongest, as a fraction of the plot from its top. */\n  peak: number\n  /** Where the dashed forecast starts, as a fraction of the plot from the reading start, or null with none. */\n  split: number | null\n}\n\n/** What a series draws through `points`, in fractions of the plot, for an SVG of `unitFrame`. */\nfunction drawingOf(\n  points: readonly LinePoint[],\n  curve: PathCurve,\n  splitKey: string | null,\n  fill: boolean,\n): LineDrawing {\n  const split =\n    splitKey === null ? null : (points.find((point) => point.key === splitKey)?.x ?? null)\n  return {\n    line: pathThrough(points, curve, 1, 1),\n    bridges: bridgesThrough(points, 1, 1),\n    lone: lonePointsThrough(points, 1, 1),\n    area: fill ? areaPathThrough(points, curve, 1, 1) : '',\n    peak: fill ? fillPeak(points) : 0,\n    split,\n  }\n}\n\n/**\n * The frame of a series' SVGs: one unit square, stretched over the plot,\n * so a path drawn in fractions of it fills it at any size. Every stroke in\n * it keeps its width with `non-scaling-stroke`, dashes and round caps too.\n */\nconst unitFrame = { viewBox: '0 0 1 1', preserveAspectRatio: 'none' } as const\n\n/** The elements a series redraws on each frame of a move. */\ninterface LineElements {\n  paths: RefObject<(SVGPathElement | null)[]>\n  bridges: RefObject<SVGPathElement | null>\n  lone: RefObject<SVGPathElement | null>\n  splits: RefObject<(SVGRectElement | null)[]>\n  /** The fill's path and gradient, for an area. */\n  fill: AreaFillElements\n  dots: RefObject<Map<string, HTMLElement>>\n  /** The series' dots on the lit category, if they show: on its top, and on the bottom of a range. */\n  litDots: () => readonly [HTMLElement | undefined, HTMLElement | undefined]\n  /** A live series' hold, from its newest point on to the plot's end, at that point's value. */\n  hold: RefObject<HTMLElement | null>\n  /** The pulse where the hold meets the plot's end. */\n  tip: RefObject<HTMLElement | null>\n  /** The fill under a live area's hold. */\n  holdFill: AreaFillElements\n}\n\n/**\n * Writes a drawing and its points into the series' elements. While the\n * series is `moving`, the lit category's dot rides on it; after, it goes\n * back to where the chart places it.\n */\nfunction paint(\n  elements: LineElements,\n  drawing: LineDrawing,\n  points: readonly LinePoint[],\n  moving = false,\n) {\n  for (const path of elements.paths.current) path?.setAttribute('d', drawing.line)\n  elements.bridges.current?.setAttribute('d', drawing.bridges)\n  elements.lone.current?.setAttribute('d', drawing.lone)\n  paintFill(elements.fill, drawing.area, drawing.peak)\n  const [solid, dashed] = elements.splits.current\n  if (drawing.split !== null) {\n    solid?.setAttribute('width', String(Math.max(0, drawing.split + SPLIT_BLEED)))\n    dashed?.setAttribute('x', String(drawing.split))\n  }\n  for (const point of points) {\n    if (point.key === null) continue\n    const dot = elements.dots.current.get(point.key)\n    if (dot) dot.style.translate = `${percentOf(point.x)}cqw ${percentOf(point.y)}cqh`\n  }\n  const newest = points.findLast((point) => point.defined)\n  if (newest) {\n    const hold = elements.hold.current\n    if (hold) hold.style.translate = `${percentOf(newest.x)}cqw ${percentOf(newest.y)}cqh`\n    const tip = elements.tip.current\n    if (tip) tip.style.translate = `100cqw ${percentOf(newest.y)}cqh`\n    paintFill(elements.holdFill, drawing.area && holdArea(newest), drawing.peak)\n  }\n  paintLitDots(elements.litDots(), points, moving)\n}\n\n/**\n * Carries a series' lit dots, on its top and on the bottom of a range, with\n * its points while it is `moving`; after, they go back to where the chart\n * places them.\n */\nfunction paintLitDots(\n  [top, bottom]: readonly [HTMLElement | undefined, HTMLElement | undefined],\n  points: readonly LinePoint[],\n  moving: boolean,\n) {\n  for (const [litDot, heightOf] of [\n    [top, (point: LinePoint) => point.y],\n    [bottom, (point: LinePoint) => point.base],\n  ] as const) {\n    if (!litDot) continue\n    const lit = moving\n      ? points.find((point) => point.key === litDot.dataset.key)\n      : undefined\n    const height = lit && heightOf(lit)\n    if (height !== undefined) {\n      litDot.dataset.moving = ''\n      litDot.style.setProperty('--lit-dot-y', `${height * 100}cqh`)\n    } else {\n      delete litDot.dataset.moving\n      litDot.style.removeProperty('--lit-dot-y')\n    }\n  }\n}\n\n/** How far past the plot's edges a series' clips reach, as a share of the plot, so its caps aren't cut. */\nconst SPLIT_BLEED = 1\n\n/**\n * Moves a series' elements to `to` whenever it changes: from wherever they\n * are, even halfway through a move, on the frames of `--line-progress`. A\n * change of curve alone redraws at once.\n */\nfunction useLineMove(\n  role: MoveRole,\n  elements: LineElements,\n  to: readonly LinePoint[],\n  curve: PathCurve,\n  splitKey: string | null,\n  fill: boolean,\n  start: readonly LinePoint[],\n  origin: number,\n  holds: boolean,\n) {\n  // The plot share the points last drawn were placed from, as the time a live chart draws its\n  // rows against moves on: the points on screen move with it, so the move starts where they are.\n  const drawnFrom = useRef(origin)\n  usePointsMove(\n    role,\n    to,\n    to\n      .map(\n        (point) =>\n          `${point.key}:${point.x.toFixed(5)}:${point.y.toFixed(5)}:${point.base?.toFixed(5)}:${point.defined}`,\n      )\n      .join('|'),\n    start,\n    `${curve}|${splitKey}|${fill}`,\n    {\n      align: (from, next) => {\n        const shift = drawnFrom.current - origin\n        drawnFrom.current = origin\n        const drawn =\n          shift === 0 ? from : from.map((point) => ({ ...point, x: point.x + shift }))\n        const aligned = alignLines(drawn, next, curve)\n        return holds ? holdArrivals(aligned, drawn) : aligned\n      },\n      at: pointsAt,\n      draw: (points, moving) =>\n        paint(elements, drawingOf(points, curve, splitKey, fill), points, moving),\n    },\n  )\n}\n\ninterface LineSeriesProps extends Omit<ComponentProps<'div'>, 'children' | 'color'> {\n  /** The key of this series' values in the data, and of its entry in the config. */\n  dataKey: string\n  /** How the line runs between its points: a smooth curve that never overshoots them, straight, or in steps. */\n  curve?: LineCurve\n  /** Marks every point with a dot, not only the one lit; `'last'` marks only the last value, as a sparkline's end dot does. */\n  dots?: boolean | 'last'\n  /** Draws the whole line dashed, such as a target or last year's line. */\n  dashed?: boolean\n  /** The key of the first category that is a forecast: the line is dashed from the one before it on. */\n  forecastFrom?: string\n  /** Bridges each gap a missing value leaves with a dashed line, in place of a break. */\n  connectNulls?: boolean\n  /**\n   * The series' own rows, on an x of times, in place of the chart's: each\n   * with the chart's `index` and the series' `dataKey`, in time order, such\n   * as a trend of two points or a second stream. Its line runs through its\n   * own times only.\n   */\n  data?: readonly ChartDatum[]\n}\n\n/**\n * One series, in the series' colour: a layer of the plot holding its fill\n * for an area, its line, a dashed bridge over each missing value, and a dot\n * on each point. It steps back while another series is brought forward.\n */\nfunction LineSeries({\n  dataKey,\n  data,\n  curve = 'monotone',\n  dots = false,\n  dashed = false,\n  forecastFrom,\n  connectNulls = false,\n  fill = false,\n  className,\n  style,\n  ...props\n}: Omit<LineSeriesProps, 'curve'> & {\n  /** How the line runs between its points, a bump chart's S among them. */\n  curve?: PathCurve\n  /** Fills the area under the line, down to its baseline. */\n  fill?: boolean\n}) {\n  const chart = useCartesian()\n  const family = useLineFamily()\n  const id = useId().replaceAll(':', '')\n  const hidden = chart.hidden.includes(dataKey)\n  const rising = !chart.entered && family.entrance === 'rise'\n  // While the chart loads, the series folds into the placeholder's and fades, and grows back\n  // out of it when the data arrives.\n  const loading = chart.status === 'loading'\n  const drawn = chart.status === 'ready' || chart.status === 'hidden' || loading\n  const { pointsOf } = family\n  // Worked out again only when the data, the scale or the size change, never on a hover over the plot.\n  const to = useMemo(\n    () => (loading ? placeholderPoints(fill) : drawn ? pointsOf(dataKey, rising) : []),\n    // `pointsOf` is made again whenever the chart's data, scale or shown series change.\n    [pointsOf, dataKey, rising, loading, drawn, fill],\n  )\n  const first = to.findIndex((point) => point.key === forecastFrom)\n  const splitKey = first > 0 ? (to[first - 1]?.key ?? null) : null\n  // A forecast from the first category on is the whole line.\n  const allForecast = first === 0\n  const paths = useRef<(SVGPathElement | null)[]>([])\n  const bridges = useRef<SVGPathElement>(null)\n  const lone = useRef<SVGPathElement>(null)\n  const splits = useRef<(SVGRectElement | null)[]>([])\n  // Each ref is its own call: the React Compiler keeps an object it builds once, skipping hooks\n  // written inside it.\n  const fillPath = useRef<SVGPathElement>(null)\n  const fillGradient = useRef<SVGLinearGradientElement>(null)\n  const fillElements = { path: fillPath, gradient: fillGradient }\n  const dotElements = useRef(new Map<string, HTMLElement>())\n  const hold = useRef<HTMLSpanElement>(null)\n  const tip = useRef<HTMLSpanElement>(null)\n  const holdFillPath = useRef<SVGPathElement>(null)\n  const holdFillGradient = useRef<SVGLinearGradientElement>(null)\n  const holdFill = { path: holdFillPath, gradient: holdFillGradient }\n  const live = chart.frame.live\n  const rest = family.restOf(dataKey)\n  // Where a series that arrives on an empty chart starts: flat along its baseline.\n  const start = useMemo(\n    () =>\n      to.map((point) => ({\n        ...point,\n        y: rest,\n        ...(point.base === undefined ? {} : { base: rest }),\n      })),\n    [to, rest],\n  )\n  useLineMove(\n    // The entrance draws the lines along their length, as a live chart draws each row in from\n    // the line's end; every other change moves them.\n    family.phase === 'entering' || live ? 'draw' : 'layout',\n    {\n      paths,\n      bridges,\n      lone,\n      splits,\n      fill: fillElements,\n      dots: dotElements,\n      litDots: () => [\n        family.litDots.current.get(dataKey),\n        family.litDots.current.get(bottomDotKey(dataKey)),\n      ],\n      hold,\n      tip,\n      holdFill,\n    },\n    to,\n    curve,\n    splitKey,\n    fill,\n    start,\n    live ? live.anchor / live.window : 0,\n    live !== null && chart.status === 'ready',\n  )\n  const drawing = useMemo(\n    () => drawingOf(to, curve, splitKey, fill),\n    [to, curve, splitKey, fill],\n  )\n  if (!drawn) return null\n  const slot = chart.series.indexOf(dataKey)\n  // The series steps back, whole, while another is brought forward.\n  const stepsBack = chart.emphasis !== null && chart.emphasis !== dataKey\n  const pathClass =\n    'fill-none stroke-current [stroke-width:calc(var(--trace-width)*var(--trace-weight,1))] [stroke-linecap:round] [stroke-linejoin:round] [vector-effect:non-scaling-stroke]'\n  const splitAt = drawing.split ?? 0\n  return (\n    <div\n      data-slot={`${family.name}-series`}\n      data-series={dataKey}\n      data-own={data ? '' : undefined}\n      data-hidden={hidden || loading ? '' : undefined}\n      aria-hidden\n      className={cn(\n        plotLayerClassName,\n        fill ? markLayer.area : markLayer.line,\n        'transition-opacity duration-(--motion-layout-duration) ease-(--motion-layout-easing) data-hidden:opacity-0',\n        className,\n      )}\n      style={\n        {\n          '--mark-color': seriesColor(dataKey),\n          ...traceVariables(family.name),\n          ...style,\n        } as CSSProperties\n      }\n      {...props}\n    >\n      {/* Rows past the plot's end, as arrive while it is held, wait out of sight. */}\n      <ChartLiveLayer live={live} direction={chart.direction} reach='plot'>\n        <EntranceWipe draws={family.entrance === 'draw'}>\n          <svg\n            {...unitFrame}\n            data-entering={family.phase === 'entering' ? '' : undefined}\n            data-dim={stepsBack ? '' : undefined}\n            className={cn(\n              'absolute inset-0 size-full overflow-visible text-(--mark-ink) transition-[color] duration-(--motion-layout-duration) ease-(--motion-layout-fade-easing) forced-colors:data-dim:[--trace-weight:0.5] data-entering:duration-(--motion-draw-duration) data-entering:ease-(--motion-draw-fade-easing)',\n              stepBackInkClassName,\n              forcedSeriesTextColor(slot),\n            )}\n          >\n            {splitKey && (\n              <defs>\n                <clipPath id={`${id}-solid`}>\n                  <rect\n                    ref={(element) => {\n                      splits.current[0] = element\n                    }}\n                    x={-SPLIT_BLEED}\n                    y={-SPLIT_BLEED}\n                    width={splitAt + SPLIT_BLEED}\n                    height={1 + SPLIT_BLEED * 2}\n                  />\n                </clipPath>\n                <clipPath id={`${id}-dashed`}>\n                  <rect\n                    ref={(element) => {\n                      splits.current[1] = element\n                    }}\n                    x={splitAt}\n                    y={-SPLIT_BLEED}\n                    width={1 + SPLIT_BLEED}\n                    height={1 + SPLIT_BLEED * 2}\n                  />\n                </clipPath>\n              </defs>\n            )}\n            <g transform={mirror(chart.direction)}>\n              {fill && (\n                <AreaFill\n                  id={`${id}-fill`}\n                  path={drawing.area}\n                  peak={drawing.peak}\n                  height={1}\n                  elements={fillElements}\n                />\n              )}\n              {connectNulls && (\n                <path\n                  ref={bridges}\n                  d={drawing.bridges}\n                  className={cn(pathClass, 'opacity-60 [stroke-dasharray:2_4]')}\n                />\n              )}\n              <path\n                ref={(element) => {\n                  paths.current[0] = element\n                }}\n                d={drawing.line}\n                clipPath={splitKey ? `url(#${id}-solid)` : undefined}\n                className={cn(\n                  pathClass,\n                  (dashed || allForecast) && '[stroke-dasharray:6_5]',\n                )}\n              />\n              <path\n                ref={lone}\n                d={drawing.lone}\n                className='fill-none stroke-current [stroke-width:calc(var(--trace-width)*3)] [stroke-linecap:round] [vector-effect:non-scaling-stroke]'\n              />\n              {splitKey && (\n                <path\n                  ref={(element) => {\n                    paths.current[1] = element\n                  }}\n                  d={drawing.line}\n                  clipPath={`url(#${id}-dashed)`}\n                  className={cn(pathClass, '[stroke-dasharray:6_5]')}\n                />\n              )}\n            </g>\n          </svg>\n          {dots && chart.status === 'ready' && !hidden && (\n            <LineDots\n              dataKey={dataKey}\n              points={to}\n              dots={dotElements}\n              last={dots === 'last'}\n              slot={slot}\n              dimmed={stepsBack}\n            />\n          )}\n        </EntranceWipe>\n      </ChartLiveLayer>\n      {live && chart.status === 'ready' && !hidden && (\n        <LineHold\n          id={`${id}-fill-hold`}\n          hold={hold}\n          tip={tip}\n          fill={fill ? { elements: holdFill, peak: drawing.peak } : null}\n          points={to}\n          live={live}\n          fresh={live.fresh(dataKey)}\n          slot={slot}\n          dimmed={stepsBack}\n        />\n      )}\n    </div>\n  )\n}\n\n/**\n * A live series' hold: a faint line that carries its newest value on to the\n * plot's end, where a pulse says it is live, so the line always reaches now\n * and its end only moves up or down as each row lands. It shows while the\n * plot runs with the clock and rows keep arriving, and fades once it is\n * held, stopped or its own stream goes quiet, since it then says nothing true.\n * Under an area, the fill holds with it. It is not data: the tooltip and the\n * table read only the rows.\n */\nfunction LineHold({\n  id,\n  hold,\n  tip,\n  fill,\n  points,\n  live,\n  fresh,\n  slot,\n  dimmed,\n}: {\n  id: string\n  hold: RefObject<HTMLSpanElement | null>\n  tip: RefObject<HTMLSpanElement | null>\n  fill: { elements: AreaFillElements; peak: number } | null\n  points: readonly LinePoint[]\n  live: ChartLive\n  /** Whether the rows the series is drawn from are still arriving: its own, or the chart's. */\n  fresh: boolean\n  slot: number\n  dimmed: boolean\n}) {\n  const { direction } = useCartesian()\n  const newest = points.findLast((point) => point.defined)\n  if (!newest) return null\n  const shown = live.running && fresh\n  const flip = direction === 'rtl' && '-scale-x-100'\n  return (\n    <div\n      data-slot='chart-live-hold'\n      data-shown={shown ? '' : undefined}\n      data-dim={dimmed ? '' : undefined}\n      className={cn(\n        forcedSeriesTextColor(slot),\n        'pointer-events-none absolute inset-0 text-(--mark-ink) opacity-0 transition-[color,opacity] duration-(--motion-exit-duration) ease-(--motion-exit-fade-easing) data-shown:opacity-100 data-shown:duration-(--motion-enter-duration) data-shown:ease-(--motion-enter-fade-easing)',\n        stepBackInkClassName,\n      )}\n    >\n      <ChartLiveLayer live={live} direction={direction} reach='plot'>\n        <div className={cn('absolute inset-0', flip)}>\n          {fill && (\n            <svg {...unitFrame} className='absolute inset-0 size-full overflow-visible'>\n              <AreaFill\n                id={id}\n                path={holdArea(newest)}\n                peak={fill.peak}\n                height={1}\n                elements={fill.elements}\n              />\n            </svg>\n          )}\n          {/* As long as the plot is wide, so it runs on to the plot's end from anywhere on it. */}\n          <span\n            ref={hold}\n            className='absolute -top-[calc(var(--trace-width)/2)] left-0 h-(--trace-width) w-[100cqw] rounded-full bg-current opacity-35 forced-colors:bg-[CanvasText]'\n            style={{ translate: `${percentOf(newest.x)}cqw ${percentOf(newest.y)}cqh` }}\n          />\n        </div>\n      </ChartLiveLayer>\n      <div className={cn('absolute inset-0', flip)}>\n        <span\n          ref={tip}\n          data-slot='chart-live-tip'\n          className='absolute top-0 left-0 size-0'\n          style={{ translate: `100cqw ${percentOf(newest.y)}cqh` }}\n        >\n          <LivePulse live={shown} className='absolute -top-1 -left-1 size-2' />\n        </span>\n      </div>\n    </div>\n  )\n}\n\n/** The fill under a hold: from its point on by a plot's width, down to the point's baseline, in a unit frame. */\nfunction holdArea(point: LinePoint) {\n  return `M${point.x},${point.y}H${point.x + 1}V${point.base ?? 1}H${point.x}Z`\n}\n\n/** The transform that runs a series' unit frame from the right, in right to left. */\nfunction mirror(direction: ReadingDirection) {\n  return direction === 'rtl' ? 'translate(1 0) scale(-1 1)' : undefined\n}\n\n/**\n * The chart's first appearance with `entrance='draw'`, when it `draws`: the\n * marks are wiped in from the reading start on `draw`, and stay whole from\n * then on.\n */\nfunction EntranceWipe({ draws, children }: { draws: boolean; children: ReactNode }) {\n  const chart = useCartesian()\n  if (!draws) return children\n  return (\n    <div\n      data-entered={chart.entered ? '' : undefined}\n      className={cn(\n        'absolute -inset-3 transition-[clip-path] duration-(--motion-draw-duration) ease-(--motion-draw-easing) motion-reduce:transition-none',\n        chart.direction === 'rtl'\n          ? '[clip-path:inset(0_0_0_100%)] data-entered:[clip-path:inset(0)]'\n          : '[clip-path:inset(0_100%_0_0)] data-entered:[clip-path:inset(0)]',\n      )}\n    >\n      <div className='absolute inset-3 [container-type:size]'>{children}</div>\n    </div>\n  )\n}\n\n/**\n * A dot on each of a series' points, moved with it on each frame, or with\n * `last` a solid one on its last value only.\n */\nconst LineDots = memo(function LineDots({\n  dataKey,\n  points,\n  dots,\n  last,\n  slot,\n  dimmed,\n}: {\n  dataKey: string\n  points: readonly LinePoint[]\n  dots: RefObject<Map<string, HTMLElement>>\n  last: boolean\n  slot: number\n  /** Every dot steps back, while another series is brought forward. */\n  dimmed: boolean\n}) {\n  const { direction } = useCartesian()\n  const final = points.findLastIndex((point) => point.defined)\n  return (\n    <div className={cn('absolute inset-0', direction === 'rtl' && '-scale-x-100')}>\n      {points.map((point, at) =>\n        point.defined && (!last || at === final) ? (\n          <span\n            key={point.key}\n            ref={(element) => {\n              if (!element || point.key === null) return\n              dots.current.set(point.key, element)\n              return () => {\n                if (point.key !== null && dots.current.get(point.key) === element)\n                  dots.current.delete(point.key)\n              }\n            }}\n            data-dim={dimmed ? '' : undefined}\n            data-series={dataKey}\n            className={cn(\n              forcedSeriesTextColor(slot),\n              'absolute top-0 left-0 size-0 transition-[color] duration-(--motion-layout-duration) ease-(--motion-layout-fade-easing) text-(--mark-ink)',\n              stepBackInkClassName,\n            )}\n            style={{ translate: `${percentOf(point.x)}cqw ${percentOf(point.y)}cqh` }}\n          >\n            <span\n              className={cn(\n                'absolute -top-1 -left-1 size-2 rounded-full',\n                last\n                  ? cn('ring-background bg-current ring-2', forcedSeriesColor(slot))\n                  : 'bg-background border-2 border-current',\n              )}\n            />\n          </span>\n        ) : null,\n      )}\n    </div>\n  )\n})\n\n/** The lit dots of a line family's series, which its series' moves carry. */\nfunction LineLitMarks() {\n  const family = useLineFamily()\n  return (\n    <LitDots\n      slot={`${family.name}-lit`}\n      dots={family.litDots}\n      topOf={family.topOf}\n      bottomOf={family.bottomOf}\n      style={traceVariables(family.name)}\n    />\n  )\n}\n\n/**\n * What marks the lit category on a chart of lines or layers: a dot on each\n * shown series where it crosses the category, on its top, and on the bottom\n * of a range. They glide from category to category with the tooltip, appear\n * in place after a rest, and fade where they are when the pointer leaves.\n * Each is kept in `dots` under its series' key, so the series' move carries\n * it (`paintLitDots`).\n */\nfunction LitDots({\n  slot,\n  dots,\n  topOf,\n  bottomOf,\n  style,\n}: {\n  slot: string\n  dots: RefObject<Map<string, HTMLElement>>\n  topOf: (key: string, stop: CartesianStop) => number | null\n  bottomOf?: (key: string, stop: CartesianStop) => number | null\n  style?: CSSProperties\n}) {\n  const chart = useCartesian()\n  const at = useChartActive().spotlit\n  const marks = useRef<HTMLDivElement>(null)\n  const fromRest = useFromRest(at)\n  // The category last lit, where the marks stay while they fade out.\n  const [last, setLast] = useState(at)\n  if (at !== null && at !== last) setLast(at)\n  const shownAt = at ?? last\n  const category = shownAt === null ? undefined : chart.current[shownAt]\n  if (chart.status !== 'ready' || !category || !chart.entered) return null\n  const centre = bandCentre(category.band)\n  const x = chart.direction === 'rtl' ? 1 - centre : centre\n  const shown = chart.series.filter((key) => !chart.hidden.includes(key))\n  const move =\n    'absolute top-0 left-0 transition-[translate] duration-(--motion-layout-duration) ease-(--motion-layout-easing) data-snap:transition-none motion-reduce:transition-none'\n  const snap = fromRest ? '' : undefined\n  return (\n    <div\n      ref={marks}\n      aria-hidden\n      data-slot={slot}\n      data-hidden={at === null ? '' : undefined}\n      className={cn(\n        plotLayerClassName,\n        'z-20 transition-opacity duration-(--motion-enter-duration) ease-(--motion-enter-easing) data-hidden:opacity-0 data-hidden:duration-(--motion-exit-duration) data-hidden:ease-(--motion-exit-easing)',\n      )}\n      style={style}\n    >\n      <ChartLiveLayer live={chart.frame.live} direction={chart.direction}>\n        {/* Across the plot, the dots move on a property, so they turn back smoothly when a glide\n          changes course. */}\n        <div\n          data-snap={snap}\n          className='absolute inset-0 transition-[--lit-dot-x] duration-(--motion-layout-duration) ease-(--motion-layout-easing) data-snap:transition-none motion-reduce:transition-none'\n          style={{ '--lit-dot-x': x } as CSSProperties}\n        >\n          {shown.flatMap((key) => {\n            // A series with no row here marks its nearest own row, as the tooltip reads it.\n            const near = chart.nearOf(key, category)\n            const top = near && topOf(key, near)\n            const bottom = (near && bottomOf?.(key, near)) ?? null\n            if (!near || top === null) return []\n            const shift = bandCentre(near.band) - centre\n            const dx = chart.direction === 'rtl' ? -shift : shift\n            const dot = (name: string, y: number) => (\n              <span\n                key={name}\n                className='absolute top-0 left-0 size-0 [translate:calc(var(--lit-dot-x)*100cqw)_0]'\n              >\n                <span\n                  ref={(element) => {\n                    if (!element) return\n                    dots.current.set(name, element)\n                    return () => {\n                      if (dots.current.get(name) === element) dots.current.delete(name)\n                    }\n                  }}\n                  data-key={near.key}\n                  data-snap={snap}\n                  // While the series moves, it carries the dot on `--lit-dot-y`, frame by frame.\n                  className={cn(move, 'size-0 data-moving:transition-none')}\n                  style={\n                    {\n                      translate: `${dx * 100}cqw var(--lit-dot-y, ${y * 100}cqh)`,\n                      '--mark-color': seriesColor(key),\n                    } as CSSProperties\n                  }\n                >\n                  {/* A series that steps back while another is brought forward takes its dot with it. */}\n                  <span\n                    data-dim={\n                      chart.emphasis !== null && chart.emphasis !== key ? '' : undefined\n                    }\n                    className={cn(\n                      'bg-(--mark-ink) ring-background absolute -top-1 -left-1 size-2 rounded-full ring-2 transition-[background-color] duration-(--motion-layout-duration) ease-(--motion-layout-fade-easing)',\n                      stepBackInkClassName,\n                      forcedSeriesColor(chart.series.indexOf(key)),\n                    )}\n                  />\n                </span>\n              </span>\n            )\n            return bottom === null\n              ? [dot(key, top)]\n              : [dot(key, top), dot(bottomDotKey(key), bottom)]\n          })}\n        </div>\n      </ChartLiveLayer>\n    </div>\n  )\n}\n\n/** The placeholder's line while the data loads, as fractions of the plot: a fixed, gentle rise, so it reads as a chart. */\nconst PLACEHOLDER_VALUES = [0.38, 0.52, 0.46, 0.64, 0.58, 0.72, 0.66] as const\n\n/** The placeholder's points, with a baseline along the plot's bottom when it is `filled`. */\nfunction placeholderPoints(filled = false): LinePoint[] {\n  return PLACEHOLDER_VALUES.map((value, at) => ({\n    key: null,\n    x: at / (PLACEHOLDER_VALUES.length - 1),\n    y: 1 - value,\n    ...(filled ? { base: 1 } : {}),\n    defined: true,\n  }))\n}\n\n/**\n * The placeholder while the data loads: a soft line breathing slowly, with\n * a soft fill under it for an area, which the series grow out of when the\n * data arrives.\n */\nfunction LinePlaceholder({ name, fill }: { name: LineFamilyName; fill: boolean }) {\n  const id = useId().replaceAll(':', '')\n  const points = placeholderPoints(fill)\n  return (\n    <div\n      data-slot={`${name}-placeholder`}\n      aria-hidden\n      className={cn(\n        plotLayerClassName,\n        'z-10 transition-opacity duration-(--motion-enter-duration) ease-(--motion-enter-easing) group-data-mounted/chart:starting:opacity-0',\n      )}\n      style={traceVariables(name)}\n    >\n      <div\n        className={cn(\n          'text-foreground/10 dark:text-foreground/15 absolute inset-0 forced-colors:text-[GrayText]!',\n          placeholderBreatheClassName,\n        )}\n      >\n        {/* The line is already a faint tint, so its fill is drawn stronger under it. */}\n        <svg\n          {...unitFrame}\n          className='absolute inset-0 size-full overflow-visible [--trace-fill-top:0.6] [--trace-fill-bottom:0.15]'\n        >\n          {fill && (\n            <AreaFill\n              id={`${id}-fill`}\n              path={areaPathThrough(points, 'monotone', 1, 1)}\n              peak={fillPeak(points)}\n              height={1}\n            />\n          )}\n          <path\n            d={pathThrough(points, 'monotone', 1, 1)}\n            className='fill-none stroke-current [stroke-width:var(--trace-width)] [stroke-linecap:round] [vector-effect:non-scaling-stroke]'\n          />\n        </svg>\n      </div>\n    </div>\n  )\n}\n\n/** A place from 0 to 1 as a percentage, rounded so the server and the browser write the same style. */\nfunction percentOf(place: number) {\n  return Math.round(place * 1e6) / 1e4\n}\n\nexport {\n  framePoints,\n  mirror,\n  registerLineProperties,\n  unitFrame,\n  frameRest,\n  frameTop,\n  EntranceWipe,\n  LineFamilyFrame,\n  type LineFamilyName,\n  type LineFamilyValue,\n  LinePlaceholder,\n  LineSeries,\n  LitDots,\n  paintLitDots,\n  type LineSeriesProps,\n  useLineFamily,\n}\n",
      "type": "registry:lib",
      "target": "@lib/chart-line.tsx"
    }
  ],
  "type": "registry:lib"
}