markstream-vue2 0.0.50 → 0.0.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/README.md +55 -1
  2. package/dist/chunks/andromeeda-0e066d27.js +4 -0
  3. package/dist/chunks/andromeeda-beebe2f9.cjs +1 -0
  4. package/dist/chunks/aurora-x-7d279c8e.cjs +1 -0
  5. package/dist/chunks/aurora-x-e4f2fe1b.js +4 -0
  6. package/dist/chunks/ayu-dark-349c357c.js +4 -0
  7. package/dist/chunks/ayu-dark-5e86208e.cjs +1 -0
  8. package/dist/chunks/ayu-light-18928686.cjs +1 -0
  9. package/dist/chunks/ayu-light-bfc150f8.js +4 -0
  10. package/dist/chunks/ayu-mirage-3383fcd0.js +4 -0
  11. package/dist/chunks/ayu-mirage-3af5c477.cjs +1 -0
  12. package/dist/chunks/catppuccin-frappe-32dd8ebe.js +4 -0
  13. package/dist/chunks/catppuccin-frappe-5990e1cc.cjs +1 -0
  14. package/dist/chunks/catppuccin-latte-7dd9ec26.cjs +1 -0
  15. package/dist/chunks/catppuccin-latte-842c8be1.js +4 -0
  16. package/dist/chunks/catppuccin-macchiato-0c355ced.js +4 -0
  17. package/dist/chunks/catppuccin-macchiato-12297a0c.cjs +1 -0
  18. package/dist/chunks/catppuccin-mocha-164bffb5.cjs +1 -0
  19. package/dist/chunks/catppuccin-mocha-840be6a5.js +4 -0
  20. package/dist/chunks/dark-plus-37515867.cjs +1 -0
  21. package/dist/chunks/dark-plus-51ee0d5e.js +4 -0
  22. package/dist/chunks/dracula-6e5c19a8.js +4 -0
  23. package/dist/chunks/dracula-ad0b94e0.cjs +1 -0
  24. package/dist/chunks/dracula-soft-223c44b5.cjs +1 -0
  25. package/dist/chunks/dracula-soft-744d21b1.js +4 -0
  26. package/dist/chunks/everforest-dark-3a566062.js +4 -0
  27. package/dist/chunks/everforest-dark-630f597e.cjs +1 -0
  28. package/dist/chunks/everforest-light-92583419.js +4 -0
  29. package/dist/chunks/everforest-light-ba8af69c.cjs +1 -0
  30. package/dist/chunks/github-dark-44cb1819.cjs +1 -0
  31. package/dist/chunks/github-dark-cb4e8bb4.js +4 -0
  32. package/dist/chunks/github-dark-default-d50179ae.js +4 -0
  33. package/dist/chunks/github-dark-default-f99477eb.cjs +1 -0
  34. package/dist/chunks/github-dark-dimmed-96ccf893.cjs +1 -0
  35. package/dist/chunks/github-dark-dimmed-ebbb9420.js +4 -0
  36. package/dist/chunks/github-dark-high-contrast-5cc08661.js +4 -0
  37. package/dist/chunks/github-dark-high-contrast-adcd4e61.cjs +1 -0
  38. package/dist/chunks/github-light-42f759a4.cjs +1 -0
  39. package/dist/chunks/github-light-555bd325.js +4 -0
  40. package/dist/chunks/github-light-default-50fa37cd.cjs +1 -0
  41. package/dist/chunks/github-light-default-9c006cf6.js +4 -0
  42. package/dist/chunks/github-light-high-contrast-15a9bb5a.cjs +1 -0
  43. package/dist/chunks/github-light-high-contrast-ffa0564e.js +4 -0
  44. package/dist/chunks/gruvbox-dark-hard-4412389e.js +4 -0
  45. package/dist/chunks/gruvbox-dark-hard-cc007dcd.cjs +1 -0
  46. package/dist/chunks/gruvbox-dark-medium-415e09f2.cjs +1 -0
  47. package/dist/chunks/gruvbox-dark-medium-fa0eeef7.js +4 -0
  48. package/dist/chunks/gruvbox-dark-soft-3125d894.cjs +1 -0
  49. package/dist/chunks/gruvbox-dark-soft-a4600b2a.js +4 -0
  50. package/dist/chunks/gruvbox-light-hard-4c8c0395.cjs +1 -0
  51. package/dist/chunks/gruvbox-light-hard-8e736562.js +4 -0
  52. package/dist/chunks/gruvbox-light-medium-0c0cbf5d.js +4 -0
  53. package/dist/chunks/gruvbox-light-medium-abf52b0c.cjs +1 -0
  54. package/dist/chunks/gruvbox-light-soft-0e7ed903.cjs +1 -0
  55. package/dist/chunks/gruvbox-light-soft-a35d50d0.js +4 -0
  56. package/dist/chunks/horizon-31da8ee5.js +4 -0
  57. package/dist/chunks/horizon-bright-bb8b03f8.js +4 -0
  58. package/dist/chunks/horizon-bright-d2ea0b12.cjs +1 -0
  59. package/dist/chunks/horizon-f8b833c3.cjs +1 -0
  60. package/dist/chunks/houston-20eb8cbf.cjs +1 -0
  61. package/dist/chunks/houston-d3d3c60d.js +4 -0
  62. package/dist/chunks/index-42602bc0.js +18739 -0
  63. package/dist/chunks/index-b485917b.cjs +1 -0
  64. package/dist/chunks/index-c958c796.cjs +1 -0
  65. package/dist/chunks/index-fce73667.js +1702 -0
  66. package/dist/chunks/kanagawa-dragon-0246ed94.cjs +1 -0
  67. package/dist/chunks/kanagawa-dragon-324edcdc.js +4 -0
  68. package/dist/chunks/kanagawa-lotus-61838bd3.cjs +1 -0
  69. package/dist/chunks/kanagawa-lotus-a847832a.js +4 -0
  70. package/dist/chunks/kanagawa-wave-2b426416.cjs +1 -0
  71. package/dist/chunks/kanagawa-wave-7b8409ec.js +4 -0
  72. package/dist/chunks/laserwave-538ee8e3.js +4 -0
  73. package/dist/chunks/laserwave-d5e6cfa6.cjs +1 -0
  74. package/dist/chunks/light-plus-471df294.cjs +1 -0
  75. package/dist/chunks/light-plus-a0703fa7.js +4 -0
  76. package/dist/chunks/material-theme-686d9ffc.js +4 -0
  77. package/dist/chunks/material-theme-9d859633.cjs +1 -0
  78. package/dist/chunks/material-theme-darker-cac9360e.js +4 -0
  79. package/dist/chunks/material-theme-darker-fe8dd38a.cjs +1 -0
  80. package/dist/chunks/material-theme-lighter-03523bbb.js +4 -0
  81. package/dist/chunks/material-theme-lighter-879be29a.cjs +1 -0
  82. package/dist/chunks/material-theme-ocean-37052f40.js +4 -0
  83. package/dist/chunks/material-theme-ocean-c1caeaa4.cjs +1 -0
  84. package/dist/chunks/material-theme-palenight-70bbf617.js +4 -0
  85. package/dist/chunks/material-theme-palenight-ef8b2399.cjs +1 -0
  86. package/dist/chunks/min-dark-0baaa2b0.cjs +1 -0
  87. package/dist/chunks/min-dark-16b503e6.js +4 -0
  88. package/dist/chunks/min-light-0c4ea4ec.js +4 -0
  89. package/dist/chunks/min-light-f65395e0.cjs +1 -0
  90. package/dist/chunks/monokai-32171550.js +4 -0
  91. package/dist/chunks/monokai-b9c22257.cjs +1 -0
  92. package/dist/chunks/night-owl-5eeb6e45.cjs +1 -0
  93. package/dist/chunks/night-owl-cb71e64c.js +4 -0
  94. package/dist/chunks/night-owl-light-3b4be46f.js +4 -0
  95. package/dist/chunks/night-owl-light-f04fad9f.cjs +1 -0
  96. package/dist/chunks/nord-0b42b6b4.cjs +1 -0
  97. package/dist/chunks/nord-b2f653cd.js +4 -0
  98. package/dist/chunks/one-dark-pro-611d46bc.js +4 -0
  99. package/dist/chunks/one-dark-pro-6ac63500.cjs +1 -0
  100. package/dist/chunks/one-light-2f27f0f0.cjs +1 -0
  101. package/dist/chunks/one-light-f2b411cc.js +4 -0
  102. package/dist/chunks/pierre-dark-9c2ca7e3.cjs +1 -0
  103. package/dist/chunks/pierre-dark-f4c18c96.js +4 -0
  104. package/dist/chunks/pierre-dark-protanopia-deuteranopia-31face57.js +4 -0
  105. package/dist/chunks/pierre-dark-protanopia-deuteranopia-67028f58.cjs +1 -0
  106. package/dist/chunks/pierre-dark-soft-3103370a.js +4 -0
  107. package/dist/chunks/pierre-dark-soft-59e1d5bc.cjs +1 -0
  108. package/dist/chunks/pierre-dark-tritanopia-b2966d75.js +4 -0
  109. package/dist/chunks/pierre-dark-tritanopia-d87f3323.cjs +1 -0
  110. package/dist/chunks/pierre-dark-vibrant-4de6032d.js +4 -0
  111. package/dist/chunks/pierre-dark-vibrant-f4553619.cjs +1 -0
  112. package/dist/chunks/pierre-light-45d08543.js +4 -0
  113. package/dist/chunks/pierre-light-ae152c30.cjs +1 -0
  114. package/dist/chunks/pierre-light-protanopia-deuteranopia-78f5453c.cjs +1 -0
  115. package/dist/chunks/pierre-light-protanopia-deuteranopia-816a3304.js +4 -0
  116. package/dist/chunks/pierre-light-soft-2a7b83ed.cjs +1 -0
  117. package/dist/chunks/pierre-light-soft-9c96aa07.js +4 -0
  118. package/dist/chunks/pierre-light-tritanopia-22534644.cjs +1 -0
  119. package/dist/chunks/pierre-light-tritanopia-b49f3566.js +4 -0
  120. package/dist/chunks/pierre-light-vibrant-178f2e13.cjs +1 -0
  121. package/dist/chunks/pierre-light-vibrant-1d779afc.js +4 -0
  122. package/dist/chunks/plastic-050a5288.js +4 -0
  123. package/dist/chunks/plastic-ab5115cb.cjs +1 -0
  124. package/dist/chunks/poimandres-9b9bffc0.cjs +1 -0
  125. package/dist/chunks/poimandres-e7807ea4.js +4 -0
  126. package/dist/chunks/red-58c74b50.cjs +1 -0
  127. package/dist/chunks/red-8b5bb9fd.js +4 -0
  128. package/dist/chunks/rose-pine-dawn-c54a297c.js +4 -0
  129. package/dist/chunks/rose-pine-dawn-dcd06a2d.cjs +1 -0
  130. package/dist/chunks/rose-pine-e3dfc7b6.js +4 -0
  131. package/dist/chunks/rose-pine-e443c3f3.cjs +1 -0
  132. package/dist/chunks/rose-pine-moon-c4ae0bee.cjs +1 -0
  133. package/dist/chunks/rose-pine-moon-ff747b44.js +4 -0
  134. package/dist/chunks/slack-dark-119fdcba.cjs +1 -0
  135. package/dist/chunks/slack-dark-cba39ccf.js +4 -0
  136. package/dist/chunks/slack-ochin-4a97383e.js +4 -0
  137. package/dist/chunks/slack-ochin-e53abb89.cjs +1 -0
  138. package/dist/chunks/snazzy-light-863adb77.js +4 -0
  139. package/dist/chunks/snazzy-light-aacd1ca8.cjs +1 -0
  140. package/dist/chunks/solarized-dark-18286b81.js +4 -0
  141. package/dist/chunks/solarized-dark-6c53ecf9.cjs +1 -0
  142. package/dist/chunks/solarized-light-abef5a54.cjs +1 -0
  143. package/dist/chunks/solarized-light-e7adfa5b.js +4 -0
  144. package/dist/chunks/synthwave-84-26ebbfca.js +4 -0
  145. package/dist/chunks/synthwave-84-ddb2c535.cjs +1 -0
  146. package/dist/chunks/tokyo-night-25368f86.js +4 -0
  147. package/dist/chunks/tokyo-night-6e0b49fd.cjs +1 -0
  148. package/dist/chunks/vesper-0ba44279.js +4 -0
  149. package/dist/chunks/vesper-a2e0b586.cjs +1 -0
  150. package/dist/chunks/vitesse-black-2be67ba4.cjs +1 -0
  151. package/dist/chunks/vitesse-black-33005deb.js +4 -0
  152. package/dist/chunks/vitesse-dark-82a14fc3.cjs +1 -0
  153. package/dist/chunks/vitesse-dark-9bb81e7a.js +4 -0
  154. package/dist/chunks/vitesse-light-2f9f7ba9.js +4 -0
  155. package/dist/chunks/vitesse-light-ee2c704b.cjs +1 -0
  156. package/dist/chunks/wasm-4cd10f60.cjs +1 -0
  157. package/dist/chunks/wasm-cb55701e.js +30 -0
  158. package/dist/index.cjs +1 -1
  159. package/dist/index.css +1 -1
  160. package/dist/index.js +5993 -5718
  161. package/dist/index.px.css +1 -1
  162. package/dist/index.tailwind.css +1 -1
  163. package/dist/tailwind.ts +1 -1
  164. package/dist/types/components/CodeBlockNode/CodeBlockNode.vue.d.ts +27 -0
  165. package/dist/types/components/NodeRenderer/CodeBlockNodeLoading.vue.d.ts +94 -0
  166. package/dist/types/components/NodeRenderer/asyncComponent.d.ts +1 -0
  167. package/dist/types/types/component-props.d.ts +3 -0
  168. package/package.json +8 -4
  169. package/dist/chunks/index-754b8598.js +0 -8
  170. package/dist/chunks/index-a4867ea2.cjs +0 -1
@@ -0,0 +1,1702 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __knownSymbol = (name, symbol) => {
8
+ if (symbol = Symbol[name])
9
+ return symbol;
10
+ throw Error("Symbol." + name + " is not defined");
11
+ };
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
37
+ var __publicField = (obj, key, value) => {
38
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
39
+ return value;
40
+ };
41
+ var __async = (__this, __arguments, generator) => {
42
+ return new Promise((resolve, reject) => {
43
+ var fulfilled = (value) => {
44
+ try {
45
+ step(generator.next(value));
46
+ } catch (e) {
47
+ reject(e);
48
+ }
49
+ };
50
+ var rejected = (value) => {
51
+ try {
52
+ step(generator.throw(value));
53
+ } catch (e) {
54
+ reject(e);
55
+ }
56
+ };
57
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
58
+ step((generator = generator.apply(__this, __arguments)).next());
59
+ });
60
+ };
61
+ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
62
+ var TextAccumulator = class {
63
+ constructor() {
64
+ __publicField(this, "chunks", []);
65
+ __publicField(this, "cached", "");
66
+ __publicField(this, "dirty", false);
67
+ __publicField(this, "length", 0);
68
+ }
69
+ append(chunk) {
70
+ if (!chunk)
71
+ return;
72
+ this.chunks.push(chunk);
73
+ this.length += chunk.length;
74
+ this.dirty = true;
75
+ if (this.chunks.length > 256)
76
+ this.compact();
77
+ }
78
+ clear(initial = "") {
79
+ this.chunks = initial ? [initial] : [];
80
+ this.cached = initial;
81
+ this.dirty = false;
82
+ this.length = initial.length;
83
+ }
84
+ toString() {
85
+ if (this.dirty) {
86
+ this.cached = this.chunks.join("");
87
+ this.dirty = false;
88
+ }
89
+ return this.cached;
90
+ }
91
+ compact() {
92
+ this.chunks = [this.chunks.join("")];
93
+ }
94
+ };
95
+ function createShell(container, maxHeight) {
96
+ container.replaceChildren();
97
+ const shell = document.createElement("div");
98
+ shell.className = "stream-diffs-shell";
99
+ shell.style.overflow = "auto";
100
+ shell.style.maxHeight = typeof maxHeight === "number" ? `${maxHeight}px` : maxHeight != null ? maxHeight : "none";
101
+ const surface = document.createElement("div");
102
+ surface.className = "stream-diffs-surface";
103
+ shell.appendChild(surface);
104
+ container.appendChild(shell);
105
+ return {
106
+ shell,
107
+ surface
108
+ };
109
+ }
110
+ function fileContents(name, contents, language) {
111
+ return {
112
+ name,
113
+ contents,
114
+ lang: language
115
+ };
116
+ }
117
+ var DiffSurfaceController = class {
118
+ constructor(input) {
119
+ __publicField(this, "input");
120
+ __publicField(this, "container");
121
+ __publicField(this, "surface");
122
+ __publicField(this, "instance");
123
+ __publicField(this, "diff");
124
+ __publicField(this, "selectedLines", null);
125
+ __publicField(this, "disposed", false);
126
+ __publicField(this, "renderListeners", /* @__PURE__ */ new Set());
127
+ __publicField(this, "visualRevision", 0);
128
+ __publicField(this, "visualReadyPromise", Promise.resolve(false));
129
+ __publicField(this, "resolveVisualReady");
130
+ __publicField(this, "module");
131
+ this.input = input;
132
+ }
133
+ mount(container) {
134
+ return __async(this, null, function* () {
135
+ this.disposed = false;
136
+ this.container = container;
137
+ this.surface = createShell(container).surface;
138
+ yield this.render();
139
+ });
140
+ }
141
+ update(input) {
142
+ return __async(this, null, function* () {
143
+ this.input = input;
144
+ if (this.surface)
145
+ yield this.render(true);
146
+ });
147
+ }
148
+ updateFile(file, annotations) {
149
+ return this.update({
150
+ kind: "file",
151
+ file,
152
+ annotations,
153
+ options: this.input.kind === "file" ? this.input.options : void 0,
154
+ workerManager: this.input.kind === "file" ? this.input.workerManager : void 0
155
+ });
156
+ }
157
+ updateDiff(oldFile, newFile, annotations) {
158
+ return this.update({
159
+ kind: "diff",
160
+ oldFile,
161
+ newFile,
162
+ annotations,
163
+ options: isDiffInput(this.input) ? this.input.options : void 0,
164
+ workerManager: isDiffInput(this.input) ? this.input.workerManager : void 0
165
+ });
166
+ }
167
+ updateParsedDiff(fileDiff, annotations) {
168
+ return this.update({
169
+ kind: "diff",
170
+ fileDiff,
171
+ annotations,
172
+ options: isDiffInput(this.input) ? this.input.options : void 0,
173
+ workerManager: isDiffInput(this.input) ? this.input.workerManager : void 0
174
+ });
175
+ }
176
+ updatePatch(patch, fileIndex = 0, annotations, patchIndex = 0) {
177
+ return this.update({
178
+ kind: "patch",
179
+ patch,
180
+ patchIndex,
181
+ fileIndex,
182
+ annotations,
183
+ options: this.input.kind === "patch" ? this.input.options : void 0,
184
+ workerManager: this.input.kind === "patch" ? this.input.workerManager : void 0
185
+ });
186
+ }
187
+ updateMergeConflict(file, annotations) {
188
+ return this.update({
189
+ kind: "merge-conflict",
190
+ file,
191
+ annotations,
192
+ options: this.input.kind === "merge-conflict" ? this.input.options : void 0,
193
+ workerManager: this.input.kind === "merge-conflict" ? this.input.workerManager : void 0
194
+ });
195
+ }
196
+ setSelectedLines(range) {
197
+ var _a;
198
+ this.selectedLines = range;
199
+ (_a = this.instance) == null ? void 0 : _a.setSelectedLines(range);
200
+ }
201
+ setAnnotations(annotations) {
202
+ if (!this.instance)
203
+ return;
204
+ if (this.input.kind === "file") {
205
+ this.input.annotations = annotations;
206
+ this.instance.setLineAnnotations(this.input.annotations);
207
+ } else {
208
+ this.input.annotations = annotations;
209
+ this.instance.setLineAnnotations(this.input.annotations);
210
+ }
211
+ this.emitRender();
212
+ }
213
+ setThemeType(themeType) {
214
+ var _a;
215
+ if (this.input.options)
216
+ this.input.options = __spreadProps(__spreadValues({}, this.input.options), {
217
+ themeType
218
+ });
219
+ else
220
+ this.input.options = { themeType };
221
+ (_a = this.instance) == null ? void 0 : _a.setThemeType(themeType);
222
+ }
223
+ setTheme(theme) {
224
+ return __async(this, null, function* () {
225
+ if (this.input.options)
226
+ this.input.options = __spreadProps(__spreadValues({}, this.input.options), {
227
+ theme
228
+ });
229
+ else
230
+ this.input.options = { theme };
231
+ if (this.surface)
232
+ yield this.render(false);
233
+ });
234
+ }
235
+ setOptions(options) {
236
+ return __async(this, null, function* () {
237
+ this.input.options = options;
238
+ if (this.surface)
239
+ yield this.render(false);
240
+ });
241
+ }
242
+ acceptReject(hunkIndex, action) {
243
+ if (!isDiffInput(this.input) || !this.diff)
244
+ throw new Error("acceptReject() requires a diff view");
245
+ const { diffAcceptRejectHunk } = this.module;
246
+ this.diff = diffAcceptRejectHunk(this.diff, hunkIndex, action);
247
+ this.instance.render({
248
+ fileDiff: this.diff,
249
+ containerWrapper: this.surface,
250
+ lineAnnotations: this.input.annotations
251
+ });
252
+ return this.diff;
253
+ }
254
+ resolveConflict(conflictIndex, resolution) {
255
+ if (this.input.kind !== "merge-conflict")
256
+ throw new Error("resolveConflict() requires a merge-conflict view");
257
+ const result = this.instance.resolveConflict(conflictIndex, resolution);
258
+ if (result) {
259
+ this.input.file = result.file;
260
+ this.diff = result.fileDiff;
261
+ }
262
+ return result == null ? void 0 : result.file;
263
+ }
264
+ getResolvedFile() {
265
+ var _a, _b;
266
+ if (!isDiffInput(this.input) || !this.diff || this.diff.isPartial)
267
+ return void 0;
268
+ const source = "newFile" in this.input ? this.input.newFile : void 0;
269
+ return {
270
+ name: (_a = source == null ? void 0 : source.name) != null ? _a : this.diff.name,
271
+ contents: this.diff.additionLines.join(""),
272
+ lang: (_b = source == null ? void 0 : source.lang) != null ? _b : this.diff.lang
273
+ };
274
+ }
275
+ getDiff() {
276
+ return this.diff;
277
+ }
278
+ getInput() {
279
+ return this.input;
280
+ }
281
+ getNativeInstance() {
282
+ return this.instance;
283
+ }
284
+ onDidRender(listener) {
285
+ this.renderListeners.add(listener);
286
+ return { dispose: () => this.renderListeners.delete(listener) };
287
+ }
288
+ whenVisualReady() {
289
+ return __async(this, null, function* () {
290
+ let pending = this.visualReadyPromise;
291
+ for (; ; ) {
292
+ const ready = yield pending;
293
+ if (pending === this.visualReadyPromise)
294
+ return ready;
295
+ pending = this.visualReadyPromise;
296
+ }
297
+ });
298
+ }
299
+ dispose() {
300
+ var _a, _b;
301
+ this.disposed = true;
302
+ this.invalidateVisualReady();
303
+ (_a = this.instance) == null ? void 0 : _a.cleanUp();
304
+ this.instance = void 0;
305
+ this.surface = void 0;
306
+ (_b = this.container) == null ? void 0 : _b.replaceChildren();
307
+ this.container = void 0;
308
+ this.renderListeners.clear();
309
+ }
310
+ render(resetDiff = true) {
311
+ return __async(this, null, function* () {
312
+ var _a, _b, _c, _d, _e, _f, _g;
313
+ const surface = this.surface;
314
+ if (!surface || this.disposed)
315
+ return;
316
+ const visualRevision = this.beginVisualRender();
317
+ const mod = (_a = this.module) != null ? _a : this.module = yield import("./index-42602bc0.js");
318
+ if (this.disposed || surface !== this.surface)
319
+ return;
320
+ (_b = this.instance) == null ? void 0 : _b.cleanUp();
321
+ surface.replaceChildren();
322
+ if (this.input.kind === "file") {
323
+ const instance2 = new mod.File(withInternalPostRender(this.input.options, () => this.markVisualReady(visualRevision)), this.input.workerManager);
324
+ instance2.render({
325
+ file: this.input.file,
326
+ containerWrapper: surface,
327
+ lineAnnotations: this.input.annotations
328
+ });
329
+ this.instance = instance2;
330
+ instance2.setSelectedLines(this.selectedLines);
331
+ this.diff = void 0;
332
+ return;
333
+ }
334
+ if (isDiffInput(this.input)) {
335
+ if (resetDiff || !this.diff)
336
+ if (this.input.kind === "patch") {
337
+ const patch = mod.parsePatchFiles(this.input.patch)[(_c = this.input.patchIndex) != null ? _c : 0];
338
+ if (!patch)
339
+ throw new Error(`Patch does not contain patch index ${(_d = this.input.patchIndex) != null ? _d : 0}`);
340
+ const fileDiff = patch.files[(_e = this.input.fileIndex) != null ? _e : 0];
341
+ if (!fileDiff)
342
+ throw new Error(`Patch does not contain file index ${(_f = this.input.fileIndex) != null ? _f : 0}`);
343
+ this.diff = fileDiff;
344
+ } else if ("fileDiff" in this.input)
345
+ this.diff = this.input.fileDiff;
346
+ else
347
+ this.diff = mod.parseDiffFromFile(this.input.oldFile, this.input.newFile, (_g = this.input.options) == null ? void 0 : _g.parseDiffOptions);
348
+ const instance2 = new mod.FileDiff(withInternalPostRender(this.input.options, () => this.markVisualReady(visualRevision)), this.input.workerManager);
349
+ instance2.render({
350
+ fileDiff: this.diff,
351
+ containerWrapper: surface,
352
+ lineAnnotations: this.input.annotations
353
+ });
354
+ this.instance = instance2;
355
+ instance2.setSelectedLines(this.selectedLines);
356
+ return;
357
+ }
358
+ const instance = new mod.UnresolvedFile(withInternalPostRender(this.input.options, () => this.markVisualReady(visualRevision)), this.input.workerManager);
359
+ instance.render({
360
+ file: this.input.file,
361
+ containerWrapper: surface,
362
+ lineAnnotations: this.input.annotations
363
+ });
364
+ this.instance = instance;
365
+ instance.setSelectedLines(this.selectedLines);
366
+ this.diff = instance.fileDiff;
367
+ });
368
+ }
369
+ emitRender() {
370
+ for (const listener of this.renderListeners)
371
+ listener();
372
+ }
373
+ beginVisualRender() {
374
+ var _a;
375
+ (_a = this.resolveVisualReady) == null ? void 0 : _a.call(this, false);
376
+ const revision = ++this.visualRevision;
377
+ this.visualReadyPromise = new Promise((resolve) => {
378
+ this.resolveVisualReady = resolve;
379
+ });
380
+ return revision;
381
+ }
382
+ markVisualReady(revision) {
383
+ var _a;
384
+ if (this.disposed || revision !== this.visualRevision)
385
+ return;
386
+ (_a = this.resolveVisualReady) == null ? void 0 : _a.call(this, true);
387
+ this.resolveVisualReady = void 0;
388
+ this.emitRender();
389
+ }
390
+ invalidateVisualReady() {
391
+ var _a;
392
+ this.visualRevision++;
393
+ (_a = this.resolveVisualReady) == null ? void 0 : _a.call(this, false);
394
+ this.resolveVisualReady = void 0;
395
+ }
396
+ };
397
+ function createDiffSurface(input) {
398
+ return new DiffSurfaceController(input);
399
+ }
400
+ function withTokenTransformer(options) {
401
+ if (!options || options.useTokenTransformer === true)
402
+ return options;
403
+ if (!options.onTokenClick && !options.onTokenEnter && !options.onTokenLeave)
404
+ return options;
405
+ return __spreadProps(__spreadValues({}, options), {
406
+ useTokenTransformer: true
407
+ });
408
+ }
409
+ function withInternalPostRender(options, onRender) {
410
+ const transformed = withTokenTransformer(options);
411
+ const userPostRender = transformed == null ? void 0 : transformed.onPostRender;
412
+ return __spreadProps(__spreadValues({}, transformed), {
413
+ onPostRender(...args) {
414
+ userPostRender == null ? void 0 : userPostRender(...args);
415
+ onRender();
416
+ }
417
+ });
418
+ }
419
+ function isDiffInput(input) {
420
+ return input.kind === "diff" || input.kind === "patch";
421
+ }
422
+ var CodeStreamController = class {
423
+ constructor(options = {}) {
424
+ __publicField(this, "options");
425
+ __publicField(this, "state", "idle");
426
+ __publicField(this, "stats", {
427
+ characters: 0,
428
+ lines: 0,
429
+ writes: 0,
430
+ resets: 0,
431
+ renderMode: "plain-text",
432
+ overflowed: false
433
+ });
434
+ __publicField(this, "text", new TextAccumulator());
435
+ __publicField(this, "pending", []);
436
+ __publicField(this, "scheduled");
437
+ __publicField(this, "generation", 0);
438
+ __publicField(this, "container");
439
+ __publicField(this, "shell");
440
+ __publicField(this, "surface");
441
+ __publicField(this, "finalizedSurface");
442
+ __publicField(this, "plainText");
443
+ __publicField(this, "finalizePromise");
444
+ __publicField(this, "renderListeners", /* @__PURE__ */ new Set());
445
+ __publicField(this, "finalizedRenderSubscription");
446
+ this.options = options;
447
+ }
448
+ mount(container) {
449
+ return __async(this, null, function* () {
450
+ var _a, _b, _c, _d, _e;
451
+ if (this.state === "disposed")
452
+ throw new Error("Cannot mount a disposed code stream. Create a new controller instead.");
453
+ ++this.generation;
454
+ this.cancelScheduledFlush();
455
+ (_a = this.finalizedSurface) == null ? void 0 : _a.dispose();
456
+ (_b = this.finalizedRenderSubscription) == null ? void 0 : _b.dispose();
457
+ (_c = this.container) == null ? void 0 : _c.replaceChildren();
458
+ this.finalizedSurface = void 0;
459
+ this.finalizedRenderSubscription = void 0;
460
+ this.plainText = void 0;
461
+ this.pending = [];
462
+ this.setState("mounting");
463
+ this.container = container;
464
+ const { shell, surface } = createShell(container, this.options.maxHeight);
465
+ this.shell = shell;
466
+ this.surface = surface;
467
+ this.mountPlainText(surface);
468
+ (_e = (_d = this.stats).startedAt) != null ? _e : _d.startedAt = performance.now();
469
+ this.setState("streaming");
470
+ });
471
+ }
472
+ append(chunk) {
473
+ if (!chunk)
474
+ return;
475
+ if (this.state === "finalized" || this.state === "finalizing" || this.state === "disposed")
476
+ throw new Error(`Cannot append while stream is ${this.state}`);
477
+ this.text.append(chunk);
478
+ this.stats.characters = this.text.length;
479
+ this.stats.lines += countNewlines(chunk) + (this.stats.lines === 0 ? 1 : 0);
480
+ this.pending.push(chunk);
481
+ this.scheduleFlush();
482
+ }
483
+ updateSnapshot(content) {
484
+ var _a;
485
+ const previous = this.text.toString();
486
+ if (content.startsWith(previous)) {
487
+ this.append(content.slice(previous.length));
488
+ return;
489
+ }
490
+ const behavior = (_a = this.options.nonAppendBehavior) != null ? _a : "reset";
491
+ if (behavior === "ignore")
492
+ return;
493
+ if (behavior === "throw")
494
+ throw new Error("Snapshot violates the append-only stream contract");
495
+ return this.reset(content);
496
+ }
497
+ consume(source) {
498
+ return __async(this, null, function* () {
499
+ try {
500
+ if (Symbol.asyncIterator in source)
501
+ try {
502
+ for (var iter = __forAwait(source), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
503
+ const chunk = temp.value;
504
+ this.append(chunk);
505
+ }
506
+ } catch (temp) {
507
+ error = [temp];
508
+ } finally {
509
+ try {
510
+ more && (temp = iter.return) && (yield temp.call(iter));
511
+ } finally {
512
+ if (error)
513
+ throw error[0];
514
+ }
515
+ }
516
+ else {
517
+ const reader = source.getReader();
518
+ try {
519
+ while (true) {
520
+ const { done, value } = yield reader.read();
521
+ if (done)
522
+ break;
523
+ this.append(value);
524
+ }
525
+ } finally {
526
+ reader.releaseLock();
527
+ }
528
+ }
529
+ } catch (error2) {
530
+ this.fail(error2);
531
+ throw error2;
532
+ }
533
+ });
534
+ }
535
+ flush() {
536
+ return __async(this, null, function* () {
537
+ var _a;
538
+ this.cancelScheduledFlush();
539
+ if (!this.pending.length)
540
+ return;
541
+ const shouldFollow = this.shouldFollowViewport();
542
+ const batch = this.pending.join("");
543
+ this.pending.length = 0;
544
+ (_a = this.plainText) == null ? void 0 : _a.append(batch);
545
+ this.stats.writes++;
546
+ this.followViewport(shouldFollow);
547
+ this.emitRender();
548
+ });
549
+ }
550
+ finalize(options = { view: "stream" }) {
551
+ if (this.state === "finalized")
552
+ return Promise.resolve();
553
+ if (this.finalizePromise)
554
+ return this.finalizePromise;
555
+ const promise = this.performFinalize(options).finally(() => {
556
+ if (this.finalizePromise === promise)
557
+ this.finalizePromise = void 0;
558
+ });
559
+ this.finalizePromise = promise;
560
+ return promise;
561
+ }
562
+ performFinalize(options) {
563
+ return __async(this, null, function* () {
564
+ var _a, _b, _e, _f;
565
+ if (this.state === "disposed")
566
+ throw new Error("Cannot finalize a disposed code stream");
567
+ const generation = this.generation;
568
+ this.setState("finalizing");
569
+ yield this.flush();
570
+ if (generation !== this.generation)
571
+ return;
572
+ this.stats.finalizedAt = performance.now();
573
+ if (!options.view || options.view === "stream") {
574
+ this.setState("finalized");
575
+ return;
576
+ }
577
+ const surface = this.surface;
578
+ if (!surface)
579
+ throw new Error("Mount the stream before finalizing to a file or diff view");
580
+ const name = (_b = this.options.fileName) != null ? _b : `code.${(_a = this.options.language) != null ? _a : "txt"}`;
581
+ const current = fileContents(name, this.getText(), this.options.language);
582
+ let finalizedSurface;
583
+ if (options.view === "file") {
584
+ const _c = options, { annotations, workerManager, view: _ } = _c, fileOptions = __objRest(_c, ["annotations", "workerManager", "view"]);
585
+ finalizedSurface = createDiffSurface({
586
+ kind: "file",
587
+ file: current,
588
+ annotations,
589
+ options: __spreadValues({
590
+ theme: this.options.theme,
591
+ themeType: this.options.themeType
592
+ }, fileOptions),
593
+ workerManager: workerManager != null ? workerManager : this.options.workerManager
594
+ });
595
+ } else {
596
+ const _d = options, { annotations, original, workerManager, view: _ } = _d, diffOptions = __objRest(_d, ["annotations", "original", "workerManager", "view"]);
597
+ finalizedSurface = createDiffSurface({
598
+ kind: "diff",
599
+ oldFile: fileContents(name, original, this.options.language),
600
+ newFile: current,
601
+ annotations,
602
+ options: __spreadValues({
603
+ theme: this.options.theme,
604
+ themeType: this.options.themeType
605
+ }, diffOptions),
606
+ workerManager: workerManager != null ? workerManager : this.options.workerManager
607
+ });
608
+ }
609
+ const staging = document.createElement("div");
610
+ staging.className = "stream-diffs-finalized";
611
+ yield finalizedSurface.mount(staging);
612
+ if (generation !== this.generation) {
613
+ finalizedSurface.dispose();
614
+ return;
615
+ }
616
+ const shell = this.shell;
617
+ const scrollTop = (_e = shell == null ? void 0 : shell.scrollTop) != null ? _e : 0;
618
+ const distanceToBottom = shell ? shell.scrollHeight - shell.scrollTop - shell.clientHeight : 0;
619
+ surface.replaceWith(staging);
620
+ this.surface = staging;
621
+ this.plainText = void 0;
622
+ this.finalizedSurface = finalizedSurface;
623
+ this.finalizedRenderSubscription = finalizedSurface.onDidRender(() => this.emitRender());
624
+ if (shell)
625
+ if (this.options.autoScroll === "always" || this.options.autoScroll !== "never" && distanceToBottom <= ((_f = this.options.autoScrollThresholdPx) != null ? _f : 32))
626
+ shell.scrollTop = shell.scrollHeight;
627
+ else
628
+ shell.scrollTop = scrollTop;
629
+ this.setState("finalized");
630
+ this.emitRender();
631
+ });
632
+ }
633
+ reset(initialContent = "") {
634
+ return __async(this, null, function* () {
635
+ var _a, _b;
636
+ const container = this.container;
637
+ ++this.generation;
638
+ this.cancelScheduledFlush();
639
+ (_a = this.finalizedSurface) == null ? void 0 : _a.dispose();
640
+ (_b = this.finalizedRenderSubscription) == null ? void 0 : _b.dispose();
641
+ this.finalizedSurface = void 0;
642
+ this.finalizedRenderSubscription = void 0;
643
+ this.plainText = void 0;
644
+ this.pending = [];
645
+ this.finalizePromise = void 0;
646
+ this.text.clear();
647
+ this.stats.resets++;
648
+ this.stats.characters = 0;
649
+ this.stats.lines = 0;
650
+ this.stats.renderMode = "plain-text";
651
+ this.stats.overflowed = false;
652
+ this.setState("idle");
653
+ if (initialContent)
654
+ this.append(initialContent);
655
+ if (container)
656
+ yield this.mount(container);
657
+ });
658
+ }
659
+ setThemeType(type) {
660
+ var _a;
661
+ this.options.themeType = type;
662
+ (_a = this.finalizedSurface) == null ? void 0 : _a.setThemeType(type);
663
+ }
664
+ setTheme(theme) {
665
+ return __async(this, null, function* () {
666
+ this.options.theme = theme;
667
+ if (this.finalizedSurface)
668
+ yield this.finalizedSurface.setTheme(theme);
669
+ });
670
+ }
671
+ setLanguage(language) {
672
+ return __async(this, null, function* () {
673
+ if (language === this.options.language)
674
+ return;
675
+ this.options.language = language;
676
+ if (!this.finalizedSurface)
677
+ return;
678
+ const input = this.finalizedSurface.getInput();
679
+ if (input.kind === "file")
680
+ yield this.finalizedSurface.updateFile(__spreadProps(__spreadValues({}, input.file), {
681
+ lang: language
682
+ }), input.annotations);
683
+ else if (input.kind === "diff" && "oldFile" in input)
684
+ yield this.finalizedSurface.updateDiff(__spreadProps(__spreadValues({}, input.oldFile), {
685
+ lang: language
686
+ }), __spreadProps(__spreadValues({}, input.newFile), {
687
+ lang: language
688
+ }), input.annotations);
689
+ });
690
+ }
691
+ getText() {
692
+ return this.text.toString();
693
+ }
694
+ getState() {
695
+ return this.state;
696
+ }
697
+ getStats() {
698
+ return __spreadValues({}, this.stats);
699
+ }
700
+ getElement() {
701
+ return this.shell;
702
+ }
703
+ getFinalizedSurface() {
704
+ return this.finalizedSurface;
705
+ }
706
+ onDidRender(listener) {
707
+ this.renderListeners.add(listener);
708
+ return { dispose: () => this.renderListeners.delete(listener) };
709
+ }
710
+ dispose() {
711
+ var _a, _b, _c;
712
+ ++this.generation;
713
+ this.cancelScheduledFlush();
714
+ (_a = this.finalizedSurface) == null ? void 0 : _a.dispose();
715
+ (_b = this.finalizedRenderSubscription) == null ? void 0 : _b.dispose();
716
+ (_c = this.container) == null ? void 0 : _c.replaceChildren();
717
+ this.plainText = void 0;
718
+ this.container = void 0;
719
+ this.surface = void 0;
720
+ this.shell = void 0;
721
+ this.finalizedSurface = void 0;
722
+ this.finalizedRenderSubscription = void 0;
723
+ this.finalizePromise = void 0;
724
+ this.renderListeners.clear();
725
+ this.setState("disposed");
726
+ }
727
+ scheduleFlush() {
728
+ var _a;
729
+ if (this.scheduled != null || !this.plainText)
730
+ return;
731
+ const strategy = (_a = this.options.flushStrategy) != null ? _a : "raf";
732
+ if (strategy === "raf" && typeof requestAnimationFrame === "function")
733
+ this.scheduled = requestAnimationFrame(() => void this.flush());
734
+ else
735
+ this.scheduled = globalThis.setTimeout(() => void this.flush(), strategy === "raf" ? 0 : strategy.intervalMs);
736
+ }
737
+ cancelScheduledFlush() {
738
+ if (this.scheduled == null)
739
+ return;
740
+ if (typeof cancelAnimationFrame === "function")
741
+ cancelAnimationFrame(this.scheduled);
742
+ clearTimeout(this.scheduled);
743
+ this.scheduled = void 0;
744
+ }
745
+ shouldFollowViewport() {
746
+ var _a;
747
+ const shell = this.shell;
748
+ if (!shell || this.options.autoScroll === "never")
749
+ return false;
750
+ if (this.options.autoScroll === "always")
751
+ return true;
752
+ return shell.scrollHeight - shell.scrollTop - shell.clientHeight <= ((_a = this.options.autoScrollThresholdPx) != null ? _a : 32);
753
+ }
754
+ followViewport(shouldFollow = this.shouldFollowViewport()) {
755
+ if (this.shell && shouldFollow)
756
+ this.shell.scrollTop = this.shell.scrollHeight;
757
+ }
758
+ mountPlainText(surface) {
759
+ const pre = document.createElement("pre");
760
+ pre.className = "stream-diffs-plain-text";
761
+ pre.dataset.streamDiffsState = "streaming";
762
+ pre.style.margin = "0";
763
+ pre.style.whiteSpace = this.options.wrap ? "pre-wrap" : "pre";
764
+ pre.style.overflowWrap = this.options.wrap ? "anywhere" : "normal";
765
+ pre.textContent = this.getText();
766
+ surface.replaceChildren(pre);
767
+ this.plainText = pre;
768
+ }
769
+ setState(state) {
770
+ var _a, _b;
771
+ this.state = state;
772
+ (_b = (_a = this.options).onStateChange) == null ? void 0 : _b.call(_a, state);
773
+ }
774
+ emitRender() {
775
+ for (const listener of this.renderListeners)
776
+ listener();
777
+ }
778
+ fail(error) {
779
+ var _a, _b;
780
+ if (this.state === "disposed")
781
+ return;
782
+ this.setState("error");
783
+ (_b = (_a = this.options).onError) == null ? void 0 : _b.call(_a, error);
784
+ }
785
+ };
786
+ function countNewlines(value) {
787
+ let count = 0;
788
+ for (let index = 0; index < value.length; index++)
789
+ if (value.charCodeAt(index) === 10)
790
+ count++;
791
+ return count;
792
+ }
793
+ function createCodeStream(options) {
794
+ return new CodeStreamController(options);
795
+ }
796
+ var DiffStreamController = class {
797
+ constructor(options = {}) {
798
+ __publicField(this, "options");
799
+ __publicField(this, "state", "idle");
800
+ __publicField(this, "generation", 0);
801
+ __publicField(this, "original", "");
802
+ __publicField(this, "modified", "");
803
+ __publicField(this, "container");
804
+ __publicField(this, "shell");
805
+ __publicField(this, "surface");
806
+ __publicField(this, "finalizedSurface");
807
+ __publicField(this, "finalizePromise");
808
+ __publicField(this, "renderListeners", /* @__PURE__ */ new Set());
809
+ __publicField(this, "finalizedRenderSubscription");
810
+ this.options = options;
811
+ }
812
+ mount(_0) {
813
+ return __async(this, arguments, function* (container, original = this.original, modified = this.modified) {
814
+ var _a, _b, _c;
815
+ if (this.state === "disposed")
816
+ throw new Error("Cannot mount a disposed diff stream. Create a new controller instead.");
817
+ ++this.generation;
818
+ this.original = original;
819
+ this.modified = modified;
820
+ (_a = this.finalizedSurface) == null ? void 0 : _a.dispose();
821
+ (_b = this.finalizedRenderSubscription) == null ? void 0 : _b.dispose();
822
+ (_c = this.container) == null ? void 0 : _c.replaceChildren();
823
+ this.finalizedSurface = void 0;
824
+ this.finalizedRenderSubscription = void 0;
825
+ this.setState("mounting");
826
+ this.container = container;
827
+ const { shell, surface } = createShell(container, this.options.maxHeight);
828
+ this.shell = shell;
829
+ this.surface = surface;
830
+ this.renderPre();
831
+ this.setState("streaming");
832
+ });
833
+ }
834
+ update(original, modified) {
835
+ if (this.state === "disposed")
836
+ throw new Error("Cannot update a disposed diff stream");
837
+ this.original = original;
838
+ this.modified = modified;
839
+ if (this.finalizedSurface)
840
+ return this.finalizedSurface.updateDiff(this.asFile(original), this.asFile(modified));
841
+ this.renderPre();
842
+ this.emitRender();
843
+ return Promise.resolve();
844
+ }
845
+ finalize(annotations) {
846
+ if (this.state === "finalized")
847
+ return Promise.resolve(this.finalizedSurface);
848
+ if (this.finalizePromise)
849
+ return this.finalizePromise;
850
+ const promise = this.performFinalize(annotations).finally(() => {
851
+ if (this.finalizePromise === promise)
852
+ this.finalizePromise = void 0;
853
+ });
854
+ this.finalizePromise = promise;
855
+ return promise;
856
+ }
857
+ performFinalize(annotations) {
858
+ return __async(this, null, function* () {
859
+ var _a, _b;
860
+ if (this.state === "disposed")
861
+ throw new Error("Cannot finalize a disposed diff stream");
862
+ const surface = this.surface;
863
+ if (!surface)
864
+ throw new Error("Mount the diff stream before finalizing it");
865
+ const generation = this.generation;
866
+ this.setState("finalizing");
867
+ const finalized = createDiffSurface({
868
+ kind: "diff",
869
+ oldFile: this.asFile(this.original),
870
+ newFile: this.asFile(this.modified),
871
+ annotations,
872
+ options: __spreadProps(__spreadValues({}, this.options), {
873
+ diffStyle: (_a = this.options.diffStyle) != null ? _a : "unified"
874
+ }),
875
+ workerManager: this.options.workerManager
876
+ });
877
+ const staging = document.createElement("div");
878
+ staging.className = "stream-diffs-finalized";
879
+ yield finalized.mount(staging);
880
+ if (generation !== this.generation) {
881
+ finalized.dispose();
882
+ return;
883
+ }
884
+ const shell = this.shell;
885
+ const scrollTop = (_b = shell == null ? void 0 : shell.scrollTop) != null ? _b : 0;
886
+ surface.replaceWith(staging);
887
+ this.surface = staging;
888
+ this.finalizedSurface = finalized;
889
+ this.finalizedRenderSubscription = finalized.onDidRender(() => this.emitRender());
890
+ if (shell)
891
+ shell.scrollTop = scrollTop;
892
+ this.setState("finalized");
893
+ this.emitRender();
894
+ return finalized;
895
+ });
896
+ }
897
+ setThemeType(type) {
898
+ var _a;
899
+ this.options.themeType = type;
900
+ (_a = this.finalizedSurface) == null ? void 0 : _a.setThemeType(type);
901
+ }
902
+ setTheme(theme) {
903
+ return __async(this, null, function* () {
904
+ this.options.theme = theme;
905
+ if (this.finalizedSurface)
906
+ yield this.finalizedSurface.setTheme(theme);
907
+ });
908
+ }
909
+ setLanguage(language) {
910
+ return __async(this, null, function* () {
911
+ if (language === this.options.language)
912
+ return;
913
+ this.options.language = language;
914
+ if (this.finalizedSurface) {
915
+ const input = this.finalizedSurface.getInput();
916
+ if (input.kind === "diff" && "oldFile" in input)
917
+ yield this.finalizedSurface.updateDiff(__spreadProps(__spreadValues({}, input.oldFile), {
918
+ lang: language
919
+ }), __spreadProps(__spreadValues({}, input.newFile), {
920
+ lang: language
921
+ }), input.annotations);
922
+ return;
923
+ }
924
+ this.renderPre();
925
+ });
926
+ }
927
+ getOriginal() {
928
+ return this.original;
929
+ }
930
+ getModified() {
931
+ return this.modified;
932
+ }
933
+ getState() {
934
+ return this.state;
935
+ }
936
+ getElement() {
937
+ return this.shell;
938
+ }
939
+ getFinalizedSurface() {
940
+ return this.finalizedSurface;
941
+ }
942
+ onDidRender(listener) {
943
+ this.renderListeners.add(listener);
944
+ return { dispose: () => this.renderListeners.delete(listener) };
945
+ }
946
+ dispose() {
947
+ var _a, _b, _c;
948
+ ++this.generation;
949
+ (_a = this.finalizedSurface) == null ? void 0 : _a.dispose();
950
+ (_b = this.finalizedRenderSubscription) == null ? void 0 : _b.dispose();
951
+ (_c = this.container) == null ? void 0 : _c.replaceChildren();
952
+ this.container = void 0;
953
+ this.shell = void 0;
954
+ this.surface = void 0;
955
+ this.finalizedSurface = void 0;
956
+ this.finalizedRenderSubscription = void 0;
957
+ this.finalizePromise = void 0;
958
+ this.renderListeners.clear();
959
+ this.setState("disposed");
960
+ }
961
+ renderPre() {
962
+ var _a, _b;
963
+ const surface = this.surface;
964
+ if (!surface || this.finalizedSurface)
965
+ return;
966
+ const root = document.createElement("div");
967
+ root.className = `stream-diffs-diff-pre stream-diffs-diff-pre--${(_a = this.options.diffStyle) != null ? _a : "unified"}`;
968
+ root.dataset.streamDiffsState = "streaming";
969
+ root.style.minWidth = "max-content";
970
+ if (((_b = this.options.diffStyle) != null ? _b : "unified") === "split") {
971
+ root.style.display = "grid";
972
+ root.style.gridTemplateColumns = "minmax(0, 1fr) minmax(0, 1fr)";
973
+ root.append(this.createPre(this.original, "deletions"), this.createPre(this.modified, "additions"));
974
+ } else
975
+ root.append(this.createPre(createUnifiedPreview(this.original, this.modified), "unified"));
976
+ surface.replaceChildren(root);
977
+ }
978
+ createPre(text, side) {
979
+ const pre = document.createElement("pre");
980
+ pre.className = `stream-diffs-diff-pre__pane stream-diffs-diff-pre__pane--${side}`;
981
+ pre.dataset.side = side;
982
+ pre.style.margin = "0";
983
+ pre.style.whiteSpace = this.options.wrap ? "pre-wrap" : "pre";
984
+ pre.style.overflowWrap = this.options.wrap ? "anywhere" : "normal";
985
+ pre.textContent = text;
986
+ return pre;
987
+ }
988
+ asFile(contents) {
989
+ var _a, _b;
990
+ return fileContents((_b = this.options.fileName) != null ? _b : `code.${(_a = this.options.language) != null ? _a : "txt"}`, contents, this.options.language);
991
+ }
992
+ setState(state) {
993
+ var _a, _b;
994
+ this.state = state;
995
+ (_b = (_a = this.options).onStateChange) == null ? void 0 : _b.call(_a, state);
996
+ }
997
+ emitRender() {
998
+ for (const listener of this.renderListeners)
999
+ listener();
1000
+ }
1001
+ };
1002
+ function createUnifiedPreview(original, modified) {
1003
+ const before = original.split("\n");
1004
+ const after = modified.split("\n");
1005
+ let prefix = 0;
1006
+ while (prefix < before.length && prefix < after.length && before[prefix] === after[prefix])
1007
+ prefix++;
1008
+ let suffix = 0;
1009
+ while (suffix < before.length - prefix && suffix < after.length - prefix && before[before.length - suffix - 1] === after[after.length - suffix - 1])
1010
+ suffix++;
1011
+ return [
1012
+ ...before.slice(0, prefix).map((line) => ` ${line}`),
1013
+ ...before.slice(prefix, before.length - suffix).map((line) => `- ${line}`),
1014
+ ...after.slice(prefix, after.length - suffix).map((line) => `+ ${line}`),
1015
+ ...before.slice(before.length - suffix).map((line) => ` ${line}`)
1016
+ ].join("\n");
1017
+ }
1018
+ function createDiffStream(options) {
1019
+ return new DiffStreamController(options);
1020
+ }
1021
+ function useMonaco(options = {}) {
1022
+ let stream;
1023
+ let diffStream;
1024
+ let surface;
1025
+ let editorAdapter;
1026
+ let diffAdapter;
1027
+ let language = "text";
1028
+ let original = "";
1029
+ let modified = "";
1030
+ let container;
1031
+ let visualRevision = 0;
1032
+ let themeType = "system";
1033
+ let appliedTheme = resolveTheme(options);
1034
+ let appliedThemePairKey = getThemePairKey(options);
1035
+ const shared = {
1036
+ disableLineNumbers: options.lineNumbers === false,
1037
+ overflow: options.wordWrap === "on" ? "wrap" : "scroll",
1038
+ enableLineSelection: options.enableLineSelection
1039
+ };
1040
+ const sharedOptions = () => __spreadProps(__spreadValues({}, shared), {
1041
+ theme: appliedTheme,
1042
+ themeType
1043
+ });
1044
+ function createEditor(target, code, lang) {
1045
+ return __async(this, null, function* () {
1046
+ var _a2;
1047
+ cleanupEditor();
1048
+ const revision = visualRevision;
1049
+ applyEditorStyles(target, options);
1050
+ container = target;
1051
+ language = normalizeSurfaceLanguage(lang);
1052
+ if (shouldRenderMergeConflict(code))
1053
+ return createMergeConflictEditor(target, code, language);
1054
+ if (options.stream === false)
1055
+ return createStaticFileEditor(target, code, language);
1056
+ const createdStream = new CodeStreamController(__spreadProps(__spreadValues(__spreadValues({}, sharedOptions()), pickPierreOptions(options)), {
1057
+ fileName: `code.${language}`,
1058
+ language,
1059
+ maxHeight: options.MAX_HEIGHT,
1060
+ autoScroll: options.autoScrollOnUpdate === false ? "never" : "near-bottom",
1061
+ autoScrollThresholdPx: options.autoScrollThresholdPx,
1062
+ workerManager: options.workerManager
1063
+ }));
1064
+ stream = createdStream;
1065
+ createdStream.append(code);
1066
+ yield createdStream.mount(target);
1067
+ if (revision !== visualRevision || stream !== createdStream || container !== target) {
1068
+ createdStream.dispose();
1069
+ throw new Error("Editor creation was cancelled");
1070
+ }
1071
+ (_a2 = options.onController) == null ? void 0 : _a2.call(options, createdStream);
1072
+ editorAdapter = createEditorAdapter(() => createdStream.getText(), target, () => createdStream.getFinalizedSurface(), (listener) => createdStream.onDidRender(listener));
1073
+ return editorAdapter;
1074
+ });
1075
+ }
1076
+ function createDiffEditor(target, oldCode, newCode, lang) {
1077
+ return __async(this, null, function* () {
1078
+ var _a2, _b, _c, _d;
1079
+ cleanupEditor();
1080
+ const revision = visualRevision;
1081
+ applyEditorStyles(target, options);
1082
+ container = target;
1083
+ language = normalizeSurfaceLanguage(lang);
1084
+ original = oldCode;
1085
+ modified = newCode;
1086
+ let createdSurface;
1087
+ let createdDiffStream;
1088
+ if (options.stream === false) {
1089
+ createdSurface = createDiffSurface({
1090
+ kind: "diff",
1091
+ oldFile: asFile(oldCode),
1092
+ newFile: asFile(newCode),
1093
+ annotations: options.lineAnnotations,
1094
+ workerManager: options.workerManager,
1095
+ options: __spreadValues(__spreadProps(__spreadValues({}, sharedOptions()), {
1096
+ diffStyle: (_a2 = options.diffStyle) != null ? _a2 : options.renderSideBySide === false ? "unified" : "split"
1097
+ }), pickPierreOptions(options))
1098
+ });
1099
+ surface = createdSurface;
1100
+ yield createdSurface.mount(target);
1101
+ if (revision !== visualRevision || surface !== createdSurface || container !== target) {
1102
+ createdSurface.dispose();
1103
+ throw new Error("Editor creation was cancelled");
1104
+ }
1105
+ (_b = options.onController) == null ? void 0 : _b.call(options, createdSurface);
1106
+ } else {
1107
+ createdDiffStream = new DiffStreamController(__spreadProps(__spreadValues(__spreadValues({}, sharedOptions()), pickPierreOptions(options)), {
1108
+ fileName: `code.${language}`,
1109
+ language,
1110
+ diffStyle: (_c = options.diffStyle) != null ? _c : options.renderSideBySide === false ? "unified" : "split",
1111
+ maxHeight: options.MAX_HEIGHT,
1112
+ wrap: options.wordWrap === "on",
1113
+ workerManager: options.workerManager
1114
+ }));
1115
+ diffStream = createdDiffStream;
1116
+ yield createdDiffStream.mount(target, oldCode, newCode);
1117
+ if (revision !== visualRevision || diffStream !== createdDiffStream || container !== target) {
1118
+ createdDiffStream.dispose();
1119
+ throw new Error("Editor creation was cancelled");
1120
+ }
1121
+ (_d = options.onController) == null ? void 0 : _d.call(options, createdDiffStream);
1122
+ }
1123
+ diffAdapter = createDiffAdapter(() => original, () => modified, target, () => createdSurface != null ? createdSurface : createdDiffStream == null ? void 0 : createdDiffStream.getFinalizedSurface());
1124
+ return diffAdapter;
1125
+ });
1126
+ }
1127
+ function updateCode(_0) {
1128
+ return __async(this, arguments, function* (code, lang = language) {
1129
+ const nextLanguage = normalizeSurfaceLanguage(lang);
1130
+ if (shouldRenderMergeConflict(code)) {
1131
+ if ((surface == null ? void 0 : surface.getInput().kind) === "merge-conflict") {
1132
+ language = nextLanguage;
1133
+ yield surface.updateMergeConflict(asFile(code), options.lineAnnotations);
1134
+ } else if (container)
1135
+ yield createMergeConflictEditor(container, code, nextLanguage);
1136
+ return;
1137
+ }
1138
+ if (options.stream === false) {
1139
+ if ((surface == null ? void 0 : surface.getInput().kind) === "file") {
1140
+ language = nextLanguage;
1141
+ yield surface.updateFile(asFile(code), options.lineAnnotations);
1142
+ } else if (container)
1143
+ yield createStaticFileEditor(container, code, nextLanguage);
1144
+ return;
1145
+ }
1146
+ if (!stream) {
1147
+ if (container)
1148
+ yield createEditor(container, code, nextLanguage);
1149
+ return;
1150
+ }
1151
+ if (stream.getState() === "finalized") {
1152
+ if (code !== stream.getText())
1153
+ yield stream.reset(code);
1154
+ return;
1155
+ }
1156
+ if (nextLanguage !== language) {
1157
+ language = nextLanguage;
1158
+ yield stream.setLanguage(nextLanguage);
1159
+ if (code !== stream.getText())
1160
+ yield stream.reset(code);
1161
+ return;
1162
+ }
1163
+ const previous = stream.getText();
1164
+ if (code.startsWith(previous))
1165
+ stream.append(code.slice(previous.length));
1166
+ else
1167
+ yield stream.reset(code);
1168
+ });
1169
+ }
1170
+ function updateDiff(_0, _1) {
1171
+ return __async(this, arguments, function* (oldCode, newCode, lang = language) {
1172
+ original = oldCode;
1173
+ modified = newCode;
1174
+ language = normalizeSurfaceLanguage(lang);
1175
+ if (diffStream) {
1176
+ yield diffStream.update(oldCode, newCode);
1177
+ return;
1178
+ }
1179
+ if (!surface) {
1180
+ if (container)
1181
+ yield createDiffEditor(container, oldCode, newCode, lang);
1182
+ return;
1183
+ }
1184
+ yield surface.updateDiff(asFile(oldCode), asFile(newCode));
1185
+ });
1186
+ }
1187
+ function cleanupEditor() {
1188
+ visualRevision++;
1189
+ stream == null ? void 0 : stream.dispose();
1190
+ diffStream == null ? void 0 : diffStream.dispose();
1191
+ if (!diffStream)
1192
+ surface == null ? void 0 : surface.dispose();
1193
+ stream = void 0;
1194
+ diffStream = void 0;
1195
+ surface = void 0;
1196
+ editorAdapter = void 0;
1197
+ diffAdapter = void 0;
1198
+ container = void 0;
1199
+ }
1200
+ function createStaticFileEditor(target, code, lang) {
1201
+ return __async(this, null, function* () {
1202
+ var _a2;
1203
+ cleanupEditor();
1204
+ const revision = visualRevision;
1205
+ container = target;
1206
+ language = lang;
1207
+ const createdSurface = createDiffSurface({
1208
+ kind: "file",
1209
+ file: asFile(code),
1210
+ annotations: options.lineAnnotations,
1211
+ workerManager: options.workerManager,
1212
+ options: __spreadValues(__spreadValues({}, sharedOptions()), pickPierreOptions(options))
1213
+ });
1214
+ surface = createdSurface;
1215
+ yield createdSurface.mount(target);
1216
+ if (revision !== visualRevision || surface !== createdSurface || container !== target) {
1217
+ createdSurface.dispose();
1218
+ throw new Error("Editor creation was cancelled");
1219
+ }
1220
+ (_a2 = options.onController) == null ? void 0 : _a2.call(options, createdSurface);
1221
+ editorAdapter = createEditorAdapter(() => {
1222
+ var _a3;
1223
+ return (_a3 = getSurfaceFileContents(createdSurface)) != null ? _a3 : code;
1224
+ }, target, () => createdSurface, (listener) => createdSurface.onDidRender(listener));
1225
+ return editorAdapter;
1226
+ });
1227
+ }
1228
+ function createMergeConflictEditor(target, code, lang) {
1229
+ return __async(this, null, function* () {
1230
+ var _a2;
1231
+ cleanupEditor();
1232
+ const revision = visualRevision;
1233
+ container = target;
1234
+ language = lang;
1235
+ const createdSurface = createDiffSurface({
1236
+ kind: "merge-conflict",
1237
+ file: asFile(code),
1238
+ annotations: options.lineAnnotations,
1239
+ workerManager: options.workerManager,
1240
+ options: __spreadValues(__spreadValues({}, sharedOptions()), pickPierreOptions(options))
1241
+ });
1242
+ surface = createdSurface;
1243
+ yield createdSurface.mount(target);
1244
+ if (revision !== visualRevision || surface !== createdSurface || container !== target) {
1245
+ createdSurface.dispose();
1246
+ throw new Error("Editor creation was cancelled");
1247
+ }
1248
+ (_a2 = options.onController) == null ? void 0 : _a2.call(options, createdSurface);
1249
+ editorAdapter = createEditorAdapter(() => {
1250
+ var _a3;
1251
+ return (_a3 = getSurfaceFileContents(createdSurface)) != null ? _a3 : code;
1252
+ }, target, () => createdSurface, (listener) => createdSurface.onDidRender(listener));
1253
+ return editorAdapter;
1254
+ });
1255
+ }
1256
+ function shouldRenderMergeConflict(code) {
1257
+ if (options.mergeConflict === false)
1258
+ return false;
1259
+ return /^<<<<<<< .+$/m.test(code) && /^=======$/m.test(code) && /^>>>>>>> .+$/m.test(code);
1260
+ }
1261
+ function setTheme(nextTheme) {
1262
+ return __async(this, null, function* () {
1263
+ if (!nextTheme)
1264
+ return;
1265
+ if (typeof nextTheme === "string") {
1266
+ const themes = options.themes;
1267
+ if ((themes == null ? void 0 : themes[0]) === nextTheme) {
1268
+ yield applyThemePairIfChanged();
1269
+ themeType = "dark";
1270
+ stream == null ? void 0 : stream.setThemeType("dark");
1271
+ diffStream == null ? void 0 : diffStream.setThemeType("dark");
1272
+ surface == null ? void 0 : surface.setThemeType("dark");
1273
+ return;
1274
+ }
1275
+ if ((themes == null ? void 0 : themes[1]) === nextTheme) {
1276
+ yield applyThemePairIfChanged();
1277
+ themeType = "light";
1278
+ stream == null ? void 0 : stream.setThemeType("light");
1279
+ diffStream == null ? void 0 : diffStream.setThemeType("light");
1280
+ surface == null ? void 0 : surface.setThemeType("light");
1281
+ return;
1282
+ }
1283
+ }
1284
+ appliedThemePairKey = void 0;
1285
+ appliedTheme = nextTheme;
1286
+ yield applyTheme(nextTheme);
1287
+ });
1288
+ }
1289
+ function applyThemePairIfChanged() {
1290
+ return __async(this, null, function* () {
1291
+ const pairKey = getThemePairKey(options);
1292
+ if (!pairKey || pairKey === appliedThemePairKey)
1293
+ return;
1294
+ appliedThemePairKey = pairKey;
1295
+ appliedTheme = resolveTheme(options);
1296
+ yield applyTheme(appliedTheme);
1297
+ });
1298
+ }
1299
+ function applyTheme(nextTheme) {
1300
+ return __async(this, null, function* () {
1301
+ yield stream == null ? void 0 : stream.setTheme(nextTheme);
1302
+ yield diffStream == null ? void 0 : diffStream.setTheme(nextTheme);
1303
+ yield surface == null ? void 0 : surface.setTheme(nextTheme);
1304
+ });
1305
+ }
1306
+ function asFile(contents) {
1307
+ return fileContents(`code.${language || "txt"}`, contents, language);
1308
+ }
1309
+ return {
1310
+ runtimeKind: "stream-diffs",
1311
+ createEditor,
1312
+ createDiffEditor,
1313
+ updateCode,
1314
+ appendCode(chunk) {
1315
+ stream == null ? void 0 : stream.append(chunk);
1316
+ },
1317
+ finalizeCode() {
1318
+ return __async(this, null, function* () {
1319
+ if (!stream || stream.getState() === "finalized")
1320
+ return stream == null ? void 0 : stream.getFinalizedSurface();
1321
+ const nativeOptions = pickPierreOptions(options);
1322
+ delete nativeOptions.lineAnnotations;
1323
+ yield stream.finalize(__spreadProps(__spreadValues({
1324
+ view: "file"
1325
+ }, nativeOptions), {
1326
+ theme: appliedTheme,
1327
+ themeType,
1328
+ annotations: options.lineAnnotations,
1329
+ workerManager: options.workerManager
1330
+ }));
1331
+ return stream.getFinalizedSurface();
1332
+ });
1333
+ },
1334
+ finalizeDiff() {
1335
+ return __async(this, null, function* () {
1336
+ if (!diffStream)
1337
+ return surface;
1338
+ surface = yield diffStream.finalize(options.lineAnnotations);
1339
+ return surface;
1340
+ });
1341
+ },
1342
+ updateDiff,
1343
+ updateOriginal(code, lang = language) {
1344
+ return updateDiff(code, modified, lang);
1345
+ },
1346
+ updateModified(code, lang = language) {
1347
+ return updateDiff(original, code, lang);
1348
+ },
1349
+ appendOriginal(chunk, lang = language) {
1350
+ return updateDiff(original + chunk, modified, lang);
1351
+ },
1352
+ appendModified(chunk, lang = language) {
1353
+ return updateDiff(original, modified + chunk, lang);
1354
+ },
1355
+ cleanupEditor,
1356
+ safeClean: cleanupEditor,
1357
+ setTheme,
1358
+ setLanguage(next) {
1359
+ return __async(this, null, function* () {
1360
+ language = normalizeSurfaceLanguage(next);
1361
+ yield stream == null ? void 0 : stream.setLanguage(language);
1362
+ yield diffStream == null ? void 0 : diffStream.setLanguage(language);
1363
+ if (surface && !diffStream) {
1364
+ const input = surface.getInput();
1365
+ if (input.kind === "file" || input.kind === "merge-conflict")
1366
+ yield surface.update(__spreadProps(__spreadValues({}, input), {
1367
+ file: __spreadProps(__spreadValues({}, input.file), {
1368
+ lang: language
1369
+ })
1370
+ }));
1371
+ else if (input.kind === "diff" && "oldFile" in input)
1372
+ yield surface.update(__spreadProps(__spreadValues({}, input), {
1373
+ oldFile: __spreadProps(__spreadValues({}, input.oldFile), {
1374
+ lang: language
1375
+ }),
1376
+ newFile: __spreadProps(__spreadValues({}, input.newFile), {
1377
+ lang: language
1378
+ })
1379
+ }));
1380
+ }
1381
+ });
1382
+ },
1383
+ getCurrentTheme: () => appliedTheme,
1384
+ getEditor: () => EDITOR_NAMESPACE,
1385
+ getEditorView: () => editorAdapter != null ? editorAdapter : null,
1386
+ getDiffEditorView: () => diffAdapter != null ? diffAdapter : null,
1387
+ getDiffModels: () => ({
1388
+ original: createModel(() => original),
1389
+ modified: createModel(() => {
1390
+ var _a2, _b, _c;
1391
+ return (_c = (_b = (_a2 = surface == null ? void 0 : surface.getResolvedFile()) == null ? void 0 : _a2.contents) != null ? _b : diffStream == null ? void 0 : diffStream.getModified()) != null ? _c : modified;
1392
+ })
1393
+ }),
1394
+ getCode: () => {
1395
+ var _a2, _b, _c;
1396
+ const input = surface == null ? void 0 : surface.getInput();
1397
+ if ((input == null ? void 0 : input.kind) === "diff" || (input == null ? void 0 : input.kind) === "patch")
1398
+ return {
1399
+ original,
1400
+ modified: (_b = (_a2 = surface == null ? void 0 : surface.getResolvedFile()) == null ? void 0 : _a2.contents) != null ? _b : modified
1401
+ };
1402
+ if ((input == null ? void 0 : input.kind) === "file" || (input == null ? void 0 : input.kind) === "merge-conflict")
1403
+ return input.file.contents;
1404
+ if (diffStream)
1405
+ return {
1406
+ original: diffStream.getOriginal(),
1407
+ modified: diffStream.getModified()
1408
+ };
1409
+ return (_c = stream == null ? void 0 : stream.getText()) != null ? _c : null;
1410
+ },
1411
+ refreshDiffPresentation: () => surface == null ? void 0 : surface.update(surface.getInput()),
1412
+ whenVisualReady: () => __async(this, null, function* () {
1413
+ var _a2;
1414
+ const target = container;
1415
+ const revision = visualRevision;
1416
+ const renderedSurface = (_a2 = surface != null ? surface : stream == null ? void 0 : stream.getFinalizedSurface()) != null ? _a2 : diffStream == null ? void 0 : diffStream.getFinalizedSurface();
1417
+ if (!renderedSurface || !(yield renderedSurface.whenVisualReady()))
1418
+ return false;
1419
+ return waitForVisualReady(target, () => {
1420
+ var _a3;
1421
+ return revision === visualRevision && target === container && renderedSurface === ((_a3 = surface != null ? surface : stream == null ? void 0 : stream.getFinalizedSurface()) != null ? _a3 : diffStream == null ? void 0 : diffStream.getFinalizedSurface());
1422
+ }, () => {
1423
+ var _a3;
1424
+ return isSurfaceRenderComplete((_a3 = surface != null ? surface : stream == null ? void 0 : stream.getFinalizedSurface()) != null ? _a3 : diffStream == null ? void 0 : diffStream.getFinalizedSurface());
1425
+ });
1426
+ })
1427
+ };
1428
+ }
1429
+ function waitForVisualReady(container, isCurrent, isRenderComplete) {
1430
+ return __async(this, null, function* () {
1431
+ var _a, _b, _c;
1432
+ if (!container || typeof window === "undefined")
1433
+ return false;
1434
+ let previousSignature = "";
1435
+ let previousPre;
1436
+ let stableFrames = 0;
1437
+ for (let frame = 0; frame < 120; frame += 1) {
1438
+ if (!isCurrent())
1439
+ return false;
1440
+ const shell = container.querySelector(".stream-diffs-shell");
1441
+ const pre = (_b = (_a = shell == null ? void 0 : shell.querySelector("diffs-container")) == null ? void 0 : _a.shadowRoot) == null ? void 0 : _b.querySelector("pre");
1442
+ const rect = shell == null ? void 0 : shell.getBoundingClientRect();
1443
+ const text = (_c = pre == null ? void 0 : pre.textContent) != null ? _c : "";
1444
+ if (!!rect && rect.width > 0 && rect.height > 0 && !!pre && isRenderComplete()) {
1445
+ const signature = `${Math.round(rect.width)}:${Math.round(rect.height)}:${pre.scrollWidth}:${pre.scrollHeight}:${text.length}`;
1446
+ stableFrames = pre === previousPre && signature === previousSignature ? stableFrames + 1 : 1;
1447
+ previousPre = pre;
1448
+ previousSignature = signature;
1449
+ if (stableFrames >= 2)
1450
+ return true;
1451
+ } else {
1452
+ previousSignature = "";
1453
+ previousPre = void 0;
1454
+ stableFrames = 0;
1455
+ }
1456
+ yield nextVisualFrame();
1457
+ }
1458
+ return false;
1459
+ });
1460
+ }
1461
+ function isSurfaceRenderComplete(surface) {
1462
+ var _a, _b, _c, _d, _e;
1463
+ if (!surface)
1464
+ return true;
1465
+ const instance = surface.getNativeInstance();
1466
+ const renderer = (_a = instance == null ? void 0 : instance.fileRenderer) != null ? _a : instance == null ? void 0 : instance.hunksRenderer;
1467
+ if (!renderer)
1468
+ return true;
1469
+ const cache = renderer.renderCache;
1470
+ if (!(cache == null ? void 0 : cache.result))
1471
+ return false;
1472
+ if (cache.highlighted === true)
1473
+ return true;
1474
+ const input = surface.getInput();
1475
+ if (normalizeSurfaceLanguage(input.kind === "file" || input.kind === "merge-conflict" ? input.file.lang : "oldFile" in input ? (_b = input.oldFile.lang) != null ? _b : input.newFile.lang : (_c = surface.getDiff()) == null ? void 0 : _c.lang) === "text")
1476
+ return true;
1477
+ const tokenizeMaxLength = Number((_e = (_d = renderer.getTokenizeMaxLength) == null ? void 0 : _d.call(renderer)) != null ? _e : 1e5);
1478
+ if (input.kind === "file" || input.kind === "merge-conflict")
1479
+ return countLines(input.file.contents) > tokenizeMaxLength;
1480
+ const diff = surface.getDiff();
1481
+ return !!diff && Math.max(diff.additionLines.length, diff.deletionLines.length) > tokenizeMaxLength;
1482
+ }
1483
+ function normalizeSurfaceLanguage(language) {
1484
+ return !language || /^(?:text|txt|plain|plaintext)$/i.test(language) ? "text" : language;
1485
+ }
1486
+ function countLines(value) {
1487
+ if (!value)
1488
+ return 0;
1489
+ let lines = 1;
1490
+ for (let index = 0; index < value.length; index += 1)
1491
+ if (value.charCodeAt(index) === 10)
1492
+ lines += 1;
1493
+ return lines;
1494
+ }
1495
+ function nextVisualFrame() {
1496
+ return new Promise((resolve) => {
1497
+ let settled = false;
1498
+ const done = () => {
1499
+ if (settled)
1500
+ return;
1501
+ settled = true;
1502
+ window.clearTimeout(timeout);
1503
+ window.cancelAnimationFrame(frame);
1504
+ resolve();
1505
+ };
1506
+ const frame = window.requestAnimationFrame(done);
1507
+ const timeout = window.setTimeout(done, 50);
1508
+ });
1509
+ }
1510
+ function resolveTheme(options) {
1511
+ var _a, _b;
1512
+ if (((_a = options.themes) == null ? void 0 : _a.length) && typeof options.themes[0] === "string" && typeof options.themes[1] === "string")
1513
+ return {
1514
+ dark: options.themes[0],
1515
+ light: options.themes[1]
1516
+ };
1517
+ return (_b = options.theme) != null ? _b : void 0;
1518
+ }
1519
+ function getThemePairKey(options) {
1520
+ var _a, _b;
1521
+ if (typeof ((_a = options.themes) == null ? void 0 : _a[0]) !== "string" || typeof ((_b = options.themes) == null ? void 0 : _b[1]) !== "string")
1522
+ return void 0;
1523
+ return `${options.themes[0]}
1524
+ ${options.themes[1]}`;
1525
+ }
1526
+ function pickPierreOptions(options) {
1527
+ var _a, _b, _c;
1528
+ const hostKeys = /* @__PURE__ */ new Set([
1529
+ "MAX_HEIGHT",
1530
+ "theme",
1531
+ "themes",
1532
+ "readOnly",
1533
+ "lineNumbers",
1534
+ "wordWrap",
1535
+ "renderSideBySide",
1536
+ "autoScrollOnUpdate",
1537
+ "autoScrollThresholdPx",
1538
+ "stream",
1539
+ "mergeConflict",
1540
+ "lineAnnotations",
1541
+ "onController",
1542
+ "workerManager",
1543
+ "languages",
1544
+ "onThemeChange"
1545
+ ]);
1546
+ const nativeOptions = Object.fromEntries(Object.entries(options).filter(([key]) => !hostKeys.has(key)));
1547
+ const legacyFolding = options.diffHideUnchangedRegions;
1548
+ delete nativeOptions.diffHideUnchangedRegions;
1549
+ const foldingOptions = typeof legacyFolding === "object" && legacyFolding ? legacyFolding : void 0;
1550
+ const foldingEnabled = (foldingOptions == null ? void 0 : foldingOptions.enabled) !== false;
1551
+ if (legacyFolding === false || foldingOptions && !foldingEnabled)
1552
+ (_a = nativeOptions.expandUnchanged) != null ? _a : nativeOptions.expandUnchanged = true;
1553
+ else if (legacyFolding === true || foldingOptions) {
1554
+ (_b = nativeOptions.expandUnchanged) != null ? _b : nativeOptions.expandUnchanged = false;
1555
+ if (foldingOptions) {
1556
+ const context = Number(foldingOptions.contextLineCount);
1557
+ if (Number.isFinite(context) && context >= 0)
1558
+ nativeOptions.parseDiffOptions = __spreadValues({
1559
+ context
1560
+ }, nativeOptions.parseDiffOptions);
1561
+ const minimumLineCount = Number(foldingOptions.minimumLineCount);
1562
+ if (Number.isFinite(minimumLineCount) && minimumLineCount >= 1)
1563
+ (_c = nativeOptions.collapsedContextThreshold) != null ? _c : nativeOptions.collapsedContextThreshold = Math.max(0, Math.floor(minimumLineCount) - 1);
1564
+ }
1565
+ }
1566
+ return nativeOptions;
1567
+ }
1568
+ function createModel(getValue) {
1569
+ return {
1570
+ getValue,
1571
+ getLineCount: () => getValue().split("\n").length
1572
+ };
1573
+ }
1574
+ function getSurfaceFileContents(surface) {
1575
+ const input = surface == null ? void 0 : surface.getInput();
1576
+ return (input == null ? void 0 : input.kind) === "file" || (input == null ? void 0 : input.kind) === "merge-conflict" ? input.file.contents : void 0;
1577
+ }
1578
+ function createEditorAdapter(getValue, container, getSurface = () => void 0, subscribeRender) {
1579
+ const readFontSize = () => Number.parseFloat(container.style.fontSize) || 14;
1580
+ return {
1581
+ getModel: () => createModel(getValue),
1582
+ getContentHeight: () => {
1583
+ var _a, _b;
1584
+ return (_b = (_a = container.querySelector(".stream-diffs-shell")) == null ? void 0 : _a.scrollHeight) != null ? _b : container.scrollHeight;
1585
+ },
1586
+ layout: () => {
1587
+ },
1588
+ getOption(key) {
1589
+ if (key === EDITOR_OPTION.fontInfo)
1590
+ return { fontSize: readFontSize() };
1591
+ if (key === EDITOR_OPTION.lineHeight)
1592
+ return Number.parseFloat(container.style.lineHeight) || Math.round(readFontSize() * 1.5);
1593
+ },
1594
+ updateOptions(next) {
1595
+ applyEditorStyles(container, next);
1596
+ },
1597
+ onDidContentSizeChange: (listener) => {
1598
+ var _a;
1599
+ return (_a = subscribeRender == null ? void 0 : subscribeRender(listener)) != null ? _a : { dispose() {
1600
+ } };
1601
+ },
1602
+ onDidLayoutChange: (listener) => {
1603
+ var _a;
1604
+ return (_a = subscribeRender == null ? void 0 : subscribeRender(listener)) != null ? _a : { dispose() {
1605
+ } };
1606
+ },
1607
+ setSelectedLines: (range) => {
1608
+ var _a;
1609
+ return (_a = getSurface()) == null ? void 0 : _a.setSelectedLines(range);
1610
+ },
1611
+ setAnnotations: (annotations) => {
1612
+ var _a;
1613
+ return (_a = getSurface()) == null ? void 0 : _a.setAnnotations(annotations);
1614
+ },
1615
+ acceptReject: (hunkIndex, action) => {
1616
+ var _a;
1617
+ return (_a = getSurface()) == null ? void 0 : _a.acceptReject(hunkIndex, action);
1618
+ },
1619
+ resolveConflict: (conflictIndex, resolution) => {
1620
+ var _a;
1621
+ return (_a = getSurface()) == null ? void 0 : _a.resolveConflict(conflictIndex, resolution);
1622
+ }
1623
+ };
1624
+ }
1625
+ function createDiffAdapter(getOriginal, getModified, container, getSurface) {
1626
+ return __spreadProps(__spreadValues({}, createEditorAdapter(getModified, container, getSurface, (listener) => {
1627
+ var _a, _b;
1628
+ return (_b = (_a = getSurface()) == null ? void 0 : _a.onDidRender(listener)) != null ? _b : { dispose() {
1629
+ } };
1630
+ })), {
1631
+ getOriginalEditor: () => createEditorAdapter(getOriginal, container, getSurface, (listener) => {
1632
+ var _a, _b;
1633
+ return (_b = (_a = getSurface()) == null ? void 0 : _a.onDidRender(listener)) != null ? _b : { dispose() {
1634
+ } };
1635
+ }),
1636
+ getModifiedEditor: () => createEditorAdapter(getModified, container, getSurface, (listener) => {
1637
+ var _a, _b;
1638
+ return (_b = (_a = getSurface()) == null ? void 0 : _a.onDidRender(listener)) != null ? _b : { dispose() {
1639
+ } };
1640
+ }),
1641
+ getLineChanges: () => {
1642
+ var _a, _b, _c;
1643
+ return (_c = (_b = (_a = getSurface()) == null ? void 0 : _a.getDiff()) == null ? void 0 : _b.hunks.map((hunk) => ({
1644
+ originalStartLineNumber: hunk.deletionStart,
1645
+ originalEndLineNumber: hunk.deletionStart + hunk.deletionCount - 1,
1646
+ modifiedStartLineNumber: hunk.additionStart,
1647
+ modifiedEndLineNumber: hunk.additionStart + hunk.additionCount - 1
1648
+ }))) != null ? _c : [];
1649
+ },
1650
+ onDidUpdateDiff: (listener) => {
1651
+ var _a, _b;
1652
+ return (_b = (_a = getSurface()) == null ? void 0 : _a.onDidRender(listener)) != null ? _b : { dispose() {
1653
+ } };
1654
+ }
1655
+ });
1656
+ }
1657
+ const EDITOR_OPTION = {
1658
+ fontInfo: 0,
1659
+ lineHeight: 1
1660
+ };
1661
+ const EDITOR_NAMESPACE = { EditorOption: EDITOR_OPTION };
1662
+ function applyEditorStyles(container, options) {
1663
+ const { style } = container;
1664
+ if (typeof options.fontSize === "number") {
1665
+ style.fontSize = `${options.fontSize}px`;
1666
+ style.setProperty("--diffs-font-size", `${options.fontSize}px`);
1667
+ }
1668
+ if (typeof options.lineHeight === "number") {
1669
+ style.lineHeight = `${options.lineHeight}px`;
1670
+ style.setProperty("--diffs-line-height", `${options.lineHeight}px`);
1671
+ }
1672
+ if (typeof options.fontFamily === "string") {
1673
+ style.fontFamily = options.fontFamily;
1674
+ style.setProperty("--diffs-font-family", options.fontFamily);
1675
+ }
1676
+ }
1677
+ function preloadMonacoWorkers() {
1678
+ return __async(this, null, function* () {
1679
+ });
1680
+ }
1681
+ function detectLanguage(code) {
1682
+ if (/^\s*</.test(code))
1683
+ return "html";
1684
+ if (/\b(interface|type|enum)\s+\w+|:\s*(string|number|boolean)\b/.test(code))
1685
+ return "typescript";
1686
+ if (/\b(const|let|function|import|export)\b/.test(code))
1687
+ return "javascript";
1688
+ if (/\b(def|from|lambda|None|True|False)\b/.test(code))
1689
+ return "python";
1690
+ return "text";
1691
+ }
1692
+ export {
1693
+ CodeStreamController,
1694
+ DiffStreamController,
1695
+ DiffSurfaceController,
1696
+ createCodeStream,
1697
+ createDiffStream,
1698
+ createDiffSurface,
1699
+ detectLanguage,
1700
+ preloadMonacoWorkers,
1701
+ useMonaco
1702
+ };