@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.4

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 (102) hide show
  1. package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
  2. package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
  3. package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
  4. package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
  5. package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
  6. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
  7. package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
  8. package/esm/CodeHighlighter/errors.js +248 -400
  9. package/esm/CodeHighlighter/parseControlledCode.js +12 -20
  10. package/esm/CodeProvider/CodeContext.js +3 -3
  11. package/esm/CodeProvider/CodeProvider.js +31 -40
  12. package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
  13. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
  14. package/esm/cli/index.js +1 -1
  15. package/esm/cli/runValidate.js +160 -264
  16. package/esm/createDemoData/createDemoData.js +11 -12
  17. package/esm/createSitemap/createSitemap.js +2 -2
  18. package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
  19. package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
  20. package/esm/pipeline/hastUtils/hastUtils.js +16 -17
  21. package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
  22. package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
  23. package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
  24. package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
  25. package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
  26. package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
  27. package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
  28. package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
  29. package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
  30. package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
  31. package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
  32. package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
  33. package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
  34. package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
  35. package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
  36. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
  37. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
  38. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
  39. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
  40. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
  41. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
  42. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
  43. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
  44. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
  45. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
  46. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
  47. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
  48. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
  49. package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
  50. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
  51. package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
  52. package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
  53. package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
  54. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
  55. package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
  56. package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
  57. package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
  58. package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
  59. package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
  60. package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
  61. package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
  62. package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
  63. package/esm/pipeline/parseSource/addLineGutters.js +33 -45
  64. package/esm/pipeline/parseSource/grammars.js +3 -3
  65. package/esm/pipeline/parseSource/parseSource.js +13 -31
  66. package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
  67. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
  68. package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
  69. package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
  70. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
  71. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
  72. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
  73. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
  74. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
  75. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
  76. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
  77. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
  78. package/esm/useCode/Pre.js +58 -62
  79. package/esm/useCode/useCode.js +59 -61
  80. package/esm/useCode/useCodeUtils.js +54 -63
  81. package/esm/useCode/useCopyFunctionality.js +10 -9
  82. package/esm/useCode/useFileNavigation.js +150 -212
  83. package/esm/useCode/useSourceEditing.js +17 -14
  84. package/esm/useCode/useTransformManagement.js +23 -26
  85. package/esm/useCode/useUIState.js +12 -20
  86. package/esm/useCode/useVariantSelection.js +62 -79
  87. package/esm/useCopier/index.js +29 -56
  88. package/esm/useDemo/createCodeSandbox.js +12 -15
  89. package/esm/useDemo/createStackBlitz.js +14 -20
  90. package/esm/useDemo/exportVariant.js +200 -180
  91. package/esm/useDemo/exportVariantAsCra.js +22 -25
  92. package/esm/useDemo/useDemo.js +80 -84
  93. package/esm/useErrors/ErrorsContext.js +1 -1
  94. package/esm/useErrors/useErrors.js +3 -3
  95. package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
  96. package/esm/usePreference/PreferencesProvider.js +1 -1
  97. package/esm/usePreference/usePreference.js +9 -11
  98. package/esm/useSearch/useSearch.js +290 -387
  99. package/esm/useUrlHashState/useUrlHashState.js +11 -14
  100. package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
  101. package/esm/withDocsInfra/withDocsInfra.js +99 -101
  102. package/package.json +7 -4
@@ -1,4 +1,3 @@
1
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
1
  /**
3
2
  * Interface for rewrite replacement operations.
4
3
  */
@@ -14,78 +13,66 @@ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIt
14
13
  * @returns The source code with import statements rewritten to const declarations
15
14
  */
16
15
  export function rewriteImportsToNull(source, importPathsToRewrite, importResult) {
17
- var replacements = [];
16
+ const replacements = [];
18
17
 
19
18
  // Find all import statements to rewrite
20
- importPathsToRewrite.forEach(function (importPath) {
21
- var importData = importResult[importPath];
19
+ importPathsToRewrite.forEach(importPath => {
20
+ const importData = importResult[importPath];
22
21
  if (importData && importData.positions.length > 0) {
23
22
  // For each position (there should typically be one per import statement)
24
- var _iterator = _createForOfIteratorHelper(importData.positions),
25
- _step;
26
- try {
27
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
28
- var position = _step.value;
29
- // Parse backwards from the quote to find 'import' keyword
30
- var importStart = position.start;
31
- var targetWord = 'import';
32
- while (importStart >= targetWord.length) {
33
- var slice = source.slice(importStart - targetWord.length, importStart);
34
- var prevChar = importStart > targetWord.length ? source[importStart - targetWord.length - 1] : '';
35
- if (slice === targetWord && (!prevChar || /\s/.test(prevChar))) {
36
- importStart -= targetWord.length;
37
- break;
38
- }
39
- importStart -= 1;
23
+ for (const position of importData.positions) {
24
+ // Parse backwards from the quote to find 'import' keyword
25
+ let importStart = position.start;
26
+ const targetWord = 'import';
27
+ while (importStart >= targetWord.length) {
28
+ const slice = source.slice(importStart - targetWord.length, importStart);
29
+ const prevChar = importStart > targetWord.length ? source[importStart - targetWord.length - 1] : '';
30
+ if (slice === targetWord && (!prevChar || /\s/.test(prevChar))) {
31
+ importStart -= targetWord.length;
32
+ break;
40
33
  }
34
+ importStart -= 1;
35
+ }
41
36
 
42
- // Parse forwards from after the closing quote to find semicolon/newline
43
- // position.end points to the character AFTER the closing quote
44
- var importEnd = position.end;
45
-
46
- // Check for optional semicolon
47
- if (importEnd < source.length && source[importEnd] === ';') {
48
- importEnd += 1;
49
- }
37
+ // Parse forwards from after the closing quote to find semicolon/newline
38
+ // position.end points to the character AFTER the closing quote
39
+ let importEnd = position.end;
50
40
 
51
- // Check for newline after the statement
52
- var hasTrailingNewline = false;
53
- if (importEnd < source.length && source[importEnd] === '\n') {
54
- hasTrailingNewline = true;
55
- importEnd += 1;
56
- }
41
+ // Check for optional semicolon
42
+ if (importEnd < source.length && source[importEnd] === ';') {
43
+ importEnd += 1;
44
+ }
57
45
 
58
- // Generate const declarations from import names
59
- var constDeclarations = importData.names.map(function (nameInfo) {
60
- var varName = nameInfo.alias || nameInfo.name;
61
- return "const ".concat(varName, " = null;");
62
- }).join('\n');
63
-
64
- // Add newline if original import had one
65
- var newText = constDeclarations + (hasTrailingNewline ? '\n' : '');
66
- replacements.push({
67
- start: importStart,
68
- end: importEnd,
69
- newText: newText
70
- });
46
+ // Check for newline after the statement
47
+ let hasTrailingNewline = false;
48
+ if (importEnd < source.length && source[importEnd] === '\n') {
49
+ hasTrailingNewline = true;
50
+ importEnd += 1;
71
51
  }
72
- } catch (err) {
73
- _iterator.e(err);
74
- } finally {
75
- _iterator.f();
52
+
53
+ // Generate const declarations from import names
54
+ const constDeclarations = importData.names.map(nameInfo => {
55
+ const varName = nameInfo.alias || nameInfo.name;
56
+ return `const ${varName} = null;`;
57
+ }).join('\n');
58
+
59
+ // Add newline if original import had one
60
+ const newText = constDeclarations + (hasTrailingNewline ? '\n' : '');
61
+ replacements.push({
62
+ start: importStart,
63
+ end: importEnd,
64
+ newText
65
+ });
76
66
  }
77
67
  }
78
68
  });
79
69
 
80
70
  // Sort replacements by position (descending) to avoid position shifts
81
- replacements.sort(function (a, b) {
82
- return b.start - a.start;
83
- });
71
+ replacements.sort((a, b) => b.start - a.start);
84
72
 
85
73
  // Apply replacements from right to left (using same logic as rewriteImports)
86
- var result = source;
87
- for (var _i = 0, _replacements = replacements; _i < _replacements.length; _i++) {
88
- var replacement = _replacements[_i];
74
+ let result = source;
75
+ for (const replacement of replacements) {
89
76
  result = result.slice(0, replacement.start) + replacement.newText + result.slice(replacement.end);
90
77
  }
91
78
  return result;
@@ -101,36 +88,24 @@ export function rewriteImportsToNull(source, importPathsToRewrite, importResult)
101
88
  * @returns The source code with import statements removed
102
89
  */
103
90
  export function removeImports(source, importPathsToRemove, importResult) {
104
- var linesToRemove = new Set();
91
+ const linesToRemove = new Set();
105
92
 
106
93
  // Find all line numbers that contain imports to remove
107
- importPathsToRemove.forEach(function (importPath) {
108
- var _importResult$importP;
109
- var positions = (_importResult$importP = importResult[importPath]) == null ? void 0 : _importResult$importP.positions;
94
+ importPathsToRemove.forEach(importPath => {
95
+ const positions = importResult[importPath]?.positions;
110
96
  if (positions && positions.length > 0) {
111
- var _iterator2 = _createForOfIteratorHelper(positions),
112
- _step2;
113
- try {
114
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
115
- var position = _step2.value;
116
- // Find which line this position is on
117
- var beforePosition = source.slice(0, position.start);
118
- var lineNumber = (beforePosition.match(/\n/g) || []).length;
119
- linesToRemove.add(lineNumber);
120
- }
121
- } catch (err) {
122
- _iterator2.e(err);
123
- } finally {
124
- _iterator2.f();
97
+ for (const position of positions) {
98
+ // Find which line this position is on
99
+ const beforePosition = source.slice(0, position.start);
100
+ const lineNumber = (beforePosition.match(/\n/g) || []).length;
101
+ linesToRemove.add(lineNumber);
125
102
  }
126
103
  }
127
104
  });
128
105
 
129
106
  // Split source into lines and filter out lines to remove
130
- var lines = source.split('\n');
131
- var filteredLines = lines.filter(function (_, index) {
132
- return !linesToRemove.has(index);
133
- });
107
+ const lines = source.split('\n');
108
+ const filteredLines = lines.filter((_, index) => !linesToRemove.has(index));
134
109
  return filteredLines.join('\n');
135
110
  }
136
111
 
@@ -145,51 +120,38 @@ export function removeImports(source, importPathsToRemove, importResult) {
145
120
  * @returns The source code with rewritten import paths
146
121
  */
147
122
  export function rewriteImports(source, importPathMapping, importResult) {
148
- var replacements = [];
123
+ const replacements = [];
149
124
 
150
125
  // Use precise position-based replacement
151
- importPathMapping.forEach(function (newPath, originalPath) {
152
- var _importResult$origina;
153
- var positions = (_importResult$origina = importResult[originalPath]) == null ? void 0 : _importResult$origina.positions;
126
+ importPathMapping.forEach((newPath, originalPath) => {
127
+ const positions = importResult[originalPath]?.positions;
154
128
  if (positions && positions.length > 0) {
155
129
  // Process all positions where this import path appears
156
- var _iterator3 = _createForOfIteratorHelper(positions),
157
- _step3;
158
- try {
159
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
160
- var position = _step3.value;
161
- // Validate position bounds
162
- if (position.start >= 0 && position.end <= source.length && position.start < position.end) {
163
- // The positions include the quotes, so we need to preserve them
164
- var originalText = source.slice(position.start, position.end);
165
- if (originalText.length > 0) {
166
- var quote = originalText.charAt(0); // Get the original quote character
167
- var newText = "".concat(quote).concat(newPath).concat(quote);
168
- replacements.push({
169
- start: position.start,
170
- end: position.end,
171
- newText: newText
172
- });
173
- }
130
+ for (const position of positions) {
131
+ // Validate position bounds
132
+ if (position.start >= 0 && position.end <= source.length && position.start < position.end) {
133
+ // The positions include the quotes, so we need to preserve them
134
+ const originalText = source.slice(position.start, position.end);
135
+ if (originalText.length > 0) {
136
+ const quote = originalText.charAt(0); // Get the original quote character
137
+ const newText = `${quote}${newPath}${quote}`;
138
+ replacements.push({
139
+ start: position.start,
140
+ end: position.end,
141
+ newText
142
+ });
174
143
  }
175
144
  }
176
- } catch (err) {
177
- _iterator3.e(err);
178
- } finally {
179
- _iterator3.f();
180
145
  }
181
146
  }
182
147
  });
183
148
 
184
149
  // Sort replacements by position (descending) to avoid position shifts
185
- replacements.sort(function (a, b) {
186
- return b.start - a.start;
187
- });
150
+ replacements.sort((a, b) => b.start - a.start);
188
151
 
189
152
  // Apply replacements from right to left
190
- var result = source;
191
- for (var _i2 = 0, _replacements2 = replacements; _i2 < _replacements2.length; _i2++) {
192
- var replacement = _replacements2[_i2];
153
+ let result = source;
154
+ for (const replacement of replacements) {
193
155
  result = result.slice(0, replacement.start) + replacement.newText + result.slice(replacement.end);
194
156
  }
195
157
  return result;
@@ -1,4 +1,3 @@
1
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
1
  // Example copied from https://github.com/wooorm/starry-night#example-adding-line-numbers
3
2
 
4
3
  /**
@@ -8,17 +7,17 @@ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIt
8
7
  * @returns The number of lines in the tree
9
8
  */
10
9
  export function countLines(tree) {
11
- var search = /\r?\n|\r/g;
12
- var index = -1;
13
- var start = 0;
14
- var startTextRemainder = '';
15
- var lineNumber = 0;
10
+ const search = /\r?\n|\r/g;
11
+ let index = -1;
12
+ let start = 0;
13
+ let startTextRemainder = '';
14
+ let lineNumber = 0;
16
15
  while (index + 1 < tree.children.length) {
17
16
  index += 1;
18
- var child = tree.children[index];
17
+ const child = tree.children[index];
19
18
  if (child.type === 'text') {
20
- var textStart = 0;
21
- var match = search.exec(child.value);
19
+ let textStart = 0;
20
+ let match = search.exec(child.value);
22
21
  while (match) {
23
22
  lineNumber += 1;
24
23
  start = index + 1;
@@ -39,31 +38,30 @@ export function countLines(tree) {
39
38
  }
40
39
  return lineNumber;
41
40
  }
42
- export function starryNightGutter(tree, sourceLines) {
43
- var frameSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 120;
41
+ export function starryNightGutter(tree, sourceLines, frameSize = 120) {
44
42
  /** @type {Array<RootContent>} */
45
- var replacement = [];
46
- var search = /\r?\n|\r/g;
47
- var index = -1;
48
- var start = 0;
49
- var startTextRemainder = '';
50
- var lineNumber = 0;
51
- var frameLines = [];
52
- var frameStartLine = 1; // Track the starting line number for the current frame
43
+ const replacement = [];
44
+ const search = /\r?\n|\r/g;
45
+ let index = -1;
46
+ let start = 0;
47
+ let startTextRemainder = '';
48
+ let lineNumber = 0;
49
+ let frameLines = [];
50
+ let frameStartLine = 1; // Track the starting line number for the current frame
53
51
 
54
52
  while (index + 1 < tree.children.length) {
55
53
  index += 1;
56
- var child = tree.children[index];
54
+ const child = tree.children[index];
57
55
  if (child.type === 'text') {
58
- var textStart = 0;
59
- var match = search.exec(child.value);
56
+ let textStart = 0;
57
+ let match = search.exec(child.value);
60
58
  while (match) {
61
59
  // Nodes in this line.
62
- var _line = tree.children.slice(start, index);
60
+ const line = tree.children.slice(start, index);
63
61
 
64
62
  // Prepend text from a partial matched earlier text.
65
63
  if (startTextRemainder) {
66
- _line.unshift({
64
+ line.unshift({
67
65
  type: 'text',
68
66
  value: startTextRemainder
69
67
  });
@@ -72,7 +70,7 @@ export function starryNightGutter(tree, sourceLines) {
72
70
 
73
71
  // Append text from this text.
74
72
  if (match.index > textStart) {
75
- _line.push({
73
+ line.push({
76
74
  type: 'text',
77
75
  value: child.value.slice(textStart, match.index)
78
76
  });
@@ -80,7 +78,7 @@ export function starryNightGutter(tree, sourceLines) {
80
78
 
81
79
  // Add a line, and the eol.
82
80
  lineNumber += 1;
83
- frameLines.push(createLine(_line, lineNumber), {
81
+ frameLines.push(createLine(line, lineNumber), {
84
82
  type: 'text',
85
83
  value: match[0]
86
84
  });
@@ -102,7 +100,7 @@ export function starryNightGutter(tree, sourceLines) {
102
100
  }
103
101
  }
104
102
  }
105
- var line = tree.children.slice(start);
103
+ const line = tree.children.slice(start);
106
104
  // Prepend text from a partial matched earlier text.
107
105
  if (startTextRemainder) {
108
106
  line.unshift({
@@ -123,22 +121,12 @@ export function starryNightGutter(tree, sourceLines) {
123
121
 
124
122
  // If there are multiple frames and sourceLines provided, add dataAsString to each frame
125
123
  if (replacement.length > 1 && sourceLines) {
126
- var _iterator = _createForOfIteratorHelper(replacement),
127
- _step;
128
- try {
129
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
130
- var _frame$properties;
131
- var frame = _step.value;
132
- if (frame.type === 'element' && frame.tagName === 'span' && ((_frame$properties = frame.properties) == null ? void 0 : _frame$properties.className) === 'frame' && typeof frame.properties.dataFrameStartLine === 'number' && typeof frame.properties.dataFrameEndLine === 'number') {
133
- var startLine = frame.properties.dataFrameStartLine - 1; // Convert to 0-based index
134
- var endLine = frame.properties.dataFrameEndLine; // This is already inclusive
135
- frame.properties.dataAsString = sourceLines.slice(startLine, endLine).join('\n');
136
- }
124
+ for (const frame of replacement) {
125
+ if (frame.type === 'element' && frame.tagName === 'span' && frame.properties?.className === 'frame' && typeof frame.properties.dataFrameStartLine === 'number' && typeof frame.properties.dataFrameEndLine === 'number') {
126
+ const startLine = frame.properties.dataFrameStartLine - 1; // Convert to 0-based index
127
+ const endLine = frame.properties.dataFrameEndLine; // This is already inclusive
128
+ frame.properties.dataAsString = sourceLines.slice(startLine, endLine).join('\n');
137
129
  }
138
- } catch (err) {
139
- _iterator.e(err);
140
- } finally {
141
- _iterator.f();
142
130
  }
143
131
  }
144
132
 
@@ -159,11 +147,11 @@ function createLine(children, line) {
159
147
  className: 'line',
160
148
  dataLn: line
161
149
  },
162
- children: children
150
+ children
163
151
  };
164
152
  }
165
153
  function createFrame(frameChildren, sourceLines, startLine, endLine) {
166
- var properties = {
154
+ const properties = {
167
155
  className: 'frame'
168
156
  };
169
157
 
@@ -175,7 +163,7 @@ function createFrame(frameChildren, sourceLines, startLine, endLine) {
175
163
  return {
176
164
  type: 'element',
177
165
  tagName: 'span',
178
- properties: properties,
166
+ properties,
179
167
  children: frameChildren
180
168
  };
181
169
  }
@@ -8,10 +8,10 @@ import textHtmlBasic from '@wooorm/starry-night/text.html.basic';
8
8
  import sourceCss from '@wooorm/starry-night/source.css';
9
9
  import sourceShell from '@wooorm/starry-night/source.shell';
10
10
  import sourceYaml from '@wooorm/starry-night/source.yaml';
11
- export var grammars = [sourceJs, sourceTs, sourceTsx, sourceJson, textMd, sourceMdx,
11
+ export const grammars = [sourceJs, sourceTs, sourceTsx, sourceJson, textMd, sourceMdx,
12
12
  // needs sourceTsx
13
13
  textHtmlBasic, sourceCss, sourceShell, sourceYaml];
14
- export var extensionMap = {
14
+ export const extensionMap = {
15
15
  '.js': 'source.js',
16
16
  '.ts': 'source.ts',
17
17
  '.jsx': 'source.tsx',
@@ -29,7 +29,7 @@ export var extensionMap = {
29
29
  * Maps simplified language names back to grammar scope names.
30
30
  * Used when `language` prop is provided instead of fileName.
31
31
  */
32
- export var languageToGrammarMap = {
32
+ export const languageToGrammarMap = {
33
33
  js: 'source.js',
34
34
  javascript: 'source.js',
35
35
  ts: 'source.ts',
@@ -1,22 +1,20 @@
1
- import _regenerator from "@babel/runtime/helpers/esm/regenerator";
2
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
1
  import { createStarryNight } from '@wooorm/starry-night';
4
2
  import { grammars, extensionMap, getGrammarFromLanguage } from "./grammars.js";
5
3
  import { starryNightGutter } from "./addLineGutters.js";
6
- var STARRY_NIGHT_KEY = '__docs_infra_starry_night_instance__';
7
- export var parseSource = function parseSource(source, fileName, language) {
8
- var starryNight = globalThis[STARRY_NIGHT_KEY];
4
+ const STARRY_NIGHT_KEY = '__docs_infra_starry_night_instance__';
5
+ export const parseSource = (source, fileName, language) => {
6
+ const starryNight = globalThis[STARRY_NIGHT_KEY];
9
7
  if (!starryNight) {
10
8
  throw new Error('Starry Night not initialized. Use createParseSource to create an initialized parseSource function.');
11
9
  }
12
10
 
13
11
  // Determine the grammar scope: prefer explicit language, then fall back to file extension
14
- var grammarScope;
12
+ let grammarScope;
15
13
  if (language) {
16
14
  grammarScope = getGrammarFromLanguage(language);
17
15
  }
18
16
  if (!grammarScope && fileName) {
19
- var fileType = fileName.slice(fileName.lastIndexOf('.'));
17
+ const fileType = fileName.slice(fileName.lastIndexOf('.'));
20
18
  grammarScope = extensionMap[fileType];
21
19
  }
22
20
  if (!grammarScope) {
@@ -30,31 +28,15 @@ export var parseSource = function parseSource(source, fileName, language) {
30
28
  }]
31
29
  };
32
30
  }
33
- var highlighted = starryNight.highlight(source, grammarScope);
34
- var sourceLines = source.split(/\r?\n|\r/);
31
+ const highlighted = starryNight.highlight(source, grammarScope);
32
+ const sourceLines = source.split(/\r?\n|\r/);
35
33
  starryNightGutter(highlighted, sourceLines); // mutates the tree to add line gutters
36
34
 
37
35
  return highlighted;
38
36
  };
39
- export var createParseSource = /*#__PURE__*/function () {
40
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
41
- return _regenerator().w(function (_context) {
42
- while (1) switch (_context.n) {
43
- case 0:
44
- if (globalThis[STARRY_NIGHT_KEY]) {
45
- _context.n = 2;
46
- break;
47
- }
48
- _context.n = 1;
49
- return createStarryNight(grammars);
50
- case 1:
51
- globalThis[STARRY_NIGHT_KEY] = _context.v;
52
- case 2:
53
- return _context.a(2, parseSource);
54
- }
55
- }, _callee);
56
- }));
57
- return function createParseSource() {
58
- return _ref.apply(this, arguments);
59
- };
60
- }();
37
+ export const createParseSource = async () => {
38
+ if (!globalThis[STARRY_NIGHT_KEY]) {
39
+ globalThis[STARRY_NIGHT_KEY] = await createStarryNight(grammars);
40
+ }
41
+ return parseSource;
42
+ };