@thxgg/steward 0.1.25 → 0.1.26
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/.output/nitro.json +1 -1
- package/.output/public/_nuxt/{Bc2V3wPK.js → B2ow85x_.js} +2 -2
- package/.output/public/_nuxt/{U78rMDmo.js → B6CbIr08.js} +1 -1
- package/.output/public/_nuxt/{BknRrWsw.js → BLQAF8wp.js} +1 -1
- package/.output/public/_nuxt/BXuwtOqb.js +1 -0
- package/.output/public/_nuxt/CAMiEhze.js +1 -0
- package/.output/public/_nuxt/{BRQ9Cxaw.js → CIBCqZF5.js} +1 -1
- package/.output/public/_nuxt/Ce0-nlm9.js +1 -0
- package/.output/public/_nuxt/{T11EuTtn.js → ConzneVY.js} +1 -1
- package/.output/public/_nuxt/D0qxz_Pn.js +1310 -0
- package/.output/public/_nuxt/D3PDtLSF.js +3 -0
- package/.output/public/_nuxt/{C73kduX-.js → DdKC0UAK.js} +1 -1
- package/.output/public/_nuxt/Detail.BGdvrJGh.css +1 -0
- package/.output/public/_nuxt/{C53_p0K1.js → Dkh9ic1y.js} +1 -1
- package/.output/public/_nuxt/LEjJTR7-.js +1 -0
- package/.output/public/_nuxt/{BTmXUZ_s.js → UqZfMfrZ.js} +1 -1
- package/.output/public/_nuxt/builds/latest.json +1 -1
- package/.output/public/_nuxt/builds/meta/25438e34-19a2-421d-aede-53fd18f1ccd4.json +1 -0
- package/.output/public/_nuxt/dckrK0oj.js +1 -0
- package/.output/public/_nuxt/entry.DT4p6_uW.css +1 -0
- package/.output/public/_nuxt/pIWeVmPw.js +1 -0
- package/.output/public/_nuxt/xrHaPo1U.js +60 -0
- package/.output/server/chunks/build/{Detail-DMMUwTWr.mjs → Detail-rpcemNXe.mjs} +674 -481
- package/.output/server/chunks/build/Detail-rpcemNXe.mjs.map +1 -0
- package/.output/server/chunks/build/DiffViewer-styles.B1FB5NJj.mjs +8 -0
- package/.output/server/chunks/build/DiffViewer-styles.B1FB5NJj.mjs.map +1 -0
- package/.output/server/chunks/build/{_prd_-ByugK4Yi.mjs → _prd_-CeibvZOH.mjs} +67 -233
- package/.output/server/chunks/build/_prd_-CeibvZOH.mjs.map +1 -0
- package/.output/server/chunks/build/client.precomputed.mjs +1 -1
- package/.output/server/chunks/build/{default-BKKgG7HJ.mjs → default-iq8SaDDN.mjs} +3 -3
- package/.output/server/chunks/build/default-iq8SaDDN.mjs.map +1 -0
- package/.output/server/chunks/build/{error-404-Bf6kdO80.mjs → error-404-DFale9A5.mjs} +2 -2
- package/.output/server/chunks/build/error-404-DFale9A5.mjs.map +1 -0
- package/.output/server/chunks/build/{index-DE1tjHAd.mjs → index-Po00RvHm.mjs} +2 -2
- package/.output/server/chunks/build/index-Po00RvHm.mjs.map +1 -0
- package/.output/server/chunks/build/{nuxt-link-SvT1nf8Z.mjs → nuxt-link-B4oWFn7n.mjs} +2 -2
- package/.output/server/chunks/build/nuxt-link-B4oWFn7n.mjs.map +1 -0
- package/.output/server/chunks/build/{repo-graph-DzT45gSB.mjs → repo-graph-BQVFpA-w.mjs} +5 -4
- package/.output/server/chunks/build/repo-graph-BQVFpA-w.mjs.map +1 -0
- package/.output/server/chunks/build/server.mjs +7 -7
- package/.output/server/chunks/build/styles.mjs +4 -5
- package/.output/server/chunks/build/{usePrd-hXZOmvAv.mjs → usePrd-Bb6jlnNZ.mjs} +2 -2
- package/.output/server/chunks/build/usePrd-Bb6jlnNZ.mjs.map +1 -0
- package/.output/server/chunks/nitro/nitro.mjs +663 -660
- package/.output/server/node_modules/@pierre/diffs/dist/components/File.js +324 -0
- package/.output/server/node_modules/@pierre/diffs/dist/components/FileDiff.js +395 -0
- package/.output/server/node_modules/@pierre/diffs/dist/components/FileStream.js +161 -0
- package/.output/server/node_modules/@pierre/diffs/dist/components/web-components.js +25 -0
- package/.output/server/node_modules/@pierre/diffs/dist/constants.js +23 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/areLanguagesAttached.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/attachResolvedLanguages.js +20 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/cleanUpResolvedLanguages.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/constants.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/getResolvedLanguages.js +16 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/getResolvedOrResolveLanguage.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/hasResolvedLanguages.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/resolveLanguage.js +30 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/languages/resolveLanguages.js +25 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/shared_highlighter.js +71 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/areThemesAttached.js +12 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/attachResolvedThemes.js +24 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/cleanUpResolvedThemes.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/constants.js +9 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/getResolvedOrResolveTheme.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/getResolvedThemes.js +16 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/hasResolvedThemes.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/registerCustomCSSVariableTheme.js +18 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/registerCustomTheme.js +14 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/resolveTheme.js +35 -0
- package/.output/server/node_modules/@pierre/diffs/dist/highlighter/themes/resolveThemes.js +21 -0
- package/.output/server/node_modules/@pierre/diffs/dist/index.js +84 -0
- package/.output/server/node_modules/@pierre/diffs/dist/managers/LineSelectionManager.js +282 -0
- package/.output/server/node_modules/@pierre/diffs/dist/managers/MouseEventManager.js +244 -0
- package/.output/server/node_modules/@pierre/diffs/dist/managers/ResizeManager.js +132 -0
- package/.output/server/node_modules/@pierre/diffs/dist/managers/ScrollSyncManager.js +62 -0
- package/.output/server/node_modules/@pierre/diffs/dist/managers/UniversalRenderingManager.js +32 -0
- package/.output/server/node_modules/@pierre/diffs/dist/renderers/DiffHunksRenderer.js +655 -0
- package/.output/server/node_modules/@pierre/diffs/dist/renderers/FileRenderer.js +243 -0
- package/.output/server/node_modules/@pierre/diffs/dist/shiki-stream/stream.js +32 -0
- package/.output/server/node_modules/@pierre/diffs/dist/shiki-stream/tokenizer.js +71 -0
- package/.output/server/node_modules/@pierre/diffs/dist/sprite.js +55 -0
- package/.output/server/node_modules/@pierre/diffs/dist/style.js +6 -0
- package/.output/server/node_modules/@pierre/diffs/dist/themes/pierre-dark.js +1328 -0
- package/.output/server/node_modules/@pierre/diffs/dist/themes/pierre-light.js +1328 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/areFilesEqual.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/areObjectsEqual.js +18 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/areOptionsEqual.js +12 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/areSelectionsEqual.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/areThemesEqual.js +9 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/cleanLastNewline.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createAnnotationElement.js +21 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createAnnotationWrapperNode.js +12 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createCodeNode.js +12 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createEmptyRowBuffer.js +16 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createFileHeaderElement.js +84 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createHoverContentNode.js +15 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createNoNewlineElement.js +24 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createPreElement.js +28 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createRowNodes.js +20 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createSeparator.js +69 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createSpanNodeFromToken.js +13 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createStyleElement.js +19 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createTransformerWithState.js +56 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/createUnsafeCSSStyleNode.js +12 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/cssWrappers.js +21 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/diffAcceptRejectHunk.js +82 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/formatCSSVariablePrefix.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getFiletypeFromFileName.js +343 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getHighlighterOptions.js +13 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getHighlighterThemeStyles.js +40 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getHunkSeparatorSlotName.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getIconForType.js +15 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getLineAnnotationName.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getLineEndingType.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getLineNodes.js +15 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getSingularPatch.js +20 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getThemes.js +16 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/getTotalLineCountFromHunks.js +10 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/hast_utils.js +42 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/isWorkerContext.js +8 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/parseDiffDecorations.js +34 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/parseDiffFromFile.js +23 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/parseLineType.js +17 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/parsePatchFiles.js +211 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/prerenderHTMLIfNecessary.js +10 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/processLine.js +42 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/renderDiffWithHighlighter.js +339 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/renderFileWithHighlighter.js +52 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/setLanguageOverride.js +11 -0
- package/.output/server/node_modules/@pierre/diffs/dist/utils/setWrapperNodeProps.js +29 -0
- package/.output/server/node_modules/@pierre/diffs/package.json +89 -0
- package/.output/server/node_modules/@shikijs/transformers/dist/index.mjs +831 -0
- package/.output/server/node_modules/@shikijs/transformers/package.json +37 -0
- package/.output/server/node_modules/diff/libesm/convert/dmp.js +21 -0
- package/.output/server/node_modules/diff/libesm/convert/xml.js +31 -0
- package/.output/server/node_modules/diff/libesm/diff/array.js +16 -0
- package/.output/server/node_modules/diff/libesm/diff/base.js +253 -0
- package/.output/server/node_modules/diff/libesm/diff/character.js +7 -0
- package/.output/server/node_modules/diff/libesm/diff/css.js +10 -0
- package/.output/server/node_modules/diff/libesm/diff/json.js +78 -0
- package/.output/server/node_modules/diff/libesm/diff/line.js +65 -0
- package/.output/server/node_modules/diff/libesm/diff/sentence.js +43 -0
- package/.output/server/node_modules/diff/libesm/diff/word.js +296 -0
- package/.output/server/node_modules/diff/libesm/index.js +30 -0
- package/.output/server/node_modules/diff/libesm/package.json +1 -0
- package/.output/server/node_modules/diff/libesm/patch/apply.js +257 -0
- package/.output/server/node_modules/diff/libesm/patch/create.js +228 -0
- package/.output/server/node_modules/diff/libesm/patch/line-endings.js +44 -0
- package/.output/server/node_modules/diff/libesm/patch/parse.js +147 -0
- package/.output/server/node_modules/diff/libesm/patch/reverse.js +23 -0
- package/.output/server/node_modules/diff/libesm/util/distance-iterator.js +37 -0
- package/.output/server/node_modules/diff/libesm/util/params.js +14 -0
- package/.output/server/node_modules/diff/libesm/util/string.js +128 -0
- package/.output/server/node_modules/diff/package.json +132 -0
- package/.output/server/package.json +4 -1
- package/dist/server/utils/git.js +8 -6
- package/package.json +2 -1
- package/.output/public/_nuxt/6tINjQEd.js +0 -141
- package/.output/public/_nuxt/B2mIQf5X.js +0 -3
- package/.output/public/_nuxt/C0BBSDJ7.js +0 -1
- package/.output/public/_nuxt/CN46Bgts.js +0 -1
- package/.output/public/_nuxt/CTJgb0zb.js +0 -1
- package/.output/public/_nuxt/Cce168lk.js +0 -30
- package/.output/public/_nuxt/CyVSeLw5.js +0 -1
- package/.output/public/_nuxt/Detail.CYc96mGf.css +0 -1
- package/.output/public/_nuxt/ZNypZshD.js +0 -13
- package/.output/public/_nuxt/builds/meta/9ce7f1bc-d5e2-47bf-8026-f4910c257b2e.json +0 -1
- package/.output/public/_nuxt/entry.Bw0CE6Iz.css +0 -1
- package/.output/public/_nuxt/pYJYAY-W.js +0 -60
- package/.output/server/chunks/build/Detail-DMMUwTWr.mjs.map +0 -1
- package/.output/server/chunks/build/DiffViewer-styles-1.mjs-d2dQvARr.mjs +0 -4
- package/.output/server/chunks/build/DiffViewer-styles-1.mjs-d2dQvARr.mjs.map +0 -1
- package/.output/server/chunks/build/DiffViewer-styles-2.mjs-X6QKNjM0.mjs +0 -4
- package/.output/server/chunks/build/DiffViewer-styles-2.mjs-X6QKNjM0.mjs.map +0 -1
- package/.output/server/chunks/build/DiffViewer-styles.0AbHFl6N.mjs +0 -8
- package/.output/server/chunks/build/DiffViewer-styles.0AbHFl6N.mjs.map +0 -1
- package/.output/server/chunks/build/DiffViewer-styles.BDwAqkTk.mjs +0 -8
- package/.output/server/chunks/build/DiffViewer-styles.BDwAqkTk.mjs.map +0 -1
- package/.output/server/chunks/build/DiffViewer-styles.DRJh5Ui4.mjs +0 -10
- package/.output/server/chunks/build/DiffViewer-styles.DRJh5Ui4.mjs.map +0 -1
- package/.output/server/chunks/build/_prd_-ByugK4Yi.mjs.map +0 -1
- package/.output/server/chunks/build/default-BKKgG7HJ.mjs.map +0 -1
- package/.output/server/chunks/build/error-404-Bf6kdO80.mjs.map +0 -1
- package/.output/server/chunks/build/index-DE1tjHAd.mjs.map +0 -1
- package/.output/server/chunks/build/nuxt-link-SvT1nf8Z.mjs.map +0 -1
- package/.output/server/chunks/build/repo-graph-DzT45gSB.mjs.map +0 -1
- package/.output/server/chunks/build/usePrd-hXZOmvAv.mjs.map +0 -1
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { ALTERNATE_FILE_NAMES_GIT, COMMIT_METADATA_SPLIT, FILENAME_HEADER_REGEX, FILENAME_HEADER_REGEX_GIT, FILE_CONTEXT_BLOB, FILE_MODE_FROM_INDEX, GIT_DIFF_FILE_BREAK_REGEX, HUNK_HEADER, SPLIT_WITH_NEWLINES, UNIFIED_DIFF_FILE_BREAK_REGEX } from "../constants.js";
|
|
2
|
+
import { cleanLastNewline } from "./cleanLastNewline.js";
|
|
3
|
+
import { parseLineType } from "./parseLineType.js";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/parsePatchFiles.ts
|
|
6
|
+
function processPatch(data, cacheKeyPrefix) {
|
|
7
|
+
const isGitDiff = GIT_DIFF_FILE_BREAK_REGEX.test(data);
|
|
8
|
+
const rawFiles = data.split(isGitDiff ? GIT_DIFF_FILE_BREAK_REGEX : UNIFIED_DIFF_FILE_BREAK_REGEX);
|
|
9
|
+
let patchMetadata;
|
|
10
|
+
const files = [];
|
|
11
|
+
let currentFile;
|
|
12
|
+
for (const file of rawFiles) {
|
|
13
|
+
if (isGitDiff && !GIT_DIFF_FILE_BREAK_REGEX.test(file)) {
|
|
14
|
+
if (patchMetadata == null) patchMetadata = file;
|
|
15
|
+
else console.error("parsePatchContent: unknown file blob:", file);
|
|
16
|
+
continue;
|
|
17
|
+
} else if (!isGitDiff && !UNIFIED_DIFF_FILE_BREAK_REGEX.test(file)) {
|
|
18
|
+
if (patchMetadata == null) patchMetadata = file;
|
|
19
|
+
else console.error("parsePatchContent: unknown file blob:", file);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
let lastHunkEnd = 0;
|
|
23
|
+
const hunks = file.split(FILE_CONTEXT_BLOB);
|
|
24
|
+
currentFile = void 0;
|
|
25
|
+
for (const hunk of hunks) {
|
|
26
|
+
const lines = hunk.split(SPLIT_WITH_NEWLINES);
|
|
27
|
+
const firstLine = lines.shift();
|
|
28
|
+
if (firstLine == null) {
|
|
29
|
+
console.error("parsePatchContent: invalid hunk", hunk);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const match = firstLine.match(HUNK_HEADER);
|
|
33
|
+
const hunkContent = [];
|
|
34
|
+
let additionLines = 0;
|
|
35
|
+
let deletionLines = 0;
|
|
36
|
+
if (match == null || currentFile == null) {
|
|
37
|
+
if (currentFile != null) {
|
|
38
|
+
console.error("parsePatchContent: Invalid hunk", hunk);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
currentFile = {
|
|
42
|
+
name: "",
|
|
43
|
+
prevName: void 0,
|
|
44
|
+
type: "change",
|
|
45
|
+
hunks: [],
|
|
46
|
+
splitLineCount: 0,
|
|
47
|
+
unifiedLineCount: 0,
|
|
48
|
+
cacheKey: cacheKeyPrefix != null ? `${cacheKeyPrefix}-${files.length}` : void 0
|
|
49
|
+
};
|
|
50
|
+
lines.unshift(firstLine);
|
|
51
|
+
for (const line of lines) {
|
|
52
|
+
const filenameMatch = line.match(isGitDiff ? FILENAME_HEADER_REGEX_GIT : FILENAME_HEADER_REGEX);
|
|
53
|
+
if (line.startsWith("diff --git")) {
|
|
54
|
+
const [, , prevName, , name] = line.trim().match(ALTERNATE_FILE_NAMES_GIT) ?? [];
|
|
55
|
+
currentFile.name = name.trim();
|
|
56
|
+
if (prevName !== name) currentFile.prevName = prevName.trim();
|
|
57
|
+
} else if (filenameMatch != null) {
|
|
58
|
+
const [, type, fileName] = filenameMatch;
|
|
59
|
+
if (type === "---" && fileName !== "/dev/null") {
|
|
60
|
+
currentFile.prevName = fileName.trim();
|
|
61
|
+
currentFile.name = fileName.trim();
|
|
62
|
+
} else if (type === "+++" && fileName !== "/dev/null") currentFile.name = fileName.trim();
|
|
63
|
+
} else if (isGitDiff) {
|
|
64
|
+
if (line.startsWith("new mode ")) currentFile.mode = line.replace("new mode", "").trim();
|
|
65
|
+
if (line.startsWith("old mode ")) currentFile.oldMode = line.replace("old mode", "").trim();
|
|
66
|
+
if (line.startsWith("new file mode")) {
|
|
67
|
+
currentFile.type = "new";
|
|
68
|
+
currentFile.mode = line.replace("new file mode", "").trim();
|
|
69
|
+
}
|
|
70
|
+
if (line.startsWith("deleted file mode")) {
|
|
71
|
+
currentFile.type = "deleted";
|
|
72
|
+
currentFile.mode = line.replace("deleted file mode", "").trim();
|
|
73
|
+
}
|
|
74
|
+
if (line.startsWith("similarity index")) if (line.startsWith("similarity index 100%")) currentFile.type = "rename-pure";
|
|
75
|
+
else currentFile.type = "rename-changed";
|
|
76
|
+
if (line.startsWith("index ")) {
|
|
77
|
+
const [, mode] = line.trim().match(FILE_MODE_FROM_INDEX) ?? [];
|
|
78
|
+
if (mode != null) currentFile.mode = mode;
|
|
79
|
+
}
|
|
80
|
+
if (line.startsWith("rename from ")) currentFile.prevName = line.replace("rename from ", "");
|
|
81
|
+
if (line.startsWith("rename to ")) currentFile.name = line.replace("rename to ", "").trim();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
continue;
|
|
85
|
+
} else {
|
|
86
|
+
let currentContent;
|
|
87
|
+
let lastLineType;
|
|
88
|
+
while (lines.length > 0 && (lines[lines.length - 1] === "\n" || lines[lines.length - 1] === "")) lines.pop();
|
|
89
|
+
for (const rawLine of lines) {
|
|
90
|
+
const parsedLine = parseLineType(rawLine);
|
|
91
|
+
if (parsedLine == null) continue;
|
|
92
|
+
const { type, line } = parsedLine;
|
|
93
|
+
if (type === "addition") {
|
|
94
|
+
if (currentContent == null || currentContent.type !== "change") {
|
|
95
|
+
currentContent = createContentGroup("change");
|
|
96
|
+
hunkContent.push(currentContent);
|
|
97
|
+
}
|
|
98
|
+
currentContent.additions.push(line);
|
|
99
|
+
additionLines++;
|
|
100
|
+
lastLineType = "addition";
|
|
101
|
+
} else if (type === "deletion") {
|
|
102
|
+
if (currentContent == null || currentContent.type !== "change") {
|
|
103
|
+
currentContent = createContentGroup("change");
|
|
104
|
+
hunkContent.push(currentContent);
|
|
105
|
+
}
|
|
106
|
+
currentContent.deletions.push(line);
|
|
107
|
+
deletionLines++;
|
|
108
|
+
lastLineType = "deletion";
|
|
109
|
+
} else if (type === "context") {
|
|
110
|
+
if (currentContent == null || currentContent.type !== "context") {
|
|
111
|
+
currentContent = createContentGroup("context");
|
|
112
|
+
hunkContent.push(currentContent);
|
|
113
|
+
}
|
|
114
|
+
currentContent.lines.push(line);
|
|
115
|
+
lastLineType = "context";
|
|
116
|
+
} else if (type === "metadata" && currentContent != null) {
|
|
117
|
+
if (currentContent.type === "context") currentContent.noEOFCR = true;
|
|
118
|
+
else if (lastLineType === "deletion") {
|
|
119
|
+
currentContent.noEOFCRDeletions = true;
|
|
120
|
+
const lastIndex = currentContent.deletions.length - 1;
|
|
121
|
+
if (lastIndex >= 0) currentContent.deletions[lastIndex] = cleanLastNewline(currentContent.deletions[lastIndex]);
|
|
122
|
+
} else if (lastLineType === "addition") {
|
|
123
|
+
currentContent.noEOFCRAdditions = true;
|
|
124
|
+
const lastIndex = currentContent.additions.length - 1;
|
|
125
|
+
if (lastIndex >= 0) currentContent.additions[lastIndex] = cleanLastNewline(currentContent.additions[lastIndex]);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const hunkData = {
|
|
131
|
+
collapsedBefore: 0,
|
|
132
|
+
splitLineCount: 0,
|
|
133
|
+
splitLineStart: 0,
|
|
134
|
+
unifiedLineCount: 0,
|
|
135
|
+
unifiedLineStart: 0,
|
|
136
|
+
additionCount: parseInt(match[4] ?? "1"),
|
|
137
|
+
additionStart: parseInt(match[3]),
|
|
138
|
+
additionLines,
|
|
139
|
+
deletionCount: parseInt(match[2] ?? "1"),
|
|
140
|
+
deletionStart: parseInt(match[1]),
|
|
141
|
+
deletionLines,
|
|
142
|
+
hunkContent,
|
|
143
|
+
hunkContext: match[5],
|
|
144
|
+
hunkSpecs: firstLine
|
|
145
|
+
};
|
|
146
|
+
if (isNaN(hunkData.additionCount) || isNaN(hunkData.deletionCount) || isNaN(hunkData.additionStart) || isNaN(hunkData.deletionStart)) {
|
|
147
|
+
console.error("parsePatchContent: invalid hunk metadata", hunkData);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
hunkData.collapsedBefore = Math.max(hunkData.additionStart - 1 - lastHunkEnd, 0);
|
|
151
|
+
currentFile.hunks.push(hunkData);
|
|
152
|
+
lastHunkEnd = hunkData.additionStart + hunkData.additionCount - 1;
|
|
153
|
+
for (const content of hunkContent) if (content.type === "context") {
|
|
154
|
+
hunkData.splitLineCount += content.lines.length;
|
|
155
|
+
hunkData.unifiedLineCount += content.lines.length;
|
|
156
|
+
} else {
|
|
157
|
+
hunkData.splitLineCount += Math.max(content.additions.length, content.deletions.length);
|
|
158
|
+
hunkData.unifiedLineCount += content.deletions.length + content.additions.length;
|
|
159
|
+
}
|
|
160
|
+
hunkData.splitLineStart = currentFile.splitLineCount;
|
|
161
|
+
hunkData.unifiedLineStart = currentFile.unifiedLineCount;
|
|
162
|
+
currentFile.splitLineCount += hunkData.splitLineCount;
|
|
163
|
+
currentFile.unifiedLineCount += hunkData.unifiedLineCount;
|
|
164
|
+
}
|
|
165
|
+
if (currentFile != null) {
|
|
166
|
+
if (!isGitDiff && currentFile.prevName != null && currentFile.name !== currentFile.prevName) if (currentFile.hunks.length > 0) currentFile.type = "rename-changed";
|
|
167
|
+
else currentFile.type = "rename-pure";
|
|
168
|
+
if (currentFile.type !== "rename-pure" && currentFile.type !== "rename-changed") currentFile.prevName = void 0;
|
|
169
|
+
files.push(currentFile);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
patchMetadata,
|
|
174
|
+
files
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Parses a patch file string into an array of parsed patches.
|
|
179
|
+
*
|
|
180
|
+
* @param data - The raw patch file content (supports multi-commit patches)
|
|
181
|
+
* @param cacheKeyPrefix - Optional prefix for generating cache keys. When provided,
|
|
182
|
+
* each file in the patch will get a cache key in the format `prefix-patchIndex-fileIndex`.
|
|
183
|
+
* This enables caching of rendered diff results in the worker pool.
|
|
184
|
+
*/
|
|
185
|
+
function parsePatchFiles(data, cacheKeyPrefix) {
|
|
186
|
+
const patches = [];
|
|
187
|
+
for (const patch of data.split(COMMIT_METADATA_SPLIT)) try {
|
|
188
|
+
patches.push(processPatch(patch, cacheKeyPrefix != null ? `${cacheKeyPrefix}-${patches.length}` : void 0));
|
|
189
|
+
} catch (error) {
|
|
190
|
+
console.error(error);
|
|
191
|
+
}
|
|
192
|
+
return patches;
|
|
193
|
+
}
|
|
194
|
+
function createContentGroup(type) {
|
|
195
|
+
if (type === "change") return {
|
|
196
|
+
type: "change",
|
|
197
|
+
additions: [],
|
|
198
|
+
deletions: [],
|
|
199
|
+
noEOFCRAdditions: false,
|
|
200
|
+
noEOFCRDeletions: false
|
|
201
|
+
};
|
|
202
|
+
return {
|
|
203
|
+
type: "context",
|
|
204
|
+
lines: [],
|
|
205
|
+
noEOFCR: false
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
//#endregion
|
|
210
|
+
export { parsePatchFiles };
|
|
211
|
+
//# sourceMappingURL=parsePatchFiles.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/utils/prerenderHTMLIfNecessary.ts
|
|
2
|
+
function prerenderHTMLIfNecessary(element, html) {
|
|
3
|
+
if (html == null) return;
|
|
4
|
+
const shadowRoot = element.shadowRoot ?? element.attachShadow({ mode: "open" });
|
|
5
|
+
if (shadowRoot.innerHTML === "") shadowRoot.innerHTML = html;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { prerenderHTMLIfNecessary };
|
|
10
|
+
//# sourceMappingURL=prerenderHTMLIfNecessary.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createHastElement, createTextNodeElement } from "./hast_utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/processLine.ts
|
|
4
|
+
function processLine(node, line, state) {
|
|
5
|
+
const lineInfo = typeof state.lineInfo === "function" ? state.lineInfo(line) : state.lineInfo[line];
|
|
6
|
+
if (lineInfo == null) {
|
|
7
|
+
console.error({
|
|
8
|
+
node,
|
|
9
|
+
line,
|
|
10
|
+
state
|
|
11
|
+
});
|
|
12
|
+
throw new Error(`processLine: line ${line}, contains no state.lineInfo`);
|
|
13
|
+
}
|
|
14
|
+
node.tagName = "span";
|
|
15
|
+
node.properties["data-column-content"] = "";
|
|
16
|
+
if (node.children.length === 0) node.children.push(createTextNodeElement("\n"));
|
|
17
|
+
return createHastElement({
|
|
18
|
+
tagName: "div",
|
|
19
|
+
children: [createHastElement({
|
|
20
|
+
tagName: "span",
|
|
21
|
+
children: [createHastElement({
|
|
22
|
+
tagName: "span",
|
|
23
|
+
children: [{
|
|
24
|
+
type: "text",
|
|
25
|
+
value: `${lineInfo.lineNumber}`
|
|
26
|
+
}],
|
|
27
|
+
properties: { "data-line-number-content": "" }
|
|
28
|
+
})],
|
|
29
|
+
properties: { "data-column-number": "" }
|
|
30
|
+
}), node],
|
|
31
|
+
properties: {
|
|
32
|
+
"data-line": lineInfo.lineNumber,
|
|
33
|
+
"data-alt-line": lineInfo.altLineNumber,
|
|
34
|
+
"data-line-type": lineInfo.type,
|
|
35
|
+
"data-line-index": lineInfo.lineIndex
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { processLine };
|
|
42
|
+
//# sourceMappingURL=processLine.js.map
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { DEFAULT_THEMES } from "../constants.js";
|
|
2
|
+
import { getFiletypeFromFileName } from "./getFiletypeFromFileName.js";
|
|
3
|
+
import { cleanLastNewline } from "./cleanLastNewline.js";
|
|
4
|
+
import { createTransformerWithState } from "./createTransformerWithState.js";
|
|
5
|
+
import { formatCSSVariablePrefix } from "./formatCSSVariablePrefix.js";
|
|
6
|
+
import { getHighlighterThemeStyles } from "./getHighlighterThemeStyles.js";
|
|
7
|
+
import { getLineNodes } from "./getLineNodes.js";
|
|
8
|
+
import { createDiffSpanDecoration, pushOrJoinSpan } from "./parseDiffDecorations.js";
|
|
9
|
+
import { diffChars, diffWordsWithSpace } from "diff";
|
|
10
|
+
|
|
11
|
+
//#region src/utils/renderDiffWithHighlighter.ts
|
|
12
|
+
function renderDiffWithHighlighter(diff, highlighter, options, forcePlainText = false) {
|
|
13
|
+
const baseThemeType = (() => {
|
|
14
|
+
const theme = options.theme ?? DEFAULT_THEMES;
|
|
15
|
+
if (typeof theme === "string") return highlighter.getTheme(theme).type;
|
|
16
|
+
})();
|
|
17
|
+
const themeStyles = getHighlighterThemeStyles({
|
|
18
|
+
theme: options.theme,
|
|
19
|
+
highlighter
|
|
20
|
+
});
|
|
21
|
+
if (diff.newLines != null && diff.oldLines != null) {
|
|
22
|
+
const { oldContent, newContent, oldInfo, newInfo, oldDecorations, newDecorations } = processLines({
|
|
23
|
+
hunks: diff.hunks,
|
|
24
|
+
oldLines: diff.oldLines,
|
|
25
|
+
newLines: diff.newLines,
|
|
26
|
+
lineDiffType: options.lineDiffType
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
code: renderTwoFiles({
|
|
30
|
+
oldFile: {
|
|
31
|
+
name: diff.prevName ?? diff.name,
|
|
32
|
+
contents: oldContent
|
|
33
|
+
},
|
|
34
|
+
oldInfo,
|
|
35
|
+
oldDecorations,
|
|
36
|
+
newFile: {
|
|
37
|
+
name: diff.name,
|
|
38
|
+
contents: newContent
|
|
39
|
+
},
|
|
40
|
+
newInfo,
|
|
41
|
+
newDecorations,
|
|
42
|
+
highlighter,
|
|
43
|
+
options,
|
|
44
|
+
languageOverride: forcePlainText ? "text" : diff.lang
|
|
45
|
+
}),
|
|
46
|
+
themeStyles,
|
|
47
|
+
baseThemeType
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const hunks = [];
|
|
51
|
+
let splitLineIndex = 0;
|
|
52
|
+
let unifiedLineIndex = 0;
|
|
53
|
+
for (const hunk of diff.hunks) {
|
|
54
|
+
const { oldContent, newContent, oldInfo, newInfo, oldDecorations, newDecorations, splitLineIndex: newSplitLineIndex, unifiedLineIndex: newUnifiedLineIndex } = processLines({
|
|
55
|
+
hunks: [hunk],
|
|
56
|
+
splitLineIndex,
|
|
57
|
+
unifiedLineIndex,
|
|
58
|
+
lineDiffType: options.lineDiffType
|
|
59
|
+
});
|
|
60
|
+
const oldFile = {
|
|
61
|
+
name: diff.prevName ?? diff.name,
|
|
62
|
+
contents: oldContent
|
|
63
|
+
};
|
|
64
|
+
const newFile = {
|
|
65
|
+
name: diff.name,
|
|
66
|
+
contents: newContent
|
|
67
|
+
};
|
|
68
|
+
hunks.push(renderTwoFiles({
|
|
69
|
+
oldFile,
|
|
70
|
+
oldInfo,
|
|
71
|
+
oldDecorations,
|
|
72
|
+
newFile,
|
|
73
|
+
newInfo,
|
|
74
|
+
newDecorations,
|
|
75
|
+
highlighter,
|
|
76
|
+
options,
|
|
77
|
+
languageOverride: forcePlainText ? "text" : diff.lang
|
|
78
|
+
}));
|
|
79
|
+
splitLineIndex = newSplitLineIndex;
|
|
80
|
+
unifiedLineIndex = newUnifiedLineIndex;
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
code: (() => {
|
|
84
|
+
if (hunks.length <= 1) {
|
|
85
|
+
const hunk = hunks[0] ?? {
|
|
86
|
+
oldLines: [],
|
|
87
|
+
newLines: []
|
|
88
|
+
};
|
|
89
|
+
if (hunk.newLines.length === 0 || hunk.oldLines.length === 0) return hunk;
|
|
90
|
+
}
|
|
91
|
+
return { hunks };
|
|
92
|
+
})(),
|
|
93
|
+
themeStyles,
|
|
94
|
+
baseThemeType
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function computeLineDiffDecorations({ oldLine, newLine, oldLineIndex, newLineIndex, oldDecorations, newDecorations, lineDiffType }) {
|
|
98
|
+
if (oldLine == null || newLine == null || lineDiffType === "none") return;
|
|
99
|
+
oldLine = cleanLastNewline(oldLine);
|
|
100
|
+
newLine = cleanLastNewline(newLine);
|
|
101
|
+
const lineDiff = lineDiffType === "char" ? diffChars(oldLine, newLine) : diffWordsWithSpace(oldLine, newLine);
|
|
102
|
+
const deletionSpans = [];
|
|
103
|
+
const additionSpans = [];
|
|
104
|
+
const enableJoin = lineDiffType === "word-alt";
|
|
105
|
+
for (const item of lineDiff) {
|
|
106
|
+
const isLastItem = item === lineDiff[lineDiff.length - 1];
|
|
107
|
+
if (!item.added && !item.removed) {
|
|
108
|
+
pushOrJoinSpan({
|
|
109
|
+
item,
|
|
110
|
+
arr: deletionSpans,
|
|
111
|
+
enableJoin,
|
|
112
|
+
isNeutral: true,
|
|
113
|
+
isLastItem
|
|
114
|
+
});
|
|
115
|
+
pushOrJoinSpan({
|
|
116
|
+
item,
|
|
117
|
+
arr: additionSpans,
|
|
118
|
+
enableJoin,
|
|
119
|
+
isNeutral: true,
|
|
120
|
+
isLastItem
|
|
121
|
+
});
|
|
122
|
+
} else if (item.removed) pushOrJoinSpan({
|
|
123
|
+
item,
|
|
124
|
+
arr: deletionSpans,
|
|
125
|
+
enableJoin,
|
|
126
|
+
isLastItem
|
|
127
|
+
});
|
|
128
|
+
else pushOrJoinSpan({
|
|
129
|
+
item,
|
|
130
|
+
arr: additionSpans,
|
|
131
|
+
enableJoin,
|
|
132
|
+
isLastItem
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
let spanIndex = 0;
|
|
136
|
+
for (const span of deletionSpans) {
|
|
137
|
+
if (span[0] === 1) oldDecorations.push(createDiffSpanDecoration({
|
|
138
|
+
line: oldLineIndex - 1,
|
|
139
|
+
spanStart: spanIndex,
|
|
140
|
+
spanLength: span[1].length
|
|
141
|
+
}));
|
|
142
|
+
spanIndex += span[1].length;
|
|
143
|
+
}
|
|
144
|
+
spanIndex = 0;
|
|
145
|
+
for (const span of additionSpans) {
|
|
146
|
+
if (span[0] === 1) newDecorations.push(createDiffSpanDecoration({
|
|
147
|
+
line: newLineIndex - 1,
|
|
148
|
+
spanStart: spanIndex,
|
|
149
|
+
spanLength: span[1].length
|
|
150
|
+
}));
|
|
151
|
+
spanIndex += span[1].length;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function processLines({ hunks, oldLines, newLines, splitLineIndex = 0, unifiedLineIndex = 0, lineDiffType }) {
|
|
155
|
+
const oldInfo = {};
|
|
156
|
+
const newInfo = {};
|
|
157
|
+
const oldDecorations = [];
|
|
158
|
+
const newDecorations = [];
|
|
159
|
+
let newLineIndex = 1;
|
|
160
|
+
let oldLineIndex = 1;
|
|
161
|
+
let newLineNumber = 1;
|
|
162
|
+
let oldLineNumber = 1;
|
|
163
|
+
let oldContent = "";
|
|
164
|
+
let newContent = "";
|
|
165
|
+
for (const hunk of hunks) {
|
|
166
|
+
while (oldLines != null && newLines != null && newLineIndex < hunk.additionStart && oldLineIndex < hunk.deletionStart) {
|
|
167
|
+
oldInfo[oldLineIndex] = {
|
|
168
|
+
type: "context-expanded",
|
|
169
|
+
lineNumber: oldLineNumber,
|
|
170
|
+
altLineNumber: newLineNumber,
|
|
171
|
+
lineIndex: `${unifiedLineIndex},${splitLineIndex}`
|
|
172
|
+
};
|
|
173
|
+
newInfo[newLineIndex] = {
|
|
174
|
+
type: "context-expanded",
|
|
175
|
+
lineNumber: newLineNumber,
|
|
176
|
+
altLineNumber: oldLineNumber,
|
|
177
|
+
lineIndex: `${unifiedLineIndex},${splitLineIndex}`
|
|
178
|
+
};
|
|
179
|
+
oldContent += oldLines[oldLineIndex - 1];
|
|
180
|
+
newContent += newLines[newLineIndex - 1];
|
|
181
|
+
oldLineIndex++;
|
|
182
|
+
newLineIndex++;
|
|
183
|
+
oldLineNumber++;
|
|
184
|
+
newLineNumber++;
|
|
185
|
+
splitLineIndex++;
|
|
186
|
+
unifiedLineIndex++;
|
|
187
|
+
}
|
|
188
|
+
oldLineNumber = hunk.deletionStart;
|
|
189
|
+
newLineNumber = hunk.additionStart;
|
|
190
|
+
for (const hunkContent of hunk.hunkContent) if (hunkContent.type === "context") for (const line of hunkContent.lines) {
|
|
191
|
+
oldInfo[oldLineIndex] = {
|
|
192
|
+
type: "context",
|
|
193
|
+
lineNumber: oldLineNumber,
|
|
194
|
+
altLineNumber: newLineNumber,
|
|
195
|
+
lineIndex: `${unifiedLineIndex},${splitLineIndex}`
|
|
196
|
+
};
|
|
197
|
+
newInfo[newLineIndex] = {
|
|
198
|
+
type: "context",
|
|
199
|
+
lineNumber: newLineNumber,
|
|
200
|
+
altLineNumber: oldLineNumber,
|
|
201
|
+
lineIndex: `${unifiedLineIndex},${splitLineIndex}`
|
|
202
|
+
};
|
|
203
|
+
oldContent += line;
|
|
204
|
+
newContent += line;
|
|
205
|
+
oldLineIndex++;
|
|
206
|
+
newLineIndex++;
|
|
207
|
+
newLineNumber++;
|
|
208
|
+
oldLineNumber++;
|
|
209
|
+
splitLineIndex++;
|
|
210
|
+
unifiedLineIndex++;
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
const len = Math.max(hunkContent.additions.length, hunkContent.deletions.length);
|
|
214
|
+
let i = 0;
|
|
215
|
+
let _unifiedLineIndex = unifiedLineIndex;
|
|
216
|
+
while (i < len) {
|
|
217
|
+
const oldLine = hunkContent.deletions[i];
|
|
218
|
+
const newLine = hunkContent.additions[i];
|
|
219
|
+
computeLineDiffDecorations({
|
|
220
|
+
newLine,
|
|
221
|
+
oldLine,
|
|
222
|
+
oldLineIndex,
|
|
223
|
+
newLineIndex,
|
|
224
|
+
oldDecorations,
|
|
225
|
+
newDecorations,
|
|
226
|
+
lineDiffType
|
|
227
|
+
});
|
|
228
|
+
if (oldLine != null) {
|
|
229
|
+
oldInfo[oldLineIndex] = {
|
|
230
|
+
type: "change-deletion",
|
|
231
|
+
lineNumber: oldLineNumber,
|
|
232
|
+
lineIndex: `${_unifiedLineIndex},${splitLineIndex}`
|
|
233
|
+
};
|
|
234
|
+
oldContent += oldLine;
|
|
235
|
+
oldLineIndex++;
|
|
236
|
+
oldLineNumber++;
|
|
237
|
+
}
|
|
238
|
+
if (newLine != null) {
|
|
239
|
+
newInfo[newLineIndex] = {
|
|
240
|
+
type: "change-addition",
|
|
241
|
+
lineNumber: newLineNumber,
|
|
242
|
+
lineIndex: `${_unifiedLineIndex + hunkContent.deletions.length},${splitLineIndex}`
|
|
243
|
+
};
|
|
244
|
+
newContent += newLine;
|
|
245
|
+
newLineIndex++;
|
|
246
|
+
newLineNumber++;
|
|
247
|
+
}
|
|
248
|
+
splitLineIndex++;
|
|
249
|
+
_unifiedLineIndex++;
|
|
250
|
+
i++;
|
|
251
|
+
}
|
|
252
|
+
unifiedLineIndex += hunkContent.additions.length + hunkContent.deletions.length;
|
|
253
|
+
}
|
|
254
|
+
if (oldLines == null || newLines == null || hunk !== hunks[hunks.length - 1]) continue;
|
|
255
|
+
while (oldLineIndex <= oldLines.length || newLineIndex <= oldLines.length) {
|
|
256
|
+
const oldLine = oldLines[oldLineIndex - 1];
|
|
257
|
+
const newLine = newLines[newLineIndex - 1];
|
|
258
|
+
if (oldLine == null && newLine == null) break;
|
|
259
|
+
if (oldLine != null) {
|
|
260
|
+
oldInfo[oldLineIndex] = {
|
|
261
|
+
type: "context-expanded",
|
|
262
|
+
lineNumber: oldLineNumber,
|
|
263
|
+
altLineNumber: newLineNumber,
|
|
264
|
+
lineIndex: `${unifiedLineIndex},${splitLineIndex}`
|
|
265
|
+
};
|
|
266
|
+
oldContent += oldLine;
|
|
267
|
+
oldLineIndex++;
|
|
268
|
+
oldLineNumber++;
|
|
269
|
+
}
|
|
270
|
+
if (newLine != null) {
|
|
271
|
+
newInfo[newLineIndex] = {
|
|
272
|
+
type: "context-expanded",
|
|
273
|
+
lineNumber: newLineNumber,
|
|
274
|
+
altLineNumber: oldLineNumber,
|
|
275
|
+
lineIndex: `${unifiedLineIndex},${splitLineIndex}`
|
|
276
|
+
};
|
|
277
|
+
newContent += newLine;
|
|
278
|
+
newLineIndex++;
|
|
279
|
+
newLineNumber++;
|
|
280
|
+
}
|
|
281
|
+
splitLineIndex++;
|
|
282
|
+
unifiedLineIndex++;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
oldContent,
|
|
287
|
+
newContent,
|
|
288
|
+
oldInfo,
|
|
289
|
+
newInfo,
|
|
290
|
+
oldDecorations,
|
|
291
|
+
newDecorations,
|
|
292
|
+
splitLineIndex,
|
|
293
|
+
unifiedLineIndex
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
function renderTwoFiles({ oldFile, newFile, oldInfo, newInfo, highlighter, oldDecorations, newDecorations, languageOverride, options: { theme: themeOrThemes = DEFAULT_THEMES,...options } }) {
|
|
297
|
+
const oldLang = languageOverride ?? getFiletypeFromFileName(oldFile.name);
|
|
298
|
+
const newLang = languageOverride ?? getFiletypeFromFileName(newFile.name);
|
|
299
|
+
const { state, transformers } = createTransformerWithState();
|
|
300
|
+
const hastConfig = (() => {
|
|
301
|
+
return typeof themeOrThemes === "string" ? {
|
|
302
|
+
...options,
|
|
303
|
+
lang: "text",
|
|
304
|
+
theme: themeOrThemes,
|
|
305
|
+
transformers,
|
|
306
|
+
decorations: void 0,
|
|
307
|
+
defaultColor: false,
|
|
308
|
+
cssVariablePrefix: formatCSSVariablePrefix("token")
|
|
309
|
+
} : {
|
|
310
|
+
...options,
|
|
311
|
+
lang: "text",
|
|
312
|
+
themes: themeOrThemes,
|
|
313
|
+
transformers,
|
|
314
|
+
decorations: void 0,
|
|
315
|
+
defaultColor: false,
|
|
316
|
+
cssVariablePrefix: formatCSSVariablePrefix("token")
|
|
317
|
+
};
|
|
318
|
+
})();
|
|
319
|
+
return {
|
|
320
|
+
oldLines: (() => {
|
|
321
|
+
if (oldFile.contents === "") return [];
|
|
322
|
+
hastConfig.lang = oldLang;
|
|
323
|
+
state.lineInfo = oldInfo;
|
|
324
|
+
hastConfig.decorations = oldDecorations;
|
|
325
|
+
return getLineNodes(highlighter.codeToHast(cleanLastNewline(oldFile.contents), hastConfig));
|
|
326
|
+
})(),
|
|
327
|
+
newLines: (() => {
|
|
328
|
+
if (newFile.contents === "") return [];
|
|
329
|
+
hastConfig.lang = newLang;
|
|
330
|
+
hastConfig.decorations = newDecorations;
|
|
331
|
+
state.lineInfo = newInfo;
|
|
332
|
+
return getLineNodes(highlighter.codeToHast(cleanLastNewline(newFile.contents), hastConfig));
|
|
333
|
+
})()
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
//#endregion
|
|
338
|
+
export { renderDiffWithHighlighter };
|
|
339
|
+
//# sourceMappingURL=renderDiffWithHighlighter.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { DEFAULT_THEMES } from "../constants.js";
|
|
2
|
+
import { getFiletypeFromFileName } from "./getFiletypeFromFileName.js";
|
|
3
|
+
import { cleanLastNewline } from "./cleanLastNewline.js";
|
|
4
|
+
import { createTransformerWithState } from "./createTransformerWithState.js";
|
|
5
|
+
import { formatCSSVariablePrefix } from "./formatCSSVariablePrefix.js";
|
|
6
|
+
import { getHighlighterThemeStyles } from "./getHighlighterThemeStyles.js";
|
|
7
|
+
import { getLineNodes } from "./getLineNodes.js";
|
|
8
|
+
|
|
9
|
+
//#region src/utils/renderFileWithHighlighter.ts
|
|
10
|
+
function renderFileWithHighlighter(file, highlighter, { theme = DEFAULT_THEMES, tokenizeMaxLineLength }, forcePlainText = false) {
|
|
11
|
+
const { state, transformers } = createTransformerWithState();
|
|
12
|
+
const lang = forcePlainText ? "text" : file.lang ?? getFiletypeFromFileName(file.name);
|
|
13
|
+
const baseThemeType = (() => {
|
|
14
|
+
if (typeof theme === "string") return highlighter.getTheme(theme).type;
|
|
15
|
+
})();
|
|
16
|
+
const themeStyles = getHighlighterThemeStyles({
|
|
17
|
+
theme,
|
|
18
|
+
highlighter
|
|
19
|
+
});
|
|
20
|
+
state.lineInfo = (shikiLineNumber) => ({
|
|
21
|
+
type: "context",
|
|
22
|
+
lineIndex: shikiLineNumber - 1,
|
|
23
|
+
lineNumber: shikiLineNumber
|
|
24
|
+
});
|
|
25
|
+
const hastConfig = (() => {
|
|
26
|
+
if (typeof theme === "string") return {
|
|
27
|
+
lang,
|
|
28
|
+
theme,
|
|
29
|
+
transformers,
|
|
30
|
+
defaultColor: false,
|
|
31
|
+
cssVariablePrefix: formatCSSVariablePrefix("token"),
|
|
32
|
+
tokenizeMaxLineLength
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
lang,
|
|
36
|
+
themes: theme,
|
|
37
|
+
transformers,
|
|
38
|
+
defaultColor: false,
|
|
39
|
+
cssVariablePrefix: formatCSSVariablePrefix("token"),
|
|
40
|
+
tokenizeMaxLineLength
|
|
41
|
+
};
|
|
42
|
+
})();
|
|
43
|
+
return {
|
|
44
|
+
code: getLineNodes(highlighter.codeToHast(cleanLastNewline(file.contents), hastConfig)),
|
|
45
|
+
themeStyles,
|
|
46
|
+
baseThemeType
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { renderFileWithHighlighter };
|
|
52
|
+
//# sourceMappingURL=renderFileWithHighlighter.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/utils/setWrapperNodeProps.ts
|
|
2
|
+
function setPreNodeProperties({ diffIndicators, disableBackground, disableLineNumbers, overflow, pre, split, themeStyles, themeType, totalLines }) {
|
|
3
|
+
if (themeType === "system") delete pre.dataset.themeType;
|
|
4
|
+
else pre.dataset.themeType = themeType;
|
|
5
|
+
switch (diffIndicators) {
|
|
6
|
+
case "bars":
|
|
7
|
+
case "classic":
|
|
8
|
+
pre.dataset.indicators = diffIndicators;
|
|
9
|
+
break;
|
|
10
|
+
case "none":
|
|
11
|
+
delete pre.dataset.indicators;
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
if (disableLineNumbers) pre.dataset.disableLineNumbers = "";
|
|
15
|
+
else delete pre.dataset.disableLineNumbers;
|
|
16
|
+
if (disableBackground) delete pre.dataset.background;
|
|
17
|
+
else pre.dataset.background = "";
|
|
18
|
+
pre.dataset.type = split ? "split" : "file";
|
|
19
|
+
pre.dataset.overflow = overflow;
|
|
20
|
+
pre.dataset.diffs = "";
|
|
21
|
+
pre.tabIndex = 0;
|
|
22
|
+
pre.style = themeStyles;
|
|
23
|
+
pre.style.setProperty("--diffs-min-number-column-width-default", `${`${totalLines}`.length}ch`);
|
|
24
|
+
return pre;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { setPreNodeProperties };
|
|
29
|
+
//# sourceMappingURL=setWrapperNodeProps.js.map
|