@happy-nut/monacori 0.1.23 → 0.1.25

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.
@@ -1189,6 +1189,16 @@ document.addEventListener('keydown', (event) => {
1189
1189
  // shortcuts (Cmd+1, F7, Cmd+[/], Cmd+B, …). Each has its own Esc + editing handlers.
1190
1190
  if (isFloatingModalOpen()) return;
1191
1191
 
1192
+ // Cmd/Ctrl+A in the diff/source view selects ONLY that view's content (the browser default reached into
1193
+ // the sidebar + terminal). In an editable field, let the default select-within-field stand.
1194
+ if ((event.metaKey || event.ctrlKey) && !event.shiftKey && !event.altKey && (event.key === 'a' || event.key === 'A')) {
1195
+ var aae = document.activeElement;
1196
+ if (!(aae && (aae.tagName === 'INPUT' || aae.tagName === 'TEXTAREA' || aae.tagName === 'SELECT')) && selectAllInView()) {
1197
+ event.preventDefault();
1198
+ return;
1199
+ }
1200
+ }
1201
+
1192
1202
  if ((event.metaKey || event.ctrlKey) && !event.shiftKey && !event.altKey && event.key === '1') {
1193
1203
  event.preventDefault();
1194
1204
  // Coming from the diff: open the file you were viewing as source so Cmd+1 lands ON it (not a stale/blank
@@ -2867,6 +2877,10 @@ refreshComments();
2867
2877
  // Exception: keep focus for clipboard/selection combos (Cmd+C/V/X/A) so the terminal's own copy &
2868
2878
  // paste keep working — blurring on Cmd+V drops the textarea focus the paste event needs.
2869
2879
  term.attachCustomKeyEventHandler(function (e) {
2880
+ // F7 / Shift+F7 are diff prev/next-change nav. Don't let the terminal eat them (it would send an
2881
+ // escape sequence to the shell); return false so xterm ignores the key and it bubbles to the document
2882
+ // handler. We DON'T blur — the diff caret is a JS cursor, so nav runs while the terminal keeps focus.
2883
+ if (e.type === 'keydown' && e.key === 'F7' && !e.metaKey && !e.ctrlKey && !e.altKey) return false;
2870
2884
  if (e.type === 'keydown' && e.metaKey) {
2871
2885
  var k = (e.key || '').toLowerCase();
2872
2886
  // The bare modifier press (Cmd goes down BEFORE the letter on macOS) must not blur — blurring
@@ -2879,6 +2893,10 @@ refreshComments();
2879
2893
  // copy misses xterm's own selection, so Cmd+C silently did nothing. No selection -> fall through.
2880
2894
  if (e.code === 'KeyC' && term.hasSelection && term.hasSelection()) { copyToClipboard(term.getSelection()); return false; }
2881
2895
  if (e.code === 'KeyC' || e.code === 'KeyV' || e.code === 'KeyX' || e.code === 'KeyA') return true;
2896
+ // Cmd/Ctrl+W is the close-pane menu accelerator. onCloseTab closes the FOCUSED pane only if the
2897
+ // terminal still has focus — blurring here first made hasFocus() false, so the focused split pane
2898
+ // never closed. Release the key WITHOUT blurring so focus stays and onCloseTab can close it.
2899
+ if (e.code === 'KeyW') return false;
2882
2900
  try { term.blur(); } catch (x) {}
2883
2901
  return false;
2884
2902
  }
@@ -3383,15 +3401,21 @@ function restoreUiState() {
3383
3401
  }
3384
3402
  return true;
3385
3403
  }
3386
- if (state.sourcePath && sourceByPath.has(state.sourcePath)) {
3387
- openSourceFile(state.sourcePath);
3404
+ // Source view. Open the saved file — or fall back to the first restored tab when that file is gone
3405
+ // (filtered out above) or wasn't recorded. Otherwise we'd render the tab bar but leave the body on its
3406
+ // "select a file" placeholder, which looks broken (a tab is clearly open). No openable tab → drop the
3407
+ // stale tabs and let the init fallback pick a sensible default.
3408
+ var openPath = (state.sourcePath && sourceByPath.has(state.sourcePath)) ? state.sourcePath : (sourceTabs[0] || '');
3409
+ if (openPath) {
3410
+ openSourceFile(openPath);
3388
3411
  // Restore the exact source caret/scroll (openSourceFile alone resets it to the top).
3389
- if (state.viewerCursor && state.viewerCursor.path === state.sourcePath) {
3412
+ if (state.viewerCursor && state.viewerCursor.path === openPath) {
3390
3413
  var vc = state.viewerCursor;
3391
- setTimeout(function () { try { setSourceCursor(state.sourcePath, vc.lineIndex, vc.column, true, -1); } catch (e) {} }, 60);
3414
+ setTimeout(function () { try { setSourceCursor(openPath, vc.lineIndex, vc.column, true, -1); } catch (e) {} }, 60);
3392
3415
  }
3393
3416
  return true;
3394
3417
  }
3418
+ sourceTabs = [];
3395
3419
  } catch {
3396
3420
  sessionStorage.removeItem(uiStateKey);
3397
3421
  }
@@ -3412,6 +3436,45 @@ function flushPendingDiffUpdate() {
3412
3436
  pendingDiffUpdate = null;
3413
3437
  try { applyDiffUpdate(u); } catch (e) {}
3414
3438
  }
3439
+ // Flicker-saver for the live-watch refresh. The default path replaces the WHOLE diff DOM
3440
+ // (container.innerHTML = …), which re-renders the file you're looking at even when only an OFF-SCREEN file
3441
+ // changed. When the file set AND order are identical, reconcile per-file instead: keep every unchanged
3442
+ // wrapper's DOM node untouched (no flicker — including the visible one) and swap only the changed wrappers,
3443
+ // which are off-screen so the swap is invisible. Returns false (caller does the full innerHTML swap) for the
3444
+ // risky cases — files added/removed/reordered — so that proven path still handles index-shift correctly.
3445
+ function reconcileDiffWrappers(container, newDiffHtml, oldSigByPath, newSigByPath) {
3446
+ var oldW = Array.prototype.slice.call(container.querySelectorAll('.d2h-file-wrapper'));
3447
+ if (!oldW.length) return false;
3448
+ var tmp = document.createElement('div');
3449
+ tmp.innerHTML = newDiffHtml;
3450
+ var newW = Array.prototype.slice.call(tmp.querySelectorAll('.d2h-file-wrapper'));
3451
+ if (newW.length !== oldW.length) return false; // add/remove → full swap (global hunk indices shift)
3452
+ for (var i = 0; i < oldW.length; i++) {
3453
+ if (diffWrapperPathKey(oldW[i]) !== diffWrapperPathKey(newW[i])) return false; // reordered → full swap
3454
+ }
3455
+ for (var j = 0; j < oldW.length; j++) {
3456
+ var ow = oldW[j], nw = newW[j], p = diffWrapperPathKey(ow);
3457
+ if ((oldSigByPath.get(p) || '') !== (newSigByPath.get(p) || '')) {
3458
+ // Changed file (off-screen): drop in the fresh shell and clear its cached body so it refetches the
3459
+ // new content when it next scrolls into view. Replacing an off-screen node is invisible.
3460
+ var nidx = (nw.id || '').replace('file-', '');
3461
+ delete bodyCache[nidx];
3462
+ delete bodyPromise[nidx];
3463
+ ow.parentNode.replaceChild(nw, ow);
3464
+ } else {
3465
+ // Unchanged file: keep its DOM node (no flicker). An earlier file's changed hunk count can shift the
3466
+ // global numbering, so sync the index attrs and renumber a materialized body's hunk ids (id/class
3467
+ // changes only — invisible, no flicker).
3468
+ var baseChanged = ow.getAttribute('data-first-hunk') !== nw.getAttribute('data-first-hunk');
3469
+ ow.id = nw.id;
3470
+ if (nw.hasAttribute('data-first-hunk')) ow.setAttribute('data-first-hunk', nw.getAttribute('data-first-hunk'));
3471
+ if (nw.hasAttribute('data-hunk-count')) ow.setAttribute('data-hunk-count', nw.getAttribute('data-hunk-count'));
3472
+ var body = ow.querySelector('.d2h-files-diff');
3473
+ if (baseChanged && body && !body.hasAttribute('data-lazy')) markWrapperHunks(ow);
3474
+ }
3475
+ }
3476
+ return true;
3477
+ }
3415
3478
  function applyDiffUpdate(u) {
3416
3479
  if (!u || !u.signature || u.signature === currentSignature) return false; // unchanged — nothing to do
3417
3480
  if (composerState) { pendingDiffUpdate = u; return false; } // composing a comment — hold the refresh until close/save
@@ -3431,11 +3494,19 @@ function applyDiffUpdate(u) {
3431
3494
  // open file's signature BEFORE fileSignatureByPath is rebuilt below.
3432
3495
  var prevOpenSig = openPath ? (fileSignatureByPath.get(openPath) || '') : '';
3433
3496
 
3434
- // Snapshot already-materialized file bodies (keyed by path + current signature) BEFORE the swap, so an
3435
- // UNCHANGED file can be re-filled synchronously afterwards. Without this, the swap turns every wrapper into
3436
- // an empty lazy shell that blanks until its body re-loads over IPC — the visible "flicker" on a watch tick.
3497
+ // Fast-path: when the file set + order are unchanged, reconcile per-file so an off-screen change never
3498
+ // flickers the file you're viewing. Falls back to the full swap (below) for add/remove/reorder or eager.
3499
+ var newSigByPath = new Map((u.fileStates || []).map(function (f) { return [f.path, f.signature]; }));
3500
+ var fastPath = false;
3501
+ if (REVIEW_LAZY && container && u.diffContainer) {
3502
+ fastPath = reconcileDiffWrappers(container, u.diffContainer, fileSignatureByPath, newSigByPath);
3503
+ }
3504
+
3505
+ // Full-swap path only: snapshot already-materialized bodies (keyed by path + signature) BEFORE the swap so
3506
+ // UNCHANGED files re-fill synchronously afterwards — otherwise the swap blanks every wrapper into an empty
3507
+ // lazy shell until its body reloads over IPC (the "flicker"). The fast-path keeps those nodes, so skip it.
3437
3508
  var prevBodies = {};
3438
- if (REVIEW_LAZY && container) {
3509
+ if (!fastPath && REVIEW_LAZY && container) {
3439
3510
  container.querySelectorAll('.d2h-file-wrapper').forEach(function (w) {
3440
3511
  var b = w.querySelector('.d2h-files-diff');
3441
3512
  if (!b || b.hasAttribute('data-lazy')) return; // only bodies that are actually materialized
@@ -3444,8 +3515,9 @@ function applyDiffUpdate(u) {
3444
3515
  });
3445
3516
  }
3446
3517
 
3447
- // 1) Replace the visible regions straight from the payload (no full-HTML parse).
3448
- if (container) container.innerHTML = u.diffContainer || '';
3518
+ // 1) Replace the visible regions straight from the payload (no full-HTML parse) — unless the fast-path
3519
+ // already reconciled the diff DOM in place.
3520
+ if (container && !fastPath) container.innerHTML = u.diffContainer || '';
3449
3521
  var changesPanel = document.getElementById('changes-panel');
3450
3522
  if (changesPanel) changesPanel.innerHTML = u.changesPanel || '';
3451
3523
  // Files tree: keep the inert island (lazy, not yet opened) in sync, and refresh the live panel when it's
@@ -3507,7 +3579,7 @@ function applyDiffUpdate(u) {
3507
3579
  // flicker). Runs BEFORE setupLazyDiff so the IntersectionObserver sees them already materialized and never
3508
3580
  // re-fetches them. The fresh wrapper carries the correct data-first-hunk + file index, so materializeBody
3509
3581
  // numbers hunks exactly as a normal lazy load would. Changed/new files stay shells and lazy-load as usual.
3510
- if (REVIEW_LAZY && container) {
3582
+ if (!fastPath && REVIEW_LAZY && container) {
3511
3583
  container.querySelectorAll('.d2h-file-wrapper').forEach(function (w) {
3512
3584
  var p = diffWrapperPathKey(w);
3513
3585
  var prev = p ? prevBodies[p] : null;
@@ -3894,6 +3966,26 @@ function isSourceViewerVisible() {
3894
3966
  return Boolean(viewer && !viewer.classList.contains('hidden'));
3895
3967
  }
3896
3968
 
3969
+ // Cmd/Ctrl+A scoped to the current view: select the source body, or the active diff file's content —
3970
+ // NOT the whole page (the browser default reached into the sidebar/terminal). Returns false if there's
3971
+ // no view target so the caller can fall back to the default.
3972
+ function selectAllInView() {
3973
+ var target = null;
3974
+ if (isSourceViewerVisible()) target = document.getElementById('source-body');
3975
+ else if (typeof isDiffViewVisible === 'function' && isDiffViewVisible()) {
3976
+ target = document.querySelector('#diff2html-container .d2h-file-wrapper:not(.df-inactive)') || document.getElementById('diff2html-container');
3977
+ }
3978
+ if (!target) return false;
3979
+ try {
3980
+ var sel = window.getSelection();
3981
+ var range = document.createRange();
3982
+ range.selectNodeContents(target);
3983
+ sel.removeAllRanges();
3984
+ sel.addRange(range);
3985
+ } catch (e) { return false; }
3986
+ return true;
3987
+ }
3988
+
3897
3989
  function openDiffFileAtCaret() {
3898
3990
  if (diffCursor && isDiffViewVisible()) {
3899
3991
  const dwrap = diffWrapperByPath(diffCursor.path);
@@ -1 +1 @@
1
- const REVIEW_LAZY="true"===document.getElementById("review-meta")?.dataset.lazy,REVIEW_LAZY_LOAD="true"===document.getElementById("review-meta")?.dataset.lazyLoad;REVIEW_LAZY||prepareDiff2HtmlHunks();const hunks=REVIEW_LAZY?[]:Array.from(document.querySelectorAll(".hunk")),hunkPeers=REVIEW_LAZY?[]:Array.from(document.querySelectorAll(".hunk-peer")),hunkMeta=[];REVIEW_LAZY&&Array.prototype.forEach.call(document.querySelectorAll("#diff2html-container .d2h-file-wrapper"),function(e){for(var t=parseInt(e.dataset.firstHunk||"0",10)||0,n=parseInt(e.dataset.hunkCount||"0",10)||0,r=e.dataset.path||((e.querySelector(".d2h-file-name")||{}).textContent||"").trim(),o=0;o<n;o++)hunkMeta[t+o]={path:r}});var diffBootDone=!1;function refreshHunkIndex(){REVIEW_LAZY?(hunkMeta.length=0,Array.prototype.forEach.call(document.querySelectorAll("#diff2html-container .d2h-file-wrapper"),function(e){for(var t=parseInt(e.dataset.firstHunk||"0",10)||0,n=parseInt(e.dataset.hunkCount||"0",10)||0,r=e.dataset.path||((e.querySelector(".d2h-file-name")||{}).textContent||"").trim(),o=0;o<n;o++)hunkMeta[t+o]={path:r}})):(prepareDiff2HtmlHunks(),hunks.length=0,Array.prototype.push.apply(hunks,document.querySelectorAll(".hunk")),hunkPeers.length=0,Array.prototype.push.apply(hunkPeers,document.querySelectorAll(".hunk-peer")))}function hunkTotal(){return REVIEW_LAZY?hunkMeta.length:hunks.length}function hunkPathAt(e){return REVIEW_LAZY?hunkMeta[e]?hunkMeta[e].path:"":hunks[e]?hunks[e].dataset.file:""}function hunkRowAt(e){if(!REVIEW_LAZY)return hunks[e]||null;var t=hunkMeta[e];return t?(ensureFileReady(diffWrapperByPath(t.path)),document.getElementById("hunk-"+e)):null}function markWrapperHunks(e){var t=parseInt(e.dataset.firstHunk||"0",10)||0,n=((e.querySelector(".d2h-file-name")||{}).textContent||"").trim(),r=new Map,o=0;Array.prototype.forEach.call(e.querySelectorAll("tr"),function(e){var i=(e.textContent||"").trim();if(0===i.indexOf("@@")){var a=r.get(i);void 0===a?(a=t+o,r.set(i,a),e.classList.add("hunk"),e.id="hunk-"+a,o+=1):e.classList.add("hunk-peer"),e.dataset.hunkIndex=String(a),e.dataset.file=n}})}var bodyCache={},bodyPromise={};function loadBodyHtml(e){return null!=bodyCache[e]?Promise.resolve(bodyCache[e]):("undefined"!=typeof window&&window.monacoriFile&&"function"==typeof window.monacoriFile.get?Promise.resolve().then(function(){return window.monacoriFile.get(Number(e),"diff")}):"undefined"!=typeof fetch?fetch("file?index="+e).then(function(e){return e.ok?e.text():""}):Promise.resolve("")).then(function(t){return bodyCache[e]=t||"",bodyCache[e]},function(){return bodyCache[e]="",""})}function materializeBody(e,t){var n=e.querySelector(".d2h-files-diff[data-lazy]");if(n&&(n.innerHTML=t||"",n.removeAttribute("data-lazy"),n.removeAttribute("data-loading"),markWrapperHunks(e),diffBootDone&&void 0!==reviewComments&&reviewComments.length))try{refreshComments()}catch(e){}}function ensureFileReady(e){if(!e)return null;var t=e.querySelector(".d2h-files-diff[data-lazy]");if(!t)return e;var n=(e.id||"").replace("file-","");if(REVIEW_LAZY_LOAD)return bodyPromise[n]||(t.setAttribute("data-loading","1"),bodyPromise[n]=loadBodyHtml(n).then(function(t){return materializeBody(e,t),e})),e;var r=document.getElementById("diff-body-"+n);return r&&materializeBody(e,r.textContent||""),e}function whenFileReady(e,t){if(e){ensureFileReady(e);var n=e.querySelector(".d2h-files-diff");if(n&&n.hasAttribute("data-lazy")){var r=(e.id||"").replace("file-","");bodyPromise[r]?bodyPromise[r].then(function(){t()}):t()}else t()}else t()}var lazyIO=null;function setupLazyDiff(){var e=document.getElementById("diff2html-container");if(e){if(lazyIO){try{lazyIO.disconnect()}catch(e){}lazyIO=null}var t=Array.prototype.slice.call(e.querySelectorAll(".d2h-file-wrapper"));if("undefined"!=typeof IntersectionObserver){var n=new IntersectionObserver(function(e){e.forEach(function(e){e.isIntersecting&&(ensureFileReady(e.target),n.unobserve(e.target))})},{root:null,rootMargin:"600px 0px"});lazyIO=n,t.forEach(function(e){n.observe(e)})}else t.forEach(function(e){ensureFileReady(e)});t[0]&&ensureFileReady(t[0])}}REVIEW_LAZY&&(setupLazyDiff(),setTimeout(function(){diffBootDone=!0},0));let links=Array.from(document.querySelectorAll("#changes-panel .file-link")),sourceLinks=Array.from(document.querySelectorAll(".source-link")),sourceFiles=JSON.parse(document.getElementById("source-files-data")?.textContent||"[]");var I18N=JSON.parse(document.getElementById("i18n-data")?.textContent||"{}");function persistRead(e){try{if(window.monacoriSettings&&window.monacoriSettings.all&&e in window.monacoriSettings.all){var t=window.monacoriSettings.all[e];return t&&"object"==typeof t?JSON.parse(JSON.stringify(t)):t}}catch(e){}}function persistSave(e,t){try{localStorage.setItem(e,"string"==typeof t?t:JSON.stringify(t))}catch(e){}try{window.monacoriSettings&&window.monacoriSettings.set(e,t)}catch(e){}}var LOCALE_KEY="monacori-locale",locale=function(){var e=persistRead(LOCALE_KEY);if("ko"!==e&&"en"!==e)try{e=localStorage.getItem(LOCALE_KEY)}catch(e){}return"ko"===e||"en"===e?e:"en"}();function t(e){var t=I18N[locale]||I18N.en||{};return t&&e in t?t[e]:I18N.en&&I18N.en[e]||e}var langSelectRef=null,themeSelectRef=null;function setupCustomSelect(e,t,n,r){var o=document.getElementById(e);if(!o)return null;function i(){var e=n(),r=t().filter(function(t){return t.value===e})[0];o.textContent=r?r.label:e}return o.addEventListener("click",function(e){e.preventDefault();var a=o.getBoundingClientRect(),s=n();showCustomDropdown(a.left,a.bottom+4,t().map(function(e){return{label:(e.value===s?"✓ ":"  ")+e.label,onSelect:function(){r(e.value),i()}}}),a.top-4)}),i(),{render:i}}function applyI18n(){document.querySelectorAll("[data-i18n]").forEach(function(e){e.textContent=t(e.getAttribute("data-i18n"))}),document.querySelectorAll("[data-i18n-ph]").forEach(function(e){e.setAttribute("placeholder",t(e.getAttribute("data-i18n-ph")))}),document.querySelectorAll("[data-i18n-title]").forEach(function(e){e.setAttribute("title",t(e.getAttribute("data-i18n-title")))}),document.querySelectorAll("[data-i18n-aria]").forEach(function(e){e.setAttribute("aria-label",t(e.getAttribute("data-i18n-aria")))}),document.documentElement.lang=locale,langSelectRef&&langSelectRef.render(),themeSelectRef&&themeSelectRef.render()}var THEME_KEY="monacori-theme",theme=function(){var e=persistRead(THEME_KEY);if("light"!==e&&"dark"!==e)try{e=localStorage.getItem(THEME_KEY)}catch(e){}return"light"===e||"dark"===e?e:"dark"}();function applyTheme(){document.documentElement.setAttribute("data-theme",theme),themeSelectRef&&themeSelectRef.render()}applyTheme();let fileStates=JSON.parse(document.getElementById("file-state-data")?.textContent||"[]"),httpEnvironments=JSON.parse(document.getElementById("http-env-data")?.textContent||"{}"),httpEnvNames=Object.keys(httpEnvironments);const httpEnvKey="monacori-http-env:"+location.pathname,httpRequestsByPath=new Map,httpVarsByPath=new Map;let sourceByPath=new Map(sourceFiles.map(e=>[e.path,e]));var sourceLoaded=!REVIEW_LAZY_LOAD,pendingSourceOpen=null,sourceBodyPath=null,sourceLoading=!1,pendingSymbol=null,sourceTabs=[];function loadSourceData(){sourceLoaded||sourceLoading||(sourceLoading=!0,("undefined"!=typeof window&&window.monacoriFile&&"function"==typeof window.monacoriFile.getSourceData?Promise.resolve().then(function(){return window.monacoriFile.getSourceData()}):"undefined"!=typeof fetch?fetch("source-data").then(function(e){return e.ok?e.text():"[]"}):Promise.resolve("[]")).then(function(e){var t=[];try{t=JSON.parse(e||"[]")}catch(e){t=[]}for(var n=0;n<t.length;n++){var r=sourceByPath.get(t[n].path);r&&(r.content=t[n].content,t[n].image&&(r.image=t[n].image))}if(sourceLoaded=!0,sourceLoading=!1,scheduleSymbolIndex(),remapComments(),pendingSourceOpen){var o=pendingSourceOpen;pendingSourceOpen=null,openSourceFile(o.path,o.shouldSwitch)}else isSourceViewerVisible()&&document.getElementById("source-viewer").dataset.openPath&&openSourceFile(document.getElementById("source-viewer").dataset.openPath,!1);if(pendingSymbol){var i=pendingSymbol;pendingSymbol=null,goToDefOrUsages(i)}},function(){sourceLoaded=!0,sourceLoading=!1}))}let fileSignatureByPath=new Map(fileStates.map(e=>[e.path,e.signature]));const reviewMeta=document.getElementById("review-meta"),watchEnabled="true"===reviewMeta?.dataset.watch;let currentSignature=reviewMeta?.dataset.signature||"";const uiStateKey="monacori-diff-ui:"+location.pathname,recentKey="monacori-diff-recent:"+location.pathname,viewedKey="monacori-diff-viewed:"+location.pathname,quickOpen=document.getElementById("quick-open"),quickInput=document.getElementById("quick-open-input"),quickResults=document.getElementById("quick-open-results"),quickModeLabel=document.getElementById("quick-open-mode"),quickFilterEl=document.getElementById("quick-open-filter");let current=-1,checkingForUpdates=!1,lastShiftAt=0,lastShiftSide=0,quickMode="all",quickItems=[],quickActive=0,recentFilter="",usageItems=[],usageActive=0,viewerCursor=null,selectedCommentRow=null,currentHttpEnvName=function(){let e="";try{e=localStorage.getItem(httpEnvKey)||""}catch(t){e=""}return e&&httpEnvNames.indexOf(e)>=0?e:httpEnvNames.length?httpEnvNames[0]:""}(),treeFocusIndex=-1,selectionAnchor=null,diffCursor=null,navList=[],navPos=-1,navSuppress=!1;var NAV_JUMP_LINES=8,NAV_MAX=60;let diffSelectionAnchor=null,measuredCharWidth=0;var COMMENTS_KEY="monacori-comments:"+location.pathname,reviewComments=[];reviewComments=function(){var e=persistRead(COMMENTS_KEY);if(Array.isArray(e))return e;try{return JSON.parse(localStorage.getItem(COMMENTS_KEY)||"[]")}catch(e){return[]}}(),Array.isArray(reviewComments)||(reviewComments=[]);var commentSeq=reviewComments.reduce(function(e,t){return Math.max(e,t.seq||0)},0),composerState=null;function prepareDiff2HtmlHunks(){const e=Array.from(document.querySelectorAll(".d2h-file-wrapper"));let t=0;e.forEach((e,n)=>{e.id="file-"+n;const r=e.querySelector(".d2h-file-name")?.textContent?.trim()||"",o=new Map;Array.from(e.querySelectorAll("tr")).forEach(e=>{const n=e.textContent.trim();if(!n.startsWith("@@"))return;let i=o.get(n);void 0===i?(i=t,o.set(n,i),e.classList.add("hunk"),e.id="hunk-"+i,t+=1):e.classList.add("hunk-peer"),e.dataset.hunkIndex=String(i),e.dataset.file=r})})}function prepareViewedControls(){document.querySelectorAll(".d2h-file-wrapper").forEach(e=>{const n=e.querySelector(".d2h-file-name")?.textContent?.trim()||"",r=e.querySelector(".d2h-file-collapse"),o=r?.querySelector("input");n&&r&&o&&(r.title=t("btn.viewed.title"),o.tabIndex=-1,r.addEventListener("click",e=>{e.preventDefault(),setFileViewed(n,!isFileViewed(n))}))}),applyViewedState()}function loadViewedState(){try{const e=JSON.parse(localStorage.getItem(viewedKey)||"{}");return e&&"object"==typeof e&&!Array.isArray(e)?e:{}}catch{return{}}}function saveViewedState(e){try{localStorage.setItem(viewedKey,JSON.stringify(e))}catch{}}function currentFileSignature(e){return fileSignatureByPath.get(e)||""}function isFileViewed(e){const t=loadViewedState();return Boolean(t[e])}function setFileViewed(e,t){const n=loadViewedState();t?n[e]=!0:delete n[e],saveViewedState(n),applyViewedState()}function applyViewedState(){document.querySelectorAll(".d2h-file-wrapper").forEach(e=>{const t=isFileViewed(e.querySelector(".d2h-file-name")?.textContent?.trim()||"");e.classList.toggle("file-viewed",t);const n=e.querySelector(".d2h-file-collapse-input");n&&(n.checked=t)}),links.forEach(e=>{e.classList.toggle("viewed",isFileViewed(e.dataset.file||""))}),updateDiffViewedToggle()}function updateDiffViewedToggle(){var e=document.getElementById("diff-viewed-toggle");if(e){var t=e.dataset.file||"",n=Boolean(t&&currentFileSignature(t));if(e.hidden=!n,n){var r=isFileViewed(t);e.classList.toggle("is-viewed",r),e.setAttribute("aria-pressed",r?"true":"false")}}}prepareViewedControls();let activeDiffRow=null;function firstCodeRowOfHunk(e){let t=e.nextElementSibling,n=null;for(;t&&!t.classList.contains("hunk")&&!t.classList.contains("hunk-peer");){if(t.querySelector&&t.querySelector(".d2h-code-side-line")&&(n||(n=t),t.querySelector(".d2h-ins, .d2h-del, ins, del")))return t;t=t.nextElementSibling}return n||e}function isChangeCodeRow(e){return!!(e&&isDiffCodeRow(e)&&e.querySelector(".d2h-ins, .d2h-del, ins, del"))}function firstChangeRowForCaret(e){const t=e.closest(".d2h-file-wrapper"),n=t?t.querySelectorAll(".d2h-file-side-diff"):[],r=e.closest(".d2h-file-side-diff");if(n.length>=2&&r){const t=Array.from(r.querySelectorAll("tr")),o=r===n[0]?n[1]:n[0],i=Array.from(o.querySelectorAll("tr"));let a=null;for(let n=t.indexOf(e)+1;n<t.length;n++){const e=t[n];if(e.classList.contains("hunk")||e.classList.contains("hunk-peer"))break;if(isChangeCodeRow(i[n]))return i[n];null===a&&isChangeCodeRow(e)&&(a=e)}if(a)return a}return firstCodeRowOfHunk(e)}function focusDiffRow(e){if(activeDiffRow&&activeDiffRow.classList.remove("diff-active-row"),activeDiffRow=e||null,!e)return;e.classList.add("diff-active-row");const t=diffRowInfoFromNode(e);if(t&&t.path){let e=t.side;if("old"===e){const n=diffWrapperByPath(t.path);isDiffCodeRow(n?diffRowAt(n,"new",t.rowIndex):null)&&(e="new")}setDiffCursor(t.path,e,t.rowIndex,0,!1)}}function renderBreadcrumb(e,t){if(!e)return;e.textContent="";const n=(t||"").split("/").filter(Boolean);n.forEach((t,r)=>{if(r>0){const t=document.createElement("span");t.className="crumb-sep",t.textContent="›",e.appendChild(t)}const o=document.createElement("span");o.className=r===n.length-1?"crumb crumb-leaf":"crumb",o.textContent=t,e.appendChild(o)})}var pendingDiffScrollRow=null,diffScrollRaf=0;function scheduleDiffScroll(e){pendingDiffScrollRow=e||null,diffScrollRaf||(diffScrollRaf=requestAnimationFrame(function(){diffScrollRaf=0;var e=pendingDiffScrollRow;pendingDiffScrollRow=null,e&&e.scrollIntoView&&e.scrollIntoView({block:"center"})}))}var pendingScrollEl=null,scrollElRaf=0;function revealAt(e,t,n){if(e)if(t&&t.clientHeight){var r=e.getBoundingClientRect().top-t.getBoundingClientRect().top;t.scrollTop+=r-t.clientHeight*n}else try{e.scrollIntoView({block:"nearest",inline:"nearest"})}catch(e){}}function scrolloffReveal(e,t,n){if(e&&t&&t.clientHeight){var r=e.getBoundingClientRect().top-t.getBoundingClientRect().top,o=e.offsetHeight||18,i=t.clientHeight,a=Math.round(i*n);r<a?t.scrollTop+=r-a:r+o>i-a&&(t.scrollTop+=r+o-(i-a))}}function scheduleScrollIntoView(e){pendingScrollEl=e||null,scrollElRaf||(scrollElRaf=requestAnimationFrame(function(){scrollElRaf=0;var e=pendingScrollEl;if(pendingScrollEl=null,e&&e.scrollIntoView)try{e.scrollIntoView({block:"nearest",inline:"nearest"})}catch(e){}}))}var setActiveRaf=0,setActiveScrollPending=!0;function setActive(e,t=!0){0!==hunkTotal()&&(current=(e%hunkTotal()+hunkTotal())%hunkTotal(),setActiveScrollPending=t,setActiveRaf||(setActiveRaf=requestAnimationFrame(function(){setActiveRaf=0,applySetActive(current,setActiveScrollPending)})))}function applySetActive(e,t){document.getElementById("source-viewer")?.classList.add("hidden"),document.getElementById("diff-view")?.classList.remove("hidden"),setTab("changes");const n=hunkPathAt(e);links.forEach(e=>e.classList.toggle("active",e.dataset.file===n)),renderBreadcrumb(document.getElementById("diff-breadcrumb"),n);var r=document.getElementById("diff-viewed-toggle");r&&(r.dataset.file=n||""),updateDiffViewedToggle(),n&&rememberRecent(n,"change"),history.replaceState(null,"","#hunk-"+e),whenFileReady(diffWrapperByPath(n),function(){showOnlyFile(n,!0);const r=document.getElementById("hunk-"+e);if(!r)return;REVIEW_LAZY?(document.querySelectorAll("#diff2html-container .hunk.active, #diff2html-container .hunk-peer.active").forEach(e=>e.classList.remove("active")),document.querySelectorAll('#diff2html-container [data-hunk-index="'+e+'"]').forEach(e=>e.classList.add("active"))):(hunks.forEach((t,n)=>t.classList.toggle("active",n===e)),hunkPeers.forEach(t=>t.classList.toggle("active",Number(t.dataset.hunkIndex)===e)));const o=firstChangeRowForCaret(r);navSuppress=!0;try{focusDiffRow(o)}finally{navSuppress=!1}t&&o&&o.scrollIntoView&&o.scrollIntoView({block:"center"})})}function showOnlyFile(e,t){REVIEW_LAZY&&ensureFileReady(diffWrapperByPath(e)),document.querySelectorAll(".d2h-file-wrapper").forEach(t=>{t.classList.toggle("df-inactive",diffWrapperPathKey(t)!==e)}),t||ensureDiffCursor()}function hunkIndexAtCaret(){if(!diffCursor)return-1;const e=diffWrapperByPath(diffCursor.path);if(!e)return-1;const t=diffRowAt(e,diffCursor.side,diffCursor.rowIndex),n=t?t.closest(".d2h-file-side-diff"):null;if(!n)return-1;let r=-1;return n.querySelectorAll("[data-hunk-index]").forEach(e=>{(e===t||t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)&&(r=Number(e.dataset.hunkIndex))}),r}function changeBlockAnchors(e){if(!e)return[];if(e.__anchors)return e.__anchors;var t=diffSideTables(e).right;if(!t)return[];for(var n=diffRowsOf(t),r=[],o=!1,i=0;i<n.length;i++){var a=isChangeCodeRow(n[i]);a&&!o&&r.push(i),o=a}return e.__anchors=r,r}var pendingFileBoundary=null;function next(e){if(0===hunkTotal())return;if(diffCursor&&isDiffViewVisible()){const t=diffWrapperByPath(diffCursor.path);if(t&&!isFileViewed(diffCursor.path)){const n=changeBlockAnchors(t),r=diffCursor.rowIndex;let o=null;if(e>0){for(let e=0;e<n.length;e++)if(n[e]>r){o=n[e];break}}else for(let e=n.length-1;e>=0;e--)if(n[e]<r){o=n[e];break}if(null!=o){const e=diffRowAt(t,"new",o);if(e){navSuppress=!0;try{focusDiffRow(e)}finally{navSuppress=!1}return void scheduleDiffScroll(e)}}}}if(e>0&&diffCursor&&isDiffViewVisible()&&!isFileViewed(diffCursor.path)&&hunkPathAt(current)===diffCursor.path){if(pendingFileBoundary!==diffCursor.path)return pendingFileBoundary=diffCursor.path,void showCaretHint(t("diff.lastHunk"));pendingFileBoundary=null}hideCaretHint();const n=hunkIndexAtCaret(),r=n>=0?n:current;let o=r<0?initialHunkForNavigation(e):r+e;for(let t=0;t<hunkTotal();t++){const t=(o%hunkTotal()+hunkTotal())%hunkTotal();if(!isFileViewed(hunkPathAt(t)||""))return void setActive(t);o+=e}}function gotoNextUnviewedFile(e){const t=hunkTotal();if(0===t)return!1;const n=firstHunkForPath(e);let r=(n>=0?n:current>=0?current:0)+1;for(let e=0;e<t;e++){const e=(r%t+t)%t;if(!isFileViewed(hunkPathAt(e)||""))return setActive(e),!0;r+=1}return!1}function initialHunkForNavigation(e){const t=firstHunkForPath(document.getElementById("source-viewer")?.dataset.openPath||"");return t>=0?t:e<0?hunkTotal()-1:0}function firstHunkForPath(e){if(!e)return-1;const t=links.find(t=>t.dataset.file===e);if(!t)return-1;const n=Number(t.dataset.hunk);return Number.isNaN(n)?-1:n}function openQuickOpen(e){quickOpen&&quickInput&&quickModeLabel&&(quickMode=e,quickModeLabel.textContent=t("recent"===e?"quickopen.recent":"content"===e?"quickopen.findInFiles":"quickopen.searchFiles"),quickOpen.classList.remove("hidden"),quickOpen.classList.toggle("quick-recent","recent"===e),recentFilter="",quickInput.value="",updateRecentFilterDisplay(),renderQuickOpenResults(),"recent"===e?document.activeElement&&document.activeElement.blur&&document.activeElement.blur():setTimeout(()=>quickInput.focus(),0))}function updateRecentFilterDisplay(){if(quickFilterEl)return"recent"!==quickMode?(quickFilterEl.textContent="",void(quickFilterEl.className="quick-open-filter")):void(recentFilter?(quickFilterEl.textContent=recentFilter,quickFilterEl.className="quick-open-filter has-filter"):(quickFilterEl.textContent=t("quickopen.typeToFilter"),quickFilterEl.className="quick-open-filter is-hint"))}function closeQuickOpen(){quickOpen?.classList.add("hidden")}function handleQuickOpenKey(e){if("Escape"===e.key)return e.preventDefault(),"recent"===quickMode&&recentFilter?(recentFilter="",updateRecentFilterDisplay(),renderQuickOpenResults(),!0):(closeQuickOpen(),!0);if("ArrowDown"===e.key)return e.preventDefault(),quickActive=Math.min(quickActive+1,Math.max(quickItems.length-1,0)),updateQuickActive(),!0;if("ArrowUp"===e.key)return e.preventDefault(),quickActive=Math.max(quickActive-1,0),updateQuickActive(),!0;if("Enter"===e.key)return e.preventDefault(),openQuickItem(quickItems[quickActive]),!0;if("recent"===quickMode){if("Backspace"===e.key)return e.preventDefault(),recentFilter&&(recentFilter=recentFilter.slice(0,-1),updateRecentFilterDisplay(),renderQuickOpenResults()),!0;if(1===e.key.length&&!e.metaKey&&!e.ctrlKey&&!e.altKey)return e.preventDefault(),recentFilter+=e.key,updateRecentFilterDisplay(),renderQuickOpenResults(),!0}return!1}function renderQuickOpenResults(){if(!quickResults)return;const e="recent"===quickMode,n=(e?recentFilter:quickInput?.value||"").trim().toLowerCase(),r=e?recentItems():allQuickItems();quickItems=r.filter(e=>{if(0===n.length)return!0;if("content"===quickMode){const t=sourceByPath.get(e.path);return Boolean(t&&t.embedded&&t.content.toLowerCase().includes(n))}return(e.path+"\n"+e.name+"\n"+e.detail).toLowerCase().includes(n)}).sort((e,t)=>scoreQuickItem(e,n)-scoreQuickItem(t,n)||e.path.localeCompare(t.path)).slice(0,80),quickActive=Math.min(quickActive,Math.max(quickItems.length-1,0)),0!==quickItems.length?(quickResults.innerHTML=quickItems.map((e,t)=>['<button type="button" class="quick-open-item'+(t===quickActive?" active":"")+'" data-index="'+t+'">','<span class="quick-open-main">','<span class="quick-open-name">'+escapeHtml(e.name)+"</span>",'<span class="quick-open-path">'+escapeHtml(e.path)+"</span>","</span>",'<span class="quick-open-badge">'+escapeHtml(e.detail)+"</span>","</button>"].join("")).join(""),renderQuickPreview(quickItems[quickActive])):quickResults.innerHTML='<div class="quick-open-empty">'+escapeHtml(t("quickopen.noFiles"))+"</div>"}function updateQuickActive(){quickResults?.querySelectorAll(".quick-open-item").forEach((e,t)=>{const n=t===quickActive;e.classList.toggle("active",n),n&&e.scrollIntoView({block:"nearest"})}),renderQuickPreview(quickItems[quickActive])}function renderQuickPreview(e){const t=document.getElementById("quick-open-preview");if(!t)return;if(!e)return void(t.innerHTML="");const n=sourceByPath.get(e.path);if(!n||!n.embedded)return void(t.innerHTML='<div class="qp-empty">'+escapeHtml(e.path)+"</div>");const r=(quickInput&&quickInput.value||"").trim().toLowerCase(),o=n.content.split(/\r?\n/);let i=-1;const a=o.map((e,t)=>{const o=r.length>0&&e.toLowerCase().includes(r);return o&&i<0&&(i=t),'<div class="qp-line'+(o?" qp-hit":"")+'"><span class="qp-num">'+(t+1)+'</span><span class="qp-code">'+highlightLine(e,n.language||"text")+"</span></div>"}).join("");if(t.innerHTML='<div class="qp-head">'+escapeHtml(e.path)+'</div><div class="qp-body">'+a+"</div>",i>=0){const e=t.querySelectorAll(".qp-line")[i];e&&e.scrollIntoView({block:"center"})}}function openQuickItem(e){if(!e)return;if(closeQuickOpen(),rememberRecent(e.path,e.kind),sourceByPath.has(e.path))return void openSourceFile(e.path);const t=links.find(t=>t.dataset.file===e.path);if(!t)return;const n=Number(t.dataset.hunk);if(!Number.isNaN(n)&&n>=0&&n<hunkTotal())setActive(n);else{showDiffView(!1);const e=t.getAttribute("href")?.slice(1);e&&document.getElementById(e)?.scrollIntoView({block:"center"})}}function allQuickItems(){const e=sourceFiles.map(e=>({path:e.path,name:baseName(e.path),detail:[e.changed?"changed":"file",e.language||"text"].join(" - "),kind:"source",recent:!1}));links.forEach(t=>{const n=t.dataset.file||"";n&&!sourceByPath.has(n)&&e.push({path:n,name:baseName(n),detail:"diff",kind:"change",recent:!1})});const t=loadRecent(),n=new Map(t.map((e,t)=>[e.path,t]));return e.map(e=>({...e,recent:n.has(e.path),recentRank:n.get(e.path)??9999}))}function recentItems(){const e=allQuickItems(),t=new Map(e.map(e=>[e.path,e]));return loadRecent().map(e=>t.get(e.path)||{path:e.path,name:baseName(e.path),detail:"change"===e.kind?"diff":"file",kind:e.kind,recent:!0,recentRank:0}).map((e,t)=>({...e,recent:!0,recentRank:t}))}function scoreQuickItem(e,t){let n=e.recentRank??9999;if(!t)return n;const r=e.path.toLowerCase(),o=e.name.toLowerCase();return o===t?n-=3e3:o.startsWith(t)?n-=2e3:r.includes("/"+t)?n-=1e3:r.includes(t)&&(n-=500),e.recent&&(n-=100),n}function loadRecent(){try{const e=JSON.parse(localStorage.getItem(recentKey)||"[]");return Array.isArray(e)?e.filter(e=>e&&"string"==typeof e.path):[]}catch{return[]}}function rememberRecent(e,t){if(!e)return;const n=[{path:e,kind:t},...loadRecent().filter(t=>t.path!==e)].slice(0,30);try{localStorage.setItem(recentKey,JSON.stringify(n))}catch{}}function baseName(e){return String(e).split("/").filter(Boolean).pop()||String(e)}function isTreeRowVisible(e){for(var t=e;t;){var n=t.parentElement;if(!n||n.classList.contains("tab-panel"))return!0;if("DETAILS"===n.tagName&&!n.open&&"SUMMARY"!==t.tagName)return!1;t=n}return!0}function treeRows(){const e=document.querySelector(".tab-panel:not(.hidden)");return e?Array.from(e.querySelectorAll("summary, .file-link")).filter(isTreeRowVisible):[]}function focusTree(e){const t=treeRows();0!==t.length&&(treeFocusIndex=Math.max(0,Math.min(t.length-1,e)),scheduleTreeFocus())}var treeFocusRaf=0;function scheduleTreeFocus(){treeFocusRaf||(treeFocusRaf=requestAnimationFrame(function(){treeFocusRaf=0;const e=treeRows();if(treeFocusIndex<0||treeFocusIndex>=e.length)return;const t=e[treeFocusIndex];document.querySelectorAll(".tree-focus").forEach(e=>{e!==t&&e.classList.remove("tree-focus")}),t&&(t.classList.add("tree-focus"),scrolloffReveal(t,document.querySelector(".sidebar-scroll"),.15))}))}function clearTreeFocus(){treeFocusIndex=-1,document.querySelectorAll(".tree-focus").forEach(e=>e.classList.remove("tree-focus"))}function focusOpenFileInTree(){const e=treeRows();if(0===e.length)return;let t=document.getElementById("source-viewer")?.dataset.openPath||"";if(!t&&"function"==typeof diffActiveWrapper){const e=diffActiveWrapper(),n=e&&e.querySelector(".d2h-file-name");n&&n.textContent&&(t=n.textContent.trim())}let n=0;if(t)for(let r=0;r<e.length;r++){const o=e[r].dataset||{};if(o.sourceFile===t||o.file===t){n=r;break}}focusTree(n)}function treePageSize(){var e=document.querySelector(".sidebar-scroll"),t=e?e.clientHeight:320;return Math.max(1,Math.floor(t/20)-1)}function treeOpenKey(){return"monacori-tree-open:"+location.pathname}function loadTreeOpen(){try{return new Set(JSON.parse(sessionStorage.getItem(treeOpenKey())||"[]"))}catch(e){return new Set}}function saveTreeOpen(e){try{sessionStorage.setItem(treeOpenKey(),JSON.stringify(Array.from(e)))}catch(e){}}var treeRevealing=!1;function persistTreeToggle(e){var t=loadTreeOpen(),n=e.dataset.dir||"";e.open?t.add(n):t.delete(n),saveTreeOpen(t)}function initSourceTreeFolds(){var e=Array.prototype.slice.call(document.querySelectorAll(".source-dir"));if(e.length){var t=loadTreeOpen(),n=document.getElementById("source-viewer")&&document.getElementById("source-viewer").dataset.openPath||"";e.forEach(function(e){e.addEventListener("toggle",function(){treeRevealing||persistTreeToggle(e)})}),treeRevealing=!0,e.forEach(function(e){var r=e.dataset.dir||"",o=n&&(n===r||0===n.indexOf(r+"/"));e.open=t.has(r)||!!o}),setTimeout(function(){treeRevealing=!1},0)}}function revealTreeFor(e){if(e){treeRevealing=!0,document.querySelectorAll(".source-dir").forEach(function(t){var n=t.dataset.dir||"";!n||e!==n&&0!==e.indexOf(n+"/")||t.open||(t.open=!0)}),setTimeout(function(){treeRevealing=!1},0);var t=document.querySelector(".source-link.active");t&&t.scrollIntoView&&t.scrollIntoView({block:"nearest"})}}function handleTreeKey(e){const t=treeRows();if(0===t.length)return!1;treeFocusIndex>=t.length&&(treeFocusIndex=t.length-1);const n=t[treeFocusIndex],r=n&&"SUMMARY"===n.tagName;return"ArrowDown"===e.key?(e.preventDefault(),focusTree(treeFocusIndex+1),!0):"ArrowUp"===e.key?(e.preventDefault(),focusTree(treeFocusIndex-1),!0):"PageDown"===e.key?(e.preventDefault(),focusTree(treeFocusIndex+treePageSize()),!0):"PageUp"===e.key?(e.preventDefault(),focusTree(treeFocusIndex-treePageSize()),!0):"Enter"===e.key&&e.altKey?(e.preventDefault(),n&&"function"==typeof openTreeRowMenu&&openTreeRowMenu(n),!0):"Enter"===e.key?(e.preventDefault(),n&&n.classList.contains("file-link")?(n.click(),clearTreeFocus()):r&&n.parentElement&&(n.parentElement.open=!n.parentElement.open),!0):"ArrowRight"===e.key?(e.preventDefault(),r&&n.parentElement&&!n.parentElement.open?n.parentElement.open=!0:focusTree(treeFocusIndex+1),!0):"ArrowLeft"===e.key?(e.preventDefault(),r&&n.parentElement&&n.parentElement.open?n.parentElement.open=!1:focusTree(treeFocusIndex-1),!0):"Escape"===e.key&&(e.preventDefault(),clearTreeFocus(),!0)}function isFloatingModalOpen(){var e=document.getElementById("settings-modal");if(e&&!e.classList.contains("hidden"))return!0;var t=document.getElementById("history-view");return!(!t||t.classList.contains("hidden"))||(!!document.getElementById("goto-line")||isDockFocused())}!function(){var e=document.getElementById("diff2html-container");e&&e.addEventListener("wheel",function(t){Math.abs(t.deltaY)>=Math.abs(t.deltaX)&&0!==t.deltaY&&(e.scrollTop+=t.deltaY,t.preventDefault())},{passive:!1})}(),document.addEventListener("keydown",e=>{if(quickOpen?.classList.contains("hidden")||!handleQuickOpenKey(e)){var t=document.getElementById("usages");if(!t||t.classList.contains("hidden")||!handleUsagesKey(e)){var n,r=!(!(n=document.getElementById("settings-modal"))||n.classList.contains("hidden"));if((e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey&&"Quote"===e.code)return e.preventDefault(),void toggleDockMaximized();if(!r&&(e.metaKey||e.ctrlKey)&&!e.altKey&&("Slash"===e.code||"Period"===e.code||"?"===e.key||">"===e.key))return e.preventDefault(),void openMergedView("Slash"===e.code||"?"===e.key?"q":"c");if(!r&&(e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey&&("KeyN"===e.code||"n"===e.key||"N"===e.key))return e.preventDefault(),void openMemoView();if(!r&&(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("Digit9"===e.code||"9"===e.key)&&"function"==typeof toggleHistory)return e.preventDefault(),void toggleHistory();if(!isFloatingModalOpen()){if((e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&"1"===e.key){if(e.preventDefault(),isDiffViewVisible()){var o=diffActiveWrapper(),i=o&&o.querySelector(".d2h-file-name"),a=diffCursor&&diffCursor.path||(i?(i.textContent||"").trim():"");a&&sourceByPath.has(a)&&openSourceFile(a)}return setTab("files"),void focusOpenFileInTree()}if((e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("l"===e.key||"L"===e.key)){var s=document.activeElement;if(!s||"INPUT"!==s.tagName&&"TEXTAREA"!==s.tagName&&"SELECT"!==s.tagName)return e.preventDefault(),void openGotoLine()}if((e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("k"===e.key||"K"===e.key)){var c=document.activeElement;if(!c||"INPUT"!==c.tagName&&"TEXTAREA"!==c.tagName&&"SELECT"!==c.tagName)return e.preventDefault(),void copyCaretLocation()}if((e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&"0"===e.key)return e.preventDefault(),setTab("changes"),void focusOpenFileInTree();if("Tab"===e.key){const t=document.activeElement;if(!(t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName||"SELECT"===t.tagName))){if(e.preventDefault(),e.shiftKey){if(isDiffViewVisible()&&diffCursor){const e="new"===diffCursor.side?"old":"new",t=diffWrapperByPath(diffCursor.path);return void(isDiffCodeRow(t?diffRowAt(t,e,diffCursor.rowIndex):null)&&setDiffCursor(diffCursor.path,e,diffCursor.rowIndex,0,!0))}focusTree(treeFocusIndex>=0?treeFocusIndex:0)}else{clearTreeFocus();const e=document.getElementById("source-viewer")?.dataset.openPath||"";!isSourceViewerVisible()||!e||viewerCursor&&viewerCursor.path===e||setSourceCursor(e,viewerCursor?viewerCursor.lineIndex:0,0,!1,-1)}return}}if(!(e.altKey||e.metaKey||e.ctrlKey||"?"!==e.key&&">"!==e.key)){const t=document.activeElement;if(!(t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName||"SELECT"===t.tagName)))return e.preventDefault(),void openComposer("?"===e.key?"q":"c")}if(!e.altKey&&!e.metaKey&&!e.ctrlKey&&"<"===e.key){const t=document.activeElement;if(!(t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName||"SELECT"===t.tagName))){let t=isSourceViewerVisible()&&document.getElementById("source-viewer")?.dataset.openPath||"";if(!t&&"function"==typeof diffActiveWrapper){const e=diffActiveWrapper(),n=e&&e.querySelector(".d2h-file-name");n&&n.textContent&&(t=n.textContent.trim())}if(t&&currentFileSignature(t)){e.preventDefault();const n=!isFileViewed(t);return setFileViewed(t,n),void(n&&gotoNextUnviewedFile(t))}}}if(e.altKey&&!e.metaKey&&!e.ctrlKey&&("ArrowLeft"===e.key||"ArrowRight"===e.key)){var l=document.activeElement;if(!(l&&("INPUT"===l.tagName||"TEXTAREA"===l.tagName||"SELECT"===l.tagName))&&treeFocusIndex<0){var d="ArrowRight"===e.key?1:-1;if(isSourceViewerVisible()&&viewerCursor)return e.preventDefault(),void moveSourceWord(d,e.shiftKey);if(isDiffViewVisible()&&diffCursor)return e.preventDefault(),void moveDiffWord(d,e.shiftKey)}}if(treeFocusIndex<0&&("PageDown"===e.key||"PageUp"===e.key)&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&!e.shiftKey){var u=isDiffViewVisible()?document.getElementById("diff2html-container"):isSourceViewerVisible()?document.getElementById("source-body"):null;if(u)return e.preventDefault(),void(u.scrollTop+=("PageDown"===e.key?.9:-.9)*u.clientHeight)}if("Shift"!==e.key&&(lastShiftAt=0,lastShiftSide=0),!(treeFocusIndex>=0&&handleTreeKey(e))&&(!(treeFocusIndex<0)||e.metaKey||e.ctrlKey||e.altKey||!isSourceViewerVisible()||!handleSourceCaretKey(e))&&(!(treeFocusIndex<0)||e.metaKey||e.ctrlKey||e.altKey||!isDiffViewVisible()||!handleDiffCaretKey(e))){if("Shift"===e.key&&!e.repeat){const t=performance.now(),n=e.location;if(0!==n&&n===lastShiftSide&&t-lastShiftAt<300)return e.preventDefault(),lastShiftAt=0,lastShiftSide=0,void openQuickOpen("all");lastShiftAt=t,lastShiftSide=n}if((e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey&&"f"===e.key.toLowerCase())return e.preventDefault(),void openQuickOpen("content");if((e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&"e"===e.key.toLowerCase())return e.preventDefault(),void openQuickOpen("recent");if((e.metaKey||e.altKey)&&"Enter"===e.key&&isSourceViewerVisible()){if(isHttpFile(document.getElementById("source-viewer")?.dataset.openPath||""))return e.preventDefault(),void runHttpAtCaret()}if((e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&"ArrowDown"===e.key)return e.preventDefault(),void(isSourceViewerVisible()?goToSymbolUnderCursor():openDiffFileAtCaret());if((e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("b"===e.key||"B"===e.key)){var f=document.activeElement;if(f&&("INPUT"===f.tagName||"TEXTAREA"===f.tagName||"SELECT"===f.tagName))return;return e.preventDefault(),void(isSourceViewerVisible()?goToSymbolUnderCursor():isDiffViewVisible()&&goToSymbolFromDiff())}if((e.metaKey||e.ctrlKey)&&!e.altKey&&("ArrowLeft"===e.key||"ArrowRight"===e.key)&&isSourceViewerVisible()&&viewerCursor){e.preventDefault();const t=sourceByPath.get(viewerCursor.path);if(t&&t.embedded){const n=t.content.split(/\r?\n/),r="ArrowLeft"===e.key?0:(n[viewerCursor.lineIndex]||"").length;e.shiftKey?selectionAnchor||(selectionAnchor={lineIndex:viewerCursor.lineIndex,column:viewerCursor.column}):selectionAnchor=null,setSourceCursor(viewerCursor.path,viewerCursor.lineIndex,r,!0,-1),applySourceSelection()}return}if((e.metaKey||e.ctrlKey)&&!e.altKey&&("ArrowLeft"===e.key||"ArrowRight"===e.key)&&isDiffViewVisible()&&diffCursor){e.preventDefault();const t=diffWrapperByPath(diffCursor.path),n=t?diffRowAt(t,diffCursor.side,diffCursor.rowIndex):null,r=n?diffLineText(n).length:0;if("ArrowLeft"===e.key){if(diffCursor.column>0)setDiffCursor(diffCursor.path,diffCursor.side,diffCursor.rowIndex,0,!0);else if("new"===diffCursor.side){const e=t?diffRowAt(t,"old",diffCursor.rowIndex):null;isDiffCodeRow(e)&&setDiffCursor(diffCursor.path,"old",diffCursor.rowIndex,diffLineText(e).length,!0)}}else if(diffCursor.column<r)setDiffCursor(diffCursor.path,diffCursor.side,diffCursor.rowIndex,r,!0);else if("old"===diffCursor.side){isDiffCodeRow(t?diffRowAt(t,"new",diffCursor.rowIndex):null)&&setDiffCursor(diffCursor.path,"new",diffCursor.rowIndex,0,!0)}return}if((e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey&&("["===e.key||"]"===e.key||"{"===e.key||"}"===e.key)&&isSourceViewerVisible()&&sourceTabs.length>1)return e.preventDefault(),void cycleSourceTab("["===e.key||"{"===e.key?-1:1);if((e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey&&("["===e.key||"]"===e.key)){var m=document.activeElement;if(!(m&&("INPUT"===m.tagName||"TEXTAREA"===m.tagName||"SELECT"===m.tagName)))return e.preventDefault(),void("["===e.key?navBack():navForward())}if("F7"===e.key&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault();const t=e.shiftKey?-1:1,n=document.getElementById("source-viewer");if(t>0&&n&&!n.classList.contains("hidden")){const e=n.dataset.openPath||"",t=firstHunkForPath(e);if(t>=0&&!isFileViewed(e))return void setActive(t)}next(t)}}}}}}),quickInput?.addEventListener("input",()=>renderQuickOpenResults()),quickResults?.addEventListener("mousemove",e=>{const t=e.target.closest?.(".quick-open-item");t&&(quickActive=Number(t.dataset.index||0),updateQuickActive())}),quickResults?.addEventListener("click",e=>{const t=e.target.closest?.(".quick-open-item");if(!t)return;const n=Number(t.dataset.index||0);openQuickItem(quickItems[n])}),quickOpen?.addEventListener("click",e=>{e.target===quickOpen&&closeQuickOpen()}),document.getElementById("usages-results")?.addEventListener("mousemove",function(e){var t=e.target.closest&&e.target.closest(".usage-item");t&&(usageActive=Number(t.dataset.index||0),updateUsageActive())}),document.getElementById("usages-results")?.addEventListener("click",function(e){var t=e.target.closest&&e.target.closest(".usage-item");t&&openUsageItem(usageItems[Number(t.dataset.index||0)])}),document.getElementById("usages")?.addEventListener("click",function(e){e.target&&"usages"===e.target.id&&closeUsages()}),document.getElementById("changes-panel")?.addEventListener("click",e=>{const t=e.target&&e.target.closest?e.target.closest(".file-link"):null;if(!t)return;showDiffView(!1);const n=Number(t.dataset.hunk);!Number.isNaN(n)&&n>=0&&n<hunkTotal()&&(e.preventDefault(),setActive(n))}),document.getElementById("files-panel")?.addEventListener("click",e=>{const t=e.target&&e.target.closest?e.target.closest(".source-link"):null;t&&t.dataset.sourceFile&&openSourceFile(t.dataset.sourceFile)}),document.querySelectorAll(".tab").forEach(e=>{e.addEventListener("click",()=>setTab(e.dataset.tab||"changes"))}),document.querySelector(".activity-rail")?.addEventListener("click",e=>{const t=e.target.closest&&e.target.closest(".rail-btn[data-view]");if(!t)return;const n=t.dataset.view;"changes"===n?(setTab("changes"),isDiffViewVisible()||showDiffView(!1)):"files"===n?setTab("files"):"q"===n||"c"===n?toggleMergedRail(n):"memo"===n?openMemoView():"history"===n&&toggleHistory(),syncRail()}),document.getElementById("back-to-diff")?.addEventListener("click",()=>showDiffView(!0)),document.getElementById("source-tabs")?.addEventListener("click",function(e){var t=e.target&&e.target.closest&&e.target.closest(".source-tab-close");if(t)return e.stopPropagation(),e.preventDefault(),void closeSourceTab(t.getAttribute("data-close-path"));var n=e.target&&e.target.closest&&e.target.closest(".source-tab");n&&openSourceFile(n.getAttribute("data-tab-path"))}),document.getElementById("diff-viewed-toggle")?.addEventListener("click",function(){var e=document.getElementById("diff-viewed-toggle"),t=e&&e.dataset.file||"";t&&setFileViewed(t,!isFileViewed(t))}),document.getElementById("source-body")?.addEventListener("click",handleSourceClick),document.getElementById("source-body")?.addEventListener("click",function(e){var t=e.target&&e.target.closest&&e.target.closest(".image-preview");t&&openLightbox(t.getAttribute("src"),t.getAttribute("alt"))}),document.addEventListener("keydown",function(e){"Escape"===e.key&&lightboxOpen()&&(e.preventDefault(),e.stopPropagation(),closeLightbox())},!0),document.addEventListener("copy",handleSourceCopy),applyI18n(),populateHttpEnvSelect(),REVIEW_LAZY_LOAD||scheduleSymbolIndex();const restored=restoreUiState();if(!restored){const e=location.hash.match(/^#hunk-(\d+)$/),t=Boolean(document.querySelector("#diff2html-container .d2h-file-wrapper"));e?setActive(Number(e[1]),!1):t&&REVIEW_LAZY_LOAD?showDiffView(!1):openDefaultSourceFile()}function isDiffViewVisible(){var e=document.getElementById("diff-view");return Boolean(e&&!e.classList.contains("hidden"))}function diffActiveWrapper(){return document.querySelector("#diff2html-container .d2h-file-wrapper:not(.df-inactive)")||document.querySelector("#diff2html-container .d2h-file-wrapper")}initSourceTreeFolds(),syncRail(),!watchEnabled||window.monacoriMenu&&"function"==typeof window.monacoriMenu.onDiffUpdate||setInterval(checkForLiveUpdate,1500),window.addEventListener("beforeunload",saveUiState),function(){var e=document.getElementById("boot-overlay");e&&requestAnimationFrame(function(){requestAnimationFrame(function(){e.classList.add("hide"),setTimeout(function(){e.remove()},240)})})}(),function(){const e=document.querySelector(".sidebar-resizer");if(!e)return;const t="monacori-sidebar-width:"+location.pathname,n=localStorage.getItem(t);n&&document.documentElement.style.setProperty("--sidebar-width",n);let r=!1;e.addEventListener("mousedown",t=>{r=!0,e.classList.add("resizing"),document.body.style.userSelect="none",t.preventDefault()}),document.addEventListener("mousemove",e=>{if(!r)return;const t=parseFloat(getComputedStyle(document.body).getPropertyValue("--rail-width"))||0,n=Math.min(640,Math.max(180,e.clientX-t));document.documentElement.style.setProperty("--sidebar-width",n+"px")}),document.addEventListener("mouseup",()=>{if(r){r=!1,e.classList.remove("resizing"),document.body.style.userSelect="";try{localStorage.setItem(t,getComputedStyle(document.documentElement).getPropertyValue("--sidebar-width").trim())}catch(e){}}})}(),function(){const e=document.getElementById("diff2html-container");if(!e)return;e.setAttribute("aria-readonly","true"),e.querySelectorAll(".d2h-code-side-linenumber, .d2h-code-linenumber, .d2h-code-line-prefix").forEach(e=>e.setAttribute("contenteditable","false"));const t=e=>Boolean(e.target&&e.target.closest&&e.target.closest(".mc-comment-row")),n=e=>{t(e)||e.preventDefault()};e.addEventListener("focusin",e=>{t(e)||clearTreeFocus()}),e.addEventListener("mousedown",e=>{t(e)||clearTreeFocus()}),e.addEventListener("beforeinput",n),e.addEventListener("paste",n),e.addEventListener("drop",n),e.addEventListener("dragstart",n),e.addEventListener("keydown",e=>{t(e)||e.metaKey||e.ctrlKey||e.altKey||1!==e.key.length&&"Enter"!==e.key&&"Backspace"!==e.key&&"Delete"!==e.key&&"Tab"!==e.key||e.preventDefault()}),e.addEventListener("click",e=>{if(t(e))return;const n=diffRowInfoFromNode(e.target);n&&n.path&&setDiffCursor(n.path,n.side,n.rowIndex,0,!1)}),ensureDiffCursor()}();var wrapperPathMap=null;function diffWrapperPathKey(e){return e.dataset&&e.dataset.path||((e.querySelector(".d2h-file-name")||{}).textContent||"").trim()}function diffWrapperByPath(e){if(wrapperPathMap){var t=wrapperPathMap.get(e);if(t&&t.isConnected)return t}wrapperPathMap=new Map;for(var n=document.querySelectorAll("#diff2html-container .d2h-file-wrapper"),r=0;r<n.length;r++){var o=diffWrapperPathKey(n[r]);o&&wrapperPathMap.set(o,n[r])}return wrapperPathMap.get(e)||null}function diffSideTables(e){var t=e?e.querySelectorAll(".d2h-file-side-diff"):[];return{left:t[0]||null,right:t[t.length-1]||null}}function diffSideTable(e,t){var n=diffSideTables(e);return"old"===t?n.left:n.right}function diffRowsOf(e){return e?Array.prototype.slice.call(e.querySelectorAll("tr")).filter(function(e){return!e.classList.contains("mc-comment-row")&&!e.classList.contains("mc-spacer-row")}):[]}function diffRowAt(e,t,n){return diffRowsOf(diffSideTable(e,t))[n]||null}function diffCellCtn(e){return e?e.querySelector(".d2h-code-line-ctn"):null}function diffLineText(e){var t=diffCellCtn(e);return t&&t.textContent||""}function diffLineNumber(e){var t=e?e.querySelector(".d2h-code-side-linenumber"):null,n=t?parseInt((t.textContent||"").trim(),10):NaN;return isFinite(n)?n:null}function diffRowInfoFromNode(e){var t=e?1===e.nodeType?e:e.parentElement:null;if(!t||!t.closest)return null;var n=t.closest(".d2h-file-wrapper"),r=t.closest(".d2h-file-side-diff"),o=t.closest("tr");if(!n||!r||!o)return null;var i=n.querySelector(".d2h-file-name"),a=(i&&i.textContent?i.textContent:"").trim(),s=r===diffSideTables(n).left?"old":"new";if(!isDiffCodeRow(o))return null;var c=diffRowsOf(r).indexOf(o);return!a||c<0?null:{path:a,side:s,rowIndex:c}}function diffCaretDomPosition(e,t){if(!e)return null;for(var n,r=t,o=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);n=o.nextNode();){var i=n.textContent.length;if(r<=i)return{node:n,offset:r};r-=i}return{node:e,offset:e.childNodes.length}}var diffCaretSpan=null;function clearDiffCaret(){var e=document.getElementById("diff2html-container");e&&(e.querySelectorAll(".mc-diff-cursor-row").forEach(function(e){e.classList.remove("mc-diff-cursor-row")}),e.querySelectorAll(".code-cursor").forEach(function(e){var t=e.parentNode;t&&(t.removeChild(e),t.normalize&&t.normalize())})),diffCaretSpan=null}function renderDiffCaret(){if(clearDiffCaret(),diffCursor){var e=diffWrapperByPath(diffCursor.path);if(e){var t=diffRowAt(e,diffCursor.side,diffCursor.rowIndex);if(t){t.classList.add("mc-diff-cursor-row");var n=diffCellCtn(t);if(n){if(0===(n.textContent||"").length){var r=document.createElement("span");return r.className="code-cursor",r.setAttribute("aria-hidden","true"),r.style.position="absolute",n.appendChild(r),void(diffCaretSpan=r)}var o=diffCaretDomPosition(n,diffCursor.column);if(o){var i=document.createElement("span");i.className="code-cursor",i.setAttribute("aria-hidden","true");try{var a=3===o.node.nodeType?Math.min(o.offset,(o.node.textContent||"").length):o.offset,s=document.createRange();s.setStart(o.node,a),s.collapse(!0),s.insertNode(i),diffCaretSpan=i}catch(e){diffCaretSpan=null}}}}}}}function setDiffCursor(e,t,n,r,o){markCaretBusy();var i=diffWrapperByPath(e);if(i){var a=diffRowsOf(diffSideTable(i,t));if(a.length){var s=Math.max(0,Math.min(n,a.length-1)),c=Math.max(0,Math.min(r,diffLineText(a[s]).length));diffCursor={path:e,side:t,rowIndex:s,column:c},pendingFileBoundary=null,hideCaretHint(),diffSelectionAnchor=null,o?scheduleDiffReveal(i,t,s):(renderDiffCaret(),applyDiffSelection()),recordNav(navEntryOf("diff"))}}}var diffRevealRaf=0,diffRevealTarget=null;function scheduleDiffReveal(e,t,n){diffRevealTarget={wrapper:e,side:t,ri:n},diffRevealRaf||(diffRevealRaf=requestAnimationFrame(function(){diffRevealRaf=0;var e=diffRevealTarget;(diffRevealTarget=null,renderDiffCaret(),applyDiffSelection(),e)&&scrolloffReveal(diffRowAt(e.wrapper,e.side,e.ri),document.getElementById("diff2html-container"),.15)}))}function navEntryOf(e){return"diff"===e?diffCursor?{kind:"diff",path:diffCursor.path,side:diffCursor.side,rowIndex:diffCursor.rowIndex,column:diffCursor.column,line:diffCursor.rowIndex}:null:viewerCursor?{kind:"source",path:viewerCursor.path,lineIndex:viewerCursor.lineIndex,column:viewerCursor.column,line:viewerCursor.lineIndex}:null}function navSamePos(e,t){return!(!e||!t||e.kind!==t.kind||e.path!==t.path||e.line!==t.line||"diff"===e.kind&&e.side!==t.side)}function recordNav(e){if(!navSuppress&&e){var t=navPos>=0?navList[navPos]:null;if(navSamePos(t,e))navList[navPos]=e;else t&&t.kind===e.kind&&t.path===e.path&&Math.abs(t.line-e.line)<NAV_JUMP_LINES?navList[navPos]=e:(navList=navList.slice(0,navPos+1),navList.push(e),navPos=navList.length-1,navList.length>NAV_MAX&&(navList.shift(),navPos-=1))}}function revealDiffFile(e){document.getElementById("source-viewer")?.classList.add("hidden"),document.getElementById("diff-view")?.classList.remove("hidden"),setTab("changes"),showOnlyFile(e),links.forEach(function(t){t.classList.toggle("active",t.dataset.file===e)}),renderBreadcrumb(document.getElementById("diff-breadcrumb"),e)}function restoreNav(e){if(e){navSuppress=!0;try{"diff"===e.kind?(revealDiffFile(e.path),setDiffCursor(e.path,e.side,e.rowIndex,e.column,!0)):setSourceCursor(e.path,e.lineIndex,e.column,!0,-1)}finally{navSuppress=!1}}}function navBack(){if(!(navPos<0)){var e=navEntryOf(isSourceViewerVisible()?"source":"diff");!e||navSamePos(e,navList[navPos])?navPos>0&&(navPos-=1,restoreNav(navList[navPos])):restoreNav(navList[navPos])}}function navForward(){navPos<navList.length-1&&(navPos+=1,restoreNav(navList[navPos]))}function applyDiffSelection(){var e=window.getSelection();if(e)if(diffSelectionAnchor&&diffCursor&&diffSelectionAnchor.side===diffCursor.side){var t=diffWrapperByPath(diffCursor.path);if(t){var n=diffCellCtn(diffRowAt(t,diffSelectionAnchor.side,diffSelectionAnchor.rowIndex)),r=diffCellCtn(diffRowAt(t,diffCursor.side,diffCursor.rowIndex)),o=n?diffCaretDomPosition(n,diffSelectionAnchor.column):null,i=r?diffCaretDomPosition(r,diffCursor.column):null;if(o&&i)try{e.setBaseAndExtent(o.node,o.offset,i.node,i.offset)}catch(e){}}else try{e.removeAllRanges()}catch(e){}}else try{e.removeAllRanges()}catch(e){}}function isDiffCodeRow(e){if(!e)return!1;if(e.querySelector(".d2h-emptyplaceholder, .d2h-code-side-emptyplaceholder"))return!1;if(!e.querySelector(".d2h-code-line-ctn"))return!1;var t=e.querySelector(".d2h-code-side-linenumber");return!!t&&(t.textContent||"").trim().length>0}function firstDiffCodeRow(e,t){for(var n=diffRowsOf(diffSideTable(e,t)),r=0;r<n.length;r++)if(isDiffCodeRow(n[r]))return r;return-1}function ensureDiffCursor(){if(isDiffViewVisible()){var e=diffActiveWrapper();e&&whenFileReady(e,function(){var t=e.querySelector(".d2h-file-name"),n=(t&&t.textContent?t.textContent:"").trim();if(n)if(diffCursor&&diffCursor.path===n)renderDiffCaret();else{var r=firstDiffCodeRow(e,"new");r<0||setDiffCursor(n,"new",r,0,!1)}})}}function moveDiffCursor(e,t,n){if(diffCursor){var r=diffWrapperByPath(diffCursor.path);if(r){var o=diffCursor.side,i=diffRowsOf(diffSideTable(r,o)),a=diffCursor.rowIndex,s=diffCursor.column,c=diffLineText(i[a]),l=n?diffSelectionAnchor||{side:diffCursor.side,rowIndex:diffCursor.rowIndex,column:diffCursor.column}:null;if(t<0)if(s>0)s-=1;else{for(var d=a-1;d>=0&&!isDiffCodeRow(i[d]);)d-=1;d>=0&&(a=d,s=diffLineText(i[d]).length)}else if(t>0)if(s<c.length)s+=1;else{for(var u=a+1;u<i.length&&!isDiffCodeRow(i[u]);)u+=1;u<i.length&&(a=u,s=0)}if(0!==e){for(var f=diffRowsOf(diffSideTable(r,o)),m=e>0?1:-1,p=a+m;p>=0&&p<f.length&&!isDiffCodeRow(f[p]);)p+=m;p>=0&&p<f.length&&(a=p,s=Math.min(s,diffLineText(f[a]).length))}setDiffCursor(diffCursor.path,o,a,s,!0),l&&(diffSelectionAnchor=l,applyDiffSelection())}}}function moveDiffWord(e,t){if(diffCursor){var n=diffWrapperByPath(diffCursor.path);if(n){var r=nextWordBoundary(diffLineText(diffRowAt(n,diffCursor.side,diffCursor.rowIndex)),diffCursor.column,e);if(r!==diffCursor.column){var o=t?diffSelectionAnchor||{side:diffCursor.side,rowIndex:diffCursor.rowIndex,column:diffCursor.column}:null;setDiffCursor(diffCursor.path,diffCursor.side,diffCursor.rowIndex,r,!0),o&&(diffSelectionAnchor=o,applyDiffSelection())}}}}function diffCommentBoxSiblingOf(e){if(!diffCursor)return null;var t=diffWrapperByPath(diffCursor.path);if(!t)return null;var n=diffRowsOf(diffSideTable(t,"new"))[diffCursor.rowIndex];if(!n)return null;var r=e<0?n.previousElementSibling:n.nextElementSibling;return r&&r.classList&&r.classList.contains("mc-comment-row")?r:null}function handleDiffCaretKey(e){if(!isDiffViewVisible()||!diffCursor)return!1;var t=document.activeElement;if(t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName||"SELECT"===t.tagName))return!1;var n=e.shiftKey;if(selectedCommentRow){if("Backspace"===e.key||"Delete"===e.key)return e.preventDefault(),deleteCommentsInRow(selectedCommentRow),!0;if("e"===e.key||"E"===e.key)return e.preventDefault(),editCommentInRow(selectedCommentRow),!0;if("ArrowUp"===e.key||"ArrowDown"===e.key||"ArrowLeft"===e.key||"ArrowRight"===e.key||"Escape"===e.key){var r="ArrowUp"===e.key?-1:"ArrowDown"===e.key?1:0,o=r<0?selectedCommentRow.previousElementSibling:r>0?selectedCommentRow.nextElementSibling:null;selectedCommentRow.classList.remove("mc-row-selected"),selectedCommentRow=null,e.preventDefault();var i=diffWrapperByPath(diffCursor.path);if(o&&i&&isDiffCodeRow(o)){var a=diffRowsOf(diffSideTable(i,"new")).indexOf(o);if(a>=0)return setDiffCursor(diffCursor.path,"new",a,0,!0),!0}return setDiffCursor(diffCursor.path,diffCursor.side,diffCursor.rowIndex,diffCursor.column,!1),!0}return!1}if(!n&&("ArrowUp"===e.key||"ArrowDown"===e.key)){var s=diffCommentBoxSiblingOf("ArrowUp"===e.key?-1:1);if(s)return e.preventDefault(),selectCommentRow(s),!0}return"ArrowDown"===e.key?(e.preventDefault(),moveDiffCursor(1,0,n),!0):"ArrowUp"===e.key?(e.preventDefault(),moveDiffCursor(-1,0,n),!0):"ArrowLeft"===e.key?(e.preventDefault(),moveDiffCursor(0,-1,n),!0):"ArrowRight"===e.key&&(e.preventDefault(),moveDiffCursor(0,1,n),!0)}function showToast(e){var t=document.getElementById("mc-toasts");t||((t=document.createElement("div")).id="mc-toasts",document.body.appendChild(t));var n=document.createElement("div");n.className="mc-toast",n.textContent=e,t.appendChild(n),requestAnimationFrame(function(){n.classList.add("show")}),setTimeout(function(){n.classList.add("hide"),setTimeout(function(){n.parentNode&&n.parentNode.removeChild(n)},300)},4500)}var caretHintEl=null,caretHintTimer=0;function showCaretHint(e){var t=activeDiffRow||document.querySelector("#diff2html-container .diff-active-row");if(t&&t.getBoundingClientRect){caretHintEl||((caretHintEl=document.createElement("div")).className="mc-caret-hint",document.body.appendChild(caretHintEl)),caretHintEl.textContent=e;var n=t.getBoundingClientRect();caretHintEl.style.left=Math.round(Math.max(8,n.left))+"px",caretHintEl.style.top=Math.round(n.bottom+4)+"px",caretHintEl.classList.remove("show"),caretHintEl.offsetWidth,caretHintEl.classList.add("show"),caretHintTimer&&clearTimeout(caretHintTimer),caretHintTimer=setTimeout(function(){caretHintEl&&caretHintEl.classList.remove("show")},2e3)}else showToast(e)}function hideCaretHint(){caretHintTimer&&(clearTimeout(caretHintTimer),caretHintTimer=0),caretHintEl&&caretHintEl.classList.remove("show")}function remapComments(){if(reviewComments.length){var e=0;reviewComments.forEach(function(t){var n=sourceByPath.get(t.path);if(n&&n.embedded&&"string"==typeof n.content&&n.content){var r=null==t.code?"":String(t.code);if(r.trim()){var o=n.content.split(/\r?\n/);if(o[t.line-1]!==r){for(var i=-1,a=1/0,s=0;s<o.length;s++)if(o[s]===r){var c=Math.abs(s-(t.line-1));c<a&&(a=c,i=s)}i>=0&&t.line!==i+1&&(t.line=i+1,e++)}}}}),e&&(saveComments(),refreshComments())}}function saveComments(){persistSave(COMMENTS_KEY,reviewComments)}function commentsAt(e,t){return reviewComments.filter(function(n){return n.path===e&&n.line===t})}function commentKindLabel(e){return t("q"===e?"comment.kind.q":"comment.kind.c")}function relevantLines(e){var t={};return reviewComments.forEach(function(n){n.path===e&&(t[n.line]=!0)}),composerState&&composerState.path===e&&(t[composerState.line]=!0),Object.keys(t).map(Number).sort(function(e,t){return e-t})}function addComment(e,t,n,r,o){var i=String(o||"").trim();i&&(commentSeq+=1,reviewComments.push({seq:commentSeq,kind:e,path:t,line:n,code:String(r||""),text:i}),saveComments())}function updateComment(e,t){var n=reviewComments.find(function(t){return t.seq===e});if(n){var r=String(t||"").trim();r?(n.text=r,saveComments()):deleteComment(e)}}function deleteComment(e){reviewComments=reviewComments.filter(function(t){return t.seq!==e}),saveComments(),refreshComments()}function sourceRowLineOf(e){var t=e?1===e.nodeType?e:e.parentElement:null,n=t&&t.closest?t.closest(".source-row"):null;if(!n)return null;var r=parseInt(n.dataset.lineIndex,10);return isFinite(r)?r:null}function currentCommentTarget(){var e=window.getSelection(),t=e&&e.toString?e.toString():"",n=!!e&&!e.isCollapsed&&t.trim().length>0;if(isSourceViewerVisible()&&viewerCursor){if(n){var r=e.rangeCount?e.getRangeAt(0):null,o=r?sourceRowLineOf(r.startContainer):null,i=r?sourceRowLineOf(r.endContainer):null;null!=o&&null!=i||(o=selectionAnchor?selectionAnchor.lineIndex:viewerCursor.lineIndex,i=viewerCursor.lineIndex);var a=Math.min(o,i),s=Math.max(o,i);return{path:viewerCursor.path,line:s+1,code:t,from:a+1,to:s+1,side:null}}var c=sourceByPath.get(viewerCursor.path),l=c&&"string"==typeof c.content&&c.content.split(/\r?\n/)[viewerCursor.lineIndex]||"";return{path:viewerCursor.path,line:viewerCursor.lineIndex+1,code:l,from:null,to:null,side:null}}if(!n&&diffCursor&&isDiffViewVisible()){var d=diffWrapperByPath(diffCursor.path),u=d?diffRowAt(d,diffCursor.side,diffCursor.rowIndex):null,f=u?diffLineNumber(u):null;if(null!=f)return{path:diffCursor.path,line:f,code:diffLineText(u)||"",from:null,to:null,side:null}}var m=e&&e.rangeCount?e.getRangeAt(0):null,p=m?m.startContainer:e?e.anchorNode:null,h=m?m.endContainer:e?e.anchorNode:null,v=p?1===p.nodeType?p:p.parentElement:null,g=h?1===h.nodeType?h:h.parentElement:null,y=g&&g.closest&&g.closest(".d2h-file-wrapper")||document.querySelector("#diff2html-container .d2h-file-wrapper:not(.df-inactive)");if(!y)return null;var w=y.querySelector(".d2h-file-name"),C=(w&&w.textContent?w.textContent:"").trim();if(!C)return null;var b=g&&g.closest?g.closest("tr"):null;if(!b||!b.querySelector(".d2h-code-side-linenumber")){var S=y.querySelectorAll(".d2h-file-side-diff"),E=S[S.length-1],k=E?E.querySelector(".d2h-code-side-linenumber"):null;b=k?k.closest("tr"):null}if(!b)return null;var L=diffLineNumber(b);if(null==L)return null;var I=n&&v&&v.closest?v.closest("tr"):null,x=I?diffLineNumber(I):null;null==x&&(x=L);var A=g&&g.closest?g.closest(".d2h-file-side-diff"):null,T=diffSideTables(y),R=A&&A===T.left?"old":"new";return{path:C,line:L,code:n?t:"",from:n?Math.min(x,L):null,to:n?Math.max(x,L):null,side:R}}function composerTargetLabel(e){return((e.path||"").split("/").pop()||e.path||"")+":"+(null!=e.from&&null!=e.to&&e.from!==e.to?e.from+"–"+e.to:String(e.line))}function threadHtml(e,n){var r="";if(commentsAt(e,n).forEach(function(e){composerState&&composerState.editSeq===e.seq||(r+='<div class="mc-card mc-'+e.kind+'"><div class="mc-card-head"><span class="mc-kind">'+commentKindLabel(e.kind)+'</span><button type="button" class="mc-del" data-seq="'+e.seq+'" title="'+escapeHtml(t("composer.delete"))+'">×</button></div><div class="mc-card-body">'+escapeHtml(e.text)+"</div></div>")}),composerState&&composerState.path===e&&composerState.line===n){var o="q"===composerState.kind?t("composer.question"):t("composer.changeRequest");r+='<div class="mc-card mc-'+composerState.kind+' mc-composer"><div class="mc-card-head"><span class="mc-kind">'+commentKindLabel(composerState.kind)+'</span><span class="mc-target" title="'+escapeHtml(composerState.path||"")+'">'+escapeHtml(composerTargetLabel(composerState))+'</span></div><textarea class="mc-input" rows="3" placeholder="'+escapeHtml(o)+'">'+escapeHtml(composerState.editText||"")+'</textarea><div class="mc-actions"><button type="button" class="mc-btn mc-save">'+escapeHtml(t("composer.save"))+'</button><button type="button" class="mc-btn mc-ghost mc-cancel">'+escapeHtml(t("composer.cancel"))+'</button><span class="mc-hint">'+escapeHtml(t("composer.hint"))+"</span></div></div>"}return r}function injectThreadRow(e,t,n){if(e&&e.parentNode){var r=document.createElement("tr");r.className="mc-comment-row";var o=document.createElement("td");o.colSpan=e.classList&&e.classList.contains("source-row")&&e.children.length||2,o.className="mc-thread-cell",o.innerHTML=threadHtml(t,n),r.appendChild(o),e.parentNode.insertBefore(r,e.nextSibling)}}function renderDiffComments(){var e=document.getElementById("diff2html-container");e&&(e.querySelectorAll(".mc-comment-row").forEach(function(e){e.remove()}),e.querySelectorAll(".d2h-file-wrapper").forEach(function(e){var t=e.querySelector(".d2h-file-name"),n=(t&&t.textContent?t.textContent:"").trim();if(n){var r=relevantLines(n);if(r.length){var o=e.querySelectorAll(".d2h-file-side-diff"),i=o[o.length-1];if(i){var a=i.querySelectorAll("tr");r.forEach(function(e){for(var t=0;t<a.length;t++){var r=a[t].querySelector(".d2h-code-side-linenumber");if(r&&(r.textContent||"").trim()===String(e)){injectThreadRow(a[t],n,e);break}}})}}}}))}function renderSourceComments(){var e=document.getElementById("source-body");if(e){e.querySelectorAll(".mc-comment-row").forEach(function(e){e.remove()});var t=document.getElementById("source-viewer"),n=t&&t.dataset.openPath||"";n&&relevantLines(n).forEach(function(t){var r=e.querySelector('.source-row[data-line-index="'+(t-1)+'"]');r&&injectThreadRow(r,n,t)})}}function renderCommentBadges(){document.querySelectorAll(".mc-file-badge").forEach(function(e){e.remove()});var e={};function n(e){var n=document.createElement("span");n.className="mc-file-badge";var r="";return e.q&&(r+='<span class="mc-fb mc-fb-q" title="'+e.q+" "+escapeHtml(t("badge.questions"))+'">'+e.q+"</span>"),e.c&&(r+='<span class="mc-fb mc-fb-c" title="'+e.c+" "+escapeHtml(t("badge.changeRequests"))+'">'+e.c+"</span>"),n.innerHTML=r,n}function r(t,r,o){document.querySelectorAll(t).forEach(function(t){var i=e[t.dataset[r]||""];if(i){var a=t.querySelector(o);a?t.insertBefore(n(i),a):t.appendChild(n(i))}})}reviewComments.forEach(function(t){var n=e[t.path]||(e[t.path]={q:0,c:0});"q"===t.kind?n.q+=1:n.c+=1}),r(".change-row","file",".diffstat"),r(".source-link","sourceFile",".count")}function applyCommentSelectionHighlight(){if(document.querySelectorAll(".mc-sel-line").forEach(function(e){e.classList.remove("mc-sel-line")}),composerState&&null!=composerState.from&&null!=composerState.to){var e=composerState.from,t=composerState.to;if(isDiffViewVisible()){var n=diffWrapperByPath(composerState.path);if(!n)return;diffRowsOf(diffSideTable(n,composerState.side||"new")).forEach(function(n){var r=diffLineNumber(n);null!=r&&r>=e&&r<=t&&n.classList.add("mc-sel-line")})}else if(isSourceViewerVisible())for(var r=e;r<=t;r++){var o=document.querySelector('.source-row[data-line-index="'+(r-1)+'"]');o&&o.classList.add("mc-sel-line")}}}function refreshComments(){renderDiffComments(),isSourceViewerVisible()&&renderSourceComments(),renderCommentBadges(),applyCommentSelectionHighlight();for(var e=!1,t=document.querySelectorAll(".mc-composer .mc-input"),n=0;n<t.length;n++)if((!t[n].closest("#diff-view")||isDiffViewVisible())&&(!t[n].closest("#source-viewer")||isSourceViewerVisible())){e=!0;break}if(document.body.classList.toggle("mc-composing",e),composerState){var r=0,o=function(){var e=activeComposerInput();if(!e)return!0;if(document.activeElement===e)return!0;try{e.focus({preventScroll:!0})}catch(t){try{e.focus()}catch(e){}}try{e.selectionStart=e.selectionEnd=e.value.length}catch(e){}return document.activeElement===e};if(!o())var i=setInterval(function(){(o()||++r>12)&&clearInterval(i)},25)}}function openComposer(e){var t=currentCommentTarget();if(t){composerState={kind:e,path:t.path,line:t.line,code:t.code,from:t.from,to:t.to,side:t.side};try{var n=window.getSelection();n&&n.removeAllRanges()}catch(e){}refreshComments()}}function closeComposer(){composerState&&(composerState=null,refreshComments(),flushPendingDiffUpdate())}function activeComposerInput(){for(var e=document.querySelectorAll(".mc-composer .mc-input"),t=0;t<e.length;t++)if((!e[t].closest("#diff-view")||isDiffViewVisible())&&(!e[t].closest("#source-viewer")||isSourceViewerVisible()))return e[t];return e[0]||null}function saveComposer(e){if(composerState){var t=e||activeComposerInput();t&&(null!=composerState.editSeq?updateComment(composerState.editSeq,t.value):addComment(composerState.kind,composerState.path,composerState.line,composerState.code,t.value),composerState=null,refreshComments(),flushPendingDiffUpdate())}}function defaultMergePrompt(e){return t("q"===e?"mergePrompt.default.q":"mergePrompt.default.c")}var mergePromptsKey="monacori-merge-prompts";function loadMergePrompts(){var e=persistRead(mergePromptsKey);if(e&&"object"==typeof e)return e;try{var t=JSON.parse(localStorage.getItem(mergePromptsKey)||"{}");return t&&"object"==typeof t?t:{}}catch(e){return{}}}function mergePromptFor(e){var t=loadMergePrompts()[e];return"string"==typeof t&&t.trim()?t:defaultMergePrompt(e)}function saveMergePrompt(e,t){var n=loadMergePrompts();t&&t.trim()?n[e]=t:delete n[e],persistSave(mergePromptsKey,n)}function mergedCaretXY(e){var t=e.selectionStart||0,n=e.value.slice(0,t).split("\n"),r=n.length-1,o=n[r].length,i=getComputedStyle(e),a=parseFloat(i.lineHeight)||18,s=e.getBoundingClientRect(),c=document.createElement("span");c.style.cssText="position:absolute;visibility:hidden;white-space:pre",c.style.font=i.font,c.textContent="MMMMMMMMMMMMMMMMMMMM",document.body.appendChild(c);var l=c.getBoundingClientRect().width/20;c.remove();var d=s.top+(parseFloat(i.paddingTop)||0)+r*a-e.scrollTop;return{x:Math.min(s.left+(parseFloat(i.paddingLeft)||0)+o*l,s.right-24),top:d,below:d+a+2}}function showCustomDropdown(e,t,n,r){var o=document.getElementById("mc-dropdown");o&&o.remove();var i=document.createElement("div");i.id="mc-dropdown",i.className="mc-dropdown";var a=0;function s(e){a=e;for(var t=0;t<i.children.length;t++)i.children[t].classList.toggle("active",t===e)}function c(){i.remove(),document.removeEventListener("keydown",l,!0),document.removeEventListener("mousedown",d,!0)}function l(e){if("ArrowDown"===e.key)e.preventDefault(),e.stopPropagation(),s(Math.min(a+1,n.length-1));else if("ArrowUp"===e.key)e.preventDefault(),e.stopPropagation(),s(Math.max(a-1,0));else if("Enter"===e.key){e.preventDefault(),e.stopPropagation();var t=n[a];c(),t&&t.onSelect()}else"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),c())}function d(e){i.contains(e.target)||c()}n.forEach(function(e,t){var n=document.createElement("button");n.type="button",n.className="mc-dropdown-item"+(0===t?" active":""),n.textContent=e.label,n.addEventListener("click",function(){c(),e.onSelect()}),n.addEventListener("mousemove",function(){s(t)}),i.appendChild(n)}),document.body.appendChild(i);var u=i.getBoundingClientRect(),f=t,m=e;"number"==typeof r&&f+u.height>window.innerHeight-8?f=Math.max(8,r-u.height):f+u.height>window.innerHeight-8&&(f=Math.max(8,window.innerHeight-u.height-8)),m+u.width>window.innerWidth-8&&(m=Math.max(8,window.innerWidth-u.width-8)),i.style.left=Math.round(m)+"px",i.style.top=Math.round(f)+"px",document.addEventListener("keydown",l,!0),document.addEventListener("mousedown",d,!0)}function mergedCommentSeqs(e,t,n){for(var r=reviewComments.filter(function(t){return t.kind===e}),o=buildMergedText(e).split(String.fromCharCode(10)),i=[],a=0,s=-1,c=0;c<o.length;c++){var l=a,d=a+o[c].length;if(0===o[c].indexOf("### ")&&s++,s>=0&&s<r.length&&d>=t&&l<=n){var u=r[s].seq;i.indexOf(u)<0&&i.push(u)}a=d+1}return i}function navigateToComment(e){var t=reviewComments.find(function(t){return t.seq===e});t&&(openSourceFile(t.path),requestAnimationFrame(function(){setSourceCursor(t.path,Math.max(0,(t.line||1)-1),0,!0,-1)}))}function jumpMergedComment(e,t){var n=e.value,r=[],o=0;if(n.split("\n").forEach(function(e){0===e.indexOf("### ")&&r.push(o),o+=e.length+1}),r.length){var i,a=e.selectionStart;if(t>0)null==(i=r.find(function(e){return e>a}))&&(i=r[r.length-1]);else{var s=r.filter(function(e){return e<a});i=s.length?s[s.length-1]:r[0]}e.selectionStart=e.selectionEnd=i;var c=n.slice(0,i).split("\n").length-1,l=parseFloat(getComputedStyle(e).lineHeight)||18;e.scrollTop=Math.max(0,c*l-e.clientHeight/2)}}function buildMergedText(e){var n=reviewComments.filter(function(t){return t.kind===e}),r=String.fromCharCode(10),o=[];return o.push(mergePromptFor(e)),o.push(""),o.push(t("q"===e?"merged.qHeading":"merged.cHeading")+" ("+n.length+")"),o.push(""),n.forEach(function(e){o.push("### "+e.path+":"+e.line),e.code&&e.code.trim()&&o.push("> "+e.code.trim()),o.push(e.text),o.push("")}),o.join(r)}var dockHeightKey="monacori-dock-height",dockMaximized=!1;function applyDockHeight(e){var t=Math.max(140,Math.min(e,window.innerHeight-120));document.documentElement.style.setProperty("--dock-height",t+"px")}function activeDockPanel(){var e=document.getElementById("mc-merged-panel")||document.getElementById("mc-memo-panel");if(e)return e;var t=document.getElementById("terminal-panel");return t&&!t.classList.contains("hidden")?t:null}function applyDockMaximized(){activeDockPanel()||(dockMaximized=!1),document.body.classList.toggle("dock-maximized",dockMaximized)}function toggleDockMaximized(){if(!(treeFocusIndex>=0)){var e=document.activeElement;e&&e.closest&&(e.closest(".dock-panel")||e.closest(".terminal-panel"))&&activeDockPanel()&&(dockMaximized=!dockMaximized,applyDockMaximized())}}function isDockFocused(){var e=document.activeElement;return!!(e&&e.closest&&e.closest(".dock-panel"))}function closeMergedMemoDocks(){var e=document.getElementById("mc-merged-panel");e&&e.remove();var t=document.getElementById("mc-memo-panel");t&&t.remove(),document.querySelectorAll(".dock-backdrop").forEach(function(e){e.remove()}),document.body.classList.toggle("dock-open",!!activeDockPanel()),document.body.classList.toggle("floating-dock",!(!document.getElementById("mc-merged-panel")&&!document.getElementById("mc-memo-panel"))),applyDockMaximized(),"function"==typeof syncRail&&syncRail()}function focusDockField(e,t){var n=0,r=function(){if(!document.querySelector(t))return!0;if(document.activeElement===e)return!0;try{e.focus()}catch(e){}return document.activeElement===e};if(!r())var o=setInterval(function(){(r()||++n>12)&&clearInterval(o)},25)}function mountDock(e,n){if(window.__monacoriTerminal&&"function"==typeof window.__monacoriTerminal.close)try{window.__monacoriTerminal.close()}catch(e){}var r=document.getElementById(e);r&&r.remove(),closeMergedMemoDocks();var o=document.createElement("div");o.id=e,o.className="dock-panel",o.tabIndex=-1;var i=document.createElement("div");i.className="dock-backdrop";var a=document.createElement("div");a.className="dock-resizer",a.setAttribute("aria-hidden","true");var s=document.createElement("div");s.className="dock-bar";var c=document.createElement("span");c.className="dock-title",c.textContent=n;var l=document.createElement("button");l.type="button",l.className="dock-btn dock-max",l.setAttribute("data-i18n-title","dock.maximize"),l.title=t("dock.maximize"),l.textContent="⤢";var d=document.createElement("button");d.type="button",d.className="dock-btn dock-close",d.setAttribute("data-i18n","merged.close"),d.textContent=t("merged.close");var u=document.createElement("div");function f(){o.remove(),i.remove(),closeMergedMemoDocks()}return u.className="dock-body",s.appendChild(c),s.appendChild(l),s.appendChild(d),o.appendChild(a),o.appendChild(s),o.appendChild(u),document.body.appendChild(i),document.body.appendChild(o),l.addEventListener("click",function(){toggleDockMaximized()}),d.addEventListener("click",f),i.addEventListener("click",f),o.addEventListener("keydown",function(e){"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),f())}),a.addEventListener("mousedown",function(e){function t(e){applyDockHeight(window.innerHeight-e.clientY)}e.preventDefault(),a.classList.add("resizing"),document.addEventListener("mousemove",t),document.addEventListener("mouseup",function e(){a.classList.remove("resizing"),document.removeEventListener("mousemove",t),document.removeEventListener("mouseup",e);var n=parseInt(getComputedStyle(document.documentElement).getPropertyValue("--dock-height"),10);if(n)try{localStorage.setItem(dockHeightKey,String(n))}catch(e){}})}),document.body.classList.add("dock-open"),document.body.classList.add("floating-dock"),applyDockMaximized(),"function"==typeof syncRail&&syncRail(),{panel:o,body:u,bar:s,close:f}}function openMergedView(e){var n=mountDock("mc-merged-panel",t("q"===e?"merged.qTitle":"merged.cTitle"));n.panel.dataset.kind=e;var r=document.createElement("textarea");r.className="mc-modal-text",r.value=buildMergedText(e),r.addEventListener("beforeinput",function(e){e.preventDefault()}),r.addEventListener("keydown",function(o){if(o.altKey&&("ArrowDown"===o.key||"ArrowUp"===o.key))return o.preventDefault(),o.stopPropagation(),void jumpMergedComment(r,"ArrowDown"===o.key?1:-1);if(o.altKey&&("Enter"===o.key||"Enter"===o.code)){o.preventDefault(),o.stopPropagation();var i=mergedCommentSeqs(e,r.selectionStart,r.selectionEnd);if(i.length){var a=mergedCaretXY(r),s=a.x,c=a.below,l=a.top,d=function(){reviewComments.filter(function(t){return t.kind===e}).length?r.value=buildMergedText(e):n.close()};if(r.selectionStart!==r.selectionEnd||i.length>1){var u=[];window.__monacoriTerminal&&"function"==typeof window.__monacoriTerminal.paneCount&&window.__monacoriTerminal.paneCount()>0&&u.push({label:t("merged.sendToTerminal"),onSelect:function(){var t=buildMergedText(e);n.close(),window.__monacoriTerminal.enterSendMode(t)}}),u.push({label:t("dropdown.remove"),onSelect:function(){i.forEach(deleteComment),d()}}),showCustomDropdown(s,c,u,l)}else{var f=i[0];showCustomDropdown(s,c,[{label:t("dropdown.navigate"),onSelect:function(){n.close(),navigateToComment(f)}},{label:t("dropdown.remove"),onSelect:function(){deleteComment(f),d()}}],l)}}}}),n.body.appendChild(r),focusDockField(r,"#mc-merged-panel")}!function(){var e=parseInt(localStorage.getItem(dockHeightKey)||"",10);e&&applyDockHeight(e)}(),window.__monacoriCloseDocks=closeMergedMemoDocks;var memoKey="monacori-memo";function loadMemo(){var e=persistRead(memoKey);if("string"==typeof e)return e;try{var t=localStorage.getItem(memoKey);return"string"==typeof t?t:""}catch(e){return""}}function saveMemo(e){persistSave(memoKey,e||"")}function renderMemoMd(e){return e&&e.trim()?renderMarkdownBlocks(e).map(function(e){return e.html}).join(""):'<div class="mc-memo-empty" data-i18n="memo.previewEmpty">'+escapeHtml(t("memo.previewEmpty"))+"</div>"}function openMemoView(){if(document.getElementById("mc-memo-panel"))closeMergedMemoDocks();else{var e=mountDock("mc-memo-panel",t("memo.title")),n=document.createElement("div");n.className="mc-memo-body";var r=document.createElement("textarea");r.className="mc-modal-text mc-memo-edit",r.spellcheck=!1,r.setAttribute("data-i18n-ph","memo.placeholder"),r.placeholder=t("memo.placeholder"),r.value=loadMemo();var o=document.createElement("div");if(o.className="md-cell mc-memo-preview",o.innerHTML=renderMemoMd(r.value),r.addEventListener("input",function(){saveMemo(r.value),o.innerHTML=renderMemoMd(r.value)}),window.__monacoriTerminal&&"function"==typeof window.__monacoriTerminal.paneCount&&window.__monacoriTerminal.paneCount()>0){var i=document.createElement("button");i.type="button",i.className="dock-btn mc-send-term",i.setAttribute("data-i18n","merged.sendToTerminal"),i.textContent=t("merged.sendToTerminal"),i.addEventListener("click",function(){var t=r.value;e.close(),window.__monacoriTerminal.enterSendMode(t)}),e.bar.insertBefore(i,e.bar.querySelector(".dock-max"))}n.appendChild(r),n.appendChild(o),e.body.appendChild(n),focusDockField(r,"#mc-memo-panel")}}function setTab(e){"files"===e&&ensureTreeRendered(),document.querySelectorAll(".tab").forEach(t=>{t.classList.toggle("active",t.dataset.tab===e)}),document.getElementById("changes-panel")?.classList.toggle("hidden","changes"!==e),document.getElementById("files-panel")?.classList.toggle("hidden","files"!==e),syncRail()}function syncRail(){var e=document.querySelector(".activity-rail");if(e){var t=function(t,n){var r=e.querySelector('[data-view="'+t+'"]');r&&r.classList.toggle("is-active",!!n)};t("changes",!document.getElementById("changes-panel")?.classList.contains("hidden")),t("files",!document.getElementById("files-panel")?.classList.contains("hidden"));var n=document.getElementById("mc-merged-panel");t("q",!(!n||"q"!==n.dataset.kind)),t("c",!(!n||"c"!==n.dataset.kind)),t("memo",!!document.getElementById("mc-memo-panel"));var r=document.getElementById("history-view");t("history",!(!r||r.classList.contains("hidden")))}}function toggleMergedRail(e){var t=document.getElementById("mc-merged-panel");t&&t.dataset.kind===e?closeMergedMemoDocks():openMergedView(e)}function ensureTreeRendered(){var e=document.getElementById("files-panel"),n=document.getElementById("files-tree-html");if(e&&n){var r=n.textContent||"";n.parentNode&&n.parentNode.removeChild(n),e.innerHTML='<div class="empty-nav">'+escapeHtml(t("source.buildingTree"))+"</div>",setTimeout(function(){if(e.innerHTML=r,sourceLinks=Array.from(document.querySelectorAll(".source-link")),"function"==typeof refreshComments)try{refreshComments()}catch(e){}},0)}}function showDiffView(e){if(document.getElementById("source-viewer")?.classList.add("hidden"),document.getElementById("diff-view")?.classList.remove("hidden"),setTab("changes"),current<0&&hunkTotal())setActive(0,e);else if(current>=0){const t=current;whenFileReady(diffWrapperByPath(hunkPathAt(t)),function(){const n=document.getElementById("hunk-"+t);n&&(showOnlyFile(hunkPathAt(t)),e&&n.scrollIntoView({block:"start"}))})}}function showSourceView(){document.getElementById("diff-view")?.classList.add("hidden"),document.getElementById("source-viewer")?.classList.remove("hidden"),setTab("files")}function saveUiState(){const e=document.querySelector(".tab.active")?.dataset.tab||"changes",t=document.getElementById("source-viewer")?.dataset.openPath||"";sessionStorage.setItem(uiStateKey,JSON.stringify({tab:e,view:document.getElementById("source-viewer")?.classList.contains("hidden")?"diff":"source",sourcePath:t,hash:location.hash,tabs:sourceTabs,diffCursor:diffCursor,viewerCursor:viewerCursor}))}function restoreUiState(){const e=sessionStorage.getItem(uiStateKey);if(!e)return!1;try{const r=JSON.parse(e);if(Array.isArray(r.tabs)&&(sourceTabs=r.tabs.filter(function(e){return sourceByPath.has(e)})),"diff"===r.view){const e=String(r.hash||location.hash||"").match(/^#hunk-(\d+)$/);if(setActive(e?Number(e[1]):current>=0?current:0,!1),r.diffCursor&&r.diffCursor.path){var t=r.diffCursor;setTimeout(function(){try{setDiffCursor(t.path,t.side,t.rowIndex,t.column,!0)}catch(e){}},60)}return!0}if(r.sourcePath&&sourceByPath.has(r.sourcePath)){if(openSourceFile(r.sourcePath),r.viewerCursor&&r.viewerCursor.path===r.sourcePath){var n=r.viewerCursor;setTimeout(function(){try{setSourceCursor(r.sourcePath,n.lineIndex,n.column,!0,-1)}catch(e){}},60)}return!0}}catch{sessionStorage.removeItem(uiStateKey)}return!1}document.addEventListener("click",function(e){var t=e.target;if(t&&t.closest){var n=t.closest(".mc-del");return n?(e.preventDefault(),void deleteComment(parseInt(n.dataset.seq,10))):t.closest(".mc-save")?(e.preventDefault(),void saveComposer()):t.closest(".mc-cancel")?(e.preventDefault(),void closeComposer()):void 0}}),document.addEventListener("keydown",function(e){var t=e.target;if(t&&t.classList&&t.classList.contains("mc-input"))return"Escape"===e.key?(e.preventDefault(),e.stopPropagation(),void closeComposer()):(e.metaKey||e.ctrlKey)&&"Enter"===e.key?(e.preventDefault(),e.stopPropagation(),void saveComposer(t)):void 0},!0),refreshComments(),function(){if(window.monacoriPty){var e=document.getElementById("terminal-panel"),n=document.getElementById("terminal-host"),r=document.getElementById("terminal-toggle"),o=document.getElementById("terminal-close"),i=e?e.querySelector(".terminal-resizer"):null;if(e&&n){r&&r.classList.remove("hidden");var a=[],s=null,c="monacori-terminal-height",l="monacori-terminal-open:"+location.pathname,d=parseInt(localStorage.getItem(c)||"",10);d&&p(d),window.monacoriPty.onData(function(e){for(var t=0;t<a.length;t++)if(a[t].id===e.id)return void a[t].term.write(e.data)}),window.monacoriPty.onExit(function(e){!function(e){for(var t=0;t<a.length;t++)if(a[t].id===e)return void C(a[t])}(e.id)}),r&&r.addEventListener("click",function(){S(!b())}),o&&o.addEventListener("click",function(){S(!1)}),window.monacoriMenu&&"function"==typeof window.monacoriMenu.onTerminalToggle&&window.monacoriMenu.onTerminalToggle(function(){if(b()){var t=document.activeElement;if(t&&e.contains(t))S(!1);else if(s)try{s.term.focus()}catch(e){}}else S(!0)}),window.monacoriMenu&&"function"==typeof window.monacoriMenu.onTerminalSplit&&window.monacoriMenu.onTerminalSplit(function(){a.length>=4||(y(),v())}),window.monacoriMenu&&"function"==typeof window.monacoriMenu.onTerminalPaneFocus&&window.monacoriMenu.onTerminalPaneFocus(function(e){if(!(a.length<2)){var t=a.indexOf(s);t<0&&(t=0),g(a[(t+e+a.length)%a.length])}}),window.monacoriMenu&&"function"==typeof window.monacoriMenu.onTerminalPaneRename&&window.monacoriMenu.onTerminalPaneRename(function(){w(s)});var u="function"==typeof ResizeObserver?new ResizeObserver(function(){b()&&v()}):null;u&&u.observe(n),window.addEventListener("resize",function(){b()&&v()}),i&&i.addEventListener("mousedown",function(e){function t(e){p(window.innerHeight-e.clientY)}e.preventDefault(),i.classList.add("resizing"),document.addEventListener("mousemove",t),document.addEventListener("mouseup",function e(){i.classList.remove("resizing"),document.removeEventListener("mousemove",t),document.removeEventListener("mouseup",e);var n=parseInt(getComputedStyle(document.documentElement).getPropertyValue("--terminal-height"),10);if(n)try{localStorage.setItem(c,String(n))}catch(e){}v()})}),window.addEventListener("beforeunload",function(){a.forEach(function(e){if(null!=e.id)try{window.monacoriPty.kill({id:e.id})}catch(e){}})});var f=null,m=0;document.addEventListener("keydown",function(e){if(null!=f)if(e.preventDefault(),e.stopPropagation(),"ArrowLeft"===e.key||"ArrowRight"===e.key||"ArrowUp"===e.key||"ArrowDown"===e.key){var t="ArrowRight"===e.key||"ArrowDown"===e.key?1:-1;m=(m+t+a.length)%a.length,k()}else if("Enter"===e.key){var n=a[m],r=f;L(),E(n,r)}else"Escape"===e.key&&L()},!0),window.__monacoriTerminal={isOpen:b,hasFocus:function(){var t=document.activeElement;return!(!t||!e.contains(t))},open:function(){S(!0)},paneCount:function(){return a.length},closeActivePane:function(){var e=s||a[a.length-1];if(e){if(null!=e.id)try{window.monacoriPty.kill({id:e.id})}catch(e){}C(e)}else S(!1)},enterSendMode:function(t){0!==a.length&&(S(!0),f=t,m=Math.max(0,a.indexOf(s)),e.classList.add("send-mode"),document.body.classList.add("terminal-send-mode"),k())},send:function(e){E(s||a[0],e)},sendToPane:function(e,t){E(a[e]||s||a[0],t)},close:function(){S(!1)}};try{"1"===sessionStorage.getItem(l)&&S(!0)}catch(e){}}}function p(e){var t=Math.max(120,Math.min(e,window.innerHeight-120));document.documentElement.style.setProperty("--terminal-height",t+"px")}function h(e){if(e)try{e.fit.fit(),null!=e.id&&window.monacoriPty.resize({id:e.id,cols:e.term.cols,rows:e.term.rows})}catch(e){}}function v(){a.forEach(h)}function g(e){s=e,e&&e.labelEl&&e.labelEl.classList.remove("has-bell"),a.forEach(function(t){t.el.classList.toggle("is-active",t===e),t.el.classList.toggle("is-inactive",a.length>1&&t!==e)}),e&&requestAnimationFrame(function(){try{if(e.labelEl&&"true"===e.labelEl.getAttribute("contenteditable"))return;e.term.focus()}catch(e){}})}function y(){if(!function(){if("function"==typeof window.Terminal)return!0;var e=document.getElementById("xterm-code");if(!e)return!1;try{var t=document.createElement("script");t.textContent=e.textContent,document.head.appendChild(t),e.remove()}catch(e){return!1}return"function"==typeof window.Terminal}())return null;var e=document.createElement("div");e.className="terminal-pane";var r=document.createElement("div");r.className="terminal-pane-label";var o=document.createElement("div");o.className="terminal-pane-host",e.appendChild(r),e.appendChild(o),n.appendChild(e);var i=new window.Terminal({fontSize:12,fontFamily:"Monaco, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",theme:{background:"#161616",foreground:"#a9b7c6",cursor:"#a9b7c6",selectionBackground:"#214283"},cursorBlink:!0}),c=new window.FitAddon.FitAddon;i.loadAddon(c),i.open(o);var l={id:null,term:i,fit:c,el:e,labelEl:r,name:"Terminal "+(a.length+1)};r.textContent=l.name,i.attachCustomKeyEventHandler(function(e){if("keydown"===e.type&&e.metaKey){var t=(e.key||"").toLowerCase();if("meta"===t||"control"===t||"alt"===t||"shift"===t)return!0;if("KeyC"===e.code&&i.hasSelection&&i.hasSelection())return function(e){if(e){try{if(window.monacoriClipboard&&window.monacoriClipboard.write)return void window.monacoriClipboard.write(e)}catch(e){}try{navigator.clipboard&&navigator.clipboard.writeText&&navigator.clipboard.writeText(e)}catch(e){}}}(i.getSelection()),!1;if("KeyC"===e.code||"KeyV"===e.code||"KeyX"===e.code||"KeyA"===e.code)return!0;try{i.blur()}catch(e){}return!1}return!0}),i.onData(function(e){null!=l.id&&window.monacoriPty.write({id:l.id,data:e})}),i.onBell(function(){if(l!==s&&l.labelEl&&l.labelEl.classList.add("has-bell"),!1!==persistRead("monacori-terminal-bell-notify"))try{window.monacoriPty.bell({title:"monacori",body:l.name+" — "+t("notify.bellBody")})}catch(e){}}),e.addEventListener("mousedown",function(e){e.target!==r&&g(l)}),r.addEventListener("dblclick",function(){w(l)}),a.push(l);try{c.fit()}catch(e){}return window.monacoriPty.spawn({cols:i.cols||80,rows:i.rows||24}).then(function(e){l.id=e&&e.id}),g(l),l}function w(e){if(e||(e=s),e){var t=e.labelEl;if("true"!==t.getAttribute("contenteditable")){g(e),t.contentEditable="true";var n=0,r=function(){if("true"!==t.getAttribute("contenteditable"))return!0;try{t.focus()}catch(e){}if(document.activeElement!==t)return!1;try{var e=document.createRange();e.selectNodeContents(t);var n=window.getSelection();n.removeAllRanges(),n.addRange(e)}catch(e){}return!0};if(!r())var o=setInterval(function(){(r()||++n>12)&&clearInterval(o)},25);t.addEventListener("keydown",a),t.addEventListener("blur",c)}}function i(n){t.removeEventListener("keydown",a),t.removeEventListener("blur",c),t.contentEditable="false",n&&(e.name=(t.textContent||"").trim()||e.name),t.textContent=e.name;try{e.term&&e.term.focus()}catch(e){}}function a(e){e.stopPropagation(),"Enter"===e.key?(e.preventDefault(),i(!0)):"Escape"===e.key&&(e.preventDefault(),i(!1))}function c(){i(!0)}}function C(e){var t=a.indexOf(e);if(!(t<0)){try{e.term.dispose()}catch(e){}e.el.parentNode&&e.el.parentNode.removeChild(e.el),a.splice(t,1),s===e&&g(a[a.length-1]||null),0===a.length?S(!1):v()}}function b(){return!e.classList.contains("hidden")}function S(t){if(t&&"function"==typeof window.__monacoriCloseDocks)try{window.__monacoriCloseDocks()}catch(e){}e.classList.toggle("hidden",!t),document.body.classList.toggle("terminal-open",t),r&&r.classList.toggle("is-active",t);try{sessionStorage.setItem(l,t?"1":"0")}catch(e){}"function"==typeof applyDockMaximized&&applyDockMaximized(),t&&(0===a.length&&y(),requestAnimationFrame(function(){if(v(),s)try{s.term.focus()}catch(e){}}))}function E(e,t){e&&(S(!0),null!=e.id&&window.monacoriPty.write({id:e.id,data:t}),g(e),requestAnimationFrame(function(){try{e.term.focus()}catch(e){}}))}function k(){a.forEach(function(e,t){e.el.classList.toggle("is-send-target",t===m),e.el.classList.toggle("is-dimmed",t!==m)})}function L(){null!=f&&(f=null,e.classList.remove("send-mode"),document.body.classList.remove("terminal-send-mode"),a.forEach(function(e){e.el.classList.remove("is-send-target","is-dimmed")}))}}(),window.monacoriMenu&&"function"==typeof window.monacoriMenu.onMergedView&&window.monacoriMenu.onMergedView(function(e){openMergedView(e)}),window.monacoriMenu&&"function"==typeof window.monacoriMenu.onOpenMemo&&window.monacoriMenu.onOpenMemo(function(){openMemoView()}),window.monacoriMenu&&"function"==typeof window.monacoriMenu.onDiffUpdate&&window.monacoriMenu.onDiffUpdate(function(e){try{applyDiffUpdate(e)}catch(e){}}),window.monacoriMenu&&"function"==typeof window.monacoriMenu.onCloseTab&&window.monacoriMenu.onCloseTab(function(){var e=window.__monacoriTerminal;e&&e.isOpen()&&e.hasFocus()?e.closeActivePane():isSourceViewerVisible()&&closeActiveSourceTab()}),function(){var e=window.__MONACORI_VERSION__||"";if(e){var n=function(n){if(n){var r=document.getElementById("app-info-status");if(function(e,t){for(var n=String(e).split("."),r=String(t).split("."),o=0;o<3;o++){var i=parseInt(n[o],10)||0,a=parseInt(r[o],10)||0;if(i>a)return!0;if(i<a)return!1}return!1}(n,e)){var o=document.getElementById("app-update-flag");o&&o.classList.remove("hidden");var i=document.getElementById("app-info-update");i&&window.monacoriUpdate&&"function"==typeof window.monacoriUpdate.run?(i.textContent=t("settings.updateRestart")+" (v"+n+")",i.classList.remove("hidden"),r&&(r.textContent=t("settings.updateAvailable")+": v"+n,r.classList.add("has-update"))):r&&(r.textContent=t("settings.updateAvailable")+": v"+n+" — npm i -g @happy-nut/monacori",r.classList.add("has-update"))}else r&&(r.textContent=t("settings.upToDate")+" (v"+e+")")}},r="";try{r=sessionStorage.getItem("monacori-update-latest")||""}catch(e){}r?n(r):"function"==typeof fetch&&fetch("https://registry.npmjs.org/@happy-nut/monacori/latest",{cache:"no-store"}).then(function(e){return e&&e.ok?e.json():null}).then(function(e){if(e&&e.version){try{sessionStorage.setItem("monacori-update-latest",e.version)}catch(e){}n(e.version)}}).catch(function(){})}}(),function(){var e=document.getElementById("settings-modal");if(e){var n=document.getElementById("app-info-btn"),r=document.getElementById("app-update-flag"),o=document.getElementById("app-info-update"),i=document.getElementById("settings-prompt-q"),a=document.getElementById("settings-prompt-c"),s=document.getElementById("settings-reset"),c=document.getElementById("settings-saved"),l=Array.prototype.slice.call(e.querySelectorAll(".settings-cat")),d=Array.prototype.slice.call(e.querySelectorAll(".settings-section")),u=null;n&&n.addEventListener("click",function(t){t.stopPropagation(),e.classList.contains("hidden")?h("general"):v()}),r&&r.addEventListener("click",function(e){e.stopPropagation(),h("general")}),l.forEach(function(e){e.addEventListener("click",function(){m(e.dataset.cat)})}),e.addEventListener("click",function(t){t.target===e&&v()}),document.addEventListener("keydown",function(t){if("Escape"===t.key&&!e.classList.contains("hidden"))return t.stopPropagation(),t.preventDefault(),void v();if((t.metaKey||t.ctrlKey)&&!t.altKey&&!t.shiftKey&&(","===t.key||"Comma"===t.code)){if(e.classList.contains("hidden")&&(document.getElementById("mc-modal")||document.getElementById("mc-memo")))return;t.preventDefault(),t.stopPropagation(),e.classList.contains("hidden")?h("general"):v()}},!0),o&&window.monacoriUpdate&&"function"==typeof window.monacoriUpdate.run&&o.addEventListener("click",function(){if(!o.disabled){o.disabled=!0;var e=document.getElementById("app-info-status");e&&(e.textContent=t("settings.updating"),e.classList.add("has-update")),window.monacoriUpdate.run().then(function(n){n&&n.ok?e&&(e.textContent=t("settings.updated")):(o.disabled=!1,e&&(e.textContent=t("settings.updateFailed")))}).catch(function(){o.disabled=!1,e&&(e.textContent=t("settings.updateFailed"))})}}),i&&i.addEventListener("input",function(){saveMergePrompt("q",i.value),g()}),a&&a.addEventListener("input",function(){saveMergePrompt("c",a.value),g()}),s&&s.addEventListener("click",function(){saveMergePrompt("q",""),saveMergePrompt("c",""),p(),g()});var f=document.getElementById("set-bell-notify");f&&(f.checked=!1!==persistRead("monacori-terminal-bell-notify"),f.addEventListener("change",function(){persistSave("monacori-terminal-bell-notify",f.checked)})),langSelectRef=setupCustomSelect("settings-language",function(){return[{value:"en",label:"English"},{value:"ko",label:"한국어"}]},function(){return locale},function(e){if(e!==locale){persistSave(LOCALE_KEY,locale=e),applyI18n(),p();try{"function"==typeof refreshComments&&refreshComments()}catch(e){}var t=document.getElementById("mc-modal");if(t){var n=t.dataset.kind||"q";t.remove(),openMergedView(n)}}}),themeSelectRef=setupCustomSelect("settings-theme",function(){return[{value:"dark",label:t("theme.dark")},{value:"light",label:t("theme.light")}]},function(){return theme},function(e){e!==theme&&(persistSave(THEME_KEY,theme=e),applyTheme())})}function m(e){l.forEach(function(t){t.classList.toggle("active",t.dataset.cat===e)}),d.forEach(function(t){t.classList.toggle("hidden",t.dataset.cat!==e)})}function p(){var e=loadMergePrompts();i&&(i.value="string"==typeof e.q?e.q:"",i.placeholder=defaultMergePrompt("q")),a&&(a.value="string"==typeof e.c?e.c:"",a.placeholder=defaultMergePrompt("c"))}function h(t){p(),t&&m(t),e.classList.remove("hidden")}function v(){e.classList.add("hidden")}function g(){c&&(c.textContent="Saved",u&&clearTimeout(u),u=setTimeout(function(){c.textContent=""},1200))}}();var pendingDiffUpdate=null;function flushPendingDiffUpdate(){if(pendingDiffUpdate){var e=pendingDiffUpdate;pendingDiffUpdate=null;try{applyDiffUpdate(e)}catch(e){}}}function applyDiffUpdate(e){if(!e||!e.signature||e.signature===currentSignature)return!1;if(composerState)return pendingDiffUpdate=e,!1;var t=document.getElementById("source-viewer"),n=t&&t.dataset.openPath||"",r=isSourceViewerVisible(),o=document.getElementById("diff2html-container"),i=o?o.scrollTop:0,a=current>=0?hunkPathAt(current):"",s=n&&fileSignatureByPath.get(n)||"",c={};REVIEW_LAZY&&o&&o.querySelectorAll(".d2h-file-wrapper").forEach(function(e){var t=e.querySelector(".d2h-files-diff");if(t&&!t.hasAttribute("data-lazy")){var n=diffWrapperPathKey(e);n&&(c[n]={sig:fileSignatureByPath.get(n)||"",html:t.innerHTML})}}),o&&(o.innerHTML=e.diffContainer||"");var l=document.getElementById("changes-panel");l&&(l.innerHTML=e.changesPanel||"");var d=document.getElementById("files-tree-html");d&&(d.textContent=e.filesTree||"");var u=document.getElementById("files-panel");!u||REVIEW_LAZY&&!u.innerHTML.trim()||(u.innerHTML=e.filesTree||"");var f=document.querySelector(".review-status");f&&(f.innerHTML=e.reviewStatus||"");var m=document.getElementById("brand-branch-name");if(m){m.textContent=e.branch||"";var p=m.closest&&m.closest(".brand-branch");p&&p.classList.toggle("hidden",!e.branch)}reviewMeta&&(reviewMeta.setAttribute("data-signature",e.signature),e.generatedAt&&reviewMeta.setAttribute("data-generated-at",e.generatedAt)),fileStates=e.fileStates||[],fileSignatureByPath=new Map(fileStates.map(function(e){return[e.path,e.signature]}));var h=!n||s!==(fileSignatureByPath.get(n)||"");sourceFiles=e.sourceFilesMeta||[],sourceByPath=new Map(sourceFiles.map(function(e){return[e.path,e]})),httpEnvironments=e.httpEnvironments||{},httpEnvNames=Object.keys(httpEnvironments),currentSignature=e.signature,links=Array.from(document.querySelectorAll("#changes-panel .file-link")),sourceLinks=Array.from(document.querySelectorAll(".source-link"));var v=!1;if(a){var g=firstHunkForPath(a);g>=0?(current=g,v=!0):current=-1}return bodyCache={},bodyPromise={},diffBootDone=!1,sourceLoaded=!REVIEW_LAZY_LOAD,sourceLoading=!1,h&&(sourceBodyPath=null),symbolIndex=null,REVIEW_LAZY&&o&&o.querySelectorAll(".d2h-file-wrapper").forEach(function(e){var t=diffWrapperPathKey(e),n=t?c[t]:null;if(n&&n.sig&&n.sig===(fileSignatureByPath.get(t)||"")&&e.querySelector(".d2h-files-diff[data-lazy]")){var r=(e.id||"").replace("file-","");materializeBody(e,n.html),bodyCache[r]=n.html,bodyPromise[r]=Promise.resolve(e)}}),refreshHunkIndex(),REVIEW_LAZY?(setupLazyDiff(),setTimeout(function(){diffBootDone=!0},0)):diffBootDone=!0,REVIEW_LAZY_LOAD||setTimeout(startSymbolIndex,0),applyI18n(),populateHttpEnvSelect(),initSourceTreeFolds(),remapComments(),refreshComments(),r&&n&&sourceByPath.has(n)?h&&openSourceFile(n,!1):o&&(showDiffView(!1),o.scrollTop=v?i:0),!0}async function checkForLiveUpdate(){if(checkingForUpdates)return;checkingForUpdates=!0;const e=document.getElementById("live-status");try{const r=await fetch("/__ai_flow_state",{cache:"no-store"});if(!r.ok)return;const o=await r.json();if(e&&o.generatedAt&&(e.textContent=t("status.live.updated")+" "+new Date(o.generatedAt).toLocaleTimeString()),o.signature&&o.signature!==currentSignature)try{var n=await fetch("__ai_flow_update",{cache:"no-store"});n.ok&&applyDiffUpdate(await n.json())}catch(e){}}catch{e&&(e.textContent=t("status.live.waiting"))}finally{checkingForUpdates=!1}}function filterNavigation(e){const t=e.trim().toLowerCase();links.forEach(e=>{const n=e.dataset.file||"",r=sourceByPath.get(n),o=(n+"\n"+(r?.content||"")).toLowerCase();e.hidden=t.length>0&&!o.includes(t)}),sourceLinks.forEach(e=>{const n=e.dataset.sourceFile||"",r=sourceByPath.get(n),o=(n+"\n"+(r?.content||"")).toLowerCase();e.hidden=t.length>0&&!o.includes(t)}),updateTreeVisibility(document.getElementById("changes-panel"),t),updateTreeVisibility(document.getElementById("files-panel"),t)}function updateTreeVisibility(e,t){e&&Array.from(e.querySelectorAll("details")).reverse().forEach(e=>{const n=Array.from(e.children).some(e=>"SUMMARY"!==e.tagName&&!e.hidden);e.hidden=t.length>0&&!n,t.length>0&&n&&(e.open=!0)})}function openDefaultSourceFile(){const e=e=>(e.path||"").split("/").length,t=sourceFiles.filter(e=>e.embedded&&(e=>/^readme(\.|$)/i.test(e.name||""))(e)).sort((t,n)=>e(t)-e(n))[0],n=sourceFiles.find(e=>e.changed&&e.embedded)||t||sourceFiles.find(e=>e.embedded)||sourceFiles.find(e=>e.changed)||sourceFiles[0];n?openSourceFile(n.path):hunkTotal()>0&&setActive(0,!1)}function handleSourceCopy(e){const t=window.getSelection(),n=document.getElementById("source-body"),r=document.getElementById("source-viewer");if(!t||t.isCollapsed||!n||!r||r.classList.contains("hidden"))return;if(!t.anchorNode||!t.focusNode)return;if(!n.contains(t.anchorNode)||!n.contains(t.focusNode))return;const o=r.dataset.openPath||"",i=sourceByPath.get(o);if(!i||!i.embedded)return;const a=selectedSourceRows(t);if(0===a.length)return;const s=a.map(e=>Number(e.dataset.lineIndex||0)+1).filter(e=>Number.isFinite(e)).sort((e,t)=>e-t),c=s[0],l=s[s.length-1];if(!c||!l)return;const d=cleanSelectedSourceText(t.toString(),a)||sourceLinesForRows(i,a);if(!d.trim())return;const u=o+":"+(c===l?String(c):c+"-"+l),f=i.language&&"text"!==i.language?i.language:"",m=String.fromCharCode(96).repeat(3),p=u+"\n\n"+m+f+"\n"+d.replace(/\s+$/g,"")+"\n"+m;e.clipboardData?.setData("text/plain",p),e.preventDefault()}function selectedSourceRows(e){if(!e.rangeCount)return[];const t=Array.from({length:e.rangeCount},(t,n)=>e.getRangeAt(n));return Array.from(document.querySelectorAll("#source-body .source-row")).filter(e=>t.some(t=>{try{return t.intersectsNode(e)}catch{return!1}})).sort((e,t)=>Number(e.dataset.lineIndex||0)-Number(t.dataset.lineIndex||0))}function cleanSelectedSourceText(e,t){const n=String(e||"").replace(/\r/g,"").replace(/\u200b/g,"");if(!n.trim())return"";const r=t.map(e=>Number(e.dataset.lineIndex||0)+1),o=n.split("\n");return o.length>=r.length?o.map((e,t)=>{const n=r[t];return n?e.replace(new RegExp("^\\s*"+n+"\\s+"),""):e}).join("\n").trimEnd():n.trimEnd()}function sourceLinesForRows(e,t){const n=e.content.split(/\r?\n/);return t.map(e=>n[Number(e.dataset.lineIndex||0)]||"").join("\n").trimEnd()}function handleSourceClick(e){const t=e.target,n=t?.closest?.(".http-run");if(n)return e.preventDefault(),void runHttpRequest(Number(n.dataset.req));const r=t?.closest?.(".http-resp-toggle");if(r){e.preventDefault();const t=r.closest(".http-response")?.querySelector(".http-resp-headers");return void(t&&t.classList.toggle("hidden"))}const o=t?.closest?.(".source-row");if(!o)return;clearTreeFocus();const i=document.getElementById("source-viewer"),a=i?.dataset.openPath||"",s=sourceByPath.get(a);if(!s||!s.embedded)return;const c=Number(o.dataset.lineIndex||0),l=s.content.split(/\r?\n/)[c]||"";setSourceCursor(a,c,estimateColumnFromClick(o.querySelector(".source-code"),e,l),!1,-1)}function estimateColumnFromClick(e,t,n){if(!e)return 0;const r=e.getBoundingClientRect(),o=getComputedStyle(e),i=Number.parseFloat(o.paddingLeft||"0")||0,a=t.clientX-r.left-i,s=measuredCharWidth||measureCharWidth(e),c=Math.round(a/Math.max(s,1));return Math.max(0,Math.min(n.length,c))}function measureCharWidth(e){const t=document.createElement("span");t.textContent="mmmmmmmmmm",t.style.position="absolute",t.style.visibility="hidden",t.style.whiteSpace="pre",t.style.font=getComputedStyle(e).font,document.body.appendChild(t);const n=t.getBoundingClientRect().width/10;return t.remove(),measuredCharWidth=n||7,measuredCharWidth}var caretBusyTimer=null;function markCaretBusy(){document.body.classList.add("caret-busy"),caretBusyTimer&&clearTimeout(caretBusyTimer),caretBusyTimer=setTimeout(function(){document.body.classList.remove("caret-busy")},650)}function setSourceCursor(e,t,n,r=!1,o=-1){markCaretBusy(),selectedCommentRow=null;const i=sourceByPath.get(e);if(!i||!i.embedded)return;const a=i.content.split(/\r?\n/),s=Math.max(0,Math.min(t,Math.max(a.length-1,0))),c=Math.max(0,Math.min(n,(a[s]||"").length)),l=viewerCursor,d=document.getElementById("source-viewer"),u=Boolean(d&&d.dataset.openPath===e&&!d.classList.contains("hidden")&&l&&l.path===e&&!isHttpFile(e)&&sourceBodyPath===e);if(viewerCursor={path:e,lineIndex:s,column:c,targetLine:o},u)r?scheduleSourceReveal(l):updateSourceCaret(l,a,i.language||"text");else{openSourceFile(e,!d||d.dataset.openPath!==e||d.classList.contains("hidden")),r&&scheduleScrollIntoView(document.querySelector(".source-row.cursor-line"))}recordNav(navEntryOf("source"))}var sourceRevealRaf=0,sourceRevealPrev=null,_srcRowH=0;function sourceRowHeight(){if(_srcRowH>0)return _srcRowH;var e=document.querySelector("#source-body .source-row");if(e){var t=e.offsetHeight;t>0&&(_srcRowH=t)}return _srcRowH}function scheduleSourceReveal(e){sourceRevealRaf||(sourceRevealPrev=e),sourceRevealRaf||(sourceRevealRaf=requestAnimationFrame(function(){sourceRevealRaf=0;var e=sourceRevealPrev;sourceRevealPrev=null;var t=sourceByPath.get(viewerCursor.path);if(t&&t.embedded){updateSourceCaret(e,t.content.split(/\r?\n/),t.language||"text");var n=document.getElementById("source-body"),r=sourceRowHeight();if(r>0&&n&&!n.classList.contains("rendered-body")){var o=viewerCursor.lineIndex*r,i=n.clientHeight,a=Math.round(.15*i),s=n.scrollTop;o<s+a?n.scrollTop=Math.max(0,o-a):o+r>s+i-a&&(n.scrollTop=o+r-i+a)}else revealAt(document.querySelector(".source-row.cursor-line"),n,.85)}}))}function updateSourceCaret(e,t,n){const r=document.getElementById("source-body");if(!r)return;const o=r.classList.contains("rendered-body"),i=e=>r.querySelector('.source-row[data-line-index="'+e+'"]');if(e&&e.lineIndex!==viewerCursor.lineIndex){const t=i(e.lineIndex);t&&t.classList.remove("cursor-line")}o||r.querySelectorAll(".code-cursor").forEach(e=>{const t=e.parentNode;t&&(t.removeChild(e),t.normalize&&t.normalize())}),r.querySelectorAll(".source-row.symbol-target").forEach(e=>e.classList.remove("symbol-target")),viewerCursor.targetLine>=0&&i(viewerCursor.targetLine)?.classList.add("symbol-target");const a=i(viewerCursor.lineIndex);a?(a.classList.add("cursor-line"),o||insertSourceCaret(a,viewerCursor.column)):o||openSourceFile(viewerCursor.path,!1)}function insertSourceCaret(e,t){var n=e.querySelector(".source-code");if(n){var r=diffCaretDomPosition(n,t);if(r){var o=document.createElement("span");o.className="code-cursor",o.setAttribute("aria-hidden","true");try{var i=3===r.node.nodeType?Math.min(r.offset,(r.node.textContent||"").length):r.offset,a=document.createRange();a.setStart(r.node,i),a.collapse(!0),a.insertNode(o)}catch(e){}}}}function openSourceAt(e,t,n){setSourceCursor(e,t,n,!0,t)}function isSourceViewerVisible(){const e=document.getElementById("source-viewer");return Boolean(e&&!e.classList.contains("hidden"))}function openDiffFileAtCaret(){if(diffCursor&&isDiffViewVisible()){const e=diffWrapperByPath(diffCursor.path),t=e?diffRowAt(e,diffCursor.side,diffCursor.rowIndex):null,n=t?diffLineNumber(t):null;return sourceByPath.has(diffCursor.path)?void setSourceCursor(diffCursor.path,null!=n?n-1:0,0,!0,-1):void openSourceFile(diffCursor.path)}const e=window.getSelection(),t=e&&e.anchorNode,n=t?1===t.nodeType?t:t.parentElement:null,r=n&&n.closest&&n.closest(".d2h-file-wrapper")||document.querySelector(".d2h-file-wrapper:not(.df-inactive)");if(!r)return;const o=(r.querySelector(".d2h-file-name")?.textContent||"").trim();if(!o)return;if(!sourceByPath.has(o))return void openSourceFile(o);let i=0;const a=n&&n.closest&&n.closest(".d2h-code-side-line");if(a){const e=a.closest("tr"),t=e&&e.querySelector(".d2h-code-side-linenumber"),n=t?parseInt((t.textContent||"").trim(),10):NaN;Number.isFinite(n)&&(i=Math.max(0,n-1))}setSourceCursor(o,i,0,!0,-1)}function commentRowSiblingOf(e,t){var n=document.querySelector('#source-body .source-row[data-line-index="'+e+'"]');if(!n)return null;var r=t<0?n.previousElementSibling:n.nextElementSibling;return r&&r.classList&&r.classList.contains("mc-comment-row")?r:null}function selectCommentRow(e){selectedCommentRow&&selectedCommentRow!==e&&selectedCommentRow.classList.remove("mc-row-selected"),selectedCommentRow=e||null,selectedCommentRow&&selectedCommentRow.classList.add("mc-row-selected")}function deleteCommentsInRow(e){if(e){var t=Array.prototype.slice.call(e.querySelectorAll(".mc-del")).map(function(e){return parseInt(e.dataset.seq,10)});selectedCommentRow=null,t.length&&(reviewComments=reviewComments.filter(function(e){return t.indexOf(e.seq)<0}),saveComments()),refreshComments()}}function editCommentInRow(e){if(e){var t=e.querySelector(".mc-del");if(t){var n=parseInt(t.dataset.seq,10),r=reviewComments.find(function(e){return e.seq===n});r&&(e.classList.remove("mc-row-selected"),selectedCommentRow=null,composerState={kind:r.kind,path:r.path,line:r.line,code:r.code,editSeq:n,editText:r.text},refreshComments())}}}function handleSourceCaretKey(e){if(!viewerCursor)return!1;var t=document.activeElement;if(t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName||"SELECT"===t.tagName))return!1;const n=e.shiftKey;if(selectedCommentRow){if("Backspace"===e.key||"Delete"===e.key)return e.preventDefault(),deleteCommentsInRow(selectedCommentRow),!0;if("e"===e.key||"E"===e.key)return e.preventDefault(),editCommentInRow(selectedCommentRow),!0;if("ArrowUp"===e.key||"ArrowDown"===e.key||"ArrowLeft"===e.key||"ArrowRight"===e.key||"Escape"===e.key){var r="ArrowUp"===e.key?-1:"ArrowDown"===e.key?1:0,o=r<0?selectedCommentRow.previousElementSibling:r>0?selectedCommentRow.nextElementSibling:null;if(selectedCommentRow.classList.remove("mc-row-selected"),selectedCommentRow=null,e.preventDefault(),o&&o.classList&&o.classList.contains("source-row")){var i=parseInt(o.dataset.lineIndex,10);if(isFinite(i))return setSourceCursor(viewerCursor.path,i,0,!0,-1),!0}return setSourceCursor(viewerCursor.path,viewerCursor.lineIndex,viewerCursor.column,!1,-1),!0}return!1}if(!n&&("ArrowUp"===e.key||"ArrowDown"===e.key)){var a=commentRowSiblingOf(viewerCursor.lineIndex,"ArrowUp"===e.key?-1:1);if(a)return e.preventDefault(),selectCommentRow(a),!0}return"ArrowDown"===e.key?(e.preventDefault(),moveSourceCursor(1,0,n),!0):"ArrowUp"===e.key?(e.preventDefault(),moveSourceCursor(-1,0,n),!0):"ArrowLeft"===e.key?(e.preventDefault(),moveSourceCursor(0,-1,n),!0):"ArrowRight"===e.key&&(e.preventDefault(),moveSourceCursor(0,1,n),!0)}function moveSourceCursor(e,t,n){if(!viewerCursor)return;const r=sourceByPath.get(viewerCursor.path);if(!r||!r.embedded)return;const o=document.getElementById("source-body");if(o&&o.classList.contains("rendered-body")){const n=Array.from(o.querySelectorAll(".source-row"));if(!n.length)return;let r=n.indexOf(o.querySelector('.source-row[data-line-index="'+viewerCursor.lineIndex+'"]'));r<0&&(r=0);const i=(e||0)+(t>0?1:t<0?-1:0),a=Math.max(0,Math.min(n.length-1,r+(i||0)));return selectionAnchor=null,void setSourceCursor(viewerCursor.path,Number(n[a].dataset.lineIndex)||0,0,!0,-1)}const i=r.content.split(/\r?\n/);let a=viewerCursor.lineIndex,s=viewerCursor.column;t<0?s>0?s-=1:a>0&&(a-=1,s=(i[a]||"").length):t>0&&(s<(i[a]||"").length?s+=1:a<i.length-1&&(a+=1,s=0)),0!==e&&(a=Math.max(0,Math.min(i.length-1,a+e)),s=Math.min(s,(i[a]||"").length)),n?selectionAnchor||(selectionAnchor={lineIndex:viewerCursor.lineIndex,column:viewerCursor.column}):selectionAnchor=null,setSourceCursor(viewerCursor.path,a,s,!0,-1),applySourceSelection()}function nextWordBoundary(e,t,n){var r=function(e){return""===e||/\s/.test(e)?0:/[A-Za-z0-9_$]/.test(e)?1:2},o=t;if(n>0){var i=r(e.charAt(o));if(0!==i)for(;o<e.length&&r(e.charAt(o))===i;)o++;for(;o<e.length&&0===r(e.charAt(o));)o++}else{for(o--;o>0&&0===r(e.charAt(o));)o--;for(var a=r(e.charAt(o));o>0&&r(e.charAt(o-1))===a;)o--;o<0&&(o=0)}return o}function moveSourceWord(e,t){if(viewerCursor){var n=sourceByPath.get(viewerCursor.path);if(n&&n.embedded){var r=n.content.split(/\r?\n/),o=viewerCursor.lineIndex,i=viewerCursor.column,a=r[o]||"";if(e>0){var s=nextWordBoundary(a,i,1);if(s<a.length||o>=r.length-1)i=s;else{var c=(r[o+=1]||"").search(/\S/);i=c<0?0:c}}else{var l=nextWordBoundary(a,i,-1);if(l<i&&/\S/.test(a.charAt(l)))i=l;else if(o>0){var d=r[o-=1]||"";i=d.length>0?nextWordBoundary(d,d.length,-1):0}else i=l}t?selectionAnchor||(selectionAnchor={lineIndex:viewerCursor.lineIndex,column:viewerCursor.column}):selectionAnchor=null,setSourceCursor(viewerCursor.path,o,i,!0,-1),applySourceSelection()}}}function applySourceSelection(){const e=window.getSelection();if(!e)return;if(!selectionAnchor||!viewerCursor)return void e.removeAllRanges();const t=caretDomPosition(selectionAnchor.lineIndex,selectionAnchor.column),n=caretDomPosition(viewerCursor.lineIndex,viewerCursor.column);if(t&&n)try{e.setBaseAndExtent(t.node,t.offset,n.node,n.offset)}catch(e){}}function caretDomPosition(e,t){const n=document.querySelector('.source-row[data-line-index="'+e+'"] .source-code');if(!n)return null;let r=t;const o=document.createTreeWalker(n,NodeFilter.SHOW_TEXT);let i;for(;i=o.nextNode();){const e=i.textContent.length;if(r<=e)return{node:i,offset:r};r-=e}return{node:n,offset:n.childNodes.length}}function wordAtCursor(){if(!viewerCursor)return null;const e=sourceByPath.get(viewerCursor.path);if(!e||!e.embedded)return null;const t=e.content.split(/\r?\n/)[viewerCursor.lineIndex]||"",n=Math.max(0,Math.min(viewerCursor.column,t.length)),r=/[A-Za-z_$][A-Za-z0-9_$]*/g;let o=null;for(;o=r.exec(t);){const e=o.index,t=e+o[0].length;if(n>=e&&n<=t)return{name:o[0],path:viewerCursor.path,lineIndex:viewerCursor.lineIndex,column:e}}return null}function goToSymbolUnderCursor(){const e=wordAtCursor();e&&goToDefOrUsages(e.name)}function goToDefOrUsages(e){if(e){if(REVIEW_LAZY_LOAD&&!sourceLoaded)return pendingSymbol=e,void loadSourceData();var t=findSymbolDefinition(e),n=caretSourceLoc();t&&n&&t.path===n.path&&t.lineIndex===n.lineIndex?openUsages(e,t):t&&openSourceAt(t.path,t.lineIndex,t.column)}}function caretSourceLoc(){if(isSourceViewerVisible()&&viewerCursor)return{path:viewerCursor.path,lineIndex:viewerCursor.lineIndex};if(isDiffViewVisible()&&diffCursor&&"new"===diffCursor.side){var e=diffWrapperByPath(diffCursor.path),t=e?diffRowAt(e,diffCursor.side,diffCursor.rowIndex):null,n=t?diffLineNumber(t):null;if(null!=n)return{path:diffCursor.path,lineIndex:n-1}}return null}function findUsages(e,t,n){var r;try{r=new RegExp("(^|[^A-Za-z0-9_$])"+escapeRegExp(e)+"(?![A-Za-z0-9_$])")}catch(e){return[]}for(var o=[],i=0;i<sourceFiles.length;i++){var a=sourceFiles[i];if(a.embedded)for(var s=String(a.content).split(/\r?\n/),c=0;c<s.length;c++)if(a.path!==t||c!==n){var l=r.exec(s[c]);if(l&&(o.push({path:a.path,lineIndex:c,column:l.index+(l[1]?l[1].length:0),text:s[c]}),o.length>=500))return o}}return o}function openUsages(e,t){var n=findUsages(e,t.path,t.lineIndex);1!==n.length?(usageItems=n,usageActive=0,showUsages(e,n.length)):openSourceAt(n[0].path,n[0].lineIndex,n[0].column)}function showUsages(e,t){var n=document.getElementById("usages"),r=document.getElementById("usages-title");n&&(r&&(r.textContent=t+" usage"+(1===t?"":"s")+" of "+e),renderUsages(),n.classList.remove("hidden"),positionUsagesAtCaret())}function positionUsagesAtCaret(){var e=document.getElementById("usages");if(e){var t=e.querySelector(".quick-open-panel");if(t){resetUsagesAnchor(e,t);var n=document.querySelector("#source-body .code-cursor")||document.querySelector("#diff2html-container .code-cursor");if(n){var r=n.getBoundingClientRect();if(r.height||r.width||r.top){var o=window.innerWidth,i=window.innerHeight,a=Math.min(560,o-16),s=Math.min(Math.max(8,r.left),o-a-8);e.classList.add("anchored"),t.style.width=a+"px",t.style.left=s+"px";var c=i-r.bottom-6-8,l=r.top-6-8;c>=200||c>=l?(t.style.top=r.bottom+6+"px",t.style.maxHeight=Math.max(120,c)+"px"):(t.style.bottom=i-r.top+6+"px",t.style.maxHeight=Math.max(120,l)+"px")}}}}}function resetUsagesAnchor(e,t){e.classList.remove("anchored"),t.style.left=t.style.top=t.style.bottom=t.style.width=t.style.maxHeight=""}function renderUsages(){var e=document.getElementById("usages-results");e&&(usageItems.length?(e.innerHTML=usageItems.map(function(e,t){var n=e.path.split("/").pop();return'<button type="button" class="quick-open-item usage-item'+(t===usageActive?" active":"")+'" data-index="'+t+'"><span class="usage-loc">'+escapeHtml(n)+":"+(e.lineIndex+1)+'</span><span class="usage-code">'+escapeHtml(e.text.replace(/^\s+/,"").slice(0,160))+"</span></button>"}).join(""),updateUsageActive()):e.innerHTML='<div class="quick-open-empty">No usages found.</div>')}function updateUsageActive(){var e=document.getElementById("usages-results");if(e)for(var t=e.querySelectorAll(".usage-item"),n=0;n<t.length;n++){var r=n===usageActive;t[n].classList.toggle("active",r),r&&t[n].scrollIntoView&&t[n].scrollIntoView({block:"nearest"})}}function handleUsagesKey(e){return"Escape"===e.key?(e.preventDefault(),closeUsages(),!0):"ArrowDown"===e.key?(e.preventDefault(),usageActive=Math.min(usageActive+1,usageItems.length-1),updateUsageActive(),!0):"ArrowUp"===e.key?(e.preventDefault(),usageActive=Math.max(usageActive-1,0),updateUsageActive(),!0):"Enter"===e.key&&(e.preventDefault(),openUsageItem(usageItems[usageActive]),!0)}function openUsageItem(e){e&&(closeUsages(),openSourceAt(e.path,e.lineIndex,e.column))}function closeUsages(){var e=document.getElementById("usages");if(e){e.classList.add("hidden");var t=e.querySelector(".quick-open-panel");t&&resetUsagesAnchor(e,t)}}"undefined"!=typeof window&&window.addEventListener("resize",function(){_srcRowH=0});var symbolIndex=null;function symbolIndexWorker(){self.onmessage=function(e){for(var t=e.data||[],n=[/^\s*(?:export\s+)?(?:default\s+)?(?:async\s+)?function\s+([A-Za-z_$][A-Za-z0-9_$]*)/,/^\s*(?:(?:public|private|protected|internal|abstract|final|open|sealed|data|inner|annotation|static|export|default|expect|actual|value)\s+)*(?:class|interface|object|enum|trait|struct)\s+([A-Za-z_$][A-Za-z0-9_$]*)/,/^\s*(?:export\s+)?(?:interface|type|enum)\s+([A-Za-z_$][A-Za-z0-9_$]*)/,/^\s*(?:export\s+)?(?:const|let|var|val)\s+([A-Za-z_$][A-Za-z0-9_$]*)/,/^\s*(?:(?:public|private|protected|internal|abstract|final|open|override|suspend|inline|operator|static|async)\s+)*(?:fun|def|fn|func)\s+([A-Za-z_$][A-Za-z0-9_$]*)/],r=new Map,o=t.length,i=Math.max(1,Math.floor(o/20)),a=0;a<o;a++){for(var s=t[a].path,c=String(t[a].content||"").split(/\r?\n/),l=0;l<c.length;l++)for(var d=c[l],u=0;u<n.length;u++){var f=n[u].exec(d);if(f&&f[1]){var m=r.get(f[1]);m||(m=[],r.set(f[1],m)),m.push({path:s,lineIndex:l,column:Math.max(0,d.indexOf(f[1]))});break}}(a+1)%i===0&&a+1<o&&self.postMessage({done:a+1,total:o})}self.postMessage({index:r,total:o})}}function scheduleSymbolIndex(){var e=function(){try{startSymbolIndex()}catch(e){}};"undefined"!=typeof window&&"function"==typeof window.requestIdleCallback?window.requestIdleCallback(e,{timeout:3e3}):setTimeout(e,0)}function startSymbolIndex(){try{if("undefined"==typeof Worker||"undefined"==typeof Blob||"undefined"==typeof URL||!URL.createObjectURL)return;var e="("+symbolIndexWorker.toString()+")()",t=URL.createObjectURL(new Blob([e],{type:"application/javascript"})),n=new Worker(t);n.onmessage=function(e){var r=e.data;if(r&&r.index){symbolIndex=r.index,setIndexProgress(r.total,r.total);try{n.terminate()}catch(e){}try{URL.revokeObjectURL(t)}catch(e){}}else r&&"number"==typeof r.done&&setIndexProgress(r.done,r.total)},n.onerror=function(){setIndexProgress(1,1);try{n.terminate()}catch(e){}};for(var r=[],o=0;o<sourceFiles.length;o++)sourceFiles[o].embedded&&r.push({path:sourceFiles[o].path,content:sourceFiles[o].content});setIndexProgress(0,r.length),n.postMessage(r)}catch(e){}}function setIndexProgress(e,n){var r=document.getElementById("index-status"),o=document.getElementById("index-progress"),i=document.getElementById("footer-progress"),a=Boolean(n)&&e<n,s=a?Math.round(e/n*100)+"%":"0%";r&&(r.textContent=a?t("status.indexing")+" "+e+"/"+n+"…":(n||0)+" "+t("status.indexed")),o&&(o.classList.toggle("hidden",!a),a&&o.firstElementChild&&(o.firstElementChild.style.width=s)),i&&(i.classList.toggle("hidden",!a),i.firstElementChild&&(i.firstElementChild.style.width=s))}function wordAtDiffCaret(){if(!diffCursor)return null;var e=diffWrapperByPath(diffCursor.path);if(!e)return null;for(var t=diffLineText(diffRowAt(e,diffCursor.side,diffCursor.rowIndex)),n=Math.max(0,Math.min(diffCursor.column,t.length)),r=/[A-Za-z_$][A-Za-z0-9_$]*/g,o=null;o=r.exec(t);)if(n>=o.index&&n<=o.index+o[0].length)return o[0];return null}function goToSymbolFromDiff(){goToDefOrUsages(wordAtDiffCaret())}function findSymbolDefinition(e){if(symbolIndex){var t=symbolIndex.get(e);if(t&&t.length){for(var n=viewerCursor&&viewerCursor.path||diffCursor&&diffCursor.path||"",r=0;r<t.length;r++)if(t[r].path===n)return t[r];return t[0]}}const o=definitionMatchers(e),i=viewerCursor?.path||"",a=[...sourceFiles.filter(e=>e.path===i),...sourceFiles.filter(e=>e.path!==i)].filter(e=>e.embedded);for(const t of a){const n=t.content.split(/\r?\n/);for(let r=0;r<n.length;r+=1){const i=n[r];if(o.some(e=>e.test(i)))return{path:t.path,lineIndex:r,column:Math.max(0,i.indexOf(e))}}}return null}function definitionMatchers(e){const t=escapeRegExp(e),n="(?:(?:public|private|protected|internal|abstract|final|open|override|suspend|inline|operator|static|async)\\s+)*";return[new RegExp("^\\s*(?:export\\s+)?(?:default\\s+)?(?:async\\s+)?function\\s+"+t+"\\b"),new RegExp("^\\s*(?:(?:public|private|protected|internal|abstract|final|open|sealed|data|inner|enum|annotation|static|export|default|expect|actual|value)\\s+)*(?:class|interface|object|enum|trait|struct)\\s+"+t+"\\b"),new RegExp("^\\s*(?:export\\s+)?(?:interface|type|enum)\\s+"+t+"\\b"),new RegExp("^\\s*(?:export\\s+)?(?:const|let|var|val)\\s+"+t+"\\b"),new RegExp("^\\s*"+n+"(?:fun|def|fn|func)\\s+"+t+"\\b"),new RegExp("^\\s*"+n+t+"\\s*\\([^)]*\\)\\s*(?::\\s*[^=]+)?\\s*(?:\\{|=>)"),new RegExp("^\\s*"+t+"\\s*[:=]\\s*(?:async\\s*)?(?:function\\b|\\([^)]*\\)\\s*=>)")]}function escapeRegExp(e){return String(e).replace(/[|\\{}()[\]^$+*?.]/g,"\\$&")}function setSourceTypeIcon(e){var t=document.getElementById("source-type-icon");if(t){var n=sourceLinks.find(function(t){return t.dataset.sourceFile===e}),r=n?n.querySelector(".ftype"):null;t.innerHTML=r?r.outerHTML:""}}function addSourceTab(e){e&&sourceTabs.indexOf(e)<0&&sourceTabs.push(e)}function sourceTabLabel(e){var t=String(e||""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function currentSourceTabPath(){var e=document.getElementById("source-viewer");return e&&e.dataset.openPath||""}function renderSourceTabs(e){var t=document.getElementById("source-tabs");if(t){if(!sourceTabs.length)return t.classList.add("hidden"),void(t.innerHTML="");t.classList.remove("hidden"),t.innerHTML=sourceTabs.map(function(t){return'<div class="source-tab'+(t===e?" active":"")+'" data-tab-path="'+escapeHtml(t)+'" title="'+escapeHtml(t)+'"><span class="source-tab-name">'+escapeHtml(sourceTabLabel(t))+'</span><button type="button" class="source-tab-close" data-close-path="'+escapeHtml(t)+'" aria-label="Close tab" title="Close (⌘W)">×</button></div>'}).join("");var n=t.querySelector(".source-tab.active");if(n){var r=t.getBoundingClientRect(),o=n.getBoundingClientRect();o.left<r.left?t.scrollLeft-=r.left-o.left+8:o.right>r.right&&(t.scrollLeft+=o.right-r.right+8)}}}function closeSourceTab(e){var n=sourceTabs.indexOf(e);if(!(n<0)){var r=e===currentSourceTabPath();if(sourceTabs.splice(n,1),r){var o=sourceTabs[n]||sourceTabs[n-1]||"";if(o)openSourceFile(o);else{var i=document.getElementById("source-viewer");i&&(i.dataset.openPath="");var a=document.getElementById("source-body");a&&(a.className="source-body empty",a.textContent=t("source.selectFile")),sourceLinks.forEach(function(e){e.classList.remove("active")}),renderSourceTabs("")}}else renderSourceTabs(currentSourceTabPath())}}function closeActiveSourceTab(){var e=currentSourceTabPath();return!!e&&(closeSourceTab(e),!0)}function cycleSourceTab(e){if(!(sourceTabs.length<2)){var t=sourceTabs.indexOf(currentSourceTabPath());t<0&&(t=0),openSourceFile(sourceTabs[(t+e+sourceTabs.length)%sourceTabs.length])}}function openSourceFile(e,n=!0){const r=sourceByPath.get(e);if(!r)return;if(composerState&&composerState.path!==e&&closeComposer(),addSourceTab(e),renderSourceTabs(e),REVIEW_LAZY_LOAD&&!sourceLoaded&&r.embedded){pendingSourceOpen={path:e,shouldSwitch:n},loadSourceData(),sourceBodyPath=null,document.getElementById("source-viewer").dataset.openPath=e,sourceLinks.forEach(t=>t.classList.toggle("active",t.dataset.sourceFile===e)),renderBreadcrumb(document.getElementById("source-title"),e),setSourceTypeIcon(e),revealTreeFor(e);var o=document.getElementById("source-body");return o.className="source-body empty",o.textContent=t("source.loading"),void(n&&showSourceView())}rememberRecent(e,"source"),sourceBodyPath=e,document.getElementById("source-viewer").dataset.openPath=e,sourceLinks.forEach(t=>t.classList.toggle("active",t.dataset.sourceFile===e)),renderBreadcrumb(document.getElementById("source-title"),e),setSourceTypeIcon(e),revealTreeFor(e);const i=r.embedded?formatBytes(r.size||0):formatBytes(r.size||0)+" · "+(r.skippedReason||"not embedded");document.getElementById("source-meta").textContent=i;const a=document.getElementById("source-body");if(r.image)return a.className="source-body image-body",a.innerHTML=renderImageView(r),document.getElementById("http-env-select")?.classList.add("hidden"),updateRenderToggle(e),void(n&&showSourceView());if(!r.embedded)return a.className="source-body empty",a.textContent=r.skippedReason?t("source.previewUnavailable").replace(/\.$/,"")+": "+r.skippedReason+".":t("source.previewUnavailable"),document.getElementById("http-env-select")?.classList.add("hidden"),updateRenderToggle(e),void(n&&showSourceView());viewerCursor&&viewerCursor.path===e||(viewerCursor={path:e,lineIndex:0,column:0,targetLine:-1}),a.className="source-body";const s=document.getElementById("http-env-select");if(isMarkdownPath(e))return renderRawMode?a.innerHTML=renderSourceTable(r,""):(a.classList.add("rendered-body"),a.innerHTML=renderMarkdownRows(r.content)),s&&s.classList.add("hidden"),updateRenderToggle(e),renderSourceComments(),void(n&&showSourceView());if(isCsvPath(e))return renderRawMode?a.innerHTML=renderSourceTable(r,""):(a.classList.add("rendered-body"),a.innerHTML=renderCsvRows(r.content,e)),s&&s.classList.add("hidden"),updateRenderToggle(e),renderSourceComments(),void(n&&showSourceView());if(isHttpFile(e))a.innerHTML=renderHttpTable(r),s&&s.classList.toggle("hidden",0===httpEnvNames.length);else if(a.innerHTML=renderSourceTable(r,""),s&&s.classList.add("hidden"),viewerCursor&&viewerCursor.path===e){var c=a.querySelector(".source-row.cursor-line");c&&insertSourceCaret(c,viewerCursor.column)}updateRenderToggle(e),renderSourceComments(),n&&showSourceView()}function isMarkdownPath(e){return/\.(md|mdx|markdown)$/i.test(e||"")}function isCsvPath(e){return/\.(csv|tsv)$/i.test(e||"")}function isRenderToggleable(e){return isMarkdownPath(e)||isCsvPath(e)}var renderRawMode=!1;function updateRenderToggle(e){var n=document.getElementById("render-toggle");if(n){var r=isRenderToggleable(e);n.classList.toggle("hidden",!r),r&&(n.textContent=t(renderRawMode?"source.viewRendered":"source.viewRaw"),n.setAttribute("aria-pressed",renderRawMode?"true":"false"))}}function toggleRenderMode(){var e=document.getElementById("source-viewer"),t=e&&e.dataset.openPath;t&&isRenderToggleable(t)&&(renderRawMode=!renderRawMode,openSourceFile(t,!1))}function renderImageView(e){return'<div class="image-view"><img class="image-preview" src="'+e.image+'" alt="'+escapeHtml(e.name)+'" data-zoomable="1"><div class="image-cap">'+escapeHtml(e.name)+" &middot; "+formatBytes(e.size||0)+" &middot; click to zoom</div></div>"}function openLightbox(e,t){if(e){var n=document.getElementById("mc-lightbox");n||((n=document.createElement("div")).id="mc-lightbox",n.className="mc-lightbox hidden",n.innerHTML='<img class="mc-lightbox-img" alt="">',document.body.appendChild(n),n.addEventListener("click",closeLightbox));var r=n.querySelector("img");r.src=e,r.alt=t||"",n.classList.remove("hidden")}}function closeLightbox(){var e=document.getElementById("mc-lightbox");e&&e.classList.add("hidden")}function lightboxOpen(){var e=document.getElementById("mc-lightbox");return!(!e||e.classList.contains("hidden"))}function renderInlineMd(e){var t=escapeHtml(e);return t=(t=(t=(t=(t=(t=t.replace(/`([^`]+)`/g,function(e,t){return"<code>"+t+"</code>"})).replace(/!\[([^\]]*)\]\(([^)\s]+)[^)]*\)/g,function(e,t,n){return/^(https?:|data:)/i.test(n)?'<img class="md-img" src="'+n+'" alt="'+t+'">':e})).replace(/\[([^\]]+)\]\(([^)\s]+)[^)]*\)/g,function(e,t,n){return/^(https?:|mailto:|#)/i.test(n)?'<a href="'+n+'" target="_blank" rel="noopener noreferrer">'+t+"</a>":t})).replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>").replace(/__([^_]+)__/g,"<strong>$1</strong>")).replace(/(^|[^*])\*([^*\s][^*]*)\*/g,"$1<em>$2</em>").replace(/(^|[^_\w])_([^_\s][^_]*)_/g,"$1<em>$2</em>")).replace(/~~([^~]+)~~/g,"<del>$1</del>")}function sanitizeHtml(e){var t=document.createElement("template");t.innerHTML=String(e);var n={SCRIPT:1,STYLE:1,IFRAME:1,OBJECT:1,EMBED:1,LINK:1,META:1,BASE:1,FORM:1,INPUT:1,BUTTON:1,TEXTAREA:1,SELECT:1,NOSCRIPT:1},r=function(e){for(var t=Array.prototype.slice.call(e.children||[]),o=0;o<t.length;o++){var i=t[o];if(n[i.tagName])i.parentNode.removeChild(i);else{for(var a=Array.prototype.slice.call(i.attributes),s=0;s<a.length;s++){var c=a[s].name.toLowerCase();0!==c.indexOf("on")?"href"!==c&&"src"!==c&&"xlink:href"!==c&&"srcset"!==c||!/^\s*(javascript|vbscript|data:text\/html):/i.test(a[s].value||"")||i.removeAttribute(a[s].name):i.removeAttribute(a[s].name)}r(i)}}};return r(t.content),t.innerHTML}function mdFenceLang(e){var t=(e||"").toLowerCase();return"js"===t||"jsx"===t||"ts"===t||"tsx"===t?"typescript":"sh"===t||"bash"===t||"zsh"===t?"shell":"yml"===t?"yaml":t||"text"}function splitTableRow(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(function(e){return e.trim()})}function renderMarkdownBlocks(e){for(var t,n=String(e).split(/\r?\n/),r=[],o=0;o<n.length;){var i=o,a=n[o],s=a.match(/^(\s*)(```+|~~~+)\s*([\w+#-]*)\s*$/);if(s){var c=s[2].charAt(0),l=new RegExp("^\\s*"+("`"===c?"`":"~")+"{3,}\\s*$"),d=mdFenceLang(s[3]),u=[];for(o++;o<n.length&&!l.test(n[o]);)u.push(n[o]),o++;o++,r.push({line:i,html:'<pre class="md-code"><code>'+u.map(function(e){return highlightLine(e,d)}).join("\n")+"</code></pre>"})}else if(/^\s*$/.test(a))o++;else if(/^\s*<(\/?[a-zA-Z][\w-]*|!--)/.test(a)){var f=[a];for(o++;o<n.length&&!/^\s*$/.test(n[o]);)f.push(n[o]),o++;r.push({line:i,html:'<div class="md-html">'+sanitizeHtml(f.join("\n"))+"</div>"})}else{var m=a.match(/^\s{0,3}(#{1,6})\s+(.*)$/);if(m){var p=m[1].length;r.push({line:i,html:"<h"+p+' class="md-h md-h'+p+'">'+renderInlineMd(m[2].replace(/\s+#+\s*$/,""))+"</h"+p+">"}),o++}else if(/^\s*([-*_])\s*(\1\s*){2,}$/.test(a))r.push({line:i,html:'<hr class="md-hr">'}),o++;else if(/^\s*>\s?/.test(a)){for(var h=[];o<n.length&&/^\s*>\s?/.test(n[o]);)h.push(n[o].replace(/^\s*>\s?/,"")),o++;r.push({line:i,html:'<blockquote class="md-quote">'+h.map(function(e){return e.trim()?"<p>"+renderInlineMd(e)+"</p>":""}).join("")+"</blockquote>"})}else if(/\|/.test(a)&&o+1<n.length&&/^\s*\|?[\s:|-]*-[\s:|-]*\|?\s*$/.test(n[o+1])){var v=splitTableRow(a);o+=2;for(var g="";o<n.length&&/\|/.test(n[o])&&!/^\s*$/.test(n[o]);){var y=splitTableRow(n[o]);g+="<tr>"+v.map(function(e,t){return"<td>"+renderInlineMd(y[t]||"")+"</td>"}).join("")+"</tr>",o++}r.push({line:i,html:'<table class="md-table"><thead><tr>'+v.map(function(e){return"<th>"+renderInlineMd(e)+"</th>"}).join("")+"</tr></thead><tbody>"+g+"</tbody></table>"})}else if(t=n[o].match(/^(\s*)([-*+]|\d+[.)])\s+(.*)$/)){for(var w=/\d/.test(t[2])?"ol":"ul",C="";o<n.length&&(t=n[o].match(/^(\s*)([-*+]|\d+[.)])\s+(.*)$/));)C+="<li>"+renderInlineMd(t[3])+"</li>",o++;r.push({line:i,html:"<"+w+' class="md-list">'+C+"</"+w+">"})}else{var b=[a];for(o++;o<n.length&&!/^\s*$/.test(n[o])&&!/^(\s{0,3}#{1,6}\s|\s*>|\s*([-*+]|\d+[.)])\s|\s*(```|~~~))/.test(n[o]);)b.push(n[o]),o++;r.push({line:i,html:'<p class="md-p">'+renderInlineMd(b.join("\n")).replace(/\n/g,"<br>")+"</p>"})}}}return r}function renderMarkdownRows(e){var t=renderMarkdownBlocks(e);return t.length?'<table class="source-table md-doc"><tbody>'+t.map(function(e){return'<tr class="source-row md-row" data-line-index="'+e.line+'"><td class="num">'+(e.line+1)+'</td><td class="source-code md-cell">'+e.html+"</td></tr>"}).join("")+"</tbody></table>":'<table class="source-table md-doc"><tbody></tbody></table>'}function parseDelimited(e,t){for(var n=[],r=[],o="",i=!1,a=String(e),s=0;s<a.length;s++){var c=a[s];i?'"'===c?'"'===a[s+1]?(o+='"',s++):i=!1:o+=c:'"'===c?i=!0:c===t?(r.push(o),o=""):"\n"===c?(r.push(o),n.push(r),r=[],o=""):"\r"!==c&&(o+=c)}return(o.length>0||r.length>0)&&(r.push(o),n.push(r)),n}function renderCsvRows(e,t){var n=parseDelimited(e,/\.tsv$/i.test(t||"")?"\t":",").filter(function(e){return!(1===e.length&&""===e[0])});if(!n.length)return'<table class="source-table csv-doc"><tbody></tbody></table>';var r=n.reduce(function(e,t){return Math.max(e,t.length)},0);return'<table class="source-table csv-doc"><tbody>'+n.map(function(e,t){for(var n=0===t,o="",i=0;i<r;i++){var a=escapeHtml(null==e[i]?"":e[i]);o+=n?'<th class="csv-cell">'+a+"</th>":'<td class="csv-cell">'+a+"</td>"}return'<tr class="source-row csv-row'+(n?" csv-head":"")+'" data-line-index="'+t+'"><td class="num">'+(t+1)+"</td>"+o+"</tr>"}).join("")+"</tbody></table>"}function isHttpFile(e){return/\.(http|rest)$/i.test(e||"")}function currentHttpEnv(){return httpEnvironments[currentHttpEnvName]||{}}function applyHttpVars(e,t){return String(null==e?"":e).replace(/\{\{\s*([\w.$-]+)\s*\}\}/g,function(e,n){return t&&Object.prototype.hasOwnProperty.call(t,n)?t[n]:e})}function parseHttpRequests(e){const t={GET:1,POST:1,PUT:1,PATCH:1,DELETE:1,HEAD:1,OPTIONS:1,TRACE:1,CONNECT:1},n=String(e).split(/\r?\n/),r=[],o={};let i=null,a="pre";function s(){i&&i.url&&(i.body=i.bodyLines.join("\n").replace(/\s+$/,""),r.push(i))}function c(e,t,n){return{name:t,method:"",url:"",headers:[],bodyLines:[],startLine:-1,endLine:n,boundaryLine:e}}for(let e=0;e<n.length;e++){const r=n[e],l=r.trim();if(0!==l.indexOf("###")){if(i||(i=c(-1,"",e),a="pre"),i.endLine=e,"pre"===a){if(""===l)continue;if(0===l.indexOf("#")||0===l.indexOf("//"))continue;const n=/^@([\w.$-]+)\s*=\s*(.*)$/.exec(l);if(n){o[n[1]]=n[2].trim();continue}const r=l.indexOf(" "),s=r>=0?l.slice(0,r):l;r>=0&&t[s.toUpperCase()]?(i.method=s.toUpperCase(),i.url=l.slice(r+1).replace(/\s+HTTP\/[\d.]+\s*$/i,"").trim()):(i.method="GET",i.url=l.replace(/\s+HTTP\/[\d.]+\s*$/i,"").trim()),i.startLine=e,a="headers";continue}if("headers"===a){if(""===l){a="body";continue}if(0===l.indexOf("#")||0===l.indexOf("//"))continue;const e=r.indexOf(":");e>0&&i.headers.push({name:r.slice(0,e).trim(),value:r.slice(e+1).trim()});continue}i.bodyLines.push(r)}else s(),i=c(e,l.replace(/^#+/,"").trim(),e),a="pre"}return s(),{requests:r,vars:o}}function renderHttpTable(e){const t=parseHttpRequests(e.content),n=t.requests;httpRequestsByPath.set(e.path,n),httpVarsByPath.set(e.path,t.vars);const r=Object.assign({},t.vars,currentHttpEnv()),o=String(e.content).split(/\r?\n/),i=viewerCursor&&viewerCursor.path===e.path?viewerCursor:null,a={},s={};n.forEach(function(e,t){e.startLine>=0&&(a[e.startLine]=t),s[e.endLine]=t});let c="";return o.forEach(function(e,t){const n=Object.prototype.hasOwnProperty.call(a,t),o=n?a[t]:-1,l=Boolean(i&&i.lineIndex===t);if(c+='<tr class="source-row http-row'+(n?" http-request-line":"")+(l?" cursor-line":"")+'" data-line-index="'+t+'"><td class="num http-gutter">'+(n?'<button type="button" class="http-run" data-req="'+o+'" title="Run request (⌘Enter / ⌥Enter)" aria-label="Run request">&#9654;</button>':"")+'<span class="num-text">'+(t+1)+'</span></td><td class="source-code">'+(l?renderHttpLineWithCursor(e,r,i.column):highlightHttpLine(e,r))+"</td></tr>",Object.prototype.hasOwnProperty.call(s,t)){const e=s[t];c+='<tr class="http-response-row"><td class="num"></td><td class="source-code"><div class="http-response hidden" id="http-resp-'+e+'"></div></td></tr>'}}),'<table class="source-table http-table"><tbody>'+c+"</tbody></table>"}function renderHttpLineWithCursor(e,t,n){var r=Math.max(0,Math.min(n,e.length));return highlightHttpLine(e.slice(0,r),t)+'<span class="code-cursor" aria-hidden="true"></span>'+highlightHttpLine(e.slice(r),t)}function highlightHttpLine(e,t){const n=e.trim();if(0===n.indexOf("###"))return'<span class="http-sep">'+escapeHtml(e)+"</span>";if(0===n.indexOf("#")||0===n.indexOf("//"))return'<span class="tok-comment">'+escapeHtml(e)+"</span>";let r=escapeHtml(e);return r=r.replace(/^(\s*)(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|TRACE|CONNECT)(\s)/,function(e,t,n,r){return t+'<span class="http-method">'+n+"</span>"+r}),r=r.replace(/\{\{\s*([\w.$-]+)\s*\}\}/g,function(e,n){const r=t&&Object.prototype.hasOwnProperty.call(t,n);return'<span class="http-var '+(r?"known":"unknown")+'" title="'+escapeHtml(r?String(t[n]):"Undefined variable")+'">'+escapeHtml(e)+"</span>"}),r}function sendHttp(e){return window.monacoriHttp&&"function"==typeof window.monacoriHttp.send?Promise.resolve(window.monacoriHttp.send(e)):fetch("/__http_send",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(function(e){return e.json()})}function runHttpRequest(e){const t=document.getElementById("source-viewer")?.dataset.openPath||"",n=httpRequestsByPath.get(t);if(!n||!n[e])return;const r=n[e],o=Object.assign({},httpVarsByPath.get(t)||{},currentHttpEnv()),i={};r.headers.forEach(function(e){const t=applyHttpVars(e.name,o);t&&(i[t]=applyHttpVars(e.value,o))});const a={method:r.method||"GET",url:applyHttpVars(r.url,o),headers:i,body:r.body?applyHttpVars(r.body,o):void 0},s=document.getElementById("http-resp-"+e);s&&(s.className="http-response loading",s.textContent=a.method+" "+a.url),sendHttp(a).then(function(e){s&&renderHttpResponse(s,e)}).catch(function(e){s&&(s.className="http-response error",s.innerHTML='<div class="http-resp-head"><span class="http-status bad">Failed</span></div><pre class="http-resp-body">'+escapeHtml(String(e&&e.message?e.message:e))+"</pre>")})}function runHttpAtCaret(){const e=document.getElementById("source-viewer")?.dataset.openPath||"",t=httpRequestsByPath.get(e);if(!t||!t.length)return;const n=viewerCursor&&viewerCursor.path===e?viewerCursor.lineIndex:0;let r=-1;for(let e=0;e<t.length;e++){const o=t[e],i=o.boundaryLine>=0?o.boundaryLine:o.startLine;if(i<=n&&n<=o.endLine){r=e;break}i<=n&&(r=e)}r<0&&(r=0),runHttpRequest(r)}function renderHttpResponse(e,t){if(!t||!t.ok){e.className="http-response error";const n=t&&t.error?t.error:"Request failed";return void(e.innerHTML='<div class="http-resp-head"><span class="http-status bad">Failed</span></div><pre class="http-resp-body">'+escapeHtml(n)+"</pre>")}e.className="http-response";const n=Number(t.status)||0,r=n>=200&&n<300?"ok":n>=400?"bad":"warn",o=t.headers||{},i=Object.keys(o).sort(),a=i.map(function(e){return'<div class="http-h"><span class="http-h-k">'+escapeHtml(e)+'</span><span class="http-h-v">'+escapeHtml(String(o[e]))+"</span></div>"}).join("");let s="";for(let e=0;e<i.length;e++)if("content-type"===i[e].toLowerCase()){s=String(o[i[e]]);break}const c=null==t.body?"":String(t.body),l=formatHttpBody(c,s);e.innerHTML='<div class="http-resp-head"><span class="http-status '+r+'">'+n+(t.statusText?" "+escapeHtml(t.statusText):"")+'</span><span class="http-resp-meta">'+(Number(t.durationMs)||0)+' ms</span><span class="http-resp-meta">'+formatBytes(c.length)+"</span>"+(i.length?'<button type="button" class="http-resp-toggle">Headers ('+i.length+")</button>":"")+'</div><div class="http-resp-headers hidden">'+a+'</div><pre class="http-resp-body">'+l+"</pre>"}function formatHttpBody(e,t){if(!e)return'<span class="http-resp-empty">(empty body)</span>';if(/json/i.test(t)||/^[\[{]/.test(e.trim()))try{return JSON.stringify(JSON.parse(e),null,2).split(/\r?\n/).map(function(e){return highlightLine(e,"json")}).join("\n")}catch(e){}return escapeHtml(e)}function populateHttpEnvSelect(){const e=document.getElementById("http-env-select");if(!e)return;let t='<option value="">No environment</option>';httpEnvNames.forEach(function(e){t+='<option value="'+escapeHtml(e)+'"'+(e===currentHttpEnvName?" selected":"")+">"+escapeHtml(e)+"</option>"}),e.innerHTML=t,e.dataset.wired||(e.dataset.wired="1",e.addEventListener("change",function(){currentHttpEnvName=e.value;try{localStorage.setItem(httpEnvKey,currentHttpEnvName)}catch(e){}const t=document.getElementById("source-viewer")?.dataset.openPath||"";if(t&&isHttpFile(t)){const e=sourceByPath.get(t),n=document.getElementById("source-body");e&&n&&(n.innerHTML=renderHttpTable(e))}}))}function renderSourceTable(e,t){const n=t.trim().toLowerCase(),r=e.content.split(/\r?\n/),o=viewerCursor&&viewerCursor.path===e.path?viewerCursor:null,i=new Set(e.changedLines||[]);return'<table class="source-table"><tbody>'+r.map((t,r)=>{const a=n.length>0&&t.toLowerCase().includes(n),s=Boolean(o&&o.lineIndex===r),c=Boolean(o&&o.targetLine===r);return['<tr class="'+["source-row",a?"search-hit":"",i.has(r+1)?"changed-line":"",s?"cursor-line":"",c?"symbol-target":""].filter(Boolean).join(" ")+'" data-line-index="'+r+'">','<td class="num">'+String(r+1)+"</td>",'<td class="source-code">'+highlightLine(t,e.language||"text")+"</td>","</tr>"].join("")}).join("")+"</tbody></table>"}function renderLineWithCursor(e,t,n){const r=Math.max(0,Math.min(n,e.length)),o=e.slice(0,r),i=e.slice(r);return highlightLine(o,t)+'<span class="code-cursor" aria-hidden="true"></span>'+highlightLine(i,t)}function highlightLine(e,t){if("text"===t)return escapeHtml(e);if("markup"===t)return escapeHtml(e).replace(/(&lt;\/?)([\w:-]+)([^&]*?)(\/?&gt;)/g,'$1<span class="tok-tag">$2</span>$3$4');if("markdown"===t){const t=escapeHtml(e);return/^\s{0,3}#{1,6}\s/.test(e)?'<span class="tok-keyword">'+t+"</span>":t.replace(new RegExp(String.fromCharCode(96)+"[^"+String.fromCharCode(96)+"]+"+String.fromCharCode(96),"g"),'<span class="tok-string">$&</span>')}const n=new Set(["as","async","await","break","case","catch","class","const","continue","def","default","defer","do","else","enum","export","extends","final","finally","fn","for","from","func","function","go","if","impl","import","in","interface","let","match","module","new","package","private","protected","public","return","select","static","struct","switch","throw","try","type","val","var","while","yield"]),r=new Set(["False","None","True","false","nil","null","self","this","true","undefined"]),o=["python","ruby","shell","yaml","toml"].includes(t)?["#"]:["//"];let i="",a=0;for(;a<e.length;){const t=e.slice(a);if(o.find(e=>t.startsWith(e))){i+='<span class="tok-comment">'+escapeHtml(t)+"</span>";break}const s=e[a];if('"'===s||"'"===s||s===String.fromCharCode(96)){const t=s;let n=a+1,r=!1;for(;n<e.length;){const o=e[n];if(o===t&&!r){n+=1;break}r="\\"===o&&!r,"\\"!==o&&(r=!1),n+=1}i+='<span class="tok-string">'+escapeHtml(e.slice(a,n))+"</span>",a=n;continue}if("@"===s){const e=t.match(/^@[A-Za-z_$][\w$.]*/);if(e){i+='<span class="tok-decorator">'+escapeHtml(e[0])+"</span>",a+=e[0].length;continue}}const c=t.match(/^\b\d+(?:\.\d+)?\b/);if(c){i+='<span class="tok-number">'+escapeHtml(c[0])+"</span>",a+=c[0].length;continue}const l=t.match(/^[A-Za-z_$][\w$-]*/);if(l){const t=l[0],o=e.slice(a+t.length);n.has(t)?i+='<span class="tok-keyword">'+escapeHtml(t)+"</span>":r.has(t)?i+='<span class="tok-literal">'+escapeHtml(t)+"</span>":/^\s*\(/.test(o)?i+='<span class="tok-function">'+escapeHtml(t)+"</span>":/^[A-Z]/.test(t)&&/[a-z]/.test(t)?i+='<span class="tok-type">'+escapeHtml(t)+"</span>":i+=escapeHtml(t),a+=t.length;continue}i+=escapeHtml(s),a+=1}return i}function escapeHtml(e){return String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function formatBytes(e){if(e<1024)return e+" B";const t=e/1024;return t<1024?t.toFixed(1)+" KiB":(t/1024).toFixed(1)+" MiB"}!function(){var e=document.getElementById("render-toggle");e&&e.addEventListener("click",function(){toggleRenderMode()}),document.addEventListener("keydown",function(e){if(!isFloatingModalOpen()&&(e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey&&("M"===e.key||"m"===e.key||"KeyM"===e.code)){var t=document.getElementById("source-viewer"),n=t&&t.dataset.openPath;n&&isRenderToggleable(n)&&isSourceViewerVisible()&&(e.preventDefault(),toggleRenderMode())}})}();var HISTORY_LANE_W=14,HISTORY_DOT_R=3.5,HISTORY_ROW_H=24,HISTORY_COLORS=["#6c9fd4","#7faf6b","#d4a857","#c77dd4","#d36c6c","#5bb6b6","#b0884f","#8d8df0"],historyCommits=[],historyGraph=[],historyMaxLane=0,historyActiveSha="",historyLoading=!1;function computeHistoryGraph(e){var t=[],n={},r=0;function o(e){return null==n[e]&&(n[e]=r++),n[e]}function i(){for(var e=0;e<t.length;e++)if(null==t[e])return e;return t.push(null),t.length-1}for(var a=[],s=0,c=0;c<e.length;c++){var l=e[c],d=t.slice(),u=t.indexOf(l.hash);-1===u&&(u=i());var f=o(l.hash);t[u]=l.hash;for(var m=0;m<t.length;m++)m!==u&&t[m]===l.hash&&(t[m]=null);var p=l.parents||[],h={};if(0===p.length)t[u]=null;else{t[u]=p[0],null==n[p[0]]&&(n[p[0]]=f),h[u]=!0;for(var v=1;v<p.length;v++){var g=t.indexOf(p[v]),y=-1!==g?g:i();t[y]=p[v],o(p[v]),h[y]=!0}}for(var w=t.slice(),C=[],b=0;b<d.length;b++)null!=d[b]&&C.push({from:b,to:d[b]===l.hash?u:b,color:n[d[b]]});for(var S=[],E=0;E<w.length;E++)null!=w[E]&&S.push({from:h[E]?u:E,to:E,color:n[w[E]]});for(var k=0;k<Math.max(d.length,w.length);k++)null==d[k]&&null==w[k]||(s=Math.max(s,k));s=Math.max(s,u),a.push({hash:l.hash,myLane:u,color:f,topEdges:C,bottomEdges:S})}return a.maxLane=s,a}function historyLaneX(e){return 9+e*HISTORY_LANE_W}function historyColor(e){return HISTORY_COLORS[e%HISTORY_COLORS.length]}function historyRowSvg(e){var t=historyLaneX(historyMaxLane)+9,n=HISTORY_ROW_H,r=n/2,o='<svg class="hgraph" width="'+t+'" height="'+n+'" viewBox="0 0 '+t+" "+n+'" aria-hidden="true">',i=function(e,t,n){var r=historyLaneX(e.from),o=historyLaneX(e.to),i=(t+n)/2;return'<path d="M'+r+" "+t+" C "+r+" "+i+", "+o+" "+i+", "+o+" "+n+'" stroke="'+historyColor(e.color)+'" fill="none" stroke-width="1.6"/>'};return e.topEdges.forEach(function(e){o+=i(e,0,r)}),e.bottomEdges.forEach(function(e){o+=i(e,r,n)}),o+='<circle cx="'+historyLaneX(e.myLane)+'" cy="'+r+'" r="'+HISTORY_DOT_R+'" fill="'+historyColor(e.color)+'"/></svg>'}function historyRefBadges(e){return e&&e.trim()?e.split(",").map(function(e){if(!(e=e.trim()))return"";var t="href-branch",n=e;return 0===e.indexOf("tag:")?(t="href-tag",n=e.replace("tag:","").trim()):0===e.indexOf("HEAD")?t="href-head":0!==e.indexOf("origin/")&&-1===e.indexOf("/")||(t="href-remote"),'<span class="href '+t+'">'+escapeHtml(n)+"</span>"}).join(""):""}function historyShortDate(e){if(!e)return"";var t=String(e).match(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})/);return t?t[1]+" "+t[2]:String(e).slice(0,16)}function renderHistoryList(){var e=document.getElementById("history-list");e&&(historyCommits.length?(e.style.setProperty("--hgraph-w",historyLaneX(historyMaxLane)+9+"px"),e.innerHTML=historyCommits.map(function(e,t){return'<button type="button" class="hrow'+(e.hash===historyActiveSha?" active":"")+'" data-sha="'+escapeHtml(e.hash)+'"><span class="hgraph-cell">'+historyRowSvg(historyGraph[t])+'</span><span class="hmsg">'+historyRefBadges(e.refs)+escapeHtml(e.subject)+'</span><span class="hauthor">'+escapeHtml(e.author)+'</span><span class="hdate">'+escapeHtml(historyShortDate(e.date))+"</span></button>"}).join("")):e.innerHTML='<div class="quick-open-empty">'+escapeHtml(t(historyLoading?"history.loading":"history.empty"))+"</div>")}function applyHistoryFilter(){var e=document.getElementById("history-search"),t=document.getElementById("history-list");if(t){var n=(e&&e.value||"").trim().toLowerCase();t.classList.toggle("filtering",n.length>0);for(var r=t.querySelectorAll(".hrow"),o=0;o<r.length;o++){var i=historyCommits[o],a=!n||-1!==(i.subject+"\n"+i.author+"\n"+i.hash).toLowerCase().indexOf(n);r[o].classList.toggle("hidden",!a)}}}function openHistoryCommit(e){if(e&&window.monacoriGit){historyActiveSha=e;var n=document.getElementById("history-list");n&&n.querySelectorAll(".hrow").forEach(function(t){t.classList.toggle("active",t.dataset.sha===e)});var r=document.getElementById("history-detail");r&&(r.innerHTML='<div class="quick-open-empty">'+escapeHtml(t("history.loading"))+"</div>"),Promise.resolve(window.monacoriGit.commitDiff(e)).then(function(t){t&&historyActiveSha===e&&renderHistoryDetail(t)},function(){})}}function renderHistoryDetail(e){var n=document.getElementById("history-detail");if(n){var r='<div class="history-detail-head"><div class="hd-msg">'+escapeHtml(e.message||"").replace(/\n/g,"<br>")+'</div><div class="hd-meta"><span class="hd-hash">'+escapeHtml((e.hash||"").slice(0,10))+'</span><span class="hd-author">'+escapeHtml(e.author)+(e.email?" &lt;"+escapeHtml(e.email)+"&gt;":"")+'</span><span class="hd-date">'+escapeHtml(historyShortDate(e.date))+"</span>"+historyRefBadges(e.refs)+"</div></div>",o=e.diffHtml&&e.diffHtml.trim()?'<div class="history-diff diff2html-container">'+e.diffHtml+"</div>":'<div class="quick-open-empty">'+escapeHtml(t(e.isMerge?"history.merge":"history.noDiff"))+"</div>";n.innerHTML=r+o}}function isHistoryOpen(){var e=document.getElementById("history-view");return!(!e||e.classList.contains("hidden"))}function closeHistory(){var e=document.getElementById("history-view");e&&e.classList.add("hidden"),"function"==typeof syncRail&&syncRail()}function openHistory(){var e=document.getElementById("history-view");if(e&&window.monacoriGit){e.classList.remove("hidden"),"function"==typeof syncRail&&syncRail();var n=document.getElementById("history-search");n&&(n.value=""),applyHistoryFilter(),historyLoading=!0,renderHistoryList(),Promise.resolve(window.monacoriGit.log({limit:300})).then(function(e){historyLoading=!1,historyCommits=Array.isArray(e)?e:[],historyGraph=computeHistoryGraph(historyCommits),historyMaxLane=historyGraph.maxLane||0,renderHistoryList();var r=document.getElementById("history-detail");r&&(r.innerHTML='<div class="quick-open-empty">'+escapeHtml(t("history.selectCommit"))+"</div>"),historyCommits[0]&&openHistoryCommit(historyCommits[0].hash),n&&setTimeout(function(){try{n.focus()}catch(e){}},0)},function(){historyLoading=!1,renderHistoryList()})}}function toggleHistory(){isHistoryOpen()?closeHistory():openHistory()}function copyTextToClipboard(e){try{if(window.monacoriClipboard&&"function"==typeof window.monacoriClipboard.write)return window.monacoriClipboard.write(e),!0}catch(e){}try{if(navigator.clipboard&&navigator.clipboard.writeText)return navigator.clipboard.writeText(e),!0}catch(e){}return!1}function caretLocation(){if("function"==typeof isSourceViewerVisible&&isSourceViewerVisible()){var e=document.getElementById("source-viewer"),t=e&&e.dataset.openPath||"";if(t&&void 0!==viewerCursor&&viewerCursor&&viewerCursor.path===t)return t+":"+(viewerCursor.lineIndex+1);if(t)return t}if("function"==typeof isDiffViewVisible&&isDiffViewVisible()&&void 0!==diffCursor&&diffCursor){var n=diffWrapperByPath(diffCursor.path),r=n?diffRowAt(n,diffCursor.side,diffCursor.rowIndex):null,o=r?diffLineNumber(r):null;return diffCursor.path+(o?":"+o:"")}return""}function copyCaretLocation(){var e=caretLocation();e&&copyTextToClipboard(e)&&"function"==typeof showToast&&showToast(t("goto.copied")+" "+e)}function gotoDiffLine(e){var t=void 0!==diffCursor&&diffCursor&&diffCursor.path||"";if(!t&&"function"==typeof diffActiveWrapper){var n=diffActiveWrapper(),r=n&&n.querySelector(".d2h-file-name");r&&r.textContent&&(t=r.textContent.trim())}var o=t&&diffWrapperByPath(t);if(o)for(var i=[diffCursor&&diffCursor.side||"new","new","old"],a=0;a<i.length;a++)for(var s=diffRowsOf(diffSideTable(o,i[a])),c=0;c<s.length;c++)if(diffLineNumber(s[c])===e)return void setDiffCursor(t,i[a],c,0,!0)}function gotoLineJump(e){if(e>=1){if("function"==typeof isSourceViewerVisible&&isSourceViewerVisible()){var t=document.getElementById("source-viewer"),n=t&&t.dataset.openPath||"",r=n&&sourceByPath.get(n);if(r&&r.embedded&&"string"==typeof r.content){var o=r.content.split(/\r?\n/).length;return void setSourceCursor(n,Math.max(0,Math.min(o-1,e-1)),0,!0,-1)}}"function"==typeof isDiffViewVisible&&isDiffViewVisible()&&gotoDiffLine(e)}}function openGotoLine(){if("function"==typeof isSourceViewerVisible&&isSourceViewerVisible()||"function"==typeof isDiffViewVisible&&isDiffViewVisible()){var e=document.getElementById("goto-line");e&&e.remove();var n=document.createElement("div");n.id="goto-line",n.className="goto-line";var r=document.createElement("input");r.type="text",r.inputMode="numeric",r.className="goto-line-input",r.placeholder=t("goto.placeholder"),n.appendChild(r),document.body.appendChild(n),document.addEventListener("keydown",i,!0),setTimeout(function(){try{r.focus()}catch(e){}},0)}function o(){n.remove(),document.removeEventListener("keydown",i,!0)}function i(e){if("Escape"===e.key)e.preventDefault(),e.stopPropagation(),o();else if("Enter"===e.key){e.preventDefault(),e.stopPropagation();var t=parseInt(r.value,10);o(),t>=1&&gotoLineJump(t)}}}function openTreeRowMenu(e){if(e){var n=e.dataset.sourceFile||e.dataset.file||"";if(n){var r=e.getBoundingClientRect(),o=[{label:t("menu.copyPath"),onSelect:function(){copyTextToClipboard(n)&&"function"==typeof showToast&&showToast(t("goto.copied")+" "+n)}}];window.monacoriApp&&"function"==typeof window.monacoriApp.revealInFinder&&(o.push({label:t("menu.revealFinder"),onSelect:function(){try{window.monacoriApp.revealInFinder(n)}catch(e){}}}),o.push({label:t("menu.openTerminal"),onSelect:function(){try{window.monacoriApp.openTerminalAt(n)}catch(e){}}})),showCustomDropdown(Math.round(r.left+14),Math.round(r.bottom+2),o,Math.round(r.top))}}}"undefined"!=typeof window&&(window.computeHistoryGraph=computeHistoryGraph),"undefined"!=typeof window&&(window.__monacoriHistory={open:openHistory,close:closeHistory,toggle:toggleHistory,isOpen:isHistoryOpen}),function(){var e=document.getElementById("history-list");e&&e.addEventListener("click",function(e){var t=e.target.closest&&e.target.closest(".hrow[data-sha]");t&&openHistoryCommit(t.dataset.sha)});var t=document.getElementById("history-search");t&&t.addEventListener("input",applyHistoryFilter);var n=document.getElementById("history-close");n&&n.addEventListener("click",closeHistory);var r=document.getElementById("history-view");r&&r.addEventListener("keydown",function(e){"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),closeHistory())})}();
1
+ const REVIEW_LAZY="true"===document.getElementById("review-meta")?.dataset.lazy,REVIEW_LAZY_LOAD="true"===document.getElementById("review-meta")?.dataset.lazyLoad;REVIEW_LAZY||prepareDiff2HtmlHunks();const hunks=REVIEW_LAZY?[]:Array.from(document.querySelectorAll(".hunk")),hunkPeers=REVIEW_LAZY?[]:Array.from(document.querySelectorAll(".hunk-peer")),hunkMeta=[];REVIEW_LAZY&&Array.prototype.forEach.call(document.querySelectorAll("#diff2html-container .d2h-file-wrapper"),function(e){for(var t=parseInt(e.dataset.firstHunk||"0",10)||0,n=parseInt(e.dataset.hunkCount||"0",10)||0,r=e.dataset.path||((e.querySelector(".d2h-file-name")||{}).textContent||"").trim(),o=0;o<n;o++)hunkMeta[t+o]={path:r}});var diffBootDone=!1;function refreshHunkIndex(){REVIEW_LAZY?(hunkMeta.length=0,Array.prototype.forEach.call(document.querySelectorAll("#diff2html-container .d2h-file-wrapper"),function(e){for(var t=parseInt(e.dataset.firstHunk||"0",10)||0,n=parseInt(e.dataset.hunkCount||"0",10)||0,r=e.dataset.path||((e.querySelector(".d2h-file-name")||{}).textContent||"").trim(),o=0;o<n;o++)hunkMeta[t+o]={path:r}})):(prepareDiff2HtmlHunks(),hunks.length=0,Array.prototype.push.apply(hunks,document.querySelectorAll(".hunk")),hunkPeers.length=0,Array.prototype.push.apply(hunkPeers,document.querySelectorAll(".hunk-peer")))}function hunkTotal(){return REVIEW_LAZY?hunkMeta.length:hunks.length}function hunkPathAt(e){return REVIEW_LAZY?hunkMeta[e]?hunkMeta[e].path:"":hunks[e]?hunks[e].dataset.file:""}function hunkRowAt(e){if(!REVIEW_LAZY)return hunks[e]||null;var t=hunkMeta[e];return t?(ensureFileReady(diffWrapperByPath(t.path)),document.getElementById("hunk-"+e)):null}function markWrapperHunks(e){var t=parseInt(e.dataset.firstHunk||"0",10)||0,n=((e.querySelector(".d2h-file-name")||{}).textContent||"").trim(),r=new Map,o=0;Array.prototype.forEach.call(e.querySelectorAll("tr"),function(e){var i=(e.textContent||"").trim();if(0===i.indexOf("@@")){var a=r.get(i);void 0===a?(a=t+o,r.set(i,a),e.classList.add("hunk"),e.id="hunk-"+a,o+=1):e.classList.add("hunk-peer"),e.dataset.hunkIndex=String(a),e.dataset.file=n}})}var bodyCache={},bodyPromise={};function loadBodyHtml(e){return null!=bodyCache[e]?Promise.resolve(bodyCache[e]):("undefined"!=typeof window&&window.monacoriFile&&"function"==typeof window.monacoriFile.get?Promise.resolve().then(function(){return window.monacoriFile.get(Number(e),"diff")}):"undefined"!=typeof fetch?fetch("file?index="+e).then(function(e){return e.ok?e.text():""}):Promise.resolve("")).then(function(t){return bodyCache[e]=t||"",bodyCache[e]},function(){return bodyCache[e]="",""})}function materializeBody(e,t){var n=e.querySelector(".d2h-files-diff[data-lazy]");if(n&&(n.innerHTML=t||"",n.removeAttribute("data-lazy"),n.removeAttribute("data-loading"),markWrapperHunks(e),diffBootDone&&void 0!==reviewComments&&reviewComments.length))try{refreshComments()}catch(e){}}function ensureFileReady(e){if(!e)return null;var t=e.querySelector(".d2h-files-diff[data-lazy]");if(!t)return e;var n=(e.id||"").replace("file-","");if(REVIEW_LAZY_LOAD)return bodyPromise[n]||(t.setAttribute("data-loading","1"),bodyPromise[n]=loadBodyHtml(n).then(function(t){return materializeBody(e,t),e})),e;var r=document.getElementById("diff-body-"+n);return r&&materializeBody(e,r.textContent||""),e}function whenFileReady(e,t){if(e){ensureFileReady(e);var n=e.querySelector(".d2h-files-diff");if(n&&n.hasAttribute("data-lazy")){var r=(e.id||"").replace("file-","");bodyPromise[r]?bodyPromise[r].then(function(){t()}):t()}else t()}else t()}var lazyIO=null;function setupLazyDiff(){var e=document.getElementById("diff2html-container");if(e){if(lazyIO){try{lazyIO.disconnect()}catch(e){}lazyIO=null}var t=Array.prototype.slice.call(e.querySelectorAll(".d2h-file-wrapper"));if("undefined"!=typeof IntersectionObserver){var n=new IntersectionObserver(function(e){e.forEach(function(e){e.isIntersecting&&(ensureFileReady(e.target),n.unobserve(e.target))})},{root:null,rootMargin:"600px 0px"});lazyIO=n,t.forEach(function(e){n.observe(e)})}else t.forEach(function(e){ensureFileReady(e)});t[0]&&ensureFileReady(t[0])}}REVIEW_LAZY&&(setupLazyDiff(),setTimeout(function(){diffBootDone=!0},0));let links=Array.from(document.querySelectorAll("#changes-panel .file-link")),sourceLinks=Array.from(document.querySelectorAll(".source-link")),sourceFiles=JSON.parse(document.getElementById("source-files-data")?.textContent||"[]");var I18N=JSON.parse(document.getElementById("i18n-data")?.textContent||"{}");function persistRead(e){try{if(window.monacoriSettings&&window.monacoriSettings.all&&e in window.monacoriSettings.all){var t=window.monacoriSettings.all[e];return t&&"object"==typeof t?JSON.parse(JSON.stringify(t)):t}}catch(e){}}function persistSave(e,t){try{localStorage.setItem(e,"string"==typeof t?t:JSON.stringify(t))}catch(e){}try{window.monacoriSettings&&window.monacoriSettings.set(e,t)}catch(e){}}var LOCALE_KEY="monacori-locale",locale=function(){var e=persistRead(LOCALE_KEY);if("ko"!==e&&"en"!==e)try{e=localStorage.getItem(LOCALE_KEY)}catch(e){}return"ko"===e||"en"===e?e:"en"}();function t(e){var t=I18N[locale]||I18N.en||{};return t&&e in t?t[e]:I18N.en&&I18N.en[e]||e}var langSelectRef=null,themeSelectRef=null;function setupCustomSelect(e,t,n,r){var o=document.getElementById(e);if(!o)return null;function i(){var e=n(),r=t().filter(function(t){return t.value===e})[0];o.textContent=r?r.label:e}return o.addEventListener("click",function(e){e.preventDefault();var a=o.getBoundingClientRect(),s=n();showCustomDropdown(a.left,a.bottom+4,t().map(function(e){return{label:(e.value===s?"✓ ":"  ")+e.label,onSelect:function(){r(e.value),i()}}}),a.top-4)}),i(),{render:i}}function applyI18n(){document.querySelectorAll("[data-i18n]").forEach(function(e){e.textContent=t(e.getAttribute("data-i18n"))}),document.querySelectorAll("[data-i18n-ph]").forEach(function(e){e.setAttribute("placeholder",t(e.getAttribute("data-i18n-ph")))}),document.querySelectorAll("[data-i18n-title]").forEach(function(e){e.setAttribute("title",t(e.getAttribute("data-i18n-title")))}),document.querySelectorAll("[data-i18n-aria]").forEach(function(e){e.setAttribute("aria-label",t(e.getAttribute("data-i18n-aria")))}),document.documentElement.lang=locale,langSelectRef&&langSelectRef.render(),themeSelectRef&&themeSelectRef.render()}var THEME_KEY="monacori-theme",theme=function(){var e=persistRead(THEME_KEY);if("light"!==e&&"dark"!==e)try{e=localStorage.getItem(THEME_KEY)}catch(e){}return"light"===e||"dark"===e?e:"dark"}();function applyTheme(){document.documentElement.setAttribute("data-theme",theme),themeSelectRef&&themeSelectRef.render()}applyTheme();let fileStates=JSON.parse(document.getElementById("file-state-data")?.textContent||"[]"),httpEnvironments=JSON.parse(document.getElementById("http-env-data")?.textContent||"{}"),httpEnvNames=Object.keys(httpEnvironments);const httpEnvKey="monacori-http-env:"+location.pathname,httpRequestsByPath=new Map,httpVarsByPath=new Map;let sourceByPath=new Map(sourceFiles.map(e=>[e.path,e]));var sourceLoaded=!REVIEW_LAZY_LOAD,pendingSourceOpen=null,sourceBodyPath=null,sourceLoading=!1,pendingSymbol=null,sourceTabs=[];function loadSourceData(){sourceLoaded||sourceLoading||(sourceLoading=!0,("undefined"!=typeof window&&window.monacoriFile&&"function"==typeof window.monacoriFile.getSourceData?Promise.resolve().then(function(){return window.monacoriFile.getSourceData()}):"undefined"!=typeof fetch?fetch("source-data").then(function(e){return e.ok?e.text():"[]"}):Promise.resolve("[]")).then(function(e){var t=[];try{t=JSON.parse(e||"[]")}catch(e){t=[]}for(var n=0;n<t.length;n++){var r=sourceByPath.get(t[n].path);r&&(r.content=t[n].content,t[n].image&&(r.image=t[n].image))}if(sourceLoaded=!0,sourceLoading=!1,scheduleSymbolIndex(),remapComments(),pendingSourceOpen){var o=pendingSourceOpen;pendingSourceOpen=null,openSourceFile(o.path,o.shouldSwitch)}else isSourceViewerVisible()&&document.getElementById("source-viewer").dataset.openPath&&openSourceFile(document.getElementById("source-viewer").dataset.openPath,!1);if(pendingSymbol){var i=pendingSymbol;pendingSymbol=null,goToDefOrUsages(i)}},function(){sourceLoaded=!0,sourceLoading=!1}))}let fileSignatureByPath=new Map(fileStates.map(e=>[e.path,e.signature]));const reviewMeta=document.getElementById("review-meta"),watchEnabled="true"===reviewMeta?.dataset.watch;let currentSignature=reviewMeta?.dataset.signature||"";const uiStateKey="monacori-diff-ui:"+location.pathname,recentKey="monacori-diff-recent:"+location.pathname,viewedKey="monacori-diff-viewed:"+location.pathname,quickOpen=document.getElementById("quick-open"),quickInput=document.getElementById("quick-open-input"),quickResults=document.getElementById("quick-open-results"),quickModeLabel=document.getElementById("quick-open-mode"),quickFilterEl=document.getElementById("quick-open-filter");let current=-1,checkingForUpdates=!1,lastShiftAt=0,lastShiftSide=0,quickMode="all",quickItems=[],quickActive=0,recentFilter="",usageItems=[],usageActive=0,viewerCursor=null,selectedCommentRow=null,currentHttpEnvName=function(){let e="";try{e=localStorage.getItem(httpEnvKey)||""}catch(t){e=""}return e&&httpEnvNames.indexOf(e)>=0?e:httpEnvNames.length?httpEnvNames[0]:""}(),treeFocusIndex=-1,selectionAnchor=null,diffCursor=null,navList=[],navPos=-1,navSuppress=!1;var NAV_JUMP_LINES=8,NAV_MAX=60;let diffSelectionAnchor=null,measuredCharWidth=0;var COMMENTS_KEY="monacori-comments:"+location.pathname,reviewComments=[];reviewComments=function(){var e=persistRead(COMMENTS_KEY);if(Array.isArray(e))return e;try{return JSON.parse(localStorage.getItem(COMMENTS_KEY)||"[]")}catch(e){return[]}}(),Array.isArray(reviewComments)||(reviewComments=[]);var commentSeq=reviewComments.reduce(function(e,t){return Math.max(e,t.seq||0)},0),composerState=null;function prepareDiff2HtmlHunks(){const e=Array.from(document.querySelectorAll(".d2h-file-wrapper"));let t=0;e.forEach((e,n)=>{e.id="file-"+n;const r=e.querySelector(".d2h-file-name")?.textContent?.trim()||"",o=new Map;Array.from(e.querySelectorAll("tr")).forEach(e=>{const n=e.textContent.trim();if(!n.startsWith("@@"))return;let i=o.get(n);void 0===i?(i=t,o.set(n,i),e.classList.add("hunk"),e.id="hunk-"+i,t+=1):e.classList.add("hunk-peer"),e.dataset.hunkIndex=String(i),e.dataset.file=r})})}function prepareViewedControls(){document.querySelectorAll(".d2h-file-wrapper").forEach(e=>{const n=e.querySelector(".d2h-file-name")?.textContent?.trim()||"",r=e.querySelector(".d2h-file-collapse"),o=r?.querySelector("input");n&&r&&o&&(r.title=t("btn.viewed.title"),o.tabIndex=-1,r.addEventListener("click",e=>{e.preventDefault(),setFileViewed(n,!isFileViewed(n))}))}),applyViewedState()}function loadViewedState(){try{const e=JSON.parse(localStorage.getItem(viewedKey)||"{}");return e&&"object"==typeof e&&!Array.isArray(e)?e:{}}catch{return{}}}function saveViewedState(e){try{localStorage.setItem(viewedKey,JSON.stringify(e))}catch{}}function currentFileSignature(e){return fileSignatureByPath.get(e)||""}function isFileViewed(e){const t=loadViewedState();return Boolean(t[e])}function setFileViewed(e,t){const n=loadViewedState();t?n[e]=!0:delete n[e],saveViewedState(n),applyViewedState()}function applyViewedState(){document.querySelectorAll(".d2h-file-wrapper").forEach(e=>{const t=isFileViewed(e.querySelector(".d2h-file-name")?.textContent?.trim()||"");e.classList.toggle("file-viewed",t);const n=e.querySelector(".d2h-file-collapse-input");n&&(n.checked=t)}),links.forEach(e=>{e.classList.toggle("viewed",isFileViewed(e.dataset.file||""))}),updateDiffViewedToggle()}function updateDiffViewedToggle(){var e=document.getElementById("diff-viewed-toggle");if(e){var t=e.dataset.file||"",n=Boolean(t&&currentFileSignature(t));if(e.hidden=!n,n){var r=isFileViewed(t);e.classList.toggle("is-viewed",r),e.setAttribute("aria-pressed",r?"true":"false")}}}prepareViewedControls();let activeDiffRow=null;function firstCodeRowOfHunk(e){let t=e.nextElementSibling,n=null;for(;t&&!t.classList.contains("hunk")&&!t.classList.contains("hunk-peer");){if(t.querySelector&&t.querySelector(".d2h-code-side-line")&&(n||(n=t),t.querySelector(".d2h-ins, .d2h-del, ins, del")))return t;t=t.nextElementSibling}return n||e}function isChangeCodeRow(e){return!!(e&&isDiffCodeRow(e)&&e.querySelector(".d2h-ins, .d2h-del, ins, del"))}function firstChangeRowForCaret(e){const t=e.closest(".d2h-file-wrapper"),n=t?t.querySelectorAll(".d2h-file-side-diff"):[],r=e.closest(".d2h-file-side-diff");if(n.length>=2&&r){const t=Array.from(r.querySelectorAll("tr")),o=r===n[0]?n[1]:n[0],i=Array.from(o.querySelectorAll("tr"));let a=null;for(let n=t.indexOf(e)+1;n<t.length;n++){const e=t[n];if(e.classList.contains("hunk")||e.classList.contains("hunk-peer"))break;if(isChangeCodeRow(i[n]))return i[n];null===a&&isChangeCodeRow(e)&&(a=e)}if(a)return a}return firstCodeRowOfHunk(e)}function focusDiffRow(e){if(activeDiffRow&&activeDiffRow.classList.remove("diff-active-row"),activeDiffRow=e||null,!e)return;e.classList.add("diff-active-row");const t=diffRowInfoFromNode(e);if(t&&t.path){let e=t.side;if("old"===e){const n=diffWrapperByPath(t.path);isDiffCodeRow(n?diffRowAt(n,"new",t.rowIndex):null)&&(e="new")}setDiffCursor(t.path,e,t.rowIndex,0,!1)}}function renderBreadcrumb(e,t){if(!e)return;e.textContent="";const n=(t||"").split("/").filter(Boolean);n.forEach((t,r)=>{if(r>0){const t=document.createElement("span");t.className="crumb-sep",t.textContent="›",e.appendChild(t)}const o=document.createElement("span");o.className=r===n.length-1?"crumb crumb-leaf":"crumb",o.textContent=t,e.appendChild(o)})}var pendingDiffScrollRow=null,diffScrollRaf=0;function scheduleDiffScroll(e){pendingDiffScrollRow=e||null,diffScrollRaf||(diffScrollRaf=requestAnimationFrame(function(){diffScrollRaf=0;var e=pendingDiffScrollRow;pendingDiffScrollRow=null,e&&e.scrollIntoView&&e.scrollIntoView({block:"center"})}))}var pendingScrollEl=null,scrollElRaf=0;function revealAt(e,t,n){if(e)if(t&&t.clientHeight){var r=e.getBoundingClientRect().top-t.getBoundingClientRect().top;t.scrollTop+=r-t.clientHeight*n}else try{e.scrollIntoView({block:"nearest",inline:"nearest"})}catch(e){}}function scrolloffReveal(e,t,n){if(e&&t&&t.clientHeight){var r=e.getBoundingClientRect().top-t.getBoundingClientRect().top,o=e.offsetHeight||18,i=t.clientHeight,a=Math.round(i*n);r<a?t.scrollTop+=r-a:r+o>i-a&&(t.scrollTop+=r+o-(i-a))}}function scheduleScrollIntoView(e){pendingScrollEl=e||null,scrollElRaf||(scrollElRaf=requestAnimationFrame(function(){scrollElRaf=0;var e=pendingScrollEl;if(pendingScrollEl=null,e&&e.scrollIntoView)try{e.scrollIntoView({block:"nearest",inline:"nearest"})}catch(e){}}))}var setActiveRaf=0,setActiveScrollPending=!0;function setActive(e,t=!0){0!==hunkTotal()&&(current=(e%hunkTotal()+hunkTotal())%hunkTotal(),setActiveScrollPending=t,setActiveRaf||(setActiveRaf=requestAnimationFrame(function(){setActiveRaf=0,applySetActive(current,setActiveScrollPending)})))}function applySetActive(e,t){document.getElementById("source-viewer")?.classList.add("hidden"),document.getElementById("diff-view")?.classList.remove("hidden"),setTab("changes");const n=hunkPathAt(e);links.forEach(e=>e.classList.toggle("active",e.dataset.file===n)),renderBreadcrumb(document.getElementById("diff-breadcrumb"),n);var r=document.getElementById("diff-viewed-toggle");r&&(r.dataset.file=n||""),updateDiffViewedToggle(),n&&rememberRecent(n,"change"),history.replaceState(null,"","#hunk-"+e),whenFileReady(diffWrapperByPath(n),function(){showOnlyFile(n,!0);const r=document.getElementById("hunk-"+e);if(!r)return;REVIEW_LAZY?(document.querySelectorAll("#diff2html-container .hunk.active, #diff2html-container .hunk-peer.active").forEach(e=>e.classList.remove("active")),document.querySelectorAll('#diff2html-container [data-hunk-index="'+e+'"]').forEach(e=>e.classList.add("active"))):(hunks.forEach((t,n)=>t.classList.toggle("active",n===e)),hunkPeers.forEach(t=>t.classList.toggle("active",Number(t.dataset.hunkIndex)===e)));const o=firstChangeRowForCaret(r);navSuppress=!0;try{focusDiffRow(o)}finally{navSuppress=!1}t&&o&&o.scrollIntoView&&o.scrollIntoView({block:"center"})})}function showOnlyFile(e,t){REVIEW_LAZY&&ensureFileReady(diffWrapperByPath(e)),document.querySelectorAll(".d2h-file-wrapper").forEach(t=>{t.classList.toggle("df-inactive",diffWrapperPathKey(t)!==e)}),t||ensureDiffCursor()}function hunkIndexAtCaret(){if(!diffCursor)return-1;const e=diffWrapperByPath(diffCursor.path);if(!e)return-1;const t=diffRowAt(e,diffCursor.side,diffCursor.rowIndex),n=t?t.closest(".d2h-file-side-diff"):null;if(!n)return-1;let r=-1;return n.querySelectorAll("[data-hunk-index]").forEach(e=>{(e===t||t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)&&(r=Number(e.dataset.hunkIndex))}),r}function changeBlockAnchors(e){if(!e)return[];if(e.__anchors)return e.__anchors;var t=diffSideTables(e).right;if(!t)return[];for(var n=diffRowsOf(t),r=[],o=!1,i=0;i<n.length;i++){var a=isChangeCodeRow(n[i]);a&&!o&&r.push(i),o=a}return e.__anchors=r,r}var pendingFileBoundary=null;function next(e){if(0===hunkTotal())return;if(diffCursor&&isDiffViewVisible()){const t=diffWrapperByPath(diffCursor.path);if(t&&!isFileViewed(diffCursor.path)){const n=changeBlockAnchors(t),r=diffCursor.rowIndex;let o=null;if(e>0){for(let e=0;e<n.length;e++)if(n[e]>r){o=n[e];break}}else for(let e=n.length-1;e>=0;e--)if(n[e]<r){o=n[e];break}if(null!=o){const e=diffRowAt(t,"new",o);if(e){navSuppress=!0;try{focusDiffRow(e)}finally{navSuppress=!1}return void scheduleDiffScroll(e)}}}}if(e>0&&diffCursor&&isDiffViewVisible()&&!isFileViewed(diffCursor.path)&&hunkPathAt(current)===diffCursor.path){if(pendingFileBoundary!==diffCursor.path)return pendingFileBoundary=diffCursor.path,void showCaretHint(t("diff.lastHunk"));pendingFileBoundary=null}hideCaretHint();const n=hunkIndexAtCaret(),r=n>=0?n:current;let o=r<0?initialHunkForNavigation(e):r+e;for(let t=0;t<hunkTotal();t++){const t=(o%hunkTotal()+hunkTotal())%hunkTotal();if(!isFileViewed(hunkPathAt(t)||""))return void setActive(t);o+=e}}function gotoNextUnviewedFile(e){const t=hunkTotal();if(0===t)return!1;const n=firstHunkForPath(e);let r=(n>=0?n:current>=0?current:0)+1;for(let e=0;e<t;e++){const e=(r%t+t)%t;if(!isFileViewed(hunkPathAt(e)||""))return setActive(e),!0;r+=1}return!1}function initialHunkForNavigation(e){const t=firstHunkForPath(document.getElementById("source-viewer")?.dataset.openPath||"");return t>=0?t:e<0?hunkTotal()-1:0}function firstHunkForPath(e){if(!e)return-1;const t=links.find(t=>t.dataset.file===e);if(!t)return-1;const n=Number(t.dataset.hunk);return Number.isNaN(n)?-1:n}function openQuickOpen(e){quickOpen&&quickInput&&quickModeLabel&&(quickMode=e,quickModeLabel.textContent=t("recent"===e?"quickopen.recent":"content"===e?"quickopen.findInFiles":"quickopen.searchFiles"),quickOpen.classList.remove("hidden"),quickOpen.classList.toggle("quick-recent","recent"===e),recentFilter="",quickInput.value="",updateRecentFilterDisplay(),renderQuickOpenResults(),"recent"===e?document.activeElement&&document.activeElement.blur&&document.activeElement.blur():setTimeout(()=>quickInput.focus(),0))}function updateRecentFilterDisplay(){if(quickFilterEl)return"recent"!==quickMode?(quickFilterEl.textContent="",void(quickFilterEl.className="quick-open-filter")):void(recentFilter?(quickFilterEl.textContent=recentFilter,quickFilterEl.className="quick-open-filter has-filter"):(quickFilterEl.textContent=t("quickopen.typeToFilter"),quickFilterEl.className="quick-open-filter is-hint"))}function closeQuickOpen(){quickOpen?.classList.add("hidden")}function handleQuickOpenKey(e){if("Escape"===e.key)return e.preventDefault(),"recent"===quickMode&&recentFilter?(recentFilter="",updateRecentFilterDisplay(),renderQuickOpenResults(),!0):(closeQuickOpen(),!0);if("ArrowDown"===e.key)return e.preventDefault(),quickActive=Math.min(quickActive+1,Math.max(quickItems.length-1,0)),updateQuickActive(),!0;if("ArrowUp"===e.key)return e.preventDefault(),quickActive=Math.max(quickActive-1,0),updateQuickActive(),!0;if("Enter"===e.key)return e.preventDefault(),openQuickItem(quickItems[quickActive]),!0;if("recent"===quickMode){if("Backspace"===e.key)return e.preventDefault(),recentFilter&&(recentFilter=recentFilter.slice(0,-1),updateRecentFilterDisplay(),renderQuickOpenResults()),!0;if(1===e.key.length&&!e.metaKey&&!e.ctrlKey&&!e.altKey)return e.preventDefault(),recentFilter+=e.key,updateRecentFilterDisplay(),renderQuickOpenResults(),!0}return!1}function renderQuickOpenResults(){if(!quickResults)return;const e="recent"===quickMode,n=(e?recentFilter:quickInput?.value||"").trim().toLowerCase(),r=e?recentItems():allQuickItems();quickItems=r.filter(e=>{if(0===n.length)return!0;if("content"===quickMode){const t=sourceByPath.get(e.path);return Boolean(t&&t.embedded&&t.content.toLowerCase().includes(n))}return(e.path+"\n"+e.name+"\n"+e.detail).toLowerCase().includes(n)}).sort((e,t)=>scoreQuickItem(e,n)-scoreQuickItem(t,n)||e.path.localeCompare(t.path)).slice(0,80),quickActive=Math.min(quickActive,Math.max(quickItems.length-1,0)),0!==quickItems.length?(quickResults.innerHTML=quickItems.map((e,t)=>['<button type="button" class="quick-open-item'+(t===quickActive?" active":"")+'" data-index="'+t+'">','<span class="quick-open-main">','<span class="quick-open-name">'+escapeHtml(e.name)+"</span>",'<span class="quick-open-path">'+escapeHtml(e.path)+"</span>","</span>",'<span class="quick-open-badge">'+escapeHtml(e.detail)+"</span>","</button>"].join("")).join(""),renderQuickPreview(quickItems[quickActive])):quickResults.innerHTML='<div class="quick-open-empty">'+escapeHtml(t("quickopen.noFiles"))+"</div>"}function updateQuickActive(){quickResults?.querySelectorAll(".quick-open-item").forEach((e,t)=>{const n=t===quickActive;e.classList.toggle("active",n),n&&e.scrollIntoView({block:"nearest"})}),renderQuickPreview(quickItems[quickActive])}function renderQuickPreview(e){const t=document.getElementById("quick-open-preview");if(!t)return;if(!e)return void(t.innerHTML="");const n=sourceByPath.get(e.path);if(!n||!n.embedded)return void(t.innerHTML='<div class="qp-empty">'+escapeHtml(e.path)+"</div>");const r=(quickInput&&quickInput.value||"").trim().toLowerCase(),o=n.content.split(/\r?\n/);let i=-1;const a=o.map((e,t)=>{const o=r.length>0&&e.toLowerCase().includes(r);return o&&i<0&&(i=t),'<div class="qp-line'+(o?" qp-hit":"")+'"><span class="qp-num">'+(t+1)+'</span><span class="qp-code">'+highlightLine(e,n.language||"text")+"</span></div>"}).join("");if(t.innerHTML='<div class="qp-head">'+escapeHtml(e.path)+'</div><div class="qp-body">'+a+"</div>",i>=0){const e=t.querySelectorAll(".qp-line")[i];e&&e.scrollIntoView({block:"center"})}}function openQuickItem(e){if(!e)return;if(closeQuickOpen(),rememberRecent(e.path,e.kind),sourceByPath.has(e.path))return void openSourceFile(e.path);const t=links.find(t=>t.dataset.file===e.path);if(!t)return;const n=Number(t.dataset.hunk);if(!Number.isNaN(n)&&n>=0&&n<hunkTotal())setActive(n);else{showDiffView(!1);const e=t.getAttribute("href")?.slice(1);e&&document.getElementById(e)?.scrollIntoView({block:"center"})}}function allQuickItems(){const e=sourceFiles.map(e=>({path:e.path,name:baseName(e.path),detail:[e.changed?"changed":"file",e.language||"text"].join(" - "),kind:"source",recent:!1}));links.forEach(t=>{const n=t.dataset.file||"";n&&!sourceByPath.has(n)&&e.push({path:n,name:baseName(n),detail:"diff",kind:"change",recent:!1})});const t=loadRecent(),n=new Map(t.map((e,t)=>[e.path,t]));return e.map(e=>({...e,recent:n.has(e.path),recentRank:n.get(e.path)??9999}))}function recentItems(){const e=allQuickItems(),t=new Map(e.map(e=>[e.path,e]));return loadRecent().map(e=>t.get(e.path)||{path:e.path,name:baseName(e.path),detail:"change"===e.kind?"diff":"file",kind:e.kind,recent:!0,recentRank:0}).map((e,t)=>({...e,recent:!0,recentRank:t}))}function scoreQuickItem(e,t){let n=e.recentRank??9999;if(!t)return n;const r=e.path.toLowerCase(),o=e.name.toLowerCase();return o===t?n-=3e3:o.startsWith(t)?n-=2e3:r.includes("/"+t)?n-=1e3:r.includes(t)&&(n-=500),e.recent&&(n-=100),n}function loadRecent(){try{const e=JSON.parse(localStorage.getItem(recentKey)||"[]");return Array.isArray(e)?e.filter(e=>e&&"string"==typeof e.path):[]}catch{return[]}}function rememberRecent(e,t){if(!e)return;const n=[{path:e,kind:t},...loadRecent().filter(t=>t.path!==e)].slice(0,30);try{localStorage.setItem(recentKey,JSON.stringify(n))}catch{}}function baseName(e){return String(e).split("/").filter(Boolean).pop()||String(e)}function isTreeRowVisible(e){for(var t=e;t;){var n=t.parentElement;if(!n||n.classList.contains("tab-panel"))return!0;if("DETAILS"===n.tagName&&!n.open&&"SUMMARY"!==t.tagName)return!1;t=n}return!0}function treeRows(){const e=document.querySelector(".tab-panel:not(.hidden)");return e?Array.from(e.querySelectorAll("summary, .file-link")).filter(isTreeRowVisible):[]}function focusTree(e){const t=treeRows();0!==t.length&&(treeFocusIndex=Math.max(0,Math.min(t.length-1,e)),scheduleTreeFocus())}var treeFocusRaf=0;function scheduleTreeFocus(){treeFocusRaf||(treeFocusRaf=requestAnimationFrame(function(){treeFocusRaf=0;const e=treeRows();if(treeFocusIndex<0||treeFocusIndex>=e.length)return;const t=e[treeFocusIndex];document.querySelectorAll(".tree-focus").forEach(e=>{e!==t&&e.classList.remove("tree-focus")}),t&&(t.classList.add("tree-focus"),scrolloffReveal(t,document.querySelector(".sidebar-scroll"),.15))}))}function clearTreeFocus(){treeFocusIndex=-1,document.querySelectorAll(".tree-focus").forEach(e=>e.classList.remove("tree-focus"))}function focusOpenFileInTree(){const e=treeRows();if(0===e.length)return;let t=document.getElementById("source-viewer")?.dataset.openPath||"";if(!t&&"function"==typeof diffActiveWrapper){const e=diffActiveWrapper(),n=e&&e.querySelector(".d2h-file-name");n&&n.textContent&&(t=n.textContent.trim())}let n=0;if(t)for(let r=0;r<e.length;r++){const o=e[r].dataset||{};if(o.sourceFile===t||o.file===t){n=r;break}}focusTree(n)}function treePageSize(){var e=document.querySelector(".sidebar-scroll"),t=e?e.clientHeight:320;return Math.max(1,Math.floor(t/20)-1)}function treeOpenKey(){return"monacori-tree-open:"+location.pathname}function loadTreeOpen(){try{return new Set(JSON.parse(sessionStorage.getItem(treeOpenKey())||"[]"))}catch(e){return new Set}}function saveTreeOpen(e){try{sessionStorage.setItem(treeOpenKey(),JSON.stringify(Array.from(e)))}catch(e){}}var treeRevealing=!1;function persistTreeToggle(e){var t=loadTreeOpen(),n=e.dataset.dir||"";e.open?t.add(n):t.delete(n),saveTreeOpen(t)}function initSourceTreeFolds(){var e=Array.prototype.slice.call(document.querySelectorAll(".source-dir"));if(e.length){var t=loadTreeOpen(),n=document.getElementById("source-viewer")&&document.getElementById("source-viewer").dataset.openPath||"";e.forEach(function(e){e.addEventListener("toggle",function(){treeRevealing||persistTreeToggle(e)})}),treeRevealing=!0,e.forEach(function(e){var r=e.dataset.dir||"",o=n&&(n===r||0===n.indexOf(r+"/"));e.open=t.has(r)||!!o}),setTimeout(function(){treeRevealing=!1},0)}}function revealTreeFor(e){if(e){treeRevealing=!0,document.querySelectorAll(".source-dir").forEach(function(t){var n=t.dataset.dir||"";!n||e!==n&&0!==e.indexOf(n+"/")||t.open||(t.open=!0)}),setTimeout(function(){treeRevealing=!1},0);var t=document.querySelector(".source-link.active");t&&t.scrollIntoView&&t.scrollIntoView({block:"nearest"})}}function handleTreeKey(e){const t=treeRows();if(0===t.length)return!1;treeFocusIndex>=t.length&&(treeFocusIndex=t.length-1);const n=t[treeFocusIndex],r=n&&"SUMMARY"===n.tagName;return"ArrowDown"===e.key?(e.preventDefault(),focusTree(treeFocusIndex+1),!0):"ArrowUp"===e.key?(e.preventDefault(),focusTree(treeFocusIndex-1),!0):"PageDown"===e.key?(e.preventDefault(),focusTree(treeFocusIndex+treePageSize()),!0):"PageUp"===e.key?(e.preventDefault(),focusTree(treeFocusIndex-treePageSize()),!0):"Enter"===e.key&&e.altKey?(e.preventDefault(),n&&"function"==typeof openTreeRowMenu&&openTreeRowMenu(n),!0):"Enter"===e.key?(e.preventDefault(),n&&n.classList.contains("file-link")?(n.click(),clearTreeFocus()):r&&n.parentElement&&(n.parentElement.open=!n.parentElement.open),!0):"ArrowRight"===e.key?(e.preventDefault(),r&&n.parentElement&&!n.parentElement.open?n.parentElement.open=!0:focusTree(treeFocusIndex+1),!0):"ArrowLeft"===e.key?(e.preventDefault(),r&&n.parentElement&&n.parentElement.open?n.parentElement.open=!1:focusTree(treeFocusIndex-1),!0):"Escape"===e.key&&(e.preventDefault(),clearTreeFocus(),!0)}function isFloatingModalOpen(){var e=document.getElementById("settings-modal");if(e&&!e.classList.contains("hidden"))return!0;var t=document.getElementById("history-view");return!(!t||t.classList.contains("hidden"))||(!!document.getElementById("goto-line")||isDockFocused())}!function(){var e=document.getElementById("diff2html-container");e&&e.addEventListener("wheel",function(t){Math.abs(t.deltaY)>=Math.abs(t.deltaX)&&0!==t.deltaY&&(e.scrollTop+=t.deltaY,t.preventDefault())},{passive:!1})}(),document.addEventListener("keydown",e=>{if(quickOpen?.classList.contains("hidden")||!handleQuickOpenKey(e)){var t=document.getElementById("usages");if(!t||t.classList.contains("hidden")||!handleUsagesKey(e)){var n,r=!(!(n=document.getElementById("settings-modal"))||n.classList.contains("hidden"));if((e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey&&"Quote"===e.code)return e.preventDefault(),void toggleDockMaximized();if(!r&&(e.metaKey||e.ctrlKey)&&!e.altKey&&("Slash"===e.code||"Period"===e.code||"?"===e.key||">"===e.key))return e.preventDefault(),void openMergedView("Slash"===e.code||"?"===e.key?"q":"c");if(!r&&(e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey&&("KeyN"===e.code||"n"===e.key||"N"===e.key))return e.preventDefault(),void openMemoView();if(!r&&(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("Digit9"===e.code||"9"===e.key)&&"function"==typeof toggleHistory)return e.preventDefault(),void toggleHistory();if(!isFloatingModalOpen()){if((e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("a"===e.key||"A"===e.key)){var o=document.activeElement;if((!o||"INPUT"!==o.tagName&&"TEXTAREA"!==o.tagName&&"SELECT"!==o.tagName)&&selectAllInView())return void e.preventDefault()}if((e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&"1"===e.key){if(e.preventDefault(),isDiffViewVisible()){var i=diffActiveWrapper(),a=i&&i.querySelector(".d2h-file-name"),s=diffCursor&&diffCursor.path||(a?(a.textContent||"").trim():"");s&&sourceByPath.has(s)&&openSourceFile(s)}return setTab("files"),void focusOpenFileInTree()}if((e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("l"===e.key||"L"===e.key)){var c=document.activeElement;if(!c||"INPUT"!==c.tagName&&"TEXTAREA"!==c.tagName&&"SELECT"!==c.tagName)return e.preventDefault(),void openGotoLine()}if((e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("k"===e.key||"K"===e.key)){var l=document.activeElement;if(!l||"INPUT"!==l.tagName&&"TEXTAREA"!==l.tagName&&"SELECT"!==l.tagName)return e.preventDefault(),void copyCaretLocation()}if((e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&"0"===e.key)return e.preventDefault(),setTab("changes"),void focusOpenFileInTree();if("Tab"===e.key){const t=document.activeElement;if(!(t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName||"SELECT"===t.tagName))){if(e.preventDefault(),e.shiftKey){if(isDiffViewVisible()&&diffCursor){const e="new"===diffCursor.side?"old":"new",t=diffWrapperByPath(diffCursor.path);return void(isDiffCodeRow(t?diffRowAt(t,e,diffCursor.rowIndex):null)&&setDiffCursor(diffCursor.path,e,diffCursor.rowIndex,0,!0))}focusTree(treeFocusIndex>=0?treeFocusIndex:0)}else{clearTreeFocus();const e=document.getElementById("source-viewer")?.dataset.openPath||"";!isSourceViewerVisible()||!e||viewerCursor&&viewerCursor.path===e||setSourceCursor(e,viewerCursor?viewerCursor.lineIndex:0,0,!1,-1)}return}}if(!(e.altKey||e.metaKey||e.ctrlKey||"?"!==e.key&&">"!==e.key)){const t=document.activeElement;if(!(t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName||"SELECT"===t.tagName)))return e.preventDefault(),void openComposer("?"===e.key?"q":"c")}if(!e.altKey&&!e.metaKey&&!e.ctrlKey&&"<"===e.key){const t=document.activeElement;if(!(t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName||"SELECT"===t.tagName))){let t=isSourceViewerVisible()&&document.getElementById("source-viewer")?.dataset.openPath||"";if(!t&&"function"==typeof diffActiveWrapper){const e=diffActiveWrapper(),n=e&&e.querySelector(".d2h-file-name");n&&n.textContent&&(t=n.textContent.trim())}if(t&&currentFileSignature(t)){e.preventDefault();const n=!isFileViewed(t);return setFileViewed(t,n),void(n&&gotoNextUnviewedFile(t))}}}if(e.altKey&&!e.metaKey&&!e.ctrlKey&&("ArrowLeft"===e.key||"ArrowRight"===e.key)){var u=document.activeElement;if(!(u&&("INPUT"===u.tagName||"TEXTAREA"===u.tagName||"SELECT"===u.tagName))&&treeFocusIndex<0){var d="ArrowRight"===e.key?1:-1;if(isSourceViewerVisible()&&viewerCursor)return e.preventDefault(),void moveSourceWord(d,e.shiftKey);if(isDiffViewVisible()&&diffCursor)return e.preventDefault(),void moveDiffWord(d,e.shiftKey)}}if(treeFocusIndex<0&&("PageDown"===e.key||"PageUp"===e.key)&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&!e.shiftKey){var f=isDiffViewVisible()?document.getElementById("diff2html-container"):isSourceViewerVisible()?document.getElementById("source-body"):null;if(f)return e.preventDefault(),void(f.scrollTop+=("PageDown"===e.key?.9:-.9)*f.clientHeight)}if("Shift"!==e.key&&(lastShiftAt=0,lastShiftSide=0),!(treeFocusIndex>=0&&handleTreeKey(e))&&(!(treeFocusIndex<0)||e.metaKey||e.ctrlKey||e.altKey||!isSourceViewerVisible()||!handleSourceCaretKey(e))&&(!(treeFocusIndex<0)||e.metaKey||e.ctrlKey||e.altKey||!isDiffViewVisible()||!handleDiffCaretKey(e))){if("Shift"===e.key&&!e.repeat){const t=performance.now(),n=e.location;if(0!==n&&n===lastShiftSide&&t-lastShiftAt<300)return e.preventDefault(),lastShiftAt=0,lastShiftSide=0,void openQuickOpen("all");lastShiftAt=t,lastShiftSide=n}if((e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey&&"f"===e.key.toLowerCase())return e.preventDefault(),void openQuickOpen("content");if((e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&"e"===e.key.toLowerCase())return e.preventDefault(),void openQuickOpen("recent");if((e.metaKey||e.altKey)&&"Enter"===e.key&&isSourceViewerVisible()){if(isHttpFile(document.getElementById("source-viewer")?.dataset.openPath||""))return e.preventDefault(),void runHttpAtCaret()}if((e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&"ArrowDown"===e.key)return e.preventDefault(),void(isSourceViewerVisible()?goToSymbolUnderCursor():openDiffFileAtCaret());if((e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("b"===e.key||"B"===e.key)){var m=document.activeElement;if(m&&("INPUT"===m.tagName||"TEXTAREA"===m.tagName||"SELECT"===m.tagName))return;return e.preventDefault(),void(isSourceViewerVisible()?goToSymbolUnderCursor():isDiffViewVisible()&&goToSymbolFromDiff())}if((e.metaKey||e.ctrlKey)&&!e.altKey&&("ArrowLeft"===e.key||"ArrowRight"===e.key)&&isSourceViewerVisible()&&viewerCursor){e.preventDefault();const t=sourceByPath.get(viewerCursor.path);if(t&&t.embedded){const n=t.content.split(/\r?\n/),r="ArrowLeft"===e.key?0:(n[viewerCursor.lineIndex]||"").length;e.shiftKey?selectionAnchor||(selectionAnchor={lineIndex:viewerCursor.lineIndex,column:viewerCursor.column}):selectionAnchor=null,setSourceCursor(viewerCursor.path,viewerCursor.lineIndex,r,!0,-1),applySourceSelection()}return}if((e.metaKey||e.ctrlKey)&&!e.altKey&&("ArrowLeft"===e.key||"ArrowRight"===e.key)&&isDiffViewVisible()&&diffCursor){e.preventDefault();const t=diffWrapperByPath(diffCursor.path),n=t?diffRowAt(t,diffCursor.side,diffCursor.rowIndex):null,r=n?diffLineText(n).length:0;if("ArrowLeft"===e.key){if(diffCursor.column>0)setDiffCursor(diffCursor.path,diffCursor.side,diffCursor.rowIndex,0,!0);else if("new"===diffCursor.side){const e=t?diffRowAt(t,"old",diffCursor.rowIndex):null;isDiffCodeRow(e)&&setDiffCursor(diffCursor.path,"old",diffCursor.rowIndex,diffLineText(e).length,!0)}}else if(diffCursor.column<r)setDiffCursor(diffCursor.path,diffCursor.side,diffCursor.rowIndex,r,!0);else if("old"===diffCursor.side){isDiffCodeRow(t?diffRowAt(t,"new",diffCursor.rowIndex):null)&&setDiffCursor(diffCursor.path,"new",diffCursor.rowIndex,0,!0)}return}if((e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey&&("["===e.key||"]"===e.key||"{"===e.key||"}"===e.key)&&isSourceViewerVisible()&&sourceTabs.length>1)return e.preventDefault(),void cycleSourceTab("["===e.key||"{"===e.key?-1:1);if((e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey&&("["===e.key||"]"===e.key)){var p=document.activeElement;if(!(p&&("INPUT"===p.tagName||"TEXTAREA"===p.tagName||"SELECT"===p.tagName)))return e.preventDefault(),void("["===e.key?navBack():navForward())}if("F7"===e.key&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault();const t=e.shiftKey?-1:1,n=document.getElementById("source-viewer");if(t>0&&n&&!n.classList.contains("hidden")){const e=n.dataset.openPath||"",t=firstHunkForPath(e);if(t>=0&&!isFileViewed(e))return void setActive(t)}next(t)}}}}}}),quickInput?.addEventListener("input",()=>renderQuickOpenResults()),quickResults?.addEventListener("mousemove",e=>{const t=e.target.closest?.(".quick-open-item");t&&(quickActive=Number(t.dataset.index||0),updateQuickActive())}),quickResults?.addEventListener("click",e=>{const t=e.target.closest?.(".quick-open-item");if(!t)return;const n=Number(t.dataset.index||0);openQuickItem(quickItems[n])}),quickOpen?.addEventListener("click",e=>{e.target===quickOpen&&closeQuickOpen()}),document.getElementById("usages-results")?.addEventListener("mousemove",function(e){var t=e.target.closest&&e.target.closest(".usage-item");t&&(usageActive=Number(t.dataset.index||0),updateUsageActive())}),document.getElementById("usages-results")?.addEventListener("click",function(e){var t=e.target.closest&&e.target.closest(".usage-item");t&&openUsageItem(usageItems[Number(t.dataset.index||0)])}),document.getElementById("usages")?.addEventListener("click",function(e){e.target&&"usages"===e.target.id&&closeUsages()}),document.getElementById("changes-panel")?.addEventListener("click",e=>{const t=e.target&&e.target.closest?e.target.closest(".file-link"):null;if(!t)return;showDiffView(!1);const n=Number(t.dataset.hunk);!Number.isNaN(n)&&n>=0&&n<hunkTotal()&&(e.preventDefault(),setActive(n))}),document.getElementById("files-panel")?.addEventListener("click",e=>{const t=e.target&&e.target.closest?e.target.closest(".source-link"):null;t&&t.dataset.sourceFile&&openSourceFile(t.dataset.sourceFile)}),document.querySelectorAll(".tab").forEach(e=>{e.addEventListener("click",()=>setTab(e.dataset.tab||"changes"))}),document.querySelector(".activity-rail")?.addEventListener("click",e=>{const t=e.target.closest&&e.target.closest(".rail-btn[data-view]");if(!t)return;const n=t.dataset.view;"changes"===n?(setTab("changes"),isDiffViewVisible()||showDiffView(!1)):"files"===n?setTab("files"):"q"===n||"c"===n?toggleMergedRail(n):"memo"===n?openMemoView():"history"===n&&toggleHistory(),syncRail()}),document.getElementById("back-to-diff")?.addEventListener("click",()=>showDiffView(!0)),document.getElementById("source-tabs")?.addEventListener("click",function(e){var t=e.target&&e.target.closest&&e.target.closest(".source-tab-close");if(t)return e.stopPropagation(),e.preventDefault(),void closeSourceTab(t.getAttribute("data-close-path"));var n=e.target&&e.target.closest&&e.target.closest(".source-tab");n&&openSourceFile(n.getAttribute("data-tab-path"))}),document.getElementById("diff-viewed-toggle")?.addEventListener("click",function(){var e=document.getElementById("diff-viewed-toggle"),t=e&&e.dataset.file||"";t&&setFileViewed(t,!isFileViewed(t))}),document.getElementById("source-body")?.addEventListener("click",handleSourceClick),document.getElementById("source-body")?.addEventListener("click",function(e){var t=e.target&&e.target.closest&&e.target.closest(".image-preview");t&&openLightbox(t.getAttribute("src"),t.getAttribute("alt"))}),document.addEventListener("keydown",function(e){"Escape"===e.key&&lightboxOpen()&&(e.preventDefault(),e.stopPropagation(),closeLightbox())},!0),document.addEventListener("copy",handleSourceCopy),applyI18n(),populateHttpEnvSelect(),REVIEW_LAZY_LOAD||scheduleSymbolIndex();const restored=restoreUiState();if(!restored){const e=location.hash.match(/^#hunk-(\d+)$/),t=Boolean(document.querySelector("#diff2html-container .d2h-file-wrapper"));e?setActive(Number(e[1]),!1):t&&REVIEW_LAZY_LOAD?showDiffView(!1):openDefaultSourceFile()}function isDiffViewVisible(){var e=document.getElementById("diff-view");return Boolean(e&&!e.classList.contains("hidden"))}function diffActiveWrapper(){return document.querySelector("#diff2html-container .d2h-file-wrapper:not(.df-inactive)")||document.querySelector("#diff2html-container .d2h-file-wrapper")}initSourceTreeFolds(),syncRail(),!watchEnabled||window.monacoriMenu&&"function"==typeof window.monacoriMenu.onDiffUpdate||setInterval(checkForLiveUpdate,1500),window.addEventListener("beforeunload",saveUiState),function(){var e=document.getElementById("boot-overlay");e&&requestAnimationFrame(function(){requestAnimationFrame(function(){e.classList.add("hide"),setTimeout(function(){e.remove()},240)})})}(),function(){const e=document.querySelector(".sidebar-resizer");if(!e)return;const t="monacori-sidebar-width:"+location.pathname,n=localStorage.getItem(t);n&&document.documentElement.style.setProperty("--sidebar-width",n);let r=!1;e.addEventListener("mousedown",t=>{r=!0,e.classList.add("resizing"),document.body.style.userSelect="none",t.preventDefault()}),document.addEventListener("mousemove",e=>{if(!r)return;const t=parseFloat(getComputedStyle(document.body).getPropertyValue("--rail-width"))||0,n=Math.min(640,Math.max(180,e.clientX-t));document.documentElement.style.setProperty("--sidebar-width",n+"px")}),document.addEventListener("mouseup",()=>{if(r){r=!1,e.classList.remove("resizing"),document.body.style.userSelect="";try{localStorage.setItem(t,getComputedStyle(document.documentElement).getPropertyValue("--sidebar-width").trim())}catch(e){}}})}(),function(){const e=document.getElementById("diff2html-container");if(!e)return;e.setAttribute("aria-readonly","true"),e.querySelectorAll(".d2h-code-side-linenumber, .d2h-code-linenumber, .d2h-code-line-prefix").forEach(e=>e.setAttribute("contenteditable","false"));const t=e=>Boolean(e.target&&e.target.closest&&e.target.closest(".mc-comment-row")),n=e=>{t(e)||e.preventDefault()};e.addEventListener("focusin",e=>{t(e)||clearTreeFocus()}),e.addEventListener("mousedown",e=>{t(e)||clearTreeFocus()}),e.addEventListener("beforeinput",n),e.addEventListener("paste",n),e.addEventListener("drop",n),e.addEventListener("dragstart",n),e.addEventListener("keydown",e=>{t(e)||e.metaKey||e.ctrlKey||e.altKey||1!==e.key.length&&"Enter"!==e.key&&"Backspace"!==e.key&&"Delete"!==e.key&&"Tab"!==e.key||e.preventDefault()}),e.addEventListener("click",e=>{if(t(e))return;const n=diffRowInfoFromNode(e.target);n&&n.path&&setDiffCursor(n.path,n.side,n.rowIndex,0,!1)}),ensureDiffCursor()}();var wrapperPathMap=null;function diffWrapperPathKey(e){return e.dataset&&e.dataset.path||((e.querySelector(".d2h-file-name")||{}).textContent||"").trim()}function diffWrapperByPath(e){if(wrapperPathMap){var t=wrapperPathMap.get(e);if(t&&t.isConnected)return t}wrapperPathMap=new Map;for(var n=document.querySelectorAll("#diff2html-container .d2h-file-wrapper"),r=0;r<n.length;r++){var o=diffWrapperPathKey(n[r]);o&&wrapperPathMap.set(o,n[r])}return wrapperPathMap.get(e)||null}function diffSideTables(e){var t=e?e.querySelectorAll(".d2h-file-side-diff"):[];return{left:t[0]||null,right:t[t.length-1]||null}}function diffSideTable(e,t){var n=diffSideTables(e);return"old"===t?n.left:n.right}function diffRowsOf(e){return e?Array.prototype.slice.call(e.querySelectorAll("tr")).filter(function(e){return!e.classList.contains("mc-comment-row")&&!e.classList.contains("mc-spacer-row")}):[]}function diffRowAt(e,t,n){return diffRowsOf(diffSideTable(e,t))[n]||null}function diffCellCtn(e){return e?e.querySelector(".d2h-code-line-ctn"):null}function diffLineText(e){var t=diffCellCtn(e);return t&&t.textContent||""}function diffLineNumber(e){var t=e?e.querySelector(".d2h-code-side-linenumber"):null,n=t?parseInt((t.textContent||"").trim(),10):NaN;return isFinite(n)?n:null}function diffRowInfoFromNode(e){var t=e?1===e.nodeType?e:e.parentElement:null;if(!t||!t.closest)return null;var n=t.closest(".d2h-file-wrapper"),r=t.closest(".d2h-file-side-diff"),o=t.closest("tr");if(!n||!r||!o)return null;var i=n.querySelector(".d2h-file-name"),a=(i&&i.textContent?i.textContent:"").trim(),s=r===diffSideTables(n).left?"old":"new";if(!isDiffCodeRow(o))return null;var c=diffRowsOf(r).indexOf(o);return!a||c<0?null:{path:a,side:s,rowIndex:c}}function diffCaretDomPosition(e,t){if(!e)return null;for(var n,r=t,o=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);n=o.nextNode();){var i=n.textContent.length;if(r<=i)return{node:n,offset:r};r-=i}return{node:e,offset:e.childNodes.length}}var diffCaretSpan=null;function clearDiffCaret(){var e=document.getElementById("diff2html-container");e&&(e.querySelectorAll(".mc-diff-cursor-row").forEach(function(e){e.classList.remove("mc-diff-cursor-row")}),e.querySelectorAll(".code-cursor").forEach(function(e){var t=e.parentNode;t&&(t.removeChild(e),t.normalize&&t.normalize())})),diffCaretSpan=null}function renderDiffCaret(){if(clearDiffCaret(),diffCursor){var e=diffWrapperByPath(diffCursor.path);if(e){var t=diffRowAt(e,diffCursor.side,diffCursor.rowIndex);if(t){t.classList.add("mc-diff-cursor-row");var n=diffCellCtn(t);if(n){if(0===(n.textContent||"").length){var r=document.createElement("span");return r.className="code-cursor",r.setAttribute("aria-hidden","true"),r.style.position="absolute",n.appendChild(r),void(diffCaretSpan=r)}var o=diffCaretDomPosition(n,diffCursor.column);if(o){var i=document.createElement("span");i.className="code-cursor",i.setAttribute("aria-hidden","true");try{var a=3===o.node.nodeType?Math.min(o.offset,(o.node.textContent||"").length):o.offset,s=document.createRange();s.setStart(o.node,a),s.collapse(!0),s.insertNode(i),diffCaretSpan=i}catch(e){diffCaretSpan=null}}}}}}}function setDiffCursor(e,t,n,r,o){markCaretBusy();var i=diffWrapperByPath(e);if(i){var a=diffRowsOf(diffSideTable(i,t));if(a.length){var s=Math.max(0,Math.min(n,a.length-1)),c=Math.max(0,Math.min(r,diffLineText(a[s]).length));diffCursor={path:e,side:t,rowIndex:s,column:c},pendingFileBoundary=null,hideCaretHint(),diffSelectionAnchor=null,o?scheduleDiffReveal(i,t,s):(renderDiffCaret(),applyDiffSelection()),recordNav(navEntryOf("diff"))}}}var diffRevealRaf=0,diffRevealTarget=null;function scheduleDiffReveal(e,t,n){diffRevealTarget={wrapper:e,side:t,ri:n},diffRevealRaf||(diffRevealRaf=requestAnimationFrame(function(){diffRevealRaf=0;var e=diffRevealTarget;(diffRevealTarget=null,renderDiffCaret(),applyDiffSelection(),e)&&scrolloffReveal(diffRowAt(e.wrapper,e.side,e.ri),document.getElementById("diff2html-container"),.15)}))}function navEntryOf(e){return"diff"===e?diffCursor?{kind:"diff",path:diffCursor.path,side:diffCursor.side,rowIndex:diffCursor.rowIndex,column:diffCursor.column,line:diffCursor.rowIndex}:null:viewerCursor?{kind:"source",path:viewerCursor.path,lineIndex:viewerCursor.lineIndex,column:viewerCursor.column,line:viewerCursor.lineIndex}:null}function navSamePos(e,t){return!(!e||!t||e.kind!==t.kind||e.path!==t.path||e.line!==t.line||"diff"===e.kind&&e.side!==t.side)}function recordNav(e){if(!navSuppress&&e){var t=navPos>=0?navList[navPos]:null;if(navSamePos(t,e))navList[navPos]=e;else t&&t.kind===e.kind&&t.path===e.path&&Math.abs(t.line-e.line)<NAV_JUMP_LINES?navList[navPos]=e:(navList=navList.slice(0,navPos+1),navList.push(e),navPos=navList.length-1,navList.length>NAV_MAX&&(navList.shift(),navPos-=1))}}function revealDiffFile(e){document.getElementById("source-viewer")?.classList.add("hidden"),document.getElementById("diff-view")?.classList.remove("hidden"),setTab("changes"),showOnlyFile(e),links.forEach(function(t){t.classList.toggle("active",t.dataset.file===e)}),renderBreadcrumb(document.getElementById("diff-breadcrumb"),e)}function restoreNav(e){if(e){navSuppress=!0;try{"diff"===e.kind?(revealDiffFile(e.path),setDiffCursor(e.path,e.side,e.rowIndex,e.column,!0)):setSourceCursor(e.path,e.lineIndex,e.column,!0,-1)}finally{navSuppress=!1}}}function navBack(){if(!(navPos<0)){var e=navEntryOf(isSourceViewerVisible()?"source":"diff");!e||navSamePos(e,navList[navPos])?navPos>0&&(navPos-=1,restoreNav(navList[navPos])):restoreNav(navList[navPos])}}function navForward(){navPos<navList.length-1&&(navPos+=1,restoreNav(navList[navPos]))}function applyDiffSelection(){var e=window.getSelection();if(e)if(diffSelectionAnchor&&diffCursor&&diffSelectionAnchor.side===diffCursor.side){var t=diffWrapperByPath(diffCursor.path);if(t){var n=diffCellCtn(diffRowAt(t,diffSelectionAnchor.side,diffSelectionAnchor.rowIndex)),r=diffCellCtn(diffRowAt(t,diffCursor.side,diffCursor.rowIndex)),o=n?diffCaretDomPosition(n,diffSelectionAnchor.column):null,i=r?diffCaretDomPosition(r,diffCursor.column):null;if(o&&i)try{e.setBaseAndExtent(o.node,o.offset,i.node,i.offset)}catch(e){}}else try{e.removeAllRanges()}catch(e){}}else try{e.removeAllRanges()}catch(e){}}function isDiffCodeRow(e){if(!e)return!1;if(e.querySelector(".d2h-emptyplaceholder, .d2h-code-side-emptyplaceholder"))return!1;if(!e.querySelector(".d2h-code-line-ctn"))return!1;var t=e.querySelector(".d2h-code-side-linenumber");return!!t&&(t.textContent||"").trim().length>0}function firstDiffCodeRow(e,t){for(var n=diffRowsOf(diffSideTable(e,t)),r=0;r<n.length;r++)if(isDiffCodeRow(n[r]))return r;return-1}function ensureDiffCursor(){if(isDiffViewVisible()){var e=diffActiveWrapper();e&&whenFileReady(e,function(){var t=e.querySelector(".d2h-file-name"),n=(t&&t.textContent?t.textContent:"").trim();if(n)if(diffCursor&&diffCursor.path===n)renderDiffCaret();else{var r=firstDiffCodeRow(e,"new");r<0||setDiffCursor(n,"new",r,0,!1)}})}}function moveDiffCursor(e,t,n){if(diffCursor){var r=diffWrapperByPath(diffCursor.path);if(r){var o=diffCursor.side,i=diffRowsOf(diffSideTable(r,o)),a=diffCursor.rowIndex,s=diffCursor.column,c=diffLineText(i[a]),l=n?diffSelectionAnchor||{side:diffCursor.side,rowIndex:diffCursor.rowIndex,column:diffCursor.column}:null;if(t<0)if(s>0)s-=1;else{for(var u=a-1;u>=0&&!isDiffCodeRow(i[u]);)u-=1;u>=0&&(a=u,s=diffLineText(i[u]).length)}else if(t>0)if(s<c.length)s+=1;else{for(var d=a+1;d<i.length&&!isDiffCodeRow(i[d]);)d+=1;d<i.length&&(a=d,s=0)}if(0!==e){for(var f=diffRowsOf(diffSideTable(r,o)),m=e>0?1:-1,p=a+m;p>=0&&p<f.length&&!isDiffCodeRow(f[p]);)p+=m;p>=0&&p<f.length&&(a=p,s=Math.min(s,diffLineText(f[a]).length))}setDiffCursor(diffCursor.path,o,a,s,!0),l&&(diffSelectionAnchor=l,applyDiffSelection())}}}function moveDiffWord(e,t){if(diffCursor){var n=diffWrapperByPath(diffCursor.path);if(n){var r=nextWordBoundary(diffLineText(diffRowAt(n,diffCursor.side,diffCursor.rowIndex)),diffCursor.column,e);if(r!==diffCursor.column){var o=t?diffSelectionAnchor||{side:diffCursor.side,rowIndex:diffCursor.rowIndex,column:diffCursor.column}:null;setDiffCursor(diffCursor.path,diffCursor.side,diffCursor.rowIndex,r,!0),o&&(diffSelectionAnchor=o,applyDiffSelection())}}}}function diffCommentBoxSiblingOf(e){if(!diffCursor)return null;var t=diffWrapperByPath(diffCursor.path);if(!t)return null;var n=diffRowsOf(diffSideTable(t,"new"))[diffCursor.rowIndex];if(!n)return null;var r=e<0?n.previousElementSibling:n.nextElementSibling;return r&&r.classList&&r.classList.contains("mc-comment-row")?r:null}function handleDiffCaretKey(e){if(!isDiffViewVisible()||!diffCursor)return!1;var t=document.activeElement;if(t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName||"SELECT"===t.tagName))return!1;var n=e.shiftKey;if(selectedCommentRow){if("Backspace"===e.key||"Delete"===e.key)return e.preventDefault(),deleteCommentsInRow(selectedCommentRow),!0;if("e"===e.key||"E"===e.key)return e.preventDefault(),editCommentInRow(selectedCommentRow),!0;if("ArrowUp"===e.key||"ArrowDown"===e.key||"ArrowLeft"===e.key||"ArrowRight"===e.key||"Escape"===e.key){var r="ArrowUp"===e.key?-1:"ArrowDown"===e.key?1:0,o=r<0?selectedCommentRow.previousElementSibling:r>0?selectedCommentRow.nextElementSibling:null;selectedCommentRow.classList.remove("mc-row-selected"),selectedCommentRow=null,e.preventDefault();var i=diffWrapperByPath(diffCursor.path);if(o&&i&&isDiffCodeRow(o)){var a=diffRowsOf(diffSideTable(i,"new")).indexOf(o);if(a>=0)return setDiffCursor(diffCursor.path,"new",a,0,!0),!0}return setDiffCursor(diffCursor.path,diffCursor.side,diffCursor.rowIndex,diffCursor.column,!1),!0}return!1}if(!n&&("ArrowUp"===e.key||"ArrowDown"===e.key)){var s=diffCommentBoxSiblingOf("ArrowUp"===e.key?-1:1);if(s)return e.preventDefault(),selectCommentRow(s),!0}return"ArrowDown"===e.key?(e.preventDefault(),moveDiffCursor(1,0,n),!0):"ArrowUp"===e.key?(e.preventDefault(),moveDiffCursor(-1,0,n),!0):"ArrowLeft"===e.key?(e.preventDefault(),moveDiffCursor(0,-1,n),!0):"ArrowRight"===e.key&&(e.preventDefault(),moveDiffCursor(0,1,n),!0)}function showToast(e){var t=document.getElementById("mc-toasts");t||((t=document.createElement("div")).id="mc-toasts",document.body.appendChild(t));var n=document.createElement("div");n.className="mc-toast",n.textContent=e,t.appendChild(n),requestAnimationFrame(function(){n.classList.add("show")}),setTimeout(function(){n.classList.add("hide"),setTimeout(function(){n.parentNode&&n.parentNode.removeChild(n)},300)},4500)}var caretHintEl=null,caretHintTimer=0;function showCaretHint(e){var t=activeDiffRow||document.querySelector("#diff2html-container .diff-active-row");if(t&&t.getBoundingClientRect){caretHintEl||((caretHintEl=document.createElement("div")).className="mc-caret-hint",document.body.appendChild(caretHintEl)),caretHintEl.textContent=e;var n=t.getBoundingClientRect();caretHintEl.style.left=Math.round(Math.max(8,n.left))+"px",caretHintEl.style.top=Math.round(n.bottom+4)+"px",caretHintEl.classList.remove("show"),caretHintEl.offsetWidth,caretHintEl.classList.add("show"),caretHintTimer&&clearTimeout(caretHintTimer),caretHintTimer=setTimeout(function(){caretHintEl&&caretHintEl.classList.remove("show")},2e3)}else showToast(e)}function hideCaretHint(){caretHintTimer&&(clearTimeout(caretHintTimer),caretHintTimer=0),caretHintEl&&caretHintEl.classList.remove("show")}function remapComments(){if(reviewComments.length){var e=0;reviewComments.forEach(function(t){var n=sourceByPath.get(t.path);if(n&&n.embedded&&"string"==typeof n.content&&n.content){var r=null==t.code?"":String(t.code);if(r.trim()){var o=n.content.split(/\r?\n/);if(o[t.line-1]!==r){for(var i=-1,a=1/0,s=0;s<o.length;s++)if(o[s]===r){var c=Math.abs(s-(t.line-1));c<a&&(a=c,i=s)}i>=0&&t.line!==i+1&&(t.line=i+1,e++)}}}}),e&&(saveComments(),refreshComments())}}function saveComments(){persistSave(COMMENTS_KEY,reviewComments)}function commentsAt(e,t){return reviewComments.filter(function(n){return n.path===e&&n.line===t})}function commentKindLabel(e){return t("q"===e?"comment.kind.q":"comment.kind.c")}function relevantLines(e){var t={};return reviewComments.forEach(function(n){n.path===e&&(t[n.line]=!0)}),composerState&&composerState.path===e&&(t[composerState.line]=!0),Object.keys(t).map(Number).sort(function(e,t){return e-t})}function addComment(e,t,n,r,o){var i=String(o||"").trim();i&&(commentSeq+=1,reviewComments.push({seq:commentSeq,kind:e,path:t,line:n,code:String(r||""),text:i}),saveComments())}function updateComment(e,t){var n=reviewComments.find(function(t){return t.seq===e});if(n){var r=String(t||"").trim();r?(n.text=r,saveComments()):deleteComment(e)}}function deleteComment(e){reviewComments=reviewComments.filter(function(t){return t.seq!==e}),saveComments(),refreshComments()}function sourceRowLineOf(e){var t=e?1===e.nodeType?e:e.parentElement:null,n=t&&t.closest?t.closest(".source-row"):null;if(!n)return null;var r=parseInt(n.dataset.lineIndex,10);return isFinite(r)?r:null}function currentCommentTarget(){var e=window.getSelection(),t=e&&e.toString?e.toString():"",n=!!e&&!e.isCollapsed&&t.trim().length>0;if(isSourceViewerVisible()&&viewerCursor){if(n){var r=e.rangeCount?e.getRangeAt(0):null,o=r?sourceRowLineOf(r.startContainer):null,i=r?sourceRowLineOf(r.endContainer):null;null!=o&&null!=i||(o=selectionAnchor?selectionAnchor.lineIndex:viewerCursor.lineIndex,i=viewerCursor.lineIndex);var a=Math.min(o,i),s=Math.max(o,i);return{path:viewerCursor.path,line:s+1,code:t,from:a+1,to:s+1,side:null}}var c=sourceByPath.get(viewerCursor.path),l=c&&"string"==typeof c.content&&c.content.split(/\r?\n/)[viewerCursor.lineIndex]||"";return{path:viewerCursor.path,line:viewerCursor.lineIndex+1,code:l,from:null,to:null,side:null}}if(!n&&diffCursor&&isDiffViewVisible()){var u=diffWrapperByPath(diffCursor.path),d=u?diffRowAt(u,diffCursor.side,diffCursor.rowIndex):null,f=d?diffLineNumber(d):null;if(null!=f)return{path:diffCursor.path,line:f,code:diffLineText(d)||"",from:null,to:null,side:null}}var m=e&&e.rangeCount?e.getRangeAt(0):null,p=m?m.startContainer:e?e.anchorNode:null,h=m?m.endContainer:e?e.anchorNode:null,v=p?1===p.nodeType?p:p.parentElement:null,g=h?1===h.nodeType?h:h.parentElement:null,y=g&&g.closest&&g.closest(".d2h-file-wrapper")||document.querySelector("#diff2html-container .d2h-file-wrapper:not(.df-inactive)");if(!y)return null;var w=y.querySelector(".d2h-file-name"),C=(w&&w.textContent?w.textContent:"").trim();if(!C)return null;var b=g&&g.closest?g.closest("tr"):null;if(!b||!b.querySelector(".d2h-code-side-linenumber")){var S=y.querySelectorAll(".d2h-file-side-diff"),E=S[S.length-1],k=E?E.querySelector(".d2h-code-side-linenumber"):null;b=k?k.closest("tr"):null}if(!b)return null;var L=diffLineNumber(b);if(null==L)return null;var I=n&&v&&v.closest?v.closest("tr"):null,x=I?diffLineNumber(I):null;null==x&&(x=L);var A=g&&g.closest?g.closest(".d2h-file-side-diff"):null,T=diffSideTables(y),R=A&&A===T.left?"old":"new";return{path:C,line:L,code:n?t:"",from:n?Math.min(x,L):null,to:n?Math.max(x,L):null,side:R}}function composerTargetLabel(e){return((e.path||"").split("/").pop()||e.path||"")+":"+(null!=e.from&&null!=e.to&&e.from!==e.to?e.from+"–"+e.to:String(e.line))}function threadHtml(e,n){var r="";if(commentsAt(e,n).forEach(function(e){composerState&&composerState.editSeq===e.seq||(r+='<div class="mc-card mc-'+e.kind+'"><div class="mc-card-head"><span class="mc-kind">'+commentKindLabel(e.kind)+'</span><button type="button" class="mc-del" data-seq="'+e.seq+'" title="'+escapeHtml(t("composer.delete"))+'">×</button></div><div class="mc-card-body">'+escapeHtml(e.text)+"</div></div>")}),composerState&&composerState.path===e&&composerState.line===n){var o="q"===composerState.kind?t("composer.question"):t("composer.changeRequest");r+='<div class="mc-card mc-'+composerState.kind+' mc-composer"><div class="mc-card-head"><span class="mc-kind">'+commentKindLabel(composerState.kind)+'</span><span class="mc-target" title="'+escapeHtml(composerState.path||"")+'">'+escapeHtml(composerTargetLabel(composerState))+'</span></div><textarea class="mc-input" rows="3" placeholder="'+escapeHtml(o)+'">'+escapeHtml(composerState.editText||"")+'</textarea><div class="mc-actions"><button type="button" class="mc-btn mc-save">'+escapeHtml(t("composer.save"))+'</button><button type="button" class="mc-btn mc-ghost mc-cancel">'+escapeHtml(t("composer.cancel"))+'</button><span class="mc-hint">'+escapeHtml(t("composer.hint"))+"</span></div></div>"}return r}function injectThreadRow(e,t,n){if(e&&e.parentNode){var r=document.createElement("tr");r.className="mc-comment-row";var o=document.createElement("td");o.colSpan=e.classList&&e.classList.contains("source-row")&&e.children.length||2,o.className="mc-thread-cell",o.innerHTML=threadHtml(t,n),r.appendChild(o),e.parentNode.insertBefore(r,e.nextSibling)}}function renderDiffComments(){var e=document.getElementById("diff2html-container");e&&(e.querySelectorAll(".mc-comment-row").forEach(function(e){e.remove()}),e.querySelectorAll(".d2h-file-wrapper").forEach(function(e){var t=e.querySelector(".d2h-file-name"),n=(t&&t.textContent?t.textContent:"").trim();if(n){var r=relevantLines(n);if(r.length){var o=e.querySelectorAll(".d2h-file-side-diff"),i=o[o.length-1];if(i){var a=i.querySelectorAll("tr");r.forEach(function(e){for(var t=0;t<a.length;t++){var r=a[t].querySelector(".d2h-code-side-linenumber");if(r&&(r.textContent||"").trim()===String(e)){injectThreadRow(a[t],n,e);break}}})}}}}))}function renderSourceComments(){var e=document.getElementById("source-body");if(e){e.querySelectorAll(".mc-comment-row").forEach(function(e){e.remove()});var t=document.getElementById("source-viewer"),n=t&&t.dataset.openPath||"";n&&relevantLines(n).forEach(function(t){var r=e.querySelector('.source-row[data-line-index="'+(t-1)+'"]');r&&injectThreadRow(r,n,t)})}}function renderCommentBadges(){document.querySelectorAll(".mc-file-badge").forEach(function(e){e.remove()});var e={};function n(e){var n=document.createElement("span");n.className="mc-file-badge";var r="";return e.q&&(r+='<span class="mc-fb mc-fb-q" title="'+e.q+" "+escapeHtml(t("badge.questions"))+'">'+e.q+"</span>"),e.c&&(r+='<span class="mc-fb mc-fb-c" title="'+e.c+" "+escapeHtml(t("badge.changeRequests"))+'">'+e.c+"</span>"),n.innerHTML=r,n}function r(t,r,o){document.querySelectorAll(t).forEach(function(t){var i=e[t.dataset[r]||""];if(i){var a=t.querySelector(o);a?t.insertBefore(n(i),a):t.appendChild(n(i))}})}reviewComments.forEach(function(t){var n=e[t.path]||(e[t.path]={q:0,c:0});"q"===t.kind?n.q+=1:n.c+=1}),r(".change-row","file",".diffstat"),r(".source-link","sourceFile",".count")}function applyCommentSelectionHighlight(){if(document.querySelectorAll(".mc-sel-line").forEach(function(e){e.classList.remove("mc-sel-line")}),composerState&&null!=composerState.from&&null!=composerState.to){var e=composerState.from,t=composerState.to;if(isDiffViewVisible()){var n=diffWrapperByPath(composerState.path);if(!n)return;diffRowsOf(diffSideTable(n,composerState.side||"new")).forEach(function(n){var r=diffLineNumber(n);null!=r&&r>=e&&r<=t&&n.classList.add("mc-sel-line")})}else if(isSourceViewerVisible())for(var r=e;r<=t;r++){var o=document.querySelector('.source-row[data-line-index="'+(r-1)+'"]');o&&o.classList.add("mc-sel-line")}}}function refreshComments(){renderDiffComments(),isSourceViewerVisible()&&renderSourceComments(),renderCommentBadges(),applyCommentSelectionHighlight();for(var e=!1,t=document.querySelectorAll(".mc-composer .mc-input"),n=0;n<t.length;n++)if((!t[n].closest("#diff-view")||isDiffViewVisible())&&(!t[n].closest("#source-viewer")||isSourceViewerVisible())){e=!0;break}if(document.body.classList.toggle("mc-composing",e),composerState){var r=0,o=function(){var e=activeComposerInput();if(!e)return!0;if(document.activeElement===e)return!0;try{e.focus({preventScroll:!0})}catch(t){try{e.focus()}catch(e){}}try{e.selectionStart=e.selectionEnd=e.value.length}catch(e){}return document.activeElement===e};if(!o())var i=setInterval(function(){(o()||++r>12)&&clearInterval(i)},25)}}function openComposer(e){var t=currentCommentTarget();if(t){composerState={kind:e,path:t.path,line:t.line,code:t.code,from:t.from,to:t.to,side:t.side};try{var n=window.getSelection();n&&n.removeAllRanges()}catch(e){}refreshComments()}}function closeComposer(){composerState&&(composerState=null,refreshComments(),flushPendingDiffUpdate())}function activeComposerInput(){for(var e=document.querySelectorAll(".mc-composer .mc-input"),t=0;t<e.length;t++)if((!e[t].closest("#diff-view")||isDiffViewVisible())&&(!e[t].closest("#source-viewer")||isSourceViewerVisible()))return e[t];return e[0]||null}function saveComposer(e){if(composerState){var t=e||activeComposerInput();t&&(null!=composerState.editSeq?updateComment(composerState.editSeq,t.value):addComment(composerState.kind,composerState.path,composerState.line,composerState.code,t.value),composerState=null,refreshComments(),flushPendingDiffUpdate())}}function defaultMergePrompt(e){return t("q"===e?"mergePrompt.default.q":"mergePrompt.default.c")}var mergePromptsKey="monacori-merge-prompts";function loadMergePrompts(){var e=persistRead(mergePromptsKey);if(e&&"object"==typeof e)return e;try{var t=JSON.parse(localStorage.getItem(mergePromptsKey)||"{}");return t&&"object"==typeof t?t:{}}catch(e){return{}}}function mergePromptFor(e){var t=loadMergePrompts()[e];return"string"==typeof t&&t.trim()?t:defaultMergePrompt(e)}function saveMergePrompt(e,t){var n=loadMergePrompts();t&&t.trim()?n[e]=t:delete n[e],persistSave(mergePromptsKey,n)}function mergedCaretXY(e){var t=e.selectionStart||0,n=e.value.slice(0,t).split("\n"),r=n.length-1,o=n[r].length,i=getComputedStyle(e),a=parseFloat(i.lineHeight)||18,s=e.getBoundingClientRect(),c=document.createElement("span");c.style.cssText="position:absolute;visibility:hidden;white-space:pre",c.style.font=i.font,c.textContent="MMMMMMMMMMMMMMMMMMMM",document.body.appendChild(c);var l=c.getBoundingClientRect().width/20;c.remove();var u=s.top+(parseFloat(i.paddingTop)||0)+r*a-e.scrollTop;return{x:Math.min(s.left+(parseFloat(i.paddingLeft)||0)+o*l,s.right-24),top:u,below:u+a+2}}function showCustomDropdown(e,t,n,r){var o=document.getElementById("mc-dropdown");o&&o.remove();var i=document.createElement("div");i.id="mc-dropdown",i.className="mc-dropdown";var a=0;function s(e){a=e;for(var t=0;t<i.children.length;t++)i.children[t].classList.toggle("active",t===e)}function c(){i.remove(),document.removeEventListener("keydown",l,!0),document.removeEventListener("mousedown",u,!0)}function l(e){if("ArrowDown"===e.key)e.preventDefault(),e.stopPropagation(),s(Math.min(a+1,n.length-1));else if("ArrowUp"===e.key)e.preventDefault(),e.stopPropagation(),s(Math.max(a-1,0));else if("Enter"===e.key){e.preventDefault(),e.stopPropagation();var t=n[a];c(),t&&t.onSelect()}else"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),c())}function u(e){i.contains(e.target)||c()}n.forEach(function(e,t){var n=document.createElement("button");n.type="button",n.className="mc-dropdown-item"+(0===t?" active":""),n.textContent=e.label,n.addEventListener("click",function(){c(),e.onSelect()}),n.addEventListener("mousemove",function(){s(t)}),i.appendChild(n)}),document.body.appendChild(i);var d=i.getBoundingClientRect(),f=t,m=e;"number"==typeof r&&f+d.height>window.innerHeight-8?f=Math.max(8,r-d.height):f+d.height>window.innerHeight-8&&(f=Math.max(8,window.innerHeight-d.height-8)),m+d.width>window.innerWidth-8&&(m=Math.max(8,window.innerWidth-d.width-8)),i.style.left=Math.round(m)+"px",i.style.top=Math.round(f)+"px",document.addEventListener("keydown",l,!0),document.addEventListener("mousedown",u,!0)}function mergedCommentSeqs(e,t,n){for(var r=reviewComments.filter(function(t){return t.kind===e}),o=buildMergedText(e).split(String.fromCharCode(10)),i=[],a=0,s=-1,c=0;c<o.length;c++){var l=a,u=a+o[c].length;if(0===o[c].indexOf("### ")&&s++,s>=0&&s<r.length&&u>=t&&l<=n){var d=r[s].seq;i.indexOf(d)<0&&i.push(d)}a=u+1}return i}function navigateToComment(e){var t=reviewComments.find(function(t){return t.seq===e});t&&(openSourceFile(t.path),requestAnimationFrame(function(){setSourceCursor(t.path,Math.max(0,(t.line||1)-1),0,!0,-1)}))}function jumpMergedComment(e,t){var n=e.value,r=[],o=0;if(n.split("\n").forEach(function(e){0===e.indexOf("### ")&&r.push(o),o+=e.length+1}),r.length){var i,a=e.selectionStart;if(t>0)null==(i=r.find(function(e){return e>a}))&&(i=r[r.length-1]);else{var s=r.filter(function(e){return e<a});i=s.length?s[s.length-1]:r[0]}e.selectionStart=e.selectionEnd=i;var c=n.slice(0,i).split("\n").length-1,l=parseFloat(getComputedStyle(e).lineHeight)||18;e.scrollTop=Math.max(0,c*l-e.clientHeight/2)}}function buildMergedText(e){var n=reviewComments.filter(function(t){return t.kind===e}),r=String.fromCharCode(10),o=[];return o.push(mergePromptFor(e)),o.push(""),o.push(t("q"===e?"merged.qHeading":"merged.cHeading")+" ("+n.length+")"),o.push(""),n.forEach(function(e){o.push("### "+e.path+":"+e.line),e.code&&e.code.trim()&&o.push("> "+e.code.trim()),o.push(e.text),o.push("")}),o.join(r)}var dockHeightKey="monacori-dock-height",dockMaximized=!1;function applyDockHeight(e){var t=Math.max(140,Math.min(e,window.innerHeight-120));document.documentElement.style.setProperty("--dock-height",t+"px")}function activeDockPanel(){var e=document.getElementById("mc-merged-panel")||document.getElementById("mc-memo-panel");if(e)return e;var t=document.getElementById("terminal-panel");return t&&!t.classList.contains("hidden")?t:null}function applyDockMaximized(){activeDockPanel()||(dockMaximized=!1),document.body.classList.toggle("dock-maximized",dockMaximized)}function toggleDockMaximized(){if(!(treeFocusIndex>=0)){var e=document.activeElement;e&&e.closest&&(e.closest(".dock-panel")||e.closest(".terminal-panel"))&&activeDockPanel()&&(dockMaximized=!dockMaximized,applyDockMaximized())}}function isDockFocused(){var e=document.activeElement;return!!(e&&e.closest&&e.closest(".dock-panel"))}function closeMergedMemoDocks(){var e=document.getElementById("mc-merged-panel");e&&e.remove();var t=document.getElementById("mc-memo-panel");t&&t.remove(),document.querySelectorAll(".dock-backdrop").forEach(function(e){e.remove()}),document.body.classList.toggle("dock-open",!!activeDockPanel()),document.body.classList.toggle("floating-dock",!(!document.getElementById("mc-merged-panel")&&!document.getElementById("mc-memo-panel"))),applyDockMaximized(),"function"==typeof syncRail&&syncRail()}function focusDockField(e,t){var n=0,r=function(){if(!document.querySelector(t))return!0;if(document.activeElement===e)return!0;try{e.focus()}catch(e){}return document.activeElement===e};if(!r())var o=setInterval(function(){(r()||++n>12)&&clearInterval(o)},25)}function mountDock(e,n){if(window.__monacoriTerminal&&"function"==typeof window.__monacoriTerminal.close)try{window.__monacoriTerminal.close()}catch(e){}var r=document.getElementById(e);r&&r.remove(),closeMergedMemoDocks();var o=document.createElement("div");o.id=e,o.className="dock-panel",o.tabIndex=-1;var i=document.createElement("div");i.className="dock-backdrop";var a=document.createElement("div");a.className="dock-resizer",a.setAttribute("aria-hidden","true");var s=document.createElement("div");s.className="dock-bar";var c=document.createElement("span");c.className="dock-title",c.textContent=n;var l=document.createElement("button");l.type="button",l.className="dock-btn dock-max",l.setAttribute("data-i18n-title","dock.maximize"),l.title=t("dock.maximize"),l.textContent="⤢";var u=document.createElement("button");u.type="button",u.className="dock-btn dock-close",u.setAttribute("data-i18n","merged.close"),u.textContent=t("merged.close");var d=document.createElement("div");function f(){o.remove(),i.remove(),closeMergedMemoDocks()}return d.className="dock-body",s.appendChild(c),s.appendChild(l),s.appendChild(u),o.appendChild(a),o.appendChild(s),o.appendChild(d),document.body.appendChild(i),document.body.appendChild(o),l.addEventListener("click",function(){toggleDockMaximized()}),u.addEventListener("click",f),i.addEventListener("click",f),o.addEventListener("keydown",function(e){"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),f())}),a.addEventListener("mousedown",function(e){function t(e){applyDockHeight(window.innerHeight-e.clientY)}e.preventDefault(),a.classList.add("resizing"),document.addEventListener("mousemove",t),document.addEventListener("mouseup",function e(){a.classList.remove("resizing"),document.removeEventListener("mousemove",t),document.removeEventListener("mouseup",e);var n=parseInt(getComputedStyle(document.documentElement).getPropertyValue("--dock-height"),10);if(n)try{localStorage.setItem(dockHeightKey,String(n))}catch(e){}})}),document.body.classList.add("dock-open"),document.body.classList.add("floating-dock"),applyDockMaximized(),"function"==typeof syncRail&&syncRail(),{panel:o,body:d,bar:s,close:f}}function openMergedView(e){var n=mountDock("mc-merged-panel",t("q"===e?"merged.qTitle":"merged.cTitle"));n.panel.dataset.kind=e;var r=document.createElement("textarea");r.className="mc-modal-text",r.value=buildMergedText(e),r.addEventListener("beforeinput",function(e){e.preventDefault()}),r.addEventListener("keydown",function(o){if(o.altKey&&("ArrowDown"===o.key||"ArrowUp"===o.key))return o.preventDefault(),o.stopPropagation(),void jumpMergedComment(r,"ArrowDown"===o.key?1:-1);if(o.altKey&&("Enter"===o.key||"Enter"===o.code)){o.preventDefault(),o.stopPropagation();var i=mergedCommentSeqs(e,r.selectionStart,r.selectionEnd);if(i.length){var a=mergedCaretXY(r),s=a.x,c=a.below,l=a.top,u=function(){reviewComments.filter(function(t){return t.kind===e}).length?r.value=buildMergedText(e):n.close()};if(r.selectionStart!==r.selectionEnd||i.length>1){var d=[];window.__monacoriTerminal&&"function"==typeof window.__monacoriTerminal.paneCount&&window.__monacoriTerminal.paneCount()>0&&d.push({label:t("merged.sendToTerminal"),onSelect:function(){var t=buildMergedText(e);n.close(),window.__monacoriTerminal.enterSendMode(t)}}),d.push({label:t("dropdown.remove"),onSelect:function(){i.forEach(deleteComment),u()}}),showCustomDropdown(s,c,d,l)}else{var f=i[0];showCustomDropdown(s,c,[{label:t("dropdown.navigate"),onSelect:function(){n.close(),navigateToComment(f)}},{label:t("dropdown.remove"),onSelect:function(){deleteComment(f),u()}}],l)}}}}),n.body.appendChild(r),focusDockField(r,"#mc-merged-panel")}!function(){var e=parseInt(localStorage.getItem(dockHeightKey)||"",10);e&&applyDockHeight(e)}(),window.__monacoriCloseDocks=closeMergedMemoDocks;var memoKey="monacori-memo";function loadMemo(){var e=persistRead(memoKey);if("string"==typeof e)return e;try{var t=localStorage.getItem(memoKey);return"string"==typeof t?t:""}catch(e){return""}}function saveMemo(e){persistSave(memoKey,e||"")}function renderMemoMd(e){return e&&e.trim()?renderMarkdownBlocks(e).map(function(e){return e.html}).join(""):'<div class="mc-memo-empty" data-i18n="memo.previewEmpty">'+escapeHtml(t("memo.previewEmpty"))+"</div>"}function openMemoView(){if(document.getElementById("mc-memo-panel"))closeMergedMemoDocks();else{var e=mountDock("mc-memo-panel",t("memo.title")),n=document.createElement("div");n.className="mc-memo-body";var r=document.createElement("textarea");r.className="mc-modal-text mc-memo-edit",r.spellcheck=!1,r.setAttribute("data-i18n-ph","memo.placeholder"),r.placeholder=t("memo.placeholder"),r.value=loadMemo();var o=document.createElement("div");if(o.className="md-cell mc-memo-preview",o.innerHTML=renderMemoMd(r.value),r.addEventListener("input",function(){saveMemo(r.value),o.innerHTML=renderMemoMd(r.value)}),window.__monacoriTerminal&&"function"==typeof window.__monacoriTerminal.paneCount&&window.__monacoriTerminal.paneCount()>0){var i=document.createElement("button");i.type="button",i.className="dock-btn mc-send-term",i.setAttribute("data-i18n","merged.sendToTerminal"),i.textContent=t("merged.sendToTerminal"),i.addEventListener("click",function(){var t=r.value;e.close(),window.__monacoriTerminal.enterSendMode(t)}),e.bar.insertBefore(i,e.bar.querySelector(".dock-max"))}n.appendChild(r),n.appendChild(o),e.body.appendChild(n),focusDockField(r,"#mc-memo-panel")}}function setTab(e){"files"===e&&ensureTreeRendered(),document.querySelectorAll(".tab").forEach(t=>{t.classList.toggle("active",t.dataset.tab===e)}),document.getElementById("changes-panel")?.classList.toggle("hidden","changes"!==e),document.getElementById("files-panel")?.classList.toggle("hidden","files"!==e),syncRail()}function syncRail(){var e=document.querySelector(".activity-rail");if(e){var t=function(t,n){var r=e.querySelector('[data-view="'+t+'"]');r&&r.classList.toggle("is-active",!!n)};t("changes",!document.getElementById("changes-panel")?.classList.contains("hidden")),t("files",!document.getElementById("files-panel")?.classList.contains("hidden"));var n=document.getElementById("mc-merged-panel");t("q",!(!n||"q"!==n.dataset.kind)),t("c",!(!n||"c"!==n.dataset.kind)),t("memo",!!document.getElementById("mc-memo-panel"));var r=document.getElementById("history-view");t("history",!(!r||r.classList.contains("hidden")))}}function toggleMergedRail(e){var t=document.getElementById("mc-merged-panel");t&&t.dataset.kind===e?closeMergedMemoDocks():openMergedView(e)}function ensureTreeRendered(){var e=document.getElementById("files-panel"),n=document.getElementById("files-tree-html");if(e&&n){var r=n.textContent||"";n.parentNode&&n.parentNode.removeChild(n),e.innerHTML='<div class="empty-nav">'+escapeHtml(t("source.buildingTree"))+"</div>",setTimeout(function(){if(e.innerHTML=r,sourceLinks=Array.from(document.querySelectorAll(".source-link")),"function"==typeof refreshComments)try{refreshComments()}catch(e){}},0)}}function showDiffView(e){if(document.getElementById("source-viewer")?.classList.add("hidden"),document.getElementById("diff-view")?.classList.remove("hidden"),setTab("changes"),current<0&&hunkTotal())setActive(0,e);else if(current>=0){const t=current;whenFileReady(diffWrapperByPath(hunkPathAt(t)),function(){const n=document.getElementById("hunk-"+t);n&&(showOnlyFile(hunkPathAt(t)),e&&n.scrollIntoView({block:"start"}))})}}function showSourceView(){document.getElementById("diff-view")?.classList.add("hidden"),document.getElementById("source-viewer")?.classList.remove("hidden"),setTab("files")}function saveUiState(){const e=document.querySelector(".tab.active")?.dataset.tab||"changes",t=document.getElementById("source-viewer")?.dataset.openPath||"";sessionStorage.setItem(uiStateKey,JSON.stringify({tab:e,view:document.getElementById("source-viewer")?.classList.contains("hidden")?"diff":"source",sourcePath:t,hash:location.hash,tabs:sourceTabs,diffCursor:diffCursor,viewerCursor:viewerCursor}))}function restoreUiState(){const e=sessionStorage.getItem(uiStateKey);if(!e)return!1;try{const o=JSON.parse(e);if(Array.isArray(o.tabs)&&(sourceTabs=o.tabs.filter(function(e){return sourceByPath.has(e)})),"diff"===o.view){const e=String(o.hash||location.hash||"").match(/^#hunk-(\d+)$/);if(setActive(e?Number(e[1]):current>=0?current:0,!1),o.diffCursor&&o.diffCursor.path){var t=o.diffCursor;setTimeout(function(){try{setDiffCursor(t.path,t.side,t.rowIndex,t.column,!0)}catch(e){}},60)}return!0}var n=o.sourcePath&&sourceByPath.has(o.sourcePath)?o.sourcePath:sourceTabs[0]||"";if(n){if(openSourceFile(n),o.viewerCursor&&o.viewerCursor.path===n){var r=o.viewerCursor;setTimeout(function(){try{setSourceCursor(n,r.lineIndex,r.column,!0,-1)}catch(e){}},60)}return!0}sourceTabs=[]}catch{sessionStorage.removeItem(uiStateKey)}return!1}document.addEventListener("click",function(e){var t=e.target;if(t&&t.closest){var n=t.closest(".mc-del");return n?(e.preventDefault(),void deleteComment(parseInt(n.dataset.seq,10))):t.closest(".mc-save")?(e.preventDefault(),void saveComposer()):t.closest(".mc-cancel")?(e.preventDefault(),void closeComposer()):void 0}}),document.addEventListener("keydown",function(e){var t=e.target;if(t&&t.classList&&t.classList.contains("mc-input"))return"Escape"===e.key?(e.preventDefault(),e.stopPropagation(),void closeComposer()):(e.metaKey||e.ctrlKey)&&"Enter"===e.key?(e.preventDefault(),e.stopPropagation(),void saveComposer(t)):void 0},!0),refreshComments(),function(){if(window.monacoriPty){var e=document.getElementById("terminal-panel"),n=document.getElementById("terminal-host"),r=document.getElementById("terminal-toggle"),o=document.getElementById("terminal-close"),i=e?e.querySelector(".terminal-resizer"):null;if(e&&n){r&&r.classList.remove("hidden");var a=[],s=null,c="monacori-terminal-height",l="monacori-terminal-open:"+location.pathname,u=parseInt(localStorage.getItem(c)||"",10);u&&p(u),window.monacoriPty.onData(function(e){for(var t=0;t<a.length;t++)if(a[t].id===e.id)return void a[t].term.write(e.data)}),window.monacoriPty.onExit(function(e){!function(e){for(var t=0;t<a.length;t++)if(a[t].id===e)return void C(a[t])}(e.id)}),r&&r.addEventListener("click",function(){S(!b())}),o&&o.addEventListener("click",function(){S(!1)}),window.monacoriMenu&&"function"==typeof window.monacoriMenu.onTerminalToggle&&window.monacoriMenu.onTerminalToggle(function(){if(b()){var t=document.activeElement;if(t&&e.contains(t))S(!1);else if(s)try{s.term.focus()}catch(e){}}else S(!0)}),window.monacoriMenu&&"function"==typeof window.monacoriMenu.onTerminalSplit&&window.monacoriMenu.onTerminalSplit(function(){a.length>=4||(y(),v())}),window.monacoriMenu&&"function"==typeof window.monacoriMenu.onTerminalPaneFocus&&window.monacoriMenu.onTerminalPaneFocus(function(e){if(!(a.length<2)){var t=a.indexOf(s);t<0&&(t=0),g(a[(t+e+a.length)%a.length])}}),window.monacoriMenu&&"function"==typeof window.monacoriMenu.onTerminalPaneRename&&window.monacoriMenu.onTerminalPaneRename(function(){w(s)});var d="function"==typeof ResizeObserver?new ResizeObserver(function(){b()&&v()}):null;d&&d.observe(n),window.addEventListener("resize",function(){b()&&v()}),i&&i.addEventListener("mousedown",function(e){function t(e){p(window.innerHeight-e.clientY)}e.preventDefault(),i.classList.add("resizing"),document.addEventListener("mousemove",t),document.addEventListener("mouseup",function e(){i.classList.remove("resizing"),document.removeEventListener("mousemove",t),document.removeEventListener("mouseup",e);var n=parseInt(getComputedStyle(document.documentElement).getPropertyValue("--terminal-height"),10);if(n)try{localStorage.setItem(c,String(n))}catch(e){}v()})}),window.addEventListener("beforeunload",function(){a.forEach(function(e){if(null!=e.id)try{window.monacoriPty.kill({id:e.id})}catch(e){}})});var f=null,m=0;document.addEventListener("keydown",function(e){if(null!=f)if(e.preventDefault(),e.stopPropagation(),"ArrowLeft"===e.key||"ArrowRight"===e.key||"ArrowUp"===e.key||"ArrowDown"===e.key){var t="ArrowRight"===e.key||"ArrowDown"===e.key?1:-1;m=(m+t+a.length)%a.length,k()}else if("Enter"===e.key){var n=a[m],r=f;L(),E(n,r)}else"Escape"===e.key&&L()},!0),window.__monacoriTerminal={isOpen:b,hasFocus:function(){var t=document.activeElement;return!(!t||!e.contains(t))},open:function(){S(!0)},paneCount:function(){return a.length},closeActivePane:function(){var e=s||a[a.length-1];if(e){if(null!=e.id)try{window.monacoriPty.kill({id:e.id})}catch(e){}C(e)}else S(!1)},enterSendMode:function(t){0!==a.length&&(S(!0),f=t,m=Math.max(0,a.indexOf(s)),e.classList.add("send-mode"),document.body.classList.add("terminal-send-mode"),k())},send:function(e){E(s||a[0],e)},sendToPane:function(e,t){E(a[e]||s||a[0],t)},close:function(){S(!1)}};try{"1"===sessionStorage.getItem(l)&&S(!0)}catch(e){}}}function p(e){var t=Math.max(120,Math.min(e,window.innerHeight-120));document.documentElement.style.setProperty("--terminal-height",t+"px")}function h(e){if(e)try{e.fit.fit(),null!=e.id&&window.monacoriPty.resize({id:e.id,cols:e.term.cols,rows:e.term.rows})}catch(e){}}function v(){a.forEach(h)}function g(e){s=e,e&&e.labelEl&&e.labelEl.classList.remove("has-bell"),a.forEach(function(t){t.el.classList.toggle("is-active",t===e),t.el.classList.toggle("is-inactive",a.length>1&&t!==e)}),e&&requestAnimationFrame(function(){try{if(e.labelEl&&"true"===e.labelEl.getAttribute("contenteditable"))return;e.term.focus()}catch(e){}})}function y(){if(!function(){if("function"==typeof window.Terminal)return!0;var e=document.getElementById("xterm-code");if(!e)return!1;try{var t=document.createElement("script");t.textContent=e.textContent,document.head.appendChild(t),e.remove()}catch(e){return!1}return"function"==typeof window.Terminal}())return null;var e=document.createElement("div");e.className="terminal-pane";var r=document.createElement("div");r.className="terminal-pane-label";var o=document.createElement("div");o.className="terminal-pane-host",e.appendChild(r),e.appendChild(o),n.appendChild(e);var i=new window.Terminal({fontSize:12,fontFamily:"Monaco, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",theme:{background:"#161616",foreground:"#a9b7c6",cursor:"#a9b7c6",selectionBackground:"#214283"},cursorBlink:!0}),c=new window.FitAddon.FitAddon;i.loadAddon(c),i.open(o);var l={id:null,term:i,fit:c,el:e,labelEl:r,name:"Terminal "+(a.length+1)};r.textContent=l.name,i.attachCustomKeyEventHandler(function(e){if("keydown"===e.type&&"F7"===e.key&&!e.metaKey&&!e.ctrlKey&&!e.altKey)return!1;if("keydown"===e.type&&e.metaKey){var t=(e.key||"").toLowerCase();if("meta"===t||"control"===t||"alt"===t||"shift"===t)return!0;if("KeyC"===e.code&&i.hasSelection&&i.hasSelection())return function(e){if(e){try{if(window.monacoriClipboard&&window.monacoriClipboard.write)return void window.monacoriClipboard.write(e)}catch(e){}try{navigator.clipboard&&navigator.clipboard.writeText&&navigator.clipboard.writeText(e)}catch(e){}}}(i.getSelection()),!1;if("KeyC"===e.code||"KeyV"===e.code||"KeyX"===e.code||"KeyA"===e.code)return!0;if("KeyW"===e.code)return!1;try{i.blur()}catch(e){}return!1}return!0}),i.onData(function(e){null!=l.id&&window.monacoriPty.write({id:l.id,data:e})}),i.onBell(function(){if(l!==s&&l.labelEl&&l.labelEl.classList.add("has-bell"),!1!==persistRead("monacori-terminal-bell-notify"))try{window.monacoriPty.bell({title:"monacori",body:l.name+" — "+t("notify.bellBody")})}catch(e){}}),e.addEventListener("mousedown",function(e){e.target!==r&&g(l)}),r.addEventListener("dblclick",function(){w(l)}),a.push(l);try{c.fit()}catch(e){}return window.monacoriPty.spawn({cols:i.cols||80,rows:i.rows||24}).then(function(e){l.id=e&&e.id}),g(l),l}function w(e){if(e||(e=s),e){var t=e.labelEl;if("true"!==t.getAttribute("contenteditable")){g(e),t.contentEditable="true";var n=0,r=function(){if("true"!==t.getAttribute("contenteditable"))return!0;try{t.focus()}catch(e){}if(document.activeElement!==t)return!1;try{var e=document.createRange();e.selectNodeContents(t);var n=window.getSelection();n.removeAllRanges(),n.addRange(e)}catch(e){}return!0};if(!r())var o=setInterval(function(){(r()||++n>12)&&clearInterval(o)},25);t.addEventListener("keydown",a),t.addEventListener("blur",c)}}function i(n){t.removeEventListener("keydown",a),t.removeEventListener("blur",c),t.contentEditable="false",n&&(e.name=(t.textContent||"").trim()||e.name),t.textContent=e.name;try{e.term&&e.term.focus()}catch(e){}}function a(e){e.stopPropagation(),"Enter"===e.key?(e.preventDefault(),i(!0)):"Escape"===e.key&&(e.preventDefault(),i(!1))}function c(){i(!0)}}function C(e){var t=a.indexOf(e);if(!(t<0)){try{e.term.dispose()}catch(e){}e.el.parentNode&&e.el.parentNode.removeChild(e.el),a.splice(t,1),s===e&&g(a[a.length-1]||null),0===a.length?S(!1):v()}}function b(){return!e.classList.contains("hidden")}function S(t){if(t&&"function"==typeof window.__monacoriCloseDocks)try{window.__monacoriCloseDocks()}catch(e){}e.classList.toggle("hidden",!t),document.body.classList.toggle("terminal-open",t),r&&r.classList.toggle("is-active",t);try{sessionStorage.setItem(l,t?"1":"0")}catch(e){}"function"==typeof applyDockMaximized&&applyDockMaximized(),t&&(0===a.length&&y(),requestAnimationFrame(function(){if(v(),s)try{s.term.focus()}catch(e){}}))}function E(e,t){e&&(S(!0),null!=e.id&&window.monacoriPty.write({id:e.id,data:t}),g(e),requestAnimationFrame(function(){try{e.term.focus()}catch(e){}}))}function k(){a.forEach(function(e,t){e.el.classList.toggle("is-send-target",t===m),e.el.classList.toggle("is-dimmed",t!==m)})}function L(){null!=f&&(f=null,e.classList.remove("send-mode"),document.body.classList.remove("terminal-send-mode"),a.forEach(function(e){e.el.classList.remove("is-send-target","is-dimmed")}))}}(),window.monacoriMenu&&"function"==typeof window.monacoriMenu.onMergedView&&window.monacoriMenu.onMergedView(function(e){openMergedView(e)}),window.monacoriMenu&&"function"==typeof window.monacoriMenu.onOpenMemo&&window.monacoriMenu.onOpenMemo(function(){openMemoView()}),window.monacoriMenu&&"function"==typeof window.monacoriMenu.onDiffUpdate&&window.monacoriMenu.onDiffUpdate(function(e){try{applyDiffUpdate(e)}catch(e){}}),window.monacoriMenu&&"function"==typeof window.monacoriMenu.onCloseTab&&window.monacoriMenu.onCloseTab(function(){var e=window.__monacoriTerminal;e&&e.isOpen()&&e.hasFocus()?e.closeActivePane():isSourceViewerVisible()&&closeActiveSourceTab()}),function(){var e=window.__MONACORI_VERSION__||"";if(e){var n=function(n){if(n){var r=document.getElementById("app-info-status");if(function(e,t){for(var n=String(e).split("."),r=String(t).split("."),o=0;o<3;o++){var i=parseInt(n[o],10)||0,a=parseInt(r[o],10)||0;if(i>a)return!0;if(i<a)return!1}return!1}(n,e)){var o=document.getElementById("app-update-flag");o&&o.classList.remove("hidden");var i=document.getElementById("app-info-update");i&&window.monacoriUpdate&&"function"==typeof window.monacoriUpdate.run?(i.textContent=t("settings.updateRestart")+" (v"+n+")",i.classList.remove("hidden"),r&&(r.textContent=t("settings.updateAvailable")+": v"+n,r.classList.add("has-update"))):r&&(r.textContent=t("settings.updateAvailable")+": v"+n+" — npm i -g @happy-nut/monacori",r.classList.add("has-update"))}else r&&(r.textContent=t("settings.upToDate")+" (v"+e+")")}},r="";try{r=sessionStorage.getItem("monacori-update-latest")||""}catch(e){}r?n(r):"function"==typeof fetch&&fetch("https://registry.npmjs.org/@happy-nut/monacori/latest",{cache:"no-store"}).then(function(e){return e&&e.ok?e.json():null}).then(function(e){if(e&&e.version){try{sessionStorage.setItem("monacori-update-latest",e.version)}catch(e){}n(e.version)}}).catch(function(){})}}(),function(){var e=document.getElementById("settings-modal");if(e){var n=document.getElementById("app-info-btn"),r=document.getElementById("app-update-flag"),o=document.getElementById("app-info-update"),i=document.getElementById("settings-prompt-q"),a=document.getElementById("settings-prompt-c"),s=document.getElementById("settings-reset"),c=document.getElementById("settings-saved"),l=Array.prototype.slice.call(e.querySelectorAll(".settings-cat")),u=Array.prototype.slice.call(e.querySelectorAll(".settings-section")),d=null;n&&n.addEventListener("click",function(t){t.stopPropagation(),e.classList.contains("hidden")?h("general"):v()}),r&&r.addEventListener("click",function(e){e.stopPropagation(),h("general")}),l.forEach(function(e){e.addEventListener("click",function(){m(e.dataset.cat)})}),e.addEventListener("click",function(t){t.target===e&&v()}),document.addEventListener("keydown",function(t){if("Escape"===t.key&&!e.classList.contains("hidden"))return t.stopPropagation(),t.preventDefault(),void v();if((t.metaKey||t.ctrlKey)&&!t.altKey&&!t.shiftKey&&(","===t.key||"Comma"===t.code)){if(e.classList.contains("hidden")&&(document.getElementById("mc-modal")||document.getElementById("mc-memo")))return;t.preventDefault(),t.stopPropagation(),e.classList.contains("hidden")?h("general"):v()}},!0),o&&window.monacoriUpdate&&"function"==typeof window.monacoriUpdate.run&&o.addEventListener("click",function(){if(!o.disabled){o.disabled=!0;var e=document.getElementById("app-info-status");e&&(e.textContent=t("settings.updating"),e.classList.add("has-update")),window.monacoriUpdate.run().then(function(n){n&&n.ok?e&&(e.textContent=t("settings.updated")):(o.disabled=!1,e&&(e.textContent=t("settings.updateFailed")))}).catch(function(){o.disabled=!1,e&&(e.textContent=t("settings.updateFailed"))})}}),i&&i.addEventListener("input",function(){saveMergePrompt("q",i.value),g()}),a&&a.addEventListener("input",function(){saveMergePrompt("c",a.value),g()}),s&&s.addEventListener("click",function(){saveMergePrompt("q",""),saveMergePrompt("c",""),p(),g()});var f=document.getElementById("set-bell-notify");f&&(f.checked=!1!==persistRead("monacori-terminal-bell-notify"),f.addEventListener("change",function(){persistSave("monacori-terminal-bell-notify",f.checked)})),langSelectRef=setupCustomSelect("settings-language",function(){return[{value:"en",label:"English"},{value:"ko",label:"한국어"}]},function(){return locale},function(e){if(e!==locale){persistSave(LOCALE_KEY,locale=e),applyI18n(),p();try{"function"==typeof refreshComments&&refreshComments()}catch(e){}var t=document.getElementById("mc-modal");if(t){var n=t.dataset.kind||"q";t.remove(),openMergedView(n)}}}),themeSelectRef=setupCustomSelect("settings-theme",function(){return[{value:"dark",label:t("theme.dark")},{value:"light",label:t("theme.light")}]},function(){return theme},function(e){e!==theme&&(persistSave(THEME_KEY,theme=e),applyTheme())})}function m(e){l.forEach(function(t){t.classList.toggle("active",t.dataset.cat===e)}),u.forEach(function(t){t.classList.toggle("hidden",t.dataset.cat!==e)})}function p(){var e=loadMergePrompts();i&&(i.value="string"==typeof e.q?e.q:"",i.placeholder=defaultMergePrompt("q")),a&&(a.value="string"==typeof e.c?e.c:"",a.placeholder=defaultMergePrompt("c"))}function h(t){p(),t&&m(t),e.classList.remove("hidden")}function v(){e.classList.add("hidden")}function g(){c&&(c.textContent="Saved",d&&clearTimeout(d),d=setTimeout(function(){c.textContent=""},1200))}}();var pendingDiffUpdate=null;function flushPendingDiffUpdate(){if(pendingDiffUpdate){var e=pendingDiffUpdate;pendingDiffUpdate=null;try{applyDiffUpdate(e)}catch(e){}}}function reconcileDiffWrappers(e,t,n,r){var o=Array.prototype.slice.call(e.querySelectorAll(".d2h-file-wrapper"));if(!o.length)return!1;var i=document.createElement("div");i.innerHTML=t;var a=Array.prototype.slice.call(i.querySelectorAll(".d2h-file-wrapper"));if(a.length!==o.length)return!1;for(var s=0;s<o.length;s++)if(diffWrapperPathKey(o[s])!==diffWrapperPathKey(a[s]))return!1;for(var c=0;c<o.length;c++){var l=o[c],u=a[c],d=diffWrapperPathKey(l);if((n.get(d)||"")!==(r.get(d)||"")){var f=(u.id||"").replace("file-","");delete bodyCache[f],delete bodyPromise[f],l.parentNode.replaceChild(u,l)}else{var m=l.getAttribute("data-first-hunk")!==u.getAttribute("data-first-hunk");l.id=u.id,u.hasAttribute("data-first-hunk")&&l.setAttribute("data-first-hunk",u.getAttribute("data-first-hunk")),u.hasAttribute("data-hunk-count")&&l.setAttribute("data-hunk-count",u.getAttribute("data-hunk-count"));var p=l.querySelector(".d2h-files-diff");m&&p&&!p.hasAttribute("data-lazy")&&markWrapperHunks(l)}}return!0}function applyDiffUpdate(e){if(!e||!e.signature||e.signature===currentSignature)return!1;if(composerState)return pendingDiffUpdate=e,!1;var t=document.getElementById("source-viewer"),n=t&&t.dataset.openPath||"",r=isSourceViewerVisible(),o=document.getElementById("diff2html-container"),i=o?o.scrollTop:0,a=current>=0?hunkPathAt(current):"",s=n&&fileSignatureByPath.get(n)||"",c=new Map((e.fileStates||[]).map(function(e){return[e.path,e.signature]})),l=!1;REVIEW_LAZY&&o&&e.diffContainer&&(l=reconcileDiffWrappers(o,e.diffContainer,fileSignatureByPath,c));var u={};!l&&REVIEW_LAZY&&o&&o.querySelectorAll(".d2h-file-wrapper").forEach(function(e){var t=e.querySelector(".d2h-files-diff");if(t&&!t.hasAttribute("data-lazy")){var n=diffWrapperPathKey(e);n&&(u[n]={sig:fileSignatureByPath.get(n)||"",html:t.innerHTML})}}),o&&!l&&(o.innerHTML=e.diffContainer||"");var d=document.getElementById("changes-panel");d&&(d.innerHTML=e.changesPanel||"");var f=document.getElementById("files-tree-html");f&&(f.textContent=e.filesTree||"");var m=document.getElementById("files-panel");!m||REVIEW_LAZY&&!m.innerHTML.trim()||(m.innerHTML=e.filesTree||"");var p=document.querySelector(".review-status");p&&(p.innerHTML=e.reviewStatus||"");var h=document.getElementById("brand-branch-name");if(h){h.textContent=e.branch||"";var v=h.closest&&h.closest(".brand-branch");v&&v.classList.toggle("hidden",!e.branch)}reviewMeta&&(reviewMeta.setAttribute("data-signature",e.signature),e.generatedAt&&reviewMeta.setAttribute("data-generated-at",e.generatedAt)),fileStates=e.fileStates||[],fileSignatureByPath=new Map(fileStates.map(function(e){return[e.path,e.signature]}));var g=!n||s!==(fileSignatureByPath.get(n)||"");sourceFiles=e.sourceFilesMeta||[],sourceByPath=new Map(sourceFiles.map(function(e){return[e.path,e]})),httpEnvironments=e.httpEnvironments||{},httpEnvNames=Object.keys(httpEnvironments),currentSignature=e.signature,links=Array.from(document.querySelectorAll("#changes-panel .file-link")),sourceLinks=Array.from(document.querySelectorAll(".source-link"));var y=!1;if(a){var w=firstHunkForPath(a);w>=0?(current=w,y=!0):current=-1}return bodyCache={},bodyPromise={},diffBootDone=!1,sourceLoaded=!REVIEW_LAZY_LOAD,sourceLoading=!1,g&&(sourceBodyPath=null),symbolIndex=null,!l&&REVIEW_LAZY&&o&&o.querySelectorAll(".d2h-file-wrapper").forEach(function(e){var t=diffWrapperPathKey(e),n=t?u[t]:null;if(n&&n.sig&&n.sig===(fileSignatureByPath.get(t)||"")&&e.querySelector(".d2h-files-diff[data-lazy]")){var r=(e.id||"").replace("file-","");materializeBody(e,n.html),bodyCache[r]=n.html,bodyPromise[r]=Promise.resolve(e)}}),refreshHunkIndex(),REVIEW_LAZY?(setupLazyDiff(),setTimeout(function(){diffBootDone=!0},0)):diffBootDone=!0,REVIEW_LAZY_LOAD||setTimeout(startSymbolIndex,0),applyI18n(),populateHttpEnvSelect(),initSourceTreeFolds(),remapComments(),refreshComments(),r&&n&&sourceByPath.has(n)?g&&openSourceFile(n,!1):o&&(showDiffView(!1),o.scrollTop=y?i:0),!0}async function checkForLiveUpdate(){if(checkingForUpdates)return;checkingForUpdates=!0;const e=document.getElementById("live-status");try{const r=await fetch("/__ai_flow_state",{cache:"no-store"});if(!r.ok)return;const o=await r.json();if(e&&o.generatedAt&&(e.textContent=t("status.live.updated")+" "+new Date(o.generatedAt).toLocaleTimeString()),o.signature&&o.signature!==currentSignature)try{var n=await fetch("__ai_flow_update",{cache:"no-store"});n.ok&&applyDiffUpdate(await n.json())}catch(e){}}catch{e&&(e.textContent=t("status.live.waiting"))}finally{checkingForUpdates=!1}}function filterNavigation(e){const t=e.trim().toLowerCase();links.forEach(e=>{const n=e.dataset.file||"",r=sourceByPath.get(n),o=(n+"\n"+(r?.content||"")).toLowerCase();e.hidden=t.length>0&&!o.includes(t)}),sourceLinks.forEach(e=>{const n=e.dataset.sourceFile||"",r=sourceByPath.get(n),o=(n+"\n"+(r?.content||"")).toLowerCase();e.hidden=t.length>0&&!o.includes(t)}),updateTreeVisibility(document.getElementById("changes-panel"),t),updateTreeVisibility(document.getElementById("files-panel"),t)}function updateTreeVisibility(e,t){e&&Array.from(e.querySelectorAll("details")).reverse().forEach(e=>{const n=Array.from(e.children).some(e=>"SUMMARY"!==e.tagName&&!e.hidden);e.hidden=t.length>0&&!n,t.length>0&&n&&(e.open=!0)})}function openDefaultSourceFile(){const e=e=>(e.path||"").split("/").length,t=sourceFiles.filter(e=>e.embedded&&(e=>/^readme(\.|$)/i.test(e.name||""))(e)).sort((t,n)=>e(t)-e(n))[0],n=sourceFiles.find(e=>e.changed&&e.embedded)||t||sourceFiles.find(e=>e.embedded)||sourceFiles.find(e=>e.changed)||sourceFiles[0];n?openSourceFile(n.path):hunkTotal()>0&&setActive(0,!1)}function handleSourceCopy(e){const t=window.getSelection(),n=document.getElementById("source-body"),r=document.getElementById("source-viewer");if(!t||t.isCollapsed||!n||!r||r.classList.contains("hidden"))return;if(!t.anchorNode||!t.focusNode)return;if(!n.contains(t.anchorNode)||!n.contains(t.focusNode))return;const o=r.dataset.openPath||"",i=sourceByPath.get(o);if(!i||!i.embedded)return;const a=selectedSourceRows(t);if(0===a.length)return;const s=a.map(e=>Number(e.dataset.lineIndex||0)+1).filter(e=>Number.isFinite(e)).sort((e,t)=>e-t),c=s[0],l=s[s.length-1];if(!c||!l)return;const u=cleanSelectedSourceText(t.toString(),a)||sourceLinesForRows(i,a);if(!u.trim())return;const d=o+":"+(c===l?String(c):c+"-"+l),f=i.language&&"text"!==i.language?i.language:"",m=String.fromCharCode(96).repeat(3),p=d+"\n\n"+m+f+"\n"+u.replace(/\s+$/g,"")+"\n"+m;e.clipboardData?.setData("text/plain",p),e.preventDefault()}function selectedSourceRows(e){if(!e.rangeCount)return[];const t=Array.from({length:e.rangeCount},(t,n)=>e.getRangeAt(n));return Array.from(document.querySelectorAll("#source-body .source-row")).filter(e=>t.some(t=>{try{return t.intersectsNode(e)}catch{return!1}})).sort((e,t)=>Number(e.dataset.lineIndex||0)-Number(t.dataset.lineIndex||0))}function cleanSelectedSourceText(e,t){const n=String(e||"").replace(/\r/g,"").replace(/\u200b/g,"");if(!n.trim())return"";const r=t.map(e=>Number(e.dataset.lineIndex||0)+1),o=n.split("\n");return o.length>=r.length?o.map((e,t)=>{const n=r[t];return n?e.replace(new RegExp("^\\s*"+n+"\\s+"),""):e}).join("\n").trimEnd():n.trimEnd()}function sourceLinesForRows(e,t){const n=e.content.split(/\r?\n/);return t.map(e=>n[Number(e.dataset.lineIndex||0)]||"").join("\n").trimEnd()}function handleSourceClick(e){const t=e.target,n=t?.closest?.(".http-run");if(n)return e.preventDefault(),void runHttpRequest(Number(n.dataset.req));const r=t?.closest?.(".http-resp-toggle");if(r){e.preventDefault();const t=r.closest(".http-response")?.querySelector(".http-resp-headers");return void(t&&t.classList.toggle("hidden"))}const o=t?.closest?.(".source-row");if(!o)return;clearTreeFocus();const i=document.getElementById("source-viewer"),a=i?.dataset.openPath||"",s=sourceByPath.get(a);if(!s||!s.embedded)return;const c=Number(o.dataset.lineIndex||0),l=s.content.split(/\r?\n/)[c]||"";setSourceCursor(a,c,estimateColumnFromClick(o.querySelector(".source-code"),e,l),!1,-1)}function estimateColumnFromClick(e,t,n){if(!e)return 0;const r=e.getBoundingClientRect(),o=getComputedStyle(e),i=Number.parseFloat(o.paddingLeft||"0")||0,a=t.clientX-r.left-i,s=measuredCharWidth||measureCharWidth(e),c=Math.round(a/Math.max(s,1));return Math.max(0,Math.min(n.length,c))}function measureCharWidth(e){const t=document.createElement("span");t.textContent="mmmmmmmmmm",t.style.position="absolute",t.style.visibility="hidden",t.style.whiteSpace="pre",t.style.font=getComputedStyle(e).font,document.body.appendChild(t);const n=t.getBoundingClientRect().width/10;return t.remove(),measuredCharWidth=n||7,measuredCharWidth}var caretBusyTimer=null;function markCaretBusy(){document.body.classList.add("caret-busy"),caretBusyTimer&&clearTimeout(caretBusyTimer),caretBusyTimer=setTimeout(function(){document.body.classList.remove("caret-busy")},650)}function setSourceCursor(e,t,n,r=!1,o=-1){markCaretBusy(),selectedCommentRow=null;const i=sourceByPath.get(e);if(!i||!i.embedded)return;const a=i.content.split(/\r?\n/),s=Math.max(0,Math.min(t,Math.max(a.length-1,0))),c=Math.max(0,Math.min(n,(a[s]||"").length)),l=viewerCursor,u=document.getElementById("source-viewer"),d=Boolean(u&&u.dataset.openPath===e&&!u.classList.contains("hidden")&&l&&l.path===e&&!isHttpFile(e)&&sourceBodyPath===e);if(viewerCursor={path:e,lineIndex:s,column:c,targetLine:o},d)r?scheduleSourceReveal(l):updateSourceCaret(l,a,i.language||"text");else{openSourceFile(e,!u||u.dataset.openPath!==e||u.classList.contains("hidden")),r&&scheduleScrollIntoView(document.querySelector(".source-row.cursor-line"))}recordNav(navEntryOf("source"))}var sourceRevealRaf=0,sourceRevealPrev=null,_srcRowH=0;function sourceRowHeight(){if(_srcRowH>0)return _srcRowH;var e=document.querySelector("#source-body .source-row");if(e){var t=e.offsetHeight;t>0&&(_srcRowH=t)}return _srcRowH}function scheduleSourceReveal(e){sourceRevealRaf||(sourceRevealPrev=e),sourceRevealRaf||(sourceRevealRaf=requestAnimationFrame(function(){sourceRevealRaf=0;var e=sourceRevealPrev;sourceRevealPrev=null;var t=sourceByPath.get(viewerCursor.path);if(t&&t.embedded){updateSourceCaret(e,t.content.split(/\r?\n/),t.language||"text");var n=document.getElementById("source-body"),r=sourceRowHeight();if(r>0&&n&&!n.classList.contains("rendered-body")){var o=viewerCursor.lineIndex*r,i=n.clientHeight,a=Math.round(.15*i),s=n.scrollTop;o<s+a?n.scrollTop=Math.max(0,o-a):o+r>s+i-a&&(n.scrollTop=o+r-i+a)}else revealAt(document.querySelector(".source-row.cursor-line"),n,.85)}}))}function updateSourceCaret(e,t,n){const r=document.getElementById("source-body");if(!r)return;const o=r.classList.contains("rendered-body"),i=e=>r.querySelector('.source-row[data-line-index="'+e+'"]');if(e&&e.lineIndex!==viewerCursor.lineIndex){const t=i(e.lineIndex);t&&t.classList.remove("cursor-line")}o||r.querySelectorAll(".code-cursor").forEach(e=>{const t=e.parentNode;t&&(t.removeChild(e),t.normalize&&t.normalize())}),r.querySelectorAll(".source-row.symbol-target").forEach(e=>e.classList.remove("symbol-target")),viewerCursor.targetLine>=0&&i(viewerCursor.targetLine)?.classList.add("symbol-target");const a=i(viewerCursor.lineIndex);a?(a.classList.add("cursor-line"),o||insertSourceCaret(a,viewerCursor.column)):o||openSourceFile(viewerCursor.path,!1)}function insertSourceCaret(e,t){var n=e.querySelector(".source-code");if(n){var r=diffCaretDomPosition(n,t);if(r){var o=document.createElement("span");o.className="code-cursor",o.setAttribute("aria-hidden","true");try{var i=3===r.node.nodeType?Math.min(r.offset,(r.node.textContent||"").length):r.offset,a=document.createRange();a.setStart(r.node,i),a.collapse(!0),a.insertNode(o)}catch(e){}}}}function openSourceAt(e,t,n){setSourceCursor(e,t,n,!0,t)}function isSourceViewerVisible(){const e=document.getElementById("source-viewer");return Boolean(e&&!e.classList.contains("hidden"))}function selectAllInView(){var e=null;if(isSourceViewerVisible()?e=document.getElementById("source-body"):"function"==typeof isDiffViewVisible&&isDiffViewVisible()&&(e=document.querySelector("#diff2html-container .d2h-file-wrapper:not(.df-inactive)")||document.getElementById("diff2html-container")),!e)return!1;try{var t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}catch(e){return!1}return!0}function openDiffFileAtCaret(){if(diffCursor&&isDiffViewVisible()){const e=diffWrapperByPath(diffCursor.path),t=e?diffRowAt(e,diffCursor.side,diffCursor.rowIndex):null,n=t?diffLineNumber(t):null;return sourceByPath.has(diffCursor.path)?void setSourceCursor(diffCursor.path,null!=n?n-1:0,0,!0,-1):void openSourceFile(diffCursor.path)}const e=window.getSelection(),t=e&&e.anchorNode,n=t?1===t.nodeType?t:t.parentElement:null,r=n&&n.closest&&n.closest(".d2h-file-wrapper")||document.querySelector(".d2h-file-wrapper:not(.df-inactive)");if(!r)return;const o=(r.querySelector(".d2h-file-name")?.textContent||"").trim();if(!o)return;if(!sourceByPath.has(o))return void openSourceFile(o);let i=0;const a=n&&n.closest&&n.closest(".d2h-code-side-line");if(a){const e=a.closest("tr"),t=e&&e.querySelector(".d2h-code-side-linenumber"),n=t?parseInt((t.textContent||"").trim(),10):NaN;Number.isFinite(n)&&(i=Math.max(0,n-1))}setSourceCursor(o,i,0,!0,-1)}function commentRowSiblingOf(e,t){var n=document.querySelector('#source-body .source-row[data-line-index="'+e+'"]');if(!n)return null;var r=t<0?n.previousElementSibling:n.nextElementSibling;return r&&r.classList&&r.classList.contains("mc-comment-row")?r:null}function selectCommentRow(e){selectedCommentRow&&selectedCommentRow!==e&&selectedCommentRow.classList.remove("mc-row-selected"),selectedCommentRow=e||null,selectedCommentRow&&selectedCommentRow.classList.add("mc-row-selected")}function deleteCommentsInRow(e){if(e){var t=Array.prototype.slice.call(e.querySelectorAll(".mc-del")).map(function(e){return parseInt(e.dataset.seq,10)});selectedCommentRow=null,t.length&&(reviewComments=reviewComments.filter(function(e){return t.indexOf(e.seq)<0}),saveComments()),refreshComments()}}function editCommentInRow(e){if(e){var t=e.querySelector(".mc-del");if(t){var n=parseInt(t.dataset.seq,10),r=reviewComments.find(function(e){return e.seq===n});r&&(e.classList.remove("mc-row-selected"),selectedCommentRow=null,composerState={kind:r.kind,path:r.path,line:r.line,code:r.code,editSeq:n,editText:r.text},refreshComments())}}}function handleSourceCaretKey(e){if(!viewerCursor)return!1;var t=document.activeElement;if(t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName||"SELECT"===t.tagName))return!1;const n=e.shiftKey;if(selectedCommentRow){if("Backspace"===e.key||"Delete"===e.key)return e.preventDefault(),deleteCommentsInRow(selectedCommentRow),!0;if("e"===e.key||"E"===e.key)return e.preventDefault(),editCommentInRow(selectedCommentRow),!0;if("ArrowUp"===e.key||"ArrowDown"===e.key||"ArrowLeft"===e.key||"ArrowRight"===e.key||"Escape"===e.key){var r="ArrowUp"===e.key?-1:"ArrowDown"===e.key?1:0,o=r<0?selectedCommentRow.previousElementSibling:r>0?selectedCommentRow.nextElementSibling:null;if(selectedCommentRow.classList.remove("mc-row-selected"),selectedCommentRow=null,e.preventDefault(),o&&o.classList&&o.classList.contains("source-row")){var i=parseInt(o.dataset.lineIndex,10);if(isFinite(i))return setSourceCursor(viewerCursor.path,i,0,!0,-1),!0}return setSourceCursor(viewerCursor.path,viewerCursor.lineIndex,viewerCursor.column,!1,-1),!0}return!1}if(!n&&("ArrowUp"===e.key||"ArrowDown"===e.key)){var a=commentRowSiblingOf(viewerCursor.lineIndex,"ArrowUp"===e.key?-1:1);if(a)return e.preventDefault(),selectCommentRow(a),!0}return"ArrowDown"===e.key?(e.preventDefault(),moveSourceCursor(1,0,n),!0):"ArrowUp"===e.key?(e.preventDefault(),moveSourceCursor(-1,0,n),!0):"ArrowLeft"===e.key?(e.preventDefault(),moveSourceCursor(0,-1,n),!0):"ArrowRight"===e.key&&(e.preventDefault(),moveSourceCursor(0,1,n),!0)}function moveSourceCursor(e,t,n){if(!viewerCursor)return;const r=sourceByPath.get(viewerCursor.path);if(!r||!r.embedded)return;const o=document.getElementById("source-body");if(o&&o.classList.contains("rendered-body")){const n=Array.from(o.querySelectorAll(".source-row"));if(!n.length)return;let r=n.indexOf(o.querySelector('.source-row[data-line-index="'+viewerCursor.lineIndex+'"]'));r<0&&(r=0);const i=(e||0)+(t>0?1:t<0?-1:0),a=Math.max(0,Math.min(n.length-1,r+(i||0)));return selectionAnchor=null,void setSourceCursor(viewerCursor.path,Number(n[a].dataset.lineIndex)||0,0,!0,-1)}const i=r.content.split(/\r?\n/);let a=viewerCursor.lineIndex,s=viewerCursor.column;t<0?s>0?s-=1:a>0&&(a-=1,s=(i[a]||"").length):t>0&&(s<(i[a]||"").length?s+=1:a<i.length-1&&(a+=1,s=0)),0!==e&&(a=Math.max(0,Math.min(i.length-1,a+e)),s=Math.min(s,(i[a]||"").length)),n?selectionAnchor||(selectionAnchor={lineIndex:viewerCursor.lineIndex,column:viewerCursor.column}):selectionAnchor=null,setSourceCursor(viewerCursor.path,a,s,!0,-1),applySourceSelection()}function nextWordBoundary(e,t,n){var r=function(e){return""===e||/\s/.test(e)?0:/[A-Za-z0-9_$]/.test(e)?1:2},o=t;if(n>0){var i=r(e.charAt(o));if(0!==i)for(;o<e.length&&r(e.charAt(o))===i;)o++;for(;o<e.length&&0===r(e.charAt(o));)o++}else{for(o--;o>0&&0===r(e.charAt(o));)o--;for(var a=r(e.charAt(o));o>0&&r(e.charAt(o-1))===a;)o--;o<0&&(o=0)}return o}function moveSourceWord(e,t){if(viewerCursor){var n=sourceByPath.get(viewerCursor.path);if(n&&n.embedded){var r=n.content.split(/\r?\n/),o=viewerCursor.lineIndex,i=viewerCursor.column,a=r[o]||"";if(e>0){var s=nextWordBoundary(a,i,1);if(s<a.length||o>=r.length-1)i=s;else{var c=(r[o+=1]||"").search(/\S/);i=c<0?0:c}}else{var l=nextWordBoundary(a,i,-1);if(l<i&&/\S/.test(a.charAt(l)))i=l;else if(o>0){var u=r[o-=1]||"";i=u.length>0?nextWordBoundary(u,u.length,-1):0}else i=l}t?selectionAnchor||(selectionAnchor={lineIndex:viewerCursor.lineIndex,column:viewerCursor.column}):selectionAnchor=null,setSourceCursor(viewerCursor.path,o,i,!0,-1),applySourceSelection()}}}function applySourceSelection(){const e=window.getSelection();if(!e)return;if(!selectionAnchor||!viewerCursor)return void e.removeAllRanges();const t=caretDomPosition(selectionAnchor.lineIndex,selectionAnchor.column),n=caretDomPosition(viewerCursor.lineIndex,viewerCursor.column);if(t&&n)try{e.setBaseAndExtent(t.node,t.offset,n.node,n.offset)}catch(e){}}function caretDomPosition(e,t){const n=document.querySelector('.source-row[data-line-index="'+e+'"] .source-code');if(!n)return null;let r=t;const o=document.createTreeWalker(n,NodeFilter.SHOW_TEXT);let i;for(;i=o.nextNode();){const e=i.textContent.length;if(r<=e)return{node:i,offset:r};r-=e}return{node:n,offset:n.childNodes.length}}function wordAtCursor(){if(!viewerCursor)return null;const e=sourceByPath.get(viewerCursor.path);if(!e||!e.embedded)return null;const t=e.content.split(/\r?\n/)[viewerCursor.lineIndex]||"",n=Math.max(0,Math.min(viewerCursor.column,t.length)),r=/[A-Za-z_$][A-Za-z0-9_$]*/g;let o=null;for(;o=r.exec(t);){const e=o.index,t=e+o[0].length;if(n>=e&&n<=t)return{name:o[0],path:viewerCursor.path,lineIndex:viewerCursor.lineIndex,column:e}}return null}function goToSymbolUnderCursor(){const e=wordAtCursor();e&&goToDefOrUsages(e.name)}function goToDefOrUsages(e){if(e){if(REVIEW_LAZY_LOAD&&!sourceLoaded)return pendingSymbol=e,void loadSourceData();var t=findSymbolDefinition(e),n=caretSourceLoc();t&&n&&t.path===n.path&&t.lineIndex===n.lineIndex?openUsages(e,t):t&&openSourceAt(t.path,t.lineIndex,t.column)}}function caretSourceLoc(){if(isSourceViewerVisible()&&viewerCursor)return{path:viewerCursor.path,lineIndex:viewerCursor.lineIndex};if(isDiffViewVisible()&&diffCursor&&"new"===diffCursor.side){var e=diffWrapperByPath(diffCursor.path),t=e?diffRowAt(e,diffCursor.side,diffCursor.rowIndex):null,n=t?diffLineNumber(t):null;if(null!=n)return{path:diffCursor.path,lineIndex:n-1}}return null}function findUsages(e,t,n){var r;try{r=new RegExp("(^|[^A-Za-z0-9_$])"+escapeRegExp(e)+"(?![A-Za-z0-9_$])")}catch(e){return[]}for(var o=[],i=0;i<sourceFiles.length;i++){var a=sourceFiles[i];if(a.embedded)for(var s=String(a.content).split(/\r?\n/),c=0;c<s.length;c++)if(a.path!==t||c!==n){var l=r.exec(s[c]);if(l&&(o.push({path:a.path,lineIndex:c,column:l.index+(l[1]?l[1].length:0),text:s[c]}),o.length>=500))return o}}return o}function openUsages(e,t){var n=findUsages(e,t.path,t.lineIndex);1!==n.length?(usageItems=n,usageActive=0,showUsages(e,n.length)):openSourceAt(n[0].path,n[0].lineIndex,n[0].column)}function showUsages(e,t){var n=document.getElementById("usages"),r=document.getElementById("usages-title");n&&(r&&(r.textContent=t+" usage"+(1===t?"":"s")+" of "+e),renderUsages(),n.classList.remove("hidden"),positionUsagesAtCaret())}function positionUsagesAtCaret(){var e=document.getElementById("usages");if(e){var t=e.querySelector(".quick-open-panel");if(t){resetUsagesAnchor(e,t);var n=document.querySelector("#source-body .code-cursor")||document.querySelector("#diff2html-container .code-cursor");if(n){var r=n.getBoundingClientRect();if(r.height||r.width||r.top){var o=window.innerWidth,i=window.innerHeight,a=Math.min(560,o-16),s=Math.min(Math.max(8,r.left),o-a-8);e.classList.add("anchored"),t.style.width=a+"px",t.style.left=s+"px";var c=i-r.bottom-6-8,l=r.top-6-8;c>=200||c>=l?(t.style.top=r.bottom+6+"px",t.style.maxHeight=Math.max(120,c)+"px"):(t.style.bottom=i-r.top+6+"px",t.style.maxHeight=Math.max(120,l)+"px")}}}}}function resetUsagesAnchor(e,t){e.classList.remove("anchored"),t.style.left=t.style.top=t.style.bottom=t.style.width=t.style.maxHeight=""}function renderUsages(){var e=document.getElementById("usages-results");e&&(usageItems.length?(e.innerHTML=usageItems.map(function(e,t){var n=e.path.split("/").pop();return'<button type="button" class="quick-open-item usage-item'+(t===usageActive?" active":"")+'" data-index="'+t+'"><span class="usage-loc">'+escapeHtml(n)+":"+(e.lineIndex+1)+'</span><span class="usage-code">'+escapeHtml(e.text.replace(/^\s+/,"").slice(0,160))+"</span></button>"}).join(""),updateUsageActive()):e.innerHTML='<div class="quick-open-empty">No usages found.</div>')}function updateUsageActive(){var e=document.getElementById("usages-results");if(e)for(var t=e.querySelectorAll(".usage-item"),n=0;n<t.length;n++){var r=n===usageActive;t[n].classList.toggle("active",r),r&&t[n].scrollIntoView&&t[n].scrollIntoView({block:"nearest"})}}function handleUsagesKey(e){return"Escape"===e.key?(e.preventDefault(),closeUsages(),!0):"ArrowDown"===e.key?(e.preventDefault(),usageActive=Math.min(usageActive+1,usageItems.length-1),updateUsageActive(),!0):"ArrowUp"===e.key?(e.preventDefault(),usageActive=Math.max(usageActive-1,0),updateUsageActive(),!0):"Enter"===e.key&&(e.preventDefault(),openUsageItem(usageItems[usageActive]),!0)}function openUsageItem(e){e&&(closeUsages(),openSourceAt(e.path,e.lineIndex,e.column))}function closeUsages(){var e=document.getElementById("usages");if(e){e.classList.add("hidden");var t=e.querySelector(".quick-open-panel");t&&resetUsagesAnchor(e,t)}}"undefined"!=typeof window&&window.addEventListener("resize",function(){_srcRowH=0});var symbolIndex=null;function symbolIndexWorker(){self.onmessage=function(e){for(var t=e.data||[],n=[/^\s*(?:export\s+)?(?:default\s+)?(?:async\s+)?function\s+([A-Za-z_$][A-Za-z0-9_$]*)/,/^\s*(?:(?:public|private|protected|internal|abstract|final|open|sealed|data|inner|annotation|static|export|default|expect|actual|value)\s+)*(?:class|interface|object|enum|trait|struct)\s+([A-Za-z_$][A-Za-z0-9_$]*)/,/^\s*(?:export\s+)?(?:interface|type|enum)\s+([A-Za-z_$][A-Za-z0-9_$]*)/,/^\s*(?:export\s+)?(?:const|let|var|val)\s+([A-Za-z_$][A-Za-z0-9_$]*)/,/^\s*(?:(?:public|private|protected|internal|abstract|final|open|override|suspend|inline|operator|static|async)\s+)*(?:fun|def|fn|func)\s+([A-Za-z_$][A-Za-z0-9_$]*)/],r=new Map,o=t.length,i=Math.max(1,Math.floor(o/20)),a=0;a<o;a++){for(var s=t[a].path,c=String(t[a].content||"").split(/\r?\n/),l=0;l<c.length;l++)for(var u=c[l],d=0;d<n.length;d++){var f=n[d].exec(u);if(f&&f[1]){var m=r.get(f[1]);m||(m=[],r.set(f[1],m)),m.push({path:s,lineIndex:l,column:Math.max(0,u.indexOf(f[1]))});break}}(a+1)%i===0&&a+1<o&&self.postMessage({done:a+1,total:o})}self.postMessage({index:r,total:o})}}function scheduleSymbolIndex(){var e=function(){try{startSymbolIndex()}catch(e){}};"undefined"!=typeof window&&"function"==typeof window.requestIdleCallback?window.requestIdleCallback(e,{timeout:3e3}):setTimeout(e,0)}function startSymbolIndex(){try{if("undefined"==typeof Worker||"undefined"==typeof Blob||"undefined"==typeof URL||!URL.createObjectURL)return;var e="("+symbolIndexWorker.toString()+")()",t=URL.createObjectURL(new Blob([e],{type:"application/javascript"})),n=new Worker(t);n.onmessage=function(e){var r=e.data;if(r&&r.index){symbolIndex=r.index,setIndexProgress(r.total,r.total);try{n.terminate()}catch(e){}try{URL.revokeObjectURL(t)}catch(e){}}else r&&"number"==typeof r.done&&setIndexProgress(r.done,r.total)},n.onerror=function(){setIndexProgress(1,1);try{n.terminate()}catch(e){}};for(var r=[],o=0;o<sourceFiles.length;o++)sourceFiles[o].embedded&&r.push({path:sourceFiles[o].path,content:sourceFiles[o].content});setIndexProgress(0,r.length),n.postMessage(r)}catch(e){}}function setIndexProgress(e,n){var r=document.getElementById("index-status"),o=document.getElementById("index-progress"),i=document.getElementById("footer-progress"),a=Boolean(n)&&e<n,s=a?Math.round(e/n*100)+"%":"0%";r&&(r.textContent=a?t("status.indexing")+" "+e+"/"+n+"…":(n||0)+" "+t("status.indexed")),o&&(o.classList.toggle("hidden",!a),a&&o.firstElementChild&&(o.firstElementChild.style.width=s)),i&&(i.classList.toggle("hidden",!a),i.firstElementChild&&(i.firstElementChild.style.width=s))}function wordAtDiffCaret(){if(!diffCursor)return null;var e=diffWrapperByPath(diffCursor.path);if(!e)return null;for(var t=diffLineText(diffRowAt(e,diffCursor.side,diffCursor.rowIndex)),n=Math.max(0,Math.min(diffCursor.column,t.length)),r=/[A-Za-z_$][A-Za-z0-9_$]*/g,o=null;o=r.exec(t);)if(n>=o.index&&n<=o.index+o[0].length)return o[0];return null}function goToSymbolFromDiff(){goToDefOrUsages(wordAtDiffCaret())}function findSymbolDefinition(e){if(symbolIndex){var t=symbolIndex.get(e);if(t&&t.length){for(var n=viewerCursor&&viewerCursor.path||diffCursor&&diffCursor.path||"",r=0;r<t.length;r++)if(t[r].path===n)return t[r];return t[0]}}const o=definitionMatchers(e),i=viewerCursor?.path||"",a=[...sourceFiles.filter(e=>e.path===i),...sourceFiles.filter(e=>e.path!==i)].filter(e=>e.embedded);for(const t of a){const n=t.content.split(/\r?\n/);for(let r=0;r<n.length;r+=1){const i=n[r];if(o.some(e=>e.test(i)))return{path:t.path,lineIndex:r,column:Math.max(0,i.indexOf(e))}}}return null}function definitionMatchers(e){const t=escapeRegExp(e),n="(?:(?:public|private|protected|internal|abstract|final|open|override|suspend|inline|operator|static|async)\\s+)*";return[new RegExp("^\\s*(?:export\\s+)?(?:default\\s+)?(?:async\\s+)?function\\s+"+t+"\\b"),new RegExp("^\\s*(?:(?:public|private|protected|internal|abstract|final|open|sealed|data|inner|enum|annotation|static|export|default|expect|actual|value)\\s+)*(?:class|interface|object|enum|trait|struct)\\s+"+t+"\\b"),new RegExp("^\\s*(?:export\\s+)?(?:interface|type|enum)\\s+"+t+"\\b"),new RegExp("^\\s*(?:export\\s+)?(?:const|let|var|val)\\s+"+t+"\\b"),new RegExp("^\\s*"+n+"(?:fun|def|fn|func)\\s+"+t+"\\b"),new RegExp("^\\s*"+n+t+"\\s*\\([^)]*\\)\\s*(?::\\s*[^=]+)?\\s*(?:\\{|=>)"),new RegExp("^\\s*"+t+"\\s*[:=]\\s*(?:async\\s*)?(?:function\\b|\\([^)]*\\)\\s*=>)")]}function escapeRegExp(e){return String(e).replace(/[|\\{}()[\]^$+*?.]/g,"\\$&")}function setSourceTypeIcon(e){var t=document.getElementById("source-type-icon");if(t){var n=sourceLinks.find(function(t){return t.dataset.sourceFile===e}),r=n?n.querySelector(".ftype"):null;t.innerHTML=r?r.outerHTML:""}}function addSourceTab(e){e&&sourceTabs.indexOf(e)<0&&sourceTabs.push(e)}function sourceTabLabel(e){var t=String(e||""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function currentSourceTabPath(){var e=document.getElementById("source-viewer");return e&&e.dataset.openPath||""}function renderSourceTabs(e){var t=document.getElementById("source-tabs");if(t){if(!sourceTabs.length)return t.classList.add("hidden"),void(t.innerHTML="");t.classList.remove("hidden"),t.innerHTML=sourceTabs.map(function(t){return'<div class="source-tab'+(t===e?" active":"")+'" data-tab-path="'+escapeHtml(t)+'" title="'+escapeHtml(t)+'"><span class="source-tab-name">'+escapeHtml(sourceTabLabel(t))+'</span><button type="button" class="source-tab-close" data-close-path="'+escapeHtml(t)+'" aria-label="Close tab" title="Close (⌘W)">×</button></div>'}).join("");var n=t.querySelector(".source-tab.active");if(n){var r=t.getBoundingClientRect(),o=n.getBoundingClientRect();o.left<r.left?t.scrollLeft-=r.left-o.left+8:o.right>r.right&&(t.scrollLeft+=o.right-r.right+8)}}}function closeSourceTab(e){var n=sourceTabs.indexOf(e);if(!(n<0)){var r=e===currentSourceTabPath();if(sourceTabs.splice(n,1),r){var o=sourceTabs[n]||sourceTabs[n-1]||"";if(o)openSourceFile(o);else{var i=document.getElementById("source-viewer");i&&(i.dataset.openPath="");var a=document.getElementById("source-body");a&&(a.className="source-body empty",a.textContent=t("source.selectFile")),sourceLinks.forEach(function(e){e.classList.remove("active")}),renderSourceTabs("")}}else renderSourceTabs(currentSourceTabPath())}}function closeActiveSourceTab(){var e=currentSourceTabPath();return!!e&&(closeSourceTab(e),!0)}function cycleSourceTab(e){if(!(sourceTabs.length<2)){var t=sourceTabs.indexOf(currentSourceTabPath());t<0&&(t=0),openSourceFile(sourceTabs[(t+e+sourceTabs.length)%sourceTabs.length])}}function openSourceFile(e,n=!0){const r=sourceByPath.get(e);if(!r)return;if(composerState&&composerState.path!==e&&closeComposer(),addSourceTab(e),renderSourceTabs(e),REVIEW_LAZY_LOAD&&!sourceLoaded&&r.embedded){pendingSourceOpen={path:e,shouldSwitch:n},loadSourceData(),sourceBodyPath=null,document.getElementById("source-viewer").dataset.openPath=e,sourceLinks.forEach(t=>t.classList.toggle("active",t.dataset.sourceFile===e)),renderBreadcrumb(document.getElementById("source-title"),e),setSourceTypeIcon(e),revealTreeFor(e);var o=document.getElementById("source-body");return o.className="source-body empty",o.textContent=t("source.loading"),void(n&&showSourceView())}rememberRecent(e,"source"),sourceBodyPath=e,document.getElementById("source-viewer").dataset.openPath=e,sourceLinks.forEach(t=>t.classList.toggle("active",t.dataset.sourceFile===e)),renderBreadcrumb(document.getElementById("source-title"),e),setSourceTypeIcon(e),revealTreeFor(e);const i=r.embedded?formatBytes(r.size||0):formatBytes(r.size||0)+" · "+(r.skippedReason||"not embedded");document.getElementById("source-meta").textContent=i;const a=document.getElementById("source-body");if(r.image)return a.className="source-body image-body",a.innerHTML=renderImageView(r),document.getElementById("http-env-select")?.classList.add("hidden"),updateRenderToggle(e),void(n&&showSourceView());if(!r.embedded)return a.className="source-body empty",a.textContent=r.skippedReason?t("source.previewUnavailable").replace(/\.$/,"")+": "+r.skippedReason+".":t("source.previewUnavailable"),document.getElementById("http-env-select")?.classList.add("hidden"),updateRenderToggle(e),void(n&&showSourceView());viewerCursor&&viewerCursor.path===e||(viewerCursor={path:e,lineIndex:0,column:0,targetLine:-1}),a.className="source-body";const s=document.getElementById("http-env-select");if(isMarkdownPath(e))return renderRawMode?a.innerHTML=renderSourceTable(r,""):(a.classList.add("rendered-body"),a.innerHTML=renderMarkdownRows(r.content)),s&&s.classList.add("hidden"),updateRenderToggle(e),renderSourceComments(),void(n&&showSourceView());if(isCsvPath(e))return renderRawMode?a.innerHTML=renderSourceTable(r,""):(a.classList.add("rendered-body"),a.innerHTML=renderCsvRows(r.content,e)),s&&s.classList.add("hidden"),updateRenderToggle(e),renderSourceComments(),void(n&&showSourceView());if(isHttpFile(e))a.innerHTML=renderHttpTable(r),s&&s.classList.toggle("hidden",0===httpEnvNames.length);else if(a.innerHTML=renderSourceTable(r,""),s&&s.classList.add("hidden"),viewerCursor&&viewerCursor.path===e){var c=a.querySelector(".source-row.cursor-line");c&&insertSourceCaret(c,viewerCursor.column)}updateRenderToggle(e),renderSourceComments(),n&&showSourceView()}function isMarkdownPath(e){return/\.(md|mdx|markdown)$/i.test(e||"")}function isCsvPath(e){return/\.(csv|tsv)$/i.test(e||"")}function isRenderToggleable(e){return isMarkdownPath(e)||isCsvPath(e)}var renderRawMode=!1;function updateRenderToggle(e){var n=document.getElementById("render-toggle");if(n){var r=isRenderToggleable(e);n.classList.toggle("hidden",!r),r&&(n.textContent=t(renderRawMode?"source.viewRendered":"source.viewRaw"),n.setAttribute("aria-pressed",renderRawMode?"true":"false"))}}function toggleRenderMode(){var e=document.getElementById("source-viewer"),t=e&&e.dataset.openPath;t&&isRenderToggleable(t)&&(renderRawMode=!renderRawMode,openSourceFile(t,!1))}function renderImageView(e){return'<div class="image-view"><img class="image-preview" src="'+e.image+'" alt="'+escapeHtml(e.name)+'" data-zoomable="1"><div class="image-cap">'+escapeHtml(e.name)+" &middot; "+formatBytes(e.size||0)+" &middot; click to zoom</div></div>"}function openLightbox(e,t){if(e){var n=document.getElementById("mc-lightbox");n||((n=document.createElement("div")).id="mc-lightbox",n.className="mc-lightbox hidden",n.innerHTML='<img class="mc-lightbox-img" alt="">',document.body.appendChild(n),n.addEventListener("click",closeLightbox));var r=n.querySelector("img");r.src=e,r.alt=t||"",n.classList.remove("hidden")}}function closeLightbox(){var e=document.getElementById("mc-lightbox");e&&e.classList.add("hidden")}function lightboxOpen(){var e=document.getElementById("mc-lightbox");return!(!e||e.classList.contains("hidden"))}function renderInlineMd(e){var t=escapeHtml(e);return t=(t=(t=(t=(t=(t=t.replace(/`([^`]+)`/g,function(e,t){return"<code>"+t+"</code>"})).replace(/!\[([^\]]*)\]\(([^)\s]+)[^)]*\)/g,function(e,t,n){return/^(https?:|data:)/i.test(n)?'<img class="md-img" src="'+n+'" alt="'+t+'">':e})).replace(/\[([^\]]+)\]\(([^)\s]+)[^)]*\)/g,function(e,t,n){return/^(https?:|mailto:|#)/i.test(n)?'<a href="'+n+'" target="_blank" rel="noopener noreferrer">'+t+"</a>":t})).replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>").replace(/__([^_]+)__/g,"<strong>$1</strong>")).replace(/(^|[^*])\*([^*\s][^*]*)\*/g,"$1<em>$2</em>").replace(/(^|[^_\w])_([^_\s][^_]*)_/g,"$1<em>$2</em>")).replace(/~~([^~]+)~~/g,"<del>$1</del>")}function sanitizeHtml(e){var t=document.createElement("template");t.innerHTML=String(e);var n={SCRIPT:1,STYLE:1,IFRAME:1,OBJECT:1,EMBED:1,LINK:1,META:1,BASE:1,FORM:1,INPUT:1,BUTTON:1,TEXTAREA:1,SELECT:1,NOSCRIPT:1},r=function(e){for(var t=Array.prototype.slice.call(e.children||[]),o=0;o<t.length;o++){var i=t[o];if(n[i.tagName])i.parentNode.removeChild(i);else{for(var a=Array.prototype.slice.call(i.attributes),s=0;s<a.length;s++){var c=a[s].name.toLowerCase();0!==c.indexOf("on")?"href"!==c&&"src"!==c&&"xlink:href"!==c&&"srcset"!==c||!/^\s*(javascript|vbscript|data:text\/html):/i.test(a[s].value||"")||i.removeAttribute(a[s].name):i.removeAttribute(a[s].name)}r(i)}}};return r(t.content),t.innerHTML}function mdFenceLang(e){var t=(e||"").toLowerCase();return"js"===t||"jsx"===t||"ts"===t||"tsx"===t?"typescript":"sh"===t||"bash"===t||"zsh"===t?"shell":"yml"===t?"yaml":t||"text"}function splitTableRow(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(function(e){return e.trim()})}function renderMarkdownBlocks(e){for(var t,n=String(e).split(/\r?\n/),r=[],o=0;o<n.length;){var i=o,a=n[o],s=a.match(/^(\s*)(```+|~~~+)\s*([\w+#-]*)\s*$/);if(s){var c=s[2].charAt(0),l=new RegExp("^\\s*"+("`"===c?"`":"~")+"{3,}\\s*$"),u=mdFenceLang(s[3]),d=[];for(o++;o<n.length&&!l.test(n[o]);)d.push(n[o]),o++;o++,r.push({line:i,html:'<pre class="md-code"><code>'+d.map(function(e){return highlightLine(e,u)}).join("\n")+"</code></pre>"})}else if(/^\s*$/.test(a))o++;else if(/^\s*<(\/?[a-zA-Z][\w-]*|!--)/.test(a)){var f=[a];for(o++;o<n.length&&!/^\s*$/.test(n[o]);)f.push(n[o]),o++;r.push({line:i,html:'<div class="md-html">'+sanitizeHtml(f.join("\n"))+"</div>"})}else{var m=a.match(/^\s{0,3}(#{1,6})\s+(.*)$/);if(m){var p=m[1].length;r.push({line:i,html:"<h"+p+' class="md-h md-h'+p+'">'+renderInlineMd(m[2].replace(/\s+#+\s*$/,""))+"</h"+p+">"}),o++}else if(/^\s*([-*_])\s*(\1\s*){2,}$/.test(a))r.push({line:i,html:'<hr class="md-hr">'}),o++;else if(/^\s*>\s?/.test(a)){for(var h=[];o<n.length&&/^\s*>\s?/.test(n[o]);)h.push(n[o].replace(/^\s*>\s?/,"")),o++;r.push({line:i,html:'<blockquote class="md-quote">'+h.map(function(e){return e.trim()?"<p>"+renderInlineMd(e)+"</p>":""}).join("")+"</blockquote>"})}else if(/\|/.test(a)&&o+1<n.length&&/^\s*\|?[\s:|-]*-[\s:|-]*\|?\s*$/.test(n[o+1])){var v=splitTableRow(a);o+=2;for(var g="";o<n.length&&/\|/.test(n[o])&&!/^\s*$/.test(n[o]);){var y=splitTableRow(n[o]);g+="<tr>"+v.map(function(e,t){return"<td>"+renderInlineMd(y[t]||"")+"</td>"}).join("")+"</tr>",o++}r.push({line:i,html:'<table class="md-table"><thead><tr>'+v.map(function(e){return"<th>"+renderInlineMd(e)+"</th>"}).join("")+"</tr></thead><tbody>"+g+"</tbody></table>"})}else if(t=n[o].match(/^(\s*)([-*+]|\d+[.)])\s+(.*)$/)){for(var w=/\d/.test(t[2])?"ol":"ul",C="";o<n.length&&(t=n[o].match(/^(\s*)([-*+]|\d+[.)])\s+(.*)$/));)C+="<li>"+renderInlineMd(t[3])+"</li>",o++;r.push({line:i,html:"<"+w+' class="md-list">'+C+"</"+w+">"})}else{var b=[a];for(o++;o<n.length&&!/^\s*$/.test(n[o])&&!/^(\s{0,3}#{1,6}\s|\s*>|\s*([-*+]|\d+[.)])\s|\s*(```|~~~))/.test(n[o]);)b.push(n[o]),o++;r.push({line:i,html:'<p class="md-p">'+renderInlineMd(b.join("\n")).replace(/\n/g,"<br>")+"</p>"})}}}return r}function renderMarkdownRows(e){var t=renderMarkdownBlocks(e);return t.length?'<table class="source-table md-doc"><tbody>'+t.map(function(e){return'<tr class="source-row md-row" data-line-index="'+e.line+'"><td class="num">'+(e.line+1)+'</td><td class="source-code md-cell">'+e.html+"</td></tr>"}).join("")+"</tbody></table>":'<table class="source-table md-doc"><tbody></tbody></table>'}function parseDelimited(e,t){for(var n=[],r=[],o="",i=!1,a=String(e),s=0;s<a.length;s++){var c=a[s];i?'"'===c?'"'===a[s+1]?(o+='"',s++):i=!1:o+=c:'"'===c?i=!0:c===t?(r.push(o),o=""):"\n"===c?(r.push(o),n.push(r),r=[],o=""):"\r"!==c&&(o+=c)}return(o.length>0||r.length>0)&&(r.push(o),n.push(r)),n}function renderCsvRows(e,t){var n=parseDelimited(e,/\.tsv$/i.test(t||"")?"\t":",").filter(function(e){return!(1===e.length&&""===e[0])});if(!n.length)return'<table class="source-table csv-doc"><tbody></tbody></table>';var r=n.reduce(function(e,t){return Math.max(e,t.length)},0);return'<table class="source-table csv-doc"><tbody>'+n.map(function(e,t){for(var n=0===t,o="",i=0;i<r;i++){var a=escapeHtml(null==e[i]?"":e[i]);o+=n?'<th class="csv-cell">'+a+"</th>":'<td class="csv-cell">'+a+"</td>"}return'<tr class="source-row csv-row'+(n?" csv-head":"")+'" data-line-index="'+t+'"><td class="num">'+(t+1)+"</td>"+o+"</tr>"}).join("")+"</tbody></table>"}function isHttpFile(e){return/\.(http|rest)$/i.test(e||"")}function currentHttpEnv(){return httpEnvironments[currentHttpEnvName]||{}}function applyHttpVars(e,t){return String(null==e?"":e).replace(/\{\{\s*([\w.$-]+)\s*\}\}/g,function(e,n){return t&&Object.prototype.hasOwnProperty.call(t,n)?t[n]:e})}function parseHttpRequests(e){const t={GET:1,POST:1,PUT:1,PATCH:1,DELETE:1,HEAD:1,OPTIONS:1,TRACE:1,CONNECT:1},n=String(e).split(/\r?\n/),r=[],o={};let i=null,a="pre";function s(){i&&i.url&&(i.body=i.bodyLines.join("\n").replace(/\s+$/,""),r.push(i))}function c(e,t,n){return{name:t,method:"",url:"",headers:[],bodyLines:[],startLine:-1,endLine:n,boundaryLine:e}}for(let e=0;e<n.length;e++){const r=n[e],l=r.trim();if(0!==l.indexOf("###")){if(i||(i=c(-1,"",e),a="pre"),i.endLine=e,"pre"===a){if(""===l)continue;if(0===l.indexOf("#")||0===l.indexOf("//"))continue;const n=/^@([\w.$-]+)\s*=\s*(.*)$/.exec(l);if(n){o[n[1]]=n[2].trim();continue}const r=l.indexOf(" "),s=r>=0?l.slice(0,r):l;r>=0&&t[s.toUpperCase()]?(i.method=s.toUpperCase(),i.url=l.slice(r+1).replace(/\s+HTTP\/[\d.]+\s*$/i,"").trim()):(i.method="GET",i.url=l.replace(/\s+HTTP\/[\d.]+\s*$/i,"").trim()),i.startLine=e,a="headers";continue}if("headers"===a){if(""===l){a="body";continue}if(0===l.indexOf("#")||0===l.indexOf("//"))continue;const e=r.indexOf(":");e>0&&i.headers.push({name:r.slice(0,e).trim(),value:r.slice(e+1).trim()});continue}i.bodyLines.push(r)}else s(),i=c(e,l.replace(/^#+/,"").trim(),e),a="pre"}return s(),{requests:r,vars:o}}function renderHttpTable(e){const t=parseHttpRequests(e.content),n=t.requests;httpRequestsByPath.set(e.path,n),httpVarsByPath.set(e.path,t.vars);const r=Object.assign({},t.vars,currentHttpEnv()),o=String(e.content).split(/\r?\n/),i=viewerCursor&&viewerCursor.path===e.path?viewerCursor:null,a={},s={};n.forEach(function(e,t){e.startLine>=0&&(a[e.startLine]=t),s[e.endLine]=t});let c="";return o.forEach(function(e,t){const n=Object.prototype.hasOwnProperty.call(a,t),o=n?a[t]:-1,l=Boolean(i&&i.lineIndex===t);if(c+='<tr class="source-row http-row'+(n?" http-request-line":"")+(l?" cursor-line":"")+'" data-line-index="'+t+'"><td class="num http-gutter">'+(n?'<button type="button" class="http-run" data-req="'+o+'" title="Run request (⌘Enter / ⌥Enter)" aria-label="Run request">&#9654;</button>':"")+'<span class="num-text">'+(t+1)+'</span></td><td class="source-code">'+(l?renderHttpLineWithCursor(e,r,i.column):highlightHttpLine(e,r))+"</td></tr>",Object.prototype.hasOwnProperty.call(s,t)){const e=s[t];c+='<tr class="http-response-row"><td class="num"></td><td class="source-code"><div class="http-response hidden" id="http-resp-'+e+'"></div></td></tr>'}}),'<table class="source-table http-table"><tbody>'+c+"</tbody></table>"}function renderHttpLineWithCursor(e,t,n){var r=Math.max(0,Math.min(n,e.length));return highlightHttpLine(e.slice(0,r),t)+'<span class="code-cursor" aria-hidden="true"></span>'+highlightHttpLine(e.slice(r),t)}function highlightHttpLine(e,t){const n=e.trim();if(0===n.indexOf("###"))return'<span class="http-sep">'+escapeHtml(e)+"</span>";if(0===n.indexOf("#")||0===n.indexOf("//"))return'<span class="tok-comment">'+escapeHtml(e)+"</span>";let r=escapeHtml(e);return r=r.replace(/^(\s*)(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|TRACE|CONNECT)(\s)/,function(e,t,n,r){return t+'<span class="http-method">'+n+"</span>"+r}),r=r.replace(/\{\{\s*([\w.$-]+)\s*\}\}/g,function(e,n){const r=t&&Object.prototype.hasOwnProperty.call(t,n);return'<span class="http-var '+(r?"known":"unknown")+'" title="'+escapeHtml(r?String(t[n]):"Undefined variable")+'">'+escapeHtml(e)+"</span>"}),r}function sendHttp(e){return window.monacoriHttp&&"function"==typeof window.monacoriHttp.send?Promise.resolve(window.monacoriHttp.send(e)):fetch("/__http_send",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(function(e){return e.json()})}function runHttpRequest(e){const t=document.getElementById("source-viewer")?.dataset.openPath||"",n=httpRequestsByPath.get(t);if(!n||!n[e])return;const r=n[e],o=Object.assign({},httpVarsByPath.get(t)||{},currentHttpEnv()),i={};r.headers.forEach(function(e){const t=applyHttpVars(e.name,o);t&&(i[t]=applyHttpVars(e.value,o))});const a={method:r.method||"GET",url:applyHttpVars(r.url,o),headers:i,body:r.body?applyHttpVars(r.body,o):void 0},s=document.getElementById("http-resp-"+e);s&&(s.className="http-response loading",s.textContent=a.method+" "+a.url),sendHttp(a).then(function(e){s&&renderHttpResponse(s,e)}).catch(function(e){s&&(s.className="http-response error",s.innerHTML='<div class="http-resp-head"><span class="http-status bad">Failed</span></div><pre class="http-resp-body">'+escapeHtml(String(e&&e.message?e.message:e))+"</pre>")})}function runHttpAtCaret(){const e=document.getElementById("source-viewer")?.dataset.openPath||"",t=httpRequestsByPath.get(e);if(!t||!t.length)return;const n=viewerCursor&&viewerCursor.path===e?viewerCursor.lineIndex:0;let r=-1;for(let e=0;e<t.length;e++){const o=t[e],i=o.boundaryLine>=0?o.boundaryLine:o.startLine;if(i<=n&&n<=o.endLine){r=e;break}i<=n&&(r=e)}r<0&&(r=0),runHttpRequest(r)}function renderHttpResponse(e,t){if(!t||!t.ok){e.className="http-response error";const n=t&&t.error?t.error:"Request failed";return void(e.innerHTML='<div class="http-resp-head"><span class="http-status bad">Failed</span></div><pre class="http-resp-body">'+escapeHtml(n)+"</pre>")}e.className="http-response";const n=Number(t.status)||0,r=n>=200&&n<300?"ok":n>=400?"bad":"warn",o=t.headers||{},i=Object.keys(o).sort(),a=i.map(function(e){return'<div class="http-h"><span class="http-h-k">'+escapeHtml(e)+'</span><span class="http-h-v">'+escapeHtml(String(o[e]))+"</span></div>"}).join("");let s="";for(let e=0;e<i.length;e++)if("content-type"===i[e].toLowerCase()){s=String(o[i[e]]);break}const c=null==t.body?"":String(t.body),l=formatHttpBody(c,s);e.innerHTML='<div class="http-resp-head"><span class="http-status '+r+'">'+n+(t.statusText?" "+escapeHtml(t.statusText):"")+'</span><span class="http-resp-meta">'+(Number(t.durationMs)||0)+' ms</span><span class="http-resp-meta">'+formatBytes(c.length)+"</span>"+(i.length?'<button type="button" class="http-resp-toggle">Headers ('+i.length+")</button>":"")+'</div><div class="http-resp-headers hidden">'+a+'</div><pre class="http-resp-body">'+l+"</pre>"}function formatHttpBody(e,t){if(!e)return'<span class="http-resp-empty">(empty body)</span>';if(/json/i.test(t)||/^[\[{]/.test(e.trim()))try{return JSON.stringify(JSON.parse(e),null,2).split(/\r?\n/).map(function(e){return highlightLine(e,"json")}).join("\n")}catch(e){}return escapeHtml(e)}function populateHttpEnvSelect(){const e=document.getElementById("http-env-select");if(!e)return;let t='<option value="">No environment</option>';httpEnvNames.forEach(function(e){t+='<option value="'+escapeHtml(e)+'"'+(e===currentHttpEnvName?" selected":"")+">"+escapeHtml(e)+"</option>"}),e.innerHTML=t,e.dataset.wired||(e.dataset.wired="1",e.addEventListener("change",function(){currentHttpEnvName=e.value;try{localStorage.setItem(httpEnvKey,currentHttpEnvName)}catch(e){}const t=document.getElementById("source-viewer")?.dataset.openPath||"";if(t&&isHttpFile(t)){const e=sourceByPath.get(t),n=document.getElementById("source-body");e&&n&&(n.innerHTML=renderHttpTable(e))}}))}function renderSourceTable(e,t){const n=t.trim().toLowerCase(),r=e.content.split(/\r?\n/),o=viewerCursor&&viewerCursor.path===e.path?viewerCursor:null,i=new Set(e.changedLines||[]);return'<table class="source-table"><tbody>'+r.map((t,r)=>{const a=n.length>0&&t.toLowerCase().includes(n),s=Boolean(o&&o.lineIndex===r),c=Boolean(o&&o.targetLine===r);return['<tr class="'+["source-row",a?"search-hit":"",i.has(r+1)?"changed-line":"",s?"cursor-line":"",c?"symbol-target":""].filter(Boolean).join(" ")+'" data-line-index="'+r+'">','<td class="num">'+String(r+1)+"</td>",'<td class="source-code">'+highlightLine(t,e.language||"text")+"</td>","</tr>"].join("")}).join("")+"</tbody></table>"}function renderLineWithCursor(e,t,n){const r=Math.max(0,Math.min(n,e.length)),o=e.slice(0,r),i=e.slice(r);return highlightLine(o,t)+'<span class="code-cursor" aria-hidden="true"></span>'+highlightLine(i,t)}function highlightLine(e,t){if("text"===t)return escapeHtml(e);if("markup"===t)return escapeHtml(e).replace(/(&lt;\/?)([\w:-]+)([^&]*?)(\/?&gt;)/g,'$1<span class="tok-tag">$2</span>$3$4');if("markdown"===t){const t=escapeHtml(e);return/^\s{0,3}#{1,6}\s/.test(e)?'<span class="tok-keyword">'+t+"</span>":t.replace(new RegExp(String.fromCharCode(96)+"[^"+String.fromCharCode(96)+"]+"+String.fromCharCode(96),"g"),'<span class="tok-string">$&</span>')}const n=new Set(["as","async","await","break","case","catch","class","const","continue","def","default","defer","do","else","enum","export","extends","final","finally","fn","for","from","func","function","go","if","impl","import","in","interface","let","match","module","new","package","private","protected","public","return","select","static","struct","switch","throw","try","type","val","var","while","yield"]),r=new Set(["False","None","True","false","nil","null","self","this","true","undefined"]),o=["python","ruby","shell","yaml","toml"].includes(t)?["#"]:["//"];let i="",a=0;for(;a<e.length;){const t=e.slice(a);if(o.find(e=>t.startsWith(e))){i+='<span class="tok-comment">'+escapeHtml(t)+"</span>";break}const s=e[a];if('"'===s||"'"===s||s===String.fromCharCode(96)){const t=s;let n=a+1,r=!1;for(;n<e.length;){const o=e[n];if(o===t&&!r){n+=1;break}r="\\"===o&&!r,"\\"!==o&&(r=!1),n+=1}i+='<span class="tok-string">'+escapeHtml(e.slice(a,n))+"</span>",a=n;continue}if("@"===s){const e=t.match(/^@[A-Za-z_$][\w$.]*/);if(e){i+='<span class="tok-decorator">'+escapeHtml(e[0])+"</span>",a+=e[0].length;continue}}const c=t.match(/^\b\d+(?:\.\d+)?\b/);if(c){i+='<span class="tok-number">'+escapeHtml(c[0])+"</span>",a+=c[0].length;continue}const l=t.match(/^[A-Za-z_$][\w$-]*/);if(l){const t=l[0],o=e.slice(a+t.length);n.has(t)?i+='<span class="tok-keyword">'+escapeHtml(t)+"</span>":r.has(t)?i+='<span class="tok-literal">'+escapeHtml(t)+"</span>":/^\s*\(/.test(o)?i+='<span class="tok-function">'+escapeHtml(t)+"</span>":/^[A-Z]/.test(t)&&/[a-z]/.test(t)?i+='<span class="tok-type">'+escapeHtml(t)+"</span>":i+=escapeHtml(t),a+=t.length;continue}i+=escapeHtml(s),a+=1}return i}function escapeHtml(e){return String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function formatBytes(e){if(e<1024)return e+" B";const t=e/1024;return t<1024?t.toFixed(1)+" KiB":(t/1024).toFixed(1)+" MiB"}!function(){var e=document.getElementById("render-toggle");e&&e.addEventListener("click",function(){toggleRenderMode()}),document.addEventListener("keydown",function(e){if(!isFloatingModalOpen()&&(e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey&&("M"===e.key||"m"===e.key||"KeyM"===e.code)){var t=document.getElementById("source-viewer"),n=t&&t.dataset.openPath;n&&isRenderToggleable(n)&&isSourceViewerVisible()&&(e.preventDefault(),toggleRenderMode())}})}();var HISTORY_LANE_W=14,HISTORY_DOT_R=3.5,HISTORY_ROW_H=24,HISTORY_COLORS=["#6c9fd4","#7faf6b","#d4a857","#c77dd4","#d36c6c","#5bb6b6","#b0884f","#8d8df0"],historyCommits=[],historyGraph=[],historyMaxLane=0,historyActiveSha="",historyLoading=!1;function computeHistoryGraph(e){var t=[],n={},r=0;function o(e){return null==n[e]&&(n[e]=r++),n[e]}function i(){for(var e=0;e<t.length;e++)if(null==t[e])return e;return t.push(null),t.length-1}for(var a=[],s=0,c=0;c<e.length;c++){var l=e[c],u=t.slice(),d=t.indexOf(l.hash);-1===d&&(d=i());var f=o(l.hash);t[d]=l.hash;for(var m=0;m<t.length;m++)m!==d&&t[m]===l.hash&&(t[m]=null);var p=l.parents||[],h={};if(0===p.length)t[d]=null;else{t[d]=p[0],null==n[p[0]]&&(n[p[0]]=f),h[d]=!0;for(var v=1;v<p.length;v++){var g=t.indexOf(p[v]),y=-1!==g?g:i();t[y]=p[v],o(p[v]),h[y]=!0}}for(var w=t.slice(),C=[],b=0;b<u.length;b++)null!=u[b]&&C.push({from:b,to:u[b]===l.hash?d:b,color:n[u[b]]});for(var S=[],E=0;E<w.length;E++)null!=w[E]&&S.push({from:h[E]?d:E,to:E,color:n[w[E]]});for(var k=0;k<Math.max(u.length,w.length);k++)null==u[k]&&null==w[k]||(s=Math.max(s,k));s=Math.max(s,d),a.push({hash:l.hash,myLane:d,color:f,topEdges:C,bottomEdges:S})}return a.maxLane=s,a}function historyLaneX(e){return 9+e*HISTORY_LANE_W}function historyColor(e){return HISTORY_COLORS[e%HISTORY_COLORS.length]}function historyRowSvg(e){var t=historyLaneX(historyMaxLane)+9,n=HISTORY_ROW_H,r=n/2,o='<svg class="hgraph" width="'+t+'" height="'+n+'" viewBox="0 0 '+t+" "+n+'" aria-hidden="true">',i=function(e,t,n){var r=historyLaneX(e.from),o=historyLaneX(e.to),i=(t+n)/2;return'<path d="M'+r+" "+t+" C "+r+" "+i+", "+o+" "+i+", "+o+" "+n+'" stroke="'+historyColor(e.color)+'" fill="none" stroke-width="1.6"/>'};return e.topEdges.forEach(function(e){o+=i(e,0,r)}),e.bottomEdges.forEach(function(e){o+=i(e,r,n)}),o+='<circle cx="'+historyLaneX(e.myLane)+'" cy="'+r+'" r="'+HISTORY_DOT_R+'" fill="'+historyColor(e.color)+'"/></svg>'}function historyRefBadges(e){return e&&e.trim()?e.split(",").map(function(e){if(!(e=e.trim()))return"";var t="href-branch",n=e;return 0===e.indexOf("tag:")?(t="href-tag",n=e.replace("tag:","").trim()):0===e.indexOf("HEAD")?t="href-head":0!==e.indexOf("origin/")&&-1===e.indexOf("/")||(t="href-remote"),'<span class="href '+t+'">'+escapeHtml(n)+"</span>"}).join(""):""}function historyShortDate(e){if(!e)return"";var t=String(e).match(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})/);return t?t[1]+" "+t[2]:String(e).slice(0,16)}function renderHistoryList(){var e=document.getElementById("history-list");e&&(historyCommits.length?(e.style.setProperty("--hgraph-w",historyLaneX(historyMaxLane)+9+"px"),e.innerHTML=historyCommits.map(function(e,t){return'<button type="button" class="hrow'+(e.hash===historyActiveSha?" active":"")+'" data-sha="'+escapeHtml(e.hash)+'"><span class="hgraph-cell">'+historyRowSvg(historyGraph[t])+'</span><span class="hmsg">'+historyRefBadges(e.refs)+escapeHtml(e.subject)+'</span><span class="hauthor">'+escapeHtml(e.author)+'</span><span class="hdate">'+escapeHtml(historyShortDate(e.date))+"</span></button>"}).join("")):e.innerHTML='<div class="quick-open-empty">'+escapeHtml(t(historyLoading?"history.loading":"history.empty"))+"</div>")}function applyHistoryFilter(){var e=document.getElementById("history-search"),t=document.getElementById("history-list");if(t){var n=(e&&e.value||"").trim().toLowerCase();t.classList.toggle("filtering",n.length>0);for(var r=t.querySelectorAll(".hrow"),o=0;o<r.length;o++){var i=historyCommits[o],a=!n||-1!==(i.subject+"\n"+i.author+"\n"+i.hash).toLowerCase().indexOf(n);r[o].classList.toggle("hidden",!a)}}}function openHistoryCommit(e){if(e&&window.monacoriGit){historyActiveSha=e;var n=document.getElementById("history-list");n&&n.querySelectorAll(".hrow").forEach(function(t){t.classList.toggle("active",t.dataset.sha===e)});var r=document.getElementById("history-detail");r&&(r.innerHTML='<div class="quick-open-empty">'+escapeHtml(t("history.loading"))+"</div>"),Promise.resolve(window.monacoriGit.commitDiff(e)).then(function(t){t&&historyActiveSha===e&&renderHistoryDetail(t)},function(){})}}function renderHistoryDetail(e){var n=document.getElementById("history-detail");if(n){var r='<div class="history-detail-head"><div class="hd-msg">'+escapeHtml(e.message||"").replace(/\n/g,"<br>")+'</div><div class="hd-meta"><span class="hd-hash">'+escapeHtml((e.hash||"").slice(0,10))+'</span><span class="hd-author">'+escapeHtml(e.author)+(e.email?" &lt;"+escapeHtml(e.email)+"&gt;":"")+'</span><span class="hd-date">'+escapeHtml(historyShortDate(e.date))+"</span>"+historyRefBadges(e.refs)+"</div></div>",o=e.diffHtml&&e.diffHtml.trim()?'<div class="history-diff diff2html-container">'+e.diffHtml+"</div>":'<div class="quick-open-empty">'+escapeHtml(t(e.isMerge?"history.merge":"history.noDiff"))+"</div>";n.innerHTML=r+o}}function isHistoryOpen(){var e=document.getElementById("history-view");return!(!e||e.classList.contains("hidden"))}function closeHistory(){var e=document.getElementById("history-view");e&&e.classList.add("hidden"),"function"==typeof syncRail&&syncRail()}function openHistory(){var e=document.getElementById("history-view");if(e&&window.monacoriGit){e.classList.remove("hidden"),"function"==typeof syncRail&&syncRail();var n=document.getElementById("history-search");n&&(n.value=""),applyHistoryFilter(),historyLoading=!0,renderHistoryList(),Promise.resolve(window.monacoriGit.log({limit:300})).then(function(e){historyLoading=!1,historyCommits=Array.isArray(e)?e:[],historyGraph=computeHistoryGraph(historyCommits),historyMaxLane=historyGraph.maxLane||0,renderHistoryList();var r=document.getElementById("history-detail");r&&(r.innerHTML='<div class="quick-open-empty">'+escapeHtml(t("history.selectCommit"))+"</div>"),historyCommits[0]&&openHistoryCommit(historyCommits[0].hash),n&&setTimeout(function(){try{n.focus()}catch(e){}},0)},function(){historyLoading=!1,renderHistoryList()})}}function toggleHistory(){isHistoryOpen()?closeHistory():openHistory()}function copyTextToClipboard(e){try{if(window.monacoriClipboard&&"function"==typeof window.monacoriClipboard.write)return window.monacoriClipboard.write(e),!0}catch(e){}try{if(navigator.clipboard&&navigator.clipboard.writeText)return navigator.clipboard.writeText(e),!0}catch(e){}return!1}function caretLocation(){if("function"==typeof isSourceViewerVisible&&isSourceViewerVisible()){var e=document.getElementById("source-viewer"),t=e&&e.dataset.openPath||"";if(t&&void 0!==viewerCursor&&viewerCursor&&viewerCursor.path===t)return t+":"+(viewerCursor.lineIndex+1);if(t)return t}if("function"==typeof isDiffViewVisible&&isDiffViewVisible()&&void 0!==diffCursor&&diffCursor){var n=diffWrapperByPath(diffCursor.path),r=n?diffRowAt(n,diffCursor.side,diffCursor.rowIndex):null,o=r?diffLineNumber(r):null;return diffCursor.path+(o?":"+o:"")}return""}function copyCaretLocation(){var e=caretLocation();e&&copyTextToClipboard(e)&&"function"==typeof showToast&&showToast(t("goto.copied")+" "+e)}function gotoDiffLine(e){var t=void 0!==diffCursor&&diffCursor&&diffCursor.path||"";if(!t&&"function"==typeof diffActiveWrapper){var n=diffActiveWrapper(),r=n&&n.querySelector(".d2h-file-name");r&&r.textContent&&(t=r.textContent.trim())}var o=t&&diffWrapperByPath(t);if(o)for(var i=[diffCursor&&diffCursor.side||"new","new","old"],a=0;a<i.length;a++)for(var s=diffRowsOf(diffSideTable(o,i[a])),c=0;c<s.length;c++)if(diffLineNumber(s[c])===e)return void setDiffCursor(t,i[a],c,0,!0)}function gotoLineJump(e){if(e>=1){if("function"==typeof isSourceViewerVisible&&isSourceViewerVisible()){var t=document.getElementById("source-viewer"),n=t&&t.dataset.openPath||"",r=n&&sourceByPath.get(n);if(r&&r.embedded&&"string"==typeof r.content){var o=r.content.split(/\r?\n/).length;return void setSourceCursor(n,Math.max(0,Math.min(o-1,e-1)),0,!0,-1)}}"function"==typeof isDiffViewVisible&&isDiffViewVisible()&&gotoDiffLine(e)}}function openGotoLine(){if("function"==typeof isSourceViewerVisible&&isSourceViewerVisible()||"function"==typeof isDiffViewVisible&&isDiffViewVisible()){var e=document.getElementById("goto-line");e&&e.remove();var n=document.createElement("div");n.id="goto-line",n.className="goto-line";var r=document.createElement("input");r.type="text",r.inputMode="numeric",r.className="goto-line-input",r.placeholder=t("goto.placeholder"),n.appendChild(r),document.body.appendChild(n),document.addEventListener("keydown",i,!0),setTimeout(function(){try{r.focus()}catch(e){}},0)}function o(){n.remove(),document.removeEventListener("keydown",i,!0)}function i(e){if("Escape"===e.key)e.preventDefault(),e.stopPropagation(),o();else if("Enter"===e.key){e.preventDefault(),e.stopPropagation();var t=parseInt(r.value,10);o(),t>=1&&gotoLineJump(t)}}}function openTreeRowMenu(e){if(e){var n=e.dataset.sourceFile||e.dataset.file||"";if(n){var r=e.getBoundingClientRect(),o=[{label:t("menu.copyPath"),onSelect:function(){copyTextToClipboard(n)&&"function"==typeof showToast&&showToast(t("goto.copied")+" "+n)}}];window.monacoriApp&&"function"==typeof window.monacoriApp.revealInFinder&&(o.push({label:t("menu.revealFinder"),onSelect:function(){try{window.monacoriApp.revealInFinder(n)}catch(e){}}}),o.push({label:t("menu.openTerminal"),onSelect:function(){try{window.monacoriApp.openTerminalAt(n)}catch(e){}}})),showCustomDropdown(Math.round(r.left+14),Math.round(r.bottom+2),o,Math.round(r.top))}}}"undefined"!=typeof window&&(window.computeHistoryGraph=computeHistoryGraph),"undefined"!=typeof window&&(window.__monacoriHistory={open:openHistory,close:closeHistory,toggle:toggleHistory,isOpen:isHistoryOpen}),function(){var e=document.getElementById("history-list");e&&e.addEventListener("click",function(e){var t=e.target.closest&&e.target.closest(".hrow[data-sha]");t&&openHistoryCommit(t.dataset.sha)});var t=document.getElementById("history-search");t&&t.addEventListener("input",applyHistoryFilter);var n=document.getElementById("history-close");n&&n.addEventListener("click",closeHistory);var r=document.getElementById("history-view");r&&r.addEventListener("keydown",function(e){"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),closeHistory())})}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happy-nut/monacori",
3
- "version": "0.1.23",
3
+ "version": "0.1.25",
4
4
  "description": "Validation control plane for AI-generated code changes.",
5
5
  "type": "module",
6
6
  "main": "dist/app-main.js",