@pierre/diffs 1.2.5 → 1.3.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CodeView.d.ts +0 -1
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +0 -23
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +7 -2
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +36 -2
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +8 -2
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +73 -1
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/UnresolvedFile.js +2 -2
- package/dist/components/VirtualizedFile.d.ts +2 -1
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +48 -48
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +1 -6
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/components/Virtualizer.d.ts +1 -1
- package/dist/components/Virtualizer.d.ts.map +1 -1
- package/dist/components/Virtualizer.js.map +1 -1
- package/dist/editor/command.d.ts +6 -0
- package/dist/editor/command.d.ts.map +1 -0
- package/dist/editor/command.js +31 -0
- package/dist/editor/command.js.map +1 -0
- package/dist/editor/css.d.ts +6 -0
- package/dist/editor/css.d.ts.map +1 -0
- package/dist/editor/css.js +218 -0
- package/dist/editor/css.js.map +1 -0
- package/dist/editor/editStack.d.ts +66 -0
- package/dist/editor/editStack.d.ts.map +1 -0
- package/dist/editor/editStack.js +218 -0
- package/dist/editor/editStack.js.map +1 -0
- package/dist/editor/editor.d.ts +22 -0
- package/dist/editor/editor.d.ts.map +1 -0
- package/dist/editor/editor.js +1323 -0
- package/dist/editor/editor.js.map +1 -0
- package/dist/editor/index.d.ts +3 -0
- package/dist/editor/index.js +4 -0
- package/dist/editor/lineAnnotations.d.ts +8 -0
- package/dist/editor/lineAnnotations.d.ts.map +1 -0
- package/dist/editor/lineAnnotations.js +32 -0
- package/dist/editor/lineAnnotations.js.map +1 -0
- package/dist/editor/pieceTable.d.ts +33 -0
- package/dist/editor/pieceTable.d.ts.map +1 -0
- package/dist/editor/pieceTable.js +590 -0
- package/dist/editor/pieceTable.js.map +1 -0
- package/dist/editor/platform.d.ts +12 -0
- package/dist/editor/platform.d.ts.map +1 -0
- package/dist/editor/platform.js +44 -0
- package/dist/editor/platform.js.map +1 -0
- package/dist/editor/quickEdit.d.ts +29 -0
- package/dist/editor/quickEdit.d.ts.map +1 -0
- package/dist/editor/quickEdit.js +81 -0
- package/dist/editor/quickEdit.js.map +1 -0
- package/dist/editor/searchPanel.d.ts +30 -0
- package/dist/editor/searchPanel.d.ts.map +1 -0
- package/dist/editor/searchPanel.js +219 -0
- package/dist/editor/searchPanel.js.map +1 -0
- package/dist/editor/selection.d.ts +126 -0
- package/dist/editor/selection.d.ts.map +1 -0
- package/dist/editor/selection.js +900 -0
- package/dist/editor/selection.js.map +1 -0
- package/dist/editor/textDocument.d.ts +139 -0
- package/dist/editor/textDocument.d.ts.map +1 -0
- package/dist/editor/textDocument.js +202 -0
- package/dist/editor/textDocument.js.map +1 -0
- package/dist/editor/textMeasure.d.ts +32 -0
- package/dist/editor/textMeasure.d.ts.map +1 -0
- package/dist/editor/textMeasure.js +108 -0
- package/dist/editor/textMeasure.js.map +1 -0
- package/dist/editor/tokenzier.d.ts +37 -0
- package/dist/editor/tokenzier.d.ts.map +1 -0
- package/dist/editor/tokenzier.js +348 -0
- package/dist/editor/tokenzier.js.map +1 -0
- package/dist/editor/utils.d.ts +16 -0
- package/dist/editor/utils.d.ts.map +1 -0
- package/dist/editor/utils.js +37 -0
- package/dist/editor/utils.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/react/EditorContext.d.ts +16 -0
- package/dist/react/EditorContext.d.ts.map +1 -0
- package/dist/react/EditorContext.js +26 -0
- package/dist/react/EditorContext.js.map +1 -0
- package/dist/react/File.d.ts +2 -1
- package/dist/react/File.d.ts.map +1 -1
- package/dist/react/File.js +3 -2
- package/dist/react/File.js.map +1 -1
- package/dist/react/FileDiff.d.ts +3 -1
- package/dist/react/FileDiff.d.ts.map +1 -1
- package/dist/react/FileDiff.js +3 -2
- package/dist/react/FileDiff.js.map +1 -1
- package/dist/react/MultiFileDiff.d.ts +3 -1
- package/dist/react/MultiFileDiff.d.ts.map +1 -1
- package/dist/react/MultiFileDiff.js +3 -2
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/PatchDiff.d.ts +3 -1
- package/dist/react/PatchDiff.d.ts.map +1 -1
- package/dist/react/PatchDiff.js +3 -2
- package/dist/react/PatchDiff.js.map +1 -1
- package/dist/react/index.d.ts +3 -2
- package/dist/react/index.js +2 -1
- package/dist/react/jsx.d.ts +0 -1
- package/dist/react/jsx.d.ts.map +1 -1
- package/dist/react/types.d.ts +1 -0
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/types.js +0 -1
- package/dist/react/utils/useFileDiffInstance.d.ts +3 -1
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +31 -5
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.d.ts +4 -1
- package/dist/react/utils/useFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileInstance.js +30 -5
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +2 -2
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +5 -1
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +108 -41
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/style.js +1 -1
- package/dist/style.js.map +1 -1
- package/dist/types.d.ts +45 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/cleanLastNewline.js +6 -1
- package/dist/utils/cleanLastNewline.js.map +1 -1
- package/dist/utils/computeFileOffsets.d.ts +13 -0
- package/dist/utils/computeFileOffsets.d.ts.map +1 -0
- package/dist/utils/computeFileOffsets.js +33 -0
- package/dist/utils/computeFileOffsets.js.map +1 -0
- package/dist/utils/createTransformerWithState.js +9 -0
- package/dist/utils/createTransformerWithState.js.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.js +1 -1
- package/dist/utils/renderFileWithHighlighter.js +5 -14
- package/dist/utils/renderFileWithHighlighter.js.map +1 -1
- package/dist/worker/WorkerPoolManager.js +1 -1
- package/dist/worker/{wasm-BaDzIkIn.js → wasm-D4DU5jgR.js} +2 -2
- package/dist/worker/wasm-D4DU5jgR.js.map +1 -0
- package/dist/worker/worker-portable.js +138 -153
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +41 -64
- package/dist/worker/worker.js.map +1 -1
- package/package.json +28 -20
- package/dist/utils/iterateOverFile.d.ts +0 -50
- package/dist/utils/iterateOverFile.d.ts.map +0 -1
- package/dist/utils/iterateOverFile.js +0 -49
- package/dist/utils/iterateOverFile.js.map +0 -1
- package/dist/worker/wasm-BaDzIkIn.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css.d.ts","names":["editorCSS","editorGlobalCSS"],"sources":["../../src/editor/css.d.ts"],"sourcesContent":["export declare const editorCSS: string;\nexport declare const editorGlobalCSS = \"\\n [data-annotation-slot] {\\n user-select: none;\\n -webkit-user-select: none;\\n }\\n\";\n//# sourceMappingURL=css.d.ts.map"],"mappings":";cAAqBA;AAAAA,cACAC,eAAAA,GADiB,6FAAA"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
//#region src/editor/css.ts
|
|
2
|
+
const editorCSS = `
|
|
3
|
+
::selection {
|
|
4
|
+
background-color: transparent;
|
|
5
|
+
}
|
|
6
|
+
@keyframes blinking {
|
|
7
|
+
0% { opacity: 1; }
|
|
8
|
+
50% { opacity: 0; }
|
|
9
|
+
100% { opacity: 1; }
|
|
10
|
+
}
|
|
11
|
+
:host, /* for jump anchor */
|
|
12
|
+
[data-code], /* for editor overlay */
|
|
13
|
+
[data-content] /* for wrap line */
|
|
14
|
+
{
|
|
15
|
+
position: relative;
|
|
16
|
+
}
|
|
17
|
+
[data-content] {
|
|
18
|
+
background-color: transparent;
|
|
19
|
+
caret-color: var(--diffs-bg-caret);
|
|
20
|
+
outline: none;
|
|
21
|
+
}
|
|
22
|
+
@media (min-width: 480px) {
|
|
23
|
+
[data-content] {
|
|
24
|
+
caret-color: transparent;
|
|
25
|
+
}
|
|
26
|
+
[data-quick-edit] {
|
|
27
|
+
caret-color: currentColor;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
[data-line] {
|
|
31
|
+
cursor: text;
|
|
32
|
+
}
|
|
33
|
+
[data-line]:not([data-selected-line]),
|
|
34
|
+
[data-line]:not([data-selected-line]) span {
|
|
35
|
+
background-color: transparent;
|
|
36
|
+
}
|
|
37
|
+
[data-line]:is([data-selected-line]),
|
|
38
|
+
[data-line]:is([data-selected-line]) span,
|
|
39
|
+
[data-line-annotation]:is([data-selected-line]) {
|
|
40
|
+
background-color: var(--diffs-editor-line-highlight-bg);
|
|
41
|
+
}
|
|
42
|
+
[data-column-number] {
|
|
43
|
+
color: var(--diffs-editor-line-number-fg);
|
|
44
|
+
}
|
|
45
|
+
[data-column-number]:is([data-selected-line]),
|
|
46
|
+
[data-gutter-buffer]:is([data-selected-line]) {
|
|
47
|
+
background-color: var(--diffs-editor-line-number-active-bg);
|
|
48
|
+
color: var(--diffs-editor-line-number-active-fg);
|
|
49
|
+
}
|
|
50
|
+
[data-column-number]:is([data-active]) {
|
|
51
|
+
color: var(--diffs-editor-line-number-active-fg);
|
|
52
|
+
}
|
|
53
|
+
[data-line]:is([data-line-type='change-deletion']) {
|
|
54
|
+
background-color: var(--diffs-line-bg);
|
|
55
|
+
-webkit-user-select: none;
|
|
56
|
+
user-select: none;
|
|
57
|
+
}
|
|
58
|
+
[data-caret], [data-selection-range] {
|
|
59
|
+
position: absolute;
|
|
60
|
+
top: 0;
|
|
61
|
+
left: 0;
|
|
62
|
+
line-height: var(--diffs-line-height);
|
|
63
|
+
pointer-events: none;
|
|
64
|
+
}
|
|
65
|
+
[data-caret] {
|
|
66
|
+
width: 2px;
|
|
67
|
+
height: 1lh;
|
|
68
|
+
background-color: var(--diffs-bg-caret);
|
|
69
|
+
animation: blinking 1.2s infinite;
|
|
70
|
+
animation-delay: 0.8s;
|
|
71
|
+
visibility: hidden;
|
|
72
|
+
}
|
|
73
|
+
[data-selection-range] {
|
|
74
|
+
height: 1lh;
|
|
75
|
+
z-index: -10;
|
|
76
|
+
background-color: var(--diffs-editor-selection-bg);
|
|
77
|
+
}
|
|
78
|
+
[data-editor-overlay] {
|
|
79
|
+
display: contents;
|
|
80
|
+
}
|
|
81
|
+
@media (min-width: 480px) {
|
|
82
|
+
[data-content]:focus ~ [data-editor-overlay] [data-caret] {
|
|
83
|
+
visibility: visible;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
[data-quick-edit-icon] {
|
|
88
|
+
position: absolute;
|
|
89
|
+
top: 0;
|
|
90
|
+
left: calc(-1lh + 2px);
|
|
91
|
+
z-index: 10;
|
|
92
|
+
width: 1lh;
|
|
93
|
+
height: 1lh;
|
|
94
|
+
border-radius: 4px;
|
|
95
|
+
display: flex;
|
|
96
|
+
align-items: center;
|
|
97
|
+
justify-content: center;
|
|
98
|
+
color: color-mix(in lab, var(--diffs-fg) 40%, var(--diffs-bg));
|
|
99
|
+
transition: background-color 0.1s ease-in-out, color 0.1s ease-in-out;
|
|
100
|
+
cursor: pointer;
|
|
101
|
+
visibility: hidden;
|
|
102
|
+
}
|
|
103
|
+
[data-quick-edit-icon][data-visible='true'] {
|
|
104
|
+
visibility: visible;
|
|
105
|
+
}
|
|
106
|
+
[data-quick-edit-icon]:hover {
|
|
107
|
+
background-color: color-mix(in lab, var(--diffs-fg) 8%, var(--diffs-bg));
|
|
108
|
+
color: var(--diffs-fg);
|
|
109
|
+
}
|
|
110
|
+
[data-quick-edit] {
|
|
111
|
+
padding-inline-end: 1ch;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
[data-search-panel] {
|
|
115
|
+
position: sticky;
|
|
116
|
+
top: 8px;
|
|
117
|
+
left: 0;
|
|
118
|
+
z-index: 100;
|
|
119
|
+
display: flex;
|
|
120
|
+
flex-direction: column;
|
|
121
|
+
gap: 4px;
|
|
122
|
+
margin-inline: 1ch;
|
|
123
|
+
margin-bottom: 4px;
|
|
124
|
+
background-color: color-mix(in lab, color-mix(in lab, var(--diffs-fg) 4%, var(--diffs-bg)), transparent 40%);
|
|
125
|
+
border: 1px solid color-mix(in lab, var(--diffs-fg) 8%, var(--diffs-bg));
|
|
126
|
+
padding: 6px;
|
|
127
|
+
border-radius: 6px;
|
|
128
|
+
box-shadow: 0 0 12px 0 color-mix(in lab, var(--diffs-fg) 16% var(--diffs-bg));
|
|
129
|
+
backdrop-filter: blur(8px);
|
|
130
|
+
}
|
|
131
|
+
[data-search-panel-row] {
|
|
132
|
+
display: flex;
|
|
133
|
+
align-items: center;
|
|
134
|
+
justify-content: flex-start;
|
|
135
|
+
gap: 2px;
|
|
136
|
+
font-family: Arial, Helvetica, sans-serif;
|
|
137
|
+
font-size: 14px;
|
|
138
|
+
}
|
|
139
|
+
[data-search-panel-row] input {
|
|
140
|
+
font-size: 14px;
|
|
141
|
+
line-height: 24px;
|
|
142
|
+
max-width: 50%;
|
|
143
|
+
padding-inline: 4px;
|
|
144
|
+
border: none;
|
|
145
|
+
outline: none;
|
|
146
|
+
background-color: transparent;
|
|
147
|
+
color: var(--diffs-fg);
|
|
148
|
+
field-sizing: content;
|
|
149
|
+
}
|
|
150
|
+
[data-search-panel-row] input::selection {
|
|
151
|
+
background-color: color-mix(in lab, var(--diffs-fg) 8%, var(--diffs-bg));
|
|
152
|
+
}
|
|
153
|
+
[data-search-panel-row] [data-matches] {
|
|
154
|
+
font-size: 12px;
|
|
155
|
+
font-weight: 500;
|
|
156
|
+
line-height: 20px;
|
|
157
|
+
padding-inline-start: 4px;
|
|
158
|
+
padding-inline-end: 8px;
|
|
159
|
+
color: color-mix(in lab, var(--diffs-fg) 50%, var(--diffs-bg));
|
|
160
|
+
}
|
|
161
|
+
[data-search-panel-row] [data-matches][data-no-matches] {
|
|
162
|
+
color: color-mix(in lab, var(--diffs-deletion-base) 90%, var(--diffs-bg));
|
|
163
|
+
}
|
|
164
|
+
[data-search-panel-row] [data-icon] {
|
|
165
|
+
width: 24px;
|
|
166
|
+
height: 24px;
|
|
167
|
+
display: flex;
|
|
168
|
+
color: color-mix(in lab, var(--diffs-fg) 40%, var(--diffs-bg));
|
|
169
|
+
align-items: center;
|
|
170
|
+
justify-content: center;
|
|
171
|
+
border-radius: 4px;
|
|
172
|
+
cursor: pointer;
|
|
173
|
+
transition: background-color 0.1s ease-in-out, color 0.1s ease-in-out;
|
|
174
|
+
}
|
|
175
|
+
[data-search-panel-row] [data-icon][data-disabled='true'] {
|
|
176
|
+
visibility: hidden;
|
|
177
|
+
}
|
|
178
|
+
[data-search-panel-row] [data-icon]:not([data-icon='search']):hover {
|
|
179
|
+
background-color: color-mix(in lab, var(--diffs-fg) 6%, var(--diffs-bg));
|
|
180
|
+
color: var(--diffs-fg);
|
|
181
|
+
}
|
|
182
|
+
[data-search-panel-row] [data-settings] {
|
|
183
|
+
display: flex;
|
|
184
|
+
align-items: center;
|
|
185
|
+
justify-content: center;
|
|
186
|
+
gap: 8px;
|
|
187
|
+
height: 100%;
|
|
188
|
+
padding: 0 8px;
|
|
189
|
+
}
|
|
190
|
+
[data-search-panel-row] [data-checkbox] {
|
|
191
|
+
display: flex;
|
|
192
|
+
align-items: center;
|
|
193
|
+
justify-content: center;
|
|
194
|
+
gap: 4px;
|
|
195
|
+
font-size: 12px;
|
|
196
|
+
color: color-mix(in lab, var(--diffs-fg) 60%, var(--diffs-bg));
|
|
197
|
+
}
|
|
198
|
+
[data-search-panel-row] [data-checkbox] input {
|
|
199
|
+
margin: 0;
|
|
200
|
+
}
|
|
201
|
+
[data-search-panel-row] [data-checkbox]:hover,
|
|
202
|
+
[data-search-panel-row] [data-checkbox]:has(input:checked) {
|
|
203
|
+
color: var(--diffs-fg);
|
|
204
|
+
}
|
|
205
|
+
[data-search-panel-row] [data-spacer] {
|
|
206
|
+
flex: 1;
|
|
207
|
+
}
|
|
208
|
+
`;
|
|
209
|
+
const editorGlobalCSS = `
|
|
210
|
+
[data-annotation-slot] {
|
|
211
|
+
user-select: none;
|
|
212
|
+
-webkit-user-select: none;
|
|
213
|
+
}
|
|
214
|
+
`;
|
|
215
|
+
|
|
216
|
+
//#endregion
|
|
217
|
+
export { editorCSS, editorGlobalCSS };
|
|
218
|
+
//# sourceMappingURL=css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css.js","names":["editorCSS: string"],"sources":["../../src/editor/css.ts"],"sourcesContent":["const DEBUG_SELECTION = false;\n\nexport const editorCSS: string = /* CSS */ `\n ::selection {\n background-color: ${DEBUG_SELECTION ? 'rgba(255, 0, 0, 0.1)' : 'transparent'};\n }\n @keyframes blinking {\n 0% { opacity: 1; }\n 50% { opacity: 0; }\n 100% { opacity: 1; }\n }\n :host, /* for jump anchor */\n [data-code], /* for editor overlay */\n [data-content] /* for wrap line */\n {\n position: relative;\n }\n [data-content] {\n background-color: transparent;\n caret-color: var(--diffs-bg-caret);\n outline: none;\n }\n @media (min-width: 480px) {\n [data-content] {\n caret-color: ${DEBUG_SELECTION ? 'red' : 'transparent'};\n }\n [data-quick-edit] {\n caret-color: currentColor;\n }\n }\n [data-line] {\n cursor: text;\n }\n [data-line]:not([data-selected-line]),\n [data-line]:not([data-selected-line]) span {\n background-color: transparent;\n }\n [data-line]:is([data-selected-line]),\n [data-line]:is([data-selected-line]) span,\n [data-line-annotation]:is([data-selected-line]) {\n background-color: var(--diffs-editor-line-highlight-bg);\n }\n [data-column-number] {\n color: var(--diffs-editor-line-number-fg);\n }\n [data-column-number]:is([data-selected-line]),\n [data-gutter-buffer]:is([data-selected-line]) {\n background-color: var(--diffs-editor-line-number-active-bg);\n color: var(--diffs-editor-line-number-active-fg);\n }\n [data-column-number]:is([data-active]) {\n color: var(--diffs-editor-line-number-active-fg);\n }\n [data-line]:is([data-line-type='change-deletion']) {\n background-color: var(--diffs-line-bg);\n -webkit-user-select: none;\n user-select: none;\n }\n [data-caret], [data-selection-range] {\n position: absolute;\n top: 0;\n left: 0;\n line-height: var(--diffs-line-height);\n pointer-events: none;\n }\n [data-caret] {\n width: 2px;\n height: 1lh;\n background-color: ${DEBUG_SELECTION ? 'transparent' : 'var(--diffs-bg-caret)'};\n animation: blinking 1.2s infinite;\n animation-delay: 0.8s;\n visibility: hidden;\n }\n [data-selection-range] {\n height: 1lh;\n z-index: -10;\n background-color: var(--diffs-editor-selection-bg);\n }\n [data-editor-overlay] {\n display: contents;\n }\n @media (min-width: 480px) {\n [data-content]:focus ~ [data-editor-overlay] [data-caret] {\n visibility: visible;\n }\n }\n\n [data-quick-edit-icon] {\n position: absolute;\n top: 0;\n left: calc(-1lh + 2px);\n z-index: 10;\n width: 1lh;\n height: 1lh;\n border-radius: 4px;\n display: flex;\n align-items: center;\n justify-content: center;\n color: color-mix(in lab, var(--diffs-fg) 40%, var(--diffs-bg));\n transition: background-color 0.1s ease-in-out, color 0.1s ease-in-out;\n cursor: pointer;\n visibility: hidden;\n }\n [data-quick-edit-icon][data-visible='true'] {\n visibility: visible;\n }\n [data-quick-edit-icon]:hover {\n background-color: color-mix(in lab, var(--diffs-fg) 8%, var(--diffs-bg));\n color: var(--diffs-fg);\n }\n [data-quick-edit] {\n padding-inline-end: 1ch;\n }\n\n [data-search-panel] {\n position: sticky;\n top: 8px;\n left: 0;\n z-index: 100;\n display: flex;\n flex-direction: column;\n gap: 4px;\n margin-inline: 1ch;\n margin-bottom: 4px;\n background-color: color-mix(in lab, color-mix(in lab, var(--diffs-fg) 4%, var(--diffs-bg)), transparent 40%);\n border: 1px solid color-mix(in lab, var(--diffs-fg) 8%, var(--diffs-bg));\n padding: 6px;\n border-radius: 6px;\n box-shadow: 0 0 12px 0 color-mix(in lab, var(--diffs-fg) 16% var(--diffs-bg));\n backdrop-filter: blur(8px);\n }\n [data-search-panel-row] {\n display: flex;\n align-items: center;\n justify-content: flex-start;\n gap: 2px;\n font-family: Arial, Helvetica, sans-serif;\n font-size: 14px;\n }\n [data-search-panel-row] input {\n font-size: 14px;\n line-height: 24px;\n max-width: 50%;\n padding-inline: 4px;\n border: none;\n outline: none;\n background-color: transparent;\n color: var(--diffs-fg);\n field-sizing: content;\n }\n [data-search-panel-row] input::selection {\n background-color: color-mix(in lab, var(--diffs-fg) 8%, var(--diffs-bg));\n }\n [data-search-panel-row] [data-matches] {\n font-size: 12px;\n font-weight: 500;\n line-height: 20px;\n padding-inline-start: 4px;\n padding-inline-end: 8px;\n color: color-mix(in lab, var(--diffs-fg) 50%, var(--diffs-bg));\n }\n [data-search-panel-row] [data-matches][data-no-matches] {\n color: color-mix(in lab, var(--diffs-deletion-base) 90%, var(--diffs-bg));\n }\n [data-search-panel-row] [data-icon] {\n width: 24px;\n height: 24px;\n display: flex;\n color: color-mix(in lab, var(--diffs-fg) 40%, var(--diffs-bg));\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n cursor: pointer;\n transition: background-color 0.1s ease-in-out, color 0.1s ease-in-out;\n }\n [data-search-panel-row] [data-icon][data-disabled='true'] {\n visibility: hidden;\n }\n [data-search-panel-row] [data-icon]:not([data-icon='search']):hover {\n background-color: color-mix(in lab, var(--diffs-fg) 6%, var(--diffs-bg));\n color: var(--diffs-fg);\n }\n [data-search-panel-row] [data-settings] {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n height: 100%;\n padding: 0 8px;\n }\n [data-search-panel-row] [data-checkbox] {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 4px;\n font-size: 12px;\n color: color-mix(in lab, var(--diffs-fg) 60%, var(--diffs-bg));\n }\n [data-search-panel-row] [data-checkbox] input {\n margin: 0;\n }\n [data-search-panel-row] [data-checkbox]:hover,\n [data-search-panel-row] [data-checkbox]:has(input:checked) {\n color: var(--diffs-fg);\n }\n [data-search-panel-row] [data-spacer] {\n flex: 1;\n }\n`;\n\n// Safari doesn't support `::selection` for slot elements in ShadowDOM,\n// Add a global style to disable selection for slot elements\nexport const editorGlobalCSS = /* CSS */ `\n [data-annotation-slot] {\n user-select: none;\n -webkit-user-select: none;\n }\n`;\n"],"mappings":";AAEA,MAAaA,YAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkN3C,MAAa,kBAA4B"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { DiffLineAnnotation } from "../types.js";
|
|
2
|
+
import { ResolvedTextEdit, TextDocument } from "./textDocument.js";
|
|
3
|
+
import { EditorSelection } from "./selection.js";
|
|
4
|
+
|
|
5
|
+
//#region src/editor/editStack.d.ts
|
|
6
|
+
/** An entry in the edit stack. */
|
|
7
|
+
interface EditStackEntry<LAnnotation> {
|
|
8
|
+
/** Forward offset edits from the entry's base text to its final text. */
|
|
9
|
+
forwardEdits: ResolvedTextEdit[];
|
|
10
|
+
/** Inverse offset edits from the entry's final text back to its base text. */
|
|
11
|
+
inverseEdits: ResolvedTextEdit[];
|
|
12
|
+
/** Document version before the entry is applied. */
|
|
13
|
+
versionBefore: number;
|
|
14
|
+
/** Document version after the entry is applied. */
|
|
15
|
+
versionAfter: number;
|
|
16
|
+
/** Selection before the transaction. */
|
|
17
|
+
selectionsBefore?: EditorSelection[];
|
|
18
|
+
/** Selection after the transaction. */
|
|
19
|
+
selectionsAfter?: EditorSelection[];
|
|
20
|
+
/** Line annotations before the transaction. */
|
|
21
|
+
lineAnnotationsBefore?: DiffLineAnnotation<LAnnotation>[];
|
|
22
|
+
/** Line annotations after the transaction. */
|
|
23
|
+
lineAnnotationsAfter?: DiffLineAnnotation<LAnnotation>[];
|
|
24
|
+
}
|
|
25
|
+
/** Options for the edit stack. */
|
|
26
|
+
interface EditStackOptions {
|
|
27
|
+
/** The maximum number of entries to keep in the undo stack. */
|
|
28
|
+
maxEntries?: number;
|
|
29
|
+
}
|
|
30
|
+
/** A stack of edit entries. */
|
|
31
|
+
declare class EditStack<LAnnotation> {
|
|
32
|
+
#private;
|
|
33
|
+
constructor(options?: EditStackOptions);
|
|
34
|
+
get canUndo(): boolean;
|
|
35
|
+
get canRedo(): boolean;
|
|
36
|
+
/** Clears both the undo and redo stacks. */
|
|
37
|
+
clear(): void;
|
|
38
|
+
/** Clears the redo stack. */
|
|
39
|
+
clearRedo(): void;
|
|
40
|
+
/** Pushes a new entry onto the undo stack. */
|
|
41
|
+
push(entry: EditStackEntry<LAnnotation>): void;
|
|
42
|
+
/** Sets the selections after the last undo entry. */
|
|
43
|
+
setLastUndoSelectionsAfter(selections: EditorSelection[]): void;
|
|
44
|
+
/** Sets the line annotations after the last undo entry. */
|
|
45
|
+
setLastUndoLineAnnotations(lineAnnotationsBefore: DiffLineAnnotation<LAnnotation>[], lineAnnotationsAfter: DiffLineAnnotation<LAnnotation>[]): void;
|
|
46
|
+
/** Returns the last undo entry, or `undefined` if empty. */
|
|
47
|
+
peekUndo(): EditStackEntry<LAnnotation> | undefined;
|
|
48
|
+
/** Replaces the last undo entry with the given entry. */
|
|
49
|
+
replaceLastUndo(entry: EditStackEntry<LAnnotation>): void;
|
|
50
|
+
/** Moves the latest undo entry to the redo stack and returns it, or `undefined` if empty. */
|
|
51
|
+
popUndoToRedo(): EditStackEntry<LAnnotation> | void;
|
|
52
|
+
/** Moves the latest redo entry back to the undo stack and returns it, or `undefined` if empty. */
|
|
53
|
+
popRedoToUndo(): EditStackEntry<LAnnotation> | void;
|
|
54
|
+
}
|
|
55
|
+
declare function createEditStackEntry<LAnnotation>(textDocument: TextDocument<LAnnotation>, resolvedEdits: ResolvedTextEdit[], versionBefore: number, versionAfter: number, selectionsBefore?: EditorSelection[], selectionsAfter?: EditorSelection[], lineAnnotationsBefore?: DiffLineAnnotation<LAnnotation>[], lineAnnotationsAfter?: DiffLineAnnotation<LAnnotation>[]): EditStackEntry<LAnnotation>;
|
|
56
|
+
/** Determines if the change matches following modes:
|
|
57
|
+
* - 'insert': simple typing
|
|
58
|
+
* - 'backspace': backward delete
|
|
59
|
+
* - 'delete': forward delete
|
|
60
|
+
*/
|
|
61
|
+
declare function shouldCoalesceEditStackEntry<LAnnotation>(previousEntry: EditStackEntry<LAnnotation> | undefined, nextEntry: EditStackEntry<LAnnotation>): boolean;
|
|
62
|
+
/** Coalesce edit stack entries for simple typing and single-character deletes. */
|
|
63
|
+
declare function coalesceEditStackEntries<LAnnotation>(previousEntry: EditStackEntry<LAnnotation>, nextEntry: EditStackEntry<LAnnotation>): EditStackEntry<LAnnotation>;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { EditStack, EditStackEntry, EditStackOptions, coalesceEditStackEntries, createEditStackEntry, shouldCoalesceEditStackEntry };
|
|
66
|
+
//# sourceMappingURL=editStack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editStack.d.ts","names":["DiffLineAnnotation","EditorSelection","ResolvedTextEdit","TextDocument","EditStackEntry","LAnnotation","EditStackOptions","EditStack","createEditStackEntry","shouldCoalesceEditStackEntry","coalesceEditStackEntries"],"sources":["../../src/editor/editStack.d.ts"],"sourcesContent":["import type { DiffLineAnnotation } from '../types';\nimport type { EditorSelection } from './selection';\nimport type { ResolvedTextEdit, TextDocument } from './textDocument';\n/** An entry in the edit stack. */\nexport interface EditStackEntry<LAnnotation> {\n /** Forward offset edits from the entry's base text to its final text. */\n forwardEdits: ResolvedTextEdit[];\n /** Inverse offset edits from the entry's final text back to its base text. */\n inverseEdits: ResolvedTextEdit[];\n /** Document version before the entry is applied. */\n versionBefore: number;\n /** Document version after the entry is applied. */\n versionAfter: number;\n /** Selection before the transaction. */\n selectionsBefore?: EditorSelection[];\n /** Selection after the transaction. */\n selectionsAfter?: EditorSelection[];\n /** Line annotations before the transaction. */\n lineAnnotationsBefore?: DiffLineAnnotation<LAnnotation>[];\n /** Line annotations after the transaction. */\n lineAnnotationsAfter?: DiffLineAnnotation<LAnnotation>[];\n}\n/** Options for the edit stack. */\nexport interface EditStackOptions {\n /** The maximum number of entries to keep in the undo stack. */\n maxEntries?: number;\n}\n/** A stack of edit entries. */\nexport declare class EditStack<LAnnotation> {\n #private;\n constructor(options?: EditStackOptions);\n get canUndo(): boolean;\n get canRedo(): boolean;\n /** Clears both the undo and redo stacks. */\n clear(): void;\n /** Clears the redo stack. */\n clearRedo(): void;\n /** Pushes a new entry onto the undo stack. */\n push(entry: EditStackEntry<LAnnotation>): void;\n /** Sets the selections after the last undo entry. */\n setLastUndoSelectionsAfter(selections: EditorSelection[]): void;\n /** Sets the line annotations after the last undo entry. */\n setLastUndoLineAnnotations(lineAnnotationsBefore: DiffLineAnnotation<LAnnotation>[], lineAnnotationsAfter: DiffLineAnnotation<LAnnotation>[]): void;\n /** Returns the last undo entry, or `undefined` if empty. */\n peekUndo(): EditStackEntry<LAnnotation> | undefined;\n /** Replaces the last undo entry with the given entry. */\n replaceLastUndo(entry: EditStackEntry<LAnnotation>): void;\n /** Moves the latest undo entry to the redo stack and returns it, or `undefined` if empty. */\n popUndoToRedo(): EditStackEntry<LAnnotation> | void;\n /** Moves the latest redo entry back to the undo stack and returns it, or `undefined` if empty. */\n popRedoToUndo(): EditStackEntry<LAnnotation> | void;\n}\nexport declare function createEditStackEntry<LAnnotation>(textDocument: TextDocument<LAnnotation>, resolvedEdits: ResolvedTextEdit[], versionBefore: number, versionAfter: number, selectionsBefore?: EditorSelection[], selectionsAfter?: EditorSelection[], lineAnnotationsBefore?: DiffLineAnnotation<LAnnotation>[], lineAnnotationsAfter?: DiffLineAnnotation<LAnnotation>[]): EditStackEntry<LAnnotation>;\n/** Determines if the change matches following modes:\n * - 'insert': simple typing\n * - 'backspace': backward delete\n * - 'delete': forward delete\n */\nexport declare function shouldCoalesceEditStackEntry<LAnnotation>(previousEntry: EditStackEntry<LAnnotation> | undefined, nextEntry: EditStackEntry<LAnnotation>): boolean;\n/** Coalesce edit stack entries for simple typing and single-character deletes. */\nexport declare function coalesceEditStackEntries<LAnnotation>(previousEntry: EditStackEntry<LAnnotation>, nextEntry: EditStackEntry<LAnnotation>): EditStackEntry<LAnnotation>;\n//# sourceMappingURL=editStack.d.ts.map"],"mappings":";;;;;;UAIiBI;EAAAA;EAECF,YAAAA,EAAAA,gBAAAA,EAAAA;EAEAA;EAMKD,YAAAA,EANLC,gBAMKD,EAAAA;EAEDA;EAEyBI,aAAAA,EAAAA,MAAAA;EAAnBL;EAEkBK,YAAAA,EAAAA,MAAAA;EAAnBL;EAAkB,gBAAA,CAAA,EANtBC,eAMsB,EAAA;EAG5BK;EAKIC,eAAS,CAAA,EAZRN,eAYQI,EAAA;EAEJC;EAQKD,qBAAAA,CAAAA,EApBHL,kBAoBGK,CApBgBA,WAoBhBA,CAAAA,EAAAA;EAAfD;EAE2BH,oBAAAA,CAAAA,EApBhBD,kBAoBgBC,CApBGI,WAoBHJ,CAAAA,EAAAA;;;AAEuFI,UAnBjHC,gBAAAA,CAmBiHD;EAAnBL;EAEhFK,UAAAA,CAAAA,EAAAA,MAAAA;;;AAEJD,cAlBNG,SAkBMH,CAAAA,WAAAA,CAAAA,CAAAA;EAESC,CAAAA,OAAAA;EAAfD,WAAAA,CAAAA,OAAAA,CAAAA,EAlBKE,gBAkBLF;EAEe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AA,EAAA,EAAA,oBAAA,CAAA,EAN6LL,kBAM7L,CANgNK,WAMhN,CAAA,EAAA,CAAA,EANiOD,cAMjO,CANgPC,WAMhP,CAAA;AAEnJ;;;;;AAAkKA,iBAF1II,4BAE0IJ,CAAAA,WAAAA,CAAAA,CAAAA,aAAAA,EAFjFD,cAEiFC,CAFlEA,WAEkEA,CAAAA,GAAAA,SAAAA,EAAAA,SAAAA,EAF7BD,cAE6BC,CAFdA,WAEcA,CAAAA,CAAAA,EAAAA,OAAAA;;AAAD,iBAAzIK,wBAAyI,CAAA,WAAA,CAAA,CAAA,aAAA,EAApFN,cAAoF,CAArEC,WAAqE,CAAA,EAAA,SAAA,EAA5CD,cAA4C,CAA7BC,WAA6B,CAAA,CAAA,EAAdD,cAAc,CAACC,WAAD,CAAA"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
//#region src/editor/editStack.ts
|
|
2
|
+
/** Largest number of undo or redo entries kept; oldest entries drop first once exceeded. */
|
|
3
|
+
const DEFAULT_EDIT_STACK_MAX_ENTRIES = 100;
|
|
4
|
+
/** A stack of edit entries. */
|
|
5
|
+
var EditStack = class {
|
|
6
|
+
#undoStack = [];
|
|
7
|
+
#redoStack = [];
|
|
8
|
+
#maxEntries;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.#maxEntries = Math.max(1, options?.maxEntries ?? DEFAULT_EDIT_STACK_MAX_ENTRIES);
|
|
11
|
+
}
|
|
12
|
+
get canUndo() {
|
|
13
|
+
return this.#undoStack.length > 0;
|
|
14
|
+
}
|
|
15
|
+
get canRedo() {
|
|
16
|
+
return this.#redoStack.length > 0;
|
|
17
|
+
}
|
|
18
|
+
/** Clears both the undo and redo stacks. */
|
|
19
|
+
clear() {
|
|
20
|
+
this.#undoStack.length = 0;
|
|
21
|
+
this.#redoStack.length = 0;
|
|
22
|
+
}
|
|
23
|
+
/** Clears the redo stack. */
|
|
24
|
+
clearRedo() {
|
|
25
|
+
this.#redoStack.length = 0;
|
|
26
|
+
}
|
|
27
|
+
/** Pushes a new entry onto the undo stack. */
|
|
28
|
+
push(entry) {
|
|
29
|
+
this.#undoStack.push(entry);
|
|
30
|
+
this.clearRedo();
|
|
31
|
+
if (this.#undoStack.length > this.#maxEntries) this.#undoStack.shift();
|
|
32
|
+
}
|
|
33
|
+
/** Sets the selections after the last undo entry. */
|
|
34
|
+
setLastUndoSelectionsAfter(selections) {
|
|
35
|
+
const lastEntry = this.#undoStack[this.#undoStack.length - 1];
|
|
36
|
+
if (lastEntry !== void 0) lastEntry.selectionsAfter = selections.map((selection) => ({ ...selection }));
|
|
37
|
+
}
|
|
38
|
+
/** Sets the line annotations after the last undo entry. */
|
|
39
|
+
setLastUndoLineAnnotations(lineAnnotationsBefore, lineAnnotationsAfter) {
|
|
40
|
+
const lastEntry = this.#undoStack[this.#undoStack.length - 1];
|
|
41
|
+
if (lastEntry !== void 0) {
|
|
42
|
+
lastEntry.lineAnnotationsBefore = lineAnnotationsBefore.slice();
|
|
43
|
+
lastEntry.lineAnnotationsAfter = lineAnnotationsAfter.slice();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Returns the last undo entry, or `undefined` if empty. */
|
|
47
|
+
peekUndo() {
|
|
48
|
+
return this.#undoStack[this.#undoStack.length - 1];
|
|
49
|
+
}
|
|
50
|
+
/** Replaces the last undo entry with the given entry. */
|
|
51
|
+
replaceLastUndo(entry) {
|
|
52
|
+
if (this.#undoStack.length === 0) {
|
|
53
|
+
this.push(entry);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
this.#undoStack[this.#undoStack.length - 1] = entry;
|
|
57
|
+
this.clearRedo();
|
|
58
|
+
}
|
|
59
|
+
/** Moves the latest undo entry to the redo stack and returns it, or `undefined` if empty. */
|
|
60
|
+
popUndoToRedo() {
|
|
61
|
+
const entry = this.#undoStack.pop();
|
|
62
|
+
if (entry !== void 0) {
|
|
63
|
+
this.#redoStack.push(entry);
|
|
64
|
+
return entry;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Moves the latest redo entry back to the undo stack and returns it, or `undefined` if empty. */
|
|
68
|
+
popRedoToUndo() {
|
|
69
|
+
const entry = this.#redoStack.pop();
|
|
70
|
+
if (entry !== void 0) {
|
|
71
|
+
this.#undoStack.push(entry);
|
|
72
|
+
return entry;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
function createEditStackEntry(textDocument, resolvedEdits, versionBefore, versionAfter, selectionsBefore, selectionsAfter, lineAnnotationsBefore, lineAnnotationsAfter) {
|
|
77
|
+
const forwardEdits = [...resolvedEdits].sort((a, b) => a.start - b.start);
|
|
78
|
+
const inverseEdits = [];
|
|
79
|
+
for (let i = 0, offsetDelta = 0; i < forwardEdits.length; i++) {
|
|
80
|
+
const edit = forwardEdits[i];
|
|
81
|
+
const replacedText = textDocument.getTextSlice(edit.start, edit.end);
|
|
82
|
+
const startAfterEdit = edit.start + offsetDelta;
|
|
83
|
+
inverseEdits.push({
|
|
84
|
+
start: startAfterEdit,
|
|
85
|
+
end: startAfterEdit + edit.text.length,
|
|
86
|
+
text: replacedText
|
|
87
|
+
});
|
|
88
|
+
offsetDelta += edit.text.length - (edit.end - edit.start);
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
forwardEdits: forwardEdits.map((edit) => ({ ...edit })),
|
|
92
|
+
inverseEdits,
|
|
93
|
+
versionBefore,
|
|
94
|
+
versionAfter,
|
|
95
|
+
selectionsBefore: selectionsBefore?.map((selection) => ({ ...selection })),
|
|
96
|
+
selectionsAfter: selectionsAfter?.map((selection) => ({ ...selection })),
|
|
97
|
+
lineAnnotationsBefore: lineAnnotationsBefore?.slice(),
|
|
98
|
+
lineAnnotationsAfter: lineAnnotationsAfter?.slice()
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** Determines if the change matches following modes:
|
|
102
|
+
* - 'insert': simple typing
|
|
103
|
+
* - 'backspace': backward delete
|
|
104
|
+
* - 'delete': forward delete
|
|
105
|
+
*/
|
|
106
|
+
function shouldCoalesceEditStackEntry(previousEntry, nextEntry) {
|
|
107
|
+
if (previousEntry === void 0 || previousEntry.forwardEdits.length === 0 || previousEntry.forwardEdits.length !== previousEntry.inverseEdits.length || previousEntry.forwardEdits.length !== nextEntry.forwardEdits.length || nextEntry.forwardEdits.length !== nextEntry.inverseEdits.length) return false;
|
|
108
|
+
let mode;
|
|
109
|
+
for (let i = 0; i < previousEntry.forwardEdits.length; i++) {
|
|
110
|
+
const previousForward = previousEntry.forwardEdits[i];
|
|
111
|
+
const previousInverse = previousEntry.inverseEdits[i];
|
|
112
|
+
const nextForward = nextEntry.forwardEdits[i];
|
|
113
|
+
const nextInverse = nextEntry.inverseEdits[i];
|
|
114
|
+
const mappedNextStart = mapOffsetAfterForwardBatchToBefore(nextForward.start, previousEntry.forwardEdits);
|
|
115
|
+
const previousWasInsert = previousForward.start <= previousForward.end && previousForward.text.length > 0 && !previousForward.text.includes("\n") && !previousInverse.text.includes("\n");
|
|
116
|
+
const nextIsInsert = nextForward.start === nextForward.end && nextForward.text.length > 0 && nextInverse.text.length === 0;
|
|
117
|
+
if (previousWasInsert && nextIsInsert) {
|
|
118
|
+
if (mappedNextStart !== previousForward.end) return false;
|
|
119
|
+
mode ??= "insert";
|
|
120
|
+
if (mode !== "insert") return false;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const previousWasDelete = previousForward.text.length === 0 && previousForward.end > previousForward.start && previousInverse.text.length > 0;
|
|
124
|
+
const nextIsDelete = nextForward.text.length === 0 && nextForward.end > nextForward.start && nextInverse.text.length > 0;
|
|
125
|
+
if (previousWasDelete && nextIsDelete) {
|
|
126
|
+
if (mappedNextStart === previousForward.end) {
|
|
127
|
+
mode ??= "delete";
|
|
128
|
+
if (mode !== "delete") return false;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (mappedNextStart + (nextForward.end - nextForward.start) !== previousForward.start) return false;
|
|
132
|
+
mode ??= "backspace";
|
|
133
|
+
if (mode !== "backspace") return false;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
return mode !== void 0;
|
|
139
|
+
}
|
|
140
|
+
/** Coalesce edit stack entries for simple typing and single-character deletes. */
|
|
141
|
+
function coalesceEditStackEntries(previousEntry, nextEntry) {
|
|
142
|
+
const forwardEdits = [];
|
|
143
|
+
const replacedTexts = [];
|
|
144
|
+
for (let i = 0; i < previousEntry.forwardEdits.length; i++) {
|
|
145
|
+
const previousForward = previousEntry.forwardEdits[i];
|
|
146
|
+
const previousInverse = previousEntry.inverseEdits[i];
|
|
147
|
+
const nextForward = nextEntry.forwardEdits[i];
|
|
148
|
+
const nextInverse = nextEntry.inverseEdits[i];
|
|
149
|
+
const mappedNextStart = mapOffsetAfterForwardBatchToBefore(nextForward.start, previousEntry.forwardEdits);
|
|
150
|
+
if (previousForward.text.length > 0) {
|
|
151
|
+
forwardEdits.push({
|
|
152
|
+
start: previousForward.start,
|
|
153
|
+
end: previousForward.end,
|
|
154
|
+
text: previousForward.text + nextForward.text
|
|
155
|
+
});
|
|
156
|
+
replacedTexts.push(previousInverse.text);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (mappedNextStart === previousForward.end) {
|
|
160
|
+
forwardEdits.push({
|
|
161
|
+
start: previousForward.start,
|
|
162
|
+
end: mappedNextStart + (nextForward.end - nextForward.start),
|
|
163
|
+
text: ""
|
|
164
|
+
});
|
|
165
|
+
replacedTexts.push(previousInverse.text + nextInverse.text);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
forwardEdits.push({
|
|
169
|
+
start: Math.min(previousForward.start, mappedNextStart),
|
|
170
|
+
end: previousForward.end,
|
|
171
|
+
text: ""
|
|
172
|
+
});
|
|
173
|
+
replacedTexts.push(nextInverse.text + previousInverse.text);
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
forwardEdits,
|
|
177
|
+
inverseEdits: buildInverseEditsFromReplacedTexts(forwardEdits, replacedTexts),
|
|
178
|
+
versionBefore: previousEntry.versionBefore,
|
|
179
|
+
versionAfter: nextEntry.versionAfter,
|
|
180
|
+
selectionsBefore: previousEntry.selectionsBefore?.slice(),
|
|
181
|
+
selectionsAfter: nextEntry.selectionsAfter?.slice(),
|
|
182
|
+
lineAnnotationsBefore: previousEntry.lineAnnotationsBefore?.slice(),
|
|
183
|
+
lineAnnotationsAfter: nextEntry.lineAnnotationsAfter?.slice()
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function buildInverseEditsFromReplacedTexts(forwardEdits, replacedTexts) {
|
|
187
|
+
const inverseEdits = [];
|
|
188
|
+
for (let i = 0, offsetDelta = 0; i < forwardEdits.length; i++) {
|
|
189
|
+
const edit = forwardEdits[i];
|
|
190
|
+
const startAfterEdit = edit.start + offsetDelta;
|
|
191
|
+
inverseEdits.push({
|
|
192
|
+
start: startAfterEdit,
|
|
193
|
+
end: startAfterEdit + edit.text.length,
|
|
194
|
+
text: replacedTexts[i]
|
|
195
|
+
});
|
|
196
|
+
offsetDelta += edit.text.length - (edit.end - edit.start);
|
|
197
|
+
}
|
|
198
|
+
return inverseEdits;
|
|
199
|
+
}
|
|
200
|
+
function mapOffsetAfterForwardBatchToBefore(offsetAfter, forwardEdits) {
|
|
201
|
+
let offset = offsetAfter;
|
|
202
|
+
for (const edit of forwardEdits) {
|
|
203
|
+
const oldLength = edit.end - edit.start;
|
|
204
|
+
const newLength = edit.text.length;
|
|
205
|
+
const delta = newLength - oldLength;
|
|
206
|
+
if (offset < edit.start) continue;
|
|
207
|
+
if (offset >= edit.start + newLength) {
|
|
208
|
+
offset -= delta;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
offset = edit.start + Math.min(offset - edit.start, oldLength);
|
|
212
|
+
}
|
|
213
|
+
return offset;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
//#endregion
|
|
217
|
+
export { EditStack, coalesceEditStackEntries, createEditStackEntry, shouldCoalesceEditStackEntry };
|
|
218
|
+
//# sourceMappingURL=editStack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editStack.js","names":["#maxEntries","#undoStack","#redoStack","inverseEdits: ResolvedTextEdit[]","mode: 'insert' | 'backspace' | 'delete' | undefined","forwardEdits: ResolvedTextEdit[]","replacedTexts: string[]"],"sources":["../../src/editor/editStack.ts"],"sourcesContent":["import type { DiffLineAnnotation } from '../types';\nimport type { EditorSelection } from './selection';\nimport type { ResolvedTextEdit, TextDocument } from './textDocument';\n\n/** Largest number of undo or redo entries kept; oldest entries drop first once exceeded. */\nconst DEFAULT_EDIT_STACK_MAX_ENTRIES = 100;\n\n/** An entry in the edit stack. */\nexport interface EditStackEntry<LAnnotation> {\n /** Forward offset edits from the entry's base text to its final text. */\n forwardEdits: ResolvedTextEdit[];\n /** Inverse offset edits from the entry's final text back to its base text. */\n inverseEdits: ResolvedTextEdit[];\n /** Document version before the entry is applied. */\n versionBefore: number;\n /** Document version after the entry is applied. */\n versionAfter: number;\n /** Selection before the transaction. */\n selectionsBefore?: EditorSelection[];\n /** Selection after the transaction. */\n selectionsAfter?: EditorSelection[];\n /** Line annotations before the transaction. */\n lineAnnotationsBefore?: DiffLineAnnotation<LAnnotation>[];\n /** Line annotations after the transaction. */\n lineAnnotationsAfter?: DiffLineAnnotation<LAnnotation>[];\n}\n\n/** Options for the edit stack. */\nexport interface EditStackOptions {\n /** The maximum number of entries to keep in the undo stack. */\n maxEntries?: number;\n}\n\n/** A stack of edit entries. */\nexport class EditStack<LAnnotation> {\n #undoStack: EditStackEntry<LAnnotation>[] = [];\n #redoStack: EditStackEntry<LAnnotation>[] = [];\n #maxEntries: number;\n\n constructor(options?: EditStackOptions) {\n this.#maxEntries = Math.max(\n 1,\n options?.maxEntries ?? DEFAULT_EDIT_STACK_MAX_ENTRIES\n );\n }\n\n get canUndo(): boolean {\n return this.#undoStack.length > 0;\n }\n\n get canRedo(): boolean {\n return this.#redoStack.length > 0;\n }\n\n /** Clears both the undo and redo stacks. */\n clear(): void {\n this.#undoStack.length = 0;\n this.#redoStack.length = 0;\n }\n\n /** Clears the redo stack. */\n clearRedo(): void {\n this.#redoStack.length = 0;\n }\n\n /** Pushes a new entry onto the undo stack. */\n push(entry: EditStackEntry<LAnnotation>): void {\n this.#undoStack.push(entry);\n this.clearRedo();\n if (this.#undoStack.length > this.#maxEntries) {\n this.#undoStack.shift();\n }\n }\n\n /** Sets the selections after the last undo entry. */\n setLastUndoSelectionsAfter(selections: EditorSelection[]): void {\n const lastEntry = this.#undoStack[this.#undoStack.length - 1];\n if (lastEntry !== undefined) {\n lastEntry.selectionsAfter = selections.map((selection) => ({\n ...selection,\n }));\n }\n }\n\n /** Sets the line annotations after the last undo entry. */\n setLastUndoLineAnnotations(\n lineAnnotationsBefore: DiffLineAnnotation<LAnnotation>[],\n lineAnnotationsAfter: DiffLineAnnotation<LAnnotation>[]\n ): void {\n const lastEntry = this.#undoStack[this.#undoStack.length - 1];\n if (lastEntry !== undefined) {\n lastEntry.lineAnnotationsBefore = lineAnnotationsBefore.slice();\n lastEntry.lineAnnotationsAfter = lineAnnotationsAfter.slice();\n }\n }\n\n /** Returns the last undo entry, or `undefined` if empty. */\n peekUndo(): EditStackEntry<LAnnotation> | undefined {\n return this.#undoStack[this.#undoStack.length - 1];\n }\n\n /** Replaces the last undo entry with the given entry. */\n replaceLastUndo(entry: EditStackEntry<LAnnotation>): void {\n if (this.#undoStack.length === 0) {\n this.push(entry);\n return;\n }\n this.#undoStack[this.#undoStack.length - 1] = entry;\n this.clearRedo();\n }\n\n /** Moves the latest undo entry to the redo stack and returns it, or `undefined` if empty. */\n popUndoToRedo(): EditStackEntry<LAnnotation> | void {\n const entry = this.#undoStack.pop();\n if (entry !== undefined) {\n this.#redoStack.push(entry);\n return entry;\n }\n }\n\n /** Moves the latest redo entry back to the undo stack and returns it, or `undefined` if empty. */\n popRedoToUndo(): EditStackEntry<LAnnotation> | void {\n const entry = this.#redoStack.pop();\n if (entry !== undefined) {\n this.#undoStack.push(entry);\n return entry;\n }\n }\n}\n\nexport function createEditStackEntry<LAnnotation>(\n textDocument: TextDocument<LAnnotation>,\n resolvedEdits: ResolvedTextEdit[],\n versionBefore: number,\n versionAfter: number,\n selectionsBefore?: EditorSelection[],\n selectionsAfter?: EditorSelection[],\n lineAnnotationsBefore?: DiffLineAnnotation<LAnnotation>[],\n lineAnnotationsAfter?: DiffLineAnnotation<LAnnotation>[]\n): EditStackEntry<LAnnotation> {\n const forwardEdits = [...resolvedEdits].sort((a, b) => a.start - b.start);\n const inverseEdits: ResolvedTextEdit[] = [];\n for (let i = 0, offsetDelta = 0; i < forwardEdits.length; i++) {\n const edit = forwardEdits[i];\n const replacedText = textDocument.getTextSlice(edit.start, edit.end);\n const startAfterEdit = edit.start + offsetDelta;\n inverseEdits.push({\n start: startAfterEdit,\n end: startAfterEdit + edit.text.length,\n text: replacedText,\n });\n offsetDelta += edit.text.length - (edit.end - edit.start);\n }\n return {\n forwardEdits: forwardEdits.map((edit) => ({ ...edit })),\n inverseEdits: inverseEdits,\n versionBefore,\n versionAfter,\n selectionsBefore: selectionsBefore?.map((selection) => ({\n ...selection,\n })),\n selectionsAfter: selectionsAfter?.map((selection) => ({ ...selection })),\n lineAnnotationsBefore: lineAnnotationsBefore?.slice(),\n lineAnnotationsAfter: lineAnnotationsAfter?.slice(),\n };\n}\n\n/** Determines if the change matches following modes:\n * - 'insert': simple typing\n * - 'backspace': backward delete\n * - 'delete': forward delete\n */\nexport function shouldCoalesceEditStackEntry<LAnnotation>(\n previousEntry: EditStackEntry<LAnnotation> | undefined,\n nextEntry: EditStackEntry<LAnnotation>\n): boolean {\n if (\n previousEntry === undefined ||\n previousEntry.forwardEdits.length === 0 ||\n previousEntry.forwardEdits.length !== previousEntry.inverseEdits.length ||\n previousEntry.forwardEdits.length !== nextEntry.forwardEdits.length ||\n nextEntry.forwardEdits.length !== nextEntry.inverseEdits.length\n ) {\n return false;\n }\n let mode: 'insert' | 'backspace' | 'delete' | undefined;\n for (let i = 0; i < previousEntry.forwardEdits.length; i++) {\n const previousForward = previousEntry.forwardEdits[i];\n const previousInverse = previousEntry.inverseEdits[i];\n const nextForward = nextEntry.forwardEdits[i];\n const nextInverse = nextEntry.inverseEdits[i];\n const mappedNextStart = mapOffsetAfterForwardBatchToBefore(\n nextForward.start,\n previousEntry.forwardEdits\n );\n const previousWasInsert =\n previousForward.start <= previousForward.end &&\n previousForward.text.length > 0 &&\n !previousForward.text.includes('\\n') &&\n !previousInverse.text.includes('\\n');\n const nextIsInsert =\n nextForward.start === nextForward.end &&\n nextForward.text.length > 0 &&\n nextInverse.text.length === 0;\n if (previousWasInsert && nextIsInsert) {\n const expectedMappedNextStart = previousForward.end;\n // Allow continuing typing after replacing a selection (e.g. \"hello\" -> \"w\")\n // while still requiring that the cursor extension maps inside the same base range.\n if (mappedNextStart !== expectedMappedNextStart) {\n return false;\n }\n mode ??= 'insert';\n if (mode !== 'insert') {\n return false;\n }\n continue;\n }\n const previousWasDelete =\n previousForward.text.length === 0 &&\n previousForward.end > previousForward.start &&\n previousInverse.text.length > 0;\n const nextIsDelete =\n nextForward.text.length === 0 &&\n nextForward.end > nextForward.start &&\n nextInverse.text.length > 0;\n if (previousWasDelete && nextIsDelete) {\n if (mappedNextStart === previousForward.end) {\n mode ??= 'delete';\n if (mode !== 'delete') {\n return false;\n }\n continue;\n }\n if (\n mappedNextStart + (nextForward.end - nextForward.start) !==\n previousForward.start\n ) {\n return false;\n }\n mode ??= 'backspace';\n if (mode !== 'backspace') {\n return false;\n }\n continue;\n }\n return false;\n }\n return mode !== undefined;\n}\n\n/** Coalesce edit stack entries for simple typing and single-character deletes. */\nexport function coalesceEditStackEntries<LAnnotation>(\n previousEntry: EditStackEntry<LAnnotation>,\n nextEntry: EditStackEntry<LAnnotation>\n): EditStackEntry<LAnnotation> {\n const forwardEdits: ResolvedTextEdit[] = [];\n const replacedTexts: string[] = [];\n for (let i = 0; i < previousEntry.forwardEdits.length; i++) {\n const previousForward = previousEntry.forwardEdits[i];\n const previousInverse = previousEntry.inverseEdits[i];\n const nextForward = nextEntry.forwardEdits[i];\n const nextInverse = nextEntry.inverseEdits[i];\n const mappedNextStart = mapOffsetAfterForwardBatchToBefore(\n nextForward.start,\n previousEntry.forwardEdits\n );\n\n if (previousForward.text.length > 0) {\n forwardEdits.push({\n start: previousForward.start,\n end: previousForward.end,\n text: previousForward.text + nextForward.text,\n });\n replacedTexts.push(previousInverse.text);\n continue;\n }\n\n if (mappedNextStart === previousForward.end) {\n forwardEdits.push({\n start: previousForward.start,\n end: mappedNextStart + (nextForward.end - nextForward.start),\n text: '',\n });\n replacedTexts.push(previousInverse.text + nextInverse.text);\n continue;\n }\n\n forwardEdits.push({\n start: Math.min(previousForward.start, mappedNextStart),\n end: previousForward.end,\n text: '',\n });\n replacedTexts.push(nextInverse.text + previousInverse.text);\n }\n\n return {\n forwardEdits,\n inverseEdits: buildInverseEditsFromReplacedTexts(\n forwardEdits,\n replacedTexts\n ),\n versionBefore: previousEntry.versionBefore,\n versionAfter: nextEntry.versionAfter,\n selectionsBefore: previousEntry.selectionsBefore?.slice(),\n selectionsAfter: nextEntry.selectionsAfter?.slice(),\n lineAnnotationsBefore: previousEntry.lineAnnotationsBefore?.slice(),\n lineAnnotationsAfter: nextEntry.lineAnnotationsAfter?.slice(),\n };\n}\n\nfunction buildInverseEditsFromReplacedTexts(\n forwardEdits: readonly ResolvedTextEdit[],\n replacedTexts: readonly string[]\n): ResolvedTextEdit[] {\n const inverseEdits: ResolvedTextEdit[] = [];\n for (let i = 0, offsetDelta = 0; i < forwardEdits.length; i++) {\n const edit = forwardEdits[i];\n const startAfterEdit = edit.start + offsetDelta;\n inverseEdits.push({\n start: startAfterEdit,\n end: startAfterEdit + edit.text.length,\n text: replacedTexts[i],\n });\n offsetDelta += edit.text.length - (edit.end - edit.start);\n }\n return inverseEdits;\n}\n\nfunction mapOffsetAfterForwardBatchToBefore(\n offsetAfter: number,\n forwardEdits: readonly ResolvedTextEdit[]\n): number {\n let offset = offsetAfter;\n for (const edit of forwardEdits) {\n const oldLength = edit.end - edit.start;\n const newLength = edit.text.length;\n const delta = newLength - oldLength;\n if (offset < edit.start) {\n continue;\n }\n if (offset >= edit.start + newLength) {\n offset -= delta;\n continue;\n }\n offset = edit.start + Math.min(offset - edit.start, oldLength);\n }\n return offset;\n}\n"],"mappings":";;AAKA,MAAM,iCAAiC;;AA6BvC,IAAa,YAAb,MAAoC;CAClC,aAA4C,EAAE;CAC9C,aAA4C,EAAE;CAC9C;CAEA,YAAY,SAA4B;AACtC,QAAKA,aAAc,KAAK,IACtB,GACA,SAAS,cAAc,+BACxB;;CAGH,IAAI,UAAmB;AACrB,SAAO,MAAKC,UAAW,SAAS;;CAGlC,IAAI,UAAmB;AACrB,SAAO,MAAKC,UAAW,SAAS;;;CAIlC,QAAc;AACZ,QAAKD,UAAW,SAAS;AACzB,QAAKC,UAAW,SAAS;;;CAI3B,YAAkB;AAChB,QAAKA,UAAW,SAAS;;;CAI3B,KAAK,OAA0C;AAC7C,QAAKD,UAAW,KAAK,MAAM;AAC3B,OAAK,WAAW;AAChB,MAAI,MAAKA,UAAW,SAAS,MAAKD,WAChC,OAAKC,UAAW,OAAO;;;CAK3B,2BAA2B,YAAqC;EAC9D,MAAM,YAAY,MAAKA,UAAW,MAAKA,UAAW,SAAS;AAC3D,MAAI,cAAc,OAChB,WAAU,kBAAkB,WAAW,KAAK,eAAe,EACzD,GAAG,WACJ,EAAE;;;CAKP,2BACE,uBACA,sBACM;EACN,MAAM,YAAY,MAAKA,UAAW,MAAKA,UAAW,SAAS;AAC3D,MAAI,cAAc,QAAW;AAC3B,aAAU,wBAAwB,sBAAsB,OAAO;AAC/D,aAAU,uBAAuB,qBAAqB,OAAO;;;;CAKjE,WAAoD;AAClD,SAAO,MAAKA,UAAW,MAAKA,UAAW,SAAS;;;CAIlD,gBAAgB,OAA0C;AACxD,MAAI,MAA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AAM,cAAc;GACrB,CAAC;AACF,iBAAe,KAAK,KAAK,UAAU,KAAK,MAAM,KAAK;;AAErD,QAAO;;AAGT,SAAS,mCACP,aACA,cACQ;CACR,IAAI,SAAS;AACb,MAAK,MAAM,QAAQ,cAAc;EAC/B,MAAM,YAAY,KAAK,MAAM,KAAK;EAClC,MAAM,YAAY,KAAK,KAAK;EAC5B,MAAM,QAAQ,YAAY;AAC1B,MAAI,SAAS,KAAK,MAChB;AAEF,MAAI,UAAU,KAAK,QAAQ,WAAW;AACpC,aAAU;AACV;;AAEF,WAAS,KAAK,QAAQ,KAAK,IAAI,SAAS,KAAK,OAAO,UAAU;;AAEhE,QAAO"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DiffLineAnnotation, DiffsEditableComponent, DiffsEditor, DiffsEditorSelection, DiffsHighlighter, FileContents, RenderRange } from "../types.js";
|
|
2
|
+
import { QuickEditContext } from "./quickEdit.js";
|
|
3
|
+
|
|
4
|
+
//#region src/editor/editor.d.ts
|
|
5
|
+
interface EditorOptions<LAnnotation> {
|
|
6
|
+
enabledQuickEdit?: boolean;
|
|
7
|
+
renderQuickEdit?: (context: QuickEditContext<LAnnotation>) => HTMLElement;
|
|
8
|
+
onChange?: (file: FileContents, lineAnnotations?: DiffLineAnnotation<LAnnotation>[]) => void;
|
|
9
|
+
__debug?: boolean;
|
|
10
|
+
}
|
|
11
|
+
declare class Editor<LAnnotation> implements DiffsEditor<LAnnotation> {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(options?: EditorOptions<LAnnotation>);
|
|
14
|
+
edit(component: DiffsEditableComponent<LAnnotation>): () => void;
|
|
15
|
+
setSelections(selections: DiffsEditorSelection[]): void;
|
|
16
|
+
focus(options?: FocusOptions): void;
|
|
17
|
+
cleanUp(): void;
|
|
18
|
+
syncWithRender(highlighter: DiffsHighlighter, fileContainer: HTMLElement, fileContents: FileContents, lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined, renderRange: RenderRange | undefined, editMode?: 'simple' | 'advanced'): void;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { Editor, EditorOptions };
|
|
22
|
+
//# sourceMappingURL=editor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.d.ts","names":["DiffLineAnnotation","DiffsEditableComponent","DiffsEditor","DiffsEditorSelection","DiffsHighlighter","FileContents","RenderRange","QuickEditContext","EditorOptions","LAnnotation","HTMLElement","Editor","FocusOptions"],"sources":["../../src/editor/editor.d.ts"],"sourcesContent":["import type { DiffLineAnnotation, DiffsEditableComponent, DiffsEditor, DiffsEditorSelection, DiffsHighlighter, FileContents, RenderRange } from '../types';\nimport { type QuickEditContext } from './quickEdit';\nexport interface EditorOptions<LAnnotation> {\n enabledQuickEdit?: boolean;\n renderQuickEdit?: (context: QuickEditContext<LAnnotation>) => HTMLElement;\n onChange?: (file: FileContents, lineAnnotations?: DiffLineAnnotation<LAnnotation>[]) => void;\n __debug?: boolean;\n}\nexport declare class Editor<LAnnotation> implements DiffsEditor<LAnnotation> {\n #private;\n constructor(options?: EditorOptions<LAnnotation>);\n edit(component: DiffsEditableComponent<LAnnotation>): () => void;\n setSelections(selections: DiffsEditorSelection[]): void;\n focus(options?: FocusOptions): void;\n cleanUp(): void;\n syncWithRender(highlighter: DiffsHighlighter, fileContainer: HTMLElement, fileContents: FileContents, lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined, renderRange: RenderRange | undefined, editMode?: 'simple' | 'advanced'): void;\n}\n//# sourceMappingURL=editor.d.ts.map"],"mappings":";;;;UAEiBQ;;EAAAA,eAAAA,CAAa,EAAA,CAAA,OAAAC,EAEEF,gBAFF,CAEmBE,WAFnB,CAAA,EAAA,GAEoCC,WAFpC;EAEmBD,QAAAA,CAAAA,EAAAA,CAAAA,IAAAA,EAC3BJ,YAD2BI,EAAAA,eAAAA,CAAAA,EACKT,kBADLS,CACwBA,WADxBA,CAAAA,EAAAA,EAAAA,GAAAA,IAAAA;EAAjBF,OAAAA,CAAAA,EAAAA,OAAAA;;AACVF,cAGDM,MAHCN,CAAAA,WAAAA,CAAAA,YAG8BH,WAH9BG,CAG0CI,WAH1CJ,CAAAA,CAAAA;EAAmDI,CAAAA,OAAAA;EAAnBT,WAAAA,CAAAA,OAAAA,CAAAA,EAK5BQ,aAL4BR,CAKdS,WALcT,CAAAA;EAAkB,IAAA,CAAA,SAAA,EAMpDC,sBANoD,CAM7BQ,WAN6B,CAAA,CAAA,EAAA,GAAA,GAAA,IAAA;EAGnDE,aAAM,CAAA,UAAAF,EAIGN,oBAJH,EAAA,CAAA,EAAA,IAAA;EAAqCM,KAAAA,CAAAA,OAAAA,CAAAA,EAK5CG,YAL4CH,CAAAA,EAAAA,IAAAA;EAExBA,OAAAA,CAAAA,CAAAA,EAAAA,IAAAA;EAAdD,cAAAA,CAAAA,WAAAA,EAKMJ,gBALNI,EAAAA,aAAAA,EAKuCE,WALvCF,EAAAA,YAAAA,EAKkEH,YALlEG,EAAAA,eAAAA,EAKiGR,kBALjGQ,CAKoHC,WALpHD,CAAAA,EAAAA,GAAAA,SAAAA,EAAAA,WAAAA,EAK6JF,WAL7JE,GAAAA,SAAAA,EAAAA,QAAAA,CAAAA,EAAAA,QAAAA,GAAAA,UAAAA,CAAAA,EAAAA,IAAAA"}
|