@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 _typeof from "@babel/runtime/helpers/esm/typeof";
2
1
  import { hasAllVariants } from "./hasAllCodeVariants.js";
3
2
  /**
4
3
  * Type guard function that determines if we have sufficient data to render a code highlighter
@@ -98,10 +97,7 @@ import { hasAllVariants } from "./hasAllCodeVariants.js";
98
97
  * }, [initialData, reason, ...]);
99
98
  * ```
100
99
  */
101
- export function maybeCodeInitialData(variants, variant, code, fileName) {
102
- var needsHighlight = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
103
- var needsAllFiles = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
104
- var needsAllVariants = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
100
+ export function maybeCodeInitialData(variants, variant, code, fileName, needsHighlight = false, needsAllFiles = false, needsAllVariants = false) {
105
101
  if (!code) {
106
102
  return {
107
103
  initialData: false,
@@ -114,7 +110,7 @@ export function maybeCodeInitialData(variants, variant, code, fileName) {
114
110
  reason: 'Not all variants are available'
115
111
  };
116
112
  }
117
- var variantCode = code[variant];
113
+ const variantCode = code[variant];
118
114
  if (!variantCode || typeof variantCode === 'string') {
119
115
  return {
120
116
  initialData: false,
@@ -134,10 +130,9 @@ export function maybeCodeInitialData(variants, variant, code, fileName) {
134
130
  reason: 'Variant source not found'
135
131
  };
136
132
  }
137
- if (variantCode.extraFiles && !Object.keys(variantCode.extraFiles).every(function (file) {
138
- var _variantCode$extraFil;
139
- var fileData = (_variantCode$extraFil = variantCode.extraFiles) == null ? void 0 : _variantCode$extraFil[file];
140
- return _typeof(fileData) === 'object' && (fileData == null ? void 0 : fileData.source) !== undefined;
133
+ if (variantCode.extraFiles && !Object.keys(variantCode.extraFiles).every(file => {
134
+ const fileData = variantCode.extraFiles?.[file];
135
+ return typeof fileData === 'object' && fileData?.source !== undefined;
141
136
  })) {
142
137
  return {
143
138
  initialData: false,
@@ -147,22 +142,21 @@ export function maybeCodeInitialData(variants, variant, code, fileName) {
147
142
  }
148
143
 
149
144
  // TODO, filename might need to be determined from filesOrder if provided?
150
- var initialFilename = fileName || variantCode.fileName;
151
- var fileSource;
145
+ const initialFilename = fileName || variantCode.fileName;
146
+ let fileSource;
152
147
  if (fileName && fileName !== variantCode.fileName) {
153
- var _variantCode$extraFil2;
154
- var fileData = variantCode == null || (_variantCode$extraFil2 = variantCode.extraFiles) == null ? void 0 : _variantCode$extraFil2[fileName];
148
+ const fileData = variantCode?.extraFiles?.[fileName];
155
149
  if (!fileData) {
156
150
  return {
157
151
  initialData: false,
158
- reason: "File not found in code"
152
+ reason: `File not found in code`
159
153
  };
160
154
  }
161
155
  if (typeof fileData === 'string') {
162
156
  // It's a URL, not actual source content
163
157
  return {
164
158
  initialData: false,
165
- reason: "File is not loaded yet"
159
+ reason: `File is not loaded yet`
166
160
  };
167
161
  }
168
162
  fileSource = fileData.source;
@@ -172,7 +166,7 @@ export function maybeCodeInitialData(variants, variant, code, fileName) {
172
166
  if (!fileSource) {
173
167
  return {
174
168
  initialData: false,
175
- reason: "File source not found"
169
+ reason: `File source not found`
176
170
  };
177
171
  }
178
172
  if (needsHighlight && typeof fileSource === 'string') {
@@ -183,10 +177,10 @@ export function maybeCodeInitialData(variants, variant, code, fileName) {
183
177
  }
184
178
  return {
185
179
  initialData: {
186
- code: code,
187
- initialFilename: initialFilename,
180
+ code,
181
+ initialFilename,
188
182
  initialSource: fileSource,
189
- initialExtraFiles: variantCode == null ? void 0 : variantCode.extraFiles
183
+ initialExtraFiles: variantCode?.extraFiles
190
184
  }
191
185
  };
192
186
  }
@@ -1,7 +1,3 @@
1
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
- import _extends from "@babel/runtime/helpers/esm/extends";
4
- var _excluded = ["metadata"];
5
1
  /**
6
2
  * Metadata merging utility for positioning metadata files relative to source files
7
3
  */
@@ -27,86 +23,83 @@ import { calculateMaxSourceBackNavigation, removeBackNavigationPrefix, buildPath
27
23
  * @returns An object with the cleaned variant and extracted metadata
28
24
  */
29
25
  export function extractCodeMetadata(variant) {
30
- var metadataPrefix = variant.metadataPrefix;
31
- var extractedMetadata = {};
32
- var nonMetadataFiles = {};
26
+ const {
27
+ metadataPrefix
28
+ } = variant;
29
+ const extractedMetadata = {};
30
+ const nonMetadataFiles = {};
33
31
  if (!variant.extraFiles) {
34
32
  return {
35
- variant: _extends(_extends({}, variant), {}, {
33
+ variant: {
34
+ ...variant,
36
35
  extraFiles: {}
37
- }),
36
+ },
38
37
  metadata: {}
39
38
  };
40
39
  }
41
40
 
42
41
  // Calculate how much back navigation to remove using pathUtils
43
- var backLevelsToRemove = calculateMaxSourceBackNavigation(variant.extraFiles || {});
42
+ let backLevelsToRemove = calculateMaxSourceBackNavigation(variant.extraFiles || {});
44
43
  if (metadataPrefix) {
45
44
  // Add metadataPrefix levels if present
46
45
  backLevelsToRemove += splitPath(metadataPrefix).length;
47
46
  }
48
47
 
49
48
  // Process all extraFiles
50
- for (var _i = 0, _Object$entries = Object.entries(variant.extraFiles); _i < _Object$entries.length; _i++) {
51
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
52
- relativePath = _Object$entries$_i[0],
53
- fileContent = _Object$entries$_i[1];
54
- var file = typeof fileContent === 'string' ? {
49
+ for (const [relativePath, fileContent] of Object.entries(variant.extraFiles)) {
50
+ const file = typeof fileContent === 'string' ? {
55
51
  source: fileContent
56
52
  } : fileContent;
57
53
  if (file.metadata) {
58
- var scopedPath = removeBackNavigationPrefix(relativePath, backLevelsToRemove);
54
+ const scopedPath = removeBackNavigationPrefix(relativePath, backLevelsToRemove);
59
55
 
60
56
  // Remove metadata flag when extracting
61
- var metadataFlag = file.metadata,
62
- cleanFile = _objectWithoutPropertiesLoose(file, _excluded);
57
+ const {
58
+ metadata: metadataFlag,
59
+ ...cleanFile
60
+ } = file;
63
61
  extractedMetadata[scopedPath] = cleanFile;
64
62
  } else {
65
63
  nonMetadataFiles[relativePath] = file;
66
64
  }
67
65
  }
68
66
  return {
69
- variant: _extends(_extends({}, variant), {}, {
67
+ variant: {
68
+ ...variant,
70
69
  extraFiles: nonMetadataFiles
71
- }),
70
+ },
72
71
  metadata: extractedMetadata
73
72
  };
74
73
  }
75
- export function mergeCodeMetadata(variant) {
76
- var _options$metadataPref;
77
- var metadataFiles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
78
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
74
+ export function mergeCodeMetadata(variant, metadataFiles = {}, options = {}) {
79
75
  // Determine which metadataPrefix to use
80
- var targetMetadataPrefix = (_options$metadataPref = options.metadataPrefix) != null ? _options$metadataPref : variant.metadataPrefix;
76
+ const targetMetadataPrefix = options.metadataPrefix ?? variant.metadataPrefix;
81
77
 
82
78
  // Check if we need to re-extract metadata due to metadataPrefix change
83
- var needsReextraction = options.metadataPrefix !== undefined && options.metadataPrefix !== variant.metadataPrefix;
79
+ const needsReextraction = options.metadataPrefix !== undefined && options.metadataPrefix !== variant.metadataPrefix;
84
80
 
85
81
  // If metadataPrefix is changing, extract existing metadata and reposition everything
86
- var workingVariant = variant;
87
- var existingMetadata = {};
82
+ let workingVariant = variant;
83
+ let existingMetadata = {};
88
84
  if (needsReextraction && variant.extraFiles) {
89
85
  // Extract existing metadata using the old metadataPrefix
90
- var extracted = extractCodeMetadata(variant);
86
+ const extracted = extractCodeMetadata(variant);
91
87
  workingVariant = extracted.variant;
92
88
  existingMetadata = extracted.metadata;
93
89
  }
94
90
 
95
91
  // Calculate the positioning level for metadata files
96
- var metadataBackNavigation = calculateMetadataBackNavigation(workingVariant.extraFiles, targetMetadataPrefix);
92
+ const metadataBackNavigation = calculateMetadataBackNavigation(workingVariant.extraFiles, targetMetadataPrefix);
97
93
 
98
94
  // Collect all metadata files that need positioning
99
- var allMetadataFiles = {};
100
- var nonMetadataFiles = {};
101
- var positionedMetadataFiles = {};
95
+ const allMetadataFiles = {};
96
+ const nonMetadataFiles = {};
97
+ const positionedMetadataFiles = {};
102
98
 
103
99
  // Process existing extraFiles from working variant
104
100
  if (workingVariant.extraFiles) {
105
- for (var _i2 = 0, _Object$entries2 = Object.entries(workingVariant.extraFiles); _i2 < _Object$entries2.length; _i2++) {
106
- var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
107
- relativePath = _Object$entries2$_i[0],
108
- fileContent = _Object$entries2$_i[1];
109
- var file = typeof fileContent === 'string' ? {
101
+ for (const [relativePath, fileContent] of Object.entries(workingVariant.extraFiles)) {
102
+ const file = typeof fileContent === 'string' ? {
110
103
  source: fileContent
111
104
  } : fileContent;
112
105
  if (file.metadata) {
@@ -124,42 +117,39 @@ export function mergeCodeMetadata(variant) {
124
117
  }
125
118
 
126
119
  // Add extracted metadata (if any) for repositioning
127
- for (var _i3 = 0, _Object$entries3 = Object.entries(existingMetadata); _i3 < _Object$entries3.length; _i3++) {
128
- var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
129
- filePath = _Object$entries3$_i[0],
130
- _file = _Object$entries3$_i[1];
131
- allMetadataFiles[filePath] = _extends(_extends({}, typeof _file === 'string' ? {
132
- source: _file
133
- } : _file), {}, {
120
+ for (const [filePath, file] of Object.entries(existingMetadata)) {
121
+ allMetadataFiles[filePath] = {
122
+ ...(typeof file === 'string' ? {
123
+ source: file
124
+ } : file),
134
125
  metadata: true
135
- });
126
+ };
136
127
  }
137
128
 
138
129
  // Add additional metadata files for positioning
139
- for (var _i4 = 0, _Object$entries4 = Object.entries(metadataFiles); _i4 < _Object$entries4.length; _i4++) {
140
- var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2),
141
- _filePath = _Object$entries4$_i[0],
142
- _file2 = _Object$entries4$_i[1];
143
- allMetadataFiles[_filePath] = _extends(_extends({}, typeof _file2 === 'string' ? {
144
- source: _file2
145
- } : _file2), {}, {
130
+ for (const [filePath, file] of Object.entries(metadataFiles)) {
131
+ allMetadataFiles[filePath] = {
132
+ ...(typeof file === 'string' ? {
133
+ source: file
134
+ } : file),
146
135
  metadata: true
147
- });
136
+ };
148
137
  }
149
138
 
150
139
  // Position new metadata files at the calculated level using buildPath
151
- for (var _i5 = 0, _Object$entries5 = Object.entries(allMetadataFiles); _i5 < _Object$entries5.length; _i5++) {
152
- var _Object$entries5$_i = _slicedToArray(_Object$entries5[_i5], 2),
153
- originalPath = _Object$entries5$_i[0],
154
- _file3 = _Object$entries5$_i[1];
155
- var metadataPath = buildPath(metadataBackNavigation, originalPath);
156
- positionedMetadataFiles[metadataPath] = _file3;
140
+ for (const [originalPath, file] of Object.entries(allMetadataFiles)) {
141
+ const metadataPath = buildPath(metadataBackNavigation, originalPath);
142
+ positionedMetadataFiles[metadataPath] = file;
157
143
  }
158
144
 
159
145
  // Combine all files
160
- var finalExtraFiles = _extends(_extends({}, nonMetadataFiles), positionedMetadataFiles);
161
- return _extends(_extends({}, workingVariant), {}, {
146
+ const finalExtraFiles = {
147
+ ...nonMetadataFiles,
148
+ ...positionedMetadataFiles
149
+ };
150
+ return {
151
+ ...workingVariant,
162
152
  extraFiles: finalExtraFiles,
163
153
  metadataPrefix: targetMetadataPrefix
164
- });
154
+ };
165
155
  }
@@ -1,41 +1,33 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _typeof from "@babel/runtime/helpers/esm/typeof";
3
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
1
  /**
5
2
  * Pure function to parse code variants and their extraFiles.
6
3
  * Converts string sources to HAST nodes and handles hastJson parsing.
7
4
  */
8
5
  export function parseCode(code, parseSource) {
9
- var parsed = {};
10
- for (var _i = 0, _Object$entries = Object.entries(code); _i < _Object$entries.length; _i++) {
11
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
12
- variant = _Object$entries$_i[0],
13
- variantCode = _Object$entries$_i[1];
6
+ const parsed = {};
7
+ for (const [variant, variantCode] of Object.entries(code)) {
14
8
  if (typeof variantCode === 'string') {
15
9
  // Already parsed/highlighted
16
10
  parsed[variant] = variantCode;
17
- } else if (variantCode && _typeof(variantCode) === 'object') {
11
+ } else if (variantCode && typeof variantCode === 'object') {
18
12
  // Parse if source is available and not already parsed, and we have a filename to determine the file type
19
13
  if (variantCode.source && typeof variantCode.source === 'string' && variantCode.fileName) {
20
14
  try {
21
- var hastRoot = parseSource(variantCode.source, variantCode.fileName);
15
+ const hastRoot = parseSource(variantCode.source, variantCode.fileName);
22
16
 
23
17
  // Also parse extraFiles if they contain sources that need parsing
24
- var parsedExtraFiles = variantCode.extraFiles ? Object.fromEntries(Object.entries(variantCode.extraFiles).map(function (_ref) {
25
- var _ref2 = _slicedToArray(_ref, 2),
26
- fileName = _ref2[0],
27
- fileContent = _ref2[1];
18
+ const parsedExtraFiles = variantCode.extraFiles ? Object.fromEntries(Object.entries(variantCode.extraFiles).map(([fileName, fileContent]) => {
28
19
  if (typeof fileContent === 'string') {
29
20
  return [fileName, fileContent]; // Keep string as-is
30
21
  }
31
- if (fileContent && _typeof(fileContent) === 'object' && fileContent.source) {
22
+ if (fileContent && typeof fileContent === 'object' && fileContent.source) {
32
23
  if (typeof fileContent.source === 'string') {
33
24
  // Parse string source in extraFile
34
25
  try {
35
- var parsedHastRoot = parseSource(fileContent.source, fileName);
36
- return [fileName, _extends(_extends({}, fileContent), {}, {
26
+ const parsedHastRoot = parseSource(fileContent.source, fileName);
27
+ return [fileName, {
28
+ ...fileContent,
37
29
  source: parsedHastRoot
38
- })];
30
+ }];
39
31
  } catch (error) {
40
32
  return [fileName, fileContent]; // Keep original if parsing fails
41
33
  }
@@ -43,10 +35,11 @@ export function parseCode(code, parseSource) {
43
35
  }
44
36
  return [fileName, fileContent]; // Keep as-is for other cases
45
37
  })) : undefined;
46
- parsed[variant] = _extends(_extends({}, variantCode), {}, {
38
+ parsed[variant] = {
39
+ ...variantCode,
47
40
  source: hastRoot,
48
41
  extraFiles: parsedExtraFiles
49
- });
42
+ };
50
43
  } catch (error) {
51
44
  // Keep original if parsing fails
52
45
  parsed[variant] = variantCode;
@@ -54,7 +47,8 @@ export function parseCode(code, parseSource) {
54
47
  } else if (variantCode.source && typeof variantCode.source === 'string' && !variantCode.fileName) {
55
48
  // Return a basic HAST root node with the source text for unsupported file types
56
49
  // This indicates that the source has at least passed through the parsing pipeline
57
- parsed[variant] = _extends(_extends({}, variantCode), {}, {
50
+ parsed[variant] = {
51
+ ...variantCode,
58
52
  source: {
59
53
  type: 'root',
60
54
  children: [{
@@ -62,28 +56,26 @@ export function parseCode(code, parseSource) {
62
56
  value: variantCode.source
63
57
  }]
64
58
  }
65
- });
66
- } else if (variantCode.source && _typeof(variantCode.source) === 'object' && 'hastJson' in variantCode.source) {
59
+ };
60
+ } else if (variantCode.source && typeof variantCode.source === 'object' && 'hastJson' in variantCode.source) {
67
61
  try {
68
62
  // Parse hastJson to HAST nodes
69
- var _hastRoot = JSON.parse(variantCode.source.hastJson);
63
+ const hastRoot = JSON.parse(variantCode.source.hastJson);
70
64
 
71
65
  // Also parse extraFiles if they contain sources that need parsing
72
- var _parsedExtraFiles = variantCode.extraFiles ? Object.fromEntries(Object.entries(variantCode.extraFiles).map(function (_ref3) {
73
- var _ref4 = _slicedToArray(_ref3, 2),
74
- fileName = _ref4[0],
75
- fileContent = _ref4[1];
66
+ const parsedExtraFiles = variantCode.extraFiles ? Object.fromEntries(Object.entries(variantCode.extraFiles).map(([fileName, fileContent]) => {
76
67
  if (typeof fileContent === 'string') {
77
68
  return [fileName, fileContent]; // Keep string as-is
78
69
  }
79
- if (fileContent && _typeof(fileContent) === 'object' && fileContent.source) {
70
+ if (fileContent && typeof fileContent === 'object' && fileContent.source) {
80
71
  if (typeof fileContent.source === 'string') {
81
72
  // Parse string source in extraFile
82
73
  try {
83
- var parsedHastRoot = parseSource(fileContent.source, fileName);
84
- return [fileName, _extends(_extends({}, fileContent), {}, {
74
+ const parsedHastRoot = parseSource(fileContent.source, fileName);
75
+ return [fileName, {
76
+ ...fileContent,
85
77
  source: parsedHastRoot
86
- })];
78
+ }];
87
79
  } catch (error) {
88
80
  return [fileName, fileContent]; // Keep original if parsing fails
89
81
  }
@@ -91,32 +83,31 @@ export function parseCode(code, parseSource) {
91
83
  }
92
84
  return [fileName, fileContent]; // Keep as-is for other cases
93
85
  })) : undefined;
94
- parsed[variant] = _extends(_extends({}, variantCode), {}, {
95
- source: _hastRoot,
96
- extraFiles: _parsedExtraFiles
97
- });
86
+ parsed[variant] = {
87
+ ...variantCode,
88
+ source: hastRoot,
89
+ extraFiles: parsedExtraFiles
90
+ };
98
91
  } catch (error) {
99
92
  // Keep original if parsing fails
100
- console.error("Failed to parse hastJson for variant ".concat(variant, ":"), error);
93
+ console.error(`Failed to parse hastJson for variant ${variant}:`, error);
101
94
  parsed[variant] = variantCode;
102
95
  }
103
96
  } else {
104
97
  // Already parsed or no source to parse - but still check extraFiles
105
- var _parsedExtraFiles2 = variantCode.extraFiles ? Object.fromEntries(Object.entries(variantCode.extraFiles).map(function (_ref5) {
106
- var _ref6 = _slicedToArray(_ref5, 2),
107
- fileName = _ref6[0],
108
- fileContent = _ref6[1];
98
+ const parsedExtraFiles = variantCode.extraFiles ? Object.fromEntries(Object.entries(variantCode.extraFiles).map(([fileName, fileContent]) => {
109
99
  if (typeof fileContent === 'string') {
110
100
  return [fileName, fileContent]; // Keep string as-is
111
101
  }
112
- if (fileContent && _typeof(fileContent) === 'object' && fileContent.source) {
102
+ if (fileContent && typeof fileContent === 'object' && fileContent.source) {
113
103
  if (typeof fileContent.source === 'string') {
114
104
  // Parse string source in extraFile
115
105
  try {
116
- var parsedHastRoot = parseSource(fileContent.source, fileName);
117
- return [fileName, _extends(_extends({}, fileContent), {}, {
106
+ const parsedHastRoot = parseSource(fileContent.source, fileName);
107
+ return [fileName, {
108
+ ...fileContent,
118
109
  source: parsedHastRoot
119
- })];
110
+ }];
120
111
  } catch (error) {
121
112
  return [fileName, fileContent]; // Keep original if parsing fails
122
113
  }
@@ -124,9 +115,10 @@ export function parseCode(code, parseSource) {
124
115
  }
125
116
  return [fileName, fileContent]; // Keep as-is for other cases
126
117
  })) : undefined;
127
- parsed[variant] = _extends(_extends({}, variantCode), {}, {
128
- extraFiles: _parsedExtraFiles2
129
- });
118
+ parsed[variant] = {
119
+ ...variantCode,
120
+ extraFiles: parsedExtraFiles
121
+ };
130
122
  }
131
123
  }
132
124
  }
@@ -1,7 +1,3 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import _typeof from "@babel/runtime/helpers/esm/typeof";
3
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
5
1
  /**
6
2
  * Shared path utilities for CodeHighlighter components
7
3
  *
@@ -22,38 +18,29 @@ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIt
22
18
  */
23
19
  export function resolveRelativePath(relativePath) {
24
20
  // Split the path into segments
25
- var segments = relativePath.split('/');
26
- var resolved = [];
27
- var backSteps = 0;
28
- var _iterator = _createForOfIteratorHelper(segments),
29
- _step;
30
- try {
31
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
32
- var segment = _step.value;
33
- if (segment === '' || segment === '.') {
34
- // Skip empty and current directory segments
35
- continue;
36
- } else if (segment === '..') {
37
- if (resolved.length > 0) {
38
- // Remove the last segment (go back one directory)
39
- resolved.pop();
40
- } else {
41
- // Count back steps that go beyond the current directory
42
- backSteps += 1;
43
- }
21
+ const segments = relativePath.split('/');
22
+ const resolved = [];
23
+ let backSteps = 0;
24
+ for (const segment of segments) {
25
+ if (segment === '' || segment === '.') {
26
+ // Skip empty and current directory segments
27
+ continue;
28
+ } else if (segment === '..') {
29
+ if (resolved.length > 0) {
30
+ // Remove the last segment (go back one directory)
31
+ resolved.pop();
44
32
  } else {
45
- // Regular directory or file segment
46
- resolved.push(segment);
33
+ // Count back steps that go beyond the current directory
34
+ backSteps += 1;
47
35
  }
36
+ } else {
37
+ // Regular directory or file segment
38
+ resolved.push(segment);
48
39
  }
49
- } catch (err) {
50
- _iterator.e(err);
51
- } finally {
52
- _iterator.f();
53
40
  }
54
41
  return {
55
42
  resolvedPath: resolved.join('/'),
56
- backSteps: backSteps
43
+ backSteps
57
44
  };
58
45
  }
59
46
 
@@ -82,8 +69,8 @@ export function removeTrailingSlash(path) {
82
69
  * Remove a specific number of back navigation prefixes from a path
83
70
  */
84
71
  export function removeBackNavigationPrefix(path, count) {
85
- var result = path;
86
- for (var i = 0; i < count; i += 1) {
72
+ let result = path;
73
+ for (let i = 0; i < count; i += 1) {
87
74
  if (result.startsWith('../')) {
88
75
  result = result.slice(3);
89
76
  } else {
@@ -118,24 +105,22 @@ export function removeBackNavigationPrefix(path, count) {
118
105
  * ```
119
106
  */
120
107
  export function calculateMaxBackNavigation(files) {
121
- var maxBackNavigation = 0;
122
- var maxSourceBackNavigation = 0;
123
- for (var _i = 0, _Object$entries = Object.entries(files); _i < _Object$entries.length; _i++) {
124
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
125
- relativePath = _Object$entries$_i[0],
126
- fileContent = _Object$entries$_i[1];
108
+ let maxBackNavigation = 0;
109
+ let maxSourceBackNavigation = 0;
110
+ for (const [relativePath, fileContent] of Object.entries(files)) {
127
111
  // Check if this is a metadata file
128
- var isMetadata = _typeof(fileContent) === 'object' && fileContent.metadata;
129
- var _resolveRelativePath = resolveRelativePath(relativePath),
130
- backSteps = _resolveRelativePath.backSteps;
112
+ const isMetadata = typeof fileContent === 'object' && fileContent.metadata;
113
+ const {
114
+ backSteps
115
+ } = resolveRelativePath(relativePath);
131
116
  if (!isMetadata) {
132
117
  maxSourceBackNavigation = Math.max(maxSourceBackNavigation, backSteps);
133
118
  }
134
119
  maxBackNavigation = Math.max(maxBackNavigation, backSteps);
135
120
  }
136
121
  return {
137
- maxBackNavigation: maxBackNavigation,
138
- maxSourceBackNavigation: maxSourceBackNavigation
122
+ maxBackNavigation,
123
+ maxSourceBackNavigation
139
124
  };
140
125
  }
141
126
 
@@ -163,13 +148,10 @@ export function calculateMaxBackNavigation(files) {
163
148
  * ```
164
149
  */
165
150
  export function calculateMaxSourceBackNavigation(files) {
166
- var maxSourceBackNavigation = 0;
167
- for (var _i2 = 0, _Object$entries2 = Object.entries(files); _i2 < _Object$entries2.length; _i2++) {
168
- var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
169
- relativePath = _Object$entries2$_i[0],
170
- fileContent = _Object$entries2$_i[1];
151
+ let maxSourceBackNavigation = 0;
152
+ for (const [relativePath, fileContent] of Object.entries(files)) {
171
153
  // Check if this is a metadata file
172
- var isMetadata = _typeof(fileContent) === 'object' && fileContent.metadata;
154
+ const isMetadata = typeof fileContent === 'object' && fileContent.metadata;
173
155
 
174
156
  // Skip metadata files - only consider non-metadata files for maxSourceBackNavigation
175
157
  if (isMetadata) {
@@ -177,8 +159,9 @@ export function calculateMaxSourceBackNavigation(files) {
177
159
  }
178
160
 
179
161
  // Use path resolution to get the net back steps (most accurate)
180
- var _resolveRelativePath2 = resolveRelativePath(relativePath),
181
- backSteps = _resolveRelativePath2.backSteps;
162
+ const {
163
+ backSteps
164
+ } = resolveRelativePath(relativePath);
182
165
  maxSourceBackNavigation = Math.max(maxSourceBackNavigation, backSteps);
183
166
  }
184
167
  return maxSourceBackNavigation;
@@ -187,18 +170,14 @@ export function calculateMaxSourceBackNavigation(files) {
187
170
  /**
188
171
  * Build a path from multiple components, filtering out empty parts
189
172
  */
190
- export function buildPath() {
191
- var parts = [];
192
- for (var _len = arguments.length, segments = new Array(_len), _key = 0; _key < _len; _key++) {
193
- segments[_key] = arguments[_key];
194
- }
195
- for (var _i3 = 0, _segments = segments; _i3 < _segments.length; _i3++) {
196
- var segment = _segments[_i3];
173
+ export function buildPath(...segments) {
174
+ const parts = [];
175
+ for (const segment of segments) {
197
176
  if (segment === undefined) {
198
177
  continue;
199
178
  }
200
179
  if (Array.isArray(segment)) {
201
- parts.push.apply(parts, _toConsumableArray(segment));
180
+ parts.push(...segment);
202
181
  } else {
203
182
  parts.push(segment);
204
183
  }
@@ -215,9 +194,9 @@ export function buildPath() {
215
194
  export function createSyntheticDirectories(count) {
216
195
  return Array.from({
217
196
  length: count
218
- }, function (_, i) {
219
- var result = '';
220
- var num = i + 1; // 1-based for Excel-style naming
197
+ }, (_, i) => {
198
+ let result = '';
199
+ let num = i + 1; // 1-based for Excel-style naming
221
200
 
222
201
  while (num > 0) {
223
202
  num -= 1; // Adjust for 0-based indexing
@@ -245,13 +224,13 @@ export function createSyntheticDirectories(count) {
245
224
  */
246
225
  export function calculateMetadataBackNavigation(files, metadataPrefix) {
247
226
  // Get the maxSourceBackNavigation from the file structure
248
- var backLevels = 0;
227
+ let backLevels = 0;
249
228
  if (files) {
250
229
  backLevels = calculateMaxSourceBackNavigation(files);
251
230
  }
252
231
  if (metadataPrefix) {
253
232
  // When a prefix is provided, add additional back navigation based on prefix depth
254
- var prefixSegments = metadataPrefix.split('/').filter(Boolean);
233
+ const prefixSegments = metadataPrefix.split('/').filter(Boolean);
255
234
  backLevels += prefixSegments.length;
256
235
  }
257
236
  return '../'.repeat(backLevels);