{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "card-09",
  "title": "Done pile",
  "description": "Tasks done today, this week or this month as small tiles that pile up on the headline, then drain away before the next range lands.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/agent-run.json",
    "https://ui.ndekocode.dev/r/card.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/motion-word-roll.json",
    "https://ui.ndekocode.dev/r/seeded.json",
    "https://ui.ndekocode.dev/r/segments.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-autoplay.json",
    "https://ui.ndekocode.dev/r/use-kept-height.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/card/card-09.tsx",
      "content": "'use client';\n\nimport { useEffect, useId, useState } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { WordRoll } from '@/components/core/word-roll';\nimport type { AutoplayStep } from '@/registry/ndeko/hooks/use-autoplay';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { seriesColorOf, type SeriesSlot } from '@/registry/ndeko/lib/agent-run';\nimport { spokenUnless } from '@/registry/ndeko/lib/demonstration';\nimport { CheckIcon } from '@/registry/ndeko/lib/icons';\nimport { hashOf } from '@/registry/ndeko/lib/seeded';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Card } from '@/registry/ndeko/ui/card';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { Segments, type Segment } from '@/registry/ndeko/ui/segments';\n\nimport { SampleNote } from './_parts/sample-note';\nimport { useCardDemo } from './_parts/use-card-demo';\n\nexport type DoneProject = {\n  id: string;\n  name: string;\n  /** The colour of the project's tiles and of its dot in the legend. */\n  series: SeriesSlot;\n};\n\nexport type DoneRange = {\n  id: string;\n  /** The word on the switch, and the words that end the headline: \"Week\", \"this week\". */\n  label: string;\n  phrase: string;\n  /** Tasks done per project id over the range. */\n  done: Record<string, number>;\n};\n\nconst PILE_WIDTH = 260;\n\nconst TILE_GAP = 2;\n\n/** A row sits a little into the one under it, the way loose tiles settle. */\nconst ROW_RISE = 0.9;\n\n/** Rotated tiles dip under their own base line: the pile rests this far above the floor so no corner is cut. */\nconst FLOOR_PX = 3;\n\n/** A wider heap for more tiles: its first row grows with the square root of the count. */\nconst HEAP_SPREAD = 2.6;\n\n/** A month of a busy team would bury the card: the heap stops growing here, the headline keeps the real count. */\nconst MAX_TILES = 90;\n\n/** A tile shifts by up to 2px and leans by up to 7 degrees. */\nconst NUDGE_STEPS = 5;\n\nconst LEAN_STEPS = 15;\n\nconst LEAN_SHIFT = 4;\n\nconst CORNER_SHARE = 0.28;\n\nconst DROP_SPREAD_MS = 520;\n\nconst DROP_STEP_MS = 60;\n\nconst DRAIN_STEP_MS = 30;\n\nconst DRAIN_MS = 440;\n\nconst TILE = [\n  'gem-plate absolute bottom-0 left-0 flex items-center justify-center',\n  'transition-[translate,opacity] duration-500 ease-(--ease-in-out-strong)',\n].join(' ');\n\n/** The heap is laid out on a fixed width: a narrow card shows its middle, where every tile lands, and clips the empty sides. */\nconst PILE_FRAME = 'flex flex-col items-center overflow-hidden';\n\nconst DROPPED_IN = 'starting:-translate-y-36 starting:opacity-0';\n\nconst DRAINED = 'translate-y-12 opacity-0 duration-300';\n\ntype TileStyle = React.CSSProperties & { '--gem': string };\n\ntype TilePlace = { x: number; y: number; turn: number; row: number };\n\nfunction tileSizeOf(count: number) {\n  if (count <= 6) {\n    return 30;\n  }\n  if (count <= 24) {\n    return 22;\n  }\n  if (count <= 48) {\n    return 16;\n  }\n  return 12;\n}\n\nfunction firstRowOf(count: number, size: number) {\n  const step = size + TILE_GAP;\n  const mostColumns = Math.floor(PILE_WIDTH / step);\n  const scaled = count * HEAP_SPREAD;\n  const spread = Math.sqrt(scaled);\n  const wanted = Math.ceil(spread);\n  const fitting = Math.min(wanted, mostColumns);\n  return Math.max(fitting, 1);\n}\n\n/** A whole number spread evenly around zero: 5 steps give -2 to 2. */\nfunction centredOn(bits: number, steps: number) {\n  const half = Math.floor(steps / 2);\n  const within = bits % steps;\n  return within - half;\n}\n\n/** A tile leans and shifts by a few pixels drawn from its place, the same on the server and in the browser. */\nfunction placeOf(\n  count: number,\n  row: number,\n  column: number,\n  rowStart: number,\n  size: number\n): TilePlace {\n  const seed = hashOf(`${count}-${row}-${column}`);\n  const leanBits = seed >>> LEAN_SHIFT;\n  const nudge = centredOn(seed, NUDGE_STEPS);\n  const turn = centredOn(leanBits, LEAN_STEPS);\n  const step = size + TILE_GAP;\n  const offset = column * step;\n  const rise = size * ROW_RISE;\n  const inRow = rowStart + offset;\n  const x = inRow + nudge;\n  const y = row * rise;\n  return { x, y, turn, row };\n}\n\n/**\n * Where each tile of a heap rests, worked out once from the count: rows centred on the floor, each\n * one tile shorter than the row under it. Nothing is simulated while the tiles fall.\n */\nfunction pileOf(count: number, size: number) {\n  const places: TilePlace[] = [];\n  const step = size + TILE_GAP;\n  let rowLength = firstRowOf(count, size);\n  let row = 0;\n  let left = count;\n  while (left > 0) {\n    const inRow = Math.min(rowLength, left);\n    const span = inRow * step;\n    const rowWidth = span - TILE_GAP;\n    const free = PILE_WIDTH - rowWidth;\n    const rowStart = free / 2;\n    for (let column = 0; column < inRow; column += 1) {\n      const place = placeOf(count, row, column, rowStart, size);\n      places.push(place);\n    }\n    const shorter = rowLength - 1;\n    left -= inRow;\n    row += 1;\n    rowLength = Math.max(shorter, 1);\n  }\n  return places;\n}\n\nfunction totalOf(range: DoneRange, projects: DoneProject[]) {\n  let total = 0;\n  for (const project of projects) {\n    const done = range.done[project.id] ?? 0;\n    total += done;\n  }\n  return total;\n}\n\n/** One series per tile, the projects taking turns, so the heap mixes their colours the way a week mixes their tasks. */\nfunction tileSeriesOf(range: DoneRange, projects: DoneProject[]) {\n  const left = projects.map((project) => range.done[project.id] ?? 0);\n  const series: SeriesSlot[] = [];\n  let hasLeft = true;\n  while (hasLeft) {\n    if (series.length >= MAX_TILES) {\n      break;\n    }\n    hasLeft = false;\n    for (let index = 0; index < projects.length; index += 1) {\n      if (left[index] > 0) {\n        left[index] -= 1;\n        series.push(projects[index].series);\n        hasLeft = true;\n      }\n    }\n  }\n  return series.slice(0, MAX_TILES);\n}\n\nfunction dropDelayOf(index: number, count: number) {\n  const tiles = Math.max(count, 1);\n  const even = DROP_SPREAD_MS / tiles;\n  const step = Math.min(even, DROP_STEP_MS);\n  return index * step;\n}\n\nfunction delayOf(\n  place: TilePlace,\n  index: number,\n  count: number,\n  isDraining: boolean\n) {\n  if (isDraining) {\n    return place.row * DRAIN_STEP_MS;\n  }\n  return dropDelayOf(index, count);\n}\n\nfunction taskWordOf(count: number) {\n  if (count === 1) {\n    return 'task done';\n  }\n  return 'tasks done';\n}\n\nfunction drainTimeOf(shouldReduceMotion: boolean) {\n  if (shouldReduceMotion) {\n    return 0;\n  }\n  return DRAIN_MS;\n}\n\ntype PileProps = {\n  rangeId: string;\n  series: SeriesSlot[];\n  /** The tiles fall away through the floor before the next range lands. */\n  isDraining: boolean;\n  /** False for the heap the card starts with: it is there, it does not fall in. */\n  hasDropped: boolean;\n};\n\nfunction Pile({ rangeId, series, isDraining, hasDropped }: PileProps) {\n  const count = series.length;\n  const size = tileSizeOf(count);\n  const places = pileOf(count, size);\n  const radius = size * CORNER_SHARE;\n  const hasGlyph = size >= 22;\n\n  return (\n    <div\n      aria-hidden='true'\n      className='relative h-32 w-[16.25rem] shrink-0 overflow-hidden'\n    >\n      {places.map((place, index) => {\n        const lift = place.y + FLOOR_PX;\n        const delay = delayOf(place, index, count, isDraining);\n        const tileStyle: TileStyle = {\n          '--gem': seriesColorOf(series[index]),\n          width: size,\n          height: size,\n          borderRadius: radius,\n          transform: `translate(${place.x}px, -${lift}px) rotate(${place.turn}deg)`,\n          transitionDelay: `${delay}ms`,\n        };\n        return (\n          <span\n            key={`${rangeId}-${index}`}\n            style={tileStyle}\n            className={cn(\n              TILE,\n              hasDropped && DROPPED_IN,\n              isDraining && DRAINED\n            )}\n          >\n            {hasGlyph && <CheckIcon strokeWidth={2.5} className='size-3' />}\n          </span>\n        );\n      })}\n    </div>\n  );\n}\n\nexport type DonePileProps = {\n  projects: DoneProject[];\n  ranges: DoneRange[];\n  rangeId: string;\n  onRangeChange: (rangeId: string) => void;\n  /** Says the counts are made up. Leave it out for real counts. */\n  note?: string;\n  className?: string;\n};\n\nexport function DonePile({\n  projects,\n  ranges,\n  rangeId,\n  onRangeChange,\n  note,\n  className,\n}: DonePileProps) {\n  const titleId = useId();\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const [shownId, setShownId] = useState(rangeId);\n  const [hasDropped, setHasDropped] = useState(false);\n  const isDraining = rangeId !== shownId;\n  const shown = ranges.find((range) => range.id === shownId);\n\n  useEffect(() => {\n    if (!isDraining) {\n      return;\n    }\n    const timer = setTimeout(() => {\n      setShownId(rangeId);\n      setHasDropped(true);\n    }, drainTimeOf(shouldReduceMotion));\n    return () => clearTimeout(timer);\n  }, [isDraining, rangeId, shouldReduceMotion]);\n\n  if (!shown) {\n    return null;\n  }\n\n  const total = totalOf(shown, projects);\n  const series = tileSeriesOf(shown, projects);\n  const segments: Segment<string>[] = ranges.map((range) => ({\n    value: range.id,\n    label: range.label,\n  }));\n\n  return (\n    <Card\n      role='group'\n      aria-labelledby={titleId}\n      className={cn('@container w-full gap-4 p-5', className)}\n    >\n      <div className='flex flex-wrap items-center justify-between gap-x-3 gap-y-2'>\n        <div className='flex min-w-0 items-baseline gap-2'>\n          <h3 id={titleId} className='text-sm font-medium'>\n            Done\n          </h3>\n          {note && <SampleNote className='truncate'>{note}</SampleNote>}\n        </div>\n        <Segments\n          value={rangeId}\n          segments={segments}\n          onValueChange={onRangeChange}\n          label='Range'\n          className='@max-2xs:w-full'\n        />\n      </div>\n      <div className={PILE_FRAME}>\n        <Pile\n          rangeId={shown.id}\n          series={series}\n          isDraining={isDraining}\n          hasDropped={hasDropped}\n        />\n        <p className='hairline-t border-foreground/15 flex w-full flex-wrap items-baseline justify-center gap-x-1.5 pt-3 text-[13px]'>\n          <MotionNumber\n            value={total}\n            className='text-[28px] leading-8 font-semibold'\n          />\n          <span>{taskWordOf(total)}</span>\n          <WordRoll text={shown.phrase} className='text-muted-foreground' />\n        </p>\n      </div>\n      <ul className='flex flex-wrap justify-center gap-x-4 gap-y-1'>\n        {projects.map((project) => {\n          const dotStyle = { backgroundColor: seriesColorOf(project.series) };\n          return (\n            <li key={project.id} className='flex items-center gap-1.5 text-xs'>\n              <span\n                aria-hidden='true'\n                style={dotStyle}\n                className='size-2 rounded-full'\n              />\n              {project.name}\n              <span className='text-muted-foreground tabular-nums'>\n                {shown.done[project.id] ?? 0}\n              </span>\n            </li>\n          );\n        })}\n      </ul>\n    </Card>\n  );\n}\n\nconst PROJECTS: DoneProject[] = [\n  { id: 'website', name: 'Website', series: 1 },\n  { id: 'mobile', name: 'Mobile app', series: 2 },\n  { id: 'billing', name: 'Billing', series: 3 },\n];\n\nconst RANGES: DoneRange[] = [\n  {\n    id: 'today',\n    label: 'Today',\n    phrase: 'today',\n    done: { website: 2, mobile: 2, billing: 1 },\n  },\n  {\n    id: 'week',\n    label: 'Week',\n    phrase: 'this week',\n    done: { website: 7, mobile: 6, billing: 4 },\n  },\n  {\n    id: 'month',\n    label: 'Month',\n    phrase: 'this month',\n    done: { website: 26, mobile: 21, billing: 15 },\n  },\n];\n\nconst FIRST_RANGE_ID = 'week';\n\nfunction announcementOf(rangeId: string) {\n  const range = RANGES.find((candidate) => candidate.id === rangeId);\n  if (!range) {\n    return '';\n  }\n  const total = totalOf(range, PROJECTS);\n  const word = taskWordOf(total);\n  return `${total} ${word} ${range.phrase}`;\n}\n\nexport default function Card09() {\n  const [rangeId, setRangeId] = useState(FIRST_RANGE_ID);\n\n  const steps: AutoplayStep[] = [\n    { after: 2600, run: () => setRangeId('month') },\n    { after: 3400, run: () => setRangeId('today') },\n    { after: 3000, run: () => setRangeId(FIRST_RANGE_ID) },\n  ];\n  const { ref, isAutoplaying } = useCardDemo(steps, {\n    loopAfter: 600,\n  });\n\n  return (\n    <div ref={ref} className='min-h-[18rem] w-full max-w-[22rem]'>\n      <DonePile\n        projects={PROJECTS}\n        ranges={RANGES}\n        rangeId={rangeId}\n        onRangeChange={setRangeId}\n        note='Illustrative'\n      />\n      <LiveRegion\n        message={spokenUnless(isAutoplaying, announcementOf(rangeId))}\n      />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/card/card-09.tsx"
    },
    {
      "path": "registry/ndeko/components/card/_parts/sample-note.tsx",
      "content": "import { cn } from '@/registry/ndeko/lib/utils';\n\ntype SampleNoteProps = {\n  /** What the sample is: \"Illustrative\", \"Sample quote\". */\n  children?: React.ReactNode;\n  className?: string;\n};\n\n/** The word that says the figures or the words of a demo are made up. */\nexport function SampleNote({\n  children = 'Illustrative',\n  className,\n}: SampleNoteProps) {\n  return (\n    <span className={cn('text-muted-foreground text-xs', className)}>\n      {children}\n    </span>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/card/_parts/sample-note.tsx"
    },
    {
      "path": "registry/ndeko/components/card/_parts/use-card-demo.ts",
      "content": "'use client';\n\nimport {\n  useAutoplay,\n  type AutoplayOptions,\n  type AutoplayStep,\n} from '@/registry/ndeko/hooks/use-autoplay';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\n\n/**\n * What every card demo shares: the demonstration, and the box that keeps its tallest height so a\n * round never moves the page.\n */\nexport function useCardDemo(\n  steps: readonly AutoplayStep[],\n  options?: AutoplayOptions\n) {\n  const demo = useAutoplay(steps, options);\n  const { ref } = demo;\n\n  useKeptHeight(ref);\n\n  return demo;\n}\n",
      "type": "registry:component",
      "target": "components/card/_parts/use-card-demo.ts"
    }
  ],
  "categories": [
    "components",
    "card"
  ],
  "type": "registry:component"
}