@mui/internal-docs-infra 0.1.1-canary.9 → 0.2.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,87 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
/**
|
|
4
|
+
* Pure function to parse controlled code and convert it to regular Code format.
|
|
5
|
+
* Handles the conversion from ControlledCode (string|null sources) to Code (HAST nodes).
|
|
6
|
+
*/
|
|
7
|
+
export function parseControlledCode(controlledCode, parseSource) {
|
|
8
|
+
var parsed = {};
|
|
9
|
+
for (var _i = 0, _Object$entries = Object.entries(controlledCode); _i < _Object$entries.length; _i++) {
|
|
10
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
11
|
+
variant = _Object$entries$_i[0],
|
|
12
|
+
variantCode = _Object$entries$_i[1];
|
|
13
|
+
if (variantCode === null) {
|
|
14
|
+
// Explicitly deleted - skip this variant
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (variantCode && _typeof(variantCode) === 'object') {
|
|
18
|
+
var mainSource = void 0;
|
|
19
|
+
|
|
20
|
+
// Convert null to empty string, then parse
|
|
21
|
+
var sourceToProcess = variantCode.source === null ? '' : variantCode.source;
|
|
22
|
+
if (typeof sourceToProcess === 'string' && variantCode.fileName) {
|
|
23
|
+
try {
|
|
24
|
+
mainSource = parseSource(sourceToProcess, variantCode.fileName);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
// Keep original string if parsing fails
|
|
27
|
+
mainSource = sourceToProcess;
|
|
28
|
+
}
|
|
29
|
+
} else if (typeof sourceToProcess === 'string' && !variantCode.fileName) {
|
|
30
|
+
// Return a basic HAST root node with the source text for unsupported file types
|
|
31
|
+
// This indicates that the source has at least passed through the parsing pipeline
|
|
32
|
+
var source = {
|
|
33
|
+
type: 'root',
|
|
34
|
+
children: [{
|
|
35
|
+
type: 'text',
|
|
36
|
+
value: sourceToProcess
|
|
37
|
+
}]
|
|
38
|
+
};
|
|
39
|
+
mainSource = source;
|
|
40
|
+
} else {
|
|
41
|
+
// Handle undefined or other non-string values
|
|
42
|
+
mainSource = sourceToProcess;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Parse extraFiles if present
|
|
46
|
+
var extraFiles = void 0;
|
|
47
|
+
if (variantCode.extraFiles) {
|
|
48
|
+
var parsedExtraFiles = {};
|
|
49
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(variantCode.extraFiles); _i2 < _Object$entries2.length; _i2++) {
|
|
50
|
+
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
51
|
+
fileName = _Object$entries2$_i[0],
|
|
52
|
+
fileData = _Object$entries2$_i[1];
|
|
53
|
+
// Convert null to empty string, then parse
|
|
54
|
+
var fileSourceToProcess = fileData.source === null ? '' : fileData.source;
|
|
55
|
+
if (typeof fileSourceToProcess === 'string') {
|
|
56
|
+
// Parse string sources
|
|
57
|
+
try {
|
|
58
|
+
var parsedSource = parseSource(fileSourceToProcess, fileName);
|
|
59
|
+
parsedExtraFiles[fileName] = {
|
|
60
|
+
source: parsedSource
|
|
61
|
+
};
|
|
62
|
+
} catch (error) {
|
|
63
|
+
// Keep original if parsing fails
|
|
64
|
+
parsedExtraFiles[fileName] = {
|
|
65
|
+
source: fileSourceToProcess
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
// Keep other values as-is
|
|
70
|
+
parsedExtraFiles[fileName] = {
|
|
71
|
+
source: fileSourceToProcess
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
extraFiles = parsedExtraFiles;
|
|
76
|
+
}
|
|
77
|
+
parsed[variant] = {
|
|
78
|
+
fileName: variantCode.fileName,
|
|
79
|
+
url: variantCode.url,
|
|
80
|
+
source: mainSource,
|
|
81
|
+
extraFiles: extraFiles,
|
|
82
|
+
filesOrder: variantCode.filesOrder
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return parsed;
|
|
87
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared path utilities for CodeHighlighter components
|
|
3
|
+
*
|
|
4
|
+
* Back navigation counting functions:
|
|
5
|
+
* - resolveRelativePath().backSteps: Net back navigation after path resolution (recommended for most cases)
|
|
6
|
+
* - countConsecutiveBackNavigation(): Raw consecutive '../' at start (for trimming leading patterns)
|
|
7
|
+
* - countBackNavigationOccurrences(): Total raw '../' count anywhere (for metadata analysis)
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Minimal file representation for path utilities
|
|
11
|
+
*/
|
|
12
|
+
type URL = string;
|
|
13
|
+
type FileEntry = URL | {
|
|
14
|
+
metadata?: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Resolves a relative path by handling .. and . segments properly
|
|
18
|
+
* This mimics path.resolve() behavior for relative paths
|
|
19
|
+
* Returns the net back navigation steps after path resolution
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveRelativePath(relativePath: string): {
|
|
22
|
+
resolvedPath: string;
|
|
23
|
+
backSteps: number;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Split a path into components, filtering out empty strings
|
|
27
|
+
*/
|
|
28
|
+
export declare function splitPath(path: string): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Extract URL path components, filtering out empty strings
|
|
31
|
+
*/
|
|
32
|
+
export declare function getUrlParts(url: string): string[];
|
|
33
|
+
/**
|
|
34
|
+
* Remove trailing slash from a path string
|
|
35
|
+
*/
|
|
36
|
+
export declare function removeTrailingSlash(path: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Remove a specific number of back navigation prefixes from a path
|
|
39
|
+
*/
|
|
40
|
+
export declare function removeBackNavigationPrefix(path: string, count: number): string;
|
|
41
|
+
/**
|
|
42
|
+
* Calculate the maximum back navigation levels from a collection of file paths
|
|
43
|
+
*
|
|
44
|
+
* This function analyzes all file paths in the collection and determines:
|
|
45
|
+
* 1. The maximum back navigation steps needed to reach any file (including metadata)
|
|
46
|
+
* 2. The maximum back navigation steps needed to reach any non-metadata file
|
|
47
|
+
*
|
|
48
|
+
* @param files - Record of relative file paths to file content (string) or file objects with optional metadata flag
|
|
49
|
+
* @returns Object containing:
|
|
50
|
+
* - maxBackNavigation: Maximum '../' steps needed to reach any file in the collection
|
|
51
|
+
* - maxSourceBackNavigation: Maximum '../' steps needed to reach any non-metadata file
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const files = {
|
|
56
|
+
* 'component.tsx': 'url',
|
|
57
|
+
* '../shared/utils.ts': 'url',
|
|
58
|
+
* '../../docs/readme.md': { metadata: true }
|
|
59
|
+
* };
|
|
60
|
+
*
|
|
61
|
+
* const result = calculateMaxBackNavigation(files);
|
|
62
|
+
* // result: { maxBackNavigation: 2, maxSourceBackNavigation: 1 }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function calculateMaxBackNavigation(files: Record<string, FileEntry>): {
|
|
66
|
+
maxBackNavigation: number;
|
|
67
|
+
maxSourceBackNavigation: number;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Calculate the maximum back navigation level from a collection of file paths
|
|
71
|
+
*
|
|
72
|
+
* This function analyzes file paths and determines the maximum number of back navigation
|
|
73
|
+
* steps needed to reach any non-metadata file. It ignores metadata files completely,
|
|
74
|
+
* focusing only on source code and other content files.
|
|
75
|
+
*
|
|
76
|
+
* @param files - Record of relative file paths to file content (string) or file objects with optional metadata flag
|
|
77
|
+
* @returns The maximum number of `../` steps needed to reach any non-metadata file
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const files = {
|
|
82
|
+
* 'component.tsx': 'url',
|
|
83
|
+
* '../shared/utils.ts': 'url',
|
|
84
|
+
* '../../docs/readme.md': { metadata: true }, // ignored
|
|
85
|
+
* '../../../deep/source.js': 'url'
|
|
86
|
+
* };
|
|
87
|
+
*
|
|
88
|
+
* const maxSteps = calculateMaxSourceBackNavigation(files);
|
|
89
|
+
* // maxSteps: 3 (from '../../../deep/source.js')
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function calculateMaxSourceBackNavigation(files: Record<string, FileEntry>): number;
|
|
93
|
+
/**
|
|
94
|
+
* Build a path from multiple components, filtering out empty parts
|
|
95
|
+
*/
|
|
96
|
+
export declare function buildPath(...segments: (string | string[] | undefined)[]): string;
|
|
97
|
+
/**
|
|
98
|
+
* Create synthetic directory names for path structure
|
|
99
|
+
* Generates alphabetic names: 'a', 'b', 'c', ..., 'z', 'aa', 'ab', 'ac', etc.
|
|
100
|
+
* @param count - Number of directory names to generate
|
|
101
|
+
* @returns Array of alphabetic directory names
|
|
102
|
+
*/
|
|
103
|
+
export declare function createSyntheticDirectories(count: number): string[];
|
|
104
|
+
/**
|
|
105
|
+
* Calculate the required back navigation pattern for metadata files positioning.
|
|
106
|
+
* This combines maxSourceBackNavigation from files with additional levels from metadataPrefix.
|
|
107
|
+
*
|
|
108
|
+
* @param files - Record of extraFiles to analyze for source back navigation
|
|
109
|
+
* @param metadataPrefix - Optional prefix path (e.g., 'src/', 'src/app/') that adds additional back navigation levels
|
|
110
|
+
* @returns A string of '../' patterns representing the back navigation needed
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const files = { '../utils.ts': 'url', '../../shared.ts': 'url' };
|
|
115
|
+
* const result = calculateMetadataBackNavigation(files, 'src/');
|
|
116
|
+
* // result: '../../../' (maxSourceBackNavigation=2 + metadataPrefix=1)
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function calculateMetadataBackNavigation(files: Record<string, FileEntry> | undefined, metadataPrefix?: string): string;
|
|
120
|
+
export {};
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
5
|
+
/**
|
|
6
|
+
* Shared path utilities for CodeHighlighter components
|
|
7
|
+
*
|
|
8
|
+
* Back navigation counting functions:
|
|
9
|
+
* - resolveRelativePath().backSteps: Net back navigation after path resolution (recommended for most cases)
|
|
10
|
+
* - countConsecutiveBackNavigation(): Raw consecutive '../' at start (for trimming leading patterns)
|
|
11
|
+
* - countBackNavigationOccurrences(): Total raw '../' count anywhere (for metadata analysis)
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Minimal file representation for path utilities
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Resolves a relative path by handling .. and . segments properly
|
|
20
|
+
* This mimics path.resolve() behavior for relative paths
|
|
21
|
+
* Returns the net back navigation steps after path resolution
|
|
22
|
+
*/
|
|
23
|
+
export function resolveRelativePath(relativePath) {
|
|
24
|
+
// Split the path into segments
|
|
25
|
+
var segments = relativePath.split('/');
|
|
26
|
+
var resolved = [];
|
|
27
|
+
var backSteps = 0;
|
|
28
|
+
var _iterator = _createForOfIteratorHelper(segments),
|
|
29
|
+
_step;
|
|
30
|
+
try {
|
|
31
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
32
|
+
var segment = _step.value;
|
|
33
|
+
if (segment === '' || segment === '.') {
|
|
34
|
+
// Skip empty and current directory segments
|
|
35
|
+
continue;
|
|
36
|
+
} else if (segment === '..') {
|
|
37
|
+
if (resolved.length > 0) {
|
|
38
|
+
// Remove the last segment (go back one directory)
|
|
39
|
+
resolved.pop();
|
|
40
|
+
} else {
|
|
41
|
+
// Count back steps that go beyond the current directory
|
|
42
|
+
backSteps += 1;
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
// Regular directory or file segment
|
|
46
|
+
resolved.push(segment);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} catch (err) {
|
|
50
|
+
_iterator.e(err);
|
|
51
|
+
} finally {
|
|
52
|
+
_iterator.f();
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
resolvedPath: resolved.join('/'),
|
|
56
|
+
backSteps: backSteps
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Split a path into components, filtering out empty strings
|
|
62
|
+
*/
|
|
63
|
+
export function splitPath(path) {
|
|
64
|
+
return path.split('/').filter(Boolean);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Extract URL path components, filtering out empty strings
|
|
69
|
+
*/
|
|
70
|
+
export function getUrlParts(url) {
|
|
71
|
+
return splitPath(new URL(url).pathname);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Remove trailing slash from a path string
|
|
76
|
+
*/
|
|
77
|
+
export function removeTrailingSlash(path) {
|
|
78
|
+
return path.endsWith('/') ? path.slice(0, -1) : path;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Remove a specific number of back navigation prefixes from a path
|
|
83
|
+
*/
|
|
84
|
+
export function removeBackNavigationPrefix(path, count) {
|
|
85
|
+
var result = path;
|
|
86
|
+
for (var i = 0; i < count; i += 1) {
|
|
87
|
+
if (result.startsWith('../')) {
|
|
88
|
+
result = result.slice(3);
|
|
89
|
+
} else {
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Calculate the maximum back navigation levels from a collection of file paths
|
|
98
|
+
*
|
|
99
|
+
* This function analyzes all file paths in the collection and determines:
|
|
100
|
+
* 1. The maximum back navigation steps needed to reach any file (including metadata)
|
|
101
|
+
* 2. The maximum back navigation steps needed to reach any non-metadata file
|
|
102
|
+
*
|
|
103
|
+
* @param files - Record of relative file paths to file content (string) or file objects with optional metadata flag
|
|
104
|
+
* @returns Object containing:
|
|
105
|
+
* - maxBackNavigation: Maximum '../' steps needed to reach any file in the collection
|
|
106
|
+
* - maxSourceBackNavigation: Maximum '../' steps needed to reach any non-metadata file
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const files = {
|
|
111
|
+
* 'component.tsx': 'url',
|
|
112
|
+
* '../shared/utils.ts': 'url',
|
|
113
|
+
* '../../docs/readme.md': { metadata: true }
|
|
114
|
+
* };
|
|
115
|
+
*
|
|
116
|
+
* const result = calculateMaxBackNavigation(files);
|
|
117
|
+
* // result: { maxBackNavigation: 2, maxSourceBackNavigation: 1 }
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export function calculateMaxBackNavigation(files) {
|
|
121
|
+
var maxBackNavigation = 0;
|
|
122
|
+
var maxSourceBackNavigation = 0;
|
|
123
|
+
for (var _i = 0, _Object$entries = Object.entries(files); _i < _Object$entries.length; _i++) {
|
|
124
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
125
|
+
relativePath = _Object$entries$_i[0],
|
|
126
|
+
fileContent = _Object$entries$_i[1];
|
|
127
|
+
// Check if this is a metadata file
|
|
128
|
+
var isMetadata = _typeof(fileContent) === 'object' && fileContent.metadata;
|
|
129
|
+
var _resolveRelativePath = resolveRelativePath(relativePath),
|
|
130
|
+
backSteps = _resolveRelativePath.backSteps;
|
|
131
|
+
if (!isMetadata) {
|
|
132
|
+
maxSourceBackNavigation = Math.max(maxSourceBackNavigation, backSteps);
|
|
133
|
+
}
|
|
134
|
+
maxBackNavigation = Math.max(maxBackNavigation, backSteps);
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
maxBackNavigation: maxBackNavigation,
|
|
138
|
+
maxSourceBackNavigation: maxSourceBackNavigation
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Calculate the maximum back navigation level from a collection of file paths
|
|
144
|
+
*
|
|
145
|
+
* This function analyzes file paths and determines the maximum number of back navigation
|
|
146
|
+
* steps needed to reach any non-metadata file. It ignores metadata files completely,
|
|
147
|
+
* focusing only on source code and other content files.
|
|
148
|
+
*
|
|
149
|
+
* @param files - Record of relative file paths to file content (string) or file objects with optional metadata flag
|
|
150
|
+
* @returns The maximum number of `../` steps needed to reach any non-metadata file
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const files = {
|
|
155
|
+
* 'component.tsx': 'url',
|
|
156
|
+
* '../shared/utils.ts': 'url',
|
|
157
|
+
* '../../docs/readme.md': { metadata: true }, // ignored
|
|
158
|
+
* '../../../deep/source.js': 'url'
|
|
159
|
+
* };
|
|
160
|
+
*
|
|
161
|
+
* const maxSteps = calculateMaxSourceBackNavigation(files);
|
|
162
|
+
* // maxSteps: 3 (from '../../../deep/source.js')
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export function calculateMaxSourceBackNavigation(files) {
|
|
166
|
+
var maxSourceBackNavigation = 0;
|
|
167
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(files); _i2 < _Object$entries2.length; _i2++) {
|
|
168
|
+
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
169
|
+
relativePath = _Object$entries2$_i[0],
|
|
170
|
+
fileContent = _Object$entries2$_i[1];
|
|
171
|
+
// Check if this is a metadata file
|
|
172
|
+
var isMetadata = _typeof(fileContent) === 'object' && fileContent.metadata;
|
|
173
|
+
|
|
174
|
+
// Skip metadata files - only consider non-metadata files for maxSourceBackNavigation
|
|
175
|
+
if (isMetadata) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Use path resolution to get the net back steps (most accurate)
|
|
180
|
+
var _resolveRelativePath2 = resolveRelativePath(relativePath),
|
|
181
|
+
backSteps = _resolveRelativePath2.backSteps;
|
|
182
|
+
maxSourceBackNavigation = Math.max(maxSourceBackNavigation, backSteps);
|
|
183
|
+
}
|
|
184
|
+
return maxSourceBackNavigation;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Build a path from multiple components, filtering out empty parts
|
|
189
|
+
*/
|
|
190
|
+
export function buildPath() {
|
|
191
|
+
var parts = [];
|
|
192
|
+
for (var _len = arguments.length, segments = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
193
|
+
segments[_key] = arguments[_key];
|
|
194
|
+
}
|
|
195
|
+
for (var _i3 = 0, _segments = segments; _i3 < _segments.length; _i3++) {
|
|
196
|
+
var segment = _segments[_i3];
|
|
197
|
+
if (segment === undefined) {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (Array.isArray(segment)) {
|
|
201
|
+
parts.push.apply(parts, _toConsumableArray(segment));
|
|
202
|
+
} else {
|
|
203
|
+
parts.push(segment);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return parts.filter(Boolean).map(removeTrailingSlash).join('/');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Create synthetic directory names for path structure
|
|
211
|
+
* Generates alphabetic names: 'a', 'b', 'c', ..., 'z', 'aa', 'ab', 'ac', etc.
|
|
212
|
+
* @param count - Number of directory names to generate
|
|
213
|
+
* @returns Array of alphabetic directory names
|
|
214
|
+
*/
|
|
215
|
+
export function createSyntheticDirectories(count) {
|
|
216
|
+
return Array.from({
|
|
217
|
+
length: count
|
|
218
|
+
}, function (_, i) {
|
|
219
|
+
var result = '';
|
|
220
|
+
var num = i + 1; // 1-based for Excel-style naming
|
|
221
|
+
|
|
222
|
+
while (num > 0) {
|
|
223
|
+
num -= 1; // Adjust for 0-based indexing
|
|
224
|
+
result = String.fromCharCode(97 + num % 26) + result;
|
|
225
|
+
num = Math.floor(num / 26);
|
|
226
|
+
}
|
|
227
|
+
return result;
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Calculate the required back navigation pattern for metadata files positioning.
|
|
233
|
+
* This combines maxSourceBackNavigation from files with additional levels from metadataPrefix.
|
|
234
|
+
*
|
|
235
|
+
* @param files - Record of extraFiles to analyze for source back navigation
|
|
236
|
+
* @param metadataPrefix - Optional prefix path (e.g., 'src/', 'src/app/') that adds additional back navigation levels
|
|
237
|
+
* @returns A string of '../' patterns representing the back navigation needed
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const files = { '../utils.ts': 'url', '../../shared.ts': 'url' };
|
|
242
|
+
* const result = calculateMetadataBackNavigation(files, 'src/');
|
|
243
|
+
* // result: '../../../' (maxSourceBackNavigation=2 + metadataPrefix=1)
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
export function calculateMetadataBackNavigation(files, metadataPrefix) {
|
|
247
|
+
// Get the maxSourceBackNavigation from the file structure
|
|
248
|
+
var backLevels = 0;
|
|
249
|
+
if (files) {
|
|
250
|
+
backLevels = calculateMaxSourceBackNavigation(files);
|
|
251
|
+
}
|
|
252
|
+
if (metadataPrefix) {
|
|
253
|
+
// When a prefix is provided, add additional back navigation based on prefix depth
|
|
254
|
+
var prefixSegments = metadataPrefix.split('/').filter(Boolean);
|
|
255
|
+
backLevels += prefixSegments.length;
|
|
256
|
+
}
|
|
257
|
+
return '../'.repeat(backLevels);
|
|
258
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Code, ParseSource } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Pure function to identify which variants need transformation.
|
|
4
|
+
* Returns entries of variants that have transforms requiring processing.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getVariantsToTransform(parsedCode: Code): Array<[string, any]>;
|
|
7
|
+
/**
|
|
8
|
+
* Pure function to get available transforms from a specific variant.
|
|
9
|
+
* Only includes transforms that have actual deltas (file changes), not just filename changes.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getAvailableTransforms(parsedCode: Code | undefined, variantName: string): string[];
|
|
12
|
+
/**
|
|
13
|
+
* Pure async function to transform a single variant's code and extraFiles.
|
|
14
|
+
* Returns the transformed variant or the original if transformation fails.
|
|
15
|
+
*/
|
|
16
|
+
export declare function transformVariant(variant: string, variantCode: any, parseSource: ParseSource): Promise<any>;
|
|
17
|
+
/**
|
|
18
|
+
* Pure async function to apply transformations to all variants that need them.
|
|
19
|
+
* Returns the enhanced code with computed transforms.
|
|
20
|
+
*/
|
|
21
|
+
export declare function applyTransforms(parsedCode: Code, parseSource: ParseSource): Promise<Code>;
|