{"version":3,"file":"renderIcon.mjs","names":[],"sources":["../../../../package/common/utils/renderIcon.tsx"],"sourcesContent":["import type { CSSProperties, ReactNode } from 'react';\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome';\nimport type { IconDefinition } from '@fortawesome/fontawesome-svg-core';\n\nimport type { IconContent } from '../types/icon.types';\n\n/** FontAwesome's own `style` type — `CSSProperties` plus its `--fa-*` variables. */\ntype FaStyle = CSSProperties & Record<`--fa-font-${string}`, string>;\n\ninterface RenderIconOptions {\n  /** Class applied to the rendered icon (or to the wrapper span for a custom element). */\n  className?: string;\n  /** Inline style applied to the rendered icon (or to the wrapper span for a custom element). */\n  style?: CSSProperties;\n}\n\n/**\n * Narrows an `IconContent` to a FontAwesome `IconDefinition`.\n *\n * Both halves of the union are plain objects (a React element is one too), so\n * they can only be told apart structurally: an icon definition always carries\n * `prefix`, `iconName` and the `icon` tuple.\n */\nexport function isIconDefinition(icon: IconContent | null | undefined): icon is IconDefinition {\n  return typeof icon === 'object' && icon !== null && 'prefix' in icon && 'iconName' in icon && 'icon' in icon;\n}\n\n/**\n * Renders an `icon` prop that may be either a FontAwesome `IconDefinition` or an\n * arbitrary React element.\n *\n * A definition goes through `FontAwesomeIcon`; an element is returned untouched\n * unless a `className`/`style` was given, in which case it is wrapped in a\n * `<span>` carrying them so component and consumer slot styling still lands\n * somewhere. Note that a custom element is not sized by FontAwesome's `1em`\n * geometry — size it yourself if the surrounding layout expects a square icon.\n */\nexport function renderIcon(icon: IconContent | null | undefined, options: RenderIconOptions = {}): ReactNode {\n  const { className, style } = options;\n\n  if (icon === null || icon === undefined) return null;\n\n  if (isIconDefinition(icon)) {\n    return <FontAwesomeIcon icon={icon} className={className} style={style as FaStyle} />;\n  }\n\n  if (className || style) {\n    return (\n      <span className={className} style={style}>\n        {icon}\n      </span>\n    );\n  }\n\n  return icon;\n}\n"],"mappings":"sHAuBA,SAAgB,EAAiB,EAA8D,CAC7F,OAAO,OAAO,GAAS,YAAY,GAAiB,WAAY,GAAQ,aAAc,GAAQ,SAAU,CAC1G,CAYA,SAAgB,EAAW,EAAsC,EAA6B,CAAC,EAAc,CAC3G,GAAM,CAAE,YAAW,SAAU,EAgB7B,OAdI,GAAS,KAAmC,KAE5C,EAAiB,CAAI,EAChB,EAAC,EAAD,CAAuB,OAAiB,YAAkB,OAAmB,CAAA,EAGlF,GAAa,EAEb,EAAC,OAAD,CAAiB,YAAkB,QAChC,SAAA,CACG,CAAA,EAIH,CACT"}