@maz-ui/nuxt 4.8.0 → 4.9.0

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,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "4.8.0",
7
+ "version": "4.9.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -172,6 +172,7 @@ const module$1 = defineNuxtModule({
172
172
  }
173
173
  addPlugin(resolve(_dirname, "./runtime/plugins/theme"));
174
174
  addPlugin(resolve(_dirname, "./runtime/plugins/translations"));
175
+ addPlugin(resolve(_dirname, "./runtime/plugins/maz-link-component"));
175
176
  if (moduleOptions.components.autoImport) {
176
177
  for (const name of Object.keys(COMPONENT_NAMES)) {
177
178
  addComponent({
@@ -0,0 +1,2 @@
1
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
2
+ export default _default;
@@ -0,0 +1,5 @@
1
+ import { defineNuxtLink, defineNuxtPlugin } from "#imports";
2
+ export default defineNuxtPlugin(({ vueApp }) => {
3
+ const NuxtLink = defineNuxtLink({});
4
+ vueApp.provide("mazLinkComponent", NuxtLink);
5
+ });
@@ -9,6 +9,13 @@ function getSavedColorMode() {
9
9
  }
10
10
  return void 0;
11
11
  }
12
+ function getSavedResolvedColorMode() {
13
+ const resolvedCookie = useCookie("maz-resolved-color-mode");
14
+ if (resolvedCookie.value && ["light", "dark"].includes(resolvedCookie.value)) {
15
+ return resolvedCookie.value;
16
+ }
17
+ return void 0;
18
+ }
12
19
  function getInitialColorMode(colorMode) {
13
20
  if (colorMode && ["light", "dark"].includes(colorMode)) {
14
21
  return colorMode;
@@ -17,6 +24,10 @@ function getInitialColorMode(colorMode) {
17
24
  if (savedColorMode && ["light", "dark"].includes(savedColorMode)) {
18
25
  return savedColorMode;
19
26
  }
27
+ const resolvedColorMode = getSavedResolvedColorMode();
28
+ if (resolvedColorMode) {
29
+ return resolvedColorMode;
30
+ }
20
31
  if (import.meta.server) {
21
32
  const headers = useRequestHeaders();
22
33
  if (headers["sec-ch-prefers-color-scheme"] === "dark") {
@@ -34,6 +45,11 @@ function getInitialColorMode(colorMode) {
34
45
  }
35
46
  return "auto";
36
47
  }
48
+ function getColorModeBlockingScript(config) {
49
+ const darkClass = config.darkClass;
50
+ const cookieMaxAge = 60 * 60 * 24 * 365;
51
+ return `(function(){try{var d=document.documentElement,m='${config.mode}',dc='${darkClass}';if(m==='light')return;var c=(document.cookie.match(/maz-color-mode=([^;]+)/)||[])[1];if(c==='light')return;if(c==='dark'||m==='dark'){d.classList.add(dc);return}var r=(document.cookie.match(/maz-resolved-color-mode=([^;]+)/)||[])[1];if(r==='light')return;if(r==='dark'){d.classList.add(dc);return}if(window.matchMedia&&window.matchMedia('(prefers-color-scheme:dark)').matches){d.classList.add(dc);document.cookie='maz-resolved-color-mode=dark;path=/;max-age=${cookieMaxAge};SameSite=Lax'}else{document.cookie='maz-resolved-color-mode=light;path=/;max-age=${cookieMaxAge};SameSite=Lax'}}catch(e){}})()`;
52
+ }
37
53
  function injectThemeCSS(config) {
38
54
  const cssOptions = {
39
55
  mode: config.mode,
@@ -86,6 +102,12 @@ export default defineNuxtPlugin(async ({ vueApp, $config }) => {
86
102
  }
87
103
  if (import.meta.server) {
88
104
  injectThemeCSS(config);
105
+ if (config.colorMode === "auto" && config.mode === "both" && config.darkModeStrategy === "class") {
106
+ useHead({
107
+ script: [{ innerHTML: getColorModeBlockingScript(config), tagPosition: "head", id: "maz-color-mode-blocking" }],
108
+ meta: [{ "http-equiv": "Accept-CH", "content": "Sec-CH-Prefers-Color-Scheme", "id": "maz-color-http-accept-ch" }]
109
+ });
110
+ }
89
111
  }
90
112
  MazUiTheme.install?.(vueApp, {
91
113
  ...config,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maz-ui/nuxt",
3
3
  "type": "module",
4
- "version": "4.8.0",
4
+ "version": "4.9.0",
5
5
  "description": "Nuxt module for Maz-UI",
6
6
  "author": "Louis Mazel <me@loicmazuel.com>",
7
7
  "license": "MIT",
@@ -50,10 +50,10 @@
50
50
  "@nuxt/devtools-kit": "^3.2.3",
51
51
  "@nuxt/kit": "^4.4.2",
52
52
  "defu": "^6.1.4",
53
- "@maz-ui/themes": "4.8.0",
54
- "@maz-ui/translations": "4.8.0",
53
+ "@maz-ui/themes": "4.9.0",
55
54
  "@maz-ui/utils": "4.7.6",
56
- "maz-ui": "4.8.0"
55
+ "maz-ui": "4.9.0",
56
+ "@maz-ui/translations": "4.8.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@nuxt/devtools": "^3.2.3",