{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "mark-lights",
  "title": "Mark lights",
  "description": "Which mark is lit, such as a cited sentence and its sources: the pointer’s and the focus’s marks held apart, the newest lit, so one leaving gives the light back to the other.",
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/lib/mark-lights.ts",
      "content": "/** What lights a mark, such as a cited sentence and the sources it cites: the pointer's and the focus's marks are held apart, so one leaving gives the light back to the other. */\ntype LightVia = 'pointer' | 'focus'\n\ninterface MarkLights<T> {\n  pointer: T | null\n  focus: T | null\n  /** Which came last, and lights when both are on a mark. */\n  newest: LightVia\n}\n\nconst NO_LIGHTS: MarkLights<never> = { pointer: null, focus: null, newest: 'pointer' }\n\n/** The lights after the pointer or the focus comes to a mark, or leaves one with null. */\nfunction lightMark<T>(\n  lights: MarkLights<T>,\n  via: LightVia,\n  mark: T | null,\n): MarkLights<T> {\n  if (lights[via] === mark) return lights\n  return { ...lights, [via]: mark, newest: mark === null ? lights.newest : via }\n}\n\n/** The mark that is lit: the newest light's, else the other's. */\nfunction litMark<T>(lights: MarkLights<T>): T | null {\n  const other = lights.newest === 'pointer' ? 'focus' : 'pointer'\n  return lights[lights.newest] ?? lights[other]\n}\n\nexport { lightMark, litMark, NO_LIGHTS }\nexport type { LightVia, MarkLights }\n",
      "type": "registry:lib",
      "target": "@lib/mark-lights.ts"
    }
  ],
  "type": "registry:lib"
}