@pierre/diffs 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +189 -0
- package/README.md +75 -5
- package/dist/renderers/DiffHunksRenderer.js +9 -5
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.js +9 -5
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/utils/parsePatchFiles.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.js +8 -2
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/package.json +3 -3
- package/LICENSE.txt +0 -201
package/LICENSE.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the
|
|
13
|
+
copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other
|
|
16
|
+
entities that control, are controlled by, or are under common control with
|
|
17
|
+
that entity. For the purposes of this definition, "control" means (i) the
|
|
18
|
+
power, direct or indirect, to cause the direction or management of such
|
|
19
|
+
entity, whether by contract or otherwise, or (ii) ownership of fifty percent
|
|
20
|
+
(50%) or more of the outstanding shares, or (iii) beneficial ownership of
|
|
21
|
+
such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
24
|
+
permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation source, and
|
|
28
|
+
configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical transformation
|
|
31
|
+
or translation of a Source form, including but not limited to compiled
|
|
32
|
+
object code, generated documentation, and conversions to other media types.
|
|
33
|
+
|
|
34
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
35
|
+
made available under the License, as indicated by a copyright notice that is
|
|
36
|
+
included in or attached to the work (an example is provided in the Appendix
|
|
37
|
+
below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object form,
|
|
40
|
+
that is based on (or derived from) the Work and for which the editorial
|
|
41
|
+
revisions, annotations, elaborations, or other modifications represent, as a
|
|
42
|
+
whole, an original work of authorship. For the purposes of this License,
|
|
43
|
+
Derivative Works shall not include works that remain separable from, or
|
|
44
|
+
merely link (or bind by name) to the interfaces of, the Work and Derivative
|
|
45
|
+
Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean any work of authorship, including the original
|
|
48
|
+
version of the Work and any modifications or additions to that Work or
|
|
49
|
+
Derivative Works thereof, that is intentionally submitted to Licensor for
|
|
50
|
+
inclusion in the Work by the copyright owner or by an individual or Legal
|
|
51
|
+
Entity authorized to submit on behalf of the copyright owner. For the
|
|
52
|
+
purposes of this definition, "submitted" means any form of electronic,
|
|
53
|
+
verbal, or written communication sent to the Licensor or its
|
|
54
|
+
representatives, including but not limited to communication on electronic
|
|
55
|
+
mailing lists, source code control systems, and issue tracking systems that
|
|
56
|
+
are managed by, or on behalf of, the Licensor for the purpose of discussing
|
|
57
|
+
and improving the Work, but excluding communication that is conspicuously
|
|
58
|
+
marked or otherwise designated in writing by the copyright owner as "Not a
|
|
59
|
+
Contribution."
|
|
60
|
+
|
|
61
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on
|
|
62
|
+
behalf of whom a Contribution has been received by Licensor and subsequently
|
|
63
|
+
incorporated within the Work.
|
|
64
|
+
|
|
65
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
66
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
67
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
68
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
69
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
70
|
+
Object form.
|
|
71
|
+
|
|
72
|
+
3. Grant of Patent License. Subject to the terms and conditions of this
|
|
73
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
74
|
+
non-exclusive, no-charge, royalty-free, irrevocable (except as stated in
|
|
75
|
+
this section) patent license to make, have made, use, offer to sell, sell,
|
|
76
|
+
import, and otherwise transfer the Work, where such license applies only to
|
|
77
|
+
those patent claims licensable by such Contributor that are necessarily
|
|
78
|
+
infringed by their Contribution(s) alone or by combination of their
|
|
79
|
+
Contribution(s) with the Work to which such Contribution(s) was submitted.
|
|
80
|
+
If You institute patent litigation against any entity (including a
|
|
81
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
|
82
|
+
Contribution incorporated within the Work constitutes direct or contributory
|
|
83
|
+
patent infringement, then any patent licenses granted to You under this
|
|
84
|
+
License for that Work shall terminate as of the date such litigation is
|
|
85
|
+
filed.
|
|
86
|
+
|
|
87
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
88
|
+
Derivative Works thereof in any medium, with or without modifications, and
|
|
89
|
+
in Source or Object form, provided that You meet the following conditions:
|
|
90
|
+
|
|
91
|
+
(a) You must give any other recipients of the Work or Derivative Works a
|
|
92
|
+
copy of this License; and
|
|
93
|
+
|
|
94
|
+
(b) You must cause any modified files to carry prominent notices stating
|
|
95
|
+
that You changed the files; and
|
|
96
|
+
|
|
97
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
98
|
+
distribute, all copyright, patent, trademark, and attribution notices from
|
|
99
|
+
the Source form of the Work, excluding those notices that do not pertain to
|
|
100
|
+
any part of the Derivative Works; and
|
|
101
|
+
|
|
102
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution,
|
|
103
|
+
then any Derivative Works that You distribute must include a readable copy
|
|
104
|
+
of the attribution notices contained within such NOTICE file, excluding
|
|
105
|
+
those notices that do not pertain to any part of the Derivative Works, in at
|
|
106
|
+
least one of the following places: within a NOTICE text file distributed as
|
|
107
|
+
part of the Derivative Works; within the Source form or documentation, if
|
|
108
|
+
provided along with the Derivative Works; or, within a display generated by
|
|
109
|
+
the Derivative Works, if and wherever such third-party notices normally
|
|
110
|
+
appear. The contents of the NOTICE file are for informational purposes only
|
|
111
|
+
and do not modify the License. You may add Your own attribution notices
|
|
112
|
+
within Derivative Works that You distribute, alongside or as an addendum to
|
|
113
|
+
the NOTICE text from the Work, provided that such additional attribution
|
|
114
|
+
notices cannot be construed as modifying the License.
|
|
115
|
+
|
|
116
|
+
You may add Your own copyright statement to Your modifications and may
|
|
117
|
+
provide additional or different license terms and conditions for use,
|
|
118
|
+
reproduction, or distribution of Your modifications, or for any such
|
|
119
|
+
Derivative Works as a whole, provided Your use, reproduction, and
|
|
120
|
+
distribution of the Work otherwise complies with the conditions stated in
|
|
121
|
+
this License.
|
|
122
|
+
|
|
123
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
124
|
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
125
|
+
Licensor shall be under the terms and conditions of this License, without
|
|
126
|
+
any additional terms or conditions. Notwithstanding the above, nothing
|
|
127
|
+
herein shall supersede or modify the terms of any separate license agreement
|
|
128
|
+
you may have executed with Licensor regarding such Contributions.
|
|
129
|
+
|
|
130
|
+
6. Trademarks. This License does not grant permission to use the trade names,
|
|
131
|
+
trademarks, service marks, or product names of the Licensor, except as
|
|
132
|
+
required for reasonable and customary use in describing the origin of the
|
|
133
|
+
Work and reproducing the content of the NOTICE file.
|
|
134
|
+
|
|
135
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
136
|
+
writing, Licensor provides the Work (and each Contributor provides its
|
|
137
|
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
138
|
+
KIND, either express or implied, including, without limitation, any
|
|
139
|
+
warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or
|
|
140
|
+
FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining
|
|
141
|
+
the appropriateness of using or redistributing the Work and assume any risks
|
|
142
|
+
associated with Your exercise of permissions under this License.
|
|
143
|
+
|
|
144
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in
|
|
145
|
+
tort (including negligence), contract, or otherwise, unless required by
|
|
146
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed to
|
|
147
|
+
in writing, shall any Contributor be liable to You for damages, including
|
|
148
|
+
any direct, indirect, special, incidental, or consequential damages of any
|
|
149
|
+
character arising as a result of this License or out of the use or inability
|
|
150
|
+
to use the Work (including but not limited to damages for loss of goodwill,
|
|
151
|
+
work stoppage, computer failure or malfunction, or any and all other
|
|
152
|
+
commercial damages or losses), even if such Contributor has been advised of
|
|
153
|
+
the possibility of such damages.
|
|
154
|
+
|
|
155
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
|
156
|
+
Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
157
|
+
acceptance of support, warranty, indemnity, or other liability obligations
|
|
158
|
+
and/or rights consistent with this License. However, in accepting such
|
|
159
|
+
obligations, You may act only on Your own behalf and on Your sole
|
|
160
|
+
responsibility, not on behalf of any other Contributor, and only if You
|
|
161
|
+
agree to indemnify, defend, and hold each Contributor harmless for any
|
|
162
|
+
liability incurred by, or claims asserted against, such Contributor by
|
|
163
|
+
reason of your accepting any such warranty or additional liability.
|
|
164
|
+
|
|
165
|
+
END OF TERMS AND CONDITIONS
|
|
166
|
+
|
|
167
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
168
|
+
|
|
169
|
+
To apply the Apache License to your work, attach the following
|
|
170
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
171
|
+
replaced with your own identifying information. (Don't include
|
|
172
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
173
|
+
comment syntax for the file format. We also recommend that a
|
|
174
|
+
file or class name and description of purpose be included on the
|
|
175
|
+
same "printed page" as the copyright notice for easier
|
|
176
|
+
identification within third-party archives.
|
|
177
|
+
|
|
178
|
+
Copyright 2025 Pierre Computer Company
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
181
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
182
|
+
License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
187
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
188
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
189
|
+
specific language governing permissions and limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,19 +1,52 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Diffs, from Pierre
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@pierre/diffs` is an open source diff and file rendering library built on
|
|
4
|
+
[Shiki](https://shiki.style/). It's super customizable and packed with the
|
|
5
|
+
features you need. Made with love by
|
|
6
|
+
[The Pierre Computer Company](https://pierre.computer). Available as vanilla
|
|
7
|
+
JavaScript and React components.
|
|
8
|
+
|
|
9
|
+
**View examples and read documentation on [Diffs.com](https://diffs.com).**
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- Diff file versions, patches, and arbitrary files
|
|
14
|
+
- Split or stacked layout
|
|
15
|
+
- Automatically adapts to Shiki themes
|
|
16
|
+
- Supports light and dark mode
|
|
17
|
+
- Options for diff highlight styles, in-line highlighting, wrapping, line
|
|
18
|
+
numbers, and more
|
|
19
|
+
- Supports custom fonts and `font-feature-settings`
|
|
20
|
+
- Flexible annotation framework for injecting comments, annotations, and more
|
|
21
|
+
- Add your own accept/reject changes UI
|
|
22
|
+
- Select and highlight lines
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
bun i @pierre/diffs
|
|
28
|
+
```
|
|
4
29
|
|
|
5
30
|
## Development
|
|
6
31
|
|
|
7
|
-
|
|
32
|
+
Technically you can use the package manager of your choice, but we use
|
|
33
|
+
[bun](https://bun.sh/).
|
|
8
34
|
|
|
9
35
|
```bash
|
|
10
|
-
|
|
36
|
+
# From the root of the mono repo: setup dependencies
|
|
37
|
+
bun install
|
|
38
|
+
|
|
39
|
+
# Start the demo vite test server from root
|
|
40
|
+
bun run demo:dev
|
|
41
|
+
|
|
42
|
+
# To run the docs from root
|
|
43
|
+
bun run docs:dev
|
|
11
44
|
```
|
|
12
45
|
|
|
13
46
|
### Testing
|
|
14
47
|
|
|
15
48
|
```bash
|
|
16
|
-
# Run tests
|
|
49
|
+
# Run tests and related command from within the package directory
|
|
17
50
|
bun test
|
|
18
51
|
|
|
19
52
|
# Update snapshots
|
|
@@ -25,3 +58,40 @@ bun run tsc
|
|
|
25
58
|
|
|
26
59
|
Tests are located in the `test/` folder and use Bun's native testing framework
|
|
27
60
|
with snapshot support.
|
|
61
|
+
|
|
62
|
+
## Publishing
|
|
63
|
+
|
|
64
|
+
**Applicable to the Pierre team only.**
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# You may need to login with npm first:
|
|
68
|
+
npm login
|
|
69
|
+
|
|
70
|
+
# Always run publish from within the package directory
|
|
71
|
+
cd packages/diffs
|
|
72
|
+
bun publish
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Building Icons
|
|
76
|
+
|
|
77
|
+
**For Pierre team only.**
|
|
78
|
+
|
|
79
|
+
To build all our SVG icons from Figma there's a couple preparation steps that
|
|
80
|
+
you need to run first.
|
|
81
|
+
|
|
82
|
+
Perform a full export of all `Published Icons` the `Pierre Design` Figma file
|
|
83
|
+
|
|
84
|
+
Do this by selecting all the icons but not the art board and in the bottom right
|
|
85
|
+
click `Export XXX Layers` and make sure to point it to a `./svg` folder at the
|
|
86
|
+
root level of this project
|
|
87
|
+
|
|
88
|
+
Once that's done, simply run:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
bun run icons:build
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
This will run a full build of all the icons into
|
|
95
|
+
`./apps/docs/components/icons/icons`
|
|
96
|
+
|
|
97
|
+
Then make sure to check in any changes needed
|
|
@@ -150,14 +150,18 @@ var DiffHunksRenderer = class {
|
|
|
150
150
|
}
|
|
151
151
|
renderDiff(diff = this.renderCache?.diff) {
|
|
152
152
|
if (diff == null) return;
|
|
153
|
+
const cache = this.workerManager?.getDiffResultCache(diff);
|
|
154
|
+
if (cache != null && this.renderCache == null) this.renderCache = {
|
|
155
|
+
diff,
|
|
156
|
+
highlighted: true,
|
|
157
|
+
...cache
|
|
158
|
+
};
|
|
153
159
|
const { options, forceRender } = this.getRenderOptions(diff);
|
|
154
|
-
let cache = this.workerManager?.getDiffResultCache(diff);
|
|
155
|
-
if (cache != null && !areRenderOptionsEqual(options, cache.options)) cache = void 0;
|
|
156
160
|
this.renderCache ??= {
|
|
157
161
|
diff,
|
|
158
|
-
highlighted:
|
|
159
|
-
options
|
|
160
|
-
result:
|
|
162
|
+
highlighted: false,
|
|
163
|
+
options,
|
|
164
|
+
result: void 0
|
|
161
165
|
};
|
|
162
166
|
if (this.workerManager?.isWorkingPool() === true) {
|
|
163
167
|
this.renderCache.result ??= this.workerManager.getPlainDiffAST(diff);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiffHunksRenderer.js","names":["EXPANDED_REGION: ExpansionRegion","options: BaseDiffOptions","onRenderUpdate?: () => unknown","workerManager?: WorkerPoolManager | undefined","options","options: RenderDiffOptions","additionsAST: ElementContent[] | undefined","deletionsAST: ElementContent[] | undefined","unifiedAST: ElementContent[] | undefined","hunkData: HunkData[]","prevHunk: Hunk | undefined","oldLine: ElementContent | undefined","newLine: ElementContent | undefined","oldLine","newLine","deletionSpan: AnnotationSpan","additionSpan: AnnotationSpan"],"sources":["../../src/renderers/DiffHunksRenderer.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\nimport { DEFAULT_THEMES } from '../constants';\nimport { areLanguagesAttached } from '../highlighter/languages/areLanguagesAttached';\nimport {\n getHighlighterIfLoaded,\n getSharedHighlighter,\n} from '../highlighter/shared_highlighter';\nimport { areThemesAttached } from '../highlighter/themes/areThemesAttached';\nimport type {\n AnnotationLineMap,\n AnnotationSpan,\n BaseDiffOptions,\n DiffLineAnnotation,\n DiffsHighlighter,\n ExpansionDirections,\n FileDiffMetadata,\n Hunk,\n HunkData,\n RenderDiffFilesResult,\n RenderDiffHunksResult,\n RenderDiffOptions,\n RenderDiffResult,\n RenderedDiffASTCache,\n SupportedLanguages,\n ThemeTypes,\n ThemedDiffResult,\n} from '../types';\nimport { areThemesEqual } from '../utils/areThemesEqual';\nimport { createAnnotationElement } from '../utils/createAnnotationElement';\nimport { createEmptyRowBuffer } from '../utils/createEmptyRowBuffer';\nimport { createFileHeaderElement } from '../utils/createFileHeaderElement';\nimport { createNoNewlineElement } from '../utils/createNoNewlineElement';\nimport { createPreElement } from '../utils/createPreElement';\nimport { createSeparator } from '../utils/createSeparator';\nimport { getFiletypeFromFileName } from '../utils/getFiletypeFromFileName';\nimport { getHighlighterOptions } from '../utils/getHighlighterOptions';\nimport { getHunkSeparatorSlotName } from '../utils/getHunkSeparatorSlotName';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport { getTotalLineCountFromHunks } from '../utils/getTotalLineCountFromHunks';\nimport { createHastElement } from '../utils/hast_utils';\nimport { renderDiffWithHighlighter } from '../utils/renderDiffWithHighlighter';\nimport type { WorkerPoolManager } from '../worker';\n\nconst EXPANDED_REGION: ExpansionRegion = {\n fromStart: 0,\n fromEnd: 0,\n};\n\ninterface PushHunkSeparatorProps {\n type: 'additions' | 'deletions' | 'unified';\n linesAST: ElementContent[];\n}\n\ninterface RenderRangeProps {\n rangeLen: number;\n fromStart: boolean;\n}\n\ninterface PushLineWithAnnotation {\n newLine?: ElementContent;\n oldLine?: ElementContent;\n\n unifiedAST?: ElementContent[];\n deletionsAST?: ElementContent[];\n additionsAST?: ElementContent[];\n\n unifiedSpan?: AnnotationSpan;\n deletionSpan?: AnnotationSpan;\n additionSpan?: AnnotationSpan;\n}\n\ninterface RenderCollapsedHunksProps {\n ast: RenderDiffFilesResult | RenderDiffHunksResult;\n hunkData: HunkData[];\n hunkIndex: number;\n hunkSpecs: string | undefined;\n isFirstHunk: boolean;\n isLastHunk: boolean;\n rangeSize: number;\n\n lineIndex: number;\n additionLineNumber: number;\n deletionLineNumber: number;\n\n additionsAST: ElementContent[];\n deletionsAST: ElementContent[];\n unifiedAST: ElementContent[];\n}\n\ninterface RenderHunkProps {\n hunk: Hunk;\n hunkData: HunkData[];\n hunkIndex: number;\n lineIndex: number;\n isLastHunk: boolean;\n prevHunk: Hunk | undefined;\n\n ast: RenderDiffFilesResult | RenderDiffHunksResult;\n unifiedAST: ElementContent[];\n deletionsAST: ElementContent[];\n additionsAST: ElementContent[];\n}\n\ninterface GetRenderOptionsReturn {\n options: RenderDiffOptions;\n forceRender: boolean;\n}\n\ntype OptionsWithDefaults = Required<\n Omit<BaseDiffOptions, 'lang' | 'unsafeCSS'>\n>;\n\ninterface ExpansionRegion {\n fromStart: number;\n fromEnd: number;\n}\n\nexport interface HunksRenderResult {\n additionsAST: ElementContent[] | undefined;\n deletionsAST: ElementContent[] | undefined;\n unifiedAST: ElementContent[] | undefined;\n hunkData: HunkData[];\n css: string;\n preNode: HASTElement;\n headerElement: HASTElement | undefined;\n totalLines: number;\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n}\n\nexport class DiffHunksRenderer<LAnnotation = undefined> {\n private highlighter: DiffsHighlighter | undefined;\n private diff: FileDiffMetadata | undefined;\n\n private expandedHunks = new Map<number, ExpansionRegion>();\n\n private deletionAnnotations: AnnotationLineMap<LAnnotation> = {};\n private additionAnnotations: AnnotationLineMap<LAnnotation> = {};\n\n private computedLang: SupportedLanguages = 'text';\n private renderCache: RenderedDiffASTCache | undefined;\n\n constructor(\n public options: BaseDiffOptions = { theme: DEFAULT_THEMES },\n private onRenderUpdate?: () => unknown,\n private workerManager?: WorkerPoolManager | undefined\n ) {\n if (workerManager?.isWorkingPool() !== true) {\n this.highlighter = areThemesAttached(options.theme ?? DEFAULT_THEMES)\n ? getHighlighterIfLoaded()\n : undefined;\n }\n }\n\n cleanUp(): void {\n this.highlighter = undefined;\n this.diff = undefined;\n this.renderCache = undefined;\n this.workerManager = undefined;\n this.onRenderUpdate = undefined;\n }\n\n setOptions(options: BaseDiffOptions): void {\n this.options = options;\n }\n\n private mergeOptions(options: Partial<BaseDiffOptions>) {\n this.options = { ...this.options, ...options };\n }\n\n setThemeType(themeType: ThemeTypes): void {\n if (this.getOptionsWithDefaults().themeType === themeType) {\n return;\n }\n this.mergeOptions({ themeType });\n }\n\n expandHunk(index: number, direction: ExpansionDirections): void {\n const { expansionLineCount } = this.getOptionsWithDefaults();\n const region = this.expandedHunks.get(index) ?? {\n fromStart: 0,\n fromEnd: 0,\n };\n if (direction === 'up' || direction === 'both') {\n region.fromStart += expansionLineCount;\n }\n if (direction === 'down' || direction === 'both') {\n region.fromEnd += expansionLineCount;\n }\n this.expandedHunks.set(index, region);\n }\n\n setLineAnnotations(lineAnnotations: DiffLineAnnotation<LAnnotation>[]): void {\n this.additionAnnotations = {};\n this.deletionAnnotations = {};\n for (const annotation of lineAnnotations) {\n const map = ((): AnnotationLineMap<LAnnotation> => {\n switch (annotation.side) {\n case 'deletions':\n return this.deletionAnnotations;\n case 'additions':\n return this.additionAnnotations;\n }\n })();\n const arr = map[annotation.lineNumber] ?? [];\n map[annotation.lineNumber] = arr;\n arr.push(annotation);\n }\n }\n\n getOptionsWithDefaults(): OptionsWithDefaults {\n const {\n diffIndicators = 'bars',\n diffStyle = 'split',\n disableBackground = false,\n disableFileHeader = false,\n disableLineNumbers = false,\n expandUnchanged = false,\n expansionLineCount = 100,\n hunkSeparators = 'line-info',\n lineDiffType = 'word-alt',\n maxLineDiffLength = 1000,\n overflow = 'scroll',\n theme = DEFAULT_THEMES,\n themeType = 'system',\n tokenizeMaxLineLength = 1000,\n useCSSClasses = false,\n } = this.options;\n return {\n diffIndicators,\n diffStyle,\n disableBackground,\n disableFileHeader,\n disableLineNumbers,\n expandUnchanged,\n expansionLineCount,\n hunkSeparators,\n lineDiffType,\n maxLineDiffLength,\n overflow,\n theme: this.workerManager?.getDiffRenderOptions().theme ?? theme,\n themeType,\n tokenizeMaxLineLength,\n useCSSClasses,\n };\n }\n\n async initializeHighlighter(): Promise<DiffsHighlighter> {\n this.highlighter = await getSharedHighlighter(\n getHighlighterOptions(this.computedLang, this.options)\n );\n return this.highlighter;\n }\n\n hydrate(diff: FileDiffMetadata | undefined): void {\n if (diff == null) {\n return;\n }\n this.diff = diff;\n const { options } = this.getRenderOptions(diff);\n let cache = this.workerManager?.getDiffResultCache(diff);\n if (cache != null && !areRenderOptionsEqual(options, cache.options)) {\n cache = undefined;\n }\n this.renderCache ??= {\n diff,\n // NOTE(amadeus): If we're hydrating, we can assume there was\n // pre-rendered HTML, otherwise one should not be hydrating\n highlighted: true,\n options,\n result: cache?.result,\n };\n if (\n this.workerManager?.isWorkingPool() === true &&\n this.renderCache.result == null\n ) {\n this.workerManager.highlightDiffAST(this, this.diff);\n } else {\n void this.asyncHighlight(diff).then(({ result, options }) => {\n this.onHighlightSuccess(diff, result, options);\n });\n }\n }\n\n private getRenderOptions(diff: FileDiffMetadata): GetRenderOptionsReturn {\n const options: RenderDiffOptions = (() => {\n if (this.workerManager?.isWorkingPool() === true) {\n return this.workerManager.getDiffRenderOptions();\n }\n const { theme, tokenizeMaxLineLength, lineDiffType } =\n this.getOptionsWithDefaults();\n return { theme, tokenizeMaxLineLength, lineDiffType };\n })();\n this.getOptionsWithDefaults();\n const { renderCache } = this;\n if (renderCache?.result == null) {\n return { options, forceRender: true };\n }\n if (\n diff !== renderCache.diff ||\n !areRenderOptionsEqual(options, renderCache.options)\n ) {\n return { options, forceRender: true };\n }\n return { options, forceRender: false };\n }\n\n renderDiff(\n diff: FileDiffMetadata | undefined = this.renderCache?.diff\n ): HunksRenderResult | undefined {\n if (diff == null) {\n return undefined;\n }\n const { options, forceRender } = this.getRenderOptions(diff);\n let cache = this.workerManager?.getDiffResultCache(diff);\n if (cache != null && !areRenderOptionsEqual(options, cache.options)) {\n cache = undefined;\n }\n this.renderCache ??= {\n diff,\n highlighted: cache != null ? true : false,\n options: cache?.options ?? options,\n result: cache?.result,\n };\n if (this.workerManager?.isWorkingPool() === true) {\n this.renderCache.result ??= this.workerManager.getPlainDiffAST(diff);\n if (!this.renderCache.highlighted || forceRender) {\n this.workerManager.highlightDiffAST(this, diff);\n }\n } else {\n this.computedLang = diff.lang ?? getFiletypeFromFileName(diff.name);\n const hasThemes =\n this.highlighter != null && areThemesAttached(options.theme);\n const hasLangs =\n this.highlighter != null && areLanguagesAttached(this.computedLang);\n\n // If we have any semblance of a highlighter with the correct theme(s)\n // attached, we can kick off some form of rendering. If we don't have\n // the correct language, then we can render plain text and after kick off\n // an async job to get the highlighted AST\n if (\n this.highlighter != null &&\n hasThemes &&\n (forceRender ||\n (!this.renderCache.highlighted && hasLangs) ||\n this.renderCache.result == null)\n ) {\n const { result, options } = this.renderDiffWithHighlighter(\n diff,\n this.highlighter,\n !hasLangs\n );\n this.renderCache = {\n diff,\n options,\n highlighted: hasLangs,\n result,\n };\n }\n\n // If we get in here it means we'll have to kick off an async highlight\n // process which will involve initializing the highlighter with new themes\n // and languages\n if (!hasThemes || !hasLangs) {\n void this.asyncHighlight(diff).then(({ result, options }) => {\n this.onHighlightSuccess(diff, result, options);\n });\n }\n }\n return this.renderCache.result != null\n ? this.processDiffResult(this.renderCache.diff, this.renderCache.result)\n : undefined;\n }\n\n async asyncRender(diff: FileDiffMetadata): Promise<HunksRenderResult> {\n const { result } = await this.asyncHighlight(diff);\n return this.processDiffResult(diff, result);\n }\n\n private createPreElement(\n split: boolean,\n totalLines: number,\n themeStyles: string,\n baseThemeType: 'light' | 'dark' | undefined\n ): HASTElement {\n const {\n diffIndicators,\n disableBackground,\n disableLineNumbers,\n overflow,\n themeType,\n } = this.getOptionsWithDefaults();\n return createPreElement({\n diffIndicators,\n disableBackground,\n disableLineNumbers,\n overflow,\n themeStyles,\n split,\n themeType: baseThemeType ?? themeType,\n totalLines,\n });\n }\n\n private async asyncHighlight(\n diff: FileDiffMetadata\n ): Promise<RenderDiffResult> {\n this.computedLang = diff.lang ?? getFiletypeFromFileName(diff.name);\n const hasThemes =\n this.highlighter != null &&\n areThemesAttached(this.options.theme ?? DEFAULT_THEMES);\n const hasLangs =\n this.highlighter != null && areLanguagesAttached(this.computedLang);\n // If we don't have the required langs or themes, then we need to\n // initialize the highlighter to load the appropriate languages and themes\n if (this.highlighter == null || !hasThemes || !hasLangs) {\n this.highlighter = await this.initializeHighlighter();\n }\n return this.renderDiffWithHighlighter(diff, this.highlighter);\n }\n\n private renderDiffWithHighlighter(\n diff: FileDiffMetadata,\n highlighter: DiffsHighlighter,\n plainText = false\n ): RenderDiffResult {\n const { options } = this.getRenderOptions(diff);\n const result = renderDiffWithHighlighter(\n diff,\n highlighter,\n options,\n plainText\n );\n return { result, options };\n }\n\n onHighlightSuccess(\n diff: FileDiffMetadata,\n result: ThemedDiffResult,\n options: RenderDiffOptions\n ): void {\n // If renderCache was blown away, we can assume we've run cleanUp()\n if (this.renderCache == null) {\n return;\n }\n const triggerRenderUpdate =\n this.renderCache.diff !== diff ||\n !this.renderCache.highlighted ||\n !areRenderOptionsEqual(this.renderCache.options, options);\n\n this.renderCache = {\n diff,\n options,\n highlighted: true,\n result,\n };\n if (triggerRenderUpdate) {\n this.onRenderUpdate?.();\n }\n }\n\n onHighlightError(error: unknown): void {\n console.error(error);\n }\n\n private processDiffResult(\n fileDiff: FileDiffMetadata,\n { code, themeStyles, baseThemeType }: ThemedDiffResult\n ): HunksRenderResult {\n const { diffStyle, disableFileHeader } = this.getOptionsWithDefaults();\n\n this.diff = fileDiff;\n const unified = diffStyle === 'unified';\n\n let additionsAST: ElementContent[] | undefined = [];\n let deletionsAST: ElementContent[] | undefined = [];\n let unifiedAST: ElementContent[] | undefined = [];\n\n let hunkIndex = 0;\n const hunkData: HunkData[] = [];\n\n let prevHunk: Hunk | undefined;\n let lineIndex = 0;\n for (const hunk of fileDiff.hunks) {\n lineIndex += hunk.collapsedBefore;\n lineIndex = this.renderHunks({\n ast: code,\n hunk,\n prevHunk,\n hunkIndex,\n isLastHunk: hunkIndex === fileDiff.hunks.length - 1,\n additionsAST,\n deletionsAST,\n unifiedAST,\n hunkData,\n lineIndex,\n });\n hunkIndex++;\n prevHunk = hunk;\n }\n\n const totalLines = Math.max(\n getTotalLineCountFromHunks(fileDiff.hunks),\n fileDiff.newLines?.length ?? 0,\n fileDiff.oldLines?.length ?? 0\n );\n\n additionsAST =\n !unified && (code.hunks != null || code.newLines.length > 0)\n ? additionsAST\n : undefined;\n deletionsAST =\n !unified && (code.hunks != null || code.oldLines.length > 0)\n ? deletionsAST\n : undefined;\n unifiedAST = unifiedAST.length > 0 ? unifiedAST : undefined;\n\n const preNode = this.createPreElement(\n deletionsAST != null && additionsAST != null,\n totalLines,\n themeStyles,\n baseThemeType\n );\n\n return {\n additionsAST,\n deletionsAST,\n unifiedAST,\n hunkData,\n preNode,\n themeStyles,\n baseThemeType,\n headerElement: !disableFileHeader\n ? this.renderHeader(this.diff, themeStyles, baseThemeType)\n : undefined,\n totalLines,\n // FIXME\n css: '',\n };\n }\n\n renderFullAST(\n result: HunksRenderResult,\n children: ElementContent[] = []\n ): HASTElement {\n if (result.unifiedAST != null) {\n children.push(\n createHastElement({\n tagName: 'code',\n children: result.unifiedAST,\n properties: {\n 'data-code': '',\n 'data-unified': '',\n },\n })\n );\n }\n if (result.deletionsAST != null) {\n children.push(\n createHastElement({\n tagName: 'code',\n children: result.deletionsAST,\n properties: {\n 'data-code': '',\n 'data-deletions': '',\n },\n })\n );\n }\n if (result.additionsAST != null) {\n children.push(\n createHastElement({\n tagName: 'code',\n children: result.additionsAST,\n properties: {\n 'data-code': '',\n 'data-additions': '',\n },\n })\n );\n }\n return { ...result.preNode, children };\n }\n\n renderFullHTML(\n result: HunksRenderResult,\n tempChildren: ElementContent[] = []\n ): string {\n return toHtml(this.renderFullAST(result, tempChildren));\n }\n\n renderPartialHTML(\n children: ElementContent[],\n columnType?: 'unified' | 'deletions' | 'additions'\n ): string {\n if (columnType == null) {\n return toHtml(children);\n }\n return toHtml(\n createHastElement({\n tagName: 'code',\n children,\n properties: {\n 'data-code': '',\n [`data-${columnType}`]: '',\n },\n })\n );\n }\n\n private renderCollapsedHunks({\n ast,\n hunkData,\n hunkIndex,\n hunkSpecs,\n isFirstHunk,\n isLastHunk,\n rangeSize,\n lineIndex,\n additionLineNumber,\n deletionLineNumber,\n unifiedAST,\n deletionsAST,\n additionsAST,\n }: RenderCollapsedHunksProps) {\n if (rangeSize <= 0) {\n return;\n }\n const { hunkSeparators, expandUnchanged, diffStyle, expansionLineCount } =\n this.getOptionsWithDefaults();\n const expandable =\n ast.hunks == null && ast.newLines.length > 0 && ast.oldLines.length > 0;\n const expandedRegion = this.expandedHunks.get(hunkIndex) ?? EXPANDED_REGION;\n const chunked = rangeSize > expansionLineCount;\n const collapsedLines = Math.max(\n !expandUnchanged\n ? rangeSize - (expandedRegion.fromEnd + expandedRegion.fromStart)\n : 0,\n 0\n );\n\n const pushHunkSeparator = ({ type, linesAST }: PushHunkSeparatorProps) => {\n if (hunkSeparators === 'line-info' || hunkSeparators === 'custom') {\n const slotName = getHunkSeparatorSlotName(type, hunkIndex);\n linesAST.push(\n createSeparator({\n type: hunkSeparators,\n content: getModifiedLinesString(collapsedLines),\n expandIndex: expandable ? hunkIndex : undefined,\n chunked,\n slotName,\n isFirstHunk,\n isLastHunk,\n })\n );\n hunkData.push({\n slotName,\n hunkIndex,\n lines: collapsedLines,\n type,\n expandable: expandable\n ? {\n up: expandable && !isFirstHunk,\n down: expandable,\n chunked,\n }\n : undefined,\n });\n } else if (hunkSeparators === 'metadata' && hunkSpecs != null) {\n linesAST.push(\n createSeparator({\n type: 'metadata',\n content: hunkSpecs,\n isFirstHunk,\n isLastHunk,\n })\n );\n } else if (hunkSeparators === 'simple' && hunkIndex > 0) {\n linesAST.push(\n createSeparator({ type: 'simple', isFirstHunk, isLastHunk: false })\n );\n }\n };\n\n const renderRange = ({ rangeLen, fromStart }: RenderRangeProps) => {\n if (ast.newLines == null || ast.oldLines == null) {\n return;\n }\n\n const offset = isLastHunk ? 0 : fromStart ? rangeSize : rangeLen;\n let dLineNumber = deletionLineNumber - offset;\n let aLineNumber = additionLineNumber - offset;\n let lIndex = lineIndex - offset;\n\n for (let i = 0; i < rangeLen; i++) {\n const oldLine = ast.oldLines[dLineNumber];\n const newLine = ast.newLines[aLineNumber];\n if (oldLine == null || newLine == null) {\n console.error({ aLineNumber, dLineNumber, ast });\n throw new Error(\n 'DiffHunksRenderer.renderHunks prefill context invalid. Must include data for old and new lines'\n );\n }\n dLineNumber++;\n aLineNumber++;\n\n if (diffStyle === 'unified') {\n this.pushLineWithAnnotation({\n newLine,\n unifiedAST,\n unifiedSpan: this.getAnnotations(\n 'unified',\n dLineNumber,\n aLineNumber,\n hunkIndex,\n lIndex\n ),\n });\n } else {\n this.pushLineWithAnnotation({\n newLine,\n oldLine,\n additionsAST,\n deletionsAST,\n ...this.getAnnotations(\n 'split',\n dLineNumber,\n aLineNumber,\n hunkIndex,\n lIndex\n ),\n });\n }\n lIndex++;\n }\n };\n\n if (expandable) {\n renderRange({\n rangeLen: Math.min(\n collapsedLines === 0 || expandUnchanged\n ? rangeSize\n : expandedRegion.fromStart,\n rangeSize\n ),\n fromStart: true,\n });\n }\n\n if (collapsedLines > 0) {\n if (diffStyle === 'unified') {\n pushHunkSeparator({ type: 'unified', linesAST: unifiedAST });\n } else {\n pushHunkSeparator({ type: 'deletions', linesAST: deletionsAST });\n pushHunkSeparator({ type: 'additions', linesAST: additionsAST });\n }\n }\n\n if (collapsedLines > 0 && expandedRegion.fromEnd > 0 && !isLastHunk) {\n renderRange({\n rangeLen: Math.min(expandedRegion.fromEnd, rangeSize),\n fromStart: false,\n });\n }\n }\n\n private renderHunks({\n hunk,\n hunkData,\n hunkIndex,\n lineIndex,\n isLastHunk,\n prevHunk,\n ast,\n deletionsAST,\n additionsAST,\n unifiedAST,\n }: RenderHunkProps): number {\n const { diffStyle } = this.getOptionsWithDefaults();\n const unified = diffStyle === 'unified';\n let additionLineNumber = hunk.additionStart - 1;\n let deletionLineNumber = hunk.deletionStart - 1;\n\n this.renderCollapsedHunks({\n additionLineNumber,\n additionsAST,\n ast,\n deletionLineNumber,\n deletionsAST,\n hunkData,\n hunkIndex,\n hunkSpecs: hunk.hunkSpecs,\n isFirstHunk: prevHunk == null,\n isLastHunk: false,\n lineIndex,\n rangeSize: Math.max(hunk.collapsedBefore, 0),\n unifiedAST,\n });\n\n let { oldLines, newLines, oldIndex, newIndex } = (() => {\n if (ast.hunks != null) {\n const lineHunk = ast.hunks[hunkIndex];\n if (lineHunk == null) {\n console.error({ ast, hunkIndex });\n throw new Error(\n `DiffHunksRenderer.renderHunks: lineHunk doesn't exist`\n );\n }\n return {\n oldLines: lineHunk.oldLines,\n newLines: lineHunk.newLines,\n oldIndex: 0,\n newIndex: 0,\n };\n }\n return {\n oldLines: ast.oldLines,\n newLines: ast.newLines,\n oldIndex: deletionLineNumber,\n newIndex: additionLineNumber,\n };\n })();\n\n // Render hunk/diff content\n for (const hunkContent of hunk.hunkContent) {\n if (hunkContent.type === 'context') {\n const { length: len } = hunkContent.lines;\n for (let i = 0; i < len; i++) {\n const oldLine = oldLines[oldIndex];\n const newLine = newLines[newIndex];\n oldIndex++;\n newIndex++;\n additionLineNumber++;\n deletionLineNumber++;\n if (unified) {\n if (newLine == null) {\n throw new Error(\n 'DiffHunksRenderer.renderHunks: newLine doesnt exist for context...'\n );\n }\n this.pushLineWithAnnotation({\n newLine,\n unifiedAST,\n unifiedSpan: this.getAnnotations(\n 'unified',\n deletionLineNumber,\n additionLineNumber,\n hunkIndex,\n lineIndex\n ),\n });\n } else {\n if (newLine == null || oldLine == null) {\n throw new Error(\n 'DiffHunksRenderer.renderHunks: newLine or oldLine doesnt exist for context...'\n );\n }\n this.pushLineWithAnnotation({\n oldLine,\n newLine,\n deletionsAST,\n additionsAST,\n ...this.getAnnotations(\n 'split',\n deletionLineNumber,\n additionLineNumber,\n hunkIndex,\n lineIndex\n ),\n });\n }\n lineIndex++;\n }\n if (hunkContent.noEOFCR) {\n const node = createNoNewlineElement('context');\n if (unified) {\n unifiedAST.push(node);\n } else {\n deletionsAST.push(node);\n additionsAST.push(node);\n }\n }\n } else {\n const { length: dLen } = hunkContent.deletions;\n const { length: aLen } = hunkContent.additions;\n const len = unified ? dLen + aLen : Math.max(dLen, aLen);\n let spanSize = 0;\n for (let i = 0; i < len; i++) {\n const { oldLine, newLine } = (() => {\n let oldLine: ElementContent | undefined = oldLines[oldIndex];\n let newLine: ElementContent | undefined = newLines[newIndex];\n if (unified) {\n if (i < dLen) {\n newLine = undefined;\n } else {\n oldLine = undefined;\n }\n } else {\n if (i >= dLen) {\n oldLine = undefined;\n }\n if (i >= aLen) {\n newLine = undefined;\n }\n }\n if (oldLine == null && newLine == null) {\n console.error({ i, len, ast, hunkContent });\n throw new Error(\n 'renderHunks: oldLine and newLine are null, something is wrong'\n );\n }\n return { oldLine, newLine };\n })();\n\n if (oldLine != null) {\n oldIndex++;\n deletionLineNumber++;\n }\n if (newLine != null) {\n newIndex++;\n additionLineNumber++;\n }\n\n if (unified) {\n this.pushLineWithAnnotation({\n oldLine,\n newLine,\n unifiedAST,\n unifiedSpan: this.getAnnotations(\n 'unified',\n oldLine != null ? deletionLineNumber : undefined,\n newLine != null ? additionLineNumber : undefined,\n hunkIndex,\n lineIndex\n ),\n });\n lineIndex++;\n } else {\n if (oldLine == null || newLine == null) {\n spanSize++;\n }\n const annotationSpans = this.getAnnotations(\n 'split',\n oldLine != null ? deletionLineNumber : undefined,\n newLine != null ? additionLineNumber : undefined,\n hunkIndex,\n lineIndex\n );\n if (annotationSpans != null) {\n if (spanSize > 0) {\n if (aLen > dLen) {\n deletionsAST.push(createEmptyRowBuffer(spanSize));\n } else {\n additionsAST.push(createEmptyRowBuffer(spanSize));\n }\n spanSize = 0;\n }\n }\n this.pushLineWithAnnotation({\n newLine,\n oldLine,\n deletionsAST,\n additionsAST,\n ...annotationSpans,\n });\n lineIndex++;\n }\n }\n if (!unified) {\n if (spanSize > 0) {\n if (aLen > dLen) {\n deletionsAST.push(createEmptyRowBuffer(spanSize));\n } else {\n additionsAST.push(createEmptyRowBuffer(spanSize));\n }\n spanSize = 0;\n }\n if (hunkContent.noEOFCRDeletions) {\n deletionsAST.push(createNoNewlineElement('change-deletion'));\n if (!hunkContent.noEOFCRAdditions) {\n additionsAST.push(createEmptyRowBuffer(1));\n }\n }\n if (hunkContent.noEOFCRAdditions) {\n additionsAST.push(createNoNewlineElement('change-addition'));\n if (!hunkContent.noEOFCRDeletions) {\n deletionsAST.push(createEmptyRowBuffer(1));\n }\n }\n }\n }\n }\n\n if (isLastHunk && ast.newLines != null && ast.newLines.length > 0) {\n this.renderCollapsedHunks({\n additionLineNumber,\n additionsAST,\n ast,\n deletionLineNumber,\n deletionsAST,\n hunkData,\n hunkIndex: hunkIndex + 1,\n hunkSpecs: undefined,\n isFirstHunk: false,\n isLastHunk: true,\n lineIndex,\n rangeSize: Math.max(\n ast.newLines.length -\n Math.max(hunk.additionStart + hunk.additionCount - 1, 0),\n 0\n ),\n unifiedAST,\n });\n }\n return lineIndex;\n }\n\n private pushLineWithAnnotation({\n newLine,\n oldLine,\n unifiedAST,\n additionsAST,\n deletionsAST,\n unifiedSpan,\n deletionSpan,\n additionSpan,\n }: PushLineWithAnnotation) {\n if (unifiedAST != null) {\n if (oldLine != null) {\n unifiedAST.push(oldLine);\n } else if (newLine != null) {\n unifiedAST.push(newLine);\n }\n if (unifiedSpan != null) {\n unifiedAST.push(createAnnotationElement(unifiedSpan));\n }\n } else if (deletionsAST != null && additionsAST != null) {\n if (oldLine != null) {\n deletionsAST.push(oldLine);\n }\n if (newLine != null) {\n additionsAST.push(newLine);\n }\n if (deletionSpan != null) {\n deletionsAST.push(createAnnotationElement(deletionSpan));\n }\n if (additionSpan != null) {\n additionsAST.push(createAnnotationElement(additionSpan));\n }\n }\n }\n\n private getAnnotations(\n type: 'unified',\n oldLineNumber: number | undefined,\n newLineNumber: number | undefined,\n hunkIndex: number,\n lineIndex: number\n ): AnnotationSpan | undefined;\n private getAnnotations(\n type: 'split',\n oldLineNumber: number | undefined,\n newLineNumber: number | undefined,\n hunkIndex: number,\n lineIndex: number\n ): { deletionSpan: AnnotationSpan; additionSpan: AnnotationSpan } | undefined;\n private getAnnotations(\n type: 'unified' | 'split',\n oldLineNumber: number | undefined,\n newLineNumber: number | undefined,\n hunkIndex: number,\n lineIndex: number\n ):\n | AnnotationSpan\n | { deletionSpan: AnnotationSpan; additionSpan: AnnotationSpan }\n | undefined {\n const deletionSpan: AnnotationSpan = {\n type: 'annotation',\n hunkIndex,\n lineIndex,\n annotations: [],\n };\n if (oldLineNumber != null) {\n for (const anno of this.deletionAnnotations[oldLineNumber] ?? []) {\n deletionSpan.annotations.push(getLineAnnotationName(anno));\n }\n }\n const additionSpan: AnnotationSpan = {\n type: 'annotation',\n hunkIndex,\n lineIndex,\n annotations: [],\n };\n if (newLineNumber != null) {\n for (const anno of this.additionAnnotations[newLineNumber] ?? []) {\n (type === 'unified' ? deletionSpan : additionSpan).annotations.push(\n getLineAnnotationName(anno)\n );\n }\n }\n if (type === 'unified') {\n if (deletionSpan.annotations.length > 0) {\n return deletionSpan;\n }\n return undefined;\n }\n if (\n additionSpan.annotations.length === 0 &&\n deletionSpan.annotations.length === 0\n ) {\n return undefined;\n }\n return { deletionSpan, additionSpan };\n }\n\n private renderHeader(\n diff: FileDiffMetadata,\n themeStyles: string,\n baseThemeType: 'light' | 'dark' | undefined\n ): HASTElement {\n const { themeType } = this.getOptionsWithDefaults();\n return createFileHeaderElement({\n fileOrDiff: diff,\n themeStyles,\n themeType: baseThemeType ?? themeType,\n });\n }\n}\n\nfunction areRenderOptionsEqual(\n optionsA: RenderDiffOptions,\n optionsB: RenderDiffOptions\n): boolean {\n return (\n areThemesEqual(optionsA.theme, optionsB.theme) &&\n optionsA.tokenizeMaxLineLength === optionsB.tokenizeMaxLineLength &&\n optionsA.lineDiffType === optionsB.lineDiffType\n );\n}\n\nfunction getModifiedLinesString(lines: number) {\n return `${lines} unmodified line${lines > 1 ? 's' : ''}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA6CA,MAAMA,kBAAmC;CACvC,WAAW;CACX,SAAS;CACV;AAoFD,IAAa,oBAAb,MAAwD;CACtD,AAAQ;CACR,AAAQ;CAER,AAAQ,gCAAgB,IAAI,KAA8B;CAE1D,AAAQ,sBAAsD,EAAE;CAChE,AAAQ,sBAAsD,EAAE;CAEhE,AAAQ,eAAmC;CAC3C,AAAQ;CAER,YACE,AAAOC,UAA2B,EAAE,OAAO,gBAAgB,EAC3D,AAAQC,gBACR,AAAQC,eACR;EAHO;EACC;EACA;AAER,MAAI,eAAe,eAAe,KAAK,KACrC,MAAK,cAAc,kBAAkB,QAAQ,SAAS,eAAe,GACjE,wBAAwB,GACxB;;CAIR,UAAgB;AACd,OAAK,cAAc;AACnB,OAAK,OAAO;AACZ,OAAK,cAAc;AACnB,OAAK,gBAAgB;AACrB,OAAK,iBAAiB;;CAGxB,WAAW,SAAgC;AACzC,OAAK,UAAU;;CAGjB,AAAQ,aAAa,SAAmC;AACtD,OAAK,UAAU;GAAE,GAAG,KAAK;GAAS,GAAG;GAAS;;CAGhD,aAAa,WAA6B;AACxC,MAAI,KAAK,wBAAwB,CAAC,cAAc,UAC9C;AAEF,OA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kB,EAAE,CAC9D,EAAC,SAAS,YAAY,eAAe,cAAc,YAAY,KAC7D,sBAAsB,KAAK,CAC5B;AAGL,MAAI,SAAS,WAAW;AACtB,OAAI,aAAa,YAAY,SAAS,EACpC,QAAO;AAET;;AAEF,MACE,aAAa,YAAY,WAAW,KACpC,aAAa,YAAY,WAAW,EAEpC;AAEF,SAAO;GAAE;GAAc;GAAc;;CAGvC,AAAQ,aACN,MACA,aACA,eACa;EACb,MAAM,EAAE,cAAc,KAAK,wBAAwB;AACnD,SAAO,wBAAwB;GAC7B,YAAY;GACZ;GACA,WAAW,iBAAiB;GAC7B,CAAC;;;AAIN,SAAS,sBACP,UACA,UACS;AACT,QACE,eAAe,SAAS,OAAO,SAAS,MAAM,IAC9C,SAAS,0BAA0B,SAAS,yBAC5C,SAAS,iBAAiB,SAAS;;AAIvC,SAAS,uBAAuB,OAAe;AAC7C,QAAO,GAAG,MAAM,kBAAkB,QAAQ,IAAI,MAAM"}
|
|
1
|
+
{"version":3,"file":"DiffHunksRenderer.js","names":["EXPANDED_REGION: ExpansionRegion","options: BaseDiffOptions","onRenderUpdate?: () => unknown","workerManager?: WorkerPoolManager | undefined","options","options: RenderDiffOptions","additionsAST: ElementContent[] | undefined","deletionsAST: ElementContent[] | undefined","unifiedAST: ElementContent[] | undefined","hunkData: HunkData[]","prevHunk: Hunk | undefined","oldLine: ElementContent | undefined","newLine: ElementContent | undefined","oldLine","newLine","deletionSpan: AnnotationSpan","additionSpan: AnnotationSpan"],"sources":["../../src/renderers/DiffHunksRenderer.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\nimport { DEFAULT_THEMES } from '../constants';\nimport { areLanguagesAttached } from '../highlighter/languages/areLanguagesAttached';\nimport {\n getHighlighterIfLoaded,\n getSharedHighlighter,\n} from '../highlighter/shared_highlighter';\nimport { areThemesAttached } from '../highlighter/themes/areThemesAttached';\nimport type {\n AnnotationLineMap,\n AnnotationSpan,\n BaseDiffOptions,\n DiffLineAnnotation,\n DiffsHighlighter,\n ExpansionDirections,\n FileDiffMetadata,\n Hunk,\n HunkData,\n RenderDiffFilesResult,\n RenderDiffHunksResult,\n RenderDiffOptions,\n RenderDiffResult,\n RenderedDiffASTCache,\n SupportedLanguages,\n ThemeTypes,\n ThemedDiffResult,\n} from '../types';\nimport { areThemesEqual } from '../utils/areThemesEqual';\nimport { createAnnotationElement } from '../utils/createAnnotationElement';\nimport { createEmptyRowBuffer } from '../utils/createEmptyRowBuffer';\nimport { createFileHeaderElement } from '../utils/createFileHeaderElement';\nimport { createNoNewlineElement } from '../utils/createNoNewlineElement';\nimport { createPreElement } from '../utils/createPreElement';\nimport { createSeparator } from '../utils/createSeparator';\nimport { getFiletypeFromFileName } from '../utils/getFiletypeFromFileName';\nimport { getHighlighterOptions } from '../utils/getHighlighterOptions';\nimport { getHunkSeparatorSlotName } from '../utils/getHunkSeparatorSlotName';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport { getTotalLineCountFromHunks } from '../utils/getTotalLineCountFromHunks';\nimport { createHastElement } from '../utils/hast_utils';\nimport { renderDiffWithHighlighter } from '../utils/renderDiffWithHighlighter';\nimport type { WorkerPoolManager } from '../worker';\n\nconst EXPANDED_REGION: ExpansionRegion = {\n fromStart: 0,\n fromEnd: 0,\n};\n\ninterface PushHunkSeparatorProps {\n type: 'additions' | 'deletions' | 'unified';\n linesAST: ElementContent[];\n}\n\ninterface RenderRangeProps {\n rangeLen: number;\n fromStart: boolean;\n}\n\ninterface PushLineWithAnnotation {\n newLine?: ElementContent;\n oldLine?: ElementContent;\n\n unifiedAST?: ElementContent[];\n deletionsAST?: ElementContent[];\n additionsAST?: ElementContent[];\n\n unifiedSpan?: AnnotationSpan;\n deletionSpan?: AnnotationSpan;\n additionSpan?: AnnotationSpan;\n}\n\ninterface RenderCollapsedHunksProps {\n ast: RenderDiffFilesResult | RenderDiffHunksResult;\n hunkData: HunkData[];\n hunkIndex: number;\n hunkSpecs: string | undefined;\n isFirstHunk: boolean;\n isLastHunk: boolean;\n rangeSize: number;\n\n lineIndex: number;\n additionLineNumber: number;\n deletionLineNumber: number;\n\n additionsAST: ElementContent[];\n deletionsAST: ElementContent[];\n unifiedAST: ElementContent[];\n}\n\ninterface RenderHunkProps {\n hunk: Hunk;\n hunkData: HunkData[];\n hunkIndex: number;\n lineIndex: number;\n isLastHunk: boolean;\n prevHunk: Hunk | undefined;\n\n ast: RenderDiffFilesResult | RenderDiffHunksResult;\n unifiedAST: ElementContent[];\n deletionsAST: ElementContent[];\n additionsAST: ElementContent[];\n}\n\ninterface GetRenderOptionsReturn {\n options: RenderDiffOptions;\n forceRender: boolean;\n}\n\ntype OptionsWithDefaults = Required<\n Omit<BaseDiffOptions, 'lang' | 'unsafeCSS'>\n>;\n\ninterface ExpansionRegion {\n fromStart: number;\n fromEnd: number;\n}\n\nexport interface HunksRenderResult {\n additionsAST: ElementContent[] | undefined;\n deletionsAST: ElementContent[] | undefined;\n unifiedAST: ElementContent[] | undefined;\n hunkData: HunkData[];\n css: string;\n preNode: HASTElement;\n headerElement: HASTElement | undefined;\n totalLines: number;\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n}\n\nexport class DiffHunksRenderer<LAnnotation = undefined> {\n private highlighter: DiffsHighlighter | undefined;\n private diff: FileDiffMetadata | undefined;\n\n private expandedHunks = new Map<number, ExpansionRegion>();\n\n private deletionAnnotations: AnnotationLineMap<LAnnotation> = {};\n private additionAnnotations: AnnotationLineMap<LAnnotation> = {};\n\n private computedLang: SupportedLanguages = 'text';\n private renderCache: RenderedDiffASTCache | undefined;\n\n constructor(\n public options: BaseDiffOptions = { theme: DEFAULT_THEMES },\n private onRenderUpdate?: () => unknown,\n private workerManager?: WorkerPoolManager | undefined\n ) {\n if (workerManager?.isWorkingPool() !== true) {\n this.highlighter = areThemesAttached(options.theme ?? DEFAULT_THEMES)\n ? getHighlighterIfLoaded()\n : undefined;\n }\n }\n\n cleanUp(): void {\n this.highlighter = undefined;\n this.diff = undefined;\n this.renderCache = undefined;\n this.workerManager = undefined;\n this.onRenderUpdate = undefined;\n }\n\n setOptions(options: BaseDiffOptions): void {\n this.options = options;\n }\n\n private mergeOptions(options: Partial<BaseDiffOptions>) {\n this.options = { ...this.options, ...options };\n }\n\n setThemeType(themeType: ThemeTypes): void {\n if (this.getOptionsWithDefaults().themeType === themeType) {\n return;\n }\n this.mergeOptions({ themeType });\n }\n\n expandHunk(index: number, direction: ExpansionDirections): void {\n const { expansionLineCount } = this.getOptionsWithDefaults();\n const region = this.expandedHunks.get(index) ?? {\n fromStart: 0,\n fromEnd: 0,\n };\n if (direction === 'up' || direction === 'both') {\n region.fromStart += expansionLineCount;\n }\n if (direction === 'down' || direction === 'both') {\n region.fromEnd += expansionLineCount;\n }\n this.expandedHunks.set(index, region);\n }\n\n setLineAnnotations(lineAnnotations: DiffLineAnnotation<LAnnotation>[]): void {\n this.additionAnnotations = {};\n this.deletionAnnotations = {};\n for (const annotation of lineAnnotations) {\n const map = ((): AnnotationLineMap<LAnnotation> => {\n switch (annotation.side) {\n case 'deletions':\n return this.deletionAnnotations;\n case 'additions':\n return this.additionAnnotations;\n }\n })();\n const arr = map[annotation.lineNumber] ?? [];\n map[annotation.lineNumber] = arr;\n arr.push(annotation);\n }\n }\n\n getOptionsWithDefaults(): OptionsWithDefaults {\n const {\n diffIndicators = 'bars',\n diffStyle = 'split',\n disableBackground = false,\n disableFileHeader = false,\n disableLineNumbers = false,\n expandUnchanged = false,\n expansionLineCount = 100,\n hunkSeparators = 'line-info',\n lineDiffType = 'word-alt',\n maxLineDiffLength = 1000,\n overflow = 'scroll',\n theme = DEFAULT_THEMES,\n themeType = 'system',\n tokenizeMaxLineLength = 1000,\n useCSSClasses = false,\n } = this.options;\n return {\n diffIndicators,\n diffStyle,\n disableBackground,\n disableFileHeader,\n disableLineNumbers,\n expandUnchanged,\n expansionLineCount,\n hunkSeparators,\n lineDiffType,\n maxLineDiffLength,\n overflow,\n theme: this.workerManager?.getDiffRenderOptions().theme ?? theme,\n themeType,\n tokenizeMaxLineLength,\n useCSSClasses,\n };\n }\n\n async initializeHighlighter(): Promise<DiffsHighlighter> {\n this.highlighter = await getSharedHighlighter(\n getHighlighterOptions(this.computedLang, this.options)\n );\n return this.highlighter;\n }\n\n hydrate(diff: FileDiffMetadata | undefined): void {\n if (diff == null) {\n return;\n }\n this.diff = diff;\n const { options } = this.getRenderOptions(diff);\n let cache = this.workerManager?.getDiffResultCache(diff);\n if (cache != null && !areRenderOptionsEqual(options, cache.options)) {\n cache = undefined;\n }\n this.renderCache ??= {\n diff,\n // NOTE(amadeus): If we're hydrating, we can assume there was\n // pre-rendered HTML, otherwise one should not be hydrating\n highlighted: true,\n options,\n result: cache?.result,\n };\n if (\n this.workerManager?.isWorkingPool() === true &&\n this.renderCache.result == null\n ) {\n this.workerManager.highlightDiffAST(this, this.diff);\n } else {\n void this.asyncHighlight(diff).then(({ result, options }) => {\n this.onHighlightSuccess(diff, result, options);\n });\n }\n }\n\n private getRenderOptions(diff: FileDiffMetadata): GetRenderOptionsReturn {\n const options: RenderDiffOptions = (() => {\n if (this.workerManager?.isWorkingPool() === true) {\n return this.workerManager.getDiffRenderOptions();\n }\n const { theme, tokenizeMaxLineLength, lineDiffType } =\n this.getOptionsWithDefaults();\n return { theme, tokenizeMaxLineLength, lineDiffType };\n })();\n this.getOptionsWithDefaults();\n const { renderCache } = this;\n if (renderCache?.result == null) {\n return { options, forceRender: true };\n }\n if (\n diff !== renderCache.diff ||\n !areRenderOptionsEqual(options, renderCache.options)\n ) {\n return { options, forceRender: true };\n }\n return { options, forceRender: false };\n }\n\n renderDiff(\n diff: FileDiffMetadata | undefined = this.renderCache?.diff\n ): HunksRenderResult | undefined {\n if (diff == null) {\n return undefined;\n }\n const cache = this.workerManager?.getDiffResultCache(diff);\n if (cache != null && this.renderCache == null) {\n this.renderCache = { diff, highlighted: true, ...cache };\n }\n const { options, forceRender } = this.getRenderOptions(diff);\n this.renderCache ??= {\n diff,\n highlighted: false,\n options,\n result: undefined,\n };\n if (this.workerManager?.isWorkingPool() === true) {\n this.renderCache.result ??= this.workerManager.getPlainDiffAST(diff);\n if (!this.renderCache.highlighted || forceRender) {\n this.workerManager.highlightDiffAST(this, diff);\n }\n } else {\n this.computedLang = diff.lang ?? getFiletypeFromFileName(diff.name);\n const hasThemes =\n this.highlighter != null && areThemesAttached(options.theme);\n const hasLangs =\n this.highlighter != null && areLanguagesAttached(this.computedLang);\n\n // If we have any semblance of a highlighter with the correct theme(s)\n // attached, we can kick off some form of rendering. If we don't have\n // the correct language, then we can render plain text and after kick off\n // an async job to get the highlighted AST\n if (\n this.highlighter != null &&\n hasThemes &&\n (forceRender ||\n (!this.renderCache.highlighted && hasLangs) ||\n this.renderCache.result == null)\n ) {\n const { result, options } = this.renderDiffWithHighlighter(\n diff,\n this.highlighter,\n !hasLangs\n );\n this.renderCache = {\n diff,\n options,\n highlighted: hasLangs,\n result,\n };\n }\n\n // If we get in here it means we'll have to kick off an async highlight\n // process which will involve initializing the highlighter with new themes\n // and languages\n if (!hasThemes || !hasLangs) {\n void this.asyncHighlight(diff).then(({ result, options }) => {\n this.onHighlightSuccess(diff, result, options);\n });\n }\n }\n return this.renderCache.result != null\n ? this.processDiffResult(this.renderCache.diff, this.renderCache.result)\n : undefined;\n }\n\n async asyncRender(diff: FileDiffMetadata): Promise<HunksRenderResult> {\n const { result } = await this.asyncHighlight(diff);\n return this.processDiffResult(diff, result);\n }\n\n private createPreElement(\n split: boolean,\n totalLines: number,\n themeStyles: string,\n baseThemeType: 'light' | 'dark' | undefined\n ): HASTElement {\n const {\n diffIndicators,\n disableBackground,\n disableLineNumbers,\n overflow,\n themeType,\n } = this.getOptionsWithDefaults();\n return createPreElement({\n diffIndicators,\n disableBackground,\n disableLineNumbers,\n overflow,\n themeStyles,\n split,\n themeType: baseThemeType ?? themeType,\n totalLines,\n });\n }\n\n private async asyncHighlight(\n diff: FileDiffMetadata\n ): Promise<RenderDiffResult> {\n this.computedLang = diff.lang ?? getFiletypeFromFileName(diff.name);\n const hasThemes =\n this.highlighter != null &&\n areThemesAttached(this.options.theme ?? DEFAULT_THEMES);\n const hasLangs =\n this.highlighter != null && areLanguagesAttached(this.computedLang);\n // If we don't have the required langs or themes, then we need to\n // initialize the highlighter to load the appropriate languages and themes\n if (this.highlighter == null || !hasThemes || !hasLangs) {\n this.highlighter = await this.initializeHighlighter();\n }\n return this.renderDiffWithHighlighter(diff, this.highlighter);\n }\n\n private renderDiffWithHighlighter(\n diff: FileDiffMetadata,\n highlighter: DiffsHighlighter,\n plainText = false\n ): RenderDiffResult {\n const { options } = this.getRenderOptions(diff);\n const result = renderDiffWithHighlighter(\n diff,\n highlighter,\n options,\n plainText\n );\n return { result, options };\n }\n\n onHighlightSuccess(\n diff: FileDiffMetadata,\n result: ThemedDiffResult,\n options: RenderDiffOptions\n ): void {\n // If renderCache was blown away, we can assume we've run cleanUp()\n if (this.renderCache == null) {\n return;\n }\n const triggerRenderUpdate =\n this.renderCache.diff !== diff ||\n !this.renderCache.highlighted ||\n !areRenderOptionsEqual(this.renderCache.options, options);\n\n this.renderCache = {\n diff,\n options,\n highlighted: true,\n result,\n };\n if (triggerRenderUpdate) {\n this.onRenderUpdate?.();\n }\n }\n\n onHighlightError(error: unknown): void {\n console.error(error);\n }\n\n private processDiffResult(\n fileDiff: FileDiffMetadata,\n { code, themeStyles, baseThemeType }: ThemedDiffResult\n ): HunksRenderResult {\n const { diffStyle, disableFileHeader } = this.getOptionsWithDefaults();\n\n this.diff = fileDiff;\n const unified = diffStyle === 'unified';\n\n let additionsAST: ElementContent[] | undefined = [];\n let deletionsAST: ElementContent[] | undefined = [];\n let unifiedAST: ElementContent[] | undefined = [];\n\n let hunkIndex = 0;\n const hunkData: HunkData[] = [];\n\n let prevHunk: Hunk | undefined;\n let lineIndex = 0;\n for (const hunk of fileDiff.hunks) {\n lineIndex += hunk.collapsedBefore;\n lineIndex = this.renderHunks({\n ast: code,\n hunk,\n prevHunk,\n hunkIndex,\n isLastHunk: hunkIndex === fileDiff.hunks.length - 1,\n additionsAST,\n deletionsAST,\n unifiedAST,\n hunkData,\n lineIndex,\n });\n hunkIndex++;\n prevHunk = hunk;\n }\n\n const totalLines = Math.max(\n getTotalLineCountFromHunks(fileDiff.hunks),\n fileDiff.newLines?.length ?? 0,\n fileDiff.oldLines?.length ?? 0\n );\n\n additionsAST =\n !unified && (code.hunks != null || code.newLines.length > 0)\n ? additionsAST\n : undefined;\n deletionsAST =\n !unified && (code.hunks != null || code.oldLines.length > 0)\n ? deletionsAST\n : undefined;\n unifiedAST = unifiedAST.length > 0 ? unifiedAST : undefined;\n\n const preNode = this.createPreElement(\n deletionsAST != null && additionsAST != null,\n totalLines,\n themeStyles,\n baseThemeType\n );\n\n return {\n additionsAST,\n deletionsAST,\n unifiedAST,\n hunkData,\n preNode,\n themeStyles,\n baseThemeType,\n headerElement: !disableFileHeader\n ? this.renderHeader(this.diff, themeStyles, baseThemeType)\n : undefined,\n totalLines,\n // FIXME\n css: '',\n };\n }\n\n renderFullAST(\n result: HunksRenderResult,\n children: ElementContent[] = []\n ): HASTElement {\n if (result.unifiedAST != null) {\n children.push(\n createHastElement({\n tagName: 'code',\n children: result.unifiedAST,\n properties: {\n 'data-code': '',\n 'data-unified': '',\n },\n })\n );\n }\n if (result.deletionsAST != null) {\n children.push(\n createHastElement({\n tagName: 'code',\n children: result.deletionsAST,\n properties: {\n 'data-code': '',\n 'data-deletions': '',\n },\n })\n );\n }\n if (result.additionsAST != null) {\n children.push(\n createHastElement({\n tagName: 'code',\n children: result.additionsAST,\n properties: {\n 'data-code': '',\n 'data-additions': '',\n },\n })\n );\n }\n return { ...result.preNode, children };\n }\n\n renderFullHTML(\n result: HunksRenderResult,\n tempChildren: ElementContent[] = []\n ): string {\n return toHtml(this.renderFullAST(result, tempChildren));\n }\n\n renderPartialHTML(\n children: ElementContent[],\n columnType?: 'unified' | 'deletions' | 'additions'\n ): string {\n if (columnType == null) {\n return toHtml(children);\n }\n return toHtml(\n createHastElement({\n tagName: 'code',\n children,\n properties: {\n 'data-code': '',\n [`data-${columnType}`]: '',\n },\n })\n );\n }\n\n private renderCollapsedHunks({\n ast,\n hunkData,\n hunkIndex,\n hunkSpecs,\n isFirstHunk,\n isLastHunk,\n rangeSize,\n lineIndex,\n additionLineNumber,\n deletionLineNumber,\n unifiedAST,\n deletionsAST,\n additionsAST,\n }: RenderCollapsedHunksProps) {\n if (rangeSize <= 0) {\n return;\n }\n const { hunkSeparators, expandUnchanged, diffStyle, expansionLineCount } =\n this.getOptionsWithDefaults();\n const expandable =\n ast.hunks == null && ast.newLines.length > 0 && ast.oldLines.length > 0;\n const expandedRegion = this.expandedHunks.get(hunkIndex) ?? EXPANDED_REGION;\n const chunked = rangeSize > expansionLineCount;\n const collapsedLines = Math.max(\n !expandUnchanged\n ? rangeSize - (expandedRegion.fromEnd + expandedRegion.fromStart)\n : 0,\n 0\n );\n\n const pushHunkSeparator = ({ type, linesAST }: PushHunkSeparatorProps) => {\n if (hunkSeparators === 'line-info' || hunkSeparators === 'custom') {\n const slotName = getHunkSeparatorSlotName(type, hunkIndex);\n linesAST.push(\n createSeparator({\n type: hunkSeparators,\n content: getModifiedLinesString(collapsedLines),\n expandIndex: expandable ? hunkIndex : undefined,\n chunked,\n slotName,\n isFirstHunk,\n isLastHunk,\n })\n );\n hunkData.push({\n slotName,\n hunkIndex,\n lines: collapsedLines,\n type,\n expandable: expandable\n ? {\n up: expandable && !isFirstHunk,\n down: expandable,\n chunked,\n }\n : undefined,\n });\n } else if (hunkSeparators === 'metadata' && hunkSpecs != null) {\n linesAST.push(\n createSeparator({\n type: 'metadata',\n content: hunkSpecs,\n isFirstHunk,\n isLastHunk,\n })\n );\n } else if (hunkSeparators === 'simple' && hunkIndex > 0) {\n linesAST.push(\n createSeparator({ type: 'simple', isFirstHunk, isLastHunk: false })\n );\n }\n };\n\n const renderRange = ({ rangeLen, fromStart }: RenderRangeProps) => {\n if (ast.newLines == null || ast.oldLines == null) {\n return;\n }\n\n const offset = isLastHunk ? 0 : fromStart ? rangeSize : rangeLen;\n let dLineNumber = deletionLineNumber - offset;\n let aLineNumber = additionLineNumber - offset;\n let lIndex = lineIndex - offset;\n\n for (let i = 0; i < rangeLen; i++) {\n const oldLine = ast.oldLines[dLineNumber];\n const newLine = ast.newLines[aLineNumber];\n if (oldLine == null || newLine == null) {\n console.error({ aLineNumber, dLineNumber, ast });\n throw new Error(\n 'DiffHunksRenderer.renderHunks prefill context invalid. Must include data for old and new lines'\n );\n }\n dLineNumber++;\n aLineNumber++;\n\n if (diffStyle === 'unified') {\n this.pushLineWithAnnotation({\n newLine,\n unifiedAST,\n unifiedSpan: this.getAnnotations(\n 'unified',\n dLineNumber,\n aLineNumber,\n hunkIndex,\n lIndex\n ),\n });\n } else {\n this.pushLineWithAnnotation({\n newLine,\n oldLine,\n additionsAST,\n deletionsAST,\n ...this.getAnnotations(\n 'split',\n dLineNumber,\n aLineNumber,\n hunkIndex,\n lIndex\n ),\n });\n }\n lIndex++;\n }\n };\n\n if (expandable) {\n renderRange({\n rangeLen: Math.min(\n collapsedLines === 0 || expandUnchanged\n ? rangeSize\n : expandedRegion.fromStart,\n rangeSize\n ),\n fromStart: true,\n });\n }\n\n if (collapsedLines > 0) {\n if (diffStyle === 'unified') {\n pushHunkSeparator({ type: 'unified', linesAST: unifiedAST });\n } else {\n pushHunkSeparator({ type: 'deletions', linesAST: deletionsAST });\n pushHunkSeparator({ type: 'additions', linesAST: additionsAST });\n }\n }\n\n if (collapsedLines > 0 && expandedRegion.fromEnd > 0 && !isLastHunk) {\n renderRange({\n rangeLen: Math.min(expandedRegion.fromEnd, rangeSize),\n fromStart: false,\n });\n }\n }\n\n private renderHunks({\n hunk,\n hunkData,\n hunkIndex,\n lineIndex,\n isLastHunk,\n prevHunk,\n ast,\n deletionsAST,\n additionsAST,\n unifiedAST,\n }: RenderHunkProps): number {\n const { diffStyle } = this.getOptionsWithDefaults();\n const unified = diffStyle === 'unified';\n let additionLineNumber = hunk.additionStart - 1;\n let deletionLineNumber = hunk.deletionStart - 1;\n\n this.renderCollapsedHunks({\n additionLineNumber,\n additionsAST,\n ast,\n deletionLineNumber,\n deletionsAST,\n hunkData,\n hunkIndex,\n hunkSpecs: hunk.hunkSpecs,\n isFirstHunk: prevHunk == null,\n isLastHunk: false,\n lineIndex,\n rangeSize: Math.max(hunk.collapsedBefore, 0),\n unifiedAST,\n });\n\n let { oldLines, newLines, oldIndex, newIndex } = (() => {\n if (ast.hunks != null) {\n const lineHunk = ast.hunks[hunkIndex];\n if (lineHunk == null) {\n console.error({ ast, hunkIndex });\n throw new Error(\n `DiffHunksRenderer.renderHunks: lineHunk doesn't exist`\n );\n }\n return {\n oldLines: lineHunk.oldLines,\n newLines: lineHunk.newLines,\n oldIndex: 0,\n newIndex: 0,\n };\n }\n return {\n oldLines: ast.oldLines,\n newLines: ast.newLines,\n oldIndex: deletionLineNumber,\n newIndex: additionLineNumber,\n };\n })();\n\n // Render hunk/diff content\n for (const hunkContent of hunk.hunkContent) {\n if (hunkContent.type === 'context') {\n const { length: len } = hunkContent.lines;\n for (let i = 0; i < len; i++) {\n const oldLine = oldLines[oldIndex];\n const newLine = newLines[newIndex];\n oldIndex++;\n newIndex++;\n additionLineNumber++;\n deletionLineNumber++;\n if (unified) {\n if (newLine == null) {\n throw new Error(\n 'DiffHunksRenderer.renderHunks: newLine doesnt exist for context...'\n );\n }\n this.pushLineWithAnnotation({\n newLine,\n unifiedAST,\n unifiedSpan: this.getAnnotations(\n 'unified',\n deletionLineNumber,\n additionLineNumber,\n hunkIndex,\n lineIndex\n ),\n });\n } else {\n if (newLine == null || oldLine == null) {\n throw new Error(\n 'DiffHunksRenderer.renderHunks: newLine or oldLine doesnt exist for context...'\n );\n }\n this.pushLineWithAnnotation({\n oldLine,\n newLine,\n deletionsAST,\n additionsAST,\n ...this.getAnnotations(\n 'split',\n deletionLineNumber,\n additionLineNumber,\n hunkIndex,\n lineIndex\n ),\n });\n }\n lineIndex++;\n }\n if (hunkContent.noEOFCR) {\n const node = createNoNewlineElement('context');\n if (unified) {\n unifiedAST.push(node);\n } else {\n deletionsAST.push(node);\n additionsAST.push(node);\n }\n }\n } else {\n const { length: dLen } = hunkContent.deletions;\n const { length: aLen } = hunkContent.additions;\n const len = unified ? dLen + aLen : Math.max(dLen, aLen);\n let spanSize = 0;\n for (let i = 0; i < len; i++) {\n const { oldLine, newLine } = (() => {\n let oldLine: ElementContent | undefined = oldLines[oldIndex];\n let newLine: ElementContent | undefined = newLines[newIndex];\n if (unified) {\n if (i < dLen) {\n newLine = undefined;\n } else {\n oldLine = undefined;\n }\n } else {\n if (i >= dLen) {\n oldLine = undefined;\n }\n if (i >= aLen) {\n newLine = undefined;\n }\n }\n if (oldLine == null && newLine == null) {\n console.error({ i, len, ast, hunkContent });\n throw new Error(\n 'renderHunks: oldLine and newLine are null, something is wrong'\n );\n }\n return { oldLine, newLine };\n })();\n\n if (oldLine != null) {\n oldIndex++;\n deletionLineNumber++;\n }\n if (newLine != null) {\n newIndex++;\n additionLineNumber++;\n }\n\n if (unified) {\n this.pushLineWithAnnotation({\n oldLine,\n newLine,\n unifiedAST,\n unifiedSpan: this.getAnnotations(\n 'unified',\n oldLine != null ? deletionLineNumber : undefined,\n newLine != null ? additionLineNumber : undefined,\n hunkIndex,\n lineIndex\n ),\n });\n lineIndex++;\n } else {\n if (oldLine == null || newLine == null) {\n spanSize++;\n }\n const annotationSpans = this.getAnnotations(\n 'split',\n oldLine != null ? deletionLineNumber : undefined,\n newLine != null ? additionLineNumber : undefined,\n hunkIndex,\n lineIndex\n );\n if (annotationSpans != null) {\n if (spanSize > 0) {\n if (aLen > dLen) {\n deletionsAST.push(createEmptyRowBuffer(spanSize));\n } else {\n additionsAST.push(createEmptyRowBuffer(spanSize));\n }\n spanSize = 0;\n }\n }\n this.pushLineWithAnnotation({\n newLine,\n oldLine,\n deletionsAST,\n additionsAST,\n ...annotationSpans,\n });\n lineIndex++;\n }\n }\n if (!unified) {\n if (spanSize > 0) {\n if (aLen > dLen) {\n deletionsAST.push(createEmptyRowBuffer(spanSize));\n } else {\n additionsAST.push(createEmptyRowBuffer(spanSize));\n }\n spanSize = 0;\n }\n if (hunkContent.noEOFCRDeletions) {\n deletionsAST.push(createNoNewlineElement('change-deletion'));\n if (!hunkContent.noEOFCRAdditions) {\n additionsAST.push(createEmptyRowBuffer(1));\n }\n }\n if (hunkContent.noEOFCRAdditions) {\n additionsAST.push(createNoNewlineElement('change-addition'));\n if (!hunkContent.noEOFCRDeletions) {\n deletionsAST.push(createEmptyRowBuffer(1));\n }\n }\n }\n }\n }\n\n if (isLastHunk && ast.newLines != null && ast.newLines.length > 0) {\n this.renderCollapsedHunks({\n additionLineNumber,\n additionsAST,\n ast,\n deletionLineNumber,\n deletionsAST,\n hunkData,\n hunkIndex: hunkIndex + 1,\n hunkSpecs: undefined,\n isFirstHunk: false,\n isLastHunk: true,\n lineIndex,\n rangeSize: Math.max(\n ast.newLines.length -\n Math.max(hunk.additionStart + hunk.additionCount - 1, 0),\n 0\n ),\n unifiedAST,\n });\n }\n return lineIndex;\n }\n\n private pushLineWithAnnotation({\n newLine,\n oldLine,\n unifiedAST,\n additionsAST,\n deletionsAST,\n unifiedSpan,\n deletionSpan,\n additionSpan,\n }: PushLineWithAnnotation) {\n if (unifiedAST != null) {\n if (oldLine != null) {\n unifiedAST.push(oldLine);\n } else if (newLine != null) {\n unifiedAST.push(newLine);\n }\n if (unifiedSpan != null) {\n unifiedAST.push(createAnnotationElement(unifiedSpan));\n }\n } else if (deletionsAST != null && additionsAST != null) {\n if (oldLine != null) {\n deletionsAST.push(oldLine);\n }\n if (newLine != null) {\n additionsAST.push(newLine);\n }\n if (deletionSpan != null) {\n deletionsAST.push(createAnnotationElement(deletionSpan));\n }\n if (additionSpan != null) {\n additionsAST.push(createAnnotationElement(additionSpan));\n }\n }\n }\n\n private getAnnotations(\n type: 'unified',\n oldLineNumber: number | undefined,\n newLineNumber: number | undefined,\n hunkIndex: number,\n lineIndex: number\n ): AnnotationSpan | undefined;\n private getAnnotations(\n type: 'split',\n oldLineNumber: number | undefined,\n newLineNumber: number | undefined,\n hunkIndex: number,\n lineIndex: number\n ): { deletionSpan: AnnotationSpan; additionSpan: AnnotationSpan } | undefined;\n private getAnnotations(\n type: 'unified' | 'split',\n oldLineNumber: number | undefined,\n newLineNumber: number | undefined,\n hunkIndex: number,\n lineIndex: number\n ):\n | AnnotationSpan\n | { deletionSpan: AnnotationSpan; additionSpan: AnnotationSpan }\n | undefined {\n const deletionSpan: AnnotationSpan = {\n type: 'annotation',\n hunkIndex,\n lineIndex,\n annotations: [],\n };\n if (oldLineNumber != null) {\n for (const anno of this.deletionAnnotations[oldLineNumber] ?? []) {\n deletionSpan.annotations.push(getLineAnnotationName(anno));\n }\n }\n const additionSpan: AnnotationSpan = {\n type: 'annotation',\n hunkIndex,\n lineIndex,\n annotations: [],\n };\n if (newLineNumber != null) {\n for (const anno of this.additionAnnotations[newLineNumber] ?? []) {\n (type === 'unified' ? deletionSpan : additionSpan).annotations.push(\n getLineAnnotationName(anno)\n );\n }\n }\n if (type === 'unified') {\n if (deletionSpan.annotations.length > 0) {\n return deletionSpan;\n }\n return undefined;\n }\n if (\n additionSpan.annotations.length === 0 &&\n deletionSpan.annotations.length === 0\n ) {\n return undefined;\n }\n return { deletionSpan, additionSpan };\n }\n\n private renderHeader(\n diff: FileDiffMetadata,\n themeStyles: string,\n baseThemeType: 'light' | 'dark' | undefined\n ): HASTElement {\n const { themeType } = this.getOptionsWithDefaults();\n return createFileHeaderElement({\n fileOrDiff: diff,\n themeStyles,\n themeType: baseThemeType ?? themeType,\n });\n }\n}\n\nfunction areRenderOptionsEqual(\n optionsA: RenderDiffOptions,\n optionsB: RenderDiffOptions\n): boolean {\n return (\n areThemesEqual(optionsA.theme, optionsB.theme) &&\n optionsA.tokenizeMaxLineLength === optionsB.tokenizeMaxLineLength &&\n optionsA.lineDiffType === optionsB.lineDi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AACT,QACE,eAAe,SAAS,OAAO,SAAS,MAAM,IAC9C,SAAS,0BAA0B,SAAS,yBAC5C,SAAS,iBAAiB,SAAS;;AAIvC,SAAS,uBAAuB,OAAe;AAC7C,QAAO,GAAG,MAAM,kBAAkB,QAAQ,IAAI,MAAM"}
|
|
@@ -94,14 +94,18 @@ var FileRenderer = class {
|
|
|
94
94
|
}
|
|
95
95
|
renderFile(file = this.renderCache?.file) {
|
|
96
96
|
if (file == null) return;
|
|
97
|
+
const cache = this.workerManager?.getFileResultCache(file);
|
|
98
|
+
if (cache != null && this.renderCache == null) this.renderCache = {
|
|
99
|
+
file,
|
|
100
|
+
highlighted: true,
|
|
101
|
+
...cache
|
|
102
|
+
};
|
|
97
103
|
const { options, forceRender } = this.getRenderOptions(file);
|
|
98
|
-
let cache = this.workerManager?.getFileResultCache(file);
|
|
99
|
-
if (cache != null && !areRenderOptionsEqual(options, cache.options)) cache = void 0;
|
|
100
104
|
this.renderCache ??= {
|
|
101
105
|
file,
|
|
102
|
-
highlighted:
|
|
103
|
-
options
|
|
104
|
-
result:
|
|
106
|
+
highlighted: false,
|
|
107
|
+
options,
|
|
108
|
+
result: void 0
|
|
105
109
|
};
|
|
106
110
|
if (this.workerManager?.isWorkingPool() === true) {
|
|
107
111
|
this.renderCache.result ??= this.workerManager.getPlainFileAST(file);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileRenderer.js","names":["options: FileRendererOptions","onRenderUpdate?: () => unknown","workerManager?: WorkerPoolManager | undefined","options","options: RenderFileOptions","codeAST: ElementContent[]"],"sources":["../../src/renderers/FileRenderer.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\nimport { DEFAULT_THEMES } from '../constants';\nimport { areLanguagesAttached } from '../highlighter/languages/areLanguagesAttached';\nimport {\n getHighlighterIfLoaded,\n getSharedHighlighter,\n} from '../highlighter/shared_highlighter';\nimport { areThemesAttached } from '../highlighter/themes/areThemesAttached';\nimport { hasResolvedThemes } from '../highlighter/themes/hasResolvedThemes';\nimport type {\n BaseCodeOptions,\n DiffsHighlighter,\n FileContents,\n LineAnnotation,\n RenderFileOptions,\n RenderFileResult,\n RenderedFileASTCache,\n SupportedLanguages,\n ThemeTypes,\n ThemedFileResult,\n} from '../types';\nimport { areThemesEqual } from '../utils/areThemesEqual';\nimport { createAnnotationElement } from '../utils/createAnnotationElement';\nimport { createFileHeaderElement } from '../utils/createFileHeaderElement';\nimport { createPreElement } from '../utils/createPreElement';\nimport { getFiletypeFromFileName } from '../utils/getFiletypeFromFileName';\nimport { getHighlighterOptions } from '../utils/getHighlighterOptions';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport { getThemes } from '../utils/getThemes';\nimport { createHastElement } from '../utils/hast_utils';\nimport { renderFileWithHighlighter } from '../utils/renderFileWithHighlighter';\nimport type { WorkerPoolManager } from '../worker';\n\ntype AnnotationLineMap<LAnnotation> = Record<\n number,\n LineAnnotation<LAnnotation>[] | undefined\n>;\n\ninterface GetRenderOptionsReturn {\n options: RenderFileOptions;\n forceRender: boolean;\n}\n\nexport interface FileRenderResult {\n codeAST: ElementContent[];\n preAST: HASTElement;\n headerAST: HASTElement | undefined;\n css: string;\n totalLines: number;\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport interface FileRendererOptions extends BaseCodeOptions {}\n\nexport class FileRenderer<LAnnotation = undefined> {\n private highlighter: DiffsHighlighter | undefined;\n private renderCache: RenderedFileASTCache | undefined;\n private computedLang: SupportedLanguages = 'text';\n private lineAnnotations: AnnotationLineMap<LAnnotation> = {};\n\n constructor(\n public options: FileRendererOptions = { theme: DEFAULT_THEMES },\n private onRenderUpdate?: () => unknown,\n private workerManager?: WorkerPoolManager | undefined\n ) {\n if (workerManager?.isWorkingPool() !== true) {\n this.highlighter = areThemesAttached(options.theme ?? DEFAULT_THEMES)\n ? getHighlighterIfLoaded()\n : undefined;\n }\n }\n\n setOptions(options: FileRendererOptions): void {\n this.options = options;\n }\n\n private mergeOptions(options: Partial<FileRendererOptions>): void {\n this.options = { ...this.options, ...options };\n }\n\n setThemeType(themeType: ThemeTypes): void {\n const currentThemeType = this.options.themeType ?? 'system';\n if (currentThemeType === themeType) {\n return;\n }\n this.mergeOptions({ themeType });\n }\n\n setLineAnnotations(lineAnnotations: LineAnnotation<LAnnotation>[]): void {\n this.lineAnnotations = {};\n for (const annotation of lineAnnotations) {\n const arr = this.lineAnnotations[annotation.lineNumber] ?? [];\n this.lineAnnotations[annotation.lineNumber] = arr;\n arr.push(annotation);\n }\n }\n\n cleanUp(): void {\n this.renderCache = undefined;\n this.highlighter = undefined;\n this.workerManager = undefined;\n this.onRenderUpdate = undefined;\n }\n\n hydrate(file: FileContents): void {\n const { options } = this.getRenderOptions(file);\n let cache = this.workerManager?.getFileResultCache(file);\n if (cache != null && !areRenderOptionsEqual(options, cache.options)) {\n cache = undefined;\n }\n this.renderCache ??= {\n file,\n options,\n // NOTE(amadeus): If we're hydrating, we can assume there was\n // pre-rendered HTML, otherwise one should not be hydrating\n highlighted: true,\n result: cache?.result,\n };\n if (\n this.workerManager?.isWorkingPool() === true &&\n this.renderCache.result == null\n ) {\n this.workerManager.highlightFileAST(this, file);\n } else {\n void this.asyncHighlight(file).then(({ result, options }) => {\n this.onHighlightSuccess(file, result, options);\n });\n }\n }\n\n private getRenderOptions(file: FileContents): GetRenderOptionsReturn {\n const options: RenderFileOptions = (() => {\n if (this.workerManager?.isWorkingPool() === true) {\n return this.workerManager.getFileRenderOptions();\n }\n const { theme = DEFAULT_THEMES, tokenizeMaxLineLength = 1000 } =\n this.options;\n return { theme, tokenizeMaxLineLength };\n })();\n const { renderCache } = this;\n if (renderCache?.result == null) {\n return { options, forceRender: true };\n }\n if (\n file !== renderCache.file ||\n !areRenderOptionsEqual(options, renderCache.options)\n ) {\n return { options, forceRender: true };\n }\n return { options, forceRender: false };\n }\n\n renderFile(\n file: FileContents | undefined = this.renderCache?.file\n ): FileRenderResult | undefined {\n if (file == null) {\n return undefined;\n }\n const { options, forceRender } = this.getRenderOptions(file);\n let cache = this.workerManager?.getFileResultCache(file);\n if (cache != null && !areRenderOptionsEqual(options, cache.options)) {\n cache = undefined;\n }\n this.renderCache ??= {\n file,\n highlighted: cache != null ? true : false,\n options: cache?.options ?? options,\n result: cache?.result,\n };\n if (this.workerManager?.isWorkingPool() === true) {\n this.renderCache.result ??= this.workerManager.getPlainFileAST(file);\n // TODO(amadeus): Figure out how to only fire this on a per file\n // basis... (maybe the poolManager can figure it out based on file name\n // and file contents probably?)\n if (!this.renderCache.highlighted || forceRender) {\n this.workerManager.highlightFileAST(this, file);\n }\n } else {\n this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);\n const hasThemes =\n this.highlighter != null && areThemesAttached(options.theme);\n const hasLangs =\n this.highlighter != null && areLanguagesAttached(this.computedLang);\n\n // If we have any semblance of a highlighter with the correct theme(s)\n // attached, we can kick off some form of rendering. If we don't have\n // the correct language, then we can render plain text and after kick off\n // an async job to get the highlighted AST\n if (\n this.highlighter != null &&\n hasThemes &&\n (forceRender ||\n (!this.renderCache.highlighted && hasLangs) ||\n this.renderCache.result == null)\n ) {\n const { result, options } = this.renderFileWithHighlighter(\n file,\n this.highlighter,\n !hasLangs\n );\n this.renderCache = {\n file,\n options,\n highlighted: hasLangs,\n result,\n };\n }\n\n // If we get in here it means we'll have to kick off an async highlight\n // process which will involve initializing the highlighter with new themes\n // and languages\n if (!hasThemes || !hasLangs) {\n void this.asyncHighlight(file).then(({ result, options }) => {\n this.onHighlightSuccess(file, result, options);\n });\n }\n }\n\n return this.renderCache.result != null\n ? this.processFileResult(this.renderCache.file, this.renderCache.result)\n : undefined;\n }\n\n async asyncRender(file: FileContents): Promise<FileRenderResult> {\n const { result } = await this.asyncHighlight(file);\n return this.processFileResult(file, result);\n }\n\n private async asyncHighlight(file: FileContents): Promise<RenderFileResult> {\n this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);\n const hasThemes =\n this.highlighter != null &&\n hasResolvedThemes(getThemes(this.options.theme));\n const hasLangs =\n this.highlighter != null && areLanguagesAttached(this.computedLang);\n // If we don't have the required langs or themes, then we need to\n // initialize the highlighter to load the appropriate languages and themes\n if (this.highlighter == null || !hasThemes || !hasLangs) {\n this.highlighter = await this.initializeHighlighter();\n }\n return this.renderFileWithHighlighter(file, this.highlighter);\n }\n\n private renderFileWithHighlighter(\n file: FileContents,\n highlighter: DiffsHighlighter,\n plainText = false\n ): RenderFileResult {\n const { options } = this.getRenderOptions(file);\n const result = renderFileWithHighlighter(\n file,\n highlighter,\n options,\n plainText\n );\n return { result, options };\n }\n\n private processFileResult(\n file: FileContents,\n result: ThemedFileResult\n ): FileRenderResult {\n const { disableFileHeader = false } = this.options;\n const codeAST: ElementContent[] = [];\n let lineIndex = 1;\n for (const line of result.code) {\n codeAST.push(line);\n const annotations = this.lineAnnotations[lineIndex];\n if (annotations != null) {\n codeAST.push(\n createAnnotationElement({\n type: 'annotation',\n hunkIndex: 0,\n lineIndex,\n annotations: annotations.map((annotation) =>\n getLineAnnotationName(annotation)\n ),\n })\n );\n }\n lineIndex++;\n }\n\n return {\n codeAST,\n preAST: this.createPreElement(\n result.code.length,\n result.themeStyles,\n result.baseThemeType\n ),\n headerAST: !disableFileHeader\n ? this.renderHeader(file, result.themeStyles, result.baseThemeType)\n : undefined,\n totalLines: result.code.length,\n themeStyles: result.themeStyles,\n baseThemeType: result.baseThemeType,\n // FIXME(amadeus): Fix this\n css: '',\n };\n }\n\n private renderHeader(\n file: FileContents,\n themeStyles: string,\n baseThemeType: 'light' | 'dark' | undefined\n ) {\n const { themeType = 'system' } = this.options;\n return createFileHeaderElement({\n fileOrDiff: file,\n themeStyles,\n themeType: baseThemeType ?? themeType,\n });\n }\n\n renderFullHTML(result: FileRenderResult): string {\n return toHtml(this.renderFullAST(result));\n }\n\n renderFullAST(\n result: FileRenderResult,\n children: ElementContent[] = []\n ): HASTElement {\n children.push(\n createHastElement({\n tagName: 'code',\n children: result.codeAST,\n properties: { 'data-code': '' },\n })\n );\n return { ...result.preAST, children };\n }\n\n renderPartialHTML(\n children: ElementContent[],\n includeCodeNode: boolean = false\n ): string {\n if (!includeCodeNode) {\n return toHtml(children);\n }\n return toHtml(\n createHastElement({\n tagName: 'code',\n children,\n properties: { 'data-code': '' },\n })\n );\n }\n\n async initializeHighlighter(): Promise<DiffsHighlighter> {\n this.highlighter = await getSharedHighlighter(\n getHighlighterOptions(this.computedLang, this.options)\n );\n return this.highlighter;\n }\n\n onHighlightSuccess(\n file: FileContents,\n result: ThemedFileResult,\n options: RenderFileOptions\n ): void {\n if (this.renderCache == null) {\n return;\n }\n const triggerRenderUpdate =\n this.renderCache.file !== file ||\n !this.renderCache.highlighted ||\n !areRenderOptionsEqual(options, this.renderCache.options);\n\n this.renderCache = {\n file,\n options,\n highlighted: true,\n result,\n };\n\n if (triggerRenderUpdate) {\n this.onRenderUpdate?.();\n }\n }\n\n onHighlightError(error: unknown): void {\n console.error(error);\n }\n\n private createPreElement(\n totalLines: number,\n themeStyles: string,\n baseThemeType: 'light' | 'dark' | undefined\n ): HASTElement {\n const {\n disableLineNumbers = false,\n overflow = 'scroll',\n themeType = 'system',\n } = this.options;\n return createPreElement({\n diffIndicators: 'none',\n disableBackground: true,\n disableLineNumbers,\n overflow,\n themeStyles,\n themeType: baseThemeType ?? themeType,\n split: false,\n totalLines,\n });\n }\n}\n\nfunction areRenderOptionsEqual(\n optionsA: RenderFileOptions,\n optionsB: RenderFileOptions\n): boolean {\n return (\n areThemesEqual(optionsA.theme, optionsB.theme) &&\n optionsA.tokenizeMaxLineLength === optionsB.tokenizeMaxLineLength\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA0DA,IAAa,eAAb,MAAmD;CACjD,AAAQ;CACR,AAAQ;CACR,AAAQ,eAAmC;CAC3C,AAAQ,kBAAkD,EAAE;CAE5D,YACE,AAAOA,UAA+B,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,OACrB,WAAW,UACX,YAAY,aACV,KAAK;AACT,SAAO,iBAAiB;GACtB,gBAAgB;GAChB,mBAAmB;GACnB;GACA;GACA;GACA,WAAW,iBAAiB;GAC5B,OAAO;GACP;GACD,CAAC;;;AAIN,SAAS,sBACP,UACA,UACS;AACT,QACE,eAAe,SAAS,OAAO,SAAS,MAAM,IAC9C,SAAS,0BAA0B,SAAS"}
|
|
1
|
+
{"version":3,"file":"FileRenderer.js","names":["options: FileRendererOptions","onRenderUpdate?: () => unknown","workerManager?: WorkerPoolManager | undefined","options","options: RenderFileOptions","codeAST: ElementContent[]"],"sources":["../../src/renderers/FileRenderer.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\n\nimport { DEFAULT_THEMES } from '../constants';\nimport { areLanguagesAttached } from '../highlighter/languages/areLanguagesAttached';\nimport {\n getHighlighterIfLoaded,\n getSharedHighlighter,\n} from '../highlighter/shared_highlighter';\nimport { areThemesAttached } from '../highlighter/themes/areThemesAttached';\nimport { hasResolvedThemes } from '../highlighter/themes/hasResolvedThemes';\nimport type {\n BaseCodeOptions,\n DiffsHighlighter,\n FileContents,\n LineAnnotation,\n RenderFileOptions,\n RenderFileResult,\n RenderedFileASTCache,\n SupportedLanguages,\n ThemeTypes,\n ThemedFileResult,\n} from '../types';\nimport { areThemesEqual } from '../utils/areThemesEqual';\nimport { createAnnotationElement } from '../utils/createAnnotationElement';\nimport { createFileHeaderElement } from '../utils/createFileHeaderElement';\nimport { createPreElement } from '../utils/createPreElement';\nimport { getFiletypeFromFileName } from '../utils/getFiletypeFromFileName';\nimport { getHighlighterOptions } from '../utils/getHighlighterOptions';\nimport { getLineAnnotationName } from '../utils/getLineAnnotationName';\nimport { getThemes } from '../utils/getThemes';\nimport { createHastElement } from '../utils/hast_utils';\nimport { renderFileWithHighlighter } from '../utils/renderFileWithHighlighter';\nimport type { WorkerPoolManager } from '../worker';\n\ntype AnnotationLineMap<LAnnotation> = Record<\n number,\n LineAnnotation<LAnnotation>[] | undefined\n>;\n\ninterface GetRenderOptionsReturn {\n options: RenderFileOptions;\n forceRender: boolean;\n}\n\nexport interface FileRenderResult {\n codeAST: ElementContent[];\n preAST: HASTElement;\n headerAST: HASTElement | undefined;\n css: string;\n totalLines: number;\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport interface FileRendererOptions extends BaseCodeOptions {}\n\nexport class FileRenderer<LAnnotation = undefined> {\n private highlighter: DiffsHighlighter | undefined;\n private renderCache: RenderedFileASTCache | undefined;\n private computedLang: SupportedLanguages = 'text';\n private lineAnnotations: AnnotationLineMap<LAnnotation> = {};\n\n constructor(\n public options: FileRendererOptions = { theme: DEFAULT_THEMES },\n private onRenderUpdate?: () => unknown,\n private workerManager?: WorkerPoolManager | undefined\n ) {\n if (workerManager?.isWorkingPool() !== true) {\n this.highlighter = areThemesAttached(options.theme ?? DEFAULT_THEMES)\n ? getHighlighterIfLoaded()\n : undefined;\n }\n }\n\n setOptions(options: FileRendererOptions): void {\n this.options = options;\n }\n\n private mergeOptions(options: Partial<FileRendererOptions>): void {\n this.options = { ...this.options, ...options };\n }\n\n setThemeType(themeType: ThemeTypes): void {\n const currentThemeType = this.options.themeType ?? 'system';\n if (currentThemeType === themeType) {\n return;\n }\n this.mergeOptions({ themeType });\n }\n\n setLineAnnotations(lineAnnotations: LineAnnotation<LAnnotation>[]): void {\n this.lineAnnotations = {};\n for (const annotation of lineAnnotations) {\n const arr = this.lineAnnotations[annotation.lineNumber] ?? [];\n this.lineAnnotations[annotation.lineNumber] = arr;\n arr.push(annotation);\n }\n }\n\n cleanUp(): void {\n this.renderCache = undefined;\n this.highlighter = undefined;\n this.workerManager = undefined;\n this.onRenderUpdate = undefined;\n }\n\n hydrate(file: FileContents): void {\n const { options } = this.getRenderOptions(file);\n let cache = this.workerManager?.getFileResultCache(file);\n if (cache != null && !areRenderOptionsEqual(options, cache.options)) {\n cache = undefined;\n }\n this.renderCache ??= {\n file,\n options,\n // NOTE(amadeus): If we're hydrating, we can assume there was\n // pre-rendered HTML, otherwise one should not be hydrating\n highlighted: true,\n result: cache?.result,\n };\n if (\n this.workerManager?.isWorkingPool() === true &&\n this.renderCache.result == null\n ) {\n this.workerManager.highlightFileAST(this, file);\n } else {\n void this.asyncHighlight(file).then(({ result, options }) => {\n this.onHighlightSuccess(file, result, options);\n });\n }\n }\n\n private getRenderOptions(file: FileContents): GetRenderOptionsReturn {\n const options: RenderFileOptions = (() => {\n if (this.workerManager?.isWorkingPool() === true) {\n return this.workerManager.getFileRenderOptions();\n }\n const { theme = DEFAULT_THEMES, tokenizeMaxLineLength = 1000 } =\n this.options;\n return { theme, tokenizeMaxLineLength };\n })();\n const { renderCache } = this;\n if (renderCache?.result == null) {\n return { options, forceRender: true };\n }\n if (\n file !== renderCache.file ||\n !areRenderOptionsEqual(options, renderCache.options)\n ) {\n return { options, forceRender: true };\n }\n return { options, forceRender: false };\n }\n\n renderFile(\n file: FileContents | undefined = this.renderCache?.file\n ): FileRenderResult | undefined {\n if (file == null) {\n return undefined;\n }\n const cache = this.workerManager?.getFileResultCache(file);\n if (cache != null && this.renderCache == null) {\n this.renderCache = { file, highlighted: true, ...cache };\n }\n const { options, forceRender } = this.getRenderOptions(file);\n this.renderCache ??= {\n file,\n highlighted: false,\n options,\n result: undefined,\n };\n if (this.workerManager?.isWorkingPool() === true) {\n this.renderCache.result ??= this.workerManager.getPlainFileAST(file);\n // TODO(amadeus): Figure out how to only fire this on a per file\n // basis... (maybe the poolManager can figure it out based on file name\n // and file contents probably?)\n if (!this.renderCache.highlighted || forceRender) {\n this.workerManager.highlightFileAST(this, file);\n }\n } else {\n this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);\n const hasThemes =\n this.highlighter != null && areThemesAttached(options.theme);\n const hasLangs =\n this.highlighter != null && areLanguagesAttached(this.computedLang);\n\n // If we have any semblance of a highlighter with the correct theme(s)\n // attached, we can kick off some form of rendering. If we don't have\n // the correct language, then we can render plain text and after kick off\n // an async job to get the highlighted AST\n if (\n this.highlighter != null &&\n hasThemes &&\n (forceRender ||\n (!this.renderCache.highlighted && hasLangs) ||\n this.renderCache.result == null)\n ) {\n const { result, options } = this.renderFileWithHighlighter(\n file,\n this.highlighter,\n !hasLangs\n );\n this.renderCache = {\n file,\n options,\n highlighted: hasLangs,\n result,\n };\n }\n\n // If we get in here it means we'll have to kick off an async highlight\n // process which will involve initializing the highlighter with new themes\n // and languages\n if (!hasThemes || !hasLangs) {\n void this.asyncHighlight(file).then(({ result, options }) => {\n this.onHighlightSuccess(file, result, options);\n });\n }\n }\n\n return this.renderCache.result != null\n ? this.processFileResult(this.renderCache.file, this.renderCache.result)\n : undefined;\n }\n\n async asyncRender(file: FileContents): Promise<FileRenderResult> {\n const { result } = await this.asyncHighlight(file);\n return this.processFileResult(file, result);\n }\n\n private async asyncHighlight(file: FileContents): Promise<RenderFileResult> {\n this.computedLang = file.lang ?? getFiletypeFromFileName(file.name);\n const hasThemes =\n this.highlighter != null &&\n hasResolvedThemes(getThemes(this.options.theme));\n const hasLangs =\n this.highlighter != null && areLanguagesAttached(this.computedLang);\n // If we don't have the required langs or themes, then we need to\n // initialize the highlighter to load the appropriate languages and themes\n if (this.highlighter == null || !hasThemes || !hasLangs) {\n this.highlighter = await this.initializeHighlighter();\n }\n return this.renderFileWithHighlighter(file, this.highlighter);\n }\n\n private renderFileWithHighlighter(\n file: FileContents,\n highlighter: DiffsHighlighter,\n plainText = false\n ): RenderFileResult {\n const { options } = this.getRenderOptions(file);\n const result = renderFileWithHighlighter(\n file,\n highlighter,\n options,\n plainText\n );\n return { result, options };\n }\n\n private processFileResult(\n file: FileContents,\n result: ThemedFileResult\n ): FileRenderResult {\n const { disableFileHeader = false } = this.options;\n const codeAST: ElementContent[] = [];\n let lineIndex = 1;\n for (const line of result.code) {\n codeAST.push(line);\n const annotations = this.lineAnnotations[lineIndex];\n if (annotations != null) {\n codeAST.push(\n createAnnotationElement({\n type: 'annotation',\n hunkIndex: 0,\n lineIndex,\n annotations: annotations.map((annotation) =>\n getLineAnnotationName(annotation)\n ),\n })\n );\n }\n lineIndex++;\n }\n\n return {\n codeAST,\n preAST: this.createPreElement(\n result.code.length,\n result.themeStyles,\n result.baseThemeType\n ),\n headerAST: !disableFileHeader\n ? this.renderHeader(file, result.themeStyles, result.baseThemeType)\n : undefined,\n totalLines: result.code.length,\n themeStyles: result.themeStyles,\n baseThemeType: result.baseThemeType,\n // FIXME(amadeus): Fix this\n css: '',\n };\n }\n\n private renderHeader(\n file: FileContents,\n themeStyles: string,\n baseThemeType: 'light' | 'dark' | undefined\n ) {\n const { themeType = 'system' } = this.options;\n return createFileHeaderElement({\n fileOrDiff: file,\n themeStyles,\n themeType: baseThemeType ?? themeType,\n });\n }\n\n renderFullHTML(result: FileRenderResult): string {\n return toHtml(this.renderFullAST(result));\n }\n\n renderFullAST(\n result: FileRenderResult,\n children: ElementContent[] = []\n ): HASTElement {\n children.push(\n createHastElement({\n tagName: 'code',\n children: result.codeAST,\n properties: { 'data-code': '' },\n })\n );\n return { ...result.preAST, children };\n }\n\n renderPartialHTML(\n children: ElementContent[],\n includeCodeNode: boolean = false\n ): string {\n if (!includeCodeNode) {\n return toHtml(children);\n }\n return toHtml(\n createHastElement({\n tagName: 'code',\n children,\n properties: { 'data-code': '' },\n })\n );\n }\n\n async initializeHighlighter(): Promise<DiffsHighlighter> {\n this.highlighter = await getSharedHighlighter(\n getHighlighterOptions(this.computedLang, this.options)\n );\n return this.highlighter;\n }\n\n onHighlightSuccess(\n file: FileContents,\n result: ThemedFileResult,\n options: RenderFileOptions\n ): void {\n if (this.renderCache == null) {\n return;\n }\n const triggerRenderUpdate =\n this.renderCache.file !== file ||\n !this.renderCache.highlighted ||\n !areRenderOptionsEqual(options, this.renderCache.options);\n\n this.renderCache = {\n file,\n options,\n highlighted: true,\n result,\n };\n\n if (triggerRenderUpdate) {\n this.onRenderUpdate?.();\n }\n }\n\n onHighlightError(error: unknown): void {\n console.error(error);\n }\n\n private createPreElement(\n totalLines: number,\n themeStyles: string,\n baseThemeType: 'light' | 'dark' | undefined\n ): HASTElement {\n const {\n disableLineNumbers = false,\n overflow = 'scroll',\n themeType = 'system',\n } = this.options;\n return createPreElement({\n diffIndicators: 'none',\n disableBackground: true,\n disableLineNumbers,\n overflow,\n themeStyles,\n themeType: baseThemeType ?? themeType,\n split: false,\n totalLines,\n });\n }\n}\n\nfunction areRenderOptionsEqual(\n optionsA: RenderFileOptions,\n optionsB: RenderFileOptions\n): boolean {\n return (\n areThemesEqual(optionsA.theme, optionsB.theme) &&\n optionsA.tokenizeMaxLineLength === optionsB.tokenizeMaxLineLength\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA0DA,IAAa,eAAb,MAAmD;CACjD,AAAQ;CACR,AAAQ;CACR,AAAQ,eAAmC;CAC3C,AAAQ,kBAAkD,EAAE;CAE5D,YACE,AAAOA,UAA+B,EAAE,OAAO,gBAAgB,EAC/D,AAAQC,gBACR,AAAQC,eACR;EAHO;EACC;EACA;AAER,MAAI,eAAe,eAAe,KAAK,KACrC,MAAK,cAAc,kBAAkB,QAAQ,SAAS,eAAe,GACjE,wBAAwB,GACxB;;CAIR,WAAW,SAAoC;AAC7C,OAAK,UAAU;;CAGjB,AAAQ,aAAa,SAA6C;AAChE,OAAK,UAAU;GAAE,GAAG,KAAK;GAAS,GAAG;GAAS;;CAGhD,aAAa,WAA6B;AAExC,OADyB,KAAK,QAAQ,aAAa,cAC1B,UACvB;AAEF,OAAK,aAAa,EAAE,WAAW,CAAC;;CAGlC,mBAAmB,iBAAsD;AACvE,OAAK,kBAAkB,EAAE;AACzB,OAAK,MAAM,cAAc,iBAAiB;GACxC,MAAM,MAAM,KAAK,gBAAgB,WAAW,eAAe,EAAE;AAC7D,QAAK,gBAAgB,WAAW,cAAc;AAC9C,OAAI,KAAK,WAAW;;;CAIxB,UAAgB;AACd,OAAK,cAAc;AACnB,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CAAC,gBACH,QAAO,OAAO,SAAS;AAEzB,SAAO,OACL,kBAAkB;GAChB,SAAS;GACT;GACA,YAAY,EAAE,aAAa,IAAI;GAChC,CAAC,CACH;;CAGH,MAAM,wBAAmD;AACvD,OAAK,cAAc,MAAM,qBACvB,sBAAsB,KAAK,cAAc,KAAK,QAAQ,CACvD;AACD,SAAO,KAAK;;CAGd,mBACE,MACA,QACA,SACM;AACN,MAAI,KAAK,eAAe,KACtB;EAEF,MAAM,sBACJ,KAAK,YAAY,SAAS,QAC1B,CAAC,KAAK,YAAY,eAClB,CAAC,sBAAsB,SAAS,KAAK,YAAY,QAAQ;AAE3D,OAAK,cAAc;GACjB;GACA;GACA,aAAa;GACb;GACD;AAED,MAAI,oBACF,MAAK,kBAAkB;;CAI3B,iBAAiB,OAAsB;AACrC,UAAQ,MAAM,MAAM;;CAGtB,AAAQ,iBACN,YACA,aACA,eACa;EACb,MAAM,EACJ,qBAAqB,OACrB,WAAW,UACX,YAAY,aACV,KAAK;AACT,SAAO,iBAAiB;GACtB,gBAAgB;GAChB,mBAAmB;GACnB;GACA;GACA;GACA,WAAW,iBAAiB;GAC5B,OAAO;GACP;GACD,CAAC;;;AAIN,SAAS,sBACP,UACA,UACS;AACT,QACE,eAAe,SAAS,OAAO,SAAS,MAAM,IAC9C,SAAS,0BAA0B,SAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsePatchFiles.d.ts","names":[],"sources":["../../src/utils/parsePatchFiles.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"parsePatchFiles.d.ts","names":[],"sources":["../../src/utils/parsePatchFiles.ts"],"sourcesContent":[],"mappings":";;;;;;AA8RA;;;;;;iBAAgB,eAAA,yCAGb"}
|
|
@@ -131,7 +131,7 @@ function processPatch(data, cacheKeyPrefix) {
|
|
|
131
131
|
collapsedBefore: 0,
|
|
132
132
|
splitLineCount: 0,
|
|
133
133
|
splitLineStart: 0,
|
|
134
|
-
unifiedLineCount:
|
|
134
|
+
unifiedLineCount: 0,
|
|
135
135
|
unifiedLineStart: 0,
|
|
136
136
|
additionCount: parseInt(match[4] ?? "1"),
|
|
137
137
|
additionStart: parseInt(match[3]),
|
|
@@ -150,7 +150,13 @@ function processPatch(data, cacheKeyPrefix) {
|
|
|
150
150
|
hunkData.collapsedBefore = Math.max(hunkData.additionStart - 1 - lastHunkEnd, 0);
|
|
151
151
|
currentFile.hunks.push(hunkData);
|
|
152
152
|
lastHunkEnd = hunkData.additionStart + hunkData.additionCount - 1;
|
|
153
|
-
|
|
153
|
+
for (const content of hunkContent) if (content.type === "context") {
|
|
154
|
+
hunkData.splitLineCount += content.lines.length;
|
|
155
|
+
hunkData.unifiedLineCount += content.lines.length;
|
|
156
|
+
} else {
|
|
157
|
+
hunkData.splitLineCount += Math.max(content.additions.length, content.deletions.length);
|
|
158
|
+
hunkData.unifiedLineCount += content.deletions.length + content.additions.length;
|
|
159
|
+
}
|
|
154
160
|
hunkData.splitLineStart = currentFile.splitLineCount;
|
|
155
161
|
hunkData.unifiedLineStart = currentFile.unifiedLineCount;
|
|
156
162
|
currentFile.splitLineCount += hunkData.splitLineCount;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsePatchFiles.js","names":["patchMetadata: string | undefined","files: FileDiffMetadata[]","currentFile: FileDiffMetadata | undefined","hunkContent: (ContextContent | ChangeContent)[]","currentContent: ContextContent | ChangeContent | undefined","lastLineType: 'context' | 'addition' | 'deletion' | undefined","hunkData: Hunk","patches: ParsedPatch[]"],"sources":["../../src/utils/parsePatchFiles.ts"],"sourcesContent":["import {\n ALTERNATE_FILE_NAMES_GIT,\n COMMIT_METADATA_SPLIT,\n FILENAME_HEADER_REGEX,\n FILENAME_HEADER_REGEX_GIT,\n FILE_CONTEXT_BLOB,\n FILE_MODE_FROM_INDEX,\n GIT_DIFF_FILE_BREAK_REGEX,\n HUNK_HEADER,\n SPLIT_WITH_NEWLINES,\n UNIFIED_DIFF_FILE_BREAK_REGEX,\n} from '../constants';\nimport type {\n ChangeContent,\n ContextContent,\n FileDiffMetadata,\n Hunk,\n ParsedPatch,\n} from '../types';\nimport { cleanLastNewline } from './cleanLastNewline';\nimport { parseLineType } from './parseLineType';\n\nfunction processPatch(data: string, cacheKeyPrefix?: string): 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 let currentFile: FileDiffMetadata | undefined;\n for (const file of rawFiles) {\n if (isGitDiff && !GIT_DIFF_FILE_BREAK_REGEX.test(file)) {\n if (patchMetadata == null) {\n patchMetadata = file;\n } else {\n console.error('parsePatchContent: unknown file blob:', file);\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 (!isGitDiff && !UNIFIED_DIFF_FILE_BREAK_REGEX.test(file)) {\n if (patchMetadata == null) {\n patchMetadata = file;\n } else {\n console.error('parsePatchContent: unknown file blob:', file);\n }\n continue;\n }\n let lastHunkEnd = 0;\n const hunks = file.split(FILE_CONTEXT_BLOB);\n currentFile = undefined;\n for (const hunk of hunks) {\n const lines = hunk.split(SPLIT_WITH_NEWLINES);\n const firstLine = lines.shift();\n if (firstLine == null) {\n console.error('parsePatchContent: invalid hunk', hunk);\n continue;\n }\n const match = firstLine.match(HUNK_HEADER);\n const hunkContent: (ContextContent | ChangeContent)[] = [];\n let additionLines = 0;\n let deletionLines = 0;\n if (match == null || currentFile == null) {\n if (currentFile != null) {\n console.error('parsePatchContent: Invalid hunk', hunk);\n continue;\n }\n currentFile = {\n name: '',\n prevName: undefined,\n type: 'change',\n hunks: [],\n splitLineCount: 0,\n unifiedLineCount: 0,\n cacheKey:\n cacheKeyPrefix != null\n ? `${cacheKeyPrefix}-${files.length}`\n : undefined,\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.oldMode = 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 [, mode] = line.trim().match(FILE_MODE_FROM_INDEX) ?? [];\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 } else {\n let currentContent: ContextContent | ChangeContent | undefined;\n let lastLineType: 'context' | 'addition' | 'deletion' | undefined;\n // Strip trailing bare newlines (format-patch separators between commits)\n while (\n lines.length > 0 &&\n (lines[lines.length - 1] === '\\n' || lines[lines.length - 1] === '')\n ) {\n lines.pop();\n }\n for (const rawLine of lines) {\n const parsedLine = parseLineType(rawLine);\n if (parsedLine == null) {\n continue;\n }\n const { type, line } = parsedLine;\n if (type === 'addition') {\n if (currentContent == null || currentContent.type !== 'change') {\n currentContent = createContentGroup('change');\n hunkContent.push(currentContent);\n }\n currentContent.additions.push(line);\n additionLines++;\n lastLineType = 'addition';\n } else if (type === 'deletion') {\n if (currentContent == null || currentContent.type !== 'change') {\n currentContent = createContentGroup('change');\n hunkContent.push(currentContent);\n }\n currentContent.deletions.push(line);\n deletionLines++;\n lastLineType = 'deletion';\n } else if (type === 'context') {\n if (currentContent == null || currentContent.type !== 'context') {\n currentContent = createContentGroup('context');\n hunkContent.push(currentContent);\n }\n currentContent.lines.push(line);\n lastLineType = 'context';\n } else if (type === 'metadata' && currentContent != null) {\n if (currentContent.type === 'context') {\n currentContent.noEOFCR = true;\n } else if (lastLineType === 'deletion') {\n currentContent.noEOFCRDeletions = true;\n const lastIndex = currentContent.deletions.length - 1;\n if (lastIndex >= 0) {\n currentContent.deletions[lastIndex] = cleanLastNewline(\n currentContent.deletions[lastIndex]\n );\n }\n } else if (lastLineType === 'addition') {\n currentContent.noEOFCRAdditions = true;\n const lastIndex = currentContent.additions.length - 1;\n if (lastIndex >= 0) {\n currentContent.additions[lastIndex] = cleanLastNewline(\n currentContent.additions[lastIndex]\n );\n }\n }\n }\n }\n }\n const hunkData: Hunk = {\n collapsedBefore: 0,\n splitLineCount: 0,\n splitLineStart: 0,\n unifiedLineCount: lines.length,\n unifiedLineStart: 0,\n additionCount: parseInt(match[4] ?? '1'),\n additionStart: parseInt(match[3]),\n additionLines,\n deletionCount: parseInt(match[2] ?? '1'),\n deletionStart: parseInt(match[1]),\n deletionLines,\n hunkContent,\n hunkContext: match[5],\n hunkSpecs: firstLine,\n };\n if (\n isNaN(hunkData.additionCount) ||\n isNaN(hunkData.deletionCount) ||\n isNaN(hunkData.additionStart) ||\n isNaN(hunkData.deletionStart)\n ) {\n console.error('parsePatchContent: invalid hunk metadata', hunkData);\n continue;\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 hunkData.splitLineCount = Math.max(\n hunkData.additionCount,\n hunkData.deletionCount\n );\n hunkData.splitLineStart = currentFile.splitLineCount;\n hunkData.unifiedLineStart = currentFile.unifiedLineCount;\n\n currentFile.splitLineCount += hunkData.splitLineCount;\n currentFile.unifiedLineCount += hunkData.unifiedLineCount;\n }\n if (currentFile != null) {\n if (\n !isGitDiff &&\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 if (\n currentFile.type !== 'rename-pure' &&\n currentFile.type !== 'rename-changed'\n ) {\n currentFile.prevName = undefined;\n }\n files.push(currentFile);\n }\n }\n return { patchMetadata, files };\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): 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 )\n );\n } catch (error) {\n console.error(error);\n }\n }\n return patches;\n}\n\nfunction createContentGroup(type: 'change'): ChangeContent;\nfunction createContentGroup(type: 'context'): ContextContent;\nfunction createContentGroup(\n type: 'change' | 'context'\n): ChangeContent | ContextContent {\n if (type === 'change') {\n return {\n type: 'change',\n additions: [],\n deletions: [],\n noEOFCRAdditions: false,\n noEOFCRDeletions: false,\n };\n }\n return { type: 'context', lines: [], noEOFCR: false };\n}\n"],"mappings":";;;;;AAsBA,SAAS,aAAa,MAAc,gBAAsC;CACxE,MAAM,YAAY,0BAA0B,KAAK,KAAK;CACtD,MAAM,WAAW,KAAK,MACpB,YAAY,4BAA4B,8BACzC;CACD,IAAIA;CACJ,MAAMC,QAA4B,EAAE;CACpC,IAAIC;AACJ,MAAK,MAAM,QAAQ,UAAU;AAC3B,MAAI,aAAa,CAAC,0BAA0B,KAAK,KAAK,EAAE;AACtD,OAAI,iBAAiB,KACnB,iBAAgB;OAEhB,SAAQ,MAAM,yCAAyC,KAAK;AAI9D;aACS,CAAC,aAAa,CAAC,8BAA8B,KAAK,KAAK,EAAE;AAClE,OAAI,iBAAiB,KACnB,iBAAgB;OAEhB,SAAQ,MAAM,yCAAyC,KAAK;AAE9D;;EAEF,IAAI,cAAc;EAClB,MAAM,QAAQ,KAAK,MAAM,kBAAkB;AAC3C,gBAAc;AACd,OAAK,MAAM,QAAQ,OAAO;GACxB,MAAM,QAAQ,KAAK,MAAM,oBAAoB;GAC7C,MAAM,YAAY,MAAM,OAAO;AAC/B,OAAI,aAAa,MAAM;AACrB,YAAQ,MAAM,mCAAmC,KAAK;AACtD;;GAEF,MAAM,QAAQ,UAAU,MAAM,YAAY;GAC1C,MAAMC,cAAkD,EAAE;GAC1D,IAAI,gBAAgB;GACpB,IAAI,gBAAgB;AACpB,OAAI,SAAS,QAAQ,eAAe,MAAM;AACxC,QAAI,eAAe,MAAM;AACvB,aAAQ,MAAM,mCAAmC,KAAK;AACtD;;AAEF,kBAAc;KACZ,MAAM;KACN,UAAU;KACV,MAAM;KACN,OAAO,EAAE;KACT,gBAAgB;KAChB,kBAAkB;KAClB,UACE,kBAAkB,OACd,GAAG,eAAe,GAAG,MAAM,WAC3B;KACP;AAG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,OACL,CACF;UACM,OAAO;AACd,UAAQ,MAAM,MAAM;;AAGxB,QAAO;;AAKT,SAAS,mBACP,MACgC;AAChC,KAAI,SAAS,SACX,QAAO;EACL,MAAM;EACN,WAAW,EAAE;EACb,WAAW,EAAE;EACb,kBAAkB;EAClB,kBAAkB;EACnB;AAEH,QAAO;EAAE,MAAM;EAAW,OAAO,EAAE;EAAE,SAAS;EAAO"}
|
|
1
|
+
{"version":3,"file":"parsePatchFiles.js","names":["patchMetadata: string | undefined","files: FileDiffMetadata[]","currentFile: FileDiffMetadata | undefined","hunkContent: (ContextContent | ChangeContent)[]","currentContent: ContextContent | ChangeContent | undefined","lastLineType: 'context' | 'addition' | 'deletion' | undefined","hunkData: Hunk","patches: ParsedPatch[]"],"sources":["../../src/utils/parsePatchFiles.ts"],"sourcesContent":["import {\n ALTERNATE_FILE_NAMES_GIT,\n COMMIT_METADATA_SPLIT,\n FILENAME_HEADER_REGEX,\n FILENAME_HEADER_REGEX_GIT,\n FILE_CONTEXT_BLOB,\n FILE_MODE_FROM_INDEX,\n GIT_DIFF_FILE_BREAK_REGEX,\n HUNK_HEADER,\n SPLIT_WITH_NEWLINES,\n UNIFIED_DIFF_FILE_BREAK_REGEX,\n} from '../constants';\nimport type {\n ChangeContent,\n ContextContent,\n FileDiffMetadata,\n Hunk,\n ParsedPatch,\n} from '../types';\nimport { cleanLastNewline } from './cleanLastNewline';\nimport { parseLineType } from './parseLineType';\n\nfunction processPatch(data: string, cacheKeyPrefix?: string): 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 let currentFile: FileDiffMetadata | undefined;\n for (const file of rawFiles) {\n if (isGitDiff && !GIT_DIFF_FILE_BREAK_REGEX.test(file)) {\n if (patchMetadata == null) {\n patchMetadata = file;\n } else {\n console.error('parsePatchContent: unknown file blob:', file);\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 (!isGitDiff && !UNIFIED_DIFF_FILE_BREAK_REGEX.test(file)) {\n if (patchMetadata == null) {\n patchMetadata = file;\n } else {\n console.error('parsePatchContent: unknown file blob:', file);\n }\n continue;\n }\n let lastHunkEnd = 0;\n const hunks = file.split(FILE_CONTEXT_BLOB);\n currentFile = undefined;\n for (const hunk of hunks) {\n const lines = hunk.split(SPLIT_WITH_NEWLINES);\n const firstLine = lines.shift();\n if (firstLine == null) {\n console.error('parsePatchContent: invalid hunk', hunk);\n continue;\n }\n const match = firstLine.match(HUNK_HEADER);\n const hunkContent: (ContextContent | ChangeContent)[] = [];\n let additionLines = 0;\n let deletionLines = 0;\n if (match == null || currentFile == null) {\n if (currentFile != null) {\n console.error('parsePatchContent: Invalid hunk', hunk);\n continue;\n }\n currentFile = {\n name: '',\n prevName: undefined,\n type: 'change',\n hunks: [],\n splitLineCount: 0,\n unifiedLineCount: 0,\n cacheKey:\n cacheKeyPrefix != null\n ? `${cacheKeyPrefix}-${files.length}`\n : undefined,\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.oldMode = 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 [, mode] = line.trim().match(FILE_MODE_FROM_INDEX) ?? [];\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 } else {\n let currentContent: ContextContent | ChangeContent | undefined;\n let lastLineType: 'context' | 'addition' | 'deletion' | undefined;\n // Strip trailing bare newlines (format-patch separators between commits)\n while (\n lines.length > 0 &&\n (lines[lines.length - 1] === '\\n' || lines[lines.length - 1] === '')\n ) {\n lines.pop();\n }\n for (const rawLine of lines) {\n const parsedLine = parseLineType(rawLine);\n if (parsedLine == null) {\n continue;\n }\n const { type, line } = parsedLine;\n if (type === 'addition') {\n if (currentContent == null || currentContent.type !== 'change') {\n currentContent = createContentGroup('change');\n hunkContent.push(currentContent);\n }\n currentContent.additions.push(line);\n additionLines++;\n lastLineType = 'addition';\n } else if (type === 'deletion') {\n if (currentContent == null || currentContent.type !== 'change') {\n currentContent = createContentGroup('change');\n hunkContent.push(currentContent);\n }\n currentContent.deletions.push(line);\n deletionLines++;\n lastLineType = 'deletion';\n } else if (type === 'context') {\n if (currentContent == null || currentContent.type !== 'context') {\n currentContent = createContentGroup('context');\n hunkContent.push(currentContent);\n }\n currentContent.lines.push(line);\n lastLineType = 'context';\n } else if (type === 'metadata' && currentContent != null) {\n if (currentContent.type === 'context') {\n currentContent.noEOFCR = true;\n } else if (lastLineType === 'deletion') {\n currentContent.noEOFCRDeletions = true;\n const lastIndex = currentContent.deletions.length - 1;\n if (lastIndex >= 0) {\n currentContent.deletions[lastIndex] = cleanLastNewline(\n currentContent.deletions[lastIndex]\n );\n }\n } else if (lastLineType === 'addition') {\n currentContent.noEOFCRAdditions = true;\n const lastIndex = currentContent.additions.length - 1;\n if (lastIndex >= 0) {\n currentContent.additions[lastIndex] = cleanLastNewline(\n currentContent.additions[lastIndex]\n );\n }\n }\n }\n }\n }\n const hunkData: Hunk = {\n collapsedBefore: 0,\n splitLineCount: 0,\n splitLineStart: 0,\n unifiedLineCount: 0,\n unifiedLineStart: 0,\n additionCount: parseInt(match[4] ?? '1'),\n additionStart: parseInt(match[3]),\n additionLines,\n deletionCount: parseInt(match[2] ?? '1'),\n deletionStart: parseInt(match[1]),\n deletionLines,\n hunkContent,\n hunkContext: match[5],\n hunkSpecs: firstLine,\n };\n if (\n isNaN(hunkData.additionCount) ||\n isNaN(hunkData.deletionCount) ||\n isNaN(hunkData.additionStart) ||\n isNaN(hunkData.deletionStart)\n ) {\n console.error('parsePatchContent: invalid hunk metadata', hunkData);\n continue;\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 hunkContent) {\n if (content.type === 'context') {\n hunkData.splitLineCount += content.lines.length;\n hunkData.unifiedLineCount += content.lines.length;\n } else {\n hunkData.splitLineCount += Math.max(\n content.additions.length,\n content.deletions.length\n );\n hunkData.unifiedLineCount +=\n content.deletions.length + content.additions.length;\n }\n }\n hunkData.splitLineStart = currentFile.splitLineCount;\n hunkData.unifiedLineStart = currentFile.unifiedLineCount;\n\n currentFile.splitLineCount += hunkData.splitLineCount;\n currentFile.unifiedLineCount += hunkData.unifiedLineCount;\n }\n if (currentFile != null) {\n if (\n !isGitDiff &&\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 if (\n currentFile.type !== 'rename-pure' &&\n currentFile.type !== 'rename-changed'\n ) {\n currentFile.prevName = undefined;\n }\n files.push(currentFile);\n }\n }\n return { patchMetadata, files };\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): 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 )\n );\n } catch (error) {\n console.error(error);\n }\n }\n return patches;\n}\n\nfunction createContentGroup(type: 'change'): ChangeContent;\nfunction createContentGroup(type: 'context'): ContextContent;\nfunction createContentGroup(\n type: 'change' | 'context'\n): ChangeContent | ContextContent {\n if (type === 'change') {\n return {\n type: 'change',\n additions: [],\n deletions: [],\n noEOFCRAdditions: false,\n noEOFCRDeletions: false,\n };\n }\n return { type: 'context', lines: [], noEOFCR: false };\n}\n"],"mappings":";;;;;AAsBA,SAAS,aAAa,MAAc,gBAAsC;CACxE,MAAM,YAAY,0BAA0B,KAAK,KAAK;CACtD,MAAM,WAAW,KAAK,MACpB,YAAY,4BAA4B,8BACzC;CACD,IAAIA;CACJ,MAAMC,QAA4B,EAAE;CACpC,IAAIC;AACJ,MAAK,MAAM,QAAQ,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AClB,kBAAkB;EACnB;AAEH,QAAO;EAAE,MAAM;EAAW,OAAO,EAAE;EAAE,SAAS;EAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pierre/diffs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "apache-2.0",
|
|
6
6
|
"scripts": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"files": [
|
|
43
43
|
"dist",
|
|
44
|
-
"LICENSE.
|
|
44
|
+
"LICENSE.md",
|
|
45
45
|
"README.md"
|
|
46
46
|
],
|
|
47
47
|
"devDependencies": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"typescript": "5.9.2"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@shikijs/core": "3.
|
|
61
|
+
"@shikijs/core": "^3.0.0",
|
|
62
62
|
"@shikijs/engine-javascript": "3.19.0",
|
|
63
63
|
"@shikijs/transformers": "3.19.0",
|
|
64
64
|
"diff": "8.0.2",
|
package/LICENSE.txt
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright 2025 Pierre Computer Company
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|