@maz-ui/themes 4.1.3 → 4.1.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,58 +1,58 @@
|
|
|
1
|
-
import { ref as
|
|
2
|
-
import { setCookie as
|
|
3
|
-
import { generateCriticalCSS as
|
|
4
|
-
import { getColorMode as
|
|
5
|
-
import { getPreset as
|
|
6
|
-
import { mergePresets as
|
|
7
|
-
function
|
|
1
|
+
import { ref as f, onMounted as k, computed as s, toValue as w, watch as y, watchEffect as T, inject as C, getCurrentInstance as M } from "vue";
|
|
2
|
+
import { setCookie as z } from "../utils/cookie-storage.js";
|
|
3
|
+
import { generateCriticalCSS as E, generateFullCSS as L, injectCSS as p, CSS_IDS as v } from "../utils/css-generator.js";
|
|
4
|
+
import { getColorMode as x, isSystemPrefersDark as I } from "../utils/get-color-mode.js";
|
|
5
|
+
import { getPreset as O } from "../utils/get-preset.js";
|
|
6
|
+
import { mergePresets as $ } from "../utils/preset-merger.js";
|
|
7
|
+
function D() {
|
|
8
8
|
return typeof document > "u" || typeof globalThis.window > "u";
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function F() {
|
|
11
11
|
return typeof document < "u";
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function R(e) {
|
|
14
14
|
return !!e;
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function U(e, o, r = {}) {
|
|
17
17
|
const {
|
|
18
|
-
internalWindow: u =
|
|
19
|
-
...
|
|
18
|
+
internalWindow: u = F() ? globalThis : void 0,
|
|
19
|
+
...c
|
|
20
20
|
} = r;
|
|
21
21
|
let n;
|
|
22
|
-
const
|
|
22
|
+
const d = f(!1);
|
|
23
23
|
k(() => {
|
|
24
|
-
|
|
24
|
+
d.value = (u && "MutationObserver" in u) ?? !1;
|
|
25
25
|
});
|
|
26
26
|
const m = () => {
|
|
27
27
|
n && (n.disconnect(), n = void 0);
|
|
28
|
-
},
|
|
29
|
-
const a =
|
|
28
|
+
}, b = s(() => {
|
|
29
|
+
const a = w(e);
|
|
30
30
|
let i;
|
|
31
|
-
return a && "$el" in a ? i = a.$el : a && (i = a), new Set([i].filter(
|
|
32
|
-
}),
|
|
33
|
-
|
|
31
|
+
return a && "$el" in a ? i = a.$el : a && (i = a), new Set([i].filter(R));
|
|
32
|
+
}), P = y(
|
|
33
|
+
b,
|
|
34
34
|
(a) => {
|
|
35
|
-
m(),
|
|
35
|
+
m(), d.value && a.size && (n = new MutationObserver(o), a.forEach((i) => n.observe(i, c)));
|
|
36
36
|
},
|
|
37
37
|
{ immediate: !0, flush: "post" }
|
|
38
38
|
);
|
|
39
39
|
return {
|
|
40
|
-
isSupported:
|
|
40
|
+
isSupported: d,
|
|
41
41
|
stop: () => {
|
|
42
|
-
|
|
42
|
+
P(), m();
|
|
43
43
|
},
|
|
44
44
|
takeRecords: () => n?.takeRecords()
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
-
const t =
|
|
48
|
-
function
|
|
47
|
+
const t = f();
|
|
48
|
+
function S(e) {
|
|
49
49
|
typeof document > "u" || !e || e.darkModeStrategy === "media" || e.mode === "light" || (e.isDark ? document.documentElement.classList.add("dark") : document.documentElement.classList.remove("dark"));
|
|
50
50
|
}
|
|
51
|
-
function
|
|
52
|
-
const e =
|
|
51
|
+
function j() {
|
|
52
|
+
const e = M()?.appContext.app;
|
|
53
53
|
e && t.value && (e.config.globalProperties.$mazThemeState = t.value);
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function N(e) {
|
|
56
56
|
if (e.currentPreset && e.colorMode !== void 0) {
|
|
57
57
|
g({
|
|
58
58
|
currentPreset: e.currentPreset,
|
|
@@ -64,7 +64,7 @@ function j(e) {
|
|
|
64
64
|
});
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
|
-
const o =
|
|
67
|
+
const o = x(e.colorMode), r = o === "auto" ? I() : o === "dark";
|
|
68
68
|
g({
|
|
69
69
|
currentPreset: e.currentPreset,
|
|
70
70
|
colorMode: o,
|
|
@@ -81,46 +81,49 @@ function g(e) {
|
|
|
81
81
|
};
|
|
82
82
|
o.addEventListener("change", r), r();
|
|
83
83
|
}
|
|
84
|
-
|
|
85
|
-
t.value && (
|
|
84
|
+
T(() => {
|
|
85
|
+
t.value && (S(t.value), j());
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
const
|
|
88
|
+
const W = s({
|
|
89
89
|
get: () => t.value?.colorMode,
|
|
90
|
-
set: (e) =>
|
|
91
|
-
}),
|
|
92
|
-
async function
|
|
90
|
+
set: (e) => l(e)
|
|
91
|
+
}), _ = s(() => t.value?.isDark ?? !1), A = s(() => t.value?.strategy), G = s(() => t.value?.mode), Q = s(() => t.value?.darkModeStrategy), h = s(() => t.value?.currentPreset), V = s(() => h.value?.name);
|
|
92
|
+
async function Y(e) {
|
|
93
93
|
if (!t.value)
|
|
94
94
|
return;
|
|
95
|
-
const o = typeof e == "string" ? await
|
|
95
|
+
const o = typeof e == "string" ? await O(e) : e;
|
|
96
96
|
if (!o || !t.value.currentPreset) {
|
|
97
97
|
console.error("[@maz-ui/themes] No preset found - If you are using the buildtime strategy, you must provide a complete preset");
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
|
-
const r = "name" in o && o.name !== t.value.currentPreset.name ? o :
|
|
100
|
+
const r = "name" in o && o.name !== t.value.currentPreset.name ? o : $(t.value.currentPreset, o);
|
|
101
101
|
if (t.value.currentPreset = r, t.value.strategy === "runtime" || t.value.strategy === "hybrid") {
|
|
102
102
|
const u = {
|
|
103
103
|
mode: t.value.mode,
|
|
104
104
|
darkSelectorStrategy: t.value.darkModeStrategy,
|
|
105
105
|
prefix: "maz"
|
|
106
|
-
},
|
|
107
|
-
p(v.CRITICAL,
|
|
106
|
+
}, c = E(r, u), n = L(r, u);
|
|
107
|
+
p(v.CRITICAL, c), p(v.FULL, n);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
function
|
|
111
|
-
t.value && (t.value.colorMode = e, e === "auto" ? t.value.isDark = typeof globalThis.window < "u" && globalThis.matchMedia("(prefers-color-scheme: dark)").matches : t.value.isDark = e === "dark",
|
|
110
|
+
function l(e, o = !0) {
|
|
111
|
+
t.value && (t.value.colorMode = e, e === "auto" ? t.value.isDark = typeof globalThis.window < "u" && globalThis.matchMedia("(prefers-color-scheme: dark)").matches : t.value.isDark = e === "dark", o && S(t.value), z("maz-color-mode", e));
|
|
112
112
|
}
|
|
113
|
-
function
|
|
114
|
-
t.value &&
|
|
113
|
+
function q() {
|
|
114
|
+
t.value && l(t.value.isDark ? "light" : "dark");
|
|
115
115
|
}
|
|
116
|
-
function
|
|
117
|
-
const e =
|
|
116
|
+
function oe() {
|
|
117
|
+
const e = f();
|
|
118
118
|
k(() => {
|
|
119
119
|
e.value = document.documentElement;
|
|
120
|
-
}),
|
|
120
|
+
}), U(
|
|
121
121
|
e,
|
|
122
122
|
() => {
|
|
123
|
-
|
|
123
|
+
if (D() || !t.value)
|
|
124
|
+
return;
|
|
125
|
+
const r = document.documentElement.classList.contains("dark") ? "dark" : "light";
|
|
126
|
+
t.value.colorMode !== r && l(r, !1);
|
|
124
127
|
},
|
|
125
128
|
{
|
|
126
129
|
attributes: !0
|
|
@@ -128,34 +131,35 @@ function te() {
|
|
|
128
131
|
);
|
|
129
132
|
let o;
|
|
130
133
|
try {
|
|
131
|
-
if (o =
|
|
134
|
+
if (o = C("mazThemeState", void 0), !o)
|
|
132
135
|
throw new Error("mazThemeState not found");
|
|
133
136
|
} catch {
|
|
134
|
-
const r =
|
|
137
|
+
const r = M();
|
|
135
138
|
r?.appContext?.app?.config?.globalProperties && (o = r.appContext.app.config.globalProperties.$mazThemeState);
|
|
136
139
|
}
|
|
137
140
|
if (o && (t.value ? (typeof document > "u" || typeof globalThis.window > "u") && (t.value = {
|
|
138
141
|
...t.value,
|
|
139
142
|
...o
|
|
140
|
-
}) :
|
|
143
|
+
}) : N(o)), y(() => o?.currentPreset, (r) => {
|
|
141
144
|
t.value && r && (t.value.currentPreset = r);
|
|
142
145
|
}, {
|
|
143
146
|
once: !0
|
|
144
147
|
}), !t.value)
|
|
145
148
|
throw new Error("[@maz-ui/themes] You must install the MazUi or MazUiTheme plugin before using useTheme composable");
|
|
146
149
|
return {
|
|
147
|
-
presetName:
|
|
148
|
-
colorMode:
|
|
149
|
-
isDark:
|
|
150
|
-
strategy:
|
|
151
|
-
updateTheme:
|
|
152
|
-
setColorMode:
|
|
153
|
-
toggleDarkMode:
|
|
154
|
-
mode:
|
|
155
|
-
darkModeStrategy:
|
|
150
|
+
presetName: V,
|
|
151
|
+
colorMode: W,
|
|
152
|
+
isDark: _,
|
|
153
|
+
strategy: A,
|
|
154
|
+
updateTheme: Y,
|
|
155
|
+
setColorMode: l,
|
|
156
|
+
toggleDarkMode: q,
|
|
157
|
+
mode: G,
|
|
158
|
+
darkModeStrategy: Q,
|
|
159
|
+
currentPreset: h
|
|
156
160
|
};
|
|
157
161
|
}
|
|
158
162
|
export {
|
|
159
163
|
g as initThemeState,
|
|
160
|
-
|
|
164
|
+
oe as useTheme
|
|
161
165
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ColorMode, DarkModeStrategy, Strategy, ThemeMode, ThemePreset, ThemePresetName, ThemePresetOverrides, ThemeState } from '../types';
|
|
2
2
|
export declare function initThemeState(initialState: ThemeState): void;
|
|
3
3
|
declare function updateTheme(preset: ThemePreset | ThemePresetOverrides | ThemePresetName): Promise<void>;
|
|
4
|
-
declare function setColorMode(colorMode: ColorMode): void;
|
|
4
|
+
declare function setColorMode(colorMode: ColorMode, updateClass?: boolean): void;
|
|
5
5
|
declare function toggleDarkMode(): void;
|
|
6
6
|
export declare function useTheme(): {
|
|
7
7
|
presetName: import('vue').ComputedRef<string | undefined>;
|
|
@@ -13,6 +13,7 @@ export declare function useTheme(): {
|
|
|
13
13
|
toggleDarkMode: typeof toggleDarkMode;
|
|
14
14
|
mode: import('vue').ComputedRef<ThemeMode>;
|
|
15
15
|
darkModeStrategy: import('vue').ComputedRef<DarkModeStrategy>;
|
|
16
|
+
currentPreset: import('vue').ComputedRef<ThemePreset | undefined>;
|
|
16
17
|
};
|
|
17
18
|
export {};
|
|
18
19
|
//# sourceMappingURL=useTheme.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../../src/composables/useTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,eAAe,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AA8DhJ,wBAAgB,cAAc,CAAC,YAAY,EAAE,UAAU,QAsBtD;
|
|
1
|
+
{"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../../src/composables/useTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,eAAe,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AA8DhJ,wBAAgB,cAAc,CAAC,YAAY,EAAE,UAAU,QAsBtD;AAcD,iBAAe,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,oBAAoB,GAAG,eAAe,iBA8BtF;AAED,iBAAS,YAAY,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,UAAO,QAkB7D;AAED,iBAAS,cAAc,SAKtB;AAED,wBAAgB,QAAQ;;;;;;;;;;;EA4EvB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maz-ui/themes",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.1.
|
|
4
|
+
"version": "4.1.5",
|
|
5
5
|
"description": "Theme system for Maz-UI with TypeScript support and CSS variables",
|
|
6
6
|
"author": "Louis Mazel <me@loicmazuel.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"lint-staged": {
|
|
103
103
|
"*.{js,ts,vue,mjs,mts,cjs,md,yml,json}": "cross-env NODE_ENV=production eslint --fix"
|
|
104
104
|
},
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "37294d421e5683b80ddc8f8fd062ecafe240d9ed"
|
|
106
106
|
}
|