{"version":3,"file":"use-icon.cjs","names":[],"sources":["../../src/icons/use-icon.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\nimport type { LucideIcon } from \"lucide-react\";\n\nimport { useIconContext } from \"./icon-context\";\nimport { loadIcon, peekIcon, subscribeToIcons } from \"./shard-cache\";\n\n/**\n * Resolve an icon slug to its component.\n *\n * Resolution is synchronous whenever it can be: the provider registry first, then\n * the shard cache. Both are plain reads during render, so a slug the app declared\n * statically — or one whose shard a sibling icon already pulled in — is returned\n * on the first frame with no intermediate empty state.\n *\n * Only a genuinely cold slug falls through to the effect, which fetches the shard\n * for that initial letter and re-renders once it lands.\n *\n * @param slug - Any icon slug, canonical or deprecated. `undefined` skips work.\n * @returns The icon component, or `undefined` while it is loading or if the slug\n *   does not exist.\n */\nexport function useIcon(slug: string | undefined): LucideIcon | undefined {\n    const context = useIconContext();\n    const fromRegistry = slug ? context?.registry[slug] : undefined;\n    const [, forceRender] = useState(0);\n\n    const cached = !fromRegistry && slug ? peekIcon(slug) : undefined;\n    const resolved = fromRegistry ?? cached;\n\n    useEffect(() => {\n        if (!slug || resolved) return;\n        let active = true;\n        const unsubscribe = subscribeToIcons(() => {\n            if (active) forceRender((n) => n + 1);\n        });\n        void loadIcon(slug);\n        return () => {\n            active = false;\n            unsubscribe();\n        };\n    }, [slug, resolved]);\n\n    return resolved;\n}\n"],"mappings":"4FAqBA,SAAgB,EAAQ,EAAkD,CACtE,IAAM,EAAU,EAAA,eAAe,EACzB,EAAe,EAAO,GAAS,SAAS,GAAQ,IAAA,GAChD,EAAG,IAAA,EAAe,EAAA,SAAA,CAAS,CAAC,EAE5B,EAAS,CAAC,GAAgB,EAAO,EAAA,SAAS,CAAI,EAAI,IAAA,GAClD,EAAW,GAAgB,EAejC,OAbA,EAAA,EAAA,UAAA,KAAgB,CACZ,GAAI,CAAC,GAAQ,EAAU,OACvB,IAAI,EAAS,GACP,EAAc,EAAA,qBAAuB,CACnC,GAAQ,EAAa,GAAM,EAAI,CAAC,CACxC,CAAC,EAED,OADA,EAAK,SAAS,CAAI,MACL,CACT,EAAS,GACT,EAAY,CAChB,CACJ,EAAG,CAAC,EAAM,CAAQ,CAAC,EAEZ,CACX"}