@vizejs/vite-plugin-musea 0.270.0 → 0.272.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.
Files changed (30) hide show
  1. package/dist/gallery/assets/{MonacoEditor-CaEpEUhO.js → MonacoEditor-DsbIpkQL.js} +2 -2
  2. package/dist/gallery/assets/{cssMode-CdtUUFyi.js → cssMode-BEYj0tak.js} +1 -1
  3. package/dist/gallery/assets/{editor.api2-DZBCMTPp.js → editor.api2-Bz2kYzUN.js} +1 -1
  4. package/dist/gallery/assets/{editor.main-Bmw0213t.js → editor.main-BVHs2SSr.js} +2 -2
  5. package/dist/gallery/assets/{freemarker2-Bv3x1gTk.js → freemarker2-BZ6nC3A3.js} +1 -1
  6. package/dist/gallery/assets/{handlebars-D11b15L3.js → handlebars-DEfvHxqu.js} +1 -1
  7. package/dist/gallery/assets/{html-DM26Zsuc.js → html-BQHhPRs4.js} +1 -1
  8. package/dist/gallery/assets/{htmlMode-DYNh3Pzf.js → htmlMode-BJg8FTpN.js} +1 -1
  9. package/dist/gallery/assets/index-BD1UzCKA.css +1 -0
  10. package/dist/gallery/assets/{index-Bc4LRCXi.js → index-De8nZlO8.js} +4 -4
  11. package/dist/gallery/assets/{javascript-CfNzBMkj.js → javascript-BnHRMqEr.js} +1 -1
  12. package/dist/gallery/assets/{jsonMode-B-ArV4k8.js → jsonMode-jcQUywhl.js} +1 -1
  13. package/dist/gallery/assets/{liquid-Ba5jhpVp.js → liquid-DBFdARj0.js} +1 -1
  14. package/dist/gallery/assets/{lspLanguageFeatures-C_kQMLR7.js → lspLanguageFeatures-BAQ0wWN5.js} +1 -1
  15. package/dist/gallery/assets/{mdx-zpKixrPp.js → mdx-B4klyOk6.js} +1 -1
  16. package/dist/gallery/assets/{monaco.contribution-9GtnssPq.js → monaco.contribution-DurMprOc.js} +2 -2
  17. package/dist/gallery/assets/{python-BltZt2Jw.js → python-DVtrR2b4.js} +1 -1
  18. package/dist/gallery/assets/{razor-BKXZq7zE.js → razor-DvGAQ27Z.js} +1 -1
  19. package/dist/gallery/assets/{tsMode-CQVoafwv.js → tsMode-Kibx_hev.js} +1 -1
  20. package/dist/gallery/assets/{typescript-DLdg7jpK.js → typescript-qDteoCEw.js} +1 -1
  21. package/dist/gallery/assets/{workers-BaJgi0mc.js → workers-Cruk8RxZ.js} +1 -1
  22. package/dist/gallery/assets/{xml-B7Ykttus.js → xml-CTVXfCOD.js} +1 -1
  23. package/dist/gallery/assets/{yaml-uYtSD5pX.js → yaml-BuZYNjL4.js} +1 -1
  24. package/dist/gallery/index.html +2 -2
  25. package/dist/index.d.mts +1 -1
  26. package/dist/index.d.mts.map +1 -1
  27. package/dist/index.mjs +68 -15
  28. package/dist/index.mjs.map +1 -1
  29. package/package.json +4 -4
  30. package/dist/gallery/assets/index-Bwb5j7qQ.css +0 -1
package/dist/index.mjs CHANGED
@@ -1330,7 +1330,7 @@ export const __styles__ = ${JSON.stringify(art.styleBlocks ?? [])};
1330
1330
  const isolatedSetup = art.scriptSetupIsolated !== false;
1331
1331
  if (scriptSetup && hasSetup && !isolatedSetup) code += `
1332
1332
  const __museaSharedSetup = (() => {
1333
- ${scriptSetup.setupBody.map((l) => ` ${l}`).join("\n")}
1333
+ ${scriptSetup.setupBody.join("\n")}
1334
1334
  return ${setupReturn};
1335
1335
  })();
1336
1336
  `;
@@ -1343,14 +1343,14 @@ ${scriptSetup.setupBody.map((l) => ` ${l}`).join("\n")}
1343
1343
  const componentNames = /* @__PURE__ */ new Map();
1344
1344
  if (componentTagName) componentNames.set(componentTagName, componentBindingName);
1345
1345
  if (scriptSetup) {
1346
- for (const name of scriptSetup.returnNames) if (/^[A-Z]/.test(name)) componentNames.set(name, name);
1346
+ for (const name of scriptSetup.returnNames) if (/^[A-Z]/.test(name) && scriptSetup.imports.some((imp) => importDeclaresName(imp, name))) componentNames.set(name, name);
1347
1347
  }
1348
1348
  const components = componentNames.size > 0 ? ` components: { ${[...componentNames].map(([name, value]) => `${JSON.stringify(name)}: ${value}`).join(", ")} },\n` : "";
1349
1349
  if (scriptSetup && hasSetup && isolatedSetup) code += `
1350
1350
  export const ${variantComponentName} = defineComponent({
1351
1351
  name: '${variantComponentName}',
1352
1352
  ${components} setup() {
1353
- ${scriptSetup.setupBody.map((l) => ` ${l}`).join("\n")}
1353
+ ${scriptSetup.setupBody.join("\n")}
1354
1354
  return ${setupReturn};
1355
1355
  },
1356
1356
  template: \`${fullTemplate}\`,
@@ -1608,6 +1608,24 @@ function registerMiddleware(devServer, ctx) {
1608
1608
  });
1609
1609
  }
1610
1610
  //#endregion
1611
+ //#region src/art-order.ts
1612
+ function sortedArts(arts) {
1613
+ return [...arts].sort(compareArtFiles);
1614
+ }
1615
+ function compareArtFiles(a, b) {
1616
+ const order = compareOrder(a.metadata.order, b.metadata.order);
1617
+ if (order !== 0) return order;
1618
+ const title = a.metadata.title.localeCompare(b.metadata.title, void 0, { numeric: true });
1619
+ if (title !== 0) return title;
1620
+ return a.path.localeCompare(b.path, void 0, { numeric: true });
1621
+ }
1622
+ function compareOrder(a, b) {
1623
+ if (a === void 0 && b === void 0) return 0;
1624
+ if (a === void 0) return 1;
1625
+ if (b === void 0) return -1;
1626
+ return a - b;
1627
+ }
1628
+ //#endregion
1611
1629
  //#region src/tokens/native.ts
1612
1630
  function tokenNative() {
1613
1631
  const native = loadNative();
@@ -1646,11 +1664,34 @@ function parseJsonResult(value) {
1646
1664
  }
1647
1665
  function normalizeCategories(categories) {
1648
1666
  for (const category of categories) {
1649
- category.tokens = nullRecord(category.tokens);
1667
+ category.tokens = nullRecord(Object.fromEntries(sortTokenEntries(category.tokens)));
1650
1668
  if (category.subcategories) normalizeCategories(category.subcategories);
1651
1669
  }
1652
1670
  return categories;
1653
1671
  }
1672
+ function sortTokenEntries(tokens) {
1673
+ return Object.entries(tokens).sort((a, b) => {
1674
+ const order = compareTokenOrder(a[1], b[1]);
1675
+ if (order !== 0) return order;
1676
+ return a[0].localeCompare(b[0], void 0, { numeric: true });
1677
+ });
1678
+ }
1679
+ function compareTokenOrder(a, b) {
1680
+ const aOrder = tokenOrder(a);
1681
+ const bOrder = tokenOrder(b);
1682
+ if (aOrder === void 0 && bOrder === void 0) return 0;
1683
+ if (aOrder === void 0) return 1;
1684
+ if (bOrder === void 0) return -1;
1685
+ return aOrder - bOrder;
1686
+ }
1687
+ function tokenOrder(token) {
1688
+ const order = token.attributes?.order;
1689
+ if (typeof order === "number" && Number.isFinite(order)) return order;
1690
+ if (typeof order === "string") {
1691
+ const parsed = Number(order);
1692
+ if (Number.isFinite(parsed)) return parsed;
1693
+ }
1694
+ }
1654
1695
  function nullRecord(record) {
1655
1696
  return Object.assign(Object.create(null), record);
1656
1697
  }
@@ -2340,6 +2381,11 @@ function inferPreviewKind(candidates, value) {
2340
2381
  "round",
2341
2382
  "rounded"
2342
2383
  ])) return "radius";
2384
+ if (hasType(candidates, ["letterspacing", "letter-spacing"]) || hasSignal(candidates, [
2385
+ "letter-spacing",
2386
+ "letterspacing",
2387
+ "tracking"
2388
+ ])) return "letterSpacing";
2343
2389
  if (hasType(candidates, ["spacing", "space"]) || hasSignal(candidates, [
2344
2390
  "spacing",
2345
2391
  "spasing",
@@ -2976,7 +3022,7 @@ function createApiMiddleware(ctx) {
2976
3022
  return;
2977
3023
  }
2978
3024
  if (url === "/arts" && req.method === "GET") {
2979
- sendJson(Array.from(ctx.artFiles.values()));
3025
+ sendJson(sortedArts(ctx.artFiles.values()));
2980
3026
  return;
2981
3027
  }
2982
3028
  if (url === "/tokens/usage" && req.method === "GET") {
@@ -3085,7 +3131,7 @@ function createApiMiddleware(ctx) {
3085
3131
  * Generate the virtual manifest module code containing all art file metadata.
3086
3132
  */
3087
3133
  function generateManifestModule(artFiles) {
3088
- const arts = Array.from(artFiles.values());
3134
+ const arts = sortedArts(artFiles.values());
3089
3135
  return `export const arts = ${JSON.stringify(arts, null, 2)};`;
3090
3136
  }
3091
3137
  //#endregion
@@ -3260,7 +3306,7 @@ function joinUrlPath(basePath, ...segments) {
3260
3306
  }
3261
3307
  async function createStaticGalleryPayload(ctx) {
3262
3308
  const apiCtx = createApiContext(ctx);
3263
- const arts = Array.from(ctx.artFiles.values());
3309
+ const arts = sortedArts(ctx.artFiles.values());
3264
3310
  const previews = {};
3265
3311
  const details = {};
3266
3312
  for (const art of arts) {
@@ -3437,22 +3483,27 @@ if (typeof window !== "undefined") {
3437
3483
  async function emitStaticGallery(emitFile, bundle, ctx) {
3438
3484
  const runtimeFileName = findRuntimeFileName(bundle);
3439
3485
  if (!runtimeFileName) throw new Error("musea static build could not find its generated runtime entry");
3440
- const payload = await createStaticGalleryPayload(ctx);
3441
3486
  const staticRoot = staticRootFromBasePath(ctx.basePath);
3442
- await emitGalleryShell(emitFile, staticRoot, ctx, payload);
3487
+ const publicBasePath = publicBasePathFromViteBase(ctx.config.base, ctx.basePath);
3488
+ const publicCtx = {
3489
+ ...ctx,
3490
+ basePath: publicBasePath
3491
+ };
3492
+ const publicPayload = await createStaticGalleryPayload(publicCtx);
3493
+ await emitGalleryShell(emitFile, staticRoot, publicCtx, publicPayload);
3443
3494
  emitFile({
3444
3495
  type: "asset",
3445
3496
  fileName: joinFileName(staticRoot, "api", "static.json"),
3446
- source: JSON.stringify(payload, null, 2)
3497
+ source: JSON.stringify(publicPayload, null, 2)
3447
3498
  });
3448
3499
  emitFile({
3449
3500
  type: "asset",
3450
3501
  fileName: joinFileName(staticRoot, "api", "arts"),
3451
- source: JSON.stringify(payload.arts, null, 2)
3502
+ source: JSON.stringify(publicPayload.arts, null, 2)
3452
3503
  });
3453
3504
  await emitAxeVendor(emitFile, staticRoot);
3454
- emitPreviewHtml(emitFile, staticRoot, runtimeFileName, ctx.basePath, payload, ctx.artFiles);
3455
- emitRootRedirect(emitFile, staticRoot, ctx.basePath);
3505
+ emitPreviewHtml(emitFile, staticRoot, runtimeFileName, publicBasePath, ctx.artFiles);
3506
+ emitRootRedirect(emitFile, staticRoot, publicBasePath);
3456
3507
  }
3457
3508
  function findRuntimeFileName(bundle) {
3458
3509
  for (const item of Object.values(bundle)) if (item.type === "chunk" && item.name === "musea-static-runtime") return item.fileName;
@@ -3484,7 +3535,6 @@ async function emitGalleryShell(emitFile, staticRoot, ctx, payload) {
3484
3535
  source: content
3485
3536
  });
3486
3537
  }
3487
- if (payload.arts.length === 0) return;
3488
3538
  }
3489
3539
  function generateStaticFallbackGalleryHtml(basePath) {
3490
3540
  return `<!DOCTYPE html>
@@ -3502,7 +3552,7 @@ function generateStaticFallbackGalleryHtml(basePath) {
3502
3552
  </body>
3503
3553
  </html>`;
3504
3554
  }
3505
- function emitPreviewHtml(emitFile, staticRoot, runtimeFileName, basePath, payload, artFiles) {
3555
+ function emitPreviewHtml(emitFile, staticRoot, runtimeFileName, basePath, artFiles) {
3506
3556
  const previewDir = joinFileName(staticRoot, "preview");
3507
3557
  const runtimeUrl = relativeUrl(previewDir, runtimeFileName);
3508
3558
  for (const art of artFiles.values()) for (const variant of art.variants) {
@@ -3557,6 +3607,9 @@ function injectStaticGlobals(html, ctx, payload) {
3557
3607
  function rewriteGalleryBase(html, basePath) {
3558
3608
  return html.replaceAll("/__musea__/", `${basePath.replace(/\/?$/, "/")}`);
3559
3609
  }
3610
+ function publicBasePathFromViteBase(viteBase, basePath) {
3611
+ return viteBase && viteBase !== "/" && viteBase !== "./" ? joinUrlPath(viteBase, basePath) : basePath;
3612
+ }
3560
3613
  function emitRootRedirect(emitFile, staticRoot, basePath) {
3561
3614
  if (!staticRoot) return;
3562
3615
  const target = joinUrlPath(basePath, "");