@pierre/diffs 1.1.5 → 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.
Files changed (130) hide show
  1. package/dist/components/File.d.ts +21 -1
  2. package/dist/components/File.d.ts.map +1 -1
  3. package/dist/components/File.js +142 -70
  4. package/dist/components/File.js.map +1 -1
  5. package/dist/components/FileDiff.d.ts +26 -5
  6. package/dist/components/FileDiff.d.ts.map +1 -1
  7. package/dist/components/FileDiff.js +143 -89
  8. package/dist/components/FileDiff.js.map +1 -1
  9. package/dist/components/FileStream.d.ts +4 -1
  10. package/dist/components/FileStream.d.ts.map +1 -1
  11. package/dist/components/FileStream.js +27 -12
  12. package/dist/components/FileStream.js.map +1 -1
  13. package/dist/components/UnresolvedFile.d.ts.map +1 -1
  14. package/dist/components/UnresolvedFile.js +6 -42
  15. package/dist/components/UnresolvedFile.js.map +1 -1
  16. package/dist/components/VirtulizerDevelopment.d.ts.map +1 -1
  17. package/dist/constants.d.ts +3 -1
  18. package/dist/constants.d.ts.map +1 -1
  19. package/dist/constants.js +3 -1
  20. package/dist/constants.js.map +1 -1
  21. package/dist/index.d.ts +6 -6
  22. package/dist/index.js +4 -4
  23. package/dist/managers/InteractionManager.d.ts.map +1 -1
  24. package/dist/react/File.d.ts +3 -1
  25. package/dist/react/File.d.ts.map +1 -1
  26. package/dist/react/File.js +5 -2
  27. package/dist/react/File.js.map +1 -1
  28. package/dist/react/FileDiff.d.ts +4 -1
  29. package/dist/react/FileDiff.d.ts.map +1 -1
  30. package/dist/react/FileDiff.js +5 -2
  31. package/dist/react/FileDiff.js.map +1 -1
  32. package/dist/react/MultiFileDiff.d.ts +4 -1
  33. package/dist/react/MultiFileDiff.d.ts.map +1 -1
  34. package/dist/react/MultiFileDiff.js +12 -6
  35. package/dist/react/MultiFileDiff.js.map +1 -1
  36. package/dist/react/PatchDiff.d.ts +4 -1
  37. package/dist/react/PatchDiff.d.ts.map +1 -1
  38. package/dist/react/PatchDiff.js +5 -2
  39. package/dist/react/PatchDiff.js.map +1 -1
  40. package/dist/react/UnresolvedFile.d.ts +4 -1
  41. package/dist/react/UnresolvedFile.d.ts.map +1 -1
  42. package/dist/react/UnresolvedFile.js +5 -2
  43. package/dist/react/UnresolvedFile.js.map +1 -1
  44. package/dist/react/WorkerPoolContext.js +7 -5
  45. package/dist/react/WorkerPoolContext.js.map +1 -1
  46. package/dist/react/index.d.ts +2 -2
  47. package/dist/react/jsx.d.ts.map +1 -1
  48. package/dist/react/types.d.ts +6 -3
  49. package/dist/react/types.d.ts.map +1 -1
  50. package/dist/react/utils/renderDiffChildren.d.ts +4 -6
  51. package/dist/react/utils/renderDiffChildren.d.ts.map +1 -1
  52. package/dist/react/utils/renderDiffChildren.js +12 -17
  53. package/dist/react/utils/renderDiffChildren.js.map +1 -1
  54. package/dist/react/utils/renderFileChildren.d.ts +2 -0
  55. package/dist/react/utils/renderFileChildren.d.ts.map +1 -1
  56. package/dist/react/utils/renderFileChildren.js +9 -6
  57. package/dist/react/utils/renderFileChildren.js.map +1 -1
  58. package/dist/react/utils/useFileDiffInstance.d.ts +7 -7
  59. package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
  60. package/dist/react/utils/useFileDiffInstance.js +20 -11
  61. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  62. package/dist/react/utils/useFileInstance.d.ts +5 -1
  63. package/dist/react/utils/useFileInstance.d.ts.map +1 -1
  64. package/dist/react/utils/useFileInstance.js +20 -7
  65. package/dist/react/utils/useFileInstance.js.map +1 -1
  66. package/dist/react/utils/useUnresolvedFileInstance.d.ts +5 -1
  67. package/dist/react/utils/useUnresolvedFileInstance.d.ts.map +1 -1
  68. package/dist/react/utils/useUnresolvedFileInstance.js +17 -4
  69. package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
  70. package/dist/renderers/DiffHunksRenderer.d.ts +14 -9
  71. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  72. package/dist/renderers/DiffHunksRenderer.js +9 -19
  73. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  74. package/dist/renderers/FileRenderer.d.ts +5 -4
  75. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  76. package/dist/renderers/FileRenderer.js +7 -17
  77. package/dist/renderers/FileRenderer.js.map +1 -1
  78. package/dist/renderers/UnresolvedFileHunksRenderer.d.ts +5 -5
  79. package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
  80. package/dist/renderers/UnresolvedFileHunksRenderer.js +2 -2
  81. package/dist/renderers/UnresolvedFileHunksRenderer.js.map +1 -1
  82. package/dist/ssr/index.d.ts +2 -2
  83. package/dist/ssr/preloadDiffs.js +7 -4
  84. package/dist/ssr/preloadDiffs.js.map +1 -1
  85. package/dist/ssr/preloadFile.js +7 -2
  86. package/dist/ssr/preloadFile.js.map +1 -1
  87. package/dist/style.js +1 -1
  88. package/dist/style.js.map +1 -1
  89. package/dist/types.d.ts +11 -11
  90. package/dist/types.d.ts.map +1 -1
  91. package/dist/utils/arePrePropertiesEqual.js +1 -1
  92. package/dist/utils/arePrePropertiesEqual.js.map +1 -1
  93. package/dist/utils/createFileHeaderElement.d.ts +3 -5
  94. package/dist/utils/createFileHeaderElement.d.ts.map +1 -1
  95. package/dist/utils/createFileHeaderElement.js +13 -9
  96. package/dist/utils/createFileHeaderElement.js.map +1 -1
  97. package/dist/utils/createPreElement.d.ts +0 -2
  98. package/dist/utils/createPreElement.d.ts.map +1 -1
  99. package/dist/utils/createPreElement.js +4 -7
  100. package/dist/utils/createPreElement.js.map +1 -1
  101. package/dist/utils/createStyleElement.d.ts +2 -1
  102. package/dist/utils/createStyleElement.d.ts.map +1 -1
  103. package/dist/utils/createStyleElement.js +9 -2
  104. package/dist/utils/createStyleElement.js.map +1 -1
  105. package/dist/utils/cssWrappers.d.ts +4 -1
  106. package/dist/utils/cssWrappers.d.ts.map +1 -1
  107. package/dist/utils/cssWrappers.js +11 -2
  108. package/dist/utils/cssWrappers.js.map +1 -1
  109. package/dist/utils/hast_utils.d.ts +1 -1
  110. package/dist/utils/hast_utils.d.ts.map +1 -1
  111. package/dist/utils/hast_utils.js.map +1 -1
  112. package/dist/utils/hostTheme.d.ts +15 -0
  113. package/dist/utils/hostTheme.d.ts.map +1 -0
  114. package/dist/utils/hostTheme.js +22 -0
  115. package/dist/utils/hostTheme.js.map +1 -0
  116. package/dist/utils/parsePatchFiles.js +1 -1
  117. package/dist/utils/parsePatchFiles.js.map +1 -1
  118. package/dist/utils/renderDiffWithHighlighter.js +1 -4
  119. package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
  120. package/dist/utils/renderFileWithHighlighter.js +1 -3
  121. package/dist/utils/renderFileWithHighlighter.js.map +1 -1
  122. package/dist/utils/setWrapperNodeProps.d.ts +0 -2
  123. package/dist/utils/setWrapperNodeProps.d.ts.map +1 -1
  124. package/dist/utils/setWrapperNodeProps.js +1 -4
  125. package/dist/utils/setWrapperNodeProps.js.map +1 -1
  126. package/dist/worker/worker-portable.js +4 -13
  127. package/dist/worker/worker-portable.js.map +1 -1
  128. package/dist/worker/worker.js +2 -7
  129. package/dist/worker/worker.js.map +1 -1
  130. 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 { CORE_CSS_ATTRIBUTE, UNSAFE_CSS_ATTRIBUTE } 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"],"mappings":";;;;;AAMA,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"}
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":["export declare function wrapCoreCSS(mainCSS: string): string;\nexport declare function wrapUnsafeCSS(unsafeCSS: string): string;\n//# sourceMappingURL=cssWrappers.d.ts.map"],"mappings":";iBAAwBA,WAAAA;AAAAA,iBACAC,aAAAA,CADW,SAAA,EAAA,MAAA,CAAA,EAAA,MAAA"}
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":";;;AAEA,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"}
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;;AAmBhC,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"}
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,MAC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;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"}
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,eA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,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 { 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,uBAAuB;EAC3B,MAAM,QAAQ,QAAQ,SAAS;AAC/B,MAAI,OAAO,UAAU,SACnB,QAAO,YAAY,SAAS,MAAM,CAAC;KAGnC;CACJ,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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KAAK;CAChE,MAAM,eACJ,oBAAoB,wBAAwB,aAAa,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"}
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;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,EAAE;EACrB;;AAeH,SAAS,eAAe,EACtB,cACA,cACA,cACA,cACA,aACA,qBACA,qBACA,kBACA,SAAS,EAAE,OAAO,gBAAgB,eAAgB,GAAG,aACR;CAC7C,MAAM,eACJ,oBAAoB,wBAAwB,aAAa,KAAK;CAChE,MAAM,eACJ,oBAAoB,wBAAwB,aAAa,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 = (() => {\n if (typeof theme === 'string') {\n return highlighter.getTheme(theme).type;\n }\n return undefined;\n })();\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,uBAAuB;AAC3B,MAAI,OAAO,UAAU,SACnB,QAAO,YAAY,SAAS,MAAM,CAAC;KAGnC;CACJ,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"}
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"}
@@ -8,8 +8,6 @@ declare function setPreNodeProperties(pre: HTMLPreElement, {
8
8
  disableLineNumbers,
9
9
  overflow,
10
10
  split,
11
- themeStyles,
12
- themeType,
13
11
  totalLines,
14
12
  customProperties
15
13
  }: PrePropertiesConfig): HTMLPreElement;
@@ -1 +1 @@
1
- {"version":3,"file":"setWrapperNodeProps.d.ts","names":["PrePropertiesConfig","setPreNodeProperties","HTMLPreElement","type","diffIndicators","disableBackground","disableLineNumbers","overflow","split","themeStyles","themeType","totalLines","customProperties"],"sources":["../../src/utils/setWrapperNodeProps.d.ts"],"sourcesContent":["import type { PrePropertiesConfig } from '../types';\nexport declare function setPreNodeProperties(pre: HTMLPreElement, { type, diffIndicators, disableBackground, disableLineNumbers, overflow, split, themeStyles, themeType, totalLines, customProperties }: PrePropertiesConfig): HTMLPreElement;\n//# sourceMappingURL=setWrapperNodeProps.d.ts.map"],"mappings":";;;iBACwBC,oBAAAA,MAA0BC;;;;;;;;;;;GAAwJF,sBAAsBE"}
1
+ {"version":3,"file":"setWrapperNodeProps.d.ts","names":["PrePropertiesConfig","setPreNodeProperties","HTMLPreElement","type","diffIndicators","disableBackground","disableLineNumbers","overflow","split","totalLines","customProperties"],"sources":["../../src/utils/setWrapperNodeProps.d.ts"],"sourcesContent":["import type { PrePropertiesConfig } from '../types';\nexport declare function setPreNodeProperties(pre: HTMLPreElement, { type, diffIndicators, disableBackground, disableLineNumbers, overflow, split, totalLines, customProperties }: PrePropertiesConfig): HTMLPreElement;\n//# sourceMappingURL=setWrapperNodeProps.d.ts.map"],"mappings":";;;iBACwBC,oBAAAA,MAA0BC;;;;;;;;;GAAgIF,sBAAsBE"}
@@ -1,5 +1,5 @@
1
1
  //#region src/utils/setWrapperNodeProps.ts
2
- function setPreNodeProperties(pre, { type, diffIndicators, disableBackground, disableLineNumbers, overflow, split, themeStyles, themeType, totalLines, customProperties }) {
2
+ function setPreNodeProperties(pre, { type, diffIndicators, disableBackground, disableLineNumbers, overflow, split, totalLines, customProperties }) {
3
3
  if (customProperties != null) for (const key in customProperties) {
4
4
  const value = customProperties[key];
5
5
  if (value != null) pre.setAttribute(key, `${value}`);
@@ -11,8 +11,6 @@ function setPreNodeProperties(pre, { type, diffIndicators, disableBackground, di
11
11
  pre.setAttribute("data-file", "");
12
12
  pre.removeAttribute("data-diff");
13
13
  }
14
- if (themeType === "system") pre.removeAttribute("data-theme-type");
15
- else pre.setAttribute("data-theme-type", themeType);
16
14
  switch (diffIndicators) {
17
15
  case "bars":
18
16
  case "classic":
@@ -30,7 +28,6 @@ function setPreNodeProperties(pre, { type, diffIndicators, disableBackground, di
30
28
  else pre.removeAttribute("data-diff-type");
31
29
  pre.setAttribute("data-overflow", overflow);
32
30
  pre.tabIndex = 0;
33
- pre.style = themeStyles;
34
31
  pre.style.setProperty("--diffs-min-number-column-width-default", `${`${totalLines}`.length}ch`);
35
32
  return pre;
36
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"setWrapperNodeProps.js","names":[],"sources":["../../src/utils/setWrapperNodeProps.ts"],"sourcesContent":["import type { PrePropertiesConfig } from '../types';\n\nexport function setPreNodeProperties(\n pre: HTMLPreElement,\n {\n type,\n diffIndicators,\n disableBackground,\n disableLineNumbers,\n overflow,\n split,\n themeStyles,\n themeType,\n totalLines,\n customProperties,\n }: PrePropertiesConfig\n): HTMLPreElement {\n // NOTE: We always apply custom properties first so the important properties\n // cannot be overridden.\n if (customProperties != null) {\n for (const key in customProperties) {\n const value = customProperties[key];\n if (value != null) {\n pre.setAttribute(key, `${value}`);\n }\n }\n }\n if (type === 'diff') {\n pre.setAttribute('data-diff', '');\n pre.removeAttribute('data-file');\n } else {\n pre.setAttribute('data-file', '');\n pre.removeAttribute('data-diff');\n }\n if (themeType === 'system') {\n pre.removeAttribute('data-theme-type');\n } else {\n pre.setAttribute('data-theme-type', themeType);\n }\n switch (diffIndicators) {\n case 'bars':\n case 'classic':\n pre.setAttribute('data-indicators', diffIndicators);\n break;\n case 'none':\n pre.removeAttribute('data-indicators');\n break;\n }\n if (disableLineNumbers) {\n pre.setAttribute('data-disable-line-numbers', '');\n } else {\n pre.removeAttribute('data-disable-line-numbers');\n }\n if (disableBackground) {\n pre.removeAttribute('data-background');\n } else {\n pre.setAttribute('data-background', '');\n }\n if (type === 'diff') {\n pre.setAttribute('data-diff-type', split ? 'split' : 'single');\n } else {\n pre.removeAttribute('data-diff-type');\n }\n pre.setAttribute('data-overflow', overflow);\n pre.tabIndex = 0;\n // Set theme color custom properties as inline styles on pre element\n pre.style = themeStyles;\n // Set CSS custom property for line number column width\n pre.style.setProperty(\n '--diffs-min-number-column-width-default',\n `${`${totalLines}`.length}ch`\n );\n return pre;\n}\n"],"mappings":";AAEA,SAAgB,qBACd,KACA,EACE,MACA,gBACA,mBACA,oBACA,UACA,OACA,aACA,WACA,YACA,oBAEc;AAGhB,KAAI,oBAAoB,KACtB,MAAK,MAAM,OAAO,kBAAkB;EAClC,MAAM,QAAQ,iBAAiB;AAC/B,MAAI,SAAS,KACX,KAAI,aAAa,KAAK,GAAG,QAAQ;;AAIvC,KAAI,SAAS,QAAQ;AACnB,MAAI,aAAa,aAAa,GAAG;AACjC,MAAI,gBAAgB,YAAY;QAC3B;AACL,MAAI,aAAa,aAAa,GAAG;AACjC,MAAI,gBAAgB,YAAY;;AAElC,KAAI,cAAc,SAChB,KAAI,gBAAgB,kBAAkB;KAEtC,KAAI,aAAa,mBAAmB,UAAU;AAEhD,SAAQ,gBAAR;EACE,KAAK;EACL,KAAK;AACH,OAAI,aAAa,mBAAmB,eAAe;AACnD;EACF,KAAK;AACH,OAAI,gBAAgB,kBAAkB;AACtC;;AAEJ,KAAI,mBACF,KAAI,aAAa,6BAA6B,GAAG;KAEjD,KAAI,gBAAgB,4BAA4B;AAElD,KAAI,kBACF,KAAI,gBAAgB,kBAAkB;KAEtC,KAAI,aAAa,mBAAmB,GAAG;AAEzC,KAAI,SAAS,OACX,KAAI,aAAa,kBAAkB,QAAQ,UAAU,SAAS;KAE9D,KAAI,gBAAgB,iBAAiB;AAEvC,KAAI,aAAa,iBAAiB,SAAS;AAC3C,KAAI,WAAW;AAEf,KAAI,QAAQ;AAEZ,KAAI,MAAM,YACR,2CACA,GAAG,GAAG,aAAa,OAAO,IAC3B;AACD,QAAO"}
1
+ {"version":3,"file":"setWrapperNodeProps.js","names":[],"sources":["../../src/utils/setWrapperNodeProps.ts"],"sourcesContent":["import type { PrePropertiesConfig } from '../types';\n\nexport function setPreNodeProperties(\n pre: HTMLPreElement,\n {\n type,\n diffIndicators,\n disableBackground,\n disableLineNumbers,\n overflow,\n split,\n totalLines,\n customProperties,\n }: PrePropertiesConfig\n): HTMLPreElement {\n // NOTE: We always apply custom properties first so the important properties\n // cannot be overridden.\n if (customProperties != null) {\n for (const key in customProperties) {\n const value = customProperties[key];\n if (value != null) {\n pre.setAttribute(key, `${value}`);\n }\n }\n }\n if (type === 'diff') {\n pre.setAttribute('data-diff', '');\n pre.removeAttribute('data-file');\n } else {\n pre.setAttribute('data-file', '');\n pre.removeAttribute('data-diff');\n }\n switch (diffIndicators) {\n case 'bars':\n case 'classic':\n pre.setAttribute('data-indicators', diffIndicators);\n break;\n case 'none':\n pre.removeAttribute('data-indicators');\n break;\n }\n if (disableLineNumbers) {\n pre.setAttribute('data-disable-line-numbers', '');\n } else {\n pre.removeAttribute('data-disable-line-numbers');\n }\n if (disableBackground) {\n pre.removeAttribute('data-background');\n } else {\n pre.setAttribute('data-background', '');\n }\n if (type === 'diff') {\n pre.setAttribute('data-diff-type', split ? 'split' : 'single');\n } else {\n pre.removeAttribute('data-diff-type');\n }\n pre.setAttribute('data-overflow', overflow);\n pre.tabIndex = 0;\n // Set CSS custom property for line number column width\n pre.style.setProperty(\n '--diffs-min-number-column-width-default',\n `${`${totalLines}`.length}ch`\n );\n return pre;\n}\n"],"mappings":";AAEA,SAAgB,qBACd,KACA,EACE,MACA,gBACA,mBACA,oBACA,UACA,OACA,YACA,oBAEc;AAGhB,KAAI,oBAAoB,KACtB,MAAK,MAAM,OAAO,kBAAkB;EAClC,MAAM,QAAQ,iBAAiB;AAC/B,MAAI,SAAS,KACX,KAAI,aAAa,KAAK,GAAG,QAAQ;;AAIvC,KAAI,SAAS,QAAQ;AACnB,MAAI,aAAa,aAAa,GAAG;AACjC,MAAI,gBAAgB,YAAY;QAC3B;AACL,MAAI,aAAa,aAAa,GAAG;AACjC,MAAI,gBAAgB,YAAY;;AAElC,SAAQ,gBAAR;EACE,KAAK;EACL,KAAK;AACH,OAAI,aAAa,mBAAmB,eAAe;AACnD;EACF,KAAK;AACH,OAAI,gBAAgB,kBAAkB;AACtC;;AAEJ,KAAI,mBACF,KAAI,aAAa,6BAA6B,GAAG;KAEjD,KAAI,gBAAgB,4BAA4B;AAElD,KAAI,kBACF,KAAI,gBAAgB,kBAAkB;KAEtC,KAAI,aAAa,mBAAmB,GAAG;AAEzC,KAAI,SAAS,OACX,KAAI,aAAa,kBAAkB,QAAQ,UAAU,SAAS;KAE9D,KAAI,gBAAgB,iBAAiB;AAEvC,KAAI,aAAa,iBAAiB,SAAS;AAC3C,KAAI,WAAW;AAEf,KAAI,MAAM,YACR,2CACA,GAAG,GAAG,aAAa,OAAO,IAC3B;AACD,QAAO"}
@@ -12150,10 +12150,12 @@ const MERGE_CONFLICT_SEPARATOR_MARKER_REGEX = /^={7,}$/;
12150
12150
  const MERGE_CONFLICT_END_MARKER_REGEX = /^>{7,}(?:\s.*)?$/;
12151
12151
  const HEADER_PREFIX_SLOT_ID = "header-prefix";
12152
12152
  const HEADER_METADATA_SLOT_ID = "header-metadata";
12153
+ const CUSTOM_HEADER_SLOT_ID = "header-custom";
12153
12154
  const DEFAULT_THEMES = {
12154
12155
  dark: "pierre-dark",
12155
12156
  light: "pierre-light"
12156
12157
  };
12158
+ const THEME_CSS_ATTRIBUTE = "data-theme-css";
12157
12159
  const UNSAFE_CSS_ATTRIBUTE = "data-unsafe-css";
12158
12160
  const CORE_CSS_ATTRIBUTE = "data-core-css";
12159
12161
  const DEFAULT_COLLAPSED_CONTEXT_THRESHOLD = 1;
@@ -15442,13 +15444,7 @@ function renderDiffWithHighlighter(diff, highlighter$1, options, { forcePlainTex
15442
15444
  totalLines = Infinity;
15443
15445
  }
15444
15446
  const isWindowedHighlight = startingLine > 0 || totalLines < Infinity;
15445
- const baseThemeType = (() => {
15446
- const theme = options.theme ?? DEFAULT_THEMES;
15447
- if (typeof theme === "string") {
15448
- return highlighter$1.getTheme(theme).type;
15449
- }
15450
- return undefined;
15451
- })();
15447
+ const baseThemeType = typeof options.theme === "string" ? highlighter$1.getTheme(options.theme).type : undefined;
15452
15448
  const themeStyles = getHighlighterThemeStyles({
15453
15449
  theme: options.theme,
15454
15450
  highlighter: highlighter$1
@@ -15794,12 +15790,7 @@ function renderFileWithHighlighter(file, highlighter$1, { theme = DEFAULT_THEMES
15794
15790
  const isWindowedHighlight = startingLine > 0 || totalLines < Infinity;
15795
15791
  const { state, transformers } = createTransformerWithState();
15796
15792
  const lang = forcePlainText ? "text" : file.lang ?? getFiletypeFromFileName(file.name);
15797
- const baseThemeType = (() => {
15798
- if (typeof theme === "string") {
15799
- return highlighter$1.getTheme(theme).type;
15800
- }
15801
- return undefined;
15802
- })();
15793
+ const baseThemeType = typeof theme === "string" ? highlighter$1.getTheme(theme).type : undefined;
15803
15794
  const themeStyles = getHighlighterThemeStyles({
15804
15795
  theme,
15805
15796
  highlighter: highlighter$1