@kakadu/components 4.0.4 → 4.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f=require("../jsx-runtime-BB_1_6y_.js"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f=require("../jsx-runtime-BB_1_6y_.js"),o=require("react"),m=["system","light","dark"];function u(e){const[t,r]=o.useState("light");return o.useEffect(()=>{const n=e&&"current"in e?e.current:e,s=(n==null?void 0:n.closest("[data-theme]"))??document.documentElement,d=()=>{s.dataset.theme&&r(s.dataset.theme)};if(typeof window<"u"&&"MutationObserver"in window){const c=new window.MutationObserver(i=>{for(const h of i)h.type==="attributes"&&d()});return d(),c.observe(s,{attributes:!0}),c.observe(document.documentElement,{attributes:!0}),()=>{c.disconnect()}}},[e]),t}function l(e){return u(e)==="light"}function g(e){return u(e)==="dark"}const w=`
|
|
2
2
|
try {
|
|
3
3
|
var themePreference = window.localStorage.getItem("theme-preference") || "system";
|
|
4
4
|
|
|
@@ -17,4 +17,4 @@
|
|
|
17
17
|
} catch (error) {
|
|
18
18
|
console.error(error);
|
|
19
19
|
}
|
|
20
|
-
`.trim().replaceAll(/\s+/g," ");function a(){const e=window.localStorage.getItem("theme-preference")??"system";return
|
|
20
|
+
`.trim().replaceAll(/\s+/g," ");function a(){const e=window.localStorage.getItem("theme-preference")??"system";return m.includes(e)?e:"system"}function y(e){const t=m.includes(e)?e:"system";if(window.localStorage.setItem("theme-preference",t),document.documentElement.dataset.themePreference=t,t==="system"){const r=window.matchMedia("(prefers-color-scheme: dark)");document.documentElement.dataset.theme=r.matches?"dark":"light"}else document.documentElement.dataset.theme=t}function P(){return o.useEffect(()=>{const e=a();e&&(document.documentElement.dataset.themePreference=e);const t=window.matchMedia("(prefers-color-scheme: dark)");e==="system"?document.documentElement.dataset.theme=t.matches?"dark":"light":document.documentElement.dataset.theme=e;const r=n=>{document.documentElement.dataset.themePreference==="system"&&(document.documentElement.dataset.theme=n.matches?"dark":"light")};return t.addEventListener("change",r),()=>{t.removeEventListener("change",r)}},[]),f.jsxRuntimeExports.jsx("script",{dangerouslySetInnerHTML:{__html:w},id:"theme-setter"})}exports.default=P;exports.getThemePreference=a;exports.setThemePreference=y;exports.themePreferences=m;exports.useIsDarkMode=g;exports.useIsLightMode=l;exports.useTheme=u;
|
|
@@ -8,7 +8,7 @@ function d(e) {
|
|
|
8
8
|
s.dataset.theme && r(s.dataset.theme);
|
|
9
9
|
};
|
|
10
10
|
if (typeof window < "u" && "MutationObserver" in window) {
|
|
11
|
-
const m = new MutationObserver((u) => {
|
|
11
|
+
const m = new window.MutationObserver((u) => {
|
|
12
12
|
for (const i of u)
|
|
13
13
|
i.type === "attributes" && c();
|
|
14
14
|
});
|