@kakadu/components 6.12.4 → 6.13.0
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,11 +1,14 @@
|
|
|
1
1
|
import React, { type RefObject } from 'react';
|
|
2
|
-
export declare const themePreferences:
|
|
2
|
+
export declare const themePreferences: readonly ["system", "light", "dark"];
|
|
3
3
|
type ThemePreference = (typeof themePreferences)[number];
|
|
4
|
+
type ThemeSetting = Exclude<ThemePreference, 'system'>;
|
|
4
5
|
type ThemeElement = HTMLElement | RefObject<HTMLElement | null>;
|
|
5
6
|
export declare function useTheme(element?: ThemeElement): ThemePreference;
|
|
6
7
|
export declare function useIsLightTheme(element?: ThemeElement): boolean;
|
|
7
8
|
export declare function useIsDarkTheme(element?: ThemeElement): boolean;
|
|
8
|
-
export declare function getThemePreference():
|
|
9
|
+
export declare function getThemePreference(): "system" | "light" | "dark";
|
|
9
10
|
export declare function setThemePreference(preference: ThemePreference): void;
|
|
10
|
-
export default function ThemeSetter(
|
|
11
|
+
export default function ThemeSetter({ override, }: {
|
|
12
|
+
readonly override?: ThemeSetting;
|
|
13
|
+
}): React.JSX.Element;
|
|
11
14
|
export {};
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("../jsx-runtime-CZa898vN.js"),c=require("react"),d=["system","light","dark"];function o(e){return!!e&&d.includes(e)}function u(e){const[t,r]=c.useState("light");return c.useEffect(()=>{const n=e&&"current"in e?e.current:e,s=(n==null?void 0:n.closest("[data-theme]"))??document.documentElement,a=()=>{o(s.dataset.theme)&&r(s.dataset.theme)};if(typeof window<"u"&&"MutationObserver"in window){const m=new window.MutationObserver(h=>{for(const f of h)f.type==="attributes"&&a()});return a(),m.observe(s,{attributes:!0}),m.observe(document.documentElement,{attributes:!0}),()=>{m.disconnect()}}},[e]),t}function g(e){return u(e)==="light"}function w(e){return u(e)==="dark"}const y=e=>`
|
|
2
|
+
try {
|
|
3
|
+
var themePreference = window.localStorage.getItem("theme-preference") || "system";
|
|
4
|
+
|
|
5
|
+
if (themePreference) {
|
|
6
|
+
document.documentElement.setAttribute("data-theme-preference", themePreference);
|
|
7
|
+
}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
var themeOverride = ${JSON.stringify(e)};
|
|
10
|
+
var query = window.matchMedia("(prefers-color-scheme: dark)");
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
`.trim().replaceAll(/\s+/g," ");function
|
|
12
|
+
document.documentElement.setAttribute(
|
|
13
|
+
"data-theme",
|
|
14
|
+
themeOverride ?? ((themePreference === "system")
|
|
15
|
+
? query.matches ? "dark" : "light"
|
|
16
|
+
: themePreference)
|
|
17
|
+
);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error(error);
|
|
20
|
+
}
|
|
21
|
+
`.trim().replaceAll(/\s+/g," ");function i(){const e=window.localStorage.getItem("theme-preference")??"system";return o(e)?e:"system"}function P(e){const t=o(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 E({override:e}){return c.useEffect(()=>{const t=i();if(t&&(document.documentElement.dataset.themePreference=t),e)document.documentElement.dataset.theme=e;else{const r=window.matchMedia("(prefers-color-scheme: dark)");t==="system"?document.documentElement.dataset.theme=r.matches?"dark":"light":document.documentElement.dataset.theme=t;const n=s=>{document.documentElement.dataset.themePreference==="system"&&(document.documentElement.dataset.theme=s.matches?"dark":"light")};return r.addEventListener("change",n),()=>{r.removeEventListener("change",n)}}},[e]),l.jsxRuntimeExports.jsx("script",{dangerouslySetInnerHTML:{__html:y(e)},id:"theme-setter"})}exports.default=E;exports.getThemePreference=i;exports.setThemePreference=P;exports.themePreferences=d;exports.useIsDarkTheme=w;exports.useIsLightTheme=g;exports.useTheme=u;
|
|
@@ -1,82 +1,96 @@
|
|
|
1
1
|
import { j as h } from "../jsx-runtime-z6PQ6F3d.mjs";
|
|
2
|
-
import { useEffect as
|
|
3
|
-
const
|
|
2
|
+
import { useEffect as a, useState as f } from "react";
|
|
3
|
+
const l = ["system", "light", "dark"];
|
|
4
|
+
function c(e) {
|
|
5
|
+
return !!e && l.includes(e);
|
|
6
|
+
}
|
|
4
7
|
function d(e) {
|
|
5
8
|
const [t, r] = f("light");
|
|
6
|
-
return
|
|
7
|
-
const n = e && "current" in e ? e.current : e,
|
|
8
|
-
|
|
9
|
+
return a(() => {
|
|
10
|
+
const n = e && "current" in e ? e.current : e, m = (n == null ? void 0 : n.closest("[data-theme]")) ?? document.documentElement, o = () => {
|
|
11
|
+
c(m.dataset.theme) && r(m.dataset.theme);
|
|
9
12
|
};
|
|
10
13
|
if (typeof window < "u" && "MutationObserver" in window) {
|
|
11
|
-
const
|
|
14
|
+
const s = new window.MutationObserver((u) => {
|
|
12
15
|
for (const i of u)
|
|
13
|
-
i.type === "attributes" &&
|
|
16
|
+
i.type === "attributes" && o();
|
|
14
17
|
});
|
|
15
|
-
return
|
|
16
|
-
|
|
18
|
+
return o(), s.observe(m, { attributes: !0 }), s.observe(document.documentElement, { attributes: !0 }), () => {
|
|
19
|
+
s.disconnect();
|
|
17
20
|
};
|
|
18
21
|
}
|
|
19
22
|
}, [e]), t;
|
|
20
23
|
}
|
|
21
|
-
function
|
|
24
|
+
function E(e) {
|
|
22
25
|
return d(e) === "light";
|
|
23
26
|
}
|
|
24
|
-
function
|
|
27
|
+
function P(e) {
|
|
25
28
|
return d(e) === "dark";
|
|
26
29
|
}
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const g = (e) => `
|
|
31
|
+
try {
|
|
32
|
+
var themePreference = window.localStorage.getItem("theme-preference") || "system";
|
|
33
|
+
|
|
34
|
+
if (themePreference) {
|
|
35
|
+
document.documentElement.setAttribute("data-theme-preference", themePreference);
|
|
36
|
+
}
|
|
34
37
|
|
|
35
|
-
|
|
38
|
+
var themeOverride = ${JSON.stringify(e)};
|
|
39
|
+
var query = window.matchMedia("(prefers-color-scheme: dark)");
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
`.trim().replaceAll(/\s+/g, " ");
|
|
47
|
-
function
|
|
41
|
+
document.documentElement.setAttribute(
|
|
42
|
+
"data-theme",
|
|
43
|
+
themeOverride ?? ((themePreference === "system")
|
|
44
|
+
? query.matches ? "dark" : "light"
|
|
45
|
+
: themePreference)
|
|
46
|
+
);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error(error);
|
|
49
|
+
}
|
|
50
|
+
`.trim().replaceAll(/\s+/g, " ");
|
|
51
|
+
function w() {
|
|
48
52
|
const e = window.localStorage.getItem("theme-preference") ?? "system";
|
|
49
|
-
return
|
|
53
|
+
return c(e) ? e : "system";
|
|
50
54
|
}
|
|
51
|
-
function
|
|
52
|
-
const t =
|
|
55
|
+
function b(e) {
|
|
56
|
+
const t = c(e) ? e : "system";
|
|
53
57
|
if (window.localStorage.setItem("theme-preference", t), document.documentElement.dataset.themePreference = t, t === "system") {
|
|
54
58
|
const r = window.matchMedia("(prefers-color-scheme: dark)");
|
|
55
59
|
document.documentElement.dataset.theme = r.matches ? "dark" : "light";
|
|
56
60
|
} else
|
|
57
61
|
document.documentElement.dataset.theme = t;
|
|
58
62
|
}
|
|
59
|
-
function
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const t =
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
function v({
|
|
64
|
+
override: e
|
|
65
|
+
}) {
|
|
66
|
+
return a(() => {
|
|
67
|
+
const t = w();
|
|
68
|
+
if (t && (document.documentElement.dataset.themePreference = t), e)
|
|
69
|
+
document.documentElement.dataset.theme = e;
|
|
70
|
+
else {
|
|
71
|
+
const r = window.matchMedia("(prefers-color-scheme: dark)");
|
|
72
|
+
t === "system" ? document.documentElement.dataset.theme = r.matches ? "dark" : "light" : document.documentElement.dataset.theme = t;
|
|
73
|
+
const n = (m) => {
|
|
74
|
+
document.documentElement.dataset.themePreference === "system" && (document.documentElement.dataset.theme = m.matches ? "dark" : "light");
|
|
75
|
+
};
|
|
76
|
+
return r.addEventListener("change", n), () => {
|
|
77
|
+
r.removeEventListener("change", n);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}, [e]), /* @__PURE__ */ h.jsx(
|
|
81
|
+
"script",
|
|
82
|
+
{
|
|
83
|
+
dangerouslySetInnerHTML: { __html: g(e) },
|
|
84
|
+
id: "theme-setter"
|
|
85
|
+
}
|
|
86
|
+
);
|
|
73
87
|
}
|
|
74
88
|
export {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
89
|
+
v as default,
|
|
90
|
+
w as getThemePreference,
|
|
91
|
+
b as setThemePreference,
|
|
92
|
+
l as themePreferences,
|
|
93
|
+
P as useIsDarkTheme,
|
|
94
|
+
E as useIsLightTheme,
|
|
81
95
|
d as useTheme
|
|
82
96
|
};
|