@vizejs/vite-plugin-musea 0.239.0 → 0.241.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/{gallery-kaxHo2Kt.mjs → gallery-DIBlUrB6.mjs} +2 -2
- package/dist/{gallery-kaxHo2Kt.mjs.map → gallery-DIBlUrB6.mjs.map} +1 -1
- package/dist/index.d.mts +0 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +364 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as createDevSessionToken, d as resolveInside, f as resolveInsideAny, h as validateDevApiRequest, i as generateGalleryScript, l as decodeUrlComponent, m as serializeScriptValue, n as generateGalleryModule, o as HttpError, p as resolveUrlPathInside, r as generateGalleryBody, s as collectRequestBody, u as parseJsonBody } from "./gallery-DIBlUrB6.mjs";
|
|
2
2
|
import { i as MuseaVrtRunner, n as generateVrtJsonReport, r as generateVrtReport } from "./vrt-Cv1PK1EF.mjs";
|
|
3
3
|
import { t as MuseaA11yRunner } from "./a11y-62l8G1tr.mjs";
|
|
4
4
|
import { n as writeArtFile, t as generateArtFile } from "./autogen-Blm3Qy_O.mjs";
|
|
@@ -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("/")}`);
|
|
@@ -1255,7 +1257,7 @@ async function tryLoadSourceGalleryHtml(devServer, url, basePath, devSessionToke
|
|
|
1255
1257
|
return devServer.transformIndexHtml(url, html);
|
|
1256
1258
|
}
|
|
1257
1259
|
async function generateFallbackGalleryHtml(basePath, devSessionToken, themeConfig) {
|
|
1258
|
-
const { generateGalleryHtml } = await import("./gallery-
|
|
1260
|
+
const { generateGalleryHtml } = await import("./gallery-DIBlUrB6.mjs").then((n) => n.t);
|
|
1259
1261
|
return generateGalleryHtml(basePath, devSessionToken, themeConfig);
|
|
1260
1262
|
}
|
|
1261
1263
|
async function serveGalleryAsset(galleryDistDir, requestUrl, res) {
|
|
@@ -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,334 @@ 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 html = injectStaticGlobals(generateStaticFallbackGalleryHtml(ctx.basePath), ctx, payload);
|
|
3087
|
+
emitFile({
|
|
3088
|
+
type: "asset",
|
|
3089
|
+
fileName: joinFileName(staticRoot, "index.html"),
|
|
3090
|
+
source: html
|
|
3091
|
+
});
|
|
3092
|
+
return;
|
|
3093
|
+
}
|
|
3094
|
+
for (const filePath of await collectFiles(galleryDir)) {
|
|
3095
|
+
const relative = path.relative(galleryDir, filePath).split(path.sep).join("/");
|
|
3096
|
+
const target = joinFileName(staticRoot, relative);
|
|
3097
|
+
const content = await fs.promises.readFile(filePath);
|
|
3098
|
+
if (relative === "index.html") emitFile({
|
|
3099
|
+
type: "asset",
|
|
3100
|
+
fileName: target,
|
|
3101
|
+
source: rewriteGalleryBase(injectStaticGlobals(content.toString("utf-8"), ctx, payload), ctx.basePath)
|
|
3102
|
+
});
|
|
3103
|
+
else emitFile({
|
|
3104
|
+
type: "asset",
|
|
3105
|
+
fileName: target,
|
|
3106
|
+
source: content
|
|
3107
|
+
});
|
|
3108
|
+
}
|
|
3109
|
+
if (payload.arts.length === 0) return;
|
|
3110
|
+
}
|
|
3111
|
+
function generateStaticFallbackGalleryHtml(basePath) {
|
|
3112
|
+
return `<!DOCTYPE html>
|
|
3113
|
+
<html lang="en">
|
|
3114
|
+
<head>
|
|
3115
|
+
<meta charset="UTF-8">
|
|
3116
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
3117
|
+
<title>Musea - Component Gallery</title>
|
|
3118
|
+
<style>html,body{min-height:100%;margin:0}body{font-family:system-ui,sans-serif}</style>
|
|
3119
|
+
</head>
|
|
3120
|
+
<body>${generateGalleryBody(basePath)}
|
|
3121
|
+
|
|
3122
|
+
<script type="module">${generateGalleryScript(basePath)}
|
|
3123
|
+
<\/script>
|
|
3124
|
+
</body>
|
|
3125
|
+
</html>`;
|
|
3126
|
+
}
|
|
3127
|
+
function emitPreviewHtml(emitFile, staticRoot, runtimeFileName, basePath, payload, artFiles) {
|
|
3128
|
+
const previewDir = joinFileName(staticRoot, "preview");
|
|
3129
|
+
const runtimeUrl = relativeUrl(previewDir, runtimeFileName);
|
|
3130
|
+
for (const art of artFiles.values()) for (const variant of art.variants) {
|
|
3131
|
+
const id = staticPreviewId(art.path, variant.name);
|
|
3132
|
+
const html = generateStaticPreviewHtml(art, variant.name, id, basePath, runtimeUrl);
|
|
3133
|
+
emitFile({
|
|
3134
|
+
type: "asset",
|
|
3135
|
+
fileName: joinFileName(previewDir, `${id}.html`),
|
|
3136
|
+
source: html
|
|
3137
|
+
});
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
function generateStaticPreviewHtml(art, variantName, previewId, basePath, runtimeUrl) {
|
|
3141
|
+
return `<!DOCTYPE html>
|
|
3142
|
+
<html lang="en">
|
|
3143
|
+
<head>
|
|
3144
|
+
<meta charset="UTF-8">
|
|
3145
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
3146
|
+
<title>${escapeHtml(art.metadata.title)} - ${escapeHtml(variantName)}</title>
|
|
3147
|
+
<script>window.__MUSEA_BASE_PATH__=${serializeScriptValue(basePath)};<\/script>
|
|
3148
|
+
<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>
|
|
3149
|
+
</head>
|
|
3150
|
+
<body>
|
|
3151
|
+
<div id="app" class="musea-variant" data-art="${escapeHtml(art.path)}" data-variant="${escapeHtml(variantName)}">
|
|
3152
|
+
<div class="musea-loading">Loading component...</div>
|
|
3153
|
+
</div>
|
|
3154
|
+
<script type="module">
|
|
3155
|
+
import { loadMuseaPreview } from ${JSON.stringify(runtimeUrl)};
|
|
3156
|
+
loadMuseaPreview(${JSON.stringify(previewId)}).catch((error) => {
|
|
3157
|
+
const el = document.getElementById("app");
|
|
3158
|
+
if (el) el.textContent = error instanceof Error ? error.message : String(error);
|
|
3159
|
+
});
|
|
3160
|
+
<\/script>
|
|
3161
|
+
</body>
|
|
3162
|
+
</html>`;
|
|
3163
|
+
}
|
|
3164
|
+
function injectStaticGlobals(html, ctx, payload) {
|
|
3165
|
+
const themeScript = ctx.themeConfig ? `window.__MUSEA_THEME_CONFIG__=${serializeScriptValue(ctx.themeConfig)};` : "";
|
|
3166
|
+
const script = `<script>window.__MUSEA_BASE_PATH__=${serializeScriptValue(ctx.basePath)};window.__MUSEA_STATIC__=true;window.__MUSEA_STATIC_PREVIEWS__=${serializeScriptValue(payload.previews)};${themeScript}<\/script>`;
|
|
3167
|
+
return html.includes("</head>") ? html.replace("</head>", `${script}</head>`) : `${script}${html}`;
|
|
3168
|
+
}
|
|
3169
|
+
function rewriteGalleryBase(html, basePath) {
|
|
3170
|
+
return html.replaceAll("/__musea__/", `${basePath.replace(/\/?$/, "/")}`);
|
|
3171
|
+
}
|
|
3172
|
+
function emitRootRedirect(emitFile, staticRoot, basePath) {
|
|
3173
|
+
if (!staticRoot) return;
|
|
3174
|
+
const target = joinUrlPath(basePath, "");
|
|
3175
|
+
emitFile({
|
|
3176
|
+
type: "asset",
|
|
3177
|
+
fileName: "index.html",
|
|
3178
|
+
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>`
|
|
3179
|
+
});
|
|
3180
|
+
}
|
|
3181
|
+
async function emitAxeVendor(emitFile, staticRoot) {
|
|
3182
|
+
try {
|
|
3183
|
+
const axePath = createRequire(import.meta.url).resolve("axe-core/axe.min.js");
|
|
3184
|
+
const source = await fs.promises.readFile(axePath);
|
|
3185
|
+
emitFile({
|
|
3186
|
+
type: "asset",
|
|
3187
|
+
fileName: joinFileName(staticRoot, "vendor/axe-core.min.js"),
|
|
3188
|
+
source
|
|
3189
|
+
});
|
|
3190
|
+
} catch {}
|
|
3191
|
+
}
|
|
3192
|
+
function resolveGalleryDistDir() {
|
|
3193
|
+
return [path.join(moduleDir, "gallery"), path.resolve(moduleDir, "../dist/gallery")].find((candidate) => fs.existsSync(path.join(candidate, "index.html"))) ?? null;
|
|
3194
|
+
}
|
|
3195
|
+
async function collectFiles(dir) {
|
|
3196
|
+
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
3197
|
+
const files = [];
|
|
3198
|
+
for (const entry of entries) {
|
|
3199
|
+
const filePath = path.join(dir, entry.name);
|
|
3200
|
+
if (entry.isDirectory()) files.push(...await collectFiles(filePath));
|
|
3201
|
+
else files.push(filePath);
|
|
3202
|
+
}
|
|
3203
|
+
return files;
|
|
3204
|
+
}
|
|
3205
|
+
function staticRootFromBasePath(basePath) {
|
|
3206
|
+
return basePath.replace(/^\/+|\/+$/g, "");
|
|
3207
|
+
}
|
|
3208
|
+
function joinFileName(...parts) {
|
|
3209
|
+
return parts.filter(Boolean).join("/");
|
|
3210
|
+
}
|
|
3211
|
+
function relativeUrl(fromDir, toFile) {
|
|
3212
|
+
const relative = path.posix.relative(fromDir || ".", toFile);
|
|
3213
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
3214
|
+
}
|
|
3215
|
+
//#endregion
|
|
2895
3216
|
//#region src/plugin/index.ts
|
|
3217
|
+
const require = createRequire(import.meta.url);
|
|
3218
|
+
function resolveVueRuntimeCompiler() {
|
|
3219
|
+
try {
|
|
3220
|
+
return require.resolve("vue/dist/vue.esm-bundler.js");
|
|
3221
|
+
} catch {
|
|
3222
|
+
return "vue/dist/vue.esm-bundler.js";
|
|
3223
|
+
}
|
|
3224
|
+
}
|
|
2896
3225
|
function extractArtTagAttributes(source) {
|
|
2897
3226
|
const artTagMatch = source.match(/<art\b([\s\S]*?)>/i);
|
|
2898
3227
|
if (!artTagMatch) return {};
|
|
@@ -2928,9 +3257,6 @@ function extractStyleBlocks(source) {
|
|
|
2928
3257
|
}
|
|
2929
3258
|
return styles;
|
|
2930
3259
|
}
|
|
2931
|
-
/**
|
|
2932
|
-
* Create Musea Vite plugin.
|
|
2933
|
-
*/
|
|
2934
3260
|
function musea(options = {}) {
|
|
2935
3261
|
let include = options.include ?? ["**/*.art.vue"];
|
|
2936
3262
|
let exclude = options.exclude ?? ["node_modules/**", "dist/**"];
|
|
@@ -2962,6 +3288,8 @@ function musea(options = {}) {
|
|
|
2962
3288
|
getServer: () => server,
|
|
2963
3289
|
processArtFile
|
|
2964
3290
|
};
|
|
3291
|
+
const virtualResolveId = createResolveId(virtualState);
|
|
3292
|
+
const virtualLoad = createLoad(virtualState);
|
|
2965
3293
|
const mainPlugin = {
|
|
2966
3294
|
name: "vite-plugin-musea",
|
|
2967
3295
|
enforce: "pre",
|
|
@@ -2969,7 +3297,10 @@ function musea(options = {}) {
|
|
|
2969
3297
|
return shouldApplyMuseaPlugin(env);
|
|
2970
3298
|
},
|
|
2971
3299
|
config() {
|
|
2972
|
-
return {
|
|
3300
|
+
return {
|
|
3301
|
+
resolve: { alias: { vue: resolveVueRuntimeCompiler() } },
|
|
3302
|
+
...isMuseaStaticBuild() ? museaStaticBuildConfig() : {}
|
|
3303
|
+
};
|
|
2973
3304
|
},
|
|
2974
3305
|
configResolved(resolvedConfig) {
|
|
2975
3306
|
config = resolvedConfig;
|
|
@@ -3067,8 +3398,26 @@ function musea(options = {}) {
|
|
|
3067
3398
|
for (const file of files) await processArtFile(file);
|
|
3068
3399
|
if (storybookCompat) await generateStorybookFiles(artFiles, config.root, storybookOutDir);
|
|
3069
3400
|
},
|
|
3070
|
-
resolveId
|
|
3071
|
-
|
|
3401
|
+
resolveId(id) {
|
|
3402
|
+
return resolveStaticRuntimeId(id) ?? virtualResolveId(id);
|
|
3403
|
+
},
|
|
3404
|
+
load(id) {
|
|
3405
|
+
return loadStaticRuntimeModule(id, artFiles) ?? virtualLoad(id);
|
|
3406
|
+
},
|
|
3407
|
+
async generateBundle(_options, bundle) {
|
|
3408
|
+
if (!isMuseaStaticBuild()) return;
|
|
3409
|
+
await emitStaticGallery((asset) => void this.emitFile(asset), bundle, {
|
|
3410
|
+
config,
|
|
3411
|
+
artFiles,
|
|
3412
|
+
scanRoots,
|
|
3413
|
+
tokensPath,
|
|
3414
|
+
basePath,
|
|
3415
|
+
resolvedPreviewCss,
|
|
3416
|
+
resolvedPreviewSetup,
|
|
3417
|
+
devSessionToken,
|
|
3418
|
+
themeConfig
|
|
3419
|
+
});
|
|
3420
|
+
},
|
|
3072
3421
|
async transform(code, id) {
|
|
3073
3422
|
if (!id.includes("?musea-virtual")) return null;
|
|
3074
3423
|
if (!id.includes("musea-art:") && !id.includes("\0musea:")) return null;
|