{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "shell-branding",
  "title": "App branding",
  "description": "Applies the accent colour the UI model sets through the theme's variables, and reads the app description.",
  "dependencies": [
    "@registrystack/app-runtime@~0.43.0-next.0"
  ],
  "files": [
    {
      "path": "shell/branding.ts",
      "content": "import { useEffect } from \"react\";\nimport { useModel } from \"@registrystack/app-runtime/react\";\n\n/**\n * The theme variables the accent colour sets. The host has already refused an\n * accent whose text cannot reach WCAG AA, so these are applied as given. The\n * text colour on a filled control stays the theme's own.\n */\nexport function accentVariables(accent: string): Record<string, string> {\n  const channels = [1, 3, 5].map((start) =>\n    Number.parseInt(accent.slice(start, start + 2), 16),\n  );\n  const darker = `#${channels\n    .map((channel) =>\n      Math.round(channel * 0.75)\n        .toString(16)\n        .padStart(2, \"0\"),\n    )\n    .join(\"\")}`;\n  return {\n    \"--primary\": accent,\n    \"--primary-dark\": darker,\n    \"--ring\": accent,\n    \"--link\": accent,\n    \"--link-record\": darker,\n  };\n}\n\ntype Style = {\n  setProperty(name: string, value: string): unknown;\n  removeProperty(name: string): unknown;\n};\n\n/** Sets the accent's variables on a root element's style; the result puts them back. */\nexport function applyAccent(style: Style, accent: string | undefined) {\n  const variables = accent ? accentVariables(accent) : {};\n  for (const [name, value] of Object.entries(variables))\n    style.setProperty(name, value);\n  return () => {\n    for (const name of Object.keys(variables)) style.removeProperty(name);\n  };\n}\n\n/**\n * The branding the UI model sets, with its accent applied to the page. The\n * accent follows the model, so a page that shows before the model is read\n * keeps the theme's own colours.\n */\nexport function useBranding(): { accent?: string; description?: string } {\n  const branding = useModel().data?.branding;\n  const accent = branding?.accent;\n  useEffect(\n    () => applyAccent(document.documentElement.style, accent),\n    [accent],\n  );\n  return branding ?? {};\n}\n",
      "type": "registry:block",
      "target": "@components/shell/branding.ts"
    }
  ],
  "type": "registry:block"
}