vuetify-nuxt-module 0.15.1 → 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.d.mts +2 -0
- package/dist/module.d.ts +2 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +2 -1
- package/dist/runtime/plugins/types.d.ts +2 -0
- package/dist/runtime/plugins/vuetify-client-hints.client.mjs +37 -37
- package/dist/runtime/plugins/vuetify-client-hints.server.mjs +32 -6
- package/package.json +1 -1
package/dist/module.d.mts
CHANGED
|
@@ -241,6 +241,8 @@ interface MOptions {
|
|
|
241
241
|
*
|
|
242
242
|
* @see https://github.com/vuetifyjs/vuetify-loader/tree/master/packages/vite-plugin
|
|
243
243
|
* @see https://github.com/userquin/vuetify-nuxt-module/issues/78 and https://github.com/userquin/vuetify-nuxt-module/issues/74
|
|
244
|
+
*
|
|
245
|
+
* @default true
|
|
244
246
|
*/
|
|
245
247
|
styles?: true | 'none' | 'sass' | {
|
|
246
248
|
configFile: string;
|
package/dist/module.d.ts
CHANGED
|
@@ -241,6 +241,8 @@ interface MOptions {
|
|
|
241
241
|
*
|
|
242
242
|
* @see https://github.com/vuetifyjs/vuetify-loader/tree/master/packages/vite-plugin
|
|
243
243
|
* @see https://github.com/userquin/vuetify-nuxt-module/issues/78 and https://github.com/userquin/vuetify-nuxt-module/issues/74
|
|
244
|
+
*
|
|
245
|
+
* @default true
|
|
244
246
|
*/
|
|
245
247
|
styles?: true | 'none' | 'sass' | {
|
|
246
248
|
configFile: string;
|
package/dist/module.json
CHANGED
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.
|
|
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)}`;
|
|
@@ -1377,6 +1377,7 @@ const module = defineNuxtModule({
|
|
|
1377
1377
|
},
|
|
1378
1378
|
moduleOptions: {
|
|
1379
1379
|
importComposables: true,
|
|
1380
|
+
includeTransformAssetsUrls: true,
|
|
1380
1381
|
styles: true
|
|
1381
1382
|
}
|
|
1382
1383
|
}),
|
|
@@ -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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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:
|
|
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",
|
|
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;
|