{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "checklist",
  "title": "Checklist",
  "description": "A list of things to tick off, such as a recipe's ingredients or a shopping list: each row a checkbox the whole row toggles, with an optional value and action.",
  "dependencies": [
    "@base-ui/react@^1.8.0"
  ],
  "registryDependencies": [
    "@ouro/button",
    "@ouro/checkbox",
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-control-ref",
    "@ouro/lib-dev",
    "@ouro/lib-env",
    "@ouro/lib-refs",
    "@ouro/lib-use-dev-messages"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/checklist/checklist-parts.tsx",
      "content": "\"use client\";\n\nimport { Checkbox as BaseCheckbox } from \"@base-ui/react/checkbox\";\nimport { createContext, useContext, useId, type JSX, type ReactNode, type Ref } from \"react\";\nimport { boxClass, indicatorClass, tickClass } from \"@/registry/ouro/components/ouro/checkbox/checkbox-styles\";\nimport {\n  actionClass,\n  descriptionClass,\n  groupDescriptionClass,\n  groupLabelClass,\n  headerClass,\n  hitClass,\n  labelClass,\n  rootClass,\n  rowClass,\n  rowInnerClass,\n  rowsClass,\n  strikeClass,\n  textClass,\n  valueClass,\n} from \"@/registry/ouro/components/ouro/checklist/checklist-styles\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { controlRef } from \"@/registry/ouro/lib/ouro/control-ref\";\nimport { devThrow } from \"@/registry/ouro/lib/ouro/dev\";\n\nconst ChecklistContext = createContext(false);\n\n/** Marks the hidden input that Base UI submits a box with. */\nconst markInput = controlRef(\"checklist\", \"hidden-input\");\n\n/** The className hint for the parts: their look comes from the theme. */\nconst ownLook = (part: string) => `<${part}>, styled through your theme's tokens; className takes layout only`;\n\n/** Props for {@link ChecklistRoot}. */\nexport interface ChecklistRootProps {\n  /** What the list is, shown above the rows and read as the group's name. Required: a group needs a name. */\n  label: string;\n  /** Hides the label visually; screen readers still read it as the group's name. */\n  hideLabel?: boolean | undefined;\n  /** Supporting text under the label, read after it through `aria-describedby`. */\n  description?: ReactNode | undefined;\n  /** Controls at the end of the header, such as a \"Clear checked\" button. */\n  actions?: ReactNode | undefined;\n  /** The rows: `ChecklistItem`s. */\n  children?: ReactNode;\n  /** Layout only: margins, width, grid placement (`mt-4`). */\n  className?: string | undefined;\n  /** The group element, a `<div role=\"group\">`. */\n  ref?: Ref<HTMLDivElement> | undefined;\n}\n\n/**\n * Part: the group a checklist built from parts renders its rows in, named by `label`. Use the\n * `Checklist` component instead unless its `items` cannot express your rows; a row removed from\n * a ChecklistRoot goes at once, while `Checklist` lets it leave.\n *\n * @example\n * <ChecklistRoot label=\"Steps\">\n *   <ChecklistItem label=\"Preheat the oven\" checked={done.oven} onCheckedChange={(checked) => mark(\"oven\", checked)} />\n * </ChecklistRoot>\n */\nexport function ChecklistRoot(props: ChecklistRootProps): JSX.Element {\n  useAppearanceClassNameCheck(\"ChecklistRoot\", props.className, process.env.NODE_ENV !== \"production\" ? ownLook(\"ChecklistRoot\") : /* istanbul ignore next @preserve -- production only */ \"\");\n  return <ChecklistRootUnchecked {...props} />;\n}\n\n/**\n * The root without its own className check, for `Checklist`, which checks its own. `reserve`\n * keeps the header's height for actions that come and go.\n *\n * @internal\n */\nexport function ChecklistRootUnchecked({ label, hideLabel, description, actions, children, className, ref, reserve }: ChecklistRootProps & { reserve?: boolean | undefined }): JSX.Element {\n  const id = useId();\n  const labelNode = (\n    <div id={`${id}-label`} data-ouro-checklist-label=\"\" className={hideLabel ? \"sr-only\" : groupLabelClass}>\n      {label}\n    </div>\n  );\n  const header = !hideLabel || description !== undefined || actions || reserve;\n  return (\n    <ChecklistContext.Provider value>\n      <div\n        ref={ref}\n        role=\"group\"\n        // Focus falls back here when the focused row leaves and none is left.\n        tabIndex={-1}\n        data-ouro=\"checklist\"\n        aria-labelledby={`${id}-label`}\n        aria-describedby={description !== undefined ? `${id}-description` : undefined}\n        className={cn(rootClass, className)}\n      >\n        {header ? (\n          <div className={headerClass}>\n            <div className=\"grid min-w-0 gap-0.5\">\n              {labelNode}\n              {description !== undefined && (\n                <div id={`${id}-description`} className={groupDescriptionClass}>\n                  {description}\n                </div>\n              )}\n            </div>\n            {actions}\n          </div>\n        ) : (\n          labelNode\n        )}\n        <div data-ouro-checklist-rows=\"\" className={rowsClass}>\n          {children}\n        </div>\n      </div>\n    </ChecklistContext.Provider>\n  );\n}\n\n/** Props for {@link ChecklistItem}. */\nexport interface ChecklistItemProps {\n  /** What to tick off, read as the row's checkbox name. */\n  label: string;\n  /** Supporting text under the label: a note, a substitution. */\n  description?: ReactNode | undefined;\n  /** Trailing text at the end of the row, such as an amount (`1 cup`) or a time. */\n  value?: ReactNode | undefined;\n  /** Whether the row is checked. */\n  checked: boolean;\n  /** Called with the new state when the row is checked or unchecked. */\n  onCheckedChange: (checked: boolean) => void;\n  /** Disables the row's box and fades it. */\n  disabled?: boolean | undefined;\n  /** A control of the row's own beside it (a button, a menu), its own tab stop outside the row's label. */\n  action?: ReactNode | undefined;\n}\n\n/**\n * Part: one row of a `ChecklistRoot`. The whole row but its `action` toggles it: a label holding\n * the box, the text and the value, with the action beside it. Use the `Checklist` component\n * instead unless its `items` cannot express your rows.\n *\n * @example\n * <ChecklistItem label=\"rolled oats\" value=\"1 cup\" checked={oats} onCheckedChange={setOats} />\n */\nexport function ChecklistItem(props: ChecklistItemProps): JSX.Element {\n  return <ChecklistRow {...props} />;\n}\n\n/**\n * A row with its phase, for `Checklist`, which lets rows enter and leave; `ChecklistItem` stays\n * put.\n *\n * @internal\n */\nexport function ChecklistRow({\n  label,\n  description,\n  value,\n  checked,\n  onCheckedChange,\n  disabled,\n  action,\n  phase = \"present\",\n  rowRef,\n}: ChecklistItemProps & { phase?: \"entering\" | \"present\" | \"leaving\" | undefined; rowRef?: Ref<HTMLDivElement> | undefined }): JSX.Element {\n  if (!useContext(ChecklistContext)) {\n    devThrow(\n      \"ChecklistItem\",\n      \"must be rendered inside <ChecklistRoot>\",\n      process.env.NODE_ENV !== \"production\"\n        ? '<ChecklistRoot label=\"…\"><ChecklistItem label=\"…\" checked={…} onCheckedChange={…} /></ChecklistRoot>'\n        : /* istanbul ignore next @preserve -- production only */ \"\",\n    );\n  }\n  const id = useId();\n  const leaving = phase === \"leaving\";\n  const describedBy = [description !== undefined && `${id}-description`, value !== undefined && `${id}-value`].filter(Boolean).join(\" \") || undefined;\n  return (\n    <div\n      ref={rowRef}\n      data-slot=\"checklist-row\"\n      data-ouro-part=\"row\"\n      data-checked={checked ? \"\" : undefined}\n      data-unchecked={checked ? undefined : \"\"}\n      data-disabled={disabled ? \"\" : undefined}\n      data-starting-style={phase === \"entering\" ? \"\" : undefined}\n      data-ending-style={leaving ? \"\" : undefined}\n      inert={leaving || undefined}\n      aria-hidden={leaving || undefined}\n      className={rowClass}\n    >\n      <div className={rowInnerClass}>\n        <label className={hitClass}>\n          <BaseCheckbox.Root\n            checked={checked}\n            onCheckedChange={(next) => onCheckedChange(next)}\n            disabled={disabled}\n            inputRef={markInput}\n            data-ouro-control=\"checklist\"\n            data-ouro-part=\"box\"\n            aria-labelledby={`${id}-label`}\n            aria-describedby={describedBy}\n            className={boxClass}\n          >\n            <BaseCheckbox.Indicator keepMounted className={indicatorClass}>\n              <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth={2} strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" className=\"size-full\">\n                <path d=\"M3.5 8.5 6.5 11.5 12.5 4.5\" pathLength={1} data-ouro-part=\"tick\" className={tickClass} />\n              </svg>\n            </BaseCheckbox.Indicator>\n          </BaseCheckbox.Root>\n          <span className={textClass}>\n            <span id={`${id}-label`} data-ouro-part=\"label\" className={labelClass}>\n              {label}\n              <span aria-hidden=\"true\" data-ouro-part=\"strike\" className={strikeClass} />\n            </span>\n            {description !== undefined && (\n              <span id={`${id}-description`} data-ouro-checklist-description=\"\" className={descriptionClass}>\n                {description}\n              </span>\n            )}\n          </span>\n          {value !== undefined && (\n            <span id={`${id}-value`} data-ouro-part=\"value\" className={valueClass}>\n              {value}\n            </span>\n          )}\n        </label>\n        {action !== undefined && <div className={actionClass}>{action}</div>}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/checklist/checklist-parts.tsx"
    },
    {
      "path": "registry/ouro/components/ouro/checklist/checklist-styles.ts",
      "content": "export {\n  actionClass,\n  descriptionClass,\n  emptyClass,\n  groupDescriptionClass,\n  groupLabelClass,\n  headerClass,\n  hitClass,\n  labelClass,\n  rootClass,\n  rowClass,\n  rowInnerClass,\n  rowPartNames,\n  rowsClass,\n  strikeClass,\n  textClass,\n  valueClass,\n};\n\n// Class strings for Checklist, apart from the components so each component file exports only\n// components (React Fast Refresh). Class strings are literal so the app's Tailwind finds them.\n// A row's state is on the row (`data-checked`, `data-starting-style`, `data-ending-style`), which\n// is the named group `group/row`; the box keeps Checkbox's own `group` for its tick.\n\n/** The group: its header above the rows. @internal */\nconst rootClass = \"grid min-w-0 gap-2 text-foreground outline-ring outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid\";\n\n/** The header: the group's label and description, and the clear button at its end. @internal */\nconst headerClass = \"flex min-h-8 items-center justify-between gap-3\";\n\n/** The group's label. @internal */\nconst groupLabelClass = \"m-0 text-base leading-6 font-medium text-foreground sm:pointer-fine:text-sm sm:pointer-fine:leading-5\";\n\n/** The group's description, under its label. @internal */\nconst groupDescriptionClass = \"m-0 text-sm leading-5 text-muted-foreground\";\n\n/** The rows. @internal */\nconst rowsClass = \"grid min-w-0\";\n\n/**\n * What shows when there are no rows. @internal\n *\n * @claim \"What shows when there are no\" registry/ouro/components/ouro/checklist/checklist.test.tsx verify:testExists(registry/ouro/components/ouro/checklist/checklist.test.tsx::Checklist > shows the empty state once the last row has left)\n */\nconst emptyClass = \"py-2 text-sm leading-5 text-muted-foreground\";\n\n/**\n * A row. It enters from nothing (`@starting-style` while it carries `data-starting-style`)\n * and leaves to nothing (`data-ending-style`): its height through `grid-template-rows` and its\n * opacity, over `--ouro-duration-base`. With reduced motion it only fades, in place.\n *\n * @internal\n */\nconst rowClass =\n  \"group/row grid grid-rows-[1fr] opacity-100 \" +\n  \"motion-safe:[transition:opacity_var(--ouro-duration-base)_var(--ouro-ease-out),grid-template-rows_var(--ouro-duration-base)_var(--ouro-ease-out)] \" +\n  \"motion-reduce:[transition:opacity_var(--ouro-duration-fast)_ease] \" +\n  \"data-ending-style:opacity-0 motion-safe:data-ending-style:grid-rows-[0fr] \" +\n  \"starting:data-starting-style:opacity-0 motion-safe:starting:data-starting-style:grid-rows-[0fr]\";\n\n/**\n * The row's single grid cell, clipped only while the row grows or shrinks, so a focus ring shows at rest. A child\n * selector, not `group-data-starting-style/row`: Chrome restyles every element under anything that gains or loses\n * `data-starting-style` while a `group-data-*` rule on it exists, which made each sheet and popover open restyle the\n * whole of it again (ourostack/ouro-ui#648).\n *\n * @internal\n * @claim \"A child selector, not `group-data-starting-style/row`\" site/e2e/site-menu.spec.ts verify:testExists(site/e2e/site-menu.spec.ts::the site's CSS has no rule that makes an open restyle more than it changes)\n */\nconst rowInnerClass = \"flex min-h-0 min-w-0 items-center gap-1 [[data-starting-style]>&]:overflow-hidden [[data-ending-style]>&]:overflow-hidden\";\n\n/**\n * The row's label: the box, the text and the value, so the whole row but its action toggles.\n * It highlights while hovered (a mouse's only) or pressed rather than scaling, as a list row\n * does, and is at least 44px tall on a coarse pointer.\n *\n * @internal\n * @claim \"It highlights while hovered (a mouse's\" registry/ouro/components/ouro/checklist/checklist.touch.test.tsx verify:testExists(registry/ouro/components/ouro/checklist/checklist.touch.test.tsx::gives every row at least 44px to tap)\n * @claim \"It highlights while hovered (a mouse's\" registry/ouro/components/ouro/checklist/checklist-styles.ts verify:fileLine(registry/ouro/components/ouro/checklist/checklist-styles.ts, /not-has-data-disabled:pointer-fine:hover:bg-muted\\/60\\snot-has-data-disabled:active:bg-muted\\/60/)\n */\nconst hitClass =\n  \"relative m-0 flex min-w-0 flex-1 items-start gap-3 rounded-ouro-md px-2 py-2 pointer-coarse:min-h-11 pointer-coarse:py-2.5 \" +\n  \"cursor-pointer select-none touch-manipulation [-webkit-tap-highlight-color:transparent] \" +\n  \"[transition:background-color_var(--ouro-duration-fast)_ease] \" +\n  \"not-has-data-disabled:pointer-fine:hover:bg-muted/60 not-has-data-disabled:active:bg-muted/60 has-data-disabled:cursor-not-allowed\";\n\n/** The text column: the label, and the description under it. @internal */\nconst textClass = \"flex min-w-0 flex-1 flex-col gap-0.5\";\n\n/** Checking softens the label and the value as the strike crosses them; unchecking returns them at once. */\nconst softens =\n  \"text-foreground group-data-checked/row:text-muted-foreground \" +\n  \"motion-safe:[transition:color_var(--ouro-duration-fast)_ease] \" +\n  \"motion-safe:group-data-checked/row:[transition:color_var(--ouro-duration-draw)_ease_calc(var(--ouro-duration-fast)*2)] \" +\n  \"motion-reduce:[transition:color_var(--ouro-duration-fast)_ease]\";\n\n/** The label's text, as wide as its words so the strike ends where they do. @internal */\nconst labelClass = \"relative w-fit max-w-full text-base leading-6 sm:pointer-fine:text-sm sm:pointer-fine:leading-5 [overflow-wrap:anywhere] \" + softens;\n\n/**\n * The strike: a line through the middle of each line of the label (a gradient one line-height\n * tall, repeated down), drawn from the inline start with `scale` over `--ouro-duration-draw` as the\n * tick finishes, and taken back at once when unchecked. With reduced motion it is whole and fades.\n *\n * @internal\n * @claim \"The strike: a line through the\" registry/ouro/components/ouro/checklist/checklist.test.tsx verify:testExists(registry/ouro/components/ouro/checklist/checklist.test.tsx::Checklist > draws the tick, then the strike, and softens the text)\n */\nconst strikeClass =\n  \"pointer-events-none absolute inset-0 \" +\n  \"[background-image:linear-gradient(transparent_calc(50%_-_0.75px),currentColor_calc(50%_-_0.75px)_calc(50%_+_0.75px),transparent_calc(50%_+_0.75px))] [background-size:100%_1lh] [background-repeat:repeat-y] \" +\n  \"[transform-origin:left_center] rtl:[transform-origin:right_center] [scale:0_1] group-data-checked/row:[scale:1] \" +\n  \"motion-safe:[transition:scale_var(--ouro-duration-fast)_var(--ouro-ease-out)] \" +\n  \"motion-safe:group-data-checked/row:[transition:scale_var(--ouro-duration-draw)_var(--ouro-ease-out)_calc(var(--ouro-duration-fast)*2)] \" +\n  \"motion-reduce:[scale:none] motion-reduce:opacity-0 motion-reduce:group-data-checked/row:opacity-100 motion-reduce:[transition:opacity_var(--ouro-duration-fast)_ease]\";\n\n/** A row's description, under its label. @internal */\nconst descriptionClass = \"text-sm leading-5 text-muted-foreground\";\n\n/** A row's value, at the end of its label: an amount, a time. @internal */\nconst valueClass = \"ms-auto shrink-0 ps-3 text-end text-base leading-6 font-medium tabular-nums sm:pointer-fine:text-sm sm:pointer-fine:leading-5 \" + softens;\n\n/** A row's own action, beside its label. @internal */\nconst actionClass = \"flex shrink-0 items-center pe-1\";\n\n/** The parts of a row whose finite animations hold a leaving row until they end. @internal */\nconst rowPartNames: readonly string[] = [\"row\", \"box\", \"tick\", \"strike\", \"label\", \"value\"];\n",
      "type": "registry:ui",
      "target": "@components/ouro/checklist/checklist-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/checklist/checklist.tsx",
      "content": "\"use client\";\n\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState, type JSX, type ReactNode, type Ref } from \"react\";\nimport { Button } from \"@/registry/ouro/components/ouro/button/button\";\nimport { ChecklistRootUnchecked, ChecklistRow } from \"@/registry/ouro/components/ouro/checklist/checklist-parts\";\nimport { emptyClass, rowPartNames } from \"@/registry/ouro/components/ouro/checklist/checklist-styles\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { useMergedRef } from \"@/registry/ouro/lib/ouro/refs\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\n\n/** One row of a {@link Checklist}. */\nexport interface ChecklistItemData {\n  /** Identifies the row: `onCheckedChange` gets it, and a row keeps its place and motion by it. */\n  id: string;\n  /** What to tick off, read as the row's checkbox name. */\n  label: string;\n  /** Supporting text under the label: a note, a substitution. */\n  description?: ReactNode | undefined;\n  /** Trailing text at the end of the row, such as an amount (`1 cup`) or a time; screen readers hear it after the label. */\n  value?: ReactNode | undefined;\n  /** Whether the row is checked. */\n  checked: boolean;\n  /** Disables the row's box and fades it. */\n  disabled?: boolean | undefined;\n  /** A control of the row's own beside it (a button, a menu), its own tab stop; clicking it does not toggle the row. */\n  action?: ReactNode | undefined;\n}\n\n/** Props for {@link Checklist}. */\nexport interface ChecklistProps {\n  /**\n   * What the list is (\"Ingredients\"), shown above the rows and read as the group's name.\n   * Required: a group needs a name. To hide it visually, keep it and add `hideLabel`.\n   */\n  label: string;\n  /** Hides the label visually; screen readers still read it as the group's name. */\n  hideLabel?: boolean | undefined;\n  /** Supporting text under the label, read after it through `aria-describedby`. */\n  description?: ReactNode | undefined;\n  /**\n   * The rows, in order. Adding one brings it in; removing one lets it leave before it goes, and\n   * an id added back while its row leaves returns that row in place.\n   */\n  items: readonly ChecklistItemData[];\n  /**\n   * Called with a row's id and its new state when it is checked or unchecked. Required: a checklist without it never changes.\n   *\n   * @claim \"Required: a checklist without it never\" registry/ouro/components/ouro/checklist/checklist.test-d.ts verify:fileLine(registry/ouro/components/ouro/checklist/checklist.test-d.ts, /\\{\\slabel:\\s\"Ingredients\";\\sitems:\\sChecklistItemData\\[\\]\\s\\}>\\(\\)\\.not\\.toExtend<ChecklistProps>/)\n   */\n  onCheckedChange: (id: string, checked: boolean) => void;\n  /** Shows a \"Clear checked\" button while something is checked, and is called when it is pressed. */\n  onClearChecked?: (() => void) | undefined;\n  /** The clear button's text. Translate it here. @default \"Clear checked\" */\n  clearLabel?: string | undefined;\n  /**\n   * What shows when there are no rows: text, or an `Empty`.\n   *\n   * @claim \"What shows when there are no\" registry/ouro/components/ouro/checklist/checklist.test.tsx verify:testExists(registry/ouro/components/ouro/checklist/checklist.test.tsx::Checklist > shows the empty state once the last row has left)\n   */\n  empty?: ReactNode | undefined;\n  /**\n   * Layout only: margins, width, grid placement (`mt-4`, `col-span-2`). Appearance classes\n   * warn in development; style checklists in your theme.\n   */\n  className?: string | undefined;\n  /** The group element, a `<div role=\"group\">`. */\n  ref?: Ref<HTMLDivElement> | undefined;\n\n  /** Not a prop. Ouro UI uses `onCheckedChange`, which gets the row's id and its new state. */\n  onChange?: { 'Use onCheckedChange={(id, checked) => setChecked(id, checked)}': never };\n  /**\n   * Not a prop. Each item says whether it is checked: `items={[{ id, label, checked: true }]}`.\n   *\n   * @claim \"Each item says whether it is\" registry/ouro/components/ouro/checklist/checklist.test-d.ts verify:fileLine(registry/ouro/components/ouro/checklist/checklist.test-d.ts, /\\{\\sid:\\s\"oats\";\\slabel:\\s\"rolled\\soats\"\\s\\}>\\(\\)\\.not\\.toExtend<ChecklistItemData>/)\n   */\n  isChecked?: { 'Use items={[{ id, label, checked: true }]}': never };\n  /** Not a prop. Ouro UI uses `onCheckedChange`, which gets the row's id and its new state. */\n  onToggle?: { 'Use onCheckedChange={(id, checked) => setChecked(id, checked)}': never };\n  /** Not a prop. Ouro UI uses `onCheckedChange`, which gets the row's id and its new state. */\n  onCheck?: { 'Use onCheckedChange={(id, checked) => setChecked(id, checked)}': never };\n  /** Not a prop. A checklist is named by its `label`: `<Checklist label=\"Ingredients\">`. */\n  legend?: { 'Use <Checklist label=\"Ingredients\">': never };\n}\n\n/** A row and where it is in its life. */\ninterface Presence<T> {\n  item: T;\n  key: string;\n  phase: \"entering\" | \"present\" | \"leaving\";\n  /**\n   * Bumped on every change of phase, so an exit or entrance that finishes late changes nothing.\n   *\n   * @claim \"Bumped on every change of phase\" registry/ouro/components/ouro/checklist/checklist.test.tsx verify:testExists(registry/ouro/components/ouro/checklist/checklist.test.tsx::Checklist > keeps a removed row until its exit finishes)\n   * @claim \"Bumped on every change of phase\" registry/ouro/components/ouro/checklist/checklist.test.tsx verify:testExists(registry/ouro/components/ouro/checklist/checklist.test.tsx::Checklist > ends in the last state when toggled twice during its animation)\n   */\n  generation: number;\n}\n\n/** Merges the new items into the rows on screen: new keys enter, missing ones leave in place, and a leaving key that is back returns. */\nfunction merge<T>(previous: Array<Presence<T>>, items: readonly T[], key: (item: T) => string): Array<Presence<T>> {\n  const before = new Map(previous.map((entry) => [entry.key, entry]));\n  const next: Array<Presence<T>> = items.map((item) => {\n    const id = key(item);\n    const entry = before.get(id);\n    if (!entry) return { item, key: id, phase: \"entering\", generation: 0 };\n    return entry.phase === \"leaving\" ? { item, key: id, phase: \"present\", generation: entry.generation + 1 } : { ...entry, item };\n  });\n  const kept = new Set(next.map((entry) => entry.key));\n  previous.forEach((entry, index) => {\n    if (kept.has(entry.key)) return;\n    // A leaving row stays after the row it followed (kept, or already placed here), or first.\n    const at = index === 0 ? 0 : next.findIndex((other) => other.key === previous[index - 1]!.key) + 1;\n    next.splice(at, 0, entry.phase === \"leaving\" ? entry : { ...entry, phase: \"leaving\", generation: entry.generation + 1 });\n  });\n  return next;\n}\n\n/**\n * Waits until a row's own finite animations end: a style flush and a frame (so the browser has\n * created the transitions), then every animation on the row or one of its parts whose iterations\n * are finite, cancelled ones included. An endless animation in the row's action (a spinner) never\n * holds it.\n * @claim \"Waits until a row's own finite\" registry/ouro/components/ouro/checklist/checklist.test.tsx verify:testExists(registry/ouro/components/ouro/checklist/checklist.test.tsx::Checklist > keeps a removed row until its exit finishes)\n * @claim \"An endless animation in the row's\" registry/ouro/components/ouro/checklist/checklist.test.tsx verify:testExists(registry/ouro/components/ouro/checklist/checklist.test.tsx::Checklist > exits even when its action animates forever)\n */\nasync function settled(row: HTMLElement): Promise<void> {\n  void getComputedStyle(row).opacity;\n  await new Promise((resolve) => requestAnimationFrame(resolve));\n  const owned = row.getAnimations({ subtree: true }).filter((animation) => {\n    const target = (animation.effect as KeyframeEffect).target!;\n    return (target === row || rowPartNames.includes(target.getAttribute(\"data-ouro-part\") ?? \"\")) && Number.isFinite(animation.effect!.getComputedTiming().iterations);\n  });\n  await Promise.allSettled(owned.map((animation) => animation.finished));\n}\n\n/**\n * Keeps removed items rendered while their rows leave, and marks added ones as entering until\n * they are in. The first render's items are present from the start.\n */\nfunction useExitRetention<T>(items: readonly T[], key: (item: T) => string): { entries: Array<Presence<T>>; rows: Map<string, HTMLElement> } {\n  const [state, setState] = useState(() => ({ items, entries: items.map((item): Presence<T> => ({ item, key: key(item), phase: \"present\", generation: 0 })) }));\n  let entries = state.entries;\n  if (state.items !== items) {\n    entries = merge(state.entries, items, key);\n    setState({ items, entries });\n  }\n  const [rows] = useState(() => new Map<string, HTMLElement>());\n  const [waiting] = useState(() => new Set<string>());\n  const finish = useCallback((done: Presence<T>) => {\n    setState((current) => ({\n      ...current,\n      entries: current.entries.flatMap((entry) => {\n        if (entry.key !== done.key || entry.generation !== done.generation) return [entry];\n        return done.phase === \"leaving\" ? [] : [{ ...entry, phase: \"present\" as const, generation: entry.generation + 1 }];\n      }),\n    }));\n  }, []);\n  useEffect(() => {\n    for (const entry of entries) {\n      const id = `${entry.key}\\n${entry.generation}`;\n      if (entry.phase === \"present\" || waiting.has(id)) continue;\n      waiting.add(id);\n      void settled(rows.get(entry.key)!).then(() => {\n        waiting.delete(id);\n        finish(entry);\n      });\n    }\n  });\n  return { entries, rows };\n}\n\n/** A row's enabled box, which focus can move to. */\nconst boxOf = (row: HTMLElement) => row.querySelector<HTMLElement>('[role=\"checkbox\"]:not([data-disabled])');\n\n/**\n * A list of things to tick off, such as a recipe's ingredients or a shopping list: each row a\n * checkbox the whole row toggles, with an optional value and action. Checking a row fills its\n * box, draws its tick and then a strike through its label, and softens its text; rows enter and\n * leave as `items` changes, and \"Clear checked\" shows while something is checked.\n *\n * Use `CheckboxGroup` instead when the choices submit with a form; use `Checklist` for progress a\n * person ticks off.\n *\n * @group Lists\n * @see https://ui.ouroboros.bot/docs/checklist\n *\n * @example\n * <Checklist\n *   label=\"Ingredients\"\n *   items={[{ id: \"oats\", label: \"rolled oats\", value: \"1 cup\", checked: checked.has(\"oats\") }]}\n *   onCheckedChange={(id, isChecked) => toggle(id, isChecked)}\n *   onClearChecked={clearAll}\n * />\n * @claim \"A list of things to tick\" registry/ouro/components/ouro/checklist/checklist.test.tsx verify:testExists(registry/ouro/components/ouro/checklist/checklist.test.tsx::Checklist > checks a row from anywhere on it, and reports the id)\n */\nexport function Checklist(props: ChecklistProps): JSX.Element {\n  const {\n    label,\n    hideLabel,\n    description,\n    items,\n    onCheckedChange,\n    onClearChecked,\n    clearLabel = \"Clear checked\",\n    empty,\n    className,\n    ref,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    onChange,\n    isChecked,\n    onToggle,\n    onCheck,\n    legend,\n  } = props;\n\n  useAppearanceClassNameCheck(\n    \"Checklist\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? \"<Checklist>, styled through your theme's tokens; className takes layout only\"\n      : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"Checklist\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => {\n          const change = [\"onCheckedChange gets the row's id and its new state\", \"<Checklist onCheckedChange={(id, checked) => setChecked(id, checked)}>\"] as const;\n          const ids = items.map((item) => item.id);\n          const repeated = ids.find((id, index) => ids.indexOf(id) !== index);\n          return [\n            !label && [\"label is required; it names the group for screen readers\", '<Checklist label=\"Ingredients\">'],\n            repeated !== undefined && [`two items share the id \"${repeated}\"; each row needs its own`, 'items={[{ id: \"oats\", … }, { id: \"milk\", … }]}'],\n            onChange !== undefined && [`onChange is not a prop; ${change[0]}`, change[1]],\n            isChecked !== undefined && [\"isChecked is not a prop; each item says whether it is checked\", 'items={[{ id: \"oats\", label: \"rolled oats\", checked: true }]}'],\n            onToggle !== undefined && [`onToggle is not a prop; ${change[0]}`, change[1]],\n            onCheck !== undefined && [`onCheck is not a prop; ${change[0]}`, change[1]],\n            legend !== undefined && [\"legend is not a prop; a checklist is named by its label\", '<Checklist label=\"Ingredients\">'],\n          ];\n        }\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  const root = useRef<HTMLDivElement>(null);\n  const rootRef = useMergedRef(ref, root);\n  const { entries, rows } = useExitRetention(items, (item) => item.id);\n  const anyChecked = items.some((item) => item.checked);\n  const clearing = useRef(false);\n\n  /** Focuses the first enabled box after `from` among the rows still present, else the one before, else the group. */\n  const refocus = (from: number) => {\n    const present = (index: number) => entries[index]!.phase !== \"leaving\" && boxOf(rows.get(entries[index]!.key)!);\n    for (let index = from + 1; index < entries.length; index += 1) {\n      const box = present(index);\n      if (box) return box.focus();\n    }\n    for (let index = Math.min(from, entries.length) - 1; index >= 0; index -= 1) {\n      const box = present(index);\n      if (box) return box.focus();\n    }\n    root.current!.focus();\n  };\n\n  // A focused row that starts to leave hands focus on before it turns inert, so focus never falls to the page.\n  useLayoutEffect(() => {\n    const active = document.activeElement;\n    const leaving = entries.findIndex((entry) => entry.phase === \"leaving\" && rows.get(entry.key)?.contains(active));\n    if (leaving !== -1) refocus(leaving);\n  });\n  // The clear button goes once nothing is checked; focus moves to the first row instead.\n  useLayoutEffect(() => {\n    if (anyChecked || !clearing.current) return;\n    clearing.current = false;\n    refocus(-1);\n  });\n\n  const register = (key: string) => (element: HTMLDivElement | null) => {\n    if (element) rows.set(key, element);\n    else rows.delete(key);\n  };\n\n  return (\n    <ChecklistRootUnchecked\n      label={label}\n      hideLabel={hideLabel}\n      description={description}\n      className={className}\n      ref={rootRef}\n      reserve={onClearChecked !== undefined}\n      actions={\n        onClearChecked && anyChecked ? (\n          <Button\n            variant=\"plain\"\n            size=\"sm\"\n            data-ouro-control=\"checklist\"\n            data-ouro-part=\"clear\"\n            onClick={() => {\n              clearing.current = true;\n              onClearChecked();\n            }}\n          >\n            {clearLabel}\n          </Button>\n        ) : undefined\n      }\n    >\n      {entries.map(({ item, key, phase }) => (\n        <ChecklistRow\n          key={key}\n          rowRef={register(key)}\n          phase={phase}\n          label={item.label}\n          description={item.description}\n          value={item.value}\n          checked={item.checked}\n          disabled={item.disabled}\n          action={item.action}\n          onCheckedChange={(checked) => onCheckedChange(item.id, checked)}\n        />\n      ))}\n      {entries.length === 0 && empty !== undefined && (\n        <div data-ouro-checklist-empty=\"\" className={emptyClass}>\n          {empty}\n        </div>\n      )}\n    </ChecklistRootUnchecked>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/checklist/checklist.tsx"
    }
  ],
  "docs": "A list of things to tick off, such as a recipe's ingredients or a shopping list: each row a checkbox the whole row toggles, with an optional value and action. Import: import { Checklist } from \"@/components/ouro/checklist/checklist\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: button, checkbox, field, the helpers they import in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/checklist.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}