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

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 (45) hide show
  1. package/esm/CodeHighlighter/CodeHighlighter.js +54 -39
  2. package/esm/CodeHighlighter/CodeHighlighterClient.js +77 -33
  3. package/esm/CodeHighlighter/errors.js +1 -1
  4. package/esm/CodeHighlighter/loadFallbackCode.js +6 -2
  5. package/esm/CodeHighlighter/loadVariant.js +64 -22
  6. package/esm/CodeHighlighter/maybeInitialData.d.ts +2 -2
  7. package/esm/CodeHighlighter/maybeInitialData.js +2 -2
  8. package/esm/CodeHighlighter/transformSource.js +57 -17
  9. package/esm/CodeHighlighter/types.d.ts +20 -3
  10. package/esm/abstractCreateDemo/abstractCreateDemo.d.ts +4 -2
  11. package/esm/abstractCreateDemo/abstractCreateDemo.js +2 -1
  12. package/esm/pipeline/hastUtils/hastUtils.d.ts +6 -0
  13. package/esm/pipeline/hastUtils/hastUtils.js +20 -0
  14. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +3 -1
  15. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +2 -1
  16. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +6 -4
  17. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +443 -258
  18. package/esm/pipeline/loadServerSource/loadServerSource.js +59 -19
  19. package/esm/pipeline/loaderUtils/index.d.ts +1 -1
  20. package/esm/pipeline/loaderUtils/index.js +1 -1
  21. package/esm/pipeline/loaderUtils/parseImportsAndComments.d.ts +91 -0
  22. package/esm/pipeline/loaderUtils/parseImportsAndComments.js +1329 -0
  23. package/esm/pipeline/loaderUtils/processRelativeImports.d.ts +8 -3
  24. package/esm/pipeline/loaderUtils/processRelativeImports.js +237 -118
  25. package/esm/pipeline/loaderUtils/resolveModulePath.d.ts +7 -3
  26. package/esm/pipeline/loaderUtils/resolveModulePath.js +3 -3
  27. package/esm/pipeline/loaderUtils/resolveModulePathWithFs.d.ts +4 -0
  28. package/esm/pipeline/loaderUtils/rewriteImports.d.ts +12 -5
  29. package/esm/pipeline/loaderUtils/rewriteImports.js +56 -26
  30. package/esm/pipeline/transformHtmlCodePrecomputed/index.d.ts +2 -0
  31. package/esm/pipeline/transformHtmlCodePrecomputed/index.js +4 -0
  32. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.d.ts +13 -0
  33. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +415 -0
  34. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +304 -47
  35. package/esm/useCode/Pre.js +5 -0
  36. package/esm/useCode/useFileNavigation.js +4 -0
  37. package/esm/withDocsInfra/withDocsInfra.d.ts +12 -1
  38. package/esm/withDocsInfra/withDocsInfra.js +34 -6
  39. package/package.json +6 -4
  40. package/esm/pipeline/loaderUtils/parseImports.d.ts +0 -19
  41. package/esm/pipeline/loaderUtils/parseImports.js +0 -306
  42. package/esm/pipeline/transformHtmlCode/index.d.ts +0 -2
  43. package/esm/pipeline/transformHtmlCode/index.js +0 -4
  44. package/esm/pipeline/transformHtmlCode/transformHtmlCode.d.ts +0 -13
  45. package/esm/pipeline/transformHtmlCode/transformHtmlCode.js +0 -300
@@ -5,15 +5,20 @@ export interface ProcessImportsResult {
5
5
  }
6
6
  /**
7
7
  * Processes imports based on the specified storage mode, automatically handling
8
- * source rewriting when needed (e.g., for 'flat' mode).
8
+ * source rewriting when needed (e.g., for 'flat' mode). Works for both JavaScript and simple file types.
9
9
  *
10
10
  * @param source - The original source code
11
11
  * @param importResult - The result from parseImports
12
- * @param resolvedPathsMap - Map from import paths to resolved file paths
13
12
  * @param storeAt - How to process the imports
13
+ * @param isJsFile - Whether this is a JavaScript file (false = basic processing for CSS/JSON/etc.)
14
+ * @param resolvedPathsMap - Map from import paths to resolved file paths (only needed for JavaScript files)
14
15
  * @returns Object with processed source and extraFiles mapping
15
16
  */
16
17
  export declare function processRelativeImports(source: string, importResult: Record<string, {
17
18
  path: string;
18
19
  names: string[];
19
- }>, resolvedPathsMap: Map<string, string>, storeAt: StoreAtMode): ProcessImportsResult;
20
+ positions?: Array<{
21
+ start: number;
22
+ end: number;
23
+ }>;
24
+ }>, storeAt: StoreAtMode, isJsFile?: boolean, resolvedPathsMap?: Map<string, string>): ProcessImportsResult;
@@ -1,122 +1,9 @@
1
1
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
- import { rewriteImportsToSameDirectory } from "./rewriteImports.js";
4
+ import { rewriteImports } from "./rewriteImports.js";
5
5
  import { isJavaScriptModule } from "./resolveModulePath.js";
6
6
  import { getFileNameFromUrl } from "./getFileNameFromUrl.js";
7
- /**
8
- * Processes imports based on the specified storage mode, automatically handling
9
- * source rewriting when needed (e.g., for 'flat' mode).
10
- *
11
- * @param source - The original source code
12
- * @param importResult - The result from parseImports
13
- * @param resolvedPathsMap - Map from import paths to resolved file paths
14
- * @param storeAt - How to process the imports
15
- * @returns Object with processed source and extraFiles mapping
16
- */
17
- export function processRelativeImports(source, importResult, resolvedPathsMap, storeAt) {
18
- var extraFiles = {};
19
-
20
- // For flat mode, we need to handle naming conflicts intelligently
21
- if (storeAt === 'flat') {
22
- var result = processFlatMode(importResult, resolvedPathsMap);
23
-
24
- // Create import path mapping for rewriting
25
- var importPathMapping = new Map();
26
-
27
- // Build a reverse mapping from resolved paths to extraFiles keys
28
- var resolvedToExtraFile = new Map();
29
- Object.entries(result.extraFiles).forEach(function (_ref) {
30
- var _ref2 = _slicedToArray(_ref, 2),
31
- extraFileKey = _ref2[0],
32
- fileUrl = _ref2[1];
33
- var resolvedPath = fileUrl.replace('file://', '');
34
- resolvedToExtraFile.set(resolvedPath, extraFileKey);
35
- });
36
-
37
- // For each import, find its resolved path and map to the corresponding extraFile key
38
- Object.entries(importResult).forEach(function (_ref3) {
39
- var _ref4 = _slicedToArray(_ref3, 2),
40
- relativePath = _ref4[0],
41
- importInfo = _ref4[1];
42
- var resolvedPath = resolvedPathsMap.get(importInfo.path);
43
- if (resolvedPath) {
44
- var extraFileKey = resolvedToExtraFile.get(resolvedPath);
45
- if (extraFileKey) {
46
- // For JavaScript modules, remove the extension; for other files (CSS, JSON, etc.), keep it
47
- var isJavascriptModule = isJavaScriptModule(relativePath);
48
- var newPath = extraFileKey;
49
- if (isJavascriptModule) {
50
- // Handle TypeScript declaration files (.d.ts) properly
51
- if (newPath.endsWith('.d.ts')) {
52
- newPath = newPath.replace(/\.d\.ts$/, '');
53
- } else {
54
- newPath = newPath.replace(/\.[^/.]+$/, '');
55
- }
56
- }
57
- // For non-JS modules (CSS, JSON, etc.), keep the full path with extension
58
-
59
- importPathMapping.set(relativePath, newPath);
60
- }
61
- }
62
- });
63
-
64
- // Rewrite the source with the mapping
65
- var rewrittenSource = rewriteImportsToSameDirectory(source, importPathMapping);
66
- return {
67
- processedSource: rewrittenSource,
68
- extraFiles: result.extraFiles
69
- };
70
- }
71
-
72
- // Process each import and generate extraFiles for non-flat modes
73
- Object.entries(importResult).forEach(function (_ref5) {
74
- var _ref6 = _slicedToArray(_ref5, 2),
75
- relativePath = _ref6[0],
76
- importInfo = _ref6[1];
77
- var resolvedPath = resolvedPathsMap.get(importInfo.path);
78
- if (resolvedPath) {
79
- var fileExtension = getFileNameFromUrl(resolvedPath).extension;
80
- var isJavascriptModule = isJavaScriptModule(relativePath);
81
- var keyPath;
82
- if (!isJavascriptModule) {
83
- // For static assets (CSS, JSON, etc.), use the original import path as-is since it already has the extension
84
- switch (storeAt) {
85
- case 'canonical':
86
- case 'import':
87
- keyPath = relativePath;
88
- break;
89
- default:
90
- keyPath = relativePath;
91
- }
92
- } else {
93
- // For JS/TS modules, apply the existing logic
94
- switch (storeAt) {
95
- case 'canonical':
96
- // Show the full resolved path including index files when they exist
97
- // e.g., import '../Component' resolved to '/src/Component/index.js'
98
- // becomes extraFiles: { '../Component/index.js': 'file:///src/Component/index.js' }
99
- keyPath = "".concat(relativePath).concat(resolvedPath.endsWith("/index".concat(fileExtension)) ? "/index".concat(fileExtension) : fileExtension);
100
- break;
101
- case 'import':
102
- // Use the original import path with the actual file extension
103
- // e.g., import '../Component' with '/src/Component/index.js'
104
- // becomes extraFiles: { '../Component.js': 'file:///src/Component/index.js' }
105
- keyPath = "".concat(relativePath).concat(fileExtension);
106
- break;
107
- default:
108
- keyPath = "".concat(relativePath).concat(fileExtension);
109
- }
110
- }
111
- extraFiles[keyPath] = "file://".concat(resolvedPath);
112
- }
113
- });
114
- return {
115
- processedSource: source,
116
- extraFiles: extraFiles
117
- };
118
- }
119
-
120
7
  /**
121
8
  * Processes flat mode with intelligent conflict resolution
122
9
  */
@@ -125,10 +12,10 @@ function processFlatMode(importResult, resolvedPathsMap) {
125
12
  var fileMapping = [];
126
13
 
127
14
  // First pass: collect all files and their path segments
128
- Object.entries(importResult).forEach(function (_ref7) {
129
- var _ref8 = _slicedToArray(_ref7, 2),
130
- relativePath = _ref8[0],
131
- importInfo = _ref8[1];
15
+ Object.entries(importResult).forEach(function (_ref) {
16
+ var _ref2 = _slicedToArray(_ref, 2),
17
+ relativePath = _ref2[0],
18
+ importInfo = _ref2[1];
132
19
  var resolvedPath = resolvedPathsMap.get(importInfo.path);
133
20
  if (resolvedPath) {
134
21
  var fileExtension = getFileNameFromUrl(resolvedPath).extension;
@@ -349,4 +236,236 @@ function processFlatMode(importResult, resolvedPathsMap) {
349
236
  // Will be set by caller after rewriting
350
237
  extraFiles: extraFiles
351
238
  };
239
+ }
240
+
241
+ /**
242
+ * Processes imports with basic conflict resolution based on filenames.
243
+ * Used for CSS, JSON, and other simple file types that don't require complex module resolution.
244
+ */
245
+ function processBasicImports(source, importResult, storeAt) {
246
+ var extraFiles = {};
247
+ if (storeAt === 'flat') {
248
+ var finalNames = new Map();
249
+ var usedNames = new Set();
250
+
251
+ // Process each import to determine final names with simple conflict resolution
252
+ Object.entries(importResult).forEach(function (_ref3) {
253
+ var _ref4 = _slicedToArray(_ref3, 2),
254
+ _relativePath = _ref4[0],
255
+ importInfo = _ref4[1];
256
+ var resolvedPath = importInfo.path; // For CSS, this is already resolved by parseImports
257
+ var fileUrl = resolvedPath.startsWith('http') ? resolvedPath : "file://".concat(resolvedPath);
258
+ var _getFileNameFromUrl = getFileNameFromUrl(fileUrl),
259
+ fileName = _getFileNameFromUrl.fileName,
260
+ extension = _getFileNameFromUrl.extension;
261
+ var finalName = fileName;
262
+ var counter = 1;
263
+
264
+ // Handle naming conflicts by appending numbers
265
+ while (usedNames.has(finalName)) {
266
+ var baseName = fileName.replace(extension, '');
267
+ finalName = "".concat(baseName, "-").concat(counter).concat(extension);
268
+ counter += 1;
269
+ }
270
+ usedNames.add(finalName);
271
+ finalNames.set(resolvedPath, finalName);
272
+ });
273
+
274
+ // Create the import path mapping for rewriting
275
+ var importPathMapping = new Map();
276
+ Object.entries(importResult).forEach(function (_ref5) {
277
+ var _ref6 = _slicedToArray(_ref5, 2),
278
+ relativePath = _ref6[0],
279
+ importInfo = _ref6[1];
280
+ var resolvedPath = importInfo.path;
281
+ var finalName = finalNames.get(resolvedPath);
282
+ if (finalName) {
283
+ importPathMapping.set(relativePath, finalName);
284
+ }
285
+ });
286
+
287
+ // Create extraFiles entries
288
+ finalNames.forEach(function (finalName, resolvedPath) {
289
+ var fileUrl = resolvedPath.startsWith('http') ? resolvedPath : "file://".concat(resolvedPath);
290
+ extraFiles["./".concat(finalName)] = fileUrl;
291
+ });
292
+
293
+ // Apply import path replacements using position-based rewriting
294
+ // Only rewrite if positions are available
295
+ var hasPositions = Object.values(importResult).some(function (imp) {
296
+ return imp.positions && imp.positions.length > 0;
297
+ });
298
+ var processedSource = hasPositions ? rewriteImports(source, importPathMapping, importResult) : source;
299
+ return {
300
+ processedSource: processedSource,
301
+ extraFiles: extraFiles
302
+ };
303
+ }
304
+ if (storeAt === 'import') {
305
+ // Create a mapping for import mode: remove ./ prefix from relative paths
306
+ var importModeMapping = new Map();
307
+ Object.keys(importResult).forEach(function (relativePath) {
308
+ if (relativePath.startsWith('./')) {
309
+ importModeMapping.set(relativePath, relativePath.slice(2));
310
+ }
311
+ // Keep other paths (../, absolute URLs) unchanged
312
+ });
313
+
314
+ // Process each import for extraFiles
315
+ Object.entries(importResult).forEach(function (_ref7) {
316
+ var _ref8 = _slicedToArray(_ref7, 2),
317
+ relativePath = _ref8[0],
318
+ importInfo = _ref8[1];
319
+ var resolvedPath = importInfo.path;
320
+ var fileUrl = resolvedPath.startsWith('http') ? resolvedPath : "file://".concat(resolvedPath);
321
+ extraFiles[relativePath] = fileUrl; // Always use original path for extraFiles
322
+ });
323
+
324
+ // Apply import path replacements using position-based rewriting
325
+ // Only rewrite if positions are available
326
+ var _hasPositions = Object.values(importResult).some(function (imp) {
327
+ return imp.positions && imp.positions.length > 0;
328
+ });
329
+ var _processedSource = _hasPositions ? rewriteImports(source, importModeMapping, importResult) : source;
330
+ return {
331
+ processedSource: _processedSource,
332
+ extraFiles: extraFiles
333
+ };
334
+ }
335
+
336
+ // Canonical mode - no rewriting needed
337
+ Object.entries(importResult).forEach(function (_ref9) {
338
+ var _ref0 = _slicedToArray(_ref9, 2),
339
+ relativePath = _ref0[0],
340
+ importInfo = _ref0[1];
341
+ var resolvedPath = importInfo.path;
342
+ var fileUrl = resolvedPath.startsWith('http') ? resolvedPath : "file://".concat(resolvedPath);
343
+ extraFiles[relativePath] = fileUrl; // Use original import path
344
+ });
345
+ return {
346
+ processedSource: source,
347
+ // No rewriting needed for canonical mode
348
+ extraFiles: extraFiles
349
+ };
350
+ }
351
+
352
+ /**
353
+ * Processes JavaScript imports with complex conflict resolution and module handling
354
+ */
355
+ function processJsImports(source, importResult, storeAt, resolvedPathsMap) {
356
+ var extraFiles = {};
357
+ if (storeAt === 'flat') {
358
+ var result = processFlatMode(importResult, resolvedPathsMap);
359
+
360
+ // Build a reverse mapping from resolved paths to extraFiles keys
361
+ var resolvedToExtraFile = new Map();
362
+ Object.entries(result.extraFiles).forEach(function (_ref1) {
363
+ var _ref10 = _slicedToArray(_ref1, 2),
364
+ extraFileKey = _ref10[0],
365
+ fileUrl = _ref10[1];
366
+ var resolvedPath = fileUrl.replace('file://', '');
367
+ resolvedToExtraFile.set(resolvedPath, extraFileKey);
368
+ });
369
+
370
+ // For each import, find its resolved path and map to the corresponding extraFile key
371
+ var importPathMapping = new Map();
372
+ Object.entries(importResult).forEach(function (_ref11) {
373
+ var _ref12 = _slicedToArray(_ref11, 2),
374
+ relativePath = _ref12[0],
375
+ importInfo = _ref12[1];
376
+ var resolvedPath = resolvedPathsMap.get(importInfo.path);
377
+ if (resolvedPath) {
378
+ var extraFileKey = resolvedToExtraFile.get(resolvedPath);
379
+ if (extraFileKey) {
380
+ // For JavaScript modules, remove the extension; for other files (CSS, JSON, etc.), keep it
381
+ var isJavascriptModule = isJavaScriptModule(relativePath);
382
+ var newPath = extraFileKey;
383
+ if (isJavascriptModule) {
384
+ // Handle TypeScript declaration files (.d.ts) properly
385
+ if (newPath.endsWith('.d.ts')) {
386
+ newPath = newPath.replace(/\.d\.ts$/, '');
387
+ } else {
388
+ newPath = newPath.replace(/\.[^/.]+$/, '');
389
+ }
390
+ }
391
+ // For non-JS modules (CSS, JSON, etc.), keep the full path with extension
392
+
393
+ importPathMapping.set(relativePath, newPath);
394
+ }
395
+ }
396
+ });
397
+
398
+ // Apply import path replacements using position-based rewriting
399
+ var processedSource = rewriteImports(source, importPathMapping, importResult);
400
+ return {
401
+ processedSource: processedSource,
402
+ extraFiles: result.extraFiles
403
+ };
404
+ }
405
+
406
+ // Non-flat modes (canonical and import)
407
+ Object.entries(importResult).forEach(function (_ref13) {
408
+ var _ref14 = _slicedToArray(_ref13, 2),
409
+ relativePath = _ref14[0],
410
+ importInfo = _ref14[1];
411
+ var resolved = resolvedPathsMap.get(importInfo.path);
412
+ if (!resolved) {
413
+ return;
414
+ }
415
+ var resolvedPath = resolved;
416
+ var fileExtension = getFileNameFromUrl(resolvedPath).extension;
417
+ var isJavascriptModule = isJavaScriptModule(relativePath);
418
+ var keyPath;
419
+ if (!isJavascriptModule) {
420
+ // For static assets (CSS, JSON, etc.), use the original import path as-is
421
+ keyPath = relativePath;
422
+ } else {
423
+ // For JS/TS modules, apply the existing logic
424
+ switch (storeAt) {
425
+ case 'canonical':
426
+ // Show the full resolved path including index files when they exist
427
+ keyPath = "".concat(relativePath).concat(resolvedPath.endsWith("/index".concat(fileExtension)) ? "/index".concat(fileExtension) : fileExtension);
428
+ break;
429
+ case 'import':
430
+ // Use the original import path with the actual file extension
431
+ keyPath = "".concat(relativePath).concat(fileExtension);
432
+ break;
433
+ default:
434
+ keyPath = "".concat(relativePath).concat(fileExtension);
435
+ }
436
+ }
437
+ var fileUrl = resolvedPath.startsWith('http') ? resolvedPath : "file://".concat(resolvedPath);
438
+ extraFiles[keyPath] = fileUrl;
439
+ });
440
+ return {
441
+ processedSource: source,
442
+ // No rewriting needed for non-flat modes
443
+ extraFiles: extraFiles
444
+ };
445
+ }
446
+
447
+ /**
448
+ * Processes imports based on the specified storage mode, automatically handling
449
+ * source rewriting when needed (e.g., for 'flat' mode). Works for both JavaScript and simple file types.
450
+ *
451
+ * @param source - The original source code
452
+ * @param importResult - The result from parseImports
453
+ * @param storeAt - How to process the imports
454
+ * @param isJsFile - Whether this is a JavaScript file (false = basic processing for CSS/JSON/etc.)
455
+ * @param resolvedPathsMap - Map from import paths to resolved file paths (only needed for JavaScript files)
456
+ * @returns Object with processed source and extraFiles mapping
457
+ */
458
+ export function processRelativeImports(source, importResult, storeAt) {
459
+ var isJsFile = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
460
+ var resolvedPathsMap = arguments.length > 4 ? arguments[4] : undefined;
461
+ if (!isJsFile) {
462
+ // Use basic processing mode for CSS, JSON, and other simple file types
463
+ return processBasicImports(source, importResult, storeAt);
464
+ }
465
+
466
+ // Use complex JavaScript processing mode
467
+ if (!resolvedPathsMap) {
468
+ throw new Error('resolvedPathsMap is required for JavaScript files');
469
+ }
470
+ return processJsImports(source, importResult, storeAt, resolvedPathsMap);
352
471
  }
@@ -1,15 +1,15 @@
1
1
  /**
2
2
  * Default file extensions for JavaScript/TypeScript modules that can be resolved
3
3
  */
4
- export declare const JAVASCRIPT_MODULE_EXTENSIONS: readonly [".ts", ".tsx", ".js", ".jsx", ".d.ts"];
4
+ export declare const JAVASCRIPT_MODULE_EXTENSIONS: readonly [".ts", ".tsx", ".js", ".jsx", ".mdx", ".d.ts"];
5
5
  /**
6
6
  * Extension priority for type-only imports - prioritize .d.ts first
7
7
  */
8
- export declare const TYPE_IMPORT_EXTENSIONS: readonly [".d.ts", ".ts", ".tsx", ".js", ".jsx"];
8
+ export declare const TYPE_IMPORT_EXTENSIONS: readonly [".d.ts", ".ts", ".tsx", ".js", ".jsx", ".mdx"];
9
9
  /**
10
10
  * Extension priority for value imports - standard priority with .d.ts last
11
11
  */
12
- export declare const VALUE_IMPORT_EXTENSIONS: readonly [".ts", ".tsx", ".js", ".jsx", ".d.ts"];
12
+ export declare const VALUE_IMPORT_EXTENSIONS: readonly [".ts", ".tsx", ".js", ".jsx", ".mdx", ".d.ts"];
13
13
  /**
14
14
  * Checks if a file path or import path represents a JavaScript/TypeScript module
15
15
  * @param path - The file path or import path to check
@@ -73,6 +73,10 @@ export declare function resolveImportResult(importResult: Record<string, {
73
73
  path: string;
74
74
  names: string[];
75
75
  includeTypeDefs?: true;
76
+ positions?: Array<{
77
+ start: number;
78
+ end: number;
79
+ }>;
76
80
  }>, readDirectory: DirectoryReader, options?: ResolveModulePathOptions): Promise<Map<string, string>>;
77
81
  /**
78
82
  * Resolves variant paths from a variants object mapping variant names to their file paths.
@@ -34,17 +34,17 @@ function joinPath(basePath) {
34
34
  /**
35
35
  * Default file extensions for JavaScript/TypeScript modules that can be resolved
36
36
  */
37
- export var JAVASCRIPT_MODULE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.d.ts'];
37
+ export var JAVASCRIPT_MODULE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mdx', '.d.ts'];
38
38
 
39
39
  /**
40
40
  * Extension priority for type-only imports - prioritize .d.ts first
41
41
  */
42
- export var TYPE_IMPORT_EXTENSIONS = ['.d.ts', '.ts', '.tsx', '.js', '.jsx'];
42
+ export var TYPE_IMPORT_EXTENSIONS = ['.d.ts', '.ts', '.tsx', '.js', '.jsx', '.mdx'];
43
43
 
44
44
  /**
45
45
  * Extension priority for value imports - standard priority with .d.ts last
46
46
  */
47
- export var VALUE_IMPORT_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.d.ts'];
47
+ export var VALUE_IMPORT_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mdx', '.d.ts'];
48
48
 
49
49
  /**
50
50
  * Checks if a file path or import path represents a JavaScript/TypeScript module
@@ -33,6 +33,10 @@ export declare function resolveImportResultWithFs(importResult: Record<string, {
33
33
  path: string;
34
34
  names: string[];
35
35
  includeTypeDefs?: true;
36
+ positions?: Array<{
37
+ start: number;
38
+ end: number;
39
+ }>;
36
40
  }>, options?: ResolveModulePathOptions): Promise<Map<string, string>>;
37
41
  /**
38
42
  * Resolves variant paths from a variants object mapping variant names to their file paths.
@@ -1,9 +1,16 @@
1
1
  /**
2
- * Rewrites relative imports in source code based on a provided mapping.
3
- * Converts imports like '../utils/helper' or './components/Button' to their mapped equivalents
2
+ * Efficiently rewrites import paths using position data.
3
+ * This avoids regex parsing and uses precise position information for replacement.
4
+ * Works for both JavaScript/TypeScript and CSS imports.
4
5
  *
5
6
  * @param source - The source code to process
6
- * @param importPathMapping - Map from original import paths to new import paths (without extensions)
7
- * @returns The source code with rewritten imports
7
+ * @param importPathMapping - Map from original import paths to new import paths
8
+ * @param importResult - Import result with position data
9
+ * @returns The source code with rewritten import paths
8
10
  */
9
- export declare function rewriteImportsToSameDirectory(source: string, importPathMapping: Map<string, string>): string;
11
+ export declare function rewriteImports(source: string, importPathMapping: Map<string, string>, importResult: Record<string, {
12
+ positions: Array<{
13
+ start: number;
14
+ end: number;
15
+ }>;
16
+ }>): string;
@@ -1,35 +1,65 @@
1
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
1
2
  /**
2
- * Rewrites relative imports in source code based on a provided mapping.
3
- * Converts imports like '../utils/helper' or './components/Button' to their mapped equivalents
3
+ * Interface for rewrite replacement operations.
4
+ */
5
+
6
+ /**
7
+ * Efficiently rewrites import paths using position data.
8
+ * This avoids regex parsing and uses precise position information for replacement.
9
+ * Works for both JavaScript/TypeScript and CSS imports.
4
10
  *
5
11
  * @param source - The source code to process
6
- * @param importPathMapping - Map from original import paths to new import paths (without extensions)
7
- * @returns The source code with rewritten imports
12
+ * @param importPathMapping - Map from original import paths to new import paths
13
+ * @param importResult - Import result with position data
14
+ * @returns The source code with rewritten import paths
8
15
  */
9
- export function rewriteImportsToSameDirectory(source, importPathMapping) {
10
- // Handle both types of imports:
11
- // 1. import [something] from 'path' (including import type)
12
- // 2. import 'path' (side-effect imports like CSS)
16
+ export function rewriteImports(source, importPathMapping, importResult) {
17
+ var replacements = [];
13
18
 
14
- return source.replace(/import\s+((?:type\s+)?(?:\w+|\*\s+as\s+\w+|{[^}]+})\s+from\s+)['"]([^'"]+)['"]/g, function (match, importPart, modulePath) {
15
- // Only process relative imports
16
- if (modulePath.startsWith('.')) {
17
- // Check if we have a mapping for this import path
18
- if (importPathMapping.has(modulePath)) {
19
- var newPath = importPathMapping.get(modulePath);
20
- return "import ".concat(importPart, "'").concat(newPath, "'");
21
- }
22
- }
23
- return match;
24
- }).replace(/import\s+['"]([^'"]+)['"]/g, function (match, modulePath) {
25
- // Only process relative imports
26
- if (modulePath.startsWith('.')) {
27
- // Check if we have a mapping for this import path
28
- if (importPathMapping.has(modulePath)) {
29
- var newPath = importPathMapping.get(modulePath);
30
- return "import '".concat(newPath, "'");
19
+ // Use precise position-based replacement
20
+ importPathMapping.forEach(function (newPath, originalPath) {
21
+ var _importResult$origina;
22
+ var positions = (_importResult$origina = importResult[originalPath]) == null ? void 0 : _importResult$origina.positions;
23
+ if (positions && positions.length > 0) {
24
+ // Process all positions where this import path appears
25
+ var _iterator = _createForOfIteratorHelper(positions),
26
+ _step;
27
+ try {
28
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
29
+ var position = _step.value;
30
+ // Validate position bounds
31
+ if (position.start >= 0 && position.end <= source.length && position.start < position.end) {
32
+ // The positions include the quotes, so we need to preserve them
33
+ var originalText = source.slice(position.start, position.end);
34
+ if (originalText.length > 0) {
35
+ var quote = originalText.charAt(0); // Get the original quote character
36
+ var newText = "".concat(quote).concat(newPath).concat(quote);
37
+ replacements.push({
38
+ start: position.start,
39
+ end: position.end,
40
+ newText: newText
41
+ });
42
+ }
43
+ }
44
+ }
45
+ } catch (err) {
46
+ _iterator.e(err);
47
+ } finally {
48
+ _iterator.f();
31
49
  }
32
50
  }
33
- return match;
34
51
  });
52
+
53
+ // Sort replacements by position (descending) to avoid position shifts
54
+ replacements.sort(function (a, b) {
55
+ return b.start - a.start;
56
+ });
57
+
58
+ // Apply replacements from right to left
59
+ var result = source;
60
+ for (var _i = 0, _replacements = replacements; _i < _replacements.length; _i++) {
61
+ var replacement = _replacements[_i];
62
+ result = result.slice(0, replacement.start) + replacement.newText + result.slice(replacement.end);
63
+ }
64
+ return result;
35
65
  }
@@ -0,0 +1,2 @@
1
+ import { transformHtmlCodePrecomputed } from "./transformHtmlCodePrecomputed.js";
2
+ export default transformHtmlCodePrecomputed;
@@ -0,0 +1,4 @@
1
+ // This is the export format expected by a remark plugin.
2
+
3
+ import { transformHtmlCodePrecomputed } from "./transformHtmlCodePrecomputed.js";
4
+ export default transformHtmlCodePrecomputed;
@@ -0,0 +1,13 @@
1
+ import type { Plugin } from 'unified';
2
+ /**
3
+ * Rehype plugin that transforms semantic HTML code structures to use loadVariant
4
+ *
5
+ * This plugin:
6
+ * 1. Finds section and dl elements in the HTML AST
7
+ * 2. Extracts code elements from the semantic structure (figure/dl/dd/pre/code)
8
+ * 3. Creates variants from multiple code elements or single Default variant
9
+ * 4. Uses loadVariant to process each variant
10
+ * 5. Stores the combined precompute data on the root element
11
+ * 6. Clears all code element contents and replaces with error message
12
+ */
13
+ export declare const transformHtmlCodePrecomputed: Plugin;