@forsakringskassan/docs-generator 2.15.7 → 2.16.1

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.
@@ -3,10 +3,10 @@
3
3
  var path$1 = require('node:path');
4
4
  var esbuild = require('esbuild');
5
5
  var vue = require('vue');
6
- var vue3 = require('./vue3-BCT8XWie.js');
6
+ var vue3 = require('./vue3-B1yNeGmz.js');
7
7
  var path = require('node:path/posix');
8
8
  require('@vue/compiler-sfc');
9
- require('./vendor-Bxk8vVJ2.js');
9
+ require('./vendor-BeoVq2Sv.js');
10
10
  require('node:url');
11
11
  require('fs');
12
12
  require('node:fs');
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var vendor = require('./vendor-Bxk8vVJ2.js');
3
+ var vendor = require('./vendor-BeoVq2Sv.js');
4
4
  var path = require('node:path/posix');
5
5
  var path$1 = require('node:path');
6
6
  require('crypto');
@@ -8,7 +8,7 @@ var crypto = require('node:crypto');
8
8
  require('node:child_process');
9
9
  var fs = require('node:fs');
10
10
  var vue = require('vue');
11
- var vue3 = require('./vue3-BCT8XWie.js');
11
+ var vue3 = require('./vue3-B1yNeGmz.js');
12
12
 
13
13
  function findDocument(haystack, needle) {
14
14
  const match = haystack.find((it) => {
@@ -26,6 +26,18 @@ function findDocument(haystack, needle) {
26
26
  return match ?? null;
27
27
  }
28
28
 
29
+ function findTag(tags, tag) {
30
+ const match = tags.find((it) => it === tag || it.startsWith(`${tag}=`));
31
+ if (!match) {
32
+ return null;
33
+ }
34
+ if (match === tag) {
35
+ return { tag, value: null };
36
+ } else {
37
+ return { tag, value: match.slice(tag.length + 1) };
38
+ }
39
+ }
40
+
29
41
  const replacements = {
30
42
  \u00E5: "a",
31
43
  \u00E4: "a",
@@ -68,6 +80,11 @@ function getOutputFilePath(outputFolder, fileInfo) {
68
80
  return normalizePath(outputFolder, path, outputName);
69
81
  }
70
82
 
83
+ function hasTag(tags, tag) {
84
+ const match = tags.find((it) => it === tag || it.startsWith(`${tag}=`));
85
+ return Boolean(match);
86
+ }
87
+
71
88
  function parseImport(raw) {
72
89
  const comments = [];
73
90
  const stripped = raw.replace(/<!--.*?-->/gms, (match) => {
@@ -518,6 +535,23 @@ function getStandalonePath(output) {
518
535
  const { dir, name } = path$1.parse(output);
519
536
  return path$1.join(dir, `${name}.html`);
520
537
  }
538
+ function getSource(content, language, tags, { namedExamples }) {
539
+ const compare = findTag(tags, "compare");
540
+ if (compare && compare.value !== null) {
541
+ const reference = namedExamples.get(compare.value);
542
+ if (!reference) {
543
+ throw new Error(
544
+ `Failed to find referenced example "${compare.value}"`
545
+ );
546
+ }
547
+ const diff = vendor.createTwoFilesPatch("a", "b", reference.content, content).split("\n").slice(3).filter((it) => !it.startsWith("@@")).join("\n");
548
+ return {
549
+ source: diff,
550
+ language: "diff"
551
+ };
552
+ }
553
+ return { source: content, language };
554
+ }
521
555
  function codePreview(options) {
522
556
  const { generateExample } = options;
523
557
  return (md) => {
@@ -525,16 +559,33 @@ function codePreview(options) {
525
559
  };
526
560
  function fence(_md, tokens, idx, _options, env) {
527
561
  const { fileInfo } = env;
528
- const { content: source, info, map } = tokens[idx];
529
- const { language, tags: rawTags } = parseInfostring(info);
530
- if (language === "mermaid") {
562
+ const { content: rawContent, info, map } = tokens[idx];
563
+ const { language: rawLanguage, tags: rawTags } = parseInfostring(info);
564
+ const name = findTag(rawTags, "name")?.value;
565
+ if (name) {
566
+ env.namedExamples.set(name, {
567
+ name,
568
+ tags: rawTags,
569
+ content: rawContent
570
+ });
571
+ }
572
+ if (hasTag(rawTags, "hidden")) {
573
+ return "";
574
+ }
575
+ if (rawLanguage === "mermaid") {
531
576
  return (
532
577
  /* HTML */
533
578
  `
534
- <pre class="mermaid">${htmlencode(source)}</pre>
579
+ <pre class="mermaid">${htmlencode(rawContent)}</pre>
535
580
  `
536
581
  );
537
582
  }
583
+ const { source, language } = getSource(
584
+ rawContent,
585
+ rawLanguage,
586
+ rawTags,
587
+ env
588
+ );
538
589
  const example = generateExample({
539
590
  source,
540
591
  language,
@@ -558,12 +609,12 @@ function codePreview(options) {
558
609
  const showFullscreen = Boolean(standalonePath) && fullscreen;
559
610
  const testIdAttr = testId ? `data-test="${testId}"` : "";
560
611
  const filteredTags = tags.filter((it) => {
561
- if (it.startsWith("test-id=")) {
612
+ if (it.startsWith("test-id=") || it.startsWith("name") || it.startsWith("compare")) {
562
613
  return false;
563
614
  }
564
615
  return true;
565
616
  });
566
- const dataTagsAttr = filteredTags.length > 0 ? `data-tags=${filteredTags.join(" ")}` : "";
617
+ const dataTagsAttr = filteredTags.length > 0 ? `data-tags="${htmlencode(filteredTags.join(" "))}"` : "";
567
618
  if (liveExample) {
568
619
  return (
569
620
  /* HTML */
@@ -983,7 +1034,8 @@ function createMarkdownRenderer(options) {
983
1034
  path: "",
984
1035
  outputName: false
985
1036
  },
986
- ids: /* @__PURE__ */ new Set()
1037
+ ids: /* @__PURE__ */ new Set(),
1038
+ namedExamples: /* @__PURE__ */ new Map()
987
1039
  };
988
1040
  const included = /* @__PURE__ */ new Set();
989
1041
  const md = vendor.MarkdownIt({
@@ -1028,9 +1080,11 @@ function createMarkdownRenderer(options) {
1028
1080
 
1029
1081
  exports.SoftError = SoftError;
1030
1082
  exports.createMarkdownRenderer = createMarkdownRenderer;
1083
+ exports.findTag = findTag;
1031
1084
  exports.generateExample = generateExample;
1032
1085
  exports.generateId = generateId;
1033
1086
  exports.getFingerprint = getFingerprint;
1034
1087
  exports.getOutputFilePath = getOutputFilePath;
1088
+ exports.hasTag = hasTag;
1035
1089
  exports.normalizePath = normalizePath;
1036
1090
  exports.parseInfostring = parseInfostring;
package/dist/index.d.ts CHANGED
@@ -299,6 +299,7 @@ export declare interface Manifest {
299
299
  anchor: string;
300
300
  }>;
301
301
  examples: Array<{
302
+ name?: string;
302
303
  selector: string;
303
304
  language: string;
304
305
  tags: string[];
package/dist/index.js CHANGED
@@ -2,13 +2,14 @@
2
2
 
3
3
  var fs = require('node:fs/promises');
4
4
  var path = require('node:path/posix');
5
- var vendor = require('./vendor-Bxk8vVJ2.js');
5
+ var vendor = require('./vendor-BeoVq2Sv.js');
6
6
  var path$1 = require('node:path');
7
7
  var require$$1 = require('crypto');
8
8
  require('node:crypto');
9
- var createMarkdownRenderer = require('./create-markdown-renderer-B5UrByJ_.js');
9
+ var createMarkdownRenderer = require('./create-markdown-renderer-CuMSwaNA.js');
10
10
  var node_child_process = require('node:child_process');
11
11
  var util = require('node:util');
12
+ var codeFrame = require('@babel/code-frame');
12
13
  var vueDocgenApi = require('vue-docgen-api');
13
14
  var fs$1 = require('node:fs');
14
15
  var sass = require('sass');
@@ -43,7 +44,7 @@ require('tls');
43
44
  require('tty');
44
45
  require('querystring');
45
46
  require('vue');
46
- require('./vue3-BCT8XWie.js');
47
+ require('./vue3-B1yNeGmz.js');
47
48
 
48
49
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
49
50
  function toArray$2(value) {
@@ -123,13 +124,16 @@ const matchHeading = /^(#+)(.*)$/gm;
123
124
  function getHeadings(text) {
124
125
  return Array.from(text.matchAll(matchHeading), parseHeading);
125
126
  }
127
+ function cleanTitle(text) {
128
+ return text.trim().replaceAll("`", "");
129
+ }
126
130
  function parseHeading(match) {
127
131
  const [, prefix, text] = match;
128
132
  const rank = prefix.length;
129
133
  const id = createMarkdownRenderer.generateId(text);
130
134
  return {
131
135
  rank,
132
- title: text.trim(),
136
+ title: cleanTitle(text),
133
137
  anchor: id
134
138
  };
135
139
  }
@@ -269,7 +273,10 @@ md$2.renderer.rules.fence = (tokens, idx, _options, collected) => {
269
273
  if (language === "import") {
270
274
  return "";
271
275
  }
276
+ const nameTag = tags.find((it) => it.startsWith("name="));
277
+ const name = nameTag ? slugify(nameTag.slice("name=".length)) : undefined;
272
278
  collected.push({
279
+ name,
273
280
  content,
274
281
  language,
275
282
  tags
@@ -336,7 +343,7 @@ function extractExamplesProcessor(options) {
336
343
  for (const example of examples) {
337
344
  const suffix = getSuffix(example.tags);
338
345
  const extension = getExtension(example.language);
339
- const filename = `example-${String(n++)}${suffix}.${extension}`;
346
+ const filename = `example-${example.name ?? String(n++)}${suffix}.${extension}`;
340
347
  const filePath = path.join(dir, filename);
341
348
  await fs.writeFile(filePath, example.content, "utf-8");
342
349
  total++;
@@ -357,7 +364,12 @@ md$1.renderer.rules.fence = (tokens, idx, _options, collected) => {
357
364
  if (language === "import") {
358
365
  extension = content.split(".").at(-1)?.trim();
359
366
  }
367
+ if (createMarkdownRenderer.hasTag(tags, "hidden")) {
368
+ return "";
369
+ }
370
+ const name = createMarkdownRenderer.findTag(tags, "name")?.value ?? undefined;
360
371
  collected.push({
372
+ name,
361
373
  selector: `#example-${fingerprint}`,
362
374
  language: extension ?? language,
363
375
  tags
@@ -872,6 +884,79 @@ function defineSources(sources) {
872
884
  return sources;
873
885
  }
874
886
 
887
+ const documentAttributeKeys = [
888
+ "title",
889
+ "short-title",
890
+ "layout",
891
+ "name",
892
+ "alias",
893
+ "status",
894
+ "visible",
895
+ "include",
896
+ "component",
897
+ "href",
898
+ "sortorder",
899
+ "redirect_from"
900
+ ];
901
+
902
+ const threshold = 3;
903
+ const suggestions = {
904
+ hidden: "visible"
905
+ };
906
+ function findLocation(content, attr) {
907
+ const match = content.match(/^---\n(.*?)^---/ms);
908
+ if (!match || match.index !== 0) {
909
+ return null;
910
+ }
911
+ const yaml = match[1];
912
+ const lines = yaml.split("\n");
913
+ const index = lines.findIndex((it) => it.startsWith(`${attr}:`));
914
+ if (index < 0) {
915
+ return null;
916
+ }
917
+ const blockBegin = 2;
918
+ return {
919
+ start: { line: index + blockBegin, column: 1 },
920
+ end: { line: index + blockBegin, column: 1 + attr.length }
921
+ };
922
+ }
923
+ function getSuggestion(attribute) {
924
+ const manual = suggestions[attribute];
925
+ if (manual) {
926
+ return [manual, 0];
927
+ }
928
+ const closestKey = vendor.closest(attribute, documentAttributeKeys);
929
+ const d = vendor.distance(attribute, closestKey);
930
+ return [closestKey, d];
931
+ }
932
+ class AttributeError extends Error {
933
+ attribute;
934
+ content;
935
+ constructor(options) {
936
+ const { attribute, filePath, content } = options;
937
+ super(`Unknown attribute "${attribute}" in "${filePath}"`);
938
+ this.name = "AttributeError";
939
+ this.attribute = attribute;
940
+ this.content = content;
941
+ }
942
+ prettyError() {
943
+ const { attribute, content, message } = this;
944
+ const [closestMatch, d] = getSuggestion(attribute);
945
+ const suggestion = d <= threshold ? `Did you mean to use "${closestMatch}"?` : `Unknown attribute "${attribute}"`;
946
+ const location = findLocation(content, attribute);
947
+ if (location) {
948
+ const codeframe = codeFrame.codeFrameColumns(content, location, {
949
+ message: suggestion
950
+ });
951
+ return [message, "", codeframe].join("\n");
952
+ } else if (d <= threshold) {
953
+ return [message, "", suggestion].join("\n");
954
+ } else {
955
+ return message;
956
+ }
957
+ }
958
+ }
959
+
875
960
  function toArray$1(value) {
876
961
  return Array.isArray(value) ? value : [value];
877
962
  }
@@ -906,26 +991,44 @@ function getBadge(attrs) {
906
991
  return "info";
907
992
  }
908
993
  }
909
- function getComponentAlias(attrs) {
910
- if (attrs.component) {
911
- return toArray$1(attrs.component).map((it) => `component:${it}`);
994
+ function validateAttributes(attributes, filePath, content) {
995
+ for (const key of Object.keys(attributes)) {
996
+ if (documentAttributeKeys.includes(key)) {
997
+ continue;
998
+ }
999
+ throw new AttributeError({
1000
+ attribute: key,
1001
+ filePath,
1002
+ content
1003
+ });
1004
+ }
1005
+ }
1006
+ function normalizeComponent(value) {
1007
+ if (typeof value === "string") {
1008
+ return {
1009
+ name: value
1010
+ };
912
1011
  } else {
913
- return [];
1012
+ return value;
1013
+ }
1014
+ }
1015
+ function getComponentAlias(value) {
1016
+ const { name } = normalizeComponent(value);
1017
+ return `component:${name}`;
1018
+ }
1019
+ function* getDocumentAlias(attrs) {
1020
+ if (attrs.alias) {
1021
+ yield* toArray$1(attrs.alias);
1022
+ }
1023
+ if (attrs.component) {
1024
+ yield* toArray$1(attrs.component).map(getComponentAlias);
914
1025
  }
915
1026
  }
916
1027
  function getComponent(attrs) {
917
1028
  if (!attrs.component) {
918
1029
  return undefined;
919
1030
  }
920
- return toArray$1(attrs.component).map((it) => {
921
- if (typeof it === "string") {
922
- return {
923
- name: it
924
- };
925
- } else {
926
- return it;
927
- }
928
- });
1031
+ return toArray$1(attrs.component).map(normalizeComponent);
929
1032
  }
930
1033
  function parseFile$1(filePath, basePath, content) {
931
1034
  const relative = basePath ? path$1.relative(basePath, createMarkdownRenderer.normalizePath(filePath)) : createMarkdownRenderer.normalizePath(filePath);
@@ -938,10 +1041,11 @@ function parseFile$1(filePath, basePath, content) {
938
1041
  const urlpath = parsed.dir;
939
1042
  const outline = getDocumentOutline(blocks.body);
940
1043
  const include = attributes.include ?? true;
1044
+ validateAttributes(attributes, filePath, content);
941
1045
  return {
942
1046
  id: `fs:${filePath.replace(/\\/g, "/")}`,
943
1047
  name,
944
- alias: [...getComponentAlias(attributes)],
1048
+ alias: Array.from(getDocumentAlias(attributes)),
945
1049
  visible: attributes.visible ?? true,
946
1050
  attributes: {
947
1051
  title: attributes.title ?? name,
@@ -974,6 +1078,36 @@ async function frontMatterFileReader(filePath, basePath) {
974
1078
 
975
1079
  const EMPTY_CHAR = "&#8208;";
976
1080
  const EM_DASH = "&#8212;";
1081
+ function getPropSlotDeprecated(prop) {
1082
+ const tags = prop.tags;
1083
+ if (!tags) {
1084
+ return EMPTY_CHAR;
1085
+ }
1086
+ const tag = tags["deprecated"]?.[0];
1087
+ if (!tag?.description) {
1088
+ return EMPTY_CHAR;
1089
+ }
1090
+ if (tag.description === true) {
1091
+ return "true";
1092
+ } else {
1093
+ return tag.description;
1094
+ }
1095
+ }
1096
+ function getEventDeprecated(event) {
1097
+ const tags = event.tags;
1098
+ if (!tags) {
1099
+ return EMPTY_CHAR;
1100
+ }
1101
+ const tag = tags.find((it) => it.title === "deprecated");
1102
+ if (!tag?.content) {
1103
+ return EMPTY_CHAR;
1104
+ }
1105
+ if (tag.content === true) {
1106
+ return "true";
1107
+ } else {
1108
+ return tag.content;
1109
+ }
1110
+ }
977
1111
  function translateProps(props) {
978
1112
  const translatedProps = [];
979
1113
  for (const prop of props) {
@@ -982,7 +1116,8 @@ function translateProps(props) {
982
1116
  description: prop.description ?? EMPTY_CHAR,
983
1117
  type: prop.type?.name ?? EMPTY_CHAR,
984
1118
  required: prop.required ? "true" : "false",
985
- default: prop.defaultValue?.value ?? EMPTY_CHAR
1119
+ default: prop.defaultValue?.value ?? EMPTY_CHAR,
1120
+ deprecated: getPropSlotDeprecated(prop)
986
1121
  };
987
1122
  translatedProps.push(translatedProp);
988
1123
  }
@@ -994,7 +1129,8 @@ function translateEvents(events) {
994
1129
  const translatedEvent = {
995
1130
  name: event.name,
996
1131
  description: event.description ?? EMPTY_CHAR,
997
- properties: translateEventProperties(event)
1132
+ properties: translateEventProperties(event),
1133
+ deprecated: getEventDeprecated(event)
998
1134
  };
999
1135
  translatedEvents.push(translatedEvent);
1000
1136
  }
@@ -1028,7 +1164,8 @@ function translateSlots(slots) {
1028
1164
  const translatedSlot = {
1029
1165
  name: slot.name,
1030
1166
  description: slot.description ?? EMPTY_CHAR,
1031
- bindings: translateSlotBindings(slot)
1167
+ bindings: translateSlotBindings(slot),
1168
+ deprecated: getPropSlotDeprecated(slot)
1032
1169
  };
1033
1170
  translatedSlots.push(translatedSlot);
1034
1171
  }
@@ -1040,7 +1177,10 @@ function translateSlotBindings(slot) {
1040
1177
  }
1041
1178
  const translatedBindings = [];
1042
1179
  for (const binding of slot.bindings) {
1043
- translatedBindings.push(binding.name ? binding.name : EMPTY_CHAR);
1180
+ const name = binding.name ?? EMPTY_CHAR;
1181
+ const type = binding.type ? `: ${binding.type.name}` : "";
1182
+ const description = binding.description ? ` ${EM_DASH} ${binding.description}` : "";
1183
+ translatedBindings.push(`${name}${type}${description}`);
1044
1184
  }
1045
1185
  return translatedBindings.join("\n");
1046
1186
  }
package/dist/markdown.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var createMarkdownRenderer = require('./create-markdown-renderer-B5UrByJ_.js');
4
- require('./vendor-Bxk8vVJ2.js');
3
+ var createMarkdownRenderer = require('./create-markdown-renderer-CuMSwaNA.js');
4
+ require('./vendor-BeoVq2Sv.js');
5
5
  require('node:url');
6
6
  require('node:path');
7
7
  require('fs');
@@ -37,7 +37,7 @@ require('querystring');
37
37
  require('node:path/posix');
38
38
  require('node:crypto');
39
39
  require('vue');
40
- require('./vue3-BCT8XWie.js');
40
+ require('./vue3-B1yNeGmz.js');
41
41
 
42
42
 
43
43
 
@@ -334,6 +334,17 @@ var require_semver = __commonJS({
334
334
  // preminor will bump the version up to the next minor release, and immediately
335
335
  // down to pre-release. premajor and prepatch work the same way.
336
336
  inc(release, identifier, identifierBase) {
337
+ if (release.startsWith("pre")) {
338
+ if (!identifier && identifierBase === false) {
339
+ throw new Error("invalid increment argument: identifier is empty");
340
+ }
341
+ if (identifier) {
342
+ const match = `-${identifier}`.match(this.options.loose ? re[t.PRERELEASELOOSE] : re[t.PRERELEASE]);
343
+ if (!match || match[1] !== identifier) {
344
+ throw new Error(`invalid identifier: ${identifier}`);
345
+ }
346
+ }
347
+ }
337
348
  switch (release) {
338
349
  case "premajor":
339
350
  this.prerelease.length = 0;
@@ -361,6 +372,12 @@ var require_semver = __commonJS({
361
372
  }
362
373
  this.inc("pre", identifier, identifierBase);
363
374
  break;
375
+ case "release":
376
+ if (this.prerelease.length === 0) {
377
+ throw new Error(`version ${this.raw} is not a prerelease`);
378
+ }
379
+ this.prerelease.length = 0;
380
+ break;
364
381
  case "major":
365
382
  if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) {
366
383
  this.major++;
@@ -386,9 +403,6 @@ var require_semver = __commonJS({
386
403
  // 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
387
404
  case "pre": {
388
405
  const base = Number(identifierBase) ? 1 : 0;
389
- if (!identifier && identifierBase === false) {
390
- throw new Error("invalid increment argument: identifier is empty");
391
- }
392
406
  if (this.prerelease.length === 0) {
393
407
  this.prerelease = [base];
394
408
  } else {
@@ -523,13 +537,12 @@ var require_diff = __commonJS({
523
537
  if (!lowVersion.patch && !lowVersion.minor) {
524
538
  return "major";
525
539
  }
526
- if (highVersion.patch) {
540
+ if (lowVersion.compareMain(highVersion) === 0) {
541
+ if (lowVersion.minor && !lowVersion.patch) {
542
+ return "minor";
543
+ }
527
544
  return "patch";
528
545
  }
529
- if (highVersion.minor) {
530
- return "minor";
531
- }
532
- return "major";
533
546
  }
534
547
  const prefix = highHasPre ? "pre" : "";
535
548
  if (v1.major !== v2.major) {
@@ -831,6 +831,18 @@ h1 code {
831
831
  font-weight: 400;
832
832
  }
833
833
 
834
+ h1 code,
835
+ h2 code,
836
+ h3 code,
837
+ h4 code,
838
+ h5 code,
839
+ h6 code {
840
+ font-size: inherit;
841
+ margin: 0;
842
+ padding: 0;
843
+ text-decoration: inherit;
844
+ }
845
+
834
846
  #content a:not(.code-preview a) {
835
847
  color: var(--docs-text-color-default);
836
848
  }
@@ -831,6 +831,18 @@ h1 code {
831
831
  font-weight: 400;
832
832
  }
833
833
 
834
+ h1 code,
835
+ h2 code,
836
+ h3 code,
837
+ h4 code,
838
+ h5 code,
839
+ h6 code {
840
+ font-size: inherit;
841
+ margin: 0;
842
+ padding: 0;
843
+ text-decoration: inherit;
844
+ }
845
+
834
846
  #content a:not(.code-preview a) {
835
847
  color: var(--docs-text-color-default);
836
848
  }
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.49.1"
8
+ "packageVersion": "7.49.2"
9
9
  }
10
10
  ]
11
11
  }