@mui/internal-docs-infra 0.1.1-canary.8 → 0.2.0-alpha.1

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,306 @@
1
+ import _regeneratorValues from "@babel/runtime/helpers/esm/regeneratorValues";
2
+ import _regenerator from "@babel/runtime/helpers/esm/regenerator";
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
6
+ // webpack does not like node: imports
7
+ // eslint-disable-next-line n/prefer-node-protocol
8
+ import path from 'path';
9
+ export function parseImports(_x, _x2) {
10
+ return _parseImports.apply(this, arguments);
11
+ }
12
+ function _parseImports() {
13
+ _parseImports = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(code, _filePath) {
14
+ var result, externals, importRegex, sideEffectImportRegex, match, _loop, _ret, sideEffectMatch, _sideEffectMatch, _sideEffectMatch2, modulePathRaw, modulePath, isRelative, resolvedPath;
15
+ return _regenerator().w(function (_context2) {
16
+ while (1) switch (_context2.n) {
17
+ case 0:
18
+ result = {};
19
+ externals = {}; // Regex to extract regular import statements with 'from' clause
20
+ importRegex = /import(?:\s+type)?\s*([^'"]*)\s*from\s*['"]([^'"]+)['"][;]?/g; // Regex to extract side-effect imports (without 'from' clause)
21
+ sideEffectImportRegex = /import\s*['"]([^'"]+)['"][;]?/g;
22
+ // eslint-disable-next-line no-cond-assign
23
+ _loop = /*#__PURE__*/_regenerator().m(function _loop() {
24
+ var _match, _match2, fullMatch, importSpecifierRaw, modulePathRaw, includeTypeDefs, importSpecifier, modulePath, isRelative, _resolvedPath, _resolvedPath2, defaultImportMatch, namespaceImportMatch, namedImportsMatch, defaultImport, namespaceImport, namedImportsStr, existing, _existing, cleanedImportsStr, namedImports, _defaultImportMatch, _namespaceImportMatch, _namedImportsMatch, _defaultImport, _namespaceImport, _namedImportsStr, _existing3, _existing4, _cleanedImportsStr, _namedImports;
25
+ return _regenerator().w(function (_context) {
26
+ while (1) switch (_context.n) {
27
+ case 0:
28
+ _match = match, _match2 = _slicedToArray(_match, 3), fullMatch = _match2[0], importSpecifierRaw = _match2[1], modulePathRaw = _match2[2]; // Determine if this is a type import by checking if the full match contains "import type"
29
+ includeTypeDefs = fullMatch.includes('import type');
30
+ importSpecifier = importSpecifierRaw == null ? void 0 : importSpecifierRaw.trim();
31
+ modulePath = modulePathRaw == null ? void 0 : modulePathRaw.trim();
32
+ if (modulePath) {
33
+ _context.n = 1;
34
+ break;
35
+ }
36
+ return _context.a(2, 0);
37
+ case 1:
38
+ // Check if this is a relative import
39
+ isRelative = modulePath.startsWith('./') || modulePath.startsWith('../'); // Handle side-effect imports (no import specifier)
40
+ if (importSpecifier) {
41
+ _context.n = 2;
42
+ break;
43
+ }
44
+ if (isRelative) {
45
+ // Resolve the relative import to an absolute path
46
+ _resolvedPath = path.resolve(path.dirname(_filePath), modulePath);
47
+ if (!result[modulePath]) {
48
+ result[modulePath] = {
49
+ path: _resolvedPath,
50
+ names: [] // Empty names array for side-effect imports
51
+ };
52
+ }
53
+ } else if (!externals[modulePath]) {
54
+ // External side-effect import
55
+ externals[modulePath] = {
56
+ names: []
57
+ };
58
+ }
59
+ return _context.a(2, 0);
60
+ case 2:
61
+ if (isRelative) {
62
+ // Resolve the relative import to an absolute path
63
+ _resolvedPath2 = path.resolve(path.dirname(_filePath), modulePath);
64
+ if (!result[modulePath]) {
65
+ result[modulePath] = _extends({
66
+ path: _resolvedPath2,
67
+ names: []
68
+ }, includeTypeDefs && {
69
+ includeTypeDefs: true
70
+ });
71
+ } else if (includeTypeDefs && !result[modulePath].includeTypeDefs) {
72
+ result[modulePath].includeTypeDefs = true;
73
+ }
74
+
75
+ // Parse the import specifier to determine the type of import
76
+ defaultImportMatch = importSpecifier.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)\s*(?:,|$)/);
77
+ namespaceImportMatch = importSpecifier.match(/\*\s+as\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/);
78
+ namedImportsMatch = importSpecifier.match(/\{([^}]+)\}/);
79
+ defaultImport = defaultImportMatch == null ? void 0 : defaultImportMatch[1];
80
+ namespaceImport = namespaceImportMatch == null ? void 0 : namespaceImportMatch[1];
81
+ namedImportsStr = namedImportsMatch == null ? void 0 : namedImportsMatch[1];
82
+ if (defaultImport) {
83
+ // Check if we already have this default import
84
+ existing = result[modulePath].names.find(function (n) {
85
+ return n.name === defaultImport && n.type === 'default';
86
+ });
87
+ if (!existing) {
88
+ result[modulePath].names.push(_extends({
89
+ name: defaultImport,
90
+ type: 'default'
91
+ }, includeTypeDefs && {
92
+ isType: true
93
+ }));
94
+ }
95
+ }
96
+ if (namespaceImport) {
97
+ // Check if we already have this namespace import
98
+ _existing = result[modulePath].names.find(function (n) {
99
+ return n.name === namespaceImport && n.type === 'namespace';
100
+ });
101
+ if (!_existing) {
102
+ result[modulePath].names.push(_extends({
103
+ name: namespaceImport,
104
+ type: 'namespace'
105
+ }, includeTypeDefs && {
106
+ isType: true
107
+ }));
108
+ }
109
+ }
110
+ if (namedImportsStr) {
111
+ // Handle named imports like { ComponentName, Component2 as Alias, type TypeName }
112
+ // Clean up the string by removing comments and extra whitespace
113
+ cleanedImportsStr = namedImportsStr.replace(/\/\*[\s\S]*?\*\//g, '') // Remove /* comment */ blocks
114
+ .replace(/\/\/.*$/gm, '') // Remove // line comments
115
+ .trim();
116
+ if (cleanedImportsStr) {
117
+ namedImports = cleanedImportsStr.split(',').map(function (s) {
118
+ return s.trim();
119
+ }).filter(function (s) {
120
+ return s.length > 0;
121
+ });
122
+ namedImports.forEach(function (namedImport) {
123
+ // Check if this specific import is a type import
124
+ var isTypeImport = namedImport.trim().startsWith('type ');
125
+
126
+ // Clean up the import name (remove 'type' keyword and handle aliases)
127
+ var cleanImport = namedImport.replace(/^type\s+/, ''); // Remove leading 'type'
128
+
129
+ // Parse original name and alias
130
+ var aliasMatch = cleanImport.match(/(.+?)\s+as\s+(.+)/);
131
+ var originalName = aliasMatch ? aliasMatch[1].trim() : cleanImport.trim();
132
+ var alias = aliasMatch ? aliasMatch[2].trim() : undefined;
133
+
134
+ // Only add if we have a valid name
135
+ if (originalName && /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(originalName)) {
136
+ // Check if we already have this named import
137
+ var _existing2 = result[modulePath].names.find(function (n) {
138
+ return n.name === originalName && n.type === 'named' && n.alias === alias;
139
+ });
140
+ if (!_existing2) {
141
+ result[modulePath].names.push(_extends(_extends({
142
+ name: originalName
143
+ }, alias && {
144
+ alias: alias
145
+ }), {}, {
146
+ type: 'named'
147
+ }, (includeTypeDefs || isTypeImport) && {
148
+ isType: true
149
+ }));
150
+ }
151
+ }
152
+ });
153
+ }
154
+ }
155
+ } else {
156
+ // This is an external import
157
+ if (!externals[modulePath]) {
158
+ externals[modulePath] = {
159
+ names: []
160
+ };
161
+ }
162
+
163
+ // Parse the import specifier to determine the type of import
164
+ _defaultImportMatch = importSpecifier.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)\s*(?:,|$)/);
165
+ _namespaceImportMatch = importSpecifier.match(/\*\s+as\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/);
166
+ _namedImportsMatch = importSpecifier.match(/\{([^}]+)\}/);
167
+ _defaultImport = _defaultImportMatch == null ? void 0 : _defaultImportMatch[1];
168
+ _namespaceImport = _namespaceImportMatch == null ? void 0 : _namespaceImportMatch[1];
169
+ _namedImportsStr = _namedImportsMatch == null ? void 0 : _namedImportsMatch[1];
170
+ if (_defaultImport) {
171
+ // Check if we already have this default import
172
+ _existing3 = externals[modulePath].names.find(function (n) {
173
+ return n.name === _defaultImport && n.type === 'default';
174
+ });
175
+ if (!_existing3) {
176
+ externals[modulePath].names.push(_extends({
177
+ name: _defaultImport,
178
+ type: 'default'
179
+ }, includeTypeDefs && {
180
+ isType: true
181
+ }));
182
+ }
183
+ }
184
+ if (_namespaceImport) {
185
+ // Check if we already have this namespace import
186
+ _existing4 = externals[modulePath].names.find(function (n) {
187
+ return n.name === _namespaceImport && n.type === 'namespace';
188
+ });
189
+ if (!_existing4) {
190
+ externals[modulePath].names.push(_extends({
191
+ name: _namespaceImport,
192
+ type: 'namespace'
193
+ }, includeTypeDefs && {
194
+ isType: true
195
+ }));
196
+ }
197
+ }
198
+ if (_namedImportsStr) {
199
+ // Handle named imports like { ComponentName, Component2 as Alias, type TypeName }
200
+ // Clean up the string by removing comments and extra whitespace
201
+ _cleanedImportsStr = _namedImportsStr.replace(/\/\*[\s\S]*?\*\//g, '') // Remove /* comment */ blocks
202
+ .replace(/\/\/.*$/gm, '') // Remove // line comments
203
+ .trim();
204
+ if (_cleanedImportsStr) {
205
+ _namedImports = _cleanedImportsStr.split(',').map(function (s) {
206
+ return s.trim();
207
+ }).filter(function (s) {
208
+ return s.length > 0;
209
+ });
210
+ _namedImports.forEach(function (namedImport) {
211
+ // Check if this specific import is a type import
212
+ var isTypeImport = namedImport.trim().startsWith('type ');
213
+
214
+ // Clean up the import name (remove 'type' keyword and handle aliases)
215
+ var cleanImport = namedImport.replace(/^type\s+/, ''); // Remove leading 'type'
216
+
217
+ // Parse original name and alias - for externals we track both
218
+ var aliasMatch = cleanImport.match(/(.+?)\s+as\s+(.+)/);
219
+ var originalName = aliasMatch ? aliasMatch[1].trim() : cleanImport.trim();
220
+ var alias = aliasMatch ? aliasMatch[2].trim() : undefined;
221
+
222
+ // Only add if we have a valid name
223
+ if (originalName && /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(originalName)) {
224
+ // Check if we already have this named import
225
+ var _existing5 = externals[modulePath].names.find(function (n) {
226
+ return n.name === originalName && n.type === 'named' && n.alias === alias;
227
+ });
228
+ if (!_existing5) {
229
+ externals[modulePath].names.push(_extends(_extends({
230
+ name: originalName
231
+ }, alias && {
232
+ alias: alias
233
+ }), {}, {
234
+ type: 'named'
235
+ }, (includeTypeDefs || isTypeImport) && {
236
+ isType: true
237
+ }));
238
+ }
239
+ }
240
+ });
241
+ }
242
+ }
243
+ }
244
+ case 3:
245
+ return _context.a(2);
246
+ }
247
+ }, _loop);
248
+ });
249
+ case 1:
250
+ if (!((match = importRegex.exec(code)) !== null)) {
251
+ _context2.n = 4;
252
+ break;
253
+ }
254
+ return _context2.d(_regeneratorValues(_loop()), 2);
255
+ case 2:
256
+ _ret = _context2.v;
257
+ if (!(_ret === 0)) {
258
+ _context2.n = 3;
259
+ break;
260
+ }
261
+ return _context2.a(3, 1);
262
+ case 3:
263
+ _context2.n = 1;
264
+ break;
265
+ case 4:
266
+ if (!((sideEffectMatch = sideEffectImportRegex.exec(code)) !== null)) {
267
+ _context2.n = 6;
268
+ break;
269
+ }
270
+ _sideEffectMatch = sideEffectMatch, _sideEffectMatch2 = _slicedToArray(_sideEffectMatch, 2), modulePathRaw = _sideEffectMatch2[1];
271
+ modulePath = modulePathRaw == null ? void 0 : modulePathRaw.trim();
272
+ if (modulePath) {
273
+ _context2.n = 5;
274
+ break;
275
+ }
276
+ return _context2.a(3, 4);
277
+ case 5:
278
+ // Check if this is a relative import
279
+ isRelative = modulePath.startsWith('./') || modulePath.startsWith('../');
280
+ if (isRelative) {
281
+ // Resolve the relative import to an absolute path
282
+ resolvedPath = path.resolve(path.dirname(_filePath), modulePath);
283
+ if (!result[modulePath]) {
284
+ result[modulePath] = {
285
+ path: resolvedPath,
286
+ names: [] // Empty names array for side-effect imports
287
+ };
288
+ }
289
+ } else if (!externals[modulePath]) {
290
+ // External side-effect import
291
+ externals[modulePath] = {
292
+ names: []
293
+ };
294
+ }
295
+ _context2.n = 4;
296
+ break;
297
+ case 6:
298
+ return _context2.a(2, {
299
+ relative: result,
300
+ externals: externals
301
+ });
302
+ }
303
+ }, _callee);
304
+ }));
305
+ return _parseImports.apply(this, arguments);
306
+ }
@@ -0,0 +1,19 @@
1
+ export type StoreAtMode = 'canonical' | 'import' | 'flat';
2
+ export interface ProcessImportsResult {
3
+ processedSource: string;
4
+ extraFiles: Record<string, string>;
5
+ }
6
+ /**
7
+ * Processes imports based on the specified storage mode, automatically handling
8
+ * source rewriting when needed (e.g., for 'flat' mode).
9
+ *
10
+ * @param source - The original source code
11
+ * @param importResult - The result from parseImports
12
+ * @param resolvedPathsMap - Map from import paths to resolved file paths
13
+ * @param storeAt - How to process the imports
14
+ * @returns Object with processed source and extraFiles mapping
15
+ */
16
+ export declare function processRelativeImports(source: string, importResult: Record<string, {
17
+ path: string;
18
+ names: string[];
19
+ }>, resolvedPathsMap: Map<string, string>, storeAt: StoreAtMode): ProcessImportsResult;
@@ -0,0 +1,352 @@
1
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import { rewriteImportsToSameDirectory } from "./rewriteImports.js";
5
+ import { isJavaScriptModule } from "./resolveModulePath.js";
6
+ import { getFileNameFromUrl } from "./getFileNameFromUrl.js";
7
+ /**
8
+ * Processes imports based on the specified storage mode, automatically handling
9
+ * source rewriting when needed (e.g., for 'flat' mode).
10
+ *
11
+ * @param source - The original source code
12
+ * @param importResult - The result from parseImports
13
+ * @param resolvedPathsMap - Map from import paths to resolved file paths
14
+ * @param storeAt - How to process the imports
15
+ * @returns Object with processed source and extraFiles mapping
16
+ */
17
+ export function processRelativeImports(source, importResult, resolvedPathsMap, storeAt) {
18
+ var extraFiles = {};
19
+
20
+ // For flat mode, we need to handle naming conflicts intelligently
21
+ if (storeAt === 'flat') {
22
+ var result = processFlatMode(importResult, resolvedPathsMap);
23
+
24
+ // Create import path mapping for rewriting
25
+ var importPathMapping = new Map();
26
+
27
+ // Build a reverse mapping from resolved paths to extraFiles keys
28
+ var resolvedToExtraFile = new Map();
29
+ Object.entries(result.extraFiles).forEach(function (_ref) {
30
+ var _ref2 = _slicedToArray(_ref, 2),
31
+ extraFileKey = _ref2[0],
32
+ fileUrl = _ref2[1];
33
+ var resolvedPath = fileUrl.replace('file://', '');
34
+ resolvedToExtraFile.set(resolvedPath, extraFileKey);
35
+ });
36
+
37
+ // For each import, find its resolved path and map to the corresponding extraFile key
38
+ Object.entries(importResult).forEach(function (_ref3) {
39
+ var _ref4 = _slicedToArray(_ref3, 2),
40
+ relativePath = _ref4[0],
41
+ importInfo = _ref4[1];
42
+ var resolvedPath = resolvedPathsMap.get(importInfo.path);
43
+ if (resolvedPath) {
44
+ var extraFileKey = resolvedToExtraFile.get(resolvedPath);
45
+ if (extraFileKey) {
46
+ // For JavaScript modules, remove the extension; for other files (CSS, JSON, etc.), keep it
47
+ var isJavascriptModule = isJavaScriptModule(relativePath);
48
+ var newPath = extraFileKey;
49
+ if (isJavascriptModule) {
50
+ // Handle TypeScript declaration files (.d.ts) properly
51
+ if (newPath.endsWith('.d.ts')) {
52
+ newPath = newPath.replace(/\.d\.ts$/, '');
53
+ } else {
54
+ newPath = newPath.replace(/\.[^/.]+$/, '');
55
+ }
56
+ }
57
+ // For non-JS modules (CSS, JSON, etc.), keep the full path with extension
58
+
59
+ importPathMapping.set(relativePath, newPath);
60
+ }
61
+ }
62
+ });
63
+
64
+ // Rewrite the source with the mapping
65
+ var rewrittenSource = rewriteImportsToSameDirectory(source, importPathMapping);
66
+ return {
67
+ processedSource: rewrittenSource,
68
+ extraFiles: result.extraFiles
69
+ };
70
+ }
71
+
72
+ // Process each import and generate extraFiles for non-flat modes
73
+ Object.entries(importResult).forEach(function (_ref5) {
74
+ var _ref6 = _slicedToArray(_ref5, 2),
75
+ relativePath = _ref6[0],
76
+ importInfo = _ref6[1];
77
+ var resolvedPath = resolvedPathsMap.get(importInfo.path);
78
+ if (resolvedPath) {
79
+ var fileExtension = getFileNameFromUrl(resolvedPath).extension;
80
+ var isJavascriptModule = isJavaScriptModule(relativePath);
81
+ var keyPath;
82
+ if (!isJavascriptModule) {
83
+ // For static assets (CSS, JSON, etc.), use the original import path as-is since it already has the extension
84
+ switch (storeAt) {
85
+ case 'canonical':
86
+ case 'import':
87
+ keyPath = relativePath;
88
+ break;
89
+ default:
90
+ keyPath = relativePath;
91
+ }
92
+ } else {
93
+ // For JS/TS modules, apply the existing logic
94
+ switch (storeAt) {
95
+ case 'canonical':
96
+ // Show the full resolved path including index files when they exist
97
+ // e.g., import '../Component' resolved to '/src/Component/index.js'
98
+ // becomes extraFiles: { '../Component/index.js': 'file:///src/Component/index.js' }
99
+ keyPath = "".concat(relativePath).concat(resolvedPath.endsWith("/index".concat(fileExtension)) ? "/index".concat(fileExtension) : fileExtension);
100
+ break;
101
+ case 'import':
102
+ // Use the original import path with the actual file extension
103
+ // e.g., import '../Component' with '/src/Component/index.js'
104
+ // becomes extraFiles: { '../Component.js': 'file:///src/Component/index.js' }
105
+ keyPath = "".concat(relativePath).concat(fileExtension);
106
+ break;
107
+ default:
108
+ keyPath = "".concat(relativePath).concat(fileExtension);
109
+ }
110
+ }
111
+ extraFiles[keyPath] = "file://".concat(resolvedPath);
112
+ }
113
+ });
114
+ return {
115
+ processedSource: source,
116
+ extraFiles: extraFiles
117
+ };
118
+ }
119
+
120
+ /**
121
+ * Processes flat mode with intelligent conflict resolution
122
+ */
123
+ function processFlatMode(importResult, resolvedPathsMap) {
124
+ var extraFiles = {};
125
+ var fileMapping = [];
126
+
127
+ // First pass: collect all files and their path segments
128
+ Object.entries(importResult).forEach(function (_ref7) {
129
+ var _ref8 = _slicedToArray(_ref7, 2),
130
+ relativePath = _ref8[0],
131
+ importInfo = _ref8[1];
132
+ var resolvedPath = resolvedPathsMap.get(importInfo.path);
133
+ if (resolvedPath) {
134
+ var fileExtension = getFileNameFromUrl(resolvedPath).extension;
135
+ var pathSegments = resolvedPath.split('/').filter(Boolean);
136
+ fileMapping.push({
137
+ resolvedPath: resolvedPath,
138
+ extension: fileExtension,
139
+ segments: pathSegments,
140
+ originalImportPath: relativePath
141
+ });
142
+ }
143
+ });
144
+
145
+ // Second pass: determine candidate names and group by conflicts
146
+ var candidateNames = new Map();
147
+ var nameGroups = new Map();
148
+ for (var _i = 0, _fileMapping = fileMapping; _i < _fileMapping.length; _i++) {
149
+ var file = _fileMapping[_i];
150
+ var fileName = file.segments[file.segments.length - 1];
151
+ var isIndexFile = fileName.startsWith('index.');
152
+ var candidateName = void 0;
153
+ if (isIndexFile) {
154
+ // Check if the original import was a direct index file (e.g., "./index.ext")
155
+ var originalImportParts = file.originalImportPath.split('/');
156
+ var isDirectIndexImport = originalImportParts.length === 2 && originalImportParts[0] === '.' && originalImportParts[1].startsWith('index.');
157
+ if (isDirectIndexImport) {
158
+ // For direct index imports like "./index.ext", keep the original name
159
+ candidateName = "index".concat(file.extension);
160
+ } else {
161
+ // For nested index files like "./test/index.ext", use parent directory + extension
162
+ var parentDir = file.segments[file.segments.length - 2];
163
+ candidateName = "".concat(parentDir).concat(file.extension);
164
+ }
165
+ } else {
166
+ candidateName = fileName;
167
+ }
168
+ candidateNames.set(file.resolvedPath, candidateName);
169
+ if (!nameGroups.has(candidateName)) {
170
+ nameGroups.set(candidateName, []);
171
+ }
172
+ nameGroups.get(candidateName).push(file.resolvedPath);
173
+ }
174
+
175
+ // Third pass: resolve conflicts for all files in conflicting groups
176
+ var finalNames = new Map();
177
+ nameGroups.forEach(function (paths, candidateName) {
178
+ if (paths.length === 1) {
179
+ // No conflict, use the candidate name
180
+ finalNames.set(paths[0], candidateName);
181
+ } else {
182
+ // Conflict detected, find optimal minimal distinguishing paths for all files
183
+ var conflictingFiles = paths.map(function (resolvedPath) {
184
+ return fileMapping.find(function (f) {
185
+ return f.resolvedPath === resolvedPath;
186
+ });
187
+ });
188
+
189
+ // Check if we can resolve conflicts by treating some files differently
190
+ // This specifically handles cases like:
191
+ // - /path/to/a/Component.js and /path/to/Component.js (parent-child relationship)
192
+
193
+ // Find files that are "shorter" (parent level) compared to others
194
+ var minLength = Math.min.apply(Math, _toConsumableArray(conflictingFiles.map(function (f) {
195
+ return f.segments.length;
196
+ })));
197
+ var maxLengthForSmart = Math.max.apply(Math, _toConsumableArray(conflictingFiles.map(function (f) {
198
+ return f.segments.length;
199
+ })));
200
+ if (maxLengthForSmart > minLength) {
201
+ // We have files at different depths, check if it's a parent-child scenario
202
+ var shorterFiles = conflictingFiles.filter(function (file) {
203
+ return file.segments.length === minLength;
204
+ });
205
+ var longerFiles = conflictingFiles.filter(function (file) {
206
+ return file.segments.length > minLength;
207
+ });
208
+ if (shorterFiles.length === 1 && longerFiles.length >= 1) {
209
+ // Check if the shorter file is truly a "parent" of the longer files
210
+ var shorterFile = shorterFiles[0];
211
+ var shorterPath = shorterFile.segments.slice(0, -1).join('/'); // Remove filename
212
+
213
+ // Check if all longer files share the same prefix as the shorter file
214
+ var allLongerFilesAreChildren = longerFiles.every(function (longerFile) {
215
+ var longerPath = longerFile.segments.slice(0, shorterFile.segments.length - 1).join('/');
216
+ return longerPath === shorterPath;
217
+ });
218
+ if (allLongerFilesAreChildren) {
219
+ // This is a true parent-child scenario, apply smart resolution
220
+
221
+ // For longer files, find distinguishing index
222
+ var _distinguishingIndex = -1;
223
+ var maxLongerLength = Math.max.apply(Math, _toConsumableArray(longerFiles.map(function (f) {
224
+ return f.segments.length;
225
+ })));
226
+ var _loop = function _loop(i) {
227
+ var segmentsAtIndex = new Set(longerFiles.map(function (f) {
228
+ return f.segments[i];
229
+ }).filter(Boolean));
230
+ if (segmentsAtIndex.size === longerFiles.length) {
231
+ _distinguishingIndex = i;
232
+ return 1; // break
233
+ }
234
+ };
235
+ for (var i = 0; i < maxLongerLength; i += 1) {
236
+ if (_loop(i)) break;
237
+ }
238
+ if (_distinguishingIndex !== -1) {
239
+ // Generate names for longer files using distinguishing segment
240
+ var _iterator = _createForOfIteratorHelper(longerFiles),
241
+ _step;
242
+ try {
243
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
244
+ var _file = _step.value;
245
+ var _fileName = _file.segments[_file.segments.length - 1];
246
+ var _isIndexFile = _fileName.startsWith('index.');
247
+ var distinguishingSegment = _file.segments[_distinguishingIndex];
248
+ var finalName = void 0;
249
+ if (_isIndexFile) {
250
+ // Check if this was a direct index import
251
+ var _originalImportParts = _file.originalImportPath.split('/');
252
+ var _isDirectIndexImport = _originalImportParts.length === 2 && _originalImportParts[0] === '.' && _originalImportParts[1].startsWith('index.');
253
+ if (_isDirectIndexImport) {
254
+ finalName = "".concat(distinguishingSegment, "/index").concat(_file.extension);
255
+ } else {
256
+ var _parentDir = _file.segments[_file.segments.length - 2];
257
+ finalName = "".concat(distinguishingSegment, "/").concat(_parentDir).concat(_file.extension);
258
+ }
259
+ } else {
260
+ finalName = "".concat(distinguishingSegment, "/").concat(_fileName);
261
+ }
262
+ finalNames.set(_file.resolvedPath, finalName);
263
+ }
264
+
265
+ // For shorter files, use the candidate name as-is (no conflicts after disambiguation)
266
+ } catch (err) {
267
+ _iterator.e(err);
268
+ } finally {
269
+ _iterator.f();
270
+ }
271
+ var _iterator2 = _createForOfIteratorHelper(shorterFiles),
272
+ _step2;
273
+ try {
274
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
275
+ var shortFile = _step2.value;
276
+ finalNames.set(shortFile.resolvedPath, candidateName);
277
+ }
278
+ } catch (err) {
279
+ _iterator2.e(err);
280
+ } finally {
281
+ _iterator2.f();
282
+ }
283
+ return; // Successfully resolved
284
+ }
285
+ }
286
+ }
287
+ }
288
+
289
+ // Fallback to original algorithm if smart resolution fails
290
+ var distinguishingIndex = -1;
291
+ var maxLength = Math.max.apply(Math, _toConsumableArray(conflictingFiles.map(function (f) {
292
+ return f.segments.length;
293
+ })));
294
+ var _loop2 = function _loop2(_i2) {
295
+ var segmentsAtIndex = new Set(conflictingFiles.map(function (f) {
296
+ return f.segments[_i2];
297
+ }).filter(Boolean));
298
+ if (segmentsAtIndex.size === conflictingFiles.length) {
299
+ distinguishingIndex = _i2;
300
+ return 1; // break
301
+ }
302
+ };
303
+ for (var _i2 = 0; _i2 < maxLength; _i2 += 1) {
304
+ if (_loop2(_i2)) break;
305
+ }
306
+ if (distinguishingIndex === -1) {
307
+ throw new Error("Cannot find distinguishing segment for files: ".concat(paths.join(', ')));
308
+ }
309
+
310
+ // Generate names using the distinguishing segment
311
+ var _iterator3 = _createForOfIteratorHelper(conflictingFiles),
312
+ _step3;
313
+ try {
314
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
315
+ var _file2 = _step3.value;
316
+ var _fileName2 = _file2.segments[_file2.segments.length - 1];
317
+ var _isIndexFile2 = _fileName2.startsWith('index.');
318
+ var _distinguishingSegment = _file2.segments[distinguishingIndex];
319
+ var _finalName = void 0;
320
+ if (_isIndexFile2) {
321
+ // Check if this was a direct index import
322
+ var _originalImportParts2 = _file2.originalImportPath.split('/');
323
+ var _isDirectIndexImport2 = _originalImportParts2.length === 2 && _originalImportParts2[0] === '.' && _originalImportParts2[1].startsWith('index.');
324
+ if (_isDirectIndexImport2) {
325
+ _finalName = "".concat(_distinguishingSegment, "/index").concat(_file2.extension);
326
+ } else {
327
+ var _parentDir2 = _file2.segments[_file2.segments.length - 2];
328
+ _finalName = "".concat(_distinguishingSegment, "/").concat(_parentDir2).concat(_file2.extension);
329
+ }
330
+ } else {
331
+ _finalName = "".concat(_distinguishingSegment, "/").concat(_fileName2);
332
+ }
333
+ finalNames.set(_file2.resolvedPath, _finalName);
334
+ }
335
+ } catch (err) {
336
+ _iterator3.e(err);
337
+ } finally {
338
+ _iterator3.f();
339
+ }
340
+ }
341
+ });
342
+
343
+ // Fourth pass: build the extraFiles mapping
344
+ finalNames.forEach(function (finalName, resolvedPath) {
345
+ extraFiles["./".concat(finalName)] = "file://".concat(resolvedPath);
346
+ });
347
+ return {
348
+ processedSource: '',
349
+ // Will be set by caller after rewriting
350
+ extraFiles: extraFiles
351
+ };
352
+ }