@cmmd-center/forge 0.13.133 → 0.13.134

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.
@@ -1,5 +1,5 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ha as t,Ua as n,Wa as r}from"./Stream-mUTFnSY9.js";import{Ft as i}from"./useOpenInteractionType-KsRrk6uH.js";import{E as a,L as o,On as s,b as c,c as l,f as u,l as d,ln as f,n as p,p as m,pn as h,s as g,sn as _,t as v,u as y,v as b,wn as x,xn as S}from"./DiffWorkerPoolProvider-DuQCCe4H.js";import{$t as C,Gt as w,I as T,Jt as E,Kt as D,Nn as O,Xt as k,Yt as A,Zt as j,c as M,cn as N,dn as P,en as F,fn as I,in as L,m as R,ps as z,qt as ee,rn as B,rs as V,s as te,sn as ne,t as H,u as U}from"./WorkerPoolContext-DJIHDFVZ.js";import{rn as W}from"./cmmdForgeRuntimeListResource-uAVdZfT3.js";import{t as G}from"./utils-B9FLzOgF.js";import{s as K}from"./scroll-area-dh4WduWB.js";import{t as re}from"./react-D4GEJ3ir.js";import{y as ie}from"./popover-DZpHoNco.js";import{t as ae}from"./chevron-right-DAF000Jz.js";import{f as oe,h as se,l as q,m as ce,n as le,o as J,p as ue,t as de,u as fe}from"./DiffPanel.logic-p0v4whSE.js";function pe(e,t){return V(e,s,t)}function me(){return typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function he(e,t){return e==null||t==null?e===t:e.header!==t.header||e.footer!==t.footer?!1:ge(e.items,t.items)}function ge(e,t){if(e==null||t==null)return e===t;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n];if(r==null||i==null||r.id!==i.id||r.type!==i.type||r.element!==i.element||r.instance!==i.instance||r.version!==i.version)return!1}return!0}function _e(e,t,n){let r=document.createElement(`div`);return r.style.display=`flow-root`,e===`header`?(r.setAttribute(F,``),t.before(r)):(r.setAttribute(C,``),t.after(r)),n?.observe(r),r}function Y(e){let t=window.devicePixelRatio??1;return Math.round(e*t)/t}var ve=`theme.disableLineNumbers.overflow.themeType.disableFileHeader.disableVirtualizationBuffers.preferredHighlighter.useCSSClasses.useTokenTransformer.tokenizeMaxLineLength.tokenizeMaxLength.unsafeCSS.diffStyle.diffIndicators.disableBackground.expandUnchanged.loadDiffFiles.collapsedContextThreshold.lineDiffType.maxLineDiffLength.expansionLineCount.lineHoverHighlight.enableTokenInteractionsOnWhitespace.enableGutterUtility.__debugPointerEvents.enableLineSelection.controlledSelection.disableErrorHandling`.split(`.`),ye=[`theme`,`disableLineNumbers`,`overflow`,`themeType`,`disableFileHeader`,`disableVirtualizationBuffers`,`preferredHighlighter`,`useCSSClasses`,`useTokenTransformer`,`tokenizeMaxLineLength`,`tokenizeMaxLength`,`unsafeCSS`,`lineHoverHighlight`,`enableTokenInteractionsOnWhitespace`,`enableGutterUtility`,`__debugPointerEvents`,`enableLineSelection`,`controlledSelection`,`disableErrorHandling`],be=[`renderCustomHeader`,`renderHeaderPrefix`,`renderHeaderFilenameSuffix`,`renderHeaderMetadata`,`renderAnnotation`,`renderGutterUtility`,`onPostRender`,`onGutterUtilityClick`,`onLineClick`,`onLineNumberClick`,`onLineEnter`,`onLineLeave`,`onTokenClick`,`onTokenEnter`,`onTokenLeave`],xe=[`onLineSelected`,`onLineSelectionStart`,`onLineSelectionChange`,`onLineSelectionEnd`],Se=Symbol(`CodeView.itemOptionsState`);function Ce(e,t){Object.defineProperty(e,Se,{configurable:!1,enumerable:!1,value:t})}function we(e){return e[Se]}function X(e,t,n){Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get(){return n(this)}})}var Te=120,Ee=1,De=`--diffs-overflow-override`,Oe=12e6,ke=1e6,Ae=2e6,je=1e7,Me=11e6;function Ne(e){if(e==null)throw Error(`CodeView: createEditor is required for items with edit: true`)}var Pe=(()=>{let{navigator:e}=globalThis,t=e.userAgent,n=/iP(?:hone|ad|od)/.test(t),r=e.platform===`MacIntel`&&e.maxTouchPoints>1;return(n||r)&&/AppleWebKit/.test(t)&&/Safari/.test(t)&&!/(CriOS|FxiOS|EdgiOS|OPiOS)/.test(t)})(),Fe=class e{static __STOP=!1;static __lastScrollPosition=0;type=`advanced`;config={overscrollSize:200,intersectionObserverMargin:0,resizeDebugging:!1};items=[];idToItem=new Map;selectedLines=null;itemEditors=new Map;attachedEditors=new Set;instanceToItem=new Map;layoutDirtyIndex;pendingLayoutReset;renderOptionsRevision=0;slotCoordinator;slotSnapshot;scrollListeners=new Set;scrollHeight=0;containerHeight=-1;scrollTop=0;scrollPageOffset=0;scrollDirty=!0;scrollInteractionFixTimer;pointerEventsDisabled=!1;codeOverflowFix=!1;height=0;heightDirty=!0;windowSpecs={top:0,bottom:0};renderState={scrollTop:-1,firstIndex:-1,lastIndex:-1,stickyHeight:0,stickyTop:-1,stickyBottom:-1};itemMetricsCache=B;fileOptionsPrototype;diffOptionsPrototype;pendingScrollTarget;pendingLayoutAnchor;shouldFixContainerFocus=!1;scrollAnimation;root;resizeObserver;container=document.createElement(`div`);stickyContainer=document.createElement(`div`);stickyOffset=document.createElement(`div`);header={element:void 0,render:void 0,height:0};footer={element:void 0,render:void 0,height:0};elementPool=[];elementPoolVersion=0;elementPoolTracker=new WeakMap;pendingElementPool=[];options;workerManager;isReadySubscription;isContainerManaged;constructor(e={theme:N},t,n=!1){this.options=e,this.computeMetricsCache(e.itemMetrics),this.fileOptionsPrototype=this.createFileOptionsPrototype(),this.diffOptionsPrototype=this.createDiffOptionsPrototype(),this.workerManager=t,this.isContainerManaged=n,this.stickyOffset.style.contain=`layout size`,this.stickyContainer.style.position=`sticky`,this.stickyContainer.style.width=`100%`,this.stickyContainer.style.contain=`layout style inline-size`,this.stickyContainer.style.isolation=`isolate`,this.stickyContainer.style.display=`flex`,this.stickyContainer.style.flexDirection=`column`}getLayout(){return this.options.layout??L}getItemTopOffset(){return this.getLayout().paddingTop+this.header.height}computeMetricsCache(e){return this.itemMetricsCache={hunkLineCount:e?.hunkLineCount??B.hunkLineCount,lineHeight:e?.lineHeight??B.lineHeight,diffHeaderHeight:e?.diffHeaderHeight??B.diffHeaderHeight,hunkSeparatorHeight:e?.hunkSeparatorHeight,spacing:e?.spacing??B.spacing,paddingTop:e?.paddingTop,paddingBottom:e?.paddingBottom},this.itemMetricsCache}getSmoothScrollSettings(){return this.options.smoothScrollSettings??ne}shouldDisablePointerEvents(){return this.options.pointerEventsOnScroll!==!0}shouldValidateItemHeights(){return P&&this.options.__devOnlyValidateItemHeights===!0}validateRenderedItemHeight(e){if(!this.shouldValidateItemHeights()||e.element==null)return;let t=e.instance.getAdvancedStickySpecs();if(t==null)return;let n=t.height,r=e.element.getBoundingClientRect().height;n!==r&&console.error(`CodeView: reconciled item height does not match DOM height`,{id:e.item.id,type:e.type,index:e.index,version:e.version,expectedHeight:n,actualHeight:r,delta:r-n,stickyTopOffset:t.topOffset,virtualizedHeight:e.instance.getVirtualizedHeight(),top:e.top,scrollTop:this.getScrollTop(),windowSpecs:{...this.windowSpecs},element:e.element,instance:e.instance})}validateStickyContainerHeight(){if(!this.shouldValidateItemHeights())return;let{firstIndex:e,lastIndex:t,stickyHeight:n,stickyTop:r,stickyBottom:i}=this.renderState;if(e===-1||t===-1)return;let a=this.stickyContainer.getBoundingClientRect().height;Math.abs(a-n)<Ee||console.error(`CodeView: sticky container height does not match computed layout`,{computedStickyHeight:n,actualStickyHeight:a,delta:a-n,stickyTop:r,stickyBottom:i,firstIndex:e,lastIndex:t,firstStickySpecs:this.items[e]?.instance.getAdvancedStickySpecs(),lastStickySpecs:this.items[t]?.instance.getAdvancedStickySpecs(),scrollTop:this.getScrollTop(),scrollPageOffset:this.scrollPageOffset,windowSpecs:{...this.windowSpecs},stickyContainer:this.stickyContainer})}clearScrollInteractionTimer(){this.scrollInteractionFixTimer!=null&&(clearTimeout(this.scrollInteractionFixTimer),this.scrollInteractionFixTimer=void 0)}suspendScrollInteractions(){this.clearScrollInteractionTimer(),this.shouldDisablePointerEvents()&&!this.pointerEventsDisabled&&(this.stickyContainer.style.pointerEvents=`none`,this.pointerEventsDisabled=!0),Pe&&!this.codeOverflowFix&&(this.stickyContainer.style.setProperty(De,`hidden`),this.codeOverflowFix=!0),this.scrollInteractionFixTimer=setTimeout(this.restoreScrollInteractions,Te)}restoreScrollInteractions=()=>{this.clearScrollInteractionTimer(),this.pointerEventsDisabled&&=(this.stickyContainer.style.removeProperty(`pointer-events`),!1),this.codeOverflowFix&&=(this.stickyContainer.style.setProperty(De,`auto`),!1)};syncLayout(){let{gap:e,paddingBottom:t,paddingTop:n}=this.getLayout();this.stickyContainer.style.gap=`${e}px`,this.container?.style.setProperty(`margin-top`,`${n}px`),this.container?.style.setProperty(`margin-bottom`,`${t}px`)}reconcileHeaderFooterHosts(){let e=this.reconcileHost(`header`),t=this.reconcileHost(`footer`);return e||t}reconcileHost(e){let{root:t,container:n}=this;if(t==null||n==null)return!1;let r=e===`header`?this.header:this.footer,i=e===`header`?this.options.renderCodeViewHeader:this.options.renderCodeViewFooter;if(i==null)return r.element!=null&&(this.resizeObserver?.unobserve(r.element),r.element.remove(),r.element=void 0,r.render=void 0,this.setHostHeight(r,0),!1);if(r.element!=null&&i===r.render)return!1;let a=r.element??_e(e,n,this.resizeObserver);r.element=a;let o=i();return o==null?!this.isContainerManaged&&a.children.length>0&&(a.textContent=``):a.replaceChildren(o),r.render=i,!0}setHostHeight(e,t){e.height!==t&&(e.height=t,this.scrollDirty=!0)}measureMountedHosts(){this.header.element!=null&&this.setHostHeight(this.header,this.header.element.getBoundingClientRect().height),this.footer.element!=null&&this.setHostHeight(this.footer,this.footer.element.getBoundingClientRect().height)}setup(t){if(this.root!=null)throw Error(`CodeView.setup: already setup`);this.workerManager?.subscribeToThemeChanges(this),this.root=t,this.root.style.overflowAnchor=`none`,this.root.hasAttribute(`tabindex`)||(this.root.tabIndex=-1),this.container??=document.createElement(`div`),this.container.style.contain=`layout style`,this.syncLayout(),this.container.appendChild(this.stickyOffset),this.container.appendChild(this.stickyContainer),this.root.appendChild(this.container),this.scrollDirty=!0,this.heightDirty=!0,this.resizeObserver=new ResizeObserver(this.handleResize),this.resizeObserver.observe(this.stickyContainer),this.root.addEventListener(`scroll`,this.handleScroll,{passive:!0}),this.root.addEventListener(`wheel`,this.clearPendingScroll,{passive:!0}),this.root.addEventListener(`touchstart`,this.clearPendingScroll,{passive:!0}),this.root.addEventListener(`pointerdown`,this.clearPendingScroll,{passive:!0}),this.root.addEventListener(`keydown`,this.clearPendingScroll,{passive:!0}),this.resizeObserver.observe(this.root),this.render(!0),window.__INSTANCE=this,window.__TOGGLE=()=>{e.__STOP?(e.__STOP=!1,this.scrollTo({type:`position`,position:e.__lastScrollPosition,behavior:`instant`})):(e.__lastScrollPosition=this.getScrollTop(),e.__STOP=!0)}}reset(){k(this.computeRenderRangeAndEmit),this.clearReadySubscription(),this.restoreScrollInteractions(),this.cleanAllRenderedItems();for(let e of this.itemEditors.values())e.editor.cleanUp();this.itemEditors.clear(),this.attachedEditors.clear(),this.selectedLines=null,this.items.length=0,this.idToItem.clear(),this.instanceToItem.clear(),this.layoutDirtyIndex=void 0,this.pendingLayoutReset=void 0,this.stickyContainer.textContent=``,this.stickyOffset.style.height=``,this.container?.style.removeProperty(`height`),this.containerHeight=-1,this.windowSpecs={top:0,bottom:0},this.pendingLayoutAnchor=void 0,this.shouldFixContainerFocus=!1,this.height=0,this.scrollTop=0,this.scrollPageOffset=0,this.scrollHeight=0,this.scrollDirty=!0,this.heightDirty=!0,this.resetRenderState(),this.isContainerManaged||this.flushSlotCoordinator()}cleanUp(){this.reset(),this.clearElementPool(),this.restoreScrollInteractions(),this.workerManager?.unsubscribeToThemeChanges(this),this.resizeObserver?.disconnect(),this.resizeObserver=void 0,this.root?.removeEventListener(`scroll`,this.handleScroll),this.root?.removeEventListener(`wheel`,this.clearPendingScroll),this.root?.removeEventListener(`touchstart`,this.clearPendingScroll),this.root?.removeEventListener(`pointerdown`,this.clearPendingScroll),this.root?.removeEventListener(`keydown`,this.clearPendingScroll),this.root?.style.removeProperty(`overflow-anchor`),this.container?.remove(),this.stickyOffset.remove(),this.stickyContainer.remove(),this.stickyContainer.textContent=``,this.header.element?.remove(),this.header.element=void 0,this.header.render=void 0,this.header.height=0,this.footer.element?.remove(),this.footer.element=void 0,this.footer.render=void 0,this.footer.height=0,this.root=void 0,this.container=void 0}cleanAllRenderedItems(){if(this.renderState.firstIndex!==-1)for(let e=this.renderState.firstIndex;e<=this.renderState.lastIndex;e++){let t=this.items[e];if(t==null)throw Error(`CodeView.cleanAllRenderedItems: Item does not exist at index: ${e}`);this.releaseRenderedItem(t)}}primeScrollTarget(e){e.type!==`position`&&this.idToItem.get(e.id)?.instance.primeHighlightCache()}getElementPoolLimit(){let e=this.getHeight()+this.config.overscrollSize*2,{diffHeaderHeight:t}=this.itemMetricsCache;return Math.max(8,Math.ceil(e/Math.max(t,10))+1)*(this.isContainerManaged?2:1)}acquireElement(){this.promotePendingPooledElements();let e=this.elementPool.pop();for(;e!=null&&!this.isElementPoolGenerationCurrent(e);)e=this.elementPool.pop();return e??=document.createElement(I),this.markElementPoolGenerationCurrent(e),e}releaseRenderedItem(e){let{element:t}=e;t!=null&&this.renderedItemOwnsFocus(t)&&(this.shouldFixContainerFocus=!0),e.instance.cleanUp(!0),this.attachedEditors.delete(e.item.id),e.element=void 0,t!=null&&(t.remove(),this.cleanElement(t),this.queueElementForPool(t))}renderedItemOwnsFocus(e){let{activeElement:t}=document;return t===e||e.contains(t)||e.shadowRoot?.activeElement!=null}fixContainerFocus(){this.shouldFixContainerFocus&&(this.shouldFixContainerFocus=!1,this.root?.focus({preventScroll:!0}))}cleanElement(e){let{shadowRoot:t}=e;if(t!=null)for(let e of Array.from(t.children))Be(e)||e.remove();this.isContainerManaged||e.replaceChildren()}queueElementForPool(e){let t=this.getElementPoolLimit();!this.isElementPoolGenerationCurrent(e)||this.getElementPoolSize()>=t||(this.isElementClean(e)?this.elementPool.push(e):this.pendingElementPool.push(e))}promotePendingPooledElements(){if(this.pendingElementPool.length===0)return;let{pendingElementPool:e}=this;this.pendingElementPool=[];let t=this.getElementPoolLimit();for(let n of e)this.isElementPoolGenerationCurrent(n)&&this.isElementClean(n)&&this.elementPool.length<t?this.elementPool.push(n):this.isElementPoolGenerationCurrent(n)&&this.getElementPoolSize()<t&&this.pendingElementPool.push(n)}isElementClean(e){return e.childNodes.length===0}getElementPoolSize(){return this.elementPool.length+this.pendingElementPool.length}clearElementPool(){this.elementPool.length=0,this.pendingElementPool.length=0}invalidateElementPool(){this.elementPoolVersion++,this.clearElementPool()}markElementPoolGenerationCurrent(e){this.elementPoolTracker.set(e,this.elementPoolVersion)}isElementPoolGenerationCurrent(e){return this.elementPoolTracker.get(e)===this.elementPoolVersion}resolveEffectiveScrollBehavior(e,t){return me()?`instant`:e.behavior===`smooth-auto`?Math.abs(t-this.getScrollTop())<=this.getHeight()*10?`smooth`:`instant`:e.behavior??`instant`}scrollTo(e){if(this.root==null)return;let t=this.normalizeScrollTarget(e);if(t==null)return;let n=this.resolveScrollTargetTop(t);n!=null&&(this.primeScrollTarget(t),this.resolveEffectiveScrollBehavior(t,n)===`smooth`?this.scrollAnimation??={position:this.getScrollTop(),velocity:0,lastTimestamp:performance.now()}:this.scrollAnimation=void 0,this.suspendScrollInteractions(),this.pendingLayoutAnchor=void 0,this.pendingScrollTarget=t,this.render())}setSelectedLines(e,t){this.applySelectedLines(e,t)}getSelectedLines(){return this.selectedLines}clearSelectedLines(e){this.applySelectedLines(null,e)}getItem(e){return this.idToItem.get(e)?.item}getEditor(e){return this.itemEditors.get(e)?.editor}updateItem(e){let t=this.idToItem.get(e.id);return t==null?(console.error(`CodeView.updateItem: unknown item id "${e.id}"`),!1):this.syncItemRecord(t,e)?(this.markItemLayoutDirty(t),this.scrollDirty=!0,this.render(),this.syncItemEditors(),this.syncSelection(),!0):!1}updateItemId(e,t){if(e===t)return!0;let n=this.idToItem.get(e);if(n==null)return console.error(`CodeView.updateItemId: unknown item id "${e}"`),!1;if(this.idToItem.has(t))return console.error(`CodeView.updateItemId: duplicate item id "${t}"`),!1;this.idToItem.delete(e),n.item.id=t,this.idToItem.set(t,n),this.updateItemOptionsId(n.instance.options,t),this.selectedLines?.id===e&&(this.selectedLines={...this.selectedLines,id:t},this.options.onSelectedLinesChange?.(this.selectedLines));let r=this.itemEditors.get(e);return r!=null&&(r.state.id=t,this.itemEditors.delete(e),this.itemEditors.set(t,r),this.attachedEditors.delete(e)&&this.attachedEditors.add(t)),this.renamePendingScrollTarget(e,t),this.renamePendingLayoutAnchor(e,t),this.render(),!0}addItem(e){this.addItems([e])}addItems(e){this.appendItemsInternal(e),this.syncItemEditors(),this.syncSelection()}removeItem(e){let t=this.idToItem.get(e);if(t==null)return console.error(`CodeView.removeItem: unknown item id "${e}"`),!1;let n=[];for(let e of this.items)e!==t&&n.push(e.item);return this.setItems(n),!0}setItems(e){let t;this.items.length===0?this.appendItemsInternal(e):this.tryAppendItems(e)||(t=this.reconcileItems(e)),this.syncItemEditors(t),this.syncSelection()}appendItemsInternal(e,t=!0){if(e.length===0)return;let n=this.getLayout(),r=this.items.length===0?0:this.scrollHeight+n.gap,i=r;for(let t=0;t<e.length;t++){let i=e[t];if(i==null)throw Error(`CodeView.appendItemsInternal: missing input item`);if(this.idToItem.has(i.id))throw Error(`CodeView.addItem: duplicate id "${i.id}"`);let a=this.createItem(i,this.items.length,r);this.items.push(a),this.idToItem.set(a.item.id,a),this.instanceToItem.set(a.instance,a),a.height=Ie(a),r+=a.height+n.gap}this.scrollHeight=r-n.gap,this.scrollDirty=!0,t&&(this.canSkipRenderForAppend(i)?this.syncContainerHeight():this.render())}canSkipRenderForAppend(e){return this.container!=null&&this.renderState.firstIndex!==-1&&this.pendingScrollTarget==null&&this.scrollAnimation==null&&this.layoutDirtyIndex==null&&e>this.windowSpecs.bottom}onThemeChange(){this.invalidateElementPool()}setOptions(e){if(e==null)return;this.capturePendingLayoutAnchor();let{options:t}=this,n=this.getLayout(),{itemMetricsCache:r}=this;Le(t,e)&&this.invalidateElementPool(),this.options=e;let i=this.computeMetricsCache(e.itemMetrics),a=!A(r,i),o=!A(n,this.getLayout());o&&this.syncLayout();let s=a||Re(t,e);if(s){let n=this.pendingLayoutReset;this.pendingLayoutReset={metrics:a?i:n?.metrics,resetFileLayoutCache:!0,resetDiffLayoutCache:!0,includeEstimatedDiffHeights:n?.includeEstimatedDiffHeights===!0||a||ze(t,e)}}(o||s)&&(this.markLayoutDirtyFromIndex(0),this.scrollDirty=!0),ee(t,e)||this.renderOptionsRevision++,this.syncItemEditors();let c=t.renderCodeViewHeader!==e.renderCodeViewHeader||t.renderCodeViewFooter!==e.renderCodeViewFooter;!this.isContainerManaged&&(this.items.length>0||c)&&this.render()}capturePendingLayoutAnchor(e=this.idToItem){this.root!=null&&this.items.length!==0&&this.pendingScrollTarget==null&&(this.pendingLayoutAnchor=this.getScrollAnchor(this.getScrollTop(),e))}render(t=!1){e.__STOP||(t?(k(this.computeRenderRangeAndEmit),this.computeRenderRangeAndEmit()):j(this.computeRenderRangeAndEmit))}isReady(){let{workerManager:e}=this;return e==null||e.isInitialized()||e.getStats().workersFailed?(this.clearReadySubscription(),!0):(this.isReadySubscription??=e.subscribeToStatChanges(e=>{e.managerState!==`initialized`&&!e.workersFailed||(this.clearReadySubscription(),this.render(!0))}),e.getStats().managerState===`waiting`&&e.initialize().catch(()=>{}),!1)}clearReadySubscription(){this.isReadySubscription!=null&&(this.isReadySubscription(),this.isReadySubscription=void 0)}instanceChanged(e,t){let n=this.instanceToItem.get(e);if(n==null)throw Error(`CodeView.instanceChanged: An instance has changed that is not registered`);t&&this.markItemLayoutDirty(n),this.render()}getWindowSpecs(){return this.windowSpecs}getContainerElement(){return this.root}getHeaderElement(){return this.header.element}getFooterElement(){return this.footer.element}getRenderedItems(){let{firstIndex:e,lastIndex:t}=this.renderState;if(e===-1||t===-1||t<e)return[];let n=[];for(let r=e;r<=t;r++){let e=this.items[r];e?.element!=null&&(e.type===`diff`?n.push({id:e.item.id,type:`diff`,item:e.item,version:e.version,element:e.element,instance:e.instance}):n.push({id:e.item.id,type:`file`,item:e.item,version:e.version,element:e.element,instance:e.instance}))}return n}setSlotCoordinator(e){return e!==this.slotCoordinator&&(this.slotCoordinator=e,this.slotSnapshot=void 0,!0)}getSlotSnapshot(e){return this.buildSlotSnapshot(e)}buildSlotSnapshot(e){let t=Ke(this.getRenderedItems(),e),{element:n}=this.header,{element:r}=this.footer;if(t!=null||n!=null||r!=null)return{items:t,header:n,footer:r}}subscribeToScroll(e){return this.scrollListeners.add(e),()=>{this.scrollListeners.delete(e)}}getLocalTopForInstance(e){let t=this.instanceToItem.get(e);if(t==null)throw Error(`CodeView.getLocalTopForInstance: unknown virtualized instance`);return t.top}getTopForItem(e){let t=this.idToItem.get(e);if(t!=null)return t.top+this.getItemTopOffset()}createItem(e,t,n){let{itemMetricsCache:r}=this;if(e.type===`diff`){let i=new fe(this.createDiffOptions(e.id),this,r,this.workerManager,this.isContainerManaged);return{type:`diff`,item:e,version:e.version,index:t,top:n,height:0,element:void 0,renderedOptionsRevision:this.renderOptionsRevision,instance:i}}let i=new o(this.createFileOptions(e.id),this,r,this.workerManager,this.isContainerManaged);return{type:`file`,item:e,version:e.version,index:t,top:n,height:0,element:void 0,renderedOptionsRevision:this.renderOptionsRevision,instance:i}}applySelectedLines(e,t){let{selectedLines:n}=this;e==null&&n==null||e!=null&&n?.id===e.id&&D(n.range,e.range)||(n!=null&&n.id!==e?.id&&this.idToItem.get(n.id)?.instance.setSelectedLines(null,{notify:!1}),this.selectedLines=e,this.idToItem.get(e?.id??``)?.instance.setSelectedLines(e?.range??null,t))}syncSelection(){if(this.selectedLines==null)return;let e=this.idToItem.get(this.selectedLines.id);if(e==null){this.selectedLines=null,this.options.onSelectedLinesChange?.(null);return}e.instance.setSelectedLines(this.selectedLines.range,{notify:!1})}isItemInEditMode(e){return e.item.edit===!0&&e.item.collapsed!==!0}attachItemEditor(e){let{id:t}=e.item,{createEditor:n}=this.options;if(e.element==null||this.attachedEditors.has(t)||!this.isItemInEditMode(e))return;let r=this.itemEditors.get(t),i=!1;try{if(r==null){Ne(n);let e={id:t},a=n({onChange:(t,n)=>{let r=this.idToItem.get(e.id);r!=null&&(e.lastChange={item:r.item,file:t,lineAnnotations:n},this.options.onItemEditChange?.(r.item,t,n))}});if(a==null)return;r={editor:a,state:e},this.itemEditors.set(t,r),i=!0}r.editor.edit(e.instance),this.attachedEditors.add(t)}catch(n){throw i&&r!=null&&(this.itemEditors.delete(t),r.editor.cleanUp()),this.releaseRenderedItem(e),n}}syncItemEditors(e){if(this.itemEditors.size===0)return;let t=[];for(let[n,r]of this.itemEditors){let i=this.idToItem.get(n),a=e?.get(n);if(a==null&&i!=null&&this.isItemInEditMode(i))continue;r.editor.cleanUp(),this.itemEditors.delete(n),this.attachedEditors.delete(n);let{lastChange:o}=r.state,s=a==null?i?.item??o?.item:o?.item??a.item;s?.type===`diff`&&(a==null&&i!=null&&i.type===`diff`&&i.instance.completeEditSession()&&(this.markItemLayoutDirty(i),this.render()),oe(s.fileDiff)),o!=null&&t.push(a!=null||i==null?o:{...o,item:i.item})}for(let{item:e,file:n,lineAnnotations:r}of t)this.options.onItemEditComplete?.(e,n,r)}renamePendingScrollTarget(e,t){let{pendingScrollTarget:n}=this;n!=null&&n.type!==`position`&&n.id===e&&(this.pendingScrollTarget={...n,id:t})}renamePendingLayoutAnchor(e,t){this.pendingLayoutAnchor?.id===e&&(this.pendingLayoutAnchor.id=t)}createFileOptionsPrototype(){let e={};for(let t of ye)X(e,t,()=>this.options[t]);X(e,`stickyHeader`,()=>this.options.stickyHeaders),X(e,`collapsed`,e=>{let t=we(e);if(t!=null)return this.getItemOptions(t,`file`)?.item.collapsed});for(let t of be)this.defineItemSharedCallback(e,`file`,t);for(let t of xe)this.defineItemSelectionCallback(e,`file`,t);return e}createDiffOptionsPrototype(){let e={};for(let t of ve)X(e,t,()=>this.options[t]);X(e,`stickyHeader`,()=>this.options.stickyHeaders),X(e,`hunkSeparators`,()=>this.options.hunkSeparators),X(e,`collapsed`,e=>{let t=we(e);if(t!=null)return this.getItemOptions(t,`diff`)?.item.collapsed});for(let t of be)this.defineItemSharedCallback(e,`diff`,t);for(let t of xe)this.defineItemSelectionCallback(e,`diff`,t);return e}createFileOptions(e){let t=Object.create(this.fileOptionsPrototype);return Ce(t,{id:e}),t}createDiffOptions(e){let t=Object.create(this.diffOptionsPrototype);return Ce(t,{id:e}),t}updateItemOptionsId(e,t){let n=we(e);if(n==null)throw Error(`CodeView.updateItemOptionsId: No valid state`);n.id=t}getItemOptions(e,t){let n=this.idToItem.get(e.id);if(n!=null&&n.type===t)return n}defineItemSharedCallback(e,t,n){X(e,n,e=>{if(this.options[n]==null)return;let r=we(e);if(r==null)return;let i=r.callbackCache??={},a=i[n];return a??(a=((...e)=>{let i=this.getItemOptions(r,t);if(i==null)return;let a=this.options[n];return a?.(...e,i)}),i[n]=a),a})}defineItemSelectionCallback(e,t,n){X(e,n,e=>{let r=we(e);if(r==null)return;let i=r.callbackCache??={},a=i[n];return a??(a=(e=>{let i=this.getItemOptions(r,t);if(i==null)return;let a=e==null?null:{id:i.item.id,range:e};this.options.controlledSelection!==!0&&(e!=null||this.selectedLines?.id===i.item.id)&&this.applySelectedLines(a,{notify:!1}),this.options.onSelectedLinesChange?.(a);let o=this.options[n];return o?.(e,i)}),i[n]=a),a})}markLayoutDirtyFromIndex(e){this.layoutDirtyIndex=Math.min(this.layoutDirtyIndex??e,e)}markItemLayoutDirty(e){if(this.items[e.index]!==e)throw Error(`CodeView.markItemLayoutDirty: unknown item id "${e.item.id}"`);this.markLayoutDirtyFromIndex(e.index)}tryAppendItems(e){if(e.length<=this.items.length)return!1;for(let t=0;t<this.items.length;t++){let n=this.items[t];if(n==null)throw Error(`CodeView.tryAppendItems: missing existing item`);let r=e[t];if(r==null||n.item.id!==r.id||n.type!==r.type)return!1}for(let t=0;t<this.items.length;t++){let n=this.items[t];if(n==null)throw Error(`CodeView.tryAppendItems: missing existing item`);let r=e[t];if(r==null)throw Error(`CodeView.tryAppendItems: append candidate missing prefix item`);this.syncItemRecord(n,r)&&this.markLayoutDirtyFromIndex(t)}return this.appendItemsInternal(e.slice(this.items.length),!1),this.scrollDirty=!0,this.render(),!0}reconcileItems(e){let{items:t,idToItem:n}=this,r=new Set(t),i=[],a=new Map,o=new Map,s=new Map,c;for(let s=0;s<e.length;s++){let l=e[s];if(l==null)throw Error(`CodeView.reconcileItems: missing input item`);if(a.has(l.id))throw Error(`CodeView.setItems: duplicate id "${l.id}"`);let u=n.get(l.id),d=u!=null&&u.type===l.type?u:this.createItem(l,s,0);d.index=s,u!=null&&u.type===l.type?(r.delete(u),this.syncItemRecord(d,l)&&(c=Math.min(c??s,s))):c=Math.min(c??s,s),t[s]!==d&&(c=Math.min(c??s,s)),i.push(d),a.set(l.id,d),o.set(d.instance,d)}if(c==null){if(r.size===0)return;c=Math.max(i.length-1,0)}this.capturePendingLayoutAnchor(a);for(let e=0;e<t.length;e++){let n=t[e];if(n==null||!r.has(n))continue;s.set(n.item.id,n),this.releaseRenderedItem(n);let a=Math.max(i.length-1,0);c=Math.min(c??a,a)}return this.items=i,this.idToItem=a,this.instanceToItem=o,this.renderState.firstIndex>=i.length?this.resetRenderState():this.renderState.lastIndex>=i.length&&(this.renderState.lastIndex=i.length-1),this.markLayoutDirtyFromIndex(c),this.scrollDirty=!0,this.render(),s.size>0?s:void 0}syncItemRecord(e,t){if(e.type!==t.type)throw Error(`CodeView.syncItemRecord: type mismatch for id "${t.id}"`);return e.version!==t.version&&(e.item=t,e.version=t.version,e.renderedOptionsRevision=-1,!0)}getMaxScrollTopForHeight(e){let{paddingBottom:t,paddingTop:n}=this.getLayout();return Math.max(n+this.header.height+e+this.footer.height+t-this.getHeight(),0)}getMaxScrollTop(){return this.getMaxScrollTopForHeight(this.getScrollHeight())}shouldRebaseScroll(){return this.getMaxScrollTop()>Me}getPagedScrollHeight(){return this.shouldRebaseScroll()?Math.min(this.getScrollHeight(),Oe):this.getScrollHeight()}getMaxPagedScrollTop(){return this.getMaxScrollTopForHeight(this.getPagedScrollHeight())}clampPagedScrollTop(e){let t=this.getMaxPagedScrollTop();return Math.max(0,Math.min(e,t))}clampScrollTop(e){let t=this.getMaxScrollTop();return Math.max(0,Math.min(e,t))}getMaxScrollPageOffset(){return Math.max(this.getMaxScrollTop()-this.getMaxPagedScrollTop(),0)}clampScrollPageOffset(e){let t=this.getMaxScrollPageOffset();return Math.max(0,Math.min(e,t))}resolveScrollPageWindow(e,t){let n=Y(this.clampPagedScrollTop(t)),r=this.clampScrollPageOffset(e-n);return n=Y(this.clampPagedScrollTop(e-r)),r=this.clampScrollPageOffset(e-n),{pagedScrollTop:n,scrollPageOffset:r}}resolvePagedScrollPosition(e){if(!this.shouldRebaseScroll())return{pagedScrollTop:this.clampPagedScrollTop(e),scrollPageOffset:0};let t=this.clampScrollPageOffset(this.scrollPageOffset),n=e-t,r=this.getMaxPagedScrollTop(),i=this.getMaxScrollPageOffset(),a=n>Me&&t<i,o=n<ke&&t>0;return n<0||n>r||a||o?this.resolveScrollPageWindow(e,o?Math.min(je,r):Ae):{pagedScrollTop:Y(this.clampPagedScrollTop(n)),scrollPageOffset:t}}needsScrollPageUpdate(e){let t=Y(this.clampScrollTop(e)),{scrollPageOffset:n}=this.resolvePagedScrollPosition(t);return n!==this.scrollPageOffset}getPagedLayoutTop(e){return this.shouldRebaseScroll()?Math.max(e-this.scrollPageOffset,0):e}getStickyHeaderOffset(){return this.options.stickyHeaders===!0&&this.options.disableFileHeader!==!0?this.itemMetricsCache.diffHeaderHeight:0}getScrollTargetRect(e){let t=this.idToItem.get(e.id);if(t==null){console.warn(`CodeView.scrollTo: unknown item id "${e.id}"`);return}if(e.type===`item`)return{top:t.top,height:t.height};if(e.type===`range`){let n=this.getRangeScrollPosition(t,e);if(n==null){console.warn(`CodeView.scrollTo: unable to resolve range ${Ve(e.range)} for item "${e.id}"`);return}return{top:t.top+n.top,height:n.height}}let n=this.getLineScrollPosition(t,e);if(n==null){console.warn(`CodeView.scrollTo: unable to resolve line ${e.lineNumber} for item "${e.id}"`);return}return{top:t.top+n.top,height:n.height}}normalizeScrollTarget(e){if(e.type===`position`||e.align!==`nearest`)return e;let t=this.getScrollTargetRect(e);if(t==null)return;let n=e.offset??0,r=this.getItemTopOffset()+t.top,i=r+t.height,a=this.getScrollTop(),o=a+(e.type===`line`||e.type===`range`?this.getStickyHeaderOffset():0),s=a+this.getHeight();if(!(r-n<=o&&i+n>=s)){if(r-n<o)return{...e,align:`start`};if(i+n>s)return{...e,align:`end`}}}resolveScrollTargetTop(e){if(e.type===`position`){let t=this.clampScrollTop(e.position);return t===e.position?this.clampScrollTop(e.position-this.getStickyHeaderOffset()):t}let t=this.idToItem.get(e.id);if(t==null){console.warn(`CodeView.scrollTo: unknown item id "${e.id}"`);return}if(e.type===`item`)return this.clampScrollTop(this.resolveAlignedScrollPosition(t.top,t.height,e.align,e.offset));if(e.type===`range`){let n=this.getRangeScrollPosition(t,e);if(n==null){console.warn(`CodeView.scrollTo: unable to resolve range ${Ve(e.range)} for item "${e.id}"`);return}return this.clampScrollTop(this.resolveAlignedScrollPosition(t.top+n.top,n.height,e.align,e.offset,this.getStickyHeaderOffset()))}let n=this.getLineScrollPosition(t,e);if(n==null){console.warn(`CodeView.scrollTo: unable to resolve line ${e.lineNumber} for item "${e.id}"`);return}return this.clampScrollTop(this.resolveAlignedScrollPosition(t.top+n.top,n.height,e.align,e.offset,this.getStickyHeaderOffset()))}resolveAlignedScrollPosition(e,t,n,r=0,i=0){e+=this.getItemTopOffset();let a=this.getHeight();return n===`center`&&t+r<a?e-(a-t)/2+r:n===`end`?e-(a-t)+r:e-i-r}getLineScrollPosition(e,t){return e.type===`diff`?e.instance.getLinePosition(t.lineNumber,t.side):e.instance.getLinePosition(t.lineNumber)}getRangeScrollPosition(e,t){let{range:n}=t,r=this.getLineScrollPosition(e,{type:`line`,id:t.id,lineNumber:n.start,side:n.side}),i=this.getLineScrollPosition(e,{type:`line`,id:t.id,lineNumber:n.end,side:n.endSide??n.side});if(r==null||i==null)return;let a=r.top,o=a+r.height,s=i.top,c=s+i.height,l=Math.min(a,s);return{top:l,height:Math.max(o,c)-l}}computeTargetScrollTopForFrame(e,t){if(this.pendingScrollTarget==null)return e;let n=this.resolveScrollTargetTop(this.pendingScrollTarget);if(n==null)return e;let{scrollAnimation:r}=this;return r==null?n:this.computeSpringStep(r,n,t).position}computeSpringStep(e,t,n){let r=Math.max(0,n-e.lastTimestamp),{omega:i}=this.getSmoothScrollSettings(),a=Math.exp(-i*r),o=e.position-t,s=e.velocity+i*o;return{position:t+(o+s*r)*a,velocity:(s*(1-i*r)-i*o)*a}}advanceScrollAnimation(e,t){if(this.pendingScrollTarget==null)return;let n=this.resolveScrollTargetTop(this.pendingScrollTarget);if(n==null){this.pendingScrollTarget=void 0,this.scrollAnimation=void 0;return}let r=this.scrollAnimation;if(r==null)return n;r.position+=t;let{position:i,velocity:a}=this.computeSpringStep(r,n,e);r.lastTimestamp=e,r.position=i,r.velocity=a;let{positionEpsilon:o,velocityEpsilon:s}=this.getSmoothScrollSettings();return Math.abs(n-i)<=o&&Math.abs(a)<=s?(r.position=n,r.velocity=0,this.scrollAnimation=void 0,n):r.position}computeRenderRangeAndEmit=(t=performance.now())=>{if(e.__STOP||this.container==null||!this.isReady())return;let n=this.getHeight(),r=this.getScrollTop(),i=r,a=this.pendingLayoutAnchor!=null,o=this.getScrollAnchor(i);if(this.layoutDirtyIndex!=null&&(this.recomputeLayout(this.layoutDirtyIndex,this.pendingLayoutReset),this.layoutDirtyIndex=void 0,this.pendingLayoutReset=void 0,a=!0),a&&o!=null){let e=this.resolveAnchoredScrollTop(o);if(e!=null){let t=e-i;i=e,this.scrollAnimation!=null&&(this.scrollAnimation.position+=t)}}a&&(i=this.clampScrollTop(i),this.syncContainerHeight());let s=this.computeTargetScrollTopForFrame(i,t),c=!a&&(this.renderState.scrollTop===-1||Math.abs(s-this.renderState.scrollTop)>n+this.config.overscrollSize*2);c&&(o=void 0),this.windowSpecs=w({scrollTop:s-this.header.height,height:n,scrollHeight:this.getScrollHeight(),fitPerfectly:c,fitPerfectlyOverscroll:this.getFitPerfectlyOverscroll(),overscrollSize:this.config.overscrollSize});let l=r;(this.pendingScrollTarget!=null&&s!==l||this.needsScrollPageUpdate(s))&&(this.applyScrollFix(s,l,this.windowSpecs),l=s);let{top:u,bottom:d}=this.windowSpecs,{firstIndex:f,lastIndex:p}=this.renderState;if(f>=0)for(let e=f;e<=p;e++){let t=this.items[e];if(t==null)throw Error(`CodeView.computeRenderRangeAndEmit: No item at index: ${e}`);t.top>u-t.height&&t.top<=d||this.releaseRenderedItem(t)}let m=this.reconcileHeaderFooterHosts(),h,g=new Set,_=this.findFirstVisibleIndex(u),v=this.findLastVisibleIndex(d);for(let e=_;e<=v;e++){let t=this.items[e];if(t==null)throw Error(`CodeView.computeRenderRangeAndEmit: missing item`);let{instance:n}=t;t.element==null?(t.element=this.acquireElement(),We(this.stickyContainer,t.element,h),n.virtualizedSetup(),Ue(t,t.element)&&(t.renderedOptionsRevision=this.renderOptionsRevision,g.add(t)),h=t.element):(We(this.stickyContainer,t.element,h),Ue(t,void 0,t.renderedOptionsRevision!==this.renderOptionsRevision)&&(t.renderedOptionsRevision=this.renderOptionsRevision,g.add(t)),h=t.element),t.item.edit===!0&&this.attachItemEditor(t)}this.renderState.firstIndex=_<=v?_:-1,this.renderState.lastIndex=v,this.flushSlotCoordinator(),this.flushManagers(g),m&&this.measureMountedHosts(),this.reconcileRenderedItems(g),this.syncContainerHeight(),this.updateStickyPositioning();let y=o==null?void 0:this.resolveAnchoredScrollTop(o);o===this.pendingLayoutAnchor&&(this.pendingLayoutAnchor=void 0);let b=y==null?0:y-i,x=s,S=!1;if(this.pendingScrollTarget!=null){let e=this.advanceScrollAnimation(t,b);e==null?x=i:(x=e,S=!0)}else x=y??s;x!==l&&(this.applyScrollFix(x,l,this.windowSpecs),l=x),S&&this.pendingScrollTarget!=null&&this.isPendingTargetSettled(this.pendingScrollTarget)&&(this.pendingScrollTarget=void 0,this.scrollAnimation=void 0),this.renderState.scrollTop=Y(l),this.updateStickyPositioning(),this.validateStickyContainerHeight(),this.fixContainerFocus(),(c||this.scrollAnimation!=null)&&this.render()};flushManagers(e){for(let t of e)t.instance.flushManagers()}syncContainerHeight(){let e=this.getPagedScrollHeight();this.container!=null&&this.containerHeight!==e&&(this.container.style.height=`${e}px`,this.containerHeight=e)}getStickyBounds(e){let{firstIndex:t,lastIndex:n}=e==null?this.renderState:{firstIndex:this.findFirstVisibleIndex(e.top),lastIndex:this.findLastVisibleIndex(e.bottom)};if(t===-1||n===-1||t>n)return;let r=this.items[t]?.instance.getAdvancedStickySpecs(e),i=this.items[n]?.instance.getAdvancedStickySpecs(e);if(r!=null&&i!=null)return{stickyTop:this.getPagedLayoutTop(Math.max(r.topOffset,0)),stickyBottom:this.getPagedLayoutTop(i.topOffset+i.height)}}applyStickyPositioning({stickyTop:e,stickyBottom:t}){let n=this.getHeight(),{itemMetricsCache:r}=this,i=t-e;this.renderState.stickyHeight=i,this.renderState.stickyTop=e,this.renderState.stickyBottom=t,this.stickyOffset.style.height=`${e}px`;let a=(Math.random()*r.lineHeight>>0)*-1,o=-Math.max(i+a,0)+n;this.stickyContainer.style.top=`${o}px`,this.stickyContainer.style.bottom=`${o+r.diffHeaderHeight}px`}syncPagedScrollScaffolding(e){this.syncContainerHeight();let t=this.getStickyBounds(e);t!=null&&this.applyStickyPositioning(t)}reconcileRenderedItems(e){let{firstIndex:t,lastIndex:n}=this.renderState;if(t===-1)return;let r=-1,i=!1;for(let a=t;a<this.items.length&&!(!i&&a>n);a++){let t=this.items[a];if(t==null)throw Error(`CodeView.reconcileRenderedItems: Invalid item`);r===-1?r=t.top:t.top!==r&&(t.top=r,t.instance.syncVirtualizedTop(),i=!0),(e==null?a<=n:e.has(t))&&(t.instance.reconcileHeights()&&(i=!0,t.height=t.instance.getVirtualizedHeight()),this.validateRenderedItemHeight(t)),r+=t.instance.getVirtualizedHeight(),a<this.items.length-1&&(r+=this.getLayout().gap)}i&&r!=null&&(this.scrollDirty=!0,this.scrollHeight=r)}updateStickyPositioning(){let e=this.getStickyBounds();if(e==null){this.renderState.firstIndex===-1&&(this.stickyOffset.style.height=``);return}let{stickyTop:t,stickyBottom:n}=e;(n-t!==this.renderState.stickyHeight||t!==this.renderState.stickyTop||n!==this.renderState.stickyBottom)&&this.applyStickyPositioning(e)}handleScroll=()=>{e.__STOP||(this.suspendScrollInteractions(),this.scrollDirty=!0,this.notifyScroll(),this.render())};clearPendingScroll=()=>{this.pendingScrollTarget=void 0,this.pendingLayoutAnchor=void 0,this.scrollAnimation=void 0};handleResize=e=>{let t=!1;for(let n of e)if(n.target===this.stickyContainer){let e=n.borderBoxSize[0].blockSize;if(Math.abs(e-this.renderState.stickyHeight)>=Ee){let e=this.getScrollTop(),n=this.getScrollAnchor(e);this.reconcileRenderedItems(),this.updateStickyPositioning();let r=n==null?void 0:this.resolveAnchoredScrollTop(n);if(r!=null){let t=r-e;this.applyScrollFix(r,e,this.windowSpecs),this.scrollAnimation!=null&&(this.scrollAnimation.position+=t)}this.pendingScrollTarget!=null&&this.isPendingTargetSettled(this.pendingScrollTarget)&&(this.pendingScrollTarget=void 0,this.scrollAnimation=void 0),t=!0}}else if(n.target===this.header.element||n.target===this.footer.element){let e=n.target===this.header.element?this.header:this.footer,r=n.borderBoxSize[0].blockSize;if(r!==e.height){let n=this.getScrollTop(),i=this.getScrollAnchor(n);this.setHostHeight(e,r);let a=i==null?void 0:this.resolveAnchoredScrollTop(i);if(a!=null){let e=a-n;this.applyScrollFix(a,n,this.windowSpecs),this.scrollAnimation!=null&&(this.scrollAnimation.position+=e)}this.pendingScrollTarget!=null&&this.isPendingTargetSettled(this.pendingScrollTarget)&&(this.pendingScrollTarget=void 0,this.scrollAnimation=void 0),t=!0}}else this.scrollDirty=!0,this.heightDirty=!0,t=!0;t&&this.render(!0)};getScrollAnchorViewportTop(e,t){return e<t?t+this.getStickyHeaderOffset():t}getScrollAnchor(e,t=this.idToItem){let n,{pendingLayoutAnchor:r}=this;if(r!=null){let e=this.idToItem.get(r.id);if(e!=null&&t.get(r.id)===e)return r;e!=null&&(n=e)}if(e<=0)return;let{firstIndex:i,lastIndex:a,stickyTop:o,stickyBottom:s}=this.renderState;if(i===-1||a===-1)return;let c=this.getHeight();if(o!==-1&&s!==-1){for(let r=i;r<=a;r++){let i=this.items[r];if(i==null)continue;let a=this.getItemTopOffset()+i.top;if(a+i.height<=e)continue;if(a>=e+c)break;if(t.get(i.item.id)!==i){n??=i;continue}if(a>=e)return{type:`item`,id:i.item.id,viewportOffset:a-e};let o=this.getScrollAnchorViewportTop(a,e)-a,s=i.instance.getNumericScrollAnchor(o);if(s!=null){let t=a+s.top;return{type:`line`,id:i.item.id,lineNumber:s.lineNumber,side:s.side,viewportOffset:t-e}}}if(n!=null)for(let e=n.index+1;e<this.items.length;e++){let n=this.items[e];if(n!=null&&t.get(n.item.id)===n)return{type:`item`,id:n.item.id,viewportOffset:0}}}}resolveAnchoredScrollTop(e){let t=this.idToItem.get(e.id);if(t==null)return;let n=this.getItemTopOffset();if(e.type===`item`){let r=n+t.top;return this.clampScrollTop(r-e.viewportOffset)}let r=t.type===`diff`?t.instance.getLinePosition(e.lineNumber,e.side):t.instance.getLinePosition(e.lineNumber);if(r==null)return;let i=n+t.top+r.top;return this.clampScrollTop(i-e.viewportOffset)}applyScrollFix(e,t,n){if(this.root==null)return;let r=Y(this.clampScrollTop(e)),i=Y(t),{scrollPageOffset:a}=this,o=Y(this.clampPagedScrollTop(i-a)),{pagedScrollTop:s,scrollPageOffset:c}=this.resolvePagedScrollPosition(r),l=s,u=a!==c;r===this.renderState.scrollTop&&r===i&&l===o&&!u||(this.suspendScrollInteractions(),(l!==o||u)&&(this.scrollPageOffset=c,this.syncPagedScrollScaffolding(n)),l!==o&&this.root.scrollTo({top:l,behavior:`instant`}),this.renderState.scrollTop=r,this.scrollTop=r,this.scrollDirty=!1)}isPendingTargetSettled(e){let t=this.resolveScrollTargetTop(e);return t==null||Y(this.getScrollTop())===Y(t)}getScrollTop(){if(!this.scrollDirty)return this.scrollTop;this.scrollDirty=!1;let e=this.root?.scrollTop??0;return this.scrollTop=this.clampScrollTop(e+this.scrollPageOffset),this.scrollTop}getHeight(){return this.heightDirty?(this.heightDirty=!1,this.height=this.root?.getBoundingClientRect().height??0,this.height):this.height}getScrollHeight(){return this.scrollHeight}flushSlotCoordinator(){if(this.slotCoordinator==null)return;let e=this.buildSlotSnapshot(this.slotCoordinator);he(this.slotSnapshot,e)||(this.slotSnapshot=e,this.slotCoordinator.onSnapshotChange(e))}notifyScroll(){if(this.scrollListeners.size===0)return;let e=this.getScrollTop();for(let t of this.scrollListeners)t(e,this)}findFirstVisibleIndex(e){let t=0,n=this.items.length-1,r=this.items.length;for(;t<=n;){let i=t+n>>1,a=this.items[i];if(a==null)throw Error(`CodeView.findFirstVisibleIndex: invalid item index`);a.top+a.height>e?(r=i,n=i-1):t=i+1}return r}findLastVisibleIndex(e){let t=0,n=this.items.length-1,r=-1;for(;t<=n;){let i=t+n>>1,a=this.items[i];if(a==null)throw Error(`CodeView.findLastVisibleIndex: invalid item index`);a.top<=e?(r=i,t=i+1):n=i-1}return r}recomputeLayout(e=0,t){if(this.items.length===0){this.scrollHeight=0;return}let n=this.getLayout(),r=0;if(e>0){let t=this.items[e-1];if(t==null)throw Error(`CodeView.recomputeLayout: invalid dirty index`);r=t.top+t.height+n.gap}for(let i=e;i<this.items.length;i++){let e=this.items[i];if(e==null)throw Error(`CodeView.recomputeLayout: invalid item index`);if(e.top=r,e.type===`diff`){let n=e.instance.consumeCodeViewLayoutChanges(e.item.fileDiff);n!=null&&Object.assign(e.item.fileDiff,n),e.height=e.instance.prepareCodeViewItem(e.item.fileDiff,r,t,e.item.annotations??[])}else e.height=e.instance.prepareCodeViewItem(e.item.file,r,t,e.item.annotations??[]);r+=e.height,i<this.items.length-1&&(r+=n.gap)}r!==this.scrollHeight&&(this.scrollDirty=!0),this.scrollHeight=r}resetRenderState(){this.renderState.scrollTop=-1,this.renderState.firstIndex=-1,this.renderState.lastIndex=-1,this.renderState.stickyHeight=0,this.renderState.stickyTop=-1,this.renderState.stickyBottom=-1}getFitPerfectlyOverscroll(){return this.getLayout().gap+this.itemMetricsCache.diffHeaderHeight}};function Ie(e){return e.instance.cleanUp(!0),e.type===`diff`?e.instance.prepareCodeViewItem(e.item.fileDiff,e.top,void 0,e.item.annotations??[]):e.instance.prepareCodeViewItem(e.item.file,e.top,void 0,e.item.annotations??[])}function Le(e,t){return!E(e.theme??N,t.theme??N)||(e.themeType??`system`)!==(t.themeType??`system`)||e.unsafeCSS!==t.unsafeCSS}function Re(e,t){return(e.overflow??`scroll`)!==(t.overflow??`scroll`)||(e.disableLineNumbers??!1)!==(t.disableLineNumbers??!1)||(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||e.unsafeCSS!==t.unsafeCSS||(e.diffStyle??`split`)!==(t.diffStyle??`split`)||(e.diffIndicators??`bars`)!==(t.diffIndicators??`bars`)||(e.hunkSeparators??`line-info`)!==(t.hunkSeparators??`line-info`)||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)}function ze(e,t){return(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.hunkSeparators??`line-info`)!==(t.hunkSeparators??`line-info`)||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)}function Be(e){return e instanceof SVGElement||T(e)&&(e.hasAttribute(`data-core-css`)||e.hasAttribute(`data-theme-css`)||e.hasAttribute(`data-unsafe-css`))}function Ve(e){let t=He(e.start,e.side),n=He(e.end,e.endSide??e.side);return t===n?t:`${t}-${n}`}function He(e,t){return t==null?`${e}`:`${t===`deletions`?`D`:`A`}${e}`}function Ue(e,t,n=!1){return e.type===`diff`?e.instance.render({deferManagers:!0,fileContainer:t,fileDiff:e.item.fileDiff,forceRender:n,lineAnnotations:e.item.annotations??[]}):e.instance.render({deferManagers:!0,fileContainer:t,file:e.item.file,forceRender:n,lineAnnotations:e.item.annotations??[]})}function We(e,t,n){if(n==null){e.firstChild!==t&&e.prepend(t);return}n.nextSibling!==t&&n.after(t)}function Ge(e){return(e.annotations?.length??0)>0}function Ke(e,{hasHeaderRenderers:t,hasAnnotationRenderer:n,hasGutterRenderer:r}){if(e.length===0)return;if(t||r)return e;if(!n)return;let i=[];for(let t of e)Ge(t.item)&&i.push(t);return i.length>0?i:void 0}var Z=e(r(),1),qe=e(i(),1),Q=n(),Je=typeof window>`u`?Z.useEffect:Z.useLayoutEffect;function Ye(e){return{instance:void 0,items:void 0,controlled:e,managedOptions:void 0,disableFlushSync:!1,slotCoordinator:void 0}}function Xe(e,t){let{className:n,containerRef:r,disableWorkerPool:i=!1,editorOptions:a,initialItems:o,items:s,onItemEditChange:c,onItemEditComplete:l,onScroll:u,onSelectedLinesChange:d,options:f,renderAnnotation:p,renderCodeViewFooter:m,renderCodeViewHeader:h,renderCustomHeader:g,renderGutterUtility:_,renderHeaderFilenameSuffix:v,renderHeaderMetadata:y,renderHeaderPrefix:b,selectedLines:x,style:S}=e,C=s!==void 0,w=te(),T=(0,Z.useContext)(H),E=(0,Z.useRef)(Ye(C)),D=g!=null,O=p!=null,k=_!=null,A=D||b!=null||v!=null||y!=null,j=A||O||k,N=h!=null,P=m!=null,F=M(e=>{d?.(e)}),I=x!==void 0,L=M(e=>{if(w==null)throw Error(`CodeView: EditContext is not attached`);let t=w({...a,...e});if(t==null)throw Error(`CodeView: EditProvider.createEditor must return an editor instance`);return t}),R=M((e,t,n)=>{c?.(e,t,n)}),z=M((e,t,n)=>{l?.(e,t,n)}),B=(0,Z.useMemo)(()=>nt({options:f,hasCustomHeader:D,hasGutterRenderer:k,hasCodeViewHeader:N,hasCodeViewFooter:P,onSelectedLinesChange:d==null?void 0:F,controlledSelection:I,createEditor:w==null?void 0:L,onItemEditChange:c==null?void 0:R,onItemEditComplete:l==null?void 0:z}),[w,I,L,R,z,F,P,N,D,k,c,l,d,f]),[V]=(0,Z.useState)(()=>tt()),[,ne]=(0,Z.useState)({}),U=M(e=>{E.current.instance!=null&&(e==null||e!==E.current.instance.getContainerElement())&&(E.current.instance.cleanUp(),V.publish(void 0),E.current=Ye(C)),e!=null&&e!==E.current.instance?.getContainerElement()&&(E.current.instance=new Fe(B,i?void 0:T,!0),E.current.instance.setup(e)),typeof r==`function`?r(e):r!=null&&(r.current=e)}),W=M(e=>{E.current.disableFlushSync?V.publish(e):(0,qe.flushSync)(()=>{V.publish(e)})}),G=(0,Z.useMemo)(()=>{if(!(!A&&!O&&!k&&!N&&!P))return{hasHeaderRenderers:A,hasAnnotationRenderer:O,hasGutterRenderer:k,onSnapshotChange:W}},[W,O,k,A,N,P]);return Je(()=>u==null?void 0:E.current.instance?.subscribeToScroll(u)),Je(()=>{let{instance:e,controlled:t,items:n,managedOptions:r,slotCoordinator:i}=E.current;if(e!=null)try{E.current.disableFlushSync=!0;let a=!1;if(ee(B,r)||(E.current.managedOptions=B,e.setOptions(B),a=!0),t!==C){console.error(`CodeView: cannot switch between controlled and uncontrolled modes. Remount with a new key instead.`);return}if(C)s!==n&&($e(n,s)?E.current.items=s:Qe(n,s)?(E.current.items=s,e.addItems(s.slice(n.length))):(E.current.items=s,e.setItems(s),a=!0));else if(n==null){let t=o??[];E.current.items=t,t.length>0&&(e.setItems(t),a=!0)}x!==void 0&&e.setSelectedLines(x,{notify:!1});let c=e.setSlotCoordinator(G),l=!1;G!==i&&((G==null||i==null)&&(l=!0),E.current.slotCoordinator=G),(a||c)&&e.render(!0),c&&G==null&&V.publish(void 0),l&&ne({})}finally{E.current.disableFlushSync=!1}}),(0,Z.useImperativeHandle)(t,()=>({addItems(e){let{controlled:t,instance:n}=E.current;et(t,`addItems`),n==null?console.error(`CodeView.addItems: no valid instance to append items with`,e):n.addItems(e)},getItem(e){let{instance:t}=E.current;if(t==null){console.error(`CodeView.getItem: no valid instance exists`,e);return}return t.getItem(e)},removeItem(e){let{controlled:t,instance:n}=E.current;return et(t,`removeItem`),n==null?(console.error(`CodeView.removeItem: no valid instance to remove item from`,e),!1):n.removeItem(e)},updateItem(e){let{controlled:t,instance:n}=E.current;return et(t,`updateItem`),n==null?(console.error(`CodeView.updateItem: no valid instance to update item with`,e),!1):n.updateItem(e)},updateItemId(e,t){let{controlled:n,instance:r}=E.current;return et(n,`updateItemId`),r==null?(console.error(`CodeView.updateItemId: no valid instance to update item id with`,e,t),!1):r.updateItemId(e,t)},scrollTo(e){let{instance:t}=E.current;t==null?console.error(`CodeView.scrollTo: no valid instance to scroll with`,e):t.scrollTo(e)},setSelectedLines(e){let{instance:t}=E.current;t==null?console.error(`CodeView.setSelectedLines: no valid instance to update selection with`,e):(t.setSelectedLines(e,{notify:!1}),F(e))},getSelectedLines(){let{instance:e}=E.current;return e==null?(console.error(`CodeView.getSelectedLines: no valid instance exists`),null):e.getSelectedLines()},clearSelectedLines(){let{instance:e}=E.current;e==null?console.error(`CodeView.clearSelectedLines: no valid instance to update selection with`):(e.clearSelectedLines({notify:!1}),F(null))},getEditor(e){let{instance:t}=E.current;if(t==null){console.error(`CodeView.getEditor: no valid instance exists`,e);return}return t.getEditor(e)},getInstance(){return E.current.instance}}),[F]),(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{ref:U,className:n,style:S}),(j||N||P)&&(0,Q.jsx)(rt,{managedContentStore:V,renderCustomHeader:g,renderHeaderPrefix:b,renderHeaderFilenameSuffix:v,renderHeaderMetadata:y,renderAnnotation:p,renderGutterUtility:_,renderCodeViewHeader:h,renderCodeViewFooter:m})]})}var Ze=(0,Z.forwardRef)(Xe);function Qe(e,t){if(e==null||t.length<=e.length)return!1;if(e.length===0)return!0;for(let n=0;n<e.length;n++)if(t[n]!==e[n])return!1;return!0}function $e(e,t){if(e==null||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function et(e,t){if(e)throw Error(`CodeView.${t} cannot be used when CodeView is controlled. Use initialItems for imperative item updates.`)}function tt(){let e,t=new Set;return{getSnapshot(){return e},publish(n){if(!he(e,n)){e=n;for(let e of t)e()}},subscribe(e){return t.add(e),()=>{t.delete(e)}}}}function nt({options:e,hasCustomHeader:t,hasGutterRenderer:n,hasCodeViewHeader:r,hasCodeViewFooter:i,onSelectedLinesChange:a,controlledSelection:o,createEditor:s,onItemEditChange:c,onItemEditComplete:l}){let u={...e,controlledSelection:o,onSelectedLinesChange:a,createEditor:s};return c!=null&&(u.onItemEditChange=c),l!=null&&(u.onItemEditComplete=l),t&&(u.renderCustomHeader=at),n&&(u.renderGutterUtility=at),r&&(u.renderCodeViewHeader=at),i&&(u.renderCodeViewFooter=at),u}var rt=(0,Z.memo)(function({managedContentStore:e,renderCustomHeader:t,renderHeaderPrefix:n,renderHeaderFilenameSuffix:r,renderHeaderMetadata:i,renderAnnotation:a,renderGutterUtility:o,renderCodeViewHeader:s,renderCodeViewFooter:c}){"use no memo";let l=M(t=>e.subscribe(t)),u=M(()=>e.getSnapshot()),d=(0,Z.useSyncExternalStore)(l,u,u),f=``;for(let e of d?.items??[])f+=`${e.id}:${e.version}:${e.type}`;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Z.useMemo)(()=>d?.items?.map(e=>(0,qe.createPortal)(it({renderedItem:e,renderCustomHeader:t,renderHeaderPrefix:n,renderHeaderFilenameSuffix:r,renderHeaderMetadata:i,renderAnnotation:a,renderGutterUtility:o}),e.element,e.id)),[t,n,r,i,a,o,f]),(0,Z.useMemo)(()=>s!=null&&d?.header!=null?(0,qe.createPortal)(s(),d.header):null,[s,d?.header]),(0,Z.useMemo)(()=>c!=null&&d?.footer!=null?(0,qe.createPortal)(c(),d.footer):null,[c,d?.footer])]})});function it({renderedItem:e,renderCustomHeader:t,renderHeaderPrefix:n,renderHeaderFilenameSuffix:r,renderHeaderMetadata:i,renderAnnotation:a,renderGutterUtility:o}){if(e.type===`diff`){let{item:s,instance:c}=e;return q({fileDiff:s.fileDiff,renderCustomHeader:t==null?void 0:()=>t(s),renderHeaderPrefix:n==null?void 0:()=>n(s),renderHeaderFilenameSuffix:r==null?void 0:()=>r(s),renderHeaderMetadata:i==null?void 0:()=>i(s),renderAnnotation:a==null?void 0:e=>a(e,s),lineAnnotations:s.annotations,renderGutterUtility:o==null?void 0:e=>o(e,s),getHoveredLine:c.getHoveredLine})}{let{item:s,instance:c}=e;return p({file:s.file,renderCustomHeader:t==null?void 0:()=>t(s),renderHeaderPrefix:n==null?void 0:()=>n(s),renderHeaderFilenameSuffix:r==null?void 0:()=>r(s),renderHeaderMetadata:i==null?void 0:()=>i(s),renderAnnotation:a==null?void 0:e=>a(e,s),lineAnnotations:s.annotations,renderGutterUtility:o==null?void 0:e=>o(e,s),getHoveredLine:c.getHoveredLine})}}function at(){}var $=t(),ot=0;function st(){return ot+=1,`pending-review-comment-${ot}`}function ct(e,t){return`${e}/${t.projectId}/${t.repository}#${t.number}`}var lt=[],ut=re()(e=>({drafts:{},summaries:{},addComment:(t,n)=>e(e=>({drafts:{...e.drafts,[t]:[...e.drafts[t]??lt,n]}})),removeComment:(t,n)=>e(e=>{let r=(e.drafts[t]??lt).filter(e=>e.id!==n);if(r.length>0)return{drafts:{...e.drafts,[t]:r}};let{[t]:i,...a}=e.drafts;return{drafts:a}}),removeComments:(t,n)=>e(e=>{let r=new Set(n),i=(e.drafts[t]??lt).filter(e=>!r.has(e.id));if(i.length>0)return{drafts:{...e.drafts,[t]:i}};let{[t]:a,...o}=e.drafts;return{drafts:o}}),clear:t=>e(e=>{let{[t]:n,...r}=e.drafts;return{drafts:r}}),setSummary:(t,n)=>e(e=>({summaries:{...e.summaries,[t]:n}})),clearSummary:(t,n)=>e(e=>{if(e.summaries[t]!==n)return e;let{[t]:r,...i}=e.summaries;return{summaries:i}})}));function dt(e){let t=(0,$.c)(2),n;return t[0]===e?n=t[1]:(n=t=>t.drafts[ct(e.environmentId,e)]??lt,t[0]=e,t[1]=n),ut(n)}function ft(e){return[...e].toSorted((e,t)=>t.committedDate.localeCompare(e.committedDate))}function pt(e,t,n){let r=e.slice(0,n),i=e.find(e=>e.oid===t);return i!==void 0&&!r.includes(i)?[...r,i]:r}function mt(e){let t=(0,$.c)(60),[n,r]=(0,Z.useState)(10),i,a,o,s,c,l,u,d,p;if(t[0]!==e||t[1]!==n){i=ft(e.commits);let r=pt(i,e.selectedCommitOid,n);p=`flex shrink-0 items-center gap-2 overflow-x-auto border-b border-border/60 px-3 py-2`,u=`min-w-40 flex-1`,t[11]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,Q.jsx)(`span`,{className:`sr-only`,children:`Diff scope`}),t[11]=d):d=t[11],a=`max-w-full rounded-md border border-border bg-background px-2 py-1 text-xs`,o=e.selectedCommitOid??``,t[12]===e?s=t[13]:(s=t=>e.onSelectedCommitChange(t.target.value||null),t[12]=e,t[13]=s),t[14]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Q.jsx)(`option`,{value:``,children:`All commits`}),t[14]=c):c=t[14],l=r.map(gt),t[0]=e,t[1]=n,t[2]=i,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u,t[9]=d,t[10]=p}else i=t[2],a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9],p=t[10];let m;t[15]!==a||t[16]!==o||t[17]!==s||t[18]!==c||t[19]!==l?(m=(0,Q.jsxs)(`select`,{className:a,value:o,onChange:s,children:[c,l]}),t[15]=a,t[16]=o,t[17]=s,t[18]=c,t[19]=l,t[20]=m):m=t[20];let h;t[21]!==u||t[22]!==d||t[23]!==m?(h=(0,Q.jsxs)(`label`,{className:u,children:[d,m]}),t[21]=u,t[22]=d,t[23]=m,t[24]=h):h=t[24];let g;t[25]!==i.length||t[26]!==n?(g=n<i.length?(0,Q.jsx)(K,{type:`button`,size:`xs`,variant:`ghost`,onClick:()=>r(ht),children:`More commits`}):null,t[25]=i.length,t[26]=n,t[27]=g):g=t[27];let _;t[28]===e.onToggleAll?_=t[29]:(_=(0,Q.jsx)(K,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":`Toggle all files`,onClick:e.onToggleAll,children:`⌄`}),t[28]=e.onToggleAll,t[29]=_);let v=e.diffStyle===`unified`,y;t[30]===e?y=t[31]:(y=()=>e.onDiffStyleChange(`unified`),t[30]=e,t[31]=y);let b;t[32]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,Q.jsx)(ce,{className:`size-3.5`}),t[32]=b):b=t[32];let x;t[33]!==v||t[34]!==y?(x=(0,Q.jsx)(K,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":`Unified diff view`,"aria-pressed":v,onClick:y,children:b}),t[33]=v,t[34]=y,t[35]=x):x=t[35];let S=e.diffStyle===`split`,C;t[36]===e?C=t[37]:(C=()=>e.onDiffStyleChange(`split`),t[36]=e,t[37]=C);let w;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,Q.jsx)(se,{className:`size-3.5`}),t[38]=w):w=t[38];let T;t[39]!==S||t[40]!==C?(T=(0,Q.jsx)(K,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":`Split diff view`,"aria-pressed":S,onClick:C,children:w}),t[39]=S,t[40]=C,t[41]=T):T=t[41];let E;t[42]===e?E=t[43]:(E=()=>e.onWordWrapChange(!e.wordWrap),t[42]=e,t[43]=E);let D;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,Q.jsx)(ue,{className:`size-3.5`}),t[44]=D):D=t[44];let O;t[45]!==e.wordWrap||t[46]!==E?(O=(0,Q.jsx)(K,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":`Toggle line wrapping`,"aria-pressed":e.wordWrap,onClick:E,children:D}),t[45]=e.wordWrap,t[46]=E,t[47]=O):O=t[47];let k;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,Q.jsx)(f,{className:`size-3.5`}),t[48]=k):k=t[48];let A;t[49]===e.onRefresh?A=t[50]:(A=(0,Q.jsx)(K,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":`Refresh pull request diff`,onClick:e.onRefresh,children:k}),t[49]=e.onRefresh,t[50]=A);let j;return t[51]!==g||t[52]!==_||t[53]!==x||t[54]!==T||t[55]!==O||t[56]!==A||t[57]!==p||t[58]!==h?(j=(0,Q.jsxs)(`header`,{className:p,children:[h,g,_,x,T,O,A]}),t[51]=g,t[52]=_,t[53]=x,t[54]=T,t[55]=O,t[56]=A,t[57]=p,t[58]=h,t[59]=j):j=t[59],j}function ht(e){return e+10}function gt(e){return(0,Q.jsx)(`option`,{value:e.oid,children:`${e.messageHeadline} (${e.oid.slice(0,7)})`},e.oid)}var _t=new Set([`pnpm-lock.yaml`,`yarn.lock`,`package-lock.json`,`bun.lockb`,`Cargo.lock`,`go.sum`,`composer.lock`,`Gemfile.lock`]),vt=new Set([`__snapshots__`,`__generated__`,`dist`,`build`,`vendor`]),yt=new Set([`__tests__`,`tests`,`test`]),bt=[`.ts`,`.tsx`,`.js`,`.jsx`,`.mjs`,`.cjs`];function xt(e){let t=e.split(`/`),n=t.at(-1)??``;return _t.has(n)||n.endsWith(`.snap`)||n.endsWith(`.min.js`)||n.endsWith(`.min.css`)||/\.generated\./.test(n)||t.slice(0,-1).some(e=>vt.has(e))?`generated`:/\.(?:test|spec)\./.test(n)||t.slice(0,-1).some(e=>yt.has(e))?`test`:`source`}function St(e){let t=e.lastIndexOf(`.`);return t>e.lastIndexOf(`/`)?e.slice(0,t):e}function Ct(e){return St(e.split(`/`).at(-1)??``)}function wt(e,t){let n=e.split(`/`).slice(0,-1);for(let e of t.split(`/`))e!==`.`&&e!==``&&(e===`..`?n.pop():n.push(e));return n.join(`/`)}var Tt=/(?:\bfrom|\bimport|\brequire\s*\()\s*\(?\s*["']([^"']+)["']/g;function Et(e,t,n,r){let i=t.startsWith(`.`)?wt(e,t):t,a=bt.find(e=>i.endsWith(e)),o=a===void 0?i:i.slice(0,-a.length),s=n.get(o)??n.get(`${o}/index`)??r.get(Ct(o));return s===e?void 0:s}function Dt(e){return Tt.lastIndex=0,Array.from(e.matchAll(Tt),e=>e[1]??``)}function Ot(e,t,n,r){let i=new Set;for(let a of t.flatMap(Dt)){let t=Et(e,a,n,r);t!==void 0&&i.add(t)}return i}function kt(e,t){let n=new Set(e),r=[],i=e.toSorted((e,t)=>e.localeCompare(t));for(;n.size>0;){let e=i.filter(e=>n.has(e)),a=e.find(e=>[...t.get(e)??[]].every(e=>!n.has(e)))??e[0];n.delete(a),r.push(a)}return r}function At(e){return(e.split(`/`).at(-1)??``).replace(/\.(?:test|spec)\..*$/,``).replace(/\.[^.]+$/,``)}function jt(e){let t=new Map;for(let n of e)t.set(J(n),n);let n=new Map;for(let e of t.keys())n.set(e,xt(e));let r=[...t.keys()].filter(e=>n.get(e)===`source`),i=new Map,a=new Set,o=new Map;for(let e of r){i.set(St(e),e);let t=Ct(e);o.has(t)&&a.add(t),o.set(t,e)}for(let e of a)o.delete(e);let s=new Map;for(let e of r){let n=t.get(e);s.set(e,Ot(e,[...n.additionLines,...n.deletionLines],i,o))}let c=kt(r,s),l=new Map;c.forEach((e,t)=>{let n=Ct(e);l.has(n)||l.set(n,t)});let u=[...t.keys()].filter(e=>n.get(e)===`test`).toSorted((e,t)=>(l.get(At(e))??2**53-1)-(l.get(At(t))??2**53-1)||e.localeCompare(t)),d=[...t.keys()].filter(e=>n.get(e)===`generated`).toSorted((e,t)=>e.localeCompare(t));return[...c,...u,...d].map(e=>t.get(e))}function Mt(e,t){return t?.[e]===!0}function Nt(e,t){return e.reduce((e,n)=>Mt(n,t)?e+1:e,0)}var Pt=`forge:pr-files-viewed:v1`,Ft=200;function It(e){return`${e.projectId}:${e.projectRepositoryId??0}:${e.repository.toLowerCase()}#${e.number}`}var Lt=new Map;function Rt(e){if(typeof e!=`object`||!e)return null;let t=Object.create(null);for(let[n,r]of Object.entries(e))n.length>0&&typeof r==`boolean`&&(t[n]=r);return Object.keys(t).length>0?t:null}function zt(e){if(typeof e!=`object`||!e)return{};let t=Object.create(null),n=Object.entries(e).slice(-200);for(let[e,r]of n){if(e.length===0||typeof r!=`object`||!r)continue;let n=Rt(r.viewedByPath);n!==null&&(t[e]={viewedByPath:n})}return t}function Bt(){if(typeof window>`u`)return{ok:!0,value:{}};try{let e=window.localStorage.getItem(Pt);return{ok:!0,value:e===null?{}:zt(JSON.parse(e))}}catch{return{ok:!1}}}function Vt(){let e=Bt();return e.ok?e.value:{}}function Ht(e){if(Lt.size===0)return e;let t={...e};for(let[e,n]of Lt)t[e]={viewedByPath:{...t[e]?.viewedByPath,...n.viewedByPath}};return t}function Ut(e){if(typeof window>`u`)return!0;try{return window.localStorage.setItem(Pt,JSON.stringify(e)),!0}catch{return!1}}function Wt(e){let t=Object.keys(e);return t.length<=Ft?e:Object.fromEntries(t.slice(-200).map(t=>[t,e[t]]))}function Gt(e,t,n,r){if(e[t]?.viewedByPath[n]===r)return e;let{[t]:i,...a}=e;return Wt({...a,[t]:{viewedByPath:{...e[t]?.viewedByPath,[n]:r}}})}var Kt=re(e=>({byPullRequest:Vt(),setFileViewed:(t,n,r)=>e(e=>{let i=Bt(),a=i.ok?Ht(i.value):e.byPullRequest,o=Gt(a,t,n,r);return o===a?(i.ok&&Lt.size>0&&Ut(o)&&Lt.clear(),e.byPullRequest[t]?.viewedByPath[n]===r&&Lt.size===0?e:{byPullRequest:a}):(Ut(o)?Lt.clear():Lt.set(t,o[t]),{byPullRequest:o})})}));function qt(e){let t=(0,$.c)(19),{reference:n,enabled:r,paths:i}=e,a,o;t[0]===n?o=t[1]:(o=It(n),t[0]=n,t[1]=o),a=o;let s=a,c;t[2]===s?c=t[3]:(c=e=>e.byPullRequest[s]?.viewedByPath,t[2]=s,t[3]=c);let l=Kt(c),u=Kt(Jt),d;t[4]!==r||t[5]!==l?(d=e=>r&&Mt(e,l??null),t[4]=r,t[5]=l,t[6]=d):d=t[6];let f=d,p;t[7]!==r||t[8]!==s||t[9]!==u?(p=(e,t)=>{r&&u(s,e,t)},t[7]=r,t[8]=s,t[9]=u,t[10]=p):p=t[10];let m=p,h,g;t[11]!==r||t[12]!==i||t[13]!==l?(g=r?Nt(i,l??null):0,t[11]=r,t[12]=i,t[13]=l,t[14]=g):g=t[14],h=g;let _=h,v,y;return t[15]!==f||t[16]!==m||t[17]!==_?(y={isViewed:f,setViewed:m,viewedCount:_},t[15]=f,t[16]=m,t[17]=_,t[18]=y):y=t[18],v=y,v}function Jt(e){return e.setFileViewed}function Yt(e,t,n){return e.hunks.some(e=>t===`left`?n>=e.deletionStart&&n<e.deletionStart+e.deletionCount:n>=e.additionStart&&n<e.additionStart+e.additionCount)}function Xt(e,t,n){let r=t!==`expanded`;return n.has(e)?!r:r}function Zt(e,t,n,r){let i=t-(n===`left`?r.oldLine:r.newLine);return i>=0&&i<e.lines?{kind:`context`,oldLine:r.oldLine+i,newLine:r.newLine+i,side:n}:null}function Qt(e,t,n,r){let i=n===`left`?r.oldLine:r.newLine,a=n===`left`?e.deletions:e.additions;return t>=i&&t<i+a?n===`left`?{kind:`deleted`,oldLine:t}:{kind:`added`,newLine:t}:null}function $t(e,t){return e.type===`context`?{oldLine:t.oldLine+e.lines,newLine:t.newLine+e.lines}:{oldLine:t.oldLine+e.deletions,newLine:t.newLine+e.additions}}function en(e,t,n){let r={oldLine:e.deletionStart,newLine:e.additionStart};for(let i of e.hunkContent){let e=i.type===`context`?Zt(i,t,n,r):Qt(i,t,n,r);if(e!==null)return e;r=$t(i,r)}return null}function tn(e,t,n){let r=n===`deletions`?`left`:`right`;for(let n of e.hunks){let e=en(n,t,r);if(e!==null)return e}return null}function nn(e){let t=(0,$.c)(7),n;return t[0]!==e.annotation.comment||t[1]!==e.annotation.kind||t[2]!==e.annotation.thread||t[3]!==e.environmentId||t[4]!==e.permissions||t[5]!==e.reference?(n=e.annotation.kind===`thread`?(0,Q.jsx)(y,{environmentId:e.environmentId,reference:e.reference,thread:e.annotation.thread,canReply:e.permissions.canReply,canResolve:e.permissions.canResolve,reactionsEnabled:e.permissions.reactionsEnabled}):(0,Q.jsx)(rn,{body:e.annotation.comment.body}),t[0]=e.annotation.comment,t[1]=e.annotation.kind,t[2]=e.annotation.thread,t[3]=e.environmentId,t[4]=e.permissions,t[5]=e.reference,t[6]=n):n=t[6],n}function rn(e){let t=(0,$.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,Q.jsx)(`p`,{className:`text-xs font-medium text-info-foreground`,children:`Pending review comment`}),t[0]=n):n=t[0];let r;return t[1]===e.body?r=t[2]:(r=(0,Q.jsxs)(`article`,{className:`rounded-md border border-info-border bg-info-surface p-3`,children:[n,(0,Q.jsx)(m,{text:e.body,className:`mt-1`})]}),t[1]=e.body,t[2]=r),r}function an(e){let t=(0,$.c)(10),n;t[0]!==e.file||t[1]!==e.omittedStats?(n=on(e.file,e.omittedStats),t[0]=e.file,t[1]=e.omittedStats,t[2]=n):n=t[2];let{additions:r,deletions:i}=n,a;t[3]===r?a=t[4]:(a=(0,Q.jsxs)(`span`,{className:`text-success-foreground`,children:[`+`,r]}),t[3]=r,t[4]=a);let o;t[5]===i?o=t[6]:(o=(0,Q.jsxs)(`span`,{className:`text-destructive-foreground`,children:[`−`,i]}),t[5]=i,t[6]=o);let s;return t[7]!==a||t[8]!==o?(s=(0,Q.jsxs)(`span`,{className:`flex gap-1 font-mono text-[11px] tabular-nums`,children:[a,o]}),t[7]=a,t[8]=o,t[9]=s):s=t[9],s}function on(e,t){let n=e.hunks.reduce((e,t)=>({additions:e.additions+t.additionLines,deletions:e.deletions+t.deletionLines}),{additions:0,deletions:0});return n.additions===0&&n.deletions===0?t.get(J(e))??n:n}function sn(e){let t=(0,$.c)(9),n=e.item.collapsed===!0,r=n?`Expand file`:`Collapse file`,i=!n,a;t[0]===e?a=t[1]:(a=()=>e.onToggleFile(e.item.id),t[0]=e,t[1]=a);let o;t[2]===n?o=t[3]:(o=n?(0,Q.jsx)(ae,{className:`size-3.5`}):(0,Q.jsx)(ie,{className:`size-3.5`}),t[2]=n,t[3]=o);let s;return t[4]!==r||t[5]!==i||t[6]!==a||t[7]!==o?(s=(0,Q.jsx)(K,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":r,"aria-expanded":i,onClick:a,children:o}),t[4]=r,t[5]=i,t[6]=a,t[7]=o,t[8]=s):s=t[8],s}function cn(e){let t=(0,$.c)(16),n;t[0]!==e.path||t[1]!==e.view?(n=e.view.isViewed(e.path),t[0]=e.path,t[1]=e.view,t[2]=n):n=t[2];let r=n,i=r?`true`:`false`,a=r?`Mark ${e.path} as not viewed`:`Mark ${e.path} as viewed`,o;t[3]!==e.path||t[4]!==e.view||t[5]!==r?(o=()=>e.view.setViewed(e.path,!r),t[3]=e.path,t[4]=e.view,t[5]=r,t[6]=o):o=t[6];let s=r?`border-success-border bg-success-surface text-success-foreground`:`border-border text-muted-foreground hover:text-foreground`,c;t[7]===s?c=t[8]:(c=G(`inline-flex size-5 shrink-0 items-center justify-center rounded-sm border`,s),t[7]=s,t[8]=c);let l;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,Q.jsx)(x,{"aria-hidden":!0,className:`size-3`}),t[9]=l):l=t[9];let u;return t[10]!==i||t[11]!==a||t[12]!==o||t[13]!==c||t[14]!==r?(u=(0,Q.jsx)(`button`,{type:`button`,"data-slot":`pr-file-viewed-toggle`,"data-viewed":i,"aria-pressed":r,"aria-label":a,onClick:o,className:c,children:l}),t[10]=i,t[11]=a,t[12]=o,t[13]=c,t[14]=r,t[15]=u):u=t[15],u}function ln(e){let t=(0,$.c)(2),n;return t[0]===e.threads?n=t[1]:(n=e.threads.length>0?(0,Q.jsxs)(`section`,{className:`border-b border-warning-border bg-warning-surface px-3 py-2 text-xs text-warning-foreground`,children:[(0,Q.jsxs)(`p`,{className:`flex items-center gap-1.5 font-medium`,children:[(0,Q.jsx)(_,{className:`size-3.5`}),`Conversations not on the diff loaded so far`]}),e.threads.map(un)]}):null,t[0]=e.threads,t[1]=n),n}function un(e){return(0,Q.jsxs)(`p`,{className:`mt-1 truncate`,children:[e.path,e.line===null?``:`:${e.line}`,e.isOutdated?` · outdated`:``]},e.id)}function dn(e){let t=(0,$.c)(2),n;return t[0]===e.children?n=t[1]:(n=(0,Q.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:e.children}),t[0]=e.children,t[1]=n),n}function fn(e){let t=(0,$.c)(7),n,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={diffHeaderHeight:32,hunkSeparatorHeight:24,spacing:0,paddingTop:0,paddingBottom:8},r={paddingTop:0,paddingBottom:0,gap:0},t[0]=n,t[1]=r):(n=t[0],r=t[1]);let i;t[2]===e.options?i=t[3]:(i={...e.options,unsafeCSS:`[data-diffs-header]{position:sticky!important;top:0;z-index:4;background:var(--background)!important;border-bottom:1px solid var(--border)!important}`,itemMetrics:n,layout:r},t[2]=e.options,t[3]=i);let a;return t[4]!==e||t[5]!==i?(a=(0,Q.jsx)(Ze,{...e,options:i}),t[4]=e,t[5]=i,t[6]=a):a=t[6],a}function pn(e){return[...e.threads.flatMap(t=>hn(e.file,t)),...e.pendingComments.flatMap(t=>_n(e.file,t))]}function mn(e,t){return e.some(e=>gn(e,t))}function hn(e,t){return gn(e,t)?[{side:yn(t.side),lineNumber:t.line,metadata:{kind:`thread`,thread:t}}]:[]}function gn(e,t){return[!t.isOutdated,t.line!==null,J(e)===t.path,t.line!==null&&Yt(e,t.side,t.line)].every(Boolean)}function _n(e,t){if(J(e)!==t.path)return[];let n=vn(t);return n===null||!Yt(e,n.side,n.line)?[]:[{side:yn(n.side),lineNumber:n.line,metadata:{kind:`pending`,comment:t}}]}function vn(e){switch(e.position.kind){case`added`:return{side:`right`,line:e.position.newLine};case`deleted`:return{side:`left`,line:e.position.oldLine};case`context`:return e.position.side===`left`?{side:`left`,line:e.position.oldLine}:{side:`right`,line:e.position.newLine}}}function yn(e){return e===`left`?`deletions`:`additions`}function bn(e){return xn[Sn(e)](e)}var xn={loading:()=>(0,Q.jsx)(U,{label:`Loading pull request diff…`}),error:e=>(0,Q.jsx)(dn,{children:e.error?.message??`Pull request diff could not be loaded.`}),empty:()=>(0,Q.jsx)(dn,{children:`This pull request has no file changes.`}),loaded:e=>(0,Q.jsx)(Dn,{...e})};function Sn(e){return Cn(e)?`loading`:wn(e)?`error`:Tn(e)?`empty`:`loaded`}function Cn(e){return e.loading&&e.slices.length===0}function wn(e){return e.error!==null&&e.slices.length===0}function Tn(e){return!En({itemCount:e.items.length,rawCount:e.raw.length,withheld:e.withheld})}function En(e){return e.itemCount>0||e.rawCount>0||e.withheld}function Dn(e){let t=(0,$.c)(12),n,r;t[0]===e?(n=t[1],r=t[2]):(n=(0,Q.jsx)(On,{...e}),r=e.items.length>0?(0,Q.jsx)(jn,{...e}):null,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===e.raw?i=t[4]:(i=(0,Q.jsx)(Pn,{raw:e.raw}),t[3]=e.raw,t[4]=i);let a;t[5]===e?a=t[6]:(a=(0,Q.jsx)(Fn,{...e}),t[5]=e,t[6]=a);let o;return t[7]!==n||t[8]!==r||t[9]!==i||t[10]!==a?(o=(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:[n,r,i,a]}),t[7]=n,t[8]=r,t[9]=i,t[10]=a,t[11]=o):o=t[11],o}function On(e){let t=(0,$.c)(18),n;t[0]!==e.activity?.reviewThreads||t[1]!==e.files?(n=e.activity?.reviewThreads.filter(t=>!mn(e.files,t)),t[0]=e.activity?.reviewThreads,t[1]=e.files,t[2]=n):n=t[2];let r=n,i;t[3]!==e.fileCount||t[4]!==e.filesViewed?(i=e.filesViewed!==void 0&&e.fileCount!==void 0&&e.filesViewed.viewedCount>0?(0,Q.jsxs)(`section`,{className:`border-b border-border/60 px-3 py-2 text-xs text-muted-foreground`,"aria-live":`polite`,children:[e.filesViewed.viewedCount,` of `,e.fileCount,` files viewed`]}):null,t[3]=e.fileCount,t[4]=e.filesViewed,t[5]=i):i=t[5];let a;t[6]===e?a=t[7]:(a=e.error===null?null:(0,Q.jsx)(kn,{...e,error:e.error}),t[6]=e,t[7]=a);let o;t[8]!==e.omittedFileCount||t[9]!==e.withheld?(o=e.withheld?(0,Q.jsx)(An,{omittedFileCount:e.omittedFileCount}):null,t[8]=e.omittedFileCount,t[9]=e.withheld,t[10]=o):o=t[10];let s;t[11]===r?s=t[12]:(s=r===void 0?null:(0,Q.jsx)(ln,{threads:r}),t[11]=r,t[12]=s);let c;return t[13]!==i||t[14]!==a||t[15]!==o||t[16]!==s?(c=(0,Q.jsxs)(Q.Fragment,{children:[i,a,o,s]}),t[13]=i,t[14]=a,t[15]=o,t[16]=s,t[17]=c):c=t[17],c}function kn(e){let t=(0,$.c)(8),n;t[0]===e.error.message?n=t[1]:(n=(0,Q.jsxs)(`span`,{children:[`More diff content could not be loaded: `,e.error.message]}),t[0]=e.error.message,t[1]=n);let r;t[2]!==e.hasNextPage||t[3]!==e.onLoadNextPage?(r=e.hasNextPage?(0,Q.jsx)(K,{type:`button`,size:`xs`,variant:`outline`,onClick:e.onLoadNextPage,children:`Retry`}):null,t[2]=e.hasNextPage,t[3]=e.onLoadNextPage,t[4]=r):r=t[4];let i;return t[5]!==n||t[6]!==r?(i=(0,Q.jsxs)(`section`,{className:`flex items-center justify-between gap-2 border-b border-destructive-border bg-destructive-surface px-3 py-2 text-xs text-destructive-foreground`,children:[n,r]}),t[5]=n,t[6]=r,t[7]=i):i=t[7],i}function An(e){let t=(0,$.c)(2),n=e.omittedFileCount>0?` ${e.omittedFileCount} file statistics remain available.`:``,r;return t[0]===n?r=t[1]:(r=(0,Q.jsxs)(`section`,{className:`border-b border-warning-border bg-warning-surface px-3 py-2 text-xs text-warning-foreground`,children:[`Binary or oversized content was withheld by the provider.`,n]}),t[0]=n,t[1]=r),r}function jn(e){let t=(0,$.c)(15),n;t[0]===e.onToggleFile?n=t[1]:(n=t=>Mn(t,e.onToggleFile),t[0]=e.onToggleFile,t[1]=n);let r;t[2]!==e.filesViewed||t[3]!==e.omittedStats?(r=t=>(0,Q.jsxs)(Q.Fragment,{children:[e.filesViewed!==void 0&&t.type===`diff`?(0,Q.jsx)(cn,{path:J(t.fileDiff),view:e.filesViewed}):null,Nn(t,e.omittedStats)]}),t[2]=e.filesViewed,t[3]=e.omittedStats,t[4]=r):r=t[4];let i;t[5]!==e.annotationPermissions||t[6]!==e.environmentId||t[7]!==e.reference?(i=t=>(0,Q.jsx)(nn,{annotation:t.metadata,environmentId:e.environmentId,reference:e.reference,permissions:e.annotationPermissions}),t[5]=e.annotationPermissions,t[6]=e.environmentId,t[7]=e.reference,t[8]=i):i=t[8];let a;return t[9]!==e.items||t[10]!==e.viewOptions||t[11]!==n||t[12]!==r||t[13]!==i?(a=(0,Q.jsx)(fn,{className:`h-full min-h-0 [scrollbar-gutter:stable]`,items:e.items,options:e.viewOptions,renderHeaderPrefix:n,renderHeaderMetadata:r,renderAnnotation:i}),t[9]=e.items,t[10]=e.viewOptions,t[11]=n,t[12]=r,t[13]=i,t[14]=a):a=t[14],a}function Mn(e,t){return(0,Q.jsx)(sn,{item:e,onToggleFile:t})}function Nn(e,t){return e.type===`diff`?(0,Q.jsx)(an,{file:e.fileDiff,omittedStats:t}):null}function Pn(e){return e.raw.map(e=>(0,Q.jsxs)(`pre`,{className:`m-3 whitespace-pre-wrap break-words rounded-md border border-warning-border bg-warning-surface p-3 font-mono text-xs text-warning-foreground`,children:[e.reason,`
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ha as t,Ua as n,Wa as r}from"./Stream-mUTFnSY9.js";import{Ft as i}from"./useOpenInteractionType-KsRrk6uH.js";import{E as a,L as o,On as s,b as c,c as l,f as u,l as d,ln as f,n as p,p as m,pn as h,s as g,sn as _,t as v,u as y,v as b,wn as x,xn as S}from"./DiffWorkerPoolProvider-BxK3crqQ.js";import{$t as C,Gt as w,I as T,Jt as E,Kt as D,Nn as O,Xt as k,Yt as A,Zt as j,c as M,cn as N,dn as P,en as F,fn as I,in as L,m as R,ps as z,qt as ee,rn as B,rs as V,s as te,sn as ne,t as H,u as U}from"./WorkerPoolContext-DfkvYwPY.js";import{rn as W}from"./cmmdForgeRuntimeListResource-6ppYDui_.js";import{t as G}from"./utils-B9FLzOgF.js";import{s as K}from"./scroll-area-dh4WduWB.js";import{t as re}from"./react-D4GEJ3ir.js";import{y as ie}from"./popover-DZpHoNco.js";import{t as ae}from"./chevron-right-DAF000Jz.js";import{f as oe,h as se,l as q,m as ce,n as le,o as J,p as ue,t as de,u as fe}from"./DiffPanel.logic-DukK-hlH.js";function pe(e,t){return V(e,s,t)}function me(){return typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function he(e,t){return e==null||t==null?e===t:e.header!==t.header||e.footer!==t.footer?!1:ge(e.items,t.items)}function ge(e,t){if(e==null||t==null)return e===t;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n];if(r==null||i==null||r.id!==i.id||r.type!==i.type||r.element!==i.element||r.instance!==i.instance||r.version!==i.version)return!1}return!0}function _e(e,t,n){let r=document.createElement(`div`);return r.style.display=`flow-root`,e===`header`?(r.setAttribute(F,``),t.before(r)):(r.setAttribute(C,``),t.after(r)),n?.observe(r),r}function Y(e){let t=window.devicePixelRatio??1;return Math.round(e*t)/t}var ve=`theme.disableLineNumbers.overflow.themeType.disableFileHeader.disableVirtualizationBuffers.preferredHighlighter.useCSSClasses.useTokenTransformer.tokenizeMaxLineLength.tokenizeMaxLength.unsafeCSS.diffStyle.diffIndicators.disableBackground.expandUnchanged.loadDiffFiles.collapsedContextThreshold.lineDiffType.maxLineDiffLength.expansionLineCount.lineHoverHighlight.enableTokenInteractionsOnWhitespace.enableGutterUtility.__debugPointerEvents.enableLineSelection.controlledSelection.disableErrorHandling`.split(`.`),ye=[`theme`,`disableLineNumbers`,`overflow`,`themeType`,`disableFileHeader`,`disableVirtualizationBuffers`,`preferredHighlighter`,`useCSSClasses`,`useTokenTransformer`,`tokenizeMaxLineLength`,`tokenizeMaxLength`,`unsafeCSS`,`lineHoverHighlight`,`enableTokenInteractionsOnWhitespace`,`enableGutterUtility`,`__debugPointerEvents`,`enableLineSelection`,`controlledSelection`,`disableErrorHandling`],be=[`renderCustomHeader`,`renderHeaderPrefix`,`renderHeaderFilenameSuffix`,`renderHeaderMetadata`,`renderAnnotation`,`renderGutterUtility`,`onPostRender`,`onGutterUtilityClick`,`onLineClick`,`onLineNumberClick`,`onLineEnter`,`onLineLeave`,`onTokenClick`,`onTokenEnter`,`onTokenLeave`],xe=[`onLineSelected`,`onLineSelectionStart`,`onLineSelectionChange`,`onLineSelectionEnd`],Se=Symbol(`CodeView.itemOptionsState`);function Ce(e,t){Object.defineProperty(e,Se,{configurable:!1,enumerable:!1,value:t})}function we(e){return e[Se]}function X(e,t,n){Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get(){return n(this)}})}var Te=120,Ee=1,De=`--diffs-overflow-override`,Oe=12e6,ke=1e6,Ae=2e6,je=1e7,Me=11e6;function Ne(e){if(e==null)throw Error(`CodeView: createEditor is required for items with edit: true`)}var Pe=(()=>{let{navigator:e}=globalThis,t=e.userAgent,n=/iP(?:hone|ad|od)/.test(t),r=e.platform===`MacIntel`&&e.maxTouchPoints>1;return(n||r)&&/AppleWebKit/.test(t)&&/Safari/.test(t)&&!/(CriOS|FxiOS|EdgiOS|OPiOS)/.test(t)})(),Fe=class e{static __STOP=!1;static __lastScrollPosition=0;type=`advanced`;config={overscrollSize:200,intersectionObserverMargin:0,resizeDebugging:!1};items=[];idToItem=new Map;selectedLines=null;itemEditors=new Map;attachedEditors=new Set;instanceToItem=new Map;layoutDirtyIndex;pendingLayoutReset;renderOptionsRevision=0;slotCoordinator;slotSnapshot;scrollListeners=new Set;scrollHeight=0;containerHeight=-1;scrollTop=0;scrollPageOffset=0;scrollDirty=!0;scrollInteractionFixTimer;pointerEventsDisabled=!1;codeOverflowFix=!1;height=0;heightDirty=!0;windowSpecs={top:0,bottom:0};renderState={scrollTop:-1,firstIndex:-1,lastIndex:-1,stickyHeight:0,stickyTop:-1,stickyBottom:-1};itemMetricsCache=B;fileOptionsPrototype;diffOptionsPrototype;pendingScrollTarget;pendingLayoutAnchor;shouldFixContainerFocus=!1;scrollAnimation;root;resizeObserver;container=document.createElement(`div`);stickyContainer=document.createElement(`div`);stickyOffset=document.createElement(`div`);header={element:void 0,render:void 0,height:0};footer={element:void 0,render:void 0,height:0};elementPool=[];elementPoolVersion=0;elementPoolTracker=new WeakMap;pendingElementPool=[];options;workerManager;isReadySubscription;isContainerManaged;constructor(e={theme:N},t,n=!1){this.options=e,this.computeMetricsCache(e.itemMetrics),this.fileOptionsPrototype=this.createFileOptionsPrototype(),this.diffOptionsPrototype=this.createDiffOptionsPrototype(),this.workerManager=t,this.isContainerManaged=n,this.stickyOffset.style.contain=`layout size`,this.stickyContainer.style.position=`sticky`,this.stickyContainer.style.width=`100%`,this.stickyContainer.style.contain=`layout style inline-size`,this.stickyContainer.style.isolation=`isolate`,this.stickyContainer.style.display=`flex`,this.stickyContainer.style.flexDirection=`column`}getLayout(){return this.options.layout??L}getItemTopOffset(){return this.getLayout().paddingTop+this.header.height}computeMetricsCache(e){return this.itemMetricsCache={hunkLineCount:e?.hunkLineCount??B.hunkLineCount,lineHeight:e?.lineHeight??B.lineHeight,diffHeaderHeight:e?.diffHeaderHeight??B.diffHeaderHeight,hunkSeparatorHeight:e?.hunkSeparatorHeight,spacing:e?.spacing??B.spacing,paddingTop:e?.paddingTop,paddingBottom:e?.paddingBottom},this.itemMetricsCache}getSmoothScrollSettings(){return this.options.smoothScrollSettings??ne}shouldDisablePointerEvents(){return this.options.pointerEventsOnScroll!==!0}shouldValidateItemHeights(){return P&&this.options.__devOnlyValidateItemHeights===!0}validateRenderedItemHeight(e){if(!this.shouldValidateItemHeights()||e.element==null)return;let t=e.instance.getAdvancedStickySpecs();if(t==null)return;let n=t.height,r=e.element.getBoundingClientRect().height;n!==r&&console.error(`CodeView: reconciled item height does not match DOM height`,{id:e.item.id,type:e.type,index:e.index,version:e.version,expectedHeight:n,actualHeight:r,delta:r-n,stickyTopOffset:t.topOffset,virtualizedHeight:e.instance.getVirtualizedHeight(),top:e.top,scrollTop:this.getScrollTop(),windowSpecs:{...this.windowSpecs},element:e.element,instance:e.instance})}validateStickyContainerHeight(){if(!this.shouldValidateItemHeights())return;let{firstIndex:e,lastIndex:t,stickyHeight:n,stickyTop:r,stickyBottom:i}=this.renderState;if(e===-1||t===-1)return;let a=this.stickyContainer.getBoundingClientRect().height;Math.abs(a-n)<Ee||console.error(`CodeView: sticky container height does not match computed layout`,{computedStickyHeight:n,actualStickyHeight:a,delta:a-n,stickyTop:r,stickyBottom:i,firstIndex:e,lastIndex:t,firstStickySpecs:this.items[e]?.instance.getAdvancedStickySpecs(),lastStickySpecs:this.items[t]?.instance.getAdvancedStickySpecs(),scrollTop:this.getScrollTop(),scrollPageOffset:this.scrollPageOffset,windowSpecs:{...this.windowSpecs},stickyContainer:this.stickyContainer})}clearScrollInteractionTimer(){this.scrollInteractionFixTimer!=null&&(clearTimeout(this.scrollInteractionFixTimer),this.scrollInteractionFixTimer=void 0)}suspendScrollInteractions(){this.clearScrollInteractionTimer(),this.shouldDisablePointerEvents()&&!this.pointerEventsDisabled&&(this.stickyContainer.style.pointerEvents=`none`,this.pointerEventsDisabled=!0),Pe&&!this.codeOverflowFix&&(this.stickyContainer.style.setProperty(De,`hidden`),this.codeOverflowFix=!0),this.scrollInteractionFixTimer=setTimeout(this.restoreScrollInteractions,Te)}restoreScrollInteractions=()=>{this.clearScrollInteractionTimer(),this.pointerEventsDisabled&&=(this.stickyContainer.style.removeProperty(`pointer-events`),!1),this.codeOverflowFix&&=(this.stickyContainer.style.setProperty(De,`auto`),!1)};syncLayout(){let{gap:e,paddingBottom:t,paddingTop:n}=this.getLayout();this.stickyContainer.style.gap=`${e}px`,this.container?.style.setProperty(`margin-top`,`${n}px`),this.container?.style.setProperty(`margin-bottom`,`${t}px`)}reconcileHeaderFooterHosts(){let e=this.reconcileHost(`header`),t=this.reconcileHost(`footer`);return e||t}reconcileHost(e){let{root:t,container:n}=this;if(t==null||n==null)return!1;let r=e===`header`?this.header:this.footer,i=e===`header`?this.options.renderCodeViewHeader:this.options.renderCodeViewFooter;if(i==null)return r.element!=null&&(this.resizeObserver?.unobserve(r.element),r.element.remove(),r.element=void 0,r.render=void 0,this.setHostHeight(r,0),!1);if(r.element!=null&&i===r.render)return!1;let a=r.element??_e(e,n,this.resizeObserver);r.element=a;let o=i();return o==null?!this.isContainerManaged&&a.children.length>0&&(a.textContent=``):a.replaceChildren(o),r.render=i,!0}setHostHeight(e,t){e.height!==t&&(e.height=t,this.scrollDirty=!0)}measureMountedHosts(){this.header.element!=null&&this.setHostHeight(this.header,this.header.element.getBoundingClientRect().height),this.footer.element!=null&&this.setHostHeight(this.footer,this.footer.element.getBoundingClientRect().height)}setup(t){if(this.root!=null)throw Error(`CodeView.setup: already setup`);this.workerManager?.subscribeToThemeChanges(this),this.root=t,this.root.style.overflowAnchor=`none`,this.root.hasAttribute(`tabindex`)||(this.root.tabIndex=-1),this.container??=document.createElement(`div`),this.container.style.contain=`layout style`,this.syncLayout(),this.container.appendChild(this.stickyOffset),this.container.appendChild(this.stickyContainer),this.root.appendChild(this.container),this.scrollDirty=!0,this.heightDirty=!0,this.resizeObserver=new ResizeObserver(this.handleResize),this.resizeObserver.observe(this.stickyContainer),this.root.addEventListener(`scroll`,this.handleScroll,{passive:!0}),this.root.addEventListener(`wheel`,this.clearPendingScroll,{passive:!0}),this.root.addEventListener(`touchstart`,this.clearPendingScroll,{passive:!0}),this.root.addEventListener(`pointerdown`,this.clearPendingScroll,{passive:!0}),this.root.addEventListener(`keydown`,this.clearPendingScroll,{passive:!0}),this.resizeObserver.observe(this.root),this.render(!0),window.__INSTANCE=this,window.__TOGGLE=()=>{e.__STOP?(e.__STOP=!1,this.scrollTo({type:`position`,position:e.__lastScrollPosition,behavior:`instant`})):(e.__lastScrollPosition=this.getScrollTop(),e.__STOP=!0)}}reset(){k(this.computeRenderRangeAndEmit),this.clearReadySubscription(),this.restoreScrollInteractions(),this.cleanAllRenderedItems();for(let e of this.itemEditors.values())e.editor.cleanUp();this.itemEditors.clear(),this.attachedEditors.clear(),this.selectedLines=null,this.items.length=0,this.idToItem.clear(),this.instanceToItem.clear(),this.layoutDirtyIndex=void 0,this.pendingLayoutReset=void 0,this.stickyContainer.textContent=``,this.stickyOffset.style.height=``,this.container?.style.removeProperty(`height`),this.containerHeight=-1,this.windowSpecs={top:0,bottom:0},this.pendingLayoutAnchor=void 0,this.shouldFixContainerFocus=!1,this.height=0,this.scrollTop=0,this.scrollPageOffset=0,this.scrollHeight=0,this.scrollDirty=!0,this.heightDirty=!0,this.resetRenderState(),this.isContainerManaged||this.flushSlotCoordinator()}cleanUp(){this.reset(),this.clearElementPool(),this.restoreScrollInteractions(),this.workerManager?.unsubscribeToThemeChanges(this),this.resizeObserver?.disconnect(),this.resizeObserver=void 0,this.root?.removeEventListener(`scroll`,this.handleScroll),this.root?.removeEventListener(`wheel`,this.clearPendingScroll),this.root?.removeEventListener(`touchstart`,this.clearPendingScroll),this.root?.removeEventListener(`pointerdown`,this.clearPendingScroll),this.root?.removeEventListener(`keydown`,this.clearPendingScroll),this.root?.style.removeProperty(`overflow-anchor`),this.container?.remove(),this.stickyOffset.remove(),this.stickyContainer.remove(),this.stickyContainer.textContent=``,this.header.element?.remove(),this.header.element=void 0,this.header.render=void 0,this.header.height=0,this.footer.element?.remove(),this.footer.element=void 0,this.footer.render=void 0,this.footer.height=0,this.root=void 0,this.container=void 0}cleanAllRenderedItems(){if(this.renderState.firstIndex!==-1)for(let e=this.renderState.firstIndex;e<=this.renderState.lastIndex;e++){let t=this.items[e];if(t==null)throw Error(`CodeView.cleanAllRenderedItems: Item does not exist at index: ${e}`);this.releaseRenderedItem(t)}}primeScrollTarget(e){e.type!==`position`&&this.idToItem.get(e.id)?.instance.primeHighlightCache()}getElementPoolLimit(){let e=this.getHeight()+this.config.overscrollSize*2,{diffHeaderHeight:t}=this.itemMetricsCache;return Math.max(8,Math.ceil(e/Math.max(t,10))+1)*(this.isContainerManaged?2:1)}acquireElement(){this.promotePendingPooledElements();let e=this.elementPool.pop();for(;e!=null&&!this.isElementPoolGenerationCurrent(e);)e=this.elementPool.pop();return e??=document.createElement(I),this.markElementPoolGenerationCurrent(e),e}releaseRenderedItem(e){let{element:t}=e;t!=null&&this.renderedItemOwnsFocus(t)&&(this.shouldFixContainerFocus=!0),e.instance.cleanUp(!0),this.attachedEditors.delete(e.item.id),e.element=void 0,t!=null&&(t.remove(),this.cleanElement(t),this.queueElementForPool(t))}renderedItemOwnsFocus(e){let{activeElement:t}=document;return t===e||e.contains(t)||e.shadowRoot?.activeElement!=null}fixContainerFocus(){this.shouldFixContainerFocus&&(this.shouldFixContainerFocus=!1,this.root?.focus({preventScroll:!0}))}cleanElement(e){let{shadowRoot:t}=e;if(t!=null)for(let e of Array.from(t.children))Be(e)||e.remove();this.isContainerManaged||e.replaceChildren()}queueElementForPool(e){let t=this.getElementPoolLimit();!this.isElementPoolGenerationCurrent(e)||this.getElementPoolSize()>=t||(this.isElementClean(e)?this.elementPool.push(e):this.pendingElementPool.push(e))}promotePendingPooledElements(){if(this.pendingElementPool.length===0)return;let{pendingElementPool:e}=this;this.pendingElementPool=[];let t=this.getElementPoolLimit();for(let n of e)this.isElementPoolGenerationCurrent(n)&&this.isElementClean(n)&&this.elementPool.length<t?this.elementPool.push(n):this.isElementPoolGenerationCurrent(n)&&this.getElementPoolSize()<t&&this.pendingElementPool.push(n)}isElementClean(e){return e.childNodes.length===0}getElementPoolSize(){return this.elementPool.length+this.pendingElementPool.length}clearElementPool(){this.elementPool.length=0,this.pendingElementPool.length=0}invalidateElementPool(){this.elementPoolVersion++,this.clearElementPool()}markElementPoolGenerationCurrent(e){this.elementPoolTracker.set(e,this.elementPoolVersion)}isElementPoolGenerationCurrent(e){return this.elementPoolTracker.get(e)===this.elementPoolVersion}resolveEffectiveScrollBehavior(e,t){return me()?`instant`:e.behavior===`smooth-auto`?Math.abs(t-this.getScrollTop())<=this.getHeight()*10?`smooth`:`instant`:e.behavior??`instant`}scrollTo(e){if(this.root==null)return;let t=this.normalizeScrollTarget(e);if(t==null)return;let n=this.resolveScrollTargetTop(t);n!=null&&(this.primeScrollTarget(t),this.resolveEffectiveScrollBehavior(t,n)===`smooth`?this.scrollAnimation??={position:this.getScrollTop(),velocity:0,lastTimestamp:performance.now()}:this.scrollAnimation=void 0,this.suspendScrollInteractions(),this.pendingLayoutAnchor=void 0,this.pendingScrollTarget=t,this.render())}setSelectedLines(e,t){this.applySelectedLines(e,t)}getSelectedLines(){return this.selectedLines}clearSelectedLines(e){this.applySelectedLines(null,e)}getItem(e){return this.idToItem.get(e)?.item}getEditor(e){return this.itemEditors.get(e)?.editor}updateItem(e){let t=this.idToItem.get(e.id);return t==null?(console.error(`CodeView.updateItem: unknown item id "${e.id}"`),!1):this.syncItemRecord(t,e)?(this.markItemLayoutDirty(t),this.scrollDirty=!0,this.render(),this.syncItemEditors(),this.syncSelection(),!0):!1}updateItemId(e,t){if(e===t)return!0;let n=this.idToItem.get(e);if(n==null)return console.error(`CodeView.updateItemId: unknown item id "${e}"`),!1;if(this.idToItem.has(t))return console.error(`CodeView.updateItemId: duplicate item id "${t}"`),!1;this.idToItem.delete(e),n.item.id=t,this.idToItem.set(t,n),this.updateItemOptionsId(n.instance.options,t),this.selectedLines?.id===e&&(this.selectedLines={...this.selectedLines,id:t},this.options.onSelectedLinesChange?.(this.selectedLines));let r=this.itemEditors.get(e);return r!=null&&(r.state.id=t,this.itemEditors.delete(e),this.itemEditors.set(t,r),this.attachedEditors.delete(e)&&this.attachedEditors.add(t)),this.renamePendingScrollTarget(e,t),this.renamePendingLayoutAnchor(e,t),this.render(),!0}addItem(e){this.addItems([e])}addItems(e){this.appendItemsInternal(e),this.syncItemEditors(),this.syncSelection()}removeItem(e){let t=this.idToItem.get(e);if(t==null)return console.error(`CodeView.removeItem: unknown item id "${e}"`),!1;let n=[];for(let e of this.items)e!==t&&n.push(e.item);return this.setItems(n),!0}setItems(e){let t;this.items.length===0?this.appendItemsInternal(e):this.tryAppendItems(e)||(t=this.reconcileItems(e)),this.syncItemEditors(t),this.syncSelection()}appendItemsInternal(e,t=!0){if(e.length===0)return;let n=this.getLayout(),r=this.items.length===0?0:this.scrollHeight+n.gap,i=r;for(let t=0;t<e.length;t++){let i=e[t];if(i==null)throw Error(`CodeView.appendItemsInternal: missing input item`);if(this.idToItem.has(i.id))throw Error(`CodeView.addItem: duplicate id "${i.id}"`);let a=this.createItem(i,this.items.length,r);this.items.push(a),this.idToItem.set(a.item.id,a),this.instanceToItem.set(a.instance,a),a.height=Ie(a),r+=a.height+n.gap}this.scrollHeight=r-n.gap,this.scrollDirty=!0,t&&(this.canSkipRenderForAppend(i)?this.syncContainerHeight():this.render())}canSkipRenderForAppend(e){return this.container!=null&&this.renderState.firstIndex!==-1&&this.pendingScrollTarget==null&&this.scrollAnimation==null&&this.layoutDirtyIndex==null&&e>this.windowSpecs.bottom}onThemeChange(){this.invalidateElementPool()}setOptions(e){if(e==null)return;this.capturePendingLayoutAnchor();let{options:t}=this,n=this.getLayout(),{itemMetricsCache:r}=this;Le(t,e)&&this.invalidateElementPool(),this.options=e;let i=this.computeMetricsCache(e.itemMetrics),a=!A(r,i),o=!A(n,this.getLayout());o&&this.syncLayout();let s=a||Re(t,e);if(s){let n=this.pendingLayoutReset;this.pendingLayoutReset={metrics:a?i:n?.metrics,resetFileLayoutCache:!0,resetDiffLayoutCache:!0,includeEstimatedDiffHeights:n?.includeEstimatedDiffHeights===!0||a||ze(t,e)}}(o||s)&&(this.markLayoutDirtyFromIndex(0),this.scrollDirty=!0),ee(t,e)||this.renderOptionsRevision++,this.syncItemEditors();let c=t.renderCodeViewHeader!==e.renderCodeViewHeader||t.renderCodeViewFooter!==e.renderCodeViewFooter;!this.isContainerManaged&&(this.items.length>0||c)&&this.render()}capturePendingLayoutAnchor(e=this.idToItem){this.root!=null&&this.items.length!==0&&this.pendingScrollTarget==null&&(this.pendingLayoutAnchor=this.getScrollAnchor(this.getScrollTop(),e))}render(t=!1){e.__STOP||(t?(k(this.computeRenderRangeAndEmit),this.computeRenderRangeAndEmit()):j(this.computeRenderRangeAndEmit))}isReady(){let{workerManager:e}=this;return e==null||e.isInitialized()||e.getStats().workersFailed?(this.clearReadySubscription(),!0):(this.isReadySubscription??=e.subscribeToStatChanges(e=>{e.managerState!==`initialized`&&!e.workersFailed||(this.clearReadySubscription(),this.render(!0))}),e.getStats().managerState===`waiting`&&e.initialize().catch(()=>{}),!1)}clearReadySubscription(){this.isReadySubscription!=null&&(this.isReadySubscription(),this.isReadySubscription=void 0)}instanceChanged(e,t){let n=this.instanceToItem.get(e);if(n==null)throw Error(`CodeView.instanceChanged: An instance has changed that is not registered`);t&&this.markItemLayoutDirty(n),this.render()}getWindowSpecs(){return this.windowSpecs}getContainerElement(){return this.root}getHeaderElement(){return this.header.element}getFooterElement(){return this.footer.element}getRenderedItems(){let{firstIndex:e,lastIndex:t}=this.renderState;if(e===-1||t===-1||t<e)return[];let n=[];for(let r=e;r<=t;r++){let e=this.items[r];e?.element!=null&&(e.type===`diff`?n.push({id:e.item.id,type:`diff`,item:e.item,version:e.version,element:e.element,instance:e.instance}):n.push({id:e.item.id,type:`file`,item:e.item,version:e.version,element:e.element,instance:e.instance}))}return n}setSlotCoordinator(e){return e!==this.slotCoordinator&&(this.slotCoordinator=e,this.slotSnapshot=void 0,!0)}getSlotSnapshot(e){return this.buildSlotSnapshot(e)}buildSlotSnapshot(e){let t=Ke(this.getRenderedItems(),e),{element:n}=this.header,{element:r}=this.footer;if(t!=null||n!=null||r!=null)return{items:t,header:n,footer:r}}subscribeToScroll(e){return this.scrollListeners.add(e),()=>{this.scrollListeners.delete(e)}}getLocalTopForInstance(e){let t=this.instanceToItem.get(e);if(t==null)throw Error(`CodeView.getLocalTopForInstance: unknown virtualized instance`);return t.top}getTopForItem(e){let t=this.idToItem.get(e);if(t!=null)return t.top+this.getItemTopOffset()}createItem(e,t,n){let{itemMetricsCache:r}=this;if(e.type===`diff`){let i=new fe(this.createDiffOptions(e.id),this,r,this.workerManager,this.isContainerManaged);return{type:`diff`,item:e,version:e.version,index:t,top:n,height:0,element:void 0,renderedOptionsRevision:this.renderOptionsRevision,instance:i}}let i=new o(this.createFileOptions(e.id),this,r,this.workerManager,this.isContainerManaged);return{type:`file`,item:e,version:e.version,index:t,top:n,height:0,element:void 0,renderedOptionsRevision:this.renderOptionsRevision,instance:i}}applySelectedLines(e,t){let{selectedLines:n}=this;e==null&&n==null||e!=null&&n?.id===e.id&&D(n.range,e.range)||(n!=null&&n.id!==e?.id&&this.idToItem.get(n.id)?.instance.setSelectedLines(null,{notify:!1}),this.selectedLines=e,this.idToItem.get(e?.id??``)?.instance.setSelectedLines(e?.range??null,t))}syncSelection(){if(this.selectedLines==null)return;let e=this.idToItem.get(this.selectedLines.id);if(e==null){this.selectedLines=null,this.options.onSelectedLinesChange?.(null);return}e.instance.setSelectedLines(this.selectedLines.range,{notify:!1})}isItemInEditMode(e){return e.item.edit===!0&&e.item.collapsed!==!0}attachItemEditor(e){let{id:t}=e.item,{createEditor:n}=this.options;if(e.element==null||this.attachedEditors.has(t)||!this.isItemInEditMode(e))return;let r=this.itemEditors.get(t),i=!1;try{if(r==null){Ne(n);let e={id:t},a=n({onChange:(t,n)=>{let r=this.idToItem.get(e.id);r!=null&&(e.lastChange={item:r.item,file:t,lineAnnotations:n},this.options.onItemEditChange?.(r.item,t,n))}});if(a==null)return;r={editor:a,state:e},this.itemEditors.set(t,r),i=!0}r.editor.edit(e.instance),this.attachedEditors.add(t)}catch(n){throw i&&r!=null&&(this.itemEditors.delete(t),r.editor.cleanUp()),this.releaseRenderedItem(e),n}}syncItemEditors(e){if(this.itemEditors.size===0)return;let t=[];for(let[n,r]of this.itemEditors){let i=this.idToItem.get(n),a=e?.get(n);if(a==null&&i!=null&&this.isItemInEditMode(i))continue;r.editor.cleanUp(),this.itemEditors.delete(n),this.attachedEditors.delete(n);let{lastChange:o}=r.state,s=a==null?i?.item??o?.item:o?.item??a.item;s?.type===`diff`&&(a==null&&i!=null&&i.type===`diff`&&i.instance.completeEditSession()&&(this.markItemLayoutDirty(i),this.render()),oe(s.fileDiff)),o!=null&&t.push(a!=null||i==null?o:{...o,item:i.item})}for(let{item:e,file:n,lineAnnotations:r}of t)this.options.onItemEditComplete?.(e,n,r)}renamePendingScrollTarget(e,t){let{pendingScrollTarget:n}=this;n!=null&&n.type!==`position`&&n.id===e&&(this.pendingScrollTarget={...n,id:t})}renamePendingLayoutAnchor(e,t){this.pendingLayoutAnchor?.id===e&&(this.pendingLayoutAnchor.id=t)}createFileOptionsPrototype(){let e={};for(let t of ye)X(e,t,()=>this.options[t]);X(e,`stickyHeader`,()=>this.options.stickyHeaders),X(e,`collapsed`,e=>{let t=we(e);if(t!=null)return this.getItemOptions(t,`file`)?.item.collapsed});for(let t of be)this.defineItemSharedCallback(e,`file`,t);for(let t of xe)this.defineItemSelectionCallback(e,`file`,t);return e}createDiffOptionsPrototype(){let e={};for(let t of ve)X(e,t,()=>this.options[t]);X(e,`stickyHeader`,()=>this.options.stickyHeaders),X(e,`hunkSeparators`,()=>this.options.hunkSeparators),X(e,`collapsed`,e=>{let t=we(e);if(t!=null)return this.getItemOptions(t,`diff`)?.item.collapsed});for(let t of be)this.defineItemSharedCallback(e,`diff`,t);for(let t of xe)this.defineItemSelectionCallback(e,`diff`,t);return e}createFileOptions(e){let t=Object.create(this.fileOptionsPrototype);return Ce(t,{id:e}),t}createDiffOptions(e){let t=Object.create(this.diffOptionsPrototype);return Ce(t,{id:e}),t}updateItemOptionsId(e,t){let n=we(e);if(n==null)throw Error(`CodeView.updateItemOptionsId: No valid state`);n.id=t}getItemOptions(e,t){let n=this.idToItem.get(e.id);if(n!=null&&n.type===t)return n}defineItemSharedCallback(e,t,n){X(e,n,e=>{if(this.options[n]==null)return;let r=we(e);if(r==null)return;let i=r.callbackCache??={},a=i[n];return a??(a=((...e)=>{let i=this.getItemOptions(r,t);if(i==null)return;let a=this.options[n];return a?.(...e,i)}),i[n]=a),a})}defineItemSelectionCallback(e,t,n){X(e,n,e=>{let r=we(e);if(r==null)return;let i=r.callbackCache??={},a=i[n];return a??(a=(e=>{let i=this.getItemOptions(r,t);if(i==null)return;let a=e==null?null:{id:i.item.id,range:e};this.options.controlledSelection!==!0&&(e!=null||this.selectedLines?.id===i.item.id)&&this.applySelectedLines(a,{notify:!1}),this.options.onSelectedLinesChange?.(a);let o=this.options[n];return o?.(e,i)}),i[n]=a),a})}markLayoutDirtyFromIndex(e){this.layoutDirtyIndex=Math.min(this.layoutDirtyIndex??e,e)}markItemLayoutDirty(e){if(this.items[e.index]!==e)throw Error(`CodeView.markItemLayoutDirty: unknown item id "${e.item.id}"`);this.markLayoutDirtyFromIndex(e.index)}tryAppendItems(e){if(e.length<=this.items.length)return!1;for(let t=0;t<this.items.length;t++){let n=this.items[t];if(n==null)throw Error(`CodeView.tryAppendItems: missing existing item`);let r=e[t];if(r==null||n.item.id!==r.id||n.type!==r.type)return!1}for(let t=0;t<this.items.length;t++){let n=this.items[t];if(n==null)throw Error(`CodeView.tryAppendItems: missing existing item`);let r=e[t];if(r==null)throw Error(`CodeView.tryAppendItems: append candidate missing prefix item`);this.syncItemRecord(n,r)&&this.markLayoutDirtyFromIndex(t)}return this.appendItemsInternal(e.slice(this.items.length),!1),this.scrollDirty=!0,this.render(),!0}reconcileItems(e){let{items:t,idToItem:n}=this,r=new Set(t),i=[],a=new Map,o=new Map,s=new Map,c;for(let s=0;s<e.length;s++){let l=e[s];if(l==null)throw Error(`CodeView.reconcileItems: missing input item`);if(a.has(l.id))throw Error(`CodeView.setItems: duplicate id "${l.id}"`);let u=n.get(l.id),d=u!=null&&u.type===l.type?u:this.createItem(l,s,0);d.index=s,u!=null&&u.type===l.type?(r.delete(u),this.syncItemRecord(d,l)&&(c=Math.min(c??s,s))):c=Math.min(c??s,s),t[s]!==d&&(c=Math.min(c??s,s)),i.push(d),a.set(l.id,d),o.set(d.instance,d)}if(c==null){if(r.size===0)return;c=Math.max(i.length-1,0)}this.capturePendingLayoutAnchor(a);for(let e=0;e<t.length;e++){let n=t[e];if(n==null||!r.has(n))continue;s.set(n.item.id,n),this.releaseRenderedItem(n);let a=Math.max(i.length-1,0);c=Math.min(c??a,a)}return this.items=i,this.idToItem=a,this.instanceToItem=o,this.renderState.firstIndex>=i.length?this.resetRenderState():this.renderState.lastIndex>=i.length&&(this.renderState.lastIndex=i.length-1),this.markLayoutDirtyFromIndex(c),this.scrollDirty=!0,this.render(),s.size>0?s:void 0}syncItemRecord(e,t){if(e.type!==t.type)throw Error(`CodeView.syncItemRecord: type mismatch for id "${t.id}"`);return e.version!==t.version&&(e.item=t,e.version=t.version,e.renderedOptionsRevision=-1,!0)}getMaxScrollTopForHeight(e){let{paddingBottom:t,paddingTop:n}=this.getLayout();return Math.max(n+this.header.height+e+this.footer.height+t-this.getHeight(),0)}getMaxScrollTop(){return this.getMaxScrollTopForHeight(this.getScrollHeight())}shouldRebaseScroll(){return this.getMaxScrollTop()>Me}getPagedScrollHeight(){return this.shouldRebaseScroll()?Math.min(this.getScrollHeight(),Oe):this.getScrollHeight()}getMaxPagedScrollTop(){return this.getMaxScrollTopForHeight(this.getPagedScrollHeight())}clampPagedScrollTop(e){let t=this.getMaxPagedScrollTop();return Math.max(0,Math.min(e,t))}clampScrollTop(e){let t=this.getMaxScrollTop();return Math.max(0,Math.min(e,t))}getMaxScrollPageOffset(){return Math.max(this.getMaxScrollTop()-this.getMaxPagedScrollTop(),0)}clampScrollPageOffset(e){let t=this.getMaxScrollPageOffset();return Math.max(0,Math.min(e,t))}resolveScrollPageWindow(e,t){let n=Y(this.clampPagedScrollTop(t)),r=this.clampScrollPageOffset(e-n);return n=Y(this.clampPagedScrollTop(e-r)),r=this.clampScrollPageOffset(e-n),{pagedScrollTop:n,scrollPageOffset:r}}resolvePagedScrollPosition(e){if(!this.shouldRebaseScroll())return{pagedScrollTop:this.clampPagedScrollTop(e),scrollPageOffset:0};let t=this.clampScrollPageOffset(this.scrollPageOffset),n=e-t,r=this.getMaxPagedScrollTop(),i=this.getMaxScrollPageOffset(),a=n>Me&&t<i,o=n<ke&&t>0;return n<0||n>r||a||o?this.resolveScrollPageWindow(e,o?Math.min(je,r):Ae):{pagedScrollTop:Y(this.clampPagedScrollTop(n)),scrollPageOffset:t}}needsScrollPageUpdate(e){let t=Y(this.clampScrollTop(e)),{scrollPageOffset:n}=this.resolvePagedScrollPosition(t);return n!==this.scrollPageOffset}getPagedLayoutTop(e){return this.shouldRebaseScroll()?Math.max(e-this.scrollPageOffset,0):e}getStickyHeaderOffset(){return this.options.stickyHeaders===!0&&this.options.disableFileHeader!==!0?this.itemMetricsCache.diffHeaderHeight:0}getScrollTargetRect(e){let t=this.idToItem.get(e.id);if(t==null){console.warn(`CodeView.scrollTo: unknown item id "${e.id}"`);return}if(e.type===`item`)return{top:t.top,height:t.height};if(e.type===`range`){let n=this.getRangeScrollPosition(t,e);if(n==null){console.warn(`CodeView.scrollTo: unable to resolve range ${Ve(e.range)} for item "${e.id}"`);return}return{top:t.top+n.top,height:n.height}}let n=this.getLineScrollPosition(t,e);if(n==null){console.warn(`CodeView.scrollTo: unable to resolve line ${e.lineNumber} for item "${e.id}"`);return}return{top:t.top+n.top,height:n.height}}normalizeScrollTarget(e){if(e.type===`position`||e.align!==`nearest`)return e;let t=this.getScrollTargetRect(e);if(t==null)return;let n=e.offset??0,r=this.getItemTopOffset()+t.top,i=r+t.height,a=this.getScrollTop(),o=a+(e.type===`line`||e.type===`range`?this.getStickyHeaderOffset():0),s=a+this.getHeight();if(!(r-n<=o&&i+n>=s)){if(r-n<o)return{...e,align:`start`};if(i+n>s)return{...e,align:`end`}}}resolveScrollTargetTop(e){if(e.type===`position`){let t=this.clampScrollTop(e.position);return t===e.position?this.clampScrollTop(e.position-this.getStickyHeaderOffset()):t}let t=this.idToItem.get(e.id);if(t==null){console.warn(`CodeView.scrollTo: unknown item id "${e.id}"`);return}if(e.type===`item`)return this.clampScrollTop(this.resolveAlignedScrollPosition(t.top,t.height,e.align,e.offset));if(e.type===`range`){let n=this.getRangeScrollPosition(t,e);if(n==null){console.warn(`CodeView.scrollTo: unable to resolve range ${Ve(e.range)} for item "${e.id}"`);return}return this.clampScrollTop(this.resolveAlignedScrollPosition(t.top+n.top,n.height,e.align,e.offset,this.getStickyHeaderOffset()))}let n=this.getLineScrollPosition(t,e);if(n==null){console.warn(`CodeView.scrollTo: unable to resolve line ${e.lineNumber} for item "${e.id}"`);return}return this.clampScrollTop(this.resolveAlignedScrollPosition(t.top+n.top,n.height,e.align,e.offset,this.getStickyHeaderOffset()))}resolveAlignedScrollPosition(e,t,n,r=0,i=0){e+=this.getItemTopOffset();let a=this.getHeight();return n===`center`&&t+r<a?e-(a-t)/2+r:n===`end`?e-(a-t)+r:e-i-r}getLineScrollPosition(e,t){return e.type===`diff`?e.instance.getLinePosition(t.lineNumber,t.side):e.instance.getLinePosition(t.lineNumber)}getRangeScrollPosition(e,t){let{range:n}=t,r=this.getLineScrollPosition(e,{type:`line`,id:t.id,lineNumber:n.start,side:n.side}),i=this.getLineScrollPosition(e,{type:`line`,id:t.id,lineNumber:n.end,side:n.endSide??n.side});if(r==null||i==null)return;let a=r.top,o=a+r.height,s=i.top,c=s+i.height,l=Math.min(a,s);return{top:l,height:Math.max(o,c)-l}}computeTargetScrollTopForFrame(e,t){if(this.pendingScrollTarget==null)return e;let n=this.resolveScrollTargetTop(this.pendingScrollTarget);if(n==null)return e;let{scrollAnimation:r}=this;return r==null?n:this.computeSpringStep(r,n,t).position}computeSpringStep(e,t,n){let r=Math.max(0,n-e.lastTimestamp),{omega:i}=this.getSmoothScrollSettings(),a=Math.exp(-i*r),o=e.position-t,s=e.velocity+i*o;return{position:t+(o+s*r)*a,velocity:(s*(1-i*r)-i*o)*a}}advanceScrollAnimation(e,t){if(this.pendingScrollTarget==null)return;let n=this.resolveScrollTargetTop(this.pendingScrollTarget);if(n==null){this.pendingScrollTarget=void 0,this.scrollAnimation=void 0;return}let r=this.scrollAnimation;if(r==null)return n;r.position+=t;let{position:i,velocity:a}=this.computeSpringStep(r,n,e);r.lastTimestamp=e,r.position=i,r.velocity=a;let{positionEpsilon:o,velocityEpsilon:s}=this.getSmoothScrollSettings();return Math.abs(n-i)<=o&&Math.abs(a)<=s?(r.position=n,r.velocity=0,this.scrollAnimation=void 0,n):r.position}computeRenderRangeAndEmit=(t=performance.now())=>{if(e.__STOP||this.container==null||!this.isReady())return;let n=this.getHeight(),r=this.getScrollTop(),i=r,a=this.pendingLayoutAnchor!=null,o=this.getScrollAnchor(i);if(this.layoutDirtyIndex!=null&&(this.recomputeLayout(this.layoutDirtyIndex,this.pendingLayoutReset),this.layoutDirtyIndex=void 0,this.pendingLayoutReset=void 0,a=!0),a&&o!=null){let e=this.resolveAnchoredScrollTop(o);if(e!=null){let t=e-i;i=e,this.scrollAnimation!=null&&(this.scrollAnimation.position+=t)}}a&&(i=this.clampScrollTop(i),this.syncContainerHeight());let s=this.computeTargetScrollTopForFrame(i,t),c=!a&&(this.renderState.scrollTop===-1||Math.abs(s-this.renderState.scrollTop)>n+this.config.overscrollSize*2);c&&(o=void 0),this.windowSpecs=w({scrollTop:s-this.header.height,height:n,scrollHeight:this.getScrollHeight(),fitPerfectly:c,fitPerfectlyOverscroll:this.getFitPerfectlyOverscroll(),overscrollSize:this.config.overscrollSize});let l=r;(this.pendingScrollTarget!=null&&s!==l||this.needsScrollPageUpdate(s))&&(this.applyScrollFix(s,l,this.windowSpecs),l=s);let{top:u,bottom:d}=this.windowSpecs,{firstIndex:f,lastIndex:p}=this.renderState;if(f>=0)for(let e=f;e<=p;e++){let t=this.items[e];if(t==null)throw Error(`CodeView.computeRenderRangeAndEmit: No item at index: ${e}`);t.top>u-t.height&&t.top<=d||this.releaseRenderedItem(t)}let m=this.reconcileHeaderFooterHosts(),h,g=new Set,_=this.findFirstVisibleIndex(u),v=this.findLastVisibleIndex(d);for(let e=_;e<=v;e++){let t=this.items[e];if(t==null)throw Error(`CodeView.computeRenderRangeAndEmit: missing item`);let{instance:n}=t;t.element==null?(t.element=this.acquireElement(),We(this.stickyContainer,t.element,h),n.virtualizedSetup(),Ue(t,t.element)&&(t.renderedOptionsRevision=this.renderOptionsRevision,g.add(t)),h=t.element):(We(this.stickyContainer,t.element,h),Ue(t,void 0,t.renderedOptionsRevision!==this.renderOptionsRevision)&&(t.renderedOptionsRevision=this.renderOptionsRevision,g.add(t)),h=t.element),t.item.edit===!0&&this.attachItemEditor(t)}this.renderState.firstIndex=_<=v?_:-1,this.renderState.lastIndex=v,this.flushSlotCoordinator(),this.flushManagers(g),m&&this.measureMountedHosts(),this.reconcileRenderedItems(g),this.syncContainerHeight(),this.updateStickyPositioning();let y=o==null?void 0:this.resolveAnchoredScrollTop(o);o===this.pendingLayoutAnchor&&(this.pendingLayoutAnchor=void 0);let b=y==null?0:y-i,x=s,S=!1;if(this.pendingScrollTarget!=null){let e=this.advanceScrollAnimation(t,b);e==null?x=i:(x=e,S=!0)}else x=y??s;x!==l&&(this.applyScrollFix(x,l,this.windowSpecs),l=x),S&&this.pendingScrollTarget!=null&&this.isPendingTargetSettled(this.pendingScrollTarget)&&(this.pendingScrollTarget=void 0,this.scrollAnimation=void 0),this.renderState.scrollTop=Y(l),this.updateStickyPositioning(),this.validateStickyContainerHeight(),this.fixContainerFocus(),(c||this.scrollAnimation!=null)&&this.render()};flushManagers(e){for(let t of e)t.instance.flushManagers()}syncContainerHeight(){let e=this.getPagedScrollHeight();this.container!=null&&this.containerHeight!==e&&(this.container.style.height=`${e}px`,this.containerHeight=e)}getStickyBounds(e){let{firstIndex:t,lastIndex:n}=e==null?this.renderState:{firstIndex:this.findFirstVisibleIndex(e.top),lastIndex:this.findLastVisibleIndex(e.bottom)};if(t===-1||n===-1||t>n)return;let r=this.items[t]?.instance.getAdvancedStickySpecs(e),i=this.items[n]?.instance.getAdvancedStickySpecs(e);if(r!=null&&i!=null)return{stickyTop:this.getPagedLayoutTop(Math.max(r.topOffset,0)),stickyBottom:this.getPagedLayoutTop(i.topOffset+i.height)}}applyStickyPositioning({stickyTop:e,stickyBottom:t}){let n=this.getHeight(),{itemMetricsCache:r}=this,i=t-e;this.renderState.stickyHeight=i,this.renderState.stickyTop=e,this.renderState.stickyBottom=t,this.stickyOffset.style.height=`${e}px`;let a=(Math.random()*r.lineHeight>>0)*-1,o=-Math.max(i+a,0)+n;this.stickyContainer.style.top=`${o}px`,this.stickyContainer.style.bottom=`${o+r.diffHeaderHeight}px`}syncPagedScrollScaffolding(e){this.syncContainerHeight();let t=this.getStickyBounds(e);t!=null&&this.applyStickyPositioning(t)}reconcileRenderedItems(e){let{firstIndex:t,lastIndex:n}=this.renderState;if(t===-1)return;let r=-1,i=!1;for(let a=t;a<this.items.length&&!(!i&&a>n);a++){let t=this.items[a];if(t==null)throw Error(`CodeView.reconcileRenderedItems: Invalid item`);r===-1?r=t.top:t.top!==r&&(t.top=r,t.instance.syncVirtualizedTop(),i=!0),(e==null?a<=n:e.has(t))&&(t.instance.reconcileHeights()&&(i=!0,t.height=t.instance.getVirtualizedHeight()),this.validateRenderedItemHeight(t)),r+=t.instance.getVirtualizedHeight(),a<this.items.length-1&&(r+=this.getLayout().gap)}i&&r!=null&&(this.scrollDirty=!0,this.scrollHeight=r)}updateStickyPositioning(){let e=this.getStickyBounds();if(e==null){this.renderState.firstIndex===-1&&(this.stickyOffset.style.height=``);return}let{stickyTop:t,stickyBottom:n}=e;(n-t!==this.renderState.stickyHeight||t!==this.renderState.stickyTop||n!==this.renderState.stickyBottom)&&this.applyStickyPositioning(e)}handleScroll=()=>{e.__STOP||(this.suspendScrollInteractions(),this.scrollDirty=!0,this.notifyScroll(),this.render())};clearPendingScroll=()=>{this.pendingScrollTarget=void 0,this.pendingLayoutAnchor=void 0,this.scrollAnimation=void 0};handleResize=e=>{let t=!1;for(let n of e)if(n.target===this.stickyContainer){let e=n.borderBoxSize[0].blockSize;if(Math.abs(e-this.renderState.stickyHeight)>=Ee){let e=this.getScrollTop(),n=this.getScrollAnchor(e);this.reconcileRenderedItems(),this.updateStickyPositioning();let r=n==null?void 0:this.resolveAnchoredScrollTop(n);if(r!=null){let t=r-e;this.applyScrollFix(r,e,this.windowSpecs),this.scrollAnimation!=null&&(this.scrollAnimation.position+=t)}this.pendingScrollTarget!=null&&this.isPendingTargetSettled(this.pendingScrollTarget)&&(this.pendingScrollTarget=void 0,this.scrollAnimation=void 0),t=!0}}else if(n.target===this.header.element||n.target===this.footer.element){let e=n.target===this.header.element?this.header:this.footer,r=n.borderBoxSize[0].blockSize;if(r!==e.height){let n=this.getScrollTop(),i=this.getScrollAnchor(n);this.setHostHeight(e,r);let a=i==null?void 0:this.resolveAnchoredScrollTop(i);if(a!=null){let e=a-n;this.applyScrollFix(a,n,this.windowSpecs),this.scrollAnimation!=null&&(this.scrollAnimation.position+=e)}this.pendingScrollTarget!=null&&this.isPendingTargetSettled(this.pendingScrollTarget)&&(this.pendingScrollTarget=void 0,this.scrollAnimation=void 0),t=!0}}else this.scrollDirty=!0,this.heightDirty=!0,t=!0;t&&this.render(!0)};getScrollAnchorViewportTop(e,t){return e<t?t+this.getStickyHeaderOffset():t}getScrollAnchor(e,t=this.idToItem){let n,{pendingLayoutAnchor:r}=this;if(r!=null){let e=this.idToItem.get(r.id);if(e!=null&&t.get(r.id)===e)return r;e!=null&&(n=e)}if(e<=0)return;let{firstIndex:i,lastIndex:a,stickyTop:o,stickyBottom:s}=this.renderState;if(i===-1||a===-1)return;let c=this.getHeight();if(o!==-1&&s!==-1){for(let r=i;r<=a;r++){let i=this.items[r];if(i==null)continue;let a=this.getItemTopOffset()+i.top;if(a+i.height<=e)continue;if(a>=e+c)break;if(t.get(i.item.id)!==i){n??=i;continue}if(a>=e)return{type:`item`,id:i.item.id,viewportOffset:a-e};let o=this.getScrollAnchorViewportTop(a,e)-a,s=i.instance.getNumericScrollAnchor(o);if(s!=null){let t=a+s.top;return{type:`line`,id:i.item.id,lineNumber:s.lineNumber,side:s.side,viewportOffset:t-e}}}if(n!=null)for(let e=n.index+1;e<this.items.length;e++){let n=this.items[e];if(n!=null&&t.get(n.item.id)===n)return{type:`item`,id:n.item.id,viewportOffset:0}}}}resolveAnchoredScrollTop(e){let t=this.idToItem.get(e.id);if(t==null)return;let n=this.getItemTopOffset();if(e.type===`item`){let r=n+t.top;return this.clampScrollTop(r-e.viewportOffset)}let r=t.type===`diff`?t.instance.getLinePosition(e.lineNumber,e.side):t.instance.getLinePosition(e.lineNumber);if(r==null)return;let i=n+t.top+r.top;return this.clampScrollTop(i-e.viewportOffset)}applyScrollFix(e,t,n){if(this.root==null)return;let r=Y(this.clampScrollTop(e)),i=Y(t),{scrollPageOffset:a}=this,o=Y(this.clampPagedScrollTop(i-a)),{pagedScrollTop:s,scrollPageOffset:c}=this.resolvePagedScrollPosition(r),l=s,u=a!==c;r===this.renderState.scrollTop&&r===i&&l===o&&!u||(this.suspendScrollInteractions(),(l!==o||u)&&(this.scrollPageOffset=c,this.syncPagedScrollScaffolding(n)),l!==o&&this.root.scrollTo({top:l,behavior:`instant`}),this.renderState.scrollTop=r,this.scrollTop=r,this.scrollDirty=!1)}isPendingTargetSettled(e){let t=this.resolveScrollTargetTop(e);return t==null||Y(this.getScrollTop())===Y(t)}getScrollTop(){if(!this.scrollDirty)return this.scrollTop;this.scrollDirty=!1;let e=this.root?.scrollTop??0;return this.scrollTop=this.clampScrollTop(e+this.scrollPageOffset),this.scrollTop}getHeight(){return this.heightDirty?(this.heightDirty=!1,this.height=this.root?.getBoundingClientRect().height??0,this.height):this.height}getScrollHeight(){return this.scrollHeight}flushSlotCoordinator(){if(this.slotCoordinator==null)return;let e=this.buildSlotSnapshot(this.slotCoordinator);he(this.slotSnapshot,e)||(this.slotSnapshot=e,this.slotCoordinator.onSnapshotChange(e))}notifyScroll(){if(this.scrollListeners.size===0)return;let e=this.getScrollTop();for(let t of this.scrollListeners)t(e,this)}findFirstVisibleIndex(e){let t=0,n=this.items.length-1,r=this.items.length;for(;t<=n;){let i=t+n>>1,a=this.items[i];if(a==null)throw Error(`CodeView.findFirstVisibleIndex: invalid item index`);a.top+a.height>e?(r=i,n=i-1):t=i+1}return r}findLastVisibleIndex(e){let t=0,n=this.items.length-1,r=-1;for(;t<=n;){let i=t+n>>1,a=this.items[i];if(a==null)throw Error(`CodeView.findLastVisibleIndex: invalid item index`);a.top<=e?(r=i,t=i+1):n=i-1}return r}recomputeLayout(e=0,t){if(this.items.length===0){this.scrollHeight=0;return}let n=this.getLayout(),r=0;if(e>0){let t=this.items[e-1];if(t==null)throw Error(`CodeView.recomputeLayout: invalid dirty index`);r=t.top+t.height+n.gap}for(let i=e;i<this.items.length;i++){let e=this.items[i];if(e==null)throw Error(`CodeView.recomputeLayout: invalid item index`);if(e.top=r,e.type===`diff`){let n=e.instance.consumeCodeViewLayoutChanges(e.item.fileDiff);n!=null&&Object.assign(e.item.fileDiff,n),e.height=e.instance.prepareCodeViewItem(e.item.fileDiff,r,t,e.item.annotations??[])}else e.height=e.instance.prepareCodeViewItem(e.item.file,r,t,e.item.annotations??[]);r+=e.height,i<this.items.length-1&&(r+=n.gap)}r!==this.scrollHeight&&(this.scrollDirty=!0),this.scrollHeight=r}resetRenderState(){this.renderState.scrollTop=-1,this.renderState.firstIndex=-1,this.renderState.lastIndex=-1,this.renderState.stickyHeight=0,this.renderState.stickyTop=-1,this.renderState.stickyBottom=-1}getFitPerfectlyOverscroll(){return this.getLayout().gap+this.itemMetricsCache.diffHeaderHeight}};function Ie(e){return e.instance.cleanUp(!0),e.type===`diff`?e.instance.prepareCodeViewItem(e.item.fileDiff,e.top,void 0,e.item.annotations??[]):e.instance.prepareCodeViewItem(e.item.file,e.top,void 0,e.item.annotations??[])}function Le(e,t){return!E(e.theme??N,t.theme??N)||(e.themeType??`system`)!==(t.themeType??`system`)||e.unsafeCSS!==t.unsafeCSS}function Re(e,t){return(e.overflow??`scroll`)!==(t.overflow??`scroll`)||(e.disableLineNumbers??!1)!==(t.disableLineNumbers??!1)||(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||e.unsafeCSS!==t.unsafeCSS||(e.diffStyle??`split`)!==(t.diffStyle??`split`)||(e.diffIndicators??`bars`)!==(t.diffIndicators??`bars`)||(e.hunkSeparators??`line-info`)!==(t.hunkSeparators??`line-info`)||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)}function ze(e,t){return(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||(e.hunkSeparators??`line-info`)!==(t.hunkSeparators??`line-info`)||(e.expandUnchanged??!1)!==(t.expandUnchanged??!1)||(e.collapsedContextThreshold??1)!==(t.collapsedContextThreshold??1)}function Be(e){return e instanceof SVGElement||T(e)&&(e.hasAttribute(`data-core-css`)||e.hasAttribute(`data-theme-css`)||e.hasAttribute(`data-unsafe-css`))}function Ve(e){let t=He(e.start,e.side),n=He(e.end,e.endSide??e.side);return t===n?t:`${t}-${n}`}function He(e,t){return t==null?`${e}`:`${t===`deletions`?`D`:`A`}${e}`}function Ue(e,t,n=!1){return e.type===`diff`?e.instance.render({deferManagers:!0,fileContainer:t,fileDiff:e.item.fileDiff,forceRender:n,lineAnnotations:e.item.annotations??[]}):e.instance.render({deferManagers:!0,fileContainer:t,file:e.item.file,forceRender:n,lineAnnotations:e.item.annotations??[]})}function We(e,t,n){if(n==null){e.firstChild!==t&&e.prepend(t);return}n.nextSibling!==t&&n.after(t)}function Ge(e){return(e.annotations?.length??0)>0}function Ke(e,{hasHeaderRenderers:t,hasAnnotationRenderer:n,hasGutterRenderer:r}){if(e.length===0)return;if(t||r)return e;if(!n)return;let i=[];for(let t of e)Ge(t.item)&&i.push(t);return i.length>0?i:void 0}var Z=e(r(),1),qe=e(i(),1),Q=n(),Je=typeof window>`u`?Z.useEffect:Z.useLayoutEffect;function Ye(e){return{instance:void 0,items:void 0,controlled:e,managedOptions:void 0,disableFlushSync:!1,slotCoordinator:void 0}}function Xe(e,t){let{className:n,containerRef:r,disableWorkerPool:i=!1,editorOptions:a,initialItems:o,items:s,onItemEditChange:c,onItemEditComplete:l,onScroll:u,onSelectedLinesChange:d,options:f,renderAnnotation:p,renderCodeViewFooter:m,renderCodeViewHeader:h,renderCustomHeader:g,renderGutterUtility:_,renderHeaderFilenameSuffix:v,renderHeaderMetadata:y,renderHeaderPrefix:b,selectedLines:x,style:S}=e,C=s!==void 0,w=te(),T=(0,Z.useContext)(H),E=(0,Z.useRef)(Ye(C)),D=g!=null,O=p!=null,k=_!=null,A=D||b!=null||v!=null||y!=null,j=A||O||k,N=h!=null,P=m!=null,F=M(e=>{d?.(e)}),I=x!==void 0,L=M(e=>{if(w==null)throw Error(`CodeView: EditContext is not attached`);let t=w({...a,...e});if(t==null)throw Error(`CodeView: EditProvider.createEditor must return an editor instance`);return t}),R=M((e,t,n)=>{c?.(e,t,n)}),z=M((e,t,n)=>{l?.(e,t,n)}),B=(0,Z.useMemo)(()=>nt({options:f,hasCustomHeader:D,hasGutterRenderer:k,hasCodeViewHeader:N,hasCodeViewFooter:P,onSelectedLinesChange:d==null?void 0:F,controlledSelection:I,createEditor:w==null?void 0:L,onItemEditChange:c==null?void 0:R,onItemEditComplete:l==null?void 0:z}),[w,I,L,R,z,F,P,N,D,k,c,l,d,f]),[V]=(0,Z.useState)(()=>tt()),[,ne]=(0,Z.useState)({}),U=M(e=>{E.current.instance!=null&&(e==null||e!==E.current.instance.getContainerElement())&&(E.current.instance.cleanUp(),V.publish(void 0),E.current=Ye(C)),e!=null&&e!==E.current.instance?.getContainerElement()&&(E.current.instance=new Fe(B,i?void 0:T,!0),E.current.instance.setup(e)),typeof r==`function`?r(e):r!=null&&(r.current=e)}),W=M(e=>{E.current.disableFlushSync?V.publish(e):(0,qe.flushSync)(()=>{V.publish(e)})}),G=(0,Z.useMemo)(()=>{if(!(!A&&!O&&!k&&!N&&!P))return{hasHeaderRenderers:A,hasAnnotationRenderer:O,hasGutterRenderer:k,onSnapshotChange:W}},[W,O,k,A,N,P]);return Je(()=>u==null?void 0:E.current.instance?.subscribeToScroll(u)),Je(()=>{let{instance:e,controlled:t,items:n,managedOptions:r,slotCoordinator:i}=E.current;if(e!=null)try{E.current.disableFlushSync=!0;let a=!1;if(ee(B,r)||(E.current.managedOptions=B,e.setOptions(B),a=!0),t!==C){console.error(`CodeView: cannot switch between controlled and uncontrolled modes. Remount with a new key instead.`);return}if(C)s!==n&&($e(n,s)?E.current.items=s:Qe(n,s)?(E.current.items=s,e.addItems(s.slice(n.length))):(E.current.items=s,e.setItems(s),a=!0));else if(n==null){let t=o??[];E.current.items=t,t.length>0&&(e.setItems(t),a=!0)}x!==void 0&&e.setSelectedLines(x,{notify:!1});let c=e.setSlotCoordinator(G),l=!1;G!==i&&((G==null||i==null)&&(l=!0),E.current.slotCoordinator=G),(a||c)&&e.render(!0),c&&G==null&&V.publish(void 0),l&&ne({})}finally{E.current.disableFlushSync=!1}}),(0,Z.useImperativeHandle)(t,()=>({addItems(e){let{controlled:t,instance:n}=E.current;et(t,`addItems`),n==null?console.error(`CodeView.addItems: no valid instance to append items with`,e):n.addItems(e)},getItem(e){let{instance:t}=E.current;if(t==null){console.error(`CodeView.getItem: no valid instance exists`,e);return}return t.getItem(e)},removeItem(e){let{controlled:t,instance:n}=E.current;return et(t,`removeItem`),n==null?(console.error(`CodeView.removeItem: no valid instance to remove item from`,e),!1):n.removeItem(e)},updateItem(e){let{controlled:t,instance:n}=E.current;return et(t,`updateItem`),n==null?(console.error(`CodeView.updateItem: no valid instance to update item with`,e),!1):n.updateItem(e)},updateItemId(e,t){let{controlled:n,instance:r}=E.current;return et(n,`updateItemId`),r==null?(console.error(`CodeView.updateItemId: no valid instance to update item id with`,e,t),!1):r.updateItemId(e,t)},scrollTo(e){let{instance:t}=E.current;t==null?console.error(`CodeView.scrollTo: no valid instance to scroll with`,e):t.scrollTo(e)},setSelectedLines(e){let{instance:t}=E.current;t==null?console.error(`CodeView.setSelectedLines: no valid instance to update selection with`,e):(t.setSelectedLines(e,{notify:!1}),F(e))},getSelectedLines(){let{instance:e}=E.current;return e==null?(console.error(`CodeView.getSelectedLines: no valid instance exists`),null):e.getSelectedLines()},clearSelectedLines(){let{instance:e}=E.current;e==null?console.error(`CodeView.clearSelectedLines: no valid instance to update selection with`):(e.clearSelectedLines({notify:!1}),F(null))},getEditor(e){let{instance:t}=E.current;if(t==null){console.error(`CodeView.getEditor: no valid instance exists`,e);return}return t.getEditor(e)},getInstance(){return E.current.instance}}),[F]),(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{ref:U,className:n,style:S}),(j||N||P)&&(0,Q.jsx)(rt,{managedContentStore:V,renderCustomHeader:g,renderHeaderPrefix:b,renderHeaderFilenameSuffix:v,renderHeaderMetadata:y,renderAnnotation:p,renderGutterUtility:_,renderCodeViewHeader:h,renderCodeViewFooter:m})]})}var Ze=(0,Z.forwardRef)(Xe);function Qe(e,t){if(e==null||t.length<=e.length)return!1;if(e.length===0)return!0;for(let n=0;n<e.length;n++)if(t[n]!==e[n])return!1;return!0}function $e(e,t){if(e==null||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function et(e,t){if(e)throw Error(`CodeView.${t} cannot be used when CodeView is controlled. Use initialItems for imperative item updates.`)}function tt(){let e,t=new Set;return{getSnapshot(){return e},publish(n){if(!he(e,n)){e=n;for(let e of t)e()}},subscribe(e){return t.add(e),()=>{t.delete(e)}}}}function nt({options:e,hasCustomHeader:t,hasGutterRenderer:n,hasCodeViewHeader:r,hasCodeViewFooter:i,onSelectedLinesChange:a,controlledSelection:o,createEditor:s,onItemEditChange:c,onItemEditComplete:l}){let u={...e,controlledSelection:o,onSelectedLinesChange:a,createEditor:s};return c!=null&&(u.onItemEditChange=c),l!=null&&(u.onItemEditComplete=l),t&&(u.renderCustomHeader=at),n&&(u.renderGutterUtility=at),r&&(u.renderCodeViewHeader=at),i&&(u.renderCodeViewFooter=at),u}var rt=(0,Z.memo)(function({managedContentStore:e,renderCustomHeader:t,renderHeaderPrefix:n,renderHeaderFilenameSuffix:r,renderHeaderMetadata:i,renderAnnotation:a,renderGutterUtility:o,renderCodeViewHeader:s,renderCodeViewFooter:c}){"use no memo";let l=M(t=>e.subscribe(t)),u=M(()=>e.getSnapshot()),d=(0,Z.useSyncExternalStore)(l,u,u),f=``;for(let e of d?.items??[])f+=`${e.id}:${e.version}:${e.type}`;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Z.useMemo)(()=>d?.items?.map(e=>(0,qe.createPortal)(it({renderedItem:e,renderCustomHeader:t,renderHeaderPrefix:n,renderHeaderFilenameSuffix:r,renderHeaderMetadata:i,renderAnnotation:a,renderGutterUtility:o}),e.element,e.id)),[t,n,r,i,a,o,f]),(0,Z.useMemo)(()=>s!=null&&d?.header!=null?(0,qe.createPortal)(s(),d.header):null,[s,d?.header]),(0,Z.useMemo)(()=>c!=null&&d?.footer!=null?(0,qe.createPortal)(c(),d.footer):null,[c,d?.footer])]})});function it({renderedItem:e,renderCustomHeader:t,renderHeaderPrefix:n,renderHeaderFilenameSuffix:r,renderHeaderMetadata:i,renderAnnotation:a,renderGutterUtility:o}){if(e.type===`diff`){let{item:s,instance:c}=e;return q({fileDiff:s.fileDiff,renderCustomHeader:t==null?void 0:()=>t(s),renderHeaderPrefix:n==null?void 0:()=>n(s),renderHeaderFilenameSuffix:r==null?void 0:()=>r(s),renderHeaderMetadata:i==null?void 0:()=>i(s),renderAnnotation:a==null?void 0:e=>a(e,s),lineAnnotations:s.annotations,renderGutterUtility:o==null?void 0:e=>o(e,s),getHoveredLine:c.getHoveredLine})}{let{item:s,instance:c}=e;return p({file:s.file,renderCustomHeader:t==null?void 0:()=>t(s),renderHeaderPrefix:n==null?void 0:()=>n(s),renderHeaderFilenameSuffix:r==null?void 0:()=>r(s),renderHeaderMetadata:i==null?void 0:()=>i(s),renderAnnotation:a==null?void 0:e=>a(e,s),lineAnnotations:s.annotations,renderGutterUtility:o==null?void 0:e=>o(e,s),getHoveredLine:c.getHoveredLine})}}function at(){}var $=t(),ot=0;function st(){return ot+=1,`pending-review-comment-${ot}`}function ct(e,t){return`${e}/${t.projectId}/${t.repository}#${t.number}`}var lt=[],ut=re()(e=>({drafts:{},summaries:{},addComment:(t,n)=>e(e=>({drafts:{...e.drafts,[t]:[...e.drafts[t]??lt,n]}})),removeComment:(t,n)=>e(e=>{let r=(e.drafts[t]??lt).filter(e=>e.id!==n);if(r.length>0)return{drafts:{...e.drafts,[t]:r}};let{[t]:i,...a}=e.drafts;return{drafts:a}}),removeComments:(t,n)=>e(e=>{let r=new Set(n),i=(e.drafts[t]??lt).filter(e=>!r.has(e.id));if(i.length>0)return{drafts:{...e.drafts,[t]:i}};let{[t]:a,...o}=e.drafts;return{drafts:o}}),clear:t=>e(e=>{let{[t]:n,...r}=e.drafts;return{drafts:r}}),setSummary:(t,n)=>e(e=>({summaries:{...e.summaries,[t]:n}})),clearSummary:(t,n)=>e(e=>{if(e.summaries[t]!==n)return e;let{[t]:r,...i}=e.summaries;return{summaries:i}})}));function dt(e){let t=(0,$.c)(2),n;return t[0]===e?n=t[1]:(n=t=>t.drafts[ct(e.environmentId,e)]??lt,t[0]=e,t[1]=n),ut(n)}function ft(e){return[...e].toSorted((e,t)=>t.committedDate.localeCompare(e.committedDate))}function pt(e,t,n){let r=e.slice(0,n),i=e.find(e=>e.oid===t);return i!==void 0&&!r.includes(i)?[...r,i]:r}function mt(e){let t=(0,$.c)(60),[n,r]=(0,Z.useState)(10),i,a,o,s,c,l,u,d,p;if(t[0]!==e||t[1]!==n){i=ft(e.commits);let r=pt(i,e.selectedCommitOid,n);p=`flex shrink-0 items-center gap-2 overflow-x-auto border-b border-border/60 px-3 py-2`,u=`min-w-40 flex-1`,t[11]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,Q.jsx)(`span`,{className:`sr-only`,children:`Diff scope`}),t[11]=d):d=t[11],a=`max-w-full rounded-md border border-border bg-background px-2 py-1 text-xs`,o=e.selectedCommitOid??``,t[12]===e?s=t[13]:(s=t=>e.onSelectedCommitChange(t.target.value||null),t[12]=e,t[13]=s),t[14]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Q.jsx)(`option`,{value:``,children:`All commits`}),t[14]=c):c=t[14],l=r.map(gt),t[0]=e,t[1]=n,t[2]=i,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u,t[9]=d,t[10]=p}else i=t[2],a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9],p=t[10];let m;t[15]!==a||t[16]!==o||t[17]!==s||t[18]!==c||t[19]!==l?(m=(0,Q.jsxs)(`select`,{className:a,value:o,onChange:s,children:[c,l]}),t[15]=a,t[16]=o,t[17]=s,t[18]=c,t[19]=l,t[20]=m):m=t[20];let h;t[21]!==u||t[22]!==d||t[23]!==m?(h=(0,Q.jsxs)(`label`,{className:u,children:[d,m]}),t[21]=u,t[22]=d,t[23]=m,t[24]=h):h=t[24];let g;t[25]!==i.length||t[26]!==n?(g=n<i.length?(0,Q.jsx)(K,{type:`button`,size:`xs`,variant:`ghost`,onClick:()=>r(ht),children:`More commits`}):null,t[25]=i.length,t[26]=n,t[27]=g):g=t[27];let _;t[28]===e.onToggleAll?_=t[29]:(_=(0,Q.jsx)(K,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":`Toggle all files`,onClick:e.onToggleAll,children:`⌄`}),t[28]=e.onToggleAll,t[29]=_);let v=e.diffStyle===`unified`,y;t[30]===e?y=t[31]:(y=()=>e.onDiffStyleChange(`unified`),t[30]=e,t[31]=y);let b;t[32]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,Q.jsx)(ce,{className:`size-3.5`}),t[32]=b):b=t[32];let x;t[33]!==v||t[34]!==y?(x=(0,Q.jsx)(K,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":`Unified diff view`,"aria-pressed":v,onClick:y,children:b}),t[33]=v,t[34]=y,t[35]=x):x=t[35];let S=e.diffStyle===`split`,C;t[36]===e?C=t[37]:(C=()=>e.onDiffStyleChange(`split`),t[36]=e,t[37]=C);let w;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,Q.jsx)(se,{className:`size-3.5`}),t[38]=w):w=t[38];let T;t[39]!==S||t[40]!==C?(T=(0,Q.jsx)(K,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":`Split diff view`,"aria-pressed":S,onClick:C,children:w}),t[39]=S,t[40]=C,t[41]=T):T=t[41];let E;t[42]===e?E=t[43]:(E=()=>e.onWordWrapChange(!e.wordWrap),t[42]=e,t[43]=E);let D;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,Q.jsx)(ue,{className:`size-3.5`}),t[44]=D):D=t[44];let O;t[45]!==e.wordWrap||t[46]!==E?(O=(0,Q.jsx)(K,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":`Toggle line wrapping`,"aria-pressed":e.wordWrap,onClick:E,children:D}),t[45]=e.wordWrap,t[46]=E,t[47]=O):O=t[47];let k;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,Q.jsx)(f,{className:`size-3.5`}),t[48]=k):k=t[48];let A;t[49]===e.onRefresh?A=t[50]:(A=(0,Q.jsx)(K,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":`Refresh pull request diff`,onClick:e.onRefresh,children:k}),t[49]=e.onRefresh,t[50]=A);let j;return t[51]!==g||t[52]!==_||t[53]!==x||t[54]!==T||t[55]!==O||t[56]!==A||t[57]!==p||t[58]!==h?(j=(0,Q.jsxs)(`header`,{className:p,children:[h,g,_,x,T,O,A]}),t[51]=g,t[52]=_,t[53]=x,t[54]=T,t[55]=O,t[56]=A,t[57]=p,t[58]=h,t[59]=j):j=t[59],j}function ht(e){return e+10}function gt(e){return(0,Q.jsx)(`option`,{value:e.oid,children:`${e.messageHeadline} (${e.oid.slice(0,7)})`},e.oid)}var _t=new Set([`pnpm-lock.yaml`,`yarn.lock`,`package-lock.json`,`bun.lockb`,`Cargo.lock`,`go.sum`,`composer.lock`,`Gemfile.lock`]),vt=new Set([`__snapshots__`,`__generated__`,`dist`,`build`,`vendor`]),yt=new Set([`__tests__`,`tests`,`test`]),bt=[`.ts`,`.tsx`,`.js`,`.jsx`,`.mjs`,`.cjs`];function xt(e){let t=e.split(`/`),n=t.at(-1)??``;return _t.has(n)||n.endsWith(`.snap`)||n.endsWith(`.min.js`)||n.endsWith(`.min.css`)||/\.generated\./.test(n)||t.slice(0,-1).some(e=>vt.has(e))?`generated`:/\.(?:test|spec)\./.test(n)||t.slice(0,-1).some(e=>yt.has(e))?`test`:`source`}function St(e){let t=e.lastIndexOf(`.`);return t>e.lastIndexOf(`/`)?e.slice(0,t):e}function Ct(e){return St(e.split(`/`).at(-1)??``)}function wt(e,t){let n=e.split(`/`).slice(0,-1);for(let e of t.split(`/`))e!==`.`&&e!==``&&(e===`..`?n.pop():n.push(e));return n.join(`/`)}var Tt=/(?:\bfrom|\bimport|\brequire\s*\()\s*\(?\s*["']([^"']+)["']/g;function Et(e,t,n,r){let i=t.startsWith(`.`)?wt(e,t):t,a=bt.find(e=>i.endsWith(e)),o=a===void 0?i:i.slice(0,-a.length),s=n.get(o)??n.get(`${o}/index`)??r.get(Ct(o));return s===e?void 0:s}function Dt(e){return Tt.lastIndex=0,Array.from(e.matchAll(Tt),e=>e[1]??``)}function Ot(e,t,n,r){let i=new Set;for(let a of t.flatMap(Dt)){let t=Et(e,a,n,r);t!==void 0&&i.add(t)}return i}function kt(e,t){let n=new Set(e),r=[],i=e.toSorted((e,t)=>e.localeCompare(t));for(;n.size>0;){let e=i.filter(e=>n.has(e)),a=e.find(e=>[...t.get(e)??[]].every(e=>!n.has(e)))??e[0];n.delete(a),r.push(a)}return r}function At(e){return(e.split(`/`).at(-1)??``).replace(/\.(?:test|spec)\..*$/,``).replace(/\.[^.]+$/,``)}function jt(e){let t=new Map;for(let n of e)t.set(J(n),n);let n=new Map;for(let e of t.keys())n.set(e,xt(e));let r=[...t.keys()].filter(e=>n.get(e)===`source`),i=new Map,a=new Set,o=new Map;for(let e of r){i.set(St(e),e);let t=Ct(e);o.has(t)&&a.add(t),o.set(t,e)}for(let e of a)o.delete(e);let s=new Map;for(let e of r){let n=t.get(e);s.set(e,Ot(e,[...n.additionLines,...n.deletionLines],i,o))}let c=kt(r,s),l=new Map;c.forEach((e,t)=>{let n=Ct(e);l.has(n)||l.set(n,t)});let u=[...t.keys()].filter(e=>n.get(e)===`test`).toSorted((e,t)=>(l.get(At(e))??2**53-1)-(l.get(At(t))??2**53-1)||e.localeCompare(t)),d=[...t.keys()].filter(e=>n.get(e)===`generated`).toSorted((e,t)=>e.localeCompare(t));return[...c,...u,...d].map(e=>t.get(e))}function Mt(e,t){return t?.[e]===!0}function Nt(e,t){return e.reduce((e,n)=>Mt(n,t)?e+1:e,0)}var Pt=`forge:pr-files-viewed:v1`,Ft=200;function It(e){return`${e.projectId}:${e.projectRepositoryId??0}:${e.repository.toLowerCase()}#${e.number}`}var Lt=new Map;function Rt(e){if(typeof e!=`object`||!e)return null;let t=Object.create(null);for(let[n,r]of Object.entries(e))n.length>0&&typeof r==`boolean`&&(t[n]=r);return Object.keys(t).length>0?t:null}function zt(e){if(typeof e!=`object`||!e)return{};let t=Object.create(null),n=Object.entries(e).slice(-200);for(let[e,r]of n){if(e.length===0||typeof r!=`object`||!r)continue;let n=Rt(r.viewedByPath);n!==null&&(t[e]={viewedByPath:n})}return t}function Bt(){if(typeof window>`u`)return{ok:!0,value:{}};try{let e=window.localStorage.getItem(Pt);return{ok:!0,value:e===null?{}:zt(JSON.parse(e))}}catch{return{ok:!1}}}function Vt(){let e=Bt();return e.ok?e.value:{}}function Ht(e){if(Lt.size===0)return e;let t={...e};for(let[e,n]of Lt)t[e]={viewedByPath:{...t[e]?.viewedByPath,...n.viewedByPath}};return t}function Ut(e){if(typeof window>`u`)return!0;try{return window.localStorage.setItem(Pt,JSON.stringify(e)),!0}catch{return!1}}function Wt(e){let t=Object.keys(e);return t.length<=Ft?e:Object.fromEntries(t.slice(-200).map(t=>[t,e[t]]))}function Gt(e,t,n,r){if(e[t]?.viewedByPath[n]===r)return e;let{[t]:i,...a}=e;return Wt({...a,[t]:{viewedByPath:{...e[t]?.viewedByPath,[n]:r}}})}var Kt=re(e=>({byPullRequest:Vt(),setFileViewed:(t,n,r)=>e(e=>{let i=Bt(),a=i.ok?Ht(i.value):e.byPullRequest,o=Gt(a,t,n,r);return o===a?(i.ok&&Lt.size>0&&Ut(o)&&Lt.clear(),e.byPullRequest[t]?.viewedByPath[n]===r&&Lt.size===0?e:{byPullRequest:a}):(Ut(o)?Lt.clear():Lt.set(t,o[t]),{byPullRequest:o})})}));function qt(e){let t=(0,$.c)(19),{reference:n,enabled:r,paths:i}=e,a,o;t[0]===n?o=t[1]:(o=It(n),t[0]=n,t[1]=o),a=o;let s=a,c;t[2]===s?c=t[3]:(c=e=>e.byPullRequest[s]?.viewedByPath,t[2]=s,t[3]=c);let l=Kt(c),u=Kt(Jt),d;t[4]!==r||t[5]!==l?(d=e=>r&&Mt(e,l??null),t[4]=r,t[5]=l,t[6]=d):d=t[6];let f=d,p;t[7]!==r||t[8]!==s||t[9]!==u?(p=(e,t)=>{r&&u(s,e,t)},t[7]=r,t[8]=s,t[9]=u,t[10]=p):p=t[10];let m=p,h,g;t[11]!==r||t[12]!==i||t[13]!==l?(g=r?Nt(i,l??null):0,t[11]=r,t[12]=i,t[13]=l,t[14]=g):g=t[14],h=g;let _=h,v,y;return t[15]!==f||t[16]!==m||t[17]!==_?(y={isViewed:f,setViewed:m,viewedCount:_},t[15]=f,t[16]=m,t[17]=_,t[18]=y):y=t[18],v=y,v}function Jt(e){return e.setFileViewed}function Yt(e,t,n){return e.hunks.some(e=>t===`left`?n>=e.deletionStart&&n<e.deletionStart+e.deletionCount:n>=e.additionStart&&n<e.additionStart+e.additionCount)}function Xt(e,t,n){let r=t!==`expanded`;return n.has(e)?!r:r}function Zt(e,t,n,r){let i=t-(n===`left`?r.oldLine:r.newLine);return i>=0&&i<e.lines?{kind:`context`,oldLine:r.oldLine+i,newLine:r.newLine+i,side:n}:null}function Qt(e,t,n,r){let i=n===`left`?r.oldLine:r.newLine,a=n===`left`?e.deletions:e.additions;return t>=i&&t<i+a?n===`left`?{kind:`deleted`,oldLine:t}:{kind:`added`,newLine:t}:null}function $t(e,t){return e.type===`context`?{oldLine:t.oldLine+e.lines,newLine:t.newLine+e.lines}:{oldLine:t.oldLine+e.deletions,newLine:t.newLine+e.additions}}function en(e,t,n){let r={oldLine:e.deletionStart,newLine:e.additionStart};for(let i of e.hunkContent){let e=i.type===`context`?Zt(i,t,n,r):Qt(i,t,n,r);if(e!==null)return e;r=$t(i,r)}return null}function tn(e,t,n){let r=n===`deletions`?`left`:`right`;for(let n of e.hunks){let e=en(n,t,r);if(e!==null)return e}return null}function nn(e){let t=(0,$.c)(7),n;return t[0]!==e.annotation.comment||t[1]!==e.annotation.kind||t[2]!==e.annotation.thread||t[3]!==e.environmentId||t[4]!==e.permissions||t[5]!==e.reference?(n=e.annotation.kind===`thread`?(0,Q.jsx)(y,{environmentId:e.environmentId,reference:e.reference,thread:e.annotation.thread,canReply:e.permissions.canReply,canResolve:e.permissions.canResolve,reactionsEnabled:e.permissions.reactionsEnabled}):(0,Q.jsx)(rn,{body:e.annotation.comment.body}),t[0]=e.annotation.comment,t[1]=e.annotation.kind,t[2]=e.annotation.thread,t[3]=e.environmentId,t[4]=e.permissions,t[5]=e.reference,t[6]=n):n=t[6],n}function rn(e){let t=(0,$.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,Q.jsx)(`p`,{className:`text-xs font-medium text-info-foreground`,children:`Pending review comment`}),t[0]=n):n=t[0];let r;return t[1]===e.body?r=t[2]:(r=(0,Q.jsxs)(`article`,{className:`rounded-md border border-info-border bg-info-surface p-3`,children:[n,(0,Q.jsx)(m,{text:e.body,className:`mt-1`})]}),t[1]=e.body,t[2]=r),r}function an(e){let t=(0,$.c)(10),n;t[0]!==e.file||t[1]!==e.omittedStats?(n=on(e.file,e.omittedStats),t[0]=e.file,t[1]=e.omittedStats,t[2]=n):n=t[2];let{additions:r,deletions:i}=n,a;t[3]===r?a=t[4]:(a=(0,Q.jsxs)(`span`,{className:`text-success-foreground`,children:[`+`,r]}),t[3]=r,t[4]=a);let o;t[5]===i?o=t[6]:(o=(0,Q.jsxs)(`span`,{className:`text-destructive-foreground`,children:[`−`,i]}),t[5]=i,t[6]=o);let s;return t[7]!==a||t[8]!==o?(s=(0,Q.jsxs)(`span`,{className:`flex gap-1 font-mono text-[11px] tabular-nums`,children:[a,o]}),t[7]=a,t[8]=o,t[9]=s):s=t[9],s}function on(e,t){let n=e.hunks.reduce((e,t)=>({additions:e.additions+t.additionLines,deletions:e.deletions+t.deletionLines}),{additions:0,deletions:0});return n.additions===0&&n.deletions===0?t.get(J(e))??n:n}function sn(e){let t=(0,$.c)(9),n=e.item.collapsed===!0,r=n?`Expand file`:`Collapse file`,i=!n,a;t[0]===e?a=t[1]:(a=()=>e.onToggleFile(e.item.id),t[0]=e,t[1]=a);let o;t[2]===n?o=t[3]:(o=n?(0,Q.jsx)(ae,{className:`size-3.5`}):(0,Q.jsx)(ie,{className:`size-3.5`}),t[2]=n,t[3]=o);let s;return t[4]!==r||t[5]!==i||t[6]!==a||t[7]!==o?(s=(0,Q.jsx)(K,{type:`button`,size:`icon-sm`,variant:`ghost`,"aria-label":r,"aria-expanded":i,onClick:a,children:o}),t[4]=r,t[5]=i,t[6]=a,t[7]=o,t[8]=s):s=t[8],s}function cn(e){let t=(0,$.c)(16),n;t[0]!==e.path||t[1]!==e.view?(n=e.view.isViewed(e.path),t[0]=e.path,t[1]=e.view,t[2]=n):n=t[2];let r=n,i=r?`true`:`false`,a=r?`Mark ${e.path} as not viewed`:`Mark ${e.path} as viewed`,o;t[3]!==e.path||t[4]!==e.view||t[5]!==r?(o=()=>e.view.setViewed(e.path,!r),t[3]=e.path,t[4]=e.view,t[5]=r,t[6]=o):o=t[6];let s=r?`border-success-border bg-success-surface text-success-foreground`:`border-border text-muted-foreground hover:text-foreground`,c;t[7]===s?c=t[8]:(c=G(`inline-flex size-5 shrink-0 items-center justify-center rounded-sm border`,s),t[7]=s,t[8]=c);let l;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,Q.jsx)(x,{"aria-hidden":!0,className:`size-3`}),t[9]=l):l=t[9];let u;return t[10]!==i||t[11]!==a||t[12]!==o||t[13]!==c||t[14]!==r?(u=(0,Q.jsx)(`button`,{type:`button`,"data-slot":`pr-file-viewed-toggle`,"data-viewed":i,"aria-pressed":r,"aria-label":a,onClick:o,className:c,children:l}),t[10]=i,t[11]=a,t[12]=o,t[13]=c,t[14]=r,t[15]=u):u=t[15],u}function ln(e){let t=(0,$.c)(2),n;return t[0]===e.threads?n=t[1]:(n=e.threads.length>0?(0,Q.jsxs)(`section`,{className:`border-b border-warning-border bg-warning-surface px-3 py-2 text-xs text-warning-foreground`,children:[(0,Q.jsxs)(`p`,{className:`flex items-center gap-1.5 font-medium`,children:[(0,Q.jsx)(_,{className:`size-3.5`}),`Conversations not on the diff loaded so far`]}),e.threads.map(un)]}):null,t[0]=e.threads,t[1]=n),n}function un(e){return(0,Q.jsxs)(`p`,{className:`mt-1 truncate`,children:[e.path,e.line===null?``:`:${e.line}`,e.isOutdated?` · outdated`:``]},e.id)}function dn(e){let t=(0,$.c)(2),n;return t[0]===e.children?n=t[1]:(n=(0,Q.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:e.children}),t[0]=e.children,t[1]=n),n}function fn(e){let t=(0,$.c)(7),n,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={diffHeaderHeight:32,hunkSeparatorHeight:24,spacing:0,paddingTop:0,paddingBottom:8},r={paddingTop:0,paddingBottom:0,gap:0},t[0]=n,t[1]=r):(n=t[0],r=t[1]);let i;t[2]===e.options?i=t[3]:(i={...e.options,unsafeCSS:`[data-diffs-header]{position:sticky!important;top:0;z-index:4;background:var(--background)!important;border-bottom:1px solid var(--border)!important}`,itemMetrics:n,layout:r},t[2]=e.options,t[3]=i);let a;return t[4]!==e||t[5]!==i?(a=(0,Q.jsx)(Ze,{...e,options:i}),t[4]=e,t[5]=i,t[6]=a):a=t[6],a}function pn(e){return[...e.threads.flatMap(t=>hn(e.file,t)),...e.pendingComments.flatMap(t=>_n(e.file,t))]}function mn(e,t){return e.some(e=>gn(e,t))}function hn(e,t){return gn(e,t)?[{side:yn(t.side),lineNumber:t.line,metadata:{kind:`thread`,thread:t}}]:[]}function gn(e,t){return[!t.isOutdated,t.line!==null,J(e)===t.path,t.line!==null&&Yt(e,t.side,t.line)].every(Boolean)}function _n(e,t){if(J(e)!==t.path)return[];let n=vn(t);return n===null||!Yt(e,n.side,n.line)?[]:[{side:yn(n.side),lineNumber:n.line,metadata:{kind:`pending`,comment:t}}]}function vn(e){switch(e.position.kind){case`added`:return{side:`right`,line:e.position.newLine};case`deleted`:return{side:`left`,line:e.position.oldLine};case`context`:return e.position.side===`left`?{side:`left`,line:e.position.oldLine}:{side:`right`,line:e.position.newLine}}}function yn(e){return e===`left`?`deletions`:`additions`}function bn(e){return xn[Sn(e)](e)}var xn={loading:()=>(0,Q.jsx)(U,{label:`Loading pull request diff…`}),error:e=>(0,Q.jsx)(dn,{children:e.error?.message??`Pull request diff could not be loaded.`}),empty:()=>(0,Q.jsx)(dn,{children:`This pull request has no file changes.`}),loaded:e=>(0,Q.jsx)(Dn,{...e})};function Sn(e){return Cn(e)?`loading`:wn(e)?`error`:Tn(e)?`empty`:`loaded`}function Cn(e){return e.loading&&e.slices.length===0}function wn(e){return e.error!==null&&e.slices.length===0}function Tn(e){return!En({itemCount:e.items.length,rawCount:e.raw.length,withheld:e.withheld})}function En(e){return e.itemCount>0||e.rawCount>0||e.withheld}function Dn(e){let t=(0,$.c)(12),n,r;t[0]===e?(n=t[1],r=t[2]):(n=(0,Q.jsx)(On,{...e}),r=e.items.length>0?(0,Q.jsx)(jn,{...e}):null,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===e.raw?i=t[4]:(i=(0,Q.jsx)(Pn,{raw:e.raw}),t[3]=e.raw,t[4]=i);let a;t[5]===e?a=t[6]:(a=(0,Q.jsx)(Fn,{...e}),t[5]=e,t[6]=a);let o;return t[7]!==n||t[8]!==r||t[9]!==i||t[10]!==a?(o=(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:[n,r,i,a]}),t[7]=n,t[8]=r,t[9]=i,t[10]=a,t[11]=o):o=t[11],o}function On(e){let t=(0,$.c)(18),n;t[0]!==e.activity?.reviewThreads||t[1]!==e.files?(n=e.activity?.reviewThreads.filter(t=>!mn(e.files,t)),t[0]=e.activity?.reviewThreads,t[1]=e.files,t[2]=n):n=t[2];let r=n,i;t[3]!==e.fileCount||t[4]!==e.filesViewed?(i=e.filesViewed!==void 0&&e.fileCount!==void 0&&e.filesViewed.viewedCount>0?(0,Q.jsxs)(`section`,{className:`border-b border-border/60 px-3 py-2 text-xs text-muted-foreground`,"aria-live":`polite`,children:[e.filesViewed.viewedCount,` of `,e.fileCount,` files viewed`]}):null,t[3]=e.fileCount,t[4]=e.filesViewed,t[5]=i):i=t[5];let a;t[6]===e?a=t[7]:(a=e.error===null?null:(0,Q.jsx)(kn,{...e,error:e.error}),t[6]=e,t[7]=a);let o;t[8]!==e.omittedFileCount||t[9]!==e.withheld?(o=e.withheld?(0,Q.jsx)(An,{omittedFileCount:e.omittedFileCount}):null,t[8]=e.omittedFileCount,t[9]=e.withheld,t[10]=o):o=t[10];let s;t[11]===r?s=t[12]:(s=r===void 0?null:(0,Q.jsx)(ln,{threads:r}),t[11]=r,t[12]=s);let c;return t[13]!==i||t[14]!==a||t[15]!==o||t[16]!==s?(c=(0,Q.jsxs)(Q.Fragment,{children:[i,a,o,s]}),t[13]=i,t[14]=a,t[15]=o,t[16]=s,t[17]=c):c=t[17],c}function kn(e){let t=(0,$.c)(8),n;t[0]===e.error.message?n=t[1]:(n=(0,Q.jsxs)(`span`,{children:[`More diff content could not be loaded: `,e.error.message]}),t[0]=e.error.message,t[1]=n);let r;t[2]!==e.hasNextPage||t[3]!==e.onLoadNextPage?(r=e.hasNextPage?(0,Q.jsx)(K,{type:`button`,size:`xs`,variant:`outline`,onClick:e.onLoadNextPage,children:`Retry`}):null,t[2]=e.hasNextPage,t[3]=e.onLoadNextPage,t[4]=r):r=t[4];let i;return t[5]!==n||t[6]!==r?(i=(0,Q.jsxs)(`section`,{className:`flex items-center justify-between gap-2 border-b border-destructive-border bg-destructive-surface px-3 py-2 text-xs text-destructive-foreground`,children:[n,r]}),t[5]=n,t[6]=r,t[7]=i):i=t[7],i}function An(e){let t=(0,$.c)(2),n=e.omittedFileCount>0?` ${e.omittedFileCount} file statistics remain available.`:``,r;return t[0]===n?r=t[1]:(r=(0,Q.jsxs)(`section`,{className:`border-b border-warning-border bg-warning-surface px-3 py-2 text-xs text-warning-foreground`,children:[`Binary or oversized content was withheld by the provider.`,n]}),t[0]=n,t[1]=r),r}function jn(e){let t=(0,$.c)(15),n;t[0]===e.onToggleFile?n=t[1]:(n=t=>Mn(t,e.onToggleFile),t[0]=e.onToggleFile,t[1]=n);let r;t[2]!==e.filesViewed||t[3]!==e.omittedStats?(r=t=>(0,Q.jsxs)(Q.Fragment,{children:[e.filesViewed!==void 0&&t.type===`diff`?(0,Q.jsx)(cn,{path:J(t.fileDiff),view:e.filesViewed}):null,Nn(t,e.omittedStats)]}),t[2]=e.filesViewed,t[3]=e.omittedStats,t[4]=r):r=t[4];let i;t[5]!==e.annotationPermissions||t[6]!==e.environmentId||t[7]!==e.reference?(i=t=>(0,Q.jsx)(nn,{annotation:t.metadata,environmentId:e.environmentId,reference:e.reference,permissions:e.annotationPermissions}),t[5]=e.annotationPermissions,t[6]=e.environmentId,t[7]=e.reference,t[8]=i):i=t[8];let a;return t[9]!==e.items||t[10]!==e.viewOptions||t[11]!==n||t[12]!==r||t[13]!==i?(a=(0,Q.jsx)(fn,{className:`h-full min-h-0 [scrollbar-gutter:stable]`,items:e.items,options:e.viewOptions,renderHeaderPrefix:n,renderHeaderMetadata:r,renderAnnotation:i}),t[9]=e.items,t[10]=e.viewOptions,t[11]=n,t[12]=r,t[13]=i,t[14]=a):a=t[14],a}function Mn(e,t){return(0,Q.jsx)(sn,{item:e,onToggleFile:t})}function Nn(e,t){return e.type===`diff`?(0,Q.jsx)(an,{file:e.fileDiff,omittedStats:t}):null}function Pn(e){return e.raw.map(e=>(0,Q.jsxs)(`pre`,{className:`m-3 whitespace-pre-wrap break-words rounded-md border border-warning-border bg-warning-surface p-3 font-mono text-xs text-warning-foreground`,children:[e.reason,`
2
2
 
3
3
  `,e.text]},`${e.reason}:${e.text.slice(0,32)}`))}function Fn(e){let t=(0,$.c)(5),n;return t[0]!==e.continuationRef||t[1]!==e.hasNextPage||t[2]!==e.loadingNextPage||t[3]!==e.onLoadNextPage?(n=e.hasNextPage?(0,Q.jsx)(`div`,{ref:e.continuationRef,className:`flex justify-center p-3`,children:(0,Q.jsx)(K,{type:`button`,size:`sm`,variant:`outline`,disabled:e.loadingNextPage,onClick:e.onLoadNextPage,children:e.loadingNextPage?`Loading more files…`:`Load more files`})}):null,t[0]=e.continuationRef,t[1]=e.hasNextPage,t[2]=e.loadingNextPage,t[3]=e.onLoadNextPage,t[4]=n):n=t[4],n}function In(e){let t=(0,Z.useRef)(null),{resolvedTheme:n}=O(),r=(0,Z.useMemo)(()=>Rn(e.slices),[e.slices]),i=(0,Z.useMemo)(()=>zn(r),[r]),a=(0,Z.useMemo)(()=>i.map(e=>J(e)),[i]),o=qt({reference:e.reference,enabled:a.length>0,paths:a}),s=Ln(i,e),c=(0,Z.useMemo)(()=>Wn(e.onLoadFileContents,e.revisionKey),[e.onLoadFileContents,e.revisionKey]);return Jn({target:t,hasNextPage:e.hasNextPage,loadingNextPage:e.loadingNextPage,error:e.error,onLoadNextPage:e.onLoadNextPage}),(0,Q.jsx)(bn,{...e,continuationRef:t,files:i,filesViewed:o,fileCount:a.length,raw:Bn(r),withheld:e.slices.some(e=>e.truncated),omittedFileCount:Vn(e.slices),omittedStats:Hn(e.slices),items:s,viewOptions:Un(e,c,n)})}function Ln(e,t){return e.map((e,n)=>{let r=de(e);return{id:r,type:`diff`,fileDiff:e,collapsed:Xt(r,t.collapsedOverride,t.toggledFiles),annotations:pn({file:e,threads:t.activity?.reviewThreads??[],pendingComments:t.pendingComments}),version:n}})}function Rn(e){return e.map(e=>le(e.patch))}function zn(e){return jt(e.flatMap(e=>e?.kind===`files`?e.files:[]))}function Bn(e){return e.flatMap(e=>e?.kind===`raw`?[e]:[])}function Vn(e){return e.reduce((e,t)=>e+(t.omittedFileStats?.length??0),0)}function Hn(e){return new Map(e.flatMap(e=>e.omittedFileStats??[]).map(e=>[e.path,e]))}function Un(e,t,n){return{diffStyle:e.diffStyle,overflow:e.wordWrap?`wrap`:`scroll`,theme:R(n),themeType:n,stickyHeaders:!0,loadDiffFiles:t,enableLineSelection:e.onSelectLines!==void 0,...e.onSelectLines===void 0?{}:{onLineSelectionEnd:Gn(e.onSelectLines)}}}function Wn(e,t){return async n=>{let r=J(n),i=n.prevName?J({name:n.prevName}):r,a=await e({changeType:n.type,oldPath:i,newPath:r});return{oldFile:n.type===`rename-pure`?null:{name:i,contents:a.oldContents,cacheKey:`${t}:old:${i}`},newFile:{name:r,contents:a.newContents,cacheKey:`${t}:new:${r}`}}}}function Gn(e){return(t,n)=>{let r=Kn(t,n.item);r!==null&&e(r)}}function Kn(e,t){return e===null||t.type!==`diff`?null:qn(e,t.fileDiff)}function qn(e,t){let n=tn(t,e.end,e.endSide??e.side);return n===null?null:{path:J(t),oldPath:t.prevName?J({name:t.prevName}):null,start:e.start,end:e.end,position:n}}function Jn(e){let t=(0,$.c)(12),{target:n,hasNextPage:r,loadingNextPage:i,error:a,onLoadNextPage:o}=e,s;t[0]!==a||t[1]!==r||t[2]!==i||t[3]!==o||t[4]!==n.current?(s=()=>{let e=n.current;if(!Xn(e,{hasNextPage:r,loadingNextPage:i,error:a,onLoadNextPage:o}))return;let t=new IntersectionObserver(e=>{e.some(Yn)&&o()},{rootMargin:`240px`});return t.observe(e),()=>t.disconnect()},t[0]=a,t[1]=r,t[2]=i,t[3]=o,t[4]=n.current,t[5]=s):s=t[5];let c;t[6]!==a||t[7]!==r||t[8]!==i||t[9]!==o||t[10]!==n?(c=[a,r,i,o,n],t[6]=a,t[7]=r,t[8]=i,t[9]=o,t[10]=n,t[11]=c):c=t[11],(0,Z.useEffect)(s,c)}function Yn(e){return e.isIntersecting}function Xn(e,t){return[e!==null,t.hasNextPage,!t.loadingNextPage,t.error===null].every(Boolean)}function Zn(e){return[e.isDetailFresh,e.selectedCommitOid===null,e.detail.capabilities.review.inlineComment,e.detail.viewerPermissions.comment].every(Boolean)}function Qn(e){return e.isDetailFresh?e.detail.capabilities.review.verdicts.filter(t=>e.detail.viewerPermissions.verdicts.includes(t)):[]}function $n(e){let t=e.selectedCommitOid??`head`;return`${e.reference.projectId}:${e.reference.repository}#${e.reference.number}:${e.detail.updatedAt}:${t}`}function er(e){let t=(0,$.c)(22),n;t[0]===e?n=t[1]:(n=t=>nr(t,e),t[0]=e,t[1]=n);let r=e.anchor.end===e.anchor.start?``:`–${e.anchor.end}`,i;t[2]!==e.anchor.path||t[3]!==e.anchor.start||t[4]!==r?(i=(0,Q.jsxs)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:[`Comment on `,e.anchor.path,`:`,e.anchor.start,r]}),t[2]=e.anchor.path,t[3]=e.anchor.start,t[4]=r,t[5]=i):i=t[5];let a;t[6]!==e.body||t[7]!==e.onBodyChange?(a=(0,Q.jsx)(c,{value:e.body,ariaLabel:`Inline review comment`,placeholder:`Add a line comment…`,density:`compact`,onChange:e.onBodyChange}),t[6]=e.body,t[7]=e.onBodyChange,t[8]=a):a=t[8];let o;t[9]===e.onCancel?o=t[10]:(o=(0,Q.jsx)(K,{type:`button`,size:`sm`,variant:`ghost`,onClick:e.onCancel,children:`Cancel`}),t[9]=e.onCancel,t[10]=o);let s=e.body.trim().length===0,l;t[11]!==e.onAdd||t[12]!==s?(l=(0,Q.jsx)(K,{type:`button`,size:`sm`,disabled:s,onClick:e.onAdd,children:`Add to review`}),t[11]=e.onAdd,t[12]=s,t[13]=l):l=t[13];let u;t[14]!==o||t[15]!==l?(u=(0,Q.jsxs)(`div`,{className:`mt-2 flex justify-end gap-2`,children:[o,l]}),t[14]=o,t[15]=l,t[16]=u):u=t[16];let d;return t[17]!==n||t[18]!==i||t[19]!==a||t[20]!==u?(d=(0,Q.jsxs)(`aside`,{className:`absolute inset-x-3 bottom-3 z-20 rounded-lg border border-border bg-card p-3 shadow-lg`,onPointerDown:tr,onKeyDown:n,children:[i,a,u]}),t[17]=n,t[18]=i,t[19]=a,t[20]=u,t[21]=d):d=t[21],d}function tr(e){return e.stopPropagation()}function nr(e,t){if(e.key===`Escape`){e.preventDefault(),t.onCancel();return}rr(e)&&t.body.trim().length>0&&(e.preventDefault(),t.onAdd())}function rr(e){return e.key===`Enter`&&[e.metaKey,e.ctrlKey].some(Boolean)}var ir=[{value:`comment`,label:`Comment`},{value:`approve`,label:`Approve`},{value:`request-changes`,label:`Request changes`}];function ar(e,t,n,r){return!r&&(e===`approve`||t.trim().length>0||n.length>0)}function or(e){let[t,n]=(0,Z.useState)(!1),[r,i]=(0,Z.useState)(null),a=async r=>{if(ar(r,e.body,e.pendingComments,t)){n(!0),i(null);try{await e.onSubmit({verdict:r,body:e.body,comments:e.pendingComments})}catch(e){i(e instanceof Error?e.message:`Review could not be submitted.`)}finally{n(!1)}}};return(0,Q.jsxs)(`aside`,{className:`absolute inset-x-3 bottom-3 z-10 rounded-lg border border-border bg-card shadow-lg`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/60 px-3 py-2 text-xs text-muted-foreground`,children:[(0,Q.jsx)(`span`,{children:e.pendingComments.length===0?`Review`:`${e.pendingComments.length} line comments pending`}),(0,Q.jsx)(K,{type:`button`,size:`xs`,variant:`ghost`,onClick:e.onClose,children:`Close`})]}),(0,Q.jsxs)(`div`,{className:`p-3`,children:[(0,Q.jsx)(c,{value:e.body,ariaLabel:`Review summary`,placeholder:`Summarize your review (optional)`,density:`compact`,disabled:t,onChange:e.onBodyChange}),r===null?null:(0,Q.jsxs)(`p`,{role:`alert`,className:`mt-2 text-xs text-destructive-foreground`,children:[`Review could not be submitted: `,r]}),(0,Q.jsx)(`div`,{className:`mt-2 flex flex-wrap justify-end gap-2`,children:ir.filter(t=>e.verdicts.includes(t.value)).map(e=>(0,Q.jsxs)(K,{type:`button`,size:`sm`,variant:e.value===`comment`?`outline`:`default`,disabled:t,onClick:()=>void a(e.value),children:[e.value===`approve`?(0,Q.jsx)(x,{className:`size-3.5`}):e.value===`comment`?(0,Q.jsx)(h,{className:`size-3.5`}):(0,Q.jsx)(S,{className:`size-3.5`}),e.label]},e.value))})]})]})}function sr(e){let t=(0,$.c)(3),n=dr(e),r;return t[0]!==n||t[1]!==e?(r=(0,Q.jsx)(cr,{props:e,model:n}),t[0]=n,t[1]=e,t[2]=r):r=t[2],r}function cr(e){let t=(0,$.c)(2),n;return t[0]===e?n=t[1]:(n=(0,Q.jsx)(v,{children:(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-background`,children:[(0,Q.jsx)(lr,{...e}),(0,Q.jsx)(ur,{...e}),(0,Q.jsx)(Sr,{...e})]})}),t[0]=e,t[1]=n),n}function lr(e){let t=(0,$.c)(12),{props:n,model:r}=e,i;t[0]===n.activity?.commits?i=t[1]:(i=n.activity?.commits??[],t[0]=n.activity?.commits,t[1]=i);let a;return t[2]!==r.diffStyle||t[3]!==r.setDiffStyle||t[4]!==r.setWordWrap||t[5]!==r.toggleAll||t[6]!==r.wordWrap||t[7]!==n.onRefresh||t[8]!==n.onSelectedCommitChange||t[9]!==n.selectedCommitOid||t[10]!==i?(a=(0,Q.jsx)(mt,{commits:i,selectedCommitOid:n.selectedCommitOid,diffStyle:r.diffStyle,wordWrap:r.wordWrap,onSelectedCommitChange:n.onSelectedCommitChange,onDiffStyleChange:r.setDiffStyle,onWordWrapChange:r.setWordWrap,onToggleAll:r.toggleAll,onRefresh:n.onRefresh}),t[2]=r.diffStyle,t[3]=r.setDiffStyle,t[4]=r.setWordWrap,t[5]=r.toggleAll,t[6]=r.wordWrap,t[7]=n.onRefresh,t[8]=n.onSelectedCommitChange,t[9]=n.selectedCommitOid,t[10]=i,t[11]=a):a=t[11],a}function ur(e){let t=(0,$.c)(27),{props:n,model:r}=e,i;t[0]===r.onSelectLines?i=t[1]:(i=r.onSelectLines===void 0?{}:{onSelectLines:r.onSelectLines},t[0]=r.onSelectLines,t[1]=i);let a=i,o=n.environmentId,s=n.reference,c=n.selectedCommitOid===null?n.activity:void 0,l;t[2]!==r.pendingComments||t[3]!==n.selectedCommitOid?(l=n.selectedCommitOid===null?r.pendingComments:[],t[2]=r.pendingComments,t[3]=n.selectedCommitOid,t[4]=l):l=t[4];let u=r.annotationPermissions,d=n.slices,f=n.loading,p=n.error,m=n.hasNextPage,h=n.loadingNextPage,g=r.collapsedOverride,_=r.toggledFiles,v=r.diffStyle,y=r.wordWrap,b;t[5]===n?b=t[6]:(b=$n(n),t[5]=n,t[6]=b);let x;return t[7]!==r.annotationPermissions||t[8]!==r.collapsedOverride||t[9]!==r.diffStyle||t[10]!==r.toggleFile||t[11]!==r.toggledFiles||t[12]!==r.wordWrap||t[13]!==n.environmentId||t[14]!==n.error||t[15]!==n.hasNextPage||t[16]!==n.loading||t[17]!==n.loadingNextPage||t[18]!==n.onLoadFileContents||t[19]!==n.onLoadNextPage||t[20]!==n.reference||t[21]!==n.slices||t[22]!==a||t[23]!==b||t[24]!==c||t[25]!==l?(x=(0,Q.jsx)(In,{environmentId:o,reference:s,activity:c,pendingComments:l,annotationPermissions:u,slices:d,loading:f,error:p,hasNextPage:m,loadingNextPage:h,collapsedOverride:g,toggledFiles:_,diffStyle:v,wordWrap:y,revisionKey:b,onToggleFile:r.toggleFile,onLoadNextPage:n.onLoadNextPage,onLoadFileContents:n.onLoadFileContents,...a}),t[7]=r.annotationPermissions,t[8]=r.collapsedOverride,t[9]=r.diffStyle,t[10]=r.toggleFile,t[11]=r.toggledFiles,t[12]=r.wordWrap,t[13]=n.environmentId,t[14]=n.error,t[15]=n.hasNextPage,t[16]=n.loading,t[17]=n.loadingNextPage,t[18]=n.onLoadFileContents,t[19]=n.onLoadNextPage,t[20]=n.reference,t[21]=n.slices,t[22]=a,t[23]=b,t[24]=c,t[25]=l,t[26]=x):x=t[26],x}function dr(e){let t=(0,$.c)(98),[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(_r),[o,s]=(0,Z.useState)(`unified`),[c,u]=(0,Z.useState)(!0),[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(``),y;t[0]!==e.environmentId||t[1]!==e.reference?(y=ct(e.environmentId,e.reference),t[0]=e.environmentId,t[1]=e.reference,t[2]=y):y=t[2];let b=y,x;t[3]!==e.environmentId||t[4]!==e.reference?(x={environmentId:e.environmentId,...e.reference},t[3]=e.environmentId,t[4]=e.reference,t[5]=x):x=t[5];let S=dt(x),C=ut(gr),w=ut(hr),T=ut(mr),E;t[6]===b?E=t[7]:(E=e=>e.summaries[b]??``,t[6]=b,t[7]=E);let D=ut(E),O=ut(pr),k=ut(fr),A,j,M,N,P,F,I,L,R,z,ee,B,V,te,ne,H,U,W,G,K,re,ie,ae,oe,se;if(t[8]!==w||t[9]!==k||t[10]!==n||t[11]!==o||t[12]!==m||t[13]!==_||t[14]!==S||t[15]!==e||t[16]!==T||t[17]!==D||t[18]!==b||t[19]!==f||t[20]!==O||t[21]!==i||t[22]!==c){let y=Zn(e),x;t[48]!==e.detail||t[49]!==e.isDetailFresh?(x=l(e.detail,e.isDetailFresh),t[48]=e.detail,t[49]=e.isDetailFresh,t[50]=x):x=t[50];let C;t[51]!==e.detail||t[52]!==e.isDetailFresh?(C=d(e.detail,e.isDetailFresh),t[51]=e.detail,t[52]=e.isDetailFresh,t[53]=C):C=t[53];let E;t[54]!==e.detail||t[55]!==e.isDetailFresh?(E=g(e.detail,e.isDetailFresh),t[54]=e.detail,t[55]=e.isDetailFresh,t[56]=E):E=t[56];let q;t[57]!==x||t[58]!==C||t[59]!==E?(q={canReply:x,canResolve:C,reactionsEnabled:E},t[57]=x,t[58]=C,t[59]=E,t[60]=q):q=t[60];let ce=q,le;t[61]===e?le=t[62]:(le=Qn(e),t[61]=e,t[62]=le);let J=le,ue;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(ue=()=>{h(null),v(``)},t[63]=ue):ue=t[63],A=ue,G=n,K=i,re=o,ie=c,ae=f,oe=m,se=_,j=b,M=S,N=ce,P=D,F=J,I=s,L=u,R=p,z=v,ee=O,B=w,V=T,te=k,ne=A,t[64]===Symbol.for(`react.memo_cache_sentinel`)?(H=()=>{r(vr),a(new Set)},U=e=>a(t=>br(t,e)),t[64]=H,t[65]=U):(H=t[64],U=t[65]),W=yr(y,h,e.onSelectLines),t[8]=w,t[9]=k,t[10]=n,t[11]=o,t[12]=m,t[13]=_,t[14]=S,t[15]=e,t[16]=T,t[17]=D,t[18]=b,t[19]=f,t[20]=O,t[21]=i,t[22]=c,t[23]=A,t[24]=j,t[25]=M,t[26]=N,t[27]=P,t[28]=F,t[29]=I,t[30]=L,t[31]=R,t[32]=z,t[33]=ee,t[34]=B,t[35]=V,t[36]=te,t[37]=ne,t[38]=H,t[39]=U,t[40]=W,t[41]=G,t[42]=K,t[43]=re,t[44]=ie,t[45]=ae,t[46]=oe,t[47]=se}else A=t[23],j=t[24],M=t[25],N=t[26],P=t[27],F=t[28],I=t[29],L=t[30],R=t[31],z=t[32],ee=t[33],B=t[34],V=t[35],te=t[36],ne=t[37],H=t[38],U=t[39],W=t[40],G=t[41],K=t[42],re=t[43],ie=t[44],ae=t[45],oe=t[46],se=t[47];let q;t[66]!==C||t[67]!==m||t[68]!==_||t[69]!==A||t[70]!==b?(q=()=>xr({draftAnchor:m,draftBody:_,reviewKey:b,addComment:C,resetDraft:A}),t[66]=C,t[67]=m,t[68]=_,t[69]=A,t[70]=b,t[71]=q):q=t[71];let ce;return t[72]!==j||t[73]!==M||t[74]!==N||t[75]!==P||t[76]!==F||t[77]!==I||t[78]!==L||t[79]!==R||t[80]!==z||t[81]!==ee||t[82]!==B||t[83]!==V||t[84]!==te||t[85]!==ne||t[86]!==H||t[87]!==U||t[88]!==W||t[89]!==q||t[90]!==G||t[91]!==K||t[92]!==re||t[93]!==ie||t[94]!==ae||t[95]!==oe||t[96]!==se?(ce={collapsedOverride:G,toggledFiles:K,diffStyle:re,wordWrap:ie,reviewOpen:ae,draftAnchor:oe,draftBody:se,reviewKey:j,pendingComments:M,annotationPermissions:N,reviewBody:P,verdicts:F,setDiffStyle:I,setWordWrap:L,setReviewOpen:R,setDraftBody:z,setReviewBody:ee,clearComments:B,removeComments:V,clearReviewBody:te,resetDraft:ne,toggleAll:H,toggleFile:U,onSelectLines:W,addDraft:q},t[72]=j,t[73]=M,t[74]=N,t[75]=P,t[76]=F,t[77]=I,t[78]=L,t[79]=R,t[80]=z,t[81]=ee,t[82]=B,t[83]=V,t[84]=te,t[85]=ne,t[86]=H,t[87]=U,t[88]=W,t[89]=q,t[90]=G,t[91]=K,t[92]=re,t[93]=ie,t[94]=ae,t[95]=oe,t[96]=se,t[97]=ce):ce=t[97],ce}function fr(e){return e.clearSummary}function pr(e){return e.setSummary}function mr(e){return e.removeComments}function hr(e){return e.clear}function gr(e){return e.addComment}function _r(){return new Set}function vr(e){return e===`expanded`?`folded`:`expanded`}function yr(e,t,n){if(e)return e=>{t(e),n!==void 0&&n(e)}}function br(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function xr(e){let t=e.draftBody.trim();t.length!==0&&e.draftAnchor!==null&&(e.addComment(e.reviewKey,{id:st(),path:e.draftAnchor.path,...e.draftAnchor.oldPath===null?{}:{oldPath:e.draftAnchor.oldPath},position:e.draftAnchor.position,body:t}),e.resetDraft())}function Sr(e){let t=(0,$.c)(11),n;t[0]!==e.model.addDraft||t[1]!==e.model.draftAnchor||t[2]!==e.model.draftBody||t[3]!==e.model.resetDraft||t[4]!==e.model.setDraftBody?(n=e.model.draftAnchor===null?null:(0,Q.jsx)(er,{anchor:e.model.draftAnchor,body:e.model.draftBody,onBodyChange:e.model.setDraftBody,onCancel:e.model.resetDraft,onAdd:e.model.addDraft}),t[0]=e.model.addDraft,t[1]=e.model.draftAnchor,t[2]=e.model.draftBody,t[3]=e.model.resetDraft,t[4]=e.model.setDraftBody,t[5]=n):n=t[5];let r;t[6]===e?r=t[7]:(r=(0,Q.jsx)(Cr,{...e}),t[6]=e,t[7]=r);let i;return t[8]!==n||t[9]!==r?(i=(0,Q.jsxs)(Q.Fragment,{children:[n,r]}),t[8]=n,t[9]=r,t[10]=i):i=t[10],i}function Cr(e){let t=(0,$.c)(21);if(e.model.verdicts.length===0)return null;if(!e.model.reviewOpen){let n;t[0]===e.model?n=t[1]:(n=()=>e.model.setReviewOpen(!0),t[0]=e.model,t[1]=n);let r=e.model.pendingComments.length>0?` (${e.model.pendingComments.length})`:``,i;return t[2]!==n||t[3]!==r?(i=(0,Q.jsxs)(`button`,{type:`button`,className:`absolute bottom-3 right-4 rounded-md bg-foreground px-3 py-1.5 text-xs font-medium text-background shadow-sm hover:opacity-90`,onClick:n,children:[`Review`,r]}),t[2]=n,t[3]=r,t[4]=i):i=t[4],i}let n,r;t[5]===e.model?(n=t[6],r=t[7]):(n=t=>e.model.setReviewBody(e.model.reviewKey,t),r=t=>{t.length===0&&e.model.clearComments(e.model.reviewKey)},t[5]=e.model,t[6]=n,t[7]=r);let i;t[8]!==e.model||t[9]!==e.props?(i=async t=>{await e.props.onSubmitReview(t),e.model.removeComments(e.model.reviewKey,e.model.pendingComments.map(wr)),e.model.clearReviewBody(e.model.reviewKey,t.body),e.model.setReviewOpen(!1)},t[8]=e.model,t[9]=e.props,t[10]=i):i=t[10];let a;t[11]===e.model?a=t[12]:(a=()=>e.model.setReviewOpen(!1),t[11]=e.model,t[12]=a);let o;return t[13]!==e.model.pendingComments||t[14]!==e.model.reviewBody||t[15]!==e.model.verdicts||t[16]!==n||t[17]!==r||t[18]!==i||t[19]!==a?(o=(0,Q.jsx)(or,{verdicts:e.model.verdicts,pendingComments:e.model.pendingComments,body:e.model.reviewBody,onBodyChange:n,onPendingCommentsChange:r,onSubmit:i,onClose:a}),t[13]=e.model.pendingComments,t[14]=e.model.reviewBody,t[15]=e.model.verdicts,t[16]=n,t[17]=r,t[18]=i,t[19]=a,t[20]=o):o=t[20],o}function wr(e){return e.id}function Tr(e){let t=(0,$.c)(27),n=z(),r;t[0]!==e.environmentId||t[1]!==e.reference||t[2]!==e.selectedCommitOid?(r=a({environmentId:e.environmentId,input:{...e.reference,...e.selectedCommitOid===null?{}:{commit:e.selectedCommitOid}}}),t[0]=e.environmentId,t[1]=e.reference,t[2]=e.selectedCommitOid,t[3]=r):r=t[3];let i=r,o=pe(i),s=u(e.environmentId,e.reference),c;t[4]===o.data?.pages?c=t[5]:(c=o.data?.pages??[],t[4]=o.data?.pages,t[5]=c);let l;t[6]===o?l=t[7]:(l=()=>void o.fetchNextPage(),t[6]=o,t[7]=l);let d;t[8]!==i||t[9]!==n?(d=()=>void n.resetQueries({queryKey:i.queryKey,exact:!0}),t[8]=i,t[9]=n,t[10]=d):d=t[10];let f;t[11]!==e.reference||t[12]!==e.selectedCommitOid?(f=async t=>{if(e.reference.projectRepositoryId===void 0)throw Error(`This pull request has no canonical Command repository identity.`);return W.getPullRequestDiffFileContents({projectId:Number(e.reference.projectId),projectRepositoryId:e.reference.projectRepositoryId,number:e.reference.number,...t,...e.selectedCommitOid===null?{}:{commit:e.selectedCommitOid}})},t[11]=e.reference,t[12]=e.selectedCommitOid,t[13]=f):f=t[13];let p;t[14]!==s||t[15]!==e.reference?(p=t=>s.execute(async()=>{if(e.reference.projectRepositoryId===void 0)throw Error(`This pull request has no canonical Command repository identity.`);await W.submitPullRequestReview({projectId:Number(e.reference.projectId),projectRepositoryId:e.reference.projectRepositoryId,number:e.reference.number,idempotencyKey:crypto.randomUUID(),verdict:t.verdict,body:t.body,comments:t.comments.map(Er)})}),t[14]=s,t[15]=e.reference,t[16]=p):p=t[16];let m;return t[17]!==o.error||t[18]!==o.hasNextPage||t[19]!==o.isFetchingNextPage||t[20]!==o.isPending||t[21]!==c||t[22]!==l||t[23]!==d||t[24]!==f||t[25]!==p?(m={slices:c,loading:o.isPending,error:o.error,hasNextPage:o.hasNextPage,loadingNextPage:o.isFetchingNextPage,loadNextPage:l,refresh:d,loadFileContents:f,submitReview:p},t[17]=o.error,t[18]=o.hasNextPage,t[19]=o.isFetchingNextPage,t[20]=o.isPending,t[21]=c,t[22]=l,t[23]=d,t[24]=f,t[25]=p,t[26]=m):m=t[26],m}function Er(e){return{path:e.path,...e.oldPath===void 0?{}:{oldPath:e.oldPath},position:{...e.position},body:e.body}}function Dr(e){let t=(0,$.c)(23),[n,r]=(0,Z.useState)(null),i;t[0]!==e.activity?.commits||t[1]!==n?(i=e.activity?.commits.some(e=>e.oid===n)?n:null,t[0]=e.activity?.commits,t[1]=n,t[2]=i):i=t[2];let a=i,o;t[3]!==e.environmentId||t[4]!==e.reference||t[5]!==a?(o={environmentId:e.environmentId,reference:e.reference,selectedCommitOid:a},t[3]=e.environmentId,t[4]=e.reference,t[5]=a,t[6]=o):o=t[6];let s=Tr(o),c;t[7]!==s.slices||t[8]!==e?(c=t=>e.onSelectLines({...t,patch:b(s.slices.map(Or).join(`
4
4
  `),t.path)}),t[7]=s.slices,t[8]=e,t[9]=c):c=t[9];let l;return t[10]!==s.error||t[11]!==s.hasNextPage||t[12]!==s.loadFileContents||t[13]!==s.loadNextPage||t[14]!==s.loading||t[15]!==s.loadingNextPage||t[16]!==s.refresh||t[17]!==s.slices||t[18]!==s.submitReview||t[19]!==e||t[20]!==a||t[21]!==c?(l=(0,Q.jsx)(sr,{...e,selectedCommitOid:a,slices:s.slices,loading:s.loading,error:s.error,hasNextPage:s.hasNextPage,loadingNextPage:s.loadingNextPage,onSelectedCommitChange:r,onLoadNextPage:s.loadNextPage,onRefresh:s.refresh,onLoadFileContents:s.loadFileContents,onSubmitReview:s.submitReview,onSelectLines:c}),t[10]=s.error,t[11]=s.hasNextPage,t[12]=s.loadFileContents,t[13]=s.loadNextPage,t[14]=s.loading,t[15]=s.loadingNextPage,t[16]=s.refresh,t[17]=s.slices,t[18]=s.submitReview,t[19]=e,t[20]=a,t[21]=c,t[22]=l):l=t[22],l}function Or(e){return e.patch}export{Dr as default};
5
- //# sourceMappingURL=PullRequestCodePanel-dQ0P1BYv.js.map
5
+ //# sourceMappingURL=PullRequestCodePanel-D9vLGRM9.js.map
@@ -1,2 +1,2 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ha as t,Ua as n,Wa as r}from"./Stream-mUTFnSY9.js";import{Gt as i,Rs as a,Xt as o,Yn as s,Zt as c,gr as l}from"./WorkerPoolContext-DJIHDFVZ.js";import{dn as u}from"./CompositeItem-DTyKsv13.js";import{Nt as d}from"./src-DpAPOFgC.js";function f(e){return a({from:e.from,strict:e.strict,shouldThrow:e.shouldThrow,structuralSharing:e.structuralSharing,select:t=>e.select?e.select(t.search):t.search})}var p=u(`file-diff`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M9 10h6`,key:`9gxzsh`}],[`path`,{d:`M12 13V7`,key:`h0r20n`}],[`path`,{d:`M9 17h6`,key:`r8uit2`}]]);function m(e){return e.threadWorktreePath??e.projectCwd??void 0}function h(e){return e?.isRepo??!0}var g=n(),_=t();function v(e,t){return e==null||t==null?e===t:e.top===t.top&&e.bottom===t.bottom}var y=1e3,b=y*4,x=[0,1e-6,.99999,1],S={overscrollSize:y,intersectionObserverMargin:b,resizeDebugging:!1},C=0,w=-1,T=class e{static __STOP=!1;static __lastScrollPosition=0;__id=`virtualizer-${++w}`;config;type=`simple`;intersectionObserver;scrollTop=0;height=0;scrollHeight=0;windowSpecs={top:0,bottom:0};root;contentContainer;resizeObserver;observers=new Map;visibleInstances=new Map;visibleInstancesDirty=!1;instancesChanged=new Set;reconcileQueue=new Set;scrollDirty=!0;heightDirty=!0;scrollHeightDirty=!0;renderedObservers=0;connectQueue=new Map;constructor(e){this.config={...S,...e}}setup(t,n){if(this.root==null){this.root=t,this.resizeObserver=new ResizeObserver(this.handleContainerResize),this.intersectionObserver=new IntersectionObserver(this.handleIntersectionChange,{root:this.root,threshold:x,rootMargin:`${this.config.intersectionObserverMargin}px 0px ${this.config.intersectionObserverMargin}px 0px`}),t instanceof Document?this.setupWindow():this.setupElement(n),window.__INSTANCE=this,window.__TOGGLE=()=>{e.__STOP?(e.__STOP=!1,(this.getScrollContainerElement()??window).scrollTo({top:e.__lastScrollPosition}),c(this.computeRenderRangeAndEmit)):(e.__lastScrollPosition=this.getScrollTop(),e.__STOP=!0)};for(let[e,t]of this.connectQueue.entries())this.connect(e,t);this.connectQueue.clear(),this.markDOMDirty(),c(this.computeRenderRangeAndEmit)}}instanceChanged(e,t){this.instancesChanged.add(e),t&&this.markDOMDirty(),c(this.computeRenderRangeAndEmit)}requestHeightReconcile(e){this.reconcileQueue.add(e),c(this.computeRenderRangeAndEmit)}getWindowSpecs(){return this.windowSpecs.top===0&&this.windowSpecs.bottom===0&&(this.windowSpecs=i({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize})),this.windowSpecs}getRoot(){return this.root}isInstanceVisible(e,t){let n=this.getScrollTop(),r=this.getHeight(),i=this.config.intersectionObserverMargin,a=n-i,o=n+r+i;return!(e<a-t||e>o)}handleContainerResize=e=>{if(this.root==null)return;let t=!1;for(let n of e){let e=n.borderBoxSize[0].blockSize;this.root instanceof Document?e!==this.scrollHeight&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log(`Virtualizer: content size change`,this.__id,{sizeChange:e-C,newSize:e}),C=e)):n.target===this.root?e!==this.height&&(this.heightDirty=!0,t=!0):n.target===this.contentContainer&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log(`Virtualizer: scroller size change`,this.__id,{sizeChange:e-C,newSize:e}),C=e))}t&&c(this.computeRenderRangeAndEmit)};setupWindow(){if(this.root==null||!(this.root instanceof Document))throw Error(`Virtualizer.setupWindow: Invalid setup method`);window.addEventListener(`scroll`,this.handleWindowScroll,{passive:!0}),window.addEventListener(`resize`,this.handleWindowResize,{passive:!0}),this.resizeObserver?.observe(this.root.documentElement)}setupElement(e){if(this.root==null||this.root instanceof Document)throw Error(`Virtualizer.setupElement: Invalid setup method`);this.root.addEventListener(`scroll`,this.handleElementScroll,{passive:!0}),this.resizeObserver?.observe(this.root),e??=this.root.firstElementChild??void 0,e instanceof HTMLElement&&(this.contentContainer=e,this.resizeObserver?.observe(e))}cleanUp(){o(this.computeRenderRangeAndEmit),this.resizeObserver?.disconnect(),this.resizeObserver=void 0,this.intersectionObserver?.disconnect(),this.intersectionObserver=void 0,this.root?.removeEventListener(`scroll`,this.handleElementScroll),window.removeEventListener(`scroll`,this.handleWindowScroll),window.removeEventListener(`resize`,this.handleWindowResize),this.root=void 0,this.contentContainer=void 0,this.observers.clear(),this.visibleInstances.clear(),this.instancesChanged.clear(),this.reconcileQueue.clear(),this.connectQueue.clear(),this.visibleInstancesDirty=!1,this.windowSpecs={top:0,bottom:0},this.scrollTop=0,this.height=0,this.scrollHeight=0,this.scrollDirty=!0,this.heightDirty=!0,this.scrollHeightDirty=!0}getOffsetInScrollContainer(e){return this.getScrollTop()+E(e,this.getScrollContainerElement())}connect(e,t){if(this.observers.has(e))throw Error(`Virtualizer.connect: instance is already connected...`);return this.intersectionObserver==null?this.connectQueue.set(e,t):(this.intersectionObserver.observe(e),this.observers.set(e,t),this.instancesChanged.add(t),this.markDOMDirty(),c(this.computeRenderRangeAndEmit)),()=>this.disconnect(e)}disconnect(e){let t=this.observers.get(e);this.connectQueue.delete(e),t!=null&&(this.intersectionObserver?.unobserve(e),this.observers.delete(e),this.instancesChanged.delete(t),this.reconcileQueue.delete(t),this.visibleInstances.delete(e)&&(this.visibleInstancesDirty=!0),this.markDOMDirty(),c(this.computeRenderRangeAndEmit))}handleWindowResize=()=>{e.__STOP||window.innerHeight===this.height||(this.heightDirty=!0,c(this.computeRenderRangeAndEmit))};handleWindowScroll=()=>{e.__STOP||this.root==null||!(this.root instanceof Document)||(this.scrollDirty=!0,c(this.computeRenderRangeAndEmit))};handleElementScroll=()=>{e.__STOP||this.root==null||this.root instanceof Document||(this.scrollDirty=!0,c(this.computeRenderRangeAndEmit))};computeRenderRangeAndEmit=()=>{if(e.__STOP)return;let t=this.heightDirty||this.scrollHeightDirty,n=this.instancesChanged.size>0;if(this.instancesChanged.size===0){let e=i({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize});if(!t&&v(this.windowSpecs,e)&&this.renderedObservers===this.observers.size&&!this.visibleInstancesDirty&&this.reconcileQueue.size===0)return;this.windowSpecs=e}this.visibleInstancesDirty=!1,this.renderedObservers=this.observers.size;let r=this.getScrollAnchor(this.height),a=new Set;for(let e of t?this.observers.values():this.visibleInstances.values())e.onRender(t)&&a.add(e);for(let e of this.instancesChanged)a.has(e)||e.onRender(t)&&a.add(e);this.scrollFix(r);for(let e of a)this.reconcileQueue.delete(e),e.reconcileHeights();for(let e of this.reconcileQueue)e.reconcileHeights()&&(n=!0);this.reconcileQueue.clear(),n||=this.instancesChanged.size>0,n&&this.markDOMDirty(),(n||t)&&c(this.computeRenderRangeAndEmit),a.clear(),this.instancesChanged.clear()};scrollFix(e){if(e==null)return;let t=this.getScrollContainerElement(),{lineIndex:n,lineOffset:r,fileElement:i,fileOffset:a,fileTypeOffset:o}=e;if(n!=null&&r!=null){let e=i.shadowRoot?.querySelector(`[data-line][data-line-index="${n}"]`);if(e instanceof HTMLElement){let n=E(e,t);if(n!==r){let e=n-r;this.applyScrollFix(e)}return}}let s=E(i,t);if(o===`top`)s!==a&&this.applyScrollFix(s-a);else{let e=s+i.getBoundingClientRect().height;e!==a&&this.applyScrollFix(e-a)}}applyScrollFix(e){this.root==null||this.root instanceof Document?window.scrollTo({top:window.scrollY+e,behavior:`instant`}):this.root.scrollTo({top:this.root.scrollTop+e,behavior:`instant`}),this.markDOMDirty()}getScrollAnchor(e){let t=this.getScrollContainerElement(),n;for(let[r]of this.visibleInstances.entries()){let i=E(r,t),a=i+r.offsetHeight,o,s;a<=0?(o=a,s=`bottom`):(o=i,s=`top`);let c,l;if(a>0&&i<e)for(let e of r.shadowRoot?.querySelectorAll(`[data-line][data-line-index]`)??[]){if(!(e instanceof HTMLElement))continue;let n=e.dataset.lineIndex;if(n==null)continue;let r=E(e,t);if(!(r<0)){c=n,l=r;break}}if(n?.lineOffset!=null&&l==null)continue;let u=!1;(n==null||l!=null&&(n.lineOffset==null||l<n.lineOffset)||l==null&&n.lineOffset==null&&(o>=0&&(n.fileOffset<0||o<n.fileOffset)||o<0&&n.fileOffset<0&&o>n.fileOffset))&&(u=!0),u&&(n={fileElement:r,fileTypeOffset:s,fileOffset:o,lineIndex:c,lineOffset:l})}return n}handleIntersectionChange=e=>{this.scrollDirty=!0;for(let{target:t,isIntersecting:n}of e){if(!(t instanceof HTMLElement))throw Error(`Virtualizer.handleIntersectionChange: target not an HTMLElement`);let e=this.observers.get(t);e!=null&&(n&&!this.visibleInstances.has(t)?(e.setVisibility(!0),this.visibleInstances.set(t,e),this.visibleInstancesDirty=!0):!n&&this.visibleInstances.has(t)&&(e.setVisibility(!1),this.visibleInstances.delete(t),this.visibleInstancesDirty=!0))}this.visibleInstancesDirty&&c(this.computeRenderRangeAndEmit)};getScrollTop(){if(!this.scrollDirty)return this.scrollTop;this.scrollDirty=!1;let e=this.root==null?0:this.root instanceof Document?window.scrollY:this.root.scrollTop;return e=this.clampScrollTop(e),this.scrollTop=e,e}scrollTo({top:e,behavior:t=`auto`}){let{root:n}=this;if(n==null)return;let r=this.clampScrollTop(e);n instanceof Document?window.scrollTo({top:r,behavior:t}):n.scrollTo({top:r,behavior:t}),this.scrollDirty=!0,c(this.computeRenderRangeAndEmit)}clampScrollTop(e){return Math.max(0,Math.min(e,this.getScrollHeight()-this.getHeight()))}getScrollHeight(){return this.scrollHeightDirty?(this.scrollHeightDirty=!1,this.scrollHeight=this.root==null?0:this.root instanceof Document?this.root.documentElement.scrollHeight:this.root.scrollHeight,this.scrollHeight):this.scrollHeight}getHeight(){return this.heightDirty?(this.heightDirty=!1,this.height=this.root==null?0:this.root instanceof Document?globalThis.innerHeight:this.root.getBoundingClientRect().height,this.height):this.height}markDOMDirty(){this.scrollDirty=!0,this.scrollHeightDirty=!0,this.heightDirty=!0}getScrollContainerElement(){return this.root==null||this.root instanceof Document?void 0:this.root}};function E(e,t){let n=e.getBoundingClientRect(),r=t?.getBoundingClientRect().top??0;return n.top-r}var D=s.filter(e=>e!==`file`&&e!==`pull-request`);function O(e){return e===`1`||e===1||e===!0}function k(e){return e===`0`||e===0||e===!1}function A(e){if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0}function j(e){return typeof e==`string`&&D.includes(e)}function M(e){let t=new Set,n=[];for(let r of e)t.has(r)||(t.add(r),n.push(r));return n}function N(e){if(Array.isArray(e))return M(e.filter(j));if(typeof e!=`string`)return[];let t=e.trim();if(t.startsWith(`[`)&&t.endsWith(`]`))try{let e=JSON.parse(t);return Array.isArray(e)?M(e.filter(j)):[]}catch{return[]}return M(t.split(`,`).map(e=>e.trim()).filter(j))}function P(e){if(O(e.canvas))return`canvas`;if(O(e.preview))return`preview`;if(O(e.diff))return`diff`}function F(e,t){let n=N(e.rightPanelTabs),r=M(t&&!n.includes(t)?[...n,t]:n),i=A(e.rightPanelTabs)!==void 0,a=O(e.rightPanelOpen),o=k(e.rightPanelOpen);return{rightPanelOpen:a?!0:!o&&i,rightPanelTabs:r,stated:a||o||i,hasExplicitTabs:i}}function I(e,t){if(t===`preview`){let t=A(e.previewTabId);return t?{previewTabId:t}:{}}if(t!==`diff`)return{};let n=A(e.diffTurnId);if(!n)return{};let r=d.make(n),i=A(e.diffFilePath);return i?{diffTurnId:r,diffFilePath:i}:{diffTurnId:r}}function L(e){let t=(j(e.rightPanel)?e.rightPanel:void 0)??P(e),n=F(e,t);return{...n.stated?{rightPanelOpen:n.rightPanelOpen}:{},...t?{rightPanel:t}:{},...n.hasExplicitTabs&&n.rightPanelTabs.length>0?{rightPanelTabs:n.rightPanelTabs}:{},...I(e,t)}}function R(e){let t=(0,_.c)(6),n;bb0:{if(!e){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[0]=e):e=t[0],n=e;break bb0}n=e.turnDiffSummaries}let r=n,i,a;t[1]===r?a=t[2]:(a=l(r),t[1]=r,t[2]=a),i=a;let o=i,s;return t[3]!==o||t[4]!==r?(s={turnDiffSummaries:r,inferredCheckpointTurnCountByTurnId:o},t[3]=o,t[4]=r,t[5]=s):s=t[5],s}function z(e,t){return typeof window>`u`&&t!=null?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`template`,{shadowrootmode:`open`,dangerouslySetInnerHTML:{__html:t}}),e]}):(0,g.jsx)(g.Fragment,{children:e})}var B=e(r(),1),V=(0,B.createContext)(void 0);function H({children:e,config:t,className:n,style:r,contentClassName:i,contentStyle:a}){let[o]=(0,B.useState)(()=>typeof window<`u`?new T(t):void 0),s=(0,B.useCallback)(e=>{e==null?o?.cleanUp():o?.setup(e)},[o]);return(0,g.jsx)(V.Provider,{value:o,children:(0,g.jsx)(`div`,{className:n,style:r,ref:s,children:(0,g.jsx)(`div`,{className:i,style:a,children:e})})})}function U(){return(0,B.useContext)(V)}export{L as a,p as c,R as i,f as l,U as n,m as o,z as r,h as s,H as t};
2
- //# sourceMappingURL=Virtualizer-B7qA3afH.js.map
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ha as t,Ua as n,Wa as r}from"./Stream-mUTFnSY9.js";import{Gt as i,Rs as a,Xt as o,Yn as s,Zt as c,gr as l}from"./WorkerPoolContext-DfkvYwPY.js";import{dn as u}from"./CompositeItem-DTyKsv13.js";import{Nt as d}from"./src-DpAPOFgC.js";function f(e){return a({from:e.from,strict:e.strict,shouldThrow:e.shouldThrow,structuralSharing:e.structuralSharing,select:t=>e.select?e.select(t.search):t.search})}var p=u(`file-diff`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M9 10h6`,key:`9gxzsh`}],[`path`,{d:`M12 13V7`,key:`h0r20n`}],[`path`,{d:`M9 17h6`,key:`r8uit2`}]]);function m(e){return e.threadWorktreePath??e.projectCwd??void 0}function h(e){return e?.isRepo??!0}var g=n(),_=t();function v(e,t){return e==null||t==null?e===t:e.top===t.top&&e.bottom===t.bottom}var y=1e3,b=y*4,x=[0,1e-6,.99999,1],S={overscrollSize:y,intersectionObserverMargin:b,resizeDebugging:!1},C=0,w=-1,T=class e{static __STOP=!1;static __lastScrollPosition=0;__id=`virtualizer-${++w}`;config;type=`simple`;intersectionObserver;scrollTop=0;height=0;scrollHeight=0;windowSpecs={top:0,bottom:0};root;contentContainer;resizeObserver;observers=new Map;visibleInstances=new Map;visibleInstancesDirty=!1;instancesChanged=new Set;reconcileQueue=new Set;scrollDirty=!0;heightDirty=!0;scrollHeightDirty=!0;renderedObservers=0;connectQueue=new Map;constructor(e){this.config={...S,...e}}setup(t,n){if(this.root==null){this.root=t,this.resizeObserver=new ResizeObserver(this.handleContainerResize),this.intersectionObserver=new IntersectionObserver(this.handleIntersectionChange,{root:this.root,threshold:x,rootMargin:`${this.config.intersectionObserverMargin}px 0px ${this.config.intersectionObserverMargin}px 0px`}),t instanceof Document?this.setupWindow():this.setupElement(n),window.__INSTANCE=this,window.__TOGGLE=()=>{e.__STOP?(e.__STOP=!1,(this.getScrollContainerElement()??window).scrollTo({top:e.__lastScrollPosition}),c(this.computeRenderRangeAndEmit)):(e.__lastScrollPosition=this.getScrollTop(),e.__STOP=!0)};for(let[e,t]of this.connectQueue.entries())this.connect(e,t);this.connectQueue.clear(),this.markDOMDirty(),c(this.computeRenderRangeAndEmit)}}instanceChanged(e,t){this.instancesChanged.add(e),t&&this.markDOMDirty(),c(this.computeRenderRangeAndEmit)}requestHeightReconcile(e){this.reconcileQueue.add(e),c(this.computeRenderRangeAndEmit)}getWindowSpecs(){return this.windowSpecs.top===0&&this.windowSpecs.bottom===0&&(this.windowSpecs=i({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize})),this.windowSpecs}getRoot(){return this.root}isInstanceVisible(e,t){let n=this.getScrollTop(),r=this.getHeight(),i=this.config.intersectionObserverMargin,a=n-i,o=n+r+i;return!(e<a-t||e>o)}handleContainerResize=e=>{if(this.root==null)return;let t=!1;for(let n of e){let e=n.borderBoxSize[0].blockSize;this.root instanceof Document?e!==this.scrollHeight&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log(`Virtualizer: content size change`,this.__id,{sizeChange:e-C,newSize:e}),C=e)):n.target===this.root?e!==this.height&&(this.heightDirty=!0,t=!0):n.target===this.contentContainer&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log(`Virtualizer: scroller size change`,this.__id,{sizeChange:e-C,newSize:e}),C=e))}t&&c(this.computeRenderRangeAndEmit)};setupWindow(){if(this.root==null||!(this.root instanceof Document))throw Error(`Virtualizer.setupWindow: Invalid setup method`);window.addEventListener(`scroll`,this.handleWindowScroll,{passive:!0}),window.addEventListener(`resize`,this.handleWindowResize,{passive:!0}),this.resizeObserver?.observe(this.root.documentElement)}setupElement(e){if(this.root==null||this.root instanceof Document)throw Error(`Virtualizer.setupElement: Invalid setup method`);this.root.addEventListener(`scroll`,this.handleElementScroll,{passive:!0}),this.resizeObserver?.observe(this.root),e??=this.root.firstElementChild??void 0,e instanceof HTMLElement&&(this.contentContainer=e,this.resizeObserver?.observe(e))}cleanUp(){o(this.computeRenderRangeAndEmit),this.resizeObserver?.disconnect(),this.resizeObserver=void 0,this.intersectionObserver?.disconnect(),this.intersectionObserver=void 0,this.root?.removeEventListener(`scroll`,this.handleElementScroll),window.removeEventListener(`scroll`,this.handleWindowScroll),window.removeEventListener(`resize`,this.handleWindowResize),this.root=void 0,this.contentContainer=void 0,this.observers.clear(),this.visibleInstances.clear(),this.instancesChanged.clear(),this.reconcileQueue.clear(),this.connectQueue.clear(),this.visibleInstancesDirty=!1,this.windowSpecs={top:0,bottom:0},this.scrollTop=0,this.height=0,this.scrollHeight=0,this.scrollDirty=!0,this.heightDirty=!0,this.scrollHeightDirty=!0}getOffsetInScrollContainer(e){return this.getScrollTop()+E(e,this.getScrollContainerElement())}connect(e,t){if(this.observers.has(e))throw Error(`Virtualizer.connect: instance is already connected...`);return this.intersectionObserver==null?this.connectQueue.set(e,t):(this.intersectionObserver.observe(e),this.observers.set(e,t),this.instancesChanged.add(t),this.markDOMDirty(),c(this.computeRenderRangeAndEmit)),()=>this.disconnect(e)}disconnect(e){let t=this.observers.get(e);this.connectQueue.delete(e),t!=null&&(this.intersectionObserver?.unobserve(e),this.observers.delete(e),this.instancesChanged.delete(t),this.reconcileQueue.delete(t),this.visibleInstances.delete(e)&&(this.visibleInstancesDirty=!0),this.markDOMDirty(),c(this.computeRenderRangeAndEmit))}handleWindowResize=()=>{e.__STOP||window.innerHeight===this.height||(this.heightDirty=!0,c(this.computeRenderRangeAndEmit))};handleWindowScroll=()=>{e.__STOP||this.root==null||!(this.root instanceof Document)||(this.scrollDirty=!0,c(this.computeRenderRangeAndEmit))};handleElementScroll=()=>{e.__STOP||this.root==null||this.root instanceof Document||(this.scrollDirty=!0,c(this.computeRenderRangeAndEmit))};computeRenderRangeAndEmit=()=>{if(e.__STOP)return;let t=this.heightDirty||this.scrollHeightDirty,n=this.instancesChanged.size>0;if(this.instancesChanged.size===0){let e=i({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize});if(!t&&v(this.windowSpecs,e)&&this.renderedObservers===this.observers.size&&!this.visibleInstancesDirty&&this.reconcileQueue.size===0)return;this.windowSpecs=e}this.visibleInstancesDirty=!1,this.renderedObservers=this.observers.size;let r=this.getScrollAnchor(this.height),a=new Set;for(let e of t?this.observers.values():this.visibleInstances.values())e.onRender(t)&&a.add(e);for(let e of this.instancesChanged)a.has(e)||e.onRender(t)&&a.add(e);this.scrollFix(r);for(let e of a)this.reconcileQueue.delete(e),e.reconcileHeights();for(let e of this.reconcileQueue)e.reconcileHeights()&&(n=!0);this.reconcileQueue.clear(),n||=this.instancesChanged.size>0,n&&this.markDOMDirty(),(n||t)&&c(this.computeRenderRangeAndEmit),a.clear(),this.instancesChanged.clear()};scrollFix(e){if(e==null)return;let t=this.getScrollContainerElement(),{lineIndex:n,lineOffset:r,fileElement:i,fileOffset:a,fileTypeOffset:o}=e;if(n!=null&&r!=null){let e=i.shadowRoot?.querySelector(`[data-line][data-line-index="${n}"]`);if(e instanceof HTMLElement){let n=E(e,t);if(n!==r){let e=n-r;this.applyScrollFix(e)}return}}let s=E(i,t);if(o===`top`)s!==a&&this.applyScrollFix(s-a);else{let e=s+i.getBoundingClientRect().height;e!==a&&this.applyScrollFix(e-a)}}applyScrollFix(e){this.root==null||this.root instanceof Document?window.scrollTo({top:window.scrollY+e,behavior:`instant`}):this.root.scrollTo({top:this.root.scrollTop+e,behavior:`instant`}),this.markDOMDirty()}getScrollAnchor(e){let t=this.getScrollContainerElement(),n;for(let[r]of this.visibleInstances.entries()){let i=E(r,t),a=i+r.offsetHeight,o,s;a<=0?(o=a,s=`bottom`):(o=i,s=`top`);let c,l;if(a>0&&i<e)for(let e of r.shadowRoot?.querySelectorAll(`[data-line][data-line-index]`)??[]){if(!(e instanceof HTMLElement))continue;let n=e.dataset.lineIndex;if(n==null)continue;let r=E(e,t);if(!(r<0)){c=n,l=r;break}}if(n?.lineOffset!=null&&l==null)continue;let u=!1;(n==null||l!=null&&(n.lineOffset==null||l<n.lineOffset)||l==null&&n.lineOffset==null&&(o>=0&&(n.fileOffset<0||o<n.fileOffset)||o<0&&n.fileOffset<0&&o>n.fileOffset))&&(u=!0),u&&(n={fileElement:r,fileTypeOffset:s,fileOffset:o,lineIndex:c,lineOffset:l})}return n}handleIntersectionChange=e=>{this.scrollDirty=!0;for(let{target:t,isIntersecting:n}of e){if(!(t instanceof HTMLElement))throw Error(`Virtualizer.handleIntersectionChange: target not an HTMLElement`);let e=this.observers.get(t);e!=null&&(n&&!this.visibleInstances.has(t)?(e.setVisibility(!0),this.visibleInstances.set(t,e),this.visibleInstancesDirty=!0):!n&&this.visibleInstances.has(t)&&(e.setVisibility(!1),this.visibleInstances.delete(t),this.visibleInstancesDirty=!0))}this.visibleInstancesDirty&&c(this.computeRenderRangeAndEmit)};getScrollTop(){if(!this.scrollDirty)return this.scrollTop;this.scrollDirty=!1;let e=this.root==null?0:this.root instanceof Document?window.scrollY:this.root.scrollTop;return e=this.clampScrollTop(e),this.scrollTop=e,e}scrollTo({top:e,behavior:t=`auto`}){let{root:n}=this;if(n==null)return;let r=this.clampScrollTop(e);n instanceof Document?window.scrollTo({top:r,behavior:t}):n.scrollTo({top:r,behavior:t}),this.scrollDirty=!0,c(this.computeRenderRangeAndEmit)}clampScrollTop(e){return Math.max(0,Math.min(e,this.getScrollHeight()-this.getHeight()))}getScrollHeight(){return this.scrollHeightDirty?(this.scrollHeightDirty=!1,this.scrollHeight=this.root==null?0:this.root instanceof Document?this.root.documentElement.scrollHeight:this.root.scrollHeight,this.scrollHeight):this.scrollHeight}getHeight(){return this.heightDirty?(this.heightDirty=!1,this.height=this.root==null?0:this.root instanceof Document?globalThis.innerHeight:this.root.getBoundingClientRect().height,this.height):this.height}markDOMDirty(){this.scrollDirty=!0,this.scrollHeightDirty=!0,this.heightDirty=!0}getScrollContainerElement(){return this.root==null||this.root instanceof Document?void 0:this.root}};function E(e,t){let n=e.getBoundingClientRect(),r=t?.getBoundingClientRect().top??0;return n.top-r}var D=s.filter(e=>e!==`file`&&e!==`pull-request`);function O(e){return e===`1`||e===1||e===!0}function k(e){return e===`0`||e===0||e===!1}function A(e){if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0}function j(e){return typeof e==`string`&&D.includes(e)}function M(e){let t=new Set,n=[];for(let r of e)t.has(r)||(t.add(r),n.push(r));return n}function N(e){if(Array.isArray(e))return M(e.filter(j));if(typeof e!=`string`)return[];let t=e.trim();if(t.startsWith(`[`)&&t.endsWith(`]`))try{let e=JSON.parse(t);return Array.isArray(e)?M(e.filter(j)):[]}catch{return[]}return M(t.split(`,`).map(e=>e.trim()).filter(j))}function P(e){if(O(e.canvas))return`canvas`;if(O(e.preview))return`preview`;if(O(e.diff))return`diff`}function F(e,t){let n=N(e.rightPanelTabs),r=M(t&&!n.includes(t)?[...n,t]:n),i=A(e.rightPanelTabs)!==void 0,a=O(e.rightPanelOpen),o=k(e.rightPanelOpen);return{rightPanelOpen:a?!0:!o&&i,rightPanelTabs:r,stated:a||o||i,hasExplicitTabs:i}}function I(e,t){if(t===`preview`){let t=A(e.previewTabId);return t?{previewTabId:t}:{}}if(t!==`diff`)return{};let n=A(e.diffTurnId);if(!n)return{};let r=d.make(n),i=A(e.diffFilePath);return i?{diffTurnId:r,diffFilePath:i}:{diffTurnId:r}}function L(e){let t=(j(e.rightPanel)?e.rightPanel:void 0)??P(e),n=F(e,t);return{...n.stated?{rightPanelOpen:n.rightPanelOpen}:{},...t?{rightPanel:t}:{},...n.hasExplicitTabs&&n.rightPanelTabs.length>0?{rightPanelTabs:n.rightPanelTabs}:{},...I(e,t)}}function R(e){let t=(0,_.c)(6),n;bb0:{if(!e){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[0]=e):e=t[0],n=e;break bb0}n=e.turnDiffSummaries}let r=n,i,a;t[1]===r?a=t[2]:(a=l(r),t[1]=r,t[2]=a),i=a;let o=i,s;return t[3]!==o||t[4]!==r?(s={turnDiffSummaries:r,inferredCheckpointTurnCountByTurnId:o},t[3]=o,t[4]=r,t[5]=s):s=t[5],s}function z(e,t){return typeof window>`u`&&t!=null?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`template`,{shadowrootmode:`open`,dangerouslySetInnerHTML:{__html:t}}),e]}):(0,g.jsx)(g.Fragment,{children:e})}var B=e(r(),1),V=(0,B.createContext)(void 0);function H({children:e,config:t,className:n,style:r,contentClassName:i,contentStyle:a}){let[o]=(0,B.useState)(()=>typeof window<`u`?new T(t):void 0),s=(0,B.useCallback)(e=>{e==null?o?.cleanUp():o?.setup(e)},[o]);return(0,g.jsx)(V.Provider,{value:o,children:(0,g.jsx)(`div`,{className:n,style:r,ref:s,children:(0,g.jsx)(`div`,{className:i,style:a,children:e})})})}function U(){return(0,B.useContext)(V)}export{L as a,p as c,R as i,f as l,U as n,m as o,z as r,h as s,H as t};
2
+ //# sourceMappingURL=Virtualizer-pdZw7YnL.js.map