@maz-ui/nuxt 4.1.7-beta.4 → 4.1.7-beta.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.
package/dist/module.json CHANGED
@@ -4,9 +4,9 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "4.1.7-beta.4",
7
+ "version": "4.1.7-beta.5",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
- "unbuild": "3.6.0"
10
+ "unbuild": "3.6.1"
11
11
  }
12
12
  }
@@ -1,14 +1,22 @@
1
1
  import { MazUiTheme } from "@maz-ui/themes/plugin";
2
- import { CSS_IDS, generateCriticalCSS, generateFullCSS, getPreset, mergePresets } from "@maz-ui/themes/utils";
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 getServerInitialColorMode(colorMode) {
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 = generateCriticalCSS(preset, cssOptions);
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: CSS_IDS.CRITICAL }]
50
+ style: [{ innerHTML: criticalCSS, id: CSS_ID }]
38
51
  });
39
52
  }
40
53
  if (config.injectAllCSSOnServer) {
41
- const fullCSS = generateFullCSS(preset, cssOptions);
54
+ const fullCSS = generateCSS(config.preset, cssOptions);
42
55
  useHead({
43
- style: [{ innerHTML: fullCSS, id: CSS_IDS.FULL }]
56
+ style: [{ innerHTML: fullCSS, id: CSS_ID }]
44
57
  });
45
58
  }
46
59
  }
47
60
  function getInjectCSSStates(config) {
48
- const criticalCSSAlreadyInjected = import.meta.client && !!document.getElementById(CSS_IDS.CRITICAL);
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
- shouldInjectCriticalCSSOnClient,
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: options.mode && options.mode !== "both" ? options.mode : options.colorMode ?? "auto",
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 colorMode = config.mode !== "both" ? config.mode : getServerInitialColorMode(config.colorMode);
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: "dark"
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
- colorMode,
94
- preset: config.preset,
95
- strategy: config.strategy,
96
- darkModeStrategy: config.darkModeStrategy,
97
- mode: config.mode,
98
- injectFullCSS: shouldInjectFullCSSOnClient,
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",
4
+ "version": "4.1.7-beta.5",
5
5
  "description": "Nuxt module for Maz-UI",
6
6
  "author": "Louis Mazel <me@loicmazuel.com>",
7
7
  "license": "MIT",
@@ -55,23 +55,23 @@
55
55
  "nuxt": ">=3.4.0 <5.0.0"
56
56
  },
57
57
  "dependencies": {
58
- "@maz-ui/themes": "4.1.7-beta.3",
59
- "@maz-ui/translations": "4.1.7-beta.3",
60
- "@nuxt/kit": "^4.0.3",
58
+ "@maz-ui/themes": "4.1.7-beta.5",
59
+ "@maz-ui/translations": "4.1.7-beta.5",
60
+ "@nuxt/kit": "^4.1.2",
61
61
  "defu": "^6.1.4",
62
- "maz-ui": "4.1.7-beta.4"
62
+ "maz-ui": "4.1.7-beta.5"
63
63
  },
64
64
  "devDependencies": {
65
- "@nuxt/devtools": "^2.6.2",
65
+ "@nuxt/devtools": "^2.6.3",
66
66
  "@nuxt/module-builder": "^1.0.2",
67
- "@nuxt/schema": "^4.0.3",
67
+ "@nuxt/schema": "^4.1.2",
68
68
  "@nuxt/test-utils": "^3.19.2",
69
- "nuxt": "^4.0.3",
69
+ "nuxt": "^4.1.2",
70
70
  "typescript": "~5.9.2",
71
71
  "vitest": "^3.2.4"
72
72
  },
73
73
  "lint-staged": {
74
74
  "*.{js,ts,mjs,mts,cjs,md,yml,json}": "cross-env NODE_ENV=production eslint --fix"
75
75
  },
76
- "gitHead": "5183ff1053430303793c92b606480965b39cfde3"
76
+ "gitHead": "2d4dcc4af1a60bfe158759bd9a94777b1a58861f"
77
77
  }