stream-monaco 0.0.14 → 0.0.16

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.
@@ -0,0 +1,2791 @@
1
+ import { __export, __reExport } from "./chunk-CHLpw0oG.js";
2
+ import * as _monaco from "monaco-editor";
3
+ import { computed } from "alien-signals";
4
+ import { shikiToMonaco } from "@shikijs/monaco";
5
+ import { createHighlighter } from "shiki";
6
+
7
+ //#region src/code.detect.ts
8
+ /**
9
+ * Language detection definitions
10
+ */
11
+ const languages = [
12
+ [
13
+ "bash",
14
+ [/#!(\/usr)?\/bin\/bash/g, 500],
15
+ [/\b(if|elif|then|fi|echo)\b|\$/g, 10]
16
+ ],
17
+ [
18
+ "html",
19
+ [/<\/?[a-z-][^\n>]*>/g, 10],
20
+ [/^\s+<!DOCTYPE\s+html/g, 500]
21
+ ],
22
+ ["http", [/^(GET|HEAD|POST|PUT|DELETE|PATCH|HTTP)\b/g, 500]],
23
+ ["js", [/\b(console|await|async|function|export|import|this|class|for|let|const|map|join|require)\b/g, 10]],
24
+ ["ts", [/\b(console|await|async|function|export|import|this|class|for|let|const|map|join|require|implements|interface|namespace)\b/g, 10]],
25
+ ["py", [/\b(def|print|class|and|or|lambda)\b/g, 10]],
26
+ ["sql", [/\b(SELECT|INSERT|FROM)\b/g, 50]],
27
+ [
28
+ "pl",
29
+ [/#!(\/usr)?\/bin\/perl/g, 500],
30
+ [/\b(use|print)\b|\$/g, 10]
31
+ ],
32
+ ["lua", [/#!(\/usr)?\/bin\/lua/g, 500]],
33
+ ["make", [/\b(ifneq|endif|if|elif|then|fi|echo|.PHONY|^[a-z]+ ?:$)\b|\$/gm, 10]],
34
+ ["uri", [/https?:|mailto:|tel:|ftp:/g, 30]],
35
+ ["css", [/^(@import|@page|@media|(\.|#)[a-z]+)/gm, 20]],
36
+ [
37
+ "diff",
38
+ [/^[+><-]/gm, 10],
39
+ [/^@@[-+,0-9 ]+@@/gm, 25]
40
+ ],
41
+ [
42
+ "md",
43
+ [/^(>|\t\*|\t\d+.|#{1,6} |-\s+|\*\s+)/gm, 25],
44
+ [/\[.*\](.*)/g, 10]
45
+ ],
46
+ ["docker", [/^(FROM|ENTRYPOINT|RUN)/gm, 500]],
47
+ [
48
+ "xml",
49
+ [/<\/?[a-z-][^\n>]*>/g, 10],
50
+ [/^<\?xml/g, 500]
51
+ ],
52
+ ["c", [/#include\b|\bprintf\s+\(/g, 100]],
53
+ ["rs", [/^\s+(use|fn|mut|match)\b/gm, 100]],
54
+ ["go", [/\b(func|fmt|package)\b/g, 100]],
55
+ ["java", [/^import\s+java/gm, 500]],
56
+ ["asm", [/^(section|global main|extern|\t(call|mov|ret))/gm, 100]],
57
+ ["css", [/^(@import|@page|@media|(\.|#)[a-z]+)/gm, 20]],
58
+ ["json", [/\b(true|false|null|\{\})\b|"[^"]+":/g, 10]],
59
+ ["yaml", [/^(\s+)?[a-z][a-z0-9]*:/gim, 10]],
60
+ [
61
+ "toml",
62
+ [/^\s*\[.*\]\s*$/gm, 100],
63
+ [/^\s*[\w-]+ *= */gm, 20]
64
+ ],
65
+ [
66
+ "mermaid",
67
+ [/^(graph|flowchart|sequenceDiagram|classDiagram|stateDiagram|erDiagram|gantt|pie|mindmap)/gm, 500],
68
+ [/\b(-->|--o|--x|=>|\[\]|[{}])\b/g, 10]
69
+ ]
70
+ ];
71
+ /**
72
+ * Try to find the language the given code belongs to
73
+ *
74
+ * @param {string} code The code to analyze
75
+ * @param {LanguageDefinition[]} [additionalLanguages] Additional language definitions to supplement the built-in ones
76
+ * @returns {CodeLanguage} The detected language of the code
77
+ */
78
+ function detectLanguage(code, additionalLanguages) {
79
+ var _allLanguages$map$fil;
80
+ const allLanguages = additionalLanguages ? [...languages, ...additionalLanguages] : languages;
81
+ return ((_allLanguages$map$fil = allLanguages.map(([lang, ...features]) => [lang, features.reduce((acc, [match, score]) => acc + [...code.matchAll(match)].length * score, 0)]).filter(([, score]) => score > 20).sort((a, b) => b[1] - a[1])[0]) === null || _allLanguages$map$fil === void 0 ? void 0 : _allLanguages$map$fil[0]) || "plain";
82
+ }
83
+ function processedLanguage(language) {
84
+ if (/^(?:shellscript|bash|sh|shell|zsh)/i.test(language)) return "shell";
85
+ if (/^(?:powershell|ps1?)/i.test(language)) return "powershell";
86
+ return language.split(":")[0];
87
+ }
88
+ /**
89
+ * 使用示例:
90
+ *
91
+ * // 基本用法
92
+ * const language1 = detectLanguage('console.log("hello")') // 'js'
93
+ *
94
+ * // 使用自定义语言检测规则
95
+ * const customLanguages: LanguageDefinition[] = [
96
+ * ['vue', [/<template>/g, 100], [/<script>/g, 50], [/<style>/g, 50]],
97
+ * ['kotlin', [/\b(fun|class|val|var)\b/g, 20]]
98
+ * ]
99
+ *
100
+ * const language2 = detectLanguage(`
101
+ * <template>
102
+ * <div>Hello Vue</div>
103
+ * </template>
104
+ * `, customLanguages) // 'vue'
105
+ *
106
+ * const language3 = detectLanguage(`
107
+ * fun main() {
108
+ * val name = "Kotlin"
109
+ * println("Hello $name")
110
+ * }
111
+ * `, customLanguages) // 'kotlin'
112
+ */
113
+
114
+ //#endregion
115
+ //#region src/constant.ts
116
+ const defaultLanguages = [
117
+ "jsx",
118
+ "tsx",
119
+ "vue",
120
+ "csharp",
121
+ "python",
122
+ "java",
123
+ "c",
124
+ "cpp",
125
+ "rust",
126
+ "go",
127
+ "powershell",
128
+ "sql",
129
+ "json",
130
+ "html",
131
+ "javascript",
132
+ "typescript",
133
+ "css",
134
+ "markdown",
135
+ "xml",
136
+ "yaml",
137
+ "toml",
138
+ "dockerfile",
139
+ "kotlin",
140
+ "objective-c",
141
+ "objective-cpp",
142
+ "php",
143
+ "ruby",
144
+ "scala",
145
+ "svelte",
146
+ "swift",
147
+ "erlang",
148
+ "angular-html",
149
+ "angular-ts",
150
+ "dart",
151
+ "lua",
152
+ "mermaid",
153
+ "cmake",
154
+ "nginx"
155
+ ];
156
+ const defaultThemes = ["vitesse-dark", "vitesse-light"];
157
+ const defaultScrollbar = {
158
+ verticalScrollbarSize: 8,
159
+ horizontalScrollbarSize: 8,
160
+ handleMouseWheel: true,
161
+ alwaysConsumeMouseWheel: false
162
+ };
163
+ const padding = 16;
164
+ const defaultRevealDebounceMs = 75;
165
+ const defaultRevealBatchOnIdleMs = 200;
166
+ const minimalEditMaxChars = 2e5;
167
+ const minimalEditMaxChangeRatio = .5;
168
+
169
+ //#endregion
170
+ //#region src/minimalEdit.ts
171
+ /**
172
+ * Compute the minimal middle replacement between two UTF-16 strings.
173
+ * Returns null when prev === next (no edits required).
174
+ */
175
+ function computeMinimalEdit(prev, next) {
176
+ if (prev === next) return null;
177
+ let start = 0;
178
+ const minLen = Math.min(prev.length, next.length);
179
+ while (start < minLen && prev.charCodeAt(start) === next.charCodeAt(start)) start++;
180
+ let endPrev = prev.length - 1;
181
+ let endNext = next.length - 1;
182
+ while (endPrev >= start && endNext >= start && prev.charCodeAt(endPrev) === next.charCodeAt(endNext)) {
183
+ endPrev--;
184
+ endNext--;
185
+ }
186
+ return {
187
+ start,
188
+ endPrevIncl: endPrev,
189
+ endNextIncl: endNext,
190
+ replaceText: next.slice(start, endNext + 1)
191
+ };
192
+ }
193
+
194
+ //#endregion
195
+ //#region src/monaco-shim.ts
196
+ var monaco_shim_exports = {};
197
+ __export(monaco_shim_exports, { default: () => monaco });
198
+ import * as import_monaco_editor from "monaco-editor";
199
+ __reExport(monaco_shim_exports, import_monaco_editor);
200
+ const monaco = _monaco;
201
+
202
+ //#endregion
203
+ //#region src/utils/logger.ts
204
+ let seq = 0;
205
+ const DEBUG = (() => {
206
+ if (typeof window !== "undefined" && window.__STREAM_MONACO_DEBUG__ !== void 0) return Boolean(window.__STREAM_MONACO_DEBUG__);
207
+ return false;
208
+ })();
209
+ function log(tag, ...args) {
210
+ if (!DEBUG) return;
211
+ seq += 1;
212
+ const id = `#${seq}`;
213
+ const ts = typeof performance !== "undefined" && performance.now ? performance.now().toFixed(1) : Date.now();
214
+ console.warn(`${id} [${tag}] @${ts}ms`, ...args);
215
+ }
216
+ function error(tag, ...args) {
217
+ if (!DEBUG) return;
218
+ console.error(`[${tag}]`, ...args);
219
+ }
220
+
221
+ //#endregion
222
+ //#region src/utils/height.ts
223
+ function createHeightManager(container, computeNext) {
224
+ let raf = null;
225
+ let debounceTimer = null;
226
+ let lastApplied = -1;
227
+ let suppressed = false;
228
+ const HYSTERESIS_PX = 12;
229
+ const DEBOUNCE_MS = 0;
230
+ function apply() {
231
+ const next = computeNext();
232
+ if (next == null) return;
233
+ log("heightManager", "computeNext ->", {
234
+ next,
235
+ lastApplied
236
+ });
237
+ if (!Number.isFinite(next) || next <= 0) {
238
+ log("heightManager", "invalid next height, ignoring", next);
239
+ return;
240
+ }
241
+ if (lastApplied !== -1 && Math.abs(next - lastApplied) <= HYSTERESIS_PX) return;
242
+ if (next === lastApplied) return;
243
+ suppressed = true;
244
+ container.style.height = `${next}px`;
245
+ lastApplied = next;
246
+ log("heightManager", "applied height ->", next);
247
+ queueMicrotask(() => {
248
+ suppressed = false;
249
+ });
250
+ }
251
+ function scheduleApply() {
252
+ if (debounceTimer != null) {
253
+ clearTimeout(debounceTimer);
254
+ debounceTimer = null;
255
+ }
256
+ if (DEBOUNCE_MS === 0) {
257
+ if (raf != null) return;
258
+ raf = requestAnimationFrame(() => {
259
+ raf = null;
260
+ apply();
261
+ });
262
+ return;
263
+ }
264
+ debounceTimer = setTimeout(() => {
265
+ debounceTimer = null;
266
+ if (raf != null) return;
267
+ raf = requestAnimationFrame(() => {
268
+ raf = null;
269
+ apply();
270
+ });
271
+ }, DEBOUNCE_MS);
272
+ }
273
+ function update() {
274
+ scheduleApply();
275
+ }
276
+ function dispose() {
277
+ if (raf != null) {
278
+ cancelAnimationFrame(raf);
279
+ raf = null;
280
+ }
281
+ if (debounceTimer != null) {
282
+ clearTimeout(debounceTimer);
283
+ debounceTimer = null;
284
+ }
285
+ }
286
+ function isSuppressed() {
287
+ return suppressed;
288
+ }
289
+ function getLastApplied() {
290
+ return lastApplied;
291
+ }
292
+ return {
293
+ update,
294
+ dispose,
295
+ isSuppressed,
296
+ getLastApplied
297
+ };
298
+ }
299
+
300
+ //#endregion
301
+ //#region src/utils/raf.ts
302
+ /**
303
+ * Create a per-instance RAF scheduler that coalesces tasks by "kind" within
304
+ * the same instance. Instances are isolated so different editors won't
305
+ * cancel each other's scheduled work.
306
+ */
307
+ function createRafScheduler(timeSource) {
308
+ const ids = {};
309
+ const ts = timeSource ?? {
310
+ requestAnimationFrame: (cb) => requestAnimationFrame(cb),
311
+ cancelAnimationFrame: (id) => cancelAnimationFrame(id)
312
+ };
313
+ function schedule(kind, cb) {
314
+ const existing = ids[kind];
315
+ if (existing != null) ts.cancelAnimationFrame(existing);
316
+ ids[kind] = ts.requestAnimationFrame((t) => {
317
+ ids[kind] = null;
318
+ cb(t);
319
+ });
320
+ }
321
+ function cancel(kind) {
322
+ const id = ids[kind];
323
+ if (id != null) {
324
+ ts.cancelAnimationFrame(id);
325
+ ids[kind] = null;
326
+ }
327
+ }
328
+ return {
329
+ schedule,
330
+ cancel
331
+ };
332
+ }
333
+
334
+ //#endregion
335
+ //#region src/utils/scroll.ts
336
+ function createScrollWatcherForEditor(ed, opts) {
337
+ var _ed$getScrollTop, _ed$onDidScrollChange;
338
+ const initial = ((_ed$getScrollTop = ed.getScrollTop) === null || _ed$getScrollTop === void 0 ? void 0 : _ed$getScrollTop.call(ed)) ?? 0;
339
+ opts.setLast(initial);
340
+ log("scrollWatcher", "initial scrollTop=", initial);
341
+ let suppressedExternally = false;
342
+ const THRESHOLD_PX = 6;
343
+ let domNode = null;
344
+ let interactionListener = null;
345
+ const listener = (e) => {
346
+ var _ed$getScrollTop2;
347
+ if (suppressedExternally) {
348
+ log("scrollWatcher", "suppressedExternally, ignoring event");
349
+ return;
350
+ }
351
+ const currentTop = e && typeof e.scrollTop === "number" ? e.scrollTop : ((_ed$getScrollTop2 = ed.getScrollTop) === null || _ed$getScrollTop2 === void 0 ? void 0 : _ed$getScrollTop2.call(ed)) ?? 0;
352
+ const delta = currentTop - opts.getLast();
353
+ opts.setLast(currentTop);
354
+ if (Math.abs(delta) < THRESHOLD_PX) {
355
+ log("scrollWatcher", "small delta ignored", delta);
356
+ try {
357
+ const scrollHeight = typeof ed.getScrollHeight === "function" ? ed.getScrollHeight() : void 0;
358
+ const li = typeof ed.getLayoutInfo === "function" ? ed.getLayoutInfo() : void 0;
359
+ const viewportH = (li === null || li === void 0 ? void 0 : li.height) ?? void 0;
360
+ if (typeof scrollHeight === "number" && typeof viewportH === "number") {
361
+ const distance = scrollHeight - (currentTop + viewportH);
362
+ if (distance <= Math.max(THRESHOLD_PX, 0)) {
363
+ log("scrollWatcher", "small delta but at bottom, maybe resume", { distance });
364
+ opts.onMaybeResume();
365
+ }
366
+ }
367
+ } catch {}
368
+ return;
369
+ }
370
+ log("scrollWatcher", "delta=", delta, "currentTop=", currentTop);
371
+ if (delta < 0) {
372
+ log("scrollWatcher", "pause detected delta=", delta);
373
+ opts.onPause();
374
+ return;
375
+ }
376
+ log("scrollWatcher", "maybe resume delta=", delta);
377
+ opts.onMaybeResume();
378
+ };
379
+ const disp = ((_ed$onDidScrollChange = ed.onDidScrollChange) === null || _ed$onDidScrollChange === void 0 ? void 0 : _ed$onDidScrollChange.call(ed, listener)) ?? null;
380
+ const api = {
381
+ dispose() {
382
+ try {
383
+ if (disp && typeof disp.dispose === "function") disp.dispose();
384
+ else if (typeof disp === "function") disp();
385
+ } catch {}
386
+ log("scrollWatcher", "dispose");
387
+ },
388
+ setSuppressed(v) {
389
+ const newVal = !!v;
390
+ if (newVal === suppressedExternally) return;
391
+ suppressedExternally = newVal;
392
+ log("scrollWatcher", "setSuppressed =>", suppressedExternally);
393
+ try {
394
+ if (!domNode && typeof ed.getDomNode === "function") domNode = ed.getDomNode();
395
+ if (suppressedExternally && domNode) {
396
+ if (!interactionListener) {
397
+ interactionListener = () => {
398
+ try {
399
+ var _ed$getScrollTop3;
400
+ log("scrollWatcher", "user interaction detected while suppressed, cancelling suppression");
401
+ opts.onPause();
402
+ suppressedExternally = false;
403
+ const cur = ((_ed$getScrollTop3 = ed.getScrollTop) === null || _ed$getScrollTop3 === void 0 ? void 0 : _ed$getScrollTop3.call(ed)) ?? 0;
404
+ opts.setLast(cur);
405
+ try {
406
+ const scrollHeight = typeof ed.getScrollHeight === "function" ? ed.getScrollHeight() : void 0;
407
+ const li = typeof ed.getLayoutInfo === "function" ? ed.getLayoutInfo() : void 0;
408
+ const viewportH = (li === null || li === void 0 ? void 0 : li.height) ?? void 0;
409
+ if (typeof scrollHeight === "number" && typeof viewportH === "number") {
410
+ const distance = scrollHeight - (cur + viewportH);
411
+ if (distance <= Math.max(THRESHOLD_PX, 0)) {
412
+ log("scrollWatcher", "interaction moved to bottom, maybe resume", { distance });
413
+ opts.onMaybeResume();
414
+ }
415
+ }
416
+ } catch {}
417
+ if (domNode && interactionListener) {
418
+ domNode.removeEventListener("wheel", interactionListener, { passive: true });
419
+ domNode.removeEventListener("pointerdown", interactionListener);
420
+ domNode.removeEventListener("touchstart", interactionListener);
421
+ }
422
+ interactionListener = null;
423
+ } catch {}
424
+ };
425
+ domNode.addEventListener("wheel", interactionListener, { passive: true });
426
+ domNode.addEventListener("pointerdown", interactionListener);
427
+ domNode.addEventListener("touchstart", interactionListener);
428
+ }
429
+ } else if (domNode && interactionListener) {
430
+ domNode.removeEventListener("wheel", interactionListener, { passive: true });
431
+ domNode.removeEventListener("pointerdown", interactionListener);
432
+ domNode.removeEventListener("touchstart", interactionListener);
433
+ interactionListener = null;
434
+ }
435
+ } catch {}
436
+ }
437
+ };
438
+ return api;
439
+ }
440
+
441
+ //#endregion
442
+ //#region src/core/DiffEditorManager.ts
443
+ var DiffEditorManager = class {
444
+ diffEditorView = null;
445
+ originalModel = null;
446
+ modifiedModel = null;
447
+ lastContainer = null;
448
+ lastKnownOriginalCode = null;
449
+ lastKnownModifiedCode = null;
450
+ lastKnownModifiedLineCount = null;
451
+ pendingDiffUpdate = null;
452
+ shouldAutoScrollDiff = true;
453
+ diffScrollWatcher = null;
454
+ lastScrollTopDiff = 0;
455
+ _hasScrollBar = false;
456
+ cachedScrollHeightDiff = null;
457
+ cachedLineHeightDiff = null;
458
+ cachedComputedHeightDiff = null;
459
+ lastKnownModifiedDirty = false;
460
+ measureViewportDiff() {
461
+ var _me$getLayoutInfo, _me$getScrollTop, _me$getScrollHeight;
462
+ if (!this.diffEditorView) return null;
463
+ const me = this.diffEditorView.getModifiedEditor();
464
+ const li = ((_me$getLayoutInfo = me.getLayoutInfo) === null || _me$getLayoutInfo === void 0 ? void 0 : _me$getLayoutInfo.call(me)) ?? null;
465
+ const lineHeight = this.cachedLineHeightDiff ?? me.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
466
+ const scrollTop = ((_me$getScrollTop = me.getScrollTop) === null || _me$getScrollTop === void 0 ? void 0 : _me$getScrollTop.call(me)) ?? this.lastScrollTopDiff ?? 0;
467
+ const scrollHeight = ((_me$getScrollHeight = me.getScrollHeight) === null || _me$getScrollHeight === void 0 ? void 0 : _me$getScrollHeight.call(me)) ?? this.cachedScrollHeightDiff ?? (li === null || li === void 0 ? void 0 : li.height) ?? 0;
468
+ const computedHeight = this.cachedComputedHeightDiff ?? this.computedHeight();
469
+ this.cachedLineHeightDiff = lineHeight;
470
+ this.cachedScrollHeightDiff = scrollHeight;
471
+ this.cachedComputedHeightDiff = computedHeight;
472
+ this.lastScrollTopDiff = scrollTop;
473
+ return {
474
+ me,
475
+ li,
476
+ lineHeight,
477
+ scrollTop,
478
+ scrollHeight,
479
+ computedHeight
480
+ };
481
+ }
482
+ lastRevealLineDiff = null;
483
+ revealTicketDiff = 0;
484
+ revealDebounceIdDiff = null;
485
+ revealDebounceMs = defaultRevealDebounceMs;
486
+ revealIdleTimerIdDiff = null;
487
+ revealStrategyOption;
488
+ revealBatchOnIdleMsOption;
489
+ scrollWatcherSuppressionMs = 500;
490
+ diffScrollWatcherSuppressionTimer = null;
491
+ appendBufferOriginalDiff = [];
492
+ appendBufferModifiedDiff = [];
493
+ appendBufferDiffScheduled = false;
494
+ diffUpdateThrottleMs = 50;
495
+ lastAppendFlushTimeDiff = 0;
496
+ appendFlushThrottleTimerDiff = null;
497
+ rafScheduler = createRafScheduler();
498
+ diffHeightManager = null;
499
+ constructor(options, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, revealDebounceMsOption) {
500
+ this.options = options;
501
+ this.maxHeightValue = maxHeightValue;
502
+ this.maxHeightCSS = maxHeightCSS;
503
+ this.autoScrollOnUpdate = autoScrollOnUpdate;
504
+ this.autoScrollInitial = autoScrollInitial;
505
+ this.autoScrollThresholdPx = autoScrollThresholdPx;
506
+ this.autoScrollThresholdLines = autoScrollThresholdLines;
507
+ this.diffAutoScroll = diffAutoScroll;
508
+ this.revealDebounceMsOption = revealDebounceMsOption;
509
+ }
510
+ scheduleFlushAppendBufferDiff() {
511
+ if (this.appendBufferDiffScheduled) return;
512
+ this.appendBufferDiffScheduled = true;
513
+ const schedule = () => {
514
+ this.rafScheduler.schedule("appendDiff", () => this.flushAppendBufferDiff());
515
+ };
516
+ const throttle = this.diffUpdateThrottleMs;
517
+ if (!throttle) {
518
+ schedule();
519
+ return;
520
+ }
521
+ const now = Date.now();
522
+ const since = now - this.lastAppendFlushTimeDiff;
523
+ if (since >= throttle) {
524
+ schedule();
525
+ return;
526
+ }
527
+ if (this.appendFlushThrottleTimerDiff != null) return;
528
+ const wait = throttle - since;
529
+ this.appendFlushThrottleTimerDiff = setTimeout(() => {
530
+ this.appendFlushThrottleTimerDiff = null;
531
+ schedule();
532
+ }, wait);
533
+ }
534
+ flushOriginalAppendBufferSync() {
535
+ if (!this.originalModel) return;
536
+ if (this.appendBufferOriginalDiff.length === 0) return;
537
+ this.rafScheduler.cancel("appendDiff");
538
+ this.appendBufferDiffScheduled = false;
539
+ const text = this.appendBufferOriginalDiff.join("");
540
+ this.appendBufferOriginalDiff.length = 0;
541
+ if (!text) return;
542
+ this.appendToModel(this.originalModel, text);
543
+ }
544
+ computedHeight() {
545
+ var _originalEditor$getMo, _modifiedEditor$getMo, _originalEditor$getSc, _modifiedEditor$getSc;
546
+ if (!this.diffEditorView) return Math.min(1 * 18 + padding, this.maxHeightValue);
547
+ const modifiedEditor = this.diffEditorView.getModifiedEditor();
548
+ const originalEditor = this.diffEditorView.getOriginalEditor();
549
+ const lineHeight = modifiedEditor.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
550
+ const oCount = ((_originalEditor$getMo = originalEditor.getModel()) === null || _originalEditor$getMo === void 0 ? void 0 : _originalEditor$getMo.getLineCount()) ?? 1;
551
+ const mCount = ((_modifiedEditor$getMo = modifiedEditor.getModel()) === null || _modifiedEditor$getMo === void 0 ? void 0 : _modifiedEditor$getMo.getLineCount()) ?? 1;
552
+ const lineCount = Math.max(oCount, mCount);
553
+ const fromLines = lineCount * lineHeight + padding;
554
+ const scrollH = Math.max(((_originalEditor$getSc = originalEditor.getScrollHeight) === null || _originalEditor$getSc === void 0 ? void 0 : _originalEditor$getSc.call(originalEditor)) ?? 0, ((_modifiedEditor$getSc = modifiedEditor.getScrollHeight) === null || _modifiedEditor$getSc === void 0 ? void 0 : _modifiedEditor$getSc.call(modifiedEditor)) ?? 0);
555
+ const desired = Math.max(fromLines, scrollH);
556
+ return Math.min(desired, this.maxHeightValue);
557
+ }
558
+ isOverflowAutoDiff() {
559
+ return !!this.lastContainer && this.lastContainer.style.overflow === "auto";
560
+ }
561
+ shouldPerformImmediateRevealDiff() {
562
+ return this.autoScrollOnUpdate && this.shouldAutoScrollDiff && this.hasVerticalScrollbarModified() && this.isOverflowAutoDiff();
563
+ }
564
+ suppressScrollWatcherDiff(ms) {
565
+ if (!this.diffScrollWatcher || typeof this.diffScrollWatcher.setSuppressed !== "function") return;
566
+ if (this.diffScrollWatcherSuppressionTimer != null) {
567
+ clearTimeout(this.diffScrollWatcherSuppressionTimer);
568
+ this.diffScrollWatcherSuppressionTimer = null;
569
+ }
570
+ this.diffScrollWatcher.setSuppressed(true);
571
+ this.diffScrollWatcherSuppressionTimer = setTimeout(() => {
572
+ try {
573
+ this.diffScrollWatcher.setSuppressed(false);
574
+ } catch {}
575
+ this.diffScrollWatcherSuppressionTimer = null;
576
+ }, ms);
577
+ }
578
+ hasVerticalScrollbarModified() {
579
+ if (!this.diffEditorView) return false;
580
+ if (this._hasScrollBar) return true;
581
+ const m = this.measureViewportDiff();
582
+ if (!m) return false;
583
+ const epsilon = Math.max(2, Math.round(m.lineHeight / 8));
584
+ return this._hasScrollBar = m.scrollHeight > m.computedHeight + Math.max(padding / 2, epsilon);
585
+ }
586
+ userIsNearBottomDiff() {
587
+ if (!this.diffEditorView) return true;
588
+ const m = this.measureViewportDiff();
589
+ if (!m || !m.li) return true;
590
+ const lineThreshold = (this.autoScrollThresholdLines ?? 0) * m.lineHeight;
591
+ const threshold = Math.max(lineThreshold || 0, this.autoScrollThresholdPx || 0);
592
+ const distance = m.scrollHeight - (m.scrollTop + m.li.height);
593
+ return distance <= threshold;
594
+ }
595
+ maybeScrollDiffToBottom(targetLine, prevLineOverride) {
596
+ this.rafScheduler.schedule("maybe-scroll-diff", () => {
597
+ log("diff", "maybeScrollDiffToBottom called", {
598
+ targetLine,
599
+ prevLineOverride,
600
+ diffAutoScroll: this.diffAutoScroll,
601
+ autoScrollOnUpdate: this.autoScrollOnUpdate,
602
+ shouldAutoScrollDiff: this.shouldAutoScrollDiff
603
+ });
604
+ if (!this.diffEditorView) return;
605
+ const hasV = this.hasVerticalScrollbarModified();
606
+ log("diff", "hasVerticalScrollbarModified ->", hasV);
607
+ if (!(this.diffAutoScroll && this.autoScrollOnUpdate && this.shouldAutoScrollDiff && hasV)) return;
608
+ const me = this.diffEditorView.getModifiedEditor();
609
+ const model = me.getModel();
610
+ const currentLine = (model === null || model === void 0 ? void 0 : model.getLineCount()) ?? 1;
611
+ const line = targetLine ?? currentLine;
612
+ const prevLine = typeof prevLineOverride === "number" ? prevLineOverride : this.lastKnownModifiedLineCount ?? -1;
613
+ log("diff", "scroll metrics", {
614
+ prevLine,
615
+ currentLine,
616
+ line,
617
+ lastRevealLineDiff: this.lastRevealLineDiff
618
+ });
619
+ if (prevLine !== -1 && prevLine === currentLine && line === currentLine) return;
620
+ if (this.lastRevealLineDiff !== null && this.lastRevealLineDiff === line) return;
621
+ const batchMs = this.revealBatchOnIdleMsOption ?? this.options.revealBatchOnIdleMs ?? defaultRevealBatchOnIdleMs;
622
+ log("diff", "reveal timing", {
623
+ batchMs,
624
+ revealDebounceMs: this.revealDebounceMs,
625
+ revealDebounceMsOption: this.revealDebounceMsOption
626
+ });
627
+ if (typeof batchMs === "number" && batchMs > 0) {
628
+ if (hasV) {
629
+ const ticket$1 = ++this.revealTicketDiff;
630
+ log("diff", "has scrollbar -> immediate ticketed reveal", {
631
+ ticket: ticket$1,
632
+ line
633
+ });
634
+ this.performRevealDiffTicketed(line, ticket$1);
635
+ return;
636
+ }
637
+ if (this.revealIdleTimerIdDiff != null) clearTimeout(this.revealIdleTimerIdDiff);
638
+ const ticket = ++this.revealTicketDiff;
639
+ log("diff", "scheduling idle reveal", {
640
+ ticket,
641
+ batchMs,
642
+ line
643
+ });
644
+ this.revealIdleTimerIdDiff = setTimeout(() => {
645
+ this.revealIdleTimerIdDiff = null;
646
+ this.performRevealDiffTicketed(line, ticket);
647
+ }, batchMs);
648
+ return;
649
+ }
650
+ if (this.revealDebounceIdDiff != null) {
651
+ clearTimeout(this.revealDebounceIdDiff);
652
+ this.revealDebounceIdDiff = null;
653
+ }
654
+ const ms = typeof this.revealDebounceMs === "number" && this.revealDebounceMs > 0 ? this.revealDebounceMs : typeof this.revealDebounceMsOption === "number" && this.revealDebounceMsOption > 0 ? this.revealDebounceMsOption : this.revealDebounceMs;
655
+ this.revealDebounceIdDiff = setTimeout(() => {
656
+ this.revealDebounceIdDiff = null;
657
+ const ticket = ++this.revealTicketDiff;
658
+ log("diff", "debounced reveal firing", {
659
+ ticket,
660
+ line
661
+ });
662
+ this.performRevealDiffTicketed(line, ticket);
663
+ }, ms);
664
+ this.lastKnownModifiedLineCount = currentLine;
665
+ });
666
+ }
667
+ performRevealDiffTicketed(line, ticket) {
668
+ this.rafScheduler.schedule("revealDiff", () => {
669
+ var _editor;
670
+ if (this.diffScrollWatcher) {
671
+ log("diff", "performRevealDiffTicketed - suppressing watcher", {
672
+ ticket,
673
+ line,
674
+ ms: this.scrollWatcherSuppressionMs
675
+ });
676
+ this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs);
677
+ }
678
+ if (ticket !== this.revealTicketDiff) return;
679
+ log("diff", "performRevealDiffTicketed - performing reveal", {
680
+ ticket,
681
+ line
682
+ });
683
+ const strategy = this.revealStrategyOption ?? this.options.revealStrategy ?? "centerIfOutside";
684
+ const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
685
+ const smooth = ScrollType && typeof ScrollType.Smooth !== "undefined" ? ScrollType.Smooth : void 0;
686
+ try {
687
+ const me = this.diffEditorView.getModifiedEditor();
688
+ if (strategy === "bottom") if (typeof smooth !== "undefined") me.revealLine(line, smooth);
689
+ else me.revealLine(line);
690
+ else if (strategy === "center") if (typeof smooth !== "undefined") me.revealLineInCenter(line, smooth);
691
+ else me.revealLineInCenter(line);
692
+ else if (typeof smooth !== "undefined") me.revealLineInCenterIfOutsideViewport(line, smooth);
693
+ else me.revealLineInCenterIfOutsideViewport(line);
694
+ } catch {
695
+ try {
696
+ this.diffEditorView.getModifiedEditor().revealLine(line);
697
+ } catch {}
698
+ }
699
+ this.lastRevealLineDiff = line;
700
+ log("diff", "performRevealDiffTicketed - revealed", {
701
+ line,
702
+ lastRevealLineDiff: this.lastRevealLineDiff
703
+ });
704
+ try {
705
+ var _this$diffEditorView, _this$diffEditorView$, _this$diffEditorView$2;
706
+ this.shouldAutoScrollDiff = true;
707
+ this.lastScrollTopDiff = ((_this$diffEditorView = this.diffEditorView) === null || _this$diffEditorView === void 0 || (_this$diffEditorView$2 = (_this$diffEditorView$ = _this$diffEditorView.getModifiedEditor()).getScrollTop) === null || _this$diffEditorView$2 === void 0 ? void 0 : _this$diffEditorView$2.call(_this$diffEditorView$)) ?? this.lastScrollTopDiff;
708
+ } catch {}
709
+ });
710
+ }
711
+ performImmediateRevealDiff(line, ticket) {
712
+ var _editor2;
713
+ if (!this.diffEditorView) return;
714
+ if (ticket !== this.revealTicketDiff) return;
715
+ const ScrollType = monaco_shim_exports.ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
716
+ const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
717
+ const me = this.diffEditorView.getModifiedEditor();
718
+ if (typeof immediate !== "undefined") me.revealLine(line, immediate);
719
+ else me.revealLine(line);
720
+ this.measureViewportDiff();
721
+ log("diff", "performImmediateRevealDiff", {
722
+ line,
723
+ ticket
724
+ });
725
+ try {
726
+ var _this$diffEditorView2, _this$diffEditorView3, _this$diffEditorView4;
727
+ this.shouldAutoScrollDiff = true;
728
+ this.lastScrollTopDiff = ((_this$diffEditorView2 = this.diffEditorView) === null || _this$diffEditorView2 === void 0 || (_this$diffEditorView4 = (_this$diffEditorView3 = _this$diffEditorView2.getModifiedEditor()).getScrollTop) === null || _this$diffEditorView4 === void 0 ? void 0 : _this$diffEditorView4.call(_this$diffEditorView3)) ?? this.lastScrollTopDiff;
729
+ } catch {}
730
+ }
731
+ scheduleImmediateRevealAfterLayoutDiff(line) {
732
+ const ticket = ++this.revealTicketDiff;
733
+ this.rafScheduler.schedule("immediate-reveal-diff", async () => {
734
+ const target = this.diffEditorView && this.diffHeightManager ? Math.min(this.computedHeight(), this.maxHeightValue) : -1;
735
+ if (target !== -1 && this.diffHeightManager) {
736
+ if (this.lastContainer) this.lastContainer.style.height = `${target}px`;
737
+ await this.waitForHeightAppliedDiff(target);
738
+ }
739
+ this.performImmediateRevealDiff(line, ticket);
740
+ });
741
+ }
742
+ waitForHeightAppliedDiff(target, timeoutMs = 500) {
743
+ return new Promise((resolve) => {
744
+ const start = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
745
+ const check = () => {
746
+ const applied = this.lastContainer ? Number.parseFloat((this.lastContainer.style.height || "").replace("px", "")) || 0 : -1;
747
+ if (applied >= target - 1) {
748
+ resolve();
749
+ return;
750
+ }
751
+ if ((typeof performance !== "undefined" && performance.now ? performance.now() : Date.now()) - start > timeoutMs) {
752
+ resolve();
753
+ return;
754
+ }
755
+ requestAnimationFrame(check);
756
+ };
757
+ check();
758
+ });
759
+ }
760
+ async createDiffEditor(container, originalCode, modifiedCode, language, currentTheme) {
761
+ var _me$getScrollHeight2, _me$getOption, _oEditor$onDidContent, _mEditor$onDidContent;
762
+ this.cleanup();
763
+ this.lastContainer = container;
764
+ container.style.overflow = "hidden";
765
+ container.style.maxHeight = this.maxHeightCSS;
766
+ const lang = processedLanguage(language) || language;
767
+ this.originalModel = monaco_shim_exports.editor.createModel(originalCode, lang);
768
+ this.modifiedModel = monaco_shim_exports.editor.createModel(modifiedCode, lang);
769
+ this.diffEditorView = monaco_shim_exports.editor.createDiffEditor(container, {
770
+ automaticLayout: true,
771
+ scrollBeyondLastLine: false,
772
+ renderSideBySide: true,
773
+ originalEditable: false,
774
+ readOnly: this.options.readOnly ?? true,
775
+ minimap: { enabled: false },
776
+ theme: currentTheme,
777
+ contextmenu: false,
778
+ scrollbar: {
779
+ ...defaultScrollbar,
780
+ ...this.options.scrollbar || {}
781
+ },
782
+ ...this.options
783
+ });
784
+ monaco_shim_exports.editor.setTheme(currentTheme);
785
+ this.diffEditorView.setModel({
786
+ original: this.originalModel,
787
+ modified: this.modifiedModel
788
+ });
789
+ this.lastKnownOriginalCode = originalCode;
790
+ this.lastKnownModifiedCode = modifiedCode;
791
+ this.diffUpdateThrottleMs = this.options.diffUpdateThrottleMs ?? 50;
792
+ this.shouldAutoScrollDiff = !!(this.autoScrollInitial && this.diffAutoScroll);
793
+ if (this.diffScrollWatcher) {
794
+ this.diffScrollWatcher.dispose();
795
+ this.diffScrollWatcher = null;
796
+ }
797
+ if (this.diffAutoScroll) {
798
+ const me$1 = this.diffEditorView.getModifiedEditor();
799
+ this.diffScrollWatcher = createScrollWatcherForEditor(me$1, {
800
+ onPause: () => {
801
+ this.shouldAutoScrollDiff = false;
802
+ },
803
+ onMaybeResume: () => {
804
+ this.rafScheduler.schedule("maybe-resume-diff", () => {
805
+ this.shouldAutoScrollDiff = this.userIsNearBottomDiff();
806
+ });
807
+ },
808
+ getLast: () => this.lastScrollTopDiff,
809
+ setLast: (v) => {
810
+ this.lastScrollTopDiff = v;
811
+ }
812
+ });
813
+ }
814
+ log("diff", "createDiffEditor", {
815
+ autoScrollInitial: this.autoScrollInitial,
816
+ diffAutoScroll: this.diffAutoScroll
817
+ });
818
+ const MIN_VISIBLE_HEIGHT = Math.min(120, this.maxHeightValue);
819
+ container.style.minHeight = `${MIN_VISIBLE_HEIGHT}px`;
820
+ if (this.diffHeightManager) {
821
+ this.diffHeightManager.dispose();
822
+ this.diffHeightManager = null;
823
+ }
824
+ this.diffHeightManager = createHeightManager(container, () => this.computedHeight());
825
+ this.diffHeightManager.update();
826
+ const initialComputed = this.computedHeight();
827
+ if (initialComputed >= this.maxHeightValue - 1) {
828
+ container.style.height = `${this.maxHeightValue}px`;
829
+ container.style.overflow = "auto";
830
+ }
831
+ const me = this.diffEditorView.getModifiedEditor();
832
+ this.cachedScrollHeightDiff = ((_me$getScrollHeight2 = me.getScrollHeight) === null || _me$getScrollHeight2 === void 0 ? void 0 : _me$getScrollHeight2.call(me)) ?? null;
833
+ this.cachedLineHeightDiff = ((_me$getOption = me.getOption) === null || _me$getOption === void 0 ? void 0 : _me$getOption.call(me, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? null;
834
+ this.cachedComputedHeightDiff = this.computedHeight();
835
+ const oEditor = this.diffEditorView.getOriginalEditor();
836
+ const mEditor = this.diffEditorView.getModifiedEditor();
837
+ (_oEditor$onDidContent = oEditor.onDidContentSizeChange) === null || _oEditor$onDidContent === void 0 || _oEditor$onDidContent.call(oEditor, () => {
838
+ this._hasScrollBar = false;
839
+ this.rafScheduler.schedule("content-size-change-diff", () => {
840
+ var _oEditor$getScrollHei, _oEditor$getOption, _this$diffHeightManag, _this$diffHeightManag2;
841
+ this.cachedScrollHeightDiff = ((_oEditor$getScrollHei = oEditor.getScrollHeight) === null || _oEditor$getScrollHei === void 0 ? void 0 : _oEditor$getScrollHei.call(oEditor)) ?? this.cachedScrollHeightDiff;
842
+ this.cachedLineHeightDiff = ((_oEditor$getOption = oEditor.getOption) === null || _oEditor$getOption === void 0 ? void 0 : _oEditor$getOption.call(oEditor, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? this.cachedLineHeightDiff;
843
+ this.cachedComputedHeightDiff = this.computedHeight();
844
+ if ((_this$diffHeightManag = this.diffHeightManager) === null || _this$diffHeightManag === void 0 ? void 0 : _this$diffHeightManag.isSuppressed()) return;
845
+ (_this$diffHeightManag2 = this.diffHeightManager) === null || _this$diffHeightManag2 === void 0 || _this$diffHeightManag2.update();
846
+ const computed$2 = this.computedHeight();
847
+ if (this.lastContainer) {
848
+ const prevOverflow = this.lastContainer.style.overflow;
849
+ const newOverflow = computed$2 >= this.maxHeightValue - 1 ? "auto" : "hidden";
850
+ if (prevOverflow !== newOverflow) {
851
+ this.lastContainer.style.overflow = newOverflow;
852
+ if (newOverflow === "auto" && this.shouldAutoScrollDiff) {
853
+ var _this$modifiedModel;
854
+ this.maybeScrollDiffToBottom((_this$modifiedModel = this.modifiedModel) === null || _this$modifiedModel === void 0 ? void 0 : _this$modifiedModel.getLineCount());
855
+ }
856
+ }
857
+ }
858
+ });
859
+ });
860
+ (_mEditor$onDidContent = mEditor.onDidContentSizeChange) === null || _mEditor$onDidContent === void 0 || _mEditor$onDidContent.call(mEditor, () => {
861
+ this._hasScrollBar = false;
862
+ this.rafScheduler.schedule("content-size-change-diff", () => {
863
+ var _mEditor$getScrollHei, _mEditor$getOption, _this$diffHeightManag3, _this$diffHeightManag4;
864
+ this.cachedScrollHeightDiff = ((_mEditor$getScrollHei = mEditor.getScrollHeight) === null || _mEditor$getScrollHei === void 0 ? void 0 : _mEditor$getScrollHei.call(mEditor)) ?? this.cachedScrollHeightDiff;
865
+ this.cachedLineHeightDiff = ((_mEditor$getOption = mEditor.getOption) === null || _mEditor$getOption === void 0 ? void 0 : _mEditor$getOption.call(mEditor, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? this.cachedLineHeightDiff;
866
+ this.cachedComputedHeightDiff = this.computedHeight();
867
+ if ((_this$diffHeightManag3 = this.diffHeightManager) === null || _this$diffHeightManag3 === void 0 ? void 0 : _this$diffHeightManag3.isSuppressed()) return;
868
+ (_this$diffHeightManag4 = this.diffHeightManager) === null || _this$diffHeightManag4 === void 0 || _this$diffHeightManag4.update();
869
+ const computed$2 = this.computedHeight();
870
+ if (this.lastContainer) {
871
+ const prevOverflow = this.lastContainer.style.overflow;
872
+ const newOverflow = computed$2 >= this.maxHeightValue - 1 ? "auto" : "hidden";
873
+ if (prevOverflow !== newOverflow) {
874
+ this.lastContainer.style.overflow = newOverflow;
875
+ if (newOverflow === "auto" && this.shouldAutoScrollDiff) {
876
+ var _this$modifiedModel2;
877
+ this.maybeScrollDiffToBottom((_this$modifiedModel2 = this.modifiedModel) === null || _this$modifiedModel2 === void 0 ? void 0 : _this$modifiedModel2.getLineCount());
878
+ }
879
+ }
880
+ }
881
+ });
882
+ });
883
+ mEditor.onDidChangeModelContent(() => {
884
+ this.lastKnownModifiedDirty = true;
885
+ this.rafScheduler.schedule("sync-last-known-modified", () => this.syncLastKnownModified());
886
+ });
887
+ this.maybeScrollDiffToBottom(this.modifiedModel.getLineCount(), this.lastKnownModifiedLineCount ?? void 0);
888
+ return this.diffEditorView;
889
+ }
890
+ updateDiff(originalCode, modifiedCode, codeLanguage) {
891
+ if (!this.diffEditorView || !this.originalModel || !this.modifiedModel) return;
892
+ const plang = codeLanguage ? processedLanguage(codeLanguage) : void 0;
893
+ if (plang && (this.originalModel.getLanguageId() !== plang || this.modifiedModel.getLanguageId() !== plang)) {
894
+ this.pendingDiffUpdate = {
895
+ original: originalCode,
896
+ modified: modifiedCode,
897
+ lang: codeLanguage
898
+ };
899
+ this.rafScheduler.schedule("diff", () => this.flushPendingDiffUpdate());
900
+ return;
901
+ }
902
+ if (this.lastKnownOriginalCode == null) this.lastKnownOriginalCode = this.originalModel.getValue();
903
+ if (this.lastKnownModifiedCode == null) this.lastKnownModifiedCode = this.modifiedModel.getValue();
904
+ const prevO = this.lastKnownOriginalCode;
905
+ const prevM = this.lastKnownModifiedCode;
906
+ let didImmediate = false;
907
+ if (originalCode !== prevO && originalCode.startsWith(prevO)) {
908
+ this.appendOriginal(originalCode.slice(prevO.length));
909
+ this.lastKnownOriginalCode = originalCode;
910
+ didImmediate = true;
911
+ }
912
+ if (modifiedCode !== prevM && modifiedCode.startsWith(prevM)) {
913
+ this.appendModified(modifiedCode.slice(prevM.length));
914
+ this.lastKnownModifiedCode = modifiedCode;
915
+ didImmediate = true;
916
+ }
917
+ if (originalCode !== this.lastKnownOriginalCode || modifiedCode !== this.lastKnownModifiedCode) {
918
+ this.pendingDiffUpdate = {
919
+ original: originalCode,
920
+ modified: modifiedCode
921
+ };
922
+ this.rafScheduler.schedule("diff", () => this.flushPendingDiffUpdate());
923
+ } else if (didImmediate) {}
924
+ }
925
+ updateOriginal(newCode, codeLanguage) {
926
+ if (!this.diffEditorView || !this.originalModel) return;
927
+ if (codeLanguage) {
928
+ const lang = processedLanguage(codeLanguage);
929
+ if (lang && this.originalModel.getLanguageId() !== lang) monaco_shim_exports.editor.setModelLanguage(this.originalModel, lang);
930
+ }
931
+ const prev = this.lastKnownOriginalCode ?? this.originalModel.getValue();
932
+ if (prev === newCode) return;
933
+ if (newCode.startsWith(prev) && prev.length < newCode.length) this.appendOriginal(newCode.slice(prev.length), codeLanguage);
934
+ else {
935
+ this.flushOriginalAppendBufferSync();
936
+ this.applyMinimalEditToModel(this.originalModel, prev, newCode);
937
+ }
938
+ this.lastKnownOriginalCode = newCode;
939
+ }
940
+ updateModified(newCode, codeLanguage) {
941
+ if (!this.diffEditorView || !this.modifiedModel) return;
942
+ if (codeLanguage) {
943
+ const lang = processedLanguage(codeLanguage);
944
+ if (lang && this.modifiedModel.getLanguageId() !== lang) monaco_shim_exports.editor.setModelLanguage(this.modifiedModel, lang);
945
+ }
946
+ const prev = this.lastKnownModifiedCode ?? this.modifiedModel.getValue();
947
+ if (prev === newCode) return;
948
+ if (newCode.startsWith(prev) && prev.length < newCode.length) this.appendModified(newCode.slice(prev.length), codeLanguage);
949
+ else {
950
+ this.flushModifiedAppendBufferSync();
951
+ const prevAfterFlush = this.modifiedModel.getValue();
952
+ const prevLine = this.modifiedModel.getLineCount();
953
+ this.applyMinimalEditToModel(this.modifiedModel, prevAfterFlush, newCode);
954
+ const newLine = this.modifiedModel.getLineCount();
955
+ if (newLine !== prevLine) {
956
+ const shouldImmediate = this.shouldPerformImmediateRevealDiff();
957
+ if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
958
+ const computed$2 = this.computedHeight();
959
+ if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) {
960
+ this.lastContainer.style.height = `${this.maxHeightValue}px`;
961
+ this.lastContainer.style.overflow = "auto";
962
+ }
963
+ if (shouldImmediate) this.scheduleImmediateRevealAfterLayoutDiff(newLine);
964
+ else this.maybeScrollDiffToBottom(newLine, prevLine);
965
+ if (this.autoScrollOnUpdate && this.shouldAutoScrollDiff) try {
966
+ var _editor3, _me2$getModel, _me2$getScrollTop;
967
+ const ScrollType = monaco_shim_exports.ScrollType || ((_editor3 = monaco_shim_exports.editor) === null || _editor3 === void 0 ? void 0 : _editor3.ScrollType);
968
+ const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
969
+ const me2 = this.diffEditorView.getModifiedEditor();
970
+ const targetLine = ((_me2$getModel = me2.getModel()) === null || _me2$getModel === void 0 ? void 0 : _me2$getModel.getLineCount()) ?? newLine;
971
+ if (typeof immediate !== "undefined") me2.revealLine(targetLine, immediate);
972
+ else me2.revealLine(targetLine);
973
+ this.lastRevealLineDiff = targetLine;
974
+ this.shouldAutoScrollDiff = true;
975
+ this.lastScrollTopDiff = ((_me2$getScrollTop = me2.getScrollTop) === null || _me2$getScrollTop === void 0 ? void 0 : _me2$getScrollTop.call(me2)) ?? this.lastScrollTopDiff;
976
+ } catch {}
977
+ }
978
+ }
979
+ this.lastKnownModifiedCode = newCode;
980
+ }
981
+ appendOriginal(appendText, codeLanguage) {
982
+ if (!this.diffEditorView || !this.originalModel || !appendText) return;
983
+ if (codeLanguage) {
984
+ const lang = processedLanguage(codeLanguage);
985
+ if (lang && this.originalModel.getLanguageId() !== lang) monaco_shim_exports.editor.setModelLanguage(this.originalModel, lang);
986
+ }
987
+ this.appendBufferOriginalDiff.push(appendText);
988
+ this.scheduleFlushAppendBufferDiff();
989
+ }
990
+ appendModified(appendText, codeLanguage) {
991
+ if (!this.diffEditorView || !this.modifiedModel || !appendText) return;
992
+ if (codeLanguage) {
993
+ const lang = processedLanguage(codeLanguage);
994
+ if (lang && this.modifiedModel.getLanguageId() !== lang) monaco_shim_exports.editor.setModelLanguage(this.modifiedModel, lang);
995
+ }
996
+ this.appendBufferModifiedDiff.push(appendText);
997
+ this.scheduleFlushAppendBufferDiff();
998
+ }
999
+ setLanguage(language, languages$1) {
1000
+ if (!languages$1.includes(language)) {
1001
+ console.warn(`Language "${language}" is not registered. Available languages: ${languages$1.join(", ")}`);
1002
+ return;
1003
+ }
1004
+ if (this.originalModel && this.originalModel.getLanguageId() !== language) monaco_shim_exports.editor.setModelLanguage(this.originalModel, language);
1005
+ if (this.modifiedModel && this.modifiedModel.getLanguageId() !== language) monaco_shim_exports.editor.setModelLanguage(this.modifiedModel, language);
1006
+ }
1007
+ getDiffEditorView() {
1008
+ return this.diffEditorView;
1009
+ }
1010
+ getDiffModels() {
1011
+ return {
1012
+ original: this.originalModel,
1013
+ modified: this.modifiedModel
1014
+ };
1015
+ }
1016
+ cleanup() {
1017
+ this.rafScheduler.cancel("diff");
1018
+ this.pendingDiffUpdate = null;
1019
+ this.rafScheduler.cancel("appendDiff");
1020
+ this.appendBufferDiffScheduled = false;
1021
+ this.appendBufferOriginalDiff.length = 0;
1022
+ this.appendBufferModifiedDiff.length = 0;
1023
+ if (this.appendFlushThrottleTimerDiff != null) {
1024
+ clearTimeout(this.appendFlushThrottleTimerDiff);
1025
+ this.appendFlushThrottleTimerDiff = null;
1026
+ }
1027
+ this.rafScheduler.cancel("content-size-change-diff");
1028
+ this.rafScheduler.cancel("sync-last-known-modified");
1029
+ if (this.diffScrollWatcher) {
1030
+ this.diffScrollWatcher.dispose();
1031
+ this.diffScrollWatcher = null;
1032
+ }
1033
+ if (this.diffHeightManager) {
1034
+ this.diffHeightManager.dispose();
1035
+ this.diffHeightManager = null;
1036
+ }
1037
+ if (this.diffEditorView) {
1038
+ this.diffEditorView.dispose();
1039
+ this.diffEditorView = null;
1040
+ }
1041
+ if (this.originalModel) {
1042
+ this.originalModel.dispose();
1043
+ this.originalModel = null;
1044
+ }
1045
+ if (this.modifiedModel) {
1046
+ this.modifiedModel.dispose();
1047
+ this.modifiedModel = null;
1048
+ }
1049
+ this.lastKnownOriginalCode = null;
1050
+ this.lastKnownModifiedCode = null;
1051
+ if (this.lastContainer) {
1052
+ this.lastContainer.innerHTML = "";
1053
+ this.lastContainer = null;
1054
+ }
1055
+ if (this.revealDebounceIdDiff != null) {
1056
+ clearTimeout(this.revealDebounceIdDiff);
1057
+ this.revealDebounceIdDiff = null;
1058
+ }
1059
+ if (this.revealIdleTimerIdDiff != null) {
1060
+ clearTimeout(this.revealIdleTimerIdDiff);
1061
+ this.revealIdleTimerIdDiff = null;
1062
+ }
1063
+ if (this.diffScrollWatcherSuppressionTimer != null) {
1064
+ clearTimeout(this.diffScrollWatcherSuppressionTimer);
1065
+ this.diffScrollWatcherSuppressionTimer = null;
1066
+ }
1067
+ this.revealTicketDiff = 0;
1068
+ this.lastRevealLineDiff = null;
1069
+ }
1070
+ safeClean() {
1071
+ this.rafScheduler.cancel("diff");
1072
+ this.pendingDiffUpdate = null;
1073
+ this.rafScheduler.cancel("appendDiff");
1074
+ this.appendBufferDiffScheduled = false;
1075
+ this.appendBufferOriginalDiff.length = 0;
1076
+ this.appendBufferModifiedDiff.length = 0;
1077
+ if (this.appendFlushThrottleTimerDiff != null) {
1078
+ clearTimeout(this.appendFlushThrottleTimerDiff);
1079
+ this.appendFlushThrottleTimerDiff = null;
1080
+ }
1081
+ if (this.diffScrollWatcher) {
1082
+ this.diffScrollWatcher.dispose();
1083
+ this.diffScrollWatcher = null;
1084
+ }
1085
+ this._hasScrollBar = false;
1086
+ this.shouldAutoScrollDiff = !!(this.autoScrollInitial && this.diffAutoScroll);
1087
+ this.lastScrollTopDiff = 0;
1088
+ if (this.diffHeightManager) {
1089
+ this.diffHeightManager.dispose();
1090
+ this.diffHeightManager = null;
1091
+ }
1092
+ if (this.revealDebounceIdDiff != null) {
1093
+ clearTimeout(this.revealDebounceIdDiff);
1094
+ this.revealDebounceIdDiff = null;
1095
+ }
1096
+ if (this.revealIdleTimerIdDiff != null) {
1097
+ clearTimeout(this.revealIdleTimerIdDiff);
1098
+ this.revealIdleTimerIdDiff = null;
1099
+ }
1100
+ if (this.diffScrollWatcherSuppressionTimer != null) {
1101
+ clearTimeout(this.diffScrollWatcherSuppressionTimer);
1102
+ this.diffScrollWatcherSuppressionTimer = null;
1103
+ }
1104
+ this.revealTicketDiff = 0;
1105
+ this.lastRevealLineDiff = null;
1106
+ this.rafScheduler.cancel("content-size-change-diff");
1107
+ this.rafScheduler.cancel("sync-last-known-modified");
1108
+ }
1109
+ syncLastKnownModified() {
1110
+ if (!this.diffEditorView || !this.lastKnownModifiedDirty) return;
1111
+ try {
1112
+ const me = this.diffEditorView.getModifiedEditor();
1113
+ const model = me.getModel();
1114
+ if (model) {
1115
+ this.lastKnownModifiedCode = model.getValue();
1116
+ this.lastKnownModifiedLineCount = model.getLineCount();
1117
+ }
1118
+ } finally {
1119
+ this.lastKnownModifiedDirty = false;
1120
+ }
1121
+ }
1122
+ flushPendingDiffUpdate() {
1123
+ if (!this.pendingDiffUpdate || !this.diffEditorView) return;
1124
+ const o = this.originalModel;
1125
+ const m = this.modifiedModel;
1126
+ if (!o || !m) {
1127
+ this.pendingDiffUpdate = null;
1128
+ return;
1129
+ }
1130
+ const { original, modified, lang } = this.pendingDiffUpdate;
1131
+ this.pendingDiffUpdate = null;
1132
+ this.flushOriginalAppendBufferSync();
1133
+ this.flushModifiedAppendBufferSync();
1134
+ if (lang) {
1135
+ const plang = processedLanguage(lang);
1136
+ if (plang) {
1137
+ if (o.getLanguageId() !== plang) {
1138
+ monaco_shim_exports.editor.setModelLanguage(o, plang);
1139
+ monaco_shim_exports.editor.setModelLanguage(m, plang);
1140
+ }
1141
+ }
1142
+ }
1143
+ if (this.lastKnownOriginalCode == null) this.lastKnownOriginalCode = o.getValue();
1144
+ if (this.lastKnownModifiedCode == null) this.lastKnownModifiedCode = m.getValue();
1145
+ const prevO = this.lastKnownOriginalCode;
1146
+ if (prevO !== original) {
1147
+ if (original.startsWith(prevO) && prevO.length < original.length) this.appendToModel(o, original.slice(prevO.length));
1148
+ else this.applyMinimalEditToModel(o, prevO, original);
1149
+ this.lastKnownOriginalCode = original;
1150
+ }
1151
+ const prevM = m.getValue();
1152
+ const prevMLineCount = m.getLineCount();
1153
+ if (prevM !== modified) {
1154
+ if (modified.startsWith(prevM) && prevM.length < modified.length) this.appendToModel(m, modified.slice(prevM.length));
1155
+ else this.applyMinimalEditToModel(m, prevM, modified);
1156
+ this.lastKnownModifiedCode = modified;
1157
+ const newMLineCount = m.getLineCount();
1158
+ if (newMLineCount !== prevMLineCount) {
1159
+ const shouldImmediate = this.shouldPerformImmediateRevealDiff();
1160
+ if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
1161
+ const computed$2 = this.computedHeight();
1162
+ if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) {
1163
+ this.lastContainer.style.height = `${this.maxHeightValue}px`;
1164
+ this.lastContainer.style.overflow = "auto";
1165
+ }
1166
+ if (shouldImmediate) this.scheduleImmediateRevealAfterLayoutDiff(newMLineCount);
1167
+ else this.maybeScrollDiffToBottom(newMLineCount, prevMLineCount);
1168
+ }
1169
+ }
1170
+ }
1171
+ flushModifiedAppendBufferSync() {
1172
+ if (!this.modifiedModel) return;
1173
+ if (this.appendBufferModifiedDiff.length === 0) return;
1174
+ this.rafScheduler.cancel("appendDiff");
1175
+ this.appendBufferDiffScheduled = false;
1176
+ const text = this.appendBufferModifiedDiff.join("");
1177
+ this.appendBufferModifiedDiff.length = 0;
1178
+ if (!text) return;
1179
+ this.appendToModel(this.modifiedModel, text);
1180
+ }
1181
+ async flushAppendBufferDiff() {
1182
+ if (!this.diffEditorView) return;
1183
+ if (this.appendBufferOriginalDiff.length === 0 && this.appendBufferModifiedDiff.length === 0) return;
1184
+ this.lastAppendFlushTimeDiff = Date.now();
1185
+ this.appendBufferDiffScheduled = false;
1186
+ if (this.originalModel && this.appendBufferOriginalDiff.length > 0) {
1187
+ const oText = this.appendBufferOriginalDiff.join("");
1188
+ this.appendBufferOriginalDiff.length = 0;
1189
+ if (oText) this.appendToModel(this.originalModel, oText);
1190
+ }
1191
+ const me = this.diffEditorView.getModifiedEditor();
1192
+ const model = me.getModel();
1193
+ if (!model) {
1194
+ this.appendBufferModifiedDiff.length = 0;
1195
+ return;
1196
+ }
1197
+ let parts = this.appendBufferModifiedDiff.splice(0);
1198
+ const prevLineInit = model.getLineCount();
1199
+ const totalText = parts.join("");
1200
+ const totalChars = totalText.length;
1201
+ if (parts.length === 1 && totalChars > 5e3) {
1202
+ const lines = totalText.split(/\r?\n/);
1203
+ const chunkSize = 200;
1204
+ const chunks = [];
1205
+ for (let i = 0; i < lines.length; i += chunkSize) chunks.push(`${lines.slice(i, i + chunkSize).join("\n")}\n`);
1206
+ if (chunks.length > 1) parts = chunks;
1207
+ }
1208
+ const applyChunked = parts.length > 1 && (totalChars > 2e3 || model.getLineCount && model.getLineCount() + 0 - prevLineInit > 50);
1209
+ log("diff", "flushAppendBufferDiff start", {
1210
+ partsCount: parts.length,
1211
+ totalChars,
1212
+ applyChunked
1213
+ });
1214
+ let prevLine = prevLineInit;
1215
+ const watcherApi = this.diffScrollWatcher;
1216
+ let suppressedByFlush = false;
1217
+ if (watcherApi && typeof watcherApi.setSuppressed === "function") try {
1218
+ if (this.diffScrollWatcherSuppressionTimer != null) {
1219
+ clearTimeout(this.diffScrollWatcherSuppressionTimer);
1220
+ this.diffScrollWatcherSuppressionTimer = null;
1221
+ }
1222
+ watcherApi.setSuppressed(true);
1223
+ suppressedByFlush = true;
1224
+ } catch {}
1225
+ if (applyChunked) {
1226
+ log("diff", "flushAppendBufferDiff applying chunked", { partsLen: parts.length });
1227
+ let idx = 0;
1228
+ for (const part of parts) {
1229
+ if (!part) continue;
1230
+ idx += 1;
1231
+ log("diff", "flushAppendBufferDiff chunk", {
1232
+ idx,
1233
+ partLen: part.length,
1234
+ prevLine
1235
+ });
1236
+ const lastColumn$1 = model.getLineMaxColumn(prevLine);
1237
+ const range$1 = new monaco_shim_exports.Range(prevLine, lastColumn$1, prevLine, lastColumn$1);
1238
+ model.applyEdits([{
1239
+ range: range$1,
1240
+ text: part,
1241
+ forceMoveMarkers: true
1242
+ }]);
1243
+ this.lastKnownModifiedCode = model.getValue();
1244
+ const newLine$1 = model.getLineCount();
1245
+ this.lastKnownModifiedLineCount = newLine$1;
1246
+ await new Promise((resolve) => typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame(resolve) : setTimeout(resolve, 0));
1247
+ const shouldImmediate$1 = this.shouldPerformImmediateRevealDiff();
1248
+ log("diff", "flushAppendBufferDiff chunk metrics", {
1249
+ idx,
1250
+ newLine: newLine$1,
1251
+ prevLine,
1252
+ shouldImmediate: shouldImmediate$1
1253
+ });
1254
+ if (shouldImmediate$1) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
1255
+ const computed$3 = this.computedHeight();
1256
+ if (computed$3 >= this.maxHeightValue - 1 && this.lastContainer) {
1257
+ this.lastContainer.style.height = `${this.maxHeightValue}px`;
1258
+ this.lastContainer.style.overflow = "auto";
1259
+ }
1260
+ if (shouldImmediate$1) this.scheduleImmediateRevealAfterLayoutDiff(newLine$1);
1261
+ else this.maybeScrollDiffToBottom(newLine$1, prevLine);
1262
+ prevLine = newLine$1;
1263
+ log("diff", "flushAppendBufferDiff chunk applied", {
1264
+ idx,
1265
+ newLine: newLine$1
1266
+ });
1267
+ }
1268
+ if (suppressedByFlush) watcherApi.setSuppressed(false);
1269
+ return;
1270
+ }
1271
+ const text = totalText;
1272
+ this.appendBufferModifiedDiff.length = 0;
1273
+ prevLine = model.getLineCount();
1274
+ const lastColumn = model.getLineMaxColumn(prevLine);
1275
+ const range = new monaco_shim_exports.Range(prevLine, lastColumn, prevLine, lastColumn);
1276
+ model.applyEdits([{
1277
+ range,
1278
+ text,
1279
+ forceMoveMarkers: true
1280
+ }]);
1281
+ this.lastKnownModifiedCode = model.getValue();
1282
+ const newLine = model.getLineCount();
1283
+ this.lastKnownModifiedLineCount = newLine;
1284
+ const shouldImmediate = this.shouldPerformImmediateRevealDiff();
1285
+ if (shouldImmediate) this.suppressScrollWatcherDiff(this.scrollWatcherSuppressionMs + 800);
1286
+ const computed$2 = this.computedHeight();
1287
+ if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) this.lastContainer.style.height = `${this.maxHeightValue}px`;
1288
+ if (shouldImmediate) this.scheduleImmediateRevealAfterLayoutDiff(newLine);
1289
+ else this.maybeScrollDiffToBottom(newLine, prevLine);
1290
+ if (this.autoScrollOnUpdate && this.shouldAutoScrollDiff) try {
1291
+ var _editor4, _me2$getModel2, _me2$getScrollTop2;
1292
+ const ScrollType = monaco_shim_exports.ScrollType || ((_editor4 = monaco_shim_exports.editor) === null || _editor4 === void 0 ? void 0 : _editor4.ScrollType);
1293
+ const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
1294
+ const me2 = this.diffEditorView.getModifiedEditor();
1295
+ const targetLine = ((_me2$getModel2 = me2.getModel()) === null || _me2$getModel2 === void 0 ? void 0 : _me2$getModel2.getLineCount()) ?? newLine;
1296
+ if (typeof immediate !== "undefined") me2.revealLine(targetLine, immediate);
1297
+ else me2.revealLine(targetLine);
1298
+ this.lastRevealLineDiff = targetLine;
1299
+ this.shouldAutoScrollDiff = true;
1300
+ this.lastScrollTopDiff = ((_me2$getScrollTop2 = me2.getScrollTop) === null || _me2$getScrollTop2 === void 0 ? void 0 : _me2$getScrollTop2.call(me2)) ?? this.lastScrollTopDiff;
1301
+ } catch {}
1302
+ if (suppressedByFlush) watcherApi.setSuppressed(false);
1303
+ try {
1304
+ var _this$diffEditorView5, _this$diffEditorView6, _this$diffEditorView7;
1305
+ this.shouldAutoScrollDiff = true;
1306
+ this.lastScrollTopDiff = ((_this$diffEditorView5 = this.diffEditorView) === null || _this$diffEditorView5 === void 0 || (_this$diffEditorView7 = (_this$diffEditorView6 = _this$diffEditorView5.getModifiedEditor()).getScrollTop) === null || _this$diffEditorView7 === void 0 ? void 0 : _this$diffEditorView7.call(_this$diffEditorView6)) ?? this.lastScrollTopDiff;
1307
+ } catch {}
1308
+ }
1309
+ applyMinimalEditToModel(model, prev, next) {
1310
+ const maxChars = minimalEditMaxChars;
1311
+ const ratio = minimalEditMaxChangeRatio;
1312
+ const maxLen = Math.max(prev.length, next.length);
1313
+ const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
1314
+ if (prev.length + next.length > maxChars || changeRatio > ratio) {
1315
+ model.setValue(next);
1316
+ if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
1317
+ return;
1318
+ }
1319
+ const res = computeMinimalEdit(prev, next);
1320
+ if (!res) return;
1321
+ const { start, endPrevIncl, replaceText } = res;
1322
+ const rangeStart = model.getPositionAt(start);
1323
+ const rangeEnd = model.getPositionAt(endPrevIncl + 1);
1324
+ const range = new monaco_shim_exports.Range(rangeStart.lineNumber, rangeStart.column, rangeEnd.lineNumber, rangeEnd.column);
1325
+ model.applyEdits([{
1326
+ range,
1327
+ text: replaceText,
1328
+ forceMoveMarkers: true
1329
+ }]);
1330
+ if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
1331
+ }
1332
+ appendToModel(model, appendText) {
1333
+ if (!appendText) return;
1334
+ const lastLine = model.getLineCount();
1335
+ const lastColumn = model.getLineMaxColumn(lastLine);
1336
+ const range = new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
1337
+ model.applyEdits([{
1338
+ range,
1339
+ text: appendText,
1340
+ forceMoveMarkers: true
1341
+ }]);
1342
+ if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
1343
+ }
1344
+ };
1345
+
1346
+ //#endregion
1347
+ //#region src/core/EditorManager.ts
1348
+ var EditorManager = class {
1349
+ editorView = null;
1350
+ lastContainer = null;
1351
+ lastKnownCode = null;
1352
+ pendingUpdate = null;
1353
+ _hasScrollBar = false;
1354
+ shouldAutoScroll = true;
1355
+ scrollWatcher = null;
1356
+ scrollWatcherSuppressionTimer = null;
1357
+ lastScrollTop = 0;
1358
+ cachedScrollHeight = null;
1359
+ cachedLineHeight = null;
1360
+ cachedComputedHeight = null;
1361
+ cachedLineCount = null;
1362
+ lastKnownCodeDirty = false;
1363
+ debug = false;
1364
+ measureViewport() {
1365
+ var _this$editorView$getL, _this$editorView, _this$editorView$getS, _this$editorView2, _this$editorView$getS2, _this$editorView3;
1366
+ if (!this.editorView) return null;
1367
+ const li = ((_this$editorView$getL = (_this$editorView = this.editorView).getLayoutInfo) === null || _this$editorView$getL === void 0 ? void 0 : _this$editorView$getL.call(_this$editorView)) ?? null;
1368
+ const lineHeight = this.cachedLineHeight ?? this.editorView.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
1369
+ const scrollTop = ((_this$editorView$getS = (_this$editorView2 = this.editorView).getScrollTop) === null || _this$editorView$getS === void 0 ? void 0 : _this$editorView$getS.call(_this$editorView2)) ?? this.lastScrollTop ?? 0;
1370
+ const scrollHeight = ((_this$editorView$getS2 = (_this$editorView3 = this.editorView).getScrollHeight) === null || _this$editorView$getS2 === void 0 ? void 0 : _this$editorView$getS2.call(_this$editorView3)) ?? this.cachedScrollHeight ?? (li === null || li === void 0 ? void 0 : li.height) ?? 0;
1371
+ const computedHeight = this.cachedComputedHeight ?? this.computedHeight(this.editorView);
1372
+ this.cachedLineHeight = lineHeight;
1373
+ this.cachedScrollHeight = scrollHeight;
1374
+ this.cachedComputedHeight = computedHeight;
1375
+ this.lastScrollTop = scrollTop;
1376
+ return {
1377
+ li,
1378
+ lineHeight,
1379
+ scrollTop,
1380
+ scrollHeight,
1381
+ computedHeight
1382
+ };
1383
+ }
1384
+ appendBuffer = [];
1385
+ appendBufferScheduled = false;
1386
+ rafScheduler = createRafScheduler();
1387
+ editorHeightManager = null;
1388
+ revealDebounceId = null;
1389
+ revealDebounceMs = defaultRevealDebounceMs;
1390
+ revealIdleTimerId = null;
1391
+ revealTicket = 0;
1392
+ revealStrategyOption;
1393
+ revealBatchOnIdleMsOption;
1394
+ scrollWatcherSuppressionMs = 500;
1395
+ constructor(options, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, revealDebounceMsOption) {
1396
+ this.options = options;
1397
+ this.maxHeightValue = maxHeightValue;
1398
+ this.maxHeightCSS = maxHeightCSS;
1399
+ this.autoScrollOnUpdate = autoScrollOnUpdate;
1400
+ this.autoScrollInitial = autoScrollInitial;
1401
+ this.autoScrollThresholdPx = autoScrollThresholdPx;
1402
+ this.autoScrollThresholdLines = autoScrollThresholdLines;
1403
+ this.revealDebounceMsOption = revealDebounceMsOption;
1404
+ }
1405
+ initDebugFlag() {
1406
+ if (typeof window !== "undefined" && window.__STREAM_MONACO_DEBUG__ !== void 0) {
1407
+ this.debug = Boolean(window.__STREAM_MONACO_DEBUG__);
1408
+ return;
1409
+ }
1410
+ if (this.options && this.options.debug !== void 0) {
1411
+ this.debug = Boolean(this.options.debug);
1412
+ return;
1413
+ }
1414
+ this.debug = false;
1415
+ }
1416
+ dlog(...args) {
1417
+ if (!this.debug) return;
1418
+ log("EditorManager", ...args);
1419
+ }
1420
+ hasVerticalScrollbar() {
1421
+ if (!this.editorView) return false;
1422
+ if (this._hasScrollBar) return true;
1423
+ const m = this.measureViewport();
1424
+ if (!m) return false;
1425
+ return this._hasScrollBar = m.scrollHeight > m.computedHeight + padding / 2;
1426
+ }
1427
+ userIsNearBottom() {
1428
+ if (!this.editorView) return true;
1429
+ const m = this.measureViewport();
1430
+ if (!m || !m.li) return true;
1431
+ const lineThreshold = (this.autoScrollThresholdLines ?? 0) * m.lineHeight;
1432
+ const threshold = Math.max(lineThreshold || 0, this.autoScrollThresholdPx || 0);
1433
+ const distance = m.scrollHeight - (m.scrollTop + m.li.height);
1434
+ return distance <= threshold;
1435
+ }
1436
+ computedHeight(editorView) {
1437
+ var _editorView$getModel;
1438
+ const lineCount = this.cachedLineCount ?? ((_editorView$getModel = editorView.getModel()) === null || _editorView$getModel === void 0 ? void 0 : _editorView$getModel.getLineCount()) ?? 1;
1439
+ const lineHeight = editorView.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
1440
+ const height = Math.min(lineCount * lineHeight + padding, this.maxHeightValue);
1441
+ log("EditorManager.computedHeight", {
1442
+ lineCount,
1443
+ lineHeight,
1444
+ computed: height,
1445
+ maxHeightValue: this.maxHeightValue
1446
+ });
1447
+ return height;
1448
+ }
1449
+ maybeScrollToBottom(targetLine) {
1450
+ this.rafScheduler.schedule("maybe-scroll", () => {
1451
+ const hasVS = this.hasVerticalScrollbar();
1452
+ this.dlog("maybeScrollToBottom called", {
1453
+ autoScrollOnUpdate: this.autoScrollOnUpdate,
1454
+ shouldAutoScroll: this.shouldAutoScroll,
1455
+ hasVerticalScrollbar: hasVS,
1456
+ targetLine
1457
+ });
1458
+ if (!(this.autoScrollOnUpdate && this.shouldAutoScroll && this.hasVerticalScrollbar())) {
1459
+ this.dlog("maybeScrollToBottom skipped (auto-scroll conditions not met)");
1460
+ return;
1461
+ }
1462
+ const model = this.editorView.getModel();
1463
+ const line = targetLine ?? (model === null || model === void 0 ? void 0 : model.getLineCount()) ?? 1;
1464
+ const batchMs = this.revealBatchOnIdleMsOption ?? this.options.revealBatchOnIdleMs ?? defaultRevealBatchOnIdleMs;
1465
+ if (typeof batchMs === "number" && batchMs > 0) {
1466
+ if (this.revealIdleTimerId != null) clearTimeout(this.revealIdleTimerId);
1467
+ const ticket = ++this.revealTicket;
1468
+ this.dlog("scheduled idle reveal ticket=", ticket, "line=", line, "batchMs=", batchMs);
1469
+ this.revealIdleTimerId = setTimeout(() => {
1470
+ this.revealIdleTimerId = null;
1471
+ this.dlog("idle reveal timer firing, ticket=", ticket, "line=", line);
1472
+ this.performReveal(line, ticket);
1473
+ }, batchMs);
1474
+ return;
1475
+ }
1476
+ if (this.revealDebounceId != null) {
1477
+ clearTimeout(this.revealDebounceId);
1478
+ this.revealDebounceId = null;
1479
+ }
1480
+ const ms = typeof this.revealDebounceMs === "number" && this.revealDebounceMs > 0 ? this.revealDebounceMs : typeof this.revealDebounceMsOption === "number" && this.revealDebounceMsOption > 0 ? this.revealDebounceMsOption : this.revealDebounceMs;
1481
+ this.revealDebounceId = setTimeout(() => {
1482
+ this.revealDebounceId = null;
1483
+ const ticket = ++this.revealTicket;
1484
+ this.dlog("scheduled debounce reveal ticket=", ticket, "line=", line, "ms=", ms);
1485
+ this.performReveal(line, ticket);
1486
+ }, ms);
1487
+ });
1488
+ }
1489
+ performReveal(line, ticket) {
1490
+ this.rafScheduler.schedule("reveal", () => {
1491
+ var _editor;
1492
+ if (ticket !== this.revealTicket) {
1493
+ this.dlog("performReveal skipped, stale ticket", ticket, "current", this.revealTicket);
1494
+ return;
1495
+ }
1496
+ this.dlog("performReveal executing, ticket=", ticket, "line=", line);
1497
+ const strategy = this.revealStrategyOption ?? this.options.revealStrategy ?? "centerIfOutside";
1498
+ this.dlog("performReveal strategy=", strategy);
1499
+ const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
1500
+ const smooth = ScrollType && typeof ScrollType.Smooth !== "undefined" ? ScrollType.Smooth : void 0;
1501
+ try {
1502
+ if (strategy === "bottom") if (typeof smooth !== "undefined") this.editorView.revealLine(line, smooth);
1503
+ else this.editorView.revealLine(line);
1504
+ else if (strategy === "center") if (typeof smooth !== "undefined") this.editorView.revealLineInCenter(line, smooth);
1505
+ else this.editorView.revealLineInCenter(line);
1506
+ else if (typeof smooth !== "undefined") this.editorView.revealLineInCenterIfOutsideViewport(line, smooth);
1507
+ else this.editorView.revealLineInCenterIfOutsideViewport(line);
1508
+ } catch {
1509
+ try {
1510
+ this.editorView.revealLine(line);
1511
+ } catch {}
1512
+ }
1513
+ });
1514
+ }
1515
+ performImmediateReveal(line, ticket) {
1516
+ this.dlog("performImmediateReveal line=", line, "ticket=", ticket);
1517
+ try {
1518
+ var _editor2;
1519
+ if (!this.editorView) return;
1520
+ if (ticket !== this.revealTicket) {
1521
+ this.dlog("performImmediateReveal skipped, stale ticket", ticket, "current", this.revealTicket);
1522
+ return;
1523
+ }
1524
+ const ScrollType = monaco_shim_exports.ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
1525
+ const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
1526
+ if (typeof immediate !== "undefined") this.editorView.revealLine(line, immediate);
1527
+ else this.editorView.revealLine(line);
1528
+ } catch {}
1529
+ try {
1530
+ this.measureViewport();
1531
+ } catch {}
1532
+ }
1533
+ forceReveal(line) {
1534
+ try {
1535
+ var _editor3;
1536
+ if (!this.editorView) return;
1537
+ const ScrollType = monaco_shim_exports.ScrollType || ((_editor3 = monaco_shim_exports.editor) === null || _editor3 === void 0 ? void 0 : _editor3.ScrollType);
1538
+ const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
1539
+ if (typeof immediate !== "undefined") this.editorView.revealLine(line, immediate);
1540
+ else this.editorView.revealLine(line);
1541
+ } catch {}
1542
+ try {
1543
+ this.measureViewport();
1544
+ } catch {}
1545
+ try {
1546
+ var _this$editorView4, _this$editorView4$get;
1547
+ this.shouldAutoScroll = true;
1548
+ this.lastScrollTop = ((_this$editorView4 = this.editorView) === null || _this$editorView4 === void 0 || (_this$editorView4$get = _this$editorView4.getScrollTop) === null || _this$editorView4$get === void 0 ? void 0 : _this$editorView4$get.call(_this$editorView4)) ?? this.lastScrollTop;
1549
+ } catch {}
1550
+ }
1551
+ isOverflowAuto() {
1552
+ try {
1553
+ return !!this.lastContainer && this.lastContainer.style.overflow === "auto";
1554
+ } catch {
1555
+ return false;
1556
+ }
1557
+ }
1558
+ shouldPerformImmediateReveal() {
1559
+ return this.autoScrollOnUpdate && this.shouldAutoScroll && this.hasVerticalScrollbar() && this.isOverflowAuto();
1560
+ }
1561
+ async createEditor(container, code, language, currentTheme) {
1562
+ var _this$editorView$getS3, _this$editorView5, _this$editorView$getO, _this$editorView6, _this$editorView$getM, _this$editorView$onDi, _this$editorView7;
1563
+ this.cleanup();
1564
+ this.lastContainer = container;
1565
+ this.initDebugFlag();
1566
+ this.dlog("createEditor container, maxHeight", this.maxHeightValue);
1567
+ container.style.overflow = "hidden";
1568
+ container.style.maxHeight = this.maxHeightCSS;
1569
+ this.editorView = monaco_shim_exports.editor.create(container, {
1570
+ value: code,
1571
+ language: processedLanguage(language) || language,
1572
+ theme: currentTheme,
1573
+ scrollBeyondLastLine: false,
1574
+ minimap: { enabled: false },
1575
+ automaticLayout: true,
1576
+ readOnly: this.options.readOnly ?? true,
1577
+ contextmenu: false,
1578
+ scrollbar: {
1579
+ ...defaultScrollbar,
1580
+ ...this.options.scrollbar || {}
1581
+ },
1582
+ ...this.options
1583
+ });
1584
+ monaco_shim_exports.editor.setTheme(currentTheme);
1585
+ this.lastKnownCode = this.editorView.getValue();
1586
+ if (this.editorHeightManager) {
1587
+ try {
1588
+ this.editorHeightManager.dispose();
1589
+ } catch {}
1590
+ this.editorHeightManager = null;
1591
+ }
1592
+ if (this.revealDebounceId != null) {
1593
+ clearTimeout(this.revealDebounceId);
1594
+ this.revealDebounceId = null;
1595
+ }
1596
+ if (this.revealIdleTimerId != null) clearTimeout(this.revealIdleTimerId);
1597
+ this.revealIdleTimerId = null;
1598
+ const MIN_VISIBLE_HEIGHT = Math.min(120, this.maxHeightValue);
1599
+ container.style.minHeight = `${MIN_VISIBLE_HEIGHT}px`;
1600
+ this.editorHeightManager = createHeightManager(container, () => {
1601
+ const computed$2 = this.computedHeight(this.editorView);
1602
+ const clamped = Math.min(computed$2, this.maxHeightValue);
1603
+ return Math.max(clamped, MIN_VISIBLE_HEIGHT);
1604
+ });
1605
+ this.editorHeightManager.update();
1606
+ const initialComputed = this.computedHeight(this.editorView);
1607
+ if (initialComputed >= this.maxHeightValue - 1) {
1608
+ container.style.height = `${this.maxHeightValue}px`;
1609
+ container.style.overflow = "auto";
1610
+ this.dlog("applied immediate maxHeight on createEditor", this.maxHeightValue);
1611
+ }
1612
+ this.cachedScrollHeight = ((_this$editorView$getS3 = (_this$editorView5 = this.editorView).getScrollHeight) === null || _this$editorView$getS3 === void 0 ? void 0 : _this$editorView$getS3.call(_this$editorView5)) ?? null;
1613
+ this.cachedLineHeight = ((_this$editorView$getO = (_this$editorView6 = this.editorView).getOption) === null || _this$editorView$getO === void 0 ? void 0 : _this$editorView$getO.call(_this$editorView6, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? null;
1614
+ this.cachedComputedHeight = this.computedHeight(this.editorView);
1615
+ this.cachedLineCount = ((_this$editorView$getM = this.editorView.getModel()) === null || _this$editorView$getM === void 0 ? void 0 : _this$editorView$getM.getLineCount()) ?? null;
1616
+ (_this$editorView$onDi = (_this$editorView7 = this.editorView).onDidContentSizeChange) === null || _this$editorView$onDi === void 0 || _this$editorView$onDi.call(_this$editorView7, () => {
1617
+ this._hasScrollBar = false;
1618
+ this.rafScheduler.schedule("content-size-change", () => {
1619
+ try {
1620
+ var _this$editorView8, _this$editorHeightMan, _this$editorHeightMan2;
1621
+ this.dlog("content-size-change frame");
1622
+ const m = this.measureViewport();
1623
+ this.dlog("content-size-change measure", m);
1624
+ this.cachedLineCount = ((_this$editorView8 = this.editorView) === null || _this$editorView8 === void 0 || (_this$editorView8 = _this$editorView8.getModel()) === null || _this$editorView8 === void 0 ? void 0 : _this$editorView8.getLineCount()) ?? this.cachedLineCount;
1625
+ if ((_this$editorHeightMan = this.editorHeightManager) === null || _this$editorHeightMan === void 0 ? void 0 : _this$editorHeightMan.isSuppressed()) {
1626
+ this.dlog("content-size-change skipped height update (suppressed)");
1627
+ return;
1628
+ }
1629
+ this.dlog("content-size-change calling heightManager.update");
1630
+ (_this$editorHeightMan2 = this.editorHeightManager) === null || _this$editorHeightMan2 === void 0 || _this$editorHeightMan2.update();
1631
+ const computed$2 = this.computedHeight(this.editorView);
1632
+ if (this.lastContainer) {
1633
+ const prevOverflow = this.lastContainer.style.overflow;
1634
+ const newOverflow = computed$2 >= this.maxHeightValue - 1 ? "auto" : "hidden";
1635
+ if (prevOverflow !== newOverflow) {
1636
+ this.lastContainer.style.overflow = newOverflow;
1637
+ if (newOverflow === "auto" && this.shouldAutoScroll) this.maybeScrollToBottom();
1638
+ }
1639
+ }
1640
+ } catch (err) {
1641
+ error("EditorManager", "content-size-change error", err);
1642
+ }
1643
+ });
1644
+ });
1645
+ this.editorView.onDidChangeModelContent(() => {
1646
+ this.lastKnownCodeDirty = true;
1647
+ this.rafScheduler.schedule("sync-last-known", () => this.syncLastKnownCode());
1648
+ });
1649
+ this.shouldAutoScroll = !!this.autoScrollInitial;
1650
+ if (this.scrollWatcher) {
1651
+ this.scrollWatcher.dispose();
1652
+ this.scrollWatcher = null;
1653
+ }
1654
+ this.scrollWatcher = createScrollWatcherForEditor(this.editorView, {
1655
+ onPause: () => {
1656
+ this.shouldAutoScroll = false;
1657
+ },
1658
+ onMaybeResume: () => {
1659
+ this.rafScheduler.schedule("maybe-resume", () => {
1660
+ this.shouldAutoScroll = this.userIsNearBottom();
1661
+ });
1662
+ },
1663
+ getLast: () => this.lastScrollTop,
1664
+ setLast: (v) => {
1665
+ this.lastScrollTop = v;
1666
+ }
1667
+ });
1668
+ this.maybeScrollToBottom();
1669
+ return this.editorView;
1670
+ }
1671
+ syncLastKnownCode() {
1672
+ if (!this.editorView || !this.lastKnownCodeDirty) return;
1673
+ const model = this.editorView.getModel();
1674
+ if (model) {
1675
+ this.lastKnownCode = model.getValue();
1676
+ this.cachedLineCount = model.getLineCount() ?? this.cachedLineCount;
1677
+ }
1678
+ this.lastKnownCodeDirty = false;
1679
+ }
1680
+ suppressScrollWatcher(ms) {
1681
+ if (!this.scrollWatcher || typeof this.scrollWatcher.setSuppressed !== "function") return;
1682
+ this.dlog("suppressScrollWatcher", ms);
1683
+ if (this.scrollWatcherSuppressionTimer != null) {
1684
+ clearTimeout(this.scrollWatcherSuppressionTimer);
1685
+ this.scrollWatcherSuppressionTimer = null;
1686
+ }
1687
+ this.scrollWatcher.setSuppressed(true);
1688
+ this.scrollWatcherSuppressionTimer = setTimeout(() => {
1689
+ if (this.scrollWatcher && typeof this.scrollWatcher.setSuppressed === "function") {
1690
+ this.scrollWatcher.setSuppressed(false);
1691
+ this.dlog("suppressScrollWatcher cleared");
1692
+ }
1693
+ this.scrollWatcherSuppressionTimer = null;
1694
+ }, ms);
1695
+ }
1696
+ scheduleImmediateRevealAfterLayout(line) {
1697
+ const ticket = ++this.revealTicket;
1698
+ this.dlog("scheduleImmediateRevealAfterLayout ticket=", ticket, "line=", line);
1699
+ this.rafScheduler.schedule("immediate-reveal", async () => {
1700
+ try {
1701
+ const target = this.editorView && this.editorHeightManager ? Math.min(this.computedHeight(this.editorView), this.maxHeightValue) : -1;
1702
+ if (target !== -1 && this.editorHeightManager) await this.waitForHeightApplied(target, 500);
1703
+ else await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => r())));
1704
+ this.dlog("running delayed immediate reveal", "ticket=", ticket, "line=", line);
1705
+ this.performImmediateReveal(line, ticket);
1706
+ } catch (err) {
1707
+ error("EditorManager", "scheduleImmediateRevealAfterLayout error", err);
1708
+ }
1709
+ });
1710
+ }
1711
+ waitForHeightApplied(target, timeoutMs = 500) {
1712
+ return new Promise((resolve) => {
1713
+ const start = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
1714
+ const check = () => {
1715
+ try {
1716
+ var _this$editorHeightMan3, _this$editorHeightMan4;
1717
+ const last = ((_this$editorHeightMan3 = this.editorHeightManager) === null || _this$editorHeightMan3 === void 0 || (_this$editorHeightMan4 = _this$editorHeightMan3.getLastApplied) === null || _this$editorHeightMan4 === void 0 ? void 0 : _this$editorHeightMan4.call(_this$editorHeightMan3)) ?? -1;
1718
+ if (last !== -1 && Math.abs(last - target) <= 12) {
1719
+ this.dlog("waitForHeightApplied satisfied", last, "target=", target);
1720
+ resolve();
1721
+ return;
1722
+ }
1723
+ const now = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
1724
+ if (now - start > timeoutMs) {
1725
+ log("EditorManager", "waitForHeightApplied timeout", last, "target=", target);
1726
+ resolve();
1727
+ return;
1728
+ }
1729
+ } catch {}
1730
+ requestAnimationFrame(check);
1731
+ };
1732
+ check();
1733
+ });
1734
+ }
1735
+ updateCode(newCode, codeLanguage) {
1736
+ this.pendingUpdate = {
1737
+ code: newCode,
1738
+ lang: codeLanguage
1739
+ };
1740
+ this.rafScheduler.schedule("update", () => this.flushPendingUpdate());
1741
+ }
1742
+ flushPendingUpdate() {
1743
+ if (!this.pendingUpdate || !this.editorView) return;
1744
+ const model = this.editorView.getModel();
1745
+ if (!model) return;
1746
+ const { code: newCode, lang: codeLanguage } = this.pendingUpdate;
1747
+ this.pendingUpdate = null;
1748
+ const processedCodeLanguage = processedLanguage(codeLanguage);
1749
+ const languageId = model.getLanguageId();
1750
+ if (languageId !== processedCodeLanguage) {
1751
+ if (processedCodeLanguage) monaco_shim_exports.editor.setModelLanguage(model, processedCodeLanguage);
1752
+ const prevLineCount$1 = model.getLineCount();
1753
+ model.setValue(newCode);
1754
+ this.lastKnownCode = newCode;
1755
+ const newLineCount$1 = model.getLineCount();
1756
+ this.cachedLineCount = newLineCount$1;
1757
+ if (newLineCount$1 !== prevLineCount$1) {
1758
+ const shouldImmediate = this.shouldPerformImmediateReveal();
1759
+ if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
1760
+ const computed$2 = this.computedHeight(this.editorView);
1761
+ if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) this.lastContainer.style.height = `${this.maxHeightValue}px`;
1762
+ this.forceReveal(newLineCount$1);
1763
+ }
1764
+ return;
1765
+ }
1766
+ const buffered = this.appendBuffer.length > 0 ? this.appendBuffer.join("") : "";
1767
+ const prevCode = this.appendBuffer.length > 0 ? this.editorView.getValue() + buffered : this.lastKnownCode ?? this.editorView.getValue();
1768
+ if (prevCode === newCode) return;
1769
+ if (newCode.startsWith(prevCode) && prevCode.length < newCode.length) {
1770
+ const suffix = newCode.slice(prevCode.length);
1771
+ if (suffix) this.appendCode(suffix, codeLanguage);
1772
+ this.lastKnownCode = newCode;
1773
+ return;
1774
+ }
1775
+ const prevLineCount = model.getLineCount();
1776
+ this.applyMinimalEdit(prevCode, newCode);
1777
+ this.lastKnownCode = newCode;
1778
+ const newLineCount = model.getLineCount();
1779
+ this.cachedLineCount = newLineCount;
1780
+ if (newLineCount !== prevLineCount) {
1781
+ const shouldImmediate = this.shouldPerformImmediateReveal();
1782
+ if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
1783
+ if (shouldImmediate) this.scheduleImmediateRevealAfterLayout(newLineCount);
1784
+ else this.maybeScrollToBottom(newLineCount);
1785
+ }
1786
+ }
1787
+ appendCode(appendText, codeLanguage) {
1788
+ if (!this.editorView) return;
1789
+ const model = this.editorView.getModel();
1790
+ if (!model) return;
1791
+ const processedCodeLanguage = codeLanguage ? processedLanguage(codeLanguage) : model.getLanguageId();
1792
+ if (processedCodeLanguage && model.getLanguageId() !== processedCodeLanguage) monaco_shim_exports.editor.setModelLanguage(model, processedCodeLanguage);
1793
+ if (appendText) {
1794
+ this.appendBuffer.push(appendText);
1795
+ if (!this.appendBufferScheduled) {
1796
+ this.appendBufferScheduled = true;
1797
+ this.rafScheduler.schedule("append", () => this.flushAppendBuffer());
1798
+ }
1799
+ }
1800
+ }
1801
+ applyMinimalEdit(prev, next) {
1802
+ if (!this.editorView) return;
1803
+ const model = this.editorView.getModel();
1804
+ if (!model) return;
1805
+ const maxChars = minimalEditMaxChars;
1806
+ const ratio = minimalEditMaxChangeRatio;
1807
+ const maxLen = Math.max(prev.length, next.length);
1808
+ const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
1809
+ if (prev.length + next.length > maxChars || changeRatio > ratio) {
1810
+ const prevLineCount = model.getLineCount();
1811
+ model.setValue(next);
1812
+ this.lastKnownCode = next;
1813
+ const newLineCount = model.getLineCount();
1814
+ this.cachedLineCount = newLineCount;
1815
+ if (newLineCount !== prevLineCount) this.maybeScrollToBottom(newLineCount);
1816
+ return;
1817
+ }
1818
+ const res = computeMinimalEdit(prev, next);
1819
+ if (!res) return;
1820
+ const { start, endPrevIncl, replaceText } = res;
1821
+ const rangeStart = model.getPositionAt(start);
1822
+ const rangeEnd = model.getPositionAt(endPrevIncl + 1);
1823
+ const range = new monaco_shim_exports.Range(rangeStart.lineNumber, rangeStart.column, rangeEnd.lineNumber, rangeEnd.column);
1824
+ const isReadOnly = this.editorView.getOption(monaco_shim_exports.editor.EditorOption.readOnly);
1825
+ const edit = [{
1826
+ range,
1827
+ text: replaceText,
1828
+ forceMoveMarkers: true
1829
+ }];
1830
+ if (isReadOnly) model.applyEdits(edit);
1831
+ else this.editorView.executeEdits("minimal-replace", edit);
1832
+ }
1833
+ flushAppendBuffer() {
1834
+ if (!this.editorView) return;
1835
+ if (this.appendBuffer.length === 0) return;
1836
+ this.appendBufferScheduled = false;
1837
+ const model = this.editorView.getModel();
1838
+ if (!model) {
1839
+ this.appendBuffer.length = 0;
1840
+ return;
1841
+ }
1842
+ const text = this.appendBuffer.join("");
1843
+ this.appendBuffer.length = 0;
1844
+ const lastLine = model.getLineCount();
1845
+ const lastColumn = model.getLineMaxColumn(lastLine);
1846
+ const range = new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
1847
+ const isReadOnly = this.editorView.getOption(monaco_shim_exports.editor.EditorOption.readOnly);
1848
+ if (isReadOnly) model.applyEdits([{
1849
+ range,
1850
+ text,
1851
+ forceMoveMarkers: true
1852
+ }]);
1853
+ else this.editorView.executeEdits("append", [{
1854
+ range,
1855
+ text,
1856
+ forceMoveMarkers: true
1857
+ }]);
1858
+ try {
1859
+ this.lastKnownCode = model.getValue();
1860
+ } catch {}
1861
+ const newLineCount = model.getLineCount();
1862
+ if (lastLine !== newLineCount) {
1863
+ this.cachedLineCount = newLineCount;
1864
+ const shouldImmediate = this.shouldPerformImmediateReveal();
1865
+ if (shouldImmediate) this.suppressScrollWatcher(this.scrollWatcherSuppressionMs);
1866
+ const computed$2 = this.computedHeight(this.editorView);
1867
+ if (computed$2 >= this.maxHeightValue - 1 && this.lastContainer) this.lastContainer.style.height = `${this.maxHeightValue}px`;
1868
+ if (shouldImmediate) try {
1869
+ this.forceReveal(newLineCount);
1870
+ } catch {}
1871
+ else this.maybeScrollToBottom(newLineCount);
1872
+ }
1873
+ }
1874
+ setLanguage(language, languages$1) {
1875
+ if (languages$1.includes(language)) {
1876
+ if (this.editorView) {
1877
+ const model = this.editorView.getModel();
1878
+ if (model && model.getLanguageId() !== language) monaco_shim_exports.editor.setModelLanguage(model, language);
1879
+ }
1880
+ } else console.warn(`Language "${language}" is not registered. Available languages: ${languages$1.join(", ")}`);
1881
+ }
1882
+ getEditorView() {
1883
+ return this.editorView;
1884
+ }
1885
+ cleanup() {
1886
+ this.rafScheduler.cancel("update");
1887
+ this.rafScheduler.cancel("sync-last-known");
1888
+ this.rafScheduler.cancel("content-size-change");
1889
+ this.rafScheduler.cancel("maybe-scroll");
1890
+ this.rafScheduler.cancel("reveal");
1891
+ this.rafScheduler.cancel("immediate-reveal");
1892
+ this.rafScheduler.cancel("maybe-resume");
1893
+ this.pendingUpdate = null;
1894
+ this.rafScheduler.cancel("append");
1895
+ this.appendBufferScheduled = false;
1896
+ this.appendBuffer.length = 0;
1897
+ if (this.revealDebounceId != null) {
1898
+ clearTimeout(this.revealDebounceId);
1899
+ this.revealDebounceId = null;
1900
+ }
1901
+ if (this.revealIdleTimerId != null) {
1902
+ clearTimeout(this.revealIdleTimerId);
1903
+ this.revealIdleTimerId = null;
1904
+ }
1905
+ if (this.scrollWatcherSuppressionTimer != null) {
1906
+ clearTimeout(this.scrollWatcherSuppressionTimer);
1907
+ this.scrollWatcherSuppressionTimer = null;
1908
+ }
1909
+ if (this.editorView) {
1910
+ this.editorView.dispose();
1911
+ this.editorView = null;
1912
+ }
1913
+ this.lastKnownCode = null;
1914
+ if (this.lastContainer) {
1915
+ this.lastContainer.style.minHeight = "";
1916
+ this.lastContainer.innerHTML = "";
1917
+ this.lastContainer = null;
1918
+ }
1919
+ if (this.scrollWatcher) {
1920
+ this.scrollWatcher.dispose();
1921
+ this.scrollWatcher = null;
1922
+ }
1923
+ if (this.editorHeightManager) {
1924
+ this.editorHeightManager.dispose();
1925
+ this.editorHeightManager = null;
1926
+ }
1927
+ }
1928
+ safeClean() {
1929
+ this.rafScheduler.cancel("update");
1930
+ this.pendingUpdate = null;
1931
+ this.rafScheduler.cancel("sync-last-known");
1932
+ if (this.scrollWatcher) {
1933
+ try {
1934
+ this.scrollWatcher.dispose();
1935
+ } catch {}
1936
+ this.scrollWatcher = null;
1937
+ }
1938
+ if (this.revealDebounceId != null) {
1939
+ clearTimeout(this.revealDebounceId);
1940
+ this.revealDebounceId = null;
1941
+ }
1942
+ if (this.revealIdleTimerId != null) {
1943
+ clearTimeout(this.revealIdleTimerId);
1944
+ this.revealIdleTimerId = null;
1945
+ }
1946
+ if (this.scrollWatcherSuppressionTimer != null) {
1947
+ clearTimeout(this.scrollWatcherSuppressionTimer);
1948
+ this.scrollWatcherSuppressionTimer = null;
1949
+ }
1950
+ this.rafScheduler.cancel("maybe-scroll");
1951
+ this.rafScheduler.cancel("reveal");
1952
+ this.rafScheduler.cancel("immediate-reveal");
1953
+ this.rafScheduler.cancel("maybe-resume");
1954
+ this._hasScrollBar = false;
1955
+ this.shouldAutoScroll = !!this.autoScrollInitial;
1956
+ this.lastScrollTop = 0;
1957
+ if (this.editorHeightManager) {
1958
+ this.editorHeightManager.dispose();
1959
+ this.editorHeightManager = null;
1960
+ }
1961
+ }
1962
+ };
1963
+
1964
+ //#endregion
1965
+ //#region src/reactivity.ts
1966
+ function computed$1(getter) {
1967
+ const c = computed(() => getter());
1968
+ return Object.defineProperty({}, "value", {
1969
+ get() {
1970
+ return c();
1971
+ },
1972
+ set(_) {},
1973
+ enumerable: true,
1974
+ configurable: false
1975
+ });
1976
+ }
1977
+
1978
+ //#endregion
1979
+ //#region src/utils/arraysEqual.ts
1980
+ function arraysEqual(a, b) {
1981
+ if (a === b) return true;
1982
+ if (!a || !b) return false;
1983
+ if (a.length !== b.length) return false;
1984
+ for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
1985
+ return true;
1986
+ }
1987
+
1988
+ //#endregion
1989
+ //#region src/utils/registerMonacoThemes.ts
1990
+ let languagesRegistered = false;
1991
+ let currentLanguages = [];
1992
+ let themeRegisterPromise = null;
1993
+ let registrationQueue = Promise.resolve();
1994
+ function enqueueRegistration(task) {
1995
+ const next = registrationQueue.then(task, task);
1996
+ registrationQueue = next.then(() => void 0, () => void 0);
1997
+ return next;
1998
+ }
1999
+ function setThemeRegisterPromise(p) {
2000
+ return themeRegisterPromise = p;
2001
+ }
2002
+ const highlighterCache = /* @__PURE__ */ new Map();
2003
+ let monacoHighlighterPromise = null;
2004
+ let lastPatchedHighlighter = null;
2005
+ const monacoThemeByKey = /* @__PURE__ */ new Map();
2006
+ const monacoLanguageSet = /* @__PURE__ */ new Set();
2007
+ function themeKey(t) {
2008
+ return typeof t === "string" ? t : t.name ?? JSON.stringify(t);
2009
+ }
2010
+ async function ensureMonacoHighlighter(themes, languages$1) {
2011
+ for (const t of themes) monacoThemeByKey.set(themeKey(t), t);
2012
+ for (const l of languages$1) monacoLanguageSet.add(l);
2013
+ if (!monacoHighlighterPromise) {
2014
+ const initialThemes = Array.from(monacoThemeByKey.values());
2015
+ const initialLangs = Array.from(monacoLanguageSet.values());
2016
+ monacoHighlighterPromise = createHighlighter({
2017
+ themes: initialThemes,
2018
+ langs: initialLangs
2019
+ }).then((h$1) => h$1);
2020
+ }
2021
+ const h = await monacoHighlighterPromise;
2022
+ const wantsThemes = Array.from(monacoThemeByKey.values());
2023
+ const wantsLangs = Array.from(monacoLanguageSet.values());
2024
+ const canLoadTheme = typeof h.loadTheme === "function";
2025
+ const canLoadLanguage = typeof h.loadLanguage === "function";
2026
+ if (canLoadTheme || canLoadLanguage) {
2027
+ if (canLoadTheme) for (const t of themes) {
2028
+ const k = themeKey(t);
2029
+ if (!h.__streamMonacoLoadedThemes) h.__streamMonacoLoadedThemes = /* @__PURE__ */ new Set();
2030
+ const loaded = h.__streamMonacoLoadedThemes;
2031
+ if (loaded.has(k)) continue;
2032
+ await h.loadTheme(t);
2033
+ loaded.add(k);
2034
+ }
2035
+ if (canLoadLanguage) for (const l of languages$1) {
2036
+ if (!h.__streamMonacoLoadedLangs) h.__streamMonacoLoadedLangs = /* @__PURE__ */ new Set();
2037
+ const loaded = h.__streamMonacoLoadedLangs;
2038
+ if (loaded.has(l)) continue;
2039
+ await h.loadLanguage(l);
2040
+ loaded.add(l);
2041
+ }
2042
+ return h;
2043
+ }
2044
+ const p = createHighlighter({
2045
+ themes: wantsThemes,
2046
+ langs: wantsLangs
2047
+ }).then((hh) => hh);
2048
+ monacoHighlighterPromise = p;
2049
+ return p;
2050
+ }
2051
+ /**
2052
+ * Clear all cached shiki highlighters.
2053
+ *
2054
+ * Useful for long-running apps that dynamically create many theme combinations,
2055
+ * or in tests to ensure a clean state. Call this when you know the highlighters
2056
+ * are no longer needed (for example on app shutdown) to free memory.
2057
+ */
2058
+ function clearHighlighterCache() {
2059
+ highlighterCache.clear();
2060
+ }
2061
+ function serializeThemes(themes) {
2062
+ return JSON.stringify(themes.map((t) => typeof t === "string" ? t : t.name ?? JSON.stringify(t)).sort());
2063
+ }
2064
+ async function getOrCreateHighlighter(themes, languages$1) {
2065
+ const key = serializeThemes(themes);
2066
+ const requestedSet = new Set(languages$1);
2067
+ let existing = highlighterCache.get(key);
2068
+ if (existing) {
2069
+ let allIncluded = true;
2070
+ for (const l of requestedSet) if (!existing.languages.has(l)) {
2071
+ allIncluded = false;
2072
+ break;
2073
+ }
2074
+ if (allIncluded) return existing.promise;
2075
+ const prev = existing;
2076
+ const current = highlighterCache.get(key);
2077
+ if (current && current !== prev) {
2078
+ let allIncludedCurrent = true;
2079
+ for (const l of requestedSet) if (!current.languages.has(l)) {
2080
+ allIncludedCurrent = false;
2081
+ break;
2082
+ }
2083
+ if (allIncludedCurrent) return current.promise;
2084
+ existing = current;
2085
+ }
2086
+ const union = new Set([...existing.languages, ...requestedSet]);
2087
+ const langsArray = Array.from(union);
2088
+ const p$1 = createHighlighter({
2089
+ themes,
2090
+ langs: langsArray
2091
+ });
2092
+ const newEntry = {
2093
+ promise: p$1,
2094
+ languages: union
2095
+ };
2096
+ highlighterCache.set(key, newEntry);
2097
+ p$1.catch(() => {
2098
+ if (highlighterCache.get(key) === newEntry && prev) highlighterCache.set(key, prev);
2099
+ });
2100
+ return p$1;
2101
+ }
2102
+ const p = createHighlighter({
2103
+ themes,
2104
+ langs: Array.from(requestedSet)
2105
+ });
2106
+ const entry = {
2107
+ promise: p,
2108
+ languages: requestedSet
2109
+ };
2110
+ highlighterCache.set(key, entry);
2111
+ p.catch(() => {
2112
+ if (highlighterCache.get(key) === entry) highlighterCache.delete(key);
2113
+ });
2114
+ return p;
2115
+ }
2116
+ /**
2117
+ * Update the theme used by the shiki highlighter for a given themes+languages
2118
+ * combination. Useful when Monaco themes are already registered (so switching
2119
+ * Monaco only requires `monaco.editor.setTheme`) but you also want shiki's
2120
+ * standalone renderer to use the new theme without recreating everything.
2121
+ */
2122
+ async function registerMonacoThemes(themes, languages$1) {
2123
+ return enqueueRegistration(async () => {
2124
+ registerMonacoLanguages(languages$1);
2125
+ const p = (async () => {
2126
+ const highlighter = await ensureMonacoHighlighter(themes, languages$1);
2127
+ if (lastPatchedHighlighter !== highlighter) {
2128
+ shikiToMonaco(highlighter, monaco_shim_exports);
2129
+ lastPatchedHighlighter = highlighter;
2130
+ }
2131
+ currentLanguages = languages$1.slice();
2132
+ return highlighter;
2133
+ })();
2134
+ setThemeRegisterPromise(p);
2135
+ try {
2136
+ const res = await p;
2137
+ return res;
2138
+ } catch (e) {
2139
+ setThemeRegisterPromise(null);
2140
+ throw e;
2141
+ }
2142
+ });
2143
+ }
2144
+ function registerMonacoLanguages(languages$1) {
2145
+ if (languagesRegistered && arraysEqual(languages$1, currentLanguages)) return;
2146
+ const existing = new Set(monaco_shim_exports.languages.getLanguages().map((l) => l.id));
2147
+ for (const lang of languages$1) if (!existing.has(lang)) try {
2148
+ monaco_shim_exports.languages.register({ id: lang });
2149
+ } catch {}
2150
+ languagesRegistered = true;
2151
+ currentLanguages = languages$1;
2152
+ }
2153
+
2154
+ //#endregion
2155
+ //#region src/type.ts
2156
+ let RevealStrategy = /* @__PURE__ */ function(RevealStrategy$1) {
2157
+ RevealStrategy$1["Bottom"] = "bottom";
2158
+ RevealStrategy$1["CenterIfOutside"] = "centerIfOutside";
2159
+ RevealStrategy$1["Center"] = "center";
2160
+ return RevealStrategy$1;
2161
+ }({});
2162
+
2163
+ //#endregion
2164
+ //#region src/index.base.ts
2165
+ let globalRequestedThemeName = null;
2166
+ let globalThemeRequestSeq = 0;
2167
+ let globalAppliedThemeName = null;
2168
+ /**
2169
+ * useMonaco 组合式函数
2170
+ *
2171
+ * 提供 Monaco 编辑器的创建、销毁、内容/主题/语言更新等能力。
2172
+ * 支持主题自动切换、语言高亮、代码更新等功能。
2173
+ *
2174
+ * @param {MonacoOptions} [monacoOptions] - 编辑器初始化配置,支持 Monaco 原生配置及扩展项
2175
+ * @param {number | string} [monacoOptions.MAX_HEIGHT] - 编辑器最大高度,可以是数字(像素)或 CSS 字符串(如 '100%', 'calc(100vh - 100px)')
2176
+ * @param {boolean} [monacoOptions.readOnly] - 是否为只读模式
2177
+ * @param {MonacoTheme[]} [monacoOptions.themes] - 主题数组,至少包含两个主题:[暗色主题, 亮色主题]
2178
+ * @param {MonacoLanguage[]} [monacoOptions.languages] - 支持的编程语言数组
2179
+ * @param {string} [monacoOptions.theme] - 初始主题名称
2180
+ * @param {boolean} [monacoOptions.isCleanOnBeforeCreate] - 是否在创建前清理之前注册的资源, 默认为 true
2181
+ * @param {(monaco: typeof import('monaco-editor')) => monaco.IDisposable[]} [monacoOptions.onBeforeCreate] - 编辑器创建前的钩子函数
2182
+ *
2183
+ * @returns {{
2184
+ * createEditor: (container: HTMLElement, code: string, language: string) => Promise<monaco.editor.IStandaloneCodeEditor>,
2185
+ * createDiffEditor: (
2186
+ * container: HTMLElement,
2187
+ * originalCode: string,
2188
+ * modifiedCode: string,
2189
+ * language: string,
2190
+ * ) => Promise<monaco.editor.IStandaloneDiffEditor>,
2191
+ * cleanupEditor: () => void,
2192
+ * updateCode: (newCode: string, codeLanguage: string) => void,
2193
+ * appendCode: (appendText: string, codeLanguage?: string) => void,
2194
+ * updateDiff: (
2195
+ * originalCode: string,
2196
+ * modifiedCode: string,
2197
+ * codeLanguage?: string,
2198
+ * ) => void,
2199
+ * updateOriginal: (newCode: string, codeLanguage?: string) => void,
2200
+ * updateModified: (newCode: string, codeLanguage?: string) => void,
2201
+ * appendOriginal: (appendText: string, codeLanguage?: string) => void,
2202
+ * appendModified: (appendText: string, codeLanguage?: string) => void,
2203
+ * setTheme: (theme: MonacoTheme) => Promise<void>,
2204
+ * setLanguage: (language: MonacoLanguage) => void,
2205
+ * getCurrentTheme: () => string,
2206
+ * getEditor: () => typeof monaco.editor,
2207
+ * getEditorView: () => monaco.editor.IStandaloneCodeEditor | null,
2208
+ * getDiffEditorView: () => monaco.editor.IStandaloneDiffEditor | null,
2209
+ * getDiffModels: () => { original: monaco.editor.ITextModel | null, modified: monaco.editor.ITextModel | null },
2210
+ * getCode: () => string | { original: string, modified: string } | null,
2211
+ * }} 返回对象包含以下方法和属性:
2212
+ *
2213
+ * @property {Function} createEditor - 创建并挂载 Monaco 编辑器到指定容器
2214
+ * @property {Function} cleanupEditor - 销毁编辑器并清理容器
2215
+ * @property {Function} updateCode - 更新编辑器内容和语言,必要时滚动到底部
2216
+ * @property {Function} appendCode - 在编辑器末尾追加文本,必要时滚动到底部
2217
+ * @property {Function} createDiffEditor - 创建并挂载 Diff 编辑器
2218
+ * @property {Function} updateDiff - 更新 Diff 编辑器的 original/modified 内容(RAF 合并、增量更新)
2219
+ * @property {Function} updateOriginal - 仅更新 Diff 的 original 内容(增量更新)
2220
+ * @property {Function} updateModified - 仅更新 Diff 的 modified 内容(增量更新)
2221
+ * @property {Function} appendOriginal - 在 Diff 的 original 末尾追加(显式流式场景)
2222
+ * @property {Function} appendModified - 在 Diff 的 modified 末尾追加(显式流式场景)
2223
+ * @property {Function} setTheme - 切换编辑器主题,返回 Promise,在主题应用完成时 resolve
2224
+ * @property {Function} setLanguage - 切换编辑器语言
2225
+ * @property {Function} getCurrentTheme - 获取当前主题名称
2226
+ * @property {Function} getEditor - 获取 Monaco 的静态 editor 对象(用于静态方法调用)
2227
+ * @property {Function} getEditorView - 获取当前编辑器实例
2228
+ * @property {Function} getDiffEditorView - 获取当前 Diff 编辑器实例
2229
+ * @property {Function} getDiffModels - 获取 Diff 的 original/modified 两个模型
2230
+ * @property {Function} getCode - 获取当前编辑器或 Diff 编辑器中的代码内容
2231
+ *
2232
+ * @throws {Error} 当主题数组不是数组或长度小于2时抛出错误
2233
+ *
2234
+ * @example
2235
+ * ```typescript
2236
+ * import { useMonaco } from 'stream-monaco'
2237
+ *
2238
+ * const { createEditor, updateCode, setTheme } = useMonaco({
2239
+ * themes: ['vitesse-dark', 'vitesse-light'],
2240
+ * languages: ['javascript', 'typescript'],
2241
+ * readOnly: false
2242
+ * })
2243
+ *
2244
+ * // 创建编辑器
2245
+ * const editor = await createEditor(containerRef.value, 'console.log("hello")', 'javascript')
2246
+ *
2247
+ * // 更新代码
2248
+ * updateCode('console.log("world")', 'javascript')
2249
+ *
2250
+ * // 切换主题
2251
+ * setTheme('vitesse-light')
2252
+ * ```
2253
+ */
2254
+ function useMonaco(monacoOptions = {}) {
2255
+ var _monacoOptions$themes;
2256
+ const disposals = [];
2257
+ if (monacoOptions.isCleanOnBeforeCreate ?? true) disposals.forEach((d) => d.dispose());
2258
+ if (monacoOptions.isCleanOnBeforeCreate ?? true) disposals.length = 0;
2259
+ let editorView = null;
2260
+ let editorMgr = null;
2261
+ let diffEditorView = null;
2262
+ let diffMgr = null;
2263
+ let originalModel = null;
2264
+ let modifiedModel = null;
2265
+ let _hasScrollBar = false;
2266
+ const themes = monacoOptions.themes && ((_monacoOptions$themes = monacoOptions.themes) === null || _monacoOptions$themes === void 0 ? void 0 : _monacoOptions$themes.length) ? monacoOptions.themes : defaultThemes;
2267
+ if (!Array.isArray(themes) || themes.length < 2) throw new Error("Monaco themes must be an array with at least two themes: [darkTheme, lightTheme]");
2268
+ const languages$1 = monacoOptions.languages ?? defaultLanguages;
2269
+ const MAX_HEIGHT = monacoOptions.MAX_HEIGHT ?? 500;
2270
+ const autoScrollOnUpdate = monacoOptions.autoScrollOnUpdate ?? true;
2271
+ const autoScrollInitial = monacoOptions.autoScrollInitial ?? true;
2272
+ const autoScrollThresholdPx = monacoOptions.autoScrollThresholdPx ?? 32;
2273
+ const autoScrollThresholdLines = monacoOptions.autoScrollThresholdLines ?? 2;
2274
+ const diffAutoScroll = monacoOptions.diffAutoScroll ?? true;
2275
+ const getMaxHeightValue = () => {
2276
+ if (typeof MAX_HEIGHT === "number") return MAX_HEIGHT;
2277
+ const match = MAX_HEIGHT.match(/^(\d+(?:\.\d+)?)/);
2278
+ return match ? Number.parseFloat(match[1]) : 500;
2279
+ };
2280
+ const getMaxHeightCSS = () => {
2281
+ if (typeof MAX_HEIGHT === "number") return `${MAX_HEIGHT}px`;
2282
+ return MAX_HEIGHT;
2283
+ };
2284
+ const maxHeightValue = getMaxHeightValue();
2285
+ const maxHeightCSS = getMaxHeightCSS();
2286
+ let lastContainer = null;
2287
+ let lastKnownCode = null;
2288
+ const minimalEditMaxCharsLocal = monacoOptions.minimalEditMaxChars ?? minimalEditMaxChars;
2289
+ const minimalEditMaxChangeRatioLocal = monacoOptions.minimalEditMaxChangeRatio ?? minimalEditMaxChangeRatio;
2290
+ let updateThrottleMs = monacoOptions.updateThrottleMs ?? 50;
2291
+ let lastFlushTime = 0;
2292
+ let updateThrottleTimer = null;
2293
+ let pendingUpdate = null;
2294
+ let shouldAutoScroll = true;
2295
+ const cachedComputedHeight = null;
2296
+ const appendBuffer = [];
2297
+ let appendBufferScheduled = false;
2298
+ const currentTheme = computed$1(() => monacoOptions.theme ?? (typeof themes[0] === "string" ? themes[0] : themes[0].name));
2299
+ let requestedThemeName = monacoOptions.theme ?? globalRequestedThemeName ?? currentTheme.value;
2300
+ let themeWatcher = null;
2301
+ const rafScheduler = createRafScheduler();
2302
+ async function tryLoadAndSetShikiTheme(highlighter, themeName) {
2303
+ if (!highlighter || typeof highlighter.setTheme !== "function") return;
2304
+ try {
2305
+ await highlighter.setTheme(themeName);
2306
+ } catch (err) {
2307
+ const message = (err === null || err === void 0 ? void 0 : err.message) ? String(err.message) : String(err);
2308
+ const lower = message.toLowerCase();
2309
+ const looksLikeMissingThemeError = lower.includes("theme") && lower.includes("not found");
2310
+ if (typeof highlighter.loadTheme === "function" && looksLikeMissingThemeError) {
2311
+ await highlighter.loadTheme(themeName);
2312
+ await highlighter.setTheme(themeName);
2313
+ return;
2314
+ }
2315
+ throw err;
2316
+ }
2317
+ }
2318
+ async function setThemeInternal(theme, force = false) {
2319
+ const themeName = typeof theme === "string" ? theme : theme.name;
2320
+ globalThemeRequestSeq += 1;
2321
+ const token = globalThemeRequestSeq;
2322
+ requestedThemeName = themeName;
2323
+ globalRequestedThemeName = themeName;
2324
+ if (!force && themeName === globalAppliedThemeName) return;
2325
+ if (token !== globalThemeRequestSeq) return;
2326
+ await registerMonacoThemes(themes, languages$1).catch(() => void 0);
2327
+ if (token !== globalThemeRequestSeq) return;
2328
+ const availableNames = themes.map((t) => typeof t === "string" ? t : t.name);
2329
+ if (!availableNames.includes(themeName)) try {
2330
+ const extended = availableNames.concat(themeName);
2331
+ const maybeHighlighter = await registerMonacoThemes(extended, languages$1);
2332
+ await tryLoadAndSetShikiTheme(maybeHighlighter, themeName).catch(() => void 0);
2333
+ } catch {
2334
+ console.warn(`Theme "${themeName}" is not registered and automatic registration failed. Available themes: ${availableNames.join(", ")}`);
2335
+ return;
2336
+ }
2337
+ if (token !== globalThemeRequestSeq) return;
2338
+ try {
2339
+ monaco_shim_exports.editor.setTheme(themeName);
2340
+ globalAppliedThemeName = themeName;
2341
+ } catch {
2342
+ try {
2343
+ const maybeHighlighter = await registerMonacoThemes(themes, languages$1);
2344
+ if (token !== globalThemeRequestSeq) return;
2345
+ monaco_shim_exports.editor.setTheme(themeName);
2346
+ globalAppliedThemeName = themeName;
2347
+ await tryLoadAndSetShikiTheme(maybeHighlighter, themeName).catch(() => void 0);
2348
+ } catch (err2) {
2349
+ console.warn(`Failed to set theme "${themeName}":`, err2);
2350
+ return;
2351
+ }
2352
+ }
2353
+ if (token !== globalThemeRequestSeq) return;
2354
+ try {
2355
+ if (typeof monacoOptions.onThemeChange === "function") await monacoOptions.onThemeChange(themeName);
2356
+ } catch (err) {
2357
+ console.warn("onThemeChange callback threw an error:", err);
2358
+ }
2359
+ }
2360
+ async function ensureThemeRegistered(themeName) {
2361
+ const availableNames = themes.map((t) => typeof t === "string" ? t : t.name);
2362
+ const list = availableNames.includes(themeName) ? themes : themes.concat(themeName);
2363
+ await registerMonacoThemes(list, languages$1);
2364
+ }
2365
+ function hasVerticalScrollbar() {
2366
+ if (!editorView) return false;
2367
+ if (_hasScrollBar) return true;
2368
+ const ch = cachedComputedHeight ?? computedHeight(editorView);
2369
+ return _hasScrollBar = editorView.getScrollHeight() > ch + padding / 2;
2370
+ }
2371
+ let revealDebounceId = null;
2372
+ const revealDebounceMs = 75;
2373
+ function maybeScrollToBottom(targetLine) {
2374
+ if (autoScrollOnUpdate && shouldAutoScroll && hasVerticalScrollbar()) {
2375
+ const model = editorView.getModel();
2376
+ const line = targetLine ?? (model === null || model === void 0 ? void 0 : model.getLineCount()) ?? 1;
2377
+ if (revealDebounceId != null) {
2378
+ clearTimeout(revealDebounceId);
2379
+ revealDebounceId = null;
2380
+ }
2381
+ revealDebounceId = setTimeout(() => {
2382
+ revealDebounceId = null;
2383
+ rafScheduler.schedule("reveal", () => {
2384
+ try {
2385
+ var _editor;
2386
+ const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
2387
+ if (ScrollType && typeof ScrollType.Smooth !== "undefined") editorView.revealLineInCenterIfOutsideViewport(line, ScrollType.Smooth);
2388
+ else editorView.revealLineInCenterIfOutsideViewport(line);
2389
+ } catch {}
2390
+ });
2391
+ }, revealDebounceMs);
2392
+ }
2393
+ }
2394
+ async function createEditor(container, code, language) {
2395
+ cleanupEditor();
2396
+ lastContainer = container;
2397
+ if (monacoOptions.isCleanOnBeforeCreate ?? true) {
2398
+ disposals.forEach((d) => d.dispose());
2399
+ disposals.length = 0;
2400
+ }
2401
+ if (monacoOptions.onBeforeCreate) {
2402
+ const ds = monacoOptions.onBeforeCreate(monaco_shim_exports);
2403
+ if (ds) disposals.push(...ds);
2404
+ }
2405
+ const initialThemeName = requestedThemeName ?? monacoOptions.theme ?? globalRequestedThemeName ?? currentTheme.value;
2406
+ await ensureThemeRegistered(initialThemeName);
2407
+ editorMgr = new EditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, monacoOptions.revealDebounceMs);
2408
+ editorView = await editorMgr.createEditor(container, code, language, initialThemeName);
2409
+ if (pendingUpdate && editorMgr) {
2410
+ const { code: queuedCode, lang: queuedLang } = pendingUpdate;
2411
+ pendingUpdate = null;
2412
+ editorMgr.updateCode(queuedCode, queuedLang);
2413
+ }
2414
+ if (typeof monacoOptions.onThemeChange === "function") monacoOptions.onThemeChange(initialThemeName);
2415
+ if (editorView) lastKnownCode = editorView.getValue();
2416
+ return editorView;
2417
+ }
2418
+ function computedHeight(editorView$1) {
2419
+ var _getModel;
2420
+ const lineCount = ((_getModel = editorView$1.getModel()) === null || _getModel === void 0 ? void 0 : _getModel.getLineCount()) ?? 1;
2421
+ const lineHeight = editorView$1.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
2422
+ const height = Math.min(lineCount * lineHeight + padding, maxHeightValue);
2423
+ return height;
2424
+ }
2425
+ async function createDiffEditor(container, originalCode, modifiedCode, language) {
2426
+ cleanupEditor();
2427
+ lastContainer = container;
2428
+ if (monacoOptions.isCleanOnBeforeCreate ?? true) {
2429
+ disposals.forEach((d) => d.dispose());
2430
+ disposals.length = 0;
2431
+ }
2432
+ if (monacoOptions.onBeforeCreate) {
2433
+ const ds = monacoOptions.onBeforeCreate(monaco_shim_exports);
2434
+ if (ds) disposals.push(...ds);
2435
+ }
2436
+ const initialThemeName = requestedThemeName ?? monacoOptions.theme ?? globalRequestedThemeName ?? currentTheme.value;
2437
+ await ensureThemeRegistered(initialThemeName);
2438
+ try {
2439
+ monaco_shim_exports.editor.setTheme(initialThemeName);
2440
+ } catch {}
2441
+ diffMgr = new DiffEditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, monacoOptions.revealDebounceMs, monacoOptions.diffUpdateThrottleMs);
2442
+ diffEditorView = await diffMgr.createDiffEditor(container, originalCode, modifiedCode, language, initialThemeName);
2443
+ if (typeof monacoOptions.onThemeChange === "function") monacoOptions.onThemeChange(initialThemeName);
2444
+ const models = diffMgr.getDiffModels();
2445
+ originalModel = models.original;
2446
+ modifiedModel = models.modified;
2447
+ return diffEditorView;
2448
+ }
2449
+ function cleanupEditor() {
2450
+ if (editorMgr) {
2451
+ editorMgr.cleanup();
2452
+ editorMgr = null;
2453
+ }
2454
+ if (diffMgr) {
2455
+ diffMgr.cleanup();
2456
+ diffMgr = null;
2457
+ }
2458
+ rafScheduler.cancel("update");
2459
+ pendingUpdate = null;
2460
+ rafScheduler.cancel("append");
2461
+ appendBufferScheduled = false;
2462
+ appendBuffer.length = 0;
2463
+ if (!editorMgr && editorView) {
2464
+ editorView.dispose();
2465
+ editorView = null;
2466
+ }
2467
+ lastKnownCode = null;
2468
+ if (lastContainer) {
2469
+ lastContainer.innerHTML = "";
2470
+ lastContainer = null;
2471
+ }
2472
+ if (themeWatcher) {
2473
+ themeWatcher();
2474
+ themeWatcher = null;
2475
+ }
2476
+ if (updateThrottleTimer != null) {
2477
+ clearTimeout(updateThrottleTimer);
2478
+ updateThrottleTimer = null;
2479
+ }
2480
+ diffEditorView = null;
2481
+ originalModel = null;
2482
+ modifiedModel = null;
2483
+ }
2484
+ function appendCode(appendText, codeLanguage) {
2485
+ if (editorMgr) editorMgr.appendCode(appendText, codeLanguage);
2486
+ else {
2487
+ if (!editorView) return;
2488
+ const model = editorView.getModel();
2489
+ if (!model) return;
2490
+ const processedCodeLanguage = codeLanguage ? processedLanguage(codeLanguage) : model.getLanguageId();
2491
+ if (processedCodeLanguage && model.getLanguageId() !== processedCodeLanguage) monaco_shim_exports.editor.setModelLanguage(model, processedCodeLanguage);
2492
+ if (appendText && lastKnownCode != null) lastKnownCode = lastKnownCode + appendText;
2493
+ if (appendText) {
2494
+ appendBuffer.push(appendText);
2495
+ if (!appendBufferScheduled) {
2496
+ appendBufferScheduled = true;
2497
+ rafScheduler.schedule("append", flushAppendBuffer);
2498
+ }
2499
+ }
2500
+ }
2501
+ }
2502
+ function applyMinimalEdit(prev, next) {
2503
+ if (!editorView) return;
2504
+ const model = editorView.getModel();
2505
+ if (!model) return;
2506
+ try {
2507
+ const maxChars = minimalEditMaxCharsLocal;
2508
+ const ratio = minimalEditMaxChangeRatioLocal;
2509
+ const maxLen = Math.max(prev.length, next.length);
2510
+ const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
2511
+ if (prev.length + next.length > maxChars || changeRatio > ratio) {
2512
+ const prevLineCount = model.getLineCount();
2513
+ model.setValue(next);
2514
+ lastKnownCode = next;
2515
+ const newLineCount = model.getLineCount();
2516
+ if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
2517
+ return;
2518
+ }
2519
+ } catch {}
2520
+ const res = computeMinimalEdit(prev, next);
2521
+ if (!res) return;
2522
+ const { start, endPrevIncl, replaceText } = res;
2523
+ const rangeStart = model.getPositionAt(start);
2524
+ const rangeEnd = model.getPositionAt(endPrevIncl + 1);
2525
+ const range = new monaco_shim_exports.Range(rangeStart.lineNumber, rangeStart.column, rangeEnd.lineNumber, rangeEnd.column);
2526
+ const isReadOnly = editorView.getOption(monaco_shim_exports.editor.EditorOption.readOnly);
2527
+ const edit = [{
2528
+ range,
2529
+ text: replaceText,
2530
+ forceMoveMarkers: true
2531
+ }];
2532
+ if (isReadOnly) model.applyEdits(edit);
2533
+ else editorView.executeEdits("minimal-replace", edit);
2534
+ }
2535
+ function flushPendingUpdate() {
2536
+ if (!pendingUpdate) return;
2537
+ lastFlushTime = Date.now();
2538
+ if (!editorView) return;
2539
+ const model = editorView.getModel();
2540
+ if (!model) return;
2541
+ const { code: newCode, lang: codeLanguage } = pendingUpdate;
2542
+ pendingUpdate = null;
2543
+ const processedCodeLanguage = processedLanguage(codeLanguage);
2544
+ let prevCode = null;
2545
+ if (appendBuffer.length > 0) try {
2546
+ prevCode = model.getValue();
2547
+ lastKnownCode = prevCode;
2548
+ } catch {
2549
+ prevCode = "";
2550
+ }
2551
+ else {
2552
+ prevCode = lastKnownCode;
2553
+ if (prevCode == null) try {
2554
+ prevCode = model.getValue();
2555
+ lastKnownCode = prevCode;
2556
+ } catch {
2557
+ prevCode = "";
2558
+ }
2559
+ }
2560
+ if (prevCode === newCode) return;
2561
+ const languageId = model.getLanguageId();
2562
+ if (languageId !== processedCodeLanguage) {
2563
+ if (processedCodeLanguage) monaco_shim_exports.editor.setModelLanguage(model, processedCodeLanguage);
2564
+ const prevLineCount = model.getLineCount();
2565
+ model.setValue(newCode);
2566
+ lastKnownCode = newCode;
2567
+ const newLineCount = model.getLineCount();
2568
+ if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
2569
+ return;
2570
+ }
2571
+ if (newCode.startsWith(prevCode) && prevCode.length < newCode.length) {
2572
+ const suffix = newCode.slice(prevCode.length);
2573
+ if (suffix) appendCode(suffix, codeLanguage);
2574
+ lastKnownCode = newCode;
2575
+ return;
2576
+ }
2577
+ try {
2578
+ const maxChars = minimalEditMaxCharsLocal;
2579
+ const ratio = minimalEditMaxChangeRatioLocal;
2580
+ const maxLen = Math.max(prevCode.length, newCode.length);
2581
+ const changeRatio = maxLen > 0 ? Math.abs(newCode.length - prevCode.length) / maxLen : 0;
2582
+ if (prevCode.length + newCode.length > maxChars || changeRatio > ratio) {
2583
+ const prevLineCount = model.getLineCount();
2584
+ model.setValue(newCode);
2585
+ lastKnownCode = newCode;
2586
+ const newLineCount = model.getLineCount();
2587
+ if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
2588
+ return;
2589
+ }
2590
+ } catch {}
2591
+ try {
2592
+ applyMinimalEdit(prevCode, newCode);
2593
+ lastKnownCode = newCode;
2594
+ const newLineCount = model.getLineCount();
2595
+ const prevLineCount = (prevCode ? prevCode.split("\n").length : 0) || model.getLineCount();
2596
+ if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
2597
+ } catch {
2598
+ try {
2599
+ const prevLineCount = model.getLineCount();
2600
+ model.setValue(newCode);
2601
+ lastKnownCode = newCode;
2602
+ const newLineCount = model.getLineCount();
2603
+ if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
2604
+ } catch {}
2605
+ }
2606
+ }
2607
+ function flushAppendBuffer() {
2608
+ if (!editorView) return;
2609
+ if (appendBuffer.length === 0) return;
2610
+ appendBufferScheduled = false;
2611
+ const model = editorView.getModel();
2612
+ if (!model) {
2613
+ appendBuffer.length = 0;
2614
+ return;
2615
+ }
2616
+ const text = appendBuffer.join("");
2617
+ appendBuffer.length = 0;
2618
+ try {
2619
+ const lastLine = model.getLineCount();
2620
+ const lastColumn = model.getLineMaxColumn(lastLine);
2621
+ const range = new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
2622
+ const isReadOnly = editorView.getOption(monaco_shim_exports.editor.EditorOption.readOnly);
2623
+ if (isReadOnly) model.applyEdits([{
2624
+ range,
2625
+ text,
2626
+ forceMoveMarkers: true
2627
+ }]);
2628
+ else editorView.executeEdits("append", [{
2629
+ range,
2630
+ text,
2631
+ forceMoveMarkers: true
2632
+ }]);
2633
+ if (lastKnownCode != null) lastKnownCode = lastKnownCode + text;
2634
+ try {
2635
+ if (lastLine !== model.getLineCount()) maybeScrollToBottom(model.getLineCount());
2636
+ } catch {}
2637
+ } catch {}
2638
+ }
2639
+ function updateCode(newCode, codeLanguage) {
2640
+ if (editorMgr) editorMgr.updateCode(newCode, codeLanguage);
2641
+ else {
2642
+ pendingUpdate = {
2643
+ code: newCode,
2644
+ lang: codeLanguage
2645
+ };
2646
+ rafScheduler.schedule("update", () => {
2647
+ if (!updateThrottleMs) {
2648
+ flushPendingUpdate();
2649
+ return;
2650
+ }
2651
+ const now = Date.now();
2652
+ const since = now - lastFlushTime;
2653
+ if (since >= updateThrottleMs) {
2654
+ flushPendingUpdate();
2655
+ return;
2656
+ }
2657
+ if (updateThrottleTimer != null) return;
2658
+ const wait = updateThrottleMs - since;
2659
+ updateThrottleTimer = setTimeout(() => {
2660
+ updateThrottleTimer = null;
2661
+ rafScheduler.schedule("update", () => flushPendingUpdate());
2662
+ }, wait);
2663
+ });
2664
+ }
2665
+ }
2666
+ function setUpdateThrottleMs(ms) {
2667
+ updateThrottleMs = ms;
2668
+ }
2669
+ function getUpdateThrottleMs() {
2670
+ return updateThrottleMs;
2671
+ }
2672
+ function updateDiff(originalCode, modifiedCode, codeLanguage) {
2673
+ if (diffMgr) diffMgr.updateDiff(originalCode, modifiedCode, codeLanguage);
2674
+ }
2675
+ function updateOriginal(newCode, codeLanguage) {
2676
+ if (diffMgr) diffMgr.updateOriginal(newCode, codeLanguage);
2677
+ }
2678
+ function updateModified(newCode, codeLanguage) {
2679
+ if (diffMgr) diffMgr.updateModified(newCode, codeLanguage);
2680
+ }
2681
+ function appendOriginal(appendText, codeLanguage) {
2682
+ if (diffMgr) diffMgr.appendOriginal(appendText, codeLanguage);
2683
+ }
2684
+ function appendModified(appendText, codeLanguage) {
2685
+ if (diffMgr) diffMgr.appendModified(appendText, codeLanguage);
2686
+ }
2687
+ return {
2688
+ createEditor,
2689
+ createDiffEditor,
2690
+ cleanupEditor,
2691
+ safeClean() {
2692
+ rafScheduler.cancel("update");
2693
+ pendingUpdate = null;
2694
+ if (editorMgr) try {
2695
+ editorMgr.safeClean();
2696
+ } catch {}
2697
+ if (diffMgr) try {
2698
+ diffMgr.safeClean();
2699
+ } catch {}
2700
+ _hasScrollBar = false;
2701
+ shouldAutoScroll = !!autoScrollInitial;
2702
+ },
2703
+ updateCode,
2704
+ appendCode,
2705
+ updateDiff,
2706
+ updateOriginal,
2707
+ updateModified,
2708
+ appendOriginal,
2709
+ appendModified,
2710
+ setTheme: setThemeInternal,
2711
+ setLanguage(language) {
2712
+ if (editorMgr) {
2713
+ editorMgr.setLanguage(language, languages$1);
2714
+ return;
2715
+ }
2716
+ if (diffMgr) {
2717
+ diffMgr.setLanguage(language, languages$1);
2718
+ return;
2719
+ }
2720
+ if (languages$1.includes(language)) {
2721
+ if (editorView) {
2722
+ const model = editorView.getModel();
2723
+ if (model && model.getLanguageId() !== language) monaco_shim_exports.editor.setModelLanguage(model, language);
2724
+ }
2725
+ if (originalModel && originalModel.getLanguageId() !== language) monaco_shim_exports.editor.setModelLanguage(originalModel, language);
2726
+ if (modifiedModel && modifiedModel.getLanguageId() !== language) monaco_shim_exports.editor.setModelLanguage(modifiedModel, language);
2727
+ } else console.warn(`Language "${language}" is not registered. Available languages: ${languages$1.join(", ")}`);
2728
+ },
2729
+ getCurrentTheme() {
2730
+ return globalAppliedThemeName ?? requestedThemeName ?? globalRequestedThemeName ?? currentTheme.value;
2731
+ },
2732
+ getEditor() {
2733
+ return monaco_shim_exports.editor;
2734
+ },
2735
+ getEditorView() {
2736
+ return editorView;
2737
+ },
2738
+ getDiffEditorView() {
2739
+ return diffEditorView;
2740
+ },
2741
+ getDiffModels() {
2742
+ return {
2743
+ original: originalModel,
2744
+ modified: modifiedModel
2745
+ };
2746
+ },
2747
+ getMonacoInstance() {
2748
+ return monaco_shim_exports;
2749
+ },
2750
+ setUpdateThrottleMs,
2751
+ getUpdateThrottleMs,
2752
+ getCode() {
2753
+ if (editorView) try {
2754
+ var _editorView$getModel;
2755
+ return ((_editorView$getModel = editorView.getModel()) === null || _editorView$getModel === void 0 ? void 0 : _editorView$getModel.getValue()) ?? null;
2756
+ } catch {
2757
+ return null;
2758
+ }
2759
+ if (diffEditorView || originalModel && modifiedModel) try {
2760
+ const original = (originalModel === null || originalModel === void 0 ? void 0 : originalModel.getValue()) ?? "";
2761
+ const modified = (modifiedModel === null || modifiedModel === void 0 ? void 0 : modifiedModel.getValue()) ?? "";
2762
+ return {
2763
+ original,
2764
+ modified
2765
+ };
2766
+ } catch {
2767
+ return null;
2768
+ }
2769
+ return null;
2770
+ }
2771
+ };
2772
+ }
2773
+
2774
+ //#endregion
2775
+ //#region src/preloadMonacoWorkers.shared.ts
2776
+ const editorWorkerPath = "monaco-editor/esm/vs/editor/editor.worker.js";
2777
+ const workerPathByLabel = {
2778
+ json: "monaco-editor/esm/vs/language/json/json.worker.js",
2779
+ css: "monaco-editor/esm/vs/language/css/css.worker.js",
2780
+ scss: "monaco-editor/esm/vs/language/css/css.worker.js",
2781
+ less: "monaco-editor/esm/vs/language/css/css.worker.js",
2782
+ html: "monaco-editor/esm/vs/language/html/html.worker.js",
2783
+ handlebars: "monaco-editor/esm/vs/language/html/html.worker.js",
2784
+ razor: "monaco-editor/esm/vs/language/html/html.worker.js",
2785
+ typescript: "monaco-editor/esm/vs/language/typescript/ts.worker.js",
2786
+ javascript: "monaco-editor/esm/vs/language/typescript/ts.worker.js"
2787
+ };
2788
+ const uniqueWorkerPaths = Array.from(new Set([editorWorkerPath, ...Object.values(workerPathByLabel)]));
2789
+
2790
+ //#endregion
2791
+ export { RevealStrategy, clearHighlighterCache, defaultRevealDebounceMs, detectLanguage, editorWorkerPath, getOrCreateHighlighter, registerMonacoThemes, uniqueWorkerPaths, useMonaco, workerPathByLabel };