@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,679 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
+ import _extends from "@babel/runtime/helpers/esm/extends";
5
+ import _regenerator from "@babel/runtime/helpers/esm/regenerator";
6
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
7
+ import { loadVariant } from "./loadVariant.js";
8
+ import { getFileNameFromUrl } from "../pipeline/loaderUtils/index.js";
9
+
10
+ // Helper function to get the source for a specific filename from a variant
11
+ function getFileSource(_x, _x2, _x3) {
12
+ return _getFileSource.apply(this, arguments);
13
+ }
14
+ function _getFileSource() {
15
+ _getFileSource = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(variant, requestedFilename, loadSource) {
16
+ var filename, extraFile, loadResult;
17
+ return _regenerator().w(function (_context) {
18
+ while (1) switch (_context.n) {
19
+ case 0:
20
+ filename = requestedFilename || variant.fileName;
21
+ if (filename) {
22
+ _context.n = 2;
23
+ break;
24
+ }
25
+ if (!(variant.source !== undefined)) {
26
+ _context.n = 1;
27
+ break;
28
+ }
29
+ return _context.a(2, {
30
+ source: variant.source,
31
+ filename: undefined
32
+ });
33
+ case 1:
34
+ throw new Error('No filename available and no source in variant');
35
+ case 2:
36
+ if (!(filename === variant.fileName && variant.source !== undefined)) {
37
+ _context.n = 3;
38
+ break;
39
+ }
40
+ return _context.a(2, {
41
+ source: variant.source,
42
+ filename: filename
43
+ });
44
+ case 3:
45
+ if (!(filename !== variant.fileName && variant.extraFiles)) {
46
+ _context.n = 7;
47
+ break;
48
+ }
49
+ extraFile = variant.extraFiles[filename];
50
+ if (!(extraFile && typeof extraFile !== 'string' && extraFile.source !== undefined)) {
51
+ _context.n = 4;
52
+ break;
53
+ }
54
+ return _context.a(2, {
55
+ source: extraFile.source,
56
+ filename: filename
57
+ });
58
+ case 4:
59
+ if (!(typeof extraFile === 'string' && loadSource)) {
60
+ _context.n = 6;
61
+ break;
62
+ }
63
+ _context.n = 5;
64
+ return loadSource(extraFile);
65
+ case 5:
66
+ loadResult = _context.v;
67
+ return _context.a(2, {
68
+ source: loadResult.source,
69
+ filename: filename
70
+ });
71
+ case 6:
72
+ if (!(extraFile && typeof extraFile !== 'string' && !extraFile.source && loadSource)) {
73
+ _context.n = 7;
74
+ break;
75
+ }
76
+ throw new Error("Extra file ".concat(filename, " has no source or URL to load from"));
77
+ case 7:
78
+ throw new Error("File ".concat(filename, " not found in variant or cannot be loaded"));
79
+ case 8:
80
+ return _context.a(2);
81
+ }
82
+ }, _callee);
83
+ }));
84
+ return _getFileSource.apply(this, arguments);
85
+ }
86
+ export function loadFallbackCode(_x4, _x5, _x6) {
87
+ return _loadFallbackCode.apply(this, arguments);
88
+ }
89
+ function _loadFallbackCode() {
90
+ _loadFallbackCode = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(url, initialVariant, loaded) {
91
+ var options,
92
+ shouldHighlight,
93
+ fallbackUsesExtraFiles,
94
+ fallbackUsesAllVariants,
95
+ sourceParser,
96
+ loadSource,
97
+ loadVariantMeta,
98
+ loadCodeMeta,
99
+ initialFilename,
100
+ variants,
101
+ globalsCode,
102
+ initial,
103
+ _allFileNames,
104
+ fileSource,
105
+ actualFilename,
106
+ result,
107
+ parseSource,
108
+ quickVariant,
109
+ _allFileNames2,
110
+ _fileSource,
111
+ _actualFilename,
112
+ _result,
113
+ _parseSource,
114
+ globalsCodeObjects,
115
+ hasStringUrls,
116
+ globalsPromises,
117
+ resolvedGlobalsCode,
118
+ _iterator,
119
+ _step,
120
+ codeObj,
121
+ targetVariant,
122
+ _yield$loadVariant,
123
+ loadedVariant,
124
+ allFileNames,
125
+ allVariants,
126
+ variantPromises,
127
+ variantResults,
128
+ finalInitial,
129
+ finalFileSource,
130
+ finalFilename,
131
+ _result2,
132
+ _args4 = arguments,
133
+ _t4,
134
+ _t5,
135
+ _t6,
136
+ _t7,
137
+ _t8,
138
+ _t9,
139
+ _t0,
140
+ _t1;
141
+ return _regenerator().w(function (_context4) {
142
+ while (1) switch (_context4.p = _context4.n) {
143
+ case 0:
144
+ options = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : {};
145
+ shouldHighlight = options.shouldHighlight, fallbackUsesExtraFiles = options.fallbackUsesExtraFiles, fallbackUsesAllVariants = options.fallbackUsesAllVariants, sourceParser = options.sourceParser, loadSource = options.loadSource, loadVariantMeta = options.loadVariantMeta, loadCodeMeta = options.loadCodeMeta, initialFilename = options.initialFilename, variants = options.variants, globalsCode = options.globalsCode;
146
+ loaded = _extends({}, loaded);
147
+
148
+ // Step 1: Ensure we have the initial variant loaded
149
+ initial = loaded[initialVariant];
150
+ if (initial) {
151
+ _context4.n = 5;
152
+ break;
153
+ }
154
+ if (loadCodeMeta) {
155
+ _context4.n = 1;
156
+ break;
157
+ }
158
+ throw new Error('"loadCodeMeta" function is required when initial variant is not provided');
159
+ case 1:
160
+ _context4.p = 1;
161
+ _context4.n = 2;
162
+ return loadCodeMeta(url);
163
+ case 2:
164
+ loaded = _context4.v;
165
+ _context4.n = 4;
166
+ break;
167
+ case 3:
168
+ _context4.p = 3;
169
+ _t4 = _context4.v;
170
+ throw new Error("Failed to load code from URL: ".concat(url, ". Error: ").concat(JSON.stringify(_t4)));
171
+ case 4:
172
+ initial = loaded[initialVariant];
173
+ if (initial) {
174
+ _context4.n = 5;
175
+ break;
176
+ }
177
+ throw new Error("Initial variant \"".concat(initialVariant, "\" not found in loaded code."));
178
+ case 5:
179
+ if (!(typeof initial !== 'string' && initial.allFilesListed && !fallbackUsesExtraFiles && !fallbackUsesAllVariants)) {
180
+ _context4.n = 16;
181
+ break;
182
+ }
183
+ // Collect all file names from the loaded code
184
+ _allFileNames = new Set();
185
+ if (initial.fileName) {
186
+ _allFileNames.add(initial.fileName);
187
+ }
188
+ if (initial.extraFiles) {
189
+ Object.keys(initial.extraFiles).forEach(function (fileName) {
190
+ return _allFileNames.add(fileName);
191
+ });
192
+ }
193
+
194
+ // Get the source for the requested filename (or main file if not specified)
195
+ _context4.p = 6;
196
+ _context4.n = 7;
197
+ return getFileSource(initial, initialFilename, loadSource);
198
+ case 7:
199
+ result = _context4.v;
200
+ fileSource = result.source;
201
+ actualFilename = result.filename;
202
+ _context4.n = 9;
203
+ break;
204
+ case 8:
205
+ _context4.p = 8;
206
+ _t5 = _context4.v;
207
+ throw new Error("Failed to get source for file ".concat(initialFilename || initial.fileName, " in variant ").concat(initialVariant, ": ").concat(_t5));
208
+ case 9:
209
+ if (!(shouldHighlight && typeof fileSource === 'string' && sourceParser && actualFilename)) {
210
+ _context4.n = 14;
211
+ break;
212
+ }
213
+ _context4.p = 10;
214
+ _context4.n = 11;
215
+ return sourceParser;
216
+ case 11:
217
+ parseSource = _context4.v;
218
+ fileSource = parseSource(fileSource, actualFilename);
219
+ _context4.n = 13;
220
+ break;
221
+ case 12:
222
+ _context4.p = 12;
223
+ _t6 = _context4.v;
224
+ throw new Error("Failed to parse source for highlighting (variant: ".concat(initialVariant, ", file: ").concat(actualFilename, "): ").concat(JSON.stringify(_t6)));
225
+ case 13:
226
+ _context4.n = 15;
227
+ break;
228
+ case 14:
229
+ if (shouldHighlight && typeof fileSource === 'string' && !actualFilename) {
230
+ // Create basic HAST node when we can't parse due to missing filename
231
+ // This marks that the source has passed through the parsing pipeline
232
+ fileSource = {
233
+ type: 'root',
234
+ children: [{
235
+ type: 'text',
236
+ value: fileSource
237
+ }]
238
+ };
239
+ }
240
+ case 15:
241
+ // Update the loaded code with any changes we made
242
+ if (actualFilename && actualFilename === initial.fileName) {
243
+ initial = _extends(_extends({}, initial), {}, {
244
+ source: fileSource
245
+ });
246
+ loaded = _extends(_extends({}, loaded), {}, _defineProperty({}, initialVariant, initial));
247
+ } else if (!actualFilename && !initial.fileName) {
248
+ // If both are undefined, we're dealing with the main source
249
+ initial = _extends(_extends({}, initial), {}, {
250
+ source: fileSource
251
+ });
252
+ loaded = _extends(_extends({}, loaded), {}, _defineProperty({}, initialVariant, initial));
253
+ }
254
+
255
+ // Early return - we have all the info we need
256
+ return _context4.a(2, {
257
+ code: loaded,
258
+ initialFilename: actualFilename,
259
+ initialSource: fileSource,
260
+ initialExtraFiles: initial.extraFiles || {},
261
+ allFileNames: Array.from(_allFileNames)
262
+ });
263
+ case 16:
264
+ if (!(typeof initial === 'string')) {
265
+ _context4.n = 33;
266
+ break;
267
+ }
268
+ _context4.p = 17;
269
+ if (!loadVariantMeta) {
270
+ _context4.n = 19;
271
+ break;
272
+ }
273
+ _context4.n = 18;
274
+ return loadVariantMeta(initialVariant, initial);
275
+ case 18:
276
+ quickVariant = _context4.v;
277
+ _context4.n = 20;
278
+ break;
279
+ case 19:
280
+ // Create a basic variant using fallback logic
281
+ quickVariant = {
282
+ url: initial,
283
+ fileName: getFileNameFromUrl(initial).fileName
284
+ };
285
+ case 20:
286
+ loaded = _extends(_extends({}, loaded), {}, _defineProperty({}, initialVariant, quickVariant));
287
+ initial = quickVariant;
288
+
289
+ // If we have all files listed and don't need extra file processing, we can optimize
290
+ if (!(quickVariant.allFilesListed && !fallbackUsesExtraFiles && !fallbackUsesAllVariants)) {
291
+ _context4.n = 31;
292
+ break;
293
+ }
294
+ // Collect all file names from the quick load
295
+ _allFileNames2 = new Set();
296
+ if (quickVariant.fileName) {
297
+ _allFileNames2.add(quickVariant.fileName);
298
+ }
299
+ if (quickVariant.extraFiles) {
300
+ Object.keys(quickVariant.extraFiles).forEach(function (fileName) {
301
+ return _allFileNames2.add(fileName);
302
+ });
303
+ }
304
+
305
+ // Get the source for the requested filename (or main file if not specified)
306
+ _context4.p = 21;
307
+ _context4.n = 22;
308
+ return getFileSource(quickVariant, initialFilename, loadSource);
309
+ case 22:
310
+ _result = _context4.v;
311
+ _fileSource = _result.source;
312
+ _actualFilename = _result.filename;
313
+ _context4.n = 24;
314
+ break;
315
+ case 23:
316
+ _context4.p = 23;
317
+ _t7 = _context4.v;
318
+ throw new Error("Failed to get source for file ".concat(initialFilename || quickVariant.fileName, " in variant ").concat(initialVariant, ": ").concat(_t7));
319
+ case 24:
320
+ if (!(shouldHighlight && typeof _fileSource === 'string' && sourceParser && _actualFilename)) {
321
+ _context4.n = 29;
322
+ break;
323
+ }
324
+ _context4.p = 25;
325
+ _context4.n = 26;
326
+ return sourceParser;
327
+ case 26:
328
+ _parseSource = _context4.v;
329
+ _fileSource = _parseSource(_fileSource, _actualFilename);
330
+ _context4.n = 28;
331
+ break;
332
+ case 27:
333
+ _context4.p = 27;
334
+ _t8 = _context4.v;
335
+ throw new Error("Failed to parse source for highlighting (variant: ".concat(initialVariant, ", file: ").concat(_actualFilename, "): ").concat(JSON.stringify(_t8)));
336
+ case 28:
337
+ _context4.n = 30;
338
+ break;
339
+ case 29:
340
+ if (shouldHighlight && typeof _fileSource === 'string' && !_actualFilename) {
341
+ // Create basic HAST node when we can't parse due to missing filename
342
+ // This marks that the source has passed through the parsing pipeline
343
+ _fileSource = {
344
+ type: 'root',
345
+ children: [{
346
+ type: 'text',
347
+ value: _fileSource
348
+ }]
349
+ };
350
+ }
351
+ case 30:
352
+ // Update the loaded code with any changes we made
353
+ if (_actualFilename && _actualFilename === quickVariant.fileName) {
354
+ initial = _extends(_extends({}, quickVariant), {}, {
355
+ source: _fileSource
356
+ });
357
+ loaded = _extends(_extends({}, loaded), {}, _defineProperty({}, initialVariant, initial));
358
+ } else if (!_actualFilename && !quickVariant.fileName) {
359
+ // If both are undefined, we're dealing with the main source
360
+ initial = _extends(_extends({}, quickVariant), {}, {
361
+ source: _fileSource
362
+ });
363
+ loaded = _extends(_extends({}, loaded), {}, _defineProperty({}, initialVariant, initial));
364
+ }
365
+
366
+ // Early return - we have all the info we need
367
+ return _context4.a(2, {
368
+ code: loaded,
369
+ initialFilename: _actualFilename,
370
+ initialSource: _fileSource,
371
+ initialExtraFiles: quickVariant.extraFiles || {},
372
+ allFileNames: Array.from(_allFileNames2)
373
+ });
374
+ case 31:
375
+ _context4.n = 33;
376
+ break;
377
+ case 32:
378
+ _context4.p = 32;
379
+ _t9 = _context4.v;
380
+ throw new Error("Failed to load initial variant code (variant: ".concat(initialVariant, ", url: ").concat(initial, "): ").concat(JSON.stringify(_t9)));
381
+ case 33:
382
+ if (!(globalsCode && globalsCode.length > 0)) {
383
+ _context4.n = 36;
384
+ break;
385
+ }
386
+ hasStringUrls = globalsCode.some(function (item) {
387
+ return typeof item === 'string';
388
+ });
389
+ if (!(hasStringUrls && !loadCodeMeta)) {
390
+ _context4.n = 34;
391
+ break;
392
+ }
393
+ throw new Error('loadCodeMeta function is required when globalsCode contains string URLs');
394
+ case 34:
395
+ // Load all string URLs in parallel, keep Code objects as-is
396
+ globalsPromises = globalsCode.map(/*#__PURE__*/function () {
397
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(globalItem) {
398
+ var _t;
399
+ return _regenerator().w(function (_context2) {
400
+ while (1) switch (_context2.p = _context2.n) {
401
+ case 0:
402
+ if (!(typeof globalItem === 'string')) {
403
+ _context2.n = 4;
404
+ break;
405
+ }
406
+ _context2.p = 1;
407
+ _context2.n = 2;
408
+ return loadCodeMeta(globalItem);
409
+ case 2:
410
+ return _context2.a(2, _context2.v);
411
+ case 3:
412
+ _context2.p = 3;
413
+ _t = _context2.v;
414
+ throw new Error("Failed to load globalsCode from URL: ".concat(globalItem, ". Error: ").concat(JSON.stringify(_t)));
415
+ case 4:
416
+ return _context2.a(2, globalItem);
417
+ case 5:
418
+ return _context2.a(2);
419
+ }
420
+ }, _callee2, null, [[1, 3]]);
421
+ }));
422
+ return function (_x7) {
423
+ return _ref.apply(this, arguments);
424
+ };
425
+ }());
426
+ _context4.n = 35;
427
+ return Promise.all(globalsPromises);
428
+ case 35:
429
+ globalsCodeObjects = _context4.v;
430
+ case 36:
431
+ if (globalsCodeObjects && globalsCodeObjects.length > 0) {
432
+ resolvedGlobalsCode = [];
433
+ _iterator = _createForOfIteratorHelper(globalsCodeObjects);
434
+ try {
435
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
436
+ codeObj = _step.value;
437
+ // Only use the variant that matches the current initialVariant
438
+ targetVariant = codeObj[initialVariant];
439
+ if (targetVariant) {
440
+ resolvedGlobalsCode.push(targetVariant);
441
+ }
442
+ }
443
+ } catch (err) {
444
+ _iterator.e(err);
445
+ } finally {
446
+ _iterator.f();
447
+ }
448
+ }
449
+ _context4.p = 37;
450
+ _context4.n = 38;
451
+ return loadVariant(url, initialVariant, initial, {
452
+ sourceParser: sourceParser,
453
+ loadSource: loadSource,
454
+ loadVariantMeta: loadVariantMeta,
455
+ sourceTransformers: undefined,
456
+ // sourceTransformers - skip transforms for fallback
457
+ disableTransforms: true,
458
+ // Don't apply transforms for fallback
459
+ disableParsing: !shouldHighlight,
460
+ // Only parse if highlighting is needed
461
+ globalsCode: resolvedGlobalsCode // Pass resolved globalsCode
462
+ });
463
+ case 38:
464
+ _yield$loadVariant = _context4.v;
465
+ loadedVariant = _yield$loadVariant.code;
466
+ // Update the loaded code with the processed variant
467
+ loaded = _extends(_extends({}, loaded), {}, _defineProperty({}, initialVariant, loadedVariant));
468
+ initial = loadedVariant;
469
+ _context4.n = 40;
470
+ break;
471
+ case 39:
472
+ _context4.p = 39;
473
+ _t0 = _context4.v;
474
+ throw new Error("Failed to load initial variant using loadVariant (variant: ".concat(initialVariant, ", url: ").concat(url, "): ").concat(JSON.stringify(_t0)));
475
+ case 40:
476
+ // Step 3: Collect all file names
477
+ allFileNames = new Set();
478
+ if (initial.fileName) {
479
+ allFileNames.add(initial.fileName);
480
+ }
481
+
482
+ // Add extra files from the initial variant
483
+ if (initial.extraFiles) {
484
+ Object.keys(initial.extraFiles).forEach(function (fileName) {
485
+ return allFileNames.add(fileName);
486
+ });
487
+ }
488
+
489
+ // Step 4: Handle fallbackUsesAllVariants - load all variants to get all possible files
490
+ if (!fallbackUsesAllVariants) {
491
+ _context4.n = 43;
492
+ break;
493
+ }
494
+ // Determine all variants to process - use provided variants or infer from loaded code
495
+ allVariants = variants || Object.keys(loaded || {});
496
+ if (!(allVariants.length === 0)) {
497
+ _context4.n = 41;
498
+ break;
499
+ }
500
+ console.warn('No variants found for fallbackUsesAllVariants processing');
501
+ _context4.n = 43;
502
+ break;
503
+ case 41:
504
+ // Process all required variants, not just the ones already loaded
505
+ variantPromises = allVariants.map(/*#__PURE__*/function () {
506
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(variantName) {
507
+ var _loaded;
508
+ var variant, allCode, _yield$loadVariant2, _loadedVariant, fileNames, _t2, _t3;
509
+ return _regenerator().w(function (_context3) {
510
+ while (1) switch (_context3.p = _context3.n) {
511
+ case 0:
512
+ if (!(variantName === initialVariant)) {
513
+ _context3.n = 1;
514
+ break;
515
+ }
516
+ return _context3.a(2, {
517
+ variantName: variantName,
518
+ loadedVariant: null,
519
+ fileNames: []
520
+ });
521
+ case 1:
522
+ variant = (_loaded = loaded) == null ? void 0 : _loaded[variantName]; // If variant is not loaded yet, load it first using loadCodeMeta
523
+ if (!(!variant && loadCodeMeta)) {
524
+ _context3.n = 5;
525
+ break;
526
+ }
527
+ _context3.p = 2;
528
+ _context3.n = 3;
529
+ return loadCodeMeta(url);
530
+ case 3:
531
+ allCode = _context3.v;
532
+ variant = allCode[variantName];
533
+ // Update loaded with all variants from loadCodeMeta
534
+ loaded = _extends(_extends({}, loaded), allCode);
535
+ _context3.n = 5;
536
+ break;
537
+ case 4:
538
+ _context3.p = 4;
539
+ _t2 = _context3.v;
540
+ console.warn("Failed to load code meta for variant ".concat(variantName, ": ").concat(_t2));
541
+ return _context3.a(2, {
542
+ variantName: variantName,
543
+ loadedVariant: null,
544
+ fileNames: []
545
+ });
546
+ case 5:
547
+ if (variant) {
548
+ _context3.n = 6;
549
+ break;
550
+ }
551
+ console.warn("Variant ".concat(variantName, " not found after loading code meta"));
552
+ return _context3.a(2, {
553
+ variantName: variantName,
554
+ loadedVariant: null,
555
+ fileNames: []
556
+ });
557
+ case 6:
558
+ _context3.p = 6;
559
+ _context3.n = 7;
560
+ return loadVariant(url, variantName, variant, {
561
+ sourceParser: sourceParser,
562
+ loadSource: loadSource,
563
+ loadVariantMeta: loadVariantMeta,
564
+ sourceTransformers: undefined,
565
+ // sourceTransformers
566
+ disableTransforms: true,
567
+ disableParsing: !shouldHighlight,
568
+ globalsCode: globalsCodeObjects && globalsCodeObjects.length > 0 ? function () {
569
+ // Convert globalsCodeObjects to VariantCode | string for this specific variant
570
+ var variantGlobalsCode = [];
571
+ var _iterator2 = _createForOfIteratorHelper(globalsCodeObjects),
572
+ _step2;
573
+ try {
574
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
575
+ var _codeObj = _step2.value;
576
+ // Only use the variant that matches the current variantName
577
+ var _targetVariant = _codeObj[variantName];
578
+ if (_targetVariant) {
579
+ variantGlobalsCode.push(_targetVariant);
580
+ }
581
+ }
582
+ } catch (err) {
583
+ _iterator2.e(err);
584
+ } finally {
585
+ _iterator2.f();
586
+ }
587
+ return variantGlobalsCode;
588
+ }() : undefined
589
+ });
590
+ case 7:
591
+ _yield$loadVariant2 = _context3.v;
592
+ _loadedVariant = _yield$loadVariant2.code;
593
+ // Collect file names from this variant
594
+ fileNames = _loadedVariant.fileName ? [_loadedVariant.fileName] : [];
595
+ if (_loadedVariant.extraFiles) {
596
+ fileNames.push.apply(fileNames, _toConsumableArray(Object.keys(_loadedVariant.extraFiles)));
597
+ }
598
+ return _context3.a(2, {
599
+ variantName: variantName,
600
+ loadedVariant: _loadedVariant,
601
+ fileNames: fileNames
602
+ });
603
+ case 8:
604
+ _context3.p = 8;
605
+ _t3 = _context3.v;
606
+ // Log but don't fail - we want to get as many file names as possible
607
+ console.warn("Failed to load variant ".concat(variantName, " for file listing: ").concat(_t3));
608
+ return _context3.a(2, {
609
+ variantName: variantName,
610
+ loadedVariant: null,
611
+ fileNames: []
612
+ });
613
+ }
614
+ }, _callee3, null, [[6, 8], [2, 4]]);
615
+ }));
616
+ return function (_x8) {
617
+ return _ref2.apply(this, arguments);
618
+ };
619
+ }());
620
+ _context4.n = 42;
621
+ return Promise.all(variantPromises);
622
+ case 42:
623
+ variantResults = _context4.v;
624
+ // Update loaded code and collect file names
625
+ variantResults.forEach(function (_ref3) {
626
+ var variantName = _ref3.variantName,
627
+ loadedVariant = _ref3.loadedVariant,
628
+ fileNames = _ref3.fileNames;
629
+ if (loadedVariant) {
630
+ loaded = _extends(_extends({}, loaded), {}, _defineProperty({}, variantName, loadedVariant));
631
+ }
632
+ fileNames.forEach(function (fileName) {
633
+ return allFileNames.add(fileName);
634
+ });
635
+ });
636
+ case 43:
637
+ // Ensure we have the latest initial variant data
638
+ finalInitial = loaded[initialVariant];
639
+ if (!(!finalInitial || typeof finalInitial === 'string')) {
640
+ _context4.n = 44;
641
+ break;
642
+ }
643
+ throw new Error("Failed to process initial variant: ".concat(initialVariant));
644
+ case 44:
645
+ _context4.p = 44;
646
+ _context4.n = 45;
647
+ return getFileSource(finalInitial, initialFilename, loadSource);
648
+ case 45:
649
+ _result2 = _context4.v;
650
+ finalFileSource = _result2.source;
651
+ finalFilename = _result2.filename;
652
+ _context4.n = 48;
653
+ break;
654
+ case 46:
655
+ _context4.p = 46;
656
+ _t1 = _context4.v;
657
+ if (!(!finalInitial.fileName && !finalInitial.source)) {
658
+ _context4.n = 47;
659
+ break;
660
+ }
661
+ throw new Error("Cannot determine filename for initial variant \"".concat(initialVariant, "\". ") + "No fileName available in variant definition, no initialFilename provided, and no source available.");
662
+ case 47:
663
+ // Fall back to the main file with proper validation
664
+ finalFileSource = finalInitial.source || '';
665
+ finalFilename = finalInitial.fileName;
666
+ case 48:
667
+ return _context4.a(2, {
668
+ code: loaded,
669
+ initialFilename: finalFilename,
670
+ initialSource: finalFileSource,
671
+ initialExtraFiles: finalInitial.extraFiles || {},
672
+ allFileNames: Array.from(allFileNames),
673
+ processedGlobalsCode: globalsCodeObjects
674
+ });
675
+ }
676
+ }, _callee4, null, [[44, 46], [37, 39], [25, 27], [21, 23], [17, 32], [10, 12], [6, 8], [1, 3]]);
677
+ }));
678
+ return _loadFallbackCode.apply(this, arguments);
679
+ }
@@ -0,0 +1,12 @@
1
+ import type { VariantCode, LoadVariantOptions, Externals } from "./types.js";
2
+ /**
3
+ * Loads a variant with support for recursive extra file loading.
4
+ * The loadSource function can now return extraFiles that will be loaded recursively.
5
+ * Supports both relative and absolute paths for extra files.
6
+ * Uses Promise.all for efficient parallel loading of extra files.
7
+ */
8
+ export declare function loadVariant(url: string | undefined, variantName: string, variant: VariantCode | string | undefined, options?: LoadVariantOptions): Promise<{
9
+ code: VariantCode;
10
+ dependencies: string[];
11
+ externals: Externals;
12
+ }>;