{"version":3,"file":"index.cjs","sources":["../../../../src/theme/InitCUIThemeScript/InitCUIThemeScript.tsx"],"sourcesContent":["import { THEME_ATTRIBUTE } from '@/utils/dom';\nimport { CUI_THEME_STORAGE_KEY } from '@/utils/localStorage';\nimport { THEMES } from '@/theme/theme.core';\nimport type { ThemeName } from '@/theme/theme.types';\n\nexport interface InitCUIThemeScriptProps {\n  defaultTheme?: ThemeName;\n  storageKey?: string;\n  attribute?: string;\n  nonce?: string;\n}\n\n/** JS string literal safe to embed in an inline `<script>`: `<` is escaped so `</script>` cannot close the element. */\nconst toScriptLiteral = (value: string) => JSON.stringify(value).replace(/</g, '\\\\u003c');\n\n// TODO: Provide support for system prefers-color-scheme\n\nexport const InitCUIThemeScript = ({\n  defaultTheme = THEMES.Light,\n  storageKey = CUI_THEME_STORAGE_KEY,\n  attribute = THEME_ATTRIBUTE,\n  nonce,\n}: InitCUIThemeScriptProps) => {\n  return (\n    <script\n      suppressHydrationWarning\n      nonce={nonce}\n      dangerouslySetInnerHTML={{\n        __html: `(function() {\ntry {\n  const theme = localStorage.getItem(${toScriptLiteral(storageKey)}) || ${toScriptLiteral(defaultTheme)};\n  const dark = ${toScriptLiteral(THEMES.Dark)};\n  const light = ${toScriptLiteral(THEMES.Light)};\n  let colorScheme = '';\n\n  if (theme === light) {\n    colorScheme = light;\n  }\n  if (theme === dark) {\n    colorScheme = dark;\n  }\n  if (colorScheme) {\n    document.documentElement.setAttribute(${toScriptLiteral(attribute)}, colorScheme);\n  }\n} catch(e){}})();`,\n      }}\n    />\n  );\n};\n\nexport default InitCUIThemeScript;\n"],"names":["THEMES","CUI_THEME_STORAGE_KEY","THEME_ATTRIBUTE","jsx"],"mappings":";;;;;;;;;AAaA,MAAM,eAAA,GAAkB,CAAC,KAAA,KAAkB,IAAA,CAAK,UAAU,KAAK,CAAA,CAAE,OAAA,CAAQ,IAAA,EAAM,SAAS,CAAA;AAIjF,MAAM,qBAAqB,CAAC;AAAA,EACjC,eAAeA,iBAAA,CAAO,KAAA;AAAA,EACtB,UAAA,GAAaC,kCAAA;AAAA,EACb,SAAA,GAAYC,mBAAA;AAAA,EACZ;AACF,CAAA,KAA+B;AAC7B,EAAA,uBACEC,cAAA;AAAA,IAAC,QAAA;AAAA,IAAA;AAAA,MACC,wBAAA,EAAwB,IAAA;AAAA,MACxB,KAAA;AAAA,MACA,uBAAA,EAAyB;AAAA,QACvB,MAAA,EAAQ,CAAA;AAAA;AAAA,qCAAA,EAEuB,gBAAgB,UAAU,CAAC,CAAA,KAAA,EAAQ,eAAA,CAAgB,YAAY,CAAC,CAAA;AAAA,eAAA,EACtF,eAAA,CAAgBH,iBAAA,CAAO,IAAI,CAAC,CAAA;AAAA,gBAAA,EAC3B,eAAA,CAAgBA,iBAAA,CAAO,KAAK,CAAC,CAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0CAAA,EAUH,eAAA,CAAgB,SAAS,CAAC,CAAA;AAAA;AAAA,iBAAA;AAAA;AAGhE;AAAA,GACF;AAEJ;;"}