@forsakringskassan/docs-generator 3.5.0 → 3.6.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.
@@ -1 +1 @@
1
- {"version":3,"file":"format-code.worker-Y0WP8Vzk.mjs","sources":["../src/utils/format-code.worker.ts"],"sourcesContent":["import { type Options, format as prettier, resolveConfig } from \"prettier\";\nimport { runAsWorker } from \"synckit\";\n\nconst configCache = new Map<string, Options | null>();\n\nasync function getConfig(filepath: string): Promise<Options | null> {\n const cached = configCache.get(filepath);\n if (cached !== undefined) {\n return cached;\n }\n const options = await resolveConfig(filepath);\n configCache.set(filepath, options);\n return options;\n}\n\n/**\n * @internal\n */\nexport async function formatCode(\n source: string,\n filepath: string,\n): Promise<string> {\n const options = await getConfig(filepath);\n const formatted = await prettier(source, { ...options, filepath });\n return formatted.trim();\n}\n\n/* eslint-disable-next-line unicorn/no-top-level-side-effects -- required for worker to function */\nrunAsWorker(formatCode);\n"],"names":["prettier"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,MAAM,WAAA,uBAAkB,GAAA,EAA4B;AAEpD,eAAe,UAAU,QAAA,EAA2C;AAChE,EAAA,MAAM,MAAA,GAAS,WAAA,CAAY,GAAA,CAAI,QAAQ,CAAA;AACvC,EAAA,IAAI,WAAW,MAAA,EAAW;AACtB,IAAA,OAAO,MAAA;AAAA,EACX;AACA,EAAA,MAAM,OAAA,GAAU,MAAM,aAAA,CAAc,QAAQ,CAAA;AAC5C,EAAA,WAAA,CAAY,GAAA,CAAI,UAAU,OAAO,CAAA;AACjC,EAAA,OAAO,OAAA;AACX;AAKA,eAAsB,UAAA,CAClB,QACA,QAAA,EACe;AACf,EAAA,MAAM,OAAA,GAAU,MAAM,SAAA,CAAU,QAAQ,CAAA;AACxC,EAAA,MAAM,SAAA,GAAY,MAAMA,OAAA,CAAS,MAAA,EAAQ,EAAE,GAAG,OAAA,EAAS,UAAU,CAAA;AACjE,EAAA,OAAO,UAAU,IAAA,EAAK;AAC1B;AAGA,WAAA,CAAY,UAAU,CAAA;;;;"}
1
+ {"version":3,"file":"format-code.worker-BmU4wqqU.mjs","sources":["../src/utils/format-code.worker.ts"],"sourcesContent":["import { type Options, format as prettier, resolveConfig } from \"prettier\";\nimport { runAsWorker } from \"synckit\";\n\nconst configCache = new Map<string, Options | null>();\n\nasync function getConfig(filepath: string): Promise<Options | null> {\n const cached = configCache.get(filepath);\n if (cached !== undefined) {\n return cached;\n }\n const options = await resolveConfig(filepath);\n configCache.set(filepath, options);\n return options;\n}\n\n/**\n * @internal\n */\nexport async function formatCode(\n source: string,\n filepath: string,\n): Promise<string> {\n const options = await getConfig(filepath);\n const formatted = await prettier(source, { ...options, filepath });\n return formatted.trim();\n}\n\n/* eslint-disable-next-line unicorn/no-top-level-side-effects -- required for worker to function */\nrunAsWorker(formatCode);\n"],"names":["prettier"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,MAAM,WAAA,uBAAkB,GAAA,EAA4B;AAEpD,eAAe,UAAU,QAAA,EAA2C;AAChE,EAAA,MAAM,MAAA,GAAS,WAAA,CAAY,GAAA,CAAI,QAAQ,CAAA;AACvC,EAAA,IAAI,WAAW,MAAA,EAAW;AACtB,IAAA,OAAO,MAAA;AAAA,EACX;AACA,EAAA,MAAM,OAAA,GAAU,MAAM,aAAA,CAAc,QAAQ,CAAA;AAC5C,EAAA,WAAA,CAAY,GAAA,CAAI,UAAU,OAAO,CAAA;AACjC,EAAA,OAAO,OAAA;AACX;AAKA,eAAsB,UAAA,CAClB,QACA,QAAA,EACe;AACf,EAAA,MAAM,OAAA,GAAU,MAAM,SAAA,CAAU,QAAQ,CAAA;AACxC,EAAA,MAAM,SAAA,GAAY,MAAMA,OAAA,CAAS,MAAA,EAAQ,EAAE,GAAG,OAAA,EAAS,UAAU,CAAA;AACjE,EAAA,OAAO,UAAU,IAAA,EAAK;AAC1B;AAGA,WAAA,CAAY,UAAU,CAAA;;;;"}
package/dist/index.d.mts CHANGED
@@ -616,6 +616,68 @@ export declare interface PackageJson {
616
616
  };
617
617
  }
618
618
 
619
+ /**
620
+ * Generates links to code playgrounds.
621
+ *
622
+ * @public
623
+ */
624
+ export declare function playgroundProcessor(options: PlaygroundProcessorOptions): Processor;
625
+
626
+ /**
627
+ * Options for a playground entry.
628
+ *
629
+ * @public
630
+ */
631
+ export declare interface PlaygroundProcessorEntry {
632
+ /**
633
+ * Unique identifier for this playground.
634
+ */
635
+ readonly id: string;
636
+ /**
637
+ * Name of template variable with the playground URL to inject.
638
+ *
639
+ * If unspecified, no template variable will be available.
640
+ */
641
+ readonly variable?: string;
642
+ /**
643
+ * The URL format.
644
+ *
645
+ * The following placeholders are available:
646
+ *
647
+ * - `base64`: Base64 encoded payload (use "atou" to decode unicode codepoints).
648
+ * - `zlibBase64`: zlib base64 encoded payload.
649
+ */
650
+ readonly urlFormat: string;
651
+ /**
652
+ * Path to a folder with files to inject into the playground url.
653
+ *
654
+ * If unspecified, no files will be injected by default.
655
+ */
656
+ readonly folder?: string;
657
+ /**
658
+ * Serialize the files to a string for using in the url generation.
659
+ *
660
+ * Default is `JSON.stringify()`.
661
+ */
662
+ serialize?(this: void, context: {
663
+ readonly files: Map<string, string>;
664
+ }): string | Promise<string>;
665
+ }
666
+
667
+ /**
668
+ * Options for {@link playgroundProcessor}.
669
+ *
670
+ * @public
671
+ */
672
+ export declare interface PlaygroundProcessorOptions extends ProcessorOptions {
673
+ /**
674
+ * List of playgrounds available.
675
+ *
676
+ * Default is empty array (no playgrounds enabled)
677
+ */
678
+ readonly entries?: PlaygroundProcessorEntry[];
679
+ }
680
+
619
681
  /**
620
682
  * @public
621
683
  */
package/dist/index.mjs CHANGED
@@ -3,12 +3,12 @@ import { createRequire as $createRequire } from "node:module";
3
3
  const require = $createRequire(import.meta.url);
4
4
 
5
5
  import { ApiItemKind, ApiModel } from '@microsoft/api-extractor-model';
6
- import { t as ts, Z as Ze, M as MarkdownIt, d as dedent, g as closest, h as distance, i as fm, j as isCI, m as moduleImporter, k as cliProgress, l as tinylr, w as watch, n as createInstance, o as fse, p as inter } from './vendor-BeEO8YMF.mjs';
6
+ import { t as ts, Z as Ze, M as MarkdownItCallable, s as strToU8, z as zlibSync, g as strFromU8, d as dedent, h as closest, i as distance, j as fm, k as isCI, m as moduleImporter, l as cliProgress, n as tinylr, w as watch, o as createInstance, p as fse, q as inter } from './vendor-C6ojgz0W.mjs';
7
7
  import path__default from 'node:path';
8
8
  import crypto from 'node:crypto';
9
9
  import path from 'node:path/posix';
10
10
  import { exec, execSync } from 'node:child_process';
11
- import { g as generateId, f as formatCode, p as parseInfostring, i as isDocumentPage, n as normalizePath, a as getFingerprint, h as hasTag, b as parseImport, d as findTag, e as getOutputFilePath, j as htmlencode, k as filePath, c as createMarkdownRenderer, l as generateExample } from './create-markdown-renderer-BuSu2H7E.mjs';
11
+ import { g as generateId, f as formatCode, p as parseInfostring, i as isDocumentPage, n as normalizePath, a as getFingerprint, h as hasTag, b as parseImport, d as findTag, e as getOutputFilePath, j as htmlencode, k as filePath, c as createMarkdownRenderer, l as generateExample } from './create-markdown-renderer-BjMECUwq.mjs';
12
12
  import { DocExcerpt } from '@microsoft/tsdoc';
13
13
  import fs from 'node:fs/promises';
14
14
  import util, { promisify, styleText } from 'node:util';
@@ -586,8 +586,9 @@ const documentAttributeKeys = [
586
586
  "redirect_from"
587
587
  ];
588
588
 
589
- const md$6 = MarkdownIt();
590
- md$6.renderer.rules.fence = (tokens, idx, _options, collected) => {
589
+ const md$6 = MarkdownItCallable();
590
+ md$6.renderer.rules.fence = (tokens, idx, _options, rawEnv) => {
591
+ const { collected } = rawEnv;
591
592
  const { content, info } = tokens[idx];
592
593
  const { language, tags } = parseInfostring(info);
593
594
  if (language === "import") {
@@ -608,7 +609,7 @@ function findExamples$1(doc) {
608
609
  return [];
609
610
  }
610
611
  const collected = [];
611
- md$6.render(doc.body, collected);
612
+ md$6.render(doc.body, { collected });
612
613
  return collected;
613
614
  }
614
615
  function getSuffix(tags) {
@@ -674,7 +675,7 @@ function extractExamplesProcessor(options) {
674
675
  };
675
676
  }
676
677
 
677
- const md$5 = MarkdownIt();
678
+ const md$5 = MarkdownItCallable();
678
679
  md$5.renderer.rules.fence = (tokens, idx, _options, env) => {
679
680
  const { collected, exampleFileMatcher } = env;
680
681
  const { content, info, map } = tokens[idx];
@@ -866,6 +867,88 @@ const versionBannerProcessor = util.deprecate(
866
867
  "versionBannerProcessor() is deprecated, use motdProcessor() instead"
867
868
  );
868
869
 
870
+ function utoa(value) {
871
+ return btoa(unescape(encodeURIComponent(value)));
872
+ }
873
+ const encoder = {
874
+ base64(value) {
875
+ return utoa(value);
876
+ },
877
+ zlibBase64(value) {
878
+ const buffer = strToU8(value);
879
+ const zipped = zlibSync(buffer, { level: 9 });
880
+ const binary = strFromU8(zipped);
881
+ return btoa(binary);
882
+ }
883
+ };
884
+ function defaultSerializer(context) {
885
+ const { files } = context;
886
+ return JSON.stringify(Object.fromEntries(files));
887
+ }
888
+ function normalizeEntry(entry) {
889
+ return {
890
+ variable: null,
891
+ folder: null,
892
+ ...entry,
893
+ serialize: entry.serialize ?? defaultSerializer
894
+ };
895
+ }
896
+ function normalizeEntries(entries) {
897
+ if (!entries) {
898
+ return [];
899
+ }
900
+ return entries.map(normalizeEntry);
901
+ }
902
+ async function getFiles(entry) {
903
+ const { folder: cwd } = entry;
904
+ const result = /* @__PURE__ */ new Map();
905
+ if (!cwd) {
906
+ return result;
907
+ }
908
+ const filenames = await Array.fromAsync(fs.glob("**", { cwd }));
909
+ const sorted = filenames.toSorted((a, b) => a.localeCompare(b));
910
+ for (const filename of sorted) {
911
+ const filePath = path__default.join(cwd, filename);
912
+ const st = await fs.lstat(filePath);
913
+ if (!st.isFile()) {
914
+ continue;
915
+ }
916
+ const content = await fs.readFile(filePath, "utf8");
917
+ result.set(filename, content);
918
+ }
919
+ return result;
920
+ }
921
+ function encode(key, value) {
922
+ const fn = encoder[key] ?? (() => void 0);
923
+ return fn(value);
924
+ }
925
+ async function generateUrl(entry) {
926
+ const files = await getFiles(entry);
927
+ const payload = await entry.serialize({ files });
928
+ const lazyEvaluation = new Proxy({}, { get: (_, k) => encode(k, payload) });
929
+ return encodeURI(interpolate(entry.urlFormat, lazyEvaluation));
930
+ }
931
+ function playgroundProcessor(options) {
932
+ const { enabled = true } = options;
933
+ const entries = normalizeEntries(options.entries);
934
+ return {
935
+ after: "generate-docs",
936
+ name: "playground-processor",
937
+ async handler(context) {
938
+ if (!enabled) {
939
+ return;
940
+ }
941
+ for (const entry of entries) {
942
+ if (!entry.variable) {
943
+ continue;
944
+ }
945
+ const url = await generateUrl(entry);
946
+ context.setTemplateData(entry.variable, url);
947
+ }
948
+ }
949
+ };
950
+ }
951
+
869
952
  function dump(value) {
870
953
  return `<pre>${JSON.stringify(value, null, 2)}</pre>`;
871
954
  }
@@ -1507,6 +1590,7 @@ function searchProcessor() {
1507
1590
  }
1508
1591
 
1509
1592
  const availableProcessors = [
1593
+ playgroundProcessor({ entries: [] }),
1510
1594
  cookieProcessor(),
1511
1595
  manifestProcessor(),
1512
1596
  matomoProcessor({ siteId: "", trackerUrl: "" }),
@@ -1888,7 +1972,7 @@ function findTranslations(filename, content) {
1888
1972
  return result;
1889
1973
  }
1890
1974
 
1891
- const md$4 = MarkdownIt();
1975
+ const md$4 = MarkdownItCallable();
1892
1976
  const EMPTY_CHAR$4 = "&#8208;";
1893
1977
  const EM_DASH$2 = `<span role="presentation">&mdash;</span>`;
1894
1978
  function render$5(text) {
@@ -1942,7 +2026,7 @@ function generateEventTable(slug, events) {
1942
2026
  );
1943
2027
  }
1944
2028
 
1945
- const md$3 = MarkdownIt();
2029
+ const md$3 = MarkdownItCallable();
1946
2030
  const EMPTY_CHAR$3 = "&#8208;";
1947
2031
  function render$4(text) {
1948
2032
  return text ? md$3.render(text) : EMPTY_CHAR$3;
@@ -1988,7 +2072,7 @@ function generateModelTable(slug, models) {
1988
2072
  );
1989
2073
  }
1990
2074
 
1991
- const md$2 = MarkdownIt();
2075
+ const md$2 = MarkdownItCallable();
1992
2076
  const EMPTY_CHAR$2 = "&#8208;";
1993
2077
  function render$3(text) {
1994
2078
  return text ? md$2.render(text) : EMPTY_CHAR$2;
@@ -2034,7 +2118,7 @@ function generatePropTable(slug, props) {
2034
2118
  );
2035
2119
  }
2036
2120
 
2037
- const md$1 = MarkdownIt();
2121
+ const md$1 = MarkdownItCallable();
2038
2122
  const EMPTY_CHAR$1 = "&#8208;";
2039
2123
  const EM_DASH$1 = `<span role="presentation">&mdash;</span>`;
2040
2124
  function render$2(text) {
@@ -2088,7 +2172,7 @@ function generateSlotTable(slug, slots) {
2088
2172
  );
2089
2173
  }
2090
2174
 
2091
- const md = MarkdownIt();
2175
+ const md = MarkdownItCallable();
2092
2176
  const EMPTY_CHAR = "&#8208;";
2093
2177
  const EM_DASH = `<span role="presentation">&mdash;</span>`;
2094
2178
  function render$1(text) {
@@ -3975,5 +4059,5 @@ class Generator {
3975
4059
  }
3976
4060
  }
3977
4061
 
3978
- export { Generator, apiExtractorProcessor, availableProcessors, cookieProcessor, defineSources, extractExamplesProcessor, frontMatterFileReader, htmlRedirectProcessor, isRelease, livereloadProcessor, manifestProcessor, matomoProcessor, motdProcessor, navigationFileReader, processorRuntimeName, redirectFileProcessor, searchProcessor, selectableVersionProcessor, sourceUrlProcessor, topnavProcessor, versionBannerProcessor, versionProcessor, vueFileReader };
4062
+ export { Generator, apiExtractorProcessor, availableProcessors, cookieProcessor, defineSources, extractExamplesProcessor, frontMatterFileReader, htmlRedirectProcessor, isRelease, livereloadProcessor, manifestProcessor, matomoProcessor, motdProcessor, navigationFileReader, playgroundProcessor, processorRuntimeName, redirectFileProcessor, searchProcessor, selectableVersionProcessor, sourceUrlProcessor, topnavProcessor, versionBannerProcessor, versionProcessor, vueFileReader };
3979
4063
  //# sourceMappingURL=index.mjs.map