{"version":3,"file":"ThemeScopeContext.mjs","names":[],"sources":["../../../src/context/ThemeScopeContext.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport React, { createContext, useContext } from 'react';\nimport type { PropsWithChildren } from 'react';\n\nimport { useChatContext } from './ChatContext';\n\n/**\n * Whether the subtree already renders inside the `str-chat <theme>` scope. A nested `.str-chat`\n * would reset every design token an app overrides on the outer element, so standalone components\n * apply the scope only when nothing above them has.\n */\nconst ThemeScopeContext = createContext(false);\n\n/** Marks its subtree as rendering inside the `str-chat <theme>` scope. */\nexport const ThemeScopeProvider = ({ children }: PropsWithChildren) => (\n  <ThemeScopeContext.Provider value={true}>{children}</ThemeScopeContext.Provider>\n);\n\nexport const useIsInThemeScope = () => useContext(ThemeScopeContext);\n\n/** The scope's classes: the `Chat` theme and `customClasses.chat`, which defaults to `str-chat`. */\nexport const useThemeScopeClassName = () => {\n  const { customClasses, theme } = useChatContext();\n  return clsx(customClasses?.chat ?? 'str-chat', theme);\n};\n\n/**\n * Renders its children inside the `str-chat <theme>` scope, adding a layout-neutral\n * (`display: contents`) wrapper only when no ancestor provides the scope.\n */\nexport const ThemeScope = ({ children }: PropsWithChildren) => {\n  const isInThemeScope = useIsInThemeScope();\n  const themeScopeClassName = useThemeScopeClassName();\n\n  if (isInThemeScope) return <>{children}</>;\n\n  return (\n    <div className={clsx(themeScopeClassName, 'str-chat__theme-scope')}>\n      <ThemeScopeProvider>{children}</ThemeScopeProvider>\n    </div>\n  );\n};\n"],"mappings":";;;;;;;;;;AAWA,IAAM,oBAAoB,cAAc,KAAK;;AAG7C,IAAa,sBAAsB,EAAE,eACnC,oBAAC,kBAAkB,UAAnB;CAA4B,OAAO;CAAO;AAAqC,CAAA;AAGjF,IAAa,0BAA0B,WAAW,iBAAiB;;AAGnE,IAAa,+BAA+B;CAC1C,MAAM,EAAE,eAAe,UAAU,eAAe;CAChD,OAAO,KAAK,eAAe,QAAQ,YAAY,KAAK;AACtD;;;;;AAMA,IAAa,cAAc,EAAE,eAAkC;CAC7D,MAAM,iBAAiB,kBAAkB;CACzC,MAAM,sBAAsB,uBAAuB;CAEnD,IAAI,gBAAgB,OAAO,oBAAA,YAAA,EAAG,SAAW,CAAA;CAEzC,OACE,oBAAC,OAAD;EAAK,WAAW,KAAK,qBAAqB,uBAAuB;YAC/D,oBAAC,oBAAD,EAAqB,SAA6B,CAAA;CAC/C,CAAA;AAET"}