@mui/internal-docs-infra 0.1.0 → 0.1.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CodeControllerContext/CodeControllerContext.d.ts +22 -0
- package/CodeControllerContext/CodeControllerContext.d.ts.map +1 -0
- package/CodeControllerContext/CodeControllerContext.js +14 -0
- package/CodeControllerContext/index.d.ts +1 -0
- package/CodeControllerContext/index.d.ts.map +1 -0
- package/CodeControllerContext/index.js +1 -0
- package/CodeHighlighter/CodeHighlighter.d.ts +2 -0
- package/CodeHighlighter/CodeHighlighter.d.ts.map +1 -0
- package/CodeHighlighter/CodeHighlighter.js +321 -0
- package/CodeHighlighter/CodeHighlighterClient.d.ts +2 -0
- package/CodeHighlighter/CodeHighlighterClient.d.ts.map +1 -0
- package/CodeHighlighter/CodeHighlighterClient.js +399 -0
- package/CodeHighlighter/CodeHighlighterContext.d.ts +14 -0
- package/CodeHighlighter/CodeHighlighterContext.d.ts.map +1 -0
- package/CodeHighlighter/CodeHighlighterContext.js +14 -0
- package/CodeHighlighter/CodeHighlighterFallbackContext.d.ts +7 -0
- package/CodeHighlighter/CodeHighlighterFallbackContext.d.ts.map +1 -0
- package/CodeHighlighter/CodeHighlighterFallbackContext.js +11 -0
- package/CodeHighlighter/applyTransform.d.ts +19 -0
- package/CodeHighlighter/applyTransform.d.ts.map +1 -0
- package/CodeHighlighter/applyTransform.js +75 -0
- package/CodeHighlighter/codeToFallbackProps.d.ts +2 -0
- package/CodeHighlighter/codeToFallbackProps.d.ts.map +1 -0
- package/CodeHighlighter/codeToFallbackProps.js +70 -0
- package/CodeHighlighter/errors.d.ts +0 -0
- package/CodeHighlighter/errors.d.ts.map +1 -0
- package/CodeHighlighter/errors.js +1 -0
- package/CodeHighlighter/hasAllVariants.d.ts +2 -0
- package/CodeHighlighter/hasAllVariants.d.ts.map +1 -0
- package/CodeHighlighter/hasAllVariants.js +31 -0
- package/CodeHighlighter/index.d.ts +4 -0
- package/CodeHighlighter/index.d.ts.map +1 -0
- package/CodeHighlighter/index.js +4 -0
- package/CodeHighlighter/loadFallbackCode.d.ts +9 -0
- package/CodeHighlighter/loadFallbackCode.d.ts.map +1 -0
- package/CodeHighlighter/loadFallbackCode.js +468 -0
- package/CodeHighlighter/loadVariant.d.ts +11 -0
- package/CodeHighlighter/loadVariant.d.ts.map +1 -0
- package/CodeHighlighter/loadVariant.js +708 -0
- package/CodeHighlighter/maybeInitialData.d.ts +10 -0
- package/CodeHighlighter/maybeInitialData.d.ts.map +1 -0
- package/CodeHighlighter/maybeInitialData.js +94 -0
- package/CodeHighlighter/parseCode.d.ts +6 -0
- package/CodeHighlighter/parseCode.d.ts.map +1 -0
- package/CodeHighlighter/parseCode.js +122 -0
- package/CodeHighlighter/parseControlledCode.d.ts +6 -0
- package/CodeHighlighter/parseControlledCode.d.ts.map +1 -0
- package/CodeHighlighter/parseControlledCode.js +76 -0
- package/CodeHighlighter/transformCode.d.ts +20 -0
- package/CodeHighlighter/transformCode.d.ts.map +1 -0
- package/CodeHighlighter/transformCode.js +223 -0
- package/CodeHighlighter/transformParsedSource.d.ts +3 -0
- package/CodeHighlighter/transformParsedSource.d.ts.map +1 -0
- package/CodeHighlighter/transformParsedSource.js +66 -0
- package/CodeHighlighter/transformSource.d.ts +2 -0
- package/CodeHighlighter/transformSource.d.ts.map +1 -0
- package/CodeHighlighter/transformSource.js +107 -0
- package/CodeHighlighter/types.d.ts +138 -0
- package/CodeHighlighter/types.d.ts.map +1 -0
- package/CodeHighlighter/types.js +1 -0
- package/CodeProvider/CodeContext.d.ts +12 -0
- package/CodeProvider/CodeContext.d.ts.map +1 -0
- package/CodeProvider/CodeContext.js +8 -0
- package/CodeProvider/CodeProvider.d.ts +13 -0
- package/CodeProvider/CodeProvider.d.ts.map +1 -0
- package/CodeProvider/CodeProvider.js +50 -0
- package/CodeProvider/index.d.ts +2 -0
- package/CodeProvider/index.d.ts.map +1 -0
- package/CodeProvider/index.js +2 -0
- package/README.md +3 -1
- package/hast/hast.d.ts +11 -0
- package/hast/hast.d.ts.map +1 -0
- package/hast/hast.js +66 -0
- package/hast/index.d.ts +1 -0
- package/hast/index.d.ts.map +1 -0
- package/hast/index.js +1 -0
- package/loadPrecomputedCodeHighlighter/index.d.ts +2 -0
- package/loadPrecomputedCodeHighlighter/index.d.ts.map +1 -0
- package/loadPrecomputedCodeHighlighter/index.js +4 -0
- package/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +57 -0
- package/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts.map +1 -0
- package/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +194 -0
- package/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +20 -0
- package/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts.map +1 -0
- package/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +243 -0
- package/loadPrecomputedCodeHighlighter/parseFunctionParameters.d.ts +15 -0
- package/loadPrecomputedCodeHighlighter/parseFunctionParameters.d.ts.map +1 -0
- package/loadPrecomputedCodeHighlighter/parseFunctionParameters.js +168 -0
- package/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts +27 -0
- package/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts.map +1 -0
- package/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +37 -0
- package/loadServerCodeMeta/index.d.ts +1 -0
- package/loadServerCodeMeta/index.d.ts.map +1 -0
- package/loadServerCodeMeta/index.js +1 -0
- package/loadServerCodeMeta/serverLoadCodeMeta.d.ts +24 -0
- package/loadServerCodeMeta/serverLoadCodeMeta.d.ts.map +1 -0
- package/loadServerCodeMeta/serverLoadCodeMeta.js +77 -0
- package/loadServerSource/index.d.ts +1 -0
- package/loadServerSource/index.d.ts.map +1 -0
- package/loadServerSource/index.js +1 -0
- package/loadServerSource/serverLoadSource.d.ts +25 -0
- package/loadServerSource/serverLoadSource.d.ts.map +1 -0
- package/loadServerSource/serverLoadSource.js +100 -0
- package/loaderUtils/getFileNameFromUrl.d.ts +11 -0
- package/loaderUtils/getFileNameFromUrl.d.ts.map +1 -0
- package/loaderUtils/getFileNameFromUrl.js +32 -0
- package/loaderUtils/index.d.ts +5 -0
- package/loaderUtils/index.d.ts.map +1 -0
- package/loaderUtils/index.js +5 -0
- package/loaderUtils/processImports.d.ts +19 -0
- package/loaderUtils/processImports.d.ts.map +1 -0
- package/loaderUtils/processImports.js +82 -0
- package/loaderUtils/resolveImports.d.ts +4 -0
- package/loaderUtils/resolveImports.d.ts.map +1 -0
- package/loaderUtils/resolveImports.js +71 -0
- package/loaderUtils/resolveModulePath.d.ts +74 -0
- package/loaderUtils/resolveModulePath.d.ts.map +1 -0
- package/loaderUtils/resolveModulePath.js +862 -0
- package/loaderUtils/resolveModulePathWithFs.d.ts +44 -0
- package/loaderUtils/resolveModulePathWithFs.d.ts.map +1 -0
- package/loaderUtils/resolveModulePathWithFs.js +159 -0
- package/loaderUtils/rewriteImports.d.ts +9 -0
- package/loaderUtils/rewriteImports.d.ts.map +1 -0
- package/loaderUtils/rewriteImports.js +57 -0
- package/package.json +20 -7
- package/parseSource/grammars.d.ts +2 -0
- package/parseSource/grammars.d.ts.map +1 -0
- package/parseSource/grammars.js +27 -0
- package/parseSource/index.d.ts +1 -0
- package/parseSource/index.d.ts.map +1 -0
- package/parseSource/index.js +1 -0
- package/parseSource/parseSource.d.ts +3 -0
- package/parseSource/parseSource.d.ts.map +1 -0
- package/parseSource/parseSource.js +37 -0
- package/transformRelativeMarkdownPaths/index.d.ts +2 -0
- package/transformRelativeMarkdownPaths/index.d.ts.map +1 -0
- package/transformRelativeMarkdownPaths/index.js +4 -0
- package/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.d.ts +12 -0
- package/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.d.ts.map +1 -0
- package/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.js +30 -0
- package/transformTsToJs/index.d.ts +1 -0
- package/transformTsToJs/index.d.ts.map +1 -0
- package/transformTsToJs/index.js +1 -0
- package/transformTsToJs/removeTypes.d.ts +13 -0
- package/transformTsToJs/removeTypes.d.ts.map +1 -0
- package/transformTsToJs/removeTypes.js +134 -0
- package/transformTsToJs/transformTsToJs.d.ts +3 -0
- package/transformTsToJs/transformTsToJs.d.ts.map +1 -0
- package/transformTsToJs/transformTsToJs.js +34 -0
- package/useCode/index.d.ts +1 -0
- package/useCode/index.d.ts.map +1 -0
- package/useCode/index.js +1 -0
- package/{esm/useDemo/index.d.ts → useCode/useCode.d.ts} +14 -28
- package/useCode/useCode.d.ts.map +1 -0
- package/useCode/useCode.js +393 -0
- package/useCopier/index.js +10 -18
- package/useDemo/index.d.ts +12 -24
- package/useDemo/index.d.ts.map +1 -0
- package/useDemo/index.js +14 -109
- package/useOnHydrate/index.d.ts +1 -0
- package/useOnHydrate/index.d.ts.map +1 -0
- package/useOnHydrate/index.js +1 -0
- package/useOnHydrate/useOnHydrate.d.ts +1 -0
- package/useOnHydrate/useOnHydrate.d.ts.map +1 -0
- package/useOnHydrate/useOnHydrate.js +18 -0
- package/useOnIdle/index.d.ts +1 -0
- package/useOnIdle/index.d.ts.map +1 -0
- package/useOnIdle/index.js +1 -0
- package/useOnIdle/useOnIdle.d.ts +1 -0
- package/useOnIdle/useOnIdle.d.ts.map +1 -0
- package/useOnIdle/useOnIdle.js +39 -0
- package/esm/package.json +0 -1
- package/esm/useCopier/index.d.ts +0 -15
- package/esm/useCopier/index.js +0 -62
- package/esm/useDemo/index.d.ts.map +0 -1
- package/esm/useDemo/index.js +0 -104
- /package/{esm/useCopier → useCopier}/index.d.ts.map +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Code, VariantExtraFiles, VariantSource } from "./types.js";
|
|
2
|
+
export declare function maybeInitialData(variants: string[], variant: string, code?: Code, fileName?: string, needsHighlight?: boolean, needsAllFiles?: boolean, needsAllVariants?: boolean): {
|
|
3
|
+
initialData: false | {
|
|
4
|
+
code: Code;
|
|
5
|
+
initialFilename: string;
|
|
6
|
+
initialSource: VariantSource;
|
|
7
|
+
initialExtraFiles?: VariantExtraFiles;
|
|
8
|
+
};
|
|
9
|
+
reason?: string;
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maybeInitialData.d.ts","sourceRoot":"","sources":["../../../src/CodeHighlighter/maybeInitialData.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEjE,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAAE,EAClB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,IAAI,EACX,QAAQ,CAAC,EAAE,MAAM,EACjB,cAAc,UAAQ,EACtB,aAAa,UAAQ,EACrB,gBAAgB,UAAQ,GACvB;IACD,WAAW,EACP,KAAK,GACL;QACE,IAAI,EAAE,IAAI,CAAC;QACX,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,EAAE,aAAa,CAAC;QAC7B,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;KACvC,CAAC;IACN,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAoGA"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
|
+
import { hasAllVariants } from "./hasAllVariants.js";
|
|
3
|
+
export function maybeInitialData(variants, variant, code, fileName) {
|
|
4
|
+
var needsHighlight = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
5
|
+
var needsAllFiles = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
6
|
+
var needsAllVariants = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
7
|
+
if (!code) {
|
|
8
|
+
return {
|
|
9
|
+
initialData: false,
|
|
10
|
+
reason: 'No code provided'
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
if (needsAllVariants && !hasAllVariants(variants, code, needsHighlight)) {
|
|
14
|
+
return {
|
|
15
|
+
initialData: false,
|
|
16
|
+
reason: 'Not all variants are available'
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
var variantCode = code[variant];
|
|
20
|
+
if (!variantCode || typeof variantCode === 'string') {
|
|
21
|
+
return {
|
|
22
|
+
initialData: false,
|
|
23
|
+
reason: 'Variant code is not loaded yet'
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (needsAllFiles) {
|
|
27
|
+
if (!variantCode) {
|
|
28
|
+
return {
|
|
29
|
+
initialData: false,
|
|
30
|
+
reason: 'Variant code not found'
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (!variantCode.source) {
|
|
34
|
+
return {
|
|
35
|
+
initialData: false,
|
|
36
|
+
reason: 'Variant source not found'
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (variantCode.extraFiles && !Object.keys(variantCode.extraFiles).every(function (file) {
|
|
40
|
+
var _variantCode$extraFil;
|
|
41
|
+
var fileData = (_variantCode$extraFil = variantCode.extraFiles) == null ? void 0 : _variantCode$extraFil[file];
|
|
42
|
+
return _typeof(fileData) === 'object' && (fileData == null ? void 0 : fileData.source) !== undefined;
|
|
43
|
+
})) {
|
|
44
|
+
return {
|
|
45
|
+
initialData: false,
|
|
46
|
+
reason: 'Not all extra files are available'
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// TODO, filename might need to be determined from filesOrder if provided?
|
|
52
|
+
var initialFilename = fileName || variantCode.fileName;
|
|
53
|
+
var fileSource;
|
|
54
|
+
if (fileName && fileName !== variantCode.fileName) {
|
|
55
|
+
var _variantCode$extraFil2;
|
|
56
|
+
var fileData = variantCode == null || (_variantCode$extraFil2 = variantCode.extraFiles) == null ? void 0 : _variantCode$extraFil2[fileName];
|
|
57
|
+
if (!fileData) {
|
|
58
|
+
return {
|
|
59
|
+
initialData: false,
|
|
60
|
+
reason: "File not found in code"
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (typeof fileData === 'string') {
|
|
64
|
+
// It's a URL, not actual source content
|
|
65
|
+
return {
|
|
66
|
+
initialData: false,
|
|
67
|
+
reason: "File is not loaded yet"
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
fileSource = fileData.source;
|
|
71
|
+
} else {
|
|
72
|
+
fileSource = variantCode.source;
|
|
73
|
+
}
|
|
74
|
+
if (!fileSource) {
|
|
75
|
+
return {
|
|
76
|
+
initialData: false,
|
|
77
|
+
reason: "File source not found"
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (needsHighlight && typeof fileSource === 'string') {
|
|
81
|
+
return {
|
|
82
|
+
initialData: false,
|
|
83
|
+
reason: 'File needs highlighting'
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
initialData: {
|
|
88
|
+
code: code,
|
|
89
|
+
initialFilename: initialFilename,
|
|
90
|
+
initialSource: fileSource,
|
|
91
|
+
initialExtraFiles: variantCode == null ? void 0 : variantCode.extraFiles
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Code, ParseSource } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Pure function to parse code variants and their extraFiles.
|
|
4
|
+
* Converts string sources to HAST nodes and handles hastJson parsing.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseCode(code: Code, parseSource: ParseSource): Code;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseCode.d.ts","sourceRoot":"","sources":["../../../src/CodeHighlighter/parseCode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEjD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,GAAG,IAAI,CAwHpE"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
+
/**
|
|
5
|
+
* Pure function to parse code variants and their extraFiles.
|
|
6
|
+
* Converts string sources to HAST nodes and handles hastJson parsing.
|
|
7
|
+
*/
|
|
8
|
+
export function parseCode(code, parseSource) {
|
|
9
|
+
var parsed = {};
|
|
10
|
+
for (var _i = 0, _Object$entries = Object.entries(code); _i < _Object$entries.length; _i++) {
|
|
11
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
12
|
+
variant = _Object$entries$_i[0],
|
|
13
|
+
variantCode = _Object$entries$_i[1];
|
|
14
|
+
if (typeof variantCode === 'string') {
|
|
15
|
+
// Already parsed/highlighted
|
|
16
|
+
parsed[variant] = variantCode;
|
|
17
|
+
} else if (variantCode && _typeof(variantCode) === 'object') {
|
|
18
|
+
// Parse if source is available and not already parsed
|
|
19
|
+
if (variantCode.source && typeof variantCode.source === 'string') {
|
|
20
|
+
try {
|
|
21
|
+
var hastNodes = parseSource(variantCode.source, variantCode.fileName);
|
|
22
|
+
|
|
23
|
+
// Also parse extraFiles if they contain sources that need parsing
|
|
24
|
+
var parsedExtraFiles = variantCode.extraFiles ? Object.fromEntries(Object.entries(variantCode.extraFiles).map(function (_ref) {
|
|
25
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
26
|
+
fileName = _ref2[0],
|
|
27
|
+
fileContent = _ref2[1];
|
|
28
|
+
if (typeof fileContent === 'string') {
|
|
29
|
+
return [fileName, fileContent]; // Keep string as-is
|
|
30
|
+
}
|
|
31
|
+
if (fileContent && _typeof(fileContent) === 'object' && fileContent.source) {
|
|
32
|
+
if (typeof fileContent.source === 'string') {
|
|
33
|
+
// Parse string source in extraFile
|
|
34
|
+
try {
|
|
35
|
+
var parsedHastNodes = parseSource(fileContent.source, fileName);
|
|
36
|
+
return [fileName, _objectSpread(_objectSpread({}, fileContent), {}, {
|
|
37
|
+
source: parsedHastNodes
|
|
38
|
+
})];
|
|
39
|
+
} catch (error) {
|
|
40
|
+
return [fileName, fileContent]; // Keep original if parsing fails
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return [fileName, fileContent]; // Keep as-is for other cases
|
|
45
|
+
})) : undefined;
|
|
46
|
+
parsed[variant] = _objectSpread(_objectSpread({}, variantCode), {}, {
|
|
47
|
+
source: hastNodes,
|
|
48
|
+
extraFiles: parsedExtraFiles
|
|
49
|
+
});
|
|
50
|
+
} catch (error) {
|
|
51
|
+
// Keep original if parsing fails
|
|
52
|
+
parsed[variant] = variantCode;
|
|
53
|
+
}
|
|
54
|
+
} else if (variantCode.source && _typeof(variantCode.source) === 'object' && 'hastJson' in variantCode.source) {
|
|
55
|
+
try {
|
|
56
|
+
// Parse hastJson to HAST nodes
|
|
57
|
+
var _hastNodes = JSON.parse(variantCode.source.hastJson);
|
|
58
|
+
|
|
59
|
+
// Also parse extraFiles if they contain sources that need parsing
|
|
60
|
+
var _parsedExtraFiles = variantCode.extraFiles ? Object.fromEntries(Object.entries(variantCode.extraFiles).map(function (_ref3) {
|
|
61
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
62
|
+
fileName = _ref4[0],
|
|
63
|
+
fileContent = _ref4[1];
|
|
64
|
+
if (typeof fileContent === 'string') {
|
|
65
|
+
return [fileName, fileContent]; // Keep string as-is
|
|
66
|
+
}
|
|
67
|
+
if (fileContent && _typeof(fileContent) === 'object' && fileContent.source) {
|
|
68
|
+
if (typeof fileContent.source === 'string') {
|
|
69
|
+
// Parse string source in extraFile
|
|
70
|
+
try {
|
|
71
|
+
var parsedHastNodes = parseSource(fileContent.source, fileName);
|
|
72
|
+
return [fileName, _objectSpread(_objectSpread({}, fileContent), {}, {
|
|
73
|
+
source: parsedHastNodes
|
|
74
|
+
})];
|
|
75
|
+
} catch (error) {
|
|
76
|
+
return [fileName, fileContent]; // Keep original if parsing fails
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return [fileName, fileContent]; // Keep as-is for other cases
|
|
81
|
+
})) : undefined;
|
|
82
|
+
parsed[variant] = _objectSpread(_objectSpread({}, variantCode), {}, {
|
|
83
|
+
source: _hastNodes,
|
|
84
|
+
extraFiles: _parsedExtraFiles
|
|
85
|
+
});
|
|
86
|
+
} catch (error) {
|
|
87
|
+
// Keep original if parsing fails
|
|
88
|
+
console.error("Failed to parse hastJson for variant ".concat(variant, ":"), error);
|
|
89
|
+
parsed[variant] = variantCode;
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
// Already parsed or no source to parse - but still check extraFiles
|
|
93
|
+
var _parsedExtraFiles2 = variantCode.extraFiles ? Object.fromEntries(Object.entries(variantCode.extraFiles).map(function (_ref5) {
|
|
94
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
95
|
+
fileName = _ref6[0],
|
|
96
|
+
fileContent = _ref6[1];
|
|
97
|
+
if (typeof fileContent === 'string') {
|
|
98
|
+
return [fileName, fileContent]; // Keep string as-is
|
|
99
|
+
}
|
|
100
|
+
if (fileContent && _typeof(fileContent) === 'object' && fileContent.source) {
|
|
101
|
+
if (typeof fileContent.source === 'string') {
|
|
102
|
+
// Parse string source in extraFile
|
|
103
|
+
try {
|
|
104
|
+
var parsedHastNodes = parseSource(fileContent.source, fileName);
|
|
105
|
+
return [fileName, _objectSpread(_objectSpread({}, fileContent), {}, {
|
|
106
|
+
source: parsedHastNodes
|
|
107
|
+
})];
|
|
108
|
+
} catch (error) {
|
|
109
|
+
return [fileName, fileContent]; // Keep original if parsing fails
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return [fileName, fileContent]; // Keep as-is for other cases
|
|
114
|
+
})) : undefined;
|
|
115
|
+
parsed[variant] = _objectSpread(_objectSpread({}, variantCode), {}, {
|
|
116
|
+
extraFiles: _parsedExtraFiles2
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return parsed;
|
|
122
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Code, ControlledCode, ParseSource } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Pure function to parse controlled code and convert it to regular Code format.
|
|
4
|
+
* Handles the conversion from ControlledCode (string|null sources) to Code (HAST nodes).
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseControlledCode(controlledCode: ControlledCode, parseSource: ParseSource): Code;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseControlledCode.d.ts","sourceRoot":"","sources":["../../../src/CodeHighlighter/parseControlledCode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEjE;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,cAAc,EAAE,cAAc,EAC9B,WAAW,EAAE,WAAW,GACvB,IAAI,CAiEN"}
|
|
@@ -0,0 +1,76 @@
|
|
|
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') {
|
|
23
|
+
try {
|
|
24
|
+
mainSource = parseSource(sourceToProcess, variantCode.fileName);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
// Keep original string if parsing fails
|
|
27
|
+
mainSource = sourceToProcess;
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
// Handle undefined or other non-string values
|
|
31
|
+
mainSource = sourceToProcess;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Parse extraFiles if present
|
|
35
|
+
var extraFiles = void 0;
|
|
36
|
+
if (variantCode.extraFiles) {
|
|
37
|
+
var parsedExtraFiles = {};
|
|
38
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(variantCode.extraFiles); _i2 < _Object$entries2.length; _i2++) {
|
|
39
|
+
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
40
|
+
fileName = _Object$entries2$_i[0],
|
|
41
|
+
fileData = _Object$entries2$_i[1];
|
|
42
|
+
// Convert null to empty string, then parse
|
|
43
|
+
var fileSourceToProcess = fileData.source === null ? '' : fileData.source;
|
|
44
|
+
if (typeof fileSourceToProcess === 'string') {
|
|
45
|
+
// Parse string sources
|
|
46
|
+
try {
|
|
47
|
+
var parsedSource = parseSource(fileSourceToProcess, fileName);
|
|
48
|
+
parsedExtraFiles[fileName] = {
|
|
49
|
+
source: parsedSource
|
|
50
|
+
};
|
|
51
|
+
} catch (error) {
|
|
52
|
+
// Keep original if parsing fails
|
|
53
|
+
parsedExtraFiles[fileName] = {
|
|
54
|
+
source: fileSourceToProcess
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
// Keep other values as-is
|
|
59
|
+
parsedExtraFiles[fileName] = {
|
|
60
|
+
source: fileSourceToProcess
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
extraFiles = parsedExtraFiles;
|
|
65
|
+
}
|
|
66
|
+
parsed[variant] = {
|
|
67
|
+
fileName: variantCode.fileName,
|
|
68
|
+
url: variantCode.url,
|
|
69
|
+
source: mainSource,
|
|
70
|
+
extraFiles: extraFiles,
|
|
71
|
+
filesOrder: variantCode.filesOrder
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return parsed;
|
|
76
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
*/
|
|
10
|
+
export declare function getAvailableTransforms(parsedCode: Code | undefined, variantName: string): string[];
|
|
11
|
+
/**
|
|
12
|
+
* Pure async function to transform a single variant's code and extraFiles.
|
|
13
|
+
* Returns the transformed variant or the original if transformation fails.
|
|
14
|
+
*/
|
|
15
|
+
export declare function transformVariant(variant: string, variantCode: any, parseSource: ParseSource): Promise<any>;
|
|
16
|
+
/**
|
|
17
|
+
* Pure async function to apply transformations to all variants that need them.
|
|
18
|
+
* Returns the enhanced code with computed transforms.
|
|
19
|
+
*/
|
|
20
|
+
export declare function applyTransforms(parsedCode: Code, parseSource: ParseSource): Promise<Code>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformCode.d.ts","sourceRoot":"","sources":["../../../src/CodeHighlighter/transformCode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGjD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,IAAI,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CA4B7E;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,IAAI,GAAG,SAAS,EAC5B,WAAW,EAAE,MAAM,GAClB,MAAM,EAAE,CAQV;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,GAAG,EAChB,WAAW,EAAE,WAAW,GACvB,OAAO,CAAC,GAAG,CAAC,CA6Ed;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA8B/F"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
3
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
4
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
5
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
6
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
7
|
+
import { toText } from 'hast-util-to-text';
|
|
8
|
+
import { transformParsedSource } from "./transformParsedSource.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Pure function to identify which variants need transformation.
|
|
12
|
+
* Returns entries of variants that have transforms requiring processing.
|
|
13
|
+
*/
|
|
14
|
+
export function getVariantsToTransform(parsedCode) {
|
|
15
|
+
return Object.entries(parsedCode).filter(function (_ref) {
|
|
16
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
17
|
+
variantCode = _ref2[1];
|
|
18
|
+
if (!variantCode || _typeof(variantCode) !== 'object') {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Check if main source has transforms and needs processing
|
|
23
|
+
var mainSourceNeedsTransform = variantCode.transforms && variantCode.source && typeof variantCode.source !== 'string' && !('hastJson' in variantCode.source);
|
|
24
|
+
|
|
25
|
+
// Check if any extraFiles have transforms and need processing
|
|
26
|
+
var extraFilesNeedTransform = variantCode.extraFiles ? Object.values(variantCode.extraFiles).some(function (fileContent) {
|
|
27
|
+
return _typeof(fileContent) === 'object' && fileContent && fileContent.transforms && fileContent.source && typeof fileContent.source !== 'string' && !('hastJson' in fileContent.source);
|
|
28
|
+
}) : false;
|
|
29
|
+
return mainSourceNeedsTransform || extraFilesNeedTransform;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Pure function to get available transforms from a specific variant.
|
|
35
|
+
*/
|
|
36
|
+
export function getAvailableTransforms(parsedCode, variantName) {
|
|
37
|
+
var currentVariant = parsedCode == null ? void 0 : parsedCode[variantName];
|
|
38
|
+
if (currentVariant && _typeof(currentVariant) === 'object' && currentVariant.transforms) {
|
|
39
|
+
return Object.keys(currentVariant.transforms);
|
|
40
|
+
}
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Pure async function to transform a single variant's code and extraFiles.
|
|
46
|
+
* Returns the transformed variant or the original if transformation fails.
|
|
47
|
+
*/
|
|
48
|
+
export function transformVariant(_x, _x2, _x3) {
|
|
49
|
+
return _transformVariant.apply(this, arguments);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Pure async function to apply transformations to all variants that need them.
|
|
54
|
+
* Returns the enhanced code with computed transforms.
|
|
55
|
+
*/
|
|
56
|
+
function _transformVariant() {
|
|
57
|
+
_transformVariant = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(variant, variantCode, parseSource) {
|
|
58
|
+
var mainTransformResult, transformedExtraFiles, hastNodes, sourceString, transformedVariant;
|
|
59
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
60
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
61
|
+
case 0:
|
|
62
|
+
if (!(_typeof(variantCode) !== 'object' || !variantCode)) {
|
|
63
|
+
_context2.next = 2;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
return _context2.abrupt("return", variantCode);
|
|
67
|
+
case 2:
|
|
68
|
+
if (!(variantCode.transforms && variantCode.source && typeof variantCode.source !== 'string' && !('hastJson' in variantCode.source))) {
|
|
69
|
+
_context2.next = 8;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
hastNodes = variantCode.source;
|
|
73
|
+
sourceString = toText(hastNodes, {
|
|
74
|
+
whitespace: 'pre'
|
|
75
|
+
});
|
|
76
|
+
_context2.next = 7;
|
|
77
|
+
return transformParsedSource(sourceString, hastNodes, variant,
|
|
78
|
+
// fileName
|
|
79
|
+
variantCode.transforms, parseSource);
|
|
80
|
+
case 7:
|
|
81
|
+
mainTransformResult = _context2.sent;
|
|
82
|
+
case 8:
|
|
83
|
+
if (!variantCode.extraFiles) {
|
|
84
|
+
_context2.next = 12;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
_context2.next = 11;
|
|
88
|
+
return Promise.all(Object.entries(variantCode.extraFiles).map(/*#__PURE__*/function () {
|
|
89
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref3) {
|
|
90
|
+
var _ref5, fileName, fileContent, extraHastNodes, extraSourceString, extraTransformResult;
|
|
91
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
92
|
+
while (1) switch (_context.prev = _context.next) {
|
|
93
|
+
case 0:
|
|
94
|
+
_ref5 = _slicedToArray(_ref3, 2), fileName = _ref5[0], fileContent = _ref5[1];
|
|
95
|
+
if (!(_typeof(fileContent) === 'object' && fileContent && fileContent.transforms && fileContent.source && typeof fileContent.source !== 'string' && !('hastJson' in fileContent.source))) {
|
|
96
|
+
_context.next = 15;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
_context.prev = 2;
|
|
100
|
+
extraHastNodes = fileContent.source;
|
|
101
|
+
extraSourceString = toText(extraHastNodes, {
|
|
102
|
+
whitespace: 'pre'
|
|
103
|
+
});
|
|
104
|
+
_context.next = 7;
|
|
105
|
+
return transformParsedSource(extraSourceString, extraHastNodes, fileName, fileContent.transforms, parseSource);
|
|
106
|
+
case 7:
|
|
107
|
+
extraTransformResult = _context.sent;
|
|
108
|
+
return _context.abrupt("return", [fileName, _objectSpread(_objectSpread({}, fileContent), {}, {
|
|
109
|
+
transforms: extraTransformResult
|
|
110
|
+
})]);
|
|
111
|
+
case 11:
|
|
112
|
+
_context.prev = 11;
|
|
113
|
+
_context.t0 = _context["catch"](2);
|
|
114
|
+
console.error("Failed to transform extraFile ".concat(fileName, ":"), _context.t0);
|
|
115
|
+
return _context.abrupt("return", [fileName, fileContent]);
|
|
116
|
+
case 15:
|
|
117
|
+
return _context.abrupt("return", [fileName, fileContent]);
|
|
118
|
+
case 16:
|
|
119
|
+
case "end":
|
|
120
|
+
return _context.stop();
|
|
121
|
+
}
|
|
122
|
+
}, _callee, null, [[2, 11]]);
|
|
123
|
+
}));
|
|
124
|
+
return function (_x6) {
|
|
125
|
+
return _ref4.apply(this, arguments);
|
|
126
|
+
};
|
|
127
|
+
}())).then(function (entries) {
|
|
128
|
+
return Object.fromEntries(entries);
|
|
129
|
+
});
|
|
130
|
+
case 11:
|
|
131
|
+
transformedExtraFiles = _context2.sent;
|
|
132
|
+
case 12:
|
|
133
|
+
// Update the variant with the computed results
|
|
134
|
+
transformedVariant = _objectSpread(_objectSpread(_objectSpread({}, variantCode), mainTransformResult && {
|
|
135
|
+
transforms: mainTransformResult
|
|
136
|
+
}), transformedExtraFiles && {
|
|
137
|
+
extraFiles: transformedExtraFiles
|
|
138
|
+
});
|
|
139
|
+
return _context2.abrupt("return", transformedVariant);
|
|
140
|
+
case 14:
|
|
141
|
+
case "end":
|
|
142
|
+
return _context2.stop();
|
|
143
|
+
}
|
|
144
|
+
}, _callee2);
|
|
145
|
+
}));
|
|
146
|
+
return _transformVariant.apply(this, arguments);
|
|
147
|
+
}
|
|
148
|
+
export function applyTransforms(_x4, _x5) {
|
|
149
|
+
return _applyTransforms.apply(this, arguments);
|
|
150
|
+
}
|
|
151
|
+
function _applyTransforms() {
|
|
152
|
+
_applyTransforms = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(parsedCode, parseSource) {
|
|
153
|
+
var variantsToTransform, results, enhancedCode, _iterator, _step, _step$value, variant, transformedVariant;
|
|
154
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
155
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
156
|
+
case 0:
|
|
157
|
+
variantsToTransform = getVariantsToTransform(parsedCode);
|
|
158
|
+
if (!(variantsToTransform.length === 0)) {
|
|
159
|
+
_context4.next = 3;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
return _context4.abrupt("return", parsedCode);
|
|
163
|
+
case 3:
|
|
164
|
+
_context4.next = 5;
|
|
165
|
+
return Promise.all(variantsToTransform.map(/*#__PURE__*/function () {
|
|
166
|
+
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref6) {
|
|
167
|
+
var _ref8, variant, variantCode, transformedVariant;
|
|
168
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
169
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
170
|
+
case 0:
|
|
171
|
+
_ref8 = _slicedToArray(_ref6, 2), variant = _ref8[0], variantCode = _ref8[1];
|
|
172
|
+
_context3.prev = 1;
|
|
173
|
+
_context3.next = 4;
|
|
174
|
+
return transformVariant(variant, variantCode, parseSource);
|
|
175
|
+
case 4:
|
|
176
|
+
transformedVariant = _context3.sent;
|
|
177
|
+
return _context3.abrupt("return", {
|
|
178
|
+
variant: variant,
|
|
179
|
+
transformedVariant: transformedVariant
|
|
180
|
+
});
|
|
181
|
+
case 8:
|
|
182
|
+
_context3.prev = 8;
|
|
183
|
+
_context3.t0 = _context3["catch"](1);
|
|
184
|
+
// Keep original variant if transformation fails
|
|
185
|
+
console.error("Failed to transform variant ".concat(variant, ":"), _context3.t0);
|
|
186
|
+
return _context3.abrupt("return", {
|
|
187
|
+
variant: variant,
|
|
188
|
+
transformedVariant: variantCode
|
|
189
|
+
});
|
|
190
|
+
case 12:
|
|
191
|
+
case "end":
|
|
192
|
+
return _context3.stop();
|
|
193
|
+
}
|
|
194
|
+
}, _callee3, null, [[1, 8]]);
|
|
195
|
+
}));
|
|
196
|
+
return function (_x7) {
|
|
197
|
+
return _ref7.apply(this, arguments);
|
|
198
|
+
};
|
|
199
|
+
}()));
|
|
200
|
+
case 5:
|
|
201
|
+
results = _context4.sent;
|
|
202
|
+
// Apply the transformations to create the enhanced code
|
|
203
|
+
enhancedCode = _objectSpread({}, parsedCode);
|
|
204
|
+
_iterator = _createForOfIteratorHelper(results);
|
|
205
|
+
try {
|
|
206
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
207
|
+
_step$value = _step.value, variant = _step$value.variant, transformedVariant = _step$value.transformedVariant;
|
|
208
|
+
enhancedCode[variant] = transformedVariant;
|
|
209
|
+
}
|
|
210
|
+
} catch (err) {
|
|
211
|
+
_iterator.e(err);
|
|
212
|
+
} finally {
|
|
213
|
+
_iterator.f();
|
|
214
|
+
}
|
|
215
|
+
return _context4.abrupt("return", enhancedCode);
|
|
216
|
+
case 10:
|
|
217
|
+
case "end":
|
|
218
|
+
return _context4.stop();
|
|
219
|
+
}
|
|
220
|
+
}, _callee4);
|
|
221
|
+
}));
|
|
222
|
+
return _applyTransforms.apply(this, arguments);
|
|
223
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformParsedSource.d.ts","sourceRoot":"","sources":["../../../src/CodeHighlighter/transformParsedSource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAIlD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,KAAK,EACnB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW,GACvB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAwB9B"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
5
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
6
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
7
|
+
import { create, patch } from 'jsondiffpatch';
|
|
8
|
+
var differ = create({
|
|
9
|
+
omitRemovedValues: true,
|
|
10
|
+
cloneDiffValues: true
|
|
11
|
+
});
|
|
12
|
+
export function transformParsedSource(_x, _x2, _x3, _x4, _x5) {
|
|
13
|
+
return _transformParsedSource.apply(this, arguments);
|
|
14
|
+
}
|
|
15
|
+
function _transformParsedSource() {
|
|
16
|
+
_transformParsedSource = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(source, parsedSource, filename, transforms, parseSource) {
|
|
17
|
+
var transformed;
|
|
18
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
19
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
20
|
+
case 0:
|
|
21
|
+
_context2.next = 2;
|
|
22
|
+
return Promise.all(Object.entries(transforms).map(/*#__PURE__*/function () {
|
|
23
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
24
|
+
var _ref3, key, transform, patched, transformedSource, parsedTransform, delta;
|
|
25
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
26
|
+
while (1) switch (_context.prev = _context.next) {
|
|
27
|
+
case 0:
|
|
28
|
+
_ref3 = _slicedToArray(_ref, 2), key = _ref3[0], transform = _ref3[1];
|
|
29
|
+
patched = patch(source.split('\n'), transform.delta);
|
|
30
|
+
if (Array.isArray(patched)) {
|
|
31
|
+
_context.next = 4;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
throw new Error("Patch for ".concat(key, " did not return an array"));
|
|
35
|
+
case 4:
|
|
36
|
+
transformedSource = patched.join('\n');
|
|
37
|
+
_context.next = 7;
|
|
38
|
+
return parseSource(transformedSource, transform.fileName || filename);
|
|
39
|
+
case 7:
|
|
40
|
+
parsedTransform = _context.sent;
|
|
41
|
+
// TODO: further optimize this delta, it looks a little noisy
|
|
42
|
+
delta = differ.diff(parsedSource, parsedTransform);
|
|
43
|
+
return _context.abrupt("return", _defineProperty({}, key, _objectSpread(_objectSpread({}, transform), {}, {
|
|
44
|
+
delta: delta
|
|
45
|
+
})));
|
|
46
|
+
case 10:
|
|
47
|
+
case "end":
|
|
48
|
+
return _context.stop();
|
|
49
|
+
}
|
|
50
|
+
}, _callee);
|
|
51
|
+
}));
|
|
52
|
+
return function (_x6) {
|
|
53
|
+
return _ref2.apply(this, arguments);
|
|
54
|
+
};
|
|
55
|
+
}()));
|
|
56
|
+
case 2:
|
|
57
|
+
transformed = _context2.sent;
|
|
58
|
+
return _context2.abrupt("return", Object.assign.apply(Object, [{}].concat(_toConsumableArray(transformed))));
|
|
59
|
+
case 4:
|
|
60
|
+
case "end":
|
|
61
|
+
return _context2.stop();
|
|
62
|
+
}
|
|
63
|
+
}, _callee2);
|
|
64
|
+
}));
|
|
65
|
+
return _transformParsedSource.apply(this, arguments);
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformSource.d.ts","sourceRoot":"","sources":["../../../src/CodeHighlighter/transformSource.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAI7E,wBAAsB,eAAe,CACnC,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,MAAM,EAChB,kBAAkB,EAAE,kBAAkB,GACrC,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAuDjC"}
|