@scalar/use-hooks 0.1.13 → 0.1.15
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.
|
@@ -3,10 +3,17 @@ import type { ColorMode, DarkLightMode, UseColorModeOptions } from './types';
|
|
|
3
3
|
* A composable hook that provides color mode (dark/light) functionality.
|
|
4
4
|
*/
|
|
5
5
|
export declare function useColorMode(opts?: UseColorModeOptions): {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/** The current color mode (writable). */
|
|
7
|
+
colorMode: import("vue").WritableComputedRef<ColorMode, ColorMode>;
|
|
8
|
+
/** The computed dark/light mode (writable). */
|
|
9
|
+
darkLightMode: import("vue").WritableComputedRef<DarkLightMode, DarkLightMode>;
|
|
10
|
+
/** Whether the current color mode is dark (writable). */
|
|
11
|
+
isDarkMode: import("vue").WritableComputedRef<boolean, boolean>;
|
|
12
|
+
/** Toggles the color mode between light and dark. */
|
|
8
13
|
toggleColorMode: () => void;
|
|
14
|
+
/** Sets the color mode to the specified value. */
|
|
9
15
|
setColorMode: (value: ColorMode) => void;
|
|
16
|
+
/** Gets the system mode preference. */
|
|
10
17
|
getSystemModePreference: () => DarkLightMode;
|
|
11
18
|
};
|
|
12
19
|
//# sourceMappingURL=useColorMode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useColorMode.d.ts","sourceRoot":"","sources":["../../src/useColorMode/useColorMode.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAS5E;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,GAAE,mBAAwB
|
|
1
|
+
{"version":3,"file":"useColorMode.d.ts","sourceRoot":"","sources":["../../src/useColorMode/useColorMode.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAS5E;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,GAAE,mBAAwB;IA4FvD,yCAAyC;;IAKzC,+CAA+C;;IAE/C,yDAAyD;;IAEzD,qDAAqD;;IAErD,kDAAkD;0BAzFvB,SAAS;IA2FpC,uCAAuC;mCApFL,aAAa;EAuFlD"}
|
|
@@ -1,44 +1,60 @@
|
|
|
1
|
-
import { ref as
|
|
1
|
+
import { ref as y, computed as a, watch as M, onMounted as h, onUnmounted as g } from "vue";
|
|
2
2
|
import { z as p } from "zod";
|
|
3
|
-
const o =
|
|
4
|
-
function
|
|
5
|
-
var
|
|
6
|
-
const { initialColorMode:
|
|
7
|
-
function
|
|
3
|
+
const o = y("dark"), v = p.enum(["dark", "light", "system"]).optional().catch(void 0);
|
|
4
|
+
function L(c = {}) {
|
|
5
|
+
var s;
|
|
6
|
+
const { initialColorMode: l = "system", overrideColorMode: u } = c;
|
|
7
|
+
function m() {
|
|
8
8
|
var e;
|
|
9
|
-
o.value =
|
|
9
|
+
o.value = r.value === "dark" ? "light" : "dark", !(typeof window > "u") && ((e = window == null ? void 0 : window.localStorage) == null || e.setItem("colorMode", o.value));
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function d(e) {
|
|
12
12
|
var t;
|
|
13
13
|
o.value = e, !(typeof window > "u") && ((t = window == null ? void 0 : window.localStorage) == null || t.setItem("colorMode", o.value));
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function n() {
|
|
16
16
|
var e;
|
|
17
17
|
return typeof window > "u" ? "light" : typeof (window == null ? void 0 : window.matchMedia) != "function" || (e = window == null ? void 0 : window.matchMedia("(prefers-color-scheme: dark)")) != null && e.matches ? "dark" : "light";
|
|
18
18
|
}
|
|
19
|
-
const
|
|
20
|
-
|
|
19
|
+
const r = a({
|
|
20
|
+
get: () => o.value === "system" ? n() : o.value,
|
|
21
|
+
set: d
|
|
22
|
+
}), f = a({
|
|
23
|
+
get: () => r.value === "dark",
|
|
24
|
+
set: (e) => d(e ? "dark" : "light")
|
|
25
|
+
});
|
|
26
|
+
function i(e) {
|
|
21
27
|
if (typeof document > "u" || typeof window > "u") return;
|
|
22
|
-
(
|
|
28
|
+
(u ?? (e === "system" ? n() : e)) === "dark" ? (document.body.classList.add("dark-mode"), document.body.classList.remove("light-mode")) : (document.body.classList.add("light-mode"), document.body.classList.remove("dark-mode"));
|
|
23
29
|
}
|
|
24
|
-
const
|
|
25
|
-
typeof window < "u" ? (
|
|
30
|
+
const w = v.parse(
|
|
31
|
+
typeof window < "u" ? (s = window == null ? void 0 : window.localStorage) == null ? void 0 : s.getItem("colorMode") : "system"
|
|
26
32
|
);
|
|
27
|
-
return o.value =
|
|
33
|
+
return o.value = w ?? l, M(o, i, { immediate: !0 }), h(() => {
|
|
28
34
|
if (typeof window < "u" && typeof (window == null ? void 0 : window.matchMedia) == "function") {
|
|
29
|
-
const e = window.matchMedia("(prefers-color-scheme: dark)"), t = () => o.value === "system" &&
|
|
30
|
-
e.addEventListener("change", t),
|
|
35
|
+
const e = window.matchMedia("(prefers-color-scheme: dark)"), t = () => o.value === "system" && i("system");
|
|
36
|
+
e.addEventListener("change", t), g(() => {
|
|
31
37
|
e.removeEventListener("change", t);
|
|
32
38
|
});
|
|
33
39
|
}
|
|
34
40
|
}), {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
/** The current color mode (writable). */
|
|
42
|
+
colorMode: a({
|
|
43
|
+
get: () => o.value,
|
|
44
|
+
set: d
|
|
45
|
+
}),
|
|
46
|
+
/** The computed dark/light mode (writable). */
|
|
47
|
+
darkLightMode: r,
|
|
48
|
+
/** Whether the current color mode is dark (writable). */
|
|
49
|
+
isDarkMode: f,
|
|
50
|
+
/** Toggles the color mode between light and dark. */
|
|
51
|
+
toggleColorMode: m,
|
|
52
|
+
/** Sets the color mode to the specified value. */
|
|
53
|
+
setColorMode: d,
|
|
54
|
+
/** Gets the system mode preference. */
|
|
55
|
+
getSystemModePreference: n
|
|
40
56
|
};
|
|
41
57
|
}
|
|
42
58
|
export {
|
|
43
|
-
|
|
59
|
+
L as useColorMode
|
|
44
60
|
};
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"url": "git+https://github.com/scalar/scalar.git",
|
|
11
11
|
"directory": "packages/use-hooks"
|
|
12
12
|
},
|
|
13
|
-
"version": "0.1.
|
|
13
|
+
"version": "0.1.15",
|
|
14
14
|
"engines": {
|
|
15
15
|
"node": ">=18"
|
|
16
16
|
},
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@vueuse/core": "^10.10.0",
|
|
43
43
|
"vue": "^3.5.12",
|
|
44
44
|
"zod": "^3.23.8",
|
|
45
|
-
"@scalar/themes": "0.9.
|
|
45
|
+
"@scalar/themes": "0.9.61",
|
|
46
46
|
"@scalar/use-toasts": "0.7.8"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|