vuetify-nuxt-module 0.6.0 → 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
@@ -4,5 +4,5 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0"
6
6
  },
7
- "version": "0.6.0"
7
+ "version": "0.6.2"
8
8
  }
package/dist/module.mjs CHANGED
@@ -2,17 +2,20 @@ import { addVitePlugin, extendWebpackConfig, addImports, addPlugin, useLogger, d
2
2
  import defu from 'defu';
3
3
  import { debounce } from 'perfect-debounce';
4
4
  import { existsSync, statSync } from 'node:fs';
5
- import { resolve, dirname } from 'node:path';
5
+ import { resolve, dirname, extname } from 'node:path';
6
6
  import process from 'node:process';
7
7
  import { createConfigLoader } from 'unconfig';
8
8
  import { readFile, utimes } from 'node:fs/promises';
9
9
  import { isPackageExists } from 'local-pkg';
10
- import { resolveVuetifyBase, normalizePath, writeStyles, cacheDir } from '@vuetify/loader-shared';
11
- import vuetify, { transformAssetUrls } from 'vite-plugin-vuetify';
10
+ import { resolveVuetifyBase, normalizePath, writeStyles, cacheDir, generateImports } from '@vuetify/loader-shared';
12
11
  import { isAbsolute, join, relative } from 'pathe';
13
12
  import { normalizePath as normalizePath$1 } from 'vite';
13
+ import { pathToFileURL } from 'node:url';
14
+ import { parseQuery, parseURL } from 'ufo';
15
+ import destr from 'destr';
16
+ import { transformAssetUrls } from 'vite-plugin-vuetify';
14
17
 
15
- const version = "0.6.0";
18
+ const version = "0.6.2";
16
19
 
17
20
  const VIRTUAL_VUETIFY_CONFIGURATION = "virtual:vuetify-configuration";
18
21
  const RESOLVED_VIRTUAL_VUETIFY_CONFIGURATION = `/@nuxt-vuetify-configuration/${VIRTUAL_VUETIFY_CONFIGURATION.slice("virtual:".length)}`;
@@ -1192,6 +1195,40 @@ function vuetifySSRClientHintsPlugin(ctx) {
1192
1195
  };
1193
1196
  }
1194
1197
 
1198
+ function parseId2(id) {
1199
+ id = id.replace(/^(virtual:nuxt:|virtual:)/, "");
1200
+ return parseURL(decodeURIComponent(isAbsolute(id) ? pathToFileURL(id).href : id));
1201
+ }
1202
+ function parseId(id) {
1203
+ const { search, pathname } = parseId2(id);
1204
+ const query = parseQuery(search);
1205
+ const urlProps = query.props ? destr(query.props) : void 0;
1206
+ return {
1207
+ query: urlProps,
1208
+ path: pathname ?? id
1209
+ };
1210
+ }
1211
+ function vuetifyImportPlugin() {
1212
+ return {
1213
+ name: "vuetify:import",
1214
+ configResolved(config) {
1215
+ if (config.plugins.findIndex((plugin) => plugin.name === "vuetify:import") < config.plugins.findIndex((plugin) => plugin.name === "vite:vue"))
1216
+ throw new Error("Vuetify plugin must be loaded after the vue plugin");
1217
+ },
1218
+ async transform(code, id) {
1219
+ const { query, path } = parseId(id);
1220
+ if ((!query || !("vue" in query)) && extname(path) === ".vue" && !/^import { render as _sfc_render } from ".*"$/m.test(code) || query && "vue" in query && (query.type === "template" || query.type === "script" && query.setup === "true")) {
1221
+ const { code: imports, source } = generateImports(code);
1222
+ return {
1223
+ code: source + imports,
1224
+ map: null
1225
+ };
1226
+ }
1227
+ return null;
1228
+ }
1229
+ };
1230
+ }
1231
+
1195
1232
  function configureVite(configKey, nuxt, ctx) {
1196
1233
  nuxt.hook("vite:extend", ({ config }) => checkVuetifyPlugins(config));
1197
1234
  nuxt.hook("vite:extendConfig", (viteInlineConfig) => {
@@ -1205,7 +1242,7 @@ function configureVite(configKey, nuxt, ctx) {
1205
1242
  configKey
1206
1243
  ];
1207
1244
  }
1208
- viteInlineConfig.plugins.push(vuetify({ styles: true, autoImport: true }));
1245
+ viteInlineConfig.plugins.push(vuetifyImportPlugin());
1209
1246
  viteInlineConfig.plugins.push(vuetifyStylesPlugin({ styles: ctx.moduleOptions.styles }, ctx.logger));
1210
1247
  viteInlineConfig.plugins.push(vuetifyConfigurationPlugin(ctx));
1211
1248
  viteInlineConfig.plugins.push(vuetifyIconsPlugin(ctx));
@@ -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
- useRequestEvent,
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 request = event.node.req;
18
- const response = event.node.res;
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, response);
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 = readClientHeader("cookie", headers)?.split(";").find((c) => c.trim().startsWith(`${cookieName}=`));
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 ? readClientHeader(AcceptClientHintsRequestHeaders.prefersColorScheme, headers)?.toLowerCase() : void 0;
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 = readClientHeader(AcceptClientHintsRequestHeaders.prefersReducedMotion, headers)?.toLowerCase();
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 = readClientHeader(AcceptClientHintsRequestHeaders.viewportHeight, headers);
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 = readClientHeader(AcceptClientHintsRequestHeaders.viewportWidth, headers);
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 withNuxtAppRendered(callback) {
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
- withNuxtAppRendered(() => {
200
+ const nuxtApp = useNuxtApp();
201
+ const callback = () => {
202
+ const event = useRequestEvent(nuxtApp);
216
203
  Object.entries(headers).forEach(([key, value]) => {
217
- response.setHeader(key, value);
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,8 +1,8 @@
1
1
  {
2
2
  "name": "vuetify-nuxt-module",
3
3
  "type": "module",
4
- "version": "0.6.0",
5
- "packageManager": "pnpm@8.9.2",
4
+ "version": "0.6.2",
5
+ "packageManager": "pnpm@8.10.2",
6
6
  "description": "Zero-Config Nuxt Module for Vuetify",
7
7
  "author": "userquin <userquin@gmail.com>",
8
8
  "license": "MIT",
@@ -69,7 +69,7 @@
69
69
  "perfect-debounce": "^1.0.0",
70
70
  "unconfig": "^0.3.9",
71
71
  "vite-plugin-vuetify": "^1.0.2",
72
- "vuetify": "^3.3.17"
72
+ "vuetify": "^3.3.23"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@antfu/eslint-config": "^0.41.0",
@@ -104,6 +104,7 @@
104
104
  "node:child_process",
105
105
  "node:fs",
106
106
  "consola",
107
+ "destr",
107
108
  "esbuild",
108
109
  "local-pkg",
109
110
  "pathe",