@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,44 @@
1
+ import { CreateDemoDataMeta, DemoData, DemoGlobalData, DemoGlobalProvider } from "./types.js";
2
+ /**
3
+ * Creates demo data for displaying code examples with syntax highlighting.
4
+ * A variant is a different implementation style of the same component.
5
+ * Returns a data object containing demo metadata and components instead of a complete demo component.
6
+ * Note: It is recommended to use abstractCreateDemo to create a complete demo component rather than just demo data.
7
+ * @param url Depends on `import.meta.url` to determine the source file location.
8
+ * @param variants The variants of the component to be rendered in the demo.
9
+ * @param meta Additional meta for the demo.
10
+ */
11
+ export declare function createDemoDataWithVariants<T extends React.ComponentType<any> = React.ComponentType>(url: string, variants: {
12
+ Default: T;
13
+ } | {
14
+ [key: string]: T;
15
+ }, meta?: CreateDemoDataMeta): DemoData<T>;
16
+ /**
17
+ * Creates demo data for displaying code examples with syntax highlighting.
18
+ * Returns a data object containing demo metadata and components instead of a complete demo component.
19
+ * Note: It is recommended to use abstractCreateDemo to create a complete demo component rather than just demo data.
20
+ * @param url Depends on `import.meta.url` to determine the source file location.
21
+ * @param component The component to be rendered in the demo.
22
+ * @param meta Additional meta for the demo.
23
+ */
24
+ export declare function createDemoData<T extends React.ComponentType<any> = React.ComponentType>(url: string, component: T, meta?: CreateDemoDataMeta): DemoData<T>;
25
+ /**
26
+ * Creates a demo data object for a global provider component with different variants.
27
+ *
28
+ * @param url The URL of the demo file.
29
+ * @param globalProviders The variants of the global provider to be rendered in the demo.
30
+ * @param meta Additional metadata for the demo data.
31
+ * @returns Demo data object.
32
+ */
33
+ export declare function createDemoGlobalWithVariants(url: string, globalProviders: {
34
+ [variant: string]: DemoGlobalProvider;
35
+ }, meta?: CreateDemoDataMeta): DemoGlobalData;
36
+ /**
37
+ * Creates a demo data object for a global provider component.
38
+ *
39
+ * @param url The URL of the demo file.
40
+ * @param globalProvider The global provider to be rendered in the demo.
41
+ * @param meta Additional metadata for the demo data.
42
+ * @returns Demo data object.
43
+ */
44
+ export declare function createDemoGlobal(url: string, globalProvider: DemoGlobalProvider, meta?: CreateDemoDataMeta): DemoGlobalData;
@@ -0,0 +1,74 @@
1
+ import { extractNameAndSlugFromUrl } from "../pipeline/loaderUtils/index.js";
2
+ /**
3
+ * Creates demo data for displaying code examples with syntax highlighting.
4
+ * A variant is a different implementation style of the same component.
5
+ * Returns a data object containing demo metadata and components instead of a complete demo component.
6
+ * Note: It is recommended to use abstractCreateDemo to create a complete demo component rather than just demo data.
7
+ * @param url Depends on `import.meta.url` to determine the source file location.
8
+ * @param variants The variants of the component to be rendered in the demo.
9
+ * @param meta Additional meta for the demo.
10
+ */
11
+ export function createDemoDataWithVariants(url, variants, meta) {
12
+ var _meta$name, _meta$slug;
13
+ if (!url.startsWith('file:')) {
14
+ throw new Error('createDemoData() requires the `url` argument to be a file URL. Use `import.meta.url` to get the current file URL.');
15
+ }
16
+ if (!meta || !meta.precompute && !meta.skipPrecompute) {
17
+ throw new Error("createDemoData() was unable to precompute the code in ".concat(url, ". Ensure the createDemoData() function is called within a path used for demo indexes. This is typically app/**/demos/*/index.ts but may be overridden in next.config.js"));
18
+ }
19
+ var precompute = meta.precompute;
20
+
21
+ // Generate name and slug from URL if not provided in meta
22
+ var generatedMeta = extractNameAndSlugFromUrl(url);
23
+ var name = (_meta$name = meta.name) != null ? _meta$name : generatedMeta.name;
24
+ var slug = (_meta$slug = meta.slug) != null ? _meta$slug : generatedMeta.slug;
25
+ var displayName = (meta == null ? void 0 : meta.displayName) || "".concat(name.replace(/ /g, ''), "Demo");
26
+ return {
27
+ name: name,
28
+ slug: slug,
29
+ displayName: displayName,
30
+ precompute: precompute,
31
+ url: url,
32
+ components: variants
33
+ };
34
+ }
35
+
36
+ /**
37
+ * Creates demo data for displaying code examples with syntax highlighting.
38
+ * Returns a data object containing demo metadata and components instead of a complete demo component.
39
+ * Note: It is recommended to use abstractCreateDemo to create a complete demo component rather than just demo data.
40
+ * @param url Depends on `import.meta.url` to determine the source file location.
41
+ * @param component The component to be rendered in the demo.
42
+ * @param meta Additional meta for the demo.
43
+ */
44
+ export function createDemoData(url, component, meta) {
45
+ return createDemoDataWithVariants(url, {
46
+ Default: component
47
+ }, meta);
48
+ }
49
+
50
+ /**
51
+ * Creates a demo data object for a global provider component with different variants.
52
+ *
53
+ * @param url The URL of the demo file.
54
+ * @param globalProviders The variants of the global provider to be rendered in the demo.
55
+ * @param meta Additional metadata for the demo data.
56
+ * @returns Demo data object.
57
+ */
58
+ export function createDemoGlobalWithVariants(url, globalProviders, meta) {
59
+ return createDemoDataWithVariants(url, globalProviders, meta);
60
+ }
61
+
62
+ /**
63
+ * Creates a demo data object for a global provider component.
64
+ *
65
+ * @param url The URL of the demo file.
66
+ * @param globalProvider The global provider to be rendered in the demo.
67
+ * @param meta Additional metadata for the demo data.
68
+ * @returns Demo data object.
69
+ */
70
+ export function createDemoGlobal(url, globalProvider, meta) {
71
+ return createDemoGlobalWithVariants(url, {
72
+ Default: globalProvider
73
+ }, meta);
74
+ }
@@ -0,0 +1 @@
1
+ export * from "./createDemoData.js";
@@ -0,0 +1 @@
1
+ export * from "./createDemoData.js";
@@ -0,0 +1,25 @@
1
+ import type { Code } from "../CodeHighlighter/types.js";
2
+ export type CreateDemoDataMeta = {
3
+ name?: string;
4
+ slug?: string;
5
+ displayName?: string;
6
+ skipPrecompute?: boolean;
7
+ precompute?: Code;
8
+ client?: React.ComponentType<{
9
+ children: React.ReactNode;
10
+ }>;
11
+ };
12
+ export type DemoData<T extends React.ComponentType<any> = React.ComponentType> = {
13
+ name: string;
14
+ slug: string;
15
+ displayName: string;
16
+ precompute: Code | undefined;
17
+ url: string;
18
+ components: {
19
+ [key: string]: T;
20
+ };
21
+ };
22
+ export type DemoGlobalProvider = React.ComponentType<{
23
+ children: React.ReactNode;
24
+ }>;
25
+ export type DemoGlobalData = DemoData<DemoGlobalProvider>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { Nodes as HastNodes } from 'hast';
2
+ export declare function hastToJsx(hast: HastNodes): React.ReactNode;
3
+ export declare function hastOrJsonToJsx(hastOrJson: HastNodes | {
4
+ hastJson: string;
5
+ }): React.ReactNode;
6
+ export declare function stringOrHastToString(source: string | HastNodes | {
7
+ hastJson: string;
8
+ }): string;
9
+ export declare function stringOrHastToJsx(source: string | HastNodes | {
10
+ hastJson: string;
11
+ }, highlighted?: boolean): React.ReactNode;
@@ -0,0 +1,67 @@
1
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
2
+ import { Fragment, jsx, jsxs } from 'react/jsx-runtime';
3
+ import { toText } from 'hast-util-to-text';
4
+ import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
5
+ export function hastToJsx(hast) {
6
+ return toJsxRuntime(hast, {
7
+ Fragment: Fragment,
8
+ jsx: jsx,
9
+ jsxs: jsxs
10
+ });
11
+ }
12
+ export function hastOrJsonToJsx(hastOrJson) {
13
+ var hast;
14
+ if ('hastJson' in hastOrJson) {
15
+ try {
16
+ hast = JSON.parse(hastOrJson.hastJson);
17
+ } catch (error) {
18
+ throw new Error("Failed to parse hastJson: ".concat(JSON.stringify(error)));
19
+ }
20
+ } else {
21
+ hast = hastOrJson;
22
+ }
23
+ return toJsxRuntime(hast, {
24
+ Fragment: Fragment,
25
+ jsx: jsx,
26
+ jsxs: jsxs
27
+ });
28
+ }
29
+ export function stringOrHastToString(source) {
30
+ if (typeof source === 'string') {
31
+ return source;
32
+ }
33
+ var hast;
34
+ if ('hastJson' in source) {
35
+ try {
36
+ hast = JSON.parse(source.hastJson);
37
+ } catch (error) {
38
+ throw new Error("Failed to parse hastJson: ".concat(JSON.stringify(error)));
39
+ }
40
+ } else {
41
+ hast = source;
42
+ }
43
+ return toText(hast, {
44
+ whitespace: 'pre'
45
+ });
46
+ }
47
+ export function stringOrHastToJsx(source, highlighted) {
48
+ if (typeof source === 'string') {
49
+ return source;
50
+ }
51
+ var hast;
52
+ if ('hastJson' in source) {
53
+ try {
54
+ hast = JSON.parse(source.hastJson);
55
+ } catch (error) {
56
+ throw new Error("Failed to parse hastJson: ".concat(JSON.stringify(error)));
57
+ }
58
+ } else {
59
+ hast = source;
60
+ }
61
+ if (highlighted && _typeof(hast) === 'object') {
62
+ return hastToJsx(hast);
63
+ }
64
+ return toText(hast, {
65
+ whitespace: 'pre'
66
+ });
67
+ }
@@ -0,0 +1 @@
1
+ export * from "./hastUtils.js";
@@ -0,0 +1 @@
1
+ export * from "./hastUtils.js";
@@ -0,0 +1,2 @@
1
+ import { loadPrecomputedCodeHighlighter } from "./loadPrecomputedCodeHighlighter.js";
2
+ export default loadPrecomputedCodeHighlighter;
@@ -0,0 +1,4 @@
1
+ // This is export format a Webpack / Turbopack loader expects
2
+
3
+ import { loadPrecomputedCodeHighlighter } from "./loadPrecomputedCodeHighlighter.js";
4
+ export default loadPrecomputedCodeHighlighter;
@@ -0,0 +1,14 @@
1
+ import type { LoaderContext } from 'webpack';
2
+ export type LoaderOptions = {};
3
+ /**
4
+ * Webpack loader that processes demo files and precomputes variant data.
5
+ *
6
+ * Finds createDemo calls, loads and processes all variants with syntax highlighting
7
+ * and TypeScript transformation, then injects the precomputed data back into the source.
8
+ *
9
+ * Supports single component syntax: createDemo(import.meta.url, Component)
10
+ * And object syntax: createDemo(import.meta.url, { Component1, Component2 })
11
+ *
12
+ * Automatically skips processing if skipPrecompute: true is set.
13
+ */
14
+ export declare function loadPrecomputedCodeHighlighter(this: LoaderContext<LoaderOptions>, source: string): Promise<void>;
@@ -0,0 +1,178 @@
1
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
+ import _regenerator from "@babel/runtime/helpers/esm/regenerator";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
+ import { loadVariant } from "../../CodeHighlighter/loadVariant.js";
6
+ import { createParseSource } from "../parseSource/index.js";
7
+ // TODO: re-enable following benchmarking
8
+ // import { TypescriptToJavascriptTransformer } from '../transformTypescriptToJavascript';
9
+
10
+ import { parseCreateFactoryCall } from "./parseCreateFactoryCall.js";
11
+ import { resolveVariantPathsWithFs } from "../loaderUtils/resolveModulePathWithFs.js";
12
+ import { replacePrecomputeValue } from "./replacePrecomputeValue.js";
13
+ import { createLoadServerSource } from "../loadServerSource/index.js";
14
+ import { getFileNameFromUrl } from "../loaderUtils/index.js";
15
+ /**
16
+ * Webpack loader that processes demo files and precomputes variant data.
17
+ *
18
+ * Finds createDemo calls, loads and processes all variants with syntax highlighting
19
+ * and TypeScript transformation, then injects the precomputed data back into the source.
20
+ *
21
+ * Supports single component syntax: createDemo(import.meta.url, Component)
22
+ * And object syntax: createDemo(import.meta.url, { Component1, Component2 })
23
+ *
24
+ * Automatically skips processing if skipPrecompute: true is set.
25
+ */
26
+ export function loadPrecomputedCodeHighlighter(_x) {
27
+ return _loadPrecomputedCodeHighlighter.apply(this, arguments);
28
+ }
29
+ function _loadPrecomputedCodeHighlighter() {
30
+ _loadPrecomputedCodeHighlighter = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(source) {
31
+ var _this = this;
32
+ var callback, demoCall, variantData, allDependencies, resolvedVariantMap, loadSource, sourceTransformers, sourceParser, variantPromises, variantResults, _iterator, _step, result, modifiedSource, _t2;
33
+ return _regenerator().w(function (_context2) {
34
+ while (1) switch (_context2.p = _context2.n) {
35
+ case 0:
36
+ callback = this.async();
37
+ this.cacheable();
38
+ _context2.p = 1;
39
+ _context2.n = 2;
40
+ return parseCreateFactoryCall(source, this.resourcePath);
41
+ case 2:
42
+ demoCall = _context2.v;
43
+ if (demoCall) {
44
+ _context2.n = 3;
45
+ break;
46
+ }
47
+ callback(null, source);
48
+ return _context2.a(2);
49
+ case 3:
50
+ if (!demoCall.options.skipPrecompute) {
51
+ _context2.n = 4;
52
+ break;
53
+ }
54
+ callback(null, source);
55
+ return _context2.a(2);
56
+ case 4:
57
+ // Load variant data for all variants
58
+ variantData = {};
59
+ allDependencies = []; // Resolve all variant entry point paths using resolveVariantPathsWithFs
60
+ _context2.n = 5;
61
+ return resolveVariantPathsWithFs(demoCall.variants || {});
62
+ case 5:
63
+ resolvedVariantMap = _context2.v;
64
+ // Create loader functions
65
+ loadSource = createLoadServerSource({
66
+ includeDependencies: true,
67
+ storeAt: 'flat' // TODO: this should be configurable
68
+ }); // Setup source transformers for TypeScript to JavaScript conversion
69
+ // const sourceTransformers: SourceTransformers = [TypescriptToJavascriptTransformer];
70
+ // TODO: maybe we should have `loadPrecomputedCodeHighlighterWithJsToTs`
71
+ sourceTransformers = []; // Create sourceParser promise for syntax highlighting
72
+ sourceParser = createParseSource(); // Process variants in parallel
73
+ variantPromises = Array.from(resolvedVariantMap.entries()).map(/*#__PURE__*/function () {
74
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
75
+ var _demoCall$namedExport;
76
+ var _ref3, variantName, fileUrl, namedExport, variant, _getFileNameFromUrl, fileName, _yield$loadVariant, processedVariant, dependencies, _t;
77
+ return _regenerator().w(function (_context) {
78
+ while (1) switch (_context.p = _context.n) {
79
+ case 0:
80
+ _ref3 = _slicedToArray(_ref, 2), variantName = _ref3[0], fileUrl = _ref3[1];
81
+ namedExport = (_demoCall$namedExport = demoCall.namedExports) == null ? void 0 : _demoCall$namedExport[variantName];
82
+ variant = fileUrl;
83
+ if (!namedExport) {
84
+ _context.n = 2;
85
+ break;
86
+ }
87
+ _getFileNameFromUrl = getFileNameFromUrl(variant), fileName = _getFileNameFromUrl.fileName;
88
+ if (fileName) {
89
+ _context.n = 1;
90
+ break;
91
+ }
92
+ throw new Error("Cannot determine fileName from URL \"".concat(variant, "\" for variant \"").concat(variantName, "\". ") + "Please ensure the URL has a valid file extension.");
93
+ case 1:
94
+ variant = {
95
+ url: fileUrl,
96
+ fileName: fileName,
97
+ namedExport: namedExport
98
+ };
99
+ case 2:
100
+ _context.p = 2;
101
+ _context.n = 3;
102
+ return loadVariant(fileUrl,
103
+ // URL for the variant entry point (already includes file://)
104
+ variantName, variant, {
105
+ sourceParser: sourceParser,
106
+ // For syntax highlighting
107
+ loadSource: loadSource,
108
+ // For loading source files and dependencies
109
+ loadVariantMeta: undefined,
110
+ sourceTransformers: sourceTransformers,
111
+ // For TypeScript to JavaScript conversion
112
+ maxDepth: 5
113
+ });
114
+ case 3:
115
+ _yield$loadVariant = _context.v;
116
+ processedVariant = _yield$loadVariant.code;
117
+ dependencies = _yield$loadVariant.dependencies;
118
+ return _context.a(2, {
119
+ variantName: variantName,
120
+ variantData: processedVariant,
121
+ // processedVariant is a complete VariantCode
122
+ dependencies: dependencies // All files that were loaded
123
+ });
124
+ case 4:
125
+ _context.p = 4;
126
+ _t = _context.v;
127
+ throw new Error("Failed to load variant ".concat(variantName, " from ").concat(fileUrl, ": ").concat(_t));
128
+ case 5:
129
+ return _context.a(2);
130
+ }
131
+ }, _callee, null, [[2, 4]]);
132
+ }));
133
+ return function (_x2) {
134
+ return _ref2.apply(this, arguments);
135
+ };
136
+ }());
137
+ _context2.n = 6;
138
+ return Promise.all(variantPromises);
139
+ case 6:
140
+ variantResults = _context2.v;
141
+ // Process results and collect dependencies
142
+ _iterator = _createForOfIteratorHelper(variantResults);
143
+ try {
144
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
145
+ result = _step.value;
146
+ if (result) {
147
+ variantData[result.variantName] = result.variantData;
148
+ result.dependencies.forEach(function (file) {
149
+ allDependencies.push(file);
150
+ });
151
+ }
152
+ }
153
+
154
+ // Replace the factory function call with the actual precomputed data
155
+ } catch (err) {
156
+ _iterator.e(err);
157
+ } finally {
158
+ _iterator.f();
159
+ }
160
+ modifiedSource = replacePrecomputeValue(source, variantData, demoCall); // Add all dependencies to webpack's watch list
161
+ allDependencies.forEach(function (dep) {
162
+ // Strip 'file://' prefix if present before adding to webpack's dependency tracking
163
+ _this.addDependency(dep.startsWith('file://') ? dep.slice(7) : dep);
164
+ });
165
+ callback(null, modifiedSource);
166
+ _context2.n = 8;
167
+ break;
168
+ case 7:
169
+ _context2.p = 7;
170
+ _t2 = _context2.v;
171
+ callback(_t2 instanceof Error ? _t2 : new Error(String(_t2)));
172
+ case 8:
173
+ return _context2.a(2);
174
+ }
175
+ }, _callee2, this, [[1, 7]]);
176
+ }));
177
+ return _loadPrecomputedCodeHighlighter.apply(this, arguments);
178
+ }
@@ -0,0 +1,47 @@
1
+ import { type ParseImportsResult } from "../loaderUtils/index.js";
2
+ import { type SplitArguments } from "./parseFunctionArguments.js";
3
+ import type { Externals } from "../../CodeHighlighter/types.js";
4
+ /**
5
+ * Parse options for create* factory call parsing
6
+ */
7
+ export interface ParseOptions {
8
+ metadataOnly?: boolean;
9
+ allowExternalVariants?: boolean;
10
+ allowMultipleFactories?: boolean;
11
+ }
12
+ export interface FactoryOptions {
13
+ name?: string;
14
+ slug?: string;
15
+ skipPrecompute?: boolean;
16
+ precompute?: any;
17
+ }
18
+ export interface ParsedCreateFactory {
19
+ functionName: string;
20
+ url: string;
21
+ variants: Record<string, string> | undefined;
22
+ namedExports: Record<string, string | undefined> | undefined;
23
+ options: FactoryOptions;
24
+ fullMatch: string;
25
+ hasOptions: boolean;
26
+ externals: Externals;
27
+ argumentsStartIndex: number;
28
+ argumentsEndIndex: number;
29
+ structuredUrl: string;
30
+ structuredVariants: string | SplitArguments | Record<string, string> | undefined;
31
+ structuredOptions?: Record<string, any>;
32
+ remaining?: string;
33
+ parseImportsResult?: ParseImportsResult;
34
+ }
35
+ /**
36
+ * Parses a file to extract a single create* factory call and its variants and options
37
+ * Returns the parsed result with remaining content included
38
+ * Returns null if no create* call is found
39
+ */
40
+ export declare function parseCreateFactoryCall(code: string, filePath: string, parseOptions?: ParseOptions, parseImportsResult?: ParseImportsResult): Promise<(ParsedCreateFactory & {
41
+ parseImportsResult?: ParseImportsResult;
42
+ }) | null>;
43
+ /**
44
+ * Parses all create* factory calls in a file sequentially
45
+ * Returns a record of export names mapped to their parsed factory calls
46
+ */
47
+ export declare function parseAllCreateFactoryCalls(code: string, filePath: string, parseOptions?: Omit<ParseOptions, 'allowMultipleFactories'>): Promise<Record<string, ParsedCreateFactory>>;