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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +3 -11
  3. package/esm/CodeControllerContext/CodeControllerContext.d.ts +62 -0
  4. package/esm/CodeControllerContext/CodeControllerContext.js +33 -0
  5. package/esm/CodeControllerContext/index.d.ts +1 -0
  6. package/esm/CodeControllerContext/index.js +1 -0
  7. package/esm/CodeExternalsContext/CodeExternalsContext.d.ts +8 -0
  8. package/esm/CodeExternalsContext/CodeExternalsContext.js +8 -0
  9. package/esm/CodeExternalsContext/index.d.ts +1 -0
  10. package/esm/CodeExternalsContext/index.js +1 -0
  11. package/esm/CodeHighlighter/CodeHighlighter.d.ts +2 -0
  12. package/esm/CodeHighlighter/CodeHighlighter.js +441 -0
  13. package/esm/CodeHighlighter/CodeHighlighterClient.d.ts +2 -0
  14. package/esm/CodeHighlighter/CodeHighlighterClient.js +984 -0
  15. package/esm/CodeHighlighter/CodeHighlighterContext.d.ts +16 -0
  16. package/esm/CodeHighlighter/CodeHighlighterContext.js +15 -0
  17. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.d.ts +7 -0
  18. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +14 -0
  19. package/esm/CodeHighlighter/addPathsToVariant.d.ts +14 -0
  20. package/esm/CodeHighlighter/addPathsToVariant.js +68 -0
  21. package/esm/CodeHighlighter/applyTransform.d.ts +19 -0
  22. package/esm/CodeHighlighter/applyTransform.js +75 -0
  23. package/esm/CodeHighlighter/calculateMainFilePath.d.ts +1 -0
  24. package/esm/CodeHighlighter/calculateMainFilePath.js +108 -0
  25. package/esm/CodeHighlighter/codeToFallbackProps.d.ts +2 -0
  26. package/esm/CodeHighlighter/codeToFallbackProps.js +73 -0
  27. package/esm/CodeHighlighter/errors.d.ts +141 -0
  28. package/esm/CodeHighlighter/errors.js +441 -0
  29. package/esm/CodeHighlighter/examineVariant.d.ts +25 -0
  30. package/esm/CodeHighlighter/examineVariant.js +73 -0
  31. package/esm/CodeHighlighter/hasAllVariants.d.ts +27 -0
  32. package/esm/CodeHighlighter/hasAllVariants.js +63 -0
  33. package/esm/CodeHighlighter/index.d.ts +1 -0
  34. package/esm/CodeHighlighter/index.js +1 -0
  35. package/esm/CodeHighlighter/loadFallbackCode.d.ts +10 -0
  36. package/esm/CodeHighlighter/loadFallbackCode.js +679 -0
  37. package/esm/CodeHighlighter/loadVariant.d.ts +12 -0
  38. package/esm/CodeHighlighter/loadVariant.js +1044 -0
  39. package/esm/CodeHighlighter/maybeInitialData.d.ts +108 -0
  40. package/esm/CodeHighlighter/maybeInitialData.js +192 -0
  41. package/esm/CodeHighlighter/mergeMetadata.d.ts +40 -0
  42. package/esm/CodeHighlighter/mergeMetadata.js +165 -0
  43. package/esm/CodeHighlighter/parseCode.d.ts +6 -0
  44. package/esm/CodeHighlighter/parseCode.js +134 -0
  45. package/esm/CodeHighlighter/parseControlledCode.d.ts +6 -0
  46. package/esm/CodeHighlighter/parseControlledCode.js +87 -0
  47. package/esm/CodeHighlighter/pathUtils.d.ts +120 -0
  48. package/esm/CodeHighlighter/pathUtils.js +258 -0
  49. package/esm/CodeHighlighter/transformCode.d.ts +21 -0
  50. package/esm/CodeHighlighter/transformCode.js +251 -0
  51. package/esm/CodeHighlighter/transformParsedSource.d.ts +3 -0
  52. package/esm/CodeHighlighter/transformParsedSource.js +60 -0
  53. package/esm/CodeHighlighter/transformSource.d.ts +2 -0
  54. package/esm/CodeHighlighter/transformSource.js +103 -0
  55. package/esm/CodeHighlighter/types.d.ts +276 -0
  56. package/esm/CodeHighlighter/types.js +1 -0
  57. package/esm/CodeProvider/CodeContext.d.ts +31 -0
  58. package/esm/CodeProvider/CodeContext.js +12 -0
  59. package/esm/CodeProvider/CodeProvider.d.ts +13 -0
  60. package/esm/CodeProvider/CodeProvider.js +83 -0
  61. package/esm/CodeProvider/index.d.ts +1 -0
  62. package/esm/CodeProvider/index.js +1 -0
  63. package/esm/abstractCreateDemo/abstractCreateDemo.d.ts +45 -0
  64. package/esm/abstractCreateDemo/abstractCreateDemo.js +100 -0
  65. package/esm/abstractCreateDemo/index.d.ts +1 -0
  66. package/esm/abstractCreateDemo/index.js +1 -0
  67. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.d.ts +32 -0
  68. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +52 -0
  69. package/esm/abstractCreateDemoClient/index.d.ts +1 -0
  70. package/esm/abstractCreateDemoClient/index.js +1 -0
  71. package/esm/createDemoData/createDemoData.d.ts +44 -0
  72. package/esm/createDemoData/createDemoData.js +74 -0
  73. package/esm/createDemoData/index.d.ts +1 -0
  74. package/esm/createDemoData/index.js +1 -0
  75. package/esm/createDemoData/types.d.ts +25 -0
  76. package/esm/createDemoData/types.js +1 -0
  77. package/esm/pipeline/hastUtils/hastUtils.d.ts +11 -0
  78. package/esm/pipeline/hastUtils/hastUtils.js +67 -0
  79. package/esm/pipeline/hastUtils/index.d.ts +1 -0
  80. package/esm/pipeline/hastUtils/index.js +1 -0
  81. package/esm/pipeline/loadPrecomputedCodeHighlighter/index.d.ts +2 -0
  82. package/esm/pipeline/loadPrecomputedCodeHighlighter/index.js +4 -0
  83. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +14 -0
  84. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +178 -0
  85. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +47 -0
  86. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +849 -0
  87. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.d.ts +85 -0
  88. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +715 -0
  89. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts +14 -0
  90. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +73 -0
  91. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.d.ts +11 -0
  92. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +203 -0
  93. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.d.ts +6 -0
  94. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +23 -0
  95. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.d.ts +6 -0
  96. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +148 -0
  97. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.d.ts +9 -0
  98. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +198 -0
  99. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.d.ts +2 -0
  100. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.js +4 -0
  101. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.d.ts +5 -0
  102. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +21 -0
  103. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.d.ts +15 -0
  104. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +233 -0
  105. package/esm/pipeline/loadServerCodeMeta/index.d.ts +1 -0
  106. package/esm/pipeline/loadServerCodeMeta/index.js +1 -0
  107. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts +24 -0
  108. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +90 -0
  109. package/esm/pipeline/loadServerSource/index.d.ts +1 -0
  110. package/esm/pipeline/loadServerSource/index.js +1 -0
  111. package/esm/pipeline/loadServerSource/loadServerSource.d.ts +25 -0
  112. package/esm/pipeline/loadServerSource/loadServerSource.js +134 -0
  113. package/esm/pipeline/loaderUtils/externalsToPackages.d.ts +1 -0
  114. package/esm/pipeline/loaderUtils/externalsToPackages.js +46 -0
  115. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.d.ts +34 -0
  116. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +161 -0
  117. package/esm/pipeline/loaderUtils/getFileNameFromUrl.d.ts +12 -0
  118. package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +66 -0
  119. package/esm/pipeline/loaderUtils/index.d.ts +7 -0
  120. package/esm/pipeline/loaderUtils/index.js +7 -0
  121. package/esm/pipeline/loaderUtils/mergeExternals.d.ts +32 -0
  122. package/esm/pipeline/loaderUtils/mergeExternals.js +72 -0
  123. package/esm/pipeline/loaderUtils/parseImports.d.ts +19 -0
  124. package/esm/pipeline/loaderUtils/parseImports.js +306 -0
  125. package/esm/pipeline/loaderUtils/processRelativeImports.d.ts +19 -0
  126. package/esm/pipeline/loaderUtils/processRelativeImports.js +352 -0
  127. package/esm/pipeline/loaderUtils/resolveModulePath.d.ts +87 -0
  128. package/esm/pipeline/loaderUtils/resolveModulePath.js +1435 -0
  129. package/esm/pipeline/loaderUtils/resolveModulePathWithFs.d.ts +47 -0
  130. package/esm/pipeline/loaderUtils/resolveModulePathWithFs.js +150 -0
  131. package/esm/pipeline/loaderUtils/rewriteImports.d.ts +9 -0
  132. package/esm/pipeline/loaderUtils/rewriteImports.js +35 -0
  133. package/esm/pipeline/parseSource/addLineGutters.d.ts +9 -0
  134. package/esm/pipeline/parseSource/addLineGutters.js +181 -0
  135. package/esm/pipeline/parseSource/grammars.d.ts +2 -0
  136. package/esm/pipeline/parseSource/grammars.js +27 -0
  137. package/esm/pipeline/parseSource/index.d.ts +1 -0
  138. package/esm/pipeline/parseSource/index.js +1 -0
  139. package/esm/pipeline/parseSource/parseSource.d.ts +3 -0
  140. package/esm/pipeline/parseSource/parseSource.js +51 -0
  141. package/esm/pipeline/transformHtmlCode/index.d.ts +2 -0
  142. package/esm/pipeline/transformHtmlCode/index.js +4 -0
  143. package/esm/pipeline/transformHtmlCode/transformHtmlCode.d.ts +13 -0
  144. package/esm/pipeline/transformHtmlCode/transformHtmlCode.js +300 -0
  145. package/esm/pipeline/transformMarkdownCode/index.d.ts +2 -0
  146. package/esm/pipeline/transformMarkdownCode/index.js +4 -0
  147. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.d.ts +2 -0
  148. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +514 -0
  149. package/esm/pipeline/transformTypescriptToJavascript/index.d.ts +1 -0
  150. package/esm/pipeline/transformTypescriptToJavascript/index.js +1 -0
  151. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.d.ts +13 -0
  152. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +131 -0
  153. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.d.ts +3 -0
  154. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +31 -0
  155. package/esm/useCode/Pre.d.ts +15 -0
  156. package/esm/useCode/Pre.js +164 -0
  157. package/esm/useCode/index.d.ts +1 -0
  158. package/esm/useCode/index.js +1 -0
  159. package/esm/useCode/useCode.d.ts +41 -0
  160. package/esm/useCode/useCode.js +128 -0
  161. package/esm/useCode/useCodeUtils.d.ts +44 -0
  162. package/esm/useCode/useCodeUtils.js +245 -0
  163. package/esm/useCode/useCopyFunctionality.d.ts +18 -0
  164. package/esm/useCode/useCopyFunctionality.js +28 -0
  165. package/esm/useCode/useFileNavigation.d.ts +41 -0
  166. package/esm/useCode/useFileNavigation.js +453 -0
  167. package/esm/useCode/useSourceEditing.d.ts +21 -0
  168. package/esm/useCode/useSourceEditing.js +32 -0
  169. package/esm/useCode/useTransformManagement.d.ts +30 -0
  170. package/esm/useCode/useTransformManagement.js +72 -0
  171. package/esm/useCode/useUIState.d.ts +16 -0
  172. package/esm/useCode/useUIState.js +21 -0
  173. package/esm/useCode/useVariantSelection.d.ts +23 -0
  174. package/esm/useCode/useVariantSelection.js +75 -0
  175. package/esm/useCopier/index.d.ts +1 -1
  176. package/esm/useCopier/index.js +5 -5
  177. package/esm/useDemo/createCodeSandbox.d.ts +15 -0
  178. package/esm/useDemo/createCodeSandbox.js +42 -0
  179. package/esm/useDemo/createStackBlitz.d.ts +22 -0
  180. package/esm/useDemo/createStackBlitz.js +38 -0
  181. package/esm/useDemo/exportVariant.d.ts +184 -0
  182. package/esm/useDemo/exportVariant.js +422 -0
  183. package/esm/useDemo/exportVariantAsCra.d.ts +15 -0
  184. package/esm/useDemo/exportVariantAsCra.js +57 -0
  185. package/esm/useDemo/flattenVariant.d.ts +19 -0
  186. package/esm/useDemo/flattenVariant.js +49 -0
  187. package/esm/useDemo/index.d.ts +6 -51
  188. package/esm/useDemo/index.js +6 -104
  189. package/esm/useDemo/useDemo.d.ts +81 -0
  190. package/esm/useDemo/useDemo.js +193 -0
  191. package/esm/useErrors/ErrorsContext.d.ts +6 -0
  192. package/esm/useErrors/ErrorsContext.js +8 -0
  193. package/esm/useErrors/index.d.ts +1 -0
  194. package/esm/useErrors/index.js +1 -0
  195. package/esm/useErrors/useErrors.d.ts +5 -0
  196. package/esm/useErrors/useErrors.js +7 -0
  197. package/esm/useLocalStorageState/index.d.ts +2 -0
  198. package/esm/useLocalStorageState/index.js +2 -0
  199. package/esm/useLocalStorageState/useLocalStorageState.d.ts +14 -0
  200. package/esm/useLocalStorageState/useLocalStorageState.js +128 -0
  201. package/esm/usePreference/PreferencesProvider.d.ts +6 -0
  202. package/esm/usePreference/PreferencesProvider.js +8 -0
  203. package/esm/usePreference/index.d.ts +2 -0
  204. package/esm/usePreference/index.js +2 -0
  205. package/esm/usePreference/usePreference.d.ts +2 -0
  206. package/esm/usePreference/usePreference.js +25 -0
  207. package/esm/useUrlHashState/index.d.ts +1 -0
  208. package/esm/useUrlHashState/index.js +1 -0
  209. package/esm/useUrlHashState/useUrlHashState.d.ts +5 -0
  210. package/esm/useUrlHashState/useUrlHashState.js +68 -0
  211. package/esm/withDocsInfra/index.d.ts +1 -0
  212. package/esm/withDocsInfra/index.js +1 -0
  213. package/esm/withDocsInfra/withDocsInfra.d.ts +82 -0
  214. package/esm/withDocsInfra/withDocsInfra.js +147 -0
  215. package/package.json +178 -11
  216. package/esm/useCopier/index.d.ts.map +0 -1
  217. package/esm/useDemo/index.d.ts.map +0 -1
@@ -0,0 +1,422 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ /**
4
+ * Export variant functionality to add extra files like package.json, tsconfig, etc.
5
+ * Users can pass configuration options that vary the output here.
6
+ */
7
+
8
+ import { externalsToPackages } from "../pipeline/loaderUtils/index.js";
9
+ import { getFileNameFromUrl } from "../pipeline/loaderUtils/getFileNameFromUrl.js";
10
+ import { createPathContext } from "../CodeHighlighter/examineVariant.js";
11
+ import { mergeMetadata, extractMetadata } from "../CodeHighlighter/mergeMetadata.js";
12
+
13
+ /**
14
+ * Merges multiple file objects into a single object.
15
+ * Similar to mergeExternals but for file structures.
16
+ * Automatically adds metadata: false to files that don't have a metadata property.
17
+ */
18
+ function mergeFiles() {
19
+ var merged = {};
20
+ for (var _len = arguments.length, fileSets = new Array(_len), _key = 0; _key < _len; _key++) {
21
+ fileSets[_key] = arguments[_key];
22
+ }
23
+ for (var _i = 0, _fileSets = fileSets; _i < _fileSets.length; _i++) {
24
+ var fileSet = _fileSets[_i];
25
+ for (var _i2 = 0, _Object$entries = Object.entries(fileSet); _i2 < _Object$entries.length; _i2++) {
26
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
27
+ fileName = _Object$entries$_i[0],
28
+ fileData = _Object$entries$_i[1];
29
+ // Later files override earlier ones (similar to Object.assign behavior)
30
+ var normalizedData = typeof fileData === 'string' ? {
31
+ source: fileData
32
+ } : _extends({}, fileData);
33
+ // Add metadata: false if not already set (source files default to false)
34
+ if (!('metadata' in normalizedData)) {
35
+ normalizedData.metadata = false;
36
+ }
37
+ merged[fileName] = normalizedData;
38
+ }
39
+ }
40
+ return merged;
41
+ }
42
+
43
+ /**
44
+ * Extract filename from URL or return undefined if not available
45
+ */
46
+ export function getFilenameFromVariant(variantCode) {
47
+ if (variantCode.fileName) {
48
+ return variantCode.fileName;
49
+ }
50
+ if (variantCode.url) {
51
+ var _getFileNameFromUrl = getFileNameFromUrl(variantCode.url),
52
+ fileName = _getFileNameFromUrl.fileName;
53
+ return fileName || undefined;
54
+ }
55
+ return undefined;
56
+ }
57
+
58
+ /**
59
+ * Generate a unique entrypoint filename that doesn't conflict with existing files
60
+ */
61
+ export function generateEntrypointFilename(existingFiles, sourceFilename, useTypescript) {
62
+ var pathPrefix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
63
+ var ext = useTypescript ? 'tsx' : 'jsx';
64
+ var candidates = ["".concat(pathPrefix, "App.").concat(ext), "".concat(pathPrefix, "entrypoint.").concat(ext), "".concat(pathPrefix, "main.").concat(ext)];
65
+
66
+ // If we have a source filename, also try variations
67
+ if (sourceFilename) {
68
+ var baseName = sourceFilename.replace(/\.[^.]*$/, '');
69
+ candidates.push("".concat(pathPrefix).concat(baseName, "-entry.").concat(ext));
70
+ }
71
+ for (var _i3 = 0, _candidates = candidates; _i3 < _candidates.length; _i3++) {
72
+ var candidate = _candidates[_i3];
73
+ if (candidate !== "".concat(pathPrefix).concat(sourceFilename) && !existingFiles[candidate]) {
74
+ return candidate;
75
+ }
76
+ }
77
+
78
+ // Generate with hash if all candidates are taken
79
+ var hash = Math.random().toString(36).substring(2, 8);
80
+ return "".concat(pathPrefix, "entrypoint-").concat(hash, ".").concat(ext);
81
+ }
82
+
83
+ /**
84
+ * Generate the relative import path from entrypoint to source file
85
+ */
86
+ export function getRelativeImportPath(sourceFilename) {
87
+ if (!sourceFilename) {
88
+ return './App'; // Default fallback
89
+ }
90
+
91
+ // Remove extension for import
92
+ var baseName = sourceFilename.replace(/\.[^.]*$/, '');
93
+ return "./".concat(baseName);
94
+ }
95
+
96
+ /**
97
+ * Default HTML template function for Vite-based demos
98
+ */
99
+ export function defaultHtmlTemplate(_ref) {
100
+ var language = _ref.language,
101
+ title = _ref.title,
102
+ description = _ref.description,
103
+ head = _ref.head,
104
+ entrypoint = _ref.entrypoint;
105
+ return "<!DOCTYPE html>\n<html lang=\"".concat(language, "\">\n <head>\n <meta charset=\"utf-8\" />\n <title>").concat(title, "</title>\n ").concat(description ? "<meta name=\"description\" content=\"".concat(description, "\" />") : '', "\n <meta name=\"viewport\" content=\"initial-scale=1, width=device-width\" />").concat(head ? "\n ".concat(head.split('\n').join('\n ')) : '', "\n </head>\n <body>\n <div id=\"root\"></div>").concat(entrypoint ? "\n <script type=\"module\" src=\"".concat(entrypoint, "\"></script>") : '', "\n </body>\n</html>\n");
106
+ }
107
+ /**
108
+ * Export a variant as a standalone project with metadata files properly scoped
109
+ */
110
+ export function exportVariant(variantCode) {
111
+ var _frameworkFiles$varia;
112
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
113
+ var _config$title = config.title,
114
+ title = _config$title === void 0 ? 'Demo' : _config$title,
115
+ titlePrefix = config.titlePrefix,
116
+ titleSuffix = config.titleSuffix,
117
+ _config$description = config.description,
118
+ description = _config$description === void 0 ? 'Demo created with Vite' : _config$description,
119
+ descriptionPrefix = config.descriptionPrefix,
120
+ descriptionSuffix = config.descriptionSuffix,
121
+ variantName = config.variantName,
122
+ _config$language = config.language,
123
+ language = _config$language === void 0 ? 'en' : _config$language,
124
+ _config$htmlPrefix = config.htmlPrefix,
125
+ htmlPrefix = _config$htmlPrefix === void 0 ? '' : _config$htmlPrefix,
126
+ _config$sourcePrefix = config.sourcePrefix,
127
+ sourcePrefix = _config$sourcePrefix === void 0 ? 'src/' : _config$sourcePrefix,
128
+ _config$assetPrefix = config.assetPrefix,
129
+ assetPrefix = _config$assetPrefix === void 0 ? '' : _config$assetPrefix,
130
+ _config$frameworkHand = config.frameworkHandlesEntrypoint,
131
+ frameworkHandlesEntrypoint = _config$frameworkHand === void 0 ? false : _config$frameworkHand,
132
+ _config$htmlSkipJsLin = config.htmlSkipJsLink,
133
+ htmlSkipJsLink = _config$htmlSkipJsLin === void 0 ? false : _config$htmlSkipJsLin,
134
+ htmlTemplate = config.htmlTemplate,
135
+ headTemplate = config.headTemplate,
136
+ rootIndexTemplate = config.rootIndexTemplate,
137
+ _config$dependencies = config.dependencies,
138
+ dependencies = _config$dependencies === void 0 ? {} : _config$dependencies,
139
+ _config$devDependenci = config.devDependencies,
140
+ devDependencies = _config$devDependenci === void 0 ? {} : _config$devDependenci,
141
+ _config$scripts = config.scripts,
142
+ scripts = _config$scripts === void 0 ? {} : _config$scripts,
143
+ packageType = config.packageType,
144
+ _config$packageJsonFi = config.packageJsonFields,
145
+ packageJsonFields = _config$packageJsonFi === void 0 ? {} : _config$packageJsonFi,
146
+ _config$tsconfigOptio = config.tsconfigOptions,
147
+ tsconfigOptions = _config$tsconfigOptio === void 0 ? {} : _config$tsconfigOptio,
148
+ _config$viteConfig = config.viteConfig,
149
+ viteConfig = _config$viteConfig === void 0 ? {} : _config$viteConfig,
150
+ _config$useTypescript = config.useTypescript,
151
+ useTypescript = _config$useTypescript === void 0 ? false : _config$useTypescript,
152
+ _config$extraMetadata = config.extraMetadataFiles,
153
+ extraMetadataFiles = _config$extraMetadata === void 0 ? {} : _config$extraMetadata,
154
+ _config$frameworkFile = config.frameworkFiles,
155
+ frameworkFiles = _config$frameworkFile === void 0 ? {} : _config$frameworkFile,
156
+ transformVariant = config.transformVariant,
157
+ _config$versions = config.versions,
158
+ versions = _config$versions === void 0 ? {} : _config$versions,
159
+ resolveDependencies = config.resolveDependencies;
160
+
161
+ // Build final title and description with prefixes and suffixes
162
+ var finalTitle = [titlePrefix, title, titleSuffix].filter(Boolean).join('');
163
+ var finalDescription = [descriptionPrefix, description, descriptionSuffix].filter(Boolean).join('');
164
+
165
+ // Use extractMetadata to properly separate metadata and non-metadata files
166
+ var _extractMetadata = extractMetadata(variantCode),
167
+ processedVariantCode = _extractMetadata.variant,
168
+ processedGlobals = _extractMetadata.metadata;
169
+ if (transformVariant) {
170
+ var transformed = transformVariant(processedVariantCode, variantName, processedGlobals);
171
+ if (transformed) {
172
+ // Re-extract metadata after transformation
173
+ var result = transformed.variant && extractMetadata(transformed.variant);
174
+ processedVariantCode = (result == null ? void 0 : result.variant) || processedVariantCode;
175
+
176
+ // Start fresh with only the new metadata and explicitly transformed globals
177
+ // Do NOT merge with the original processedGlobals to avoid duplication
178
+ processedGlobals = _extends(_extends({}, result == null ? void 0 : result.metadata), transformed.globals);
179
+ }
180
+ }
181
+
182
+ // If packageType is explicitly provided (even as undefined), use that value
183
+ var finalPackageType;
184
+ if ('packageType' in config) {
185
+ finalPackageType = packageType;
186
+ } else {
187
+ finalPackageType = !Object.keys(frameworkFiles).length ? 'module' : undefined;
188
+ }
189
+
190
+ // Get existing extraFiles and source filename
191
+ var sourceFilename = getFilenameFromVariant(processedVariantCode);
192
+
193
+ // Get path context to understand navigation
194
+ var pathContext = createPathContext(variantCode);
195
+
196
+ // Determine if we need to rename the source file
197
+ var ext = useTypescript ? 'tsx' : 'jsx';
198
+ var isSourceFileIndex = sourceFilename === "index.".concat(ext);
199
+ var hasBackNavigation = pathContext.maxSourceBackNavigation > 0;
200
+ var actualSourceFilename = sourceFilename;
201
+
202
+ // Use urlDirectory to construct the full path from src root
203
+ var directoryPath = pathContext.urlDirectory.slice(1).join('/'); // Remove 'src' and join the rest
204
+ var actualRootFile = directoryPath ? "".concat(sourcePrefix).concat(directoryPath, "/").concat(sourceFilename) : "".concat(sourcePrefix).concat(sourceFilename);
205
+
206
+ // If the source file is index.tsx and it's in the src root, we need to rename it
207
+ if (isSourceFileIndex && !hasBackNavigation) {
208
+ actualSourceFilename = generateEntrypointFilename(processedVariantCode.extraFiles || {}, sourceFilename, useTypescript);
209
+ // When renaming due to conflicts, place the file in src root regardless of original location
210
+ actualRootFile = "".concat(sourcePrefix).concat(actualSourceFilename);
211
+ }
212
+
213
+ // The main entrypoint is always src/index.tsx (or .jsx)
214
+ var mainEntrypointFilename = "index.".concat(ext);
215
+ var entrypoint = !htmlSkipJsLink ? "".concat(sourcePrefix).concat(mainEntrypointFilename) : undefined;
216
+
217
+ // Get relative import path for the main component
218
+ var importPath;
219
+ if (!hasBackNavigation) {
220
+ // Component is in src root - import directly
221
+ importPath = getRelativeImportPath(actualSourceFilename);
222
+ } else {
223
+ // Component is in a subdirectory - import with full path from src root
224
+ var componentPath = directoryPath ? "".concat(directoryPath, "/").concat(actualSourceFilename) : actualSourceFilename;
225
+ importPath = "./".concat((componentPath || '').replace(/\.[^.]*$/, '')); // Remove extension
226
+ }
227
+
228
+ // Strip /index from the end of import paths since module resolution handles it automatically
229
+ if (importPath.endsWith('/index')) {
230
+ importPath = importPath.slice(0, -6); // Remove '/index'
231
+ }
232
+ var importString = processedVariantCode.namedExport ? "import { ".concat(processedVariantCode.namedExport, " as App } from '").concat(importPath, "';") : "import App from '".concat(importPath, "';");
233
+
234
+ // Collect all files that will be generated
235
+ var generatedFiles = {};
236
+
237
+ // Update the variant's fileName if we renamed it
238
+ if (isSourceFileIndex && !hasBackNavigation && actualSourceFilename && actualSourceFilename !== sourceFilename) {
239
+ processedVariantCode.fileName = actualSourceFilename;
240
+ }
241
+
242
+ // Check if they're providing their own framework
243
+ var isFramework = 'frameworkFiles' in config;
244
+ var externalPackages = externalsToPackages(processedVariantCode.externals || []);
245
+ var variantDeps = Object.keys(externalPackages).reduce(function (acc, pkg) {
246
+ // Check if we have a specific version for this package first
247
+ if (versions[pkg]) {
248
+ acc[pkg] = versions[pkg];
249
+ } else if (resolveDependencies) {
250
+ var resolvedDeps = resolveDependencies(pkg);
251
+ Object.assign(acc, resolvedDeps);
252
+ } else {
253
+ // Simple fallback: just use 'latest' for each package
254
+ acc[pkg] = 'latest';
255
+ }
256
+ return acc;
257
+ }, {});
258
+
259
+ // Collect metadata files to be generated
260
+ var metadataFiles = {};
261
+
262
+ // Generate package.json
263
+ var packageJson = _extends(_extends({
264
+ "private": true,
265
+ name: finalTitle.toLowerCase().replace(/[^a-z0-9]/g, '-'),
266
+ version: '0.0.0',
267
+ description: finalDescription
268
+ }, finalPackageType && {
269
+ type: finalPackageType
270
+ }), {}, {
271
+ // Add type if specified
272
+ scripts: _extends(_extends({}, !isFramework && {
273
+ dev: 'vite',
274
+ build: 'vite build',
275
+ preview: 'vite preview'
276
+ }), scripts),
277
+ dependencies: _extends(_extends({
278
+ react: versions.react || 'latest',
279
+ 'react-dom': versions['react-dom'] || 'latest'
280
+ }, variantDeps), dependencies),
281
+ devDependencies: _extends(_extends(_extends({}, !isFramework && {
282
+ '@vitejs/plugin-react': 'latest',
283
+ vite: 'latest'
284
+ }), useTypescript && {
285
+ typescript: 'latest',
286
+ '@types/react': versions['@types/react'] || 'latest',
287
+ '@types/react-dom': versions['@types/react-dom'] || 'latest'
288
+ }), devDependencies)
289
+ }, packageJsonFields);
290
+ metadataFiles['package.json'] = {
291
+ source: "".concat(JSON.stringify(packageJson, null, 2), "\n")
292
+ };
293
+
294
+ // Generate entrypoint and HTML files unless framework handles them
295
+ if (!frameworkHandlesEntrypoint) {
296
+ // Create entrypoint file that imports the main component
297
+ var defaultEntrypointContent = "import * as React from 'react';\nimport * as ReactDOM from 'react-dom/client';\n".concat(importString, "\n\nReactDOM.createRoot(document.getElementById('root')").concat(useTypescript ? '!' : '', ").render(\n <React.StrictMode>\n <App />\n </React.StrictMode>\n);\n");
298
+ var entrypointContent = rootIndexTemplate ? rootIndexTemplate({
299
+ importString: importString,
300
+ useTypescript: useTypescript
301
+ }) : defaultEntrypointContent;
302
+ generatedFiles[mainEntrypointFilename] = {
303
+ source: entrypointContent
304
+ };
305
+ }
306
+
307
+ // Add Vite config file only if no framework files (Vite-specific)
308
+ if (!isFramework) {
309
+ var viteConfigContent = "import { defineConfig } from 'vite';\nimport react from '@vitejs/plugin-react';\n\n// https://vitejs.dev/config/\nexport default defineConfig({\n plugins: [react()],\n define: { 'process.env': {} },\n ...".concat(JSON.stringify(viteConfig, null, 2).split('\n').join('\n '), "\n});\n");
310
+ metadataFiles["vite.config.".concat(useTypescript ? 'ts' : 'js')] = {
311
+ source: viteConfigContent
312
+ };
313
+ }
314
+
315
+ // Add TypeScript configuration if requested
316
+ if (useTypescript) {
317
+ // Check if frameworkFiles already includes a tsconfig
318
+ var hasFrameworkTsConfig = (frameworkFiles == null ? void 0 : frameworkFiles.globals) && Object.keys(frameworkFiles.globals).some(function (fileName) {
319
+ return fileName.includes('tsconfig.json') && !fileName.includes('tsconfig.node.json');
320
+ });
321
+ if (!hasFrameworkTsConfig) {
322
+ // Main tsconfig.json (default Vite config)
323
+ var defaultTsConfig = _extends({
324
+ compilerOptions: _extends({
325
+ target: 'ES2020',
326
+ useDefineForClassFields: true,
327
+ lib: ['ES2020', 'DOM', 'DOM.Iterable'],
328
+ module: 'ESNext',
329
+ skipLibCheck: true,
330
+ moduleResolution: 'bundler',
331
+ allowImportingTsExtensions: true,
332
+ resolveJsonModule: true,
333
+ isolatedModules: true,
334
+ noEmit: true,
335
+ jsx: 'react-jsx',
336
+ strict: true,
337
+ noUnusedLocals: true,
338
+ noUnusedParameters: true,
339
+ noFallthroughCasesInSwitch: true
340
+ }, tsconfigOptions),
341
+ include: ['src']
342
+ }, !isFramework && {
343
+ references: [{
344
+ path: './tsconfig.node.json'
345
+ }]
346
+ });
347
+ metadataFiles['tsconfig.json'] = {
348
+ source: "".concat(JSON.stringify(defaultTsConfig, null, 2), "\n")
349
+ };
350
+ }
351
+
352
+ // Only add tsconfig.node.json for Vite (not for framework files)
353
+ if (!isFramework) {
354
+ // Node tsconfig for Vite config
355
+ var nodeTsConfig = {
356
+ compilerOptions: {
357
+ composite: true,
358
+ skipLibCheck: true,
359
+ module: 'ESNext',
360
+ moduleResolution: 'bundler',
361
+ allowSyntheticDefaultImports: true
362
+ },
363
+ include: ['vite.config.ts']
364
+ };
365
+ metadataFiles['tsconfig.node.json'] = {
366
+ source: "".concat(JSON.stringify(nodeTsConfig, null, 2), "\n")
367
+ };
368
+ }
369
+ }
370
+
371
+ // Generate HTML file after all files are ready
372
+ if (!frameworkHandlesEntrypoint) {
373
+ // Add index.html
374
+ var headContent = headTemplate ? headTemplate({
375
+ sourcePrefix: sourcePrefix,
376
+ assetPrefix: assetPrefix,
377
+ variant: processedVariantCode,
378
+ variantName: variantName
379
+ }) : undefined;
380
+ var htmlContent = htmlTemplate ? htmlTemplate({
381
+ language: language,
382
+ title: finalTitle,
383
+ description: finalDescription,
384
+ head: headContent,
385
+ entrypoint: entrypoint,
386
+ variant: processedVariantCode,
387
+ variantName: variantName
388
+ }) : defaultHtmlTemplate({
389
+ language: language,
390
+ title: finalTitle,
391
+ description: finalDescription,
392
+ head: headContent,
393
+ entrypoint: entrypoint
394
+ });
395
+ var htmlFileName = htmlPrefix ? "".concat(htmlPrefix, "index.html") : 'index.html';
396
+ metadataFiles[htmlFileName] = {
397
+ source: htmlContent
398
+ };
399
+ }
400
+
401
+ // Merge all metadata files including framework metadata and globals
402
+ var allMetadataFiles = mergeFiles(processedGlobals || {}, metadataFiles, extraMetadataFiles, frameworkFiles.globals || {});
403
+
404
+ // Merge all files using mergeMetadata to properly position everything with 'src/' (sourcePrefix opt) prefix
405
+ var allSourceFilesWithFramework = mergeFiles(processedVariantCode.extraFiles || {}, generatedFiles, ((_frameworkFiles$varia = frameworkFiles.variant) == null ? void 0 : _frameworkFiles$varia.extraFiles) || {});
406
+
407
+ // Update the variant with all source files including framework source files
408
+ var finalVariantWithSources = _extends(_extends({}, processedVariantCode), {}, {
409
+ extraFiles: allSourceFilesWithFramework
410
+ });
411
+
412
+ // Use mergeMetadata to position everything correctly
413
+ var finalVariant = mergeMetadata(finalVariantWithSources, allMetadataFiles, {
414
+ metadataPrefix: sourcePrefix
415
+ });
416
+
417
+ // Return new VariantCode with properly positioned files
418
+ return {
419
+ exported: finalVariant,
420
+ rootFile: actualRootFile
421
+ };
422
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Export VariantCode as Create React App template using exportVariant
3
+ * This is a general-purpose wrapper that creates CRA-compatible templates
4
+ * without library-specific dependencies
5
+ */
6
+ import type { VariantCode } from "../CodeHighlighter/types.js";
7
+ import { type ExportConfig } from "./exportVariant.js";
8
+ /**
9
+ * Export a VariantCode as a Create React App template
10
+ * Returns an object with the exported VariantCode and entrypoint path
11
+ */
12
+ export declare function exportVariantAsCra(variantCode: VariantCode, config?: Omit<ExportConfig, 'viteConfig' | 'packageType' | 'htmlSkipJsLink'>): {
13
+ exported: VariantCode;
14
+ rootFile: string;
15
+ };
@@ -0,0 +1,57 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ var _excluded = ["title", "description", "scripts", "devDependencies"];
4
+ /**
5
+ * Export VariantCode as Create React App template using exportVariant
6
+ * This is a general-purpose wrapper that creates CRA-compatible templates
7
+ * without library-specific dependencies
8
+ */
9
+
10
+ import { exportVariant } from "./exportVariant.js";
11
+
12
+ /**
13
+ * Export a VariantCode as a Create React App template
14
+ * Returns an object with the exported VariantCode and entrypoint path
15
+ */
16
+ export function exportVariantAsCra(variantCode) {
17
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
18
+ var _config$title = config.title,
19
+ title = _config$title === void 0 ? 'Demo' : _config$title,
20
+ _config$description = config.description,
21
+ description = _config$description === void 0 ? 'Demo created with Create React App' : _config$description,
22
+ _config$scripts = config.scripts,
23
+ scripts = _config$scripts === void 0 ? {} : _config$scripts,
24
+ _config$devDependenci = config.devDependencies,
25
+ devDependencies = _config$devDependenci === void 0 ? {} : _config$devDependenci,
26
+ otherConfig = _objectWithoutPropertiesLoose(config, _excluded);
27
+
28
+ // Default CRA scripts
29
+ var craScripts = _extends({
30
+ start: 'react-scripts start',
31
+ build: 'react-scripts build',
32
+ test: 'react-scripts test',
33
+ eject: 'react-scripts eject'
34
+ }, scripts);
35
+
36
+ // CRA only needs react-scripts, other deps are handled by exportVariant
37
+ var craDevDependencies = _extends({
38
+ 'react-scripts': 'latest'
39
+ }, devDependencies);
40
+
41
+ // Create export configuration for CRA
42
+ var exportConfig = _extends({
43
+ title: title,
44
+ description: description,
45
+ htmlPrefix: 'public/',
46
+ packageType: undefined,
47
+ // CRA should not have 'type: module'
48
+ htmlSkipJsLink: true,
49
+ frameworkFiles: {},
50
+ // Prevent Vite-specific files from being generated
51
+ devDependencies: craDevDependencies,
52
+ scripts: craScripts
53
+ }, otherConfig);
54
+
55
+ // Use exportVariant to generate the final result
56
+ return exportVariant(variantCode, exportConfig);
57
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Flatten variant utility to convert a VariantCode into a flat files list
3
+ * Handles relative path resolution and metadata file scoping
4
+ * Uses addPathsToVariant for the core logic, then flattens the result
5
+ */
6
+ import type { VariantCode } from "../CodeHighlighter/types.js";
7
+ export interface FlatFile {
8
+ source: string;
9
+ metadata?: boolean;
10
+ }
11
+ export interface FlattenedFiles {
12
+ [filePath: string]: FlatFile;
13
+ }
14
+ /**
15
+ * Flatten a VariantCode into a flat files structure
16
+ * Resolves relative paths and handles metadata file scoping
17
+ * Uses addPathsToVariant for path resolution logic
18
+ */
19
+ export declare function flattenVariant(variant: VariantCode): FlattenedFiles;
@@ -0,0 +1,49 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ /**
3
+ * Flatten variant utility to convert a VariantCode into a flat files list
4
+ * Handles relative path resolution and metadata file scoping
5
+ * Uses addPathsToVariant for the core logic, then flattens the result
6
+ */
7
+
8
+ import { stringOrHastToString } from "../pipeline/hastUtils/index.js";
9
+ import { addPathsToVariant } from "../CodeHighlighter/addPathsToVariant.js";
10
+ /**
11
+ * Flatten a VariantCode into a flat files structure
12
+ * Resolves relative paths and handles metadata file scoping
13
+ * Uses addPathsToVariant for path resolution logic
14
+ */
15
+ export function flattenVariant(variant) {
16
+ var result = {};
17
+
18
+ // Use addPathsToVariant to get the structured paths
19
+ var variantWithPaths = addPathsToVariant(variant);
20
+
21
+ // Add main file if it exists
22
+ if (variantWithPaths.path && variantWithPaths.source !== undefined) {
23
+ result[variantWithPaths.path] = {
24
+ source: stringOrHastToString(variantWithPaths.source)
25
+ };
26
+ }
27
+
28
+ // Add extra files if they exist
29
+ if (variantWithPaths.extraFiles) {
30
+ for (var _i = 0, _Object$values = Object.values(variantWithPaths.extraFiles); _i < _Object$values.length; _i++) {
31
+ var fileWithPath = _Object$values[_i];
32
+ // Skip files that are just URLs or missing a path
33
+ if (typeof fileWithPath === 'string' || !fileWithPath.path) {
34
+ continue;
35
+ }
36
+
37
+ // Skip files with no source content
38
+ if (!fileWithPath.source && fileWithPath.source !== '') {
39
+ continue;
40
+ }
41
+ result[fileWithPath.path] = _extends({
42
+ source: stringOrHastToString(fileWithPath.source || '')
43
+ }, fileWithPath.metadata && {
44
+ metadata: fileWithPath.metadata
45
+ });
46
+ }
47
+ }
48
+ return result;
49
+ }
@@ -1,51 +1,6 @@
1
- import * as React from 'react';
2
- import { Nodes } from 'hast';
3
- import { UseCopierOpts } from "../useCopier/index.js";
4
- type Source = Nodes;
5
- export type Variant = {
6
- component: React.ReactNode;
7
- fileName: string;
8
- source: Source;
9
- extraSource?: {
10
- [key: string]: Source;
11
- };
12
- };
13
- export type Demo = {
14
- name?: string;
15
- slug?: string;
16
- description?: string;
17
- variants: {
18
- [key: string]: Variant;
19
- };
20
- };
21
- type UseDemoOpts = {
22
- defaultOpen?: boolean;
23
- copy?: UseCopierOpts;
24
- githubUrlPrefix?: string;
25
- codeSandboxUrlPrefix?: string;
26
- stackBlitzPrefix?: string;
27
- };
28
- export declare function useDemo(demo: Demo, opts?: UseDemoOpts): {
29
- component: React.ReactNode;
30
- name: string | undefined;
31
- slug: string | undefined;
32
- description: string | undefined;
33
- ref: React.RefObject<HTMLDivElement | null>;
34
- variants: string[];
35
- selectedVariant: string;
36
- selectVariant: React.Dispatch<React.SetStateAction<string>>;
37
- files: {
38
- name: string;
39
- component: JSX.Element;
40
- }[];
41
- selectedFile: any;
42
- selectedFileName: string;
43
- selectFileName: React.Dispatch<React.SetStateAction<string>>;
44
- expanded: boolean;
45
- expand: () => void;
46
- setExpanded: React.Dispatch<React.SetStateAction<boolean>>;
47
- resetFocus: () => void;
48
- copy: (event: React.MouseEvent<HTMLButtonElement>) => Promise<void>;
49
- copyDisabled: boolean;
50
- };
51
- export {};
1
+ export * from "./useDemo.js";
2
+ export * from "./createStackBlitz.js";
3
+ export * from "./createCodeSandbox.js";
4
+ export * from "./flattenVariant.js";
5
+ export * from "./exportVariant.js";
6
+ export * from "./exportVariantAsCra.js";