vuetify-nuxt-module 0.6.1 → 0.6.2
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.2";
|
|
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)}`;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { setResponseHeader } from "h3";
|
|
1
2
|
import {
|
|
2
3
|
ssrClientHintsConfiguration
|
|
3
4
|
} from "virtual:vuetify-ssr-client-hints-configuration";
|
|
@@ -8,19 +9,27 @@ import {
|
|
|
8
9
|
defineNuxtPlugin,
|
|
9
10
|
useCookie,
|
|
10
11
|
useNuxtApp,
|
|
11
|
-
|
|
12
|
+
useRequestHeaders,
|
|
12
13
|
useState
|
|
13
14
|
} from "#imports";
|
|
15
|
+
const AcceptClientHintsHeaders = {
|
|
16
|
+
prefersColorScheme: "Sec-CH-Prefers-Color-Scheme",
|
|
17
|
+
prefersReducedMotion: "Sec-CH-Prefers-Reduced-Motion",
|
|
18
|
+
viewportHeight: "Sec-CH-Viewport-Height",
|
|
19
|
+
viewportWidth: "Sec-CH-Viewport-Width"
|
|
20
|
+
};
|
|
21
|
+
const AcceptClientHintsRequestHeaders = Object.entries(AcceptClientHintsHeaders).reduce((acc, [key, value]) => {
|
|
22
|
+
acc[key] = value.toLowerCase();
|
|
23
|
+
return acc;
|
|
24
|
+
}, {});
|
|
25
|
+
const HttpRequestHeaders = Array.from(Object.values(AcceptClientHintsRequestHeaders)).concat("user-agent", "cookie");
|
|
14
26
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
15
|
-
const event = useRequestEvent();
|
|
16
27
|
const state = useState(VuetifyHTTPClientHints);
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const requestHeaders = request.headers ?? {};
|
|
20
|
-
const userAgentHeader = readClientHeader("user-agent", requestHeaders);
|
|
28
|
+
const requestHeaders = useRequestHeaders(HttpRequestHeaders);
|
|
29
|
+
const userAgentHeader = requestHeaders["user-agent"];
|
|
21
30
|
const userAgent = userAgentHeader ? parseUserAgent(userAgentHeader) : null;
|
|
22
31
|
const clientHintsRequest = collectClientHints(userAgent, ssrClientHintsConfiguration, requestHeaders);
|
|
23
|
-
writeClientHintsResponseHeaders(clientHintsRequest, ssrClientHintsConfiguration
|
|
32
|
+
writeClientHintsResponseHeaders(clientHintsRequest, ssrClientHintsConfiguration);
|
|
24
33
|
state.value = clientHintsRequest;
|
|
25
34
|
state.value.colorSchemeCookie = writeThemeCookie(
|
|
26
35
|
clientHintsRequest,
|
|
@@ -47,12 +56,6 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
47
56
|
})
|
|
48
57
|
};
|
|
49
58
|
});
|
|
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
59
|
const chromiumBasedBrowserFeatures = {
|
|
57
60
|
prefersColorScheme: (_, v) => v[0] >= 93,
|
|
58
61
|
prefersReducedMotion: (_, v) => v[0] >= 108,
|
|
@@ -72,17 +75,7 @@ const allowedBrowsers = [
|
|
|
72
75
|
viewportWidth: (android, v) => v[0] >= (android ? 73 : 94)
|
|
73
76
|
}]
|
|
74
77
|
];
|
|
75
|
-
const AcceptClientHintsRequestHeaders = Object.entries(AcceptClientHintsHeaders).reduce((acc, [key, value]) => {
|
|
76
|
-
acc[key] = value.toLowerCase();
|
|
77
|
-
return acc;
|
|
78
|
-
}, {});
|
|
79
78
|
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
79
|
function browserFeatureAvailable(userAgent, feature) {
|
|
87
80
|
if (userAgent == null || userAgent.type !== "browser")
|
|
88
81
|
return false;
|
|
@@ -128,7 +121,7 @@ function collectClientHints(userAgent, ssrClientHintsConfiguration2, headers) {
|
|
|
128
121
|
if (ssrClientHintsConfiguration2.prefersColorScheme) {
|
|
129
122
|
if (ssrClientHintsConfiguration2.prefersColorSchemeOptions) {
|
|
130
123
|
const cookieName = ssrClientHintsConfiguration2.prefersColorSchemeOptions.cookieName;
|
|
131
|
-
const cookieValue =
|
|
124
|
+
const cookieValue = headers.cookie?.split(";").find((c) => c.trim().startsWith(`${cookieName}=`));
|
|
132
125
|
if (cookieValue) {
|
|
133
126
|
const value = cookieValue.split("=")?.[1].trim();
|
|
134
127
|
if (ssrClientHintsConfiguration2.prefersColorSchemeOptions.themeNames.includes(value)) {
|
|
@@ -138,7 +131,7 @@ function collectClientHints(userAgent, ssrClientHintsConfiguration2, headers) {
|
|
|
138
131
|
}
|
|
139
132
|
}
|
|
140
133
|
if (!hints.colorSchemeFromCookie) {
|
|
141
|
-
const value = hints.prefersColorSchemeAvailable ?
|
|
134
|
+
const value = hints.prefersColorSchemeAvailable ? headers[AcceptClientHintsRequestHeaders.prefersColorScheme]?.toLowerCase() : void 0;
|
|
142
135
|
if (value === "dark" || value === "light" || value === "no-preference") {
|
|
143
136
|
hints.prefersColorScheme = value;
|
|
144
137
|
hints.firstRequest = false;
|
|
@@ -153,14 +146,14 @@ function collectClientHints(userAgent, ssrClientHintsConfiguration2, headers) {
|
|
|
153
146
|
}
|
|
154
147
|
}
|
|
155
148
|
if (hints.prefersReducedMotionAvailable && ssrClientHintsConfiguration2.prefersReducedMotion) {
|
|
156
|
-
const value =
|
|
149
|
+
const value = headers[AcceptClientHintsRequestHeaders.prefersReducedMotion]?.toLowerCase();
|
|
157
150
|
if (value === "no-preference" || value === "reduce") {
|
|
158
151
|
hints.prefersReducedMotion = value;
|
|
159
152
|
hints.firstRequest = false;
|
|
160
153
|
}
|
|
161
154
|
}
|
|
162
155
|
if (hints.viewportHeightAvailable && ssrClientHintsConfiguration2.viewportSize) {
|
|
163
|
-
const header =
|
|
156
|
+
const header = headers[AcceptClientHintsRequestHeaders.viewportHeight];
|
|
164
157
|
if (header) {
|
|
165
158
|
hints.firstRequest = false;
|
|
166
159
|
try {
|
|
@@ -173,7 +166,7 @@ function collectClientHints(userAgent, ssrClientHintsConfiguration2, headers) {
|
|
|
173
166
|
hints.viewportHeight = ssrClientHintsConfiguration2.clientHeight;
|
|
174
167
|
}
|
|
175
168
|
if (hints.viewportWidthAvailable && ssrClientHintsConfiguration2.viewportSize) {
|
|
176
|
-
const header =
|
|
169
|
+
const header = headers[AcceptClientHintsRequestHeaders.viewportWidth];
|
|
177
170
|
if (header) {
|
|
178
171
|
hints.firstRequest = false;
|
|
179
172
|
try {
|
|
@@ -192,15 +185,7 @@ function writeClientHintHeaders(key, headers) {
|
|
|
192
185
|
headers[header] = (headers[header] ? headers[header] : []).concat(key);
|
|
193
186
|
});
|
|
194
187
|
}
|
|
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) {
|
|
188
|
+
function writeClientHintsResponseHeaders(clientHintsRequest, ssrClientHintsConfiguration2) {
|
|
204
189
|
const headers = {};
|
|
205
190
|
if (ssrClientHintsConfiguration2.prefersColorScheme && clientHintsRequest.prefersColorSchemeAvailable)
|
|
206
191
|
writeClientHintHeaders(AcceptClientHintsHeaders.prefersColorScheme, headers);
|
|
@@ -212,10 +197,17 @@ function writeClientHintsResponseHeaders(clientHintsRequest, ssrClientHintsConfi
|
|
|
212
197
|
}
|
|
213
198
|
if (Object.keys(headers).length === 0)
|
|
214
199
|
return;
|
|
215
|
-
|
|
200
|
+
const nuxtApp = useNuxtApp();
|
|
201
|
+
const callback = () => {
|
|
202
|
+
const event = useRequestEvent(nuxtApp);
|
|
216
203
|
Object.entries(headers).forEach(([key, value]) => {
|
|
217
|
-
|
|
204
|
+
setResponseHeader(event, key, value);
|
|
218
205
|
});
|
|
206
|
+
};
|
|
207
|
+
const unhook = nuxtApp.hooks.hookOnce("app:rendered", callback);
|
|
208
|
+
nuxtApp.hooks.hookOnce("app:error", () => {
|
|
209
|
+
unhook();
|
|
210
|
+
return callback();
|
|
219
211
|
});
|
|
220
212
|
}
|
|
221
213
|
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.2",
|
|
5
5
|
"packageManager": "pnpm@8.10.2",
|
|
6
6
|
"description": "Zero-Config Nuxt Module for Vuetify",
|
|
7
7
|
"author": "userquin <userquin@gmail.com>",
|
|
@@ -129,4 +129,4 @@
|
|
|
129
129
|
"installDependencies": false,
|
|
130
130
|
"startCommand": "node .stackblitz.js && pnpm install && pnpm run dev"
|
|
131
131
|
}
|
|
132
|
-
}
|
|
132
|
+
}
|