@maz-ui/nuxt 4.1.7-beta.4 → 4.1.7-beta.6
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.
- package/dist/module.json +2 -2
- package/dist/runtime/plugins/theme.js +44 -40
- package/package.json +9 -10
package/dist/module.json
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { MazUiTheme } from "@maz-ui/themes/plugin";
|
|
2
|
-
import {
|
|
2
|
+
import { CSS_ID, generateCSS, getPreset, mergePresets } from "@maz-ui/themes/utils";
|
|
3
|
+
import { getSystemColorMode } from "@maz-ui/themes/utils/get-color-mode";
|
|
3
4
|
import { defineNuxtPlugin, useCookie, useHead, useRequestHeaders } from "nuxt/app";
|
|
4
|
-
function
|
|
5
|
-
if (colorMode !== "auto") {
|
|
6
|
-
return colorMode;
|
|
7
|
-
}
|
|
5
|
+
function getSavedColorMode() {
|
|
8
6
|
const colorModeCookie = useCookie("maz-color-mode");
|
|
9
7
|
if (colorModeCookie.value && ["light", "dark", "auto"].includes(colorModeCookie.value)) {
|
|
10
8
|
return colorModeCookie.value;
|
|
11
9
|
}
|
|
10
|
+
return void 0;
|
|
11
|
+
}
|
|
12
|
+
function getInitialColorMode(colorMode) {
|
|
13
|
+
if (colorMode && ["light", "dark"].includes(colorMode)) {
|
|
14
|
+
return colorMode;
|
|
15
|
+
}
|
|
16
|
+
const savedColorMode = getSavedColorMode();
|
|
17
|
+
if (savedColorMode && ["light", "dark"].includes(savedColorMode)) {
|
|
18
|
+
return savedColorMode;
|
|
19
|
+
}
|
|
12
20
|
if (import.meta.server) {
|
|
13
21
|
const headers = useRequestHeaders();
|
|
14
22
|
if (headers["sec-ch-prefers-color-scheme"] === "dark") {
|
|
@@ -18,40 +26,41 @@ function getServerInitialColorMode(colorMode) {
|
|
|
18
26
|
if (userAgent?.includes("dark")) {
|
|
19
27
|
return "dark";
|
|
20
28
|
}
|
|
29
|
+
} else {
|
|
30
|
+
const systemColorMode = getSystemColorMode();
|
|
31
|
+
if (systemColorMode === "dark") {
|
|
32
|
+
return "dark";
|
|
33
|
+
}
|
|
21
34
|
}
|
|
22
35
|
return "auto";
|
|
23
36
|
}
|
|
24
|
-
function injectThemeCSS({
|
|
25
|
-
mode,
|
|
26
|
-
preset,
|
|
27
|
-
config
|
|
28
|
-
}) {
|
|
37
|
+
function injectThemeCSS(config) {
|
|
29
38
|
const cssOptions = {
|
|
30
|
-
mode,
|
|
39
|
+
mode: config.mode,
|
|
31
40
|
darkSelectorStrategy: config.darkModeStrategy ?? "class",
|
|
32
|
-
prefix: "maz"
|
|
41
|
+
prefix: "maz",
|
|
42
|
+
darkClass: config.darkClass ?? "dark"
|
|
33
43
|
};
|
|
34
|
-
if (config.injectCriticalCSS) {
|
|
35
|
-
const criticalCSS =
|
|
44
|
+
if (config.injectCriticalCSS && !config.injectAllCSSOnServer) {
|
|
45
|
+
const criticalCSS = generateCSS(config.preset, {
|
|
46
|
+
...cssOptions,
|
|
47
|
+
onlyCritical: true
|
|
48
|
+
});
|
|
36
49
|
useHead({
|
|
37
|
-
style: [{ innerHTML: criticalCSS, id:
|
|
50
|
+
style: [{ innerHTML: criticalCSS, id: CSS_ID }]
|
|
38
51
|
});
|
|
39
52
|
}
|
|
40
53
|
if (config.injectAllCSSOnServer) {
|
|
41
|
-
const fullCSS =
|
|
54
|
+
const fullCSS = generateCSS(config.preset, cssOptions);
|
|
42
55
|
useHead({
|
|
43
|
-
style: [{ innerHTML: fullCSS, id:
|
|
56
|
+
style: [{ innerHTML: fullCSS, id: CSS_ID }]
|
|
44
57
|
});
|
|
45
58
|
}
|
|
46
59
|
}
|
|
47
60
|
function getInjectCSSStates(config) {
|
|
48
|
-
const
|
|
49
|
-
const shouldInjectCriticalCSSOnClient = !!config.injectCriticalCSS && import.meta.client && !criticalCSSAlreadyInjected;
|
|
50
|
-
const fullCSSAlreadyInjected = import.meta.client && !!document.getElementById(CSS_IDS.FULL);
|
|
51
|
-
const shouldInjectFullCSSOnClient = !!config.injectFullCSS && import.meta.client && !fullCSSAlreadyInjected;
|
|
61
|
+
const isCSSAlreadyInjected = import.meta.client && !!document.getElementById(CSS_ID);
|
|
52
62
|
return {
|
|
53
|
-
|
|
54
|
-
shouldInjectFullCSSOnClient
|
|
63
|
+
shouldInjectCSSOnClient: !!config.injectAllCSSOnServer && import.meta.client && !isCSSAlreadyInjected
|
|
55
64
|
};
|
|
56
65
|
}
|
|
57
66
|
export default defineNuxtPlugin(async ({ vueApp, $config }) => {
|
|
@@ -62,8 +71,9 @@ export default defineNuxtPlugin(async ({ vueApp, $config }) => {
|
|
|
62
71
|
}
|
|
63
72
|
const config = {
|
|
64
73
|
strategy: "hybrid",
|
|
74
|
+
darkClass: "dark",
|
|
65
75
|
darkModeStrategy: "class",
|
|
66
|
-
colorMode:
|
|
76
|
+
colorMode: getSavedColorMode() ?? options.colorMode ?? "auto",
|
|
67
77
|
mode: "both",
|
|
68
78
|
injectAllCSSOnServer: false,
|
|
69
79
|
injectCriticalCSS: true,
|
|
@@ -72,30 +82,24 @@ export default defineNuxtPlugin(async ({ vueApp, $config }) => {
|
|
|
72
82
|
...options,
|
|
73
83
|
preset
|
|
74
84
|
};
|
|
75
|
-
const
|
|
76
|
-
const isDark = colorMode === "auto" && config.mode === "both" ? getServerInitialColorMode(config.colorMode) === "dark" : colorMode === "dark" || config.mode === "dark";
|
|
85
|
+
const isDark = config.colorMode === "auto" && config.mode === "both" ? getInitialColorMode(config.colorMode) === "dark" : config.colorMode === "dark" || config.mode === "dark";
|
|
77
86
|
if (isDark && config.darkModeStrategy === "class") {
|
|
78
87
|
useHead({
|
|
79
88
|
htmlAttrs: {
|
|
80
|
-
class:
|
|
89
|
+
class: config.darkClass
|
|
81
90
|
}
|
|
82
91
|
});
|
|
83
92
|
}
|
|
84
|
-
const { shouldInjectCriticalCSSOnClient, shouldInjectFullCSSOnClient } = getInjectCSSStates(config);
|
|
85
93
|
if (import.meta.server) {
|
|
86
|
-
injectThemeCSS(
|
|
87
|
-
mode: config.mode,
|
|
88
|
-
preset: config.preset,
|
|
89
|
-
config
|
|
90
|
-
});
|
|
94
|
+
injectThemeCSS(config);
|
|
91
95
|
}
|
|
96
|
+
const { shouldInjectCSSOnClient } = getInjectCSSStates(config);
|
|
92
97
|
MazUiTheme.install?.(vueApp, {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
injectCriticalCSS: shouldInjectCriticalCSSOnClient
|
|
98
|
+
...config,
|
|
99
|
+
colorMode: getSavedColorMode() ?? config.colorMode,
|
|
100
|
+
// @ts-expect-error _isDark is a private property
|
|
101
|
+
_isDark: isDark,
|
|
102
|
+
injectFullCSS: !config.injectAllCSSOnServer || shouldInjectCSSOnClient,
|
|
103
|
+
injectCriticalCSS: shouldInjectCSSOnClient
|
|
100
104
|
});
|
|
101
105
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maz-ui/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.1.7-beta.
|
|
4
|
+
"version": "4.1.7-beta.6",
|
|
5
5
|
"description": "Nuxt module for Maz-UI",
|
|
6
6
|
"author": "Louis Mazel <me@loicmazuel.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -55,23 +55,22 @@
|
|
|
55
55
|
"nuxt": ">=3.4.0 <5.0.0"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@maz-ui/themes": "4.1.7-beta.
|
|
59
|
-
"@maz-ui/translations": "4.1.7-beta.
|
|
60
|
-
"@nuxt/kit": "^4.
|
|
58
|
+
"@maz-ui/themes": "4.1.7-beta.6",
|
|
59
|
+
"@maz-ui/translations": "4.1.7-beta.6",
|
|
60
|
+
"@nuxt/kit": "^4.1.2",
|
|
61
61
|
"defu": "^6.1.4",
|
|
62
|
-
"maz-ui": "4.1.7-beta.
|
|
62
|
+
"maz-ui": "4.1.7-beta.6"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@nuxt/devtools": "^2.6.
|
|
65
|
+
"@nuxt/devtools": "^2.6.3",
|
|
66
66
|
"@nuxt/module-builder": "^1.0.2",
|
|
67
|
-
"@nuxt/schema": "^4.
|
|
67
|
+
"@nuxt/schema": "^4.1.2",
|
|
68
68
|
"@nuxt/test-utils": "^3.19.2",
|
|
69
|
-
"nuxt": "^4.
|
|
70
|
-
"typescript": "~5.9.2",
|
|
69
|
+
"nuxt": "^4.1.2",
|
|
71
70
|
"vitest": "^3.2.4"
|
|
72
71
|
},
|
|
73
72
|
"lint-staged": {
|
|
74
73
|
"*.{js,ts,mjs,mts,cjs,md,yml,json}": "cross-env NODE_ENV=production eslint --fix"
|
|
75
74
|
},
|
|
76
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "c7a54d3e824edf3fced1e6c4432c50f248b15a18"
|
|
77
76
|
}
|