@vizejs/vite-plugin-musea 0.238.0 → 0.240.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/gallery/assets/{MonacoEditor-C3CE861I.js → MonacoEditor-D6vHGjOV.js} +2 -2
- package/dist/gallery/assets/{cssMode-BXq0Ju6p.js → cssMode-COwrxII5.js} +1 -1
- package/dist/gallery/assets/{editor.api2-BXu2DGoP.js → editor.api2-CJZ9tF6K.js} +1 -1
- package/dist/gallery/assets/{editor.main-vYjaQbj5.js → editor.main-Dt6-6pas.js} +2 -2
- package/dist/gallery/assets/{freemarker2-DncPC0Th.js → freemarker2-Dnb1g0Jo.js} +1 -1
- package/dist/gallery/assets/{handlebars-DPsxWCvQ.js → handlebars-DOmT_A6M.js} +1 -1
- package/dist/gallery/assets/{html-ZcHv66DP.js → html-Qempe7xt.js} +1 -1
- package/dist/gallery/assets/{htmlMode-B8uj_Bj4.js → htmlMode-CKgIR73L.js} +1 -1
- package/dist/gallery/assets/{index-S3a1Kwf3.js → index-Dtsku8dI.js} +25 -25
- package/dist/gallery/assets/{javascript-XXTccPPJ.js → javascript-o8yJHIsv.js} +1 -1
- package/dist/gallery/assets/{jsonMode-Dklq6Auq.js → jsonMode-DDj5uiry.js} +1 -1
- package/dist/gallery/assets/{liquid-0zEVGu7o.js → liquid-GihPC2aI.js} +1 -1
- package/dist/gallery/assets/{lspLanguageFeatures-B3Kfl_eX.js → lspLanguageFeatures-Cj9PuIZx.js} +1 -1
- package/dist/gallery/assets/{mdx-DW0gwcL4.js → mdx-B0KQLOVD.js} +1 -1
- package/dist/gallery/assets/{monaco.contribution-CUl8_Iy6.js → monaco.contribution-BUitKtul.js} +2 -2
- package/dist/gallery/assets/{python-BRiJ2uVF.js → python-DaeXews5.js} +1 -1
- package/dist/gallery/assets/{razor-BmWAdP4c.js → razor-D7eowHXw.js} +1 -1
- package/dist/gallery/assets/{tsMode-BxWrfOgv.js → tsMode-DAcic1g_.js} +1 -1
- package/dist/gallery/assets/{typescript-CDxC4zQ3.js → typescript-DZzujlOz.js} +1 -1
- package/dist/gallery/assets/{workers-BulAypKc.js → workers-M0x9Vvdl.js} +1 -1
- package/dist/gallery/assets/{xml-C7fAmWkq.js → xml-CaKMy0Ek.js} +1 -1
- package/dist/gallery/assets/{yaml-BTbQA6Bq.js → yaml-Cop9p_yY.js} +1 -1
- package/dist/gallery/index.html +1 -1
- package/dist/index.d.mts +0 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +347 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import { transformWithEsbuild } from "vite";
|
|
|
7
7
|
import fs from "node:fs";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import { vizeConfigStore } from "@vizejs/vite-plugin";
|
|
10
|
+
import crypto from "node:crypto";
|
|
10
11
|
import { fileURLToPath } from "node:url";
|
|
11
12
|
//#region src/native-loader.ts
|
|
12
13
|
/**
|
|
@@ -808,7 +809,8 @@ function __museaInitAddons(container, variantName, extraCaptureEvents = []) {
|
|
|
808
809
|
// Dynamically load axe-core from local vendor route if not already loaded
|
|
809
810
|
if (!window.axe) {
|
|
810
811
|
const script = document.createElement('script');
|
|
811
|
-
const _basePath =
|
|
812
|
+
const _basePath = window.__MUSEA_BASE_PATH__
|
|
813
|
+
|| location.pathname.replace(/\\/preview(?:\\/[^/]+\\.html)?$/, '');
|
|
812
814
|
script.src = _basePath + '/vendor/axe-core.min.js';
|
|
813
815
|
await new Promise((resolve, reject) => {
|
|
814
816
|
script.onload = resolve;
|
|
@@ -1217,7 +1219,7 @@ mount();
|
|
|
1217
1219
|
}
|
|
1218
1220
|
//#endregion
|
|
1219
1221
|
//#region src/server-middleware.ts
|
|
1220
|
-
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
1222
|
+
const moduleDir$1 = path.dirname(fileURLToPath(import.meta.url));
|
|
1221
1223
|
const galleryAssetMimeTypes = {
|
|
1222
1224
|
".js": "application/javascript",
|
|
1223
1225
|
".css": "text/css",
|
|
@@ -1227,11 +1229,11 @@ const galleryAssetMimeTypes = {
|
|
|
1227
1229
|
".woff2": "font/woff2",
|
|
1228
1230
|
".woff": "font/woff"
|
|
1229
1231
|
};
|
|
1230
|
-
function resolveGalleryDistDir() {
|
|
1231
|
-
return path.resolve(moduleDir, "gallery");
|
|
1232
|
+
function resolveGalleryDistDir$1() {
|
|
1233
|
+
return path.resolve(moduleDir$1, "gallery");
|
|
1232
1234
|
}
|
|
1233
1235
|
function resolveGallerySourceDir() {
|
|
1234
|
-
return path.resolve(moduleDir, "../gallery");
|
|
1236
|
+
return path.resolve(moduleDir$1, "../gallery");
|
|
1235
1237
|
}
|
|
1236
1238
|
function toViteFsPath(filePath) {
|
|
1237
1239
|
return encodeURI(`/@fs${filePath.split(path.sep).join("/")}`);
|
|
@@ -1293,7 +1295,7 @@ function registerMiddleware(devServer, ctx) {
|
|
|
1293
1295
|
devServer.middlewares.use(basePath, async (req, res, next) => {
|
|
1294
1296
|
const url = req.url || "/";
|
|
1295
1297
|
if (url === "/" || url === "/index.html" || url.startsWith("/tokens") || url.startsWith("/component/") || url.startsWith("/tests")) {
|
|
1296
|
-
const galleryDistDir = resolveGalleryDistDir();
|
|
1298
|
+
const galleryDistDir = resolveGalleryDistDir$1();
|
|
1297
1299
|
const indexHtmlPath = path.join(galleryDistDir, "index.html");
|
|
1298
1300
|
try {
|
|
1299
1301
|
await fs.promises.access(indexHtmlPath);
|
|
@@ -1316,7 +1318,7 @@ function registerMiddleware(devServer, ctx) {
|
|
|
1316
1318
|
}
|
|
1317
1319
|
}
|
|
1318
1320
|
if (url.startsWith("/assets/")) {
|
|
1319
|
-
if (await serveGalleryAsset(resolveGalleryDistDir(), url, res)) return;
|
|
1321
|
+
if (await serveGalleryAsset(resolveGalleryDistDir$1(), url, res)) return;
|
|
1320
1322
|
}
|
|
1321
1323
|
next();
|
|
1322
1324
|
});
|
|
@@ -2892,7 +2894,319 @@ function watchMuseaArtFiles(watcher, files) {
|
|
|
2892
2894
|
watcher.add(targets);
|
|
2893
2895
|
}
|
|
2894
2896
|
//#endregion
|
|
2897
|
+
//#region src/static-data.ts
|
|
2898
|
+
function staticPreviewId(artPath, variantName) {
|
|
2899
|
+
return crypto.createHash("sha256").update(artPath).update("\0").update(variantName).digest("hex").slice(0, 20);
|
|
2900
|
+
}
|
|
2901
|
+
function joinUrlPath(basePath, ...segments) {
|
|
2902
|
+
return `${basePath === "/" ? "" : basePath.replace(/\/+$/, "")}/${segments.map((segment) => segment.replace(/^\/+|\/+$/g, "")).filter(Boolean).join("/")}`;
|
|
2903
|
+
}
|
|
2904
|
+
async function createStaticGalleryPayload(ctx) {
|
|
2905
|
+
const apiCtx = createApiContext(ctx);
|
|
2906
|
+
const arts = Array.from(ctx.artFiles.values());
|
|
2907
|
+
const previews = {};
|
|
2908
|
+
const details = {};
|
|
2909
|
+
for (const art of arts) {
|
|
2910
|
+
previews[art.path] = {};
|
|
2911
|
+
const a11y = {};
|
|
2912
|
+
for (const variant of art.variants) {
|
|
2913
|
+
const id = staticPreviewId(art.path, variant.name);
|
|
2914
|
+
previews[art.path][variant.name] = joinUrlPath(ctx.basePath, "preview", `${id}.html`);
|
|
2915
|
+
a11y[variant.name] = await captureJson((sendJson, sendError) => {
|
|
2916
|
+
handleArtA11y(apiCtx, artVariantMatch(art.path, variant.name), sendJson, sendError);
|
|
2917
|
+
}, emptyA11y());
|
|
2918
|
+
}
|
|
2919
|
+
details[art.path] = {
|
|
2920
|
+
source: await captureJson((sendJson, sendError) => {
|
|
2921
|
+
return handleArtSource(apiCtx, artMatch(art.path), sendJson, sendError);
|
|
2922
|
+
}, {
|
|
2923
|
+
source: "",
|
|
2924
|
+
path: art.path
|
|
2925
|
+
}),
|
|
2926
|
+
palette: await captureJson((sendJson, sendError) => {
|
|
2927
|
+
return handleArtPalette(apiCtx, artMatch(art.path), sendJson, sendError);
|
|
2928
|
+
}, emptyPalette(art)),
|
|
2929
|
+
analysis: await captureJson((sendJson, sendError) => {
|
|
2930
|
+
return handleArtAnalysis(apiCtx, artMatch(art.path), sendJson, sendError);
|
|
2931
|
+
}, {
|
|
2932
|
+
props: [],
|
|
2933
|
+
emits: []
|
|
2934
|
+
}),
|
|
2935
|
+
docs: await captureJson((sendJson, sendError) => {
|
|
2936
|
+
return handleArtDocs(apiCtx, artMatch(art.path), sendJson, sendError);
|
|
2937
|
+
}, emptyDocs(art)),
|
|
2938
|
+
a11y
|
|
2939
|
+
};
|
|
2940
|
+
}
|
|
2941
|
+
return {
|
|
2942
|
+
arts,
|
|
2943
|
+
previews,
|
|
2944
|
+
details,
|
|
2945
|
+
tokens: await captureJson((sendJson) => handleTokensGet(apiCtx, sendJson), emptyTokens()),
|
|
2946
|
+
tokenUsage: await captureJson((sendJson) => handleTokensUsage(apiCtx, sendJson), {})
|
|
2947
|
+
};
|
|
2948
|
+
}
|
|
2949
|
+
function createApiContext(ctx) {
|
|
2950
|
+
return {
|
|
2951
|
+
config: ctx.config,
|
|
2952
|
+
artFiles: ctx.artFiles,
|
|
2953
|
+
scanRoots: ctx.scanRoots,
|
|
2954
|
+
tokensPath: ctx.tokensPath,
|
|
2955
|
+
basePath: ctx.basePath,
|
|
2956
|
+
resolvedPreviewCss: ctx.resolvedPreviewCss,
|
|
2957
|
+
resolvedPreviewSetup: ctx.resolvedPreviewSetup,
|
|
2958
|
+
devSessionToken: ctx.devSessionToken,
|
|
2959
|
+
processArtFile: async (filePath) => {
|
|
2960
|
+
await fs.promises.access(filePath);
|
|
2961
|
+
},
|
|
2962
|
+
getDevServerPort: () => 5173
|
|
2963
|
+
};
|
|
2964
|
+
}
|
|
2965
|
+
async function captureJson(run, fallback) {
|
|
2966
|
+
let captured = fallback;
|
|
2967
|
+
const sendJson = (data) => {
|
|
2968
|
+
captured = data;
|
|
2969
|
+
};
|
|
2970
|
+
const sendError = (message, status = 500) => {
|
|
2971
|
+
captured = {
|
|
2972
|
+
error: message,
|
|
2973
|
+
status
|
|
2974
|
+
};
|
|
2975
|
+
};
|
|
2976
|
+
await run(sendJson, sendError);
|
|
2977
|
+
return captured;
|
|
2978
|
+
}
|
|
2979
|
+
function artMatch(artPath) {
|
|
2980
|
+
return ["", encodeURIComponent(artPath)];
|
|
2981
|
+
}
|
|
2982
|
+
function artVariantMatch(artPath, variantName) {
|
|
2983
|
+
return [
|
|
2984
|
+
"",
|
|
2985
|
+
encodeURIComponent(artPath),
|
|
2986
|
+
encodeURIComponent(variantName)
|
|
2987
|
+
];
|
|
2988
|
+
}
|
|
2989
|
+
function emptyPalette(art) {
|
|
2990
|
+
return {
|
|
2991
|
+
title: art.metadata.title,
|
|
2992
|
+
controls: [],
|
|
2993
|
+
groups: [],
|
|
2994
|
+
json: "{}",
|
|
2995
|
+
typescript: ""
|
|
2996
|
+
};
|
|
2997
|
+
}
|
|
2998
|
+
function emptyDocs(art) {
|
|
2999
|
+
return {
|
|
3000
|
+
markdown: "",
|
|
3001
|
+
title: art.metadata.title,
|
|
3002
|
+
variant_count: art.variants.length
|
|
3003
|
+
};
|
|
3004
|
+
}
|
|
3005
|
+
function emptyA11y() {
|
|
3006
|
+
return {
|
|
3007
|
+
violations: [],
|
|
3008
|
+
passes: 0,
|
|
3009
|
+
incomplete: 0
|
|
3010
|
+
};
|
|
3011
|
+
}
|
|
3012
|
+
function emptyTokens() {
|
|
3013
|
+
return {
|
|
3014
|
+
categories: [],
|
|
3015
|
+
tokenMap: {},
|
|
3016
|
+
meta: {
|
|
3017
|
+
filePath: "",
|
|
3018
|
+
tokenCount: 0,
|
|
3019
|
+
primitiveCount: 0,
|
|
3020
|
+
semanticCount: 0
|
|
3021
|
+
}
|
|
3022
|
+
};
|
|
3023
|
+
}
|
|
3024
|
+
//#endregion
|
|
3025
|
+
//#region src/static-export.ts
|
|
3026
|
+
const MUSEA_STATIC_BUILD_ENV = "VIZE_MUSEA_STATIC_BUILD";
|
|
3027
|
+
const VIRTUAL_STATIC_RUNTIME = "virtual:musea-static-runtime";
|
|
3028
|
+
const RESOLVED_STATIC_RUNTIME = "\0musea-static-runtime";
|
|
3029
|
+
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
3030
|
+
function isMuseaStaticBuild() {
|
|
3031
|
+
return process.env[MUSEA_STATIC_BUILD_ENV] === "1";
|
|
3032
|
+
}
|
|
3033
|
+
function museaStaticBuildConfig() {
|
|
3034
|
+
return { build: { rollupOptions: { input: { "musea-static-runtime": VIRTUAL_STATIC_RUNTIME } } } };
|
|
3035
|
+
}
|
|
3036
|
+
function resolveStaticRuntimeId(id) {
|
|
3037
|
+
return id === "virtual:musea-static-runtime" ? RESOLVED_STATIC_RUNTIME : null;
|
|
3038
|
+
}
|
|
3039
|
+
function loadStaticRuntimeModule(id, artFiles) {
|
|
3040
|
+
if (id !== RESOLVED_STATIC_RUNTIME) return null;
|
|
3041
|
+
return `
|
|
3042
|
+
const loaders = { ${Array.from(artFiles.values()).flatMap((art) => art.variants.map((variant) => {
|
|
3043
|
+
const key = staticPreviewId(art.path, variant.name);
|
|
3044
|
+
const moduleId = `virtual:musea-preview:${art.path}:${variant.name}`;
|
|
3045
|
+
return `${JSON.stringify(key)}: () => import(${JSON.stringify(moduleId)})`;
|
|
3046
|
+
})).join(",\n")} };
|
|
3047
|
+
|
|
3048
|
+
export async function loadMuseaPreview(id) {
|
|
3049
|
+
const load = loaders[id];
|
|
3050
|
+
if (!load) throw new Error("Musea preview not found: " + id);
|
|
3051
|
+
await load();
|
|
3052
|
+
}
|
|
3053
|
+
|
|
3054
|
+
if (typeof window !== "undefined") {
|
|
3055
|
+
window.__MUSEA_LOAD_PREVIEW__ = loadMuseaPreview;
|
|
3056
|
+
}
|
|
3057
|
+
`;
|
|
3058
|
+
}
|
|
3059
|
+
async function emitStaticGallery(emitFile, bundle, ctx) {
|
|
3060
|
+
const runtimeFileName = findRuntimeFileName(bundle);
|
|
3061
|
+
if (!runtimeFileName) throw new Error("musea static build could not find its generated runtime entry");
|
|
3062
|
+
const payload = await createStaticGalleryPayload(ctx);
|
|
3063
|
+
const staticRoot = staticRootFromBasePath(ctx.basePath);
|
|
3064
|
+
await emitGalleryShell(emitFile, staticRoot, ctx, payload);
|
|
3065
|
+
emitFile({
|
|
3066
|
+
type: "asset",
|
|
3067
|
+
fileName: joinFileName(staticRoot, "api", "static.json"),
|
|
3068
|
+
source: JSON.stringify(payload, null, 2)
|
|
3069
|
+
});
|
|
3070
|
+
emitFile({
|
|
3071
|
+
type: "asset",
|
|
3072
|
+
fileName: joinFileName(staticRoot, "api", "arts"),
|
|
3073
|
+
source: JSON.stringify(payload.arts, null, 2)
|
|
3074
|
+
});
|
|
3075
|
+
await emitAxeVendor(emitFile, staticRoot);
|
|
3076
|
+
emitPreviewHtml(emitFile, staticRoot, runtimeFileName, ctx.basePath, payload, ctx.artFiles);
|
|
3077
|
+
emitRootRedirect(emitFile, staticRoot, ctx.basePath);
|
|
3078
|
+
}
|
|
3079
|
+
function findRuntimeFileName(bundle) {
|
|
3080
|
+
for (const item of Object.values(bundle)) if (item.type === "chunk" && item.name === "musea-static-runtime") return item.fileName;
|
|
3081
|
+
return null;
|
|
3082
|
+
}
|
|
3083
|
+
async function emitGalleryShell(emitFile, staticRoot, ctx, payload) {
|
|
3084
|
+
const galleryDir = resolveGalleryDistDir();
|
|
3085
|
+
if (!galleryDir) {
|
|
3086
|
+
const { generateGalleryHtml } = await import("./gallery-kaxHo2Kt.mjs").then((n) => n.t);
|
|
3087
|
+
const html = injectStaticGlobals(generateGalleryHtml(ctx.basePath, "", ctx.themeConfig), ctx, payload);
|
|
3088
|
+
emitFile({
|
|
3089
|
+
type: "asset",
|
|
3090
|
+
fileName: joinFileName(staticRoot, "index.html"),
|
|
3091
|
+
source: html
|
|
3092
|
+
});
|
|
3093
|
+
return;
|
|
3094
|
+
}
|
|
3095
|
+
for (const filePath of await collectFiles(galleryDir)) {
|
|
3096
|
+
const relative = path.relative(galleryDir, filePath).split(path.sep).join("/");
|
|
3097
|
+
const target = joinFileName(staticRoot, relative);
|
|
3098
|
+
const content = await fs.promises.readFile(filePath);
|
|
3099
|
+
if (relative === "index.html") emitFile({
|
|
3100
|
+
type: "asset",
|
|
3101
|
+
fileName: target,
|
|
3102
|
+
source: rewriteGalleryBase(injectStaticGlobals(content.toString("utf-8"), ctx, payload), ctx.basePath)
|
|
3103
|
+
});
|
|
3104
|
+
else emitFile({
|
|
3105
|
+
type: "asset",
|
|
3106
|
+
fileName: target,
|
|
3107
|
+
source: content
|
|
3108
|
+
});
|
|
3109
|
+
}
|
|
3110
|
+
if (payload.arts.length === 0) return;
|
|
3111
|
+
}
|
|
3112
|
+
function emitPreviewHtml(emitFile, staticRoot, runtimeFileName, basePath, payload, artFiles) {
|
|
3113
|
+
const previewDir = joinFileName(staticRoot, "preview");
|
|
3114
|
+
const runtimeUrl = relativeUrl(previewDir, runtimeFileName);
|
|
3115
|
+
for (const art of artFiles.values()) for (const variant of art.variants) {
|
|
3116
|
+
const id = staticPreviewId(art.path, variant.name);
|
|
3117
|
+
const html = generateStaticPreviewHtml(art, variant.name, id, basePath, runtimeUrl);
|
|
3118
|
+
emitFile({
|
|
3119
|
+
type: "asset",
|
|
3120
|
+
fileName: joinFileName(previewDir, `${id}.html`),
|
|
3121
|
+
source: html
|
|
3122
|
+
});
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
function generateStaticPreviewHtml(art, variantName, previewId, basePath, runtimeUrl) {
|
|
3126
|
+
return `<!DOCTYPE html>
|
|
3127
|
+
<html lang="en">
|
|
3128
|
+
<head>
|
|
3129
|
+
<meta charset="UTF-8">
|
|
3130
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
3131
|
+
<title>${escapeHtml(art.metadata.title)} - ${escapeHtml(variantName)}</title>
|
|
3132
|
+
<script>window.__MUSEA_BASE_PATH__=${serializeScriptValue(basePath)};<\/script>
|
|
3133
|
+
<style>html,body{width:100%;height:100%;margin:0}body{font-family:system-ui,sans-serif;background:#fff;padding:1rem;overflow:auto;box-sizing:border-box}.musea-variant{min-height:calc(100vh - 2rem)}.musea-error{color:#dc2626;background:#fef2f2;border:1px solid #fecaca;border-radius:8px;padding:1rem;font-size:.875rem}.musea-loading{color:#6b7280;font-size:.875rem}.musea-bg-checkerboard{background-image:linear-gradient(45deg,#ccc 25%,transparent 25%),linear-gradient(-45deg,#ccc 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#ccc 75%),linear-gradient(-45deg,transparent 75%,#ccc 75%)!important;background-size:20px 20px!important;background-position:0 0,0 10px,10px -10px,-10px 0!important}</style>
|
|
3134
|
+
</head>
|
|
3135
|
+
<body>
|
|
3136
|
+
<div id="app" class="musea-variant" data-art="${escapeHtml(art.path)}" data-variant="${escapeHtml(variantName)}">
|
|
3137
|
+
<div class="musea-loading">Loading component...</div>
|
|
3138
|
+
</div>
|
|
3139
|
+
<script type="module">
|
|
3140
|
+
import { loadMuseaPreview } from ${JSON.stringify(runtimeUrl)};
|
|
3141
|
+
loadMuseaPreview(${JSON.stringify(previewId)}).catch((error) => {
|
|
3142
|
+
const el = document.getElementById("app");
|
|
3143
|
+
if (el) el.textContent = error instanceof Error ? error.message : String(error);
|
|
3144
|
+
});
|
|
3145
|
+
<\/script>
|
|
3146
|
+
</body>
|
|
3147
|
+
</html>`;
|
|
3148
|
+
}
|
|
3149
|
+
function injectStaticGlobals(html, ctx, payload) {
|
|
3150
|
+
const themeScript = ctx.themeConfig ? `window.__MUSEA_THEME_CONFIG__=${serializeScriptValue(ctx.themeConfig)};` : "";
|
|
3151
|
+
const script = `<script>window.__MUSEA_BASE_PATH__=${serializeScriptValue(ctx.basePath)};window.__MUSEA_STATIC__=true;window.__MUSEA_STATIC_PREVIEWS__=${serializeScriptValue(payload.previews)};${themeScript}<\/script>`;
|
|
3152
|
+
return html.includes("</head>") ? html.replace("</head>", `${script}</head>`) : `${script}${html}`;
|
|
3153
|
+
}
|
|
3154
|
+
function rewriteGalleryBase(html, basePath) {
|
|
3155
|
+
return html.replaceAll("/__musea__/", `${basePath.replace(/\/?$/, "/")}`);
|
|
3156
|
+
}
|
|
3157
|
+
function emitRootRedirect(emitFile, staticRoot, basePath) {
|
|
3158
|
+
if (!staticRoot) return;
|
|
3159
|
+
const target = joinUrlPath(basePath, "");
|
|
3160
|
+
emitFile({
|
|
3161
|
+
type: "asset",
|
|
3162
|
+
fileName: "index.html",
|
|
3163
|
+
source: `<!doctype html><meta charset="utf-8"><meta http-equiv="refresh" content="0; url=${target}"><script>location.replace(${JSON.stringify(target)}+location.search+location.hash)<\/script>`
|
|
3164
|
+
});
|
|
3165
|
+
}
|
|
3166
|
+
async function emitAxeVendor(emitFile, staticRoot) {
|
|
3167
|
+
try {
|
|
3168
|
+
const axePath = createRequire(import.meta.url).resolve("axe-core/axe.min.js");
|
|
3169
|
+
const source = await fs.promises.readFile(axePath);
|
|
3170
|
+
emitFile({
|
|
3171
|
+
type: "asset",
|
|
3172
|
+
fileName: joinFileName(staticRoot, "vendor/axe-core.min.js"),
|
|
3173
|
+
source
|
|
3174
|
+
});
|
|
3175
|
+
} catch {}
|
|
3176
|
+
}
|
|
3177
|
+
function resolveGalleryDistDir() {
|
|
3178
|
+
return [path.join(moduleDir, "gallery"), path.resolve(moduleDir, "../dist/gallery")].find((candidate) => fs.existsSync(path.join(candidate, "index.html"))) ?? null;
|
|
3179
|
+
}
|
|
3180
|
+
async function collectFiles(dir) {
|
|
3181
|
+
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
3182
|
+
const files = [];
|
|
3183
|
+
for (const entry of entries) {
|
|
3184
|
+
const filePath = path.join(dir, entry.name);
|
|
3185
|
+
if (entry.isDirectory()) files.push(...await collectFiles(filePath));
|
|
3186
|
+
else files.push(filePath);
|
|
3187
|
+
}
|
|
3188
|
+
return files;
|
|
3189
|
+
}
|
|
3190
|
+
function staticRootFromBasePath(basePath) {
|
|
3191
|
+
return basePath.replace(/^\/+|\/+$/g, "");
|
|
3192
|
+
}
|
|
3193
|
+
function joinFileName(...parts) {
|
|
3194
|
+
return parts.filter(Boolean).join("/");
|
|
3195
|
+
}
|
|
3196
|
+
function relativeUrl(fromDir, toFile) {
|
|
3197
|
+
const relative = path.posix.relative(fromDir || ".", toFile);
|
|
3198
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
3199
|
+
}
|
|
3200
|
+
//#endregion
|
|
2895
3201
|
//#region src/plugin/index.ts
|
|
3202
|
+
const require = createRequire(import.meta.url);
|
|
3203
|
+
function resolveVueRuntimeCompiler() {
|
|
3204
|
+
try {
|
|
3205
|
+
return require.resolve("vue/dist/vue.esm-bundler.js");
|
|
3206
|
+
} catch {
|
|
3207
|
+
return "vue/dist/vue.esm-bundler.js";
|
|
3208
|
+
}
|
|
3209
|
+
}
|
|
2896
3210
|
function extractArtTagAttributes(source) {
|
|
2897
3211
|
const artTagMatch = source.match(/<art\b([\s\S]*?)>/i);
|
|
2898
3212
|
if (!artTagMatch) return {};
|
|
@@ -2928,9 +3242,6 @@ function extractStyleBlocks(source) {
|
|
|
2928
3242
|
}
|
|
2929
3243
|
return styles;
|
|
2930
3244
|
}
|
|
2931
|
-
/**
|
|
2932
|
-
* Create Musea Vite plugin.
|
|
2933
|
-
*/
|
|
2934
3245
|
function musea(options = {}) {
|
|
2935
3246
|
let include = options.include ?? ["**/*.art.vue"];
|
|
2936
3247
|
let exclude = options.exclude ?? ["node_modules/**", "dist/**"];
|
|
@@ -2962,6 +3273,8 @@ function musea(options = {}) {
|
|
|
2962
3273
|
getServer: () => server,
|
|
2963
3274
|
processArtFile
|
|
2964
3275
|
};
|
|
3276
|
+
const virtualResolveId = createResolveId(virtualState);
|
|
3277
|
+
const virtualLoad = createLoad(virtualState);
|
|
2965
3278
|
const mainPlugin = {
|
|
2966
3279
|
name: "vite-plugin-musea",
|
|
2967
3280
|
enforce: "pre",
|
|
@@ -2969,7 +3282,10 @@ function musea(options = {}) {
|
|
|
2969
3282
|
return shouldApplyMuseaPlugin(env);
|
|
2970
3283
|
},
|
|
2971
3284
|
config() {
|
|
2972
|
-
return {
|
|
3285
|
+
return {
|
|
3286
|
+
resolve: { alias: { vue: resolveVueRuntimeCompiler() } },
|
|
3287
|
+
...isMuseaStaticBuild() ? museaStaticBuildConfig() : {}
|
|
3288
|
+
};
|
|
2973
3289
|
},
|
|
2974
3290
|
configResolved(resolvedConfig) {
|
|
2975
3291
|
config = resolvedConfig;
|
|
@@ -3067,8 +3383,26 @@ function musea(options = {}) {
|
|
|
3067
3383
|
for (const file of files) await processArtFile(file);
|
|
3068
3384
|
if (storybookCompat) await generateStorybookFiles(artFiles, config.root, storybookOutDir);
|
|
3069
3385
|
},
|
|
3070
|
-
resolveId
|
|
3071
|
-
|
|
3386
|
+
resolveId(id) {
|
|
3387
|
+
return resolveStaticRuntimeId(id) ?? virtualResolveId(id);
|
|
3388
|
+
},
|
|
3389
|
+
load(id) {
|
|
3390
|
+
return loadStaticRuntimeModule(id, artFiles) ?? virtualLoad(id);
|
|
3391
|
+
},
|
|
3392
|
+
async generateBundle(_options, bundle) {
|
|
3393
|
+
if (!isMuseaStaticBuild()) return;
|
|
3394
|
+
await emitStaticGallery((asset) => void this.emitFile(asset), bundle, {
|
|
3395
|
+
config,
|
|
3396
|
+
artFiles,
|
|
3397
|
+
scanRoots,
|
|
3398
|
+
tokensPath,
|
|
3399
|
+
basePath,
|
|
3400
|
+
resolvedPreviewCss,
|
|
3401
|
+
resolvedPreviewSetup,
|
|
3402
|
+
devSessionToken,
|
|
3403
|
+
themeConfig
|
|
3404
|
+
});
|
|
3405
|
+
},
|
|
3072
3406
|
async transform(code, id) {
|
|
3073
3407
|
if (!id.includes("?musea-virtual")) return null;
|
|
3074
3408
|
if (!id.includes("musea-art:") && !id.includes("\0musea:")) return null;
|