@maz-ui/nuxt 4.0.0-beta.20 → 4.0.0-beta.21

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 CHANGED
@@ -11,12 +11,6 @@ interface MazUiNuxtThemeOptions extends MazUiThemeOptions {
11
11
  * @default true
12
12
  */
13
13
  injectFullCSSOnServer?: boolean;
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;
20
14
  }
21
15
  interface MazUiNuxtOptions {
22
16
  /**
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "4.0.0-beta.20",
7
+ "version": "4.0.0-beta.21",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.1",
10
10
  "unbuild": "3.6.0"
package/dist/module.mjs CHANGED
@@ -99,8 +99,7 @@ const defaults = {
99
99
  strategy: "hybrid",
100
100
  darkModeStrategy: "class",
101
101
  colorMode: "auto",
102
- mode: "both",
103
- spa: false
102
+ mode: "both"
104
103
  },
105
104
  translations: {
106
105
  locale: "en",
@@ -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,67 +21,72 @@ function getServerInitialColorMode(colorMode) {
23
21
  }
24
22
  return "auto";
25
23
  }
24
+ function injectThemeCSSOnServer({
25
+ mode,
26
+ preset,
27
+ config
28
+ }) {
29
+ const cssOptions = {
30
+ mode,
31
+ darkSelectorStrategy: config.darkModeStrategy ?? "class",
32
+ prefix: "maz"
33
+ };
34
+ const criticalCSS = generateCriticalCSS(preset, cssOptions);
35
+ useHead({
36
+ style: [
37
+ {
38
+ innerHTML: criticalCSS,
39
+ id: CSS_IDS.CRITICAL
40
+ }
41
+ ]
42
+ });
43
+ if (config.injectFullCSSOnServer) {
44
+ const fullCSS = generateFullCSS(preset, cssOptions);
45
+ useHead({
46
+ style: [{ innerHTML: fullCSS, id: CSS_IDS.FULL }]
47
+ });
48
+ }
49
+ }
26
50
  export default defineNuxtPlugin(async ({ vueApp, $config }) => {
27
51
  const options = $config.public.mazUi.theme;
28
52
  let preset = await getPreset(options?.preset);
29
53
  if (options?.overrides) {
30
54
  preset = mergePresets(preset, options.overrides);
31
55
  }
56
+ const isClientSideRendering = import.meta.client && !document.getElementById(CSS_IDS.CRITICAL);
32
57
  const config = {
33
58
  strategy: "hybrid",
34
59
  darkModeStrategy: "class",
35
60
  colorMode: options.mode && options.mode !== "both" ? options.mode : options.colorMode ?? "auto",
36
61
  mode: "both",
37
- injectFullCSSOnServer: true,
62
+ injectFullCSSOnServer: false,
63
+ injectCriticalCSS: true,
64
+ injectFullCSS: true,
38
65
  ...options,
39
66
  preset
40
67
  };
41
68
  const colorMode = config.mode !== "both" ? config.mode : getServerInitialColorMode(config.colorMode);
42
69
  const isDark = colorMode === "auto" && config.mode === "both" ? getServerInitialColorMode(config.colorMode) === "dark" : colorMode === "dark" || config.mode === "dark";
43
- const themeState = {
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);
70
+ if (isDark && config.darkModeStrategy === "class") {
58
71
  useHead({
59
- style: [
60
- {
61
- innerHTML: criticalCSS,
62
- id: "maz-theme-critical"
63
- }
64
- ]
72
+ htmlAttrs: {
73
+ class: "dark"
74
+ }
75
+ });
76
+ }
77
+ if (import.meta.server) {
78
+ injectThemeCSSOnServer({
79
+ mode: config.mode,
80
+ preset: config.preset,
81
+ config
65
82
  });
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
83
  }
80
84
  MazUiTheme.install(vueApp, {
81
85
  ...config,
82
- preset: themeState.currentPreset,
83
- colorMode: themeState.colorMode,
84
- strategy: themeState.strategy,
85
- darkModeStrategy: themeState.darkModeStrategy,
86
- injectFullCSS: config.spa ? true : !config.injectFullCSSOnServer,
87
- injectCriticalCSS: !!config.spa
86
+ colorMode,
87
+ strategy: config.strategy,
88
+ darkModeStrategy: config.darkModeStrategy,
89
+ injectFullCSS: isClientSideRendering,
90
+ injectCriticalCSS: isClientSideRendering
88
91
  });
89
92
  });
@@ -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 (process.server) {
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.20",
4
+ "version": "4.0.0-beta.21",
5
5
  "description": "Nuxt module for Maz-UI",
6
6
  "author": "Louis Mazel <me@loicmazuel.com>",
7
7
  "license": "MIT",
@@ -50,14 +50,14 @@
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": "vue-tsc --noEmit --skipLibCheck"
53
+ "typecheck": "nuxi typecheck"
54
54
  },
55
55
  "dependencies": {
56
56
  "@maz-ui/themes": "4.0.0-beta.19",
57
- "@maz-ui/translations": "4.0.0-beta.19",
57
+ "@maz-ui/translations": "4.0.0-beta.21",
58
58
  "@nuxt/kit": "^4.0.1",
59
59
  "defu": "^6.1.4",
60
- "maz-ui": "4.0.0-beta.20"
60
+ "maz-ui": "4.0.0-beta.21"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@nuxt/devtools": "^2.6.2",
@@ -72,5 +72,5 @@
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": "f0744074a7967b3eba10a5f861c6ddea995a90c1"
75
+ "gitHead": "b1960589b8f969f4675251dd5e39eecaf98388b1"
76
76
  }