@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,14 @@
1
+ import type { ParsedCreateFactory } from "./parseCreateFactoryCall.js";
2
+ /**
3
+ * Adds or replaces precompute data in createDemo function calls.
4
+ *
5
+ * @param source - The source code string containing createDemo calls
6
+ * @param precomputeData - The data object to inject
7
+ * @param demoCallInfo - Information about the parsed demo call structure from parseCreateFactoryCall
8
+ * @param options - Optional configuration
9
+ * @param options.passPrecomputeAsIs - Whether to pass precompute data as-is without JSON stringifying (default: false)
10
+ * @returns The modified source code with precompute data injected
11
+ */
12
+ export declare function replacePrecomputeValue(source: string, precomputeData: Record<string, any>, demoCallInfo?: ParsedCreateFactory, options?: {
13
+ passPrecomputeAsIs?: boolean;
14
+ }): string;
@@ -0,0 +1,73 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import { serializeFunctionArguments } from "./serializeFunctionArguments.js";
3
+ /**
4
+ * Adds or replaces precompute data in createDemo function calls.
5
+ *
6
+ * @param source - The source code string containing createDemo calls
7
+ * @param precomputeData - The data object to inject
8
+ * @param demoCallInfo - Information about the parsed demo call structure from parseCreateFactoryCall
9
+ * @param options - Optional configuration
10
+ * @param options.passPrecomputeAsIs - Whether to pass precompute data as-is without JSON stringifying (default: false)
11
+ * @returns The modified source code with precompute data injected
12
+ */
13
+ export function replacePrecomputeValue(source, precomputeData, demoCallInfo) {
14
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
15
+ // If no demoCallInfo provided, return unchanged
16
+ if (!demoCallInfo) {
17
+ return source;
18
+ }
19
+ var hasOptions = demoCallInfo.hasOptions,
20
+ argumentsStartIndex = demoCallInfo.argumentsStartIndex,
21
+ argumentsEndIndex = demoCallInfo.argumentsEndIndex,
22
+ structuredUrl = demoCallInfo.structuredUrl,
23
+ structuredVariants = demoCallInfo.structuredVariants,
24
+ structuredOptions = demoCallInfo.structuredOptions;
25
+ var _options$passPrecompu = options.passPrecomputeAsIs,
26
+ passPrecomputeAsIs = _options$passPrecompu === void 0 ? false : _options$passPrecompu;
27
+
28
+ // Create new options object with precompute data
29
+ var newOptions = {};
30
+
31
+ // First, copy all existing options to preserve their order
32
+ if (hasOptions && structuredOptions) {
33
+ Object.entries(structuredOptions).forEach(function (_ref) {
34
+ var _ref2 = _slicedToArray(_ref, 2),
35
+ key = _ref2[0],
36
+ value = _ref2[1];
37
+ if (key !== 'precompute') {
38
+ // Skip existing precompute, we'll replace it
39
+ newOptions[key] = value;
40
+ }
41
+ });
42
+ }
43
+
44
+ // Add precompute data - pass as-is if requested, otherwise JSON stringify
45
+ newOptions.precompute = passPrecomputeAsIs ? precomputeData : JSON.stringify(precomputeData, null, 2);
46
+
47
+ // Serialize all arguments using the standard function
48
+ var args;
49
+
50
+ // Build arguments array based on what's available
51
+ if (hasOptions || Object.keys(newOptions).length > 0) {
52
+ // We need to include options
53
+ if (structuredVariants !== undefined) {
54
+ // Normal case: url, variants, options
55
+ args = [structuredUrl, structuredVariants, newOptions];
56
+ } else {
57
+ // Metadata-only case: url, options (skip undefined variants)
58
+ args = [structuredUrl, newOptions];
59
+ }
60
+ } else if (structuredVariants !== undefined) {
61
+ // No options needed, but we have variants
62
+ args = [structuredUrl, structuredVariants];
63
+ } else {
64
+ // Only URL argument
65
+ args = [structuredUrl];
66
+ }
67
+ var serializedArgs = serializeFunctionArguments(args);
68
+
69
+ // Replace the arguments section
70
+ var before = source.substring(0, argumentsStartIndex);
71
+ var after = source.substring(argumentsEndIndex);
72
+ return "".concat(before).concat(serializedArgs).concat(after);
73
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Utility function for serializing structured function arguments back to string format
3
+ * This is the inverse of parseFunctionArguments - it takes structured data and creates
4
+ * valid JavaScript/TypeScript function call arguments.
5
+ */
6
+ import type { SplitArguments } from "./parseFunctionArguments.js";
7
+ /**
8
+ * Serialize structured arguments back to a string representation
9
+ * Uses JSON.stringify for object values for performance and reliability
10
+ */
11
+ export declare function serializeFunctionArguments(args: SplitArguments): string;
@@ -0,0 +1,203 @@
1
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ /**
4
+ * Utility function for serializing structured function arguments back to string format
5
+ * This is the inverse of parseFunctionArguments - it takes structured data and creates
6
+ * valid JavaScript/TypeScript function call arguments.
7
+ */
8
+
9
+ import { isArray, isFunction, isGeneric, isArrowFunction, isObjectLiteral, isTypeAssertion } from "./parseFunctionArguments.js";
10
+
11
+ /**
12
+ * Serialize structured arguments back to a string representation
13
+ * Uses JSON.stringify for object values for performance and reliability
14
+ */
15
+ export function serializeFunctionArguments(args) {
16
+ return args.map(function (arg) {
17
+ return serializeArgument(arg);
18
+ }).join(', ');
19
+ }
20
+
21
+ /**
22
+ * Serialize a single argument based on its type
23
+ */
24
+ function serializeArgument(arg) {
25
+ if (typeof arg === 'string') {
26
+ return arg;
27
+ }
28
+ if (typeof arg === 'number' || typeof arg === 'boolean' || arg === null) {
29
+ return String(arg);
30
+ }
31
+
32
+ // Check structured types using type guards
33
+ var arrayCheck = isArray(arg);
34
+ if (arrayCheck) {
35
+ return "[".concat(arrayCheck.items.map(function (item) {
36
+ return serializeArgument(item);
37
+ }).join(', '), "]");
38
+ }
39
+ var functionCheck = isFunction(arg);
40
+ if (functionCheck) {
41
+ var args = functionCheck.arguments.map(function (p) {
42
+ return serializeArgument(p);
43
+ }).join(', ');
44
+ return "".concat(functionCheck.name, "(").concat(args, ")");
45
+ }
46
+ var genericCheck = isGeneric(arg);
47
+ if (genericCheck) {
48
+ var generics = genericCheck.generics.map(function (g) {
49
+ return serializeArgument(g);
50
+ }).join(', ');
51
+ if (genericCheck.arguments === null) {
52
+ // Type generic like Theme<"dark" | "light">
53
+ return "".concat(genericCheck.name, "<").concat(generics, ">");
54
+ }
55
+ // Function generic like Component<Props>(args) - only add () if there are actual arguments
56
+ if (genericCheck.arguments.length > 0) {
57
+ var _args = genericCheck.arguments.map(function (p) {
58
+ return serializeArgument(p);
59
+ }).join(', ');
60
+ return "".concat(genericCheck.name, "<").concat(generics, ">(").concat(_args, ")");
61
+ }
62
+ // Generic without function call - like Component<Props>
63
+ return "".concat(genericCheck.name, "<").concat(generics, ">");
64
+ }
65
+ var arrowCheck = isArrowFunction(arg);
66
+ if (arrowCheck) {
67
+ var _args2 = arrowCheck.args.map(function (p) {
68
+ return serializeArgument(p);
69
+ }).join(', ');
70
+ var argStr = arrowCheck.args.length === 1 ? _args2 : "(".concat(_args2, ")");
71
+ if (arrowCheck.types) {
72
+ // Typed arrow function
73
+ var _arrowCheck$types = _slicedToArray(arrowCheck.types, 2),
74
+ inputTypes = _arrowCheck$types[0],
75
+ outputTypes = _arrowCheck$types[1];
76
+ var inputTypeStr = Array.isArray(inputTypes) ? inputTypes.join(', ') : inputTypes;
77
+ return "(".concat(_args2, ": ").concat(inputTypeStr, "): ").concat(outputTypes, " => ").concat(serializeArgument(arrowCheck.returnValue));
78
+ }
79
+ // Simple arrow function
80
+ return "".concat(argStr, " => ").concat(serializeArgument(arrowCheck.returnValue));
81
+ }
82
+ var typeAssertionCheck = isTypeAssertion(arg);
83
+ if (typeAssertionCheck) {
84
+ return "".concat(serializeArgument(typeAssertionCheck.expression), " as ").concat(typeAssertionCheck.type);
85
+ }
86
+ var objectCheck = isObjectLiteral(arg);
87
+ if (objectCheck) {
88
+ return serializeObject(objectCheck.properties);
89
+ }
90
+
91
+ // Array but not a structured type - serialize as array literal
92
+ if (Array.isArray(arg)) {
93
+ // Check if this is a double-wrapped array literal from parseArrayLiteral
94
+ // parseArrayLiteral calls parseArgumentsRecursive which returns an array,
95
+ // so we get [[item1, item2]] instead of [item1, item2]
96
+ var doubleWrappedCheck = isArray(arg);
97
+ if (doubleWrappedCheck) {
98
+ // This is a double-wrapped array literal - unwrap it
99
+ return "[".concat(arg[0].map(function (item) {
100
+ return serializeArgument(item);
101
+ }).join(', '), "]");
102
+ }
103
+
104
+ // Regular array
105
+ return "[".concat(arg.map(function (item) {
106
+ return serializeArgument(item);
107
+ }).join(', '), "]");
108
+ }
109
+
110
+ // Object but not a structured type - serialize as object literal
111
+ if (_typeof(arg) === 'object' && arg !== null) {
112
+ return serializeObject(arg);
113
+ }
114
+
115
+ // Fallback to string representation
116
+ return String(arg);
117
+ }
118
+
119
+ /**
120
+ * Serialize an object to JavaScript object literal syntax
121
+ */
122
+ function serializeObject(obj) {
123
+ if (Object.keys(obj).length === 0) {
124
+ return '{}';
125
+ }
126
+ var entries = Object.entries(obj).map(function (_ref) {
127
+ var _ref2 = _slicedToArray(_ref, 2),
128
+ key = _ref2[0],
129
+ value = _ref2[1];
130
+ var serializedValue = serializeObjectValue(value);
131
+
132
+ // Handle shorthand properties (key === value)
133
+ if (typeof value === 'string' && key === value) {
134
+ return key;
135
+ }
136
+ return "".concat(key, ": ").concat(serializedValue);
137
+ });
138
+ return "{ ".concat(entries.join(', '), " }");
139
+ } /**
140
+ * Serialize an object value, using JSON.stringify when appropriate
141
+ */
142
+ function serializeObjectValue(value) {
143
+ // Special case: array literals in objects are double-wrapped by the parser
144
+ // Check if this is a double-wrapped array literal: [[item1, item2, item3]]
145
+ // This MUST come before the structured type check to prevent it being treated as a structured array
146
+ if (isArray(value)) {
147
+ // This is a double-wrapped array literal - unwrap it
148
+ return "[".concat(value[0].map(function (item) {
149
+ return serializeObjectValue(item);
150
+ }).join(', '), "]");
151
+ }
152
+
153
+ // For structured types, recursively serialize first
154
+ if (_typeof(value) === 'object' && value !== null && isStructuredType(value)) {
155
+ return serializeArgument(value);
156
+ }
157
+
158
+ // For primitive values, just convert to string
159
+ if (typeof value === 'number' || typeof value === 'boolean' || value === null) {
160
+ return String(value);
161
+ }
162
+
163
+ // For strings, preserve original quotes from the parser
164
+ if (typeof value === 'string') {
165
+ // The parser preserves quotes for string literals and returns identifiers without quotes
166
+ // So we should return exactly what the parser gave us
167
+ return value;
168
+ }
169
+
170
+ // For plain objects and arrays, serialize keys/values individually
171
+ if (_typeof(value) === 'object' && value !== null && !isStructuredType(value)) {
172
+ if (Array.isArray(value)) {
173
+ // Check if this is a double-wrapped array literal
174
+ if (isArray(value)) {
175
+ // This is a double-wrapped array literal - unwrap it
176
+ return "[".concat(value[0].map(function (item) {
177
+ return serializeObjectValue(item);
178
+ }).join(', '), "]");
179
+ }
180
+ // Regular array
181
+ return "[".concat(value.map(function (item) {
182
+ return serializeObjectValue(item);
183
+ }).join(', '), "]");
184
+ }
185
+ var pairs = Object.entries(value).map(function (_ref3) {
186
+ var _ref4 = _slicedToArray(_ref3, 2),
187
+ key = _ref4[0],
188
+ val = _ref4[1];
189
+ return "".concat(key, ": ").concat(serializeObjectValue(val));
190
+ });
191
+ return "{ ".concat(pairs.join(', '), " }");
192
+ }
193
+
194
+ // Fallback
195
+ return serializeArgument(value);
196
+ }
197
+
198
+ /**
199
+ * Check if a value is one of our structured types that needs special handling
200
+ */
201
+ function isStructuredType(value) {
202
+ return !!(isArray(value) || isFunction(value) || isGeneric(value) || isArrowFunction(value) || isTypeAssertion(value));
203
+ }
@@ -0,0 +1,6 @@
1
+ import type { Externals } from "../../CodeHighlighter/types.js";
2
+ /**
3
+ * Filters out type-only imports from externals since they don't exist at runtime.
4
+ * This is essential for client-side code where type imports are stripped during compilation.
5
+ */
6
+ export declare function filterRuntimeExternals(externals: Externals): Externals;
@@ -0,0 +1,23 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ /**
3
+ * Filters out type-only imports from externals since they don't exist at runtime.
4
+ * This is essential for client-side code where type imports are stripped during compilation.
5
+ */
6
+ export function filterRuntimeExternals(externals) {
7
+ var runtimeExternals = {};
8
+ for (var _i = 0, _Object$entries = Object.entries(externals); _i < _Object$entries.length; _i++) {
9
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
10
+ modulePath = _Object$entries$_i[0],
11
+ imports = _Object$entries$_i[1];
12
+ // Filter out imports where isType is true
13
+ var runtimeImports = imports.filter(function (importItem) {
14
+ return !importItem.isType;
15
+ });
16
+
17
+ // Only include the module if it has runtime imports
18
+ if (runtimeImports.length > 0) {
19
+ runtimeExternals[modulePath] = runtimeImports;
20
+ }
21
+ }
22
+ return runtimeExternals;
23
+ }
@@ -0,0 +1,6 @@
1
+ import type { Externals } from "../../CodeHighlighter/types.js";
2
+ /**
3
+ * Generates import statements from externals without creating a provider
4
+ * Returns just the import lines needed to bring in the dependencies
5
+ */
6
+ export declare function generateImportStatements(externals: Externals): string[];
@@ -0,0 +1,148 @@
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
+ * Generates import statements from externals without creating a provider
48
+ * Returns just the import lines needed to bring in the dependencies
49
+ */
50
+ export function generateImportStatements(externals) {
51
+ var moduleImports = {};
52
+ var usedNames = new Set();
53
+ var seenImports = new Set();
54
+
55
+ // First pass: collect all imports and resolve naming conflicts
56
+ for (var _i = 0, _Object$entries = Object.entries(externals); _i < _Object$entries.length; _i++) {
57
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
58
+ modulePath = _Object$entries$_i[0],
59
+ importItems = _Object$entries$_i[1];
60
+ if (!moduleImports[modulePath]) {
61
+ moduleImports[modulePath] = {
62
+ named: [],
63
+ namespace: []
64
+ };
65
+ }
66
+ var _iterator = _createForOfIteratorHelper(importItems),
67
+ _step;
68
+ try {
69
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
70
+ var _step$value = _step.value,
71
+ originalName = _step$value.name,
72
+ type = _step$value.type,
73
+ isType = _step$value.isType;
74
+ // Skip type-only imports and empty names
75
+ if (isType || !originalName.trim()) {
76
+ continue;
77
+ }
78
+ var importKey = "".concat(modulePath, ":").concat(originalName, ":").concat(type);
79
+
80
+ // Skip duplicates
81
+ if (seenImports.has(importKey)) {
82
+ continue;
83
+ }
84
+ seenImports.add(importKey);
85
+ var uniqueName = generateUniqueImportName(originalName, modulePath, type, usedNames);
86
+ usedNames.add(uniqueName);
87
+ if (type === 'default') {
88
+ moduleImports[modulePath]["default"] = uniqueName;
89
+ } else if (type === 'named') {
90
+ moduleImports[modulePath].named.push({
91
+ original: originalName,
92
+ unique: uniqueName
93
+ });
94
+ } else if (type === 'namespace') {
95
+ moduleImports[modulePath].namespace.push(uniqueName);
96
+ }
97
+ }
98
+ } catch (err) {
99
+ _iterator.e(err);
100
+ } finally {
101
+ _iterator.f();
102
+ }
103
+ }
104
+
105
+ // Second pass: generate consolidated import statements
106
+ var imports = [];
107
+ for (var _i2 = 0, _Object$entries2 = Object.entries(moduleImports); _i2 < _Object$entries2.length; _i2++) {
108
+ var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
109
+ _modulePath = _Object$entries2$_i[0],
110
+ moduleImport = _Object$entries2$_i[1];
111
+ var importParts = [];
112
+
113
+ // Add default import
114
+ if (moduleImport["default"]) {
115
+ importParts.push(moduleImport["default"]);
116
+ }
117
+
118
+ // Add named imports (consolidated into one statement)
119
+ if (moduleImport.named.length > 0) {
120
+ var namedImports = moduleImport.named.map(function (_ref) {
121
+ var original = _ref.original,
122
+ unique = _ref.unique;
123
+ return original === unique ? original : "".concat(original, " as ").concat(unique);
124
+ }).join(', ');
125
+ importParts.push("{ ".concat(namedImports, " }"));
126
+ }
127
+
128
+ // Generate import statement
129
+ if (importParts.length > 0) {
130
+ imports.push("import ".concat(importParts.join(', '), " from '").concat(_modulePath, "';"));
131
+ }
132
+
133
+ // Add namespace imports (separate statements as they can't be combined)
134
+ var _iterator2 = _createForOfIteratorHelper(moduleImport.namespace),
135
+ _step2;
136
+ try {
137
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
138
+ var namespaceName = _step2.value;
139
+ imports.push("import * as ".concat(namespaceName, " from '").concat(_modulePath, "';"));
140
+ }
141
+ } catch (err) {
142
+ _iterator2.e(err);
143
+ } finally {
144
+ _iterator2.f();
145
+ }
146
+ }
147
+ return imports;
148
+ }
@@ -0,0 +1,9 @@
1
+ import type { Externals } from "../../CodeHighlighter/types.js";
2
+ /**
3
+ * Generates both import statements and resolved externals object
4
+ * Returns the import statements and the externals as a JavaScript object
5
+ */
6
+ export declare function generateResolvedExternals(externals: Externals): {
7
+ imports: string[];
8
+ resolvedExternals: Record<string, string>;
9
+ };