vuetify-nuxt-module 0.15.2 → 0.16.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
@@ -5,5 +5,5 @@
5
5
  "nuxt": ">=3.9.0",
6
6
  "bridge": false
7
7
  },
8
- "version": "0.15.2"
8
+ "version": "0.16.0"
9
9
  }
package/dist/module.mjs CHANGED
@@ -14,7 +14,7 @@ import { pathToFileURL } from 'node:url';
14
14
  import { parseQuery, parseURL } from 'ufo';
15
15
  import destr from 'destr';
16
16
 
17
- const version = "0.15.2";
17
+ const version = "0.16.0";
18
18
 
19
19
  const VIRTUAL_VUETIFY_CONFIGURATION = "virtual:vuetify-configuration";
20
20
  const RESOLVED_VIRTUAL_VUETIFY_CONFIGURATION = `/@nuxt-vuetify-configuration/${VIRTUAL_VUETIFY_CONFIGURATION.slice("virtual:".length)}`;
@@ -7,12 +7,14 @@ export interface ClientHintRequestFeatures {
7
7
  prefersReducedMotionAvailable: boolean
8
8
  viewportHeightAvailable: boolean
9
9
  viewportWidthAvailable: boolean
10
+ devicePixelRatioAvailable: boolean
10
11
  }
11
12
  export interface SSRClientHints extends ClientHintRequestFeatures {
12
13
  prefersColorScheme?: 'dark' | 'light' | 'no-preference'
13
14
  prefersReducedMotion?: 'no-preference' | 'reduce'
14
15
  viewportHeight?: number
15
16
  viewportWidth?: number
17
+ devicePixelRatio?: number
16
18
  colorSchemeFromCookie?: string
17
19
  colorSchemeCookie?: string
18
20
  }
@@ -44,46 +44,46 @@ const plugin = defineNuxtPlugin({
44
44
  if (viewportSize && viewportWidthAvailable)
45
45
  window.location.reload();
46
46
  }
47
- if (viewportSize || prefersColorScheme && prefersColorSchemeOptions) {
48
- nuxtApp.hook("vuetify:before-create", ({ vuetifyOptions }) => {
49
- if (viewportSize) {
50
- const clientWidth = state.value.viewportWidth;
51
- const clientHeight = state.value.viewportHeight;
52
- vuetifyOptions.ssr = typeof clientWidth === "number" ? {
53
- clientWidth,
54
- clientHeight
55
- } : true;
56
- }
57
- if (prefersColorScheme && prefersColorSchemeOptions) {
58
- if (vuetifyOptions.theme === false) {
59
- vuetifyOptions.theme = { defaultTheme: state.value.colorSchemeFromCookie ?? prefersColorSchemeOptions.defaultTheme };
60
- } else {
61
- vuetifyOptions.theme = vuetifyOptions.theme ?? {};
62
- vuetifyOptions.theme.defaultTheme = state.value.colorSchemeFromCookie ?? prefersColorSchemeOptions.defaultTheme;
63
- }
64
- }
65
- });
47
+ nuxtApp.hook("vuetify:before-create", ({ vuetifyOptions }) => {
48
+ if (viewportSize) {
49
+ const clientWidth = state.value.viewportWidth;
50
+ const clientHeight = state.value.viewportHeight;
51
+ vuetifyOptions.ssr = typeof clientWidth === "number" ? {
52
+ clientWidth,
53
+ clientHeight
54
+ } : true;
55
+ } else {
56
+ vuetifyOptions.ssr = true;
57
+ }
66
58
  if (prefersColorScheme && prefersColorSchemeOptions) {
67
- const themeCookie = state.value.colorSchemeCookie;
68
- if (themeCookie) {
69
- nuxtApp.hook("app:beforeMount", () => {
70
- const vuetify = useNuxtApp().$vuetify;
71
- const cookieName = prefersColorSchemeOptions.cookieName;
72
- const parseCookieName = `${cookieName}=`;
73
- const cookieEntry = `${parseCookieName}${state.value.colorSchemeFromCookie ?? prefersColorSchemeOptions.defaultTheme};`;
74
- watch(vuetify.theme.global.name, (newThemeName) => {
75
- document.cookie = themeCookie.replace(cookieEntry, `${cookieName}=${newThemeName};`);
76
- });
77
- if (prefersColorSchemeOptions.useBrowserThemeOnly) {
78
- const { darkThemeName, lightThemeName } = prefersColorSchemeOptions;
79
- const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
80
- prefersDark.addEventListener("change", (e) => {
81
- vuetify.theme.global.name.value = e.matches ? darkThemeName : lightThemeName;
82
- });
83
- }
84
- });
59
+ if (vuetifyOptions.theme === false) {
60
+ vuetifyOptions.theme = { defaultTheme: state.value.colorSchemeFromCookie ?? prefersColorSchemeOptions.defaultTheme };
61
+ } else {
62
+ vuetifyOptions.theme = vuetifyOptions.theme ?? {};
63
+ vuetifyOptions.theme.defaultTheme = state.value.colorSchemeFromCookie ?? prefersColorSchemeOptions.defaultTheme;
85
64
  }
86
65
  }
66
+ });
67
+ if (prefersColorScheme && prefersColorSchemeOptions) {
68
+ const themeCookie = state.value.colorSchemeCookie;
69
+ if (themeCookie) {
70
+ nuxtApp.hook("app:beforeMount", () => {
71
+ const vuetify = useNuxtApp().$vuetify;
72
+ const cookieName = prefersColorSchemeOptions.cookieName;
73
+ const parseCookieName = `${cookieName}=`;
74
+ const cookieEntry = `${parseCookieName}${state.value.colorSchemeFromCookie ?? prefersColorSchemeOptions.defaultTheme};`;
75
+ watch(vuetify.theme.global.name, (newThemeName) => {
76
+ document.cookie = themeCookie.replace(cookieEntry, `${cookieName}=${newThemeName};`);
77
+ });
78
+ if (prefersColorSchemeOptions.useBrowserThemeOnly) {
79
+ const { darkThemeName, lightThemeName } = prefersColorSchemeOptions;
80
+ const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
81
+ prefersDark.addEventListener("change", (e) => {
82
+ vuetify.theme.global.name.value = e.matches ? darkThemeName : lightThemeName;
83
+ });
84
+ }
85
+ });
86
+ }
87
87
  }
88
88
  return {
89
89
  provide: reactive({
@@ -17,7 +17,8 @@ const AcceptClientHintsHeaders = {
17
17
  prefersColorScheme: "Sec-CH-Prefers-Color-Scheme",
18
18
  prefersReducedMotion: "Sec-CH-Prefers-Reduced-Motion",
19
19
  viewportHeight: "Sec-CH-Viewport-Height",
20
- viewportWidth: "Sec-CH-Viewport-Width"
20
+ viewportWidth: "Sec-CH-Viewport-Width",
21
+ devicePixelRatio: "Sec-CH-DPR"
21
22
  };
22
23
  const AcceptClientHintsRequestHeaders = Object.entries(AcceptClientHintsHeaders).reduce((acc, [key, value]) => {
23
24
  acc[key] = value.toLowerCase();
@@ -26,7 +27,7 @@ const AcceptClientHintsRequestHeaders = Object.entries(AcceptClientHintsHeaders)
26
27
  const HttpRequestHeaders = Array.from(Object.values(AcceptClientHintsRequestHeaders)).concat("user-agent", "cookie");
27
28
  const plugin = defineNuxtPlugin({
28
29
  name: "vuetify:client-hints:server:plugin",
29
- order: -25,
30
+ order: 24,
30
31
  parallel: true,
31
32
  setup(nuxtApp) {
32
33
  const state = useState(VuetifyHTTPClientHints);
@@ -75,19 +76,24 @@ const chromiumBasedBrowserFeatures = {
75
76
  prefersColorScheme: (_, v) => v[0] >= 93,
76
77
  prefersReducedMotion: (_, v) => v[0] >= 108,
77
78
  viewportHeight: (_, v) => v[0] >= 108,
78
- viewportWidth: (_, v) => v[0] >= 108
79
+ viewportWidth: (_, v) => v[0] >= 108,
80
+ devicePixelRatio: (_, v) => v[0] >= 46
79
81
  };
80
82
  const allowedBrowsers = [
81
83
  // 'edge',
82
84
  // 'edge-ios',
83
85
  ["chrome", chromiumBasedBrowserFeatures],
84
- ["edge-chromium", chromiumBasedBrowserFeatures],
86
+ ["edge-chromium", {
87
+ ...chromiumBasedBrowserFeatures,
88
+ devicePixelRatio: (_, v) => v[0] >= 79
89
+ }],
85
90
  ["chromium-webview", chromiumBasedBrowserFeatures],
86
91
  ["opera", {
87
92
  prefersColorScheme: (android, v) => v[0] >= (android ? 66 : 79),
88
93
  prefersReducedMotion: (android, v) => v[0] >= (android ? 73 : 94),
89
94
  viewportHeight: (android, v) => v[0] >= (android ? 73 : 94),
90
- viewportWidth: (android, v) => v[0] >= (android ? 73 : 94)
95
+ viewportWidth: (android, v) => v[0] >= (android ? 73 : 94),
96
+ devicePixelRatio: (_, v) => v[0] >= 33
91
97
  }]
92
98
  ];
93
99
  const ClientHeaders = ["Accept-CH", "Vary", "Critical-CH"];
@@ -117,7 +123,8 @@ function lookupClientHints(userAgent, ssrClientHintsConfiguration2) {
117
123
  prefersColorSchemeAvailable: false,
118
124
  prefersReducedMotionAvailable: false,
119
125
  viewportHeightAvailable: false,
120
- viewportWidthAvailable: false
126
+ viewportWidthAvailable: false,
127
+ devicePixelRatioAvailable: false
121
128
  };
122
129
  if (userAgent == null || userAgent.type !== "browser")
123
130
  return features;
@@ -128,6 +135,7 @@ function lookupClientHints(userAgent, ssrClientHintsConfiguration2) {
128
135
  if (ssrClientHintsConfiguration2.viewportSize) {
129
136
  features.viewportHeightAvailable = browserFeatureAvailable(userAgent, "viewportHeight");
130
137
  features.viewportWidthAvailable = browserFeatureAvailable(userAgent, "viewportWidth");
138
+ features.devicePixelRatioAvailable = browserFeatureAvailable(userAgent, "devicePixelRatio");
131
139
  }
132
140
  return features;
133
141
  }
@@ -193,6 +201,22 @@ function collectClientHints(userAgent, ssrClientHintsConfiguration2, headers) {
193
201
  } else {
194
202
  hints.viewportWidth = ssrClientHintsConfiguration2.clientWidth;
195
203
  }
204
+ if (hints.devicePixelRatioAvailable && ssrClientHintsConfiguration2.viewportSize) {
205
+ const header = headers[AcceptClientHintsRequestHeaders.devicePixelRatio];
206
+ if (header) {
207
+ hints.firstRequest = false;
208
+ try {
209
+ hints.devicePixelRatio = Number.parseFloat(header);
210
+ if (!Number.isNaN(hints.devicePixelRatio) && hints.devicePixelRatio > 0) {
211
+ if (typeof hints.viewportWidth === "number")
212
+ hints.viewportWidth = Math.round(hints.viewportWidth / hints.devicePixelRatio);
213
+ if (typeof hints.viewportHeight === "number")
214
+ hints.viewportHeight = Math.round(hints.viewportHeight / hints.devicePixelRatio);
215
+ }
216
+ } catch {
217
+ }
218
+ }
219
+ }
196
220
  return hints;
197
221
  }
198
222
  function writeClientHintHeaders(key, headers) {
@@ -209,6 +233,8 @@ function writeClientHintsResponseHeaders(clientHintsRequest, ssrClientHintsConfi
209
233
  if (ssrClientHintsConfiguration2.viewportSize && clientHintsRequest.viewportHeightAvailable && clientHintsRequest.viewportWidthAvailable) {
210
234
  writeClientHintHeaders(AcceptClientHintsHeaders.viewportHeight, headers);
211
235
  writeClientHintHeaders(AcceptClientHintsHeaders.viewportWidth, headers);
236
+ if (clientHintsRequest.devicePixelRatioAvailable)
237
+ writeClientHintHeaders(AcceptClientHintsHeaders.devicePixelRatio, headers);
212
238
  }
213
239
  if (Object.keys(headers).length === 0)
214
240
  return;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vuetify-nuxt-module",
3
3
  "type": "module",
4
- "version": "0.15.2",
4
+ "version": "0.16.0",
5
5
  "packageManager": "pnpm@9.5.0",
6
6
  "description": "Zero-Config Nuxt Module for Vuetify",
7
7
  "author": "userquin <userquin@gmail.com>",
@@ -142,4 +142,4 @@
142
142
  "installDependencies": false,
143
143
  "startCommand": "node .stackblitz.js && pnpm install && nr prepack && nr dev:prepare && nr dev"
144
144
  }
145
- }
145
+ }