{"version":3,"file":"themeScope.mjs","names":[],"sources":["../../../../src/plugins/AIComponents/themeScope.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport React, { useContext } from 'react';\nimport type { PropsWithChildren } from 'react';\n\nimport { ChatContext } from '../../context/ChatContext';\nimport { ThemeScopeProvider, useIsInThemeScope } from '../../context/ThemeScopeContext';\n\n/**\n * The `str-chat <theme>` scope classes for an AI component's root, or `undefined` when an ancestor\n * (`ChatView`, `Channel`, `ChannelNavigation` or another AI component) already provides the scope.\n * A nested `.str-chat` would reset the design tokens an app overrides on the outer element.\n *\n * Unlike the main SDK's scope, it does not require `Chat`: the AI components also render without\n * one, and there they get the plain `str-chat` scope, with no theme.\n *\n * A component puts the classes on its own root element and renders its children inside\n * `ThemeScopeProvider`, so the AI components inside it don't add a scope of their own.\n */\nexport const useAIThemeScopeClassName = (): string | undefined => {\n  const isInThemeScope = useIsInThemeScope();\n  const chatContext = useContext(ChatContext);\n  if (isInThemeScope) return undefined;\n  return clsx(chatContext?.customClasses?.chat ?? 'str-chat', chatContext?.theme);\n};\n\n/**\n * The scope for an AI component with no single root element of its own, such as `AIMarkdown`:\n * a layout-neutral (`display: contents`) wrapper, added only when no ancestor provides the scope.\n */\nexport const AIThemeScope = ({ children }: PropsWithChildren) => {\n  const themeScopeClassName = useAIThemeScopeClassName();\n  if (!themeScopeClassName) return <>{children}</>;\n  return (\n    <div className={clsx(themeScopeClassName, 'str-chat__theme-scope')}>\n      <ThemeScopeProvider>{children}</ThemeScopeProvider>\n    </div>\n  );\n};\n\nexport { ThemeScopeProvider };\n"],"mappings":";;;;;;;;;;;;;;;;;AAkBA,IAAa,iCAAqD;CAChE,MAAM,iBAAiB,kBAAkB;CACzC,MAAM,cAAc,WAAW,WAAW;CAC1C,IAAI,gBAAgB,OAAO,KAAA;CAC3B,OAAO,KAAK,aAAa,eAAe,QAAQ,YAAY,aAAa,KAAK;AAChF;;;;;AAMA,IAAa,gBAAgB,EAAE,eAAkC;CAC/D,MAAM,sBAAsB,yBAAyB;CACrD,IAAI,CAAC,qBAAqB,OAAO,oBAAA,YAAA,EAAG,SAAW,CAAA;CAC/C,OACE,oBAAC,OAAD;EAAK,WAAW,KAAK,qBAAqB,uBAAuB;YAC/D,oBAAC,oBAAD,EAAqB,SAA6B,CAAA;CAC/C,CAAA;AAET"}