{"version":3,"sources":["../src/color-mode-script.tsx"],"sourcesContent":["export type ColorModeScriptProps = {\n  type?: \"localStorage\" | \"cookie\"\n  initialColorMode?: \"light\" | \"dark\" | \"system\"\n  storageKey?: string\n  nonce?: string\n}\n\nconst VALID_VALUES = new Set([\"dark\", \"light\", \"system\"])\n\n/**\n * runtime safe-guard against invalid color mode values\n */\nfunction normalize(initialColorMode: \"light\" | \"dark\" | \"system\") {\n  let value = initialColorMode\n  if (!VALID_VALUES.has(value)) value = \"light\"\n  return value\n}\n\nexport function getScriptSrc(props: ColorModeScriptProps = {}) {\n  const {\n    initialColorMode = \"light\",\n    type = \"localStorage\",\n    storageKey: key = \"chakra-ui-color-mode\",\n  } = props\n\n  // runtime safe-guard against invalid color mode values\n  const init = normalize(initialColorMode)\n\n  const isCookie = type === \"cookie\"\n\n  const cookieScript = `(function(){try{var a=function(o){var l=\"(prefers-color-scheme: dark)\",v=window.matchMedia(l).matches?\"dark\":\"light\",e=o===\"system\"?v:o,d=document.documentElement,m=document.body,i=\"chakra-ui-light\",n=\"chakra-ui-dark\",s=e===\"dark\";return m.classList.add(s?n:i),m.classList.remove(s?i:n),d.style.colorScheme=e,d.dataset.theme=e,e},u=a,h=\"${init}\",r=\"${key}\",t=document.cookie.match(new RegExp(\"(^| )\".concat(r,\"=([^;]+)\"))),c=t?t[2]:null;c?a(c):document.cookie=\"\".concat(r,\"=\").concat(a(h),\"; max-age=31536000; path=/\")}catch(a){}})();\n  `\n\n  const localStorageScript = `(function(){try{var a=function(c){var v=\"(prefers-color-scheme: dark)\",h=window.matchMedia(v).matches?\"dark\":\"light\",r=c===\"system\"?h:c,o=document.documentElement,s=document.body,l=\"chakra-ui-light\",d=\"chakra-ui-dark\",i=r===\"dark\";return s.classList.add(i?d:l),s.classList.remove(i?l:d),o.style.colorScheme=r,o.dataset.theme=r,r},n=a,m=\"${init}\",e=\"${key}\",t=localStorage.getItem(e);t?a(t):localStorage.setItem(e,a(m))}catch(a){}})();\n  `\n\n  const fn = isCookie ? cookieScript : localStorageScript\n  return `!${fn}`.trim()\n}\n\nexport function ColorModeScript(props: ColorModeScriptProps = {}) {\n  const { nonce } = props\n\n  return (\n    <script\n      id=\"chakra-script\"\n      nonce={nonce}\n      dangerouslySetInnerHTML={{ __html: getScriptSrc(props) }}\n    />\n  )\n}\n"],"mappings":";;;AA4CI;AArCJ,IAAM,eAAe,oBAAI,IAAI,CAAC,QAAQ,SAAS,QAAQ,CAAC;AAKxD,SAAS,UAAU,kBAA+C;AAChE,MAAI,QAAQ;AACZ,MAAI,CAAC,aAAa,IAAI,KAAK;AAAG,YAAQ;AACtC,SAAO;AACT;AAEO,SAAS,aAAa,QAA8B,CAAC,GAAG;AAC7D,QAAM;AAAA,IACJ,mBAAmB;AAAA,IACnB,OAAO;AAAA,IACP,YAAY,MAAM;AAAA,EACpB,IAAI;AAGJ,QAAM,OAAO,UAAU,gBAAgB;AAEvC,QAAM,WAAW,SAAS;AAE1B,QAAM,eAAe,oVAAoV,YAAY;AAAA;AAGrX,QAAM,qBAAqB,oVAAoV,YAAY;AAAA;AAG3X,QAAM,KAAK,WAAW,eAAe;AACrC,SAAO,IAAI,KAAK,KAAK;AACvB;AAEO,SAAS,gBAAgB,QAA8B,CAAC,GAAG;AAChE,QAAM,EAAE,MAAM,IAAI;AAElB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,IAAG;AAAA,MACH;AAAA,MACA,yBAAyB,EAAE,QAAQ,aAAa,KAAK,EAAE;AAAA;AAAA,EACzD;AAEJ;","names":[]}