{"version":3,"file":"DynamicIcon.mjs","names":[],"sources":["../../src/dynamic/DynamicIcon.tsx"],"sourcesContent":["'use client';\n\nimport {\n  type ComponentType,\n  lazy,\n  type ReactNode,\n  Suspense,\n  useMemo,\n} from 'react';\nimport type { IconProps } from '../utils';\n\ntype LazyComponent = ComponentType<IconProps>;\ntype LazyCache = Map<string, LazyComponent>;\n\nconst warnedNames: Set<string> = /* @__PURE__ */ new Set<string>();\n\nfunction warnMissing(exportName: string): void {\n  if (\n    typeof process !== 'undefined' &&\n    // biome-ignore lint/complexity/useLiteralKeys: dot notation preferred for bundler DCE, but TS noPropertyAccessFromIndexSignature requires bracket access\n    process.env['NODE_ENV'] !== 'production' &&\n    !warnedNames.has(exportName)\n  ) {\n    warnedNames.add(exportName);\n    // biome-ignore lint/suspicious/noConsole: intentional dev-mode warning\n    console.warn(`[react-web3-icons] Icon \"${exportName}\" not found.`);\n  }\n}\n\n/**\n * Creates a dynamic icon component that lazily loads exactly one icon module\n * per resolved name, so rendering a single icon downloads a per-icon chunk\n * instead of the whole category bundle.\n *\n * @param resolveExportName - Maps user-facing props to the icon's export name (e.g. 'EthereumMono'), or null if not found.\n * @param imports - Per-icon lazy import map for the category (generated by the icon pipeline).\n * @param stripKeys - Props keys to remove before forwarding to the underlying icon component.\n */\nexport function createDynamicIcon<P>(\n  resolveExportName: (props: P) => string | null,\n  imports: Record<string, () => Promise<Record<string, unknown>>>,\n  stripKeys: readonly string[],\n) {\n  const cache: LazyCache = new Map();\n\n  function DynamicIconInner(\n    props: P & Omit<IconProps, 'ref'> & { fallback?: ReactNode },\n  ) {\n    const { fallback = null, ...rest } = props;\n    const exportName = resolveExportName(props as P);\n\n    const LazyIcon = useMemo(() => {\n      if (!exportName) {\n        return null;\n      }\n      const cached = cache.get(exportName);\n      if (cached) {\n        return cached;\n      }\n      const importIcon = imports[exportName];\n      if (!importIcon) {\n        warnMissing(exportName);\n        return null;\n      }\n      const component = lazy(() =>\n        importIcon().then(mod => {\n          const comp = mod[exportName] as LazyComponent | undefined;\n          if (!comp) {\n            warnMissing(exportName);\n            return { default: (() => null) as unknown as LazyComponent };\n          }\n          return { default: comp };\n        }),\n      );\n      cache.set(exportName, component);\n      return component;\n    }, [exportName]);\n\n    if (!LazyIcon) {\n      return <>{fallback}</>;\n    }\n\n    // Strip category-specific props before forwarding\n    const iconProps: Record<string, unknown> = {};\n    for (const [key, value] of Object.entries(rest)) {\n      if (!stripKeys.includes(key)) {\n        iconProps[key] = value;\n      }\n    }\n\n    return (\n      <Suspense fallback={fallback}>\n        <LazyIcon {...(iconProps as IconProps)} />\n      </Suspense>\n    );\n  }\n\n  return DynamicIconInner;\n}\n"],"mappings":";;;;AAcA,MAAM,8BAA2C,IAAI,IAAY;AAEjE,SAAS,YAAY,YAA0B;CAC7C,IACE,OAAO,YAAY,eAEnB,QAAQ,IAAI,gBAAgB,gBAC5B,CAAC,YAAY,IAAI,UAAU,GAC3B;EACA,YAAY,IAAI,UAAU;EAE1B,QAAQ,KAAK,4BAA4B,WAAW,aAAa;CACnE;AACF;;;;;;;;;;AAWA,SAAgB,kBACd,mBACA,SACA,WACA;CACA,MAAM,wBAAmB,IAAI,IAAI;CAEjC,SAAS,iBACP,OACA;EACA,MAAM,EAAE,WAAW,MAAM,GAAG,SAAS;EACrC,MAAM,aAAa,kBAAkB,KAAU;EAE/C,MAAM,WAAW,cAAc;GAC7B,IAAI,CAAC,YACH,OAAO;GAET,MAAM,SAAS,MAAM,IAAI,UAAU;GACnC,IAAI,QACF,OAAO;GAET,MAAM,aAAa,QAAQ;GAC3B,IAAI,CAAC,YAAY;IACf,YAAY,UAAU;IACtB,OAAO;GACT;GACA,MAAM,YAAY,WAChB,WAAW,CAAC,CAAC,MAAK,QAAO;IACvB,MAAM,OAAO,IAAI;IACjB,IAAI,CAAC,MAAM;KACT,YAAY,UAAU;KACtB,OAAO,EAAE,gBAAgB,MAAkC;IAC7D;IACA,OAAO,EAAE,SAAS,KAAK;GACzB,CAAC,CACH;GACA,M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