{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "area-fill",
  "title": "Area fill",
  "description": "The fill under a line: the shape between its points and their baselines, a wash in the line’s colour that fades from the shape’s peak to the plot’s bottom, an SVG gradient that steps back with the line. Area chart and Sparkline share it.",
  "dependencies": [
    "d3-shape"
  ],
  "devDependencies": [
    "@types/d3-shape"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/line-path.json"
  ],
  "files": [
    {
      "path": "registry/lib/area-fill.tsx",
      "content": "import { curves, type LinePoint, type PathCurve } from '@/registry/lib/line-path'\nimport { area as areaPath } from 'd3-shape'\nimport type { ComponentProps, RefObject } from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * The fill under a line: the shape between its points and their baselines,\n * in the current text colour, fading from its peak to the plot's bottom so\n * it reads as a wash under the line rather than a block. It is an SVG path\n * with a gradient of its own, so a move redraws it as cheaply as the line\n * above it, and a change of the text colour, such as a series stepping\n * back, fades it with the line. The Area chart draws one under each area,\n * and the Sparkline under its line.\n *\n * How strong the wash is comes from `--trace-fill-top`, at the shape's peak,\n * and `--trace-fill-bottom`, at the plot's bottom, both from 0 to 1, which\n * the chart that draws it sets from its own variables, such as\n * `--area-chart-fill-top`.\n */\n\n/** The shape between `points` and their baselines, for a plot `width` by `height` in the SVG's units, broken at each missing value. */\nfunction areaPathThrough(\n  points: readonly LinePoint[],\n  curve: PathCurve,\n  width: number,\n  height: number,\n): string {\n  return (\n    areaPath<LinePoint>()\n      .defined((point) => point.defined)\n      .x((point) => point.x * width)\n      .y0((point) => (point.base ?? 1) * height)\n      .y1((point) => point.y * height)\n      .curve(curves[curve])(points) ?? ''\n  )\n}\n\n/** The highest any shown point reaches, as a fraction of the plot from its top, where the wash is strongest; 0 with none. */\nfunction fillPeak(points: readonly LinePoint[]): number {\n  let peak = Infinity\n  for (const point of points) {\n    if (point.defined) peak = Math.min(peak, point.y, point.base ?? 1)\n  }\n  return Number.isFinite(peak) ? Math.max(0, peak) : 0\n}\n\n/** The elements a fill redraws on each frame of a move. */\ninterface AreaFillElements {\n  path: RefObject<SVGPathElement | null>\n  gradient: RefObject<SVGLinearGradientElement | null>\n}\n\n/** Writes the fill's shape, `path`, and where its wash starts, `peak` from the top in the SVG's units, straight into its elements. */\nfunction paintFill(elements: AreaFillElements, path: string, peak: number) {\n  elements.path.current?.setAttribute('d', path)\n  elements.gradient.current?.setAttribute('y1', String(peak))\n}\n\n/**\n * The fill, inside an `<svg>`: its gradient, named `id`, and its shape, in\n * the text colour, which forced colours set too.\n */\nfunction AreaFill({\n  id,\n  path,\n  peak,\n  height,\n  elements,\n  className,\n  ...props\n}: Omit<ComponentProps<'path'>, 'id' | 'd' | 'ref'> & {\n  /** The gradient's id, unique on the page. */\n  id: string\n  /** The shape, from `areaPathThrough`. */\n  path: string\n  /** Where the wash is strongest, from the top in the SVG's units. */\n  peak: number\n  /** The plot's height in the SVG's units, where the wash is faintest. */\n  height: number\n  /** Refs to the path and its gradient, for a move to redraw them. */\n  elements?: AreaFillElements\n}) {\n  return (\n    <>\n      <defs>\n        <linearGradient\n          ref={elements?.gradient}\n          id={id}\n          gradientUnits='userSpaceOnUse'\n          x1={0}\n          x2={0}\n          y1={peak}\n          y2={height}\n        >\n          <stop\n            offset={0}\n            className='[stop-color:currentColor] [stop-opacity:var(--trace-fill-top,0.32)]'\n          />\n          <stop\n            offset={1}\n            className='[stop-color:currentColor] [stop-opacity:var(--trace-fill-bottom,0.04)]'\n          />\n        </linearGradient>\n      </defs>\n      <path\n        ref={elements?.path}\n        data-slot='area-fill'\n        d={path}\n        fill={`url(#${id})`}\n        className={cn('stroke-none', className)}\n        {...props}\n      />\n    </>\n  )\n}\n\nexport { AreaFill, type AreaFillElements, areaPathThrough, fillPeak, paintFill }\n",
      "type": "registry:lib",
      "target": "@lib/area-fill.tsx"
    }
  ],
  "type": "registry:lib"
}