@maz-ui/nuxt 4.0.0-beta.20 → 4.0.0-beta.22
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.d.mts +1 -7
- package/dist/module.json +2 -2
- package/dist/module.mjs +1 -2
- package/dist/runtime/plugins/theme.js +50 -45
- package/dist/runtime/plugins/translations.js +1 -1
- package/package.json +10 -10
package/dist/module.d.mts
CHANGED
|
@@ -10,13 +10,7 @@ interface MazUiNuxtThemeOptions extends MazUiThemeOptions {
|
|
|
10
10
|
* @description Inject full CSS on server-side to prevent FOUC on client-side
|
|
11
11
|
* @default true
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Spa mode
|
|
16
|
-
* @description Enable full CSS injection on client-side for app with SSR disabled on some pages
|
|
17
|
-
* @default false
|
|
18
|
-
*/
|
|
19
|
-
spa?: boolean;
|
|
13
|
+
injectAllCSSOnServer?: boolean;
|
|
20
14
|
}
|
|
21
15
|
interface MazUiNuxtOptions {
|
|
22
16
|
/**
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { generateFullCSS, mergePresets } from "@maz-ui/themes";
|
|
2
1
|
import { MazUiTheme } from "@maz-ui/themes/plugin";
|
|
3
|
-
import { getPreset } from "@maz-ui/themes/utils";
|
|
4
|
-
import { generateCriticalCSS } from "@maz-ui/themes/utils/css-generator";
|
|
2
|
+
import { CSS_IDS, generateCriticalCSS, generateFullCSS, getPreset, mergePresets } from "@maz-ui/themes/utils";
|
|
5
3
|
import { defineNuxtPlugin, useCookie, useHead, useRequestHeaders } from "nuxt/app";
|
|
6
4
|
function getServerInitialColorMode(colorMode) {
|
|
7
5
|
if (colorMode !== "auto") {
|
|
@@ -23,6 +21,35 @@ function getServerInitialColorMode(colorMode) {
|
|
|
23
21
|
}
|
|
24
22
|
return "auto";
|
|
25
23
|
}
|
|
24
|
+
function injectThemeCSS({
|
|
25
|
+
mode,
|
|
26
|
+
preset,
|
|
27
|
+
config
|
|
28
|
+
}) {
|
|
29
|
+
const cssOptions = {
|
|
30
|
+
mode,
|
|
31
|
+
darkSelectorStrategy: config.darkModeStrategy ?? "class",
|
|
32
|
+
prefix: "maz"
|
|
33
|
+
};
|
|
34
|
+
const shouldInjectCriticalCSSOnServer = config.injectCriticalCSS && import.meta.server;
|
|
35
|
+
const criticalCSSAlreadyInjected = import.meta.client && document.getElementById(CSS_IDS.CRITICAL);
|
|
36
|
+
const shouldInjectCriticalCSSOnClient = config.injectCriticalCSS && import.meta.client && !criticalCSSAlreadyInjected;
|
|
37
|
+
if (shouldInjectCriticalCSSOnServer || shouldInjectCriticalCSSOnClient) {
|
|
38
|
+
const criticalCSS = generateCriticalCSS(preset, cssOptions);
|
|
39
|
+
useHead({
|
|
40
|
+
style: [{ innerHTML: criticalCSS, id: CSS_IDS.CRITICAL }]
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const shouldInjectFullCSSOnServer = config.injectAllCSSOnServer && import.meta.server;
|
|
44
|
+
const fullCSSAlreadyInjected = import.meta.client && document.getElementById(CSS_IDS.FULL);
|
|
45
|
+
const shouldInjectFullCSSOnClient = config.injectFullCSS && import.meta.client && !fullCSSAlreadyInjected;
|
|
46
|
+
if (shouldInjectFullCSSOnServer || shouldInjectFullCSSOnClient) {
|
|
47
|
+
const fullCSS = generateFullCSS(preset, cssOptions);
|
|
48
|
+
useHead({
|
|
49
|
+
style: [{ innerHTML: fullCSS, id: CSS_IDS.FULL }]
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
26
53
|
export default defineNuxtPlugin(async ({ vueApp, $config }) => {
|
|
27
54
|
const options = $config.public.mazUi.theme;
|
|
28
55
|
let preset = await getPreset(options?.preset);
|
|
@@ -34,56 +61,34 @@ export default defineNuxtPlugin(async ({ vueApp, $config }) => {
|
|
|
34
61
|
darkModeStrategy: "class",
|
|
35
62
|
colorMode: options.mode && options.mode !== "both" ? options.mode : options.colorMode ?? "auto",
|
|
36
63
|
mode: "both",
|
|
37
|
-
|
|
64
|
+
injectAllCSSOnServer: false,
|
|
65
|
+
injectCriticalCSS: true,
|
|
66
|
+
injectFullCSS: true,
|
|
67
|
+
overrides: {},
|
|
38
68
|
...options,
|
|
39
69
|
preset
|
|
40
70
|
};
|
|
41
71
|
const colorMode = config.mode !== "both" ? config.mode : getServerInitialColorMode(config.colorMode);
|
|
42
72
|
const isDark = colorMode === "auto" && config.mode === "both" ? getServerInitialColorMode(config.colorMode) === "dark" : colorMode === "dark" || config.mode === "dark";
|
|
43
|
-
|
|
44
|
-
currentPreset: config.preset,
|
|
45
|
-
colorMode,
|
|
46
|
-
mode: config.mode,
|
|
47
|
-
isDark,
|
|
48
|
-
strategy: config.strategy,
|
|
49
|
-
darkModeStrategy: config.darkModeStrategy
|
|
50
|
-
};
|
|
51
|
-
if (import.meta.server) {
|
|
52
|
-
const cssOptions = {
|
|
53
|
-
mode: themeState.mode,
|
|
54
|
-
darkSelectorStrategy: config.darkModeStrategy ?? "class",
|
|
55
|
-
prefix: "maz"
|
|
56
|
-
};
|
|
57
|
-
const criticalCSS = generateCriticalCSS(themeState.currentPreset, cssOptions);
|
|
73
|
+
if (isDark && config.darkModeStrategy === "class") {
|
|
58
74
|
useHead({
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
id: "maz-theme-critical"
|
|
63
|
-
}
|
|
64
|
-
]
|
|
75
|
+
htmlAttrs: {
|
|
76
|
+
class: "dark"
|
|
77
|
+
}
|
|
65
78
|
});
|
|
66
|
-
if (config.injectFullCSSOnServer) {
|
|
67
|
-
const fullCSS = generateFullCSS(themeState.currentPreset, cssOptions);
|
|
68
|
-
useHead({
|
|
69
|
-
style: [{ innerHTML: fullCSS, id: "maz-theme-full" }]
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
if (isDark && config.darkModeStrategy === "class") {
|
|
73
|
-
useHead({
|
|
74
|
-
htmlAttrs: {
|
|
75
|
-
class: "dark"
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
79
|
}
|
|
80
|
+
injectThemeCSS({
|
|
81
|
+
mode: config.mode,
|
|
82
|
+
preset: config.preset,
|
|
83
|
+
config
|
|
84
|
+
});
|
|
80
85
|
MazUiTheme.install(vueApp, {
|
|
81
|
-
|
|
82
|
-
preset:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
injectFullCSS:
|
|
87
|
-
injectCriticalCSS:
|
|
86
|
+
colorMode,
|
|
87
|
+
preset: config.preset,
|
|
88
|
+
strategy: config.strategy,
|
|
89
|
+
darkModeStrategy: config.darkModeStrategy,
|
|
90
|
+
mode: config.mode,
|
|
91
|
+
injectFullCSS: false,
|
|
92
|
+
injectCriticalCSS: false
|
|
88
93
|
});
|
|
89
94
|
});
|
|
@@ -3,7 +3,7 @@ import { defineNuxtPlugin } from "nuxt/app";
|
|
|
3
3
|
export default defineNuxtPlugin(async ({ vueApp, $config }) => {
|
|
4
4
|
const translationsOptions = $config.public.mazUi.translations || {};
|
|
5
5
|
const i18n = MazTranslations.install(vueApp, translationsOptions);
|
|
6
|
-
if (
|
|
6
|
+
if (import.meta.server) {
|
|
7
7
|
const locale = translationsOptions.locale || "en";
|
|
8
8
|
const fallbackLocale = translationsOptions.fallbackLocale || "en";
|
|
9
9
|
try {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maz-ui/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.22",
|
|
5
5
|
"description": "Nuxt module for Maz-UI",
|
|
6
6
|
"author": "Louis Mazel <me@loicmazuel.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -50,27 +50,27 @@
|
|
|
50
50
|
"dev": "nuxt-module-build build --stub && nuxt-module-build prepare",
|
|
51
51
|
"lint": "cross-env NODE_ENV=production eslint .",
|
|
52
52
|
"lint:fix": "pnpm lint --fix",
|
|
53
|
-
"typecheck": "
|
|
53
|
+
"typecheck": "nuxi typecheck"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@maz-ui/themes": "4.0.0-beta.
|
|
57
|
-
"@maz-ui/translations": "4.0.0-beta.
|
|
58
|
-
"@nuxt/kit": "^4.0.
|
|
56
|
+
"@maz-ui/themes": "4.0.0-beta.22",
|
|
57
|
+
"@maz-ui/translations": "4.0.0-beta.21",
|
|
58
|
+
"@nuxt/kit": "^4.0.2",
|
|
59
59
|
"defu": "^6.1.4",
|
|
60
|
-
"maz-ui": "4.0.0-beta.
|
|
60
|
+
"maz-ui": "4.0.0-beta.22"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@nuxt/devtools": "^2.6.2",
|
|
64
64
|
"@nuxt/eslint-config": "^1.7.1",
|
|
65
|
-
"@nuxt/module-builder": "^1.0.
|
|
66
|
-
"@nuxt/schema": "^4.0.
|
|
65
|
+
"@nuxt/module-builder": "^1.0.2",
|
|
66
|
+
"@nuxt/schema": "^4.0.2",
|
|
67
67
|
"@nuxt/test-utils": "^3.19.2",
|
|
68
|
-
"nuxt": "^4.0.
|
|
68
|
+
"nuxt": "^4.0.2",
|
|
69
69
|
"typescript": "~5.8.3",
|
|
70
70
|
"vitest": "^3.2.4"
|
|
71
71
|
},
|
|
72
72
|
"lint-staged": {
|
|
73
73
|
"*.{js,ts,mjs,mts,cjs,md,yml,json}": "cross-env NODE_ENV=production eslint --fix"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "372f6e17aca4c1391167abe40af57fd2175a82a5"
|
|
76
76
|
}
|