vuetify-nuxt-module 0.6.1 → 0.6.4
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
package/dist/module.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import { parseQuery, parseURL } from 'ufo';
|
|
|
15
15
|
import destr from 'destr';
|
|
16
16
|
import { transformAssetUrls } from 'vite-plugin-vuetify';
|
|
17
17
|
|
|
18
|
-
const version = "0.6.
|
|
18
|
+
const version = "0.6.4";
|
|
19
19
|
|
|
20
20
|
const VIRTUAL_VUETIFY_CONFIGURATION = "virtual:vuetify-configuration";
|
|
21
21
|
const RESOLVED_VIRTUAL_VUETIFY_CONFIGURATION = `/@nuxt-vuetify-configuration/${VIRTUAL_VUETIFY_CONFIGURATION.slice("virtual:".length)}`;
|
|
@@ -50,8 +50,14 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
50
50
|
clientHeight
|
|
51
51
|
} : true;
|
|
52
52
|
}
|
|
53
|
-
if (prefersColorScheme && prefersColorSchemeOptions)
|
|
54
|
-
vuetifyOptions.theme
|
|
53
|
+
if (prefersColorScheme && prefersColorSchemeOptions) {
|
|
54
|
+
if (vuetifyOptions.theme === false) {
|
|
55
|
+
vuetifyOptions.theme = { defaultTheme: state.value.colorSchemeFromCookie ?? prefersColorSchemeOptions.defaultTheme };
|
|
56
|
+
} else {
|
|
57
|
+
vuetifyOptions.theme = vuetifyOptions.theme ?? {};
|
|
58
|
+
vuetifyOptions.theme.defaultTheme = state.value.colorSchemeFromCookie ?? prefersColorSchemeOptions.defaultTheme;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
55
61
|
});
|
|
56
62
|
if (prefersColorScheme && prefersColorSchemeOptions) {
|
|
57
63
|
const themeCookie = state.value.colorSchemeCookie;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { setResponseHeader } from "h3";
|
|
1
2
|
import {
|
|
2
3
|
ssrClientHintsConfiguration
|
|
3
4
|
} from "virtual:vuetify-ssr-client-hints-configuration";
|
|
@@ -9,18 +10,27 @@ import {
|
|
|
9
10
|
useCookie,
|
|
10
11
|
useNuxtApp,
|
|
11
12
|
useRequestEvent,
|
|
13
|
+
useRequestHeaders,
|
|
12
14
|
useState
|
|
13
15
|
} from "#imports";
|
|
16
|
+
const AcceptClientHintsHeaders = {
|
|
17
|
+
prefersColorScheme: "Sec-CH-Prefers-Color-Scheme",
|
|
18
|
+
prefersReducedMotion: "Sec-CH-Prefers-Reduced-Motion",
|
|
19
|
+
viewportHeight: "Sec-CH-Viewport-Height",
|
|
20
|
+
viewportWidth: "Sec-CH-Viewport-Width"
|
|
21
|
+
};
|
|
22
|
+
const AcceptClientHintsRequestHeaders = Object.entries(AcceptClientHintsHeaders).reduce((acc, [key, value]) => {
|
|
23
|
+
acc[key] = value.toLowerCase();
|
|
24
|
+
return acc;
|
|
25
|
+
}, {});
|
|
26
|
+
const HttpRequestHeaders = Array.from(Object.values(AcceptClientHintsRequestHeaders)).concat("user-agent", "cookie");
|
|
14
27
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
15
|
-
const event = useRequestEvent();
|
|
16
28
|
const state = useState(VuetifyHTTPClientHints);
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const requestHeaders = request.headers ?? {};
|
|
20
|
-
const userAgentHeader = readClientHeader("user-agent", requestHeaders);
|
|
29
|
+
const requestHeaders = useRequestHeaders(HttpRequestHeaders);
|
|
30
|
+
const userAgentHeader = requestHeaders["user-agent"];
|
|
21
31
|
const userAgent = userAgentHeader ? parseUserAgent(userAgentHeader) : null;
|
|
22
32
|
const clientHintsRequest = collectClientHints(userAgent, ssrClientHintsConfiguration, requestHeaders);
|
|
23
|
-
writeClientHintsResponseHeaders(clientHintsRequest, ssrClientHintsConfiguration
|
|
33
|
+
writeClientHintsResponseHeaders(clientHintsRequest, ssrClientHintsConfiguration);
|
|
24
34
|
state.value = clientHintsRequest;
|
|
25
35
|
state.value.colorSchemeCookie = writeThemeCookie(
|
|
26
36
|
clientHintsRequest,
|
|
@@ -33,11 +43,20 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
33
43
|
clientWidth,
|
|
34
44
|
clientHeight
|
|
35
45
|
} : true;
|
|
36
|
-
if (clientHintsRequest.colorSchemeFromCookie)
|
|
37
|
-
vuetifyOptions.theme
|
|
46
|
+
if (clientHintsRequest.colorSchemeFromCookie) {
|
|
47
|
+
if (vuetifyOptions.theme === false) {
|
|
48
|
+
vuetifyOptions.theme = { defaultTheme: clientHintsRequest.colorSchemeFromCookie };
|
|
49
|
+
} else {
|
|
50
|
+
vuetifyOptions.theme ??= {};
|
|
51
|
+
vuetifyOptions.theme.defaultTheme = clientHintsRequest.colorSchemeFromCookie;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
38
54
|
await nuxtApp.hooks.callHook("vuetify:ssr-client-hints", {
|
|
39
55
|
vuetifyOptions,
|
|
40
|
-
ssrClientHintsConfiguration
|
|
56
|
+
ssrClientHintsConfiguration: {
|
|
57
|
+
...ssrClientHintsConfiguration,
|
|
58
|
+
enabled: true
|
|
59
|
+
},
|
|
41
60
|
ssrClientHints: state.value
|
|
42
61
|
});
|
|
43
62
|
});
|
|
@@ -47,12 +66,6 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
47
66
|
})
|
|
48
67
|
};
|
|
49
68
|
});
|
|
50
|
-
const AcceptClientHintsHeaders = {
|
|
51
|
-
prefersColorScheme: "Sec-CH-Prefers-Color-Scheme",
|
|
52
|
-
prefersReducedMotion: "Sec-CH-Prefers-Reduced-Motion",
|
|
53
|
-
viewportHeight: "Sec-CH-Viewport-Height",
|
|
54
|
-
viewportWidth: "Sec-CH-Viewport-Width"
|
|
55
|
-
};
|
|
56
69
|
const chromiumBasedBrowserFeatures = {
|
|
57
70
|
prefersColorScheme: (_, v) => v[0] >= 93,
|
|
58
71
|
prefersReducedMotion: (_, v) => v[0] >= 108,
|
|
@@ -72,17 +85,7 @@ const allowedBrowsers = [
|
|
|
72
85
|
viewportWidth: (android, v) => v[0] >= (android ? 73 : 94)
|
|
73
86
|
}]
|
|
74
87
|
];
|
|
75
|
-
const AcceptClientHintsRequestHeaders = Object.entries(AcceptClientHintsHeaders).reduce((acc, [key, value]) => {
|
|
76
|
-
acc[key] = value.toLowerCase();
|
|
77
|
-
return acc;
|
|
78
|
-
}, {});
|
|
79
88
|
const ClientHeaders = ["Accept-CH", "Vary", "Critical-CH"];
|
|
80
|
-
function readClientHeader(name, headers) {
|
|
81
|
-
const value = headers[name];
|
|
82
|
-
if (Array.isArray(value))
|
|
83
|
-
return value[0];
|
|
84
|
-
return value;
|
|
85
|
-
}
|
|
86
89
|
function browserFeatureAvailable(userAgent, feature) {
|
|
87
90
|
if (userAgent == null || userAgent.type !== "browser")
|
|
88
91
|
return false;
|
|
@@ -128,7 +131,7 @@ function collectClientHints(userAgent, ssrClientHintsConfiguration2, headers) {
|
|
|
128
131
|
if (ssrClientHintsConfiguration2.prefersColorScheme) {
|
|
129
132
|
if (ssrClientHintsConfiguration2.prefersColorSchemeOptions) {
|
|
130
133
|
const cookieName = ssrClientHintsConfiguration2.prefersColorSchemeOptions.cookieName;
|
|
131
|
-
const cookieValue =
|
|
134
|
+
const cookieValue = headers.cookie?.split(";").find((c) => c.trim().startsWith(`${cookieName}=`));
|
|
132
135
|
if (cookieValue) {
|
|
133
136
|
const value = cookieValue.split("=")?.[1].trim();
|
|
134
137
|
if (ssrClientHintsConfiguration2.prefersColorSchemeOptions.themeNames.includes(value)) {
|
|
@@ -138,7 +141,7 @@ function collectClientHints(userAgent, ssrClientHintsConfiguration2, headers) {
|
|
|
138
141
|
}
|
|
139
142
|
}
|
|
140
143
|
if (!hints.colorSchemeFromCookie) {
|
|
141
|
-
const value = hints.prefersColorSchemeAvailable ?
|
|
144
|
+
const value = hints.prefersColorSchemeAvailable ? headers[AcceptClientHintsRequestHeaders.prefersColorScheme]?.toLowerCase() : void 0;
|
|
142
145
|
if (value === "dark" || value === "light" || value === "no-preference") {
|
|
143
146
|
hints.prefersColorScheme = value;
|
|
144
147
|
hints.firstRequest = false;
|
|
@@ -153,14 +156,14 @@ function collectClientHints(userAgent, ssrClientHintsConfiguration2, headers) {
|
|
|
153
156
|
}
|
|
154
157
|
}
|
|
155
158
|
if (hints.prefersReducedMotionAvailable && ssrClientHintsConfiguration2.prefersReducedMotion) {
|
|
156
|
-
const value =
|
|
159
|
+
const value = headers[AcceptClientHintsRequestHeaders.prefersReducedMotion]?.toLowerCase();
|
|
157
160
|
if (value === "no-preference" || value === "reduce") {
|
|
158
161
|
hints.prefersReducedMotion = value;
|
|
159
162
|
hints.firstRequest = false;
|
|
160
163
|
}
|
|
161
164
|
}
|
|
162
165
|
if (hints.viewportHeightAvailable && ssrClientHintsConfiguration2.viewportSize) {
|
|
163
|
-
const header =
|
|
166
|
+
const header = headers[AcceptClientHintsRequestHeaders.viewportHeight];
|
|
164
167
|
if (header) {
|
|
165
168
|
hints.firstRequest = false;
|
|
166
169
|
try {
|
|
@@ -173,7 +176,7 @@ function collectClientHints(userAgent, ssrClientHintsConfiguration2, headers) {
|
|
|
173
176
|
hints.viewportHeight = ssrClientHintsConfiguration2.clientHeight;
|
|
174
177
|
}
|
|
175
178
|
if (hints.viewportWidthAvailable && ssrClientHintsConfiguration2.viewportSize) {
|
|
176
|
-
const header =
|
|
179
|
+
const header = headers[AcceptClientHintsRequestHeaders.viewportWidth];
|
|
177
180
|
if (header) {
|
|
178
181
|
hints.firstRequest = false;
|
|
179
182
|
try {
|
|
@@ -192,15 +195,7 @@ function writeClientHintHeaders(key, headers) {
|
|
|
192
195
|
headers[header] = (headers[header] ? headers[header] : []).concat(key);
|
|
193
196
|
});
|
|
194
197
|
}
|
|
195
|
-
function
|
|
196
|
-
const nuxtApp = useNuxtApp();
|
|
197
|
-
const unhook = nuxtApp.hooks.hookOnce("app:rendered", callback);
|
|
198
|
-
nuxtApp.hooks.hookOnce("app:error", () => {
|
|
199
|
-
unhook();
|
|
200
|
-
return callback();
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
function writeClientHintsResponseHeaders(clientHintsRequest, ssrClientHintsConfiguration2, response) {
|
|
198
|
+
function writeClientHintsResponseHeaders(clientHintsRequest, ssrClientHintsConfiguration2) {
|
|
204
199
|
const headers = {};
|
|
205
200
|
if (ssrClientHintsConfiguration2.prefersColorScheme && clientHintsRequest.prefersColorSchemeAvailable)
|
|
206
201
|
writeClientHintHeaders(AcceptClientHintsHeaders.prefersColorScheme, headers);
|
|
@@ -212,10 +207,17 @@ function writeClientHintsResponseHeaders(clientHintsRequest, ssrClientHintsConfi
|
|
|
212
207
|
}
|
|
213
208
|
if (Object.keys(headers).length === 0)
|
|
214
209
|
return;
|
|
215
|
-
|
|
210
|
+
const nuxtApp = useNuxtApp();
|
|
211
|
+
const callback = () => {
|
|
212
|
+
const event = useRequestEvent(nuxtApp);
|
|
216
213
|
Object.entries(headers).forEach(([key, value]) => {
|
|
217
|
-
|
|
214
|
+
setResponseHeader(event, key, value);
|
|
218
215
|
});
|
|
216
|
+
};
|
|
217
|
+
const unhook = nuxtApp.hooks.hookOnce("app:rendered", callback);
|
|
218
|
+
nuxtApp.hooks.hookOnce("app:error", () => {
|
|
219
|
+
unhook();
|
|
220
|
+
return callback();
|
|
219
221
|
});
|
|
220
222
|
}
|
|
221
223
|
function writeThemeCookie(clientHintsRequest, ssrClientHintsConfiguration2) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vuetify-nuxt-module",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.4",
|
|
5
5
|
"packageManager": "pnpm@8.10.2",
|
|
6
6
|
"description": "Zero-Config Nuxt Module for Vuetify",
|
|
7
7
|
"author": "userquin <userquin@gmail.com>",
|
|
@@ -43,24 +43,23 @@
|
|
|
43
43
|
"*.mjs"
|
|
44
44
|
],
|
|
45
45
|
"scripts": {
|
|
46
|
-
"
|
|
46
|
+
"prepack": "nuxt-module-build",
|
|
47
47
|
"dev": "nuxi dev playground",
|
|
48
48
|
"dev:multiple-json": "MULTIPLE_LANG_FILES=true nuxi dev playground",
|
|
49
|
-
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
|
|
50
|
-
"dev:prepare:multiple-json": "nuxt-module-build --stub && MULTIPLE_LANG_FILES=true nuxi prepare playground",
|
|
49
|
+
"dev:prepare": "nuxt-module-build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
50
|
+
"dev:prepare:multiple-json": "nuxt-module-build --stub && nuxt-module-build prepare && MULTIPLE_LANG_FILES=true nuxi prepare playground",
|
|
51
51
|
"dev:build": "nuxi build playground",
|
|
52
52
|
"dev:generate": "nuxi generate playground",
|
|
53
53
|
"dev:build:multiple-json": "MULTIPLE_LANG_FILES=true nuxi build playground",
|
|
54
54
|
"dev:generate:multiple-json": "MULTIPLE_LANG_FILES=true nuxi generate playground",
|
|
55
55
|
"dev:preview": "nuxi preview playground",
|
|
56
56
|
"docs:dev": "pnpm -C docs run dev",
|
|
57
|
-
"docs:build": "
|
|
57
|
+
"docs:build": "nuxt-module-build prepare && pnpm -C docs run build",
|
|
58
58
|
"docs:serve": "pnpm -C docs run serve",
|
|
59
59
|
"lint": "eslint .",
|
|
60
60
|
"lint:fix": "nr lint --fix",
|
|
61
61
|
"test": "vitest run",
|
|
62
62
|
"test:watch": "vitest watch",
|
|
63
|
-
"prepublishOnly": "pnpm build",
|
|
64
63
|
"release": "bumpp && npm publish"
|
|
65
64
|
},
|
|
66
65
|
"dependencies": {
|
|
@@ -129,4 +128,4 @@
|
|
|
129
128
|
"installDependencies": false,
|
|
130
129
|
"startCommand": "node .stackblitz.js && pnpm install && pnpm run dev"
|
|
131
130
|
}
|
|
132
|
-
}
|
|
131
|
+
}
|