@mui/internal-docs-infra 0.3.1-canary.2 → 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 (110) hide show
  1. package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
  2. package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
  3. package/esm/CodeHighlighter/CodeHighlighter.js +252 -327
  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/CodeHighlighter/types.d.ts +7 -1
  11. package/esm/CodeProvider/CodeContext.js +3 -3
  12. package/esm/CodeProvider/CodeProvider.js +31 -40
  13. package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
  14. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
  15. package/esm/cli/index.js +1 -1
  16. package/esm/cli/runValidate.js +160 -264
  17. package/esm/createDemoData/createDemoData.js +11 -12
  18. package/esm/createSitemap/createSitemap.js +2 -2
  19. package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
  20. package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
  21. package/esm/pipeline/hastUtils/hastUtils.js +16 -17
  22. package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
  23. package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
  24. package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
  25. package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
  26. package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
  27. package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
  28. package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
  29. package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
  30. package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +517 -727
  31. package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +683 -1032
  32. package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
  33. package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
  34. package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
  35. package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
  36. package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
  37. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
  38. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
  39. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
  40. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
  41. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
  42. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
  43. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
  44. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
  45. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
  46. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
  47. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
  48. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
  49. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
  50. package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
  51. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
  52. package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
  53. package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
  54. package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
  55. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
  56. package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
  57. package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
  58. package/esm/pipeline/loaderUtils/getLanguageFromExtension.d.ts +24 -0
  59. package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +62 -0
  60. package/esm/pipeline/loaderUtils/index.d.ts +2 -1
  61. package/esm/pipeline/loaderUtils/index.js +2 -1
  62. package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
  63. package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
  64. package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
  65. package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
  66. package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
  67. package/esm/pipeline/parseSource/addLineGutters.js +33 -45
  68. package/esm/pipeline/parseSource/grammars.d.ts +12 -1
  69. package/esm/pipeline/parseSource/grammars.js +36 -4
  70. package/esm/pipeline/parseSource/index.d.ts +2 -1
  71. package/esm/pipeline/parseSource/index.js +2 -1
  72. package/esm/pipeline/parseSource/parseSource.js +23 -32
  73. package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
  74. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
  75. package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
  76. package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
  77. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +266 -320
  78. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
  79. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +183 -267
  80. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
  81. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
  82. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
  83. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
  84. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
  85. package/esm/useCode/Pre.d.ts +2 -0
  86. package/esm/useCode/Pre.js +58 -60
  87. package/esm/useCode/useCode.js +59 -61
  88. package/esm/useCode/useCodeUtils.js +54 -63
  89. package/esm/useCode/useCopyFunctionality.js +10 -9
  90. package/esm/useCode/useFileNavigation.js +171 -209
  91. package/esm/useCode/useSourceEditing.js +17 -14
  92. package/esm/useCode/useTransformManagement.js +23 -26
  93. package/esm/useCode/useUIState.js +12 -20
  94. package/esm/useCode/useVariantSelection.js +62 -79
  95. package/esm/useCopier/index.js +29 -56
  96. package/esm/useDemo/createCodeSandbox.js +12 -15
  97. package/esm/useDemo/createStackBlitz.js +14 -20
  98. package/esm/useDemo/exportVariant.js +200 -180
  99. package/esm/useDemo/exportVariantAsCra.js +22 -25
  100. package/esm/useDemo/useDemo.js +80 -84
  101. package/esm/useErrors/ErrorsContext.js +1 -1
  102. package/esm/useErrors/useErrors.js +3 -3
  103. package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
  104. package/esm/usePreference/PreferencesProvider.js +1 -1
  105. package/esm/usePreference/usePreference.js +9 -11
  106. package/esm/useSearch/useSearch.js +290 -387
  107. package/esm/useUrlHashState/useUrlHashState.js +11 -14
  108. package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
  109. package/esm/withDocsInfra/withDocsInfra.js +99 -101
  110. package/package.json +7 -4
@@ -1,7 +1,3 @@
1
- import _regenerator from "@babel/runtime/helpers/esm/regenerator";
2
- import _extends from "@babel/runtime/helpers/esm/extends";
3
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
1
  // webpack does not like node: imports
6
2
  // eslint-disable-next-line n/prefer-node-protocol
7
3
  import { readFile } from 'fs/promises';
@@ -17,7 +13,7 @@ import { isJavaScriptModule } from "../loaderUtils/resolveModulePath.js";
17
13
  * It reads the source file, resolves its imports, and returns the processed source along with any
18
14
  * additional files and dependencies that were found.
19
15
  */
20
- export var loadServerSource = createLoadServerSource();
16
+ export const loadServerSource = createLoadServerSource();
21
17
 
22
18
  /**
23
19
  * Creates a loadSource function that reads a file and extracts its dependencies.
@@ -27,151 +23,128 @@ export var loadServerSource = createLoadServerSource();
27
23
  * - 'import': Import path with file extension (e.g., '../Component.js')
28
24
  * - 'flat': Flattened to current directory with rewritten imports (e.g., './Component.js')
29
25
  */
30
- export function createLoadServerSource() {
31
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
32
- var _options$includeDepen = options.includeDependencies,
33
- includeDependencies = _options$includeDepen === void 0 ? true : _options$includeDepen,
34
- _options$storeAt = options.storeAt,
35
- storeAt = _options$storeAt === void 0 ? 'flat' : _options$storeAt;
36
- return /*#__PURE__*/function () {
37
- var _loadSource = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(url) {
38
- var filePath, source, isJavascriptModuleFile, isCssFile, _yield$parseImportsAn, importResult, externals, transformedExternals, _i, _Object$entries, _Object$entries$_i, modulePath, externalImport, processedSource, extraFiles, extraDependencies, importsCompatible, _i2, _Object$entries2, _Object$entries2$_i, importPath, _Object$entries2$_i$, importUrl, names, positions, result, relativeImportsCompatible, _i3, _Object$entries3, _Object$entries3$_i, _importPath, _Object$entries3$_i$, _importUrl, _names, includeTypeDefs, _positions, resolvedPathsMap, _result;
39
- return _regenerator().w(function (_context) {
40
- while (1) switch (_context.n) {
41
- case 0:
42
- // Convert file:// URL to proper file system path for reading the file
43
- // Using fileURLToPath handles Windows drive letters correctly (e.g., file:///C:/... → C:\...)
44
- filePath = url.startsWith('file://') ? fileURLToPath(url) : url; // Read the file
45
- _context.n = 1;
46
- return readFile(filePath, 'utf8');
47
- case 1:
48
- source = _context.v;
49
- if (includeDependencies) {
50
- _context.n = 2;
51
- break;
52
- }
53
- return _context.a(2, {
54
- source: source
55
- });
56
- case 2:
57
- // Check if this is a static asset file (non-JS/TS modules)
58
- isJavascriptModuleFile = isJavaScriptModule(filePath);
59
- isCssFile = filePath.toLowerCase().endsWith('.css');
60
- if (!(!isJavascriptModuleFile && !isCssFile)) {
61
- _context.n = 3;
62
- break;
63
- }
64
- return _context.a(2, {
65
- source: source
66
- });
67
- case 3:
68
- _context.n = 4;
69
- return parseImportsAndComments(source, url);
70
- case 4:
71
- _yield$parseImportsAn = _context.v;
72
- importResult = _yield$parseImportsAn.relative;
73
- externals = _yield$parseImportsAn.externals;
74
- // Transform externals from parseImportsAndComments format to simplified format
75
- transformedExternals = {};
76
- for (_i = 0, _Object$entries = Object.entries(externals); _i < _Object$entries.length; _i++) {
77
- _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), modulePath = _Object$entries$_i[0], externalImport = _Object$entries$_i[1];
78
- transformedExternals[modulePath] = externalImport.names.map(function (importName) {
79
- return {
80
- name: importName.name,
81
- type: importName.type,
82
- isType: importName.isType
83
- };
84
- });
85
- }
86
- if (!(Object.keys(importResult).length === 0)) {
87
- _context.n = 5;
88
- break;
89
- }
90
- return _context.a(2, {
91
- source: source,
92
- externals: Object.keys(transformedExternals).length > 0 ? transformedExternals : undefined
93
- });
94
- case 5:
95
- // Convert import result to the format expected by processImports, preserving position data
96
- importsCompatible = {};
97
- for (_i2 = 0, _Object$entries2 = Object.entries(importResult); _i2 < _Object$entries2.length; _i2++) {
98
- _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2), importPath = _Object$entries2$_i[0], _Object$entries2$_i$ = _Object$entries2$_i[1], importUrl = _Object$entries2$_i$.url, names = _Object$entries2$_i$.names, positions = _Object$entries2$_i$.positions;
99
- importsCompatible[importPath] = {
100
- url: importUrl,
101
- names: names.map(function (_ref) {
102
- var name = _ref.name,
103
- alias = _ref.alias;
104
- return alias || name;
105
- }),
106
- positions: positions
107
- };
108
- }
109
- if (!isCssFile) {
110
- _context.n = 6;
111
- break;
112
- }
113
- // For CSS files, we don't need complex path resolution
114
- // The parseImportsAndComments function already resolved paths for CSS
115
- result = processRelativeImports(source, importsCompatible, storeAt);
116
- processedSource = result.processedSource;
117
- extraFiles = result.extraFiles;
26
+ export function createLoadServerSource(options = {}) {
27
+ const {
28
+ includeDependencies = true,
29
+ storeAt = 'flat'
30
+ } = options;
31
+ return async function loadSource(url) {
32
+ // Convert file:// URL to proper file system path for reading the file
33
+ // Using fileURLToPath handles Windows drive letters correctly (e.g., file:///C:/... → C:\...)
34
+ const filePath = url.startsWith('file://') ? fileURLToPath(url) : url;
118
35
 
119
- // Build dependencies list for recursive loading (CSS files use direct paths)
120
- extraDependencies = Object.values(importResult).map(function (_ref2) {
121
- var importUrl = _ref2.url;
122
- return importUrl;
123
- });
124
- _context.n = 8;
125
- break;
126
- case 6:
127
- // For JavaScript/TypeScript files, resolve paths first
128
- relativeImportsCompatible = {};
129
- for (_i3 = 0, _Object$entries3 = Object.entries(importResult); _i3 < _Object$entries3.length; _i3++) {
130
- _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2), _importPath = _Object$entries3$_i[0], _Object$entries3$_i$ = _Object$entries3$_i[1], _importUrl = _Object$entries3$_i$.url, _names = _Object$entries3$_i$.names, includeTypeDefs = _Object$entries3$_i$.includeTypeDefs, _positions = _Object$entries3$_i$.positions;
131
- relativeImportsCompatible[_importPath] = _extends({
132
- url: _importUrl,
133
- names: _names.map(function (_ref3) {
134
- var name = _ref3.name,
135
- alias = _ref3.alias;
136
- return alias || name;
137
- }),
138
- // Use alias if available
139
- positions: _positions
140
- }, includeTypeDefs && {
141
- includeTypeDefs: includeTypeDefs
142
- });
143
- }
36
+ // Read the file
37
+ const source = await readFile(filePath, 'utf8');
38
+ if (!includeDependencies) {
39
+ return {
40
+ source
41
+ };
42
+ }
43
+
44
+ // Check if this is a static asset file (non-JS/TS modules)
45
+ const isJavascriptModuleFile = isJavaScriptModule(filePath);
46
+ const isCssFile = filePath.toLowerCase().endsWith('.css');
47
+ if (!isJavascriptModuleFile && !isCssFile) {
48
+ // Static assets (CSS, JSON, etc.) don't have imports to resolve
49
+ return {
50
+ source
51
+ };
52
+ }
53
+
54
+ // Get all relative imports from this file
55
+ // Pass the original URL to parseImportsAndComments for cross-platform path handling
56
+ const {
57
+ relative: importResult,
58
+ externals
59
+ } = await parseImportsAndComments(source, url);
60
+
61
+ // Transform externals from parseImportsAndComments format to simplified format
62
+ const transformedExternals = {};
63
+ for (const [modulePath, externalImport] of Object.entries(externals)) {
64
+ transformedExternals[modulePath] = externalImport.names.map(importName => ({
65
+ name: importName.name,
66
+ type: importName.type,
67
+ isType: importName.isType
68
+ }));
69
+ }
70
+ if (Object.keys(importResult).length === 0) {
71
+ return {
72
+ source,
73
+ externals: Object.keys(transformedExternals).length > 0 ? transformedExternals : undefined
74
+ };
75
+ }
76
+ let processedSource;
77
+ let extraFiles;
78
+ let extraDependencies;
79
+
80
+ // Convert import result to the format expected by processImports, preserving position data
81
+ const importsCompatible = {};
82
+ for (const [importPath, {
83
+ url: importUrl,
84
+ names,
85
+ positions
86
+ }] of Object.entries(importResult)) {
87
+ importsCompatible[importPath] = {
88
+ url: importUrl,
89
+ names: names.map(({
90
+ name,
91
+ alias
92
+ }) => alias || name),
93
+ positions
94
+ };
95
+ }
96
+ if (isCssFile) {
97
+ // For CSS files, we don't need complex path resolution
98
+ // The parseImportsAndComments function already resolved paths for CSS
99
+ const result = processRelativeImports(source, importsCompatible, storeAt);
100
+ processedSource = result.processedSource;
101
+ extraFiles = result.extraFiles;
102
+
103
+ // Build dependencies list for recursive loading (CSS files use direct paths)
104
+ extraDependencies = Object.values(importResult).map(({
105
+ url: importUrl
106
+ }) => importUrl);
107
+ } else {
108
+ // For JavaScript/TypeScript files, resolve paths first
109
+ const relativeImportsCompatible = {};
110
+ for (const [importPath, {
111
+ url: importUrl,
112
+ names,
113
+ includeTypeDefs,
114
+ positions
115
+ }] of Object.entries(importResult)) {
116
+ relativeImportsCompatible[importPath] = {
117
+ url: importUrl,
118
+ names: names.map(({
119
+ name,
120
+ alias
121
+ }) => alias || name),
122
+ // Use alias if available
123
+ positions,
124
+ ...(includeTypeDefs && {
125
+ includeTypeDefs
126
+ })
127
+ };
128
+ }
129
+
130
+ // Resolve import paths, handling JS/TS modules and static assets appropriately
131
+ const resolvedPathsMap = await resolveImportResultWithFs(relativeImportsCompatible);
144
132
 
145
- // Resolve import paths, handling JS/TS modules and static assets appropriately
146
- _context.n = 7;
147
- return resolveImportResultWithFs(relativeImportsCompatible);
148
- case 7:
149
- resolvedPathsMap = _context.v;
150
- // Process imports using the unified helper function
151
- _result = processRelativeImports(source, importsCompatible, storeAt, true, resolvedPathsMap);
152
- processedSource = _result.processedSource;
153
- extraFiles = _result.extraFiles;
133
+ // Process imports using the unified helper function
134
+ const result = processRelativeImports(source, importsCompatible, storeAt, true, resolvedPathsMap);
135
+ processedSource = result.processedSource;
136
+ extraFiles = result.extraFiles;
154
137
 
155
- // Build dependencies list for recursive loading
156
- extraDependencies = Object.values(importResult).map(function (_ref4) {
157
- var importUrl = _ref4.url;
158
- return resolvedPathsMap.get(importUrl);
159
- }).filter(function (resolved) {
160
- return resolved !== undefined;
161
- });
162
- case 8:
163
- return _context.a(2, {
164
- source: processedSource,
165
- extraFiles: Object.keys(extraFiles).length > 0 ? extraFiles : undefined,
166
- extraDependencies: extraDependencies.length > 0 ? extraDependencies : undefined,
167
- externals: Object.keys(transformedExternals).length > 0 ? transformedExternals : undefined
168
- });
169
- }
170
- }, _callee);
171
- }));
172
- function loadSource(_x) {
173
- return _loadSource.apply(this, arguments);
138
+ // Build dependencies list for recursive loading
139
+ extraDependencies = Object.values(importResult).map(({
140
+ url: importUrl
141
+ }) => resolvedPathsMap.get(importUrl)).filter(resolved => resolved !== undefined);
174
142
  }
175
- return loadSource;
176
- }();
143
+ return {
144
+ source: processedSource,
145
+ extraFiles: Object.keys(extraFiles).length > 0 ? extraFiles : undefined,
146
+ extraDependencies: extraDependencies.length > 0 ? extraDependencies : undefined,
147
+ externals: Object.keys(transformedExternals).length > 0 ? transformedExternals : undefined
148
+ };
149
+ };
177
150
  }
@@ -1,13 +1,13 @@
1
1
  export function externalsToPackages(externals) {
2
- var packages = {};
3
- externals.forEach(function (external) {
2
+ const packages = {};
3
+ externals.forEach(external => {
4
4
  // Filter out path aliases that start with @/
5
5
  if (external.startsWith('@/')) {
6
6
  return;
7
7
  }
8
8
 
9
9
  // Extract package name from import path
10
- var packageName = extractPackageName(external);
10
+ const packageName = extractPackageName(external);
11
11
  if (packageName) {
12
12
  packages[packageName] = true;
13
13
  }
@@ -32,15 +32,15 @@ function extractPackageName(importPath) {
32
32
 
33
33
  // Handle scoped packages (starting with @)
34
34
  if (importPath.startsWith('@')) {
35
- var _parts = importPath.split('/');
36
- if (_parts.length >= 2) {
35
+ const parts = importPath.split('/');
36
+ if (parts.length >= 2) {
37
37
  // Return @scope/package-name
38
- return "".concat(_parts[0], "/").concat(_parts[1]);
38
+ return `${parts[0]}/${parts[1]}`;
39
39
  }
40
40
  return null;
41
41
  }
42
42
 
43
43
  // Handle regular packages
44
- var parts = importPath.split('/');
44
+ const parts = importPath.split('/');
45
45
  return parts[0] || null;
46
46
  }
@@ -39,9 +39,7 @@ function camelToTitleCase(camelCase) {
39
39
  // Insert spaces before letters that follow numbers
40
40
  .replace(/([0-9])([a-zA-Z])/g, '$1 $2')
41
41
  // Capitalize the first letter
42
- .replace(/^./, function (str) {
43
- return str.toUpperCase();
44
- });
42
+ .replace(/^./, str => str.toUpperCase());
45
43
  }
46
44
 
47
45
  /**
@@ -51,9 +49,7 @@ function camelToTitleCase(camelCase) {
51
49
  */
52
50
  function kebabToTitleCase(kebabCase) {
53
51
  return kebabCase.split(/[-_]/) // Split on both hyphens and underscores
54
- .map(function (word) {
55
- return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
56
- }).join(' ');
52
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(' ');
57
53
  }
58
54
 
59
55
  /**
@@ -86,19 +82,19 @@ function toKebabCase(str) {
86
82
  function extractLastSegment(url) {
87
83
  // Convert to portable path format for consistent handling across platforms
88
84
  // This handles file:// URLs, Windows paths with backslashes, and regular paths
89
- var path = fileUrlToPortablePath(url);
85
+ const path = fileUrlToPortablePath(url);
90
86
 
91
87
  // Strip query parameters and hash fragments before processing
92
- var cleanPath = path.split('?')[0].split('#')[0];
88
+ const cleanPath = path.split('?')[0].split('#')[0];
93
89
 
94
90
  // Split the path into segments and filter out empty ones
95
- var segments = cleanPath.split('/').filter(Boolean);
91
+ const segments = cleanPath.split('/').filter(Boolean);
96
92
  if (segments.length === 0) {
97
93
  throw new Error('Could not extract meaningful segment from URL');
98
94
  }
99
95
 
100
96
  // Get the last segment
101
- var lastSegment = segments[segments.length - 1];
97
+ let lastSegment = segments[segments.length - 1];
102
98
 
103
99
  // Handle index files - any file that starts with 'index.'
104
100
  if (lastSegment.startsWith('index.')) {
@@ -110,7 +106,7 @@ function extractLastSegment(url) {
110
106
  } else {
111
107
  // Strip everything after the first dot from non-index files
112
108
  // This handles all extensions: .js, .d.ts, .module.css, .config.dev.js, etc.
113
- var firstDotIndex = lastSegment.indexOf('.');
109
+ const firstDotIndex = lastSegment.indexOf('.');
114
110
  if (firstDotIndex !== -1) {
115
111
  lastSegment = lastSegment.substring(0, firstDotIndex);
116
112
  }
@@ -143,7 +139,7 @@ function extractLastSegment(url) {
143
139
  * // Returns: { name: 'Getting Started', slug: 'getting-started' }
144
140
  */
145
141
  export function extractNameAndSlugFromUrl(url) {
146
- var segment = extractLastSegment(url);
142
+ const segment = extractLastSegment(url);
147
143
 
148
144
  // Check if the segment is camelCase and handle it appropriately
149
145
  if (isCamelCase(segment)) {
@@ -28,10 +28,10 @@ export function fileUrlToPortablePath(fileUrl) {
28
28
  // If it's not a file:// URL, check if it's already a portable path
29
29
  if (!fileUrl.startsWith('file://')) {
30
30
  // Normalize backslashes to forward slashes
31
- var normalized = fileUrl.replace(/\\/g, '/');
31
+ const normalized = fileUrl.replace(/\\/g, '/');
32
32
  // If it doesn't start with /, it's likely a Windows path - add leading slash
33
33
  if (!normalized.startsWith('/') && /^[a-zA-Z]:\//.test(normalized)) {
34
- return "/".concat(normalized);
34
+ return `/${normalized}`;
35
35
  }
36
36
  return normalized;
37
37
  }
@@ -39,14 +39,14 @@ export function fileUrlToPortablePath(fileUrl) {
39
39
  // Strip the file:// prefix
40
40
  // file:///home/user/file.ts => /home/user/file.ts (Unix)
41
41
  // file:///C:/Users/file.ts => /C:/Users/file.ts (Windows - keep the leading slash)
42
- var path = fileUrl.slice(7); // Remove 'file://'
42
+ let path = fileUrl.slice(7); // Remove 'file://'
43
43
 
44
44
  // Normalize any backslashes that might have snuck in
45
45
  path = path.replace(/\\/g, '/');
46
46
 
47
47
  // If it doesn't start with /, add one (should already have one for valid file:// URLs)
48
48
  if (!path.startsWith('/')) {
49
- path = "/".concat(path);
49
+ path = `/${path}`;
50
50
  }
51
51
  return path;
52
52
  }
@@ -76,5 +76,5 @@ export function portablePathToFileUrl(portablePath) {
76
76
  // For Windows portable paths like /C:/Users/..., we need file:// + path
77
77
  // For Unix paths like /home/user/..., we need file:// + path
78
78
  // Both cases: file:// + /path = file:///path
79
- return "file://".concat(portablePath);
79
+ return `file://${portablePath}`;
80
80
  }
@@ -1,8 +1,7 @@
1
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
1
  /**
3
2
  * Known compound extensions that should be treated as a single unit
4
3
  */
5
- var COMPOUND_EXTENSIONS = ['.module.css', '.module.scss', '.module.sass', '.module.less', '.d.ts', '.test.js', '.test.jsx', '.test.ts', '.test.tsx', '.spec.js', '.spec.jsx', '.spec.ts', '.spec.tsx', '.config.js', '.config.ts', '.setup.js', '.setup.ts', '.stories.js', '.stories.jsx', '.stories.ts', '.stories.tsx'];
4
+ const COMPOUND_EXTENSIONS = ['.module.css', '.module.scss', '.module.sass', '.module.less', '.d.ts', '.test.js', '.test.jsx', '.test.ts', '.test.tsx', '.spec.js', '.spec.jsx', '.spec.ts', '.spec.tsx', '.config.js', '.config.ts', '.setup.js', '.setup.ts', '.stories.js', '.stories.jsx', '.stories.ts', '.stories.tsx'];
6
5
 
7
6
  /**
8
7
  * Extracts the filename and extension from a URL or file path.
@@ -15,14 +14,14 @@ var COMPOUND_EXTENSIONS = ['.module.css', '.module.scss', '.module.sass', '.modu
15
14
  export function getFileNameFromUrl(url) {
16
15
  try {
17
16
  // Use URL constructor to handle various URL formats
18
- var urlObj = new URL(url);
19
- var pathname = urlObj.pathname;
20
- var fileName = pathname.split('/').pop() || '';
17
+ const urlObj = new URL(url);
18
+ const pathname = urlObj.pathname;
19
+ const fileName = pathname.split('/').pop() || '';
21
20
  return extractFileNameAndExtension(fileName);
22
- } catch (_unused) {
21
+ } catch {
23
22
  // If URL parsing fails, fall back to simple string manipulation
24
- var _fileName = url.split('/').pop() || url;
25
- return extractFileNameAndExtension(_fileName);
23
+ const fileName = url.split('/').pop() || url;
24
+ return extractFileNameAndExtension(fileName);
26
25
  }
27
26
  }
28
27
 
@@ -38,29 +37,20 @@ function extractFileNameAndExtension(fileName) {
38
37
  }
39
38
 
40
39
  // Check for compound extensions first
41
- var _iterator = _createForOfIteratorHelper(COMPOUND_EXTENSIONS),
42
- _step;
43
- try {
44
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
45
- var compoundExt = _step.value;
46
- if (fileName.endsWith(compoundExt)) {
47
- return {
48
- fileName: fileName,
49
- extension: compoundExt
50
- };
51
- }
40
+ for (const compoundExt of COMPOUND_EXTENSIONS) {
41
+ if (fileName.endsWith(compoundExt)) {
42
+ return {
43
+ fileName,
44
+ extension: compoundExt
45
+ };
52
46
  }
53
-
54
- // Fall back to simple extension detection
55
- } catch (err) {
56
- _iterator.e(err);
57
- } finally {
58
- _iterator.f();
59
47
  }
60
- var lastDotIndex = fileName.lastIndexOf('.');
61
- var extension = lastDotIndex > 0 ? fileName.substring(lastDotIndex) : '';
48
+
49
+ // Fall back to simple extension detection
50
+ const lastDotIndex = fileName.lastIndexOf('.');
51
+ const extension = lastDotIndex > 0 ? fileName.substring(lastDotIndex) : '';
62
52
  return {
63
- fileName: fileName,
64
- extension: extension
53
+ fileName,
54
+ extension
65
55
  };
66
56
  }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Maps file extensions to language names.
3
+ * These are user-friendly names that can be used in the `language` prop.
4
+ */
5
+ export declare const languageMap: Record<string, string>;
6
+ /**
7
+ * Maps language aliases to canonical language names.
8
+ * Used to normalize short language names (e.g., from className like 'language-js')
9
+ * to their full names.
10
+ */
11
+ export declare const languageAliasMap: Record<string, string>;
12
+ /**
13
+ * Gets the language name from a file extension.
14
+ * @param extension - The file extension (e.g., '.tsx', '.css')
15
+ * @returns The language name or undefined if not recognized
16
+ */
17
+ export declare function getLanguageFromExtension(extension: string): string | undefined;
18
+ /**
19
+ * Normalizes a language name to its canonical form.
20
+ * This handles aliases like 'js' -> 'javascript', 'ts' -> 'typescript'.
21
+ * @param language - The language name or alias
22
+ * @returns The canonical language name, or the input if not a known alias
23
+ */
24
+ export declare function normalizeLanguage(language: string): string;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Maps file extensions to language names.
3
+ * These are user-friendly names that can be used in the `language` prop.
4
+ */
5
+ export const languageMap = {
6
+ '.js': 'javascript',
7
+ '.ts': 'typescript',
8
+ '.jsx': 'jsx',
9
+ '.tsx': 'tsx',
10
+ '.json': 'json',
11
+ '.md': 'markdown',
12
+ '.mdx': 'mdx',
13
+ '.html': 'html',
14
+ '.css': 'css',
15
+ '.sh': 'shell',
16
+ '.yaml': 'yaml',
17
+ '.yml': 'yaml'
18
+ };
19
+
20
+ /**
21
+ * Maps language aliases to canonical language names.
22
+ * Used to normalize short language names (e.g., from className like 'language-js')
23
+ * to their full names.
24
+ */
25
+ export const languageAliasMap = {
26
+ js: 'javascript',
27
+ ts: 'typescript',
28
+ javascript: 'javascript',
29
+ typescript: 'typescript',
30
+ jsx: 'jsx',
31
+ tsx: 'tsx',
32
+ json: 'json',
33
+ md: 'markdown',
34
+ markdown: 'markdown',
35
+ mdx: 'mdx',
36
+ html: 'html',
37
+ css: 'css',
38
+ sh: 'shell',
39
+ bash: 'shell',
40
+ shell: 'shell',
41
+ yaml: 'yaml',
42
+ yml: 'yaml'
43
+ };
44
+
45
+ /**
46
+ * Gets the language name from a file extension.
47
+ * @param extension - The file extension (e.g., '.tsx', '.css')
48
+ * @returns The language name or undefined if not recognized
49
+ */
50
+ export function getLanguageFromExtension(extension) {
51
+ return languageMap[extension];
52
+ }
53
+
54
+ /**
55
+ * Normalizes a language name to its canonical form.
56
+ * This handles aliases like 'js' -> 'javascript', 'ts' -> 'typescript'.
57
+ * @param language - The language name or alias
58
+ * @returns The canonical language name, or the input if not a known alias
59
+ */
60
+ export function normalizeLanguage(language) {
61
+ return languageAliasMap[language] ?? language;
62
+ }
@@ -5,4 +5,5 @@ export * from "./processRelativeImports.js";
5
5
  export * from "./getFileNameFromUrl.js";
6
6
  export * from "./extractNameAndSlugFromUrl.js";
7
7
  export * from "./externalsToPackages.js";
8
- export * from "./fileUrlToPortablePath.js";
8
+ export * from "./fileUrlToPortablePath.js";
9
+ export * from "./getLanguageFromExtension.js";
@@ -5,4 +5,5 @@ export * from "./processRelativeImports.js";
5
5
  export * from "./getFileNameFromUrl.js";
6
6
  export * from "./extractNameAndSlugFromUrl.js";
7
7
  export * from "./externalsToPackages.js";
8
- export * from "./fileUrlToPortablePath.js";
8
+ export * from "./fileUrlToPortablePath.js";
9
+ export * from "./getLanguageFromExtension.js";