{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "logo",
  "title": "Logo",
  "description": "the brand from lib/brand.ts (Studio › Use system › Brand assets) · one-colour logos take the text colour · placeholder + name without one",
  "dependencies": [
    "cn@^0.5.2"
  ],
  "registryDependencies": [
    "@halftone-web/kit-setup",
    "@halftone-web/lib-brand",
    "@halftone-web/lib-brand-context",
    "@halftone-web/lib-embed"
  ],
  "files": [
    {
      "path": "components/kit/logo.tsx",
      "content": "'use client';\nimport type * as React from 'react';\nimport { cn } from 'cn';\nimport type { BrandImage } from '@/lib/brand';\nimport { brandImageUrl, useBrand } from '@/lib/brand-context';\n\ntype Props = {\n  /** `full` the logo (default), `mark` the square mark (falls back to the logo). */\n  variant?: 'full' | 'mark';\n  /** Height in pixels. Width follows the logo's shape. Default 20. */\n  size?: number;\n  /** The name to show (and read out) when there's no logo: a sample's product name. Default the brand's name. */\n  name?: string;\n  className?: string;\n};\n\n/**\n * The brand's logo from lib/brand.ts (Studio's brand download). A one-colour logo is drawn in the\n * text colour (`currentColor`), so it follows light and dark and any `text-*` class; a coloured one can have a\n * dark version. Without a logo: a placeholder square and the name, so pages look the same before a brand is\n * applied.\n */\nexport function Logo({ variant = 'full', size = 20, name, className }: Props) {\n  const brand = useBrand();\n  const label = name ?? brand.name;\n  const light = variant === 'mark' ? (brand.mark ?? brand.logo) : brand.logo;\n  const dark = variant === 'mark' ? (brand.mark ? brand.markDark : brand.logoDark) : brand.logoDark;\n\n  if (!light) {\n    return (\n      <span className={cn('inline-flex items-center gap-2', className)}>\n        <span aria-hidden className=\"bg-primary shrink-0 rounded-md\" style={{ width: size, height: size }} />\n        {variant === 'full' ? label : <span className=\"sr-only\">{label}</span>}\n      </span>\n    );\n  }\n  const draw = (image: BrandImage, extra?: string): React.ReactNode => {\n    const url = brandImageUrl(image);\n    const box = { width: Math.round(size * image.aspect), height: size };\n    if (image.mono) {\n      const mask = `url(\"${url}\") center / contain no-repeat`;\n      return <span role=\"img\" aria-label={label} className={cn('inline-block shrink-0 bg-current', extra)} style={{ ...box, mask, WebkitMask: mask }} />;\n    }\n    // eslint-disable-next-line @next/next/no-img-element -- a data-URL logo: next/image has nothing to optimise\n    return <img src={url} alt={label} {...box} className={cn('shrink-0', extra)} />;\n  };\n  return (\n    <span className={cn('inline-flex items-center', className)}>\n      {dark ? (\n        <>\n          {draw(light, 'dark:hidden')}\n          {draw(dark, 'hidden dark:inline-block')}\n        </>\n      ) : (\n        draw(light)\n      )}\n    </span>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/kit/logo.tsx"
    },
    {
      "path": "lib/brand.ts",
      "content": "/**\n * Your brand, as <Logo> shows it (components/kit/logo.tsx). Replace this file by unzipping the brand\n * download from Studio (halftonedesignsystem.com/studio › Use system › Brand assets): it carries\n * your logo inline, so it renders the same on a phone, in a static export and in the frames on the docs site.\n *\n * No logo (the default): <Logo> draws a placeholder square and the name, as the kit always has.\n */\nexport type BrandImage = {\n  /** The logo as SVG text, or */\n  svg?: string;\n  /** as a PNG data URL (data:image/png;base64,…). */\n  png?: string;\n  /** Every colour in the SVG is currentColor: the logo takes the theme's text colour in light and dark. */\n  mono?: boolean;\n  /** Width / height. */\n  aspect: number;\n};\n\nexport type Brand = {\n  name: string;\n  /** The full logo (often a wordmark), and its dark-theme version when it isn't mono. */\n  logo?: BrandImage;\n  logoDark?: BrandImage;\n  /** The square mark (app icon, small places); falls back to the logo. */\n  mark?: BrandImage;\n  markDark?: BrandImage;\n};\n\nexport const BRAND: Brand = { name: 'Halftone' };\n",
      "type": "registry:component",
      "target": "lib/brand.ts"
    },
    {
      "path": "lib/brand-context.tsx",
      "content": "'use client';\nimport * as React from 'react';\nimport { BRAND, type Brand, type BrandImage } from '@/lib/brand';\nimport { allowedOrigins, readEmbed } from '@/lib/embed';\n\n/**\n * The brand on screen: lib/brand.ts, or the docs studio's live one in an embedded session. The studio posts\n * `{ type: 'kit:brand', v: 1, brand }` (brand null = back to lib/brand.ts) and keeps the latest in\n * sessionStorage for the next frame. Every image is checked before it is shown.\n */\nexport const EMBED_BRAND_KEY = 'kit.embed.brand';\nconst MAX_SVG = 300_000;\nconst MAX_PNG = 400_000;\n\nfunction isBrandImage(value: unknown): value is BrandImage {\n  if (!value || typeof value !== 'object') return false;\n  const v = value as BrandImage;\n  if (typeof v.aspect !== 'number' || !(v.aspect > 0 && v.aspect < 50)) return false;\n  if (typeof v.png === 'string') return v.png.startsWith('data:image/png;base64,') && v.png.length <= MAX_PNG;\n  if (typeof v.svg === 'string') return v.svg.length <= MAX_SVG && /^<svg\\b/i.test(v.svg.trim()) && !/<script|<foreignObject|\\son[a-z]+\\s*=/i.test(v.svg);\n  return false;\n}\n\n/** A message's brand, checked: the brand, null to go back to lib/brand.ts, or undefined to ignore it. */\nexport function parseEmbedBrand(data: unknown): Brand | null | undefined {\n  const d = data as { type?: unknown; v?: unknown; brand?: unknown } | null;\n  if (d?.type !== 'kit:brand' || d.v !== 1) return undefined;\n  if (d.brand === null) return null;\n  const b = d.brand as Partial<Brand> | undefined;\n  if (!b || typeof b.name !== 'string' || !b.name.trim()) return undefined;\n  const out: Brand = { name: b.name.slice(0, 80) };\n  for (const key of ['logo', 'logoDark', 'mark', 'markDark'] as const) if (isBrandImage(b[key])) out[key] = b[key];\n  return out;\n}\n\n/** A brand image as a URL an <img> or a CSS mask can load. */\nexport const brandImageUrl = (image: BrandImage) => image.png ?? `data:image/svg+xml;charset=utf-8,${encodeURIComponent(image.svg ?? '')}`;\n\n// A tiny store rather than a provider: <Logo> works anywhere, and the server render (BRAND) hydrates cleanly\n// before an embedded frame switches to the studio's brand.\nlet current: Brand = BRAND;\nlet started = false;\nconst listeners = new Set<() => void>();\nconst set = (next: Brand) => {\n  current = next;\n  listeners.forEach((l) => l());\n};\n\nfunction start() {\n  if (started || typeof window === 'undefined') return;\n  started = true;\n  if (!readEmbed().embedded || window.parent === window) return;\n  // The last brand the studio sent, for a frame that loads after it.\n  try {\n    const raw = sessionStorage.getItem(EMBED_BRAND_KEY);\n    const cached = raw ? parseEmbedBrand({ type: 'kit:brand', v: 1, brand: JSON.parse(raw) }) : undefined;\n    if (cached) current = cached;\n  } catch {}\n  const origins = allowedOrigins();\n  window.addEventListener('message', (event: MessageEvent) => {\n    if (!origins.includes(event.origin)) return;\n    const next = parseEmbedBrand(event.data);\n    if (next !== undefined) set(next ?? BRAND);\n  });\n}\n\nconst subscribe = (listener: () => void) => {\n  start();\n  listeners.add(listener);\n  return () => {\n    listeners.delete(listener);\n  };\n};\n\n/** The brand on screen (lib/brand.ts, or the docs studio's live one). */\nexport const useBrand = () => React.useSyncExternalStore(subscribe, () => current, () => BRAND);\n",
      "type": "registry:component",
      "target": "lib/brand-context.tsx"
    }
  ],
  "meta": {
    "exports": [
      "Logo"
    ],
    "api": "<Logo variant?=\"full|mark\" size? name? />"
  },
  "categories": [
    "media"
  ],
  "type": "registry:component"
}