@mui/internal-docs-infra 0.1.1-canary.9 → 0.2.0-alpha.2

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 (217) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +3 -11
  3. package/esm/CodeControllerContext/CodeControllerContext.d.ts +62 -0
  4. package/esm/CodeControllerContext/CodeControllerContext.js +33 -0
  5. package/esm/CodeControllerContext/index.d.ts +1 -0
  6. package/esm/CodeControllerContext/index.js +1 -0
  7. package/esm/CodeExternalsContext/CodeExternalsContext.d.ts +8 -0
  8. package/esm/CodeExternalsContext/CodeExternalsContext.js +8 -0
  9. package/esm/CodeExternalsContext/index.d.ts +1 -0
  10. package/esm/CodeExternalsContext/index.js +1 -0
  11. package/esm/CodeHighlighter/CodeHighlighter.d.ts +2 -0
  12. package/esm/CodeHighlighter/CodeHighlighter.js +441 -0
  13. package/esm/CodeHighlighter/CodeHighlighterClient.d.ts +2 -0
  14. package/esm/CodeHighlighter/CodeHighlighterClient.js +984 -0
  15. package/esm/CodeHighlighter/CodeHighlighterContext.d.ts +16 -0
  16. package/esm/CodeHighlighter/CodeHighlighterContext.js +15 -0
  17. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.d.ts +7 -0
  18. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +14 -0
  19. package/esm/CodeHighlighter/addPathsToVariant.d.ts +14 -0
  20. package/esm/CodeHighlighter/addPathsToVariant.js +68 -0
  21. package/esm/CodeHighlighter/applyTransform.d.ts +19 -0
  22. package/esm/CodeHighlighter/applyTransform.js +75 -0
  23. package/esm/CodeHighlighter/calculateMainFilePath.d.ts +1 -0
  24. package/esm/CodeHighlighter/calculateMainFilePath.js +108 -0
  25. package/esm/CodeHighlighter/codeToFallbackProps.d.ts +2 -0
  26. package/esm/CodeHighlighter/codeToFallbackProps.js +73 -0
  27. package/esm/CodeHighlighter/errors.d.ts +141 -0
  28. package/esm/CodeHighlighter/errors.js +441 -0
  29. package/esm/CodeHighlighter/examineVariant.d.ts +25 -0
  30. package/esm/CodeHighlighter/examineVariant.js +73 -0
  31. package/esm/CodeHighlighter/hasAllVariants.d.ts +27 -0
  32. package/esm/CodeHighlighter/hasAllVariants.js +63 -0
  33. package/esm/CodeHighlighter/index.d.ts +1 -0
  34. package/esm/CodeHighlighter/index.js +1 -0
  35. package/esm/CodeHighlighter/loadFallbackCode.d.ts +10 -0
  36. package/esm/CodeHighlighter/loadFallbackCode.js +679 -0
  37. package/esm/CodeHighlighter/loadVariant.d.ts +12 -0
  38. package/esm/CodeHighlighter/loadVariant.js +1044 -0
  39. package/esm/CodeHighlighter/maybeInitialData.d.ts +108 -0
  40. package/esm/CodeHighlighter/maybeInitialData.js +192 -0
  41. package/esm/CodeHighlighter/mergeMetadata.d.ts +40 -0
  42. package/esm/CodeHighlighter/mergeMetadata.js +165 -0
  43. package/esm/CodeHighlighter/parseCode.d.ts +6 -0
  44. package/esm/CodeHighlighter/parseCode.js +134 -0
  45. package/esm/CodeHighlighter/parseControlledCode.d.ts +6 -0
  46. package/esm/CodeHighlighter/parseControlledCode.js +87 -0
  47. package/esm/CodeHighlighter/pathUtils.d.ts +120 -0
  48. package/esm/CodeHighlighter/pathUtils.js +258 -0
  49. package/esm/CodeHighlighter/transformCode.d.ts +21 -0
  50. package/esm/CodeHighlighter/transformCode.js +251 -0
  51. package/esm/CodeHighlighter/transformParsedSource.d.ts +3 -0
  52. package/esm/CodeHighlighter/transformParsedSource.js +60 -0
  53. package/esm/CodeHighlighter/transformSource.d.ts +2 -0
  54. package/esm/CodeHighlighter/transformSource.js +103 -0
  55. package/esm/CodeHighlighter/types.d.ts +276 -0
  56. package/esm/CodeHighlighter/types.js +1 -0
  57. package/esm/CodeProvider/CodeContext.d.ts +31 -0
  58. package/esm/CodeProvider/CodeContext.js +12 -0
  59. package/esm/CodeProvider/CodeProvider.d.ts +13 -0
  60. package/esm/CodeProvider/CodeProvider.js +83 -0
  61. package/esm/CodeProvider/index.d.ts +1 -0
  62. package/esm/CodeProvider/index.js +1 -0
  63. package/esm/abstractCreateDemo/abstractCreateDemo.d.ts +45 -0
  64. package/esm/abstractCreateDemo/abstractCreateDemo.js +100 -0
  65. package/esm/abstractCreateDemo/index.d.ts +1 -0
  66. package/esm/abstractCreateDemo/index.js +1 -0
  67. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.d.ts +32 -0
  68. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +52 -0
  69. package/esm/abstractCreateDemoClient/index.d.ts +1 -0
  70. package/esm/abstractCreateDemoClient/index.js +1 -0
  71. package/esm/createDemoData/createDemoData.d.ts +44 -0
  72. package/esm/createDemoData/createDemoData.js +74 -0
  73. package/esm/createDemoData/index.d.ts +1 -0
  74. package/esm/createDemoData/index.js +1 -0
  75. package/esm/createDemoData/types.d.ts +25 -0
  76. package/esm/createDemoData/types.js +1 -0
  77. package/esm/pipeline/hastUtils/hastUtils.d.ts +11 -0
  78. package/esm/pipeline/hastUtils/hastUtils.js +67 -0
  79. package/esm/pipeline/hastUtils/index.d.ts +1 -0
  80. package/esm/pipeline/hastUtils/index.js +1 -0
  81. package/esm/pipeline/loadPrecomputedCodeHighlighter/index.d.ts +2 -0
  82. package/esm/pipeline/loadPrecomputedCodeHighlighter/index.js +4 -0
  83. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +14 -0
  84. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +178 -0
  85. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +47 -0
  86. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +849 -0
  87. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.d.ts +85 -0
  88. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +715 -0
  89. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts +14 -0
  90. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +73 -0
  91. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.d.ts +11 -0
  92. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +203 -0
  93. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.d.ts +6 -0
  94. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +23 -0
  95. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.d.ts +6 -0
  96. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +148 -0
  97. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.d.ts +9 -0
  98. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +198 -0
  99. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.d.ts +2 -0
  100. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.js +4 -0
  101. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.d.ts +5 -0
  102. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +21 -0
  103. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.d.ts +15 -0
  104. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +233 -0
  105. package/esm/pipeline/loadServerCodeMeta/index.d.ts +1 -0
  106. package/esm/pipeline/loadServerCodeMeta/index.js +1 -0
  107. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts +24 -0
  108. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +90 -0
  109. package/esm/pipeline/loadServerSource/index.d.ts +1 -0
  110. package/esm/pipeline/loadServerSource/index.js +1 -0
  111. package/esm/pipeline/loadServerSource/loadServerSource.d.ts +25 -0
  112. package/esm/pipeline/loadServerSource/loadServerSource.js +134 -0
  113. package/esm/pipeline/loaderUtils/externalsToPackages.d.ts +1 -0
  114. package/esm/pipeline/loaderUtils/externalsToPackages.js +46 -0
  115. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.d.ts +34 -0
  116. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +161 -0
  117. package/esm/pipeline/loaderUtils/getFileNameFromUrl.d.ts +12 -0
  118. package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +66 -0
  119. package/esm/pipeline/loaderUtils/index.d.ts +7 -0
  120. package/esm/pipeline/loaderUtils/index.js +7 -0
  121. package/esm/pipeline/loaderUtils/mergeExternals.d.ts +32 -0
  122. package/esm/pipeline/loaderUtils/mergeExternals.js +72 -0
  123. package/esm/pipeline/loaderUtils/parseImports.d.ts +19 -0
  124. package/esm/pipeline/loaderUtils/parseImports.js +306 -0
  125. package/esm/pipeline/loaderUtils/processRelativeImports.d.ts +19 -0
  126. package/esm/pipeline/loaderUtils/processRelativeImports.js +352 -0
  127. package/esm/pipeline/loaderUtils/resolveModulePath.d.ts +87 -0
  128. package/esm/pipeline/loaderUtils/resolveModulePath.js +1435 -0
  129. package/esm/pipeline/loaderUtils/resolveModulePathWithFs.d.ts +47 -0
  130. package/esm/pipeline/loaderUtils/resolveModulePathWithFs.js +150 -0
  131. package/esm/pipeline/loaderUtils/rewriteImports.d.ts +9 -0
  132. package/esm/pipeline/loaderUtils/rewriteImports.js +35 -0
  133. package/esm/pipeline/parseSource/addLineGutters.d.ts +9 -0
  134. package/esm/pipeline/parseSource/addLineGutters.js +181 -0
  135. package/esm/pipeline/parseSource/grammars.d.ts +2 -0
  136. package/esm/pipeline/parseSource/grammars.js +27 -0
  137. package/esm/pipeline/parseSource/index.d.ts +1 -0
  138. package/esm/pipeline/parseSource/index.js +1 -0
  139. package/esm/pipeline/parseSource/parseSource.d.ts +3 -0
  140. package/esm/pipeline/parseSource/parseSource.js +51 -0
  141. package/esm/pipeline/transformHtmlCode/index.d.ts +2 -0
  142. package/esm/pipeline/transformHtmlCode/index.js +4 -0
  143. package/esm/pipeline/transformHtmlCode/transformHtmlCode.d.ts +13 -0
  144. package/esm/pipeline/transformHtmlCode/transformHtmlCode.js +300 -0
  145. package/esm/pipeline/transformMarkdownCode/index.d.ts +2 -0
  146. package/esm/pipeline/transformMarkdownCode/index.js +4 -0
  147. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.d.ts +2 -0
  148. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +514 -0
  149. package/esm/pipeline/transformTypescriptToJavascript/index.d.ts +1 -0
  150. package/esm/pipeline/transformTypescriptToJavascript/index.js +1 -0
  151. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.d.ts +13 -0
  152. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +131 -0
  153. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.d.ts +3 -0
  154. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +31 -0
  155. package/esm/useCode/Pre.d.ts +15 -0
  156. package/esm/useCode/Pre.js +164 -0
  157. package/esm/useCode/index.d.ts +1 -0
  158. package/esm/useCode/index.js +1 -0
  159. package/esm/useCode/useCode.d.ts +41 -0
  160. package/esm/useCode/useCode.js +128 -0
  161. package/esm/useCode/useCodeUtils.d.ts +44 -0
  162. package/esm/useCode/useCodeUtils.js +245 -0
  163. package/esm/useCode/useCopyFunctionality.d.ts +18 -0
  164. package/esm/useCode/useCopyFunctionality.js +28 -0
  165. package/esm/useCode/useFileNavigation.d.ts +41 -0
  166. package/esm/useCode/useFileNavigation.js +453 -0
  167. package/esm/useCode/useSourceEditing.d.ts +21 -0
  168. package/esm/useCode/useSourceEditing.js +32 -0
  169. package/esm/useCode/useTransformManagement.d.ts +30 -0
  170. package/esm/useCode/useTransformManagement.js +72 -0
  171. package/esm/useCode/useUIState.d.ts +16 -0
  172. package/esm/useCode/useUIState.js +21 -0
  173. package/esm/useCode/useVariantSelection.d.ts +23 -0
  174. package/esm/useCode/useVariantSelection.js +75 -0
  175. package/esm/useCopier/index.d.ts +1 -1
  176. package/esm/useCopier/index.js +5 -5
  177. package/esm/useDemo/createCodeSandbox.d.ts +15 -0
  178. package/esm/useDemo/createCodeSandbox.js +42 -0
  179. package/esm/useDemo/createStackBlitz.d.ts +22 -0
  180. package/esm/useDemo/createStackBlitz.js +38 -0
  181. package/esm/useDemo/exportVariant.d.ts +184 -0
  182. package/esm/useDemo/exportVariant.js +422 -0
  183. package/esm/useDemo/exportVariantAsCra.d.ts +15 -0
  184. package/esm/useDemo/exportVariantAsCra.js +57 -0
  185. package/esm/useDemo/flattenVariant.d.ts +19 -0
  186. package/esm/useDemo/flattenVariant.js +49 -0
  187. package/esm/useDemo/index.d.ts +6 -51
  188. package/esm/useDemo/index.js +6 -104
  189. package/esm/useDemo/useDemo.d.ts +81 -0
  190. package/esm/useDemo/useDemo.js +193 -0
  191. package/esm/useErrors/ErrorsContext.d.ts +6 -0
  192. package/esm/useErrors/ErrorsContext.js +8 -0
  193. package/esm/useErrors/index.d.ts +1 -0
  194. package/esm/useErrors/index.js +1 -0
  195. package/esm/useErrors/useErrors.d.ts +5 -0
  196. package/esm/useErrors/useErrors.js +7 -0
  197. package/esm/useLocalStorageState/index.d.ts +2 -0
  198. package/esm/useLocalStorageState/index.js +2 -0
  199. package/esm/useLocalStorageState/useLocalStorageState.d.ts +14 -0
  200. package/esm/useLocalStorageState/useLocalStorageState.js +128 -0
  201. package/esm/usePreference/PreferencesProvider.d.ts +6 -0
  202. package/esm/usePreference/PreferencesProvider.js +8 -0
  203. package/esm/usePreference/index.d.ts +2 -0
  204. package/esm/usePreference/index.js +2 -0
  205. package/esm/usePreference/usePreference.d.ts +2 -0
  206. package/esm/usePreference/usePreference.js +25 -0
  207. package/esm/useUrlHashState/index.d.ts +1 -0
  208. package/esm/useUrlHashState/index.js +1 -0
  209. package/esm/useUrlHashState/useUrlHashState.d.ts +5 -0
  210. package/esm/useUrlHashState/useUrlHashState.js +68 -0
  211. package/esm/withDocsInfra/index.d.ts +1 -0
  212. package/esm/withDocsInfra/index.js +1 -0
  213. package/esm/withDocsInfra/withDocsInfra.d.ts +82 -0
  214. package/esm/withDocsInfra/withDocsInfra.js +147 -0
  215. package/package.json +178 -11
  216. package/esm/useCopier/index.d.ts.map +0 -1
  217. package/esm/useDemo/index.d.ts.map +0 -1
@@ -0,0 +1,134 @@
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
+ // webpack does not like node: imports
6
+ // eslint-disable-next-line n/prefer-node-protocol
7
+ import { readFile } from 'fs/promises';
8
+ import { parseImports } from "../loaderUtils/index.js";
9
+ import { resolveImportResultWithFs } from "../loaderUtils/resolveModulePathWithFs.js";
10
+ import { processRelativeImports } from "../loaderUtils/processRelativeImports.js";
11
+ import { isJavaScriptModule } from "../loaderUtils/resolveModulePath.js";
12
+ /**
13
+ * Default loadServerSource function that reads a file and extracts its dependencies.
14
+ * This function is used to load source files for demos, resolving their imports and dependencies.
15
+ * It reads the source file, resolves its imports, and returns the processed source along with any
16
+ * additional files and dependencies that were found.
17
+ */
18
+ export var loadServerSource = createLoadServerSource();
19
+
20
+ /**
21
+ * Creates a loadSource function that reads a file and extracts its dependencies.
22
+ *
23
+ * @param options.storeAt - Controls how imports are stored in extraFiles:
24
+ * - 'canonical': Full resolved path (e.g., '../Component/index.js')
25
+ * - 'import': Import path with file extension (e.g., '../Component.js')
26
+ * - 'flat': Flattened to current directory with rewritten imports (e.g., './Component.js')
27
+ */
28
+ export function createLoadServerSource() {
29
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
30
+ var _options$includeDepen = options.includeDependencies,
31
+ includeDependencies = _options$includeDepen === void 0 ? true : _options$includeDepen,
32
+ _options$storeAt = options.storeAt,
33
+ storeAt = _options$storeAt === void 0 ? 'flat' : _options$storeAt;
34
+ return /*#__PURE__*/function () {
35
+ var _loadSource = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(url) {
36
+ var filePath, source, isJavascriptModuleFile, _yield$parseImports, importResult, externals, transformedExternals, _i, _Object$entries, _Object$entries$_i, modulePath, externalImport, relativeImportsCompatible, _i2, _Object$entries2, _Object$entries2$_i, importPath, _Object$entries2$_i$, path, names, includeTypeDefs, resolvedPathsMap, _processRelativeImpor, processedSource, extraFiles, extraDependencies;
37
+ return _regenerator().w(function (_context) {
38
+ while (1) switch (_context.n) {
39
+ case 0:
40
+ // Remove file:// prefix if present
41
+ filePath = url.replace('file://', ''); // Read the file
42
+ _context.n = 1;
43
+ return readFile(filePath, 'utf8');
44
+ case 1:
45
+ source = _context.v;
46
+ if (includeDependencies) {
47
+ _context.n = 2;
48
+ break;
49
+ }
50
+ return _context.a(2, {
51
+ source: source
52
+ });
53
+ case 2:
54
+ // Check if this is a static asset file (non-JS/TS modules)
55
+ isJavascriptModuleFile = isJavaScriptModule(filePath);
56
+ if (isJavascriptModuleFile) {
57
+ _context.n = 3;
58
+ break;
59
+ }
60
+ return _context.a(2, {
61
+ source: source
62
+ });
63
+ case 3:
64
+ _context.n = 4;
65
+ return parseImports(source, filePath);
66
+ case 4:
67
+ _yield$parseImports = _context.v;
68
+ importResult = _yield$parseImports.relative;
69
+ externals = _yield$parseImports.externals;
70
+ // Transform externals from parseImports format to simplified format
71
+ transformedExternals = {};
72
+ for (_i = 0, _Object$entries = Object.entries(externals); _i < _Object$entries.length; _i++) {
73
+ _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), modulePath = _Object$entries$_i[0], externalImport = _Object$entries$_i[1];
74
+ transformedExternals[modulePath] = externalImport.names.map(function (importName) {
75
+ return {
76
+ name: importName.name,
77
+ type: importName.type,
78
+ isType: importName.isType
79
+ };
80
+ });
81
+ }
82
+ if (!(Object.keys(importResult).length === 0)) {
83
+ _context.n = 5;
84
+ break;
85
+ }
86
+ return _context.a(2, {
87
+ source: source,
88
+ externals: Object.keys(transformedExternals).length > 0 ? transformedExternals : undefined
89
+ });
90
+ case 5:
91
+ // Convert to format expected by resolveImportResultWithFs and processImports
92
+ relativeImportsCompatible = {};
93
+ for (_i2 = 0, _Object$entries2 = Object.entries(importResult); _i2 < _Object$entries2.length; _i2++) {
94
+ _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2), importPath = _Object$entries2$_i[0], _Object$entries2$_i$ = _Object$entries2$_i[1], path = _Object$entries2$_i$.path, names = _Object$entries2$_i$.names, includeTypeDefs = _Object$entries2$_i$.includeTypeDefs;
95
+ relativeImportsCompatible[importPath] = _extends({
96
+ path: path,
97
+ names: names.map(function (_ref) {
98
+ var name = _ref.name,
99
+ alias = _ref.alias;
100
+ return alias || name;
101
+ })
102
+ }, includeTypeDefs && {
103
+ includeTypeDefs: includeTypeDefs
104
+ });
105
+ }
106
+
107
+ // Resolve import paths, handling JS/TS modules and static assets appropriately
108
+ _context.n = 6;
109
+ return resolveImportResultWithFs(relativeImportsCompatible);
110
+ case 6:
111
+ resolvedPathsMap = _context.v;
112
+ // Process imports using the consolidated helper function
113
+ _processRelativeImpor = processRelativeImports(source, relativeImportsCompatible, resolvedPathsMap, storeAt), processedSource = _processRelativeImpor.processedSource, extraFiles = _processRelativeImpor.extraFiles; // Build dependencies list for recursive loading
114
+ extraDependencies = Object.values(importResult).map(function (_ref2) {
115
+ var path = _ref2.path;
116
+ return resolvedPathsMap.get(path);
117
+ }).filter(function (path) {
118
+ return path !== undefined;
119
+ });
120
+ return _context.a(2, {
121
+ source: processedSource,
122
+ extraFiles: Object.keys(extraFiles).length > 0 ? extraFiles : undefined,
123
+ extraDependencies: extraDependencies.length > 0 ? extraDependencies : undefined,
124
+ externals: Object.keys(transformedExternals).length > 0 ? transformedExternals : undefined
125
+ });
126
+ }
127
+ }, _callee);
128
+ }));
129
+ function loadSource(_x) {
130
+ return _loadSource.apply(this, arguments);
131
+ }
132
+ return loadSource;
133
+ }();
134
+ }
@@ -0,0 +1 @@
1
+ export declare function externalsToPackages(externals: string[]): Record<string, true>;
@@ -0,0 +1,46 @@
1
+ export function externalsToPackages(externals) {
2
+ var packages = {};
3
+ externals.forEach(function (external) {
4
+ // Filter out path aliases that start with @/
5
+ if (external.startsWith('@/')) {
6
+ return;
7
+ }
8
+
9
+ // Extract package name from import path
10
+ var packageName = extractPackageName(external);
11
+ if (packageName) {
12
+ packages[packageName] = true;
13
+ }
14
+ });
15
+ return packages;
16
+ }
17
+
18
+ /**
19
+ * Extracts the package name from an import path.
20
+ * Examples:
21
+ * - 'react' -> 'react'
22
+ * - 'react-dom' -> 'react-dom'
23
+ * - '@mui/internal-docs-infra/CodeHighlighter' -> '@mui/internal-docs-infra'
24
+ * - '@mui/internal-docs-infra/parseSource' -> '@mui/internal-docs-infra'
25
+ * - 'lodash/get' -> 'lodash'
26
+ * - 'some-package/submodule/deep' -> 'some-package'
27
+ */
28
+ function extractPackageName(importPath) {
29
+ if (!importPath) {
30
+ return null;
31
+ }
32
+
33
+ // Handle scoped packages (starting with @)
34
+ if (importPath.startsWith('@')) {
35
+ var _parts = importPath.split('/');
36
+ if (_parts.length >= 2) {
37
+ // Return @scope/package-name
38
+ return "".concat(_parts[0], "/").concat(_parts[1]);
39
+ }
40
+ return null;
41
+ }
42
+
43
+ // Handle regular packages
44
+ var parts = importPath.split('/');
45
+ return parts[0] || null;
46
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Extracts and formats a name and slug from a URL path.
3
+ * This utility takes the last meaningful segment of a URL path and formats it
4
+ * into both a human-readable title and a URL-friendly slug.
5
+ *
6
+ * - Strips common file extensions (index.js, index.ts, index.tsx, etc.)
7
+ * - Converts kebab-case to Title Case for names
8
+ * - Ensures slugs are in kebab-case format
9
+ */
10
+ /**
11
+ * Extracts and formats a name and slug from a URL path
12
+ * @param url - The URL to extract from (can be file:// URL or regular path)
13
+ * @returns Object containing the formatted name and slug
14
+ *
15
+ * @example
16
+ * extractNameAndSlugFromUrl('file:///app/components/demos/advanced-keyboard/index.ts')
17
+ * // Returns: { name: 'Advanced Keyboard', slug: 'advanced-keyboard' }
18
+ *
19
+ * @example
20
+ * extractNameAndSlugFromUrl('/src/components/button-group.tsx')
21
+ * // Returns: { name: 'Button Group', slug: 'button-group' }
22
+ *
23
+ * @example
24
+ * extractNameAndSlugFromUrl('/src/components/customButton.tsx')
25
+ * // Returns: { name: 'Custom Button', slug: 'custom-button' }
26
+ *
27
+ * @example
28
+ * extractNameAndSlugFromUrl('https://example.com/docs/getting-started/')
29
+ * // Returns: { name: 'Getting Started', slug: 'getting-started' }
30
+ */
31
+ export declare function extractNameAndSlugFromUrl(url: string): {
32
+ name: string;
33
+ slug: string;
34
+ };
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Extracts and formats a name and slug from a URL path.
3
+ * This utility takes the last meaningful segment of a URL path and formats it
4
+ * into both a human-readable title and a URL-friendly slug.
5
+ *
6
+ * - Strips common file extensions (index.js, index.ts, index.tsx, etc.)
7
+ * - Converts kebab-case to Title Case for names
8
+ * - Ensures slugs are in kebab-case format
9
+ */
10
+
11
+ /**
12
+ * Converts a camelCase string to kebab-case
13
+ * @param camelCase - The camelCase string to convert
14
+ * @returns kebab-case string
15
+ */
16
+ function camelToKebabCase(camelCase) {
17
+ return camelCase
18
+ // Insert hyphens before uppercase letters that follow lowercase letters or numbers
19
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
20
+ // Insert hyphens before numbers that follow letters
21
+ .replace(/([a-zA-Z])([0-9])/g, '$1-$2')
22
+ // Insert hyphens before letters that follow numbers
23
+ .replace(/([0-9])([a-zA-Z])/g, '$1-$2').toLowerCase();
24
+ }
25
+
26
+ /**
27
+ * Converts a camelCase string to Title Case with spaces
28
+ * @param camelCase - The camelCase string to convert
29
+ * @returns Title case string with spaces
30
+ */
31
+ function camelToTitleCase(camelCase) {
32
+ return camelCase
33
+ // Insert spaces before uppercase letters that follow lowercase letters or numbers
34
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
35
+ // Insert spaces before numbers that follow letters
36
+ .replace(/([a-zA-Z])([0-9])/g, '$1 $2')
37
+ // Insert spaces before letters that follow numbers
38
+ .replace(/([0-9])([a-zA-Z])/g, '$1 $2')
39
+ // Capitalize the first letter
40
+ .replace(/^./, function (str) {
41
+ return str.toUpperCase();
42
+ });
43
+ }
44
+
45
+ /**
46
+ * Converts a kebab-case string to Title Case
47
+ * @param kebabCase - The kebab-case string to convert
48
+ * @returns Title case string
49
+ */
50
+ function kebabToTitleCase(kebabCase) {
51
+ return kebabCase.split(/[-_]/) // Split on both hyphens and underscores
52
+ .map(function (word) {
53
+ return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
54
+ }).join(' ');
55
+ }
56
+
57
+ /**
58
+ * Detects if a string is camelCase or PascalCase
59
+ * @param str - The string to check
60
+ * @returns true if the string is camelCase or PascalCase
61
+ */
62
+ function isCamelCase(str) {
63
+ // Check if it matches the camelCase/PascalCase pattern:
64
+ // - Only contains letters and numbers
65
+ // - Has at least one transition from lowercase letter or number to uppercase letter
66
+ // - Doesn't contain hyphens, underscores, or spaces
67
+ return /^[a-zA-Z][a-zA-Z0-9]*$/.test(str) && /[a-z0-9][A-Z]/.test(str);
68
+ }
69
+
70
+ /**
71
+ * Converts a string to kebab-case
72
+ * @param str - The string to convert
73
+ * @returns kebab-case string
74
+ */
75
+ function toKebabCase(str) {
76
+ return str.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
77
+ }
78
+
79
+ /**
80
+ * Extracts the last meaningful segment from a URL path
81
+ * @param url - The URL to extract from
82
+ * @returns The last meaningful path segment
83
+ */
84
+ function extractLastSegment(url) {
85
+ // Handle file: URLs by removing the protocol
86
+ var path = url;
87
+ if (url.startsWith('file:')) {
88
+ path = url.replace(/^file:\/\//, '');
89
+ }
90
+
91
+ // Strip query parameters and hash fragments before processing
92
+ path = path.split('?')[0].split('#')[0];
93
+
94
+ // Split the path into segments and filter out empty ones
95
+ var segments = path.split('/').filter(Boolean);
96
+ if (segments.length === 0) {
97
+ throw new Error('Could not extract meaningful segment from URL');
98
+ }
99
+
100
+ // Get the last segment
101
+ var lastSegment = segments[segments.length - 1];
102
+
103
+ // Handle index files - any file that starts with 'index.'
104
+ if (lastSegment.startsWith('index.')) {
105
+ // If it's an index file, use the parent directory name
106
+ if (segments.length < 2) {
107
+ throw new Error('Cannot extract name from index file without parent directory');
108
+ }
109
+ lastSegment = segments[segments.length - 2];
110
+ } else {
111
+ // Strip everything after the first dot from non-index files
112
+ // This handles all extensions: .js, .d.ts, .module.css, .config.dev.js, etc.
113
+ var firstDotIndex = lastSegment.indexOf('.');
114
+ if (firstDotIndex !== -1) {
115
+ lastSegment = lastSegment.substring(0, firstDotIndex);
116
+ }
117
+ }
118
+ if (!lastSegment) {
119
+ throw new Error('Could not extract meaningful segment from URL');
120
+ }
121
+ return lastSegment;
122
+ }
123
+
124
+ /**
125
+ * Extracts and formats a name and slug from a URL path
126
+ * @param url - The URL to extract from (can be file:// URL or regular path)
127
+ * @returns Object containing the formatted name and slug
128
+ *
129
+ * @example
130
+ * extractNameAndSlugFromUrl('file:///app/components/demos/advanced-keyboard/index.ts')
131
+ * // Returns: { name: 'Advanced Keyboard', slug: 'advanced-keyboard' }
132
+ *
133
+ * @example
134
+ * extractNameAndSlugFromUrl('/src/components/button-group.tsx')
135
+ * // Returns: { name: 'Button Group', slug: 'button-group' }
136
+ *
137
+ * @example
138
+ * extractNameAndSlugFromUrl('/src/components/customButton.tsx')
139
+ * // Returns: { name: 'Custom Button', slug: 'custom-button' }
140
+ *
141
+ * @example
142
+ * extractNameAndSlugFromUrl('https://example.com/docs/getting-started/')
143
+ * // Returns: { name: 'Getting Started', slug: 'getting-started' }
144
+ */
145
+ export function extractNameAndSlugFromUrl(url) {
146
+ var segment = extractLastSegment(url);
147
+
148
+ // Check if the segment is camelCase and handle it appropriately
149
+ if (isCamelCase(segment)) {
150
+ return {
151
+ name: camelToTitleCase(segment),
152
+ slug: camelToKebabCase(segment)
153
+ };
154
+ }
155
+
156
+ // For kebab-case, snake_case, or other formats, use the existing logic
157
+ return {
158
+ name: kebabToTitleCase(segment),
159
+ slug: toKebabCase(segment)
160
+ };
161
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Extracts the filename and extension from a URL or file path.
3
+ * This function is isomorphic and works in both Node.js and browser environments.
4
+ * It properly handles compound extensions like .module.css, .d.ts, .test.js, etc.
5
+ *
6
+ * @param url - The URL or file path to extract the filename from
7
+ * @returns An object containing the filename and extension
8
+ */
9
+ export declare function getFileNameFromUrl(url: string): {
10
+ fileName: string;
11
+ extension: string;
12
+ };
@@ -0,0 +1,66 @@
1
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
+ /**
3
+ * Known compound extensions that should be treated as a single unit
4
+ */
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'];
6
+
7
+ /**
8
+ * Extracts the filename and extension from a URL or file path.
9
+ * This function is isomorphic and works in both Node.js and browser environments.
10
+ * It properly handles compound extensions like .module.css, .d.ts, .test.js, etc.
11
+ *
12
+ * @param url - The URL or file path to extract the filename from
13
+ * @returns An object containing the filename and extension
14
+ */
15
+ export function getFileNameFromUrl(url) {
16
+ try {
17
+ // 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() || '';
21
+ return extractFileNameAndExtension(fileName);
22
+ } catch (_unused) {
23
+ // If URL parsing fails, fall back to simple string manipulation
24
+ var _fileName = url.split('/').pop() || url;
25
+ return extractFileNameAndExtension(_fileName);
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Helper function to extract filename and extension, handling compound extensions
31
+ */
32
+ function extractFileNameAndExtension(fileName) {
33
+ if (!fileName) {
34
+ return {
35
+ fileName: '',
36
+ extension: ''
37
+ };
38
+ }
39
+
40
+ // 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
+ }
52
+ }
53
+
54
+ // Fall back to simple extension detection
55
+ } catch (err) {
56
+ _iterator.e(err);
57
+ } finally {
58
+ _iterator.f();
59
+ }
60
+ var lastDotIndex = fileName.lastIndexOf('.');
61
+ var extension = lastDotIndex > 0 ? fileName.substring(lastDotIndex) : '';
62
+ return {
63
+ fileName: fileName,
64
+ extension: extension
65
+ };
66
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./parseImports.js";
2
+ export * from "./resolveModulePath.js";
3
+ export * from "./rewriteImports.js";
4
+ export * from "./processRelativeImports.js";
5
+ export * from "./getFileNameFromUrl.js";
6
+ export * from "./extractNameAndSlugFromUrl.js";
7
+ export * from "./externalsToPackages.js";
@@ -0,0 +1,7 @@
1
+ export * from "./parseImports.js";
2
+ export * from "./resolveModulePath.js";
3
+ export * from "./rewriteImports.js";
4
+ export * from "./processRelativeImports.js";
5
+ export * from "./getFileNameFromUrl.js";
6
+ export * from "./extractNameAndSlugFromUrl.js";
7
+ export * from "./externalsToPackages.js";
@@ -0,0 +1,32 @@
1
+ import type { Externals } from "../../CodeHighlighter/types.js";
2
+ /**
3
+ * Merges multiple externals objects into a single object, combining imports from the same module.
4
+ * Deduplicates imports by name and type within each module.
5
+ *
6
+ * @param externalsArray Array of externals objects to merge
7
+ * @returns Merged externals object
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const externals1 = {
12
+ * 'react': [{ name: 'React', type: 'default' }],
13
+ * 'lodash': [{ name: 'map', type: 'named' }]
14
+ * };
15
+ *
16
+ * const externals2 = {
17
+ * 'react': [{ name: 'useState', type: 'named' }],
18
+ * 'lodash': [{ name: 'map', type: 'named' }] // duplicate - will be removed
19
+ * };
20
+ *
21
+ * const merged = mergeExternals([externals1, externals2]);
22
+ * // Result:
23
+ * // {
24
+ * // 'react': [
25
+ * // { name: 'React', type: 'default' },
26
+ * // { name: 'useState', type: 'named' }
27
+ * // ],
28
+ * // 'lodash': [{ name: 'map', type: 'named' }]
29
+ * // }
30
+ * ```
31
+ */
32
+ export declare function mergeExternals(externalsArray: Array<Externals>): Externals;
@@ -0,0 +1,72 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
4
+ /**
5
+ * Merges multiple externals objects into a single object, combining imports from the same module.
6
+ * Deduplicates imports by name and type within each module.
7
+ *
8
+ * @param externalsArray Array of externals objects to merge
9
+ * @returns Merged externals object
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const externals1 = {
14
+ * 'react': [{ name: 'React', type: 'default' }],
15
+ * 'lodash': [{ name: 'map', type: 'named' }]
16
+ * };
17
+ *
18
+ * const externals2 = {
19
+ * 'react': [{ name: 'useState', type: 'named' }],
20
+ * 'lodash': [{ name: 'map', type: 'named' }] // duplicate - will be removed
21
+ * };
22
+ *
23
+ * const merged = mergeExternals([externals1, externals2]);
24
+ * // Result:
25
+ * // {
26
+ * // 'react': [
27
+ * // { name: 'React', type: 'default' },
28
+ * // { name: 'useState', type: 'named' }
29
+ * // ],
30
+ * // 'lodash': [{ name: 'map', type: 'named' }]
31
+ * // }
32
+ * ```
33
+ */
34
+ export function mergeExternals(externalsArray) {
35
+ var merged = {};
36
+ var _iterator = _createForOfIteratorHelper(externalsArray),
37
+ _step;
38
+ try {
39
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
40
+ var externals = _step.value;
41
+ var _loop = function _loop() {
42
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
43
+ modulePath = _Object$entries$_i[0],
44
+ imports = _Object$entries$_i[1];
45
+ if (!merged[modulePath]) {
46
+ // First time seeing this module, copy all imports
47
+ merged[modulePath] = _toConsumableArray(imports);
48
+ } else {
49
+ // Module already exists, merge imports and deduplicate
50
+ var existingImports = merged[modulePath];
51
+ var newImports = imports.filter(function (newImport) {
52
+ // Check if this import already exists (same name, type, and isType)
53
+ return !existingImports.some(function (existingImport) {
54
+ return existingImport.name === newImport.name && existingImport.type === newImport.type && existingImport.isType === newImport.isType;
55
+ });
56
+ });
57
+
58
+ // Add only the new imports that don't already exist
59
+ merged[modulePath] = [].concat(_toConsumableArray(existingImports), _toConsumableArray(newImports));
60
+ }
61
+ };
62
+ for (var _i = 0, _Object$entries = Object.entries(externals); _i < _Object$entries.length; _i++) {
63
+ _loop();
64
+ }
65
+ }
66
+ } catch (err) {
67
+ _iterator.e(err);
68
+ } finally {
69
+ _iterator.f();
70
+ }
71
+ return merged;
72
+ }
@@ -0,0 +1,19 @@
1
+ export interface ImportName {
2
+ name: string;
3
+ alias?: string;
4
+ type: 'default' | 'named' | 'namespace';
5
+ isType?: boolean;
6
+ }
7
+ export interface RelativeImport {
8
+ path: string;
9
+ names: ImportName[];
10
+ includeTypeDefs?: true;
11
+ }
12
+ export interface ExternalImport {
13
+ names: ImportName[];
14
+ }
15
+ export interface ParseImportsResult {
16
+ relative: Record<string, RelativeImport>;
17
+ externals: Record<string, ExternalImport>;
18
+ }
19
+ export declare function parseImports(code: string, _filePath: string): Promise<ParseImportsResult>;