@forsakringskassan/docs-generator 2.19.1 → 2.21.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.js CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  var fs = require('node:fs/promises');
4
4
  var path = require('node:path/posix');
5
- var vendor = require('./vendor-BO0JjPoU.js');
6
- var createMarkdownRenderer = require('./create-markdown-renderer-BVgcQwRq.js');
5
+ var vendor = require('./vendor-CLvDQIrx.js');
6
+ var createMarkdownRenderer = require('./create-markdown-renderer-LhP3SCgI.js');
7
7
  var path$1 = require('node:path');
8
8
  var require$$1 = require('crypto');
9
9
  require('node:crypto');
@@ -44,7 +44,7 @@ require('tls');
44
44
  require('tty');
45
45
  require('querystring');
46
46
  require('vue');
47
- require('./vue3-BitM0YmN.js');
47
+ require('./vue3-BKfEgvlU.js');
48
48
 
49
49
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
50
50
  function toArray$2(value) {
@@ -1616,9 +1616,9 @@ function cssAssetProcessor(assetFolder, assets, options) {
1616
1616
  name: "css-asset-processor",
1617
1617
  after: "assets",
1618
1618
  async handler(context) {
1619
- const assetInfo = context.getTemplateData("assets") ?? {};
1620
- const head = context.getTemplateData("injectHead") ?? [];
1621
- const body = context.getTemplateData("injectBody") ?? [];
1619
+ const assetInfo = context.getTemplateData("assets", {});
1620
+ const head = context.getTemplateData("injectHead", []);
1621
+ const body = context.getTemplateData("injectBody", []);
1622
1622
  for (const asset of toSorted$1(assets, byPriority$1)) {
1623
1623
  const info = await compileStyle(
1624
1624
  assetFolder,
@@ -1628,7 +1628,10 @@ function cssAssetProcessor(assetFolder, assets, options) {
1628
1628
  );
1629
1629
  const attrs = serializeAttrs(asset.options.attributes);
1630
1630
  const inject = { ...info, attrs: Array.from(attrs).join(" ") };
1631
- assetInfo[asset.name] = info;
1631
+ assetInfo[asset.name] = {
1632
+ ...info,
1633
+ importmap: false
1634
+ };
1632
1635
  switch (asset.options.appendTo) {
1633
1636
  case "none":
1634
1637
  break;
@@ -1639,11 +1642,8 @@ function cssAssetProcessor(assetFolder, assets, options) {
1639
1642
  body.push(inject);
1640
1643
  break;
1641
1644
  }
1642
- context.setTemplateData("injectHead", head);
1643
- context.setTemplateData("injectBody", body);
1644
1645
  context.log(info.filename, formatSize(info.size));
1645
1646
  }
1646
- context.setTemplateData("assets", assetInfo);
1647
1647
  }
1648
1648
  };
1649
1649
  }
@@ -1652,11 +1652,16 @@ function esbuild(options) {
1652
1652
  return esbuild$1.build(options);
1653
1653
  }
1654
1654
 
1655
+ function toExternalVendor(vendor) {
1656
+ return typeof vendor === "string" ? vendor : vendor.package;
1657
+ }
1655
1658
  async function compileScript(options) {
1656
1659
  const {
1657
1660
  assetFolder,
1658
1661
  name,
1659
1662
  src,
1663
+ assets,
1664
+ vendor,
1660
1665
  buildOptions,
1661
1666
  fs: fs$1 = fs
1662
1667
  } = options;
@@ -1664,13 +1669,14 @@ async function compileScript(options) {
1664
1669
  try {
1665
1670
  const entryPoints = [src instanceof URL ? node_url.fileURLToPath(src) : src];
1666
1671
  const outfile = path$1.join("temp", `asset-${name}.js`);
1672
+ const external = [...assets, ...vendor.map(toExternalVendor)];
1667
1673
  await esbuild({
1668
1674
  entryPoints,
1669
1675
  outfile,
1670
1676
  bundle: true,
1671
- format: "iife",
1677
+ format: "esm",
1672
1678
  platform: "browser",
1673
- external: ["vue", "@fkui/vue"],
1679
+ external,
1674
1680
  tsconfig: path$1.join(__dirname, "../tsconfig-examples.json"),
1675
1681
  ...buildOptions,
1676
1682
  define: {
@@ -1706,24 +1712,33 @@ function byPriority({ options: a }, { options: b }) {
1706
1712
  function toSorted(values, comparator) {
1707
1713
  return [...values].sort(comparator);
1708
1714
  }
1709
- function jsAssetProcessor(assetFolder, assets) {
1715
+ function isExternal(asset) {
1716
+ return asset.options.appendTo === "none";
1717
+ }
1718
+ function jsAssetProcessor(assetFolder, assets, vendor) {
1719
+ const externalAssets = assets.filter(isExternal).map((it) => it.name);
1710
1720
  return {
1711
1721
  name: "js-asset-processor",
1712
1722
  after: "assets",
1713
1723
  async handler(context) {
1714
- const assetInfo = context.getTemplateData("assets") ?? {};
1715
- const head = context.getTemplateData("injectHead") ?? [];
1716
- const body = context.getTemplateData("injectBody") ?? [];
1724
+ const assetInfo = context.getTemplateData("assets", {});
1725
+ const head = context.getTemplateData("injectHead", []);
1726
+ const body = context.getTemplateData("injectBody", []);
1717
1727
  for (const asset of toSorted(assets, byPriority)) {
1718
1728
  const info = await compileScript({
1719
1729
  assetFolder,
1720
1730
  name: asset.name,
1721
1731
  src: asset.src,
1732
+ assets: externalAssets,
1733
+ vendor,
1722
1734
  buildOptions: asset.buildOptions
1723
1735
  });
1724
1736
  const attrs = serializeAttrs(asset.options.attributes);
1725
1737
  const inject = { ...info, attrs: Array.from(attrs).join(" ") };
1726
- assetInfo[asset.name] = info;
1738
+ assetInfo[asset.name] = {
1739
+ ...info,
1740
+ importmap: externalAssets.includes(asset.name)
1741
+ };
1727
1742
  switch (asset.options.appendTo) {
1728
1743
  case "none":
1729
1744
  break;
@@ -1734,8 +1749,6 @@ function jsAssetProcessor(assetFolder, assets) {
1734
1749
  body.push(inject);
1735
1750
  break;
1736
1751
  }
1737
- context.setTemplateData("injectHead", head);
1738
- context.setTemplateData("injectBody", body);
1739
1752
  context.log(info.filename, formatSize(info.size));
1740
1753
  }
1741
1754
  }
@@ -2260,7 +2273,30 @@ async function render(doc, docs, nav, vendors, options) {
2260
2273
  return relative !== "" ? relative : ".";
2261
2274
  },
2262
2275
  sidenav,
2263
- vendors
2276
+ vendors,
2277
+ importmap(doc2) {
2278
+ const assets = Object.values(templateData.assets).filter(
2279
+ (it) => it.importmap
2280
+ );
2281
+ const imports = Object.fromEntries([
2282
+ ...vendors.map((it) => {
2283
+ return [it.package, relative(it.publicPath, doc2)];
2284
+ }),
2285
+ ...assets.map((it) => {
2286
+ return [it.name, relative(it.publicPath, doc2)];
2287
+ })
2288
+ ]);
2289
+ const integrity = Object.fromEntries([
2290
+ ...vendors.map((it) => {
2291
+ return [relative(it.publicPath, doc2), it.integrity];
2292
+ }),
2293
+ ...assets.map((it) => {
2294
+ return [relative(it.publicPath, doc2), it.integrity];
2295
+ })
2296
+ ]);
2297
+ const importmap = { imports, integrity };
2298
+ return JSON.stringify(importmap, null, 2);
2299
+ }
2264
2300
  };
2265
2301
  const generatedExamples = [];
2266
2302
  const generatedStandalone = [];
@@ -2443,46 +2479,10 @@ function nunjucksProcessor(options) {
2443
2479
  };
2444
2480
  }
2445
2481
 
2446
- function customRequire(name) {
2447
- if (typeof window.__modules__ === "undefined") {
2448
- window.__modules__ = {};
2449
- }
2450
- const mod = window.__modules__[name];
2451
- if (!mod) {
2452
- throw new Error(`Cannot find module "${name}"`);
2453
- }
2454
- return mod;
2455
- }
2456
- function getAssetSource(asset, require) {
2482
+ function getAssetSource(asset) {
2457
2483
  const lines = [];
2458
2484
  const pkg = asset.package.replace(/\\/g, "/");
2459
- if (!asset.expose) {
2460
- return `import "${pkg}"`;
2461
- }
2462
- if (asset.expose === "named") {
2463
- lines.push(`import * as lib from "${pkg}";`);
2464
- } else {
2465
- lines.push(`import lib from "${pkg}";`);
2466
- }
2467
- asset.subpaths.map((subpath, index) => {
2468
- if (asset.expose === "named") {
2469
- lines.push(`import * as lib$${index} from "${subpath}";`);
2470
- } else {
2471
- lines.push(`import lib$${index} from "${subpath}";`);
2472
- }
2473
- });
2474
- lines.push(`window.require = window.require || ${require};`);
2475
- lines.push(`window.__modules__ = window.__modules__ || {};`);
2476
- lines.push(`window.__modules__["${asset.package}"] = lib;`);
2477
- if (typeof asset.alias !== "undefined") {
2478
- lines.push(`window.__modules__["${asset.alias}"] = lib;`);
2479
- }
2480
- asset.subpaths.map((subpath, index) => {
2481
- lines.push(`window.__modules__["${subpath}"] = lib$${index};`);
2482
- });
2483
- if (typeof asset.global !== "undefined") {
2484
- lines.push(`window["${asset.global}"] = lib;`);
2485
- }
2485
+ lines.push(`export * from "${pkg}";`);
2486
2486
  return lines.join("\n");
2487
2487
  }
2488
2488
  async function compileVendor(assetFolder, vendor, options) {
@@ -2490,14 +2490,14 @@ async function compileVendor(assetFolder, vendor, options) {
2490
2490
  const slug = slugify(name);
2491
2491
  const outfile = `temp/vendor-${slug}.out.js`;
2492
2492
  const tmpfile = `temp/vendor-${slug}.in.js`;
2493
- const source = getAssetSource(vendor, customRequire.toString());
2493
+ const source = getAssetSource(vendor);
2494
2494
  const tsconfig = path$1.resolve(__dirname, "../tsconfig-examples.json");
2495
2495
  await fs.writeFile(tmpfile, source, "utf-8");
2496
2496
  await esbuild$1.build({
2497
2497
  entryPoints: [tmpfile],
2498
2498
  outfile,
2499
2499
  bundle: true,
2500
- format: "iife",
2500
+ format: "esm",
2501
2501
  platform: "browser",
2502
2502
  tsconfig,
2503
2503
  define: {
@@ -2529,16 +2529,11 @@ function normalizeVendorDefinition(vendor) {
2529
2529
  if (typeof vendor === "string") {
2530
2530
  return {
2531
2531
  package: vendor,
2532
- global: void 0,
2533
- expose: "named",
2534
- subpaths: []
2532
+ alias: void 0
2535
2533
  };
2536
2534
  } else {
2537
2535
  return {
2538
2536
  package: vendor.package,
2539
- global: vendor.global,
2540
- expose: vendor.expose ?? "named",
2541
- subpaths: vendor.subpaths ?? [],
2542
2537
  alias: vendor.alias ?? void 0
2543
2538
  };
2544
2539
  }
@@ -2744,7 +2739,7 @@ function createContext(outputFolder, templateLoader) {
2744
2739
  children: [],
2745
2740
  visible: true
2746
2741
  };
2747
- const templateData = {};
2742
+ const templateData = /* @__PURE__ */ new Map();
2748
2743
  return {
2749
2744
  get docs() {
2750
2745
  return docs;
@@ -2796,13 +2791,20 @@ function createContext(outputFolder, templateLoader) {
2796
2791
  sidenav = root;
2797
2792
  },
2798
2793
  getAllTemplateData() {
2799
- return templateData;
2794
+ return Object.fromEntries(templateData.entries());
2800
2795
  },
2801
- getTemplateData(key) {
2802
- return templateData[key];
2796
+ getTemplateData(key, defaultValue) {
2797
+ if (templateData.has(key)) {
2798
+ return templateData.get(key);
2799
+ } else if (defaultValue) {
2800
+ templateData.set(key, defaultValue);
2801
+ return defaultValue;
2802
+ } else {
2803
+ return void 0;
2804
+ }
2803
2805
  },
2804
2806
  setTemplateData(key, value) {
2805
- templateData[key] = value;
2807
+ templateData.set(key, value);
2806
2808
  }
2807
2809
  };
2808
2810
  }
@@ -2923,7 +2925,7 @@ class Generator {
2923
2925
  redirectProcessor(),
2924
2926
  vendorProcessor(assetFolder, this.vendor),
2925
2927
  cssAssetProcessor(assetFolder, this.styles, { cwd }),
2926
- jsAssetProcessor(assetFolder, this.scripts),
2928
+ jsAssetProcessor(assetFolder, this.scripts, this.vendor),
2927
2929
  staticResourcesProcessor(assetFolder, this.resources),
2928
2930
  navigationProcessor(),
2929
2931
  nunjucksProcessor({