@pierre/diffs 1.1.4 → 1.1.6
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/dist/components/File.d.ts +21 -1
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +142 -70
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +26 -5
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +143 -89
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/FileStream.d.ts +4 -1
- package/dist/components/FileStream.d.ts.map +1 -1
- package/dist/components/FileStream.js +27 -12
- package/dist/components/FileStream.js.map +1 -1
- package/dist/components/UnresolvedFile.js +6 -42
- package/dist/components/UnresolvedFile.js.map +1 -1
- package/dist/components/VirtulizerDevelopment.d.ts.map +1 -1
- package/dist/constants.d.ts +3 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +3 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +4 -4
- package/dist/managers/InteractionManager.d.ts.map +1 -1
- package/dist/react/File.d.ts +3 -1
- package/dist/react/File.d.ts.map +1 -1
- package/dist/react/File.js +5 -2
- package/dist/react/File.js.map +1 -1
- package/dist/react/FileDiff.d.ts +4 -1
- package/dist/react/FileDiff.d.ts.map +1 -1
- package/dist/react/FileDiff.js +5 -2
- package/dist/react/FileDiff.js.map +1 -1
- package/dist/react/MultiFileDiff.d.ts +4 -1
- package/dist/react/MultiFileDiff.d.ts.map +1 -1
- package/dist/react/MultiFileDiff.js +12 -6
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/PatchDiff.d.ts +4 -1
- package/dist/react/PatchDiff.d.ts.map +1 -1
- package/dist/react/PatchDiff.js +5 -2
- package/dist/react/PatchDiff.js.map +1 -1
- package/dist/react/UnresolvedFile.d.ts +4 -1
- package/dist/react/UnresolvedFile.d.ts.map +1 -1
- package/dist/react/UnresolvedFile.js +5 -2
- package/dist/react/UnresolvedFile.js.map +1 -1
- package/dist/react/WorkerPoolContext.js +7 -5
- package/dist/react/WorkerPoolContext.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/jsx.d.ts.map +1 -1
- package/dist/react/types.d.ts +6 -3
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.d.ts +4 -6
- package/dist/react/utils/renderDiffChildren.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.js +12 -17
- package/dist/react/utils/renderDiffChildren.js.map +1 -1
- package/dist/react/utils/renderFileChildren.d.ts +2 -0
- package/dist/react/utils/renderFileChildren.d.ts.map +1 -1
- package/dist/react/utils/renderFileChildren.js +9 -6
- package/dist/react/utils/renderFileChildren.js.map +1 -1
- package/dist/react/utils/useFileDiffInstance.d.ts +7 -7
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +20 -11
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.d.ts +5 -1
- package/dist/react/utils/useFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileInstance.js +20 -7
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/react/utils/useUnresolvedFileInstance.d.ts +5 -1
- package/dist/react/utils/useUnresolvedFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useUnresolvedFileInstance.js +17 -4
- package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +14 -9
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +9 -19
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +5 -4
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +7 -17
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts +5 -5
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.js +2 -2
- package/dist/renderers/UnresolvedFileHunksRenderer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/ssr/preloadDiffs.js +7 -4
- package/dist/ssr/preloadDiffs.js.map +1 -1
- package/dist/ssr/preloadFile.js +7 -2
- package/dist/ssr/preloadFile.js.map +1 -1
- package/dist/style.js +1 -1
- package/dist/style.js.map +1 -1
- package/dist/types.d.ts +11 -11
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/arePrePropertiesEqual.js +1 -1
- package/dist/utils/arePrePropertiesEqual.js.map +1 -1
- package/dist/utils/createFileHeaderElement.d.ts +3 -5
- package/dist/utils/createFileHeaderElement.d.ts.map +1 -1
- package/dist/utils/createFileHeaderElement.js +13 -9
- package/dist/utils/createFileHeaderElement.js.map +1 -1
- package/dist/utils/createPreElement.d.ts +0 -2
- package/dist/utils/createPreElement.d.ts.map +1 -1
- package/dist/utils/createPreElement.js +4 -7
- package/dist/utils/createPreElement.js.map +1 -1
- package/dist/utils/createStyleElement.d.ts +2 -1
- package/dist/utils/createStyleElement.d.ts.map +1 -1
- package/dist/utils/createStyleElement.js +9 -2
- package/dist/utils/createStyleElement.js.map +1 -1
- package/dist/utils/cssWrappers.d.ts +4 -1
- package/dist/utils/cssWrappers.d.ts.map +1 -1
- package/dist/utils/cssWrappers.js +11 -2
- package/dist/utils/cssWrappers.js.map +1 -1
- package/dist/utils/hast_utils.d.ts +1 -1
- package/dist/utils/hast_utils.d.ts.map +1 -1
- package/dist/utils/hast_utils.js.map +1 -1
- package/dist/utils/hostTheme.d.ts +15 -0
- package/dist/utils/hostTheme.d.ts.map +1 -0
- package/dist/utils/hostTheme.js +22 -0
- package/dist/utils/hostTheme.js.map +1 -0
- package/dist/utils/parsePatchFiles.js +1 -1
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.js +1 -4
- package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
- package/dist/utils/renderFileWithHighlighter.js +1 -3
- package/dist/utils/renderFileWithHighlighter.js.map +1 -1
- package/dist/utils/resolveRegion.js +14 -7
- package/dist/utils/resolveRegion.js.map +1 -1
- package/dist/utils/setWrapperNodeProps.d.ts +0 -2
- package/dist/utils/setWrapperNodeProps.d.ts.map +1 -1
- package/dist/utils/setWrapperNodeProps.js +1 -4
- package/dist/utils/setWrapperNodeProps.js.map +1 -1
- package/dist/worker/worker-portable.js +4 -13
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +2 -7
- package/dist/worker/worker.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createStyleElement.d.ts","names":["Element","HASTElement","createStyleElement"],"sources":["../../src/utils/createStyleElement.d.ts"],"sourcesContent":["import type { Element as HASTElement } from 'hast';\nexport declare function createStyleElement(content: string, isCoreCSS?: boolean): HASTElement;\n//# sourceMappingURL=createStyleElement.d.ts.map"],"mappings":";;;iBACwBE,kBAAAA,wCAA0DD"}
|
|
1
|
+
{"version":3,"file":"createStyleElement.d.ts","names":["Element","HASTElement","createStyleElement","createThemeStyleElement"],"sources":["../../src/utils/createStyleElement.d.ts"],"sourcesContent":["import type { Element as HASTElement } from 'hast';\nexport declare function createStyleElement(content: string, isCoreCSS?: boolean): HASTElement;\nexport declare function createThemeStyleElement(content: string): HASTElement;\n//# sourceMappingURL=createStyleElement.d.ts.map"],"mappings":";;;iBACwBE,kBAAAA,wCAA0DD;iBAC1DE,uBAAAA,mBAA0CF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CORE_CSS_ATTRIBUTE, UNSAFE_CSS_ATTRIBUTE } from "../constants.js";
|
|
1
|
+
import { CORE_CSS_ATTRIBUTE, THEME_CSS_ATTRIBUTE, UNSAFE_CSS_ATTRIBUTE } from "../constants.js";
|
|
2
2
|
import { createHastElement, createTextNodeElement } from "./hast_utils.js";
|
|
3
3
|
import { wrapCoreCSS, wrapUnsafeCSS } from "./cssWrappers.js";
|
|
4
4
|
|
|
@@ -13,7 +13,14 @@ function createStyleElement(content, isCoreCSS = false) {
|
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
+
function createThemeStyleElement(content) {
|
|
17
|
+
return createHastElement({
|
|
18
|
+
tagName: "style",
|
|
19
|
+
children: [createTextNodeElement(content)],
|
|
20
|
+
properties: { [THEME_CSS_ATTRIBUTE]: "" }
|
|
21
|
+
});
|
|
22
|
+
}
|
|
16
23
|
|
|
17
24
|
//#endregion
|
|
18
|
-
export { createStyleElement };
|
|
25
|
+
export { createStyleElement, createThemeStyleElement };
|
|
19
26
|
//# sourceMappingURL=createStyleElement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createStyleElement.js","names":[],"sources":["../../src/utils/createStyleElement.ts"],"sourcesContent":["import type { Element as HASTElement } from 'hast';\n\nimport {
|
|
1
|
+
{"version":3,"file":"createStyleElement.js","names":[],"sources":["../../src/utils/createStyleElement.ts"],"sourcesContent":["import type { Element as HASTElement } from 'hast';\n\nimport {\n CORE_CSS_ATTRIBUTE,\n THEME_CSS_ATTRIBUTE,\n UNSAFE_CSS_ATTRIBUTE,\n} from '../constants';\nimport { wrapCoreCSS, wrapUnsafeCSS } from './cssWrappers';\nimport { createHastElement, createTextNodeElement } from './hast_utils';\n\nexport function createStyleElement(\n content: string,\n isCoreCSS: boolean = false\n): HASTElement {\n return createHastElement({\n tagName: 'style',\n children: [\n createTextNodeElement(\n isCoreCSS ? wrapCoreCSS(content) : wrapUnsafeCSS(content)\n ),\n ],\n properties: {\n [CORE_CSS_ATTRIBUTE]: isCoreCSS ? '' : undefined,\n [UNSAFE_CSS_ATTRIBUTE]: !isCoreCSS ? '' : undefined,\n },\n });\n}\n\nexport function createThemeStyleElement(content: string): HASTElement {\n return createHastElement({\n tagName: 'style',\n children: [createTextNodeElement(content)],\n properties: {\n [THEME_CSS_ATTRIBUTE]: '',\n },\n });\n}\n"],"mappings":";;;;;AAUA,SAAgB,mBACd,SACA,YAAqB,OACR;AACb,QAAO,kBAAkB;EACvB,SAAS;EACT,UAAU,CACR,sBACE,YAAY,YAAY,QAAQ,GAAG,cAAc,QAAQ,CAC1D,CACF;EACD,YAAY;IACT,qBAAqB,YAAY,KAAK;IACtC,uBAAuB,CAAC,YAAY,KAAK;GAC3C;EACF,CAAC;;AAGJ,SAAgB,wBAAwB,SAA8B;AACpE,QAAO,kBAAkB;EACvB,SAAS;EACT,UAAU,CAAC,sBAAsB,QAAQ,CAAC;EAC1C,YAAY,GACT,sBAAsB,IACxB;EACF,CAAC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { ThemeTypes } from "../types.js";
|
|
2
|
+
|
|
1
3
|
//#region src/utils/cssWrappers.d.ts
|
|
2
4
|
declare function wrapCoreCSS(mainCSS: string): string;
|
|
3
5
|
declare function wrapUnsafeCSS(unsafeCSS: string): string;
|
|
6
|
+
declare function wrapThemeCSS(themeCSS: string, themeType?: ThemeTypes): string;
|
|
4
7
|
//#endregion
|
|
5
|
-
export { wrapCoreCSS, wrapUnsafeCSS };
|
|
8
|
+
export { wrapCoreCSS, wrapThemeCSS, wrapUnsafeCSS };
|
|
6
9
|
//# sourceMappingURL=cssWrappers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cssWrappers.d.ts","names":["wrapCoreCSS","wrapUnsafeCSS"],"sources":["../../src/utils/cssWrappers.d.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"cssWrappers.d.ts","names":["ThemeTypes","wrapCoreCSS","wrapUnsafeCSS","wrapThemeCSS"],"sources":["../../src/utils/cssWrappers.d.ts"],"sourcesContent":["import type { ThemeTypes } from '../types';\nexport declare function wrapCoreCSS(mainCSS: string): string;\nexport declare function wrapUnsafeCSS(unsafeCSS: string): string;\nexport declare function wrapThemeCSS(themeCSS: string, themeType?: ThemeTypes): string;\n//# sourceMappingURL=cssWrappers.d.ts.map"],"mappings":";;;iBACwBC,WAAAA;iBACAC,aAAAA;AADAD,iBAEAE,YAAAA,CAFW,QAAA,EAAA,MAAA,EAAA,SAAA,CAAA,EAEgCH,UAFhC,CAAA,EAAA,MAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import style_default from "../style.js";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/cssWrappers.ts
|
|
4
|
-
const LAYER_ORDER = `@layer base, theme, unsafe;`;
|
|
4
|
+
const LAYER_ORDER = `@layer base, theme, rendered, unsafe;`;
|
|
5
5
|
function wrapCoreCSS(mainCSS) {
|
|
6
6
|
return `${LAYER_ORDER}
|
|
7
7
|
${style_default}
|
|
@@ -15,7 +15,16 @@ function wrapUnsafeCSS(unsafeCSS) {
|
|
|
15
15
|
${unsafeCSS}
|
|
16
16
|
}`;
|
|
17
17
|
}
|
|
18
|
+
function wrapThemeCSS(themeCSS, themeType = "system") {
|
|
19
|
+
return `${LAYER_ORDER}
|
|
20
|
+
@layer rendered {
|
|
21
|
+
:host {${themeType === "system" ? "" : `
|
|
22
|
+
color-scheme: ${themeType};`}
|
|
23
|
+
${themeCSS}
|
|
24
|
+
}
|
|
25
|
+
}`;
|
|
26
|
+
}
|
|
18
27
|
|
|
19
28
|
//#endregion
|
|
20
|
-
export { wrapCoreCSS, wrapUnsafeCSS };
|
|
29
|
+
export { wrapCoreCSS, wrapThemeCSS, wrapUnsafeCSS };
|
|
21
30
|
//# sourceMappingURL=cssWrappers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cssWrappers.js","names":["rawStyles"],"sources":["../../src/utils/cssWrappers.ts"],"sourcesContent":["import rawStyles from '../style.css';\n\nconst LAYER_ORDER = `@layer base, theme, unsafe;`;\n\nexport function wrapCoreCSS(mainCSS: string) {\n return `${LAYER_ORDER}\n${rawStyles}\n@layer theme {\n ${mainCSS}\n}`;\n}\n\nexport function wrapUnsafeCSS(unsafeCSS: string) {\n return `${LAYER_ORDER}\n@layer unsafe {\n ${unsafeCSS}\n}`;\n}\n"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"cssWrappers.js","names":["rawStyles"],"sources":["../../src/utils/cssWrappers.ts"],"sourcesContent":["import rawStyles from '../style.css';\nimport type { ThemeTypes } from '../types';\n\nconst LAYER_ORDER = `@layer base, theme, rendered, unsafe;`;\n\nexport function wrapCoreCSS(mainCSS: string) {\n return `${LAYER_ORDER}\n${rawStyles}\n@layer theme {\n ${mainCSS}\n}`;\n}\n\nexport function wrapUnsafeCSS(unsafeCSS: string) {\n return `${LAYER_ORDER}\n@layer unsafe {\n ${unsafeCSS}\n}`;\n}\n\nexport function wrapThemeCSS(\n themeCSS: string,\n themeType: ThemeTypes = 'system'\n) {\n const colorSchemeRule =\n themeType === 'system'\n ? ''\n : `\n color-scheme: ${themeType};`;\n\n return `${LAYER_ORDER}\n@layer rendered {\n :host {${colorSchemeRule}\n ${themeCSS}\n }\n}`;\n}\n"],"mappings":";;;AAGA,MAAM,cAAc;AAEpB,SAAgB,YAAY,SAAiB;AAC3C,QAAO,GAAG,YAAY;EACtBA,cAAU;;IAER,QAAQ;;;AAIZ,SAAgB,cAAc,WAAmB;AAC/C,QAAO,GAAG,YAAY;;IAEpB,UAAU;;;AAId,SAAgB,aACd,UACA,YAAwB,UACxB;AAOA,QAAO,GAAG,YAAY;;WALpB,cAAc,WACV,KACA;kBACU,UAAU,GAID;IACvB,SAAS"}
|
|
@@ -5,7 +5,7 @@ import { Element, ElementContent, Properties, Root, Text } from "hast";
|
|
|
5
5
|
//#region src/utils/hast_utils.d.ts
|
|
6
6
|
declare function createTextNodeElement(value: string): Text;
|
|
7
7
|
interface CreateHastElementProps {
|
|
8
|
-
tagName: 'span' | 'div' | 'button' | 'code' | 'pre' | 'slot' | 'svg' | 'use' | 'style' | 'template';
|
|
8
|
+
tagName: 'span' | 'div' | 'button' | 'code' | 'pre' | 'slot' | 'svg' | 'use' | 'style' | 'template' | 'bdi';
|
|
9
9
|
children?: ElementContent[];
|
|
10
10
|
properties?: Properties;
|
|
11
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hast_utils.d.ts","names":["ElementContent","Element","HASTElement","Properties","Root","Text","SVGSpriteNames","LineTypes","createTextNodeElement","CreateHastElementProps","createHastElement","tagName","children","properties","CreateIconProps","createIconElement","name","width","height","findCodeElement","createGutterWrapper","createGutterItem","createGutterGap"],"sources":["../../src/utils/hast_utils.d.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement, Properties, Root, Text } from 'hast';\nimport type { SVGSpriteNames } from '../sprite';\nimport type { LineTypes } from '../types';\nexport declare function createTextNodeElement(value: string): Text;\ninterface CreateHastElementProps {\n tagName: 'span' | 'div' | 'button' | 'code' | 'pre' | 'slot' | 'svg' | 'use' | 'style' | 'template';\n children?: ElementContent[];\n properties?: Properties;\n}\nexport declare function createHastElement({ tagName, children, properties }: CreateHastElementProps): HASTElement;\ninterface CreateIconProps {\n name: SVGSpriteNames;\n width?: number;\n height?: number;\n properties?: Properties;\n}\nexport declare function createIconElement({ name, width, height, properties }: CreateIconProps): HASTElement;\nexport declare function findCodeElement(nodes: Root | HASTElement): HASTElement | undefined;\nexport declare function createGutterWrapper(children?: ElementContent[]): HASTElement;\nexport declare function createGutterItem(lineType: LineTypes | 'buffer' | 'separator' | 'annotation', lineNumber: number, lineIndex: string, properties?: Properties): HASTElement;\nexport declare function createGutterGap(type: LineTypes | undefined, bufferType: 'annotation' | 'buffer' | 'metadata', size: number): HASTElement;\nexport {};\n//# sourceMappingURL=hast_utils.d.ts.map"],"mappings":";;;;;iBAGwBQ,qBAAAA,iBAAsCH;UACpDI,sBAAAA;EADcD,OAAAA,EAAAA,MAAAA,GAAAA,KAAAA,GAAqB,QAAA,GAAiBH,MAAI,GAAA,KAAA,GAAA,MAAA,GAAA,KAAA,GAAA,KAAA,GAAA,OAAA,GAAA,UAAA;EACxDI,QAAAA,CAAAA,EAEKT,cAFiB,EAAA;EAKRU,UAAAA,CAAAA,EAFPP,UAEwB;;AAAYS,iBAA7BF,iBAAAA,CAA6BE;EAAAA,OAAAA;EAAAA,QAAAA;EAAAA;AAAAA,CAAAA,EAAwBH,sBAAxBG,CAAAA,EAAiDV,OAAjDU;UAC3CE,eAAAA,CADqDD;EAAcJ,IAAAA,EAEnEH,cAFmEG;EAAyBP,KAAAA,CAAAA,EAAAA,MAAAA;EAAW,MAAA,CAAA,EAAA,MAAA;EACvGY,UAAAA,CAAAA,EAIOX,UAJQ;AAMzB;AAA4Ca,iBAApBD,iBAAAA,CAAoBC;EAAAA,IAAAA;EAAAA,KAAAA;EAAAA,MAAAA;EAAAA;AAAAA,CAAAA,EAAmCF,eAAnCE,CAAAA,EAAqDd,OAArDc;AAAMC,iBAC1BE,eAAAA,CAD0BF,KAAAA,EACHb,IADGa,GACIf,OADJe,CAAAA,EACkBf,OADlBe,GAAAA,SAAAA;AAAOC,iBAEjCE,mBAAAA,CAFiCF,QAAAA,CAAAA,EAEFlB,cAFEkB,EAAAA,CAAAA,EAEiBhB,OAFjBgB;AAAQL,iBAGzCQ,gBAAAA,CAHyCR,QAAAA,EAGdN,SAHcM,GAAAA,QAAAA,GAAAA,WAAAA,GAAAA,YAAAA,EAAAA,UAAAA,EAAAA,MAAAA,EAAAA,SAAAA,EAAAA,MAAAA,EAAAA,UAAAA,CAAAA,EAGyFV,UAHzFU,CAAAA,EAGsGX,OAHtGW;AAAcC,iBAIvDQ,eAAAA,CAJuDR,IAAAA,EAIjCP,SAJiCO,GAAAA,SAAAA,EAAAA,UAAAA,EAAAA,YAAAA,GAAAA,QAAAA,GAAAA,UAAAA,EAAAA,IAAAA,EAAAA,MAAAA,CAAAA,EAIuDZ,OAJvDY"}
|
|
1
|
+
{"version":3,"file":"hast_utils.d.ts","names":["ElementContent","Element","HASTElement","Properties","Root","Text","SVGSpriteNames","LineTypes","createTextNodeElement","CreateHastElementProps","createHastElement","tagName","children","properties","CreateIconProps","createIconElement","name","width","height","findCodeElement","createGutterWrapper","createGutterItem","createGutterGap"],"sources":["../../src/utils/hast_utils.d.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement, Properties, Root, Text } from 'hast';\nimport type { SVGSpriteNames } from '../sprite';\nimport type { LineTypes } from '../types';\nexport declare function createTextNodeElement(value: string): Text;\ninterface CreateHastElementProps {\n tagName: 'span' | 'div' | 'button' | 'code' | 'pre' | 'slot' | 'svg' | 'use' | 'style' | 'template' | 'bdi';\n children?: ElementContent[];\n properties?: Properties;\n}\nexport declare function createHastElement({ tagName, children, properties }: CreateHastElementProps): HASTElement;\ninterface CreateIconProps {\n name: SVGSpriteNames;\n width?: number;\n height?: number;\n properties?: Properties;\n}\nexport declare function createIconElement({ name, width, height, properties }: CreateIconProps): HASTElement;\nexport declare function findCodeElement(nodes: Root | HASTElement): HASTElement | undefined;\nexport declare function createGutterWrapper(children?: ElementContent[]): HASTElement;\nexport declare function createGutterItem(lineType: LineTypes | 'buffer' | 'separator' | 'annotation', lineNumber: number, lineIndex: string, properties?: Properties): HASTElement;\nexport declare function createGutterGap(type: LineTypes | undefined, bufferType: 'annotation' | 'buffer' | 'metadata', size: number): HASTElement;\nexport {};\n//# sourceMappingURL=hast_utils.d.ts.map"],"mappings":";;;;;iBAGwBQ,qBAAAA,iBAAsCH;UACpDI,sBAAAA;EADcD,OAAAA,EAAAA,MAAAA,GAAAA,KAAAA,GAAqB,QAAA,GAAiBH,MAAI,GAAA,KAAA,GAAA,MAAA,GAAA,KAAA,GAAA,KAAA,GAAA,OAAA,GAAA,UAAA,GAAA,KAAA;EACxDI,QAAAA,CAAAA,EAEKT,cAFiB,EAAA;EAKRU,UAAAA,CAAAA,EAFPP,UAEwB;;AAAYS,iBAA7BF,iBAAAA,CAA6BE;EAAAA,OAAAA;EAAAA,QAAAA;EAAAA;AAAAA,CAAAA,EAAwBH,sBAAxBG,CAAAA,EAAiDV,OAAjDU;UAC3CE,eAAAA,CADqDD;EAAcJ,IAAAA,EAEnEH,cAFmEG;EAAyBP,KAAAA,CAAAA,EAAAA,MAAAA;EAAW,MAAA,CAAA,EAAA,MAAA;EACvGY,UAAAA,CAAAA,EAIOX,UAJQ;AAMzB;AAA4Ca,iBAApBD,iBAAAA,CAAoBC;EAAAA,IAAAA;EAAAA,KAAAA;EAAAA,MAAAA;EAAAA;AAAAA,CAAAA,EAAmCF,eAAnCE,CAAAA,EAAqDd,OAArDc;AAAMC,iBAC1BE,eAAAA,CAD0BF,KAAAA,EACHb,IADGa,GACIf,OADJe,CAAAA,EACkBf,OADlBe,GAAAA,SAAAA;AAAOC,iBAEjCE,mBAAAA,CAFiCF,QAAAA,CAAAA,EAEFlB,cAFEkB,EAAAA,CAAAA,EAEiBhB,OAFjBgB;AAAQL,iBAGzCQ,gBAAAA,CAHyCR,QAAAA,EAGdN,SAHcM,GAAAA,QAAAA,GAAAA,WAAAA,GAAAA,YAAAA,EAAAA,UAAAA,EAAAA,MAAAA,EAAAA,SAAAA,EAAAA,MAAAA,EAAAA,UAAAA,CAAAA,EAGyFV,UAHzFU,CAAAA,EAGsGX,OAHtGW;AAAcC,iBAIvDQ,eAAAA,CAJuDR,IAAAA,EAIjCP,SAJiCO,GAAAA,SAAAA,EAAAA,UAAAA,EAAAA,YAAAA,GAAAA,QAAAA,GAAAA,UAAAA,EAAAA,IAAAA,EAAAA,MAAAA,CAAAA,EAIuDZ,OAJvDY"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hast_utils.js","names":["firstChild: RootContent | HASTElement | Root | null"],"sources":["../../src/utils/hast_utils.ts"],"sourcesContent":["import type {\n ElementContent,\n Element as HASTElement,\n Properties,\n Root,\n RootContent,\n Text,\n} from 'hast';\n\nimport type { SVGSpriteNames } from '../sprite';\nimport type { LineTypes } from '../types';\n\nexport function createTextNodeElement(value: string): Text {\n return { type: 'text', value };\n}\n\ninterface CreateHastElementProps {\n tagName:\n | 'span'\n | 'div'\n | 'button'\n | 'code'\n | 'pre'\n | 'slot'\n | 'svg'\n | 'use'\n | 'style'\n | 'template';\n children?: ElementContent[];\n properties?: Properties;\n}\n\nexport function createHastElement({\n tagName,\n children = [],\n properties = {},\n}: CreateHastElementProps): HASTElement {\n return {\n type: 'element',\n tagName,\n properties,\n children,\n };\n}\n\ninterface CreateIconProps {\n name: SVGSpriteNames;\n width?: number;\n height?: number;\n properties?: Properties;\n}\n\nexport function createIconElement({\n name,\n width = 16,\n height = 16,\n properties,\n}: CreateIconProps): HASTElement {\n return createHastElement({\n tagName: 'svg',\n properties: { width, height, viewBox: '0 0 16 16', ...properties },\n children: [\n createHastElement({\n tagName: 'use',\n properties: { href: `#${name.replace(/^#/, '')}` },\n }),\n ],\n });\n}\n\nexport function findCodeElement(\n nodes: Root | HASTElement\n): HASTElement | undefined {\n let firstChild: RootContent | HASTElement | Root | null = nodes.children[0];\n while (firstChild != null) {\n if (firstChild.type === 'element' && firstChild.tagName === 'code') {\n return firstChild;\n }\n if ('children' in firstChild) {\n firstChild = firstChild.children[0];\n } else {\n firstChild = null;\n }\n }\n return undefined;\n}\n\nexport function createGutterWrapper(children?: ElementContent[]): HASTElement {\n return createHastElement({\n tagName: 'div',\n properties: { 'data-gutter': '' },\n children,\n });\n}\n\nexport function createGutterItem(\n lineType: LineTypes | 'buffer' | 'separator' | 'annotation',\n lineNumber: number,\n lineIndex: string,\n properties: Properties = {}\n): HASTElement {\n return createHastElement({\n tagName: 'div',\n properties: {\n 'data-line-type': lineType,\n 'data-column-number': lineNumber,\n 'data-line-index': lineIndex,\n ...properties,\n },\n children:\n lineNumber != null\n ? [\n createHastElement({\n tagName: 'span',\n properties: { 'data-line-number-content': '' },\n children: [createTextNodeElement(`${lineNumber}`)],\n }),\n ]\n : undefined,\n });\n}\n\nexport function createGutterGap(\n type: LineTypes | undefined,\n bufferType: 'annotation' | 'buffer' | 'metadata',\n size: number\n): HASTElement {\n return createHastElement({\n tagName: 'div',\n properties: {\n 'data-gutter-buffer': bufferType,\n 'data-buffer-size': size,\n 'data-line-type': bufferType === 'annotation' ? undefined : type,\n style:\n bufferType === 'annotation'\n ? `grid-row: span ${size};`\n : `grid-row: span ${size};min-height:calc(${size} * 1lh);`,\n },\n });\n}\n"],"mappings":";AAYA,SAAgB,sBAAsB,OAAqB;AACzD,QAAO;EAAE,MAAM;EAAQ;EAAO;;
|
|
1
|
+
{"version":3,"file":"hast_utils.js","names":["firstChild: RootContent | HASTElement | Root | null"],"sources":["../../src/utils/hast_utils.ts"],"sourcesContent":["import type {\n ElementContent,\n Element as HASTElement,\n Properties,\n Root,\n RootContent,\n Text,\n} from 'hast';\n\nimport type { SVGSpriteNames } from '../sprite';\nimport type { LineTypes } from '../types';\n\nexport function createTextNodeElement(value: string): Text {\n return { type: 'text', value };\n}\n\ninterface CreateHastElementProps {\n tagName:\n | 'span'\n | 'div'\n | 'button'\n | 'code'\n | 'pre'\n | 'slot'\n | 'svg'\n | 'use'\n | 'style'\n | 'template'\n | 'bdi';\n children?: ElementContent[];\n properties?: Properties;\n}\n\nexport function createHastElement({\n tagName,\n children = [],\n properties = {},\n}: CreateHastElementProps): HASTElement {\n return {\n type: 'element',\n tagName,\n properties,\n children,\n };\n}\n\ninterface CreateIconProps {\n name: SVGSpriteNames;\n width?: number;\n height?: number;\n properties?: Properties;\n}\n\nexport function createIconElement({\n name,\n width = 16,\n height = 16,\n properties,\n}: CreateIconProps): HASTElement {\n return createHastElement({\n tagName: 'svg',\n properties: { width, height, viewBox: '0 0 16 16', ...properties },\n children: [\n createHastElement({\n tagName: 'use',\n properties: { href: `#${name.replace(/^#/, '')}` },\n }),\n ],\n });\n}\n\nexport function findCodeElement(\n nodes: Root | HASTElement\n): HASTElement | undefined {\n let firstChild: RootContent | HASTElement | Root | null = nodes.children[0];\n while (firstChild != null) {\n if (firstChild.type === 'element' && firstChild.tagName === 'code') {\n return firstChild;\n }\n if ('children' in firstChild) {\n firstChild = firstChild.children[0];\n } else {\n firstChild = null;\n }\n }\n return undefined;\n}\n\nexport function createGutterWrapper(children?: ElementContent[]): HASTElement {\n return createHastElement({\n tagName: 'div',\n properties: { 'data-gutter': '' },\n children,\n });\n}\n\nexport function createGutterItem(\n lineType: LineTypes | 'buffer' | 'separator' | 'annotation',\n lineNumber: number,\n lineIndex: string,\n properties: Properties = {}\n): HASTElement {\n return createHastElement({\n tagName: 'div',\n properties: {\n 'data-line-type': lineType,\n 'data-column-number': lineNumber,\n 'data-line-index': lineIndex,\n ...properties,\n },\n children:\n lineNumber != null\n ? [\n createHastElement({\n tagName: 'span',\n properties: { 'data-line-number-content': '' },\n children: [createTextNodeElement(`${lineNumber}`)],\n }),\n ]\n : undefined,\n });\n}\n\nexport function createGutterGap(\n type: LineTypes | undefined,\n bufferType: 'annotation' | 'buffer' | 'metadata',\n size: number\n): HASTElement {\n return createHastElement({\n tagName: 'div',\n properties: {\n 'data-gutter-buffer': bufferType,\n 'data-buffer-size': size,\n 'data-line-type': bufferType === 'annotation' ? undefined : type,\n style:\n bufferType === 'annotation'\n ? `grid-row: span ${size};`\n : `grid-row: span ${size};min-height:calc(${size} * 1lh);`,\n },\n });\n}\n"],"mappings":";AAYA,SAAgB,sBAAsB,OAAqB;AACzD,QAAO;EAAE,MAAM;EAAQ;EAAO;;AAoBhC,SAAgB,kBAAkB,EAChC,SACA,WAAW,EAAE,EACb,aAAa,EAAE,IACuB;AACtC,QAAO;EACL,MAAM;EACN;EACA;EACA;EACD;;AAUH,SAAgB,kBAAkB,EAChC,MACA,QAAQ,IACR,SAAS,IACT,cAC+B;AAC/B,QAAO,kBAAkB;EACvB,SAAS;EACT,YAAY;GAAE;GAAO;GAAQ,SAAS;GAAa,GAAG;GAAY;EAClE,UAAU,CACR,kBAAkB;GAChB,SAAS;GACT,YAAY,EAAE,MAAM,IAAI,KAAK,QAAQ,MAAM,GAAG,IAAI;GACnD,CAAC,CACH;EACF,CAAC;;AAGJ,SAAgB,gBACd,OACyB;CACzB,IAAIA,aAAsD,MAAM,SAAS;AACzE,QAAO,cAAc,MAAM;AACzB,MAAI,WAAW,SAAS,aAAa,WAAW,YAAY,OAC1D,QAAO;AAET,MAAI,cAAc,WAChB,cAAa,WAAW,SAAS;MAEjC,cAAa;;;AAMnB,SAAgB,oBAAoB,UAA0C;AAC5E,QAAO,kBAAkB;EACvB,SAAS;EACT,YAAY,EAAE,eAAe,IAAI;EACjC;EACD,CAAC;;AAGJ,SAAgB,iBACd,UACA,YACA,WACA,aAAyB,EAAE,EACd;AACb,QAAO,kBAAkB;EACvB,SAAS;EACT,YAAY;GACV,kBAAkB;GAClB,sBAAsB;GACtB,mBAAmB;GACnB,GAAG;GACJ;EACD,UACE,cAAc,OACV,CACE,kBAAkB;GAChB,SAAS;GACT,YAAY,EAAE,4BAA4B,IAAI;GAC9C,UAAU,CAAC,sBAAsB,GAAG,aAAa,CAAC;GACnD,CAAC,CACH,GACD;EACP,CAAC;;AAGJ,SAAgB,gBACd,MACA,YACA,MACa;AACb,QAAO,kBAAkB;EACvB,SAAS;EACT,YAAY;GACV,sBAAsB;GACtB,oBAAoB;GACpB,kBAAkB,eAAe,eAAe,SAAY;GAC5D,OACE,eAAe,eACX,kBAAkB,KAAK,KACvB,kBAAkB,KAAK,mBAAmB,KAAK;GACtD;EACF,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/utils/hostTheme.d.ts
|
|
2
|
+
interface UpsertHostThemeStyleProps {
|
|
3
|
+
shadowRoot: ShadowRoot;
|
|
4
|
+
currentNode: HTMLStyleElement | undefined;
|
|
5
|
+
themeCSS: string;
|
|
6
|
+
}
|
|
7
|
+
declare function upsertHostThemeStyle({
|
|
8
|
+
shadowRoot,
|
|
9
|
+
currentNode,
|
|
10
|
+
themeCSS
|
|
11
|
+
}: UpsertHostThemeStyleProps): HTMLStyleElement | undefined;
|
|
12
|
+
declare function createHostThemeStyleNode(): HTMLStyleElement;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { createHostThemeStyleNode, upsertHostThemeStyle };
|
|
15
|
+
//# sourceMappingURL=hostTheme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostTheme.d.ts","names":["UpsertHostThemeStyleProps","ShadowRoot","HTMLStyleElement","upsertHostThemeStyle","shadowRoot","currentNode","themeCSS","createHostThemeStyleNode"],"sources":["../../src/utils/hostTheme.d.ts"],"sourcesContent":["interface UpsertHostThemeStyleProps {\n shadowRoot: ShadowRoot;\n currentNode: HTMLStyleElement | undefined;\n themeCSS: string;\n}\nexport declare function upsertHostThemeStyle({ shadowRoot, currentNode, themeCSS }: UpsertHostThemeStyleProps): HTMLStyleElement | undefined;\nexport declare function createHostThemeStyleNode(): HTMLStyleElement;\nexport {};\n//# sourceMappingURL=hostTheme.d.ts.map"],"mappings":";UAAUA,yBAAAA;EAAAA,UAAAA,EACMC,UADND;EAKcG,WAAAA,EAHPD,gBAG2B,GAAA,SAAA;EAAGE,QAAAA,EAAAA,MAAAA;;AAAyBE,iBAAhDH,oBAAAA,CAAgDG;EAAAA,UAAAA;EAAAA,WAAAA;EAAAA;AAAAA,CAAAA,EAAYN,yBAAZM,CAAAA,EAAwCJ,gBAAxCI,GAAAA,SAAAA;AAAYN,iBAC5DO,wBAAAA,CAAAA,CAD4DP,EAChCE,gBADgCF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { THEME_CSS_ATTRIBUTE } from "../constants.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/hostTheme.ts
|
|
4
|
+
function upsertHostThemeStyle({ shadowRoot, currentNode, themeCSS }) {
|
|
5
|
+
if (themeCSS.trim() === "") {
|
|
6
|
+
currentNode?.remove();
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
currentNode ??= createHostThemeStyleNode();
|
|
10
|
+
currentNode.textContent = themeCSS;
|
|
11
|
+
if (currentNode.parentNode !== shadowRoot) shadowRoot.appendChild(currentNode);
|
|
12
|
+
return currentNode;
|
|
13
|
+
}
|
|
14
|
+
function createHostThemeStyleNode() {
|
|
15
|
+
const node = document.createElement("style");
|
|
16
|
+
node.setAttribute(THEME_CSS_ATTRIBUTE, "");
|
|
17
|
+
return node;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { createHostThemeStyleNode, upsertHostThemeStyle };
|
|
22
|
+
//# sourceMappingURL=hostTheme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostTheme.js","names":[],"sources":["../../src/utils/hostTheme.ts"],"sourcesContent":["import { THEME_CSS_ATTRIBUTE } from '../constants';\n\ninterface UpsertHostThemeStyleProps {\n shadowRoot: ShadowRoot;\n currentNode: HTMLStyleElement | undefined;\n themeCSS: string;\n}\n\n// Keep the host theme style stable so renderers can update the host-scoped theme\n// CSS without rebuilding the rest of the shadow DOM.\nexport function upsertHostThemeStyle({\n shadowRoot,\n currentNode,\n themeCSS,\n}: UpsertHostThemeStyleProps): HTMLStyleElement | undefined {\n if (themeCSS.trim() === '') {\n currentNode?.remove();\n return undefined;\n }\n\n currentNode ??= createHostThemeStyleNode();\n currentNode.textContent = themeCSS;\n if (currentNode.parentNode !== shadowRoot) {\n shadowRoot.appendChild(currentNode);\n }\n return currentNode;\n}\n\nexport function createHostThemeStyleNode(): HTMLStyleElement {\n const node = document.createElement('style');\n node.setAttribute(THEME_CSS_ATTRIBUTE, '');\n return node;\n}\n"],"mappings":";;;AAUA,SAAgB,qBAAqB,EACnC,YACA,aACA,YAC0D;AAC1D,KAAI,SAAS,MAAM,KAAK,IAAI;AAC1B,eAAa,QAAQ;AACrB;;AAGF,iBAAgB,0BAA0B;AAC1C,aAAY,cAAc;AAC1B,KAAI,YAAY,eAAe,WAC7B,YAAW,YAAY,YAAY;AAErC,QAAO;;AAGT,SAAgB,2BAA6C;CAC3D,MAAM,OAAO,SAAS,cAAc,QAAQ;AAC5C,MAAK,aAAa,qBAAqB,GAAG;AAC1C,QAAO"}
|
|
@@ -101,7 +101,7 @@ function processFile(fileDiffString, { cacheKey, isGitDiff = GIT_DIFF_FILE_BREAK
|
|
|
101
101
|
if (newObjectId != null) currentFile.newObjectId = newObjectId;
|
|
102
102
|
if (mode != null) currentFile.mode = mode;
|
|
103
103
|
}
|
|
104
|
-
if (line.startsWith("rename from ")) currentFile.prevName = line.replace("rename from ", "");
|
|
104
|
+
if (line.startsWith("rename from ")) currentFile.prevName = line.replace("rename from ", "").trim();
|
|
105
105
|
if (line.startsWith("rename to ")) currentFile.name = line.replace("rename to ", "").trim();
|
|
106
106
|
}
|
|
107
107
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsePatchFiles.js","names":["patchMetadata: string | undefined","files: FileDiffMetadata[]","currentFile: FileDiffMetadata | undefined","currentContent: ContextContent | ChangeContent | undefined","lastLineType: 'context' | 'addition' | 'deletion' | undefined","hunkData: Hunk","lastHunkEnd","patches: ParsedPatch[]"],"sources":["../../src/utils/parsePatchFiles.ts"],"sourcesContent":["import {\n ALTERNATE_FILE_NAMES_GIT,\n COMMIT_METADATA_SPLIT,\n FILE_CONTEXT_BLOB,\n FILENAME_HEADER_REGEX,\n FILENAME_HEADER_REGEX_GIT,\n GIT_DIFF_FILE_BREAK_REGEX,\n HUNK_HEADER,\n INDEX_LINE_METADATA,\n SPLIT_WITH_NEWLINES,\n UNIFIED_DIFF_FILE_BREAK_REGEX,\n} from '../constants';\nimport type {\n ChangeContent,\n ContextContent,\n FileContents,\n FileDiffMetadata,\n Hunk,\n ParsedPatch,\n} from '../types';\nimport { cleanLastNewline } from './cleanLastNewline';\nimport { parseLineType } from './parseLineType';\n\nexport function processPatch(\n data: string,\n cacheKeyPrefix?: string,\n throwOnError = false\n): ParsedPatch {\n const isGitDiff = GIT_DIFF_FILE_BREAK_REGEX.test(data);\n const rawFiles = data.split(\n isGitDiff ? GIT_DIFF_FILE_BREAK_REGEX : UNIFIED_DIFF_FILE_BREAK_REGEX\n );\n let patchMetadata: string | undefined;\n const files: FileDiffMetadata[] = [];\n for (const fileOrPatchMetadata of rawFiles) {\n if (isGitDiff && !GIT_DIFF_FILE_BREAK_REGEX.test(fileOrPatchMetadata)) {\n if (patchMetadata == null) {\n patchMetadata = fileOrPatchMetadata;\n } else {\n if (throwOnError) {\n throw Error('parsePatchContent: unknown file blob');\n } else {\n console.error(\n 'parsePatchContent: unknown file blob:',\n fileOrPatchMetadata\n );\n }\n }\n // If we get in here, it's most likely the introductory metadata from the\n // patch, or something is fucked with the diff format\n continue;\n } else if (\n !isGitDiff &&\n !UNIFIED_DIFF_FILE_BREAK_REGEX.test(fileOrPatchMetadata)\n ) {\n if (patchMetadata == null) {\n patchMetadata = fileOrPatchMetadata;\n } else {\n if (throwOnError) {\n throw Error('parsePatchContent: unknown file blob');\n } else {\n console.error(\n 'parsePatchContent: unknown file blob:',\n fileOrPatchMetadata\n );\n }\n }\n continue;\n }\n const currentFile = processFile(fileOrPatchMetadata, {\n cacheKey:\n cacheKeyPrefix != null\n ? `${cacheKeyPrefix}-${files.length}`\n : undefined,\n isGitDiff,\n throwOnError,\n });\n if (currentFile != null) {\n files.push(currentFile);\n }\n }\n return { patchMetadata, files };\n}\n\ninterface ProcessFileOptions {\n cacheKey?: string;\n isGitDiff?: boolean;\n oldFile?: FileContents;\n newFile?: FileContents;\n throwOnError?: boolean;\n}\n\nexport function processFile(\n fileDiffString: string,\n {\n cacheKey,\n isGitDiff = GIT_DIFF_FILE_BREAK_REGEX.test(fileDiffString),\n oldFile,\n newFile,\n throwOnError = false,\n }: ProcessFileOptions = {}\n): FileDiffMetadata | undefined {\n let lastHunkEnd = 0;\n const hunks = fileDiffString.split(FILE_CONTEXT_BLOB);\n let currentFile: FileDiffMetadata | undefined;\n const isPartial = oldFile == null || newFile == null;\n let deletionLineIndex = 0;\n let additionLineIndex = 0;\n for (const hunk of hunks) {\n const lines = hunk.split(SPLIT_WITH_NEWLINES);\n const firstLine = lines.shift();\n if (firstLine == null) {\n if (throwOnError) {\n throw Error('parsePatchContent: invalid hunk');\n } else {\n console.error('parsePatchContent: invalid hunk', hunk);\n }\n continue;\n }\n const fileHeaderMatch = firstLine.match(HUNK_HEADER);\n let additionLines = 0;\n let deletionLines = 0;\n // Setup currentFile, this should be the first iteration of our hunks, and\n // technically not a hunk\n if (fileHeaderMatch == null || currentFile == null) {\n if (currentFile != null) {\n if (throwOnError) {\n throw Error('parsePatchContent: Invalid hunk');\n } else {\n console.error('parsePatchContent: Invalid hunk', hunk);\n }\n continue;\n }\n currentFile = {\n name: '',\n type: 'change',\n hunks: [],\n splitLineCount: 0,\n unifiedLineCount: 0,\n isPartial,\n additionLines:\n !isPartial && oldFile != null && newFile != null\n ? newFile.contents.split(SPLIT_WITH_NEWLINES)\n : [],\n deletionLines:\n !isPartial && oldFile != null && newFile != null\n ? oldFile.contents.split(SPLIT_WITH_NEWLINES)\n : [],\n cacheKey,\n };\n // If either file is technically empty, then we should empty the\n // arrays respectively\n if (currentFile.additionLines.length === 1 && newFile?.contents === '') {\n currentFile.additionLines.length = 0;\n }\n if (currentFile.deletionLines.length === 1 && oldFile?.contents === '') {\n currentFile.deletionLines.length = 0;\n }\n\n // Push that first line back into the group of lines so we can properly\n // parse it out\n lines.unshift(firstLine);\n for (const line of lines) {\n const filenameMatch = line.match(\n isGitDiff ? FILENAME_HEADER_REGEX_GIT : FILENAME_HEADER_REGEX\n );\n if (line.startsWith('diff --git')) {\n const [, , prevName, , name] =\n line.trim().match(ALTERNATE_FILE_NAMES_GIT) ?? [];\n currentFile.name = name.trim();\n if (prevName !== name) {\n currentFile.prevName = prevName.trim();\n }\n } else if (filenameMatch != null) {\n const [, type, fileName] = filenameMatch;\n if (type === '---' && fileName !== '/dev/null') {\n currentFile.prevName = fileName.trim();\n currentFile.name = fileName.trim();\n } else if (type === '+++' && fileName !== '/dev/null') {\n currentFile.name = fileName.trim();\n }\n }\n // Git diffs have a bunch of additional metadata we can pull from\n else if (isGitDiff) {\n if (line.startsWith('new mode ')) {\n currentFile.mode = line.replace('new mode', '').trim();\n }\n if (line.startsWith('old mode ')) {\n currentFile.prevMode = line.replace('old mode', '').trim();\n }\n if (line.startsWith('new file mode')) {\n currentFile.type = 'new';\n currentFile.mode = line.replace('new file mode', '').trim();\n }\n if (line.startsWith('deleted file mode')) {\n currentFile.type = 'deleted';\n currentFile.mode = line.replace('deleted file mode', '').trim();\n }\n if (line.startsWith('similarity index')) {\n if (line.startsWith('similarity index 100%')) {\n currentFile.type = 'rename-pure';\n } else {\n currentFile.type = 'rename-changed';\n }\n }\n if (line.startsWith('index ')) {\n const [, prevObjectId, newObjectId, mode] =\n line.trim().match(INDEX_LINE_METADATA) ?? [];\n if (prevObjectId != null) {\n currentFile.prevObjectId = prevObjectId;\n }\n if (newObjectId != null) {\n currentFile.newObjectId = newObjectId;\n }\n if (mode != null) {\n currentFile.mode = mode;\n }\n }\n // We have to handle these for pure renames because there won't be\n // --- and +++ lines\n if (line.startsWith('rename from ')) {\n currentFile.prevName = line.replace('rename from ', '');\n }\n if (line.startsWith('rename to ')) {\n currentFile.name = line.replace('rename to ', '').trim();\n }\n }\n }\n continue;\n }\n\n // Otherwise, time to start parsing out the hunk\n let currentContent: ContextContent | ChangeContent | undefined;\n let lastLineType: 'context' | 'addition' | 'deletion' | undefined;\n\n // Strip trailing bare newlines (format-patch separators between commits)\n // if needed\n while (\n lines.length > 0 &&\n (lines[lines.length - 1] === '\\n' ||\n lines[lines.length - 1] === '\\r' ||\n lines[lines.length - 1] === '\\r\\n' ||\n lines[lines.length - 1] === '')\n ) {\n lines.pop();\n }\n\n const additionStart = parseInt(fileHeaderMatch[3]);\n const deletionStart = parseInt(fileHeaderMatch[1]);\n deletionLineIndex = isPartial ? deletionLineIndex : deletionStart - 1;\n additionLineIndex = isPartial ? additionLineIndex : additionStart - 1;\n\n const hunkData: Hunk = {\n collapsedBefore: 0,\n\n splitLineCount: 0,\n splitLineStart: 0,\n\n unifiedLineCount: 0,\n unifiedLineStart: 0,\n\n additionCount: parseInt(fileHeaderMatch[4] ?? '1'),\n additionStart,\n additionLines,\n\n deletionCount: parseInt(fileHeaderMatch[2] ?? '1'),\n deletionStart,\n deletionLines,\n\n deletionLineIndex,\n additionLineIndex,\n\n hunkContent: [],\n hunkContext: fileHeaderMatch[5],\n hunkSpecs: firstLine,\n\n noEOFCRAdditions: false,\n noEOFCRDeletions: false,\n };\n\n // Lets validate out hunkData to ensure there's no broken data from the\n // regex\n if (\n isNaN(hunkData.additionCount) ||\n isNaN(hunkData.deletionCount) ||\n isNaN(hunkData.additionStart) ||\n isNaN(hunkData.deletionStart)\n ) {\n if (throwOnError) {\n throw Error('parsePatchContent: invalid hunk metadata');\n } else {\n console.error('parsePatchContent: invalid hunk metadata', hunkData);\n }\n continue;\n }\n\n // Now we process each line of the hunk\n for (const rawLine of lines) {\n const parsedLine = parseLineType(rawLine);\n // If we can't properly process the line, well, lets just try to salvage\n // things and continue... It's possible an AI generated diff might have\n // some stray blank lines or something in there\n if (parsedLine == null) {\n console.error('processFile: invalid rawLine:', rawLine);\n continue;\n }\n\n const { type, line } = parsedLine;\n if (type === 'addition') {\n if (currentContent == null || currentContent.type !== 'change') {\n currentContent = createContentGroup(\n 'change',\n deletionLineIndex,\n additionLineIndex\n );\n hunkData.hunkContent.push(currentContent);\n }\n additionLineIndex++;\n if (isPartial) {\n currentFile.additionLines.push(line);\n }\n currentContent.additions++;\n additionLines++;\n lastLineType = 'addition';\n } else if (type === 'deletion') {\n if (currentContent == null || currentContent.type !== 'change') {\n currentContent = createContentGroup(\n 'change',\n deletionLineIndex,\n additionLineIndex\n );\n hunkData.hunkContent.push(currentContent);\n }\n deletionLineIndex++;\n if (isPartial) {\n currentFile.deletionLines.push(line);\n }\n currentContent.deletions++;\n deletionLines++;\n lastLineType = 'deletion';\n } else if (type === 'context') {\n if (currentContent == null || currentContent.type !== 'context') {\n currentContent = createContentGroup(\n 'context',\n deletionLineIndex,\n additionLineIndex\n );\n hunkData.hunkContent.push(currentContent);\n }\n additionLineIndex++;\n deletionLineIndex++;\n if (isPartial) {\n currentFile.deletionLines.push(line);\n currentFile.additionLines.push(line);\n }\n currentContent.lines++;\n lastLineType = 'context';\n } else if (type === 'metadata' && currentContent != null) {\n if (currentContent.type === 'context') {\n hunkData.noEOFCRAdditions = true;\n hunkData.noEOFCRDeletions = true;\n } else if (lastLineType === 'deletion') {\n hunkData.noEOFCRDeletions = true;\n } else if (lastLineType === 'addition') {\n hunkData.noEOFCRAdditions = true;\n }\n // If we're dealing with partial content from a diff, we need to strip\n // newlines manually from the content\n if (\n isPartial &&\n (lastLineType === 'addition' || lastLineType === 'context')\n ) {\n const lastIndex = currentFile.additionLines.length - 1;\n if (lastIndex >= 0) {\n currentFile.additionLines[lastIndex] = cleanLastNewline(\n currentFile.additionLines[lastIndex]\n );\n }\n }\n if (\n isPartial &&\n (lastLineType === 'deletion' || lastLineType === 'context')\n ) {\n const lastIndex = currentFile.deletionLines.length - 1;\n if (lastIndex >= 0) {\n currentFile.deletionLines[lastIndex] = cleanLastNewline(\n currentFile.deletionLines[lastIndex]\n );\n }\n }\n }\n }\n\n hunkData.additionLines = additionLines;\n hunkData.deletionLines = deletionLines;\n\n hunkData.collapsedBefore = Math.max(\n hunkData.additionStart - 1 - lastHunkEnd,\n 0\n );\n currentFile.hunks.push(hunkData);\n lastHunkEnd = hunkData.additionStart + hunkData.additionCount - 1;\n for (const content of hunkData.hunkContent) {\n if (content.type === 'context') {\n hunkData.splitLineCount += content.lines;\n hunkData.unifiedLineCount += content.lines;\n } else {\n hunkData.splitLineCount += Math.max(\n content.additions,\n content.deletions\n );\n hunkData.unifiedLineCount += content.deletions + content.additions;\n }\n }\n hunkData.splitLineStart =\n currentFile.splitLineCount + hunkData.collapsedBefore;\n hunkData.unifiedLineStart =\n currentFile.unifiedLineCount + hunkData.collapsedBefore;\n\n currentFile.splitLineCount +=\n hunkData.collapsedBefore + hunkData.splitLineCount;\n currentFile.unifiedLineCount +=\n hunkData.collapsedBefore + hunkData.unifiedLineCount;\n }\n if (currentFile == null) {\n return undefined;\n }\n\n // Account for collapsed lines after the final hunk and increment the\n // split/unified counts properly\n if (\n currentFile.hunks.length > 0 &&\n !isPartial &&\n currentFile.additionLines.length > 0 &&\n currentFile.deletionLines.length > 0\n ) {\n const lastHunk = currentFile.hunks[currentFile.hunks.length - 1];\n const lastHunkEnd = lastHunk.additionStart + lastHunk.additionCount - 1;\n const totalFileLines = currentFile.additionLines.length;\n const collapsedAfter = Math.max(totalFileLines - lastHunkEnd, 0);\n currentFile.splitLineCount += collapsedAfter;\n currentFile.unifiedLineCount += collapsedAfter;\n }\n\n // If this isn't a git diff style patch, then we'll need to sus out some\n // additional metadata manually\n if (!isGitDiff) {\n if (\n currentFile.prevName != null &&\n currentFile.name !== currentFile.prevName\n ) {\n if (currentFile.hunks.length > 0) {\n currentFile.type = 'rename-changed';\n } else {\n currentFile.type = 'rename-pure';\n }\n }\n // Sort of a hack for detecting deleted/added files...\n else if (newFile != null && newFile.contents === '') {\n currentFile.type = 'deleted';\n } else if (oldFile != null && oldFile.contents === '') {\n currentFile.type = 'new';\n }\n }\n if (\n currentFile.type !== 'rename-pure' &&\n currentFile.type !== 'rename-changed'\n ) {\n currentFile.prevName = undefined;\n }\n return currentFile;\n}\n\n/**\n * Parses a patch file string into an array of parsed patches.\n *\n * @param data - The raw patch file content (supports multi-commit patches)\n * @param cacheKeyPrefix - Optional prefix for generating cache keys. When provided,\n * each file in the patch will get a cache key in the format `prefix-patchIndex-fileIndex`.\n * This enables caching of rendered diff results in the worker pool.\n */\nexport function parsePatchFiles(\n data: string,\n cacheKeyPrefix?: string,\n throwOnError = false\n): ParsedPatch[] {\n // NOTE(amadeus): This function is pretty forgiving in that it can accept a\n // patch file that includes commit metdata, multiple commits, or not\n const patches: ParsedPatch[] = [];\n for (const patch of data.split(COMMIT_METADATA_SPLIT)) {\n try {\n patches.push(\n processPatch(\n patch,\n cacheKeyPrefix != null\n ? `${cacheKeyPrefix}-${patches.length}`\n : undefined,\n throwOnError\n )\n );\n } catch (error) {\n if (throwOnError) {\n throw error;\n } else {\n console.error(error);\n }\n }\n }\n return patches;\n}\n\nfunction createContentGroup(\n type: 'change',\n deletionLineIndex: number,\n additionLineIndex: number\n): ChangeContent;\nfunction createContentGroup(\n type: 'context',\n deletionLineIndex: number,\n additionLineIndex: number\n): ContextContent;\nfunction createContentGroup(\n type: 'change' | 'context',\n deletionLineIndex: number,\n additionLineIndex: number\n): ChangeContent | ContextContent {\n if (type === 'change') {\n return {\n type: 'change',\n additions: 0,\n deletions: 0,\n additionLineIndex,\n deletionLineIndex,\n };\n }\n return {\n type: 'context',\n lines: 0,\n additionLineIndex,\n deletionLineIndex,\n };\n}\n"],"mappings":";;;;;AAuBA,SAAgB,aACd,MACA,gBACA,eAAe,OACF;CACb,MAAM,YAAY,0BAA0B,KAAK,KAAK;CACtD,MAAM,WAAW,KAAK,MACpB,YAAY,4BAA4B,8BACzC;CACD,IAAIA;CACJ,MAAMC,QAA4B,EAAE;AACpC,MAAK,MAAM,uBAAuB,UAAU;AAC1C,MAAI,aAAa,CAAC,0BAA0B,KAAK,oBAAoB,EAAE;AACrE,OAAI,iBAAiB,KACnB,iBAAgB;YAEZ,aACF,OAAM,MAAM,uCAAuC;OAEnD,SAAQ,MACN,yCACA,oBACD;AAKL;aAEA,CAAC,aACD,CAAC,8BAA8B,KAAK,oBAAoB,EACxD;AACA,OAAI,iBAAiB,KACnB,iBAAgB;YAEZ,aACF,OAAM,MAAM,uCAAuC;OAEnD,SAAQ,MACN,yCACA,oBACD;AAGL;;EAEF,MAAM,cAAc,YAAY,qBAAqB;GACnD,UACE,kBAAkB,OACd,GAAG,eAAe,GAAG,MAAM,WAC3B;GACN;GACA;GACD,CAAC;AACF,MAAI,eAAe,KACjB,OAAM,KAAK,YAAY;;AAG3B,QAAO;EAAE;EAAe;EAAO;;AAWjC,SAAgB,YACd,gBACA,EACE,UACA,YAAY,0BAA0B,KAAK,eAAe,EAC1D,SACA,SACA,eAAe,UACO,EAAE,EACI;CAC9B,IAAI,cAAc;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N,WAAW;EACX,WAAW;EACX;EACA;EACD;AAEH,QAAO;EACL,MAAM;EACN,OAAO;EACP;EACA;EACD"}
|
|
1
|
+
{"version":3,"file":"parsePatchFiles.js","names":["patchMetadata: string | undefined","files: FileDiffMetadata[]","currentFile: FileDiffMetadata | undefined","currentContent: ContextContent | ChangeContent | undefined","lastLineType: 'context' | 'addition' | 'deletion' | undefined","hunkData: Hunk","lastHunkEnd","patches: ParsedPatch[]"],"sources":["../../src/utils/parsePatchFiles.ts"],"sourcesContent":["import {\n ALTERNATE_FILE_NAMES_GIT,\n COMMIT_METADATA_SPLIT,\n FILE_CONTEXT_BLOB,\n FILENAME_HEADER_REGEX,\n FILENAME_HEADER_REGEX_GIT,\n GIT_DIFF_FILE_BREAK_REGEX,\n HUNK_HEADER,\n INDEX_LINE_METADATA,\n SPLIT_WITH_NEWLINES,\n UNIFIED_DIFF_FILE_BREAK_REGEX,\n} from '../constants';\nimport type {\n ChangeContent,\n ContextContent,\n FileContents,\n FileDiffMetadata,\n Hunk,\n ParsedPatch,\n} from '../types';\nimport { cleanLastNewline } from './cleanLastNewline';\nimport { parseLineType } from './parseLineType';\n\nexport function processPatch(\n data: string,\n cacheKeyPrefix?: string,\n throwOnError = false\n): ParsedPatch {\n const isGitDiff = GIT_DIFF_FILE_BREAK_REGEX.test(data);\n const rawFiles = data.split(\n isGitDiff ? GIT_DIFF_FILE_BREAK_REGEX : UNIFIED_DIFF_FILE_BREAK_REGEX\n );\n let patchMetadata: string | undefined;\n const files: FileDiffMetadata[] = [];\n for (const fileOrPatchMetadata of rawFiles) {\n if (isGitDiff && !GIT_DIFF_FILE_BREAK_REGEX.test(fileOrPatchMetadata)) {\n if (patchMetadata == null) {\n patchMetadata = fileOrPatchMetadata;\n } else {\n if (throwOnError) {\n throw Error('parsePatchContent: unknown file blob');\n } else {\n console.error(\n 'parsePatchContent: unknown file blob:',\n fileOrPatchMetadata\n );\n }\n }\n // If we get in here, it's most likely the introductory metadata from the\n // patch, or something is fucked with the diff format\n continue;\n } else if (\n !isGitDiff &&\n !UNIFIED_DIFF_FILE_BREAK_REGEX.test(fileOrPatchMetadata)\n ) {\n if (patchMetadata == null) {\n patchMetadata = fileOrPatchMetadata;\n } else {\n if (throwOnError) {\n throw Error('parsePatchContent: unknown file blob');\n } else {\n console.error(\n 'parsePatchContent: unknown file blob:',\n fileOrPatchMetadata\n );\n }\n }\n continue;\n }\n const currentFile = processFile(fileOrPatchMetadata, {\n cacheKey:\n cacheKeyPrefix != null\n ? `${cacheKeyPrefix}-${files.length}`\n : undefined,\n isGitDiff,\n throwOnError,\n });\n if (currentFile != null) {\n files.push(currentFile);\n }\n }\n return { patchMetadata, files };\n}\n\ninterface ProcessFileOptions {\n cacheKey?: string;\n isGitDiff?: boolean;\n oldFile?: FileContents;\n newFile?: FileContents;\n throwOnError?: boolean;\n}\n\nexport function processFile(\n fileDiffString: string,\n {\n cacheKey,\n isGitDiff = GIT_DIFF_FILE_BREAK_REGEX.test(fileDiffString),\n oldFile,\n newFile,\n throwOnError = false,\n }: ProcessFileOptions = {}\n): FileDiffMetadata | undefined {\n let lastHunkEnd = 0;\n const hunks = fileDiffString.split(FILE_CONTEXT_BLOB);\n let currentFile: FileDiffMetadata | undefined;\n const isPartial = oldFile == null || newFile == null;\n let deletionLineIndex = 0;\n let additionLineIndex = 0;\n for (const hunk of hunks) {\n const lines = hunk.split(SPLIT_WITH_NEWLINES);\n const firstLine = lines.shift();\n if (firstLine == null) {\n if (throwOnError) {\n throw Error('parsePatchContent: invalid hunk');\n } else {\n console.error('parsePatchContent: invalid hunk', hunk);\n }\n continue;\n }\n const fileHeaderMatch = firstLine.match(HUNK_HEADER);\n let additionLines = 0;\n let deletionLines = 0;\n // Setup currentFile, this should be the first iteration of our hunks, and\n // technically not a hunk\n if (fileHeaderMatch == null || currentFile == null) {\n if (currentFile != null) {\n if (throwOnError) {\n throw Error('parsePatchContent: Invalid hunk');\n } else {\n console.error('parsePatchContent: Invalid hunk', hunk);\n }\n continue;\n }\n currentFile = {\n name: '',\n type: 'change',\n hunks: [],\n splitLineCount: 0,\n unifiedLineCount: 0,\n isPartial,\n additionLines:\n !isPartial && oldFile != null && newFile != null\n ? newFile.contents.split(SPLIT_WITH_NEWLINES)\n : [],\n deletionLines:\n !isPartial && oldFile != null && newFile != null\n ? oldFile.contents.split(SPLIT_WITH_NEWLINES)\n : [],\n cacheKey,\n };\n // If either file is technically empty, then we should empty the\n // arrays respectively\n if (currentFile.additionLines.length === 1 && newFile?.contents === '') {\n currentFile.additionLines.length = 0;\n }\n if (currentFile.deletionLines.length === 1 && oldFile?.contents === '') {\n currentFile.deletionLines.length = 0;\n }\n\n // Push that first line back into the group of lines so we can properly\n // parse it out\n lines.unshift(firstLine);\n for (const line of lines) {\n const filenameMatch = line.match(\n isGitDiff ? FILENAME_HEADER_REGEX_GIT : FILENAME_HEADER_REGEX\n );\n if (line.startsWith('diff --git')) {\n const [, , prevName, , name] =\n line.trim().match(ALTERNATE_FILE_NAMES_GIT) ?? [];\n currentFile.name = name.trim();\n if (prevName !== name) {\n currentFile.prevName = prevName.trim();\n }\n } else if (filenameMatch != null) {\n const [, type, fileName] = filenameMatch;\n if (type === '---' && fileName !== '/dev/null') {\n currentFile.prevName = fileName.trim();\n currentFile.name = fileName.trim();\n } else if (type === '+++' && fileName !== '/dev/null') {\n currentFile.name = fileName.trim();\n }\n }\n // Git diffs have a bunch of additional metadata we can pull from\n else if (isGitDiff) {\n if (line.startsWith('new mode ')) {\n currentFile.mode = line.replace('new mode', '').trim();\n }\n if (line.startsWith('old mode ')) {\n currentFile.prevMode = line.replace('old mode', '').trim();\n }\n if (line.startsWith('new file mode')) {\n currentFile.type = 'new';\n currentFile.mode = line.replace('new file mode', '').trim();\n }\n if (line.startsWith('deleted file mode')) {\n currentFile.type = 'deleted';\n currentFile.mode = line.replace('deleted file mode', '').trim();\n }\n if (line.startsWith('similarity index')) {\n if (line.startsWith('similarity index 100%')) {\n currentFile.type = 'rename-pure';\n } else {\n currentFile.type = 'rename-changed';\n }\n }\n if (line.startsWith('index ')) {\n const [, prevObjectId, newObjectId, mode] =\n line.trim().match(INDEX_LINE_METADATA) ?? [];\n if (prevObjectId != null) {\n currentFile.prevObjectId = prevObjectId;\n }\n if (newObjectId != null) {\n currentFile.newObjectId = newObjectId;\n }\n if (mode != null) {\n currentFile.mode = mode;\n }\n }\n // We have to handle these for pure renames because there won't be\n // --- and +++ lines\n if (line.startsWith('rename from ')) {\n currentFile.prevName = line.replace('rename from ', '').trim();\n }\n if (line.startsWith('rename to ')) {\n currentFile.name = line.replace('rename to ', '').trim();\n }\n }\n }\n continue;\n }\n\n // Otherwise, time to start parsing out the hunk\n let currentContent: ContextContent | ChangeContent | undefined;\n let lastLineType: 'context' | 'addition' | 'deletion' | undefined;\n\n // Strip trailing bare newlines (format-patch separators between commits)\n // if needed\n while (\n lines.length > 0 &&\n (lines[lines.length - 1] === '\\n' ||\n lines[lines.length - 1] === '\\r' ||\n lines[lines.length - 1] === '\\r\\n' ||\n lines[lines.length - 1] === '')\n ) {\n lines.pop();\n }\n\n const additionStart = parseInt(fileHeaderMatch[3]);\n const deletionStart = parseInt(fileHeaderMatch[1]);\n deletionLineIndex = isPartial ? deletionLineIndex : deletionStart - 1;\n additionLineIndex = isPartial ? additionLineIndex : additionStart - 1;\n\n const hunkData: Hunk = {\n collapsedBefore: 0,\n\n splitLineCount: 0,\n splitLineStart: 0,\n\n unifiedLineCount: 0,\n unifiedLineStart: 0,\n\n additionCount: parseInt(fileHeaderMatch[4] ?? '1'),\n additionStart,\n additionLines,\n\n deletionCount: parseInt(fileHeaderMatch[2] ?? '1'),\n deletionStart,\n deletionLines,\n\n deletionLineIndex,\n additionLineIndex,\n\n hunkContent: [],\n hunkContext: fileHeaderMatch[5],\n hunkSpecs: firstLine,\n\n noEOFCRAdditions: false,\n noEOFCRDeletions: false,\n };\n\n // Lets validate out hunkData to ensure there's no broken data from the\n // regex\n if (\n isNaN(hunkData.additionCount) ||\n isNaN(hunkData.deletionCount) ||\n isNaN(hunkData.additionStart) ||\n isNaN(hunkData.deletionStart)\n ) {\n if (throwOnError) {\n throw Error('parsePatchContent: invalid hunk metadata');\n } else {\n console.error('parsePatchContent: invalid hunk metadata', hunkData);\n }\n continue;\n }\n\n // Now we process each line of the hunk\n for (const rawLine of lines) {\n const parsedLine = parseLineType(rawLine);\n // If we can't properly process the line, well, lets just try to salvage\n // things and continue... It's possible an AI generated diff might have\n // some stray blank lines or something in there\n if (parsedLine == null) {\n console.error('processFile: invalid rawLine:', rawLine);\n continue;\n }\n\n const { type, line } = parsedLine;\n if (type === 'addition') {\n if (currentContent == null || currentContent.type !== 'change') {\n currentContent = createContentGroup(\n 'change',\n deletionLineIndex,\n additionLineIndex\n );\n hunkData.hunkContent.push(currentContent);\n }\n additionLineIndex++;\n if (isPartial) {\n currentFile.additionLines.push(line);\n }\n currentContent.additions++;\n additionLines++;\n lastLineType = 'addition';\n } else if (type === 'deletion') {\n if (currentContent == null || currentContent.type !== 'change') {\n currentContent = createContentGroup(\n 'change',\n deletionLineIndex,\n additionLineIndex\n );\n hunkData.hunkContent.push(currentContent);\n }\n deletionLineIndex++;\n if (isPartial) {\n currentFile.deletionLines.push(line);\n }\n currentContent.deletions++;\n deletionLines++;\n lastLineType = 'deletion';\n } else if (type === 'context') {\n if (currentContent == null || currentContent.type !== 'context') {\n currentContent = createContentGroup(\n 'context',\n deletionLineIndex,\n additionLineIndex\n );\n hunkData.hunkContent.push(currentContent);\n }\n additionLineIndex++;\n deletionLineIndex++;\n if (isPartial) {\n currentFile.deletionLines.push(line);\n currentFile.additionLines.push(line);\n }\n currentContent.lines++;\n lastLineType = 'context';\n } else if (type === 'metadata' && currentContent != null) {\n if (currentContent.type === 'context') {\n hunkData.noEOFCRAdditions = true;\n hunkData.noEOFCRDeletions = true;\n } else if (lastLineType === 'deletion') {\n hunkData.noEOFCRDeletions = true;\n } else if (lastLineType === 'addition') {\n hunkData.noEOFCRAdditions = true;\n }\n // If we're dealing with partial content from a diff, we need to strip\n // newlines manually from the content\n if (\n isPartial &&\n (lastLineType === 'addition' || lastLineType === 'context')\n ) {\n const lastIndex = currentFile.additionLines.length - 1;\n if (lastIndex >= 0) {\n currentFile.additionLines[lastIndex] = cleanLastNewline(\n currentFile.additionLines[lastIndex]\n );\n }\n }\n if (\n isPartial &&\n (lastLineType === 'deletion' || lastLineType === 'context')\n ) {\n const lastIndex = currentFile.deletionLines.length - 1;\n if (lastIndex >= 0) {\n currentFile.deletionLines[lastIndex] = cleanLastNewline(\n currentFile.deletionLines[lastIndex]\n );\n }\n }\n }\n }\n\n hunkData.additionLines = additionLines;\n hunkData.deletionLines = deletionLines;\n\n hunkData.collapsedBefore = Math.max(\n hunkData.additionStart - 1 - lastHunkEnd,\n 0\n );\n currentFile.hunks.push(hunkData);\n lastHunkEnd = hunkData.additionStart + hunkData.additionCount - 1;\n for (const content of hunkData.hunkContent) {\n if (content.type === 'context') {\n hunkData.splitLineCount += content.lines;\n hunkData.unifiedLineCount += content.lines;\n } else {\n hunkData.splitLineCount += Math.max(\n content.additions,\n content.deletions\n );\n hunkData.unifiedLineCount += content.deletions + content.additions;\n }\n }\n hunkData.splitLineStart =\n currentFile.splitLineCount + hunkData.collapsedBefore;\n hunkData.unifiedLineStart =\n currentFile.unifiedLineCount + hunkData.collapsedBefore;\n\n currentFile.splitLineCount +=\n hunkData.collapsedBefore + hunkData.splitLineCount;\n currentFile.unifiedLineCount +=\n hunkData.collapsedBefore + hunkData.unifiedLineCount;\n }\n if (currentFile == null) {\n return undefined;\n }\n\n // Account for collapsed lines after the final hunk and increment the\n // split/unified counts properly\n if (\n currentFile.hunks.length > 0 &&\n !isPartial &&\n currentFile.additionLines.length > 0 &&\n currentFile.deletionLines.length > 0\n ) {\n const lastHunk = currentFile.hunks[currentFile.hunks.length - 1];\n const lastHunkEnd = lastHunk.additionStart + lastHunk.additionCount - 1;\n const totalFileLines = currentFile.additionLines.length;\n const collapsedAfter = Math.max(totalFileLines - lastHunkEnd, 0);\n currentFile.splitLineCount += collapsedAfter;\n currentFile.unifiedLineCount += collapsedAfter;\n }\n\n // If this isn't a git diff style patch, then we'll need to sus out some\n // additional metadata manually\n if (!isGitDiff) {\n if (\n currentFile.prevName != null &&\n currentFile.name !== currentFile.prevName\n ) {\n if (currentFile.hunks.length > 0) {\n currentFile.type = 'rename-changed';\n } else {\n currentFile.type = 'rename-pure';\n }\n }\n // Sort of a hack for detecting deleted/added files...\n else if (newFile != null && newFile.contents === '') {\n currentFile.type = 'deleted';\n } else if (oldFile != null && oldFile.contents === '') {\n currentFile.type = 'new';\n }\n }\n if (\n currentFile.type !== 'rename-pure' &&\n currentFile.type !== 'rename-changed'\n ) {\n currentFile.prevName = undefined;\n }\n return currentFile;\n}\n\n/**\n * Parses a patch file string into an array of parsed patches.\n *\n * @param data - The raw patch file content (supports multi-commit patches)\n * @param cacheKeyPrefix - Optional prefix for generating cache keys. When provided,\n * each file in the patch will get a cache key in the format `prefix-patchIndex-fileIndex`.\n * This enables caching of rendered diff results in the worker pool.\n */\nexport function parsePatchFiles(\n data: string,\n cacheKeyPrefix?: string,\n throwOnError = false\n): ParsedPatch[] {\n // NOTE(amadeus): This function is pretty forgiving in that it can accept a\n // patch file that includes commit metdata, multiple commits, or not\n const patches: ParsedPatch[] = [];\n for (const patch of data.split(COMMIT_METADATA_SPLIT)) {\n try {\n patches.push(\n processPatch(\n patch,\n cacheKeyPrefix != null\n ? `${cacheKeyPrefix}-${patches.length}`\n : undefined,\n throwOnError\n )\n );\n } catch (error) {\n if (throwOnError) {\n throw error;\n } else {\n console.error(error);\n }\n }\n }\n return patches;\n}\n\nfunction createContentGroup(\n type: 'change',\n deletionLineIndex: number,\n additionLineIndex: number\n): ChangeContent;\nfunction createContentGroup(\n type: 'context',\n deletionLineIndex: number,\n additionLineIndex: number\n): ContextContent;\nfunction createContentGroup(\n type: 'change' | 'context',\n deletionLineIndex: number,\n additionLineIndex: number\n): ChangeContent | ContextContent {\n if (type === 'change') {\n return {\n type: 'change',\n additions: 0,\n deletions: 0,\n additionLineIndex,\n deletionLineIndex,\n };\n }\n return {\n type: 'context',\n lines: 0,\n additionLineIndex,\n deletionLineIndex,\n };\n}\n"],"mappings":";;;;;AAuBA,SAAgB,aACd,MACA,gBACA,eAAe,OACF;CACb,MAAM,YAAY,0BAA0B,KAAK,KAAK;CACtD,MAAM,WAAW,KAAK,MACpB,YAAY,4BAA4B,8BACzC;CACD,IAAIA;CACJ,MAAMC,QAA4B,EAAE;AACpC,MAAK,MAAM,uBAAuB,UAAU;AAC1C,MAAI,aAAa,CAAC,0BAA0B,KAAK,oBAAoB,EAAE;AACrE,OAAI,iBAAiB,KACnB,iBAAgB;YAEZ,aACF,OAAM,MAAM,uCAAuC;OAEnD,SAAQ,MACN,yCACA,oBACD;AAKL;aAEA,CAAC,aACD,CAAC,8BAA8B,KAAK,oBAAoB,EACxD;AACA,OAAI,iBAAiB,KACnB,iBAAgB;YAEZ,aACF,OAAM,MAAM,uCAAuC;OAEnD,SAAQ,MACN,yCACA,oBACD;AAGL;;EAEF,MAAM,cAAc,YAAY,qBAAqB;GACnD,UACE,kBAAkB,OACd,GAAG,eAAe,GAAG,MAAM,WAC3B;GACN;GACA;GACD,CAAC;AACF,MAAI,eAAe,KACjB,OAAM,KAAK,YAAY;;AAG3B,QAAO;EAAE;EAAe;EAAO;;AAWjC,SAAgB,YACd,gBACA,EACE,UACA,YAAY,0BAA0B,KAAK,eAAe,EAC1D,SACA,SACA,eAAe,UACO,EAAE,EACI;CAC9B,IAAI,cAAc;CAClB,MAAM,QAAQ,eAAe,MAAM,kBAAkB;CACrD,IAAIC;CACJ,MAAM,YAAY,WAAW,QAAQ,WAAW;CAChD,IAAI,oBAAoB;CACxB,IAAI,oBAAoB;AACxB,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,QAAQ,KAAK,MAAM,oBAAoB;EAC7C,MAAM,YAAY,MAAM,OAAO;AAC/B,MAAI,aAAa,MAAM;AACrB,OAAI,aACF,OA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aACD,YAAY,cAAc,SAAS,KACnC,YAAY,cAAc,SAAS,GACnC;EACA,MAAM,WAAW,YAAY,MAAM,YAAY,MAAM,SAAS;EAC9D,MAAMC,gBAAc,SAAS,gBAAgB,SAAS,gBAAgB;EACtE,MAAM,iBAAiB,YAAY,cAAc;EACjD,MAAM,iBAAiB,KAAK,IAAI,iBAAiBA,eAAa,EAAE;AAChE,cAAY,kBAAkB;AAC9B,cAAY,oBAAoB;;AAKlC,KAAI,CAAC,WACH;MACE,YAAY,YAAY,QACxB,YAAY,SAAS,YAAY,SAEjC,KAAI,YAAY,MAAM,SAAS,EAC7B,aAAY,OAAO;MAEnB,aAAY,OAAO;WAId,WAAW,QAAQ,QAAQ,aAAa,GAC/C,aAAY,OAAO;WACV,WAAW,QAAQ,QAAQ,aAAa,GACjD,aAAY,OAAO;;AAGvB,KACE,YAAY,SAAS,iBACrB,YAAY,SAAS,iBAErB,aAAY,WAAW;AAEzB,QAAO;;;;;;;;;;AAWT,SAAgB,gBACd,MACA,gBACA,eAAe,OACA;CAGf,MAAMC,UAAyB,EAAE;AACjC,MAAK,MAAM,SAAS,KAAK,MAAM,sBAAsB,CACnD,KAAI;AACF,UAAQ,KACN,aACE,OACA,kBAAkB,OACd,GAAG,eAAe,GAAG,QAAQ,WAC7B,QACJ,aACD,CACF;UACM,OAAO;AACd,MAAI,aACF,OAAM;MAEN,SAAQ,MAAM,MAAM;;AAI1B,QAAO;;AAaT,SAAS,mBACP,MACA,mBACA,mBACgC;AAChC,KAAI,SAAS,SACX,QAAO;EACL,MAAM;EACN,WAAW;EACX,WAAW;EACX;EACA;EACD;AAEH,QAAO;EACL,MAAM;EACN,OAAO;EACP;EACA;EACD"}
|
|
@@ -20,10 +20,7 @@ function renderDiffWithHighlighter(diff, highlighter, options, { forcePlainText,
|
|
|
20
20
|
totalLines = Infinity;
|
|
21
21
|
}
|
|
22
22
|
const isWindowedHighlight = startingLine > 0 || totalLines < Infinity;
|
|
23
|
-
const baseThemeType = (
|
|
24
|
-
const theme = options.theme ?? DEFAULT_THEMES;
|
|
25
|
-
if (typeof theme === "string") return highlighter.getTheme(theme).type;
|
|
26
|
-
})();
|
|
23
|
+
const baseThemeType = typeof options.theme === "string" ? highlighter.getTheme(options.theme).type : void 0;
|
|
27
24
|
const themeStyles = getHighlighterThemeStyles({
|
|
28
25
|
theme: options.theme,
|
|
29
26
|
highlighter
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderDiffWithHighlighter.js","names":["DEFAULT_PLAIN_TEXT_OPTIONS: ForceDiffPlainTextOptions","code: RenderDiffFilesResult","deletionSpans: [0 | 1, string][]","additionSpans: [0 | 1, string][]","hastConfig: CodeToHastOptions<DiffsThemeNames>"],"sources":["../../src/utils/renderDiffWithHighlighter.ts"],"sourcesContent":["import { diffChars, diffWordsWithSpace } from 'diff';\n\nimport {\n DEFAULT_COLLAPSED_CONTEXT_THRESHOLD,\n DEFAULT_THEMES,\n} from '../constants';\nimport type {\n CodeToHastOptions,\n DecorationItem,\n DiffsHighlighter,\n DiffsThemeNames,\n FileContents,\n FileDiffMetadata,\n ForceDiffPlainTextOptions,\n LineDiffTypes,\n LineInfo,\n RenderDiffFilesResult,\n RenderDiffOptions,\n SupportedLanguages,\n ThemedDiffResult,\n} from '../types';\nimport { cleanLastNewline } from './cleanLastNewline';\nimport { createTransformerWithState } from './createTransformerWithState';\nimport { formatCSSVariablePrefix } from './formatCSSVariablePrefix';\nimport { getFiletypeFromFileName } from './getFiletypeFromFileName';\nimport { getHighlighterThemeStyles } from './getHighlighterThemeStyles';\nimport { getLineNodes } from './getLineNodes';\nimport { iterateOverDiff } from './iterateOverDiff';\nimport {\n createDiffSpanDecoration,\n pushOrJoinSpan,\n} from './parseDiffDecorations';\n\nconst DEFAULT_PLAIN_TEXT_OPTIONS: ForceDiffPlainTextOptions = {\n forcePlainText: false,\n};\n\nexport function renderDiffWithHighlighter(\n diff: FileDiffMetadata,\n highlighter: DiffsHighlighter,\n options: RenderDiffOptions,\n {\n forcePlainText,\n startingLine,\n totalLines,\n expandedHunks,\n collapsedContextThreshold = DEFAULT_COLLAPSED_CONTEXT_THRESHOLD,\n }: ForceDiffPlainTextOptions = DEFAULT_PLAIN_TEXT_OPTIONS\n): ThemedDiffResult {\n if (forcePlainText) {\n startingLine ??= 0;\n totalLines ??= Infinity;\n } else {\n // If we aren't forcing plain text, then we intentionally do not support\n // ranges for highlighting as that could break the syntax highlighting, we\n // we override any values that may have been passed in. Maybe one day we\n // warn about this?\n startingLine = 0;\n totalLines = Infinity;\n }\n const isWindowedHighlight = startingLine > 0 || totalLines < Infinity;\n const baseThemeType = (() => {\n const theme = options.theme ?? DEFAULT_THEMES;\n if (typeof theme === 'string') {\n return highlighter.getTheme(theme).type;\n }\n return undefined;\n })();\n const themeStyles = getHighlighterThemeStyles({\n theme: options.theme,\n highlighter,\n });\n\n // If we have a large file and we are rendering the WHOLE plain diff ast,\n // then we should remove the lineDiffType to make sure things render quickly.\n // For highlighted ASTs or windowed highlights, we should just inherit the\n // setting\n const lineDiffType =\n forcePlainText &&\n !isWindowedHighlight &&\n (diff.unifiedLineCount > 1000 || diff.splitLineCount > 1000)\n ? 'none'\n : options.lineDiffType;\n\n const code: RenderDiffFilesResult = {\n deletionLines: [],\n additionLines: [],\n };\n\n const shouldGroupAll = !forcePlainText && !diff.isPartial;\n const expandedHunksForIteration = forcePlainText ? expandedHunks : undefined;\n const buckets = new Map<number, RenderBucket>();\n function getBucketForHunk(hunkIndex: number) {\n const index = shouldGroupAll ? 0 : hunkIndex;\n const bucket = buckets.get(index) ?? createBucket();\n buckets.set(index, bucket);\n return bucket;\n }\n\n function appendContent(\n lineContent: string,\n lineIndex: number,\n segments: HighlightSegment[],\n contentWrapper: FakeArrayType\n ) {\n if (isWindowedHighlight) {\n let segment = segments.at(-1);\n if (\n segment == null ||\n segment.targetIndex + segment.count !== lineIndex\n ) {\n segment = {\n targetIndex: lineIndex,\n originalOffset: contentWrapper.length,\n count: 0,\n };\n segments.push(segment);\n }\n segment.count++;\n }\n contentWrapper.push(lineContent);\n }\n\n iterateOverDiff({\n diff,\n diffStyle: 'both',\n startingLine,\n totalLines,\n expandedHunks: isWindowedHighlight ? expandedHunksForIteration : true,\n collapsedContextThreshold,\n callback: ({ hunkIndex, additionLine, deletionLine, type }) => {\n const bucket = getBucketForHunk(hunkIndex);\n const splitLineIndex =\n additionLine != null\n ? additionLine.splitLineIndex\n : deletionLine.splitLineIndex;\n\n if (type === 'change' && additionLine != null && deletionLine != null) {\n computeLineDiffDecorations({\n additionLine: diff.additionLines[additionLine.lineIndex],\n deletionLine: diff.deletionLines[deletionLine.lineIndex],\n deletionLineIndex: bucket.deletionContent.length,\n additionLineIndex: bucket.additionContent.length,\n deletionDecorations: bucket.deletionDecorations,\n additionDecorations: bucket.additionDecorations,\n lineDiffType,\n });\n }\n\n if (deletionLine != null) {\n appendContent(\n diff.deletionLines[deletionLine.lineIndex],\n deletionLine.lineIndex,\n bucket.deletionSegments,\n bucket.deletionContent\n );\n bucket.deletionInfo.push({\n type: type === 'change' ? 'change-deletion' : type,\n lineNumber: deletionLine.lineNumber,\n altLineNumber:\n type === 'change'\n ? undefined\n : (additionLine.lineNumber ?? undefined),\n lineIndex: `${deletionLine.unifiedLineIndex},${splitLineIndex}`,\n });\n }\n\n if (additionLine != null) {\n appendContent(\n diff.additionLines[additionLine.lineIndex],\n additionLine.lineIndex,\n bucket.additionSegments,\n bucket.additionContent\n );\n bucket.additionInfo.push({\n type: type === 'change' ? 'change-addition' : type,\n lineNumber: additionLine.lineNumber,\n altLineNumber:\n type === 'change'\n ? undefined\n : (deletionLine.lineNumber ?? undefined),\n lineIndex: `${additionLine.unifiedLineIndex},${splitLineIndex}`,\n });\n }\n },\n });\n\n for (const bucket of buckets.values()) {\n if (\n bucket.deletionContent.length === 0 &&\n bucket.additionContent.length === 0\n ) {\n continue;\n }\n\n const deletionFile = {\n name: diff.prevName ?? diff.name,\n contents: bucket.deletionContent.value,\n };\n const additionFile = {\n name: diff.name,\n contents: bucket.additionContent.value,\n };\n const { deletionLines, additionLines } = renderTwoFiles({\n deletionFile,\n deletionInfo: bucket.deletionInfo,\n deletionDecorations: bucket.deletionDecorations,\n\n additionFile,\n additionInfo: bucket.additionInfo,\n additionDecorations: bucket.additionDecorations,\n\n highlighter,\n options,\n languageOverride: forcePlainText ? 'text' : diff.lang,\n });\n\n if (shouldGroupAll) {\n code.deletionLines = deletionLines;\n code.additionLines = additionLines;\n continue;\n }\n\n if (bucket.deletionSegments.length > 0) {\n for (const seg of bucket.deletionSegments) {\n for (let i = 0; i < seg.count; i++) {\n code.deletionLines[seg.targetIndex + i] =\n deletionLines[seg.originalOffset + i];\n }\n }\n } else {\n code.deletionLines.push(...deletionLines);\n }\n if (bucket.additionSegments.length > 0) {\n for (const seg of bucket.additionSegments) {\n for (let i = 0; i < seg.count; i++) {\n code.additionLines[seg.targetIndex + i] =\n additionLines[seg.originalOffset + i];\n }\n }\n } else {\n code.additionLines.push(...additionLines);\n }\n }\n\n return { code, themeStyles, baseThemeType };\n}\n\ninterface ProcessLineDiffProps {\n deletionLine: string | undefined;\n additionLine: string | undefined;\n deletionLineIndex: number;\n additionLineIndex: number;\n deletionDecorations: DecorationItem[];\n additionDecorations: DecorationItem[];\n lineDiffType: LineDiffTypes;\n}\n\nfunction computeLineDiffDecorations({\n deletionLine,\n additionLine,\n deletionLineIndex,\n additionLineIndex,\n deletionDecorations,\n additionDecorations,\n lineDiffType,\n}: ProcessLineDiffProps) {\n if (deletionLine == null || additionLine == null || lineDiffType === 'none') {\n return;\n }\n deletionLine = cleanLastNewline(deletionLine);\n additionLine = cleanLastNewline(additionLine);\n // NOTE(amadeus): Because we visually trim trailing newlines when rendering,\n // we also gotta make sure the diff parsing doesn't include the newline\n // character that could be there...\n const lineDiff =\n lineDiffType === 'char'\n ? diffChars(deletionLine, additionLine)\n : diffWordsWithSpace(deletionLine, additionLine);\n const deletionSpans: [0 | 1, string][] = [];\n const additionSpans: [0 | 1, string][] = [];\n const enableJoin = lineDiffType === 'word-alt';\n const lastItem = lineDiff.at(-1);\n for (const item of lineDiff) {\n const isLastItem = item === lastItem;\n if (!item.added && !item.removed) {\n pushOrJoinSpan({\n item,\n arr: deletionSpans,\n enableJoin,\n isNeutral: true,\n isLastItem,\n });\n pushOrJoinSpan({\n item,\n arr: additionSpans,\n enableJoin,\n isNeutral: true,\n isLastItem,\n });\n } else if (item.removed) {\n pushOrJoinSpan({ item, arr: deletionSpans, enableJoin, isLastItem });\n } else {\n pushOrJoinSpan({ item, arr: additionSpans, enableJoin, isLastItem });\n }\n }\n let spanIndex = 0;\n for (const span of deletionSpans) {\n if (span[0] === 1) {\n deletionDecorations.push(\n createDiffSpanDecoration({\n line: deletionLineIndex,\n spanStart: spanIndex,\n spanLength: span[1].length,\n })\n );\n }\n spanIndex += span[1].length;\n }\n spanIndex = 0;\n for (const span of additionSpans) {\n if (span[0] === 1) {\n additionDecorations.push(\n createDiffSpanDecoration({\n line: additionLineIndex,\n spanStart: spanIndex,\n spanLength: span[1].length,\n })\n );\n }\n spanIndex += span[1].length;\n }\n}\n\ninterface HighlightSegment {\n // The where the highlighted region starts\n originalOffset: number;\n // Where to place the highlighted line in RenderDiffFilesResult\n targetIndex: number;\n // Number of highlighted lines\n count: number;\n}\n\ninterface FakeArrayType {\n push(value: string): void;\n value: string;\n length: number;\n}\n\ninterface RenderBucket {\n deletionContent: FakeArrayType;\n additionContent: FakeArrayType;\n deletionInfo: (LineInfo | undefined)[];\n additionInfo: (LineInfo | undefined)[];\n deletionDecorations: DecorationItem[];\n additionDecorations: DecorationItem[];\n deletionSegments: HighlightSegment[];\n additionSegments: HighlightSegment[];\n}\n\nfunction createBucket(): RenderBucket {\n return {\n deletionContent: {\n push(value: string) {\n this.value += value;\n this.length++;\n },\n value: '',\n length: 0,\n },\n additionContent: {\n push(value: string) {\n this.value += value;\n this.length++;\n },\n value: '',\n length: 0,\n },\n deletionInfo: [],\n additionInfo: [],\n deletionDecorations: [],\n additionDecorations: [],\n deletionSegments: [],\n additionSegments: [],\n };\n}\n\ninterface RenderTwoFilesProps {\n deletionFile: FileContents;\n additionFile: FileContents;\n deletionInfo: (LineInfo | undefined)[];\n additionInfo: (LineInfo | undefined)[];\n deletionDecorations: DecorationItem[];\n additionDecorations: DecorationItem[];\n options: RenderDiffOptions;\n highlighter: DiffsHighlighter;\n languageOverride: SupportedLanguages | undefined;\n}\n\nfunction renderTwoFiles({\n deletionFile,\n additionFile,\n deletionInfo,\n additionInfo,\n highlighter,\n deletionDecorations,\n additionDecorations,\n languageOverride,\n options: { theme: themeOrThemes = DEFAULT_THEMES, ...options },\n}: RenderTwoFilesProps): RenderDiffFilesResult {\n const deletionLang =\n languageOverride ?? getFiletypeFromFileName(deletionFile.name);\n const additionLang =\n languageOverride ?? getFiletypeFromFileName(additionFile.name);\n const { state, transformers } = createTransformerWithState();\n const hastConfig: CodeToHastOptions<DiffsThemeNames> = (() => {\n return typeof themeOrThemes === 'string'\n ? {\n ...options,\n // language will be overwritten for each highlight\n lang: 'text',\n theme: themeOrThemes,\n transformers,\n decorations: undefined,\n defaultColor: false,\n cssVariablePrefix: formatCSSVariablePrefix('token'),\n }\n : {\n ...options,\n // language will be overwritten for each highlight\n lang: 'text',\n themes: themeOrThemes,\n transformers,\n decorations: undefined,\n defaultColor: false,\n cssVariablePrefix: formatCSSVariablePrefix('token'),\n };\n })();\n\n const deletionLines = (() => {\n if (deletionFile.contents === '') {\n return [];\n }\n hastConfig.lang = deletionLang;\n state.lineInfo = deletionInfo;\n hastConfig.decorations = deletionDecorations;\n return getLineNodes(\n highlighter.codeToHast(\n cleanLastNewline(deletionFile.contents),\n hastConfig\n )\n );\n })();\n const additionLines = (() => {\n if (additionFile.contents === '') {\n return [];\n }\n hastConfig.lang = additionLang;\n hastConfig.decorations = additionDecorations;\n state.lineInfo = additionInfo;\n return getLineNodes(\n highlighter.codeToHast(\n cleanLastNewline(additionFile.contents),\n hastConfig\n )\n );\n })();\n\n return { deletionL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AmB,wBAAwB,QAAQ;GACpD,GACD;GACE,GAAG;GAEH,MAAM;GACN,QAAQ;GACR;GACA,aAAa;GACb,cAAc;GACd,mBAAmB,wBAAwB,QAAQ;GACpD;KACH;AA+BJ,QAAO;EAAE,sBA7BoB;AAC3B,OAAI,aAAa,aAAa,GAC5B,QAAO,EAAE;AAEX,cAAW,OAAO;AAClB,SAAM,WAAW;AACjB,cAAW,cAAc;AACzB,UAAO,aACL,YAAY,WACV,iBAAiB,aAAa,SAAS,EACvC,WACD,CACF;MACC;EAgBoB,sBAfK;AAC3B,OAAI,aAAa,aAAa,GAC5B,QAAO,EAAE;AAEX,cAAW,OAAO;AAClB,cAAW,cAAc;AACzB,SAAM,WAAW;AACjB,UAAO,aACL,YAAY,WACV,iBAAiB,aAAa,SAAS,EACvC,WACD,CACF;MACC;EAEmC"}
|
|
1
|
+
{"version":3,"file":"renderDiffWithHighlighter.js","names":["DEFAULT_PLAIN_TEXT_OPTIONS: ForceDiffPlainTextOptions","code: RenderDiffFilesResult","deletionSpans: [0 | 1, string][]","additionSpans: [0 | 1, string][]","hastConfig: CodeToHastOptions<DiffsThemeNames>"],"sources":["../../src/utils/renderDiffWithHighlighter.ts"],"sourcesContent":["import { diffChars, diffWordsWithSpace } from 'diff';\n\nimport {\n DEFAULT_COLLAPSED_CONTEXT_THRESHOLD,\n DEFAULT_THEMES,\n} from '../constants';\nimport type {\n CodeToHastOptions,\n DecorationItem,\n DiffsHighlighter,\n DiffsThemeNames,\n FileContents,\n FileDiffMetadata,\n ForceDiffPlainTextOptions,\n LineDiffTypes,\n LineInfo,\n RenderDiffFilesResult,\n RenderDiffOptions,\n SupportedLanguages,\n ThemedDiffResult,\n} from '../types';\nimport { cleanLastNewline } from './cleanLastNewline';\nimport { createTransformerWithState } from './createTransformerWithState';\nimport { formatCSSVariablePrefix } from './formatCSSVariablePrefix';\nimport { getFiletypeFromFileName } from './getFiletypeFromFileName';\nimport { getHighlighterThemeStyles } from './getHighlighterThemeStyles';\nimport { getLineNodes } from './getLineNodes';\nimport { iterateOverDiff } from './iterateOverDiff';\nimport {\n createDiffSpanDecoration,\n pushOrJoinSpan,\n} from './parseDiffDecorations';\n\nconst DEFAULT_PLAIN_TEXT_OPTIONS: ForceDiffPlainTextOptions = {\n forcePlainText: false,\n};\n\nexport function renderDiffWithHighlighter(\n diff: FileDiffMetadata,\n highlighter: DiffsHighlighter,\n options: RenderDiffOptions,\n {\n forcePlainText,\n startingLine,\n totalLines,\n expandedHunks,\n collapsedContextThreshold = DEFAULT_COLLAPSED_CONTEXT_THRESHOLD,\n }: ForceDiffPlainTextOptions = DEFAULT_PLAIN_TEXT_OPTIONS\n): ThemedDiffResult {\n if (forcePlainText) {\n startingLine ??= 0;\n totalLines ??= Infinity;\n } else {\n // If we aren't forcing plain text, then we intentionally do not support\n // ranges for highlighting as that could break the syntax highlighting, we\n // we override any values that may have been passed in. Maybe one day we\n // warn about this?\n startingLine = 0;\n totalLines = Infinity;\n }\n const isWindowedHighlight = startingLine > 0 || totalLines < Infinity;\n const baseThemeType =\n typeof options.theme === 'string'\n ? highlighter.getTheme(options.theme).type\n : undefined;\n const themeStyles = getHighlighterThemeStyles({\n theme: options.theme,\n highlighter,\n });\n\n // If we have a large file and we are rendering the WHOLE plain diff ast,\n // then we should remove the lineDiffType to make sure things render quickly.\n // For highlighted ASTs or windowed highlights, we should just inherit the\n // setting\n const lineDiffType =\n forcePlainText &&\n !isWindowedHighlight &&\n (diff.unifiedLineCount > 1000 || diff.splitLineCount > 1000)\n ? 'none'\n : options.lineDiffType;\n\n const code: RenderDiffFilesResult = {\n deletionLines: [],\n additionLines: [],\n };\n\n const shouldGroupAll = !forcePlainText && !diff.isPartial;\n const expandedHunksForIteration = forcePlainText ? expandedHunks : undefined;\n const buckets = new Map<number, RenderBucket>();\n function getBucketForHunk(hunkIndex: number) {\n const index = shouldGroupAll ? 0 : hunkIndex;\n const bucket = buckets.get(index) ?? createBucket();\n buckets.set(index, bucket);\n return bucket;\n }\n\n function appendContent(\n lineContent: string,\n lineIndex: number,\n segments: HighlightSegment[],\n contentWrapper: FakeArrayType\n ) {\n if (isWindowedHighlight) {\n let segment = segments.at(-1);\n if (\n segment == null ||\n segment.targetIndex + segment.count !== lineIndex\n ) {\n segment = {\n targetIndex: lineIndex,\n originalOffset: contentWrapper.length,\n count: 0,\n };\n segments.push(segment);\n }\n segment.count++;\n }\n contentWrapper.push(lineContent);\n }\n\n iterateOverDiff({\n diff,\n diffStyle: 'both',\n startingLine,\n totalLines,\n expandedHunks: isWindowedHighlight ? expandedHunksForIteration : true,\n collapsedContextThreshold,\n callback: ({ hunkIndex, additionLine, deletionLine, type }) => {\n const bucket = getBucketForHunk(hunkIndex);\n const splitLineIndex =\n additionLine != null\n ? additionLine.splitLineIndex\n : deletionLine.splitLineIndex;\n\n if (type === 'change' && additionLine != null && deletionLine != null) {\n computeLineDiffDecorations({\n additionLine: diff.additionLines[additionLine.lineIndex],\n deletionLine: diff.deletionLines[deletionLine.lineIndex],\n deletionLineIndex: bucket.deletionContent.length,\n additionLineIndex: bucket.additionContent.length,\n deletionDecorations: bucket.deletionDecorations,\n additionDecorations: bucket.additionDecorations,\n lineDiffType,\n });\n }\n\n if (deletionLine != null) {\n appendContent(\n diff.deletionLines[deletionLine.lineIndex],\n deletionLine.lineIndex,\n bucket.deletionSegments,\n bucket.deletionContent\n );\n bucket.deletionInfo.push({\n type: type === 'change' ? 'change-deletion' : type,\n lineNumber: deletionLine.lineNumber,\n altLineNumber:\n type === 'change'\n ? undefined\n : (additionLine.lineNumber ?? undefined),\n lineIndex: `${deletionLine.unifiedLineIndex},${splitLineIndex}`,\n });\n }\n\n if (additionLine != null) {\n appendContent(\n diff.additionLines[additionLine.lineIndex],\n additionLine.lineIndex,\n bucket.additionSegments,\n bucket.additionContent\n );\n bucket.additionInfo.push({\n type: type === 'change' ? 'change-addition' : type,\n lineNumber: additionLine.lineNumber,\n altLineNumber:\n type === 'change'\n ? undefined\n : (deletionLine.lineNumber ?? undefined),\n lineIndex: `${additionLine.unifiedLineIndex},${splitLineIndex}`,\n });\n }\n },\n });\n\n for (const bucket of buckets.values()) {\n if (\n bucket.deletionContent.length === 0 &&\n bucket.additionContent.length === 0\n ) {\n continue;\n }\n\n const deletionFile = {\n name: diff.prevName ?? diff.name,\n contents: bucket.deletionContent.value,\n };\n const additionFile = {\n name: diff.name,\n contents: bucket.additionContent.value,\n };\n const { deletionLines, additionLines } = renderTwoFiles({\n deletionFile,\n deletionInfo: bucket.deletionInfo,\n deletionDecorations: bucket.deletionDecorations,\n\n additionFile,\n additionInfo: bucket.additionInfo,\n additionDecorations: bucket.additionDecorations,\n\n highlighter,\n options,\n languageOverride: forcePlainText ? 'text' : diff.lang,\n });\n\n if (shouldGroupAll) {\n code.deletionLines = deletionLines;\n code.additionLines = additionLines;\n continue;\n }\n\n if (bucket.deletionSegments.length > 0) {\n for (const seg of bucket.deletionSegments) {\n for (let i = 0; i < seg.count; i++) {\n code.deletionLines[seg.targetIndex + i] =\n deletionLines[seg.originalOffset + i];\n }\n }\n } else {\n code.deletionLines.push(...deletionLines);\n }\n if (bucket.additionSegments.length > 0) {\n for (const seg of bucket.additionSegments) {\n for (let i = 0; i < seg.count; i++) {\n code.additionLines[seg.targetIndex + i] =\n additionLines[seg.originalOffset + i];\n }\n }\n } else {\n code.additionLines.push(...additionLines);\n }\n }\n\n return { code, themeStyles, baseThemeType };\n}\n\ninterface ProcessLineDiffProps {\n deletionLine: string | undefined;\n additionLine: string | undefined;\n deletionLineIndex: number;\n additionLineIndex: number;\n deletionDecorations: DecorationItem[];\n additionDecorations: DecorationItem[];\n lineDiffType: LineDiffTypes;\n}\n\nfunction computeLineDiffDecorations({\n deletionLine,\n additionLine,\n deletionLineIndex,\n additionLineIndex,\n deletionDecorations,\n additionDecorations,\n lineDiffType,\n}: ProcessLineDiffProps) {\n if (deletionLine == null || additionLine == null || lineDiffType === 'none') {\n return;\n }\n deletionLine = cleanLastNewline(deletionLine);\n additionLine = cleanLastNewline(additionLine);\n // NOTE(amadeus): Because we visually trim trailing newlines when rendering,\n // we also gotta make sure the diff parsing doesn't include the newline\n // character that could be there...\n const lineDiff =\n lineDiffType === 'char'\n ? diffChars(deletionLine, additionLine)\n : diffWordsWithSpace(deletionLine, additionLine);\n const deletionSpans: [0 | 1, string][] = [];\n const additionSpans: [0 | 1, string][] = [];\n const enableJoin = lineDiffType === 'word-alt';\n const lastItem = lineDiff.at(-1);\n for (const item of lineDiff) {\n const isLastItem = item === lastItem;\n if (!item.added && !item.removed) {\n pushOrJoinSpan({\n item,\n arr: deletionSpans,\n enableJoin,\n isNeutral: true,\n isLastItem,\n });\n pushOrJoinSpan({\n item,\n arr: additionSpans,\n enableJoin,\n isNeutral: true,\n isLastItem,\n });\n } else if (item.removed) {\n pushOrJoinSpan({ item, arr: deletionSpans, enableJoin, isLastItem });\n } else {\n pushOrJoinSpan({ item, arr: additionSpans, enableJoin, isLastItem });\n }\n }\n let spanIndex = 0;\n for (const span of deletionSpans) {\n if (span[0] === 1) {\n deletionDecorations.push(\n createDiffSpanDecoration({\n line: deletionLineIndex,\n spanStart: spanIndex,\n spanLength: span[1].length,\n })\n );\n }\n spanIndex += span[1].length;\n }\n spanIndex = 0;\n for (const span of additionSpans) {\n if (span[0] === 1) {\n additionDecorations.push(\n createDiffSpanDecoration({\n line: additionLineIndex,\n spanStart: spanIndex,\n spanLength: span[1].length,\n })\n );\n }\n spanIndex += span[1].length;\n }\n}\n\ninterface HighlightSegment {\n // The where the highlighted region starts\n originalOffset: number;\n // Where to place the highlighted line in RenderDiffFilesResult\n targetIndex: number;\n // Number of highlighted lines\n count: number;\n}\n\ninterface FakeArrayType {\n push(value: string): void;\n value: string;\n length: number;\n}\n\ninterface RenderBucket {\n deletionContent: FakeArrayType;\n additionContent: FakeArrayType;\n deletionInfo: (LineInfo | undefined)[];\n additionInfo: (LineInfo | undefined)[];\n deletionDecorations: DecorationItem[];\n additionDecorations: DecorationItem[];\n deletionSegments: HighlightSegment[];\n additionSegments: HighlightSegment[];\n}\n\nfunction createBucket(): RenderBucket {\n return {\n deletionContent: {\n push(value: string) {\n this.value += value;\n this.length++;\n },\n value: '',\n length: 0,\n },\n additionContent: {\n push(value: string) {\n this.value += value;\n this.length++;\n },\n value: '',\n length: 0,\n },\n deletionInfo: [],\n additionInfo: [],\n deletionDecorations: [],\n additionDecorations: [],\n deletionSegments: [],\n additionSegments: [],\n };\n}\n\ninterface RenderTwoFilesProps {\n deletionFile: FileContents;\n additionFile: FileContents;\n deletionInfo: (LineInfo | undefined)[];\n additionInfo: (LineInfo | undefined)[];\n deletionDecorations: DecorationItem[];\n additionDecorations: DecorationItem[];\n options: RenderDiffOptions;\n highlighter: DiffsHighlighter;\n languageOverride: SupportedLanguages | undefined;\n}\n\nfunction renderTwoFiles({\n deletionFile,\n additionFile,\n deletionInfo,\n additionInfo,\n highlighter,\n deletionDecorations,\n additionDecorations,\n languageOverride,\n options: { theme: themeOrThemes = DEFAULT_THEMES, ...options },\n}: RenderTwoFilesProps): RenderDiffFilesResult {\n const deletionLang =\n languageOverride ?? getFiletypeFromFileName(deletionFile.name);\n const additionLang =\n languageOverride ?? getFiletypeFromFileName(additionFile.name);\n const { state, transformers } = createTransformerWithState();\n const hastConfig: CodeToHastOptions<DiffsThemeNames> = (() => {\n return typeof themeOrThemes === 'string'\n ? {\n ...options,\n // language will be overwritten for each highlight\n lang: 'text',\n theme: themeOrThemes,\n transformers,\n decorations: undefined,\n defaultColor: false,\n cssVariablePrefix: formatCSSVariablePrefix('token'),\n }\n : {\n ...options,\n // language will be overwritten for each highlight\n lang: 'text',\n themes: themeOrThemes,\n transformers,\n decorations: undefined,\n defaultColor: false,\n cssVariablePrefix: formatCSSVariablePrefix('token'),\n };\n })();\n\n const deletionLines = (() => {\n if (deletionFile.contents === '') {\n return [];\n }\n hastConfig.lang = deletionLang;\n state.lineInfo = deletionInfo;\n hastConfig.decorations = deletionDecorations;\n return getLineNodes(\n highlighter.codeToHast(\n cleanLastNewline(deletionFile.contents),\n hastConfig\n )\n );\n })();\n const additionLines = (() => {\n if (additionFile.contents === '') {\n return [];\n }\n hastConfig.lang = additionLang;\n hastConfig.decorations = additionDecorations;\n state.lineInfo = additionInfo;\n return getLineNodes(\n highlighter.codeToHast(\n cleanLastNewline(additionFile.contents),\n hastConfig\n )\n );\n })();\n\n return { deletionLines, additionLines };\n}\n"],"mappings":";;;;;;;;;;;;AAiCA,MAAMA,6BAAwD,EAC5D,gBAAgB,OACjB;AAED,SAAgB,0BACd,MACA,aACA,SACA,EACE,gBACA,cACA,YACA,eACA,4BAA4B,wCACC,4BACb;AAClB,KAAI,gBAAgB;AAClB,mBAAiB;AACjB,iBAAe;QACV;AAKL,iBAAe;AACf,eAAa;;CAEf,MAAM,sBAAsB,eAAe,KAAK,aAAa;CAC7D,MAAM,gBACJ,OAAO,QAAQ,UAAU,WACrB,YAAY,SAAS,QAAQ,MAAM,CAAC,OACpC;CACN,MAAM,cAAc,0BAA0B;EAC5C,OAAO,QAAQ;EACf;EACD,CAAC;CAMF,MAAM,eACJ,kBACA,CAAC,wBACA,KAAK,mBAAmB,OAAQ,KAAK,iBAAiB,OACnD,SACA,QAAQ;CAEd,MAAMC,OAA8B;EAClC,eAAe,EAAE;EACjB,eAAe,EAAE;EAClB;CAED,MAAM,iBAAiB,CAAC,kBAAkB,CAAC,KAAK;CAChD,MAAM,4BAA4B,iBAAiB,gBAAgB;CACnE,MAAM,0BAAU,IAAI,KAA2B;CAC/C,SAAS,iBAAiB,WAAmB;EAC3C,MAAM,QAAQ,iBAAiB,IAAI;EACnC,MAAM,SAAS,QAAQ,IAAI,MAAM,IAAI,cAAc;AACnD,UAAQ,IAAI,OAAO,OAAO;AAC1B,SAAO;;CAGT,SAAS,cACP,aACA,WACA,UACA,gBACA;AACA,MAAI,qBAAqB;GACvB,IAAI,UAAU,SAAS,GAAG,GAAG;AAC7B,OACE,WAAW,QACX,QAAQ,cAAc,QAAQ,UAAU,WACxC;AACA,cAAU;KACR,aAA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,KAAK;CAChE,MAAM,EAAE,OAAO,iBAAiB,4BAA4B;CAC5D,MAAMC,oBAAwD;AAC5D,SAAO,OAAO,kBAAkB,WAC5B;GACE,GAAG;GAEH,MAAM;GACN,OAAO;GACP;GACA,aAAa;GACb,cAAc;GACd,mBAAmB,wBAAwB,QAAQ;GACpD,GACD;GACE,GAAG;GAEH,MAAM;GACN,QAAQ;GACR;GACA,aAAa;GACb,cAAc;GACd,mBAAmB,wBAAwB,QAAQ;GACpD;KACH;AA+BJ,QAAO;EAAE,sBA7BoB;AAC3B,OAAI,aAAa,aAAa,GAC5B,QAAO,EAAE;AAEX,cAAW,OAAO;AAClB,SAAM,WAAW;AACjB,cAAW,cAAc;AACzB,UAAO,aACL,YAAY,WACV,iBAAiB,aAAa,SAAS,EACvC,WACD,CACF;MACC;EAgBoB,sBAfK;AAC3B,OAAI,aAAa,aAAa,GAC5B,QAAO,EAAE;AAEX,cAAW,OAAO;AAClB,cAAW,cAAc;AACzB,SAAM,WAAW;AACjB,UAAO,aACL,YAAY,WACV,iBAAiB,aAAa,SAAS,EACvC,WACD,CACF;MACC;EAEmC"}
|
|
@@ -21,9 +21,7 @@ function renderFileWithHighlighter(file, highlighter, { theme = DEFAULT_THEMES,
|
|
|
21
21
|
const isWindowedHighlight = startingLine > 0 || totalLines < Infinity;
|
|
22
22
|
const { state, transformers } = createTransformerWithState();
|
|
23
23
|
const lang = forcePlainText ? "text" : file.lang ?? getFiletypeFromFileName(file.name);
|
|
24
|
-
const baseThemeType = (
|
|
25
|
-
if (typeof theme === "string") return highlighter.getTheme(theme).type;
|
|
26
|
-
})();
|
|
24
|
+
const baseThemeType = typeof theme === "string" ? highlighter.getTheme(theme).type : void 0;
|
|
27
25
|
const themeStyles = getHighlighterThemeStyles({
|
|
28
26
|
theme,
|
|
29
27
|
highlighter
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderFileWithHighlighter.js","names":["DEFAULT_PLAIN_TEXT_OPTIONS: ForceFilePlainTextOptions","hastConfig: CodeToHastOptions<DiffsThemeNames>","windowContent: string"],"sources":["../../src/utils/renderFileWithHighlighter.ts"],"sourcesContent":["import { DEFAULT_THEMES } from '../constants';\nimport type {\n CodeToHastOptions,\n DiffsHighlighter,\n DiffsThemeNames,\n FileContents,\n ForceFilePlainTextOptions,\n RenderFileOptions,\n ThemedFileResult,\n} from '../types';\nimport { cleanLastNewline } from './cleanLastNewline';\nimport { createTransformerWithState } from './createTransformerWithState';\nimport { formatCSSVariablePrefix } from './formatCSSVariablePrefix';\nimport { getFiletypeFromFileName } from './getFiletypeFromFileName';\nimport { getHighlighterThemeStyles } from './getHighlighterThemeStyles';\nimport { getLineNodes } from './getLineNodes';\nimport { iterateOverFile } from './iterateOverFile';\nimport { splitFileContents } from './splitFileContents';\n\nconst DEFAULT_PLAIN_TEXT_OPTIONS: ForceFilePlainTextOptions = {\n forcePlainText: false,\n};\n\nexport function renderFileWithHighlighter(\n file: FileContents,\n highlighter: DiffsHighlighter,\n { theme = DEFAULT_THEMES, tokenizeMaxLineLength }: RenderFileOptions,\n {\n forcePlainText,\n startingLine,\n totalLines,\n lines,\n }: ForceFilePlainTextOptions = DEFAULT_PLAIN_TEXT_OPTIONS\n): ThemedFileResult {\n if (forcePlainText) {\n startingLine ??= 0;\n totalLines ??= Infinity;\n } else {\n // If we aren't forcing plain text, then we intentionally do not support\n // ranges for highlighting as that could break the syntax highlighting, we\n // we override any values that may have been passed in. Maybe one day we\n // warn about this?\n startingLine = 0;\n totalLines = Infinity;\n }\n const isWindowedHighlight = startingLine > 0 || totalLines < Infinity;\n const { state, transformers } = createTransformerWithState();\n const lang = forcePlainText\n ? 'text'\n : (file.lang ?? getFiletypeFromFileName(file.name));\n const baseThemeType
|
|
1
|
+
{"version":3,"file":"renderFileWithHighlighter.js","names":["DEFAULT_PLAIN_TEXT_OPTIONS: ForceFilePlainTextOptions","hastConfig: CodeToHastOptions<DiffsThemeNames>","windowContent: string"],"sources":["../../src/utils/renderFileWithHighlighter.ts"],"sourcesContent":["import { DEFAULT_THEMES } from '../constants';\nimport type {\n CodeToHastOptions,\n DiffsHighlighter,\n DiffsThemeNames,\n FileContents,\n ForceFilePlainTextOptions,\n RenderFileOptions,\n ThemedFileResult,\n} from '../types';\nimport { cleanLastNewline } from './cleanLastNewline';\nimport { createTransformerWithState } from './createTransformerWithState';\nimport { formatCSSVariablePrefix } from './formatCSSVariablePrefix';\nimport { getFiletypeFromFileName } from './getFiletypeFromFileName';\nimport { getHighlighterThemeStyles } from './getHighlighterThemeStyles';\nimport { getLineNodes } from './getLineNodes';\nimport { iterateOverFile } from './iterateOverFile';\nimport { splitFileContents } from './splitFileContents';\n\nconst DEFAULT_PLAIN_TEXT_OPTIONS: ForceFilePlainTextOptions = {\n forcePlainText: false,\n};\n\nexport function renderFileWithHighlighter(\n file: FileContents,\n highlighter: DiffsHighlighter,\n { theme = DEFAULT_THEMES, tokenizeMaxLineLength }: RenderFileOptions,\n {\n forcePlainText,\n startingLine,\n totalLines,\n lines,\n }: ForceFilePlainTextOptions = DEFAULT_PLAIN_TEXT_OPTIONS\n): ThemedFileResult {\n if (forcePlainText) {\n startingLine ??= 0;\n totalLines ??= Infinity;\n } else {\n // If we aren't forcing plain text, then we intentionally do not support\n // ranges for highlighting as that could break the syntax highlighting, we\n // we override any values that may have been passed in. Maybe one day we\n // warn about this?\n startingLine = 0;\n totalLines = Infinity;\n }\n const isWindowedHighlight = startingLine > 0 || totalLines < Infinity;\n const { state, transformers } = createTransformerWithState();\n const lang = forcePlainText\n ? 'text'\n : (file.lang ?? getFiletypeFromFileName(file.name));\n const baseThemeType =\n typeof theme === 'string' ? highlighter.getTheme(theme).type : undefined;\n const themeStyles = getHighlighterThemeStyles({\n theme,\n highlighter,\n });\n state.lineInfo = (shikiLineNumber: number) => ({\n type: 'context',\n lineIndex: shikiLineNumber - 1 + startingLine,\n lineNumber: shikiLineNumber + startingLine,\n });\n const hastConfig: CodeToHastOptions<DiffsThemeNames> = (() => {\n if (typeof theme === 'string') {\n return {\n lang,\n theme,\n transformers,\n defaultColor: false,\n cssVariablePrefix: formatCSSVariablePrefix('token'),\n tokenizeMaxLineLength,\n };\n }\n return {\n lang,\n themes: theme,\n transformers,\n defaultColor: false,\n cssVariablePrefix: formatCSSVariablePrefix('token'),\n tokenizeMaxLineLength,\n };\n })();\n const highlightedLines = getLineNodes(\n highlighter.codeToHast(\n isWindowedHighlight\n ? extractWindowedFileContent(\n lines ?? splitFileContents(file.contents),\n startingLine,\n totalLines\n )\n : cleanLastNewline(file.contents),\n hastConfig\n )\n );\n\n // Create sparse array for windowed rendering\n const code = isWindowedHighlight ? new Array(startingLine) : highlightedLines;\n if (isWindowedHighlight) {\n code.push(...highlightedLines);\n }\n\n return { code, themeStyles, baseThemeType };\n}\n\nfunction extractWindowedFileContent(\n lines: string[],\n startingLine: number,\n totalLines: number\n): string {\n let windowContent: string = '';\n iterateOverFile({\n lines,\n startingLine,\n totalLines,\n callback({ content }) {\n windowContent += content;\n },\n });\n return windowContent;\n}\n"],"mappings":";;;;;;;;;;;AAmBA,MAAMA,6BAAwD,EAC5D,gBAAgB,OACjB;AAED,SAAgB,0BACd,MACA,aACA,EAAE,QAAQ,gBAAgB,yBAC1B,EACE,gBACA,cACA,YACA,UAC6B,4BACb;AAClB,KAAI,gBAAgB;AAClB,mBAAiB;AACjB,iBAAe;QACV;AAKL,iBAAe;AACf,eAAa;;CAEf,MAAM,sBAAsB,eAAe,KAAK,aAAa;CAC7D,MAAM,EAAE,OAAO,iBAAiB,4BAA4B;CAC5D,MAAM,OAAO,iBACT,SACC,KAAK,QAAQ,wBAAwB,KAAK,KAAK;CACpD,MAAM,gBACJ,OAAO,UAAU,WAAW,YAAY,SAAS,MAAM,CAAC,OAAO;CACjE,MAAM,cAAc,0BAA0B;EAC5C;EACA;EACD,CAAC;AACF,OAAM,YAAY,qBAA6B;EAC7C,MAAM;EACN,WAAW,kBAAkB,IAAI;EACjC,YAAY,kBAAkB;EAC/B;CACD,MAAMC,oBAAwD;AAC5D,MAAI,OAAO,UAAU,SACnB,QAAO;GACL;GACA;GACA;GACA,cAAc;GACd,mBAAmB,wBAAwB,QAAQ;GACnD;GACD;AAEH,SAAO;GACL;GACA,QAAQ;GACR;GACA,cAAc;GACd,mBAAmB,wBAAwB,QAAQ;GACnD;GACD;KACC;CACJ,MAAM,mBAAmB,aACvB,YAAY,WACV,sBACI,2BACE,SAAS,kBAAkB,KAAK,SAAS,EACzC,cACA,WACD,GACD,iBAAiB,KAAK,SAAS,EACnC,WACD,CACF;CAGD,MAAM,OAAO,sBAAsB,IAAI,MAAM,aAAa,GAAG;AAC7D,KAAI,oBACF,MAAK,KAAK,GAAG,iBAAiB;AAGhC,QAAO;EAAE;EAAM;EAAa;EAAe;;AAG7C,SAAS,2BACP,OACA,cACA,YACQ;CACR,IAAIC,gBAAwB;AAC5B,iBAAgB;EACd;EACA;EACA;EACA,SAAS,EAAE,WAAW;AACpB,oBAAiB;;EAEpB,CAAC;AACF,QAAO"}
|
|
@@ -29,14 +29,9 @@ function resolveRegion(diff, target) {
|
|
|
29
29
|
unifiedLineCount: 0
|
|
30
30
|
};
|
|
31
31
|
const updatesEOFState = hunkIndex === hunks.length - 1 && endContentIndex === currentHunk.hunkContent.length - 1;
|
|
32
|
+
const shouldProcessCollapsedContext = !diff.isPartial;
|
|
32
33
|
for (const [index, hunk] of hunks.entries()) {
|
|
33
|
-
|
|
34
|
-
cursor.nextAdditionLineIndex += hunk.collapsedBefore;
|
|
35
|
-
cursor.nextDeletionLineIndex += hunk.collapsedBefore;
|
|
36
|
-
cursor.nextAdditionStart += hunk.collapsedBefore;
|
|
37
|
-
cursor.nextDeletionStart += hunk.collapsedBefore;
|
|
38
|
-
cursor.splitLineCount += hunk.collapsedBefore;
|
|
39
|
-
cursor.unifiedLineCount += hunk.collapsedBefore;
|
|
34
|
+
processCollapsedContext(diff, resolvedDiff, cursor, hunk.deletionLineIndex - hunk.collapsedBefore, hunk.additionLineIndex - hunk.collapsedBefore, hunk.collapsedBefore, shouldProcessCollapsedContext);
|
|
40
35
|
const newHunk = {
|
|
41
36
|
...hunk,
|
|
42
37
|
hunkContent: [],
|
|
@@ -110,6 +105,18 @@ function pushCollapsedContextLines(diff, deletionLines, additionLines, deletionL
|
|
|
110
105
|
diff.additionLines.push(additionLine);
|
|
111
106
|
}
|
|
112
107
|
}
|
|
108
|
+
function processCollapsedContext(sourceDiff, resolvedDiff, cursor, deletionLineIndex, additionLineIndex, lineCount, shouldProcessContent) {
|
|
109
|
+
if (lineCount <= 0) return;
|
|
110
|
+
if (shouldProcessContent) {
|
|
111
|
+
pushCollapsedContextLines(resolvedDiff, sourceDiff.deletionLines, sourceDiff.additionLines, deletionLineIndex, additionLineIndex, lineCount);
|
|
112
|
+
cursor.nextAdditionLineIndex += lineCount;
|
|
113
|
+
cursor.nextDeletionLineIndex += lineCount;
|
|
114
|
+
}
|
|
115
|
+
cursor.nextAdditionStart += lineCount;
|
|
116
|
+
cursor.nextDeletionStart += lineCount;
|
|
117
|
+
cursor.splitLineCount += lineCount;
|
|
118
|
+
cursor.unifiedLineCount += lineCount;
|
|
119
|
+
}
|
|
113
120
|
function pushContentLinesToDiff(content, diff, deletionLines, additionLines) {
|
|
114
121
|
if (content.type === "context") for (let i = 0; i < content.lines; i++) {
|
|
115
122
|
const line = additionLines[content.additionLineIndex + i];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveRegion.js","names":["resolvedDiff: FileDiffMetadata","cursor: CursorState","newHunk: Hunk","newContent: ContextContent"],"sources":["../../src/utils/resolveRegion.ts"],"sourcesContent":["import type {\n ChangeContent,\n ContextContent,\n FileDiffMetadata,\n Hunk,\n} from '../types';\n\ninterface RegionResolutionTarget {\n hunkIndex: number;\n startContentIndex: number;\n endContentIndex: number;\n resolution: 'deletions' | 'additions' | 'both';\n indexesToDelete?: Set<number>;\n}\n\ninterface CursorState {\n nextAdditionLineIndex: number;\n nextDeletionLineIndex: number;\n nextAdditionStart: number;\n nextDeletionStart: number;\n splitLineCount: number;\n unifiedLineCount: number;\n}\n\nexport function resolveRegion(\n diff: FileDiffMetadata,\n target: RegionResolutionTarget\n): FileDiffMetadata {\n const {\n resolution,\n hunkIndex,\n startContentIndex,\n endContentIndex,\n indexesToDelete = new Set(),\n } = target;\n const currentHunk = diff.hunks[hunkIndex];\n if (currentHunk == null) {\n console.error({ diff, hunkIndex });\n throw new Error(`resolveRegion: Invalid hunk index: ${hunkIndex}`);\n }\n\n if (\n startContentIndex < 0 ||\n endContentIndex >= currentHunk.hunkContent.length ||\n startContentIndex > endContentIndex\n ) {\n throw new Error(\n `resolveRegion: Invalid content range, ${startContentIndex}, ${endContentIndex}`\n );\n }\n\n const { hunks, additionLines, deletionLines } = diff;\n const resolvedDiff: FileDiffMetadata = {\n ...diff,\n hunks: [],\n deletionLines: [],\n additionLines: [],\n splitLineCount: 0,\n unifiedLineCount: 0,\n cacheKey:\n diff.cacheKey != null\n ? `${diff.cacheKey}:${resolution[0]}-${hunkIndex}:${startContentIndex}-${endContentIndex}`\n : undefined,\n };\n\n const cursor: CursorState = {\n nextAdditionLineIndex: 0,\n nextDeletionLineIndex: 0,\n nextAdditionStart: 1,\n nextDeletionStart: 1,\n splitLineCount: 0,\n unifiedLineCount: 0,\n };\n const updatesEOFState =\n hunkIndex === hunks.length - 1 &&\n endContentIndex === currentHunk.hunkContent.length - 1;\n\n for (const [index, hunk] of hunks.entries()) {\n pushCollapsedContextLines(\n resolvedDiff,\n deletionLines,\n additionLines,\n hunk.deletionLineIndex - hunk.collapsedBefore,\n hunk.additionLineIndex - hunk.collapsedBefore,\n hunk.collapsedBefore\n );\n cursor.nextAdditionLineIndex += hunk.collapsedBefore;\n cursor.nextDeletionLineIndex += hunk.collapsedBefore;\n cursor.nextAdditionStart += hunk.collapsedBefore;\n cursor.nextDeletionStart += hunk.collapsedBefore;\n cursor.splitLineCount += hunk.collapsedBefore;\n cursor.unifiedLineCount += hunk.collapsedBefore;\n\n const newHunk: Hunk = {\n ...hunk,\n hunkContent: [],\n additionStart: cursor.nextAdditionStart,\n deletionStart: cursor.nextDeletionStart,\n additionLineIndex: cursor.nextAdditionLineIndex,\n deletionLineIndex: cursor.nextDeletionLineIndex,\n additionCount: 0,\n deletionCount: 0,\n deletionLines: 0,\n additionLines: 0,\n splitLineStart: cursor.splitLineCount,\n unifiedLineStart: cursor.unifiedLineCount,\n splitLineCount: 0,\n unifiedLineCount: 0,\n };\n\n for (const [contentIndex, content] of hunk.hunkContent.entries()) {\n // If we are outside of the targeted hunk or content region\n if (\n index !== hunkIndex ||\n contentIndex < startContentIndex ||\n contentIndex > endContentIndex\n ) {\n pushContentLinesToDiff(\n content,\n resolvedDiff,\n deletionLines,\n additionLines\n );\n const newContent = {\n ...content,\n additionLineIndex: cursor.nextAdditionLineIndex,\n deletionLineIndex: cursor.nextDeletionLineIndex,\n };\n newHunk.hunkContent.push(newContent);\n advanceCursor(newContent, cursor, newHunk);\n }\n // If we are at an index to delete, replace with an empty context node\n else if (indexesToDelete.has(contentIndex)) {\n newHunk.hunkContent.push({\n type: 'context',\n lines: 0,\n deletionLineIndex: cursor.nextDeletionLineIndex,\n additionLineIndex: cursor.nextAdditionLineIndex,\n });\n }\n // There's nothing to `resolve` with context nodes, so just push them as\n // they are\n else if (content.type === 'context') {\n pushContentLinesToDiff(\n content,\n resolvedDiff,\n deletionLines,\n additionLines\n );\n const newContent: ContextContent = {\n ...content,\n deletionLineIndex: cursor.nextDeletionLineIndex,\n additionLineIndex: cursor.nextAdditionLineIndex,\n };\n newHunk.hunkContent.push(newContent);\n advanceCursor(newContent, cursor, newHunk);\n }\n // Looks like we have a change to resolve and push\n else {\n pushResolveLinesToDiff(\n resolution,\n content,\n resolvedDiff,\n deletionLines,\n additionLines\n );\n const newContent: ContextContent = {\n type: 'context',\n lines:\n resolution === 'deletions'\n ? content.deletions\n : resolution === 'additions'\n ? content.additions\n : content.deletions + content.additions,\n deletionLineIndex: cursor.nextDeletionLineIndex,\n additionLineIndex: cursor.nextAdditionLineIndex,\n };\n newHunk.hunkContent.push(newContent);\n advanceCursor(newContent, cursor, newHunk);\n }\n }\n\n if (index === hunkIndex && updatesEOFState) {\n const noEOFCR =\n resolution === 'deletions'\n ? hunk.noEOFCRDeletions\n : hunk.noEOFCRAdditions;\n newHunk.noEOFCRAdditions = noEOFCR;\n newHunk.noEOFCRDeletions = noEOFCR;\n }\n\n resolvedDiff.hunks.push(newHunk);\n }\n\n const finalHunk = hunks.at(-1);\n if (finalHunk != null && !diff.isPartial) {\n pushCollapsedContextLines(\n resolvedDiff,\n deletionLines,\n additionLines,\n finalHunk.deletionLineIndex + finalHunk.deletionCount,\n finalHunk.additionLineIndex + finalHunk.additionCount,\n Math.min(\n deletionLines.length -\n (finalHunk.deletionLineIndex + finalHunk.deletionCount),\n additionLines.length -\n (finalHunk.additionLineIndex + finalHunk.additionCount)\n )\n );\n }\n\n resolvedDiff.splitLineCount = cursor.splitLineCount;\n resolvedDiff.unifiedLineCount = cursor.unifiedLineCount;\n\n return resolvedDiff;\n}\n\nfunction pushCollapsedContextLines(\n diff: FileDiffMetadata,\n deletionLines: string[],\n additionLines: string[],\n deletionLineIndex: number,\n additionLineIndex: number,\n lineCount: number\n) {\n for (let index = 0; index < lineCount; index++) {\n const deletionLine = deletionLines[deletionLineIndex + index];\n const additionLine = additionLines[additionLineIndex + index];\n if (deletionLine == null || additionLine == null) {\n throw new Error(\n 'pushCollapsedContextLines: missing collapsed context line'\n );\n }\n diff.deletionLines.push(deletionLine);\n diff.additionLines.push(additionLine);\n }\n}\n\nfunction pushContentLinesToDiff(\n content: ContextContent | ChangeContent,\n diff: FileDiffMetadata,\n deletionLines: string[],\n additionLines: string[]\n) {\n if (content.type === 'context') {\n for (let i = 0; i < content.lines; i++) {\n const line = additionLines[content.additionLineIndex + i];\n if (line == null) {\n console.error({ additionLines, content, i });\n throw new Error('pushContentLinesToDiff: Context line does not exist');\n }\n diff.deletionLines.push(line);\n diff.additionLines.push(line);\n }\n } else {\n const len = Math.max(content.deletions, content.additions);\n for (let i = 0; i < len; i++) {\n if (i < content.deletions) {\n const line = deletionLines[content.deletionLineIndex + i];\n if (line == null) {\n console.error({ deletionLines, content, i });\n throw new Error(\n 'pushContentLinesToDiff: Deletion line does not exist'\n );\n }\n diff.deletionLines.push(line);\n }\n if (i < content.additions) {\n const line = additionLines[content.additionLineIndex + i];\n if (line == null) {\n console.error({ additionLines, content, i });\n throw new Error(\n 'pushContentLinesToDiff: Addition line does not exist'\n );\n }\n diff.additionLines.push(line);\n }\n }\n }\n}\n\nfunction pushResolveLinesToDiff(\n resolution: 'deletions' | 'additions' | 'both',\n content: ChangeContent,\n diff: FileDiffMetadata,\n deletionLines: string[],\n additionLines: string[]\n) {\n if (resolution === 'deletions' || resolution === 'both') {\n for (let i = 0; i < content.deletions; i++) {\n const line = deletionLines[content.deletionLineIndex + i];\n if (line == null) {\n console.error({ deletionLines, content, i });\n throw new Error('pushResolveLinesToDiff: Deletion line does not exist');\n }\n diff.deletionLines.push(line);\n diff.additionLines.push(line);\n }\n }\n if (resolution === 'additions' || resolution === 'both') {\n for (let i = 0; i < content.additions; i++) {\n const line = additionLines[content.additionLineIndex + i];\n if (line == null) {\n console.error({ additionLines, content, i });\n throw new Error('pushResolveLinesToDiff: Addition line does not exist');\n }\n diff.deletionLines.push(line);\n diff.additionLines.push(line);\n }\n }\n}\n\nfunction advanceCursor(\n content: ChangeContent | ContextContent,\n cursor: CursorState,\n hunk: Hunk\n) {\n if (content.type === 'context') {\n cursor.nextAdditionLineIndex += content.lines;\n cursor.nextDeletionLineIndex += content.lines;\n cursor.nextAdditionStart += content.lines;\n cursor.nextDeletionStart += content.lines;\n cursor.splitLineCount += content.lines;\n cursor.unifiedLineCount += content.lines;\n\n hunk.additionCount += content.lines;\n hunk.deletionCount += content.lines;\n hunk.splitLineCount += content.lines;\n hunk.unifiedLineCount += content.lines;\n } else {\n cursor.nextAdditionLineIndex += content.additions;\n cursor.nextDeletionLineIndex += content.deletions;\n cursor.nextAdditionStart += content.additions;\n cursor.nextDeletionStart += content.deletions;\n cursor.splitLineCount += Math.max(content.deletions, content.additions);\n cursor.unifiedLineCount += content.deletions + content.additions;\n\n hunk.deletionCount += content.deletions;\n hunk.deletionLines += content.deletions;\n hunk.additionCount += content.additions;\n hunk.additionLines += content.additions;\n hunk.splitLineCount += Math.max(content.deletions, content.additions);\n hunk.unifiedLineCount += content.deletions + content.additions;\n }\n}\n"],"mappings":";AAwBA,SAAgB,cACd,MACA,QACkB;CAClB,MAAM,EACJ,YACA,WACA,mBACA,iBACA,kCAAkB,IAAI,KAAK,KACzB;CACJ,MAAM,cAAc,KAAK,MAAM;AAC/B,KAAI,eAAe,MAAM;AACvB,UAAQ,MAAM;GAAE;GAAM;GAAW,CAAC;AAClC,QAAM,IAAI,MAAM,sCAAsC,YAAY;;AAGpE,KACE,oBAAoB,KACpB,mBAAmB,YAAY,YAAY,UAC3C,oBAAoB,gBAEpB,OAAM,IAAI,MACR,yCAAyC,kBAAkB,IAAI,kBAChE;CAGH,MAAM,EAAE,OAAO,eAAe,kBAAkB;CAChD,MAAMA,eAAiC;EACrC,GAAG;EACH,OAAO,EAAE;EACT,eAAe,EAAE;EACjB,eAAe,EAAE;EACjB,gBAAgB;EAChB,kBAAkB;EAClB,UACE,KAAK,YAAY,OACb,GAAG,KAAK,SAAS,GAAG,WAAW,GAAG,GAAG,UAAU,GAAG,kBAAkB,GAAG,oBACvE;EACP;CAED,MAAMC,SAAsB;EAC1B,uBAAuB;EACvB,uBAAuB;EACvB,mBAAmB;EACnB,mBAAmB;EACnB,gBAAgB;EAChB,kBAAkB;EACnB;CACD,MAAM,kBACJ,cAAc,MAAM,SAAS,KAC7B,oBAAoB,YAAY,YAAY,SAAS;AAEvD,MAAK,MAAM,CAAC,OAAO,SAAS,MAAM,SAAS,EAAE;AAC3C,4BACE,cACA,eACA,eACA,KAAK,oBAAoB,KAAK,iBAC9B,KAAK,oBAAoB,KAAK,iBAC9B,KAAK,g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QAAQ;AACpC,SAAO,qBAAqB,QAAQ;AACpC,SAAO,kBAAkB,QAAQ;AACjC,SAAO,oBAAoB,QAAQ;AAEnC,OAAK,iBAAiB,QAAQ;AAC9B,OAAK,iBAAiB,QAAQ;AAC9B,OAAK,kBAAkB,QAAQ;AAC/B,OAAK,oBAAoB,QAAQ;QAC5B;AACL,SAAO,yBAAyB,QAAQ;AACxC,SAAO,yBAAyB,QAAQ;AACxC,SAAO,qBAAqB,QAAQ;AACpC,SAAO,qBAAqB,QAAQ;AACpC,SAAO,kBAAkB,KAAK,IAAI,QAAQ,WAAW,QAAQ,UAAU;AACvE,SAAO,oBAAoB,QAAQ,YAAY,QAAQ;AAEvD,OAAK,iBAAiB,QAAQ;AAC9B,OAAK,iBAAiB,QAAQ;AAC9B,OAAK,iBAAiB,QAAQ;AAC9B,OAAK,iBAAiB,QAAQ;AAC9B,OAAK,kBAAkB,KAAK,IAAI,QAAQ,WAAW,QAAQ,UAAU;AACrE,OAAK,oBAAoB,QAAQ,YAAY,QAAQ"}
|
|
1
|
+
{"version":3,"file":"resolveRegion.js","names":["resolvedDiff: FileDiffMetadata","cursor: CursorState","newHunk: Hunk","newContent: ContextContent"],"sources":["../../src/utils/resolveRegion.ts"],"sourcesContent":["import type {\n ChangeContent,\n ContextContent,\n FileDiffMetadata,\n Hunk,\n} from '../types';\n\ninterface RegionResolutionTarget {\n hunkIndex: number;\n startContentIndex: number;\n endContentIndex: number;\n resolution: 'deletions' | 'additions' | 'both';\n indexesToDelete?: Set<number>;\n}\n\ninterface CursorState {\n nextAdditionLineIndex: number;\n nextDeletionLineIndex: number;\n nextAdditionStart: number;\n nextDeletionStart: number;\n splitLineCount: number;\n unifiedLineCount: number;\n}\n\nexport function resolveRegion(\n diff: FileDiffMetadata,\n target: RegionResolutionTarget\n): FileDiffMetadata {\n const {\n resolution,\n hunkIndex,\n startContentIndex,\n endContentIndex,\n indexesToDelete = new Set(),\n } = target;\n const currentHunk = diff.hunks[hunkIndex];\n if (currentHunk == null) {\n console.error({ diff, hunkIndex });\n throw new Error(`resolveRegion: Invalid hunk index: ${hunkIndex}`);\n }\n\n if (\n startContentIndex < 0 ||\n endContentIndex >= currentHunk.hunkContent.length ||\n startContentIndex > endContentIndex\n ) {\n throw new Error(\n `resolveRegion: Invalid content range, ${startContentIndex}, ${endContentIndex}`\n );\n }\n\n const { hunks, additionLines, deletionLines } = diff;\n const resolvedDiff: FileDiffMetadata = {\n ...diff,\n hunks: [],\n deletionLines: [],\n additionLines: [],\n splitLineCount: 0,\n unifiedLineCount: 0,\n cacheKey:\n diff.cacheKey != null\n ? `${diff.cacheKey}:${resolution[0]}-${hunkIndex}:${startContentIndex}-${endContentIndex}`\n : undefined,\n };\n\n const cursor: CursorState = {\n nextAdditionLineIndex: 0,\n nextDeletionLineIndex: 0,\n nextAdditionStart: 1,\n nextDeletionStart: 1,\n splitLineCount: 0,\n unifiedLineCount: 0,\n };\n const updatesEOFState =\n hunkIndex === hunks.length - 1 &&\n endContentIndex === currentHunk.hunkContent.length - 1;\n const shouldProcessCollapsedContext = !diff.isPartial;\n\n for (const [index, hunk] of hunks.entries()) {\n processCollapsedContext(\n diff,\n resolvedDiff,\n cursor,\n hunk.deletionLineIndex - hunk.collapsedBefore,\n hunk.additionLineIndex - hunk.collapsedBefore,\n hunk.collapsedBefore,\n shouldProcessCollapsedContext\n );\n\n const newHunk: Hunk = {\n ...hunk,\n hunkContent: [],\n additionStart: cursor.nextAdditionStart,\n deletionStart: cursor.nextDeletionStart,\n additionLineIndex: cursor.nextAdditionLineIndex,\n deletionLineIndex: cursor.nextDeletionLineIndex,\n additionCount: 0,\n deletionCount: 0,\n deletionLines: 0,\n additionLines: 0,\n splitLineStart: cursor.splitLineCount,\n unifiedLineStart: cursor.unifiedLineCount,\n splitLineCount: 0,\n unifiedLineCount: 0,\n };\n\n for (const [contentIndex, content] of hunk.hunkContent.entries()) {\n // If we are outside of the targeted hunk or content region\n if (\n index !== hunkIndex ||\n contentIndex < startContentIndex ||\n contentIndex > endContentIndex\n ) {\n pushContentLinesToDiff(\n content,\n resolvedDiff,\n deletionLines,\n additionLines\n );\n const newContent = {\n ...content,\n additionLineIndex: cursor.nextAdditionLineIndex,\n deletionLineIndex: cursor.nextDeletionLineIndex,\n };\n newHunk.hunkContent.push(newContent);\n advanceCursor(newContent, cursor, newHunk);\n }\n // If we are at an index to delete, replace with an empty context node\n else if (indexesToDelete.has(contentIndex)) {\n newHunk.hunkContent.push({\n type: 'context',\n lines: 0,\n deletionLineIndex: cursor.nextDeletionLineIndex,\n additionLineIndex: cursor.nextAdditionLineIndex,\n });\n }\n // There's nothing to `resolve` with context nodes, so just push them as\n // they are\n else if (content.type === 'context') {\n pushContentLinesToDiff(\n content,\n resolvedDiff,\n deletionLines,\n additionLines\n );\n const newContent: ContextContent = {\n ...content,\n deletionLineIndex: cursor.nextDeletionLineIndex,\n additionLineIndex: cursor.nextAdditionLineIndex,\n };\n newHunk.hunkContent.push(newContent);\n advanceCursor(newContent, cursor, newHunk);\n }\n // Looks like we have a change to resolve and push\n else {\n pushResolveLinesToDiff(\n resolution,\n content,\n resolvedDiff,\n deletionLines,\n additionLines\n );\n const newContent: ContextContent = {\n type: 'context',\n lines:\n resolution === 'deletions'\n ? content.deletions\n : resolution === 'additions'\n ? content.additions\n : content.deletions + content.additions,\n deletionLineIndex: cursor.nextDeletionLineIndex,\n additionLineIndex: cursor.nextAdditionLineIndex,\n };\n newHunk.hunkContent.push(newContent);\n advanceCursor(newContent, cursor, newHunk);\n }\n }\n\n if (index === hunkIndex && updatesEOFState) {\n const noEOFCR =\n resolution === 'deletions'\n ? hunk.noEOFCRDeletions\n : hunk.noEOFCRAdditions;\n newHunk.noEOFCRAdditions = noEOFCR;\n newHunk.noEOFCRDeletions = noEOFCR;\n }\n\n resolvedDiff.hunks.push(newHunk);\n }\n\n const finalHunk = hunks.at(-1);\n if (finalHunk != null && !diff.isPartial) {\n pushCollapsedContextLines(\n resolvedDiff,\n deletionLines,\n additionLines,\n finalHunk.deletionLineIndex + finalHunk.deletionCount,\n finalHunk.additionLineIndex + finalHunk.additionCount,\n Math.min(\n deletionLines.length -\n (finalHunk.deletionLineIndex + finalHunk.deletionCount),\n additionLines.length -\n (finalHunk.additionLineIndex + finalHunk.additionCount)\n )\n );\n }\n\n resolvedDiff.splitLineCount = cursor.splitLineCount;\n resolvedDiff.unifiedLineCount = cursor.unifiedLineCount;\n\n return resolvedDiff;\n}\n\nfunction pushCollapsedContextLines(\n diff: FileDiffMetadata,\n deletionLines: string[],\n additionLines: string[],\n deletionLineIndex: number,\n additionLineIndex: number,\n lineCount: number\n) {\n for (let index = 0; index < lineCount; index++) {\n const deletionLine = deletionLines[deletionLineIndex + index];\n const additionLine = additionLines[additionLineIndex + index];\n if (deletionLine == null || additionLine == null) {\n throw new Error(\n 'pushCollapsedContextLines: missing collapsed context line'\n );\n }\n diff.deletionLines.push(deletionLine);\n diff.additionLines.push(additionLine);\n }\n}\n\n// Partial patches track omitted context in `collapsedBefore`, but those lines do\n// not exist in the diff's line arrays. Keep the virtual row counts and file\n// positions in sync without inventing hidden lines.\nfunction processCollapsedContext(\n sourceDiff: FileDiffMetadata,\n resolvedDiff: FileDiffMetadata,\n cursor: CursorState,\n deletionLineIndex: number,\n additionLineIndex: number,\n lineCount: number,\n shouldProcessContent: boolean\n) {\n if (lineCount <= 0) {\n return;\n }\n\n if (shouldProcessContent) {\n pushCollapsedContextLines(\n resolvedDiff,\n sourceDiff.deletionLines,\n sourceDiff.additionLines,\n deletionLineIndex,\n additionLineIndex,\n lineCount\n );\n cursor.nextAdditionLineIndex += lineCount;\n cursor.nextDeletionLineIndex += lineCount;\n }\n\n cursor.nextAdditionStart += lineCount;\n cursor.nextDeletionStart += lineCount;\n cursor.splitLineCount += lineCount;\n cursor.unifiedLineCount += lineCount;\n}\n\nfunction pushContentLinesToDiff(\n content: ContextContent | ChangeContent,\n diff: FileDiffMetadata,\n deletionLines: string[],\n additionLines: string[]\n) {\n if (content.type === 'context') {\n for (let i = 0; i < content.lines; i++) {\n const line = additionLines[content.additionLineIndex + i];\n if (line == null) {\n console.error({ additionLines, content, i });\n throw new Error('pushContentLinesToDiff: Context line does not exist');\n }\n diff.deletionLines.push(line);\n diff.additionLines.push(line);\n }\n } else {\n const len = Math.max(content.deletions, content.additions);\n for (let i = 0; i < len; i++) {\n if (i < content.deletions) {\n const line = deletionLines[content.deletionLineIndex + i];\n if (line == null) {\n console.error({ deletionLines, content, i });\n throw new Error(\n 'pushContentLinesToDiff: Deletion line does not exist'\n );\n }\n diff.deletionLines.push(line);\n }\n if (i < content.additions) {\n const line = additionLines[content.additionLineIndex + i];\n if (line == null) {\n console.error({ additionLines, content, i });\n throw new Error(\n 'pushContentLinesToDiff: Addition line does not exist'\n );\n }\n diff.additionLines.push(line);\n }\n }\n }\n}\n\nfunction pushResolveLinesToDiff(\n resolution: 'deletions' | 'additions' | 'both',\n content: ChangeContent,\n diff: FileDiffMetadata,\n deletionLines: string[],\n additionLines: string[]\n) {\n if (resolution === 'deletions' || resolution === 'both') {\n for (let i = 0; i < content.deletions; i++) {\n const line = deletionLines[content.deletionLineIndex + i];\n if (line == null) {\n console.error({ deletionLines, content, i });\n throw new Error('pushResolveLinesToDiff: Deletion line does not exist');\n }\n diff.deletionLines.push(line);\n diff.additionLines.push(line);\n }\n }\n if (resolution === 'additions' || resolution === 'both') {\n for (let i = 0; i < content.additions; i++) {\n const line = additionLines[content.additionLineIndex + i];\n if (line == null) {\n console.error({ additionLines, content, i });\n throw new Error('pushResolveLinesToDiff: Addition line does not exist');\n }\n diff.deletionLines.push(line);\n diff.additionLines.push(line);\n }\n }\n}\n\nfunction advanceCursor(\n content: ChangeContent | ContextContent,\n cursor: CursorState,\n hunk: Hunk\n) {\n if (content.type === 'context') {\n cursor.nextAdditionLineIndex += content.lines;\n cursor.nextDeletionLineIndex += content.lines;\n cursor.nextAdditionStart += content.lines;\n cursor.nextDeletionStart += content.lines;\n cursor.splitLineCount += content.lines;\n cursor.unifiedLineCount += content.lines;\n\n hunk.additionCount += content.lines;\n hunk.deletionCount += content.lines;\n hunk.splitLineCount += content.lines;\n hunk.unifiedLineCount += content.lines;\n } else {\n cursor.nextAdditionLineIndex += content.additions;\n cursor.nextDeletionLineIndex += content.deletions;\n cursor.nextAdditionStart += content.additions;\n cursor.nextDeletionStart += content.deletions;\n cursor.splitLineCount += Math.max(content.deletions, content.additions);\n cursor.unifiedLineCount += content.deletions + content.additions;\n\n hunk.deletionCount += content.deletions;\n hunk.deletionLines += content.deletions;\n hunk.additionCount += content.additions;\n hunk.additionLines += content.additions;\n hunk.splitLineCount += Math.max(content.deletions, content.additions);\n hunk.unifiedLineCount += content.deletions + content.additions;\n }\n}\n"],"mappings":";AAwBA,SAAgB,cACd,MACA,QACkB;CAClB,MAAM,EACJ,YACA,WACA,mBACA,iBACA,kCAAkB,IAAI,KAAK,KACzB;CACJ,MAAM,cAAc,KAAK,MAAM;AAC/B,KAAI,eAAe,MAAM;AACvB,UAAQ,MAAM;GAAE;GAAM;GAAW,CAAC;AAClC,QAAM,IAAI,MAAM,sCAAsC,YAAY;;AAGpE,KACE,oBAAoB,KACpB,mBAAmB,YAAY,YAAY,UAC3C,oBAAoB,gBAEpB,OAAM,IAAI,MACR,yCAAyC,kBAAkB,IAAI,kBAChE;CAGH,MAAM,EAAE,OAAO,eAAe,kBAAkB;CAChD,MAAMA,eAAiC;EACrC,GAAG;EACH,OAAO,EAAE;EACT,eAAe,EAAE;EACjB,eAAe,EAAE;EACjB,gBAAgB;EAChB,kBAAkB;EAClB,UACE,KAAK,YAAY,OACb,GAAG,KAAK,SAAS,GAAG,WAAW,GAAG,GAAG,UAAU,GAAG,kBAAkB,GAAG,oBACvE;EACP;CAED,MAAMC,SAAsB;EAC1B,uBAAuB;EACvB,uBAAuB;EACvB,mBAAmB;EACnB,mBAAmB;EACnB,gBAAgB;EAChB,kBAAkB;EACnB;CACD,MAAM,kBACJ,cAAc,MAAM,SAAS,KAC7B,oBAAoB,YAAY,Y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