@vizejs/vite-plugin-musea 0.302.0 → 0.306.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
@@ -637,6 +637,19 @@ function __museaInitAddons(container, variantName, extraCaptureEvents = []) {
637
637
  script.onerror = reject;
638
638
  document.head.appendChild(script);
639
639
  });
640
+ // A load event is not proof the vendor script exists. axe-core is
641
+ // an optional peer, so a static export can ship without it, and a
642
+ // static host is free to answer the missing asset with an SPA
643
+ // fallback: 200 plus HTML. The script tag then "loads" fine and
644
+ // window.axe is still undefined, which surfaced downstream as an
645
+ // opaque "cannot read properties of undefined" instead of the real
646
+ // cause.
647
+ if (!window.axe) {
648
+ throw new Error(
649
+ 'axe-core did not load from ' + script.src +
650
+ ' - install axe-core so the gallery can ship it, and check that the path is served as JavaScript rather than an SPA fallback'
651
+ );
652
+ }
640
653
  }
641
654
  // Run axe-core on the .musea-variant container only (not the full document)
642
655
  const context = document.querySelector('.musea-variant') || document;
@@ -2913,19 +2926,6 @@ async function handleArtDocs(ctx, match, sendJson, sendError) {
2913
2926
  }
2914
2927
  }
2915
2928
  /** GET /api/arts/:path/variants/:name/a11y */
2916
- function handleArtA11y(ctx, match, sendJson, sendError) {
2917
- const artPath = decodeUrlComponent(match[1], "art path");
2918
- decodeUrlComponent(match[2], "variant name");
2919
- if (!ctx.artFiles.get(artPath)) {
2920
- sendError("Art not found", 404);
2921
- return;
2922
- }
2923
- sendJson({
2924
- violations: [],
2925
- passes: 0,
2926
- incomplete: 0
2927
- });
2928
- }
2929
2929
  //#endregion
2930
2930
  //#region src/api-routes/post-handlers.ts
2931
2931
  /** POST /api/preview-with-props */
@@ -3116,7 +3116,6 @@ function createApiMiddleware(ctx) {
3116
3116
  const paletteMatch = rest.match(/^(.+)\/palette$/);
3117
3117
  const analysisMatch = rest.match(/^(.+)\/analysis$/);
3118
3118
  const docsMatch = rest.match(/^(.+)\/docs$/);
3119
- const a11yMatch = rest.match(/^(.+)\/variants\/([^/]+)\/a11y$/);
3120
3119
  if (sourceMatch) {
3121
3120
  await handleArtSource(ctx, sourceMatch, sendJson, sendError);
3122
3121
  return;
@@ -3133,10 +3132,6 @@ function createApiMiddleware(ctx) {
3133
3132
  await handleArtDocs(ctx, docsMatch, sendJson, sendError);
3134
3133
  return;
3135
3134
  }
3136
- if (a11yMatch) {
3137
- handleArtA11y(ctx, a11yMatch, sendJson, sendError);
3138
- return;
3139
- }
3140
3135
  const artPath = decodeUrlComponent(rest, "art path");
3141
3136
  const art = ctx.artFiles.get(artPath);
3142
3137
  if (art) sendJson(art);
@@ -3364,13 +3359,9 @@ async function createStaticGalleryPayload(ctx) {
3364
3359
  const details = {};
3365
3360
  for (const art of arts) {
3366
3361
  previews[art.path] = {};
3367
- const a11y = {};
3368
3362
  for (const variant of art.variants) {
3369
3363
  const id = staticPreviewId(art.path, variant.name);
3370
3364
  previews[art.path][variant.name] = joinUrlPath(ctx.basePath, "preview", `${id}.html`);
3371
- a11y[variant.name] = await captureJson((sendJson, sendError) => {
3372
- handleArtA11y(apiCtx, artVariantMatch(art.path, variant.name), sendJson, sendError);
3373
- }, emptyA11y());
3374
3365
  }
3375
3366
  details[art.path] = {
3376
3367
  source: await captureJson((sendJson, sendError) => {
@@ -3390,8 +3381,7 @@ async function createStaticGalleryPayload(ctx) {
3390
3381
  }),
3391
3382
  docs: await captureJson((sendJson, sendError) => {
3392
3383
  return handleArtDocs(apiCtx, artMatch(art.path), sendJson, sendError);
3393
- }, emptyDocs(art)),
3394
- a11y
3384
+ }, emptyDocs(art))
3395
3385
  };
3396
3386
  }
3397
3387
  return {
@@ -3436,13 +3426,6 @@ async function captureJson(run, fallback) {
3436
3426
  function artMatch(artPath) {
3437
3427
  return ["", encodeURIComponent(artPath)];
3438
3428
  }
3439
- function artVariantMatch(artPath, variantName) {
3440
- return [
3441
- "",
3442
- encodeURIComponent(artPath),
3443
- encodeURIComponent(variantName)
3444
- ];
3445
- }
3446
3429
  function emptyPalette(art) {
3447
3430
  return {
3448
3431
  title: art.metadata.title,
@@ -3459,13 +3442,6 @@ function emptyDocs(art) {
3459
3442
  variant_count: art.variants.length
3460
3443
  };
3461
3444
  }
3462
- function emptyA11y() {
3463
- return {
3464
- violations: [],
3465
- passes: 0,
3466
- incomplete: 0
3467
- };
3468
- }
3469
3445
  function emptyTokens() {
3470
3446
  return {
3471
3447
  categories: [],
@@ -3709,7 +3685,9 @@ async function emitAxeVendor(emitFile, staticRoot) {
3709
3685
  fileName: joinFileName(staticRoot, "vendor/axe-core.min.js"),
3710
3686
  source
3711
3687
  });
3712
- } catch {}
3688
+ } catch {
3689
+ console.warn("[musea] axe-core is not installed, so the exported gallery cannot run accessibility checks.\n Install it to enable the A11y panel in the static build: vp install -D axe-core");
3690
+ }
3713
3691
  }
3714
3692
  function staticRootFromBasePath(basePath) {
3715
3693
  return basePath.replace(/^\/+|\/+$/g, "");