{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "icon",
  "title": "Icon",
  "description": "Astro icon rendering for Lucide symbols and Simple Icons brand marks.",
  "dependencies": [
    "@lucide/astro",
    "class-variance-authority",
    "cn",
    "simple-icons"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "packages/ui/src/components/ui/icon/icon.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport { resolveIcon } from \"./resolve-icon.ts\"\nimport type { IconProps } from \"./types.ts\"\nimport { cn } from \"cn\"\n\ntype Props = IconProps & Omit<HTMLAttributes<\"svg\">, \"name\" | \"href\">\n\nconst { name, href, class: className, ...props } = Astro.props\n\n/** Loaded Lucide component or Simple Icons path data. */\nconst resolved = await resolveIcon({ name, href })\nconst LucideIcon = resolved?.source === \"lucide\" ? resolved.Icon : undefined\nconst simpleIcon = resolved?.source === \"simple\" ? resolved.icon : undefined\n\nconst isLabelled =\n  \"aria-label\" in props || \"aria-labelledby\" in props || \"role\" in props\n\nconst iconClass = cn(\"size-[1em] text-base\", className)\n\nconst requested = name ?? href\nif (requested != null && requested !== \"\" && !LucideIcon && !simpleIcon) {\n  Astro.logger?.warn(\n    `Icon \"${requested}\" was not found in Lucide or Simple Icons`,\n  )\n}\n---\n\n{LucideIcon && (\n  <LucideIcon\n    class={iconClass}\n    aria-hidden={isLabelled ? undefined : \"true\"}\n    {...props}\n  />\n)}\n{simpleIcon && (\n  <svg\n    xmlns=\"http://www.w3.org/2000/svg\"\n    viewBox=\"0 0 24 24\"\n    role=\"img\"\n    height={24}\n    width={24}\n    fill=\"currentColor\"\n    class={iconClass}\n    aria-hidden={isLabelled ? undefined : \"true\"}\n    {...props}\n  >\n    <title>{simpleIcon.title}</title>\n    <path d={simpleIcon.path} />\n  </svg>\n)}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/icon/icon.astro"
    },
    {
      "path": "packages/ui/src/components/ui/icon/icon-frame.astro",
      "content": "---\nimport type { HTMLAttributes, HTMLTag, Polymorphic } from \"astro/types\"\nimport { iconFrameVariants, type IconFrameVariants } from \"./icon-variants\"\n\nimport { cn } from \"cn\"\n\ntype Props<T extends HTMLTag = \"span\"> = Polymorphic<{ as: T }> &\n  HTMLAttributes<T> &\n  IconFrameVariants\n\nconst {\n  as: Tag = \"span\",\n  class: className,\n  size,\n  variant,\n  ...props\n} = Astro.props\n---\n\n<Tag class={cn(iconFrameVariants({ size, variant }), className)} {...props}>\n  <slot />\n</Tag>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/icon/icon-frame.astro"
    },
    {
      "path": "packages/ui/src/components/ui/icon/icon-variants.ts",
      "content": "import { cva, type VariantProps } from 'class-variance-authority'\n\nexport const iconFrameVariants = cva(\n    \"flex shrink-0 items-center justify-center rounded-lg ring-1 inset-shadow-[0_1px_--theme(--color-white/65%)] ring-inset dark:inset-shadow-[0_1px_--theme(--color-white/10%)] [&>svg:not-[class*='size-']]:size-5\",\n    {\n        variants: {\n            size: {\n                default: 'size-10',\n                sm: \"size-8 [&>svg:not-[class*='size-']]:size-4\",\n                lg: \"size-12 [&>svg:not-[class*='size-']]:size-6\",\n            },\n            variant: {\n                default: 'bg-primary/12 text-primary ring-primary/20',\n                glass: 'bg-white/12 text-white ring-white/20 backdrop-blur-md',\n                outline: 'text-foreground ring-foreground/20 bg-transparent',\n            },\n        },\n        defaultVariants: {\n            size: 'default',\n            variant: 'default',\n        },\n    },\n)\n\nexport type IconFrameVariants = VariantProps<typeof iconFrameVariants>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/icon/icon-variants.ts"
    },
    {
      "path": "packages/ui/src/components/ui/icon/lucide-icon.ts",
      "content": "import type { HTMLAttributes } from 'astro/types'\n\n/** Astro renders each Lucide icon module as a component. */\nexport type LucideIconComponent = (props: HTMLAttributes<'svg'>) => unknown\n\n/**\n * Lazy loaders for Lucide icon modules.\n * The server build includes all matching modules for content name lookup.\n * The slug is the kebab-case name on lucide.dev, for example `map-pin`.\n *\n * The parent node_modules path is used to support a monorepo structure. Remove it if the `@lucide/astro` package is installed in the app root.\n */\nconst lucideIconModules = import.meta.glob<{ default: LucideIconComponent }>(\n    [\n        '/node_modules/@lucide/astro/src/icons/*.ts',\n        '/../node_modules/@lucide/astro/src/icons/*.ts',\n        '!**/icons/index.ts',\n    ],\n    { exhaustive: true },\n)\n\n/** Index loaders by slug without loading the icon modules. */\nconst lucideIconLoaders = new Map<string, (typeof lucideIconModules)[string]>()\nfor (const [path, load] of Object.entries(lucideIconModules)) {\n    const slug = path.slice(path.lastIndexOf('/') + 1, -3)\n    // Keep the first match when both package paths contain the same slug.\n    if (!lucideIconLoaders.has(slug)) lucideIconLoaders.set(slug, load)\n}\n\n/** True when Lucide ships a module for this slug. */\nexport function hasLucideIcon(name: string): boolean {\n    return lucideIconLoaders.has(name)\n}\n\n/** Load one Lucide component. Returns undefined when the slug is unknown. */\nexport async function loadLucideIcon(\n    name: string,\n): Promise<LucideIconComponent | undefined> {\n    const load = lucideIconLoaders.get(name)\n    if (!load) return undefined\n    const module = await load()\n    return module.default\n}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/icon/lucide-icon.ts"
    },
    {
      "path": "packages/ui/src/components/ui/icon/resolve-icon.ts",
      "content": "import type { SimpleIcon } from 'simple-icons'\n\nimport type { LucideIconComponent } from './lucide-icon.ts'\nimport type { IconProps } from './types.ts'\n\nexport type IconSource = 'lucide' | 'simple'\n\n/** A loaded icon component and the set it came from. */\nexport type ResolvedIcon =\n    | {\n          source: 'lucide'\n          /** Lucide Astro component for the resolved slug. */\n          Icon: LucideIconComponent\n      }\n    | {\n          source: 'simple'\n          /** Simple Icons path data for the resolved slug. */\n          icon: SimpleIcon\n      }\n\ntype SelectedIcon = {\n    source: IconSource\n    /** Icon slug, for example `menu` or `github`. */\n    name: string\n}\n\n/**\n * Link text that selects an icon when the caller passes `href`.\n * A slug such as `x` exists in Lucide and in Simple Icons.\n * The link selects the brand mark. `phone`, `mail`, and `map-pin`\n * are Lucide icons and are used when Simple Icons has no match.\n */\nexport const hrefIconMap = {\n    'x.com': 'x',\n    twitter: 'twitter',\n    facebook: 'facebook',\n    instagram: 'instagram',\n    pinterest: 'pinterest',\n    youtube: 'youtube',\n    tiktok: 'tiktok',\n    snapchat: 'snapchat',\n    reddit: 'reddit',\n    tumblr: 'tumblr',\n    'wa.me': 'whatsapp',\n    telegram: 'telegram',\n    // telegram short link\n    't.me': 'telegram',\n    discord: 'discord',\n    vimeo: 'vimeo',\n    flickr: 'flickr',\n    yelp: 'yelp',\n    spotify: 'spotify',\n    behance: 'behance',\n    dribbble: 'dribbble',\n    soundcloud: 'soundcloud',\n    github: 'github',\n    twitch: 'twitch',\n    'tel:': 'phone',\n    'mailto:': 'mail',\n    'maps.app.goo.gl': 'google-maps',\n    // google business profile short link\n    'g.page': 'google',\n    linkedin: 'linkedin',\n    // youtube short link\n    'youtu.be': 'youtube',\n    'trustpilot.com': 'trustpilot',\n} as const\n\n/**\n * Choose a Lucide or Simple Icons slug for a content name or a link.\n * A plain name tries Lucide first. A link tries Simple Icons first.\n * Prefix a name with `lucide:` or `simple:` to choose the set.\n */\nexport async function selectIcon(\n    input: Pick<IconProps, 'name' | 'href'>,\n    hasIcon: (source: IconSource, name: string) => boolean | Promise<boolean>,\n): Promise<SelectedIcon | undefined> {\n    let key =\n        input.name != null && input.name !== '' ? String(input.name) : undefined\n    let order = ['lucide', 'simple'] satisfies IconSource[]\n\n    // if no name is provided, try to resolve from the href\n    if (!key && input.href) {\n        const hrefText = input.href.toString()\n        const hrefKey = (\n            Object.keys(hrefIconMap) as (keyof typeof hrefIconMap)[]\n        ).find((candidate) => hrefText.includes(candidate))\n        if (hrefKey) {\n            key = hrefIconMap[hrefKey]\n            order = ['simple', 'lucide']\n        }\n    }\n\n    if (!key) return undefined\n    // `x.com` is a link fragment, not a Lucide slug.\n    if (key === 'x.com') key = 'simple:x'\n\n    const [prefix, icon] = (\n        key.includes(':') ? key.split(':') : [undefined, key]\n    ) as [string | undefined, string | undefined]\n    if (prefix === 'lucide' || prefix === 'simple') order = [prefix]\n    if (!icon) return undefined\n\n    for (const source of order) {\n        if (await hasIcon(source, icon)) return { source, name: icon }\n    }\n\n    return undefined\n}\n\n/**\n * Load a Lucide component or Simple Icons data for a content name or a link.\n * Returns undefined when the name and href do not match an icon.\n */\nexport async function resolveIcon(\n    input: Pick<IconProps, 'name' | 'href'>,\n): Promise<ResolvedIcon | undefined> {\n    // Import each set only when selection reaches it.\n    const selected = await selectIcon(input, async (source, iconName) => {\n        if (source === 'lucide') {\n            const { hasLucideIcon } = await import('./lucide-icon.ts')\n            return hasLucideIcon(iconName)\n        }\n        const { hasSimpleIcon } = await import('./simple-icon.ts')\n        return hasSimpleIcon(iconName)\n    })\n    if (!selected) return undefined\n\n    if (selected.source === 'lucide') {\n        const { loadLucideIcon } = await import('./lucide-icon.ts')\n        const Icon = await loadLucideIcon(selected.name)\n        return Icon ? { source: 'lucide', Icon } : undefined\n    }\n\n    const { loadSimpleIcon } = await import('./simple-icon.ts')\n    const icon = await loadSimpleIcon(selected.name)\n    return icon ? { source: 'simple', icon } : undefined\n}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/icon/resolve-icon.ts"
    },
    {
      "path": "packages/ui/src/components/ui/icon/simple-icon.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport { loadSimpleIcon } from \"./simple-icon.ts\"\n\ntype Props = Omit<HTMLAttributes<\"svg\">, \"name\"> & {\n  /** Simple Icons slug, for example `github` or `x`. */\n  name: string\n}\n\nconst {\n  name,\n  class: className = \"size-[1em] text-base\",\n  ...props\n} = Astro.props\n\nconst icon = loadSimpleIcon(name)\n\nif (!icon) {\n  console.warn(`Simple Icons icon ${name} not found`)\n}\n---\n\n{icon && (\n  <svg\n    xmlns=\"http://www.w3.org/2000/svg\"\n    viewBox=\"0 0 24 24\"\n    role=\"img\"\n    height={24}\n    width={24}\n    fill=\"currentColor\"\n    class={className}\n    {...props}\n  >\n    <title>{icon.title}</title>\n    <path d={icon.path} />\n  </svg>\n)}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/icon/simple-icon.astro"
    },
    {
      "path": "packages/ui/src/components/ui/icon/simple-icon.ts",
      "content": "import * as icons from 'simple-icons'\n\n/**\n * Read icon data on the server and render paths inline.\n * An SVG glob makes Astro emit every matching SVG as a public asset.\n * Static builds discard this data after page rendering. Server builds retain it.\n */\nconst simpleIcons = new Map(\n    Object.values(icons).map((icon) => [icon.slug, icon]),\n)\n\n/** True when Simple Icons has this slug. */\nexport function hasSimpleIcon(name: string) {\n    return simpleIcons.has(name)\n}\n\n/** Load icon data. Returns undefined when the slug is unknown. */\nexport function loadSimpleIcon(name: string) {\n    return simpleIcons.get(name)\n}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/icon/simple-icon.ts"
    },
    {
      "path": "packages/ui/src/components/ui/icon/types.ts",
      "content": "import type { HTMLAttributes } from 'astro/types'\n\n// not adding the lucide icon names to this as it would cause ~2000 icon names to be listed in the docs\n\nexport type IconName = `lucide:${string}` | `simple:${string}`\n\nexport type IconProps = {\n    /** Link used to select a brand icon when `name` is omitted. */\n    href?: HTMLAttributes<'a'>['href']\n    /**\n     * Icon slug from lucide.dev or Simple Icons. Lucide is tried first.\n     * Use `simple:` or `lucide:` when the slug exists in both sets.\n     */\n    name?: IconName | (string & {})\n}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/icon/types.ts"
    },
    {
      "path": "packages/ui/src/components/ui/icon/index.ts",
      "content": "export { default as Icon } from './icon.astro'\nexport { default as IconFrame } from './icon-frame.astro'\nexport * from './types.ts'\n",
      "type": "registry:file",
      "target": "~/src/components/ui/icon/index.ts"
    }
  ],
  "meta": {
    "framework": "astro",
    "source": "@gnostic/ui",
    "testedDependencies": {
      "@lucide/astro": "^1.68.0",
      "class-variance-authority": "^0.7.1",
      "cn": "0.5.2",
      "simple-icons": "^16.36.0"
    }
  },
  "docs": "https://ui.gnosticai.com/components/icon",
  "categories": [
    "ui"
  ],
  "type": "registry:ui"
}
