@mui/internal-docs-infra 0.1.0 → 0.1.1-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 (177) hide show
  1. package/CodeControllerContext/CodeControllerContext.d.ts +22 -0
  2. package/CodeControllerContext/CodeControllerContext.d.ts.map +1 -0
  3. package/CodeControllerContext/CodeControllerContext.js +14 -0
  4. package/CodeControllerContext/index.d.ts +1 -0
  5. package/CodeControllerContext/index.d.ts.map +1 -0
  6. package/CodeControllerContext/index.js +1 -0
  7. package/CodeHighlighter/CodeHighlighter.d.ts +2 -0
  8. package/CodeHighlighter/CodeHighlighter.d.ts.map +1 -0
  9. package/CodeHighlighter/CodeHighlighter.js +321 -0
  10. package/CodeHighlighter/CodeHighlighterClient.d.ts +2 -0
  11. package/CodeHighlighter/CodeHighlighterClient.d.ts.map +1 -0
  12. package/CodeHighlighter/CodeHighlighterClient.js +399 -0
  13. package/CodeHighlighter/CodeHighlighterContext.d.ts +14 -0
  14. package/CodeHighlighter/CodeHighlighterContext.d.ts.map +1 -0
  15. package/CodeHighlighter/CodeHighlighterContext.js +14 -0
  16. package/CodeHighlighter/CodeHighlighterFallbackContext.d.ts +7 -0
  17. package/CodeHighlighter/CodeHighlighterFallbackContext.d.ts.map +1 -0
  18. package/CodeHighlighter/CodeHighlighterFallbackContext.js +11 -0
  19. package/CodeHighlighter/applyTransform.d.ts +19 -0
  20. package/CodeHighlighter/applyTransform.d.ts.map +1 -0
  21. package/CodeHighlighter/applyTransform.js +75 -0
  22. package/CodeHighlighter/codeToFallbackProps.d.ts +2 -0
  23. package/CodeHighlighter/codeToFallbackProps.d.ts.map +1 -0
  24. package/CodeHighlighter/codeToFallbackProps.js +70 -0
  25. package/CodeHighlighter/errors.d.ts +0 -0
  26. package/CodeHighlighter/errors.d.ts.map +1 -0
  27. package/CodeHighlighter/errors.js +1 -0
  28. package/CodeHighlighter/hasAllVariants.d.ts +2 -0
  29. package/CodeHighlighter/hasAllVariants.d.ts.map +1 -0
  30. package/CodeHighlighter/hasAllVariants.js +31 -0
  31. package/CodeHighlighter/index.d.ts +4 -0
  32. package/CodeHighlighter/index.d.ts.map +1 -0
  33. package/CodeHighlighter/index.js +4 -0
  34. package/CodeHighlighter/loadFallbackCode.d.ts +9 -0
  35. package/CodeHighlighter/loadFallbackCode.d.ts.map +1 -0
  36. package/CodeHighlighter/loadFallbackCode.js +468 -0
  37. package/CodeHighlighter/loadVariant.d.ts +11 -0
  38. package/CodeHighlighter/loadVariant.d.ts.map +1 -0
  39. package/CodeHighlighter/loadVariant.js +708 -0
  40. package/CodeHighlighter/maybeInitialData.d.ts +10 -0
  41. package/CodeHighlighter/maybeInitialData.d.ts.map +1 -0
  42. package/CodeHighlighter/maybeInitialData.js +94 -0
  43. package/CodeHighlighter/parseCode.d.ts +6 -0
  44. package/CodeHighlighter/parseCode.d.ts.map +1 -0
  45. package/CodeHighlighter/parseCode.js +122 -0
  46. package/CodeHighlighter/parseControlledCode.d.ts +6 -0
  47. package/CodeHighlighter/parseControlledCode.d.ts.map +1 -0
  48. package/CodeHighlighter/parseControlledCode.js +76 -0
  49. package/CodeHighlighter/transformCode.d.ts +20 -0
  50. package/CodeHighlighter/transformCode.d.ts.map +1 -0
  51. package/CodeHighlighter/transformCode.js +223 -0
  52. package/CodeHighlighter/transformParsedSource.d.ts +3 -0
  53. package/CodeHighlighter/transformParsedSource.d.ts.map +1 -0
  54. package/CodeHighlighter/transformParsedSource.js +66 -0
  55. package/CodeHighlighter/transformSource.d.ts +2 -0
  56. package/CodeHighlighter/transformSource.d.ts.map +1 -0
  57. package/CodeHighlighter/transformSource.js +107 -0
  58. package/CodeHighlighter/types.d.ts +138 -0
  59. package/CodeHighlighter/types.d.ts.map +1 -0
  60. package/CodeHighlighter/types.js +1 -0
  61. package/CodeProvider/CodeContext.d.ts +12 -0
  62. package/CodeProvider/CodeContext.d.ts.map +1 -0
  63. package/CodeProvider/CodeContext.js +8 -0
  64. package/CodeProvider/CodeProvider.d.ts +13 -0
  65. package/CodeProvider/CodeProvider.d.ts.map +1 -0
  66. package/CodeProvider/CodeProvider.js +50 -0
  67. package/CodeProvider/index.d.ts +2 -0
  68. package/CodeProvider/index.d.ts.map +1 -0
  69. package/CodeProvider/index.js +2 -0
  70. package/README.md +3 -1
  71. package/hast/hast.d.ts +11 -0
  72. package/hast/hast.d.ts.map +1 -0
  73. package/hast/hast.js +66 -0
  74. package/hast/index.d.ts +1 -0
  75. package/hast/index.d.ts.map +1 -0
  76. package/hast/index.js +1 -0
  77. package/loadPrecomputedCodeHighlighter/index.d.ts +2 -0
  78. package/loadPrecomputedCodeHighlighter/index.d.ts.map +1 -0
  79. package/loadPrecomputedCodeHighlighter/index.js +4 -0
  80. package/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +57 -0
  81. package/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts.map +1 -0
  82. package/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +194 -0
  83. package/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +20 -0
  84. package/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts.map +1 -0
  85. package/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +243 -0
  86. package/loadPrecomputedCodeHighlighter/parseFunctionParameters.d.ts +15 -0
  87. package/loadPrecomputedCodeHighlighter/parseFunctionParameters.d.ts.map +1 -0
  88. package/loadPrecomputedCodeHighlighter/parseFunctionParameters.js +168 -0
  89. package/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts +27 -0
  90. package/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts.map +1 -0
  91. package/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +37 -0
  92. package/loadServerCodeMeta/index.d.ts +1 -0
  93. package/loadServerCodeMeta/index.d.ts.map +1 -0
  94. package/loadServerCodeMeta/index.js +1 -0
  95. package/loadServerCodeMeta/serverLoadCodeMeta.d.ts +24 -0
  96. package/loadServerCodeMeta/serverLoadCodeMeta.d.ts.map +1 -0
  97. package/loadServerCodeMeta/serverLoadCodeMeta.js +77 -0
  98. package/loadServerSource/index.d.ts +1 -0
  99. package/loadServerSource/index.d.ts.map +1 -0
  100. package/loadServerSource/index.js +1 -0
  101. package/loadServerSource/serverLoadSource.d.ts +25 -0
  102. package/loadServerSource/serverLoadSource.d.ts.map +1 -0
  103. package/loadServerSource/serverLoadSource.js +100 -0
  104. package/loaderUtils/getFileNameFromUrl.d.ts +11 -0
  105. package/loaderUtils/getFileNameFromUrl.d.ts.map +1 -0
  106. package/loaderUtils/getFileNameFromUrl.js +32 -0
  107. package/loaderUtils/index.d.ts +5 -0
  108. package/loaderUtils/index.d.ts.map +1 -0
  109. package/loaderUtils/index.js +5 -0
  110. package/loaderUtils/processImports.d.ts +19 -0
  111. package/loaderUtils/processImports.d.ts.map +1 -0
  112. package/loaderUtils/processImports.js +82 -0
  113. package/loaderUtils/resolveImports.d.ts +4 -0
  114. package/loaderUtils/resolveImports.d.ts.map +1 -0
  115. package/loaderUtils/resolveImports.js +71 -0
  116. package/loaderUtils/resolveModulePath.d.ts +74 -0
  117. package/loaderUtils/resolveModulePath.d.ts.map +1 -0
  118. package/loaderUtils/resolveModulePath.js +862 -0
  119. package/loaderUtils/resolveModulePathWithFs.d.ts +44 -0
  120. package/loaderUtils/resolveModulePathWithFs.d.ts.map +1 -0
  121. package/loaderUtils/resolveModulePathWithFs.js +159 -0
  122. package/loaderUtils/rewriteImports.d.ts +9 -0
  123. package/loaderUtils/rewriteImports.d.ts.map +1 -0
  124. package/loaderUtils/rewriteImports.js +57 -0
  125. package/package.json +20 -7
  126. package/parseSource/grammars.d.ts +2 -0
  127. package/parseSource/grammars.d.ts.map +1 -0
  128. package/parseSource/grammars.js +27 -0
  129. package/parseSource/index.d.ts +1 -0
  130. package/parseSource/index.d.ts.map +1 -0
  131. package/parseSource/index.js +1 -0
  132. package/parseSource/parseSource.d.ts +3 -0
  133. package/parseSource/parseSource.d.ts.map +1 -0
  134. package/parseSource/parseSource.js +37 -0
  135. package/transformRelativeMarkdownPaths/index.d.ts +2 -0
  136. package/transformRelativeMarkdownPaths/index.d.ts.map +1 -0
  137. package/transformRelativeMarkdownPaths/index.js +4 -0
  138. package/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.d.ts +12 -0
  139. package/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.d.ts.map +1 -0
  140. package/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.js +30 -0
  141. package/transformTsToJs/index.d.ts +1 -0
  142. package/transformTsToJs/index.d.ts.map +1 -0
  143. package/transformTsToJs/index.js +1 -0
  144. package/transformTsToJs/removeTypes.d.ts +13 -0
  145. package/transformTsToJs/removeTypes.d.ts.map +1 -0
  146. package/transformTsToJs/removeTypes.js +134 -0
  147. package/transformTsToJs/transformTsToJs.d.ts +3 -0
  148. package/transformTsToJs/transformTsToJs.d.ts.map +1 -0
  149. package/transformTsToJs/transformTsToJs.js +34 -0
  150. package/useCode/index.d.ts +1 -0
  151. package/useCode/index.d.ts.map +1 -0
  152. package/useCode/index.js +1 -0
  153. package/{esm/useDemo/index.d.ts → useCode/useCode.d.ts} +14 -28
  154. package/useCode/useCode.d.ts.map +1 -0
  155. package/useCode/useCode.js +393 -0
  156. package/useCopier/index.js +10 -18
  157. package/useDemo/index.d.ts +12 -24
  158. package/useDemo/index.d.ts.map +1 -0
  159. package/useDemo/index.js +14 -109
  160. package/useOnHydrate/index.d.ts +1 -0
  161. package/useOnHydrate/index.d.ts.map +1 -0
  162. package/useOnHydrate/index.js +1 -0
  163. package/useOnHydrate/useOnHydrate.d.ts +1 -0
  164. package/useOnHydrate/useOnHydrate.d.ts.map +1 -0
  165. package/useOnHydrate/useOnHydrate.js +18 -0
  166. package/useOnIdle/index.d.ts +1 -0
  167. package/useOnIdle/index.d.ts.map +1 -0
  168. package/useOnIdle/index.js +1 -0
  169. package/useOnIdle/useOnIdle.d.ts +1 -0
  170. package/useOnIdle/useOnIdle.d.ts.map +1 -0
  171. package/useOnIdle/useOnIdle.js +39 -0
  172. package/esm/package.json +0 -1
  173. package/esm/useCopier/index.d.ts +0 -15
  174. package/esm/useCopier/index.js +0 -62
  175. package/esm/useDemo/index.d.ts.map +0 -1
  176. package/esm/useDemo/index.js +0 -104
  177. /package/{esm/useCopier → useCopier}/index.d.ts.map +0 -0
@@ -0,0 +1,194 @@
1
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
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 { parseSourceFactory } from "../parseSource/index.js";
7
+ import { TsToJsTransformer } from "../transformTsToJs/index.js";
8
+ import { parseCreateFactoryCall } from "./parseCreateFactoryCall.js";
9
+ import { resolveVariantPathsWithFs } from "../loaderUtils/resolveModulePathWithFs.js";
10
+ import { replacePrecomputeValue } from "./replacePrecomputeValue.js";
11
+ import { createServerLoadSource } from "../loadServerSource/index.js";
12
+ /**
13
+ * Webpack loader that processes demo files and precomputes variant data.
14
+ *
15
+ * This loader:
16
+ * 1. Parses demo files to find a single createDemo call with precompute: true
17
+ * 2. Resolves all variant entry point paths using resolveModulePathsWithFs
18
+ * 3. Uses loadVariant to handle all loading, parsing, and transformation:
19
+ * - loadSource: Loads individual files and extracts dependencies
20
+ * - loadVariantMeta: Creates basic variant structure
21
+ * - parseSource: Applies syntax highlighting using Starry Night
22
+ * - sourceTransformers: Handles TypeScript to JavaScript conversion
23
+ * 4. loadVariant handles recursive dependency loading automatically
24
+ * 5. Adds all dependencies to webpack's watch list
25
+ * 6. Replaces precompute: true with the actual precomputed data using replacePrecomputeValue
26
+ *
27
+ * Note: Only supports one createDemo call per file. Will throw an error if multiple calls are found.
28
+ *
29
+ * Features:
30
+ * - Proper variant entry point resolution using resolveModulePathsWithFs
31
+ * - Complete dependency tree loading handled by loadVariant
32
+ * - Syntax highlighting using Starry Night (via parseSource)
33
+ * - TypeScript to JavaScript transformation (via transformTsToJs)
34
+ * - Webpack dependency tracking for hot reloading
35
+ * - Precise precompute value replacement (via replacePrecomputeValue)
36
+ *
37
+ * Example input:
38
+ * ```typescript
39
+ * import { createDemo } from '@/functions/createDemo';
40
+ * import CssModules from './CssModules';
41
+ * import Tailwind from './Tailwind';
42
+ *
43
+ * export const CodeDemo = createDemo(
44
+ * import.meta.url,
45
+ * { CssModules, Tailwind },
46
+ * {
47
+ * name: 'Basic Code Block',
48
+ * slug: 'code',
49
+ * precompute: true,
50
+ * },
51
+ * );
52
+ * ```
53
+ *
54
+ * Example output (precompute: true replaced with processed data):
55
+ * The precompute property is replaced with an object containing:
56
+ * - fileName: The main file name
57
+ * - source: HAST nodes with syntax highlighting applied
58
+ * - extraFiles: Object containing additional dependency files
59
+ * - transforms: Object with language variants (e.g., JavaScript version from TypeScript)
60
+ */
61
+ export function loadPrecomputedCodeHighlighter(_x) {
62
+ return _loadPrecomputedCodeHighlighter.apply(this, arguments);
63
+ }
64
+ function _loadPrecomputedCodeHighlighter() {
65
+ _loadPrecomputedCodeHighlighter = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(source) {
66
+ var _this = this;
67
+ var callback, demoCall, variantData, allDependencies, resolvedVariantMap, loadSource, sourceTransformers, sourceParser, variantPromises, variantResults, _iterator, _step, result, modifiedSource;
68
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
69
+ while (1) switch (_context2.prev = _context2.next) {
70
+ case 0:
71
+ callback = this.async();
72
+ this.cacheable();
73
+ _context2.prev = 2;
74
+ _context2.next = 5;
75
+ return parseCreateFactoryCall(source, this.resourcePath);
76
+ case 5:
77
+ demoCall = _context2.sent;
78
+ if (demoCall) {
79
+ _context2.next = 9;
80
+ break;
81
+ }
82
+ callback(null, source);
83
+ return _context2.abrupt("return");
84
+ case 9:
85
+ if (demoCall.options.precompute) {
86
+ _context2.next = 12;
87
+ break;
88
+ }
89
+ callback(null, source);
90
+ return _context2.abrupt("return");
91
+ case 12:
92
+ // Load variant data for all variants
93
+ variantData = {};
94
+ allDependencies = []; // Resolve all variant entry point paths using resolveVariantPathsWithFs
95
+ _context2.next = 16;
96
+ return resolveVariantPathsWithFs(demoCall.variants);
97
+ case 16:
98
+ resolvedVariantMap = _context2.sent;
99
+ // Create loader functions
100
+ loadSource = createServerLoadSource({
101
+ includeDependencies: true,
102
+ storeAt: 'flat' // TODO: this should be configurable
103
+ }); // Setup source transformers for TypeScript to JavaScript conversion
104
+ sourceTransformers = [TsToJsTransformer]; // Create sourceParser promise for syntax highlighting
105
+ sourceParser = parseSourceFactory(); // Process variants in parallel
106
+ variantPromises = Array.from(resolvedVariantMap.entries()).map(/*#__PURE__*/function () {
107
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
108
+ var _ref3, variantName, fileUrl, _yield$loadVariant, processedVariant, dependencies;
109
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
110
+ while (1) switch (_context.prev = _context.next) {
111
+ case 0:
112
+ _ref3 = _slicedToArray(_ref, 2), variantName = _ref3[0], fileUrl = _ref3[1];
113
+ _context.prev = 1;
114
+ _context.next = 4;
115
+ return loadVariant(fileUrl,
116
+ // URL for the variant entry point (already includes file://)
117
+ variantName, fileUrl,
118
+ // Let loadVariantMeta handle creating the initial variant
119
+ sourceParser,
120
+ // For syntax highlighting
121
+ loadSource,
122
+ // For loading source files and dependencies
123
+ undefined, sourceTransformers,
124
+ // For TypeScript to JavaScript conversion
125
+ {
126
+ maxDepth: 5
127
+ });
128
+ case 4:
129
+ _yield$loadVariant = _context.sent;
130
+ processedVariant = _yield$loadVariant.code;
131
+ dependencies = _yield$loadVariant.dependencies;
132
+ return _context.abrupt("return", {
133
+ variantName: variantName,
134
+ variantData: processedVariant,
135
+ // processedVariant is a complete VariantCode
136
+ dependencies: dependencies // All files that were loaded
137
+ });
138
+ case 10:
139
+ _context.prev = 10;
140
+ _context.t0 = _context["catch"](1);
141
+ console.warn("Failed to load variant ".concat(variantName, " from ").concat(fileUrl, ":"), _context.t0);
142
+ return _context.abrupt("return", null);
143
+ case 14:
144
+ case "end":
145
+ return _context.stop();
146
+ }
147
+ }, _callee, null, [[1, 10]]);
148
+ }));
149
+ return function (_x2) {
150
+ return _ref2.apply(this, arguments);
151
+ };
152
+ }());
153
+ _context2.next = 23;
154
+ return Promise.all(variantPromises);
155
+ case 23:
156
+ variantResults = _context2.sent;
157
+ // Process results and collect dependencies
158
+ _iterator = _createForOfIteratorHelper(variantResults);
159
+ try {
160
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
161
+ result = _step.value;
162
+ if (result) {
163
+ variantData[result.variantName] = result.variantData;
164
+ result.dependencies.forEach(function (file) {
165
+ allDependencies.push(file);
166
+ });
167
+ }
168
+ }
169
+
170
+ // Replace 'precompute: true' with the actual precomputed data
171
+ } catch (err) {
172
+ _iterator.e(err);
173
+ } finally {
174
+ _iterator.f();
175
+ }
176
+ modifiedSource = replacePrecomputeValue(source, variantData); // Add all dependencies to webpack's watch list
177
+ allDependencies.forEach(function (dep) {
178
+ return _this.addDependency(dep);
179
+ });
180
+ callback(null, modifiedSource);
181
+ _context2.next = 34;
182
+ break;
183
+ case 31:
184
+ _context2.prev = 31;
185
+ _context2.t0 = _context2["catch"](2);
186
+ callback(_context2.t0 instanceof Error ? _context2.t0 : new Error(String(_context2.t0)));
187
+ case 34:
188
+ case "end":
189
+ return _context2.stop();
190
+ }
191
+ }, _callee2, this, [[2, 31]]);
192
+ }));
193
+ return _loadPrecomputedCodeHighlighter.apply(this, arguments);
194
+ }
@@ -0,0 +1,20 @@
1
+ export interface FactoryOptions {
2
+ name?: string;
3
+ slug?: string;
4
+ precompute?: boolean;
5
+ }
6
+ export interface ParsedCreateFactory {
7
+ functionName: string;
8
+ url: string;
9
+ variants: Record<string, string>;
10
+ options: FactoryOptions;
11
+ fullMatch: string;
12
+ variantsObjectStr: string;
13
+ optionsObjectStr: string;
14
+ }
15
+ /**
16
+ * Parses a file to extract a single create* factory call and its variants and options
17
+ * Only supports one create* call per file - will throw an error if multiple are found
18
+ * Returns null if no create* call is found
19
+ */
20
+ export declare function parseCreateFactoryCall(code: string, filePath: string): Promise<ParsedCreateFactory | null>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseCreateFactoryCall.d.ts","sourceRoot":"","sources":["../../../src/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.ts"],"names":[],"mappings":"AAqBA,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAgFD;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAiErC"}
@@ -0,0 +1,243 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import { resolveImports } from "../loaderUtils/index.js";
5
+ import { parseFunctionParameters } from "./parseFunctionParameters.js";
6
+
7
+ /**
8
+ * Helper function to convert the new resolveImports format to a Map
9
+ * that maps import names to their resolved paths
10
+ */
11
+ function buildImportMap(importResult) {
12
+ var importMap = new Map();
13
+ Object.values(importResult).forEach(function (_ref) {
14
+ var path = _ref.path,
15
+ names = _ref.names;
16
+ names.forEach(function (name) {
17
+ importMap.set(name, path);
18
+ });
19
+ });
20
+ return importMap;
21
+ }
22
+ /**
23
+ * Parses a variants object string and maps variant names to their import paths
24
+ */
25
+ function parseVariantsObject(variantsObjectStr, importMap) {
26
+ var demoImports = {};
27
+
28
+ // Parse the demo object to extract key-value pairs
29
+ // Handle both { Default: BasicCode } and { Default } syntax
30
+ var objectContentRegex = /(\w+)(?:\s*:\s*(\w+))?/g;
31
+ var objectMatch = objectContentRegex.exec(variantsObjectStr);
32
+ while (objectMatch !== null) {
33
+ var _objectMatch = objectMatch,
34
+ _objectMatch2 = _slicedToArray(_objectMatch, 3),
35
+ key = _objectMatch2[1],
36
+ value = _objectMatch2[2];
37
+ var importName = value || key; // Use value if provided, otherwise use key (shorthand syntax)
38
+
39
+ if (importMap.has(importName)) {
40
+ demoImports[key] = importMap.get(importName);
41
+ }
42
+ objectMatch = objectContentRegex.exec(variantsObjectStr);
43
+ }
44
+ return demoImports;
45
+ }
46
+
47
+ /**
48
+ * Validates that a URL parameter follows the expected convention
49
+ */
50
+ function validateUrlParameter(url, functionName, filePath) {
51
+ var trimmedUrl = url.trim();
52
+
53
+ // Check for import.meta.url
54
+ if (trimmedUrl === 'import.meta.url') {
55
+ return;
56
+ }
57
+
58
+ // Check for CJS equivalent: require('url').pathToFileURL(__filename).toString()
59
+ // https://github.com/javiertury/babel-plugin-transform-import-meta#importmetaurl
60
+ var cjsPattern = /require\s*\(\s*['"`]url['"`]\s*\)\s*\.\s*pathToFileURL\s*\(\s*__filename\s*\)\s*\.\s*toString\s*\(\s*\)/;
61
+ if (cjsPattern.test(trimmedUrl)) {
62
+ return;
63
+ }
64
+ throw new Error("Invalid URL parameter in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected 'import.meta.url' or 'require('url').pathToFileURL(__filename).toString()' but got: ".concat(trimmedUrl));
65
+ }
66
+
67
+ /**
68
+ * Validates that a variants parameter is an object mapping to imports
69
+ */
70
+ function validateVariantsParameter(variantsObjectStr, functionName, filePath) {
71
+ if (!variantsObjectStr || variantsObjectStr.trim() === '') {
72
+ throw new Error("Invalid variants parameter in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected an object mapping variant names to imports.");
73
+ }
74
+
75
+ // Basic validation that it looks like an object
76
+ var trimmed = variantsObjectStr.trim();
77
+ if (!trimmed.startsWith('{') || !trimmed.endsWith('}')) {
78
+ throw new Error("Invalid variants parameter in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected an object but got: ".concat(trimmed));
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Parses a file to extract a single create* factory call and its variants and options
84
+ * Only supports one create* call per file - will throw an error if multiple are found
85
+ * Returns null if no create* call is found
86
+ */
87
+ export function parseCreateFactoryCall(_x, _x2) {
88
+ return _parseCreateFactoryCall.apply(this, arguments);
89
+ }
90
+
91
+ /**
92
+ * Finds create* factory calls in code, handling multiline cases
93
+ */
94
+ function _parseCreateFactoryCall() {
95
+ _parseCreateFactoryCall = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(code, filePath) {
96
+ var importResult, importMap, createFactoryMatches, match, functionName, fullMatch, urlParam, variantsObjectStr, optionsObjectStr, url, variants, options, nameMatch, slugMatch, precomputeMatch;
97
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
98
+ while (1) switch (_context.prev = _context.next) {
99
+ case 0:
100
+ _context.next = 2;
101
+ return resolveImports(code, filePath);
102
+ case 2:
103
+ importResult = _context.sent;
104
+ importMap = buildImportMap(importResult); // Find all create* calls in the code
105
+ createFactoryMatches = findCreateFactoryCalls(code, filePath); // Enforce single create* call per file
106
+ if (!(createFactoryMatches.length > 1)) {
107
+ _context.next = 7;
108
+ break;
109
+ }
110
+ throw new Error("Multiple create* factory calls found in ".concat(filePath, ". Only one create* call per file is supported. Found ").concat(createFactoryMatches.length, " calls."));
111
+ case 7:
112
+ if (!(createFactoryMatches.length === 0)) {
113
+ _context.next = 9;
114
+ break;
115
+ }
116
+ return _context.abrupt("return", null);
117
+ case 9:
118
+ match = createFactoryMatches[0];
119
+ functionName = match.functionName, fullMatch = match.fullMatch, urlParam = match.urlParam, variantsObjectStr = match.variantsObjectStr, optionsObjectStr = match.optionsObjectStr; // Validate URL parameter
120
+ validateUrlParameter(urlParam, functionName, filePath);
121
+
122
+ // Validate variants parameter
123
+ validateVariantsParameter(variantsObjectStr, functionName, filePath);
124
+
125
+ // Extract URL (typically import.meta.url)
126
+ url = urlParam.trim(); // Resolve variants for this specific create* call
127
+ variants = parseVariantsObject(variantsObjectStr, importMap); // Parse options object
128
+ options = {}; // Extract name
129
+ nameMatch = optionsObjectStr.match(/name\s*:\s*['"`]([^'"`]+)['"`]/);
130
+ if (nameMatch) {
131
+ options.name = nameMatch[1];
132
+ }
133
+
134
+ // Extract slug
135
+ slugMatch = optionsObjectStr.match(/slug\s*:\s*['"`]([^'"`]+)['"`]/);
136
+ if (slugMatch) {
137
+ options.slug = slugMatch[1];
138
+ }
139
+
140
+ // Extract precompute
141
+ precomputeMatch = optionsObjectStr.match(/precompute\s*:\s*(true|false)/);
142
+ if (precomputeMatch) {
143
+ options.precompute = precomputeMatch[1] === 'true';
144
+ }
145
+ return _context.abrupt("return", {
146
+ functionName: functionName,
147
+ url: url,
148
+ variants: variants,
149
+ options: options,
150
+ fullMatch: fullMatch,
151
+ variantsObjectStr: variantsObjectStr,
152
+ optionsObjectStr: optionsObjectStr
153
+ });
154
+ case 23:
155
+ case "end":
156
+ return _context.stop();
157
+ }
158
+ }, _callee);
159
+ }));
160
+ return _parseCreateFactoryCall.apply(this, arguments);
161
+ }
162
+ function findCreateFactoryCalls(code, filePath) {
163
+ var results = [];
164
+
165
+ // Find all create* function calls
166
+ var createFactoryRegex = /\b(create\w*)\s*\(/g;
167
+ var match = createFactoryRegex.exec(code);
168
+ while (match !== null) {
169
+ var functionName = match[1];
170
+ var startIndex = match.index;
171
+ var parenIndex = match.index + match[0].length - 1; // Position of opening parenthesis
172
+
173
+ // Find the matching closing parenthesis
174
+ var parenCount = 0;
175
+ var endIndex = -1;
176
+ for (var i = parenIndex; i < code.length; i += 1) {
177
+ if (code[i] === '(') {
178
+ parenCount += 1;
179
+ } else if (code[i] === ')') {
180
+ parenCount -= 1;
181
+ if (parenCount === 0) {
182
+ endIndex = i;
183
+ break;
184
+ }
185
+ }
186
+ }
187
+ if (endIndex === -1) {
188
+ match = createFactoryRegex.exec(code);
189
+ continue;
190
+ }
191
+ var fullMatch = code.substring(startIndex, endIndex + 1);
192
+ var content = code.substring(parenIndex + 1, endIndex);
193
+
194
+ // Split by commas at the top level, handling nested structures and comments
195
+ var _parseFunctionParamet = parseFunctionParameters(content),
196
+ parts = _parseFunctionParamet.parts,
197
+ objects = _parseFunctionParamet.objects;
198
+
199
+ // Validate the function follows the convention
200
+ if (parts.length < 2 || parts.length > 3) {
201
+ throw new Error("Invalid ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected 2-3 parameters (url, variants, options?) but got ".concat(parts.length, " parameters. ") + "Functions starting with 'create' must follow the convention: create*(url, variants, options?)");
202
+ }
203
+ if (parts.length === 2) {
204
+ var _parts = _slicedToArray(parts, 1),
205
+ urlParam = _parts[0];
206
+
207
+ // Extract the actual object string for variants
208
+ var variantsObjectStr = objects[1];
209
+ if (!variantsObjectStr) {
210
+ throw new Error("Invalid variants parameter in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected an object but could not parse: ".concat(parts[1].trim()));
211
+ }
212
+ results.push({
213
+ functionName: functionName,
214
+ fullMatch: fullMatch,
215
+ urlParam: urlParam.trim(),
216
+ variantsObjectStr: variantsObjectStr,
217
+ optionsObjectStr: '{}' // Default empty options
218
+ });
219
+ } else if (parts.length === 3) {
220
+ var _parts2 = _slicedToArray(parts, 1),
221
+ _urlParam = _parts2[0];
222
+
223
+ // Extract the actual object strings
224
+ var _variantsObjectStr = objects[1];
225
+ var optionsObjectStr = objects[2];
226
+ if (!_variantsObjectStr) {
227
+ throw new Error("Invalid variants parameter in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected an object but could not parse: ".concat(parts[1].trim()));
228
+ }
229
+ if (!optionsObjectStr) {
230
+ throw new Error("Invalid options parameter in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected an object but could not parse: ".concat(parts[2].trim()));
231
+ }
232
+ results.push({
233
+ functionName: functionName,
234
+ fullMatch: fullMatch,
235
+ urlParam: _urlParam.trim(),
236
+ variantsObjectStr: _variantsObjectStr,
237
+ optionsObjectStr: optionsObjectStr
238
+ });
239
+ }
240
+ match = createFactoryRegex.exec(code);
241
+ }
242
+ return results;
243
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Utility function for parsing function parameters and handling nested structures
3
+ * in JavaScript/TypeScript code.
4
+ */
5
+ export interface ParsedParameters {
6
+ /** The raw parameter strings split by top-level commas */
7
+ parts: string[];
8
+ /** Extracted balanced brace objects from each part (null if not an object) */
9
+ objects: (string | null)[];
10
+ }
11
+ /**
12
+ * Parses function parameters, splitting by top-level commas and extracting object literals.
13
+ * This combines comma-splitting with object extraction for common use cases.
14
+ */
15
+ export declare function parseFunctionParameters(str: string): ParsedParameters;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseFunctionParameters.d.ts","sourceRoot":"","sources":["../../../src/loadPrecomputedCodeHighlighter/parseFunctionParameters.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,0DAA0D;IAC1D,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,8EAA8E;IAC9E,OAAO,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CA8FrE"}
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Utility function for parsing function parameters and handling nested structures
3
+ * in JavaScript/TypeScript code.
4
+ */
5
+
6
+ /**
7
+ * Parses function parameters, splitting by top-level commas and extracting object literals.
8
+ * This combines comma-splitting with object extraction for common use cases.
9
+ */
10
+ export function parseFunctionParameters(str) {
11
+ var parts = [];
12
+ var objects = [];
13
+ var current = '';
14
+ var parenCount = 0;
15
+ var braceCount = 0;
16
+ var inSingleLineComment = false;
17
+ var inMultiLineComment = false;
18
+ var inString = false;
19
+ var stringChar = '';
20
+ for (var i = 0; i < str.length; i += 1) {
21
+ var _char = str[i];
22
+ var nextChar = str[i + 1];
23
+
24
+ // Handle comments
25
+ if (!inString && !inSingleLineComment && !inMultiLineComment) {
26
+ if (_char === '/' && nextChar === '/') {
27
+ inSingleLineComment = true;
28
+ current += _char;
29
+ continue;
30
+ }
31
+ if (_char === '/' && nextChar === '*') {
32
+ inMultiLineComment = true;
33
+ current += _char;
34
+ continue;
35
+ }
36
+ }
37
+ if (inSingleLineComment && _char === '\n') {
38
+ inSingleLineComment = false;
39
+ current += _char;
40
+ continue;
41
+ }
42
+ if (inMultiLineComment && _char === '*' && nextChar === '/') {
43
+ inMultiLineComment = false;
44
+ current += _char + nextChar;
45
+ i += 1; // Skip next character
46
+ continue;
47
+ }
48
+ if (inSingleLineComment || inMultiLineComment) {
49
+ current += _char;
50
+ continue;
51
+ }
52
+
53
+ // Handle strings
54
+ if (!inString && (_char === '"' || _char === "'" || _char === '`')) {
55
+ inString = true;
56
+ stringChar = _char;
57
+ current += _char;
58
+ continue;
59
+ }
60
+ if (inString && _char === stringChar && str[i - 1] !== '\\') {
61
+ inString = false;
62
+ stringChar = '';
63
+ current += _char;
64
+ continue;
65
+ }
66
+ if (inString) {
67
+ current += _char;
68
+ continue;
69
+ }
70
+
71
+ // Handle brackets and parentheses
72
+ if (_char === '(') {
73
+ parenCount += 1;
74
+ } else if (_char === ')') {
75
+ parenCount -= 1;
76
+ } else if (_char === '{') {
77
+ braceCount += 1;
78
+ } else if (_char === '}') {
79
+ braceCount -= 1;
80
+ } else if (_char === ',' && parenCount === 0 && braceCount === 0) {
81
+ var trimmedPart = current.trim();
82
+ parts.push(trimmedPart);
83
+ objects.push(extractBalancedBraces(trimmedPart));
84
+ current = '';
85
+ continue;
86
+ }
87
+ current += _char;
88
+ }
89
+ if (current.trim()) {
90
+ var _trimmedPart = current.trim();
91
+ parts.push(_trimmedPart);
92
+ objects.push(extractBalancedBraces(_trimmedPart));
93
+ }
94
+ return {
95
+ parts: parts,
96
+ objects: objects
97
+ };
98
+ }
99
+
100
+ /**
101
+ * Extracts a balanced brace object from a string, handling leading whitespace and comments
102
+ */
103
+ function extractBalancedBraces(str) {
104
+ // Find the first opening brace, skipping whitespace and comments
105
+ var startIndex = -1;
106
+ var inSingleLineComment = false;
107
+ var inMultiLineComment = false;
108
+ for (var i = 0; i < str.length; i += 1) {
109
+ var _char2 = str[i];
110
+ var nextChar = str[i + 1];
111
+
112
+ // Handle comments
113
+ if (!inSingleLineComment && !inMultiLineComment) {
114
+ if (_char2 === '/' && nextChar === '/') {
115
+ inSingleLineComment = true;
116
+ continue;
117
+ }
118
+ if (_char2 === '/' && nextChar === '*') {
119
+ inMultiLineComment = true;
120
+ i += 1; // Skip next character
121
+ continue;
122
+ }
123
+ }
124
+ if (inSingleLineComment && _char2 === '\n') {
125
+ inSingleLineComment = false;
126
+ continue;
127
+ }
128
+ if (inMultiLineComment && _char2 === '*' && nextChar === '/') {
129
+ inMultiLineComment = false;
130
+ i += 1; // Skip next character
131
+ continue;
132
+ }
133
+ if (inSingleLineComment || inMultiLineComment) {
134
+ continue;
135
+ }
136
+
137
+ // Skip whitespace
138
+ if (_char2 === ' ' || _char2 === '\t' || _char2 === '\n' || _char2 === '\r') {
139
+ continue;
140
+ }
141
+
142
+ // Found first non-whitespace, non-comment character
143
+ if (_char2 === '{') {
144
+ startIndex = i;
145
+ break;
146
+ } else {
147
+ // If it's not a brace, this isn't a valid object
148
+ return null;
149
+ }
150
+ }
151
+ if (startIndex === -1) {
152
+ return null;
153
+ }
154
+ var braceCount = 0;
155
+ var endIndex = -1;
156
+ for (var _i = startIndex; _i < str.length; _i += 1) {
157
+ if (str[_i] === '{') {
158
+ braceCount += 1;
159
+ } else if (str[_i] === '}') {
160
+ braceCount -= 1;
161
+ if (braceCount === 0) {
162
+ endIndex = _i;
163
+ break;
164
+ }
165
+ }
166
+ }
167
+ return endIndex !== -1 ? str.substring(startIndex, endIndex + 1) : null;
168
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Replaces 'precompute: true' with the actual precomputed data in source code.
3
+ *
4
+ * This function performs a precise replacement of the boolean true value in
5
+ * 'precompute: true' expressions with the provided data object, keeping the
6
+ * rest of the source code unchanged.
7
+ *
8
+ * @param source - The source code string containing 'precompute: true'
9
+ * @param precomputeData - The data object to replace the true value with
10
+ * @returns The modified source code with precompute data injected
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const source = `
15
+ * export const demo = createDemo(
16
+ * import.meta.url,
17
+ * { Component },
18
+ * { precompute: true }
19
+ * );
20
+ * `;
21
+ *
22
+ * const data = { variants: { default: { code: "..." } } };
23
+ * const result = replacePrecomputeValue(source, data);
24
+ * // Result will have 'precompute: true' replaced with 'precompute: { variants: { default: { code: "..." } } }'
25
+ * ```
26
+ */
27
+ export declare function replacePrecomputeValue(source: string, precomputeData: Record<string, any>): string;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replacePrecomputeValue.d.ts","sourceRoot":"","sources":["../../../src/loadPrecomputedCodeHighlighter/replacePrecomputeValue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAClC,MAAM,CAUR"}