UNPKG

iobroker.javascript

Version:
30 lines (29 loc) 11.7 kB
import{b as $e,c as ee,p as $,f as _e,a as q,g as Z,_ as we,r as Re}from"./ConfigCustomJavascriptSet__loadShare__react__loadShare__.mjs-0SjJESw9.js";import{W as Ge,T as D,c as qe,R as He,s as Ue}from"./createTheme-Wd4QxQE0.js";import{j as g}from"./jsx-runtime-DfVU3AZG.js";import{u as Fe,b as Ee,G as Ye,R as Be,d as ze}from"./index-AZB1OHDH.js";import{a as ve}from"./useTheme-DWZ6jNyq.js";import{D as Qe}from"./DefaultPropsProvider-CGb21NGY.js";const Le=$e(null);function te(){return ee(Le)}const Je=typeof Symbol=="function"&&Symbol.for,Xe=Je?Symbol.for("mui.nested"):"__THEME_NESTED__";function Ze(e,t){return typeof t=="function"?t(e):{...e,...t}}function We(e){const{children:t,theme:o}=e,r=te(),l=$(()=>{const d=r===null?{...o}:Ze(r,o);return d!=null&&(d[Xe]=r!==null),d},[o,r]);return g.jsx(Le.Provider,{value:l,children:t})}function et(e){const t=ve(),o=Fe()||"",{modularCssLayers:r}=e;let l="mui.global, mui.components, mui.theme, mui.custom, mui.sx";return!r||t!==null?l="":typeof r=="string"?l=r.replace(/mui(?!\.)/g,l):l=`@layer ${l};`,Ee(()=>{var a,h;const d=document.querySelector("head");if(!d)return;const n=d.firstChild;if(l){if(n&&((a=n.hasAttribute)!=null&&a.call(n,"data-mui-layer-order"))&&n.getAttribute("data-mui-layer-order")===o)return;const p=document.createElement("style");p.setAttribute("data-mui-layer-order",o),p.textContent=l,d.prepend(p)}else(h=d.querySelector(`style[data-mui-layer-order="${o}"]`))==null||h.remove()},[l,o]),l?g.jsx(Ye,{styles:l}):null}const Te={};function ke(e,t,o,r=!1){return $(()=>{const l=e&&t[e]||t;if(typeof o=="function"){const d=o(l),n=e?{...t,[e]:d}:d;return r?()=>n:n}return e?{...t,[e]:o}:{...t,...o}},[e,t,o,r])}function je(e){const{children:t,theme:o,themeId:r}=e,l=ve(Te),d=te()||Te,n=ke(r,l,o),a=ke(r,d,o,!0),h=(r?n[r]:n).direction==="rtl",p=et(n);return g.jsx(We,{theme:a,children:g.jsx(Ge.Provider,{value:n,children:g.jsx(Be,{value:h,children:g.jsxs(Qe,{value:r?n[r].components:n.components,children:[p,t]})})})})}const oe="mode",re="color-scheme",tt="data-color-scheme";function ot(e){const{defaultMode:t="system",defaultLightColorScheme:o="light",defaultDarkColorScheme:r="dark",modeStorageKey:l=oe,colorSchemeStorageKey:d=re,attribute:n=tt,colorSchemeNode:a="document.documentElement",nonce:h}=e||{};let p="",y=n;if(n==="class"&&(y=".%s"),n==="data"&&(y="[data-%s]"),y.startsWith(".")){const f=y.substring(1);p+=`${a}.classList.remove('${f}'.replace('%s', light), '${f}'.replace('%s', dark)); ${a}.classList.add('${f}'.replace('%s', colorScheme));`}const M=y.match(/\[([^\]]+)\]/);if(M){const[f,m]=M[1].split("=");m||(p+=`${a}.removeAttribute('${f}'.replace('%s', light)); ${a}.removeAttribute('${f}'.replace('%s', dark));`),p+=` ${a}.setAttribute('${f}'.replace('%s', colorScheme), ${m?`${m}.replace('%s', colorScheme)`:'""'});`}else p+=`${a}.setAttribute('${y}', colorScheme);`;return g.jsx("script",{suppressHydrationWarning:!0,nonce:typeof window>"u"?h:"",dangerouslySetInnerHTML:{__html:`(function() { try { let colorScheme = ''; const mode = localStorage.getItem('${l}') || '${t}'; const dark = localStorage.getItem('${d}-dark') || '${r}'; const light = localStorage.getItem('${d}-light') || '${o}'; if (mode === 'system') { // handle system mode const mql = window.matchMedia('(prefers-color-scheme: dark)'); if (mql.matches) { colorScheme = dark } else { colorScheme = light } } if (mode === 'light') { colorScheme = light; } if (mode === 'dark') { colorScheme = dark; } if (colorScheme) { ${p} } } catch(e){}})();`}},"mui-color-scheme-init")}function rt(){}const nt=({key:e,storageWindow:t})=>(!t&&typeof window<"u"&&(t=window),{get(o){if(typeof window>"u")return;if(!t)return o;let r;try{r=t.localStorage.getItem(e)}catch{}return r||o},set:o=>{if(t)try{t.localStorage.setItem(e,o)}catch{}},subscribe:o=>{if(!t)return rt;const r=l=>{const d=l.newValue;l.key===e&&o(d)};return t.addEventListener("storage",r),()=>{t.removeEventListener("storage",r)}}});function W(){}function xe(e){if(typeof window<"u"&&typeof window.matchMedia=="function"&&e==="system")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Ie(e,t){if(e.mode==="light"||e.mode==="system"&&e.systemMode==="light")return t("light");if(e.mode==="dark"||e.mode==="system"&&e.systemMode==="dark")return t("dark")}function st(e){return Ie(e,t=>{if(t==="light")return e.lightColorScheme;if(t==="dark")return e.darkColorScheme})}function ct(e){const{defaultMode:t="light",defaultLightColorScheme:o,defaultDarkColorScheme:r,supportedColorSchemes:l=[],modeStorageKey:d=oe,colorSchemeStorageKey:n=re,storageWindow:a=typeof window>"u"?void 0:window,storageManager:h=nt,noSsr:p=!1}=e,y=l.join(","),M=l.length>1,f=$(()=>h==null?void 0:h({key:d,storageWindow:a}),[h,d,a]),m=$(()=>h==null?void 0:h({key:`${n}-light`,storageWindow:a}),[h,n,a]),S=$(()=>h==null?void 0:h({key:`${n}-dark`,storageWindow:a}),[h,n,a]),[E,I]=_e(()=>{const s=(f==null?void 0:f.get(t))||t,c=(m==null?void 0:m.get(o))||o,i=(S==null?void 0:S.get(r))||r;return{mode:s,systemMode:xe(s),lightColorScheme:c,darkColorScheme:i}}),[L,F]=_e(p||!M);q(()=>{F(!0)},[]);const O=st(E),V=Z(s=>{I(c=>{if(s===c.mode)return c;const i=s??t;return f==null||f.set(i),{...c,mode:i,systemMode:xe(i)}})},[f,t]),A=Z(s=>{s?typeof s=="string"?s&&!y.includes(s)?console.error(`\`${s}\` does not exist in \`theme.colorSchemes\`.`):I(c=>{const i={...c};return Ie(c,u=>{u==="light"&&(m==null||m.set(s),i.lightColorScheme=s),u==="dark"&&(S==null||S.set(s),i.darkColorScheme=s)}),i}):I(c=>{const i={...c},u=s.light===null?o:s.light,j=s.dark===null?r:s.dark;return u&&(y.includes(u)?(i.lightColorScheme=u,m==null||m.set(u)):console.error(`\`${u}\` does not exist in \`theme.colorSchemes\`.`)),j&&(y.includes(j)?(i.darkColorScheme=j,S==null||S.set(j)):console.error(`\`${j}\` does not exist in \`theme.colorSchemes\`.`)),i}):I(c=>(m==null||m.set(o),S==null||S.set(r),{...c,lightColorScheme:o,darkColorScheme:r}))},[y,m,S,o,r]),K=Z(s=>{E.mode==="system"&&I(c=>{const i=s!=null&&s.matches?"dark":"light";return c.systemMode===i?c:{...c,systemMode:i}})},[E.mode]),H=we(K);return H.current=K,q(()=>{if(typeof window.matchMedia!="function"||!M)return;const s=(...i)=>H.current(...i),c=window.matchMedia("(prefers-color-scheme: dark)");return c.addListener(s),s(c),()=>{c.removeListener(s)}},[M]),q(()=>{if(M){const s=(f==null?void 0:f.subscribe(u=>{(!u||["light","dark","system"].includes(u))&&V(u||t)}))||W,c=(m==null?void 0:m.subscribe(u=>{(!u||y.match(u))&&A({light:u})}))||W,i=(S==null?void 0:S.subscribe(u=>{(!u||y.match(u))&&A({dark:u})}))||W;return()=>{s(),c(),i()}}},[A,V,y,t,a,M,f,m,S]),{...E,mode:L?E.mode:void 0,systemMode:L?E.systemMode:void 0,colorScheme:L?O:void 0,setMode:V,setColorScheme:A}}const it="*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}";function lt(e){const{themeId:t,theme:o={},modeStorageKey:r=oe,colorSchemeStorageKey:l=re,disableTransitionOnChange:d=!1,defaultColorScheme:n,resolveTheme:a}=e,h={allColorSchemes:[],colorScheme:void 0,darkColorScheme:void 0,lightColorScheme:void 0,mode:void 0,setColorScheme:()=>{},setMode:()=>{},systemMode:void 0},p=$e(void 0),y=()=>ee(p)||h,M={},f={};function m(L){var ye,Ce,ge,be;const{children:F,theme:O,modeStorageKey:V=r,colorSchemeStorageKey:A=l,disableTransitionOnChange:K=d,storageManager:H,storageWindow:s=typeof window>"u"?void 0:window,documentNode:c=typeof document>"u"?void 0:document,colorSchemeNode:i=typeof document>"u"?void 0:document.documentElement,disableNestedContext:u=!1,disableStyleSheetGeneration:j=!1,defaultMode:Pe="system",noSsr:De}=L,Y=we(!1),B=te(),z=ee(p),Q=!!z&&!u,ne=$(()=>O||(typeof o=="function"?o():o),[O]),se=ne[t],T=se||ne,{colorSchemes:v=M,components:ce=f,cssVarPrefix:J}=T,ie=Object.keys(v).filter(C=>!!v[C]).join(","),P=$(()=>ie.split(","),[ie]),le=typeof n=="string"?n:n.light,de=typeof n=="string"?n:n.dark,Oe=v[le]&&v[de]?Pe:((Ce=(ye=v[T.defaultColorScheme])==null?void 0:ye.palette)==null?void 0:Ce.mode)||((ge=T.palette)==null?void 0:ge.mode),{mode:Ve,setMode:me,systemMode:ae,lightColorScheme:ue,darkColorScheme:he,colorScheme:Ke,setColorScheme:fe}=ct({supportedColorSchemes:P,defaultLightColorScheme:le,defaultDarkColorScheme:de,modeStorageKey:V,colorSchemeStorageKey:A,defaultMode:Oe,storageManager:H,storageWindow:s,noSsr:De});let X=Ve,k=Ke;Q&&(X=z.mode,k=z.colorScheme);const N=$(()=>{var G;const C=k||T.defaultColorScheme,b=((G=T.generateThemeVars)==null?void 0:G.call(T))||T.vars,_={...T,components:ce,colorSchemes:v,cssVarPrefix:J,vars:b};if(typeof _.generateSpacing=="function"&&(_.spacing=_.generateSpacing()),C){const x=v[C];x&&typeof x=="object"&&Object.keys(x).forEach(w=>{x[w]&&typeof x[w]=="object"?_[w]={..._[w],...x[w]}:_[w]=x[w]})}return a?a(_):_},[T,k,ce,v,J]),R=T.colorSchemeSelector;Ee(()=>{if(k&&i&&R&&R!=="media"){const C=R;let b=R;if(C==="class"&&(b=".%s"),C==="data"&&(b="[data-%s]"),C!=null&&C.startsWith("data-")&&!C.includes("%s")&&(b=`[${C}="%s"]`),b.startsWith("."))i.classList.remove(...P.map(_=>b.substring(1).replace("%s",_))),i.classList.add(b.substring(1).replace("%s",k));else{const _=b.replace("%s",k).match(/\[([^\]]+)\]/);if(_){const[G,x]=_[1].split("=");x||P.forEach(w=>{i.removeAttribute(G.replace(k,w))}),i.setAttribute(G,x?x.replace(/"|'/g,""):"")}else i.setAttribute(b,k)}}},[k,R,i,P]),q(()=>{let C;if(K&&Y.current&&c){const b=c.createElement("style");b.appendChild(c.createTextNode(it)),c.head.appendChild(b),window.getComputedStyle(c.body),C=setTimeout(()=>{c.head.removeChild(b)},1)}return()=>{clearTimeout(C)}},[k,K,c]),q(()=>(Y.current=!0,()=>{Y.current=!1}),[]);const Ne=$(()=>({allColorSchemes:P,colorScheme:k,darkColorScheme:he,lightColorScheme:ue,mode:X,setColorScheme:fe,setMode:me,systemMode:ae}),[P,k,he,ue,X,fe,me,ae,N.colorSchemeSelector]);let Se=!0;(j||T.cssVariables===!1||Q&&(B==null?void 0:B.cssVarPrefix)===J)&&(Se=!1);const pe=g.jsxs(Re,{children:[g.jsx(je,{themeId:se?t:void 0,theme:N,children:F}),Se&&g.jsx(ze,{styles:((be=N.generateStyleSheets)==null?void 0:be.call(N))||[]})]});return Q?pe:g.jsx(p.Provider,{value:Ne,children:pe})}const S=typeof n=="string"?n:n.light,E=typeof n=="string"?n:n.dark;return{CssVarsProvider:m,useColorScheme:y,getInitColorSchemeScript:L=>ot({colorSchemeStorageKey:l,defaultLightColorScheme:S,defaultDarkColorScheme:E,modeStorageKey:r,...L})}}function dt({theme:e,...t}){const o=D in e?e[D]:void 0;return g.jsx(je,{...t,themeId:o?D:void 0,theme:o||e})}const U={colorSchemeStorageKey:"mui-color-scheme",defaultLightColorScheme:"light",defaultDarkColorScheme:"dark",modeStorageKey:"mui-mode"},{CssVarsProvider:Ae,useColorScheme:Ct,getInitColorSchemeScript:mt}=lt({themeId:D,theme:()=>qe({cssVariables:!0}),colorSchemeStorageKey:U.colorSchemeStorageKey,modeStorageKey:U.modeStorageKey,defaultColorScheme:{light:U.defaultLightColorScheme,dark:U.defaultDarkColorScheme},resolveTheme:e=>{const t={...e,typography:He(e.palette,e.typography)};return t.unstable_sx=function(r){return Ue({sx:r,theme:this})},t}});function gt(e){return g.jsx(Ae,{...e})}let Me=!1;const bt=e=>(Me||(console.warn(["MUI: The getInitColorSchemeScript function has been deprecated.","","You should use `import InitColorSchemeScript from '@mui/material/InitColorSchemeScript'`","and replace the function call with `<InitColorSchemeScript />` instead."].join(` `)),Me=!0),mt(e)),at=Ae;function _t({theme:e,...t}){const o=$(()=>{if(typeof e=="function")return e;const r=D in e?e[D]:e;return"colorSchemes"in r?null:"vars"in r?e:{...e,vars:null}},[e]);return o?g.jsx(dt,{theme:o,...t}):g.jsx(at,{theme:e,...t})}export{at as C,gt as E,_t as T,bt as g,Ct as u};