stream-monaco 0.0.15 → 0.0.17

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