{"version":3,"file":"bodyEnd.mjs","names":[],"sources":["../../../../package/common/bodyEnd/bodyEnd.tsx"],"sourcesContent":["import { createPortal } from 'react-dom';\nimport { useContext, type CSSProperties, type ReactElement } from 'react';\n\nimport { ThemeVariablesContext } from '../themeProvider/themeVariablesContext';\nimport themeStyles from '../themeProvider/theme.module.pcss';\nimport { PortalHostContext } from './portalHostContext';\nimport type { BodyEndProps } from './bodyEnd.types';\nimport { isDev } from '../utils/isDev';\n\nfunction BodyEnd({ children = null }: BodyEndProps): ReactElement | null {\n  const themeVariables = useContext(ThemeVariablesContext);\n  const host = useContext(PortalHostContext);\n  const target = host === undefined ? document.getElementById('bodyEnd') : host;\n  if (!target) {\n    if (host === undefined && isDev()) {\n      console.error('[BodyEnd] Nowhere to render. Wrap your app in <AhroweProvider>, or add <div id=\"bodyEnd\"></div>.');\n    }\n    return null;\n  }\n  /*\n   * Carry the nearest theme through the portal. `display: contents` is what makes this safe:\n   * the wrapper generates no box, so positioning, stacking and clipping are untouched —\n   * escaping clipping ancestors is the whole point of this component — while custom\n   * properties still inherit, because inheritance follows the element tree, not the box tree.\n   *\n   * Variables this theme leaves unset still fall through to whatever wraps the target, which\n   * is the same cascade the children would have seen rendered in place. `themeRoot` sets the\n   * base typography again, which the target would otherwise pass down from its own theme.\n   */\n  if (!themeVariables) return createPortal(children, target);\n  return createPortal(\n    <div className={themeStyles.themeRoot} style={{ display: 'contents', ...themeVariables } as CSSProperties}>\n      {children}\n    </div>,\n    target,\n  );\n}\n\nexport default BodyEnd;\n"],"mappings":"4WASA,SAAS,EAAQ,CAAE,WAAW,MAA2C,CACvE,IAAM,EAAiB,EAAW,CAAqB,EACjD,EAAO,EAAW,CAAiB,EACnC,EAAS,IAAS,IAAA,GAAY,SAAS,eAAe,SAAS,EAAI,EAkBzE,OAjBK,EAiBE,EADF,EAEH,EAAC,MAAD,CAAK,UAAW,EAAY,UAAW,MAAO,CAAE,QAAS,WAAY,GAAG,CAAe,EACpF,UACE,CAAA,EAJkC,EAKvC,CALuD,GAfnD,IAAS,IAAA,IAAa,EAAM,GAC9B,QAAQ,MAAM,kGAAkG,EAE3G,KAmBX"}