@vizejs/vite-plugin-musea 0.442.0 → 0.454.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/README.md +4 -0
- package/dist/a11y/index.d.mts +1 -1
- package/dist/a11y/index.mjs +1 -1
- package/dist/{a11y-BU5kFNk-.mjs → a11y-DuFu75hl.mjs} +2 -2
- package/dist/{a11y-BU5kFNk-.mjs.map → a11y-DuFu75hl.mjs.map} +1 -1
- package/dist/cli/index.d.mts +3 -2
- package/dist/cli/index.d.mts.map +1 -1
- package/dist/cli/index.mjs +342 -62
- package/dist/cli/index.mjs.map +1 -1
- package/dist/gallery/assets/{MonacoEditor-DpMHG8uG.js → MonacoEditor-CwTBvTDB.js} +2 -2
- package/dist/gallery/assets/{cssMode-BhNXI_iH.js → cssMode-CelCYNbn.js} +1 -1
- package/dist/gallery/assets/{editor.api-pyN3BEOj.js → editor.api-a6jnMk-M.js} +1 -1
- package/dist/gallery/assets/{freemarker2-DDdeAW1l.js → freemarker2-DPAvE--z.js} +1 -1
- package/dist/gallery/assets/{handlebars-d_XLJufS.js → handlebars-BM0wnfAw.js} +1 -1
- package/dist/gallery/assets/{html-pNQuOCmG.js → html-BVxuhUk3.js} +1 -1
- package/dist/gallery/assets/{htmlMode-C9_7c2MZ.js → htmlMode-BMPJCjfA.js} +1 -1
- package/dist/gallery/assets/index-B0odPzN2.css +1 -0
- package/dist/gallery/assets/index-Dc3b2Q04.js +73 -0
- package/dist/gallery/assets/{javascript-V9iW4BoD.js → javascript-DNIAc6FS.js} +1 -1
- package/dist/gallery/assets/{jsonMode-B_jKD9Gd.js → jsonMode-DoEfywTC.js} +1 -1
- package/dist/gallery/assets/{liquid-B5bf9QtA.js → liquid-Bda2NkY3.js} +1 -1
- package/dist/gallery/assets/{lspLanguageFeatures-DF8jpKLy.js → lspLanguageFeatures-Bss0uLYW.js} +1 -1
- package/dist/gallery/assets/{mdx-B6b4WvnG.js → mdx-Cz_EcYUc.js} +1 -1
- package/dist/gallery/assets/{python-C_8hKql2.js → python-DumZpK8Y.js} +1 -1
- package/dist/gallery/assets/{razor-BK6Cp9pQ.js → razor-B35B929n.js} +1 -1
- package/dist/gallery/assets/{register-BcnlSPEw.js → register-CQcuOoyc.js} +2 -2
- package/dist/gallery/assets/{toggleHighContrast-D_Ox9lw9.js → toggleHighContrast-MeFDOtI7.js} +1 -1
- package/dist/gallery/assets/{tsMode-BODHbLZw.js → tsMode-DJXGbiLp.js} +1 -1
- package/dist/gallery/assets/{typescript-CdaOwWaG.js → typescript-CkqSzVk4.js} +1 -1
- package/dist/gallery/assets/{vs-mnsDk7Q8.js → vs-BnuldxuJ.js} +3 -3
- package/dist/gallery/assets/{workers-DYnbCsrm.js → workers-tF2102zJ.js} +1 -1
- package/dist/gallery/assets/{xml-ClcAB6Hf.js → xml-ntbvGSvU.js} +1 -1
- package/dist/gallery/assets/{yaml-mW5XIYQE.js → yaml-s2GvmKpO.js} +1 -1
- package/dist/gallery/index.html +2 -2
- package/dist/{gallery-CLe_4-XW.mjs → gallery-LgVvVp28.mjs} +2 -2
- package/dist/{gallery-CLe_4-XW.mjs.map → gallery-LgVvVp28.mjs.map} +1 -1
- package/dist/{index-BU4-FGUC.d.mts → index-DENP7L3t.d.mts} +2 -2
- package/dist/{index-BU4-FGUC.d.mts.map → index-DENP7L3t.d.mts.map} +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +112 -435
- package/dist/index.mjs.map +1 -1
- package/dist/{options-DCuB_Fpu.mjs → options-DNFbTB_5.mjs} +435 -37
- package/dist/options-DNFbTB_5.mjs.map +1 -0
- package/dist/{template-BgBSA10_.mjs → template-CpNUvZPp.mjs} +5 -3
- package/dist/template-CpNUvZPp.mjs.map +1 -0
- package/dist/{utils-DeMLVlNS.mjs → utils-BloA9YP9.mjs} +35 -29
- package/dist/utils-BloA9YP9.mjs.map +1 -0
- package/dist/{vrt-PuxpRuHa.mjs → vrt-dFU3k2J6.mjs} +49 -6
- package/dist/vrt-dFU3k2J6.mjs.map +1 -0
- package/dist/{vrt-DtcnqPhF.d.mts → vrt-nAWyjDmd.d.mts} +8 -5
- package/dist/vrt-nAWyjDmd.d.mts.map +1 -0
- package/dist/vrt.d.mts +1 -1
- package/dist/vrt.mjs +1 -1
- package/package.json +5 -5
- package/dist/gallery/assets/index-DpZpi0O6.css +0 -1
- package/dist/gallery/assets/index-qkpGvqJF.js +0 -73
- package/dist/options-DCuB_Fpu.mjs.map +0 -1
- package/dist/template-BgBSA10_.mjs.map +0 -1
- package/dist/utils-DeMLVlNS.mjs.map +0 -1
- package/dist/vrt-DtcnqPhF.d.mts.map +0 -1
- package/dist/vrt-PuxpRuHa.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { C as resolveUrlPathInside, E as loadNative, S as resolveTrustedSourcePath, _ as assertVueSourcePath, a as scanArtFiles, b as resolveInside, c as buildThemeConfig, d as createDevSessionToken, f as parseJsonBody, h as assertArtVueSourcePath, i as resolveScanRoots, m as validateDevApiRequest, n as generateStorybookFiles, o as shouldProcess, p as serializeScriptValue, r as matchGlob,
|
|
2
|
-
import { C as
|
|
3
|
-
import { a as generateGalleryGlobalsScript, i as generateDevGlobalsScript, n as generateGalleryScript, r as generateGalleryModule, t as generateGalleryBody } from "./template-
|
|
4
|
-
import { i as MuseaVrtRunner, n as generateVrtJsonReport, r as generateVrtReport
|
|
5
|
-
import { t as MuseaA11yRunner } from "./a11y-
|
|
1
|
+
import { C as resolveUrlPathInside, E as loadNative, S as resolveTrustedSourcePath, _ as assertVueSourcePath, a as scanArtFiles, b as resolveInside, c as buildThemeConfig, d as createDevSessionToken, f as parseJsonBody, h as assertArtVueSourcePath, i as resolveScanRoots, m as validateDevApiRequest, n as generateStorybookFiles, o as shouldProcess, p as serializeScriptValue, r as matchGlob, t as escapeHtml, u as collectRequestBody, v as decodeUrlComponent, w as HttpError } from "./utils-BloA9YP9.mjs";
|
|
2
|
+
import { A as scanTokenUsage, C as handleTokensUsage, D as processStyleDictionary, E as generateTokensMarkdown, F as expandSelfTag, I as resolveArtComponent, L as variantComponentNames, M as generateArtModule, N as parseScriptSetupForArt, O as buildTokenMap, P as rewriteRelativeImportStatement, S as handleTokensUpdate, T as generateTokensHtml, _ as handleArtSource, a as attachArtReportOwner, b as handleTokensDelete, c as rewriteDevGalleryAsset, d as createStaticGalleryPayload, f as joinUrlPath, g as handleArtDocs, h as handleArtAnalysis, i as assertArtReportOwnership, j as parseTokens, k as resolveReferences, l as rewriteGalleryBase, m as sortedArts, o as resolveArtReportTarget, p as staticPreviewId, r as processMuseaArtFile, s as publicBasePathFromViteBase, t as attachMuseaOptions, u as rewriteGalleryTextAssetBase, v as handleArtPalette, w as resolveTokenPreview, x as handleTokensGet, y as handleTokensCreate } from "./options-DNFbTB_5.mjs";
|
|
3
|
+
import { a as generateGalleryGlobalsScript, i as generateDevGlobalsScript, n as generateGalleryScript, r as generateGalleryModule, t as generateGalleryBody } from "./template-CpNUvZPp.mjs";
|
|
4
|
+
import { i as MuseaVrtRunner, n as generateVrtJsonReport, r as generateVrtReport } from "./vrt-dFU3k2J6.mjs";
|
|
5
|
+
import { t as MuseaA11yRunner } from "./a11y-DuFu75hl.mjs";
|
|
6
6
|
import { n as writeArtFile, t as generateArtFile } from "./autogen-B-N0cJbZ.mjs";
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
|
-
import fs from "node:fs";
|
|
8
|
+
import fs, { existsSync } from "node:fs";
|
|
9
9
|
import path from "node:path";
|
|
10
|
-
import { createHash } from "node:crypto";
|
|
11
10
|
import { fileURLToPath } from "node:url";
|
|
12
|
-
import {
|
|
13
|
-
import { VIZE_CONFIG_FILE_ENV, loadConfig } from "@vizejs/vite-plugin";
|
|
11
|
+
import { VIZE_CONFIG_FILE_ENV, loadConfig, resolveViteConfigExport } from "@vizejs/vite-plugin";
|
|
14
12
|
import { getResolvedVizeConfigRegistration } from "@vizejs/vite-plugin/internal/config-bridge";
|
|
15
13
|
import * as vite from "vite";
|
|
14
|
+
import { normalizePath } from "vite";
|
|
16
15
|
//#region src/toolbar.ts
|
|
17
16
|
function normalizeToolbar(toolbar = []) {
|
|
18
17
|
const ids = /* @__PURE__ */ new Set();
|
|
@@ -812,8 +811,36 @@ mount();
|
|
|
812
811
|
`;
|
|
813
812
|
}
|
|
814
813
|
//#endregion
|
|
814
|
+
//#region src/preview-module-id.ts
|
|
815
|
+
/** Keep the final colon delimiter unambiguous while retaining ordinary module IDs. */
|
|
816
|
+
function previewModuleId(artPath, variantName) {
|
|
817
|
+
return `virtual:musea-preview:${artPath}:${variantName.replaceAll("%", "%25").replaceAll(":", "%3A")}`;
|
|
818
|
+
}
|
|
819
|
+
//#endregion
|
|
820
|
+
//#region src/middleware-response.ts
|
|
821
|
+
/** Both transformed and fallback previews keep the same response contract. */
|
|
822
|
+
function sendPreviewModule(response, code) {
|
|
823
|
+
response.setHeader("Content-Type", "application/javascript");
|
|
824
|
+
response.setHeader("Cache-Control", "no-cache");
|
|
825
|
+
response.end(code);
|
|
826
|
+
}
|
|
827
|
+
function sendPreviewError(response, error) {
|
|
828
|
+
response.statusCode = 500;
|
|
829
|
+
response.end(error instanceof Error ? error.message : String(error));
|
|
830
|
+
}
|
|
831
|
+
/** Art fallbacks retain their existing headers and bound generation failures. */
|
|
832
|
+
function sendArtModuleFallback(response, generate) {
|
|
833
|
+
try {
|
|
834
|
+
const code = generate();
|
|
835
|
+
response.setHeader("Content-Type", "application/javascript");
|
|
836
|
+
response.end(code);
|
|
837
|
+
} catch (error) {
|
|
838
|
+
sendPreviewError(response, error);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
//#endregion
|
|
815
842
|
//#region src/server-middleware.ts
|
|
816
|
-
const moduleDir$
|
|
843
|
+
const moduleDir$2 = path.dirname(fileURLToPath(import.meta.url));
|
|
817
844
|
const galleryAssetMimeTypes = {
|
|
818
845
|
".js": "application/javascript",
|
|
819
846
|
".css": "text/css",
|
|
@@ -824,10 +851,10 @@ const galleryAssetMimeTypes = {
|
|
|
824
851
|
".woff": "font/woff"
|
|
825
852
|
};
|
|
826
853
|
function resolveGalleryDistDir$1() {
|
|
827
|
-
return path.resolve(moduleDir$
|
|
854
|
+
return path.resolve(moduleDir$2, "gallery");
|
|
828
855
|
}
|
|
829
856
|
function resolveGallerySourceDir() {
|
|
830
|
-
return path.resolve(moduleDir$
|
|
857
|
+
return path.resolve(moduleDir$2, "../gallery");
|
|
831
858
|
}
|
|
832
859
|
function toViteFsPath(filePath) {
|
|
833
860
|
return encodeURI(`/@fs${filePath.split(path.sep).join("/")}`);
|
|
@@ -847,10 +874,10 @@ async function tryLoadSourceGalleryHtml(devServer, url, basePath, devSessionToke
|
|
|
847
874
|
return devServer.transformIndexHtml(url, html);
|
|
848
875
|
}
|
|
849
876
|
async function generateFallbackGalleryHtml(basePath, devSessionToken, themeConfig, tokenPreviewConfig, toolbar) {
|
|
850
|
-
const { generateGalleryHtml } = await import("./gallery-
|
|
877
|
+
const { generateGalleryHtml } = await import("./gallery-LgVvVp28.mjs");
|
|
851
878
|
return generateGalleryHtml(basePath, devSessionToken, themeConfig, tokenPreviewConfig, toolbar);
|
|
852
879
|
}
|
|
853
|
-
async function serveGalleryAsset(galleryDistDir, requestUrl, res) {
|
|
880
|
+
async function serveGalleryAsset(galleryDistDir, requestUrl, res, basePath = "/__musea__") {
|
|
854
881
|
try {
|
|
855
882
|
const filePath = resolveUrlPathInside(galleryDistDir, requestUrl, "asset path");
|
|
856
883
|
if (!(await fs.promises.stat(filePath)).isFile()) return false;
|
|
@@ -858,7 +885,7 @@ async function serveGalleryAsset(galleryDistDir, requestUrl, res) {
|
|
|
858
885
|
const ext = path.extname(filePath);
|
|
859
886
|
res.setHeader("Content-Type", galleryAssetMimeTypes[ext] || "application/octet-stream");
|
|
860
887
|
res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
|
|
861
|
-
res.end(content);
|
|
888
|
+
res.end(rewriteDevGalleryAsset(content, filePath, basePath));
|
|
862
889
|
return true;
|
|
863
890
|
} catch (error) {
|
|
864
891
|
if (error instanceof HttpError) {
|
|
@@ -878,7 +905,7 @@ function registerMiddleware(devServer, ctx) {
|
|
|
878
905
|
const indexHtmlPath = path.join(galleryDistDir, "index.html");
|
|
879
906
|
try {
|
|
880
907
|
await fs.promises.access(indexHtmlPath);
|
|
881
|
-
let html = await fs.promises.readFile(indexHtmlPath, "utf-8");
|
|
908
|
+
let html = rewriteGalleryBase(await fs.promises.readFile(indexHtmlPath, "utf-8"), basePath);
|
|
882
909
|
html = html.replace("</head>", `<script>${generateDevGlobalsScript(basePath, devSessionToken, themeConfig, tokenPreviewConfig, toolbar)}<\/script></head>`);
|
|
883
910
|
res.setHeader("Content-Type", "text/html");
|
|
884
911
|
res.end(html);
|
|
@@ -897,7 +924,7 @@ function registerMiddleware(devServer, ctx) {
|
|
|
897
924
|
}
|
|
898
925
|
}
|
|
899
926
|
if (url.startsWith("/assets/")) {
|
|
900
|
-
if (await serveGalleryAsset(resolveGalleryDistDir$1(), url, res)) return;
|
|
927
|
+
if (await serveGalleryAsset(resolveGalleryDistDir$1(), url, res, basePath)) return;
|
|
901
928
|
}
|
|
902
929
|
next();
|
|
903
930
|
});
|
|
@@ -934,19 +961,22 @@ function registerMiddleware(devServer, ctx) {
|
|
|
934
961
|
res.end("Variant not found");
|
|
935
962
|
return;
|
|
936
963
|
}
|
|
937
|
-
|
|
964
|
+
let variantComponentName;
|
|
938
965
|
try {
|
|
939
|
-
|
|
966
|
+
variantComponentName = variantComponentNames(art.variants).get(variant.name);
|
|
967
|
+
} catch (error) {
|
|
968
|
+
sendPreviewError(res, error);
|
|
969
|
+
return;
|
|
970
|
+
}
|
|
971
|
+
const moduleCode = generatePreviewModule(art, variantComponentName, variant.name, ctx.resolvedPreviewCss, ctx.resolvedPreviewSetup, 3, ctx.toolbar);
|
|
972
|
+
try {
|
|
973
|
+
const result = await devServer.transformRequest(previewModuleId(artPath, variantName));
|
|
940
974
|
if (result) {
|
|
941
|
-
res
|
|
942
|
-
res.setHeader("Cache-Control", "no-cache");
|
|
943
|
-
res.end(result.code);
|
|
975
|
+
sendPreviewModule(res, result.code);
|
|
944
976
|
return;
|
|
945
977
|
}
|
|
946
978
|
} catch {}
|
|
947
|
-
res
|
|
948
|
-
res.setHeader("Cache-Control", "no-cache");
|
|
949
|
-
res.end(moduleCode);
|
|
979
|
+
sendPreviewModule(res, moduleCode);
|
|
950
980
|
});
|
|
951
981
|
devServer.middlewares.use(`${basePath}/preview`, async (req, res, _next) => {
|
|
952
982
|
const url = new URL(req.url || "", `http://localhost`);
|
|
@@ -1000,407 +1030,19 @@ function registerMiddleware(devServer, ctx) {
|
|
|
1000
1030
|
try {
|
|
1001
1031
|
const virtualId = `virtual:musea-art:${artPath}`;
|
|
1002
1032
|
const result = await devServer.transformRequest(virtualId);
|
|
1003
|
-
if (result)
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
}
|
|
1008
|
-
const moduleCode = generateArtModule(art, artPath, {
|
|
1009
|
-
root: devServer.config.root,
|
|
1010
|
-
scanRoots: ctx.scanRoots
|
|
1011
|
-
});
|
|
1012
|
-
res.setHeader("Content-Type", "application/javascript");
|
|
1013
|
-
res.end(moduleCode);
|
|
1014
|
-
}
|
|
1033
|
+
if (result) sendPreviewModule(res, result.code);
|
|
1034
|
+
else sendArtModuleFallback(res, () => generateArtModule(art, artPath, {
|
|
1035
|
+
root: devServer.config.root,
|
|
1036
|
+
scanRoots: ctx.scanRoots
|
|
1037
|
+
}));
|
|
1015
1038
|
} catch (err) {
|
|
1016
1039
|
console.error("[musea] Failed to transform art module:", err);
|
|
1017
|
-
|
|
1040
|
+
sendArtModuleFallback(res, () => generateArtModule(art, artPath, {
|
|
1018
1041
|
root: devServer.config.root,
|
|
1019
1042
|
scanRoots: ctx.scanRoots
|
|
1020
|
-
});
|
|
1021
|
-
res.setHeader("Content-Type", "application/javascript");
|
|
1022
|
-
res.end(moduleCode);
|
|
1023
|
-
}
|
|
1024
|
-
});
|
|
1025
|
-
}
|
|
1026
|
-
//#endregion
|
|
1027
|
-
//#region src/tokens/generator.ts
|
|
1028
|
-
/**
|
|
1029
|
-
* Token documentation generators for Style Dictionary integration.
|
|
1030
|
-
*
|
|
1031
|
-
* Generates HTML, Markdown, and JSON documentation from parsed token categories,
|
|
1032
|
-
* and provides the main processStyleDictionary orchestrator function.
|
|
1033
|
-
*/
|
|
1034
|
-
const SAFE_CSS_COLOR_PATTERN = /^(?:#[0-9a-fA-F]{3,8}|(?:rgb|hsl)a?\(\s*[-+.\d,%\s/]+\)|(?:oklch|oklab|lab|lch)\(\s*[-+.\d,%\s/]+\))$/;
|
|
1035
|
-
const DANGEROUS_PROTOCOL_PATTERN = /\b(javascript|vbscript):/gi;
|
|
1036
|
-
function escapeTokenText(value) {
|
|
1037
|
-
return escapeHtml(value).replace(DANGEROUS_PROTOCOL_PATTERN, "$1:");
|
|
1038
|
-
}
|
|
1039
|
-
function safeCssColor(value, type) {
|
|
1040
|
-
if (typeof value !== "string") return null;
|
|
1041
|
-
const trimmed = value.trim();
|
|
1042
|
-
return (type === "color" || trimmed.startsWith("#") || trimmed.startsWith("rgb") || trimmed.startsWith("hsl")) && SAFE_CSS_COLOR_PATTERN.test(trimmed) ? trimmed : null;
|
|
1043
|
-
}
|
|
1044
|
-
/**
|
|
1045
|
-
* Generate HTML documentation for tokens.
|
|
1046
|
-
*/
|
|
1047
|
-
function generateTokensHtml(categories) {
|
|
1048
|
-
const renderToken = (name, token) => {
|
|
1049
|
-
const color = safeCssColor(token.value, token.type);
|
|
1050
|
-
return `
|
|
1051
|
-
<div class="token">
|
|
1052
|
-
<div class="token-preview">
|
|
1053
|
-
${color ? `<div class="color-swatch" style="background: ${color}"></div>` : ""}
|
|
1054
|
-
</div>
|
|
1055
|
-
<div class="token-info">
|
|
1056
|
-
<div class="token-name">${escapeTokenText(name)}</div>
|
|
1057
|
-
<div class="token-value">${escapeTokenText(String(token.value))}</div>
|
|
1058
|
-
${token.description ? `<div class="token-description">${escapeTokenText(token.description)}</div>` : ""}
|
|
1059
|
-
</div>
|
|
1060
|
-
</div>
|
|
1061
|
-
`;
|
|
1062
|
-
};
|
|
1063
|
-
const renderCategory = (category, level = 2) => {
|
|
1064
|
-
const heading = `h${Math.min(level, 6)}`;
|
|
1065
|
-
let html = `<${heading}>${escapeTokenText(category.name)}</${heading}>`;
|
|
1066
|
-
html += "<div class=\"tokens-grid\">";
|
|
1067
|
-
for (const [name, token] of Object.entries(category.tokens)) html += renderToken(name, token);
|
|
1068
|
-
html += "</div>";
|
|
1069
|
-
if (category.subcategories) for (const sub of category.subcategories) html += renderCategory(sub, level + 1);
|
|
1070
|
-
return html;
|
|
1071
|
-
};
|
|
1072
|
-
return `<!DOCTYPE html>
|
|
1073
|
-
<html lang="en">
|
|
1074
|
-
<head>
|
|
1075
|
-
<meta charset="UTF-8">
|
|
1076
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
1077
|
-
<title>Design Tokens - Musea</title>
|
|
1078
|
-
<style>
|
|
1079
|
-
:root {
|
|
1080
|
-
--musea-bg: #0d0d0d;
|
|
1081
|
-
--musea-bg-secondary: #1a1815;
|
|
1082
|
-
--musea-text: #e6e9f0;
|
|
1083
|
-
--musea-text-muted: #7b8494;
|
|
1084
|
-
--musea-accent: #a34828;
|
|
1085
|
-
--musea-border: #3a3530;
|
|
1086
|
-
}
|
|
1087
|
-
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
1088
|
-
body {
|
|
1089
|
-
font-family: 'Inter', -apple-system, sans-serif;
|
|
1090
|
-
background: var(--musea-bg);
|
|
1091
|
-
color: var(--musea-text);
|
|
1092
|
-
line-height: 1.6;
|
|
1093
|
-
padding: 2rem;
|
|
1094
|
-
}
|
|
1095
|
-
h1 { margin-bottom: 2rem; color: var(--musea-accent); }
|
|
1096
|
-
h2 { margin: 2rem 0 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--musea-border); }
|
|
1097
|
-
h3, h4, h5, h6 { margin: 1.5rem 0 0.75rem; }
|
|
1098
|
-
.tokens-grid {
|
|
1099
|
-
display: grid;
|
|
1100
|
-
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
|
1101
|
-
gap: 1rem;
|
|
1102
|
-
margin-bottom: 1.5rem;
|
|
1103
|
-
}
|
|
1104
|
-
.token {
|
|
1105
|
-
background: var(--musea-bg-secondary);
|
|
1106
|
-
border: 1px solid var(--musea-border);
|
|
1107
|
-
border-radius: 8px;
|
|
1108
|
-
padding: 1rem;
|
|
1109
|
-
display: flex;
|
|
1110
|
-
gap: 1rem;
|
|
1111
|
-
align-items: center;
|
|
1112
|
-
}
|
|
1113
|
-
.token-preview {
|
|
1114
|
-
flex-shrink: 0;
|
|
1115
|
-
width: 48px;
|
|
1116
|
-
height: 48px;
|
|
1117
|
-
display: flex;
|
|
1118
|
-
align-items: center;
|
|
1119
|
-
justify-content: center;
|
|
1120
|
-
}
|
|
1121
|
-
.color-swatch {
|
|
1122
|
-
width: 48px;
|
|
1123
|
-
height: 48px;
|
|
1124
|
-
border-radius: 8px;
|
|
1125
|
-
border: 1px solid var(--musea-border);
|
|
1126
|
-
}
|
|
1127
|
-
.token-info {
|
|
1128
|
-
flex: 1;
|
|
1129
|
-
min-width: 0;
|
|
1130
|
-
}
|
|
1131
|
-
.token-name {
|
|
1132
|
-
font-weight: 600;
|
|
1133
|
-
font-family: 'JetBrains Mono', monospace;
|
|
1134
|
-
font-size: 0.875rem;
|
|
1135
|
-
}
|
|
1136
|
-
.token-value {
|
|
1137
|
-
color: var(--musea-text-muted);
|
|
1138
|
-
font-family: 'JetBrains Mono', monospace;
|
|
1139
|
-
font-size: 0.75rem;
|
|
1140
|
-
word-break: break-all;
|
|
1141
|
-
}
|
|
1142
|
-
.token-description {
|
|
1143
|
-
color: var(--musea-text-muted);
|
|
1144
|
-
font-size: 0.75rem;
|
|
1145
|
-
margin-top: 0.25rem;
|
|
1146
|
-
}
|
|
1147
|
-
</style>
|
|
1148
|
-
</head>
|
|
1149
|
-
<body>
|
|
1150
|
-
<h1>Design Tokens</h1>
|
|
1151
|
-
${categories.map((cat) => renderCategory(cat)).join("")}
|
|
1152
|
-
</body>
|
|
1153
|
-
</html>`;
|
|
1154
|
-
}
|
|
1155
|
-
/**
|
|
1156
|
-
* Generate Markdown documentation for tokens.
|
|
1157
|
-
*/
|
|
1158
|
-
function generateTokensMarkdown(categories) {
|
|
1159
|
-
return tokenNative().generateDesignTokensMarkdown(categories, (/* @__PURE__ */ new Date()).toISOString());
|
|
1160
|
-
}
|
|
1161
|
-
/**
|
|
1162
|
-
* Style Dictionary plugin for Musea.
|
|
1163
|
-
* Parses tokens and generates documentation in the specified format.
|
|
1164
|
-
*/
|
|
1165
|
-
async function processStyleDictionary(config) {
|
|
1166
|
-
const categories = await parseTokens(config.tokensPath);
|
|
1167
|
-
const outputDir = config.outputDir ?? ".vize/tokens";
|
|
1168
|
-
const outputFormat = config.outputFormat ?? "html";
|
|
1169
|
-
await fs.promises.mkdir(outputDir, { recursive: true });
|
|
1170
|
-
let content;
|
|
1171
|
-
let filename;
|
|
1172
|
-
switch (outputFormat) {
|
|
1173
|
-
case "html":
|
|
1174
|
-
content = generateTokensHtml(categories);
|
|
1175
|
-
filename = "tokens.html";
|
|
1176
|
-
break;
|
|
1177
|
-
case "markdown":
|
|
1178
|
-
content = generateTokensMarkdown(categories);
|
|
1179
|
-
filename = "tokens.md";
|
|
1180
|
-
break;
|
|
1181
|
-
default:
|
|
1182
|
-
content = JSON.stringify({ categories }, null, 2);
|
|
1183
|
-
filename = "tokens.json";
|
|
1184
|
-
}
|
|
1185
|
-
const outputPath = path.join(outputDir, filename);
|
|
1186
|
-
await fs.promises.writeFile(outputPath, content, "utf-8");
|
|
1187
|
-
console.log(`[musea] Generated token documentation: ${outputPath}`);
|
|
1188
|
-
return {
|
|
1189
|
-
categories,
|
|
1190
|
-
metadata: {
|
|
1191
|
-
name: path.basename(config.tokensPath),
|
|
1192
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1043
|
+
}));
|
|
1193
1044
|
}
|
|
1194
|
-
};
|
|
1195
|
-
}
|
|
1196
|
-
//#endregion
|
|
1197
|
-
//#region src/tokens/preview.ts
|
|
1198
|
-
function resolveTokenPreview(input) {
|
|
1199
|
-
const reference = resolveReference(input.token, input.tokenMap);
|
|
1200
|
-
const value = input.token.$resolvedValue ?? reference?.value ?? input.token.value;
|
|
1201
|
-
const candidates = buildCandidates(input.tokenPath, input.token, reference);
|
|
1202
|
-
const kind = resolveCustomKind(candidates, reference?.path, input.config?.rules) ?? inferPreviewKind(candidates, value);
|
|
1203
|
-
return {
|
|
1204
|
-
kind: new Set(input.config?.disabledKinds ?? []).has(kind) ? "generic" : kind,
|
|
1205
|
-
value,
|
|
1206
|
-
tokenPath: input.tokenPath,
|
|
1207
|
-
reference
|
|
1208
|
-
};
|
|
1209
|
-
}
|
|
1210
|
-
function resolveReference(token, tokenMap) {
|
|
1211
|
-
if (!token.$reference) return void 0;
|
|
1212
|
-
const referencedToken = tokenMap?.[token.$reference];
|
|
1213
|
-
return {
|
|
1214
|
-
path: token.$reference,
|
|
1215
|
-
token: referencedToken,
|
|
1216
|
-
value: referencedToken ? referencedToken.$resolvedValue ?? referencedToken.value : void 0
|
|
1217
|
-
};
|
|
1218
|
-
}
|
|
1219
|
-
function buildCandidates(tokenPath, token, reference) {
|
|
1220
|
-
const candidates = [{
|
|
1221
|
-
tokenPath,
|
|
1222
|
-
name: pathName(tokenPath),
|
|
1223
|
-
token
|
|
1224
|
-
}];
|
|
1225
|
-
if (reference?.token) candidates.push({
|
|
1226
|
-
tokenPath: reference.path,
|
|
1227
|
-
name: pathName(reference.path),
|
|
1228
|
-
token: reference.token
|
|
1229
|
-
});
|
|
1230
|
-
return candidates;
|
|
1231
|
-
}
|
|
1232
|
-
function resolveCustomKind(candidates, referencePath, rules) {
|
|
1233
|
-
for (const rule of rules ?? []) if (matchesRule(rule, candidates, referencePath)) return rule.kind;
|
|
1234
|
-
}
|
|
1235
|
-
function matchesRule(rule, candidates, referencePath) {
|
|
1236
|
-
const checks = [];
|
|
1237
|
-
if (rule.type !== void 0) checks.push(candidates.some((candidate) => typeMatches(candidate, rule.type)));
|
|
1238
|
-
if (rule.pathIncludes !== void 0) checks.push(candidates.some((candidate) => includesAny(candidate.tokenPath, rule.pathIncludes)));
|
|
1239
|
-
if (rule.nameIncludes !== void 0) checks.push(candidates.some((candidate) => includesAny(candidate.name, rule.nameIncludes)));
|
|
1240
|
-
if (rule.referencePathIncludes !== void 0) checks.push(referencePath !== void 0 && includesAny(referencePath, rule.referencePathIncludes));
|
|
1241
|
-
return checks.length > 0 && checks.every(Boolean);
|
|
1242
|
-
}
|
|
1243
|
-
function inferPreviewKind(candidates, value) {
|
|
1244
|
-
if (hasType(candidates, ["color"]) || isColorValue(value)) return "color";
|
|
1245
|
-
if (hasType(candidates, ["shadow", "box-shadow"]) || hasSignal(candidates, ["shadow", "box-shadow"])) return "shadow";
|
|
1246
|
-
if (hasType(candidates, [
|
|
1247
|
-
"z-index",
|
|
1248
|
-
"zindex",
|
|
1249
|
-
"zIndex"
|
|
1250
|
-
]) || hasSignal(candidates, [
|
|
1251
|
-
"z-index",
|
|
1252
|
-
"zindex",
|
|
1253
|
-
"stacking-order"
|
|
1254
|
-
])) return "zIndex";
|
|
1255
|
-
if (hasType(candidates, ["opacity"]) || hasSignal(candidates, ["opacity", "alpha"])) return "opacity";
|
|
1256
|
-
if (hasType(candidates, [
|
|
1257
|
-
"border-radius",
|
|
1258
|
-
"borderradius",
|
|
1259
|
-
"radius"
|
|
1260
|
-
]) || hasSignal(candidates, [
|
|
1261
|
-
"border-radius",
|
|
1262
|
-
"borderradius",
|
|
1263
|
-
"radius",
|
|
1264
|
-
"round",
|
|
1265
|
-
"rounded"
|
|
1266
|
-
])) return "radius";
|
|
1267
|
-
if (hasType(candidates, ["letterspacing", "letter-spacing"]) || hasSignal(candidates, [
|
|
1268
|
-
"letter-spacing",
|
|
1269
|
-
"letterspacing",
|
|
1270
|
-
"tracking"
|
|
1271
|
-
])) return "letterSpacing";
|
|
1272
|
-
if (hasType(candidates, ["spacing", "space"]) || hasSignal(candidates, [
|
|
1273
|
-
"spacing",
|
|
1274
|
-
"spasing",
|
|
1275
|
-
"space",
|
|
1276
|
-
"gap",
|
|
1277
|
-
"padding",
|
|
1278
|
-
"margin",
|
|
1279
|
-
"inset"
|
|
1280
|
-
])) return "spacing";
|
|
1281
|
-
if (hasSignal(candidates, [
|
|
1282
|
-
"font-size",
|
|
1283
|
-
"fontsize",
|
|
1284
|
-
"text-size"
|
|
1285
|
-
])) return "fontSize";
|
|
1286
|
-
if (hasType(candidates, ["fontweight", "font-weight"]) || hasSignal(candidates, [
|
|
1287
|
-
"font-weight",
|
|
1288
|
-
"fontweight",
|
|
1289
|
-
"weight"
|
|
1290
|
-
])) return "fontWeight";
|
|
1291
|
-
if (hasType(candidates, ["lineheight", "line-height"]) || hasSignal(candidates, ["line-height", "lineheight"])) return "lineHeight";
|
|
1292
|
-
return "generic";
|
|
1293
|
-
}
|
|
1294
|
-
function hasType(candidates, terms) {
|
|
1295
|
-
return candidates.some((candidate) => typeMatches(candidate, terms));
|
|
1296
|
-
}
|
|
1297
|
-
function hasSignal(candidates, terms) {
|
|
1298
|
-
return candidates.some((candidate) => includesAny(candidate.tokenPath, terms) || includesAny(candidate.name, terms) || candidate.token.type !== void 0 && includesAny(candidate.token.type, terms));
|
|
1299
|
-
}
|
|
1300
|
-
function typeMatches(candidate, expected) {
|
|
1301
|
-
if (!candidate.token.type) return false;
|
|
1302
|
-
return toArray(expected).some((term) => normalize(candidate.token.type) === normalize(term));
|
|
1303
|
-
}
|
|
1304
|
-
function includesAny(value, expected) {
|
|
1305
|
-
const normalizedValue = normalize(value);
|
|
1306
|
-
const compactValue = compact(normalizedValue);
|
|
1307
|
-
return toArray(expected).some((term) => {
|
|
1308
|
-
const normalizedTerm = normalize(term);
|
|
1309
|
-
return normalizedValue.includes(normalizedTerm) || compactValue.includes(compact(normalizedTerm));
|
|
1310
|
-
});
|
|
1311
|
-
}
|
|
1312
|
-
function isColorValue(value) {
|
|
1313
|
-
if (typeof value !== "string") return false;
|
|
1314
|
-
return /^(#|rgb\(|rgba\(|hsl\(|hsla\(|oklch\(|oklab\(|lab\(|lch\(|color\()/i.test(value.trim());
|
|
1315
|
-
}
|
|
1316
|
-
function pathName(tokenPath) {
|
|
1317
|
-
return tokenPath.split(".").at(-1) ?? tokenPath;
|
|
1318
|
-
}
|
|
1319
|
-
function normalize(value) {
|
|
1320
|
-
return value.trim().toLowerCase().replace(/[_\s]+/g, "-");
|
|
1321
|
-
}
|
|
1322
|
-
function compact(value) {
|
|
1323
|
-
return value.replace(/[-.]/g, "");
|
|
1324
|
-
}
|
|
1325
|
-
function toArray(value) {
|
|
1326
|
-
return Array.isArray(value) ? value : [value];
|
|
1327
|
-
}
|
|
1328
|
-
//#endregion
|
|
1329
|
-
//#region src/vrt/report-identity.ts
|
|
1330
|
-
/** Reserve one qualified namespace and compare legacy names on case-insensitive filesystems. */
|
|
1331
|
-
function legacyName(identity) {
|
|
1332
|
-
const basename = path.posix.basename(identity, ".art.vue");
|
|
1333
|
-
return /^[a-z0-9._-]{1,200}$/i.test(basename) && !/^art-[0-9a-f]{64}$/i.test(basename) ? `vrt-${basename}` : void 0;
|
|
1334
|
-
}
|
|
1335
|
-
/** The complete discovered Art set decides collisions, even for a single-Art request. */
|
|
1336
|
-
function resolveArtReportTarget(artPath, artPaths, projectRoot, reportDir) {
|
|
1337
|
-
const identities = Array.from(artPaths, (item) => resolveSnapshotIdentity(item, projectRoot));
|
|
1338
|
-
const identity = resolveSnapshotIdentity(artPath, projectRoot);
|
|
1339
|
-
if (!identities.includes(identity)) throw new Error(`Report Art not found: ${artPath}`);
|
|
1340
|
-
const candidates = identities.map(legacyName);
|
|
1341
|
-
const counts = /* @__PURE__ */ new Map();
|
|
1342
|
-
for (const name of candidates) if (name) counts.set(name.toLowerCase(), (counts.get(name.toLowerCase()) ?? 0) + 1);
|
|
1343
|
-
const names = identities.map((item, index) => {
|
|
1344
|
-
const candidate = candidates[index];
|
|
1345
|
-
const colliding = candidate && counts.get(candidate.toLowerCase()) > 1;
|
|
1346
|
-
return candidate && !colliding ? candidate : `vrt-art-${createHash("sha256").update(JSON.stringify([1, item])).digest("hex")}`;
|
|
1347
1045
|
});
|
|
1348
|
-
if (new Set(names.map((name) => name.toLowerCase())).size !== names.length) throw new Error("Ambiguous VRT report identities");
|
|
1349
|
-
const base = names[identities.indexOf(identity)];
|
|
1350
|
-
return {
|
|
1351
|
-
identity,
|
|
1352
|
-
jsonReportPath: path.join(reportDir, `${base}-report.json`),
|
|
1353
|
-
htmlReportPath: path.join(reportDir, `${base}-report.html`)
|
|
1354
|
-
};
|
|
1355
|
-
}
|
|
1356
|
-
async function existsRegularFile(file) {
|
|
1357
|
-
try {
|
|
1358
|
-
if (!(await lstat(file)).isFile()) throw new Error(`VRT report is not a regular file: ${file}`);
|
|
1359
|
-
return true;
|
|
1360
|
-
} catch (error) {
|
|
1361
|
-
if (error.code === "ENOENT") return false;
|
|
1362
|
-
throw error;
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
/** Fail before capture or writes; legacy adoption requires every recorded result to have this owner. */
|
|
1366
|
-
async function assertArtReportOwnership(target, projectRoot) {
|
|
1367
|
-
const refusal = `Ambiguous VRT report ownership: ${target.jsonReportPath}. Archive or move the existing reports before retrying.`;
|
|
1368
|
-
const names = [path.basename(target.jsonReportPath), path.basename(target.htmlReportPath)];
|
|
1369
|
-
let existingNames;
|
|
1370
|
-
try {
|
|
1371
|
-
existingNames = await readdir(path.dirname(target.jsonReportPath));
|
|
1372
|
-
} catch (error) {
|
|
1373
|
-
if (error.code === "ENOENT") return;
|
|
1374
|
-
throw error;
|
|
1375
|
-
}
|
|
1376
|
-
if (existingNames.some((item) => names.some((name) => item !== name && item.toLowerCase() === name.toLowerCase()))) throw new Error(refusal);
|
|
1377
|
-
const jsonExists = await existsRegularFile(target.jsonReportPath);
|
|
1378
|
-
const htmlExists = await existsRegularFile(target.htmlReportPath);
|
|
1379
|
-
if (!jsonExists && !htmlExists) return;
|
|
1380
|
-
if (!jsonExists) throw new Error(refusal);
|
|
1381
|
-
try {
|
|
1382
|
-
const report = JSON.parse(await readFile(target.jsonReportPath, "utf8"));
|
|
1383
|
-
if (!report || typeof report !== "object" || Array.isArray(report)) throw new Error(refusal);
|
|
1384
|
-
if (Object.hasOwn(report, "reportOwner")) {
|
|
1385
|
-
const owner = report.reportOwner;
|
|
1386
|
-
if (!owner || typeof owner !== "object" || owner.version !== 1 || owner.artIdentity !== target.identity) throw new Error(refusal);
|
|
1387
|
-
} else {
|
|
1388
|
-
const results = report.results;
|
|
1389
|
-
if (!Array.isArray(results) || !results.length || results.some((item) => !item || typeof item !== "object" || typeof item.artPath !== "string" || resolveSnapshotIdentity(item.artPath, projectRoot) !== target.identity)) throw new Error(refusal);
|
|
1390
|
-
}
|
|
1391
|
-
} catch {
|
|
1392
|
-
throw new Error(refusal);
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
/** Keep ownership portable when a report directory moves to another machine. */
|
|
1396
|
-
function attachArtReportOwner(json, target) {
|
|
1397
|
-
return JSON.stringify({
|
|
1398
|
-
...JSON.parse(json),
|
|
1399
|
-
reportOwner: {
|
|
1400
|
-
version: 1,
|
|
1401
|
-
artIdentity: target.identity
|
|
1402
|
-
}
|
|
1403
|
-
}, null, 2);
|
|
1404
1046
|
}
|
|
1405
1047
|
//#endregion
|
|
1406
1048
|
//#region src/api-routes/post-handlers.ts
|
|
@@ -1418,7 +1060,7 @@ function handlePreviewWithProps(ctx, body, res, sendJson, sendError) {
|
|
|
1418
1060
|
sendError("Variant not found", 404);
|
|
1419
1061
|
return;
|
|
1420
1062
|
}
|
|
1421
|
-
const moduleCode = generatePreviewModuleWithProps(art,
|
|
1063
|
+
const moduleCode = generatePreviewModuleWithProps(art, variantComponentNames(art.variants).get(variant.name), variant.name, propsOverride, ctx.resolvedPreviewCss, ctx.resolvedPreviewSetup, 3, ctx.toolbar);
|
|
1422
1064
|
res.setHeader("Content-Type", "application/javascript");
|
|
1423
1065
|
res.end(moduleCode);
|
|
1424
1066
|
} catch (e) {
|
|
@@ -1848,9 +1490,13 @@ function createLoad(state) {
|
|
|
1848
1490
|
const lastColonIndex = rest.lastIndexOf(":");
|
|
1849
1491
|
if (lastColonIndex !== -1) {
|
|
1850
1492
|
const artPath = rest.slice(0, lastColonIndex);
|
|
1851
|
-
const variantName = rest.slice(lastColonIndex + 1);
|
|
1493
|
+
const variantName = decodeVariantName(rest.slice(lastColonIndex + 1));
|
|
1852
1494
|
const art = state.artFiles.get(artPath);
|
|
1853
|
-
if (art)
|
|
1495
|
+
if (art) {
|
|
1496
|
+
const variantComponentName = variantComponentNames(art.variants).get(variantName);
|
|
1497
|
+
if (!variantComponentName) return null;
|
|
1498
|
+
return generatePreviewModule(art, variantComponentName, variantName, state.resolvedPreviewCss, state.resolvedPreviewSetup, state.getVueVersion(), state.toolbar);
|
|
1499
|
+
}
|
|
1854
1500
|
}
|
|
1855
1501
|
}
|
|
1856
1502
|
if (id.startsWith("\0musea-shared:")) {
|
|
@@ -2024,7 +1670,7 @@ function relativePath(root, filePath) {
|
|
|
2024
1670
|
}
|
|
2025
1671
|
//#endregion
|
|
2026
1672
|
//#region src/static-gallery-shell.ts
|
|
2027
|
-
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
1673
|
+
const moduleDir$1 = path.dirname(fileURLToPath(import.meta.url));
|
|
2028
1674
|
function joinFileName(...parts) {
|
|
2029
1675
|
return parts.filter(Boolean).join("/");
|
|
2030
1676
|
}
|
|
@@ -2081,7 +1727,7 @@ function generateStaticFallbackGalleryHtml(basePath) {
|
|
|
2081
1727
|
</html>`;
|
|
2082
1728
|
}
|
|
2083
1729
|
function resolveGalleryDistDir() {
|
|
2084
|
-
return [path.join(moduleDir, "gallery"), path.resolve(moduleDir, "../dist/gallery")].find((candidate) => fs.existsSync(path.join(candidate, "index.html"))) ?? null;
|
|
1730
|
+
return [path.join(moduleDir$1, "gallery"), path.resolve(moduleDir$1, "../dist/gallery")].find((candidate) => fs.existsSync(path.join(candidate, "index.html"))) ?? null;
|
|
2085
1731
|
}
|
|
2086
1732
|
async function collectFiles(dir) {
|
|
2087
1733
|
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
@@ -2136,7 +1782,7 @@ function loadStaticRuntimeModule(id, artFiles) {
|
|
|
2136
1782
|
return `
|
|
2137
1783
|
const loaders = { ${Array.from(artFiles.values()).flatMap((art) => art.variants.map((variant) => {
|
|
2138
1784
|
const key = staticPreviewId(art.path, variant.name);
|
|
2139
|
-
const moduleId =
|
|
1785
|
+
const moduleId = previewModuleId(art.path, variant.name);
|
|
2140
1786
|
return `${JSON.stringify(key)}: () => import(${JSON.stringify(moduleId)})`;
|
|
2141
1787
|
})).join(",\n")} };
|
|
2142
1788
|
|
|
@@ -2254,7 +1900,7 @@ function relativeUrl(fromDir, toFile) {
|
|
|
2254
1900
|
}
|
|
2255
1901
|
//#endregion
|
|
2256
1902
|
//#region src/plugin/config.ts
|
|
2257
|
-
async function resolveMuseaSharedConfig(resolvedConfig, loadConfigFile = loadConfig) {
|
|
1903
|
+
async function resolveMuseaSharedConfig(resolvedConfig, loadConfigFile = loadConfig, projectViteConfig = resolveViteConfigExport) {
|
|
2258
1904
|
let registration = getResolvedVizeConfigRegistration(resolvedConfig);
|
|
2259
1905
|
if (!registration.registered) {
|
|
2260
1906
|
await Promise.resolve();
|
|
@@ -2262,18 +1908,19 @@ async function resolveMuseaSharedConfig(resolvedConfig, loadConfigFile = loadCon
|
|
|
2262
1908
|
}
|
|
2263
1909
|
if (registration.registered) return await registration.config;
|
|
2264
1910
|
const configFile = process.env[VIZE_CONFIG_FILE_ENV];
|
|
2265
|
-
if (!configFile) return null;
|
|
2266
1911
|
try {
|
|
1912
|
+
const env = {
|
|
1913
|
+
mode: resolvedConfig.mode,
|
|
1914
|
+
command: resolvedConfig.command === "build" ? "build" : "serve",
|
|
1915
|
+
isSsrBuild: !!resolvedConfig.build?.ssr
|
|
1916
|
+
};
|
|
2267
1917
|
return await loadConfigFile(resolvedConfig.root, {
|
|
2268
1918
|
configFile,
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
isSsrBuild: !!resolvedConfig.build?.ssr
|
|
2273
|
-
}
|
|
2274
|
-
});
|
|
1919
|
+
viteConfig: false,
|
|
1920
|
+
env
|
|
1921
|
+
}) ?? await projectViteConfig(resolvedConfig, env);
|
|
2275
1922
|
} catch (error) {
|
|
2276
|
-
throw new Error(`[musea] Failed to load Vize config from ${configFile}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
1923
|
+
throw new Error(`[musea] Failed to load Vize config from ${configFile ?? resolvedConfig.root}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
2277
1924
|
}
|
|
2278
1925
|
}
|
|
2279
1926
|
//#endregion
|
|
@@ -2323,6 +1970,34 @@ function hasLegacyVueSfcCompilerPlugin(plugins) {
|
|
|
2323
1970
|
});
|
|
2324
1971
|
}
|
|
2325
1972
|
//#endregion
|
|
1973
|
+
//#region src/gallery-dependencies.ts
|
|
1974
|
+
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
1975
|
+
const globPath = (entry) => normalizePath(entry).replace(/([*?{}[\]()!])/g, "\\$1");
|
|
1976
|
+
async function registerSourceGalleryDependencies(config) {
|
|
1977
|
+
const client = config.environments.client;
|
|
1978
|
+
const optimizer = client.optimizeDeps;
|
|
1979
|
+
const gallery = path.join(moduleDir, "../gallery/index.html");
|
|
1980
|
+
if (config.command !== "serve" || optimizer.disabled === true || optimizer.disabled === "dev" || optimizer.noDiscovery || existsSync(path.join(moduleDir, "gallery/index.html")) || !existsSync(gallery)) return;
|
|
1981
|
+
let entries = optimizer.entries;
|
|
1982
|
+
if (!entries) {
|
|
1983
|
+
const input = client.build.rollupOptions.input;
|
|
1984
|
+
if (input) {
|
|
1985
|
+
const inputs = typeof input === "string" ? [input] : Array.isArray(input) ? input : Object.values(input);
|
|
1986
|
+
const resolve = config.createResolver();
|
|
1987
|
+
entries = await Promise.all(inputs.map(async (entry) => {
|
|
1988
|
+
const resolved = await resolve(entry, path.join(process.cwd(), "*"));
|
|
1989
|
+
if (!resolved) throw new Error(`Failed to resolve gallery dependency scan input: ${entry}`);
|
|
1990
|
+
return globPath(resolved);
|
|
1991
|
+
}));
|
|
1992
|
+
} else entries = [
|
|
1993
|
+
"**/*.html",
|
|
1994
|
+
"!**/__tests__/**",
|
|
1995
|
+
"!**/coverage/**"
|
|
1996
|
+
];
|
|
1997
|
+
}
|
|
1998
|
+
optimizer.entries = [...new Set([...typeof entries === "string" ? [entries] : entries, globPath(gallery)])];
|
|
1999
|
+
}
|
|
2000
|
+
//#endregion
|
|
2326
2001
|
//#region src/plugin/index.ts
|
|
2327
2002
|
function musea(options = {}) {
|
|
2328
2003
|
let include = options.include ?? ["**/*.art.vue"];
|
|
@@ -2384,6 +2059,7 @@ function musea(options = {}) {
|
|
|
2384
2059
|
options: applyMuseaStaticBuildInput,
|
|
2385
2060
|
async configResolved(resolvedConfig) {
|
|
2386
2061
|
config = resolvedConfig;
|
|
2062
|
+
await registerSourceGalleryDependencies(resolvedConfig);
|
|
2387
2063
|
const vizeConfig = await resolveMuseaSharedConfig(resolvedConfig);
|
|
2388
2064
|
if (vizeConfig?.musea) {
|
|
2389
2065
|
const mc = vizeConfig.musea;
|
|
@@ -2394,6 +2070,7 @@ function musea(options = {}) {
|
|
|
2394
2070
|
if (options.inlineArt === void 0 && mc.inlineArt !== void 0) inlineArt = mc.inlineArt;
|
|
2395
2071
|
if (options.tokenPreviews === void 0 && mc.tokenPreviews !== void 0) tokenPreviewConfig = mc.tokenPreviews;
|
|
2396
2072
|
}
|
|
2073
|
+
if (basePath !== "/") basePath = basePath.replace(/\/+$/, "");
|
|
2397
2074
|
vueVersion = resolveStaticPreviewVueVersion(vueVersion, resolvedConfig.plugins);
|
|
2398
2075
|
if (toolbar.length > 0 && vueVersion !== 3 && vueVersion !== "2.7") throw new Error("[musea] Global toolbar controls require Vue 3 or Vue 2.7");
|
|
2399
2076
|
staticBuildEnabled = shouldEmitMuseaStaticGallery(resolvedConfig.command, storybookCompat);
|