{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "utils",
  "type": "registry:lib",
  "title": "Utilities",
  "description": "cn(): clsx + tailwind-merge, and the theme-root scope overlays portal into.",
  "dependencies": [
    "clsx@^2.1.1",
    "tailwind-merge@^3.7.0"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/lib/utils.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/lib/utils.ts",
      "content": "import clsx, { type ClassValue } from 'clsx';\nimport { extendTailwindMerge } from 'tailwind-merge';\n\nconst colors = ['canvas', 'surface', 'surface-2', 'surface-3', 'ink', 'ink-2', 'muted', 'line', 'line-strong', 'accent', 'accent-hover', 'accent-soft', 'accent-ink', 'accent-fg', 'on-ink', 'danger'].map((c) => `kh-${c}`);\n\n/** clsx + tailwind-merge, taught the kh- token names so a later class on a primitive really wins. */\nconst merge = extendTailwindMerge({\n  extend: {\n    theme: {\n      color: colors,\n      text: ['kh-caption', 'kh-small', 'kh-body', 'kh-lead', 'kh-heading', 'kh-title', 'kh-display'],\n      radius: ['kh-sm', 'kh', 'kh-lg', 'kh-xl', 'kh-pill'],\n      shadow: ['kh-1', 'kh-2', 'kh-3'],\n      font: ['kh-display', 'kh-sans', 'kh-mono'],\n      spacing: ['kh-section', 'kh-gutter'],\n      container: ['kh-page', 'kh-narrow', 'kh-prose', 'kh-lead'],\n    },\n  },\n});\n\nexport const cn = (...v: ClassValue[]) => merge(clsx(v));\n\n/**\n * Roving focus for a set of buttons: moves focus from `current` to the previous or next enabled match of `selector`\n * inside `container` for the arrow keys on the given axes (wrapping), and to the first or last for Home and End.\n * Returns true when the key was handled, so the caller can preventDefault.\n */\nexport function moveFocus(container: HTMLElement, current: Element, key: string, axis: 'horizontal' | 'vertical' | 'both', selector: string): boolean {\n  const prevKeys = axis === 'horizontal' ? ['ArrowLeft'] : axis === 'vertical' ? ['ArrowUp'] : ['ArrowLeft', 'ArrowUp'];\n  const nextKeys = axis === 'horizontal' ? ['ArrowRight'] : axis === 'vertical' ? ['ArrowDown'] : ['ArrowRight', 'ArrowDown'];\n  const all = [...container.querySelectorAll<HTMLElement>(selector)].filter((el) => !(el as HTMLButtonElement).disabled && el.getAttribute('aria-disabled') !== 'true');\n  const i = all.indexOf(current as HTMLElement);\n  if (i < 0 || all.length === 0) return false;\n  let target: HTMLElement | undefined;\n  if (prevKeys.includes(key)) target = all[(i - 1 + all.length) % all.length];\n  else if (nextKeys.includes(key)) target = all[(i + 1) % all.length];\n  else if (key === 'Home') target = all[0];\n  else if (key === 'End') target = all[all.length - 1];\n  if (!target) return false;\n  target.focus();\n  return true;\n}\n"
    },
    {
      "path": "src/lib/theme-root.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/lib/theme-root.tsx",
      "content": "import { createContext, useCallback, useContext, useState, type ReactNode } from 'react';\n\nconst Ctx = createContext<HTMLElement | undefined>(undefined);\n\n/** The `.kh-root` element an overlay should portal into, so it keeps the theme's tokens. Undefined until mounted. */\nexport const useThemeRoot = () => useContext(Ctx);\n\n/**\n * Overlays (dialog, menu, popover, tooltip) portal out of their parent. The tokens live on `.kh-root`, so a portal to\n * <body> would lose every colour. This finds the root next to the component (else the first on the page) and offers it\n * to the overlay as the portal container.\n */\nexport function ThemeRootScope({ children }: { children: ReactNode }) {\n  const [root, setRoot] = useState<HTMLElement>();\n  const mark = useCallback((el: HTMLElement | null) => {\n    if (el) setRoot(el.closest<HTMLElement>('.kh-root') ?? document.querySelector<HTMLElement>('.kh-root') ?? undefined);\n  }, []);\n  return (\n    <Ctx.Provider value={root}>\n      <span hidden ref={mark} />\n      {children}\n    </Ctx.Provider>\n  );\n}\n"
    },
    {
      "path": "src/lib/placement.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/lib/placement.ts",
      "content": "// Where a block sits: a page band (the default) or inside an app's panel (InPanel, src/blocks/in-panel.tsx). In lib, not blocks,\n// so SidebarLayout (a free component) can set it for its content without depending on the paid block kit (card 18).\nimport { createContext, useContext } from 'react';\n\nexport type BlockPlacement = 'page' | 'panel';\nexport const BlockPlacementContext = createContext<BlockPlacement>('page');\nexport const useInPanel = () => useContext(BlockPlacementContext) === 'panel';\n"
    }
  ]
}
