@p4code/cli 0.1.37 → 0.1.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{n as t,r as n,t as r}from"./compiler-runtime-CLAvuQ-D.js";import{A as i,Ac as a,C as o,Cc as s,E as c,Ec as l,Hs as u,I as d,Is as f,O as p,Qr as m,Uu as h,Vu as g,Wt as _,ai as v,ci as y,di as b,dl as x,fi as S,g as C,gc as w,hc as T,ic as E,in as D,k as ee,li as O,mi as te,ni as k,oi as A,pc as j,pi as M,si as ne,u as re,vc as N,w as ie,ws as P}from"./terminal-links-B2KXT7CK.js";import{t as F}from"./arrow-right-BnQZ60ie.js";import{A as I,An as L,Ar as ae,Dr as oe,F as R,G as z,Gr as se,M as B,Mn as V,Mr as ce,N as H,Nn as U,Nr as le,O as W,Or as ue,P as G,Pn as K,Qn as q,Rr as J,Vr as de,a as fe,ar as pe,c as me,cr as he,dr as ge,er as _e,fr as ve,g as ye,hr as Y,i as be,ir as xe,j as Se,jn as Ce,jr as we,k as Te,lr as Ee,mr as X,n as De,nr as Oe,o as ke,or as Ae,pr as je,r as Me,rr as Ne,s as Pe,sr as Fe,t as Ie,tr as Le,ur as Re}from"./index-DYDaZ0DX.js";var ze=P(`camera`,[[`path`,{d:`M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z`,key:`18u6gg`}],[`circle`,{cx:`12`,cy:`13`,r:`3`,key:`1vg3eu`}]]),Be=P(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),Ve=P(`mouse-pointer-2`,[[`path`,{d:`M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z`,key:`edeuup`}]]),He=P(`radio-tower`,[[`path`,{d:`M4.9 16.1C1 12.2 1 5.8 4.9 1.9`,key:`s0qx1y`}],[`path`,{d:`M7.8 4.7a6.14 6.14 0 0 0-.8 7.5`,key:`1idnkw`}],[`circle`,{cx:`12`,cy:`9`,r:`2`,key:`1092wv`}],[`path`,{d:`M16.2 4.8c2 2 2.26 5.11.8 7.47`,key:`ojru2q`}],[`path`,{d:`M19.1 1.9a9.96 9.96 0 0 1 0 14.1`,key:`rhi7fg`}],[`path`,{d:`M9.5 18h5`,key:`mfy3pd`}],[`path`,{d:`m8 22 4-11 4 11`,key:`25yftu`}]]),Z=e(n(),1),Q=r(),$=t();function Ue(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=_(`relative inline-flex w-full min-w-0 items-center rounded-lg border border-input bg-background not-dark:bg-clip-padding text-base text-foreground shadow-xs/5 ring-ring/24 transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] not-has-[input:disabled,textarea:disabled]:not-has-[input:focus-visible,textarea:focus-visible]:not-has-[input[aria-invalid],textarea[aria-invalid]]:before:shadow-[0_1px_--theme(--color-black/4%)] has-[input:focus-visible,textarea:focus-visible]:has-[input[aria-invalid],textarea[aria-invalid]]:border-destructive/64 has-[input:focus-visible,textarea:focus-visible]:has-[input[aria-invalid],textarea[aria-invalid]]:ring-destructive/16 has-[textarea]:h-auto has-data-[align=block-end]:h-auto has-data-[align=block-start]:h-auto has-data-[align=block-end]:flex-col has-data-[align=block-start]:flex-col has-[input:focus-visible,textarea:focus-visible]:border-ring has-[input[aria-invalid],textarea[aria-invalid]]:border-destructive/36 has-autofill:bg-foreground/4 has-[input:disabled,textarea:disabled]:opacity-64 has-[input:disabled,textarea:disabled,input:focus-visible,textarea:focus-visible,input[aria-invalid],textarea[aria-invalid]]:shadow-none has-[input:focus-visible,textarea:focus-visible]:ring-[3px] sm:text-sm dark:bg-input/32 dark:has-autofill:bg-foreground/8 dark:has-[input[aria-invalid],textarea[aria-invalid]]:ring-destructive/24 dark:not-has-[input:disabled,textarea:disabled]:not-has-[input:focus-visible,textarea:focus-visible]:not-has-[input[aria-invalid],textarea[aria-invalid]]:before:shadow-[0_-1px_--theme(--color-white/6%)] has-data-[align=inline-start]:**:[[data-size=sm]_input]:ps-1.5 has-data-[align=inline-end]:**:[[data-size=sm]_input]:pe-1.5 *:[[data-slot=input-control],[data-slot=textarea-control]]:contents *:[[data-slot=input-control],[data-slot=textarea-control]]:before:hidden has-[[data-align=block-start],[data-align=block-end]]:**:[input]:h-auto has-data-[align=inline-start]:**:[input]:ps-2 has-data-[align=inline-end]:**:[input]:pe-2 has-data-[align=block-end]:**:[input]:pt-1.5 has-data-[align=block-start]:**:[input]:pb-1.5 **:[textarea]:min-h-20.5 **:[textarea]:resize-none **:[textarea]:py-[calc(--spacing(3)-1px)] **:[textarea]:max-sm:min-h-23.5 **:[textarea_button]:rounded-[calc(var(--radius-md)-1px)]`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`div`,{className:i,"data-slot":`input-group`,role:`group`,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var We=f(`[&_svg]:-mx-0.5 flex h-auto cursor-text select-none items-center justify-center gap-2 leading-none [&>kbd]:rounded-[calc(var(--radius)-5px)] in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4.5 sm:in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4 not-has-[button]:**:[svg:not([class*='opacity-'])]:opacity-80`,{defaultVariants:{align:`inline-start`},variants:{align:{"block-end":`order-last w-full justify-start px-[calc(--spacing(3)-1px)] pb-[calc(--spacing(3)-1px)] [.border-t]:pt-[calc(--spacing(3)-1px)] [[data-size=sm]+&]:px-[calc(--spacing(2.5)-1px)]`,"block-start":`order-first w-full justify-start px-[calc(--spacing(3)-1px)] pt-[calc(--spacing(3)-1px)] [.border-b]:pb-[calc(--spacing(3)-1px)] [[data-size=sm]+&]:px-[calc(--spacing(2.5)-1px)]`,"inline-end":`has-[>:last-child[data-slot=badge]]:-me-1.5 has-[>button]:-me-2 order-last pe-[calc(--spacing(3)-1px)] has-[>kbd:last-child]:me-[-0.35rem] [[data-size=sm]+&]:pe-[calc(--spacing(2.5)-1px)]`,"inline-start":`has-[>:last-child[data-slot=badge]]:-ms-1.5 has-[>button]:-ms-2 order-first ps-[calc(--spacing(3)-1px)] has-[>kbd:last-child]:ms-[-0.35rem] [[data-size=sm]+&]:ps-[calc(--spacing(2.5)-1px)]`}}});function Ge(e){let t=(0,Q.c)(11),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,align:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i===void 0?`inline-start`:i,o;t[4]!==a||t[5]!==n?(o=_(We({align:a}),n),t[4]=a,t[5]=n,t[6]=o):o=t[6];let s;return t[7]!==a||t[8]!==r||t[9]!==o?(s=(0,$.jsx)(`div`,{className:o,"data-align":a,"data-slot":`input-group-addon`,onMouseDown:Ke,...r}),t[7]=a,t[8]=r,t[9]=o,t[10]=s):s=t[10],s}function Ke(e){if(e.target.closest(`button, a, input, select, textarea, [role='button'], [role='combobox'], [role='listbox'], [data-slot='select-trigger']`))return;e.preventDefault();let t=e.currentTarget.parentElement,n=t?.querySelector(`input, textarea`);n&&!t?.querySelector(`input:focus, textarea:focus`)&&n.focus()}function qe(e){let t=(0,Q.c)(6),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;return t[3]!==n||t[4]!==r?(i=(0,$.jsx)(q,{className:n,unstyled:!0,...r}),t[3]=n,t[4]=r,t[5]=i):i=t[5],i}var Je=()=>{};function Ye(e){let t=(0,Q.c)(98),{url:n,displayUrl:r,loading:i,loadProgress:a,canGoBack:s,canGoForward:l,refreshDisabled:u,inputDisabled:d,focusUrlNonce:f,onBack:p,onForward:h,onRefresh:g,onSubmit:v,onOpenInBrowser:y,onCapture:b,captureDisabled:x,recording:S,onPictureInPicture:C,pictureInPicture:w,pictureInPictureDisabled:T,onPickElement:E,pickActive:D,pickDisabled:ee,pickDisabledReason:O,trailingActions:te}=e,k=(0,Z.useRef)(null),[A,j]=(0,Z.useState)(n),[M,ne]=(0,Z.useState)(!1),re,N;t[0]===f?(re=t[1],N=t[2]):(re=()=>{if(f==null)return;let e=k.current;e&&e.focus()},N=[f],t[0]=f,t[1]=re,t[2]=N),(0,Z.useEffect)(re,N);let P;t[3]!==A||t[4]!==v?(P=e=>{e?.preventDefault();let t=A.trim();t.length!==0&&(v(t),k.current?.blur())},t[3]=A,t[4]=v,t[5]=P):P=t[5];let I=P,L=s?p:Je,ae=!s,R;t[6]!==L||t[7]!==ae?(R=(0,$.jsx)(m,{variant:`ghost`,size:`icon-xs`,onClick:L,disabled:ae,"aria-label":`Back`,type:`button`}),t[6]=L,t[7]=ae,t[8]=R):R=t[8];let z;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,$.jsx)(se,{}),t[9]=z):z=t[9];let B;t[10]===R?B=t[11]:(B=(0,$.jsx)(c,{render:R,children:z}),t[10]=R,t[11]=B);let V;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(V=(0,$.jsx)(ie,{children:`Back`}),t[12]=V):V=t[12];let H;t[13]===B?H=t[14]:(H=(0,$.jsxs)(o,{children:[B,V]}),t[13]=B,t[14]=H);let U=l?h:Je,le=!l,W;t[15]!==U||t[16]!==le?(W=(0,$.jsx)(m,{variant:`ghost`,size:`icon-xs`,onClick:U,disabled:le,"aria-label":`Forward`,type:`button`}),t[15]=U,t[16]=le,t[17]=W):W=t[17];let ue;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(ue=(0,$.jsx)(F,{}),t[18]=ue):ue=t[18];let G;t[19]===W?G=t[20]:(G=(0,$.jsx)(c,{render:W,children:ue}),t[19]=W,t[20]=G);let K;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(K=(0,$.jsx)(ie,{children:`Forward`}),t[21]=K):K=t[21];let q;t[22]===G?q=t[23]:(q=(0,$.jsxs)(o,{children:[G,K]}),t[22]=G,t[23]=q);let J=u?Je:g,fe=i?`Stop`:`Refresh`,pe;t[24]!==u||t[25]!==J||t[26]!==fe?(pe=(0,$.jsx)(m,{variant:`ghost`,size:`icon-xs`,onClick:J,disabled:u,"aria-label":fe,type:`button`}),t[24]=u,t[25]=J,t[26]=fe,t[27]=pe):pe=t[27];let me=i&&`animate-spin`,he;t[28]===me?he=t[29]:(he=_(me),t[28]=me,t[29]=he);let ge;t[30]===he?ge=t[31]:(ge=(0,$.jsx)(oe,{className:he}),t[30]=he,t[31]=ge);let _e;t[32]!==pe||t[33]!==ge?(_e=(0,$.jsx)(c,{render:pe,children:ge}),t[32]=pe,t[33]=ge,t[34]=_e):_e=t[34];let ve=i?`Loading…`:`Refresh`,ye;t[35]===ve?ye=t[36]:(ye=(0,$.jsx)(ie,{children:ve}),t[35]=ve,t[36]=ye);let Y;t[37]!==_e||t[38]!==ye?(Y=(0,$.jsxs)(o,{children:[_e,ye]}),t[37]=_e,t[38]=ye,t[39]=Y):Y=t[39];let be;t[40]!==H||t[41]!==q||t[42]!==Y?(be=(0,$.jsxs)(`div`,{className:`flex items-center gap-0.5`,role:`group`,"aria-label":`Navigation`,children:[H,q,Y]}),t[40]=H,t[41]=q,t[42]=Y,t[43]=be):be=t[43];let xe=M?A:r??n,Se=y&&!M&&`group-hover/address:pe-7 transition-[padding]`,Ce;t[44]===Se?Ce=t[45]:(Ce=_(Se),t[44]=Se,t[45]=Ce);let Te;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(Te=e=>j(e.target.value),t[46]=Te):Te=t[46];let Ee;t[47]===n?Ee=t[48]:(Ee=()=>{j(n),ne(!0),queueMicrotask(()=>k.current?.select())},t[47]=n,t[48]=Ee);let X;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(X=()=>{ne(!1)},t[49]=X):X=t[49];let De;t[50]!==I||t[51]!==n?(De=e=>{e.key===`Enter`&&I(e),e.key===`Escape`&&(e.preventDefault(),j(n),k.current?.blur())},t[50]=I,t[51]=n,t[52]=De):De=t[52];let Oe;t[53]!==d||t[54]!==xe||t[55]!==Ce||t[56]!==Ee||t[57]!==De?(Oe=(0,$.jsx)(c,{render:(0,$.jsx)(qe,{ref:k,value:xe,className:Ce,onChange:Te,onFocus:Ee,onBlur:X,onKeyDown:De,placeholder:`Search or enter URL`,spellCheck:!1,disabled:d,"data-preview-url-input":!0,size:`sm`})}),t[53]=d,t[54]=xe,t[55]=Ce,t[56]=Ee,t[57]=De,t[58]=Oe):Oe=t[58];let ke;t[59]!==r||t[60]!==M||t[61]!==n?(ke=!M&&r?(0,$.jsx)(ie,{children:n}):null,t[59]=r,t[60]=M,t[61]=n,t[62]=ke):ke=t[62];let Ae;t[63]!==Oe||t[64]!==ke?(Ae=(0,$.jsxs)(o,{children:[Oe,ke]}),t[63]=Oe,t[64]=ke,t[65]=Ae):Ae=t[65];let je;t[66]!==M||t[67]!==y?(je=y&&!M?(0,$.jsx)(Ge,{align:`inline-end`,className:`pointer-events-none absolute inset-y-0 right-0 opacity-0 transition-opacity group-hover/address:pointer-events-auto group-hover/address:opacity-100`,children:(0,$.jsxs)(o,{children:[(0,$.jsx)(c,{render:(0,$.jsx)(m,{variant:`ghost`,size:`icon-xs`,onClick:y,"aria-label":`Open in system browser`,type:`button`}),children:(0,$.jsx)(de,{})}),(0,$.jsx)(ie,{children:`Open in system browser`})]})}):null,t[66]=M,t[67]=y,t[68]=je):je=t[68];let Me;t[69]!==Ae||t[70]!==je?(Me=(0,$.jsxs)(Ue,{className:`group/address h-7 flex-1 rounded-md border-transparent bg-transparent shadow-none before:shadow-none hover:bg-muted/40 focus-within:bg-background`,children:[Ae,je]}),t[69]=Ae,t[70]=je,t[71]=Me):Me=t[71];let Ne;t[72]!==E||t[73]!==D||t[74]!==ee||t[75]!==O?(Ne=E?(0,$.jsxs)(o,{children:[(0,$.jsx)(c,{render:(0,$.jsx)(m,{variant:D?`secondary`:`ghost`,size:`icon-xs`,onClick:E,disabled:ee,"aria-label":D?`Cancel annotation`:`Annotate preview`,"aria-pressed":D?`true`:`false`,type:`button`}),children:(0,$.jsx)(ce,{className:_(D&&`text-primary`)})}),(0,$.jsx)(ie,{children:ee&&O?O:D?`Cancel annotation (Esc)`:`Annotate elements, regions, and drawings`})]}):null,t[72]=E,t[73]=D,t[74]=ee,t[75]=O,t[76]=Ne):Ne=t[76];let Pe;t[77]!==x||t[78]!==b||t[79]!==S?(Pe=b?(0,$.jsxs)(o,{children:[(0,$.jsxs)(c,{render:(0,$.jsx)(m,{variant:S?`secondary`:`ghost`,size:`icon-xs`,onClick:e=>b(e.shiftKey),"aria-label":S?`Stop recording`:`Capture screenshot`,type:`button`,className:`relative`,disabled:x}),children:[(0,$.jsx)(ze,{className:_(S&&`text-destructive`)}),S?(0,$.jsx)(`span`,{className:`absolute right-0.5 top-0.5 size-1.5 animate-status-pulse rounded-full bg-destructive`}):null]}),(0,$.jsx)(ie,{children:S?`Stop recording`:`Screenshot · Shift-click to record`})]}):null,t[77]=x,t[78]=b,t[79]=S,t[80]=Pe):Pe=t[80];let Fe;t[81]!==C||t[82]!==w||t[83]!==T?(Fe=C?(0,$.jsxs)(o,{children:[(0,$.jsx)(c,{render:(0,$.jsx)(m,{variant:w?`secondary`:`ghost`,size:`icon-xs`,onClick:C,"aria-label":w?`Close floating preview`:`Float preview over chat`,"aria-pressed":w?`true`:`false`,type:`button`,disabled:T}),children:(0,$.jsx)(we,{className:_(w&&`text-primary`)})}),(0,$.jsx)(ie,{children:w?`Close floating preview`:`Float preview over chat`})]}):null,t[81]=C,t[82]=w,t[83]=T,t[84]=Fe):Fe=t[84];let Ie;t[85]!==I||t[86]!==be||t[87]!==Me||t[88]!==Ne||t[89]!==Pe||t[90]!==Fe||t[91]!==te?(Ie=(0,$.jsxs)(`form`,{onSubmit:I,className:`surface-subheader gap-1 px-2`,"data-surface-subheader":!0,children:[be,Me,Ne,Pe,Fe,te]}),t[85]=I,t[86]=be,t[87]=Me,t[88]=Ne,t[89]=Pe,t[90]=Fe,t[91]=te,t[92]=Ie):Ie=t[92];let Le;t[93]===a?Le=t[94]:(Le=a>0?(0,$.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute bottom-0 left-0 z-10 h-0.5 rounded-r-full bg-primary transition-all duration-150 ease-out`,style:{width:`${a}%`,boxShadow:`0 0 6px 1px var(--color-ring)`}}):null,t[93]=a,t[94]=Le);let Re;return t[95]!==Ie||t[96]!==Le?(Re=(0,$.jsxs)(`div`,{className:`relative`,children:[Ie,Le]}),t[95]=Ie,t[96]=Le,t[97]=Re):Re=t[97],Re}function Xe(e){try{let t=new URL(e.url),n=new URL(e.environmentHttpBaseUrl);if(t.origin===n.origin&&t.pathname.startsWith(`/api/assets/`)){let n=t.pathname.split(`/`).at(-1);if(!n)return null;let r=decodeURIComponent(n);return!r||r===`.`||r===`..`?null:`${e.environmentLabel} · ${r}`}return t.protocol===`http:`||t.protocol===`https:`?t.host:null}catch{return null}}function Ze(e){let t=(0,Q.c)(6),{className:n}=e,r;t[0]===n?r=t[1]:(r=_(`relative flex flex-col gap-0.5 overflow-hidden rounded-[5px] border border-border/60 bg-card p-1 shadow-xs/5`,n),t[0]=n,t[1]=r);let i;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsxs)(`div`,{className:`flex gap-[2px]`,children:[(0,$.jsx)(`span`,{className:`size-[3px] rounded-full bg-destructive/80`}),(0,$.jsx)(`span`,{className:`size-[3px] rounded-full bg-warning/80`}),(0,$.jsx)(`span`,{className:`size-[3px] rounded-full bg-success/80`})]}),t[2]=i):i=t[2];let a;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsxs)(`div`,{className:`mt-[1px] flex flex-1 flex-col gap-[2px]`,children:[(0,$.jsx)(`span`,{className:`h-[2px] w-full rounded-full bg-muted-foreground/30`}),(0,$.jsx)(`span`,{className:`h-[2px] w-3/5 rounded-full bg-muted-foreground/20`})]}),t[3]=a):a=t[3];let o;return t[4]===r?o=t[5]:(o=(0,$.jsxs)(`div`,{"aria-hidden":!0,className:r,children:[i,a]}),t[4]=r,t[5]=o),o}function Qe(e){let t=(0,Q.c)(17),{server:n,onOpen:r}=e,i;t[0]===n?i=t[1]:(i=$e(n),t[0]=n,t[1]=i);let a=i,o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(Ze,{className:`size-7 shrink-0`}),t[2]=o):o=t[2];let s;t[3]===a?s=t[4]:(s=(0,$.jsx)(`span`,{className:`truncate text-sm font-medium text-foreground`,children:a}),t[3]=a,t[4]=s);let c;t[5]!==n.host||t[6]!==n.port?(c=(0,$.jsxs)(`span`,{className:`truncate text-xs text-muted-foreground`,children:[n.host,`:`,n.port]}),t[5]=n.host,t[6]=n.port,t[7]=c):c=t[7];let l;t[8]!==s||t[9]!==c?(l=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[s,c]}),t[8]=s,t[9]=c,t[10]=l):l=t[10];let u;t[11]===n.listening?u=t[12]:(u=n.listening?(0,$.jsx)(et,{}):(0,$.jsx)(tt,{}),t[11]=n.listening,t[12]=u);let d;return t[13]!==r||t[14]!==l||t[15]!==u?(d=(0,$.jsxs)(`button`,{type:`button`,onClick:r,className:`group flex w-full items-center gap-3 px-3 py-3 text-left hover:bg-accent/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring`,children:[o,l,u]}),t[13]=r,t[14]=l,t[15]=u,t[16]=d):d=t[16],d}function $e(e){return e.processName?e.processName:e.listening?`Listening`:e.source===`configured`?`Configured`:`Recently seen`}function et(){let e=(0,Q.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsxs)(`span`,{"aria-label":`Listening`,className:`relative inline-flex size-2 shrink-0`,children:[(0,$.jsx)(`span`,{className:`absolute inset-0 animate-status-ping rounded-full bg-success opacity-60`}),(0,$.jsx)(`span`,{className:`relative inline-flex size-2 rounded-full bg-success`})]}),e[0]=t):t=e[0],t}function tt(){let e=(0,Q.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(`span`,{"aria-label":`Not currently listening`,className:`size-2 shrink-0 rounded-full bg-muted-foreground/40`}),e[0]=t):t=e[0],t}function nt(e){let t=(0,Q.c)(7),n=ve(e.environmentId),r;if(t[0]!==e.configuredUrls||t[1]!==e.environmentId||t[2]!==e.recentlySeenUrls||t[3]!==n){let i;t[5]===e.environmentId?i=t[6]:(i=t=>({...t,url:Ee(e.environmentId,t.url)}),t[5]=e.environmentId,t[6]=i),r=rt({scanner:n.map(i),configuredUrls:e.configuredUrls??[],recentlySeenUrls:e.recentlySeenUrls??[]}),t[0]=e.configuredUrls,t[1]=e.environmentId,t[2]=e.recentlySeenUrls,t[3]=n,t[4]=r}else r=t[4];return r}function rt(e){let t=new Map;for(let n of e.configuredUrls){let e=at(n);if(!e)continue;let r=it(e.host,e.port);t.has(r)||t.set(r,{host:e.host,port:e.port,url:e.url,processName:null,pid:null,terminal:null,source:`configured`,listening:!1})}for(let n of e.scanner){let e=it(n.host,n.port),r=t.get(e);if(r){t.set(e,{...r,processName:n.processName??r.processName,pid:n.pid??r.pid,terminal:n.terminal??r.terminal,listening:!0});continue}t.set(e,{...n,source:`scanner`,listening:!0})}for(let n of e.recentlySeenUrls){let e=at(n);if(!e)continue;let r=it(e.host,e.port);t.has(r)||t.set(r,{host:e.host,port:e.port,url:e.url,processName:null,pid:null,terminal:null,source:`recent`,listening:!1})}return Array.from(t.values()).toSorted((e,t)=>{let n={configured:0,scanner:1,recent:2};return n[e.source]===n[t.source]?e.port-t.port:n[e.source]-n[t.source]})}function it(e,t){return`${e.toLowerCase()}:${t}`}function at(e){try{let t=new URL(e);if(t.protocol!==`http:`&&t.protocol!==`https:`||!Re(t.hostname))return null;let n=t.port?Number.parseInt(t.port,10):t.protocol===`http:`?80:443;return!Number.isFinite(n)||n<=0?null:{host:t.hostname,port:n,url:t.href}}catch{return null}}function ot(e){let t=(0,Q.c)(16),{environmentId:n,configuredUrls:r,recentlySeenUrls:i,onOpenUrl:a}=e,o;t[0]!==r||t[1]!==n||t[2]!==i?(o={environmentId:n,configuredUrls:r,recentlySeenUrls:i},t[0]=r,t[1]=n,t[2]=i,t[3]=o):o=t[3];let s=nt(o);if(s.length===0){let e;return t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsxs)(L,{children:[(0,$.jsx)(V,{variant:`icon`,children:(0,$.jsx)(J,{className:`size-4.5 text-muted-foreground`})}),(0,$.jsx)(U,{children:`No preview yet`}),(0,$.jsx)(Ce,{children:`Type a URL above, or run a dev script. Listening localhost ports will show up here automatically.`})]}),t[4]=e):e=t[4],e}let c;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(He,{className:`size-4 shrink-0`}),(0,$.jsx)(`h2`,{className:`font-medium`,children:`Local servers`})]}),t[5]=c):c=t[5];let l;if(t[6]!==a||t[7]!==s){let e;t[9]===a?e=t[10]:(e=e=>(0,$.jsx)(Qe,{server:e,onOpen:()=>a(e.url)},`${e.host}:${e.port}`),t[9]=a,t[10]=e),l=s.map(e),t[6]=a,t[7]=s,t[8]=l}else l=t[8];let u;t[11]===l?u=t[12]:(u=(0,$.jsx)(`div`,{className:`flex flex-col divide-y divide-border/60 overflow-hidden rounded-xl border border-border/70 bg-background`,children:l}),t[11]=l,t[12]=u);let d;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(`p`,{className:`px-1 text-xs text-muted-foreground`,children:`Select a listening port to open it in this browser tab.`}),t[13]=d):d=t[13];let f;return t[14]===u?f=t[15]:(f=(0,$.jsx)(`div`,{className:`flex h-full min-h-0 overflow-y-auto px-5 py-8`,children:(0,$.jsxs)(`div`,{className:`m-auto flex w-full max-w-xl flex-col gap-3`,children:[c,u,d]})}),t[14]=u,t[15]=f),f}var st=[{value:`system`,label:`System`},{value:`light`,label:`Light`},{value:`dark`,label:`Dark`}];function ct(e){let t=(0,Q.c)(74),{tabId:n,hasWebContents:r,zoomFactor:i,colorScheme:a,deviceToolbarVisible:s,onToggleDeviceToolbar:l,nativePictureInPicture:u,onNativePictureInPicture:d}=e;if(!I)return null;let f=!n||!r,p;t[0]===n?p=t[1]:(p=e=>()=>{n&&e(n).catch(gt)},t[0]=n,t[1]=p);let h=p,g;t[2]===i?g=t[3]:(g=Math.round(i*100),t[2]=i,t[3]=g);let _=`${g}%`,y;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsxs)(o,{children:[(0,$.jsx)(c,{render:(0,$.jsx)(te,{render:(0,$.jsx)(m,{variant:`ghost`,size:`icon-xs`,type:`button`,"aria-label":`Preview menu`})}),children:(0,$.jsx)(Be,{})}),(0,$.jsx)(ie,{children:`More`})]}),t[4]=y):y=t[4];let x;t[5]===h?x=t[6]:(x=h(I.hardReload),t[5]=h,t[6]=x);let C;t[7]!==x||t[8]!==f?(C=(0,$.jsx)(v,{onClick:x,disabled:f,children:`Hard reload`}),t[7]=x,t[8]=f,t[9]=C):C=t[9];let w;t[10]===h?w=t[11]:(w=h(I.openDevTools),t[10]=h,t[11]=w);let T;t[12]!==w||t[13]!==f?(T=(0,$.jsx)(v,{onClick:w,disabled:f,children:`Open DevTools`}),t[12]=w,t[13]=f,t[14]=T):T=t[14];let E=u?`Close separate preview window`:`Open separate preview window`,D;t[15]!==d||t[16]!==E||t[17]!==f?(D=(0,$.jsx)(v,{onClick:d,disabled:f,children:E}),t[15]=d,t[16]=E,t[17]=f,t[18]=D):D=t[18];let ee=s?`Hide device toolbar`:`Show device toolbar`,j;t[19]!==l||t[20]!==ee||t[21]!==f?(j=(0,$.jsx)(v,{onClick:l,disabled:f,children:ee}),t[19]=l,t[20]=ee,t[21]=f,t[22]=j):j=t[22];let re;t[23]===f?re=t[24]:(re=(0,$.jsx)(M,{disabled:f,children:`Appearance`}),t[23]=f,t[24]=re);let N;t[25]===n?N=t[26]:(N=e=>{n&&I.setColorScheme(n,e).catch(ht)},t[25]=n,t[26]=N);let P;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(P=st.map(mt),t[27]=P):P=t[27];let F;t[28]!==a||t[29]!==N?(F=(0,$.jsx)(S,{className:`min-w-32`,children:(0,$.jsx)(ne,{value:a,onValueChange:N,children:P})}),t[28]=a,t[29]=N,t[30]=F):F=t[30];let L;t[31]!==re||t[32]!==F?(L=(0,$.jsxs)(b,{children:[re,F]}),t[31]=re,t[32]=F,t[33]=L):L=t[33];let oe;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(oe=(0,$.jsx)(O,{}),t[34]=oe):oe=t[34];let R;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,$.jsx)(`span`,{children:`Zoom`}),t[35]=R):R=t[35];let z;t[36]===h?z=t[37]:(z=h(I.zoomOut),t[36]=h,t[37]=z);let se;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(se=(0,$.jsx)(le,{}),t[38]=se):se=t[38];let B;t[39]!==z||t[40]!==f?(B=(0,$.jsx)(m,{variant:`outline`,size:`icon-xs`,type:`button`,onClick:z,"aria-label":`Zoom out`,disabled:f,children:se}),t[39]=z,t[40]=f,t[41]=B):B=t[41];let V;t[42]===_?V=t[43]:(V=(0,$.jsx)(`span`,{className:`min-w-12 text-center text-xs tabular-nums text-muted-foreground`,children:_}),t[42]=_,t[43]=V);let ce;t[44]===h?ce=t[45]:(ce=h(I.zoomIn),t[44]=h,t[45]=ce);let H;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(H=(0,$.jsx)(ae,{}),t[46]=H):H=t[46];let U;t[47]!==ce||t[48]!==f?(U=(0,$.jsx)(m,{variant:`outline`,size:`icon-xs`,type:`button`,onClick:ce,"aria-label":`Zoom in`,disabled:f,children:H}),t[47]=ce,t[48]=f,t[49]=U):U=t[49];let W;t[50]===h?W=t[51]:(W=h(I.resetZoom),t[50]=h,t[51]=W);let G;t[52]===Symbol.for(`react.memo_cache_sentinel`)?(G=(0,$.jsx)(ue,{}),t[52]=G):G=t[52];let K;t[53]!==W||t[54]!==f?(K=(0,$.jsx)(m,{variant:`ghost`,size:`icon-xs`,type:`button`,onClick:W,"aria-label":`Reset zoom`,disabled:f,children:G}),t[53]=W,t[54]=f,t[55]=K):K=t[55];let q;t[56]!==B||t[57]!==V||t[58]!==U||t[59]!==K?(q=(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[B,V,U,K]}),t[56]=B,t[57]=V,t[58]=U,t[59]=K,t[60]=q):q=t[60];let J;t[61]!==q||t[62]!==f?(J=(0,$.jsxs)(v,{closeOnClick:!1,onClick:pt,className:`justify-between`,disabled:f,children:[R,q]}),t[61]=q,t[62]=f,t[63]=J):J=t[63];let de,fe,pe;t[64]===Symbol.for(`react.memo_cache_sentinel`)?(de=(0,$.jsx)(O,{}),fe=(0,$.jsx)(v,{onClick:dt,children:`Clear cookies`}),pe=(0,$.jsx)(v,{onClick:lt,children:`Clear cache`}),t[64]=de,t[65]=fe,t[66]=pe):(de=t[64],fe=t[65],pe=t[66]);let me;return t[67]!==j||t[68]!==L||t[69]!==J||t[70]!==C||t[71]!==T||t[72]!==D?(me=(0,$.jsxs)(k,{children:[y,(0,$.jsxs)(A,{align:`end`,sideOffset:6,className:`min-w-56`,children:[C,T,D,j,L,oe,J,de,fe,pe]})]}),t[67]=j,t[68]=L,t[69]=J,t[70]=C,t[71]=T,t[72]=D,t[73]=me):me=t[73],me}function lt(){I.clearCache().catch(ut)}function ut(){}function dt(){I.clearCookies().catch(ft)}function ft(){}function pt(e){return e.preventDefault()}function mt(e){return(0,$.jsx)(y,{value:e.value,children:e.label},e.value)}function ht(){}function gt(){}function _t(e){return he[e]||(e.length>0?e:`Network error`)}function vt(e){let t=(0,Q.c)(32),{url:n,code:r,description:i,onReload:a}=e,[o,s]=(0,Z.useState)(!1),c;t[0]===n?c=t[1]:(c=xt(n)??n,t[0]=n,t[1]=c);let l=c,u;t[2]===i?u=t[3]:(u=_t(i),t[2]=i,t[3]=u);let d=u,f;t[4]!==r||t[5]!==i?(f=i.length>0?i:`ERR_${Math.abs(r)||`FAILED`}`,t[4]=r,t[5]=i,t[6]=f):f=t[6];let p=f,h,g;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(bt,{className:`mb-6 size-12 text-muted-foreground/70`}),g=(0,$.jsx)(`h1`,{className:`mb-3 text-2xl font-semibold leading-tight text-foreground`,children:`This site can’t be reached`}),t[7]=h,t[8]=g):(h=t[7],g=t[8]);let _;t[9]===l?_=t[10]:(_=(0,$.jsx)(`span`,{className:`font-semibold text-foreground`,children:l}),t[9]=l,t[10]=_);let v;t[11]!==d||t[12]!==_?(v=(0,$.jsxs)(`p`,{className:`text-sm leading-relaxed text-muted-foreground`,children:[_,`: `,d,`.`]}),t[11]=d,t[12]=_,t[13]=v):v=t[13];let y;t[14]===o?y=t[15]:(y=o?(0,$.jsxs)(`div`,{className:`mt-6 rounded-lg border border-border bg-muted/40 p-4 text-sm`,children:[(0,$.jsx)(`p`,{className:`mb-2 font-medium text-foreground`,children:`Try:`}),(0,$.jsxs)(`ul`,{className:`list-disc space-y-1 pl-5 text-muted-foreground`,children:[(0,$.jsx)(`li`,{children:`Checking your connection`}),(0,$.jsx)(`li`,{children:`Confirming the dev server is running`}),(0,$.jsx)(`li`,{children:`Checking the proxy and the firewall`})]})]}):null,t[14]=o,t[15]=y);let b;t[16]===p?b=t[17]:(b=(0,$.jsx)(`div`,{className:`mt-8 text-xs uppercase tracking-wide text-muted-foreground/70`,children:p}),t[16]=p,t[17]=b);let x;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(x=()=>s(yt),t[18]=x):x=t[18];let S=o?`Hide details`:`Details`,C;t[19]===S?C=t[20]:(C=(0,$.jsx)(m,{type:`button`,variant:`outline`,size:`sm`,onClick:x,children:S}),t[19]=S,t[20]=C);let w;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(`div`,{className:`flex-1`}),t[21]=w):w=t[21];let T;t[22]===a?T=t[23]:(T=(0,$.jsx)(m,{type:`button`,size:`sm`,onClick:a,children:`Reload`}),t[22]=a,t[23]=T);let E;t[24]!==C||t[25]!==T?(E=(0,$.jsxs)(`div`,{className:`mt-auto flex items-center gap-2 pt-8`,children:[C,w,T]}),t[24]=C,t[25]=T,t[26]=E):E=t[26];let D;return t[27]!==E||t[28]!==v||t[29]!==y||t[30]!==b?(D=(0,$.jsx)(`div`,{className:`relative flex h-full min-h-0 w-full overflow-y-auto bg-background`,children:(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-xl flex-1 flex-col px-8 py-12 sm:py-16`,children:[h,g,v,y,b,E]})}),t[27]=E,t[28]=v,t[29]=y,t[30]=b,t[31]=D):D=t[31],D}function yt(e){return!e}function bt(e){let t=(0,Q.c)(5),{className:n}=e,r,i,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsx)(`path`,{d:`M16 12 L48 12 L48 52 L16 52 Z`}),i=(0,$.jsx)(`path`,{d:`M22 22 L42 22 M22 30 L36 30 M22 38 L40 38`,strokeLinecap:`round`}),a=(0,$.jsx)(`path`,{d:`M52 8 L12 56`,strokeLinecap:`round`}),t[0]=r,t[1]=i,t[2]=a):(r=t[0],i=t[1],a=t[2]);let o;return t[3]===n?o=t[4]:(o=(0,$.jsxs)(`svg`,{viewBox:`0 0 64 64`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,className:n,children:[r,i,a]}),t[3]=n,t[4]=o),o}function xt(e){try{return new URL(e).host}catch{return null}}function St(e){let t=e.toLowerCase();return t.includes(`mac`)?`Reveal in Finder`:t.includes(`win`)?`Reveal in File Explorer`:`Reveal in Files`}var Ct=120,wt=220,Tt=4,Et=90,Dt=.08,Ot=.5;function kt(e){let[t,n]=(0,Z.useState)(0),r=(0,Z.useRef)(0);return r.current=t,(0,Z.useEffect)(()=>{if(!e){if(r.current===0)return;n(100);let e=window.setTimeout(()=>n(0),wt);return()=>window.clearTimeout(e)}n(e=>e>0&&e<95?e:Tt);let t=window.setInterval(()=>{let e=r.current;if(e>=Et)return;let t=Et-e,i=Math.max(Ot,t*Dt);n(Math.min(Et,e+i))},Ct);return()=>window.clearInterval(t)},[e]),t}var At=class extends h()(`PreviewSessionThreadKeyParseError`,{threadKey:g}){get message(){return`Invalid scoped preview thread key: ${this.threadKey}`}},jt=j(e=>{let t=l(e);if(t===null)throw new At({threadKey:e});let n=je.list({environmentId:t.environmentId,input:{threadId:t.threadId}}),r=je.events({environmentId:t.environmentId,input:{}});return T(e=>{let i=!1,a=0,o=e=>{s(e)&&xe(t,e.value)},c=r=>{if(!s(r)||r.value.threadId!==t.threadId)return;let i=Ne(t).serverEpoch;if(i!==null&&i!==r.value.serverEpoch){e.refresh(n);return}Le(t,r.value)};e.addFinalizer(()=>{i=!0});let l=e.once(r);e.subscribe(n,e=>{o(e)}),e.subscribe(r,e=>{a+=1,c(e)}),queueMicrotask(()=>{i||(e.refresh(n),a===0&&c(l))})}).pipe(w(1e3),N(`preview:session-sync:${e}`))});function Mt(e){let t=(0,Q.c)(2),n;t[0]===e?n=t[1]:(n=jt(a(e)),t[0]=e,t[1]=n),u(n)}var Nt=1500,Pt=.001;function Ft(e){let t=(0,Q.c)(11),{zoomFactor:n}=e,[r,i]=(0,Z.useState)(!1),a=(0,Z.useRef)(n),o=(0,Z.useRef)(null),s,c;t[0]===n?(s=t[1],c=t[2]):(s=()=>{if(!(Math.abs(a.current-n)<Pt))return a.current=n,i(!0),o.current!==null&&window.clearTimeout(o.current),o.current=window.setTimeout(()=>{i(!1),o.current=null},Nt),()=>{o.current!==null&&(window.clearTimeout(o.current),o.current=null)}},c=[n],t[0]=n,t[1]=s,t[2]=c),(0,Z.useEffect)(s,c);let l;t[3]===n?l=t[4]:(l=Math.round(n*100),t[3]=n,t[4]=l);let u=`${l}%`,d=!r,f=r?`opacity-100 translate-y-0`:`opacity-0 -translate-y-1`,p;t[5]===f?p=t[6]:(p=_(`pointer-events-none absolute top-3 right-3 z-20 select-none rounded-full border border-border/70 bg-popover/95 px-2.5 py-1 text-xs font-medium text-foreground shadow-md/10 backdrop-blur transition-all duration-200 ease-out`,f),t[5]=f,t[6]=p);let m;return t[7]!==u||t[8]!==d||t[9]!==p?(m=(0,$.jsx)(`div`,{"aria-hidden":d,className:p,children:u}),t[7]=u,t[8]=d,t[9]=p,t[10]=m):m=t[10],m}function It(e,t){return e?1:t===`human`?.18:.35}var Lt=700;function Rt(e){let t=(0,Q.c)(9),{tabId:n,zoomFactor:r,controller:i}=e,a;t[0]===n?a=t[1]:(a=e=>e.byTabId[n]??null,t[0]=n,t[1]=a);let o=me(a),s;t[2]===n?s=t[3]:(s=e=>e.byTabId[n]?.content??null,t[2]=n,t[3]=s);let c=R(s);if(!o)return null;let l;return t[4]!==c||t[5]!==i||t[6]!==o||t[7]!==r?(l=(0,$.jsx)(zt,{event:o,content:c,zoomFactor:r,controller:i},o.sequence),t[4]=c,t[5]=i,t[6]=o,t[7]=r,t[8]=l):l=t[8],l}function zt(e){let t=(0,Q.c)(15),{event:n,content:r,zoomFactor:i,controller:a}=e,[o,s]=(0,Z.useState)(!0),c,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>{let e=window.setTimeout(()=>s(!1),Lt);return()=>window.clearTimeout(e)},l=[],t[0]=c,t[1]=l):(c=t[0],l=t[1]),(0,Z.useEffect)(c,l);let u;t[2]!==o||t[3]!==a?(u=It(o,a),t[2]=o,t[3]=a,t[4]=u):u=t[4];let d=`translate3d(${n.x*i*(r?.scale??1)+(r?.x??0)-(r?.scrollLeft??0)}px, ${n.y*i*(r?.scale??1)+(r?.y??0)-(r?.scrollTop??0)}px, 0)`,f;t[5]!==u||t[6]!==d?(f={opacity:u,transform:d},t[5]=u,t[6]=d,t[7]=f):f=t[7];let p;t[8]!==n.phase||t[9]!==n.sequence?(p=n.phase===`click`?(0,$.jsx)(`span`,{className:`absolute left-0.5 top-0.5 size-4 animate-status-ping rounded-full bg-primary/25 motion-reduce:animate-none`},n.sequence):null,t[8]=n.phase,t[9]=n.sequence,t[10]=p):p=t[10];let m;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(Ve,{className:`relative size-5 -translate-x-0.5 -translate-y-0.5 fill-background text-primary drop-shadow-sm`,strokeWidth:2}),t[11]=m):m=t[11];let h;return t[12]!==f||t[13]!==p?(h=(0,$.jsxs)(`div`,{className:`pointer-events-none absolute left-0 top-0 z-40 transition-[transform,opacity] duration-150 ease-out motion-reduce:transition-none`,style:f,"aria-hidden":`true`,"data-agent-browser-cursor":!0,children:[p,m]}),t[12]=f,t[13]=p,t[14]=h):h=t[14],h}var Bt=typeof window>`u`?null:d();function Vt({threadRef:e,tabId:t,configuredUrls:n,visible:r}){let[o,s]=(0,Z.useState)(void 0),[c,l]=(0,Z.useState)(!1),u=ke(),d=(0,Z.useRef)(!1),f=(0,Z.useRef)(!0),m=Fe(e),h=B(t=>Se(t.byThreadKey,e)),g=D(e=>e.addPreviewAnnotation),_=D(e=>e.addImage),v=ee(e.environmentId),y=i(e.environmentId),b=p(je.open),S=p(je.resize,`preview viewport resize`),{resolvedTheme:w}=re();Mt(e),(0,Z.useEffect)(()=>(f.current=!0,()=>{f.current=!1}),[]);let T=t??m.activeTabId,O=T?H(e,m.serverEpoch,T):null,te=T&&O?u.has(O)?O:Me(e,T):null,k=T?m.sessions[T]??null:null,A=T?m.desktopByTabId[T]??null:null,j=k?.navStatus??{_tag:`Idle`},M=j._tag===`Idle`?``:j.url,ne=A?.loading??j._tag===`Loading`,N=A?.canGoBack??k?.canGoBack??!1,ie=A?.canGoForward??k?.canGoForward??!1,P=j._tag===`Idle`,F=j._tag===`LoadFailed`,L=Te(k),ae=A?.controller??`none`,oe=kt(ne),se=M&&v&&y?Xe({url:M,environmentLabel:v.label,environmentHttpBaseUrl:y})??void 0:void 0,V=k?.viewport??x,ce=R(e=>O?e.byTabId[O]?.rect??null:null),U=(0,Z.useCallback)(async t=>{O&&I?(await I.navigate(O,t),pe(e,t)):await _e({openPreview:b,threadRef:e,url:t})},[b,O,e]),le=(0,Z.useCallback)(async e=>{try{await U(ge(e))}catch{}},[U]),W=(0,Z.useCallback)(async t=>{try{await U(Ee(e.environmentId,t))}catch{}},[U,e.environmentId]),ue=(0,Z.useCallback)(()=>{I&&O&&I.refresh(O)},[O]),q=(0,Z.useCallback)(()=>{I&&O&&I.zoomIn(O)},[O]),J=(0,Z.useCallback)(()=>{I&&O&&I.zoomOut(O)},[O]),de=(0,Z.useCallback)(()=>{I&&O&&I.resetZoom(O)},[O]),me=(0,Z.useCallback)(async t=>{if(!T)return;let n=await S({environmentId:e.environmentId,input:{threadId:e.threadId,tabId:T,viewport:t}});if(n._tag===`Failure`){let e=E(n);throw X.add({type:`error`,title:`Unable to resize browser viewport`,description:e instanceof Error?e.message:`An error occurred.`}),e}Ae(e,n.value)},[S,T,e]),he=()=>{if(!O)return;if(V._tag!==`fill`){Ie(O,x).catch(()=>void 0);return}let e=ce?Pe(ce,A?.zoomFactor):{width:1024,height:768};Ie(O,{_tag:`freeform`,...e}).catch(()=>void 0)};(0,Z.useEffect)(()=>{if(O)return De(O,me)},[me,O]);let ve=(0,Z.useCallback)(()=>{I&&O&&I.goBack(O)},[O]),xe=(0,Z.useCallback)(()=>{I&&O&&I.goForward(O)},[O]),Ce=(0,Z.useCallback)(()=>{!Bt||!M||Bt.shell.openExternal(M).catch(()=>void 0)},[M]),we=(0,Z.useCallback)(()=>{if(T){if(h?.tabId===T){B.getState().close(e);return}B.getState().open(e,T),C.getState().close(e)}},[h?.tabId,T,e]),Oe=(0,Z.useCallback)(()=>{!I||!O||(A?.pictureInPicture?I.pictureInPicture.close:I.pictureInPicture.open)(O).catch(e=>{X.add({type:`error`,title:`Unable to update popped-out preview`,description:e instanceof Error?e.message:`An error occurred.`})})},[A?.pictureInPicture,O]),Ne=(0,Z.useCallback)(t=>{if(!I||!O||!T)return;let n=I;if(te){fe(te).then(e=>{if(!e)return;let t=!1,r,i=()=>{if(!navigator.clipboard?.writeText){X.update(r,Y({type:`error`,title:`Unable to copy recording path`,description:`Clipboard API unavailable.`,actionProps:a}));return}navigator.clipboard.writeText(e.path).then(()=>{t=!0,o(),window.setTimeout(()=>{t=!1,o()},2e3)},e=>{X.update(r,Y({type:`error`,title:`Unable to copy recording path`,description:e instanceof Error?e.message:`An error occurred.`,actionProps:a}))})},a={children:St(navigator.platform),onClick:()=>void n.revealArtifact(e.path)},o=()=>{X.update(r,Y({type:`success`,title:`Recording saved`,actionProps:a,data:{secondaryActionProps:{children:t?`Copied!`:`Copy path`,disabled:t,onClick:i},secondaryActionVariant:`outline`}}))};r=X.add(Y({type:`success`,title:`Recording saved`,actionProps:a,data:{secondaryActionProps:{children:`Copy path`,onClick:i},secondaryActionVariant:`outline`}}))},e=>{X.add({type:`error`,title:`Unable to stop recording`,description:e instanceof Error?e.message:`An error occurred.`})});return}if(t){be(O,e,T).catch(e=>{X.add({type:`error`,title:`Unable to start recording`,description:e instanceof Error?e.message:`An error occurred.`})});return}n.captureScreenshot(O).then(e=>{let t={children:St(navigator.platform),onClick:()=>void n.revealArtifact(e.path)},r=!1,i=!1,a,o=(e=`success`,n=`Screenshot saved`,o)=>{X.update(a,Y({type:e,title:n,description:o,actionProps:{children:i?`Copied!`:`Copy image`,disabled:i,onClick:c},data:{additionalActions:[{id:`copy-path`,props:{children:r?`Copied!`:`Copy path`,disabled:r,onClick:s}}],secondaryActionProps:{...t},secondaryActionVariant:`outline`}}))},s=()=>{if(!navigator.clipboard?.writeText){o(`error`,`Unable to copy screenshot path`,`Clipboard API unavailable.`);return}navigator.clipboard.writeText(e.path).then(()=>{r=!0,o(),window.setTimeout(()=>{r=!1,o()},2e3)},e=>{o(`error`,`Unable to copy screenshot path`,e instanceof Error?e.message:`An error occurred.`)})},c=()=>{n.copyArtifactToClipboard(e.path).then(()=>{i=!0,o(),window.setTimeout(()=>{i=!1,o()},2e3)},e=>{o(`error`,`Unable to copy screenshot`,e instanceof Error?e.message:`An error occurred.`)})};a=X.add(Y({type:`success`,title:`Screenshot saved`,actionProps:{children:`Copy image`,onClick:c},data:{additionalActions:[{id:`copy-path`,props:{children:`Copy path`,onClick:s}}],secondaryActionProps:{...t},secondaryActionVariant:`outline`}}))},e=>{X.add({type:`error`,title:`Unable to capture screenshot`,description:e instanceof Error?e.message:`An error occurred.`})})},[te,O,T,e]),Le=(0,Z.useCallback)(()=>{if(!I||!O)return;if(d.current){I.cancelPickElement(O).catch(()=>void 0);return}let t=typeof document<`u`?document.activeElement:null;d.current=!0,l(!0),(async()=>{try{let t=await I.pickElement(O);if(!t)return;g(e,t);let n=await ye(t);n&&t.screenshot&&_(e,{type:`image`,id:t.id,name:n.name,mimeType:n.type,sizeBytes:n.size,previewUrl:t.screenshot.dataUrl,file:n})}catch{}finally{if(d.current=!1,f.current&&l(!1),t&&t.isConnected&&typeof t.focus==`function`)try{t.focus({preventScroll:!0})}catch{}}})()},[_,g,O,e]);return(0,Z.useEffect)(()=>{let e=z(M,w);e&&U(e).catch(()=>void 0)},[U,w,M]),(0,Z.useEffect)(()=>()=>{d.current&&(d.current=!1,I&&O&&I.cancelPickElement(O).catch(()=>void 0),f.current&&l(!1))},[O]),(0,Z.useEffect)(()=>{if(r)return K(e=>{switch(e){case`refresh`:ue();return;case`focus-url`:s(e=>(e??0)+1);return;case`zoom-in`:q();return;case`zoom-out`:J();return;case`reset-zoom`:de();return;case`toggle-panel`:return}})},[ue,de,q,J,r]),(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col bg-background`,"data-thread-key":a(e),children:[(0,$.jsx)(Ye,{url:M,displayUrl:se,loading:ne,loadProgress:oe,canGoBack:N,canGoForward:ie,refreshDisabled:P,focusUrlNonce:o,onBack:ve,onForward:xe,onRefresh:ue,onSubmit:e=>void le(e),onOpenInBrowser:T?Ce:void 0,onCapture:I&&T?Ne:void 0,captureDisabled:!A||F,recording:te!==null,onPictureInPicture:I&&T?we:void 0,pictureInPicture:h?.tabId===T,pictureInPictureDisabled:!A?.hasWebContents||F,onPickElement:I&&T?Le:void 0,pickActive:c,pickDisabled:!T||F,pickDisabledReason:F?`Page didn't load — pick unavailable until the page renders`:void 0,trailingActions:I?(0,$.jsx)(ct,{tabId:O,hasWebContents:A?.hasWebContents??!1,zoomFactor:A?.zoomFactor??1,colorScheme:A?.colorScheme??`system`,deviceToolbarVisible:V._tag!==`fill`,onToggleDeviceToolbar:he,nativePictureInPicture:A?.pictureInPicture??!1,onNativePictureInPicture:Oe}):null}),(0,$.jsxs)(`div`,{className:`relative min-h-0 flex-1 overflow-hidden`,children:[O&&k&&!L?(0,$.jsx)(G,{tabId:O,visible:r&&!F,className:`absolute inset-0 h-full w-full`},O):null,L?(0,$.jsx)(ot,{environmentId:e.environmentId,configuredUrls:n,recentlySeenUrls:m.recentlySeenUrls,onOpenUrl:e=>void W(e)}):null,k&&A?(0,$.jsx)(Ft,{zoomFactor:A.zoomFactor}):null,O&&A&&!L&&!F?(0,$.jsx)(Rt,{tabId:O,zoomFactor:A.zoomFactor,controller:ae}):null,ae===`none`?null:(0,$.jsx)(`div`,{className:`pointer-events-none absolute left-3 top-3 z-40 rounded-full border border-border/70 bg-background/90 px-2.5 py-1 text-[11px] font-medium shadow-sm backdrop-blur`,children:ae===`agent`?`Agent controlling browser`:`Human control`}),j._tag===`LoadFailed`?(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-background`,children:(0,$.jsx)(vt,{url:j.url,code:j.code,description:j.description,onReload:ue})}):null]})]})}function Ht(e){let t=(0,Q.c)(13),{mode:n,threadRef:r,tabId:i,configuredUrls:a,visible:o}=e;if(!Oe()){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center gap-3 p-8 text-center`,children:(0,$.jsx)(`p`,{className:`max-w-sm text-sm text-muted-foreground`,children:`Preview is only available in the P4Code desktop app.`})}),t[0]=e):e=t[0];let r;return t[1]===n?r=t[2]:(r=(0,$.jsx)(W,{mode:n,children:e}),t[1]=n,t[2]=r),r}let s;t[3]===i?s=t[4]:(s=i===void 0?{}:{tabId:i},t[3]=i,t[4]=s);let c;t[5]!==a||t[6]!==s||t[7]!==r||t[8]!==o?(c=(0,$.jsx)(Vt,{threadRef:r,...s,configuredUrls:a,visible:o}),t[5]=a,t[6]=s,t[7]=r,t[8]=o,t[9]=c):c=t[9];let l;return t[10]!==n||t[11]!==c?(l=(0,$.jsx)(W,{mode:n,children:c}),t[10]=n,t[11]=c,t[12]=l):l=t[12],l}export{Ht as PreviewPanel};
2
+ //# sourceMappingURL=PreviewPanel-BwdTNeQU.js.map
@@ -0,0 +1,2 @@
1
+ import{ws as e}from"./terminal-links-B2KXT7CK.js";var t=e(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]);export{t};
2
+ //# sourceMappingURL=arrow-right-BnQZ60ie.js.map
@@ -1,2 +1,2 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{n as t,r as n,t as r}from"./compiler-runtime-CLAvuQ-D.js";import{Wr as i,c as a}from"./terminal-links-B1K-cj6g.js";import{At as o,Ct as s,Dt as c,E as l,Et as u,Fr as d,Ft as f,Gt as p,Ht as m,It as h,Jt as g,Kt as _,Lt as v,Mt as y,Nt as b,Ot as x,Pt as S,Rt as C,St as w,Ut as T,Wt as E,Xt as D,Yt as O,Zt as k,_n as A,_t as j,at as M,bt as N,ct as P,dn as F,dt as I,en as L,ft as R,gn as z,gt as B,ht as ee,in as V,it as H,jt as te,kt as U,ln as W,lt as ne,mt as re,nn as ie,nt as G,on as K,ot as ae,pn as oe,pt as se,qt as q,rt as ce,st as le,tn as ue,tt as J,ut as de,vn as fe,vt as Y,wr as pe,wt as me,xt as he,yt as ge,zt as _e}from"./index-Cwuc4uKy.js";var ve=-1,ye=class{__id=`file-renderer:${++ve}`;highlighter;renderCache;computedLang=`text`;lineAnnotations={};lineCache;textDoucmentCache=new WeakMap;constructor(e={theme:F},t,n){this.options=e,this.onRenderUpdate=t,this.workerManager=n,n?.isWorkingPool()!==!0&&(this.highlighter=h(e.theme??F)?C():void 0)}setOptions(e){this.options=e}mergeOptions(e){this.options={...this.options,...e}}setLineAnnotations(e){this.lineAnnotations={};for(let t of e){let e=this.lineAnnotations[t.lineNumber]??[];this.lineAnnotations[t.lineNumber]=e,e.push(t)}}cleanUp(){this.recycle(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.clearRenderCache(),this.highlighter=void 0,this.workerManager?.cleanUpTasks(this),this.lineCache=void 0}clearRenderCache(){let e=this.renderCache;this.renderCache=void 0,e!=null&&e.isDirty===!0&&e.file.cacheKey!=null&&this.workerManager?.evictFileFromCache(e.file.cacheKey)}hydrate(e){let{options:t}=this.getRenderOptions(e),n=X(this.getOrCreateLineCache(e).length,this.getTokenizeMaxLength()),r=this.workerManager?.getFileResultCache(e);r!=null&&!S(t,r.options)&&(r=void 0),this.renderCache??={file:e,options:t,highlighted:!n&&!Y(e),result:n?void 0:r?.result,renderRange:void 0},this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!n&&this.workerManager.highlightFileAST(this,e):this.highlighter??(this.computedLang=e.lang??U(e.name),this.initializeHighlighter())}getRenderOptions(e){let t=(()=>{if(this.workerManager?.isWorkingPool()===!0)return this.workerManager.getFileRenderOptions();let{theme:e=F,tokenizeMaxLineLength:t=1e3}=this.options;return{theme:e,useTokenTransformer:j(this.options),tokenizeMaxLineLength:t}})(),{renderCache:n}=this;return n?.result==null||!k(e,n.file)||!S(t,n.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}getOrCreateLineCache(e){if(e.cacheKey==null)return this.lineCache=void 0,u(e.contents);let{lineCache:t}=this;return(t==null||t.cacheKey!==e.cacheKey)&&(t={cacheKey:e.cacheKey,lines:u(e.contents)}),this.lineCache=t,t.lines}getLineCount(e){return this.textDoucmentCache.get(e)?.lineCount??this.getOrCreateLineCache(e).length}updateRenderCache(e,t){if(this.renderCache==null)return;let{result:n}=this.renderCache;if(n!=null){for(let[r,i]of e)n.code[r]={type:`element`,tagName:`div`,properties:{"data-line":r+1,"data-line-type":`context`,"data-line-index":r},children:i.map(([e,n,r])=>e===0&&n===``?r===``?{type:`element`,tagName:`br`,properties:{},children:[]}:{type:`text`,value:r}:{type:`element`,tagName:`span`,properties:{"data-char":e,style:`--diffs-token-${t}:${n};`},children:[{type:`text`,value:r}]})};n.baseThemeType=t,this.renderCache.isDirty=!0}}applyDocumentChange(e){if(this.renderCache==null)return;let{file:t,result:n}=this.renderCache;if(n!=null&&n.code.length!==e.lineCount){for(let t=n.code.length;t<e.lineCount;t++)n.code.push({type:`element`,tagName:`div`,properties:{"data-line":t+1,"data-line-type":`context`,"data-line-index":t},children:[{type:`element`,tagName:`span`,properties:{"data-char":0},children:[{type:`text`,value:e.getLineText(t)}]}]});this.renderCache.isDirty=!0}this.textDoucmentCache.set(t,e)}renderFile(e=this.renderCache?.file,t=W){if(e==null)return;let{options:n,forceHighlight:r}=this.getRenderOptions(e),i=this.getMatchingWorkerResultCache(e,n);i!=null&&!this.hasHighlightedRenderCache(e,n)&&(this.renderCache={file:e,highlighted:!0,renderRange:void 0,...i},r=!1),this.renderCache??={file:e,highlighted:!1,options:n,result:void 0,renderRange:void 0};let a=this.getOrCreateLineCache(e),o=e.contents.length>0,s=!o||Y(e)||X(a.length,this.getTokenizeMaxLength()),c=!k(e,this.renderCache.file),l=!b(this.renderCache.renderRange,t);if(this.workerManager?.isWorkingPool()===!0)(s||this.renderCache.result==null||!this.renderCache.highlighted&&(c||l))&&(this.renderCache.file=e,this.renderCache.options=n,this.renderCache.highlighted=!1,(this.renderCache.result==null||c||l||r)&&(this.renderCache.result=this.workerManager.getPlainFileAST(e,t.startingLine,t.totalLines,a)),this.renderCache.renderRange=t),!s&&o&&(!this.renderCache.highlighted||r)&&this.workerManager.highlightFileAST(this,e);else{this.computedLang=e.lang??U(e.name);let t=this.highlighter!=null&&h(n.theme),i=this.highlighter!=null&&m(this.computedLang),a=!s&&i;if(this.highlighter!=null&&t&&(r||s||!this.renderCache.highlighted&&a||this.renderCache.result==null)){let{result:t,options:n}=this.renderFileWithHighlighter(e,this.highlighter,s||!i);this.renderCache={file:e,options:n,highlighted:a,result:t,renderRange:void 0}}(!t||!s&&!i)&&this.asyncHighlight(e).then(({result:t,options:n})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.onHighlightSuccess(e,t,n,!s)})}return this.renderCache.result==null?void 0:this.processFileResult(this.renderCache.file,t,this.renderCache.result)}async asyncRender(e,t=W){let{result:n}=await this.asyncHighlight(e);return this.processFileResult(e,t,n)}async asyncHighlight(e){let t=X(this.getOrCreateLineCache(e).length,this.getTokenizeMaxLength());this.computedLang=t?`text`:e.lang??U(e.name);let n=this.highlighter!=null&&f(v(this.options.theme)),r=t||this.highlighter!=null&&m(this.computedLang);return(this.highlighter==null||!n||!r)&&(this.highlighter=await this.initializeHighlighter()),this.renderFileWithHighlighter(e,this.highlighter,t)}renderFileWithHighlighter(e,t,n=!1){let{options:r}=this.getRenderOptions(e);return{result:me(e,t,r,{forcePlainText:n}),options:r}}processFileResult(e,t,{code:n,themeStyles:r,baseThemeType:i}){let a=this.getLineCount(e),{disableFileHeader:o=!1}=this.options,l=[],u=O(),d=Math.min(t.startingLine+t.totalLines,a),f=0,p=s(t)?he(this.lineAnnotations):void 0;p!=null&&(u.children.push(q(`context`,`annotation`,1)),l.push(y({type:`annotation`,hunkIndex:-1,lineIndex:-1,annotations:p.map(e=>c(e))})),f++);for(let r=t.startingLine;r<d;r++){let t=r+1,i=n[r];if(i==null){let n=`FileRenderer.processFileResult: Line doesnt exist`;throw console.error(n,{name:e.name,lineIndex:r,lineNumber:t}),Error(n)}u.children.push(g(`context`,t,`${r}`)),l.push(i),f++;let a=this.lineAnnotations[t];a!=null&&(u.children.push(q(`context`,`annotation`,1)),l.push(y({type:`annotation`,hunkIndex:0,lineIndex:t,annotations:a.map(e=>c(e))})),f++)}return u.properties.style=`grid-row: span ${f}`,{gutterAST:u.children??[],contentAST:l,preAST:this.createPreElement(a),headerAST:o?void 0:this.renderHeader(e),totalLines:a,rowCount:f,themeStyles:r,baseThemeType:i,bufferBefore:t.bufferBefore,bufferAfter:t.bufferAfter,css:``}}renderHeader(e){let{headerRenderMode:t=`default`,stickyHeader:n=!1}=this.options;return te({fileOrDiff:e,mode:t,stickyHeader:n})}renderFullHTML(e){return _(this.renderFullAST(e))}renderFullAST(e,t=[]){return t.push(D({tagName:`code`,children:this.renderCodeAST(e),properties:{"data-code":``}})),{...e.preAST,children:t}}renderCodeAST(e){let t=O();return t.children=e.gutterAST,t.properties.style=`grid-row: span ${e.rowCount}`,[t,ge(e.contentAST,e.rowCount)]}renderPartialHTML(e,t=!1){return _(t?D({tagName:`code`,children:e,properties:{"data-code":``}}):e)}async initializeHighlighter(){return this.highlighter=await _e(x(this.computedLang,this.options)),this.highlighter}onHighlightSuccess(e,t,n,r=!0){if(this.renderCache==null)return;let i=!k(e,this.renderCache.file)||!this.renderCache.highlighted||!S(n,this.renderCache.options);this.renderCache={file:e,options:n,highlighted:r,result:t,renderRange:void 0},i&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(e,t){let n=this.workerManager?.getFileResultCache(e);if(!(n==null||!S(t,n.options)))return n}hasHighlightedRenderCache(e,t){let{renderCache:n}=this;return n?.result!=null&&n.highlighted&&k(e,n.file)&&S(t,n.options)}onHighlightError(e){console.error(e)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}createPreElement(e){let{disableLineNumbers:t=!1,overflow:n=`scroll`}=this.options;return o({type:`file`,diffIndicators:`none`,disableBackground:!0,disableLineNumbers:t,overflow:n,split:!1,totalLines:e})}};function X(e,t){return e>t}function be(e,t){return e.lineNumber===t.lineNumber&&e.metadata===t.metadata}function Z(e){return{theme:e?.theme,disableLineNumbers:e?.disableLineNumbers,overflow:e?.overflow,themeType:e?.themeType,collapsed:e?.collapsed,disableFileHeader:e?.disableFileHeader,disableVirtualizationBuffers:e?.disableVirtualizationBuffers,stickyHeader:e?.stickyHeader,preferredHighlighter:e?.preferredHighlighter,useCSSClasses:e?.useCSSClasses,useTokenTransformer:e?.useTokenTransformer,tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,unsafeCSS:e?.unsafeCSS,headerRenderMode:e?.renderCustomHeader==null?`default`:`custom`}}var xe=[``],Se=-1,Q=class{static LoadedCustomComponent=!0;__id=`file:${++Se}`;type=`file`;fileContainer;spriteSVG;pre;code;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;errorWrapper;placeHolder;lastRenderedHeaderHTML;cachedHeaderHTML;appliedPreAttributes;lastRowCount;mounted=!1;headerElement;headerCustom;headerPrefix;headerMetadata;fileRenderer;resizeManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;file;renderRange;enabled=!0;editor;constructor(e={theme:F},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.fileRenderer=new ye(e,this.handleHighlightRender,this.workerManager),this.resizeManager=new T,this.interactionManager=new E(`file`,p(e)),this.workerManager?.subscribeToThemeChanges(this)}handleHighlightRender=()=>{this.rerender()};rerender(){!this.enabled||this.file==null||this.render({file:this.file,forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.fileRenderer.clearRenderCache(),this.rerender()}setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(p(this.options))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??`system`)!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme==`string`||this.fileContainer==null||this.appliedThemeCSS==null)return!1;let t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType===t?!1:(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!ue(this.appliedThemeCSS.theme,this.options.theme??F)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}let{overflow:e=`scroll`}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,e===`wrap`),this.managersDirty=!1}cleanUp(e=!1){this.emitPostRender(!0),this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.annotationCache.clear(),this.pre=void 0,this.bufferBefore=void 0,this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.placeHolder=void 0,this.unsafeCSSStyle=void 0,e?this.fileRenderer.recycle():(this.fileRenderer.cleanUp(),this.workerManager=void 0,this.file=void 0),this.enabled=!1,this.editor?.cleanUp(),this.editor=void 0}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){let{fileContainer:t,prerenderedHTML:n,preventEmit:r=!1,file:i,lineAnnotations:a}=e;this.hydrateElements(t,n),Ce(this.pre,i,this.options.collapsed)||we(this.headerElement,i,this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({file:i,lineAnnotations:a}),r||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),ae(e,t);for(let t of Array.from(e.shadowRoot?.children??[])){if(t instanceof SVGElement){this.spriteSVG=t;continue}if(t instanceof HTMLElement){if(t instanceof HTMLPreElement){this.pre=t,this.appliedPreAttributes=void 0;continue}if(t instanceof HTMLStyleElement&&t.hasAttribute(`data-theme-css`)){this.themeCSSStyle=t;continue}if(t instanceof HTMLStyleElement&&t.hasAttribute(`data-unsafe-css`)){this.unsafeCSSStyle=t,this.appliedUnsafeCSS=t.textContent;continue}if(`diffsHeader`in t.dataset){this.headerElement=t,this.lastRenderedHeaderHTML=void 0;continue}}}this.pre!=null&&(this.syncCodeNodeFromPre(this.pre),this.pre.removeAttribute(`data-dehydrated`)),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({file:e,lineAnnotations:t}){this.lineAnnotations=t??this.lineAnnotations,this.file=e,this.fileRenderer.setOptions(Z(this.options)),this.syncInteractionOptions(),this.pre!=null&&(this.fileRenderer.hydrate(e),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}getOrCreateLineCache(e=this.file){return e==null?xe:this.fileRenderer.getOrCreateLineCache(e)}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}syncRenderView=()=>{let e=this.editor,t=this.fileContainer,n=this.file;e!=null&&t!=null&&n!=null&&this.fileRenderer.initializeHighlighter().then(r=>{e.__syncRenderView(r,t,n,this.lineAnnotations,this.renderRange)})};attachEditor(e){return this.editor?.cleanUp(),this.editor=e,V(this.syncRenderView),()=>{this.editor=void 0}}applyDocumentChange(e,t){this.fileRenderer.applyDocumentChange(e),t!=null&&t!==this.lineAnnotations&&this.file!=null&&(this.setLineAnnotations(t),this.fileRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations())}updateRenderCache(e,t){this.fileRenderer.updateRenderCache(e,t)}render({file:e,fileContainer:t,forceRender:n=!1,preventEmit:r=!1,containerWrapper:i,deferManagers:a=!1,lineAnnotations:o,renderRange:s}){if(!this.enabled)throw Error(`File.render: attempting to call render after cleaned up`);this.editor?.__postponeBackgroundTokenizeToNextFrame();let{collapsed:c=!1,themeType:l=`system`}=this.options,u=c?void 0:s,d=this.renderRange,f=this.hasThemeChanged(),p=o!=null&&(o.length>0||this.lineAnnotations.length>0)?o!==this.lineAnnotations:!1,m=!k(this.file,e);if(!c&&!n&&b(u,this.renderRange)&&!m&&!p&&!f)return this.applyCachedThemeState(l);this.renderRange=u,m&&(this.cachedHeaderHTML=void 0),this.file=e,this.fileRenderer.setOptions(Z(this.options)),this.syncInteractionOptions(),o!=null&&this.setLineAnnotations(o),this.fileRenderer.setLineAnnotations(this.lineAnnotations);let{disableErrorHandling:h=!1,disableFileHeader:g=!1}=this.options;if(g&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),t=this.getOrCreateFileContainerNode(t,i),this.applyCachedThemeState(l),c){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{let n=this.fileRenderer.renderFile(e,z);n!=null&&this.applyThemeState(t,n.themeStyles,l,n.baseThemeType),n?.headerAST!=null&&this.applyHeaderToDOM(n.headerAST,t),this.injectUnsafeCSS()}catch(e){if(h)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,t)}return r||this.emitPostRender(),!0}try{let r=this.getOrCreatePreNode(t);if(!this.canPartiallyRender(n,p,m||f)||!this.applyPartialRender(d,u)){let n=this.fileRenderer.renderFile(e,u);if(n==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(t,n.themeStyles,l,n.baseThemeType),n.headerAST!=null&&this.applyHeaderToDOM(n.headerAST,t),this.applyFullRender(n,r)}this.applyBuffers(r,u),this.injectUnsafeCSS(),this.managersDirty=!0,a||this.flushManagers(),this.renderAnnotations(),this.renderGutterUtility(),this.editor!=null&&V(this.syncRenderView)}catch(e){if(h)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,t)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){let{fileContainer:t,options:{onPostRender:n}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;n?.(t,this,`unmount`);return}if(t==null)return;let r=this.mounted?`update`:`mount`;this.mounted=!0,n?.(t,this,r)}removeRenderedCode(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.code?.remove(),this.code=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(let{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}canPartiallyRender(e,t,n){return!(e||t||n)}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){let e=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:`open`});this.placeHolder=document.createElement(`div`),this.placeHolder.dataset.placeholder=``,e.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty(`height`,`${e}px`),!0}primeHighlightCache(){let{file:e,workerManager:t}=this;e==null||e.cacheKey==null||t==null||Y(e)||this.fileRenderer.getOrCreateLineCache(e).length>(this.options.tokenizeMaxLength??1e5)||t.primeFileHighlightCache(e)}cleanChildNodes(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.code?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.gutterUtilityContent?.remove(),this.headerPrefix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.code=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.gutterUtilityContent=void 0,this.headerPrefix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.lastRenderedHeaderHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(let{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear();return}let e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(let[n,r]of this.lineAnnotations.entries()){let i=`${n}-${c(r)}`,a=this.annotationCache.get(i);if(a==null||!be(r,a.annotation)){a?.element.remove();let e=t(r);if(e==null)continue;a={element:re(c(r)),annotation:r},a.element.appendChild(e),this.fileContainer.appendChild(a.element),this.annotationCache.set(i,a)}e.delete(i)}for(let[t,{element:n}]of e.entries())this.annotationCache.delete(t),n.remove()}renderGutterUtility(){let{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let n=se();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}injectUnsafeCSS(){let{unsafeCSS:e}=this.options,t=this.fileContainer?.shadowRoot;if(t!=null){if(e==null||e===``){this.unsafeCSSStyle!=null&&(this.unsafeCSSStyle.remove(),this.unsafeCSSStyle=void 0),this.appliedUnsafeCSS=void 0;return}this.unsafeCSSStyle?.parentNode===t&&this.appliedUnsafeCSS===e||(this.unsafeCSSStyle??=R(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=de(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){let i=e.shadowRoot??e.attachShadow({mode:`open`}),a=r??n,o=this.options.theme??F,s=typeof o==`string`?o:{...o},c=I(i);if(this.themeCSSStyle?.parentNode===i&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===a&&this.appliedThemeCSS.scrollbarGutter===c){this.appliedThemeCSS.theme=s;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===i){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:s,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:c};return}this.themeCSSStyle=ce({shadowRoot:i,currentNode:this.themeCSSStyle,themeCSS:ne(t,a,c)}),this.appliedThemeCSS=this.themeCSSStyle==null?void 0:{theme:s,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:c}}hydrateMeasuredScrollbar(){let e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=P(this.themeCSSStyle.textContent??``,I(e)))}applyFullRender(e,t){this.cleanupErrorWrapper(),this.applyPreNodeAttributes(t,e),this.code=le({code:this.code});let n=this.fileRenderer.renderCodeAST(e);if(this.code.childElementCount>=2)for(let e=0;e<2;e++){let t=this.code.children[e],r=n[e];t.innerHTML=_(r.children),t.style.cssText=r.properties.style}else this.code.innerHTML=_(n);t.contains(this.code)||t.replaceChildren(this.code),this.lastRowCount=e.rowCount}applyPartialRender(e,t){if(e==null||t==null)return!1;let{file:n,code:r}=this,i=r==null?void 0:this.getColumns(r);if(n==null||r==null||i==null)return!1;let a=e.startingLine,o=t.startingLine,s=e.totalLines===1/0?1/0:a+e.totalLines,c=t.totalLines===1/0?1/0:o+t.totalLines,l=Math.max(a,o),u=Math.min(s,c);if(u<=l||!this.trimDOMToOverlap(i.gutter,l,u)||!this.trimDOMToOverlap(i.content,l,u))return!1;let{length:d}=i.content.children,f=(e,t)=>{if(!(t<=0))return this.fileRenderer.renderFile(n,{startingLine:e,totalLines:t,bufferBefore:0,bufferAfter:0})},p=o<l?f(o,l-o):void 0;if(p===void 0&&o<l)return!1;let m=c===1/0?1/0:Math.max(0,c-u),h=c>u?f(u,m):void 0;return h===void 0&&c>u?!1:(this.cleanupErrorWrapper(),p!=null&&(i.gutter.insertAdjacentHTML(`afterbegin`,this.fileRenderer.renderPartialHTML(p.gutterAST)),i.content.insertAdjacentHTML(`afterbegin`,this.fileRenderer.renderPartialHTML(p.contentAST)),d+=p.rowCount),h!=null&&(i.gutter.insertAdjacentHTML(`beforeend`,this.fileRenderer.renderPartialHTML(h.gutterAST)),i.content.insertAdjacentHTML(`beforeend`,this.fileRenderer.renderPartialHTML(h.contentAST)),d+=h.rowCount),this.lastRowCount!==d&&(i.gutter.style.setProperty(`grid-row`,`span ${d}`),i.content.style.setProperty(`grid-row`,`span ${d}`),this.lastRowCount=d),!0)}getColumns(e){let t=e.children[0],n=e.children[1];if(!(!(t instanceof HTMLElement)||!(n instanceof HTMLElement)||t.dataset.gutter==null||n.dataset.content==null))return{gutter:t,content:n}}trimDOMToOverlap(e,t,n){let r=this.getDOMBoundaryIndices(e,[t,n]),i=r.get(t)??e.children.length,a=r.get(n)??e.children.length;if(i>a)return!1;for(let t=e.children.length-1;t>=a;--t)e.children[t]?.remove();for(let t=i-1;t>=0;--t)e.children[t]?.remove();return!0}getDOMBoundaryIndices(e,t){let n=[...new Set(t)].sort((e,t)=>e-t),r=new Map;if(n.length===0)return r;let i=0,a=n[i],{children:o}=e;a===0&&(r.set(0,0),i+=1,a=n[i]);for(let e=0;e<o.length;e+=1){let t=o[e];if(!(t instanceof HTMLElement))continue;let s=this.getLineIndexFromDOMNode(t);if(s!=null){for(;a!=null&&s>=a;)r.set(a,e),i+=1,a=n[i];if(i>=n.length)break}}for(let e of n)r.has(e)||r.set(e,o.length);return r}getLineIndexFromDOMNode(e){let t=e.dataset.lineIndex;if(t==null)return;let n=Number(t);return Number.isNaN(n)?void 0:n}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore??(this.bufferBefore=document.createElement(`div`),this.bufferBefore.dataset.virtualizerBuffer=`before`,e.before(this.bufferBefore)),this.bufferBefore.style.setProperty(`height`,`${t.bufferBefore}px`),this.bufferBefore.style.setProperty(`contain`,`strict`)):this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),t.bufferAfter>0?(this.bufferAfter??(this.bufferAfter=document.createElement(`div`),this.bufferAfter.dataset.virtualizerBuffer=`after`,e.after(this.bufferAfter)),this.bufferAfter.style.setProperty(`height`,`${t.bufferAfter}px`),this.bufferAfter.style.setProperty(`contain`,`strict`)):this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0)}shouldDisableVirtualizationBuffers(){return this.options.disableVirtualizationBuffers??!1}applyHeaderToDOM(e,t){let{file:n}=this;if(n==null)return;this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;let r=this.cachedHeaderHTML??_(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){let e=document.createElement(`div`);e.innerHTML=r;let n=e.firstElementChild;if(!(n instanceof HTMLElement))return;this.headerElement==null?t.shadowRoot?.prepend(n):t.shadowRoot?.replaceChild(n,this.headerElement),this.headerElement=n,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged)return;let{renderHeaderPrefix:i,renderCustomHeader:a,renderHeaderMetadata:o}=this.options;if(a!=null){let e=a(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,K,e),this.headerPrefix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerMetadata=void 0}else{let e=i?.(n)??void 0,r=o?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,fe,e),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,A,r),this.headerCustom?.remove(),this.headerCustom=void 0}}clearHeaderSlots(){this.headerPrefix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.headerPrefix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0}upsertHeaderSlotElement(e,t,n,r){if(r==null){t?.remove();return}let i=t??this.createHeaderSlotElement(n);return t??e.appendChild(i),this.replaceHeaderSlotContent(i,r),i}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){let t=document.createElement(`div`);return t.slot=e,t}getOrCreateFileContainerNode(e,t){let{fileContainer:n}=this,r=e??n??document.createElement(`diffs-container`),i=n!==r;return i&&this.emitPostRender(!0),this.fileContainer=r,n!=null&&i&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),i&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){let{shadowRoot:t}=e;if(t!=null)for(let e of t.children)e instanceof SVGElement?this.spriteSVG??=e:H(e)&&e.hasAttribute(`data-theme-css`)?(this.themeCSSStyle??=e,this.hasAdoptedThemeCSS=!0):H(e)&&e.hasAttribute(`data-unsafe-css`)&&(this.unsafeCSSStyle??=e,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){let t=e.shadowRoot??e.attachShadow({mode:`open`});if(this.spriteSVG==null){let e=document.createElement(`div`);e.innerHTML=B;let t=e.firstChild;t instanceof SVGElement&&(this.spriteSVG=t)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){let t=e.shadowRoot??e.attachShadow({mode:`open`});return this.pre==null?(this.pre=document.createElement(`pre`),this.appliedPreAttributes=void 0,this.code=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(e.shadowRoot?.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodeFromPre(e){this.code=void 0;for(let t of Array.from(e.children))if(t instanceof HTMLElement&&t.hasAttribute(`data-code`)){this.code=t;return}}applyPreNodeAttributes(e,{totalLines:t}){let{overflow:n=`scroll`,disableLineNumbers:r=!1}=this.options,i={type:`file`,split:!1,overflow:n,disableLineNumbers:r,diffIndicators:`none`,disableBackground:!0,totalLines:t};ee(i,this.appliedPreAttributes)||(M(e,i),this.appliedPreAttributes=i)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;let n=t.shadowRoot??t.attachShadow({mode:`open`});this.errorWrapper??=document.createElement(`div`),this.errorWrapper.dataset.errorWrapper=``,this.errorWrapper.textContent=``,n.appendChild(this.errorWrapper);let r=document.createElement(`div`);r.dataset.errorMessage=``,r.innerText=e.message,this.errorWrapper.appendChild(r);let i=document.createElement(`pre`);i.dataset.errorStack=``,i.innerText=e.stack??`No Error Stack`,this.errorWrapper.appendChild(i)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}};function Ce(e,t,n=!1){return!n&&e==null&&t!=null}function we(e,t,n=!1){return e==null&&t!=null&&!n}var Te=5e3,Ee=-1;function De(e,t){return(e.overflow??`scroll`)!==(t.overflow??`scroll`)||(e.collapsed??!1)!==(t.collapsed??!1)||(e.disableLineNumbers??!1)!==(t.disableLineNumbers??!1)||(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||e.unsafeCSS!==t.unsafeCSS}var Oe=class extends Q{__id=`virtualized-file:${++Ee}`;top;height=0;cache={heights:new Map,checkpoints:[],fileAnnotationHeight:0};isVisible=!1;isSetup=!1;layoutDirty=!0;forceRenderOverride;currentCollapsed;constructor(e,t,n=oe,r,i=!1){super(e,r,i),this.virtualizer=t,this.metrics=n}setMetrics(e,t=!1){!t&&ie(this.metrics,e)||(this.metrics=e,this.resetLayoutCache())}setLineAnnotations(e){this.syncLineAnnotations(e)&&this.resetLayoutCache()}syncLineAnnotations(e){return e==null||e===this.lineAnnotations||e.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(e),!0)}hasLineAnnotations(){return this.lineAnnotations.some(e=>e.lineNumber>0)}getLineHeight(e,t=!1){let n=this.cache.heights.get(e);if(n!=null)return n;let r=t?2:1;return this.metrics.lineHeight*r}setOptions(e){if(this.isAdvancedMode())throw Error(`VirtualizedFile.setOptions cannot be used inside CodeView. Update CodeView options instead.`);if(e==null)return;let{options:t}=this,n=!L(t,e),r=De(t,e);super.setOptions(e),r&&this.resetLayoutCache(!0),n&&(this.forceRenderOverride=!0),n&&this.virtualizer.instanceChanged(this,r)}setThemeType(e){if(this.isAdvancedMode())throw Error(`VirtualizedFile.setThemeType cannot be used inside CodeView. Update CodeView options instead.`);super.setThemeType(e)}resetLayoutCache(e=!1){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heights.size>0&&this.cache.heights.clear(),this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.renderRange!=null&&(this.renderRange=void 0),e&&this.isSimpleMode()&&this.computeApproximateSize()}reconcileHeights(){let e=!1;if(this.fileContainer==null||this.file==null)return this.height!==0&&(e=!0),this.height=0,e;let{overflow:t=`scroll`}=this.options;if(this.top=this.getVirtualizedTop(),t===`scroll`&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled()||this.code==null)return e;let n=this.code.children[1];if(!(n instanceof HTMLElement))return e;let r=w(this.lineAnnotations);if(this.renderRange!=null&&r&&s(this.renderRange)){let t=ke(n)??0;t!==this.cache.fileAnnotationHeight&&(this.cache.fileAnnotationHeight=t,e=!0)}else!r&&this.cache.fileAnnotationHeight!==0&&(this.cache.fileAnnotationHeight=0,e=!0);for(let t of n.children){if(!(t instanceof HTMLElement))continue;let n=t.dataset.lineIndex;if(n==null)continue;let r=Number(n),i=t.getBoundingClientRect().height,a=!1;t.nextElementSibling instanceof HTMLElement&&(`lineAnnotation`in t.nextElementSibling.dataset||`noNewline`in t.nextElementSibling.dataset)&&(`noNewline`in t.nextElementSibling.dataset&&(a=!0),i+=t.nextElementSibling.getBoundingClientRect().height);let o=this.getLineHeight(r,a);i!==o&&(e=!0,i===this.metrics.lineHeight*(a?2:1)?this.cache.heights.delete(r):this.cache.heights.set(r,i))}return(e||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),e}onRender=e=>this.fileContainer==null||this.file==null?!1:(e&&(this.top=this.getVirtualizedTop()),this.render({file:this.file}));prepareCodeViewItem(e,t,n,r){let i=this.syncLineAnnotations(r),a=n?.resetFileLayoutCache===!0||i;n?.metrics!=null&&(this.metrics=n.metrics,a=!0);let{collapsed:o=!1}=this.options;return this.currentCollapsed!==o&&(this.currentCollapsed=o,a=!0),a&&this.resetLayoutCache(),this.file!==e&&(this.layoutDirty=!0),this.file=e,this.top=t,this.computeApproximateSize(),this.height}getLinePosition(e){if(this.file==null||e<1)return;let{disableFileHeader:t=!1,collapsed:n=!1}=this.options,r=this.fileRenderer.getLineCount(this.file)-1,i=J(this.metrics,t);if(n||r<0)return{top:i,height:0};let a=Math.min(Math.max(e-1,0),r),{overflow:o=`scroll`}=this.options,{lineHeight:s}=this.metrics;if(i+=this.cache.fileAnnotationHeight,o===`scroll`&&!this.hasLineAnnotations())return{top:i+a*s,height:s};let c=this.getLayoutCheckpointBeforeLineIndex(a);i=c?.top??i;for(let e=c?.lineIndex??0;e<a;e++)i+=this.getLineHeight(e,!1);return{top:i,height:this.getLineHeight(a,!1)}}getNumericScrollAnchor(e){if(this.file==null||this.renderRange==null)return;let{disableFileHeader:t=!1,collapsed:n=!1,overflow:r=`scroll`}=this.options;if(n||this.renderRange.totalLines<=0)return;let i=this.fileRenderer.getLineCount(this.file)-1;if(i<0)return;let a=J(this.metrics,t),o=Math.min(this.renderRange.startingLine,i),s=Math.min(o+this.renderRange.totalLines-1,i);if(s<o)return;let{fileAnnotationHeight:c}=this.cache;if(r===`scroll`&&!this.hasLineAnnotations()){let{lineHeight:t}=this.metrics,n=a+(o===0?c:this.renderRange.bufferBefore),r=o+Math.max(Math.ceil((e-n)/t),0);return r>s?void 0:{lineNumber:r+1,top:a+c+r*t}}let l=a+(o===0?c:this.renderRange.bufferBefore);for(let t=o;t<=s;t++){if(l>=e)return{lineNumber:t+1,top:l};l+=this.getLineHeight(t)}}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(e){if(this.top==null||this.file==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};let t=e==null?this.renderRange:this.computeRenderRangeFromWindow(this.file,this.top,e);if(t==null)return;let{bufferBefore:n,bufferAfter:r,totalLines:i}=t,a=0;if(i===0){let t=e??this.virtualizer.getWindowSpecs();this.top<t.top&&(a=r)}return{topOffset:this.top+n+a,height:this.height-(n+r)}}cleanUp(e=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),e||this.resetLayoutCache(),this.isSetup=!1,super.cleanUp(e)}computeApproximateSize(e=!1){let t=this.isResizeDebuggingEnabled();if(!e&&!this.layoutDirty&&!t)return;let n=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.file==null){this.layoutDirty=!1;return}let{disableFileHeader:r=!1,collapsed:i=!1,overflow:a=`scroll`}=this.options,{lineHeight:o}=this.metrics,s=this.fileRenderer.getLineCount(this.file),c=J(this.metrics,r),l=G(this.metrics);if(this.height+=c,i){this.layoutDirty=!1;return}if(this.height+=this.cache.fileAnnotationHeight,a===`scroll`&&!this.hasLineAnnotations())this.height+=s*o;else for(let e=0;e<s;e++)this.addLayoutCheckpoint(e,this.height),this.height+=this.getLineHeight(e,!1);if(s>0&&(this.height+=l),this.fileContainer!=null&&t&&!n){let e=this.fileContainer.getBoundingClientRect();e.height===this.height?console.log(`VirtualizedFile.computeApproximateSize: computed height IS CORRECT`):console.log(`VirtualizedFile.computeApproximateSize: computed height doesnt match`,{name:this.file.name,elementHeight:e.height,computedHeight:this.height})}this.layoutDirty=!1}setVisibility(e){this.isAdvancedMode()||this.fileContainer==null||(e&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!e&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.file==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(e,t,n=!1){let{heights:r,checkpoints:i}=this.cache,a=this.renderRange;if(super.applyDocumentChange(e,t),this.getSimpleVirtualizer()?.markDOMDirty(),this.layoutDirty=!0,r.size>0&&r.clear(),i.length>0&&(i.length=0),this.isSimpleMode()&&this.computeApproximateSize(),n&&a!==void 0&&this.file!==void 0){let e=this.virtualizer.getWindowSpecs(),t=this.computeRenderRangeFromWindow(this.file,this.top??0,e);t.bufferAfter!==a.bufferAfter&&this.updateBuffers(t)}}render({fileContainer:e,file:t,forceRender:n=!1,lineAnnotations:r,...i}){let a=this.file==null||!k(this.file,t),{forceRenderOverride:o,isSetup:s}=this;this.forceRenderOverride=void 0;let c=this.syncLineAnnotations(r);if(c&&this.resetLayoutCache(),this.file=t,e=this.getOrCreateFileContainerNode(e),this.file==null)return console.error(`VirtualizedFile.render: attempting to virtually render when we dont have file`),!1;if(s)this.top??=this.getVirtualizedTop(),a&&this.isSimpleMode()&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(!0));else{this.computeApproximateSize();let t=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(t==null)throw Error(`VirtualizedFile.render: simple virtualizer is not available`);t.connect(e,this),this.isVisible=t.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode())return this.renderPlaceholder(this.height);let l=this.virtualizer.getWindowSpecs(),u=this.top??0,d=this.computeRenderRangeFromWindow(this.file,u,l);return super.render({file:this.file,fileContainer:e,renderRange:d,lineAnnotations:r,forceRender:(o??n)||c,...i})}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}isSimpleMode(){return this.virtualizer.type===`simple`}isAdvancedMode(){return this.virtualizer.type===`advanced`}addLayoutCheckpoint(e,t){e%Te===0&&this.cache.checkpoints.push({lineIndex:e,top:t})}getLayoutCheckpointBeforeLineIndex(e){if(e<=0||this.cache.checkpoints.length===0)return;let t=0,n=this.cache.checkpoints.length-1,r;for(;t<=n;){let i=t+n>>1,a=this.cache.checkpoints[i];if(a==null)throw Error(`VirtualizedFile: invalid checkpoint index`);a.lineIndex<=e?(r=a,t=i+1):n=i-1}return r}getLayoutCheckpointBeforeTop(e,t){let n=0,r=this.cache.checkpoints.length-1,i=-1;for(;n<=r;){let t=n+r>>1,a=this.cache.checkpoints[t];if(a==null)throw Error(`VirtualizedFile: invalid checkpoint index`);a.top<=e?(i=t,n=t+1):r=t-1}if(t==null)return i>=0?this.cache.checkpoints[i]:void 0;for(let e=i;e>=0;e--){let n=this.cache.checkpoints[e];if(n==null)throw Error(`VirtualizedFile: invalid checkpoint index`);if(n.lineIndex%t===0)return n}}getVirtualizedTop(){return this.virtualizer.type===`advanced`?this.virtualizer.getLocalTopForInstance(this):this.fileContainer==null?0:this.virtualizer.getOffsetInScrollContainer(this.fileContainer)}getSimpleVirtualizer(){return this.virtualizer.type===`simple`?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}computeRenderRangeFromWindow(e,t,{top:n,bottom:r}){let{disableFileHeader:i=!1,overflow:a=`scroll`}=this.options,{hunkLineCount:o,lineHeight:s}=this.metrics,c=this.fileRenderer.getLineCount(e),l=this.height,u=J(this.metrics,i),d=c>0?G(this.metrics):0,{fileAnnotationHeight:f}=this.cache,p=u+f,m=Math.max(0,l-u-f-d),h=w(this.lineAnnotations),g=t+u,_=f>0&&h&&g<r&&g+f>n;if(t<n-l||t>r)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-u-d};if(c<=o)return{startingLine:0,totalLines:o,bufferBefore:0,bufferAfter:0};let v=Math.ceil(Math.max(r-n,0)/s),y=Math.ceil(v/o)*o+o*2,b=y/o,x=(n+r)/2;if(a===`scroll`&&!this.hasLineAnnotations()){let e=t+p,i=e+m;if(!_&&!(e<r&&i>n))return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-u-d};let a=Math.floor(_&&x<t+p?0:(x-(t+p))/s),h=Math.floor(a/o)-Math.floor(b/2),g=Math.ceil(c/o),v=Math.max(0,Math.min(h,g))*o,S=h<0?y+h*o:y,C=v===0?0:f+v*s,w=Math.min(S,c-v);return{startingLine:v,totalLines:S,bufferBefore:C,bufferAfter:Math.max(0,(c-v-w)*s)}}let S=b,C=[],T=this.getLayoutCheckpointBeforeTop(Math.max(0,n-t-y*s*2),o),E=t+(T?.top??p),D=T?.lineIndex??0,O,k,A,j=T?.lineIndex??0;for(let e=j;e<c;e++){let i=D%o===0,a=Math.floor(D/o);if(i&&(C[a]=E-(t+p),A!=null)){if(A<=0)break;A--}let s=this.getLineHeight(e,!1);E>n-s&&E<r&&(O??=a),E+s>x&&(k??=a),A==null&&E>=r&&i&&(A=S),D++,E+=s}if(O==null)if(_)O=0,k=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-u-d};k??=O;let M=Math.round(k-b/2),N=Math.max(0,Math.ceil(c/o)-b),P=Math.max(0,Math.min(M,N)),F=P*o,I=M<0?y+M*o:y,L=C[P]??0,R=F===0?0:f+L,z=P+I/o,B=z<C.length?m-C[z]:m-(E-t-p);return{startingLine:F,totalLines:I,bufferBefore:R,bufferAfter:Math.max(0,B)}}};function ke(e){let t;for(let n of e.children)n instanceof HTMLElement&&n.dataset.lineAnnotation===N&&(t=Math.max(t??0,n.getBoundingClientRect().height));return t}var $=t();function Ae({file:e,renderCustomHeader:t,renderHeaderPrefix:n,renderHeaderMetadata:r,renderAnnotation:i,lineAnnotations:a,renderGutterUtility:o,getHoveredLine:s}){let u=t?.(e),d=n?.(e),f=r?.(e);return(0,$.jsxs)($.Fragment,{children:[u==null?(0,$.jsxs)($.Fragment,{children:[d!=null&&(0,$.jsx)(`div`,{slot:`header-prefix`,children:d}),f!=null&&(0,$.jsx)(`div`,{slot:`header-metadata`,children:f})]}):(0,$.jsx)(`div`,{slot:K,children:u}),i!=null&&a?.map((e,t)=>(0,$.jsx)(`div`,{slot:c(e),children:i(e)},t)),o!=null&&(0,$.jsx)(`div`,{slot:`gutter-utility-slot`,style:l,children:o(s)})]})}var je=r(),Me=e(n(),1);function Ne(e){let t=(0,je.c)(44),{kind:n,rangeLabel:r,text:o,onCancel:s,onComment:c,onDelete:l}=e,[u,f]=(0,Me.useState)(``);if(n===`comment`){let e,n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(d,{className:`size-4 text-muted-foreground`}),n=(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:`Local comment`}),t[0]=e,t[1]=n):(e=t[0],n=t[1]);let a;t[2]===r?a=t[3]:(a=(0,$.jsx)(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,children:r}),t[2]=r,t[3]=a);let s;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(pe,{className:`size-3.5`}),t[4]=s):s=t[4];let c;t[5]===l?c=t[6]:(c=(0,$.jsx)(i,{variant:`ghost`,size:`icon-xs`,"aria-label":`Delete comment`,onClick:l,children:s}),t[5]=l,t[6]=c);let u;t[7]!==a||t[8]!==c?(u=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e,n,a,c]}),t[7]=a,t[8]=c,t[9]=u):u=t[9];let f;t[10]===o?f=t[11]:(f=(0,$.jsx)(`p`,{className:`mt-2 whitespace-pre-wrap text-sm leading-relaxed text-foreground`,children:o}),t[10]=o,t[11]=f);let p;return t[12]!==u||t[13]!==f?(p=(0,$.jsxs)(`div`,{"data-file-comment-annotation":!0,className:`mx-3 my-2 rounded-xl border border-border/70 bg-background p-3 shadow-sm`,contentEditable:!1,onPointerDown:Fe,children:[u,f]}),t[12]=u,t[13]=f,t[14]=p):p=t[14],p}let p;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(d,{className:`size-4 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`text-sm font-medium`,children:`Local comment`})]}),t[15]=p):p=t[15];let m;t[16]===r?m=t[17]:(m=(0,$.jsxs)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:[`Comment on lines `,r]}),t[16]=r,t[17]=m);let h=`Comment on lines ${r}`,g;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(g=e=>f(e.target.value),t[18]=g):g=t[18];let _;t[19]!==s||t[20]!==c||t[21]!==u?(_=e=>{e.key===`Escape`&&(e.preventDefault(),s()),(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&u.trim()&&(e.preventDefault(),c(u.trim()))},t[19]=s,t[20]=c,t[21]=u,t[22]=_):_=t[22];let v;t[23]!==h||t[24]!==_||t[25]!==u?(v=(0,$.jsx)(a,{autoFocus:!0,className:`mt-3`,size:`sm`,value:u,placeholder:`Request change`,"aria-label":h,onChange:g,onKeyDown:_}),t[23]=h,t[24]=_,t[25]=u,t[26]=v):v=t[26];let y;t[27]===s?y=t[28]:(y=(0,$.jsx)(i,{variant:`ghost`,size:`sm`,onClick:s,children:`Cancel`}),t[27]=s,t[28]=y);let b;t[29]===u?b=t[30]:(b=u.trim(),t[29]=u,t[30]=b);let x=!b,S;t[31]!==c||t[32]!==u?(S=()=>c(u.trim()),t[31]=c,t[32]=u,t[33]=S):S=t[33];let C;t[34]!==S||t[35]!==x?(C=(0,$.jsx)(i,{size:`sm`,disabled:x,onClick:S,children:`Comment`}),t[34]=S,t[35]=x,t[36]=C):C=t[36];let w;t[37]!==C||t[38]!==y?(w=(0,$.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[y,C]}),t[37]=C,t[38]=y,t[39]=w):w=t[39];let T;return t[40]!==w||t[41]!==m||t[42]!==v?(T=(0,$.jsxs)(`div`,{"data-file-comment-annotation":!0,className:`mx-3 my-2 rounded-xl border border-border/70 bg-background p-3 shadow-lg`,contentEditable:!1,onPointerDown:Pe,children:[p,m,v,w]}),t[40]=w,t[41]=m,t[42]=v,t[43]=T):T=t[43],T}function Pe(e){return e.stopPropagation()}function Fe(e){return e.stopPropagation()}var Ie=0;function Le(){return Ie+=1,`file-comment-${Date.now()}-${Ie}`}function Re(e){return{startLine:Math.min(e.start,e.end),endLine:Math.max(e.start,e.end)}}function ze(e,t){return e===t?`L${e}`:`L${e} to L${t}`}function Be(e){return e.map(e=>({...e,metadata:{entries:e.metadata.entries.map(t=>{let n=t.endLine-t.startLine;return{...t,endLine:e.lineNumber,startLine:Math.max(1,e.lineNumber-n)}})}}))}export{Ne as a,Q as c,Be as i,Le as n,Ae as o,Re as r,Oe as s,ze as t};
2
- //# sourceMappingURL=fileCommentAnnotations-C-wWopty.js.map
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{n as t,r as n,t as r}from"./compiler-runtime-CLAvuQ-D.js";import{Qr as i,c as a}from"./terminal-links-B2KXT7CK.js";import{At as o,Ct as s,Dt as c,E as l,Et as u,Fr as d,Ft as f,Gt as p,Ht as m,It as h,Jt as g,Kt as _,Lt as v,Mt as y,Nt as b,Ot as x,Pt as S,Rt as C,St as w,Ut as T,Wt as E,Xt as D,Yt as O,Zt as k,_n as A,_t as j,at as M,bt as N,ct as P,dn as F,dt as I,en as L,ft as R,gn as z,gt as B,ht as ee,in as V,it as H,jt as te,kt as U,ln as W,lt as ne,mt as re,nn as ie,nt as G,on as K,ot as ae,pn as oe,pt as se,qt as q,rt as ce,st as le,tn as ue,tt as J,ut as de,vn as fe,vt as Y,wr as pe,wt as me,xt as he,yt as ge,zt as _e}from"./index-DYDaZ0DX.js";var ve=-1,ye=class{__id=`file-renderer:${++ve}`;highlighter;renderCache;computedLang=`text`;lineAnnotations={};lineCache;textDoucmentCache=new WeakMap;constructor(e={theme:F},t,n){this.options=e,this.onRenderUpdate=t,this.workerManager=n,n?.isWorkingPool()!==!0&&(this.highlighter=h(e.theme??F)?C():void 0)}setOptions(e){this.options=e}mergeOptions(e){this.options={...this.options,...e}}setLineAnnotations(e){this.lineAnnotations={};for(let t of e){let e=this.lineAnnotations[t.lineNumber]??[];this.lineAnnotations[t.lineNumber]=e,e.push(t)}}cleanUp(){this.recycle(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.clearRenderCache(),this.highlighter=void 0,this.workerManager?.cleanUpTasks(this),this.lineCache=void 0}clearRenderCache(){let e=this.renderCache;this.renderCache=void 0,e!=null&&e.isDirty===!0&&e.file.cacheKey!=null&&this.workerManager?.evictFileFromCache(e.file.cacheKey)}hydrate(e){let{options:t}=this.getRenderOptions(e),n=X(this.getOrCreateLineCache(e).length,this.getTokenizeMaxLength()),r=this.workerManager?.getFileResultCache(e);r!=null&&!S(t,r.options)&&(r=void 0),this.renderCache??={file:e,options:t,highlighted:!n&&!Y(e),result:n?void 0:r?.result,renderRange:void 0},this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!n&&this.workerManager.highlightFileAST(this,e):this.highlighter??(this.computedLang=e.lang??U(e.name),this.initializeHighlighter())}getRenderOptions(e){let t=(()=>{if(this.workerManager?.isWorkingPool()===!0)return this.workerManager.getFileRenderOptions();let{theme:e=F,tokenizeMaxLineLength:t=1e3}=this.options;return{theme:e,useTokenTransformer:j(this.options),tokenizeMaxLineLength:t}})(),{renderCache:n}=this;return n?.result==null||!k(e,n.file)||!S(t,n.options)?{options:t,forceHighlight:!0}:{options:t,forceHighlight:!1}}getOrCreateLineCache(e){if(e.cacheKey==null)return this.lineCache=void 0,u(e.contents);let{lineCache:t}=this;return(t==null||t.cacheKey!==e.cacheKey)&&(t={cacheKey:e.cacheKey,lines:u(e.contents)}),this.lineCache=t,t.lines}getLineCount(e){return this.textDoucmentCache.get(e)?.lineCount??this.getOrCreateLineCache(e).length}updateRenderCache(e,t){if(this.renderCache==null)return;let{result:n}=this.renderCache;if(n!=null){for(let[r,i]of e)n.code[r]={type:`element`,tagName:`div`,properties:{"data-line":r+1,"data-line-type":`context`,"data-line-index":r},children:i.map(([e,n,r])=>e===0&&n===``?r===``?{type:`element`,tagName:`br`,properties:{},children:[]}:{type:`text`,value:r}:{type:`element`,tagName:`span`,properties:{"data-char":e,style:`--diffs-token-${t}:${n};`},children:[{type:`text`,value:r}]})};n.baseThemeType=t,this.renderCache.isDirty=!0}}applyDocumentChange(e){if(this.renderCache==null)return;let{file:t,result:n}=this.renderCache;if(n!=null&&n.code.length!==e.lineCount){for(let t=n.code.length;t<e.lineCount;t++)n.code.push({type:`element`,tagName:`div`,properties:{"data-line":t+1,"data-line-type":`context`,"data-line-index":t},children:[{type:`element`,tagName:`span`,properties:{"data-char":0},children:[{type:`text`,value:e.getLineText(t)}]}]});this.renderCache.isDirty=!0}this.textDoucmentCache.set(t,e)}renderFile(e=this.renderCache?.file,t=W){if(e==null)return;let{options:n,forceHighlight:r}=this.getRenderOptions(e),i=this.getMatchingWorkerResultCache(e,n);i!=null&&!this.hasHighlightedRenderCache(e,n)&&(this.renderCache={file:e,highlighted:!0,renderRange:void 0,...i},r=!1),this.renderCache??={file:e,highlighted:!1,options:n,result:void 0,renderRange:void 0};let a=this.getOrCreateLineCache(e),o=e.contents.length>0,s=!o||Y(e)||X(a.length,this.getTokenizeMaxLength()),c=!k(e,this.renderCache.file),l=!b(this.renderCache.renderRange,t);if(this.workerManager?.isWorkingPool()===!0)(s||this.renderCache.result==null||!this.renderCache.highlighted&&(c||l))&&(this.renderCache.file=e,this.renderCache.options=n,this.renderCache.highlighted=!1,(this.renderCache.result==null||c||l||r)&&(this.renderCache.result=this.workerManager.getPlainFileAST(e,t.startingLine,t.totalLines,a)),this.renderCache.renderRange=t),!s&&o&&(!this.renderCache.highlighted||r)&&this.workerManager.highlightFileAST(this,e);else{this.computedLang=e.lang??U(e.name);let t=this.highlighter!=null&&h(n.theme),i=this.highlighter!=null&&m(this.computedLang),a=!s&&i;if(this.highlighter!=null&&t&&(r||s||!this.renderCache.highlighted&&a||this.renderCache.result==null)){let{result:t,options:n}=this.renderFileWithHighlighter(e,this.highlighter,s||!i);this.renderCache={file:e,options:n,highlighted:a,result:t,renderRange:void 0}}(!t||!s&&!i)&&this.asyncHighlight(e).then(({result:t,options:n})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.onHighlightSuccess(e,t,n,!s)})}return this.renderCache.result==null?void 0:this.processFileResult(this.renderCache.file,t,this.renderCache.result)}async asyncRender(e,t=W){let{result:n}=await this.asyncHighlight(e);return this.processFileResult(e,t,n)}async asyncHighlight(e){let t=X(this.getOrCreateLineCache(e).length,this.getTokenizeMaxLength());this.computedLang=t?`text`:e.lang??U(e.name);let n=this.highlighter!=null&&f(v(this.options.theme)),r=t||this.highlighter!=null&&m(this.computedLang);return(this.highlighter==null||!n||!r)&&(this.highlighter=await this.initializeHighlighter()),this.renderFileWithHighlighter(e,this.highlighter,t)}renderFileWithHighlighter(e,t,n=!1){let{options:r}=this.getRenderOptions(e);return{result:me(e,t,r,{forcePlainText:n}),options:r}}processFileResult(e,t,{code:n,themeStyles:r,baseThemeType:i}){let a=this.getLineCount(e),{disableFileHeader:o=!1}=this.options,l=[],u=O(),d=Math.min(t.startingLine+t.totalLines,a),f=0,p=s(t)?he(this.lineAnnotations):void 0;p!=null&&(u.children.push(q(`context`,`annotation`,1)),l.push(y({type:`annotation`,hunkIndex:-1,lineIndex:-1,annotations:p.map(e=>c(e))})),f++);for(let r=t.startingLine;r<d;r++){let t=r+1,i=n[r];if(i==null){let n=`FileRenderer.processFileResult: Line doesnt exist`;throw console.error(n,{name:e.name,lineIndex:r,lineNumber:t}),Error(n)}u.children.push(g(`context`,t,`${r}`)),l.push(i),f++;let a=this.lineAnnotations[t];a!=null&&(u.children.push(q(`context`,`annotation`,1)),l.push(y({type:`annotation`,hunkIndex:0,lineIndex:t,annotations:a.map(e=>c(e))})),f++)}return u.properties.style=`grid-row: span ${f}`,{gutterAST:u.children??[],contentAST:l,preAST:this.createPreElement(a),headerAST:o?void 0:this.renderHeader(e),totalLines:a,rowCount:f,themeStyles:r,baseThemeType:i,bufferBefore:t.bufferBefore,bufferAfter:t.bufferAfter,css:``}}renderHeader(e){let{headerRenderMode:t=`default`,stickyHeader:n=!1}=this.options;return te({fileOrDiff:e,mode:t,stickyHeader:n})}renderFullHTML(e){return _(this.renderFullAST(e))}renderFullAST(e,t=[]){return t.push(D({tagName:`code`,children:this.renderCodeAST(e),properties:{"data-code":``}})),{...e.preAST,children:t}}renderCodeAST(e){let t=O();return t.children=e.gutterAST,t.properties.style=`grid-row: span ${e.rowCount}`,[t,ge(e.contentAST,e.rowCount)]}renderPartialHTML(e,t=!1){return _(t?D({tagName:`code`,children:e,properties:{"data-code":``}}):e)}async initializeHighlighter(){return this.highlighter=await _e(x(this.computedLang,this.options)),this.highlighter}onHighlightSuccess(e,t,n,r=!0){if(this.renderCache==null)return;let i=!k(e,this.renderCache.file)||!this.renderCache.highlighted||!S(n,this.renderCache.options);this.renderCache={file:e,options:n,highlighted:r,result:t,renderRange:void 0},i&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(e,t){let n=this.workerManager?.getFileResultCache(e);if(!(n==null||!S(t,n.options)))return n}hasHighlightedRenderCache(e,t){let{renderCache:n}=this;return n?.result!=null&&n.highlighted&&k(e,n.file)&&S(t,n.options)}onHighlightError(e){console.error(e)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}createPreElement(e){let{disableLineNumbers:t=!1,overflow:n=`scroll`}=this.options;return o({type:`file`,diffIndicators:`none`,disableBackground:!0,disableLineNumbers:t,overflow:n,split:!1,totalLines:e})}};function X(e,t){return e>t}function be(e,t){return e.lineNumber===t.lineNumber&&e.metadata===t.metadata}function Z(e){return{theme:e?.theme,disableLineNumbers:e?.disableLineNumbers,overflow:e?.overflow,themeType:e?.themeType,collapsed:e?.collapsed,disableFileHeader:e?.disableFileHeader,disableVirtualizationBuffers:e?.disableVirtualizationBuffers,stickyHeader:e?.stickyHeader,preferredHighlighter:e?.preferredHighlighter,useCSSClasses:e?.useCSSClasses,useTokenTransformer:e?.useTokenTransformer,tokenizeMaxLineLength:e?.tokenizeMaxLineLength,tokenizeMaxLength:e?.tokenizeMaxLength,unsafeCSS:e?.unsafeCSS,headerRenderMode:e?.renderCustomHeader==null?`default`:`custom`}}var xe=[``],Se=-1,Q=class{static LoadedCustomComponent=!0;__id=`file:${++Se}`;type=`file`;fileContainer;spriteSVG;pre;code;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;errorWrapper;placeHolder;lastRenderedHeaderHTML;cachedHeaderHTML;appliedPreAttributes;lastRowCount;mounted=!1;headerElement;headerCustom;headerPrefix;headerMetadata;fileRenderer;resizeManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;file;renderRange;enabled=!0;editor;constructor(e={theme:F},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.fileRenderer=new ye(e,this.handleHighlightRender,this.workerManager),this.resizeManager=new T,this.interactionManager=new E(`file`,p(e)),this.workerManager?.subscribeToThemeChanges(this)}handleHighlightRender=()=>{this.rerender()};rerender(){!this.enabled||this.file==null||this.render({file:this.file,forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.fileRenderer.clearRenderCache(),this.rerender()}setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(p(this.options))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??`system`)!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme==`string`||this.fileContainer==null||this.appliedThemeCSS==null)return!1;let t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType===t?!1:(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!ue(this.appliedThemeCSS.theme,this.options.theme??F)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}let{overflow:e=`scroll`}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,e===`wrap`),this.managersDirty=!1}cleanUp(e=!1){this.emitPostRender(!0),this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.annotationCache.clear(),this.pre=void 0,this.bufferBefore=void 0,this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.placeHolder=void 0,this.unsafeCSSStyle=void 0,e?this.fileRenderer.recycle():(this.fileRenderer.cleanUp(),this.workerManager=void 0,this.file=void 0),this.enabled=!1,this.editor?.cleanUp(),this.editor=void 0}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){let{fileContainer:t,prerenderedHTML:n,preventEmit:r=!1,file:i,lineAnnotations:a}=e;this.hydrateElements(t,n),Ce(this.pre,i,this.options.collapsed)||we(this.headerElement,i,this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({file:i,lineAnnotations:a}),r||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),ae(e,t);for(let t of Array.from(e.shadowRoot?.children??[])){if(t instanceof SVGElement){this.spriteSVG=t;continue}if(t instanceof HTMLElement){if(t instanceof HTMLPreElement){this.pre=t,this.appliedPreAttributes=void 0;continue}if(t instanceof HTMLStyleElement&&t.hasAttribute(`data-theme-css`)){this.themeCSSStyle=t;continue}if(t instanceof HTMLStyleElement&&t.hasAttribute(`data-unsafe-css`)){this.unsafeCSSStyle=t,this.appliedUnsafeCSS=t.textContent;continue}if(`diffsHeader`in t.dataset){this.headerElement=t,this.lastRenderedHeaderHTML=void 0;continue}}}this.pre!=null&&(this.syncCodeNodeFromPre(this.pre),this.pre.removeAttribute(`data-dehydrated`)),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({file:e,lineAnnotations:t}){this.lineAnnotations=t??this.lineAnnotations,this.file=e,this.fileRenderer.setOptions(Z(this.options)),this.syncInteractionOptions(),this.pre!=null&&(this.fileRenderer.hydrate(e),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}getOrCreateLineCache(e=this.file){return e==null?xe:this.fileRenderer.getOrCreateLineCache(e)}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}syncRenderView=()=>{let e=this.editor,t=this.fileContainer,n=this.file;e!=null&&t!=null&&n!=null&&this.fileRenderer.initializeHighlighter().then(r=>{e.__syncRenderView(r,t,n,this.lineAnnotations,this.renderRange)})};attachEditor(e){return this.editor?.cleanUp(),this.editor=e,V(this.syncRenderView),()=>{this.editor=void 0}}applyDocumentChange(e,t){this.fileRenderer.applyDocumentChange(e),t!=null&&t!==this.lineAnnotations&&this.file!=null&&(this.setLineAnnotations(t),this.fileRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations())}updateRenderCache(e,t){this.fileRenderer.updateRenderCache(e,t)}render({file:e,fileContainer:t,forceRender:n=!1,preventEmit:r=!1,containerWrapper:i,deferManagers:a=!1,lineAnnotations:o,renderRange:s}){if(!this.enabled)throw Error(`File.render: attempting to call render after cleaned up`);this.editor?.__postponeBackgroundTokenizeToNextFrame();let{collapsed:c=!1,themeType:l=`system`}=this.options,u=c?void 0:s,d=this.renderRange,f=this.hasThemeChanged(),p=o!=null&&(o.length>0||this.lineAnnotations.length>0)?o!==this.lineAnnotations:!1,m=!k(this.file,e);if(!c&&!n&&b(u,this.renderRange)&&!m&&!p&&!f)return this.applyCachedThemeState(l);this.renderRange=u,m&&(this.cachedHeaderHTML=void 0),this.file=e,this.fileRenderer.setOptions(Z(this.options)),this.syncInteractionOptions(),o!=null&&this.setLineAnnotations(o),this.fileRenderer.setLineAnnotations(this.lineAnnotations);let{disableErrorHandling:h=!1,disableFileHeader:g=!1}=this.options;if(g&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),t=this.getOrCreateFileContainerNode(t,i),this.applyCachedThemeState(l),c){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{let n=this.fileRenderer.renderFile(e,z);n!=null&&this.applyThemeState(t,n.themeStyles,l,n.baseThemeType),n?.headerAST!=null&&this.applyHeaderToDOM(n.headerAST,t),this.injectUnsafeCSS()}catch(e){if(h)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,t)}return r||this.emitPostRender(),!0}try{let r=this.getOrCreatePreNode(t);if(!this.canPartiallyRender(n,p,m||f)||!this.applyPartialRender(d,u)){let n=this.fileRenderer.renderFile(e,u);if(n==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(t,n.themeStyles,l,n.baseThemeType),n.headerAST!=null&&this.applyHeaderToDOM(n.headerAST,t),this.applyFullRender(n,r)}this.applyBuffers(r,u),this.injectUnsafeCSS(),this.managersDirty=!0,a||this.flushManagers(),this.renderAnnotations(),this.renderGutterUtility(),this.editor!=null&&V(this.syncRenderView)}catch(e){if(h)throw e;console.error(e),e instanceof Error&&this.applyErrorToDOM(e,t)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){let{fileContainer:t,options:{onPostRender:n}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;n?.(t,this,`unmount`);return}if(t==null)return;let r=this.mounted?`update`:`mount`;this.mounted=!0,n?.(t,this,r)}removeRenderedCode(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.code?.remove(),this.code=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(let{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}canPartiallyRender(e,t,n){return!(e||t||n)}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){let e=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:`open`});this.placeHolder=document.createElement(`div`),this.placeHolder.dataset.placeholder=``,e.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty(`height`,`${e}px`),!0}primeHighlightCache(){let{file:e,workerManager:t}=this;e==null||e.cacheKey==null||t==null||Y(e)||this.fileRenderer.getOrCreateLineCache(e).length>(this.options.tokenizeMaxLength??1e5)||t.primeFileHighlightCache(e)}cleanChildNodes(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.code?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.gutterUtilityContent?.remove(),this.headerPrefix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.code=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.gutterUtilityContent=void 0,this.headerPrefix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.lastRenderedHeaderHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(let{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear();return}let e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(let[n,r]of this.lineAnnotations.entries()){let i=`${n}-${c(r)}`,a=this.annotationCache.get(i);if(a==null||!be(r,a.annotation)){a?.element.remove();let e=t(r);if(e==null)continue;a={element:re(c(r)),annotation:r},a.element.appendChild(e),this.fileContainer.appendChild(a.element),this.annotationCache.set(i,a)}e.delete(i)}for(let[t,{element:n}]of e.entries())this.annotationCache.delete(t),n.remove()}renderGutterUtility(){let{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}let n=se();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}injectUnsafeCSS(){let{unsafeCSS:e}=this.options,t=this.fileContainer?.shadowRoot;if(t!=null){if(e==null||e===``){this.unsafeCSSStyle!=null&&(this.unsafeCSSStyle.remove(),this.unsafeCSSStyle=void 0),this.appliedUnsafeCSS=void 0;return}this.unsafeCSSStyle?.parentNode===t&&this.appliedUnsafeCSS===e||(this.unsafeCSSStyle??=R(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=de(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){let i=e.shadowRoot??e.attachShadow({mode:`open`}),a=r??n,o=this.options.theme??F,s=typeof o==`string`?o:{...o},c=I(i);if(this.themeCSSStyle?.parentNode===i&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===a&&this.appliedThemeCSS.scrollbarGutter===c){this.appliedThemeCSS.theme=s;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===i){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:s,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:c};return}this.themeCSSStyle=ce({shadowRoot:i,currentNode:this.themeCSSStyle,themeCSS:ne(t,a,c)}),this.appliedThemeCSS=this.themeCSSStyle==null?void 0:{theme:s,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:c}}hydrateMeasuredScrollbar(){let e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=P(this.themeCSSStyle.textContent??``,I(e)))}applyFullRender(e,t){this.cleanupErrorWrapper(),this.applyPreNodeAttributes(t,e),this.code=le({code:this.code});let n=this.fileRenderer.renderCodeAST(e);if(this.code.childElementCount>=2)for(let e=0;e<2;e++){let t=this.code.children[e],r=n[e];t.innerHTML=_(r.children),t.style.cssText=r.properties.style}else this.code.innerHTML=_(n);t.contains(this.code)||t.replaceChildren(this.code),this.lastRowCount=e.rowCount}applyPartialRender(e,t){if(e==null||t==null)return!1;let{file:n,code:r}=this,i=r==null?void 0:this.getColumns(r);if(n==null||r==null||i==null)return!1;let a=e.startingLine,o=t.startingLine,s=e.totalLines===1/0?1/0:a+e.totalLines,c=t.totalLines===1/0?1/0:o+t.totalLines,l=Math.max(a,o),u=Math.min(s,c);if(u<=l||!this.trimDOMToOverlap(i.gutter,l,u)||!this.trimDOMToOverlap(i.content,l,u))return!1;let{length:d}=i.content.children,f=(e,t)=>{if(!(t<=0))return this.fileRenderer.renderFile(n,{startingLine:e,totalLines:t,bufferBefore:0,bufferAfter:0})},p=o<l?f(o,l-o):void 0;if(p===void 0&&o<l)return!1;let m=c===1/0?1/0:Math.max(0,c-u),h=c>u?f(u,m):void 0;return h===void 0&&c>u?!1:(this.cleanupErrorWrapper(),p!=null&&(i.gutter.insertAdjacentHTML(`afterbegin`,this.fileRenderer.renderPartialHTML(p.gutterAST)),i.content.insertAdjacentHTML(`afterbegin`,this.fileRenderer.renderPartialHTML(p.contentAST)),d+=p.rowCount),h!=null&&(i.gutter.insertAdjacentHTML(`beforeend`,this.fileRenderer.renderPartialHTML(h.gutterAST)),i.content.insertAdjacentHTML(`beforeend`,this.fileRenderer.renderPartialHTML(h.contentAST)),d+=h.rowCount),this.lastRowCount!==d&&(i.gutter.style.setProperty(`grid-row`,`span ${d}`),i.content.style.setProperty(`grid-row`,`span ${d}`),this.lastRowCount=d),!0)}getColumns(e){let t=e.children[0],n=e.children[1];if(!(!(t instanceof HTMLElement)||!(n instanceof HTMLElement)||t.dataset.gutter==null||n.dataset.content==null))return{gutter:t,content:n}}trimDOMToOverlap(e,t,n){let r=this.getDOMBoundaryIndices(e,[t,n]),i=r.get(t)??e.children.length,a=r.get(n)??e.children.length;if(i>a)return!1;for(let t=e.children.length-1;t>=a;--t)e.children[t]?.remove();for(let t=i-1;t>=0;--t)e.children[t]?.remove();return!0}getDOMBoundaryIndices(e,t){let n=[...new Set(t)].sort((e,t)=>e-t),r=new Map;if(n.length===0)return r;let i=0,a=n[i],{children:o}=e;a===0&&(r.set(0,0),i+=1,a=n[i]);for(let e=0;e<o.length;e+=1){let t=o[e];if(!(t instanceof HTMLElement))continue;let s=this.getLineIndexFromDOMNode(t);if(s!=null){for(;a!=null&&s>=a;)r.set(a,e),i+=1,a=n[i];if(i>=n.length)break}}for(let e of n)r.has(e)||r.set(e,o.length);return r}getLineIndexFromDOMNode(e){let t=e.dataset.lineIndex;if(t==null)return;let n=Number(t);return Number.isNaN(n)?void 0:n}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore??(this.bufferBefore=document.createElement(`div`),this.bufferBefore.dataset.virtualizerBuffer=`before`,e.before(this.bufferBefore)),this.bufferBefore.style.setProperty(`height`,`${t.bufferBefore}px`),this.bufferBefore.style.setProperty(`contain`,`strict`)):this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),t.bufferAfter>0?(this.bufferAfter??(this.bufferAfter=document.createElement(`div`),this.bufferAfter.dataset.virtualizerBuffer=`after`,e.after(this.bufferAfter)),this.bufferAfter.style.setProperty(`height`,`${t.bufferAfter}px`),this.bufferAfter.style.setProperty(`contain`,`strict`)):this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0)}shouldDisableVirtualizationBuffers(){return this.options.disableVirtualizationBuffers??!1}applyHeaderToDOM(e,t){let{file:n}=this;if(n==null)return;this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;let r=this.cachedHeaderHTML??_(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){let e=document.createElement(`div`);e.innerHTML=r;let n=e.firstElementChild;if(!(n instanceof HTMLElement))return;this.headerElement==null?t.shadowRoot?.prepend(n):t.shadowRoot?.replaceChild(n,this.headerElement),this.headerElement=n,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged)return;let{renderHeaderPrefix:i,renderCustomHeader:a,renderHeaderMetadata:o}=this.options;if(a!=null){let e=a(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,K,e),this.headerPrefix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerMetadata=void 0}else{let e=i?.(n)??void 0,r=o?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,fe,e),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,A,r),this.headerCustom?.remove(),this.headerCustom=void 0}}clearHeaderSlots(){this.headerPrefix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.headerPrefix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0}upsertHeaderSlotElement(e,t,n,r){if(r==null){t?.remove();return}let i=t??this.createHeaderSlotElement(n);return t??e.appendChild(i),this.replaceHeaderSlotContent(i,r),i}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){let t=document.createElement(`div`);return t.slot=e,t}getOrCreateFileContainerNode(e,t){let{fileContainer:n}=this,r=e??n??document.createElement(`diffs-container`),i=n!==r;return i&&this.emitPostRender(!0),this.fileContainer=r,n!=null&&i&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),i&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){let{shadowRoot:t}=e;if(t!=null)for(let e of t.children)e instanceof SVGElement?this.spriteSVG??=e:H(e)&&e.hasAttribute(`data-theme-css`)?(this.themeCSSStyle??=e,this.hasAdoptedThemeCSS=!0):H(e)&&e.hasAttribute(`data-unsafe-css`)&&(this.unsafeCSSStyle??=e,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){let t=e.shadowRoot??e.attachShadow({mode:`open`});if(this.spriteSVG==null){let e=document.createElement(`div`);e.innerHTML=B;let t=e.firstChild;t instanceof SVGElement&&(this.spriteSVG=t)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){let t=e.shadowRoot??e.attachShadow({mode:`open`});return this.pre==null?(this.pre=document.createElement(`pre`),this.appliedPreAttributes=void 0,this.code=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(e.shadowRoot?.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodeFromPre(e){this.code=void 0;for(let t of Array.from(e.children))if(t instanceof HTMLElement&&t.hasAttribute(`data-code`)){this.code=t;return}}applyPreNodeAttributes(e,{totalLines:t}){let{overflow:n=`scroll`,disableLineNumbers:r=!1}=this.options,i={type:`file`,split:!1,overflow:n,disableLineNumbers:r,diffIndicators:`none`,disableBackground:!0,totalLines:t};ee(i,this.appliedPreAttributes)||(M(e,i),this.appliedPreAttributes=i)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;let n=t.shadowRoot??t.attachShadow({mode:`open`});this.errorWrapper??=document.createElement(`div`),this.errorWrapper.dataset.errorWrapper=``,this.errorWrapper.textContent=``,n.appendChild(this.errorWrapper);let r=document.createElement(`div`);r.dataset.errorMessage=``,r.innerText=e.message,this.errorWrapper.appendChild(r);let i=document.createElement(`pre`);i.dataset.errorStack=``,i.innerText=e.stack??`No Error Stack`,this.errorWrapper.appendChild(i)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}};function Ce(e,t,n=!1){return!n&&e==null&&t!=null}function we(e,t,n=!1){return e==null&&t!=null&&!n}var Te=5e3,Ee=-1;function De(e,t){return(e.overflow??`scroll`)!==(t.overflow??`scroll`)||(e.collapsed??!1)!==(t.collapsed??!1)||(e.disableLineNumbers??!1)!==(t.disableLineNumbers??!1)||(e.disableFileHeader??!1)!==(t.disableFileHeader??!1)||e.unsafeCSS!==t.unsafeCSS}var Oe=class extends Q{__id=`virtualized-file:${++Ee}`;top;height=0;cache={heights:new Map,checkpoints:[],fileAnnotationHeight:0};isVisible=!1;isSetup=!1;layoutDirty=!0;forceRenderOverride;currentCollapsed;constructor(e,t,n=oe,r,i=!1){super(e,r,i),this.virtualizer=t,this.metrics=n}setMetrics(e,t=!1){!t&&ie(this.metrics,e)||(this.metrics=e,this.resetLayoutCache())}setLineAnnotations(e){this.syncLineAnnotations(e)&&this.resetLayoutCache()}syncLineAnnotations(e){return e==null||e===this.lineAnnotations||e.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(e),!0)}hasLineAnnotations(){return this.lineAnnotations.some(e=>e.lineNumber>0)}getLineHeight(e,t=!1){let n=this.cache.heights.get(e);if(n!=null)return n;let r=t?2:1;return this.metrics.lineHeight*r}setOptions(e){if(this.isAdvancedMode())throw Error(`VirtualizedFile.setOptions cannot be used inside CodeView. Update CodeView options instead.`);if(e==null)return;let{options:t}=this,n=!L(t,e),r=De(t,e);super.setOptions(e),r&&this.resetLayoutCache(!0),n&&(this.forceRenderOverride=!0),n&&this.virtualizer.instanceChanged(this,r)}setThemeType(e){if(this.isAdvancedMode())throw Error(`VirtualizedFile.setThemeType cannot be used inside CodeView. Update CodeView options instead.`);super.setThemeType(e)}resetLayoutCache(e=!1){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heights.size>0&&this.cache.heights.clear(),this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.renderRange!=null&&(this.renderRange=void 0),e&&this.isSimpleMode()&&this.computeApproximateSize()}reconcileHeights(){let e=!1;if(this.fileContainer==null||this.file==null)return this.height!==0&&(e=!0),this.height=0,e;let{overflow:t=`scroll`}=this.options;if(this.top=this.getVirtualizedTop(),t===`scroll`&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled()||this.code==null)return e;let n=this.code.children[1];if(!(n instanceof HTMLElement))return e;let r=w(this.lineAnnotations);if(this.renderRange!=null&&r&&s(this.renderRange)){let t=ke(n)??0;t!==this.cache.fileAnnotationHeight&&(this.cache.fileAnnotationHeight=t,e=!0)}else!r&&this.cache.fileAnnotationHeight!==0&&(this.cache.fileAnnotationHeight=0,e=!0);for(let t of n.children){if(!(t instanceof HTMLElement))continue;let n=t.dataset.lineIndex;if(n==null)continue;let r=Number(n),i=t.getBoundingClientRect().height,a=!1;t.nextElementSibling instanceof HTMLElement&&(`lineAnnotation`in t.nextElementSibling.dataset||`noNewline`in t.nextElementSibling.dataset)&&(`noNewline`in t.nextElementSibling.dataset&&(a=!0),i+=t.nextElementSibling.getBoundingClientRect().height);let o=this.getLineHeight(r,a);i!==o&&(e=!0,i===this.metrics.lineHeight*(a?2:1)?this.cache.heights.delete(r):this.cache.heights.set(r,i))}return(e||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),e}onRender=e=>this.fileContainer==null||this.file==null?!1:(e&&(this.top=this.getVirtualizedTop()),this.render({file:this.file}));prepareCodeViewItem(e,t,n,r){let i=this.syncLineAnnotations(r),a=n?.resetFileLayoutCache===!0||i;n?.metrics!=null&&(this.metrics=n.metrics,a=!0);let{collapsed:o=!1}=this.options;return this.currentCollapsed!==o&&(this.currentCollapsed=o,a=!0),a&&this.resetLayoutCache(),this.file!==e&&(this.layoutDirty=!0),this.file=e,this.top=t,this.computeApproximateSize(),this.height}getLinePosition(e){if(this.file==null||e<1)return;let{disableFileHeader:t=!1,collapsed:n=!1}=this.options,r=this.fileRenderer.getLineCount(this.file)-1,i=J(this.metrics,t);if(n||r<0)return{top:i,height:0};let a=Math.min(Math.max(e-1,0),r),{overflow:o=`scroll`}=this.options,{lineHeight:s}=this.metrics;if(i+=this.cache.fileAnnotationHeight,o===`scroll`&&!this.hasLineAnnotations())return{top:i+a*s,height:s};let c=this.getLayoutCheckpointBeforeLineIndex(a);i=c?.top??i;for(let e=c?.lineIndex??0;e<a;e++)i+=this.getLineHeight(e,!1);return{top:i,height:this.getLineHeight(a,!1)}}getNumericScrollAnchor(e){if(this.file==null||this.renderRange==null)return;let{disableFileHeader:t=!1,collapsed:n=!1,overflow:r=`scroll`}=this.options;if(n||this.renderRange.totalLines<=0)return;let i=this.fileRenderer.getLineCount(this.file)-1;if(i<0)return;let a=J(this.metrics,t),o=Math.min(this.renderRange.startingLine,i),s=Math.min(o+this.renderRange.totalLines-1,i);if(s<o)return;let{fileAnnotationHeight:c}=this.cache;if(r===`scroll`&&!this.hasLineAnnotations()){let{lineHeight:t}=this.metrics,n=a+(o===0?c:this.renderRange.bufferBefore),r=o+Math.max(Math.ceil((e-n)/t),0);return r>s?void 0:{lineNumber:r+1,top:a+c+r*t}}let l=a+(o===0?c:this.renderRange.bufferBefore);for(let t=o;t<=s;t++){if(l>=e)return{lineNumber:t+1,top:l};l+=this.getLineHeight(t)}}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(e){if(this.top==null||this.file==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};let t=e==null?this.renderRange:this.computeRenderRangeFromWindow(this.file,this.top,e);if(t==null)return;let{bufferBefore:n,bufferAfter:r,totalLines:i}=t,a=0;if(i===0){let t=e??this.virtualizer.getWindowSpecs();this.top<t.top&&(a=r)}return{topOffset:this.top+n+a,height:this.height-(n+r)}}cleanUp(e=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),e||this.resetLayoutCache(),this.isSetup=!1,super.cleanUp(e)}computeApproximateSize(e=!1){let t=this.isResizeDebuggingEnabled();if(!e&&!this.layoutDirty&&!t)return;let n=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.file==null){this.layoutDirty=!1;return}let{disableFileHeader:r=!1,collapsed:i=!1,overflow:a=`scroll`}=this.options,{lineHeight:o}=this.metrics,s=this.fileRenderer.getLineCount(this.file),c=J(this.metrics,r),l=G(this.metrics);if(this.height+=c,i){this.layoutDirty=!1;return}if(this.height+=this.cache.fileAnnotationHeight,a===`scroll`&&!this.hasLineAnnotations())this.height+=s*o;else for(let e=0;e<s;e++)this.addLayoutCheckpoint(e,this.height),this.height+=this.getLineHeight(e,!1);if(s>0&&(this.height+=l),this.fileContainer!=null&&t&&!n){let e=this.fileContainer.getBoundingClientRect();e.height===this.height?console.log(`VirtualizedFile.computeApproximateSize: computed height IS CORRECT`):console.log(`VirtualizedFile.computeApproximateSize: computed height doesnt match`,{name:this.file.name,elementHeight:e.height,computedHeight:this.height})}this.layoutDirty=!1}setVisibility(e){this.isAdvancedMode()||this.fileContainer==null||(e&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!e&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.file==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(e,t,n=!1){let{heights:r,checkpoints:i}=this.cache,a=this.renderRange;if(super.applyDocumentChange(e,t),this.getSimpleVirtualizer()?.markDOMDirty(),this.layoutDirty=!0,r.size>0&&r.clear(),i.length>0&&(i.length=0),this.isSimpleMode()&&this.computeApproximateSize(),n&&a!==void 0&&this.file!==void 0){let e=this.virtualizer.getWindowSpecs(),t=this.computeRenderRangeFromWindow(this.file,this.top??0,e);t.bufferAfter!==a.bufferAfter&&this.updateBuffers(t)}}render({fileContainer:e,file:t,forceRender:n=!1,lineAnnotations:r,...i}){let a=this.file==null||!k(this.file,t),{forceRenderOverride:o,isSetup:s}=this;this.forceRenderOverride=void 0;let c=this.syncLineAnnotations(r);if(c&&this.resetLayoutCache(),this.file=t,e=this.getOrCreateFileContainerNode(e),this.file==null)return console.error(`VirtualizedFile.render: attempting to virtually render when we dont have file`),!1;if(s)this.top??=this.getVirtualizedTop(),a&&this.isSimpleMode()&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(!0));else{this.computeApproximateSize();let t=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(t==null)throw Error(`VirtualizedFile.render: simple virtualizer is not available`);t.connect(e,this),this.isVisible=t.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode())return this.renderPlaceholder(this.height);let l=this.virtualizer.getWindowSpecs(),u=this.top??0,d=this.computeRenderRangeFromWindow(this.file,u,l);return super.render({file:this.file,fileContainer:e,renderRange:d,lineAnnotations:r,forceRender:(o??n)||c,...i})}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}isSimpleMode(){return this.virtualizer.type===`simple`}isAdvancedMode(){return this.virtualizer.type===`advanced`}addLayoutCheckpoint(e,t){e%Te===0&&this.cache.checkpoints.push({lineIndex:e,top:t})}getLayoutCheckpointBeforeLineIndex(e){if(e<=0||this.cache.checkpoints.length===0)return;let t=0,n=this.cache.checkpoints.length-1,r;for(;t<=n;){let i=t+n>>1,a=this.cache.checkpoints[i];if(a==null)throw Error(`VirtualizedFile: invalid checkpoint index`);a.lineIndex<=e?(r=a,t=i+1):n=i-1}return r}getLayoutCheckpointBeforeTop(e,t){let n=0,r=this.cache.checkpoints.length-1,i=-1;for(;n<=r;){let t=n+r>>1,a=this.cache.checkpoints[t];if(a==null)throw Error(`VirtualizedFile: invalid checkpoint index`);a.top<=e?(i=t,n=t+1):r=t-1}if(t==null)return i>=0?this.cache.checkpoints[i]:void 0;for(let e=i;e>=0;e--){let n=this.cache.checkpoints[e];if(n==null)throw Error(`VirtualizedFile: invalid checkpoint index`);if(n.lineIndex%t===0)return n}}getVirtualizedTop(){return this.virtualizer.type===`advanced`?this.virtualizer.getLocalTopForInstance(this):this.fileContainer==null?0:this.virtualizer.getOffsetInScrollContainer(this.fileContainer)}getSimpleVirtualizer(){return this.virtualizer.type===`simple`?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}computeRenderRangeFromWindow(e,t,{top:n,bottom:r}){let{disableFileHeader:i=!1,overflow:a=`scroll`}=this.options,{hunkLineCount:o,lineHeight:s}=this.metrics,c=this.fileRenderer.getLineCount(e),l=this.height,u=J(this.metrics,i),d=c>0?G(this.metrics):0,{fileAnnotationHeight:f}=this.cache,p=u+f,m=Math.max(0,l-u-f-d),h=w(this.lineAnnotations),g=t+u,_=f>0&&h&&g<r&&g+f>n;if(t<n-l||t>r)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-u-d};if(c<=o)return{startingLine:0,totalLines:o,bufferBefore:0,bufferAfter:0};let v=Math.ceil(Math.max(r-n,0)/s),y=Math.ceil(v/o)*o+o*2,b=y/o,x=(n+r)/2;if(a===`scroll`&&!this.hasLineAnnotations()){let e=t+p,i=e+m;if(!_&&!(e<r&&i>n))return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-u-d};let a=Math.floor(_&&x<t+p?0:(x-(t+p))/s),h=Math.floor(a/o)-Math.floor(b/2),g=Math.ceil(c/o),v=Math.max(0,Math.min(h,g))*o,S=h<0?y+h*o:y,C=v===0?0:f+v*s,w=Math.min(S,c-v);return{startingLine:v,totalLines:S,bufferBefore:C,bufferAfter:Math.max(0,(c-v-w)*s)}}let S=b,C=[],T=this.getLayoutCheckpointBeforeTop(Math.max(0,n-t-y*s*2),o),E=t+(T?.top??p),D=T?.lineIndex??0,O,k,A,j=T?.lineIndex??0;for(let e=j;e<c;e++){let i=D%o===0,a=Math.floor(D/o);if(i&&(C[a]=E-(t+p),A!=null)){if(A<=0)break;A--}let s=this.getLineHeight(e,!1);E>n-s&&E<r&&(O??=a),E+s>x&&(k??=a),A==null&&E>=r&&i&&(A=S),D++,E+=s}if(O==null)if(_)O=0,k=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-u-d};k??=O;let M=Math.round(k-b/2),N=Math.max(0,Math.ceil(c/o)-b),P=Math.max(0,Math.min(M,N)),F=P*o,I=M<0?y+M*o:y,L=C[P]??0,R=F===0?0:f+L,z=P+I/o,B=z<C.length?m-C[z]:m-(E-t-p);return{startingLine:F,totalLines:I,bufferBefore:R,bufferAfter:Math.max(0,B)}}};function ke(e){let t;for(let n of e.children)n instanceof HTMLElement&&n.dataset.lineAnnotation===N&&(t=Math.max(t??0,n.getBoundingClientRect().height));return t}var $=t();function Ae({file:e,renderCustomHeader:t,renderHeaderPrefix:n,renderHeaderMetadata:r,renderAnnotation:i,lineAnnotations:a,renderGutterUtility:o,getHoveredLine:s}){let u=t?.(e),d=n?.(e),f=r?.(e);return(0,$.jsxs)($.Fragment,{children:[u==null?(0,$.jsxs)($.Fragment,{children:[d!=null&&(0,$.jsx)(`div`,{slot:`header-prefix`,children:d}),f!=null&&(0,$.jsx)(`div`,{slot:`header-metadata`,children:f})]}):(0,$.jsx)(`div`,{slot:K,children:u}),i!=null&&a?.map((e,t)=>(0,$.jsx)(`div`,{slot:c(e),children:i(e)},t)),o!=null&&(0,$.jsx)(`div`,{slot:`gutter-utility-slot`,style:l,children:o(s)})]})}var je=r(),Me=e(n(),1);function Ne(e){let t=(0,je.c)(44),{kind:n,rangeLabel:r,text:o,onCancel:s,onComment:c,onDelete:l}=e,[u,f]=(0,Me.useState)(``);if(n===`comment`){let e,n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(d,{className:`size-4 text-muted-foreground`}),n=(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:`Local comment`}),t[0]=e,t[1]=n):(e=t[0],n=t[1]);let a;t[2]===r?a=t[3]:(a=(0,$.jsx)(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,children:r}),t[2]=r,t[3]=a);let s;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(pe,{className:`size-3.5`}),t[4]=s):s=t[4];let c;t[5]===l?c=t[6]:(c=(0,$.jsx)(i,{variant:`ghost`,size:`icon-xs`,"aria-label":`Delete comment`,onClick:l,children:s}),t[5]=l,t[6]=c);let u;t[7]!==a||t[8]!==c?(u=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e,n,a,c]}),t[7]=a,t[8]=c,t[9]=u):u=t[9];let f;t[10]===o?f=t[11]:(f=(0,$.jsx)(`p`,{className:`mt-2 whitespace-pre-wrap text-sm leading-relaxed text-foreground`,children:o}),t[10]=o,t[11]=f);let p;return t[12]!==u||t[13]!==f?(p=(0,$.jsxs)(`div`,{"data-file-comment-annotation":!0,className:`mx-3 my-2 rounded-xl border border-border/70 bg-background p-3 shadow-sm`,contentEditable:!1,onPointerDown:Fe,children:[u,f]}),t[12]=u,t[13]=f,t[14]=p):p=t[14],p}let p;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(d,{className:`size-4 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`text-sm font-medium`,children:`Local comment`})]}),t[15]=p):p=t[15];let m;t[16]===r?m=t[17]:(m=(0,$.jsxs)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:[`Comment on lines `,r]}),t[16]=r,t[17]=m);let h=`Comment on lines ${r}`,g;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(g=e=>f(e.target.value),t[18]=g):g=t[18];let _;t[19]!==s||t[20]!==c||t[21]!==u?(_=e=>{e.key===`Escape`&&(e.preventDefault(),s()),(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&u.trim()&&(e.preventDefault(),c(u.trim()))},t[19]=s,t[20]=c,t[21]=u,t[22]=_):_=t[22];let v;t[23]!==h||t[24]!==_||t[25]!==u?(v=(0,$.jsx)(a,{autoFocus:!0,className:`mt-3`,size:`sm`,value:u,placeholder:`Request change`,"aria-label":h,onChange:g,onKeyDown:_}),t[23]=h,t[24]=_,t[25]=u,t[26]=v):v=t[26];let y;t[27]===s?y=t[28]:(y=(0,$.jsx)(i,{variant:`ghost`,size:`sm`,onClick:s,children:`Cancel`}),t[27]=s,t[28]=y);let b;t[29]===u?b=t[30]:(b=u.trim(),t[29]=u,t[30]=b);let x=!b,S;t[31]!==c||t[32]!==u?(S=()=>c(u.trim()),t[31]=c,t[32]=u,t[33]=S):S=t[33];let C;t[34]!==S||t[35]!==x?(C=(0,$.jsx)(i,{size:`sm`,disabled:x,onClick:S,children:`Comment`}),t[34]=S,t[35]=x,t[36]=C):C=t[36];let w;t[37]!==C||t[38]!==y?(w=(0,$.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[y,C]}),t[37]=C,t[38]=y,t[39]=w):w=t[39];let T;return t[40]!==w||t[41]!==m||t[42]!==v?(T=(0,$.jsxs)(`div`,{"data-file-comment-annotation":!0,className:`mx-3 my-2 rounded-xl border border-border/70 bg-background p-3 shadow-lg`,contentEditable:!1,onPointerDown:Pe,children:[p,m,v,w]}),t[40]=w,t[41]=m,t[42]=v,t[43]=T):T=t[43],T}function Pe(e){return e.stopPropagation()}function Fe(e){return e.stopPropagation()}var Ie=0;function Le(){return Ie+=1,`file-comment-${Date.now()}-${Ie}`}function Re(e){return{startLine:Math.min(e.start,e.end),endLine:Math.max(e.start,e.end)}}function ze(e,t){return e===t?`L${e}`:`L${e} to L${t}`}function Be(e){return e.map(e=>({...e,metadata:{entries:e.metadata.entries.map(t=>{let n=t.endLine-t.startLine;return{...t,endLine:e.lineNumber,startLine:Math.max(1,e.lineNumber-n)}})}}))}export{Ne as a,Q as c,Be as i,Le as n,Ae as o,Re as r,Oe as s,ze as t};
2
+ //# sourceMappingURL=fileCommentAnnotations-qrdl_QDz.js.map