@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.
- package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
- package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
- package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
- package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
- package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
- package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
- package/esm/CodeHighlighter/errors.js +248 -400
- package/esm/CodeHighlighter/parseControlledCode.js +12 -20
- package/esm/CodeProvider/CodeContext.js +3 -3
- package/esm/CodeProvider/CodeProvider.js +31 -40
- package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
- package/esm/cli/index.js +1 -1
- package/esm/cli/runValidate.js +160 -264
- package/esm/createDemoData/createDemoData.js +11 -12
- package/esm/createSitemap/createSitemap.js +2 -2
- package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
- package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
- package/esm/pipeline/hastUtils/hastUtils.js +16 -17
- package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
- package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
- package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
- package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
- package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
- package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
- package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
- package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
- package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
- package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
- package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
- package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
- package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
- package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
- package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
- package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
- package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
- package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
- package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
- package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
- package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
- package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
- package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
- package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
- package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
- package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
- package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
- package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
- package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
- package/esm/pipeline/parseSource/addLineGutters.js +33 -45
- package/esm/pipeline/parseSource/grammars.js +3 -3
- package/esm/pipeline/parseSource/parseSource.js +13 -31
- package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
- package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
- package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
- package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
- package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
- package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
- package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
- package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
- package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
- package/esm/useCode/Pre.js +58 -62
- package/esm/useCode/useCode.js +59 -61
- package/esm/useCode/useCodeUtils.js +54 -63
- package/esm/useCode/useCopyFunctionality.js +10 -9
- package/esm/useCode/useFileNavigation.js +150 -212
- package/esm/useCode/useSourceEditing.js +17 -14
- package/esm/useCode/useTransformManagement.js +23 -26
- package/esm/useCode/useUIState.js +12 -20
- package/esm/useCode/useVariantSelection.js +62 -79
- package/esm/useCopier/index.js +29 -56
- package/esm/useDemo/createCodeSandbox.js +12 -15
- package/esm/useDemo/createStackBlitz.js +14 -20
- package/esm/useDemo/exportVariant.js +200 -180
- package/esm/useDemo/exportVariantAsCra.js +22 -25
- package/esm/useDemo/useDemo.js +80 -84
- package/esm/useErrors/ErrorsContext.js +1 -1
- package/esm/useErrors/useErrors.js +3 -3
- package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
- package/esm/usePreference/PreferencesProvider.js +1 -1
- package/esm/usePreference/usePreference.js +9 -11
- package/esm/useSearch/useSearch.js +290 -387
- package/esm/useUrlHashState/useUrlHashState.js +11 -14
- package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
- package/esm/withDocsInfra/withDocsInfra.js +99 -101
- 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
|
-
|
|
16
|
+
const replacements = [];
|
|
18
17
|
|
|
19
18
|
// Find all import statements to rewrite
|
|
20
|
-
importPathsToRewrite.forEach(
|
|
21
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
importEnd += 1;
|
|
56
|
-
}
|
|
41
|
+
// Check for optional semicolon
|
|
42
|
+
if (importEnd < source.length && source[importEnd] === ';') {
|
|
43
|
+
importEnd += 1;
|
|
44
|
+
}
|
|
57
45
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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(
|
|
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
|
-
|
|
87
|
-
for (
|
|
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
|
-
|
|
91
|
+
const linesToRemove = new Set();
|
|
105
92
|
|
|
106
93
|
// Find all line numbers that contain imports to remove
|
|
107
|
-
importPathsToRemove.forEach(
|
|
108
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
131
|
-
|
|
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
|
-
|
|
123
|
+
const replacements = [];
|
|
149
124
|
|
|
150
125
|
// Use precise position-based replacement
|
|
151
|
-
importPathMapping.forEach(
|
|
152
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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(
|
|
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
|
-
|
|
191
|
-
for (
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
17
|
+
const child = tree.children[index];
|
|
19
18
|
if (child.type === 'text') {
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
54
|
+
const child = tree.children[index];
|
|
57
55
|
if (child.type === 'text') {
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
let textStart = 0;
|
|
57
|
+
let match = search.exec(child.value);
|
|
60
58
|
while (match) {
|
|
61
59
|
// Nodes in this line.
|
|
62
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
|
150
|
+
children
|
|
163
151
|
};
|
|
164
152
|
}
|
|
165
153
|
function createFrame(frameChildren, sourceLines, startLine, endLine) {
|
|
166
|
-
|
|
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
|
|
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
|
|
11
|
+
export const grammars = [sourceJs, sourceTs, sourceTsx, sourceJson, textMd, sourceMdx,
|
|
12
12
|
// needs sourceTsx
|
|
13
13
|
textHtmlBasic, sourceCss, sourceShell, sourceYaml];
|
|
14
|
-
export
|
|
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
|
|
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
|
-
|
|
7
|
-
export
|
|
8
|
-
|
|
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
|
-
|
|
12
|
+
let grammarScope;
|
|
15
13
|
if (language) {
|
|
16
14
|
grammarScope = getGrammarFromLanguage(language);
|
|
17
15
|
}
|
|
18
16
|
if (!grammarScope && fileName) {
|
|
19
|
-
|
|
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
|
-
|
|
34
|
-
|
|
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
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
+
};
|