@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.
- package/CHANGELOG.md +9 -0
- package/README.md +3 -11
- package/esm/CodeControllerContext/CodeControllerContext.d.ts +62 -0
- package/esm/CodeControllerContext/CodeControllerContext.js +33 -0
- package/esm/CodeControllerContext/index.d.ts +1 -0
- package/esm/CodeControllerContext/index.js +1 -0
- package/esm/CodeExternalsContext/CodeExternalsContext.d.ts +8 -0
- package/esm/CodeExternalsContext/CodeExternalsContext.js +8 -0
- package/esm/CodeExternalsContext/index.d.ts +1 -0
- package/esm/CodeExternalsContext/index.js +1 -0
- package/esm/CodeHighlighter/CodeHighlighter.d.ts +2 -0
- package/esm/CodeHighlighter/CodeHighlighter.js +441 -0
- package/esm/CodeHighlighter/CodeHighlighterClient.d.ts +2 -0
- package/esm/CodeHighlighter/CodeHighlighterClient.js +984 -0
- package/esm/CodeHighlighter/CodeHighlighterContext.d.ts +16 -0
- package/esm/CodeHighlighter/CodeHighlighterContext.js +15 -0
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.d.ts +7 -0
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +14 -0
- package/esm/CodeHighlighter/addPathsToVariant.d.ts +14 -0
- package/esm/CodeHighlighter/addPathsToVariant.js +68 -0
- package/esm/CodeHighlighter/applyTransform.d.ts +19 -0
- package/esm/CodeHighlighter/applyTransform.js +75 -0
- package/esm/CodeHighlighter/calculateMainFilePath.d.ts +1 -0
- package/esm/CodeHighlighter/calculateMainFilePath.js +108 -0
- package/esm/CodeHighlighter/codeToFallbackProps.d.ts +2 -0
- package/esm/CodeHighlighter/codeToFallbackProps.js +73 -0
- package/esm/CodeHighlighter/errors.d.ts +141 -0
- package/esm/CodeHighlighter/errors.js +441 -0
- package/esm/CodeHighlighter/examineVariant.d.ts +25 -0
- package/esm/CodeHighlighter/examineVariant.js +73 -0
- package/esm/CodeHighlighter/hasAllVariants.d.ts +27 -0
- package/esm/CodeHighlighter/hasAllVariants.js +63 -0
- package/esm/CodeHighlighter/index.d.ts +1 -0
- package/esm/CodeHighlighter/index.js +1 -0
- package/esm/CodeHighlighter/loadFallbackCode.d.ts +10 -0
- package/esm/CodeHighlighter/loadFallbackCode.js +679 -0
- package/esm/CodeHighlighter/loadVariant.d.ts +12 -0
- package/esm/CodeHighlighter/loadVariant.js +1044 -0
- package/esm/CodeHighlighter/maybeInitialData.d.ts +108 -0
- package/esm/CodeHighlighter/maybeInitialData.js +192 -0
- package/esm/CodeHighlighter/mergeMetadata.d.ts +40 -0
- package/esm/CodeHighlighter/mergeMetadata.js +165 -0
- package/esm/CodeHighlighter/parseCode.d.ts +6 -0
- package/esm/CodeHighlighter/parseCode.js +134 -0
- package/esm/CodeHighlighter/parseControlledCode.d.ts +6 -0
- package/esm/CodeHighlighter/parseControlledCode.js +87 -0
- package/esm/CodeHighlighter/pathUtils.d.ts +120 -0
- package/esm/CodeHighlighter/pathUtils.js +258 -0
- package/esm/CodeHighlighter/transformCode.d.ts +21 -0
- package/esm/CodeHighlighter/transformCode.js +251 -0
- package/esm/CodeHighlighter/transformParsedSource.d.ts +3 -0
- package/esm/CodeHighlighter/transformParsedSource.js +60 -0
- package/esm/CodeHighlighter/transformSource.d.ts +2 -0
- package/esm/CodeHighlighter/transformSource.js +103 -0
- package/esm/CodeHighlighter/types.d.ts +276 -0
- package/esm/CodeHighlighter/types.js +1 -0
- package/esm/CodeProvider/CodeContext.d.ts +31 -0
- package/esm/CodeProvider/CodeContext.js +12 -0
- package/esm/CodeProvider/CodeProvider.d.ts +13 -0
- package/esm/CodeProvider/CodeProvider.js +83 -0
- package/esm/CodeProvider/index.d.ts +1 -0
- package/esm/CodeProvider/index.js +1 -0
- package/esm/abstractCreateDemo/abstractCreateDemo.d.ts +45 -0
- package/esm/abstractCreateDemo/abstractCreateDemo.js +100 -0
- package/esm/abstractCreateDemo/index.d.ts +1 -0
- package/esm/abstractCreateDemo/index.js +1 -0
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.d.ts +32 -0
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +52 -0
- package/esm/abstractCreateDemoClient/index.d.ts +1 -0
- package/esm/abstractCreateDemoClient/index.js +1 -0
- package/esm/createDemoData/createDemoData.d.ts +44 -0
- package/esm/createDemoData/createDemoData.js +74 -0
- package/esm/createDemoData/index.d.ts +1 -0
- package/esm/createDemoData/index.js +1 -0
- package/esm/createDemoData/types.d.ts +25 -0
- package/esm/createDemoData/types.js +1 -0
- package/esm/pipeline/hastUtils/hastUtils.d.ts +11 -0
- package/esm/pipeline/hastUtils/hastUtils.js +67 -0
- package/esm/pipeline/hastUtils/index.d.ts +1 -0
- package/esm/pipeline/hastUtils/index.js +1 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/index.d.ts +2 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/index.js +4 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +14 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +178 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +47 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +849 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.d.ts +85 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +715 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts +14 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +73 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.d.ts +11 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +203 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.d.ts +6 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +23 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.d.ts +6 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +148 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.d.ts +9 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +198 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.d.ts +2 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.js +4 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.d.ts +5 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +21 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.d.ts +15 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +233 -0
- package/esm/pipeline/loadServerCodeMeta/index.d.ts +1 -0
- package/esm/pipeline/loadServerCodeMeta/index.js +1 -0
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts +24 -0
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +90 -0
- package/esm/pipeline/loadServerSource/index.d.ts +1 -0
- package/esm/pipeline/loadServerSource/index.js +1 -0
- package/esm/pipeline/loadServerSource/loadServerSource.d.ts +25 -0
- package/esm/pipeline/loadServerSource/loadServerSource.js +134 -0
- package/esm/pipeline/loaderUtils/externalsToPackages.d.ts +1 -0
- package/esm/pipeline/loaderUtils/externalsToPackages.js +46 -0
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.d.ts +34 -0
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +161 -0
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.d.ts +12 -0
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +66 -0
- package/esm/pipeline/loaderUtils/index.d.ts +7 -0
- package/esm/pipeline/loaderUtils/index.js +7 -0
- package/esm/pipeline/loaderUtils/mergeExternals.d.ts +32 -0
- package/esm/pipeline/loaderUtils/mergeExternals.js +72 -0
- package/esm/pipeline/loaderUtils/parseImports.d.ts +19 -0
- package/esm/pipeline/loaderUtils/parseImports.js +306 -0
- package/esm/pipeline/loaderUtils/processRelativeImports.d.ts +19 -0
- package/esm/pipeline/loaderUtils/processRelativeImports.js +352 -0
- package/esm/pipeline/loaderUtils/resolveModulePath.d.ts +87 -0
- package/esm/pipeline/loaderUtils/resolveModulePath.js +1435 -0
- package/esm/pipeline/loaderUtils/resolveModulePathWithFs.d.ts +47 -0
- package/esm/pipeline/loaderUtils/resolveModulePathWithFs.js +150 -0
- package/esm/pipeline/loaderUtils/rewriteImports.d.ts +9 -0
- package/esm/pipeline/loaderUtils/rewriteImports.js +35 -0
- package/esm/pipeline/parseSource/addLineGutters.d.ts +9 -0
- package/esm/pipeline/parseSource/addLineGutters.js +181 -0
- package/esm/pipeline/parseSource/grammars.d.ts +2 -0
- package/esm/pipeline/parseSource/grammars.js +27 -0
- package/esm/pipeline/parseSource/index.d.ts +1 -0
- package/esm/pipeline/parseSource/index.js +1 -0
- package/esm/pipeline/parseSource/parseSource.d.ts +3 -0
- package/esm/pipeline/parseSource/parseSource.js +51 -0
- package/esm/pipeline/transformHtmlCode/index.d.ts +2 -0
- package/esm/pipeline/transformHtmlCode/index.js +4 -0
- package/esm/pipeline/transformHtmlCode/transformHtmlCode.d.ts +13 -0
- package/esm/pipeline/transformHtmlCode/transformHtmlCode.js +300 -0
- package/esm/pipeline/transformMarkdownCode/index.d.ts +2 -0
- package/esm/pipeline/transformMarkdownCode/index.js +4 -0
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.d.ts +2 -0
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +514 -0
- package/esm/pipeline/transformTypescriptToJavascript/index.d.ts +1 -0
- package/esm/pipeline/transformTypescriptToJavascript/index.js +1 -0
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.d.ts +13 -0
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +131 -0
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.d.ts +3 -0
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +31 -0
- package/esm/useCode/Pre.d.ts +15 -0
- package/esm/useCode/Pre.js +164 -0
- package/esm/useCode/index.d.ts +1 -0
- package/esm/useCode/index.js +1 -0
- package/esm/useCode/useCode.d.ts +41 -0
- package/esm/useCode/useCode.js +128 -0
- package/esm/useCode/useCodeUtils.d.ts +44 -0
- package/esm/useCode/useCodeUtils.js +245 -0
- package/esm/useCode/useCopyFunctionality.d.ts +18 -0
- package/esm/useCode/useCopyFunctionality.js +28 -0
- package/esm/useCode/useFileNavigation.d.ts +41 -0
- package/esm/useCode/useFileNavigation.js +453 -0
- package/esm/useCode/useSourceEditing.d.ts +21 -0
- package/esm/useCode/useSourceEditing.js +32 -0
- package/esm/useCode/useTransformManagement.d.ts +30 -0
- package/esm/useCode/useTransformManagement.js +72 -0
- package/esm/useCode/useUIState.d.ts +16 -0
- package/esm/useCode/useUIState.js +21 -0
- package/esm/useCode/useVariantSelection.d.ts +23 -0
- package/esm/useCode/useVariantSelection.js +75 -0
- package/esm/useCopier/index.d.ts +1 -1
- package/esm/useCopier/index.js +5 -5
- package/esm/useDemo/createCodeSandbox.d.ts +15 -0
- package/esm/useDemo/createCodeSandbox.js +42 -0
- package/esm/useDemo/createStackBlitz.d.ts +22 -0
- package/esm/useDemo/createStackBlitz.js +38 -0
- package/esm/useDemo/exportVariant.d.ts +184 -0
- package/esm/useDemo/exportVariant.js +422 -0
- package/esm/useDemo/exportVariantAsCra.d.ts +15 -0
- package/esm/useDemo/exportVariantAsCra.js +57 -0
- package/esm/useDemo/flattenVariant.d.ts +19 -0
- package/esm/useDemo/flattenVariant.js +49 -0
- package/esm/useDemo/index.d.ts +6 -51
- package/esm/useDemo/index.js +6 -104
- package/esm/useDemo/useDemo.d.ts +81 -0
- package/esm/useDemo/useDemo.js +193 -0
- package/esm/useErrors/ErrorsContext.d.ts +6 -0
- package/esm/useErrors/ErrorsContext.js +8 -0
- package/esm/useErrors/index.d.ts +1 -0
- package/esm/useErrors/index.js +1 -0
- package/esm/useErrors/useErrors.d.ts +5 -0
- package/esm/useErrors/useErrors.js +7 -0
- package/esm/useLocalStorageState/index.d.ts +2 -0
- package/esm/useLocalStorageState/index.js +2 -0
- package/esm/useLocalStorageState/useLocalStorageState.d.ts +14 -0
- package/esm/useLocalStorageState/useLocalStorageState.js +128 -0
- package/esm/usePreference/PreferencesProvider.d.ts +6 -0
- package/esm/usePreference/PreferencesProvider.js +8 -0
- package/esm/usePreference/index.d.ts +2 -0
- package/esm/usePreference/index.js +2 -0
- package/esm/usePreference/usePreference.d.ts +2 -0
- package/esm/usePreference/usePreference.js +25 -0
- package/esm/useUrlHashState/index.d.ts +1 -0
- package/esm/useUrlHashState/index.js +1 -0
- package/esm/useUrlHashState/useUrlHashState.d.ts +5 -0
- package/esm/useUrlHashState/useUrlHashState.js +68 -0
- package/esm/withDocsInfra/index.d.ts +1 -0
- package/esm/withDocsInfra/index.js +1 -0
- package/esm/withDocsInfra/withDocsInfra.d.ts +82 -0
- package/esm/withDocsInfra/withDocsInfra.js +147 -0
- package/package.json +178 -11
- package/esm/useCopier/index.d.ts.map +0 -1
- package/esm/useDemo/index.d.ts.map +0 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type DirectoryEntry, type DirectoryReader, type ResolveModulePathOptions, type TypeAwareResolveResult } from "./resolveModulePath.js";
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a module path using Node.js filesystem APIs.
|
|
4
|
+
* This is a convenience wrapper around the generic resolveModulePath function.
|
|
5
|
+
*
|
|
6
|
+
* @param modulePath - The module path to resolve (without file extension)
|
|
7
|
+
* @param options - Configuration options
|
|
8
|
+
* @param includeTypeDefs - If true, returns both import and typeImport paths with different extension priorities
|
|
9
|
+
* @returns Promise<string | TypeAwareResolveResult> - The resolved file path(s), or throws if not found
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveModulePathWithFs(modulePath: string, options?: ResolveModulePathOptions): Promise<string>;
|
|
12
|
+
export declare function resolveModulePathWithFs(modulePath: string, options: ResolveModulePathOptions, includeTypeDefs: true): Promise<TypeAwareResolveResult>;
|
|
13
|
+
/**
|
|
14
|
+
* Resolves multiple module paths using Node.js filesystem APIs.
|
|
15
|
+
* This is a convenience wrapper around the generic resolveModulePaths function.
|
|
16
|
+
*
|
|
17
|
+
* @param modulePaths - Array of module paths to resolve (without file extensions)
|
|
18
|
+
* @param options - Configuration options
|
|
19
|
+
* @returns Promise<Map<string, string>> - Map from input path to resolved file path
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveModulePathsWithFs(modulePaths: string[], options?: ResolveModulePathOptions): Promise<Map<string, string>>;
|
|
22
|
+
/**
|
|
23
|
+
* Resolves import result by separating JavaScript modules from static assets,
|
|
24
|
+
* only resolving JavaScript modules and returning a combined map.
|
|
25
|
+
* This is a convenience wrapper around the generic resolveImportResult function
|
|
26
|
+
* that uses Node.js filesystem APIs.
|
|
27
|
+
*
|
|
28
|
+
* @param importResult - The result from parseImports containing all imports
|
|
29
|
+
* @param options - Configuration options for module resolution
|
|
30
|
+
* @returns Promise<Map<string, string>> - Map from import path to resolved file path
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolveImportResultWithFs(importResult: Record<string, {
|
|
33
|
+
path: string;
|
|
34
|
+
names: string[];
|
|
35
|
+
includeTypeDefs?: true;
|
|
36
|
+
}>, options?: ResolveModulePathOptions): Promise<Map<string, string>>;
|
|
37
|
+
/**
|
|
38
|
+
* Resolves variant paths from a variants object mapping variant names to their file paths.
|
|
39
|
+
* This is a convenience wrapper around the generic resolveVariantPaths function
|
|
40
|
+
* that uses Node.js filesystem APIs.
|
|
41
|
+
*
|
|
42
|
+
* @param variants - Object mapping variant names to their file paths
|
|
43
|
+
* @param options - Configuration options for module resolution
|
|
44
|
+
* @returns Promise<Map<string, string>> - Map from variant name to resolved file URL
|
|
45
|
+
*/
|
|
46
|
+
export declare function resolveVariantPathsWithFs(variants: Record<string, string>, options?: ResolveModulePathOptions): Promise<Map<string, string>>;
|
|
47
|
+
export type { DirectoryEntry, DirectoryReader, ResolveModulePathOptions };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
+
// webpack does not like node: imports
|
|
4
|
+
// eslint-disable-next-line n/prefer-node-protocol
|
|
5
|
+
import { readdir } from 'fs/promises';
|
|
6
|
+
import { resolveModulePath, resolveModulePaths, resolveImportResult, resolveVariantPaths } from "./resolveModulePath.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Node.js filesystem-based directory reader that converts Dirent objects
|
|
10
|
+
* to the DirectoryEntry interface expected by the resolver functions.
|
|
11
|
+
*/
|
|
12
|
+
var nodeDirectoryReader = /*#__PURE__*/function () {
|
|
13
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(path) {
|
|
14
|
+
var entries;
|
|
15
|
+
return _regenerator().w(function (_context) {
|
|
16
|
+
while (1) switch (_context.n) {
|
|
17
|
+
case 0:
|
|
18
|
+
_context.n = 1;
|
|
19
|
+
return readdir(path, {
|
|
20
|
+
withFileTypes: true
|
|
21
|
+
});
|
|
22
|
+
case 1:
|
|
23
|
+
entries = _context.v;
|
|
24
|
+
return _context.a(2, entries.map(function (entry) {
|
|
25
|
+
return {
|
|
26
|
+
name: entry.name,
|
|
27
|
+
isFile: entry.isFile(),
|
|
28
|
+
isDirectory: entry.isDirectory()
|
|
29
|
+
};
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
}, _callee);
|
|
33
|
+
}));
|
|
34
|
+
return function nodeDirectoryReader(_x) {
|
|
35
|
+
return _ref.apply(this, arguments);
|
|
36
|
+
};
|
|
37
|
+
}();
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Resolves a module path using Node.js filesystem APIs.
|
|
41
|
+
* This is a convenience wrapper around the generic resolveModulePath function.
|
|
42
|
+
*
|
|
43
|
+
* @param modulePath - The module path to resolve (without file extension)
|
|
44
|
+
* @param options - Configuration options
|
|
45
|
+
* @param includeTypeDefs - If true, returns both import and typeImport paths with different extension priorities
|
|
46
|
+
* @returns Promise<string | TypeAwareResolveResult> - The resolved file path(s), or throws if not found
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
export function resolveModulePathWithFs(_x2) {
|
|
50
|
+
return _resolveModulePathWithFs.apply(this, arguments);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Resolves multiple module paths using Node.js filesystem APIs.
|
|
55
|
+
* This is a convenience wrapper around the generic resolveModulePaths function.
|
|
56
|
+
*
|
|
57
|
+
* @param modulePaths - Array of module paths to resolve (without file extensions)
|
|
58
|
+
* @param options - Configuration options
|
|
59
|
+
* @returns Promise<Map<string, string>> - Map from input path to resolved file path
|
|
60
|
+
*/
|
|
61
|
+
function _resolveModulePathWithFs() {
|
|
62
|
+
_resolveModulePathWithFs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(modulePath) {
|
|
63
|
+
var options,
|
|
64
|
+
includeTypeDefs,
|
|
65
|
+
_args2 = arguments;
|
|
66
|
+
return _regenerator().w(function (_context2) {
|
|
67
|
+
while (1) switch (_context2.n) {
|
|
68
|
+
case 0:
|
|
69
|
+
options = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
|
|
70
|
+
includeTypeDefs = _args2.length > 2 ? _args2[2] : undefined;
|
|
71
|
+
return _context2.a(2, resolveModulePath(modulePath, nodeDirectoryReader, options, includeTypeDefs));
|
|
72
|
+
}
|
|
73
|
+
}, _callee2);
|
|
74
|
+
}));
|
|
75
|
+
return _resolveModulePathWithFs.apply(this, arguments);
|
|
76
|
+
}
|
|
77
|
+
export function resolveModulePathsWithFs(_x3) {
|
|
78
|
+
return _resolveModulePathsWithFs.apply(this, arguments);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Resolves import result by separating JavaScript modules from static assets,
|
|
83
|
+
* only resolving JavaScript modules and returning a combined map.
|
|
84
|
+
* This is a convenience wrapper around the generic resolveImportResult function
|
|
85
|
+
* that uses Node.js filesystem APIs.
|
|
86
|
+
*
|
|
87
|
+
* @param importResult - The result from parseImports containing all imports
|
|
88
|
+
* @param options - Configuration options for module resolution
|
|
89
|
+
* @returns Promise<Map<string, string>> - Map from import path to resolved file path
|
|
90
|
+
*/
|
|
91
|
+
function _resolveModulePathsWithFs() {
|
|
92
|
+
_resolveModulePathsWithFs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(modulePaths) {
|
|
93
|
+
var options,
|
|
94
|
+
_args3 = arguments;
|
|
95
|
+
return _regenerator().w(function (_context3) {
|
|
96
|
+
while (1) switch (_context3.n) {
|
|
97
|
+
case 0:
|
|
98
|
+
options = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
|
|
99
|
+
return _context3.a(2, resolveModulePaths(modulePaths, nodeDirectoryReader, options));
|
|
100
|
+
}
|
|
101
|
+
}, _callee3);
|
|
102
|
+
}));
|
|
103
|
+
return _resolveModulePathsWithFs.apply(this, arguments);
|
|
104
|
+
}
|
|
105
|
+
export function resolveImportResultWithFs(_x4) {
|
|
106
|
+
return _resolveImportResultWithFs.apply(this, arguments);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Resolves variant paths from a variants object mapping variant names to their file paths.
|
|
111
|
+
* This is a convenience wrapper around the generic resolveVariantPaths function
|
|
112
|
+
* that uses Node.js filesystem APIs.
|
|
113
|
+
*
|
|
114
|
+
* @param variants - Object mapping variant names to their file paths
|
|
115
|
+
* @param options - Configuration options for module resolution
|
|
116
|
+
* @returns Promise<Map<string, string>> - Map from variant name to resolved file URL
|
|
117
|
+
*/
|
|
118
|
+
function _resolveImportResultWithFs() {
|
|
119
|
+
_resolveImportResultWithFs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(importResult) {
|
|
120
|
+
var options,
|
|
121
|
+
_args4 = arguments;
|
|
122
|
+
return _regenerator().w(function (_context4) {
|
|
123
|
+
while (1) switch (_context4.n) {
|
|
124
|
+
case 0:
|
|
125
|
+
options = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
|
|
126
|
+
return _context4.a(2, resolveImportResult(importResult, nodeDirectoryReader, options));
|
|
127
|
+
}
|
|
128
|
+
}, _callee4);
|
|
129
|
+
}));
|
|
130
|
+
return _resolveImportResultWithFs.apply(this, arguments);
|
|
131
|
+
}
|
|
132
|
+
export function resolveVariantPathsWithFs(_x5) {
|
|
133
|
+
return _resolveVariantPathsWithFs.apply(this, arguments);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Re-export types for convenience
|
|
137
|
+
function _resolveVariantPathsWithFs() {
|
|
138
|
+
_resolveVariantPathsWithFs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(variants) {
|
|
139
|
+
var options,
|
|
140
|
+
_args5 = arguments;
|
|
141
|
+
return _regenerator().w(function (_context5) {
|
|
142
|
+
while (1) switch (_context5.n) {
|
|
143
|
+
case 0:
|
|
144
|
+
options = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
|
|
145
|
+
return _context5.a(2, resolveVariantPaths(variants, nodeDirectoryReader, options));
|
|
146
|
+
}
|
|
147
|
+
}, _callee5);
|
|
148
|
+
}));
|
|
149
|
+
return _resolveVariantPathsWithFs.apply(this, arguments);
|
|
150
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
|
4
|
+
*
|
|
5
|
+
* @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
|
|
8
|
+
*/
|
|
9
|
+
export declare function rewriteImportsToSameDirectory(source: string, importPathMapping: Map<string, string>): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
|
4
|
+
*
|
|
5
|
+
* @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
|
|
8
|
+
*/
|
|
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)
|
|
13
|
+
|
|
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, "'");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return match;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Root } from 'hast';
|
|
2
|
+
/**
|
|
3
|
+
* Counts the number of lines in a HAST tree without mutating it.
|
|
4
|
+
* Uses the same logic as starryNightGutter but only returns the count.
|
|
5
|
+
* @param tree - The HAST tree to count lines in
|
|
6
|
+
* @returns The number of lines in the tree
|
|
7
|
+
*/
|
|
8
|
+
export declare function countLines(tree: Root): number;
|
|
9
|
+
export declare function starryNightGutter(tree: Root, sourceLines?: string[], frameSize?: number): void;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
+
// Example copied from https://github.com/wooorm/starry-night#example-adding-line-numbers
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Counts the number of lines in a HAST tree without mutating it.
|
|
6
|
+
* Uses the same logic as starryNightGutter but only returns the count.
|
|
7
|
+
* @param tree - The HAST tree to count lines in
|
|
8
|
+
* @returns The number of lines in the tree
|
|
9
|
+
*/
|
|
10
|
+
export function countLines(tree) {
|
|
11
|
+
var search = /\r?\n|\r/g;
|
|
12
|
+
var index = -1;
|
|
13
|
+
var start = 0;
|
|
14
|
+
var startTextRemainder = '';
|
|
15
|
+
var lineNumber = 0;
|
|
16
|
+
while (index + 1 < tree.children.length) {
|
|
17
|
+
index += 1;
|
|
18
|
+
var child = tree.children[index];
|
|
19
|
+
if (child.type === 'text') {
|
|
20
|
+
var textStart = 0;
|
|
21
|
+
var match = search.exec(child.value);
|
|
22
|
+
while (match) {
|
|
23
|
+
lineNumber += 1;
|
|
24
|
+
start = index + 1;
|
|
25
|
+
textStart = match.index + match[0].length;
|
|
26
|
+
match = search.exec(child.value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// If we matched, make sure to not drop the text after the last line ending.
|
|
30
|
+
if (start === index + 1) {
|
|
31
|
+
startTextRemainder = child.value.slice(textStart);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Check if we have remaining content to process as a line
|
|
37
|
+
if (start < tree.children.length || startTextRemainder) {
|
|
38
|
+
lineNumber += 1;
|
|
39
|
+
}
|
|
40
|
+
return lineNumber;
|
|
41
|
+
}
|
|
42
|
+
export function starryNightGutter(tree, sourceLines) {
|
|
43
|
+
var frameSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 120;
|
|
44
|
+
/** @type {Array<RootContent>} */
|
|
45
|
+
var replacement = [];
|
|
46
|
+
var search = /\r?\n|\r/g;
|
|
47
|
+
var index = -1;
|
|
48
|
+
var start = 0;
|
|
49
|
+
var startTextRemainder = '';
|
|
50
|
+
var lineNumber = 0;
|
|
51
|
+
var frameLines = [];
|
|
52
|
+
var frameStartLine = 1; // Track the starting line number for the current frame
|
|
53
|
+
|
|
54
|
+
while (index + 1 < tree.children.length) {
|
|
55
|
+
index += 1;
|
|
56
|
+
var child = tree.children[index];
|
|
57
|
+
if (child.type === 'text') {
|
|
58
|
+
var textStart = 0;
|
|
59
|
+
var match = search.exec(child.value);
|
|
60
|
+
while (match) {
|
|
61
|
+
// Nodes in this line.
|
|
62
|
+
var _line = tree.children.slice(start, index);
|
|
63
|
+
|
|
64
|
+
// Prepend text from a partial matched earlier text.
|
|
65
|
+
if (startTextRemainder) {
|
|
66
|
+
_line.unshift({
|
|
67
|
+
type: 'text',
|
|
68
|
+
value: startTextRemainder
|
|
69
|
+
});
|
|
70
|
+
startTextRemainder = '';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Append text from this text.
|
|
74
|
+
if (match.index > textStart) {
|
|
75
|
+
_line.push({
|
|
76
|
+
type: 'text',
|
|
77
|
+
value: child.value.slice(textStart, match.index)
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Add a line, and the eol.
|
|
82
|
+
lineNumber += 1;
|
|
83
|
+
frameLines.push(createLine(_line, lineNumber), {
|
|
84
|
+
type: 'text',
|
|
85
|
+
value: match[0]
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Check if we need to create a frame (only if sourceLines provided, otherwise keep everything in one frame)
|
|
89
|
+
if (sourceLines && lineNumber % frameSize === 0) {
|
|
90
|
+
replacement.push(createFrame(frameLines, sourceLines, frameStartLine, lineNumber));
|
|
91
|
+
frameLines = [];
|
|
92
|
+
frameStartLine = lineNumber + 1;
|
|
93
|
+
}
|
|
94
|
+
start = index + 1;
|
|
95
|
+
textStart = match.index + match[0].length;
|
|
96
|
+
match = search.exec(child.value);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// If we matched, make sure to not drop the text after the last line ending.
|
|
100
|
+
if (start === index + 1) {
|
|
101
|
+
startTextRemainder = child.value.slice(textStart);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
var line = tree.children.slice(start);
|
|
106
|
+
// Prepend text from a partial matched earlier text.
|
|
107
|
+
if (startTextRemainder) {
|
|
108
|
+
line.unshift({
|
|
109
|
+
type: 'text',
|
|
110
|
+
value: startTextRemainder
|
|
111
|
+
});
|
|
112
|
+
startTextRemainder = '';
|
|
113
|
+
}
|
|
114
|
+
if (line.length > 0) {
|
|
115
|
+
lineNumber += 1;
|
|
116
|
+
frameLines.push(createLine(line, lineNumber));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Add any remaining lines as the final frame
|
|
120
|
+
if (frameLines.length > 0) {
|
|
121
|
+
replacement.push(createFrame(frameLines, sourceLines, frameStartLine, lineNumber));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// If there are multiple frames and sourceLines provided, add dataAsString to each frame
|
|
125
|
+
if (replacement.length > 1 && sourceLines) {
|
|
126
|
+
var _iterator = _createForOfIteratorHelper(replacement),
|
|
127
|
+
_step;
|
|
128
|
+
try {
|
|
129
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
130
|
+
var _frame$properties;
|
|
131
|
+
var frame = _step.value;
|
|
132
|
+
if (frame.type === 'element' && frame.tagName === 'span' && ((_frame$properties = frame.properties) == null ? void 0 : _frame$properties.className) === 'frame' && typeof frame.properties.frameStartLine === 'number' && typeof frame.properties.frameEndLine === 'number') {
|
|
133
|
+
var startLine = frame.properties.frameStartLine - 1; // Convert to 0-based index
|
|
134
|
+
var endLine = frame.properties.frameEndLine; // This is already inclusive
|
|
135
|
+
frame.properties.dataAsString = sourceLines.slice(startLine, endLine).join('\n');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} catch (err) {
|
|
139
|
+
_iterator.e(err);
|
|
140
|
+
} finally {
|
|
141
|
+
_iterator.f();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Replace children with new array.
|
|
146
|
+
tree.children = replacement;
|
|
147
|
+
|
|
148
|
+
// Add total line count to root data
|
|
149
|
+
if (!tree.data) {
|
|
150
|
+
tree.data = {};
|
|
151
|
+
}
|
|
152
|
+
tree.data.totalLines = lineNumber;
|
|
153
|
+
}
|
|
154
|
+
function createLine(children, line) {
|
|
155
|
+
return {
|
|
156
|
+
type: 'element',
|
|
157
|
+
tagName: 'span',
|
|
158
|
+
properties: {
|
|
159
|
+
className: 'line',
|
|
160
|
+
dataLn: line
|
|
161
|
+
},
|
|
162
|
+
children: children
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function createFrame(frameChildren, sourceLines, startLine, endLine) {
|
|
166
|
+
var properties = {
|
|
167
|
+
className: 'frame'
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// Store line range information if provided (for dataAsString generation)
|
|
171
|
+
if (sourceLines && startLine !== undefined && endLine !== undefined) {
|
|
172
|
+
properties.frameStartLine = startLine;
|
|
173
|
+
properties.frameEndLine = endLine;
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
type: 'element',
|
|
177
|
+
tagName: 'span',
|
|
178
|
+
properties: properties,
|
|
179
|
+
children: frameChildren
|
|
180
|
+
};
|
|
181
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import sourceJs from '@wooorm/starry-night/source.js';
|
|
2
|
+
import sourceTs from '@wooorm/starry-night/source.ts';
|
|
3
|
+
import sourceTsx from '@wooorm/starry-night/source.tsx';
|
|
4
|
+
import sourceJson from '@wooorm/starry-night/source.json';
|
|
5
|
+
import textMd from '@wooorm/starry-night/text.md';
|
|
6
|
+
import sourceMdx from '@wooorm/starry-night/source.mdx';
|
|
7
|
+
import textHtmlBasic from '@wooorm/starry-night/text.html.basic';
|
|
8
|
+
import sourceCss from '@wooorm/starry-night/source.css';
|
|
9
|
+
import sourceShell from '@wooorm/starry-night/source.shell';
|
|
10
|
+
import sourceYaml from '@wooorm/starry-night/source.yaml';
|
|
11
|
+
export var grammars = [sourceJs, sourceTs, sourceTsx, sourceJson, textMd, sourceMdx,
|
|
12
|
+
// needs sourceTsx
|
|
13
|
+
textHtmlBasic, sourceCss, sourceShell, sourceYaml];
|
|
14
|
+
export var extensionMap = {
|
|
15
|
+
'.js': 'source.js',
|
|
16
|
+
'.ts': 'source.ts',
|
|
17
|
+
'.jsx': 'source.tsx',
|
|
18
|
+
// TODO: is there a JSX grammar?
|
|
19
|
+
'.tsx': 'source.tsx',
|
|
20
|
+
'.json': 'source.json',
|
|
21
|
+
'.md': 'text.md',
|
|
22
|
+
'.mdx': 'source.mdx',
|
|
23
|
+
'.html': 'text.html.basic',
|
|
24
|
+
'.css': 'source.css',
|
|
25
|
+
'.sh': 'source.shell',
|
|
26
|
+
'.yaml': 'source.yaml'
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./parseSource.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./parseSource.js";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
+
import { createStarryNight } from '@wooorm/starry-night';
|
|
4
|
+
import { grammars, extensionMap } from "./grammars.js";
|
|
5
|
+
import { starryNightGutter } from "./addLineGutters.js";
|
|
6
|
+
var STARRY_NIGHT_KEY = '__docs_infra_starry_night_instance__';
|
|
7
|
+
export var parseSource = function parseSource(source, fileName) {
|
|
8
|
+
var starryNight = globalThis[STARRY_NIGHT_KEY];
|
|
9
|
+
if (!starryNight) {
|
|
10
|
+
throw new Error('Starry Night not initialized. Use createParseSource to create an initialized parseSource function.');
|
|
11
|
+
}
|
|
12
|
+
var fileType = fileName.slice(fileName.lastIndexOf('.'));
|
|
13
|
+
if (!extensionMap[fileType]) {
|
|
14
|
+
// Return a basic HAST root node with the source text for unsupported file types
|
|
15
|
+
// TODO: should we split and add line gutters?
|
|
16
|
+
return {
|
|
17
|
+
type: 'root',
|
|
18
|
+
children: [{
|
|
19
|
+
type: 'text',
|
|
20
|
+
value: source
|
|
21
|
+
}]
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
var highlighted = starryNight.highlight(source, extensionMap[fileType]);
|
|
25
|
+
var sourceLines = source.split(/\r?\n|\r/);
|
|
26
|
+
starryNightGutter(highlighted, sourceLines); // mutates the tree to add line gutters
|
|
27
|
+
|
|
28
|
+
return highlighted;
|
|
29
|
+
};
|
|
30
|
+
export var createParseSource = /*#__PURE__*/function () {
|
|
31
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
32
|
+
return _regenerator().w(function (_context) {
|
|
33
|
+
while (1) switch (_context.n) {
|
|
34
|
+
case 0:
|
|
35
|
+
if (globalThis[STARRY_NIGHT_KEY]) {
|
|
36
|
+
_context.n = 2;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
_context.n = 1;
|
|
40
|
+
return createStarryNight(grammars);
|
|
41
|
+
case 1:
|
|
42
|
+
globalThis[STARRY_NIGHT_KEY] = _context.v;
|
|
43
|
+
case 2:
|
|
44
|
+
return _context.a(2, parseSource);
|
|
45
|
+
}
|
|
46
|
+
}, _callee);
|
|
47
|
+
}));
|
|
48
|
+
return function createParseSource() {
|
|
49
|
+
return _ref.apply(this, arguments);
|
|
50
|
+
};
|
|
51
|
+
}();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Plugin } from 'unified';
|
|
2
|
+
/**
|
|
3
|
+
* Rehype plugin that transforms pre > code elements to use loadVariant
|
|
4
|
+
*
|
|
5
|
+
* This plugin:
|
|
6
|
+
* 1. Finds pre elements in the HTML AST
|
|
7
|
+
* 2. Collects all code children within each pre element
|
|
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 pre element
|
|
11
|
+
* 6. Clears all code element contents
|
|
12
|
+
*/
|
|
13
|
+
export declare const transformHtmlCode: Plugin;
|