@vizejs/vite-plugin-musea 0.291.0 → 0.302.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/index.mjs CHANGED
@@ -3492,13 +3492,82 @@ function publicBasePathFromViteBase(viteBase, basePath) {
3492
3492
  return viteBase && viteBase !== "/" && viteBase !== "./" ? joinUrlPath(viteBase, basePath) : basePath;
3493
3493
  }
3494
3494
  //#endregion
3495
+ //#region src/static-gallery-shell.ts
3496
+ const moduleDir = path.dirname(fileURLToPath(import.meta.url));
3497
+ function joinFileName(...parts) {
3498
+ return parts.filter(Boolean).join("/");
3499
+ }
3500
+ async function emitGalleryShell(emitFile, staticRoot, ctx, payload, galleryDistDir = resolveGalleryDistDir()) {
3501
+ if (!galleryDistDir) {
3502
+ const html = injectStaticGlobals(generateStaticFallbackGalleryHtml(ctx.basePath), ctx, payload);
3503
+ emitFile({
3504
+ type: "asset",
3505
+ fileName: joinFileName(staticRoot, "index.html"),
3506
+ source: html
3507
+ });
3508
+ return;
3509
+ }
3510
+ for (const filePath of await collectFiles(galleryDistDir)) {
3511
+ const relative = path.relative(galleryDistDir, filePath).split(path.sep).join("/");
3512
+ const target = joinFileName(staticRoot, relative);
3513
+ const content = await fs.promises.readFile(filePath);
3514
+ if (relative === "index.html") emitFile({
3515
+ type: "asset",
3516
+ fileName: target,
3517
+ source: injectStaticGlobals(rewriteGalleryBase(content.toString("utf-8"), ctx.basePath), ctx, payload)
3518
+ });
3519
+ else emitFile({
3520
+ type: "asset",
3521
+ fileName: target,
3522
+ source: rewriteGalleryTextAssetBase(content, relative, ctx.basePath)
3523
+ });
3524
+ }
3525
+ }
3526
+ function injectStaticGlobals(html, ctx, payload) {
3527
+ const script = `<script>${generateGalleryGlobalsScript({
3528
+ basePath: ctx.basePath,
3529
+ staticPreviews: payload.previews,
3530
+ themeConfig: ctx.themeConfig,
3531
+ tokenPreviewConfig: ctx.tokenPreviewConfig
3532
+ })}<\/script>`;
3533
+ return html.includes("</head>") ? html.replace("</head>", `${script}</head>`) : `${script}${html}`;
3534
+ }
3535
+ function generateStaticFallbackGalleryHtml(basePath) {
3536
+ return `<!DOCTYPE html>
3537
+ <html lang="en">
3538
+ <head>
3539
+ <meta charset="UTF-8">
3540
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
3541
+ <title>Musea - Component Gallery</title>
3542
+ <style>html,body{min-height:100%;margin:0}body{font-family:system-ui,sans-serif}</style>
3543
+ </head>
3544
+ <body>${generateGalleryBody(basePath)}
3545
+
3546
+ <script type="module">${generateGalleryScript(basePath)}
3547
+ <\/script>
3548
+ </body>
3549
+ </html>`;
3550
+ }
3551
+ function resolveGalleryDistDir() {
3552
+ return [path.join(moduleDir, "gallery"), path.resolve(moduleDir, "../dist/gallery")].find((candidate) => fs.existsSync(path.join(candidate, "index.html"))) ?? null;
3553
+ }
3554
+ async function collectFiles(dir) {
3555
+ const entries = await fs.promises.readdir(dir, { withFileTypes: true });
3556
+ const files = [];
3557
+ for (const entry of entries) {
3558
+ const filePath = path.join(dir, entry.name);
3559
+ if (entry.isDirectory()) files.push(...await collectFiles(filePath));
3560
+ else files.push(filePath);
3561
+ }
3562
+ return files;
3563
+ }
3564
+ //#endregion
3495
3565
  //#region src/static-export.ts
3496
3566
  const MUSEA_STATIC_BUILD_ENV = "VIZE_MUSEA_STATIC_BUILD";
3497
3567
  const VIRTUAL_STATIC_RUNTIME = "virtual:musea-static-runtime";
3498
3568
  const RESOLVED_STATIC_RUNTIME = "\0musea-static-runtime";
3499
3569
  const STATIC_RUNTIME_INPUT_NAME = "musea-static-runtime";
3500
3570
  const STATIC_USER_INPUT_NAME = "musea-static-entry";
3501
- const moduleDir = path.dirname(fileURLToPath(import.meta.url));
3502
3571
  function isMuseaStaticBuild() {
3503
3572
  return process.env[MUSEA_STATIC_BUILD_ENV] === "1";
3504
3573
  }
@@ -3579,49 +3648,6 @@ function findRuntimeFileName(bundle) {
3579
3648
  for (const item of Object.values(bundle)) if (item.type === "chunk" && item.name === "musea-static-runtime") return item.fileName;
3580
3649
  return null;
3581
3650
  }
3582
- async function emitGalleryShell(emitFile, staticRoot, ctx, payload) {
3583
- const galleryDir = resolveGalleryDistDir();
3584
- if (!galleryDir) {
3585
- const html = injectStaticGlobals(generateStaticFallbackGalleryHtml(ctx.basePath), ctx, payload);
3586
- emitFile({
3587
- type: "asset",
3588
- fileName: joinFileName(staticRoot, "index.html"),
3589
- source: html
3590
- });
3591
- return;
3592
- }
3593
- for (const filePath of await collectFiles(galleryDir)) {
3594
- const relative = path.relative(galleryDir, filePath).split(path.sep).join("/");
3595
- const target = joinFileName(staticRoot, relative);
3596
- const content = await fs.promises.readFile(filePath);
3597
- if (relative === "index.html") emitFile({
3598
- type: "asset",
3599
- fileName: target,
3600
- source: rewriteGalleryBase(injectStaticGlobals(content.toString("utf-8"), ctx, payload), ctx.basePath)
3601
- });
3602
- else emitFile({
3603
- type: "asset",
3604
- fileName: target,
3605
- source: rewriteGalleryTextAssetBase(content, relative, ctx.basePath)
3606
- });
3607
- }
3608
- }
3609
- function generateStaticFallbackGalleryHtml(basePath) {
3610
- return `<!DOCTYPE html>
3611
- <html lang="en">
3612
- <head>
3613
- <meta charset="UTF-8">
3614
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
3615
- <title>Musea - Component Gallery</title>
3616
- <style>html,body{min-height:100%;margin:0}body{font-family:system-ui,sans-serif}</style>
3617
- </head>
3618
- <body>${generateGalleryBody(basePath)}
3619
-
3620
- <script type="module">${generateGalleryScript(basePath)}
3621
- <\/script>
3622
- </body>
3623
- </html>`;
3624
- }
3625
3651
  function emitPreviewHtml(emitFile, staticRoot, runtimeFileName, basePath, artFiles) {
3626
3652
  const previewDir = joinFileName(staticRoot, "preview");
3627
3653
  const runtimeUrl = relativeUrl(previewDir, runtimeFileName);
@@ -3665,15 +3691,6 @@ function generateStaticPreviewHtml(art, variantName, previewId, basePath, runtim
3665
3691
  </body>
3666
3692
  </html>`;
3667
3693
  }
3668
- function injectStaticGlobals(html, ctx, payload) {
3669
- const script = `<script>${generateGalleryGlobalsScript({
3670
- basePath: ctx.basePath,
3671
- staticPreviews: payload.previews,
3672
- themeConfig: ctx.themeConfig,
3673
- tokenPreviewConfig: ctx.tokenPreviewConfig
3674
- })}<\/script>`;
3675
- return html.includes("</head>") ? html.replace("</head>", `${script}</head>`) : `${script}${html}`;
3676
- }
3677
3694
  function emitRootRedirect(emitFile, staticRoot, basePath) {
3678
3695
  if (!staticRoot) return;
3679
3696
  const target = joinUrlPath(basePath, "");
@@ -3694,25 +3711,9 @@ async function emitAxeVendor(emitFile, staticRoot) {
3694
3711
  });
3695
3712
  } catch {}
3696
3713
  }
3697
- function resolveGalleryDistDir() {
3698
- return [path.join(moduleDir, "gallery"), path.resolve(moduleDir, "../dist/gallery")].find((candidate) => fs.existsSync(path.join(candidate, "index.html"))) ?? null;
3699
- }
3700
- async function collectFiles(dir) {
3701
- const entries = await fs.promises.readdir(dir, { withFileTypes: true });
3702
- const files = [];
3703
- for (const entry of entries) {
3704
- const filePath = path.join(dir, entry.name);
3705
- if (entry.isDirectory()) files.push(...await collectFiles(filePath));
3706
- else files.push(filePath);
3707
- }
3708
- return files;
3709
- }
3710
3714
  function staticRootFromBasePath(basePath) {
3711
3715
  return basePath.replace(/^\/+|\/+$/g, "");
3712
3716
  }
3713
- function joinFileName(...parts) {
3714
- return parts.filter(Boolean).join("/");
3715
- }
3716
3717
  function relativeUrl(fromDir, toFile) {
3717
3718
  const relative = path.posix.relative(fromDir || ".", toFile);
3718
3719
  return relative.startsWith(".") ? relative : `./${relative}`;