@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,198 @@
1
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ /**
4
+ * Generates a unique import name based on module path and original name
5
+ */
6
+ function generateUniqueImportName(originalName, modulePath, type, usedNames) {
7
+ // If no conflict, use original name
8
+ if (!usedNames.has(originalName)) {
9
+ return originalName;
10
+ }
11
+
12
+ // For conflicts, strategy depends on type and context:
13
+ // - Namespace imports: always use numbered suffixes
14
+ // - Named imports from simple test cases (lib1, lib2, etc.): use numbered suffixes
15
+ // - Other cases: try module-based names first
16
+
17
+ var wantsNumberedSuffix = type === 'namespace' || modulePath.startsWith('lib') && /^lib\d+$/.test(modulePath);
18
+ if (wantsNumberedSuffix) {
19
+ // Use numbered suffixes
20
+ var attempt = 1;
21
+ var _uniqueName = "".concat(originalName).concat(attempt);
22
+ while (usedNames.has(_uniqueName)) {
23
+ attempt += 1;
24
+ _uniqueName = "".concat(originalName).concat(attempt);
25
+ }
26
+ return _uniqueName;
27
+ }
28
+
29
+ // For real modules, try module-based names first
30
+ var moduleKey = modulePath.replace(/[@/.-]/g, '') // Remove special characters
31
+ .toLowerCase().slice(0, 20); // Limit length
32
+
33
+ var uniqueName = "".concat(originalName).concat(moduleKey);
34
+
35
+ // If that's still taken, try numbered suffixes
36
+ if (usedNames.has(uniqueName)) {
37
+ var _attempt = 1;
38
+ do {
39
+ uniqueName = "".concat(originalName).concat(_attempt);
40
+ _attempt += 1;
41
+ } while (usedNames.has(uniqueName));
42
+ }
43
+ return uniqueName;
44
+ }
45
+
46
+ /**
47
+ * Helper function to check if a string is a valid JavaScript identifier
48
+ */
49
+ function isValidIdentifier(str) {
50
+ // JavaScript identifier rules: must start with letter, $, or _, followed by letters, digits, $, or _
51
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(str);
52
+ }
53
+
54
+ /**
55
+ * Generates both import statements and resolved externals object
56
+ * Returns the import statements and the externals as a JavaScript object
57
+ */
58
+ export function generateResolvedExternals(externals) {
59
+ var moduleImports = {};
60
+ var usedNames = new Set();
61
+ var seenImports = new Set();
62
+
63
+ // First pass: collect all imports and resolve naming conflicts
64
+ for (var _i = 0, _Object$entries = Object.entries(externals); _i < _Object$entries.length; _i++) {
65
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
66
+ modulePath = _Object$entries$_i[0],
67
+ importItems = _Object$entries$_i[1];
68
+ if (!moduleImports[modulePath]) {
69
+ moduleImports[modulePath] = {
70
+ named: [],
71
+ namespace: []
72
+ };
73
+ }
74
+ var _iterator = _createForOfIteratorHelper(importItems),
75
+ _step;
76
+ try {
77
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
78
+ var _step$value = _step.value,
79
+ originalName = _step$value.name,
80
+ type = _step$value.type,
81
+ isType = _step$value.isType;
82
+ // Skip type-only imports and empty names
83
+ if (isType || !originalName.trim()) {
84
+ continue;
85
+ }
86
+ var importKey = "".concat(modulePath, ":").concat(originalName, ":").concat(type);
87
+
88
+ // Skip duplicates
89
+ if (seenImports.has(importKey)) {
90
+ continue;
91
+ }
92
+ seenImports.add(importKey);
93
+ var uniqueName = generateUniqueImportName(originalName, modulePath, type, usedNames);
94
+ usedNames.add(uniqueName);
95
+ if (type === 'default') {
96
+ moduleImports[modulePath]["default"] = uniqueName;
97
+ } else if (type === 'named') {
98
+ moduleImports[modulePath].named.push({
99
+ original: originalName,
100
+ unique: uniqueName
101
+ });
102
+ } else if (type === 'namespace') {
103
+ moduleImports[modulePath].namespace.push(uniqueName);
104
+ }
105
+ }
106
+ } catch (err) {
107
+ _iterator.e(err);
108
+ } finally {
109
+ _iterator.f();
110
+ }
111
+ }
112
+
113
+ // Second pass: generate consolidated import statements and resolved externals
114
+ var imports = [];
115
+ var resolvedExternalsObject = {};
116
+ for (var _i2 = 0, _Object$entries2 = Object.entries(moduleImports); _i2 < _Object$entries2.length; _i2++) {
117
+ var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
118
+ _modulePath = _Object$entries2$_i[0],
119
+ moduleImport = _Object$entries2$_i[1];
120
+ var hasDefault = moduleImport["default"] !== undefined;
121
+ var hasNamed = moduleImport.named.length > 0;
122
+ var hasNamespace = moduleImport.namespace.length > 0;
123
+
124
+ // Skip modules that have no valid imports
125
+ if (!hasDefault && !hasNamed && !hasNamespace) {
126
+ continue;
127
+ }
128
+ var importParts = [];
129
+
130
+ // Add default import
131
+ if (moduleImport["default"]) {
132
+ importParts.push(moduleImport["default"]);
133
+ }
134
+
135
+ // Add named imports (consolidated into one statement)
136
+ if (moduleImport.named.length > 0) {
137
+ var namedImports = moduleImport.named.map(function (_ref) {
138
+ var original = _ref.original,
139
+ unique = _ref.unique;
140
+ return original === unique ? original : "".concat(original, " as ").concat(unique);
141
+ }).join(', ');
142
+ importParts.push("{ ".concat(namedImports, " }"));
143
+ }
144
+
145
+ // Generate import statement
146
+ if (importParts.length > 0) {
147
+ imports.push("import ".concat(importParts.join(', '), " from '").concat(_modulePath, "';"));
148
+ }
149
+
150
+ // Add namespace imports (separate statements as they can't be combined)
151
+ var _iterator2 = _createForOfIteratorHelper(moduleImport.namespace),
152
+ _step2;
153
+ try {
154
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
155
+ var namespaceName = _step2.value;
156
+ imports.push("import * as ".concat(namespaceName, " from '").concat(_modulePath, "';"));
157
+ }
158
+
159
+ // Generate resolved externals entry for this module
160
+ // For invalid JavaScript identifiers, use the quoted version as the key
161
+ } catch (err) {
162
+ _iterator2.e(err);
163
+ } finally {
164
+ _iterator2.f();
165
+ }
166
+ var objectKey = isValidIdentifier(_modulePath) ? _modulePath : "\"".concat(_modulePath, "\"");
167
+ var resolvedValue = void 0;
168
+ if (hasDefault && !hasNamed && !hasNamespace) {
169
+ // Single default export - use direct assignment (e.g., 'react': React)
170
+ resolvedValue = moduleImport["default"];
171
+ } else if (!hasDefault && hasNamed && !hasNamespace) {
172
+ // Named exports only - use object syntax (e.g., '@mui/material': { Button, TextField })
173
+ var namedExports = moduleImport.named.map(function (_ref2) {
174
+ var original = _ref2.original;
175
+ return original;
176
+ }).join(', ');
177
+ resolvedValue = "{ ".concat(namedExports, " }");
178
+ } else if (!hasDefault && !hasNamed && hasNamespace) {
179
+ // Single namespace export - use direct assignment (e.g., 'lodash': lodash)
180
+ resolvedValue = moduleImport.namespace[0];
181
+ } else if (hasDefault) {
182
+ // Mixed imports - prefer default for the resolved externals
183
+ resolvedValue = moduleImport["default"];
184
+ } else if (hasNamespace) {
185
+ // Mixed imports - use namespace if no default
186
+ resolvedValue = moduleImport.namespace[0];
187
+ } else {
188
+ continue; // Should not happen, but safety check
189
+ }
190
+
191
+ // Add to the resolved externals object using the object key
192
+ resolvedExternalsObject[objectKey] = resolvedValue;
193
+ }
194
+ return {
195
+ imports: imports,
196
+ resolvedExternals: resolvedExternalsObject
197
+ };
198
+ }
@@ -0,0 +1,2 @@
1
+ import { loadPrecomputedCodeHighlighterClient } from "./loadPrecomputedCodeHighlighterClient.js";
2
+ export default loadPrecomputedCodeHighlighterClient;
@@ -0,0 +1,4 @@
1
+ // This is export format a Webpack / Turbopack loader expects
2
+
3
+ import { loadPrecomputedCodeHighlighterClient } from "./loadPrecomputedCodeHighlighterClient.js";
4
+ export default loadPrecomputedCodeHighlighterClient;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Injects import statements into source code after 'use client' directive.
3
+ * Handles proper placement of imports in client components.
4
+ */
5
+ export declare function injectImportsIntoSource(source: string, importLines: string[]): string;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Injects import statements into source code after 'use client' directive.
3
+ * Handles proper placement of imports in client components.
4
+ */
5
+ export function injectImportsIntoSource(source, importLines) {
6
+ if (importLines.length === 0) {
7
+ return source;
8
+ }
9
+ var importString = "".concat(importLines.join('\n'), "\n\n");
10
+
11
+ // Check if file starts with 'use client'
12
+ var useClientMatch = source.match(/^['"]use client['"]\s*;\s*\n/);
13
+ if (useClientMatch) {
14
+ // Insert after 'use client' directive
15
+ var afterUseClient = useClientMatch[0];
16
+ return "".concat(afterUseClient).concat(importString).concat(source.slice(afterUseClient.length));
17
+ }
18
+
19
+ // Insert at the beginning
20
+ return "".concat(importString).concat(source);
21
+ }
@@ -0,0 +1,15 @@
1
+ import type { LoaderContext } from 'webpack';
2
+ export type LoaderOptions = {};
3
+ /**
4
+ * Webpack loader that processes demo client files and precomputes externals.
5
+ *
6
+ * Finds createDemoClient calls and injects all required externals as imports
7
+ * at the top of the file, then passes them to the function as precompute.externals.
8
+ *
9
+ * The pattern expected is: create*Client(import.meta.url, { options: true })
10
+ * The result will be: create*Client(import.meta.url, { options: true, precompute: { externals } })
11
+ *
12
+ * Automatically skips processing if skipPrecompute: true is set.
13
+ */
14
+ export declare function loadPrecomputedCodeHighlighterClient(this: LoaderContext<LoaderOptions>, source: string): Promise<void>;
15
+ export default loadPrecomputedCodeHighlighterClient;
@@ -0,0 +1,233 @@
1
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
+ import _regenerator from "@babel/runtime/helpers/esm/regenerator";
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 { parseCreateFactoryCall } from "../loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js";
9
+ import { generateResolvedExternals } from "./generateResolvedExternals.js";
10
+ import { loadVariant } from "../../CodeHighlighter/loadVariant.js";
11
+ import { createLoadServerSource } from "../loadServerSource/index.js";
12
+ import { resolveVariantPathsWithFs } from "../loaderUtils/resolveModulePathWithFs.js";
13
+ import { getFileNameFromUrl } from "../loaderUtils/index.js";
14
+ import { mergeExternals } from "../loaderUtils/mergeExternals.js";
15
+ import { filterRuntimeExternals } from "./filterRuntimeExternals.js";
16
+ import { injectImportsIntoSource } from "./injectImportsIntoSource.js";
17
+ import { replacePrecomputeValue } from "../loadPrecomputedCodeHighlighter/replacePrecomputeValue.js";
18
+ /**
19
+ * Webpack loader that processes demo client files and precomputes externals.
20
+ *
21
+ * Finds createDemoClient calls and injects all required externals as imports
22
+ * at the top of the file, then passes them to the function as precompute.externals.
23
+ *
24
+ * The pattern expected is: create*Client(import.meta.url, { options: true })
25
+ * The result will be: create*Client(import.meta.url, { options: true, precompute: { externals } })
26
+ *
27
+ * Automatically skips processing if skipPrecompute: true is set.
28
+ */
29
+ export function loadPrecomputedCodeHighlighterClient(_x) {
30
+ return _loadPrecomputedCodeHighlighterClient.apply(this, arguments);
31
+ }
32
+
33
+ // Default export for webpack loader
34
+ function _loadPrecomputedCodeHighlighterClient() {
35
+ _loadPrecomputedCodeHighlighterClient = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(source) {
36
+ var _this = this;
37
+ var callback, demoCall, allDependencies, allExternalsArray, clientDir, indexPath, indexDemoCall, indexSource, resolvedVariantMap, loadSource, variantPromises, variantResults, _iterator, _step, result, allExternals, runtimeExternals, _generateResolvedExte, importLines, resolvedExternals, precomputeData, modifiedSource, _t2, _t3;
38
+ return _regenerator().w(function (_context2) {
39
+ while (1) switch (_context2.p = _context2.n) {
40
+ case 0:
41
+ callback = this.async();
42
+ this.cacheable();
43
+ _context2.p = 1;
44
+ _context2.n = 2;
45
+ return parseCreateFactoryCall(source, this.resourcePath, {
46
+ metadataOnly: true
47
+ });
48
+ case 2:
49
+ demoCall = _context2.v;
50
+ if (demoCall) {
51
+ _context2.n = 3;
52
+ break;
53
+ }
54
+ callback(null, source);
55
+ return _context2.a(2);
56
+ case 3:
57
+ if (demoCall.functionName.includes('Client')) {
58
+ _context2.n = 4;
59
+ break;
60
+ }
61
+ callback(null, source);
62
+ return _context2.a(2);
63
+ case 4:
64
+ if (!demoCall.options.skipPrecompute) {
65
+ _context2.n = 5;
66
+ break;
67
+ }
68
+ callback(null, source);
69
+ return _context2.a(2);
70
+ case 5:
71
+ // Load variant data for all variants to collect externals
72
+ allDependencies = [];
73
+ allExternalsArray = []; // For client files, we need to read the corresponding index.ts to get variants
74
+ // The client.ts and index.ts should be in the same directory
75
+ clientDir = this.resourcePath.substring(0, this.resourcePath.lastIndexOf('/'));
76
+ indexPath = "".concat(clientDir, "/index.ts"); // Read and parse the index.ts file to get variant information
77
+ indexDemoCall = null;
78
+ _context2.p = 6;
79
+ _context2.n = 7;
80
+ return readFile(indexPath, 'utf-8');
81
+ case 7:
82
+ indexSource = _context2.v;
83
+ // Add index.ts as a dependency for hot reloading
84
+ this.addDependency(indexPath);
85
+ _context2.n = 8;
86
+ return parseCreateFactoryCall(indexSource, indexPath);
87
+ case 8:
88
+ indexDemoCall = _context2.v;
89
+ _context2.n = 10;
90
+ break;
91
+ case 9:
92
+ _context2.p = 9;
93
+ _t2 = _context2.v;
94
+ // If we can't read index.ts, we can't determine variants
95
+ console.warn("Could not read ".concat(indexPath, " to determine variants for client: ").concat(_t2));
96
+ callback(null, source);
97
+ return _context2.a(2);
98
+ case 10:
99
+ if (!(!indexDemoCall || !indexDemoCall.variants)) {
100
+ _context2.n = 11;
101
+ break;
102
+ }
103
+ console.warn("No createDemo call or variants found in ".concat(indexPath, " for client processing"));
104
+ callback(null, source);
105
+ return _context2.a(2);
106
+ case 11:
107
+ _context2.n = 12;
108
+ return resolveVariantPathsWithFs(indexDemoCall.variants);
109
+ case 12:
110
+ resolvedVariantMap = _context2.v;
111
+ // Create loader functions
112
+ loadSource = createLoadServerSource({
113
+ includeDependencies: true,
114
+ storeAt: 'flat' // TODO: choose whichever is most performant as it shouldn't affect the output
115
+ }); // Process variants in parallel to collect externals
116
+ variantPromises = Array.from(resolvedVariantMap.entries()).map(/*#__PURE__*/function () {
117
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
118
+ var _indexDemoCall$namedE;
119
+ var _ref3, variantName, fileUrl, namedExport, variant, _getFileNameFromUrl, fileName, _yield$loadVariant, dependencies, externals, _t;
120
+ return _regenerator().w(function (_context) {
121
+ while (1) switch (_context.p = _context.n) {
122
+ case 0:
123
+ _ref3 = _slicedToArray(_ref, 2), variantName = _ref3[0], fileUrl = _ref3[1];
124
+ namedExport = (_indexDemoCall$namedE = indexDemoCall.namedExports) == null ? void 0 : _indexDemoCall$namedE[variantName];
125
+ variant = fileUrl;
126
+ if (!namedExport) {
127
+ _context.n = 2;
128
+ break;
129
+ }
130
+ _getFileNameFromUrl = getFileNameFromUrl(variant), fileName = _getFileNameFromUrl.fileName;
131
+ if (fileName) {
132
+ _context.n = 1;
133
+ break;
134
+ }
135
+ throw new Error("Cannot determine fileName from URL \"".concat(variant, "\" for variant \"").concat(variantName, "\". ") + "Please ensure the URL has a valid file extension.");
136
+ case 1:
137
+ variant = {
138
+ url: fileUrl,
139
+ fileName: fileName,
140
+ namedExport: namedExport
141
+ };
142
+ case 2:
143
+ _context.p = 2;
144
+ _context.n = 3;
145
+ return loadVariant(fileUrl,
146
+ // URL for the variant entry point (already includes file://)
147
+ variantName, variant, {
148
+ loadSource: loadSource,
149
+ // For loading source files and dependencies
150
+ maxDepth: 5,
151
+ disableParsing: true,
152
+ disableTransforms: true
153
+ });
154
+ case 3:
155
+ _yield$loadVariant = _context.v;
156
+ dependencies = _yield$loadVariant.dependencies;
157
+ externals = _yield$loadVariant.externals;
158
+ return _context.a(2, {
159
+ variantName: variantName,
160
+ dependencies: dependencies,
161
+ // All files that were loaded
162
+ externals: externals // Combined externals from all loaded files
163
+ });
164
+ case 4:
165
+ _context.p = 4;
166
+ _t = _context.v;
167
+ throw new Error("Failed to load variant ".concat(variantName, " from ").concat(fileUrl, ": ").concat(_t));
168
+ case 5:
169
+ return _context.a(2);
170
+ }
171
+ }, _callee, null, [[2, 4]]);
172
+ }));
173
+ return function (_x2) {
174
+ return _ref2.apply(this, arguments);
175
+ };
176
+ }());
177
+ _context2.n = 13;
178
+ return Promise.all(variantPromises);
179
+ case 13:
180
+ variantResults = _context2.v;
181
+ // Process results and collect dependencies and externals
182
+ _iterator = _createForOfIteratorHelper(variantResults);
183
+ try {
184
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
185
+ result = _step.value;
186
+ if (result) {
187
+ result.dependencies.forEach(function (file) {
188
+ allDependencies.push(file);
189
+ });
190
+ // Collect externals for proper merging
191
+ allExternalsArray.push(result.externals);
192
+ }
193
+ }
194
+
195
+ // Properly merge externals from all variants
196
+ } catch (err) {
197
+ _iterator.e(err);
198
+ } finally {
199
+ _iterator.f();
200
+ }
201
+ allExternals = mergeExternals(allExternalsArray); // Filter out type-only imports since they don't exist at runtime
202
+ runtimeExternals = filterRuntimeExternals(allExternals); // Generate import statements and resolved externals object
203
+ _generateResolvedExte = generateResolvedExternals(runtimeExternals), importLines = _generateResolvedExte.imports, resolvedExternals = _generateResolvedExte.resolvedExternals; // Add externals argument to the createDemoClient call using replacePrecomputeValue first
204
+ // (before injecting imports, so the original positions are still valid)
205
+ // with passPrecomputeAsIs enabled so externals are passed as resolved objects
206
+ precomputeData = {
207
+ externals: resolvedExternals
208
+ };
209
+ modifiedSource = replacePrecomputeValue(source, precomputeData, demoCall, {
210
+ passPrecomputeAsIs: true
211
+ }); // Then inject imports at the top of the file (after 'use client' if present)
212
+ modifiedSource = injectImportsIntoSource(modifiedSource, importLines);
213
+
214
+ // Add all dependencies to webpack's watch list
215
+ allDependencies.forEach(function (dep) {
216
+ // Strip 'file://' prefix if present before adding to webpack's dependency tracking
217
+ _this.addDependency(dep.startsWith('file://') ? dep.slice(7) : dep);
218
+ });
219
+ callback(null, modifiedSource);
220
+ _context2.n = 15;
221
+ break;
222
+ case 14:
223
+ _context2.p = 14;
224
+ _t3 = _context2.v;
225
+ callback(_t3 instanceof Error ? _t3 : new Error(String(_t3)));
226
+ case 15:
227
+ return _context2.a(2);
228
+ }
229
+ }, _callee2, this, [[6, 9], [1, 14]]);
230
+ }));
231
+ return _loadPrecomputedCodeHighlighterClient.apply(this, arguments);
232
+ }
233
+ export default loadPrecomputedCodeHighlighterClient;
@@ -0,0 +1 @@
1
+ export * from "./loadServerCodeMeta.js";
@@ -0,0 +1 @@
1
+ export * from "./loadServerCodeMeta.js";
@@ -0,0 +1,24 @@
1
+ import type { LoadCodeMeta } from "../../CodeHighlighter/types.js";
2
+ export interface CreateLoadCodeMetaOptions {}
3
+ /**
4
+ * Default loadServerCodeMeta function that resolves variant paths from demo files.
5
+ * This function is used to load code metadata for demos, specifically resolving paths for variants defined in the demo files.
6
+ * It reads the demo file, parses it to find `createDemo` calls with variants, and resolves the paths for those variants.
7
+ * It returns a Code object mapping variant names to their resolved file URLs.
8
+ */
9
+ export declare const loadServerCodeMeta: LoadCodeMeta;
10
+ /**
11
+ * Creates a loadCodeMeta function that resolves variant paths from demo files.
12
+ *
13
+ * This factory function creates a LoadCodeMeta implementation that:
14
+ * 1. Parses the demo file to find createDemo calls with variants
15
+ * 2. Resolves all variant entry point paths using resolveVariantPaths
16
+ * 3. Returns a Code object mapping variant names to their resolved file URLs
17
+ *
18
+ * The actual loading, parsing, and transformation of the variants is handled
19
+ * elsewhere by the CodeHighlighter component using loadVariant.
20
+ *
21
+ * @param options - Configuration options (currently unused)
22
+ * @returns LoadCodeMeta function that takes a URL and returns Promise<Code>
23
+ */
24
+ export declare function createLoadServerCodeMeta(_options?: CreateLoadCodeMetaOptions): LoadCodeMeta;
@@ -0,0 +1,90 @@
1
+ import _regenerator from "@babel/runtime/helpers/esm/regenerator";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
+ import { readFile } from 'node:fs/promises';
5
+ import { resolveVariantPathsWithFs } from "../loaderUtils/resolveModulePathWithFs.js";
6
+ import { parseCreateFactoryCall } from "../loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js";
7
+ import { getFileNameFromUrl } from "../loaderUtils/index.js";
8
+ /**
9
+ * Default loadServerCodeMeta function that resolves variant paths from demo files.
10
+ * This function is used to load code metadata for demos, specifically resolving paths for variants defined in the demo files.
11
+ * It reads the demo file, parses it to find `createDemo` calls with variants, and resolves the paths for those variants.
12
+ * It returns a Code object mapping variant names to their resolved file URLs.
13
+ */
14
+ export var loadServerCodeMeta = createLoadServerCodeMeta();
15
+
16
+ /**
17
+ * Creates a loadCodeMeta function that resolves variant paths from demo files.
18
+ *
19
+ * This factory function creates a LoadCodeMeta implementation that:
20
+ * 1. Parses the demo file to find createDemo calls with variants
21
+ * 2. Resolves all variant entry point paths using resolveVariantPaths
22
+ * 3. Returns a Code object mapping variant names to their resolved file URLs
23
+ *
24
+ * The actual loading, parsing, and transformation of the variants is handled
25
+ * elsewhere by the CodeHighlighter component using loadVariant.
26
+ *
27
+ * @param options - Configuration options (currently unused)
28
+ * @returns LoadCodeMeta function that takes a URL and returns Promise<Code>
29
+ */
30
+ export function createLoadServerCodeMeta() {
31
+ var _options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
32
+ return /*#__PURE__*/function () {
33
+ var _loadCodeMeta = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(url) {
34
+ var filePath, source, demoCall, code, resolvedVariantMap;
35
+ return _regenerator().w(function (_context) {
36
+ while (1) switch (_context.n) {
37
+ case 0:
38
+ // Remove file:// prefix if present to get file path
39
+ filePath = url.replace('file://', ''); // Read the source file to find createDemo calls
40
+ _context.n = 1;
41
+ return readFile(filePath, 'utf-8');
42
+ case 1:
43
+ source = _context.v;
44
+ _context.n = 2;
45
+ return parseCreateFactoryCall(source, filePath);
46
+ case 2:
47
+ demoCall = _context.v;
48
+ if (!(!demoCall || !demoCall.variants)) {
49
+ _context.n = 3;
50
+ break;
51
+ }
52
+ return _context.a(2, {});
53
+ case 3:
54
+ code = {}; // Resolve all variant paths and get them as file URLs
55
+ _context.n = 4;
56
+ return resolveVariantPathsWithFs(demoCall.variants || {});
57
+ case 4:
58
+ resolvedVariantMap = _context.v;
59
+ // Build Code object from the resolved variant map
60
+ Array.from(resolvedVariantMap.entries()).forEach(function (_ref) {
61
+ var _demoCall$namedExport;
62
+ var _ref2 = _slicedToArray(_ref, 2),
63
+ variantName = _ref2[0],
64
+ fileUrl = _ref2[1];
65
+ var namedExport = (_demoCall$namedExport = demoCall.namedExports) == null ? void 0 : _demoCall$namedExport[variantName];
66
+ code[variantName] = fileUrl;
67
+ if (namedExport) {
68
+ var _getFileNameFromUrl = getFileNameFromUrl(fileUrl),
69
+ fileName = _getFileNameFromUrl.fileName;
70
+ if (!fileName) {
71
+ throw new Error("Cannot determine fileName from URL \"".concat(fileUrl, "\" for variant \"").concat(variantName, "\". ") + "Please ensure the URL has a valid file extension.");
72
+ }
73
+ code[variantName] = {
74
+ url: fileUrl,
75
+ fileName: fileName,
76
+ namedExport: namedExport
77
+ };
78
+ }
79
+ // TODO: will this cause loadVariantMeta not to run? Maybe we should always run it
80
+ });
81
+ return _context.a(2, code);
82
+ }
83
+ }, _callee);
84
+ }));
85
+ function loadCodeMeta(_x) {
86
+ return _loadCodeMeta.apply(this, arguments);
87
+ }
88
+ return loadCodeMeta;
89
+ }();
90
+ }
@@ -0,0 +1 @@
1
+ export * from "./loadServerSource.js";
@@ -0,0 +1 @@
1
+ export * from "./loadServerSource.js";
@@ -0,0 +1,25 @@
1
+ import type { LoadSource } from "../../CodeHighlighter/types.js";
2
+ import { type StoreAtMode } from "../loaderUtils/processRelativeImports.js";
3
+ interface LoadSourceOptions {
4
+ maxDepth?: number;
5
+ maxFiles?: number;
6
+ includeDependencies?: boolean;
7
+ storeAt?: StoreAtMode;
8
+ }
9
+ /**
10
+ * Default loadServerSource function that reads a file and extracts its dependencies.
11
+ * This function is used to load source files for demos, resolving their imports and dependencies.
12
+ * It reads the source file, resolves its imports, and returns the processed source along with any
13
+ * additional files and dependencies that were found.
14
+ */
15
+ export declare const loadServerSource: LoadSource;
16
+ /**
17
+ * Creates a loadSource function that reads a file and extracts its dependencies.
18
+ *
19
+ * @param options.storeAt - Controls how imports are stored in extraFiles:
20
+ * - 'canonical': Full resolved path (e.g., '../Component/index.js')
21
+ * - 'import': Import path with file extension (e.g., '../Component.js')
22
+ * - 'flat': Flattened to current directory with rewritten imports (e.g., './Component.js')
23
+ */
24
+ export declare function createLoadServerSource(options?: LoadSourceOptions): LoadSource;
25
+ export {};