@vizejs/nuxt 0.49.0 → 0.58.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/nuxt",
3
- "version": "0.49.0",
3
+ "version": "0.58.0",
4
4
  "description": "Nuxt module for Vize - compiler, musea gallery, linter, and type checker",
5
5
  "keywords": [
6
6
  "compiler",
@@ -36,18 +36,18 @@
36
36
  "access": "public"
37
37
  },
38
38
  "dependencies": {
39
- "@nuxt/kit": "^4.0.0",
40
- "@vizejs/musea-nuxt": "0.49.0",
41
- "@vizejs/vite-plugin": "0.49.0",
42
- "@vizejs/vite-plugin-musea": "0.49.0",
43
- "vize": "0.49.0"
39
+ "@nuxt/kit": "4.4.2",
40
+ "@vizejs/musea-nuxt": "0.58.0",
41
+ "@vizejs/vite-plugin": "0.58.0",
42
+ "@vizejs/vite-plugin-musea": "0.58.0",
43
+ "vize": "0.58.0"
44
44
  },
45
45
  "devDependencies": {
46
- "typescript": "^5.7.0",
47
- "vite": "npm:@voidzero-dev/vite-plus-core@latest",
48
- "vite-plus": "latest",
49
- "vue": "^3.5.0",
50
- "vue-router": "^4.5.0"
46
+ "typescript": "6.0.3",
47
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.1.19",
48
+ "vite-plus": "0.1.19",
49
+ "vue": "3.5.32",
50
+ "vue-router": "4.6.4"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "nuxt": "^3.0.0 || ^4.0.0"
package/dist/index.d.mts DELETED
@@ -1,28 +0,0 @@
1
- import { MuseaOptions, MuseaOptions as MuseaOptions$1 } from "@vizejs/vite-plugin-musea";
2
- import * as nuxt_schema0 from "nuxt/schema";
3
- import { NuxtMuseaOptions, NuxtMuseaOptions as NuxtMuseaOptions$1 } from "@vizejs/musea-nuxt";
4
-
5
- //#region src/index.d.ts
6
- interface VizeNuxtOptions {
7
- /**
8
- * Enable/disable the Vize compiler (Vue SFC compilation via Vite plugin).
9
- * Set to `false` to use Vue's default SFC compiler instead.
10
- * @default true
11
- */
12
- compiler?: boolean;
13
- /**
14
- * Musea gallery options.
15
- * Set to `false` to disable musea.
16
- */
17
- musea?: MuseaOptions$1 | false;
18
- /**
19
- * Nuxt mock options for musea gallery.
20
- * NOTE: In Nuxt context, nuxtMusea mocks are NOT added as a global Vite plugin
21
- * because they would intercept `#imports` resolution and break Nuxt's internals.
22
- * Real Nuxt composables are available via Nuxt's own plugin pipeline.
23
- */
24
- nuxtMusea?: NuxtMuseaOptions$1;
25
- }
26
- declare const _default: nuxt_schema0.NuxtModule<VizeNuxtOptions, VizeNuxtOptions, false>;
27
- //#endregion
28
- export { type MuseaOptions, type NuxtMuseaOptions, VizeNuxtOptions, _default as default };
package/dist/index.mjs DELETED
@@ -1,408 +0,0 @@
1
- import { createRequire } from "node:module";
2
- import fs from "node:fs";
3
- import { addServerPlugin, addVitePlugin, createResolver, defineNuxtModule } from "@nuxt/kit";
4
- import vize from "@vizejs/vite-plugin";
5
- import { musea } from "@vizejs/vite-plugin-musea";
6
- import path from "node:path";
7
- //#region src/components.ts
8
- const COMPONENT_CALL_RE = /_?resolveComponent\s*\(\s*["'`]([^"'`]+)["'`]\s*(?:,\s*[^)]+)?\)/g;
9
- const COMPONENT_EXT_RE = /\.(?:[cm]?js|ts|vue)$/;
10
- const DTS_COMPONENT_RE = /^export const (\w+): (?:LazyComponent<)?typeof import\((["'])(.+?)\2\)(?:\.([A-Za-z_$][\w$]*)|\[['"]([A-Za-z_$][\w$]*)['"]\])>?/;
11
- const DTS_EXT_RE = /\.d\.ts$/;
12
- const FILE_EXTS = [
13
- ".js",
14
- ".mjs",
15
- ".ts",
16
- ".vue"
17
- ];
18
- const CLIENT_COMPONENT_RE = /\.client\.(?:[cm]?js|ts|vue)$/;
19
- const SERVER_COMPONENT_RE = /\.server\.(?:[cm]?js|ts|vue)$/;
20
- const RUNTIME_COMPONENT_DIRS = [
21
- "dist/runtime/components",
22
- "dist/runtime/components/nuxt4",
23
- "runtime/components"
24
- ];
25
- function toKebabCase(name) {
26
- return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/_/g, "-").toLowerCase();
27
- }
28
- function toPascalCase(name) {
29
- return name.split(/[-_.]/g).filter(Boolean).map((part) => part[0].toUpperCase() + part.slice(1)).join("");
30
- }
31
- function addComponentAlias(map, name, resolved) {
32
- if (!name || map.has(name)) return;
33
- map.set(name, resolved);
34
- const kebabName = toKebabCase(name);
35
- if (!map.has(kebabName)) map.set(kebabName, resolved);
36
- const pascalName = toPascalCase(name);
37
- if (!map.has(pascalName)) map.set(pascalName, resolved);
38
- }
39
- function addLazyComponentAlias(map, name, resolved) {
40
- if (!name || name.startsWith("Lazy")) return;
41
- addComponentAlias(map, `Lazy${toPascalCase(name)}`, {
42
- ...resolved,
43
- lazy: true
44
- });
45
- }
46
- function resolveImportPath(importPath) {
47
- if (fs.existsSync(importPath)) return importPath;
48
- for (const ext of FILE_EXTS) {
49
- const withExt = importPath + ext;
50
- if (fs.existsSync(withExt)) return withExt;
51
- }
52
- return importPath;
53
- }
54
- function detectComponentMode(filePath) {
55
- if (CLIENT_COMPONENT_RE.test(filePath)) return "client";
56
- if (SERVER_COMPONENT_RE.test(filePath)) return "server";
57
- }
58
- function createComponentImport(filePath, exportName, lazy) {
59
- const componentImport = {
60
- exportName,
61
- filePath
62
- };
63
- if (lazy) componentImport.lazy = true;
64
- const mode = detectComponentMode(filePath);
65
- if (mode) componentImport.mode = mode;
66
- return componentImport;
67
- }
68
- function getNuxtComponentDtsFiles(rootDir, buildDir) {
69
- const candidates = [
70
- path.join(buildDir, "components.d.ts"),
71
- path.join(buildDir, "types", "components.d.ts"),
72
- path.join(rootDir, ".nuxt", "components.d.ts"),
73
- path.join(rootDir, ".nuxt", "types", "components.d.ts"),
74
- path.join(rootDir, "node_modules", ".cache", "nuxt", ".nuxt", "components.d.ts"),
75
- path.join(rootDir, "node_modules", ".cache", "nuxt", ".nuxt", "types", "components.d.ts")
76
- ];
77
- return Array.from(new Set(candidates.filter((candidate) => fs.existsSync(candidate))));
78
- }
79
- function loadDtsComponents(rootDir, buildDir) {
80
- const resolved = /* @__PURE__ */ new Map();
81
- for (const filePath of getNuxtComponentDtsFiles(rootDir, buildDir)) {
82
- const lines = fs.readFileSync(filePath, "utf-8").split("\n");
83
- for (const line of lines) {
84
- const match = line.match(DTS_COMPONENT_RE);
85
- if (!match) continue;
86
- const [, name, , importPath, exportNameDot, exportNameBracket] = match;
87
- const exportName = exportNameDot || exportNameBracket;
88
- if (!exportName) continue;
89
- const componentImport = createComponentImport(resolveImportPath(path.resolve(path.dirname(filePath), importPath)), exportName, name.startsWith("Lazy"));
90
- addComponentAlias(resolved, name, componentImport);
91
- addLazyComponentAlias(resolved, name, componentImport);
92
- }
93
- }
94
- return resolved;
95
- }
96
- function getProjectPackageNames(moduleNames) {
97
- const packageNames = new Set(["nuxt"]);
98
- for (const name of moduleNames || []) packageNames.add(name);
99
- return Array.from(packageNames);
100
- }
101
- function walkRuntimeComponentDir(resolved, dir) {
102
- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
103
- const entryPath = path.join(dir, entry.name);
104
- if (entry.isDirectory()) {
105
- walkRuntimeComponentDir(resolved, entryPath);
106
- continue;
107
- }
108
- if (!COMPONENT_EXT_RE.test(entry.name) || DTS_EXT_RE.test(entry.name)) continue;
109
- const baseName = entry.name.replace(COMPONENT_EXT_RE, "");
110
- const componentName = baseName === "index" ? path.basename(path.dirname(entryPath)) : baseName;
111
- if (!/[A-Z]/.test(componentName)) continue;
112
- addComponentAlias(resolved, componentName, { ...createComponentImport(entryPath, "default") });
113
- addLazyComponentAlias(resolved, componentName, { ...createComponentImport(entryPath, "default") });
114
- }
115
- }
116
- function loadRuntimeComponents(rootDir, moduleNames) {
117
- const resolved = /* @__PURE__ */ new Map();
118
- const requireFromRoot = createRequire(path.join(rootDir, "package.json"));
119
- for (const packageName of getProjectPackageNames(moduleNames)) {
120
- let packageJsonPath = "";
121
- try {
122
- packageJsonPath = requireFromRoot.resolve(`${packageName}/package.json`);
123
- } catch {
124
- continue;
125
- }
126
- const packageDir = path.dirname(packageJsonPath);
127
- for (const runtimeDir of RUNTIME_COMPONENT_DIRS) {
128
- const runtimePath = path.join(packageDir, runtimeDir);
129
- if (fs.existsSync(runtimePath)) walkRuntimeComponentDir(resolved, runtimePath);
130
- }
131
- }
132
- return resolved;
133
- }
134
- function createNuxtComponentResolver(options) {
135
- const registered = /* @__PURE__ */ new Map();
136
- let dtsResolved = null;
137
- let runtimeResolved = null;
138
- function getDtsResolved() {
139
- if (!dtsResolved) dtsResolved = loadDtsComponents(options.rootDir, options.buildDir);
140
- return dtsResolved;
141
- }
142
- function getRuntimeResolved() {
143
- if (!runtimeResolved) runtimeResolved = loadRuntimeComponents(options.rootDir, options.moduleNames);
144
- return runtimeResolved;
145
- }
146
- return {
147
- register(components) {
148
- for (const component of components) {
149
- const resolved = createComponentImport(component.filePath, component.export || "default");
150
- addComponentAlias(registered, component.pascalName, resolved);
151
- addComponentAlias(registered, component.kebabName, resolved);
152
- addComponentAlias(registered, component.name, resolved);
153
- addLazyComponentAlias(registered, component.pascalName, resolved);
154
- addLazyComponentAlias(registered, component.kebabName, resolved);
155
- addLazyComponentAlias(registered, component.name, resolved);
156
- }
157
- },
158
- resolve(name) {
159
- const normalizedName = name.trim();
160
- const directResolved = registered.get(normalizedName) ?? getDtsResolved().get(normalizedName);
161
- if (directResolved) return directResolved;
162
- if (!/[A-Z]/.test(normalizedName)) return null;
163
- return getRuntimeResolved().get(normalizedName) ?? null;
164
- }
165
- };
166
- }
167
- function injectNuxtComponentImports(code, resolveComponentImport) {
168
- const componentImports = [];
169
- const importedComponents = /* @__PURE__ */ new Map();
170
- let counter = 0;
171
- let needsDefineAsyncComponent = false;
172
- let needsCreateClientOnly = false;
173
- const nextCode = code.replace(COMPONENT_CALL_RE, (match, name) => {
174
- const resolved = resolveComponentImport(name);
175
- if (!resolved) return match;
176
- const importKey = `${resolved.exportName}\u0000${resolved.filePath}\u0000${resolved.lazy ? "lazy" : "eager"}\u0000${resolved.mode ?? "default"}`;
177
- let variableName = importedComponents.get(importKey);
178
- if (!variableName) {
179
- variableName = `__nuxt_component_${counter++}`;
180
- importedComponents.set(importKey, variableName);
181
- if (resolved.lazy) {
182
- needsDefineAsyncComponent = true;
183
- const exportAccessor = resolved.exportName === "default" ? "module.default" : `module[${JSON.stringify(resolved.exportName)}]`;
184
- if (resolved.mode === "client") {
185
- needsCreateClientOnly = true;
186
- componentImports.push(`const ${variableName} = __nuxt_define_async_component(() => import(${JSON.stringify(resolved.filePath)}).then((module) => __nuxt_create_client_only(${exportAccessor})));`);
187
- } else componentImports.push(`const ${variableName} = __nuxt_define_async_component(() => import(${JSON.stringify(resolved.filePath)}).then((module) => ${exportAccessor}));`);
188
- } else if (resolved.exportName === "default") if (resolved.mode === "client") {
189
- needsCreateClientOnly = true;
190
- const rawVariableName = `${variableName}_raw`;
191
- componentImports.push(`import ${rawVariableName} from ${JSON.stringify(resolved.filePath)};`);
192
- componentImports.push(`const ${variableName} = __nuxt_create_client_only(${rawVariableName});`);
193
- } else componentImports.push(`import ${variableName} from ${JSON.stringify(resolved.filePath)};`);
194
- else if (resolved.mode === "client") {
195
- needsCreateClientOnly = true;
196
- const rawVariableName = `${variableName}_raw`;
197
- componentImports.push(`import { ${resolved.exportName} as ${rawVariableName} } from ${JSON.stringify(resolved.filePath)};`);
198
- componentImports.push(`const ${variableName} = __nuxt_create_client_only(${rawVariableName});`);
199
- } else componentImports.push(`import { ${resolved.exportName} as ${variableName} } from ${JSON.stringify(resolved.filePath)};`);
200
- }
201
- return variableName;
202
- });
203
- if (componentImports.length === 0) return code;
204
- return [
205
- ...needsDefineAsyncComponent ? ["import { defineAsyncComponent as __nuxt_define_async_component } from \"vue\";"] : [],
206
- ...needsCreateClientOnly ? ["import { createClientOnly as __nuxt_create_client_only } from \"#app/components/client-only\";"] : [],
207
- ...componentImports
208
- ].join("\n") + "\n" + nextCode;
209
- }
210
- //#endregion
211
- //#region src/i18n.ts
212
- const I18N_FN_MAP = {
213
- $t: "t: $t",
214
- $rt: "rt: $rt",
215
- $d: "d: $d",
216
- $n: "n: $n",
217
- $tm: "tm: $tm",
218
- $te: "te: $te"
219
- };
220
- const I18N_FN_RE = /(?<![.\w])\$([tdn]|rt|tm|te)\s*\(/g;
221
- const SETUP_FN_RE = /setup\s*\(__props[\s\S]*?\)\s*\{/;
222
- const USE_I18N_DESTRUCTURE_RE = /const\s*\{([^}]*)\}\s*=\s*useI18n\s*\(\s*\)\s*;?/;
223
- function getLocalAlias(specifier) {
224
- const colon = specifier.indexOf(":");
225
- return (colon === -1 ? specifier : specifier.slice(colon + 1)).trim();
226
- }
227
- function collectUsedI18nSpecifiers(code) {
228
- const used = /* @__PURE__ */ new Set();
229
- for (const match of code.matchAll(I18N_FN_RE)) {
230
- const specifier = I18N_FN_MAP[`$${match[1]}`];
231
- if (specifier) used.add(specifier);
232
- }
233
- return Array.from(used);
234
- }
235
- function collectDestructuredLocalNames(destructure) {
236
- const locals = /* @__PURE__ */ new Set();
237
- for (const rawPart of destructure.split(",")) {
238
- const part = rawPart.trim();
239
- if (!part) continue;
240
- const withoutDefault = (part.split("=")[0] ?? part).trim();
241
- const aliasMatch = withoutDefault.match(/^(?:\.\.\.)?[^:]+:\s*(.+)$/);
242
- const localName = (aliasMatch ? aliasMatch[1] : withoutDefault).trim();
243
- if (localName) locals.add(localName);
244
- }
245
- return locals;
246
- }
247
- function injectNuxtI18nHelpers(code) {
248
- const usedSpecifiers = collectUsedI18nSpecifiers(code);
249
- if (usedSpecifiers.length === 0) return code;
250
- const setupMatch = code.match(SETUP_FN_RE);
251
- if (!setupMatch || setupMatch.index === void 0) return code;
252
- const setupBodyStart = setupMatch.index + setupMatch[0].length;
253
- const existingMatch = code.slice(setupBodyStart).match(USE_I18N_DESTRUCTURE_RE);
254
- if (existingMatch && existingMatch.index !== void 0) {
255
- const existingLocals = collectDestructuredLocalNames(existingMatch[1]);
256
- const missingSpecifiers = usedSpecifiers.filter((specifier) => {
257
- return !existingLocals.has(getLocalAlias(specifier));
258
- });
259
- if (missingSpecifiers.length === 0) return code;
260
- const merged = existingMatch[1].trim();
261
- const nextDestructure = merged ? `${merged}, ${missingSpecifiers.join(", ")}` : missingSpecifiers.join(", ");
262
- const matchStart = setupBodyStart + existingMatch.index;
263
- const matchEnd = matchStart + existingMatch[0].length;
264
- return code.slice(0, matchStart) + `const { ${nextDestructure} } = useI18n();` + code.slice(matchEnd);
265
- }
266
- return code.slice(0, setupBodyStart) + `\nconst { ${usedSpecifiers.join(", ")} } = useI18n();\n` + code.slice(setupBodyStart);
267
- }
268
- //#endregion
269
- //#region src/utils.ts
270
- function normalizeUrlPrefix(value) {
271
- const withLeadingSlash = value.startsWith("/") ? value : `/${value}`;
272
- return withLeadingSlash.endsWith("/") ? withLeadingSlash : `${withLeadingSlash}/`;
273
- }
274
- function buildNuxtDevAssetBase(baseURL = "/", buildAssetsDir = "/_nuxt/") {
275
- const normalizedBase = normalizeUrlPrefix(baseURL);
276
- const normalizedAssetsDir = normalizeUrlPrefix(buildAssetsDir);
277
- return normalizedBase === "/" ? normalizedAssetsDir : normalizeUrlPrefix(`${normalizedBase}${normalizedAssetsDir.replace(/^\//, "")}`);
278
- }
279
- function buildNuxtCompilerOptions(rootDir, baseURL = "/", buildAssetsDir = "/_nuxt/") {
280
- return {
281
- devUrlBase: buildNuxtDevAssetBase(baseURL, buildAssetsDir),
282
- root: rootDir
283
- };
284
- }
285
- function isVizeVirtualVueModuleId(id) {
286
- return id.startsWith("\0") && /\.vue\.ts(?:\?|$)/.test(id);
287
- }
288
- function normalizeVizeVirtualVueModuleId(id) {
289
- return (id.startsWith("\0vize-ssr:") ? id.slice(10) : id.slice(1)).replace(/\.ts$/, "");
290
- }
291
- //#endregion
292
- //#region src/index.ts
293
- /**
294
- * @vizejs/nuxt - Nuxt module for Vize
295
- *
296
- * Provides:
297
- * - Compiler: Vue SFC compilation via Vite plugin
298
- * - Musea: Component gallery with Nuxt mock support
299
- * - Linter: `vize lint` CLI command (via `vize` bin)
300
- * - Type Checker: `vize check` CLI command (via `vize` bin)
301
- */
302
- var src_default = defineNuxtModule({
303
- meta: {
304
- name: "@vizejs/nuxt",
305
- configKey: "vize"
306
- },
307
- defaults: {
308
- musea: {
309
- include: ["**/*.art.vue"],
310
- inlineArt: false
311
- },
312
- nuxtMusea: { route: { path: "/" } }
313
- },
314
- setup(options, nuxt) {
315
- const resolver = createResolver(import.meta.url);
316
- nuxt.options.vite.plugins = nuxt.options.vite.plugins || [];
317
- if (options.compiler !== false) {
318
- const compilerOptions = buildNuxtCompilerOptions(nuxt.options.rootDir, nuxt.options.app.baseURL, nuxt.options.app.buildAssetsDir);
319
- nuxt.options.vite.plugins.push(vize(compilerOptions));
320
- if (nuxt.options.dev) {
321
- nuxt.options.nitro.virtual ||= {};
322
- nuxt.options.nitro.virtual["#vizejs/nuxt/dev-stylesheet-links-config"] = `export const devAssetBase = ${JSON.stringify(compilerOptions.devUrlBase)};`;
323
- addServerPlugin(resolver.resolve("./runtime/server/dev-stylesheet-links"));
324
- }
325
- nuxt.hook("vite:configResolved", (config) => {
326
- for (let i = config.plugins.length - 1; i >= 0; i--) {
327
- const p = config.plugins[i];
328
- if ((p && typeof p === "object" && "name" in p ? p.name : "") === "vite:vue") config.plugins.splice(i, 1);
329
- }
330
- });
331
- }
332
- let unimportCtx = null;
333
- nuxt.hook("imports:context", (ctx) => {
334
- unimportCtx = ctx;
335
- });
336
- const nuxtComponentResolver = createNuxtComponentResolver({
337
- buildDir: nuxt.options.buildDir,
338
- moduleNames: nuxt.options.modules.filter((moduleName) => typeof moduleName === "string"),
339
- rootDir: nuxt.options.rootDir
340
- });
341
- nuxt.hook("components:extend", (comps) => {
342
- nuxtComponentResolver.register(comps);
343
- });
344
- addVitePlugin({
345
- name: "vizejs:nuxt-transform-bridge",
346
- enforce: "post",
347
- async transform(code, id) {
348
- if (!isVizeVirtualVueModuleId(id)) return;
349
- let result = code;
350
- let changed = false;
351
- const nextComponentResult = injectNuxtComponentImports(result, (name) => {
352
- return nuxtComponentResolver.resolve(name);
353
- });
354
- if (nextComponentResult !== result) {
355
- result = nextComponentResult;
356
- changed = true;
357
- }
358
- const nextResult = injectNuxtI18nHelpers(result);
359
- if (nextResult !== result) {
360
- result = nextResult;
361
- changed = true;
362
- }
363
- if (unimportCtx) try {
364
- const injected = await unimportCtx.injectImports(result, id);
365
- if (injected.imports && injected.imports.length > 0) {
366
- result = injected.code;
367
- changed = true;
368
- }
369
- } catch {}
370
- if (changed) return {
371
- code: result,
372
- map: null
373
- };
374
- }
375
- });
376
- addVitePlugin({
377
- name: "vizejs:unocss-bridge",
378
- configResolved(config) {
379
- for (const plugin of config.plugins) if (plugin.name?.startsWith("unocss:") && typeof plugin.transform === "function") {
380
- const origTransform = plugin.transform;
381
- const isExtractionOnly = plugin.name.startsWith("unocss:global");
382
- plugin.transform = function(code, id, ...args) {
383
- if (isVizeVirtualVueModuleId(id)) {
384
- const normalizedId = normalizeVizeVirtualVueModuleId(id);
385
- let effectiveCode = code;
386
- if (isExtractionOnly) try {
387
- const originalSource = fs.readFileSync(normalizedId.split("?")[0], "utf-8");
388
- effectiveCode = code + "\n" + originalSource;
389
- } catch {}
390
- return origTransform.call(this, effectiveCode, normalizedId, ...args);
391
- }
392
- return origTransform.call(this, code, id, ...args);
393
- };
394
- }
395
- }
396
- });
397
- if (options.musea !== false) {
398
- const museaBasePath = options.musea && typeof options.musea === "object" && "basePath" in options.musea ? options.musea.basePath : "/__musea__";
399
- nuxt.options.vite.plugins.push(...musea(options.musea || {}));
400
- nuxt.hook("listen", (_server, listener) => {
401
- const url = listener.url?.replace(/\/$/, "") || "http://localhost:3000";
402
- console.log(` \x1b[36m➜\x1b[0m \x1b[1mMusea Gallery:\x1b[0m \x1b[36m${url}${museaBasePath}\x1b[0m`);
403
- });
404
- }
405
- }
406
- });
407
- //#endregion
408
- export { src_default as default };
@@ -1,4 +0,0 @@
1
- //#region src/runtime/server/dev-stylesheet-links.d.ts
2
- declare const _default: any;
3
- //#endregion
4
- export { _default as default };
@@ -1,34 +0,0 @@
1
- import { defineNitroPlugin } from "nitropack/runtime";
2
- import { devAssetBase } from "#vizejs/nuxt/dev-stylesheet-links-config";
3
- //#region src/dev-html.ts
4
- function sanitizeNuxtDevStylesheetLinks(html, buildAssetsDir = "/_nuxt/") {
5
- function normalizeUrlPrefix(value) {
6
- const withLeadingSlash = value.startsWith("/") ? value : `/${value}`;
7
- return withLeadingSlash.endsWith("/") ? withLeadingSlash : `${withLeadingSlash}/`;
8
- }
9
- const normalizedAssetsDir = normalizeUrlPrefix(buildAssetsDir);
10
- const seenHrefs = /* @__PURE__ */ new Set();
11
- function shouldKeepHref(href) {
12
- if (seenHrefs.has(href)) return false;
13
- seenHrefs.add(href);
14
- if (!href.startsWith(normalizedAssetsDir)) return true;
15
- const pathPart = href.slice(normalizedAssetsDir.length).split("?")[0].split("#")[0];
16
- let decodedPath = pathPart;
17
- try {
18
- decodedPath = decodeURIComponent(pathPart);
19
- } catch {}
20
- if (decodedPath.includes("\0")) return false;
21
- return pathPart.startsWith("@fs/") || pathPart.startsWith("@id/") || pathPart.startsWith("assets/") || pathPart.startsWith("virtual:") || /^__[\w.-]+\.css$/i.test(pathPart) || /^[\w.-]+\.css$/i.test(pathPart);
22
- }
23
- return html.replace(/<link\b(?=[^>]*\brel=(["'])stylesheet\1)[^>]*\bhref=(["'])(.*?)\2[^>]*>/gi, (tag, _relQuote, _hrefQuote, href) => shouldKeepHref(href) ? tag : "");
24
- }
25
- //#endregion
26
- //#region src/runtime/server/dev-stylesheet-links.ts
27
- var dev_stylesheet_links_default = defineNitroPlugin((nitroApp) => {
28
- nitroApp.hooks.hook("render:response", (response) => {
29
- if (typeof response?.body !== "string" || !response.body.includes("<link")) return;
30
- response.body = sanitizeNuxtDevStylesheetLinks(response.body, devAssetBase);
31
- });
32
- });
33
- //#endregion
34
- export { dev_stylesheet_links_default as default };