@vizejs/vite-plugin-musea 0.135.0 → 0.137.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 +36 -3
- package/dist/a11y/index.d.mts +1 -1
- package/dist/autogen/index.mjs +1 -1
- package/dist/{autogen-CywxMrJH.mjs → autogen-D32ZAiUd.mjs} +10 -8
- package/dist/autogen-D32ZAiUd.mjs.map +1 -0
- package/dist/gallery/assets/{MonacoEditor-ChPO-ZtO.js → MonacoEditor-BpKM7zbX.js} +2 -2
- package/dist/gallery/assets/{cssMode-tpEf1wjZ.js → cssMode-BdjqtB00.js} +1 -1
- package/dist/gallery/assets/{editor.api2-D2V4qV43.js → editor.api2-SLfptPIG.js} +1 -1
- package/dist/gallery/assets/{editor.main-B3fhJ8X5.js → editor.main-BljYFdfA.js} +2 -2
- package/dist/gallery/assets/{freemarker2-D9q7dgOY.js → freemarker2-DGmuhp50.js} +1 -1
- package/dist/gallery/assets/{handlebars-dCjq6t-4.js → handlebars-B954rIbz.js} +1 -1
- package/dist/gallery/assets/{html-l0AO0O65.js → html-BDQYSwH9.js} +1 -1
- package/dist/gallery/assets/{htmlMode-DX8C44PK.js → htmlMode-CSWWPg90.js} +1 -1
- package/dist/gallery/assets/{index-P1L8IaBA.css → index-BiMZ3Oo8.css} +1 -1
- package/dist/gallery/assets/index-CqK_XPg7.js +72 -0
- package/dist/gallery/assets/{javascript-DwD4tp-i.js → javascript-CYIH4OIS.js} +1 -1
- package/dist/gallery/assets/{jsonMode-6FizhbWG.js → jsonMode-CBrOXZY9.js} +1 -1
- package/dist/gallery/assets/{liquid-DcyqPOD8.js → liquid-FmyEnoPx.js} +1 -1
- package/dist/gallery/assets/{lspLanguageFeatures-DHY9tXb5.js → lspLanguageFeatures-Bu74h5y3.js} +1 -1
- package/dist/gallery/assets/{mdx-CwEaAM87.js → mdx-C3TFJbUn.js} +1 -1
- package/dist/gallery/assets/{monaco.contribution-DTmtm_Kx.js → monaco.contribution-HZxb4U4v.js} +2 -2
- package/dist/gallery/assets/{python-knXrGY--.js → python-BcMXVfwL.js} +1 -1
- package/dist/gallery/assets/{razor-BM2_GyF3.js → razor-DeiRoULl.js} +1 -1
- package/dist/gallery/assets/{tsMode-C5FA3F_c.js → tsMode-BoStKF93.js} +1 -1
- package/dist/gallery/assets/{typescript-x3O9BFS4.js → typescript-DigSpqaD.js} +1 -1
- package/dist/gallery/assets/{workers-CioQ1cEs.js → workers-BIEUw9pN.js} +1 -1
- package/dist/gallery/assets/{xml-CDZz0d4E.js → xml-B98zYTDh.js} +1 -1
- package/dist/gallery/assets/{yaml-Dfe1aVPk.js → yaml-OUYUOTjV.js} +1 -1
- package/dist/gallery/index.html +2 -2
- package/dist/{index-BMCTR1nC.d.mts → index-C5RD-jcD.d.mts} +2 -2
- package/dist/{index-BMCTR1nC.d.mts.map → index-C5RD-jcD.d.mts.map} +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +85 -11
- package/dist/index.mjs.map +1 -1
- package/dist/{vrt-CeAvfIsi.d.mts → vrt-D76vnsOt.d.mts} +3 -1
- package/dist/vrt-D76vnsOt.d.mts.map +1 -0
- package/dist/vrt.d.mts +1 -1
- package/package.json +4 -4
- package/dist/autogen-CywxMrJH.mjs.map +0 -1
- package/dist/gallery/assets/index-SaDls6HF.js +0 -68
- package/dist/vrt-CeAvfIsi.d.mts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as collectRequestBody, c as parseJsonBody, d as resolveUrlPathInside, f as serializeScriptValue, i as HttpError, l as resolveInside, n as generateGalleryModule, o as createDevSessionToken, p as validateDevApiRequest, s as decodeUrlComponent, u as resolveInsideAny } from "./gallery-kaxHo2Kt.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
|
-
import { n as writeArtFile, t as generateArtFile } from "./autogen-
|
|
4
|
+
import { n as writeArtFile, t as generateArtFile } from "./autogen-D32ZAiUd.mjs";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
6
|
import { transformWithEsbuild } from "vite";
|
|
7
7
|
import fs from "node:fs";
|
|
@@ -226,6 +226,12 @@ function buildThemeConfig(theme) {
|
|
|
226
226
|
function extractScriptSetupContent(source) {
|
|
227
227
|
return source.match(/<script\s+[^>]*setup[^>]*>([\s\S]*?)<\/script>/)?.[1]?.trim();
|
|
228
228
|
}
|
|
229
|
+
function extractScriptSetupIsolated(source) {
|
|
230
|
+
const match = source.match(/<script\s+([^>]*)\bsetup\b([^>]*)>/);
|
|
231
|
+
if (!match) return true;
|
|
232
|
+
const isolate = `${match[1] ?? ""} ${match[2] ?? ""}`.match(/\bisolate\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/);
|
|
233
|
+
return (isolate?.[1] ?? isolate?.[2] ?? isolate?.[3]) !== "false";
|
|
234
|
+
}
|
|
229
235
|
function resolveRelativeSpecifier(specifier, artDir) {
|
|
230
236
|
if (!specifier.startsWith(".")) return specifier;
|
|
231
237
|
return path.resolve(artDir, specifier);
|
|
@@ -295,6 +301,11 @@ function collectImportedNames(statement, returnNames) {
|
|
|
295
301
|
if (alias) returnNames.add(alias);
|
|
296
302
|
}
|
|
297
303
|
}
|
|
304
|
+
function importDeclaresName(statement, name) {
|
|
305
|
+
const names = /* @__PURE__ */ new Set();
|
|
306
|
+
collectImportedNames(statement, names);
|
|
307
|
+
return names.has(name);
|
|
308
|
+
}
|
|
298
309
|
function collectObjectDestructuredNames(statement, returnNames) {
|
|
299
310
|
const match = statement.match(/^(?:export\s+)?(?:const|let|var)\s+\{([\s\S]*?)\}\s*=/);
|
|
300
311
|
if (!match) return;
|
|
@@ -367,8 +378,14 @@ function parseScriptSetupForArt(content) {
|
|
|
367
378
|
const setupBody = [];
|
|
368
379
|
const returnNames = /* @__PURE__ */ new Set();
|
|
369
380
|
let currentImport = null;
|
|
381
|
+
const defineArtComponent = extractDefineArtComponent(content);
|
|
382
|
+
let defineArtBalance = 0;
|
|
370
383
|
for (const line of lines) {
|
|
371
384
|
const trimmed = line.trim();
|
|
385
|
+
if (defineArtBalance > 0) {
|
|
386
|
+
defineArtBalance += countCharBalance(line, "(", ")");
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
372
389
|
if (currentImport) {
|
|
373
390
|
currentImport.push(line);
|
|
374
391
|
const statement = currentImport.join("\n");
|
|
@@ -389,6 +406,10 @@ function parseScriptSetupForArt(content) {
|
|
|
389
406
|
}
|
|
390
407
|
continue;
|
|
391
408
|
}
|
|
409
|
+
if (isDefineArtLine(trimmed)) {
|
|
410
|
+
defineArtBalance = Math.max(0, countCharBalance(line, "(", ")"));
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
392
413
|
setupBody.push(line);
|
|
393
414
|
}
|
|
394
415
|
if (currentImport) {
|
|
@@ -398,24 +419,58 @@ function parseScriptSetupForArt(content) {
|
|
|
398
419
|
}
|
|
399
420
|
collectTopLevelReturnNames(setupBody, returnNames);
|
|
400
421
|
returnNames.delete("type");
|
|
422
|
+
if (defineArtComponent.name) returnNames.delete(defineArtComponent.name);
|
|
401
423
|
return {
|
|
402
424
|
imports,
|
|
403
425
|
setupBody,
|
|
404
|
-
returnNames: [...returnNames]
|
|
426
|
+
returnNames: [...returnNames],
|
|
427
|
+
defineArtComponentName: defineArtComponent.name,
|
|
428
|
+
defineArtComponentSource: defineArtComponent.source
|
|
405
429
|
};
|
|
406
430
|
}
|
|
431
|
+
function extractDefineArtComponent(content) {
|
|
432
|
+
const sourceMatch = content.match(/\bdefineArt\s*\(\s*(['"])([^'"]+)\1/);
|
|
433
|
+
if (sourceMatch) return {
|
|
434
|
+
name: componentNameFromSource(sourceMatch[2]),
|
|
435
|
+
source: sourceMatch[2]
|
|
436
|
+
};
|
|
437
|
+
return { name: content.match(/\bdefineArt\s*\(\s*([A-Za-z_$][\w$]*)/)?.[1] };
|
|
438
|
+
}
|
|
439
|
+
function componentNameFromSource(source) {
|
|
440
|
+
const withoutQuery = source.split(/[?#]/, 1)[0] || source;
|
|
441
|
+
const filename = path.basename(withoutQuery);
|
|
442
|
+
const extension = path.extname(filename);
|
|
443
|
+
const name = toPascalCase(extension ? filename.slice(0, -extension.length) : filename);
|
|
444
|
+
return name === "Variant" ? "MuseaComponent" : name;
|
|
445
|
+
}
|
|
446
|
+
function isDefineArtLine(trimmed) {
|
|
447
|
+
return /\bdefineArt\s*\(/.test(trimmed);
|
|
448
|
+
}
|
|
407
449
|
function generateArtModule(art, filePath, options = {}) {
|
|
408
450
|
let componentImportPath;
|
|
409
451
|
let componentTagName;
|
|
410
|
-
|
|
452
|
+
let componentBindingName = "__MuseaComponent";
|
|
453
|
+
const scriptSetup = art.scriptSetupContent ? parseScriptSetupForArt(art.scriptSetupContent) : null;
|
|
454
|
+
const defineArtComponentName = scriptSetup?.defineArtComponentName;
|
|
455
|
+
const defineArtComponentSource = scriptSetup?.defineArtComponentSource;
|
|
411
456
|
if (art.isInline && art.componentPath) {
|
|
412
457
|
componentImportPath = options.root ? resolveComponentSourcePath(art, filePath, allowedSourceRoots(options.root, options.scanRoots ?? [])) ?? void 0 : art.componentPath;
|
|
413
458
|
componentTagName = "MuseaComponent";
|
|
414
|
-
} else if (art.metadata.component) {
|
|
415
|
-
|
|
416
|
-
|
|
459
|
+
} else if (defineArtComponentSource || art.metadata.component) {
|
|
460
|
+
const componentSource = defineArtComponentSource ?? art.metadata.component;
|
|
461
|
+
if (componentSource) {
|
|
462
|
+
const sourceArt = componentSource === art.metadata.component ? art : {
|
|
463
|
+
...art,
|
|
464
|
+
metadata: {
|
|
465
|
+
...art.metadata,
|
|
466
|
+
component: componentSource
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
componentImportPath = options.root ? resolveComponentSourcePath(sourceArt, filePath, allowedSourceRoots(options.root, options.scanRoots ?? [])) ?? void 0 : path.isAbsolute(componentSource) ? componentSource : path.resolve(path.dirname(filePath), componentSource);
|
|
470
|
+
}
|
|
471
|
+
componentTagName = defineArtComponentName ?? (art.metadata.component ? componentNameFromSource(art.metadata.component) : "MuseaComponent");
|
|
472
|
+
componentBindingName = componentTagName;
|
|
417
473
|
}
|
|
418
|
-
const scriptSetup = art.scriptSetupContent ? parseScriptSetupForArt(art.scriptSetupContent) : null;
|
|
419
474
|
let code = `
|
|
420
475
|
// Auto-generated module for: ${path.basename(filePath)}
|
|
421
476
|
import { defineComponent, h } from 'vue';
|
|
@@ -428,13 +483,23 @@ import { defineComponent, h } from 'vue';
|
|
|
428
483
|
}
|
|
429
484
|
}
|
|
430
485
|
if (componentImportPath && componentTagName) {
|
|
431
|
-
if (!scriptSetup?.imports.some((imp) =>
|
|
486
|
+
if (!scriptSetup?.imports.some((imp) => importDeclaresName(imp, componentBindingName))) code += `import ${componentBindingName} from ${JSON.stringify(componentImportPath)};\n`;
|
|
432
487
|
code += `export const __component__ = ${componentBindingName};\n`;
|
|
433
488
|
}
|
|
434
489
|
code += `
|
|
435
490
|
export const metadata = ${JSON.stringify(art.metadata)};
|
|
436
491
|
export const variants = ${JSON.stringify(art.variants)};
|
|
437
492
|
export const __styles__ = ${JSON.stringify(art.styleBlocks ?? [])};
|
|
493
|
+
`;
|
|
494
|
+
const hasSetupBody = scriptSetup?.setupBody.some((line) => line.trim().length > 0) ?? false;
|
|
495
|
+
const hasSetup = !!scriptSetup && (hasSetupBody || scriptSetup.returnNames.length > 0);
|
|
496
|
+
const setupReturn = `{ ${scriptSetup?.returnNames.join(", ") ?? ""} }`;
|
|
497
|
+
const isolatedSetup = art.scriptSetupIsolated !== false;
|
|
498
|
+
if (scriptSetup && hasSetup && !isolatedSetup) code += `
|
|
499
|
+
const __museaSharedSetup = (() => {
|
|
500
|
+
${scriptSetup.setupBody.map((l) => ` ${l}`).join("\n")}
|
|
501
|
+
return ${setupReturn};
|
|
502
|
+
})();
|
|
438
503
|
`;
|
|
439
504
|
for (const variant of art.variants) {
|
|
440
505
|
const variantComponentName = toPascalCase(variant.name);
|
|
@@ -448,13 +513,21 @@ export const __styles__ = ${JSON.stringify(art.styleBlocks ?? [])};
|
|
|
448
513
|
for (const name of scriptSetup.returnNames) if (/^[A-Z]/.test(name)) componentNames.set(name, name);
|
|
449
514
|
}
|
|
450
515
|
const components = componentNames.size > 0 ? ` components: { ${[...componentNames].map(([name, value]) => `${JSON.stringify(name)}: ${value}`).join(", ")} },\n` : "";
|
|
451
|
-
|
|
452
|
-
if (scriptSetup && (hasSetupBody || scriptSetup.returnNames.length > 0)) code += `
|
|
516
|
+
if (scriptSetup && hasSetup && isolatedSetup) code += `
|
|
453
517
|
export const ${variantComponentName} = defineComponent({
|
|
454
518
|
name: '${variantComponentName}',
|
|
455
519
|
${components} setup() {
|
|
456
520
|
${scriptSetup.setupBody.map((l) => ` ${l}`).join("\n")}
|
|
457
|
-
return
|
|
521
|
+
return ${setupReturn};
|
|
522
|
+
},
|
|
523
|
+
template: \`${fullTemplate}\`,
|
|
524
|
+
});
|
|
525
|
+
`;
|
|
526
|
+
else if (scriptSetup && hasSetup) code += `
|
|
527
|
+
export const ${variantComponentName} = defineComponent({
|
|
528
|
+
name: '${variantComponentName}',
|
|
529
|
+
${components} setup() {
|
|
530
|
+
return __museaSharedSetup;
|
|
458
531
|
},
|
|
459
532
|
template: \`${fullTemplate}\`,
|
|
460
533
|
});
|
|
@@ -2688,6 +2761,7 @@ function musea(options = {}) {
|
|
|
2688
2761
|
})),
|
|
2689
2762
|
hasScriptSetup: isInline ? false : parsed.hasScriptSetup,
|
|
2690
2763
|
scriptSetupContent: !isInline && parsed.hasScriptSetup ? extractScriptSetupContent(source) : void 0,
|
|
2764
|
+
scriptSetupIsolated: !isInline && parsed.hasScriptSetup ? extractScriptSetupIsolated(source) : true,
|
|
2691
2765
|
hasScript: parsed.hasScript,
|
|
2692
2766
|
styleCount: parsed.styleCount,
|
|
2693
2767
|
styleBlocks: isInline ? [] : extractStyleBlocks(source),
|