@fabiofiorita/porcelain 0.71.0 → 0.71.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/web/dist/assets/_-Cgj9Amlg.js +1 -0
- package/web/dist/assets/_layerId-WtWgdySc.js +1 -0
- package/web/dist/assets/_paired-BhXDazsm.js +1 -0
- package/web/dist/assets/_paired-C2SpPGqV.js +1 -0
- package/web/dist/assets/{_paired-D4B6U2tK.js → _paired-CQqaert8.js} +1 -1
- package/web/dist/assets/{_paired-B5NlVJC_.js → _paired-jHMYqNRe.js} +1 -1
- package/web/dist/assets/_reviewId-DYfy6yXm.js +1 -0
- package/web/dist/assets/_revision-Cl64oJuE.js +1 -0
- package/web/dist/assets/_section-BZ9yGLgf.js +1 -0
- package/web/dist/assets/_worktreeId-9KlGkDDm.js +1 -0
- package/web/dist/assets/_worktreeId-BhXDazsm.js +1 -0
- package/web/dist/assets/_worktreeId-C2SpPGqV.js +1 -0
- package/web/dist/assets/{_worktreeId-CO2pdZDS.js → _worktreeId-CDTAw3Hd.js} +1 -1
- package/web/dist/assets/access-Cf1mwFvV.js +1 -0
- package/web/dist/assets/{connected-workspace-Ct9I-K0k.js → connected-workspace-C1KgZzkv.js} +1 -1
- package/web/dist/assets/{desktop-actions-9fnMnk0K.js → desktop-actions-3aiwi-wY.js} +1 -1
- package/web/dist/assets/{file-editor-BRZ1wGrJ.js → file-editor-CpwgQA6Z.js} +2 -2
- package/web/dist/assets/{files-CbiIDuCN.js → files-D4CzkVZ-.js} +1 -1
- package/web/dist/assets/index-4fobVNe9.js +10 -0
- package/web/dist/assets/index-rsNq4als.css +2 -0
- package/web/dist/assets/lazyRouteComponent-B-XUbSrq.js +1 -0
- package/web/dist/assets/link-DkgNzeiC.js +1 -0
- package/web/dist/assets/pair-BhXDazsm.js +1 -0
- package/web/dist/assets/pair-GnPjxKlt.js +1 -0
- package/web/dist/assets/{review-route-BmOqxMxv.js → review-route-pjHfjF9J.js} +1 -1
- package/web/dist/assets/reviews-CCry97BC.js +1382 -0
- package/web/dist/assets/root-DLTE-HSj.js +1 -0
- package/web/dist/assets/{store-B70lwceg.js → store-C-FZWhob.js} +29 -29
- package/web/dist/assets/useRouterState-3SkCgP-l.js +1 -0
- package/web/dist/assets/{workspace-error-DxSI59T-.js → workspace-error-D6f2voC4.js} +1 -1
- package/web/dist/assets/{workspace-pending-BD49-liX.js → workspace-pending-eUi5r6LE.js} +1 -1
- package/web/dist/index.html +10 -10
- package/web/dist/assets/_-B7WKStG_.js +0 -1
- package/web/dist/assets/_layerId-Cpzkbx-o.js +0 -1
- package/web/dist/assets/_paired-DIrKwyOd.js +0 -1
- package/web/dist/assets/_paired-dOYqBIXq.js +0 -1
- package/web/dist/assets/_reviewId-CcQvm0cu.js +0 -1
- package/web/dist/assets/_revision-BFFo1iEH.js +0 -1
- package/web/dist/assets/_section-B-luVh6R.js +0 -1
- package/web/dist/assets/_worktreeId-BKxKSVKs.js +0 -1
- package/web/dist/assets/_worktreeId-DIrKwyOd.js +0 -1
- package/web/dist/assets/_worktreeId-dOYqBIXq.js +0 -1
- package/web/dist/assets/access-P0rZuFJT.js +0 -1
- package/web/dist/assets/index-BXo5ZqVf.css +0 -2
- package/web/dist/assets/index-YZrLUmqQ.js +0 -10
- package/web/dist/assets/lazyRouteComponent-HdZJNYM2.js +0 -1
- package/web/dist/assets/link-D9sCFypD.js +0 -1
- package/web/dist/assets/pair-dOYqBIXq.js +0 -1
- package/web/dist/assets/pair-xkkjkm9Y.js +0 -1
- package/web/dist/assets/reviews-CQOio1Aq.js +0 -1382
- package/web/dist/assets/useMatch-N1ge3lF_.js +0 -1
- package/web/dist/assets/useRouterState-DuzGu1Qw.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Di as t,Mi as n,Ni as r,in as i,nn as a}from"./files-D4CzkVZ-.js";import{Dt as o,c as s,i as c,o as l,s as u,u as ee,wt as te}from"./access-Cf1mwFvV.js";import{i as ne,t as re}from"./link-DkgNzeiC.js";import{A as ie,C as d,D as f,E as p,I as m,M as ae,N as oe,O as h,T as g,b as se,c as ce,f as le,g as ue,i as de,k as fe,l as pe,o as me,t as he,v as ge,w as _,y as v}from"./reviews-CCry97BC.js";import{_ as y,ar as b,g as _e,ir as ve,tr as ye}from"./store-C-FZWhob.js";import{n as be,r as xe}from"./desktop-actions-3aiwi-wY.js";var Se=e(r(),1),x=t(),S=n();function C({className:e,...t}){return(0,S.jsx)(`kbd`,{"data-slot":`kbd`,className:i(`pointer-events-none inline-flex h-5 w-fit min-w-5 items-center justify-center gap-1 rounded-lg bg-muted px-1 font-sans text-xs font-medium text-muted-foreground select-none in-data-[slot=input-group]:bg-input in-data-[slot=tooltip-content]:bg-background/20 in-data-[slot=tooltip-content]:text-background dark:in-data-[slot=tooltip-content]:bg-background/10 [&_svg:not([class*='size-'])]:size-3`,e),...t})}function Ce({className:e,...t}){return(0,S.jsx)(`kbd`,{"data-slot":`kbd-group`,className:i(`inline-flex items-center gap-1`,e),...t})}function w(e){let t=(0,x.c)(7),{icon:n,tone:r}=e,a=(r===void 0?`default`:r)===`destructive`?`bg-destructive/10 text-destructive`:`bg-muted text-foreground`,o;t[0]===a?o=t[1]:(o=i(`grid size-10 shrink-0 place-items-center rounded-xl`,a),t[0]=a,t[1]=o);let s;t[2]===n?s=t[3]:(s=(0,S.jsx)(n,{className:`size-5`}),t[2]=n,t[3]=s);let c;return t[4]!==o||t[5]!==s?(c=(0,S.jsx)(`span`,{"aria-hidden":`true`,className:o,children:s}),t[4]=o,t[5]=s,t[6]=c):c=t[6],c}function T(e){let t=(0,x.c)(4),{keys:n}=e,r;t[0]===n?r=t[1]:(r=n.split(`+`).map(E),t[0]=n,t[1]=r);let i;return t[2]===r?i=t[3]:(i=(0,S.jsx)(Ce,{children:r}),t[2]=r,t[3]=i),i}function E(e){return(0,S.jsx)(C,{className:`min-w-6 justify-center`,children:ve(e)},e)}function we(e){let t=(0,x.c)(6),{open:n,onOpenChange:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,S.jsx)(w,{icon:m}),t[0]=i):i=t[0];let a;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,S.jsxs)(f,{className:`flex-row items-center text-left`,children:[i,(0,S.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,S.jsx)(h,{children:`Keyboard shortcuts`}),(0,S.jsx)(p,{children:`None of them fire while you are typing.`})]})]}),t[1]=a):a=t[1];let o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,S.jsxs)(g,{className:`max-h-[85svh] grid-rows-[auto_minmax(0,1fr)] overflow-hidden sm:max-w-xl`,children:[a,(0,S.jsx)(d,{className:`-mr-3 min-h-0`,children:(0,S.jsx)(`div`,{className:`flex flex-col gap-5 pr-3`,children:y.map(D)})})]}),t[2]=o):o=t[2];let s;return t[3]!==r||t[4]!==n?(s=(0,S.jsx)(_,{open:n,onOpenChange:r,children:o}),t[3]=r,t[4]=n,t[5]=s):s=t[5],s}function D(e){return(0,S.jsxs)(`section`,{"aria-labelledby":`shortcuts-${e.title}`,children:[(0,S.jsx)(`h3`,{id:`shortcuts-${e.title}`,className:`mb-1 text-xs font-medium tracking-wide text-muted-foreground uppercase`,children:e.title}),(0,S.jsx)(`dl`,{className:`divide-y rounded-xl border`,children:e.items.map(O)})]},e.title)}function O(e){return(0,S.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-3 py-2`,children:[(0,S.jsx)(`dt`,{className:`text-sm`,children:e.label}),(0,S.jsx)(`dd`,{className:`shrink-0`,children:(0,S.jsx)(T,{keys:e.keys})})]},e.keys)}var Te={"not-found":{title:`Page not found`,description:`This URL does not open a page in Porcelain.`},"missing-worktree":{title:`Worktree not found`,description:`This URL has an invalid or unavailable worktree ID.`},empty:{title:`Select a worktree`,description:`Choose a worktree to establish your review context.`}};function k(e){let t=(0,x.c)(74),{review:n,remote:r,unavailable:d,notice:f,children:p}=e,m=pe(),h=Te[f??`empty`],[g,_]=(0,Se.useState)(!1),{setOpenMobile:v,isMobile:y,open:b,openMobile:ve}=se(),C=ne(),Ce=te(),w=fe(Ce.connection),T;t[0]===w?T=t[1]:(T=oe(w,ae(w)?.id),t[0]=w,t[1]=T);let E=T;o();let D=te(r?.connection),O=r?.remote.environmentId??null,k;t[2]!==n||t[3]!==O?(k=n&&{remote:O,projectId:n.selection.projectId,worktreeId:n.selection.worktree.id},t[2]=n,t[3]=O,t[4]=k):k=t[4];let A=k,j;t[5]!==r||t[6]!==n?(j=n?de({entry:n.search.entry,surface:n.search.surface,project:n.inventory.projects.find(e=>e.id===n.selection.projectId)?.name,environment:r||n.inventory.environment.custom?n.inventory.environment.name:void 0}):`Porcelain`,t[5]=r,t[6]=n,t[7]=j):j=t[7],ce(j);let M;t[8]!==C||t[9]!==n?(M=e=>C({...xe(e),replace:n===void 0}),t[8]=C,t[9]=n,t[10]=M):M=t[10];let N=M,De=be(Ce.connection,N),P;t[11]!==C||t[12]!==v?(P=e=>{let t=e===void 0?me:e;v(!1),C({to:`/settings/$section`,params:{section:t}})},t[11]=C,t[12]=v,t[13]=P):P=t[13];let F=P,I;t[14]===De?I=t[15]:(I=e=>e?ie.openWithPayload({remote:e.remote.environmentId}):De(),t[14]=De,t[15]=I);let L;t[16]===F?L=t[17]:(L=()=>F(),t[16]=F,t[17]=L);let R;t[18]!==C||t[19]!==v?(R=e=>{v(!1),C({to:`/settings/$section/$environmentId`,params:{section:`remotes`,environmentId:e}})},t[18]=C,t[19]=v,t[20]=R):R=t[20];let z;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(z=()=>_(!0),t[21]=z):z=t[21];let B;t[22]!==w||t[23]!==A||t[24]!==void 0||t[25]!==I||t[26]!==L||t[27]!==R?(B={inventory:w,remotes:void 0,selected:A,onOpenProject:I,onOpenSettings:L,onOpenRemotes:R,onOpenShortcuts:z},t[22]=w,t[23]=A,t[24]=void 0,t[25]=I,t[26]=L,t[27]=R,t[28]=B):B=t[28];let V=B,H;t[29]!==C||t[30]!==A?(H=(e,t)=>{A&&C({...xe(A),search:t=>({...t,...e}),...t})},t[29]=C,t[30]=A,t[31]=H):H=t[31];let Oe=H,U;t[32]===F?U=t[33]:(U=()=>F(),t[32]=F,t[33]=U);let W;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(W={ignoreInputs:!0},t[34]=W):W=t[34],ye(_e.openSettings,U,W);let G,K;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(G=()=>_(!0),K={ignoreInputs:!0},t[35]=G,t[36]=K):(G=t[35],K=t[36]),ye(_e.openShortcuts,G,K);let q;t[37]!==y||t[38]!==V||t[39]!==N||t[40]!==v?(q=y&&(0,S.jsx)(ge,{variant:`floating`,children:(0,S.jsx)(ue,{...V,onSelect:e=>{N(e),v(!1)}})}),t[37]=y,t[38]=V,t[39]=N,t[40]=v,t[41]=q):q=t[41];let J;t[42]===N?J=t[43]:(J=e=>void N(e),t[42]=N,t[43]=J);let Y;t[44]!==V||t[45]!==J?(Y={...V,onSelect:J},t[44]=V,t[45]=J,t[46]=Y):Y=t[46];let X;t[47]!==p||t[48]!==D||t[49]!==y||t[50]!==h||t[51]!==m||t[52]!==V||t[53]!==f||t[54]!==Oe||t[55]!==b||t[56]!==ve||t[57]!==E||t[58]!==r||t[59]!==n||t[60]!==O||t[61]!==d?(X=p??(n?(0,S.jsx)(he,{navigationTrigger:m,worktree:n.selection.worktree,projectId:n.selection.projectId,search:n.search,onSearch:Oe,context:D},`${O??``}:${n.selection.worktree.id}`):(0,S.jsx)(Ee,{navigationTrigger:m,isMobile:y,open:b,openMobile:ve,children:r&&d?(0,S.jsx)(c,{name:r.remote.name,status:d,onOpenRemotes:()=>V.onOpenRemotes(r.remote.environmentId)}):(0,S.jsxs)(l,{children:[(0,S.jsxs)(s,{children:[(0,S.jsx)(ee,{children:(0,S.jsx)(`h1`,{children:h.title})}),(0,S.jsx)(u,{children:h.description})]}),f===`missing-worktree`&&E&&(0,S.jsx)(re,{className:i(a()),to:`/$projectId/$worktreeId`,params:{projectId:E.projectId,worktreeId:E.worktree.id},children:`Open available worktree`}),f&&(0,S.jsx)(re,{className:i(a({variant:`outline`})),to:`/`,search:{},children:`Back to workspace`})]})})),t[47]=p,t[48]=D,t[49]=y,t[50]=h,t[51]=m,t[52]=V,t[53]=f,t[54]=Oe,t[55]=b,t[56]=ve,t[57]=E,t[58]=r,t[59]=n,t[60]=O,t[61]=d,t[62]=X):X=t[62];let Z;t[63]!==y||t[64]!==b||t[65]!==Y||t[66]!==X?(Z=(0,S.jsx)(le,{navigator:Y,isMobile:y,open:b,children:X}),t[63]=y,t[64]=b,t[65]=Y,t[66]=X,t[67]=Z):Z=t[67];let Q;t[68]===g?Q=t[69]:(Q=(0,S.jsx)(we,{open:g,onOpenChange:_}),t[68]=g,t[69]=Q);let $;return t[70]!==q||t[71]!==Z||t[72]!==Q?($=(0,S.jsxs)(S.Fragment,{children:[q,Z,Q]}),t[70]=q,t[71]=Z,t[72]=Q,t[73]=$):$=t[73],$}function Ee(e){let t=(0,x.c)(8),{navigationTrigger:n,isMobile:r,open:i,openMobile:a,children:o}=e,s;t[0]===n?s=t[1]:(s=e=>n.attach(e),t[0]=n,t[1]=s);let c=r?a:i,l;t[2]!==s||t[3]!==c?(l=(0,S.jsx)(v,{ref:s,className:`absolute top-3 left-3`,"aria-label":`Toggle Sidebar`,"aria-expanded":c,"aria-keyshortcuts":b()===`mac`?`Meta+B`:`Control+B`,title:`Toggle projects (${_e.toggleNavigator})`}),t[2]=s,t[3]=c,t[4]=l):l=t[4];let u;return t[5]!==o||t[6]!==l?(u=(0,S.jsxs)(`div`,{className:`relative grid h-full min-h-0 place-items-center rounded-xl border bg-card p-8`,children:[l,o]}),t[5]=o,t[6]=l,t[7]=u):u=t[7],u}export{k as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as e,
|
|
1
|
+
import{A as e,Di as t,Mi as n,bi as r}from"./files-D4CzkVZ-.js";import{Dt as i,xn as a}from"./access-Cf1mwFvV.js";import{i as o,n as s}from"./link-DkgNzeiC.js";import{A as c,S as l,j as u,o as d}from"./reviews-CCry97BC.js";import{Xn as f}from"./store-C-FZWhob.js";var p=t(),m=n();function h(e){let t={projectId:e.projectId,worktreeId:e.worktreeId};return e.remote===null?s({to:`/$projectId/$worktreeId`,params:t}):s({to:`/remotes/$environmentId/$projectId/$worktreeId`,params:{environmentId:e.remote,...t}})}function g(e,t){let n=(0,p.c)(2),r=u(e,t,_),i;return n[0]===r?i=n[1]:(i=()=>r?r():c.openWithPayload({remote:null}),n[0]=r,n[1]=i),i}function _(e){return f.add({title:`Could not open the project`,description:a(e),type:`error`})}function v(t){let n=(0,p.c)(10),{connection:a,empty:s}=t,c=o(),u=i(),f;n[0]!==s||n[1]!==c?(f=e=>c({...h(e),replace:s}),n[0]=s,n[1]=c,n[2]=f):f=n[2];let _=f,v=g(a,_),y;n[3]!==c||n[4]!==v?(y=e(e=>{e===`open-settings`?c({to:`/settings/$section`,params:{section:d}}):v()}),n[3]=c,n[4]=v,n[5]=y):y=n[5],r(y);let b;return n[6]!==a||n[7]!==_||n[8]!==u?(b=(0,m.jsx)(l,{connection:a,remotes:u,onOpened:_}),n[6]=a,n[7]=_,n[8]=u,n[9]=b):b=n[9],b}export{g as n,h as r,v as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$t as t,Ei as n,Mi as r,ji as i,nl as a,tn as o,wi as s}from"./files-CbiIDuCN.js";import{A as c,Bn as l,F as u,G as d,Gn as f,Hn as p,Ht as m,I as h,Jn as g,Kn as _,O as v,Rn as y,St as b,Tn as x,Tt as S,Un as C,Ut as w,Vn as T,W as E,Wn as D,Xn as ee,cn as O,ft as k,g as A,i as te,j,mn as M,qn as N,qt as P,s as F,sn as I,t as ne,tr as re,u as ie,v as ae,xt as oe,y as se,yt as ce}from"./store-B70lwceg.js";var le={compositeOverBg:l,contrastRatio:T,deriveMutedFg:p,hoverWouldEraseText:C,isDarkSurface:D,isFullyTransparent:f,pickReadableForeground:_,relativeLuminance:N,surfacesMatch:g};function ue(e,t){return e==null||t==null?e===t:e.top===t.top&&e.bottom===t.bottom}var de=1e3,fe=de*4,pe=[0,1e-6,.99999,1],me={overscrollSize:de,intersectionObserverMargin:fe,resizeDebugging:!1},he=0,ge=-1,_e=class e{static __STOP=!1;static __lastScrollPosition=0;__id=`virtualizer-${++ge}`;config;type=`simple`;intersectionObserver;scrollTop=0;height=0;scrollHeight=0;windowSpecs={top:0,bottom:0};root;contentContainer;resizeObserver;observers=new Map;visibleInstances=new Map;visibleInstancesDirty=!1;instancesChanged=new Set;reconcileQueue=new Set;scrollDirty=!0;heightDirty=!0;scrollHeightDirty=!0;renderedObservers=0;connectQueue=new Map;constructor(e){this.config={...me,...e}}setup(t,n){if(this.root==null){this.root=t,this.resizeObserver=new ResizeObserver(this.handleContainerResize),this.intersectionObserver=new IntersectionObserver(this.handleIntersectionChange,{root:this.root,threshold:pe,rootMargin:`${this.config.intersectionObserverMargin}px 0px ${this.config.intersectionObserverMargin}px 0px`}),t instanceof Document?this.setupWindow():this.setupElement(n),window.__INSTANCE=this,window.__TOGGLE=()=>{e.__STOP?(e.__STOP=!1,(this.getScrollContainerElement()??window).scrollTo({top:e.__lastScrollPosition}),b(this.computeRenderRangeAndEmit)):(e.__lastScrollPosition=this.getScrollTop(),e.__STOP=!0)};for(let[e,t]of this.connectQueue.entries())this.connect(e,t);this.connectQueue.clear(),this.markDOMDirty(),b(this.computeRenderRangeAndEmit)}}instanceChanged(e,t){this.instancesChanged.add(e),t&&this.markDOMDirty(),b(this.computeRenderRangeAndEmit)}requestHeightReconcile(e){this.reconcileQueue.add(e),b(this.computeRenderRangeAndEmit)}getWindowSpecs(){return this.windowSpecs.top===0&&this.windowSpecs.bottom===0&&(this.windowSpecs=ce({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize})),this.windowSpecs}getRoot(){return this.root}isInstanceVisible(e,t){let n=this.getScrollTop(),r=this.getHeight(),i=this.config.intersectionObserverMargin,a=n-i,o=n+r+i;return!(e<a-t||e>o)}handleContainerResize=e=>{if(this.root==null)return;let t=!1;for(let n of e){let e=n.borderBoxSize[0].blockSize;this.root instanceof Document?e!==this.scrollHeight&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log(`Virtualizer: content size change`,this.__id,{sizeChange:e-he,newSize:e}),he=e)):n.target===this.root?e!==this.height&&(this.heightDirty=!0,t=!0):n.target===this.contentContainer&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log(`Virtualizer: scroller size change`,this.__id,{sizeChange:e-he,newSize:e}),he=e))}t&&b(this.computeRenderRangeAndEmit)};setupWindow(){if(this.root==null||!(this.root instanceof Document))throw Error(`Virtualizer.setupWindow: Invalid setup method`);window.addEventListener(`scroll`,this.handleWindowScroll,{passive:!0}),window.addEventListener(`resize`,this.handleWindowResize,{passive:!0}),this.resizeObserver?.observe(this.root.documentElement)}setupElement(e){if(this.root==null||this.root instanceof Document)throw Error(`Virtualizer.setupElement: Invalid setup method`);this.root.addEventListener(`scroll`,this.handleElementScroll,{passive:!0}),this.resizeObserver?.observe(this.root),e??=this.root.firstElementChild??void 0,e instanceof HTMLElement&&(this.contentContainer=e,this.resizeObserver?.observe(e))}cleanUp(){oe(this.computeRenderRangeAndEmit),this.resizeObserver?.disconnect(),this.resizeObserver=void 0,this.intersectionObserver?.disconnect(),this.intersectionObserver=void 0,this.root?.removeEventListener(`scroll`,this.handleElementScroll),window.removeEventListener(`scroll`,this.handleWindowScroll),window.removeEventListener(`resize`,this.handleWindowResize),this.root=void 0,this.contentContainer=void 0,this.observers.clear(),this.visibleInstances.clear(),this.instancesChanged.clear(),this.reconcileQueue.clear(),this.connectQueue.clear(),this.visibleInstancesDirty=!1,this.windowSpecs={top:0,bottom:0},this.scrollTop=0,this.height=0,this.scrollHeight=0,this.scrollDirty=!0,this.heightDirty=!0,this.scrollHeightDirty=!0}getOffsetInScrollContainer(e){return this.getScrollTop()+ve(e,this.getScrollContainerElement())}connect(e,t){if(this.observers.has(e))throw Error(`Virtualizer.connect: instance is already connected...`);return this.intersectionObserver==null?this.connectQueue.set(e,t):(this.intersectionObserver.observe(e),this.observers.set(e,t),this.instancesChanged.add(t),this.markDOMDirty(),b(this.computeRenderRangeAndEmit)),()=>this.disconnect(e)}disconnect(e){let t=this.observers.get(e);this.connectQueue.delete(e),t!=null&&(this.intersectionObserver?.unobserve(e),this.observers.delete(e),this.instancesChanged.delete(t),this.reconcileQueue.delete(t),this.visibleInstances.delete(e)&&(this.visibleInstancesDirty=!0),this.markDOMDirty(),b(this.computeRenderRangeAndEmit))}handleWindowResize=()=>{e.__STOP||window.innerHeight===this.height||(this.heightDirty=!0,b(this.computeRenderRangeAndEmit))};handleWindowScroll=()=>{!e.__STOP&&this.root!=null&&this.root instanceof Document&&(this.scrollDirty=!0,b(this.computeRenderRangeAndEmit))};handleElementScroll=()=>{e.__STOP||this.root==null||this.root instanceof Document||(this.scrollDirty=!0,b(this.computeRenderRangeAndEmit))};computeRenderRangeAndEmit=()=>{if(e.__STOP)return;let t=this.heightDirty||this.scrollHeightDirty,n=this.instancesChanged.size>0;if(this.instancesChanged.size===0){let e=ce({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize});if(!t&&ue(this.windowSpecs,e)&&this.renderedObservers===this.observers.size&&!this.visibleInstancesDirty&&this.reconcileQueue.size===0)return;this.windowSpecs=e}this.visibleInstancesDirty=!1,this.renderedObservers=this.observers.size;let r=this.getScrollAnchor(this.height),i=new Set;for(let e of t?this.observers.values():this.visibleInstances.values())e.onRender(t)&&i.add(e);for(let e of this.instancesChanged)i.has(e)||e.onRender(t)&&i.add(e);this.scrollFix(r);for(let e of i)this.reconcileQueue.delete(e),e.reconcileHeights();for(let e of this.reconcileQueue)e.reconcileHeights()&&(n=!0);this.reconcileQueue.clear(),n||=this.instancesChanged.size>0,n&&this.markDOMDirty(),(n||t)&&b(this.computeRenderRangeAndEmit),i.clear(),this.instancesChanged.clear()};scrollFix(e){if(e==null)return;let t=this.getScrollContainerElement(),{lineIndex:n,lineOffset:r,fileElement:i,fileOffset:a,fileTypeOffset:o}=e;if(n!=null&&r!=null){let e=i.shadowRoot?.querySelector(`[data-line][data-line-index="${n}"]`);if(e instanceof HTMLElement){let n=ve(e,t);if(n!==r){let e=n-r;this.applyScrollFix(e)}return}}let s=ve(i,t);if(o===`top`)s!==a&&this.applyScrollFix(s-a);else{let e=s+i.getBoundingClientRect().height;e!==a&&this.applyScrollFix(e-a)}}applyScrollFix(e){this.root==null||this.root instanceof Document?window.scrollTo({top:window.scrollY+e,behavior:`instant`}):this.root.scrollTo({top:this.root.scrollTop+e,behavior:`instant`}),this.markDOMDirty()}getScrollAnchor(e){let t=this.getScrollContainerElement(),n;for(let[r]of this.visibleInstances.entries()){let i=ve(r,t),a=i+r.offsetHeight,o,s;a<=0?(o=a,s=`bottom`):(o=i,s=`top`);let c,l;if(a>0&&i<e)for(let e of r.shadowRoot?.querySelectorAll(`[data-line][data-line-index]`)??[]){if(!(e instanceof HTMLElement))continue;let n=e.dataset.lineIndex;if(n==null)continue;let r=ve(e,t);if(!(r<0)){c=n,l=r;break}}if(n?.lineOffset!=null&&l==null)continue;let u=!1;(n==null||l!=null&&(n.lineOffset==null||l<n.lineOffset)||l==null&&n.lineOffset==null&&(o>=0&&(n.fileOffset<0||o<n.fileOffset)||o<0&&n.fileOffset<0&&o>n.fileOffset))&&(u=!0),u&&(n={fileElement:r,fileTypeOffset:s,fileOffset:o,lineIndex:c,lineOffset:l})}return n}handleIntersectionChange=e=>{this.scrollDirty=!0;for(let{target:t,isIntersecting:n}of e){if(!(t instanceof HTMLElement))throw Error(`Virtualizer.handleIntersectionChange: target not an HTMLElement`);let e=this.observers.get(t);e!=null&&(n&&!this.visibleInstances.has(t)?(e.setVisibility(!0),this.visibleInstances.set(t,e),this.visibleInstancesDirty=!0):!n&&this.visibleInstances.has(t)&&(e.setVisibility(!1),this.visibleInstances.delete(t),this.visibleInstancesDirty=!0))}this.visibleInstancesDirty&&b(this.computeRenderRangeAndEmit)};getScrollTop(){if(!this.scrollDirty)return this.scrollTop;this.scrollDirty=!1;let e=this.root==null?0:this.root instanceof Document?window.scrollY:this.root.scrollTop;return e=this.clampScrollTop(e),this.scrollTop=e,e}scrollTo({top:e,behavior:t=`auto`}){let{root:n}=this;if(n==null)return;let r=this.clampScrollTop(e);n instanceof Document?window.scrollTo({top:r,behavior:t}):n.scrollTo({top:r,behavior:t}),this.scrollDirty=!0,b(this.computeRenderRangeAndEmit)}clampScrollTop(e){return Math.max(0,Math.min(e,this.getScrollHeight()-this.getHeight()))}getScrollHeight(){return this.scrollHeightDirty?(this.scrollHeightDirty=!1,this.scrollHeight=this.root==null?0:this.root instanceof Document?this.root.documentElement.scrollHeight:this.root.scrollHeight,this.scrollHeight):this.scrollHeight}getHeight(){return this.heightDirty?(this.heightDirty=!1,this.height=this.root==null?0:this.root instanceof Document?globalThis.innerHeight:this.root.getBoundingClientRect().height,this.height):this.height}markDOMDirty(){this.scrollDirty=!0,this.scrollHeightDirty=!0,this.heightDirty=!0}getScrollContainerElement(){return this.root==null||this.root instanceof Document?void 0:this.root}};function ve(e,t){let n=e.getBoundingClientRect(),r=t?.getBoundingClientRect().top??0;return n.top-r}var ye=100,be=`insert`,xe=`backspace`,Se=`delete`,Ce=class e{#e=[];#t=[];#n;#r=!1;constructor(e){this.#n=Math.max(1,e?.maxEntries??ye)}get canUndo(){return this.#e.length>0}get canRedo(){return this.#t.length>0}getState(){return{undoStack:this.#e.map(Te),redoStack:this.#t.map(Te),maxEntries:this.#n,canCoalesce:this.#r}}getLiveState(){return Object.defineProperties({},{undoStack:{enumerable:!0,get:()=>this.#e},redoStack:{enumerable:!0,get:()=>this.#t},maxEntries:{enumerable:!0,get:()=>this.#n},canCoalesce:{enumerable:!0,get:()=>this.#r}})}static fromState(t){let n=new e({maxEntries:t.maxEntries});return n.#e=t.undoStack,n.#t=t.redoStack,n.#r=t.canCoalesce,n}clear(){this.#e.length=0,this.#t.length=0,this.#r=!1}clearRedo(){this.#t.length=0}push(e){this.#e.push(e),this.clearRedo(),this.#r=!0,this.#e.length>this.#n&&this.#e.shift()}setLastUndoSelectionsAfter(e){let t=this.#e[this.#e.length-1];t!==void 0&&(t.selectionsAfter=e.map(e=>({...e})))}setLastUndoLineAnnotations(e,t){let n=this.#e[this.#e.length-1];n!==void 0&&(n.lineAnnotationsBefore=e.slice(),n.lineAnnotationsAfter=t.slice())}peekUndo(){return this.#e[this.#e.length-1]}peekUndoForCoalescing(){return this.#r?this.peekUndo():void 0}replaceLastUndo(e){if(this.#e.length===0){this.push(e);return}this.#e[this.#e.length-1]=e,this.clearRedo(),this.#r=!0}popUndoToRedo(){let e=this.#e.pop();if(e!==void 0)return this.#t.push(e),this.#r=!1,e}popRedoToUndo(){let e=this.#t.pop();if(e!==void 0)return this.#e.push(e),this.#r=!1,e}};function we(e){return{...e,forwardEdits:e.forwardEdits.map(e=>({...e})),inverseEdits:e.inverseEdits.map(e=>({...e})),selectionsBefore:e.selectionsBefore?.map(Ee),selectionsAfter:e.selectionsAfter?.map(Ee),lineAnnotationsBefore:e.lineAnnotationsBefore?.slice(),lineAnnotationsAfter:e.lineAnnotationsAfter?.slice()}}function Te(e){return{...we(e),lineAnnotationsBefore:e.lineAnnotationsBefore?.map(e=>({...e})),lineAnnotationsAfter:e.lineAnnotationsAfter?.map(e=>({...e}))}}function Ee(e){return{...e,start:{...e.start},end:{...e.end}}}function De(e,t,n,r,i,a,o,s){let c=[...t].sort((e,t)=>e.start-t.start),l=[],u;if(i?.length===c.length){let t=[];for(let n of i){if(n.start.line!==n.end.line||n.start.character!==n.end.character)break;t.push(e.offsetAt(n.start))}if(t.length===c.length){t.sort((e,t)=>e-t);let e=!0,n=!0;for(let r=0;r<c.length;r++){let i=c[r];if(i.text.length>0||i.start===i.end){e=!1,n=!1;break}e&&=t[r]===i.end,n&&=t[r]===i.start}u=e?xe:n?Se:void 0}}for(let t=0,n=0;t<c.length;t++){let r=c[t],i=e.getTextSlice(r.start,r.end),a=r.start+n;l.push({start:a,end:a+r.text.length,text:i}),n+=r.text.length-(r.end-r.start)}return{forwardEdits:c.map(e=>({...e})),inverseEdits:l,versionBefore:n,versionAfter:r,selectionsBefore:i?.map(e=>({...e})),selectionsAfter:a?.map(e=>({...e})),lineAnnotationsBefore:o?.slice(),lineAnnotationsAfter:s?.slice(),coalescingMode:u}}function Oe(e,t){if(e===void 0||e.undoBoundary===!0||t.undoBoundary===!0||e.forwardEdits.length===0||e.forwardEdits.length!==e.inverseEdits.length||e.forwardEdits.length!==t.forwardEdits.length||t.forwardEdits.length!==t.inverseEdits.length)return!1;let n;for(let r=0;r<e.forwardEdits.length;r++){let i=e.forwardEdits[r],a=e.inverseEdits[r],o=t.forwardEdits[r],s=t.inverseEdits[r],c=je(o.start,e.forwardEdits),l=i.start<=i.end&&i.text.length>0&&!i.text.includes(`
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$t as t,Di as n,Mi as r,Ni as i,Ti as a,rl as o,tn as s}from"./files-D4CzkVZ-.js";import{A as c,Bn as l,F as u,G as d,Gn as f,Hn as p,Ht as m,I as h,Jn as g,Kn as _,O as v,Rn as y,St as b,Tn as x,Tt as S,Un as C,Ut as w,Vn as T,W as E,Wn as D,Xn as ee,cn as O,ft as k,g as A,i as te,j,mn as M,qn as N,qt as P,s as F,sn as I,t as ne,tr as re,u as ie,v as ae,xt as oe,y as se,yt as ce}from"./store-C-FZWhob.js";var le={compositeOverBg:l,contrastRatio:T,deriveMutedFg:p,hoverWouldEraseText:C,isDarkSurface:D,isFullyTransparent:f,pickReadableForeground:_,relativeLuminance:N,surfacesMatch:g};function ue(e,t){return e==null||t==null?e===t:e.top===t.top&&e.bottom===t.bottom}var de=1e3,fe=de*4,pe=[0,1e-6,.99999,1],me={overscrollSize:de,intersectionObserverMargin:fe,resizeDebugging:!1},he=0,ge=-1,_e=class e{static __STOP=!1;static __lastScrollPosition=0;__id=`virtualizer-${++ge}`;config;type=`simple`;intersectionObserver;scrollTop=0;height=0;scrollHeight=0;windowSpecs={top:0,bottom:0};root;contentContainer;resizeObserver;observers=new Map;visibleInstances=new Map;visibleInstancesDirty=!1;instancesChanged=new Set;reconcileQueue=new Set;scrollDirty=!0;heightDirty=!0;scrollHeightDirty=!0;renderedObservers=0;connectQueue=new Map;constructor(e){this.config={...me,...e}}setup(t,n){if(this.root==null){this.root=t,this.resizeObserver=new ResizeObserver(this.handleContainerResize),this.intersectionObserver=new IntersectionObserver(this.handleIntersectionChange,{root:this.root,threshold:pe,rootMargin:`${this.config.intersectionObserverMargin}px 0px ${this.config.intersectionObserverMargin}px 0px`}),t instanceof Document?this.setupWindow():this.setupElement(n),window.__INSTANCE=this,window.__TOGGLE=()=>{e.__STOP?(e.__STOP=!1,(this.getScrollContainerElement()??window).scrollTo({top:e.__lastScrollPosition}),b(this.computeRenderRangeAndEmit)):(e.__lastScrollPosition=this.getScrollTop(),e.__STOP=!0)};for(let[e,t]of this.connectQueue.entries())this.connect(e,t);this.connectQueue.clear(),this.markDOMDirty(),b(this.computeRenderRangeAndEmit)}}instanceChanged(e,t){this.instancesChanged.add(e),t&&this.markDOMDirty(),b(this.computeRenderRangeAndEmit)}requestHeightReconcile(e){this.reconcileQueue.add(e),b(this.computeRenderRangeAndEmit)}getWindowSpecs(){return this.windowSpecs.top===0&&this.windowSpecs.bottom===0&&(this.windowSpecs=ce({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize})),this.windowSpecs}getRoot(){return this.root}isInstanceVisible(e,t){let n=this.getScrollTop(),r=this.getHeight(),i=this.config.intersectionObserverMargin,a=n-i,o=n+r+i;return!(e<a-t||e>o)}handleContainerResize=e=>{if(this.root==null)return;let t=!1;for(let n of e){let e=n.borderBoxSize[0].blockSize;this.root instanceof Document?e!==this.scrollHeight&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log(`Virtualizer: content size change`,this.__id,{sizeChange:e-he,newSize:e}),he=e)):n.target===this.root?e!==this.height&&(this.heightDirty=!0,t=!0):n.target===this.contentContainer&&(this.scrollHeightDirty=!0,t=!0,this.config.resizeDebugging&&(console.log(`Virtualizer: scroller size change`,this.__id,{sizeChange:e-he,newSize:e}),he=e))}t&&b(this.computeRenderRangeAndEmit)};setupWindow(){if(this.root==null||!(this.root instanceof Document))throw Error(`Virtualizer.setupWindow: Invalid setup method`);window.addEventListener(`scroll`,this.handleWindowScroll,{passive:!0}),window.addEventListener(`resize`,this.handleWindowResize,{passive:!0}),this.resizeObserver?.observe(this.root.documentElement)}setupElement(e){if(this.root==null||this.root instanceof Document)throw Error(`Virtualizer.setupElement: Invalid setup method`);this.root.addEventListener(`scroll`,this.handleElementScroll,{passive:!0}),this.resizeObserver?.observe(this.root),e??=this.root.firstElementChild??void 0,e instanceof HTMLElement&&(this.contentContainer=e,this.resizeObserver?.observe(e))}cleanUp(){oe(this.computeRenderRangeAndEmit),this.resizeObserver?.disconnect(),this.resizeObserver=void 0,this.intersectionObserver?.disconnect(),this.intersectionObserver=void 0,this.root?.removeEventListener(`scroll`,this.handleElementScroll),window.removeEventListener(`scroll`,this.handleWindowScroll),window.removeEventListener(`resize`,this.handleWindowResize),this.root=void 0,this.contentContainer=void 0,this.observers.clear(),this.visibleInstances.clear(),this.instancesChanged.clear(),this.reconcileQueue.clear(),this.connectQueue.clear(),this.visibleInstancesDirty=!1,this.windowSpecs={top:0,bottom:0},this.scrollTop=0,this.height=0,this.scrollHeight=0,this.scrollDirty=!0,this.heightDirty=!0,this.scrollHeightDirty=!0}getOffsetInScrollContainer(e){return this.getScrollTop()+ve(e,this.getScrollContainerElement())}connect(e,t){if(this.observers.has(e))throw Error(`Virtualizer.connect: instance is already connected...`);return this.intersectionObserver==null?this.connectQueue.set(e,t):(this.intersectionObserver.observe(e),this.observers.set(e,t),this.instancesChanged.add(t),this.markDOMDirty(),b(this.computeRenderRangeAndEmit)),()=>this.disconnect(e)}disconnect(e){let t=this.observers.get(e);this.connectQueue.delete(e),t!=null&&(this.intersectionObserver?.unobserve(e),this.observers.delete(e),this.instancesChanged.delete(t),this.reconcileQueue.delete(t),this.visibleInstances.delete(e)&&(this.visibleInstancesDirty=!0),this.markDOMDirty(),b(this.computeRenderRangeAndEmit))}handleWindowResize=()=>{e.__STOP||window.innerHeight===this.height||(this.heightDirty=!0,b(this.computeRenderRangeAndEmit))};handleWindowScroll=()=>{!e.__STOP&&this.root!=null&&this.root instanceof Document&&(this.scrollDirty=!0,b(this.computeRenderRangeAndEmit))};handleElementScroll=()=>{e.__STOP||this.root==null||this.root instanceof Document||(this.scrollDirty=!0,b(this.computeRenderRangeAndEmit))};computeRenderRangeAndEmit=()=>{if(e.__STOP)return;let t=this.heightDirty||this.scrollHeightDirty,n=this.instancesChanged.size>0;if(this.instancesChanged.size===0){let e=ce({scrollTop:this.getScrollTop(),height:this.getHeight(),scrollHeight:this.getScrollHeight(),overscrollSize:this.config.overscrollSize});if(!t&&ue(this.windowSpecs,e)&&this.renderedObservers===this.observers.size&&!this.visibleInstancesDirty&&this.reconcileQueue.size===0)return;this.windowSpecs=e}this.visibleInstancesDirty=!1,this.renderedObservers=this.observers.size;let r=this.getScrollAnchor(this.height),i=new Set;for(let e of t?this.observers.values():this.visibleInstances.values())e.onRender(t)&&i.add(e);for(let e of this.instancesChanged)i.has(e)||e.onRender(t)&&i.add(e);this.scrollFix(r);for(let e of i)this.reconcileQueue.delete(e),e.reconcileHeights();for(let e of this.reconcileQueue)e.reconcileHeights()&&(n=!0);this.reconcileQueue.clear(),n||=this.instancesChanged.size>0,n&&this.markDOMDirty(),(n||t)&&b(this.computeRenderRangeAndEmit),i.clear(),this.instancesChanged.clear()};scrollFix(e){if(e==null)return;let t=this.getScrollContainerElement(),{lineIndex:n,lineOffset:r,fileElement:i,fileOffset:a,fileTypeOffset:o}=e;if(n!=null&&r!=null){let e=i.shadowRoot?.querySelector(`[data-line][data-line-index="${n}"]`);if(e instanceof HTMLElement){let n=ve(e,t);if(n!==r){let e=n-r;this.applyScrollFix(e)}return}}let s=ve(i,t);if(o===`top`)s!==a&&this.applyScrollFix(s-a);else{let e=s+i.getBoundingClientRect().height;e!==a&&this.applyScrollFix(e-a)}}applyScrollFix(e){this.root==null||this.root instanceof Document?window.scrollTo({top:window.scrollY+e,behavior:`instant`}):this.root.scrollTo({top:this.root.scrollTop+e,behavior:`instant`}),this.markDOMDirty()}getScrollAnchor(e){let t=this.getScrollContainerElement(),n;for(let[r]of this.visibleInstances.entries()){let i=ve(r,t),a=i+r.offsetHeight,o,s;a<=0?(o=a,s=`bottom`):(o=i,s=`top`);let c,l;if(a>0&&i<e)for(let e of r.shadowRoot?.querySelectorAll(`[data-line][data-line-index]`)??[]){if(!(e instanceof HTMLElement))continue;let n=e.dataset.lineIndex;if(n==null)continue;let r=ve(e,t);if(!(r<0)){c=n,l=r;break}}if(n?.lineOffset!=null&&l==null)continue;let u=!1;(n==null||l!=null&&(n.lineOffset==null||l<n.lineOffset)||l==null&&n.lineOffset==null&&(o>=0&&(n.fileOffset<0||o<n.fileOffset)||o<0&&n.fileOffset<0&&o>n.fileOffset))&&(u=!0),u&&(n={fileElement:r,fileTypeOffset:s,fileOffset:o,lineIndex:c,lineOffset:l})}return n}handleIntersectionChange=e=>{this.scrollDirty=!0;for(let{target:t,isIntersecting:n}of e){if(!(t instanceof HTMLElement))throw Error(`Virtualizer.handleIntersectionChange: target not an HTMLElement`);let e=this.observers.get(t);e!=null&&(n&&!this.visibleInstances.has(t)?(e.setVisibility(!0),this.visibleInstances.set(t,e),this.visibleInstancesDirty=!0):!n&&this.visibleInstances.has(t)&&(e.setVisibility(!1),this.visibleInstances.delete(t),this.visibleInstancesDirty=!0))}this.visibleInstancesDirty&&b(this.computeRenderRangeAndEmit)};getScrollTop(){if(!this.scrollDirty)return this.scrollTop;this.scrollDirty=!1;let e=this.root==null?0:this.root instanceof Document?window.scrollY:this.root.scrollTop;return e=this.clampScrollTop(e),this.scrollTop=e,e}scrollTo({top:e,behavior:t=`auto`}){let{root:n}=this;if(n==null)return;let r=this.clampScrollTop(e);n instanceof Document?window.scrollTo({top:r,behavior:t}):n.scrollTo({top:r,behavior:t}),this.scrollDirty=!0,b(this.computeRenderRangeAndEmit)}clampScrollTop(e){return Math.max(0,Math.min(e,this.getScrollHeight()-this.getHeight()))}getScrollHeight(){return this.scrollHeightDirty?(this.scrollHeightDirty=!1,this.scrollHeight=this.root==null?0:this.root instanceof Document?this.root.documentElement.scrollHeight:this.root.scrollHeight,this.scrollHeight):this.scrollHeight}getHeight(){return this.heightDirty?(this.heightDirty=!1,this.height=this.root==null?0:this.root instanceof Document?globalThis.innerHeight:this.root.getBoundingClientRect().height,this.height):this.height}markDOMDirty(){this.scrollDirty=!0,this.scrollHeightDirty=!0,this.heightDirty=!0}getScrollContainerElement(){return this.root==null||this.root instanceof Document?void 0:this.root}};function ve(e,t){let n=e.getBoundingClientRect(),r=t?.getBoundingClientRect().top??0;return n.top-r}var ye=100,be=`insert`,xe=`backspace`,Se=`delete`,Ce=class e{#e=[];#t=[];#n;#r=!1;constructor(e){this.#n=Math.max(1,e?.maxEntries??ye)}get canUndo(){return this.#e.length>0}get canRedo(){return this.#t.length>0}getState(){return{undoStack:this.#e.map(Te),redoStack:this.#t.map(Te),maxEntries:this.#n,canCoalesce:this.#r}}getLiveState(){return Object.defineProperties({},{undoStack:{enumerable:!0,get:()=>this.#e},redoStack:{enumerable:!0,get:()=>this.#t},maxEntries:{enumerable:!0,get:()=>this.#n},canCoalesce:{enumerable:!0,get:()=>this.#r}})}static fromState(t){let n=new e({maxEntries:t.maxEntries});return n.#e=t.undoStack,n.#t=t.redoStack,n.#r=t.canCoalesce,n}clear(){this.#e.length=0,this.#t.length=0,this.#r=!1}clearRedo(){this.#t.length=0}push(e){this.#e.push(e),this.clearRedo(),this.#r=!0,this.#e.length>this.#n&&this.#e.shift()}setLastUndoSelectionsAfter(e){let t=this.#e[this.#e.length-1];t!==void 0&&(t.selectionsAfter=e.map(e=>({...e})))}setLastUndoLineAnnotations(e,t){let n=this.#e[this.#e.length-1];n!==void 0&&(n.lineAnnotationsBefore=e.slice(),n.lineAnnotationsAfter=t.slice())}peekUndo(){return this.#e[this.#e.length-1]}peekUndoForCoalescing(){return this.#r?this.peekUndo():void 0}replaceLastUndo(e){if(this.#e.length===0){this.push(e);return}this.#e[this.#e.length-1]=e,this.clearRedo(),this.#r=!0}popUndoToRedo(){let e=this.#e.pop();if(e!==void 0)return this.#t.push(e),this.#r=!1,e}popRedoToUndo(){let e=this.#t.pop();if(e!==void 0)return this.#e.push(e),this.#r=!1,e}};function we(e){return{...e,forwardEdits:e.forwardEdits.map(e=>({...e})),inverseEdits:e.inverseEdits.map(e=>({...e})),selectionsBefore:e.selectionsBefore?.map(Ee),selectionsAfter:e.selectionsAfter?.map(Ee),lineAnnotationsBefore:e.lineAnnotationsBefore?.slice(),lineAnnotationsAfter:e.lineAnnotationsAfter?.slice()}}function Te(e){return{...we(e),lineAnnotationsBefore:e.lineAnnotationsBefore?.map(e=>({...e})),lineAnnotationsAfter:e.lineAnnotationsAfter?.map(e=>({...e}))}}function Ee(e){return{...e,start:{...e.start},end:{...e.end}}}function De(e,t,n,r,i,a,o,s){let c=[...t].sort((e,t)=>e.start-t.start),l=[],u;if(i?.length===c.length){let t=[];for(let n of i){if(n.start.line!==n.end.line||n.start.character!==n.end.character)break;t.push(e.offsetAt(n.start))}if(t.length===c.length){t.sort((e,t)=>e-t);let e=!0,n=!0;for(let r=0;r<c.length;r++){let i=c[r];if(i.text.length>0||i.start===i.end){e=!1,n=!1;break}e&&=t[r]===i.end,n&&=t[r]===i.start}u=e?xe:n?Se:void 0}}for(let t=0,n=0;t<c.length;t++){let r=c[t],i=e.getTextSlice(r.start,r.end),a=r.start+n;l.push({start:a,end:a+r.text.length,text:i}),n+=r.text.length-(r.end-r.start)}return{forwardEdits:c.map(e=>({...e})),inverseEdits:l,versionBefore:n,versionAfter:r,selectionsBefore:i?.map(e=>({...e})),selectionsAfter:a?.map(e=>({...e})),lineAnnotationsBefore:o?.slice(),lineAnnotationsAfter:s?.slice(),coalescingMode:u}}function Oe(e,t){if(e===void 0||e.undoBoundary===!0||t.undoBoundary===!0||e.forwardEdits.length===0||e.forwardEdits.length!==e.inverseEdits.length||e.forwardEdits.length!==t.forwardEdits.length||t.forwardEdits.length!==t.inverseEdits.length)return!1;let n;for(let r=0;r<e.forwardEdits.length;r++){let i=e.forwardEdits[r],a=e.inverseEdits[r],o=t.forwardEdits[r],s=t.inverseEdits[r],c=je(o.start,e.forwardEdits),l=i.start<=i.end&&i.text.length>0&&!i.text.includes(`
|
|
2
2
|
`)&&!a.text.includes(`
|
|
3
3
|
`),u=o.start===o.end&&o.text.length>0&&!o.text.includes(`
|
|
4
4
|
`)&&s.text.length===0;if(l&&u){if(o.start!==a.end||(n??=be,n!==be||e.coalescingMode!==void 0&&e.coalescingMode!==be||t.coalescingMode!==void 0&&t.coalescingMode!==be))return!1;continue}let d=i.text.length===0&&i.end>i.start&&a.text.length>0,f=o.text.length===0&&o.end>o.start&&s.text.length>0;if(d&&f){let r;if(c===i.end)r=Se;else if(c+(o.end-o.start)!==i.start)return!1;else r=xe;if(n??=r,n!==r||e.coalescingMode!==void 0&&e.coalescingMode!==r||t.coalescingMode!==void 0&&t.coalescingMode!==r)return!1;continue}return!1}return n!==void 0}function ke(e,t){let n=[],r=[],i;for(let a=0;a<e.forwardEdits.length;a++){let o=e.forwardEdits[a],s=e.inverseEdits[a],c=t.forwardEdits[a],l=t.inverseEdits[a],u=je(c.start,e.forwardEdits);if(o.text.length>0){i??=be,n.push({start:o.start,end:o.end,text:o.text+c.text}),r.push(s.text);continue}if(u===o.end){i??=Se,n.push({start:o.start,end:u+(c.end-c.start),text:``}),r.push(s.text+l.text);continue}i??=xe,n.push({start:Math.min(o.start,u),end:o.end,text:``}),r.push(l.text+s.text)}return{forwardEdits:n,inverseEdits:Ae(n,r),versionBefore:e.versionBefore,versionAfter:t.versionAfter,selectionsBefore:e.selectionsBefore?.slice(),selectionsAfter:t.selectionsAfter?.slice(),lineAnnotationsBefore:e.lineAnnotationsBefore?.slice(),lineAnnotationsAfter:t.lineAnnotationsAfter?.slice(),coalescingMode:i}}function Ae(e,t){let n=[];for(let r=0,i=0;r<e.length;r++){let a=e[r],o=a.start+i;n.push({start:o,end:o+a.text.length,text:t[r]}),i+=a.text.length-(a.end-a.start)}return n}function je(e,t){let n=e;for(let e of t){let t=e.end-e.start,r=e.text.length,i=r-t;if(!(n<e.start)){if(n>=e.start+r){n-=i;continue}n=e.start+Math.min(n-e.start,t)}}return n}var Me=1e5,Ne=10,Pe=13,Fe=`\`~!@#$%^&*()-=+[{]}\\|;:'",.<>/?`,Ie=class{source;offset;length;lineOffsetStart;lineOffsetEnd;hasVirtualTrailingCRBreak;firstCharCode;lastCharCode;static Original=0;static Added=1;constructor(e,t,n,r,i,a,o,s){this.source=e,this.offset=t,this.length=n,this.lineOffsetStart=r,this.lineOffsetEnd=i,this.hasVirtualTrailingCRBreak=a,this.firstCharCode=o,this.lastCharCode=s}get lineBreakCount(){return this.lineOffsetEnd-this.lineOffsetStart+ +!!this.hasVirtualTrailingCRBreak}},Le=class{text;lineOffsets;constructor(e){this.text=e,this.lineOffsets=m(e)}append(e){let t=this.text.length;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);(r===Ne||r===Pe)&&(r===Pe&&e.charCodeAt(n+1)===Ne&&n++,this.lineOffsets.push(t+n+1))}return this.text+=e,t}},Re=class{piece;subtreeLength;subtreeLineBreakCount;subtreeFirstCharCode;subtreeLastCharCode;left=null;right=null;parent=null;priority=0;constructor(e,t=e.length,n=e.lineBreakCount,r=e.firstCharCode,i=e.lastCharCode){this.piece=e,this.subtreeLength=t,this.subtreeLineBreakCount=n,this.subtreeFirstCharCode=r,this.subtreeLastCharCode=i}updateSubtreeLength(){this.subtreeLength=(this.left?.subtreeLength??0)+this.piece.length+(this.right?.subtreeLength??0),this.subtreeLineBreakCount=(this.left?.subtreeLineBreakCount??0)+this.piece.lineBreakCount+(this.right?.subtreeLineBreakCount??0)-+!!R(this.left?.subtreeLastCharCode,this.piece.firstCharCode)-!!R(this.piece.lastCharCode,this.right?.subtreeFirstCharCode),this.subtreeFirstCharCode=this.left?.subtreeFirstCharCode??this.piece.firstCharCode,this.subtreeLastCharCode=this.right?.subtreeLastCharCode??this.piece.lastCharCode}},ze=class{#e;#t=new Le(``);#n=null;#r=0;#i=0;#a=null;#o=null;#s=null;#c=2654435769;constructor(e){this.#e=new Le(e);let t=this.#y(Ie.Original,0,e.length);this.#n=t.length>0?this.#C(t):null,this.#r=this.#n?.subtreeLength??0,this.#i=(this.#n?.subtreeLineBreakCount??0)+1}get lineCount(){return this.#i}getText(e){if(e===void 0)return this.#g();let t=this.offsetAt(e.start),n=this.offsetAt(e.end);return this.getTextSlice(t,n)}getLineText(e,t=!1){if(this.#a!==null&&this.#a[0]===e&&this.#a[1]===t)return this.#a[2];let n=this.#f(e);if(n===void 0)throw Error(`Line index out of range: ${e}`);let r=this.getTextSlice(n[0],n[1],!t);return this.#a=[e,t,r],this.#o=[e,t,r.length],r}getLineLength(e,t=!1){let n=this.#o,r=this.#a;if(n!==null&&n[0]===e&&n[1]===t)return n[2];if(r!==null&&r[0]===e&&r[1]===t){let n=r[2].length;return this.#o=[e,t,n],n}let i=this.#f(e);if(i===void 0)throw Error(`Line index out of range: ${e}`);let[a,o]=i,s=o-a;if(!t)for(;s>0&&Be(this.charAt(a+s-1).charCodeAt(0));)s--;return this.#o=[e,t,s],s}getTextSlice(e,t,n=!1){if(e>=t)return``;let r=L(e,0,this.#r),i=L(t,r,this.#r);if(r>=i)return``;let a=this.#u(r);if(a===void 0)return``;let o=[],[s,c]=a,l=i-r;for(;s!==null&&l>0;){let e=Math.min(s.piece.length-c,l),t=this.#v(s.piece.source),r=s.piece.offset+c,i=r+e;if(n)for(;i>r&&Be(t.text.charCodeAt(i-1));)i--;o.push(t.text.slice(r,i)),l-=e,c=0,s=this.#d(s)}return o.join(``)}charAt(e){let t=this.#u(e);if(t===void 0)return``;let[n,r]=t;return this.#v(n.piece.source).text.charAt(n.piece.offset+r)}includes(e){if(e.length===0)return!0;let t=Ve(e),n=0,r=!1;return this.#_(i=>{for(let a=i.start;a<i.end;a++){let o=i.text.charCodeAt(a);for(;n>0&&o!==e.charCodeAt(n);)n=t[n-1];if(o===e.charCodeAt(n)&&n++,n===e.length)return r=!0,!1}return!0}),r}findNextNonOverlappingSubstring(e,t){if(e.length===0||e.length>this.#r)return;let n=He(t,this.#r),r=n.reduce((e,[,t])=>Math.max(e,t),0),i=Ve(e),a=0,o=0,s,c;return this.#_(t=>{for(let l=t.start;l<t.end;l++){let u=t.text.charCodeAt(l);for(;a>0&&u!==e.charCodeAt(a);)a=i[a-1];if(u===e.charCodeAt(a)&&a++,a===e.length){let t=o-e.length+1;if(!Ue(n,t,t+e.length)){if(t>=r)return c=t,!1;s??=t}a=i[a-1]}o++}return!0}),c??s}search(e){if(e.text.length===0||this.#r===0||e.text.includes(`
|
|
@@ -585,4 +585,4 @@ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$t as t,Ei as n,Mi as
|
|
|
585
585
|
`}),this.#y=z(`style`,{dataset:`editorCss`,textContent:fr}),this.#b=z(`style`,{dataset:`editorThemeCss`}),this.#x=ai(),this.#E=z(`div`,{dataset:`editorOverlay`});let e=e=>{let t=e.composedPath()[0];return t instanceof Node&&this.#w?.contains(t)===!0},t=()=>{this.#X!=null&&(this.#X=void 0,this.#Y=!1,this.#q=!1)},n=e=>{if(e.pointerType!==`mouse`)return;let t=this.#Q;this.#Ge(),t&&this.#lt(),this.#e.enabledSelectionAction===!0&&this.#oe!==void 0&&this.#oe.length>0&&!W(this.#oe.at(-1))&&this.#Ut(this.#oe)};this.#s=[B(document,`focusin`,n=>{e(n)||t()},{passive:!0}),B(document,`pointerdown`,n=>{e(n)||queueMicrotask(t)},{capture:!0,passive:!0}),B(document,`selectionchange`,()=>{let e=this.#S?.shadowRoot;if(this.#q||this.#J||e==null||!this.#Y||this.#oe!==void 0&&this.#oe.length>1&&!this.#$)return;let t=document.getSelection();if(t==null)return;let n;if(n=typeof t.getComposedRanges==`function`?t.getComposedRanges({shadowRoots:[e]})?.[0]:Si(e),n===void 0||!this.#Sn(n))return;let r=Kt(n,0);if(r!==void 0){if(this.#$&&this.#te&&this.#oe!==void 0&&this.#oe.length>0){let e=this.#oe.at(-1);this.#Ut([bn(e,r)]);return}if(this.#$)this.#ne===void 0?this.#ne=r:r=yn(this.#ne,r);else if(this.#ne!==void 0)r.direction=yn(this.#ne,r).direction;else if(this.#oe!==void 0&&this.#oe.length===1){let e=this.#oe[0];K(e.start,r.start)===0&&K(e.end,r.end)===0&&(r.direction=e.direction)}this.#ee!==void 0&&(this.#ee.focusLine=G(r).line,this.#Ot())||(this.#ie===void 0?this.#Ut([r]):this.#Ut([...this.#ie.filter(e=>!hn(e,r)),r]))}},{passive:!0}),B(document,`pointerup`,n,{passive:!0}),B(document,`pointercancel`,n,{passive:!0}),B(document,`keydown`,e=>{e.key===`Shift`?this.#ne=this.#oe?.at(-1):e.key===`Alt`&&!e.repeat&&this.#Y&&this.#e.editPrediction?.mode===`subtle`&&(this.#ve=!this.#ve,this.#Ut(this.#oe??[]))},{passive:!0}),B(document,`keyup`,e=>{e.key===`Shift`&&(this.#ne=void 0)},{passive:!0})]}#Ge(){this.#c?.forEach(e=>e()),this.#c=void 0,this.#q=!1,this.#Q=!1,this.#$=!1,this.#ee=void 0,this.#te=!1,this.#ne=void 0,this.#ie=void 0}#Ke(e){this.#c?.forEach(e=>e()),this.#c=e}#qe(){return this.#M?.options.enableLineSelection===!0}#Je(){this.#J=this.#oe!==void 0}#Ye(e,t){let{onFocus:n,onBlur:r}=this.#e,i=t=>{let n=t.composedPath()[0];return n!==void 0&&(n===e||e.contains(n))};this.#o?.forEach(e=>e()),this.#o=[B(e,`focus`,()=>{this.#Y=!0,n?.(),!this.#$&&!this.#q&&this.#oe!==void 0&&this.#oe.length>0&&this.#mt(this.#oe.at(-1))},{passive:!0}),B(e,`blur`,()=>{this.#X?.target===e&&(this.#X=void 0,this.#q=!1),this.#Y=!1,r?.()},{passive:!0}),B(e,`pointerdown`,t=>{if(this.#K=!0,this.#J=!1,t.pointerType!==`mouse`)return;if(this.#ee=void 0,this.#yt(t)){this.#Tt(!0),this.#oe!==void 0&&this.#Ut([]);return}this.#Tt(!1),this.#H?.removePopover();let n=[];if(h()&&this.#L!==void 0&&this.#L.length>0){let t=[...e.querySelectorAll(`[data-line-annotation]`)].map(e=>[B(e,`mouseenter`,()=>{this.#q=!0}),B(e,`mouseleave`,()=>{this.#q=!1})]).flat();n.push(...t)}this.#$=!0;let r=t.button===0&&t.altKey&&!t.ctrlKey&&!t.metaKey&&!t.shiftKey;if(this.#ne=void 0,r?(this.#ee={pointerId:t.pointerId,startClientX:t.clientX,clientX:t.clientX,startScrollLeft:e.parentElement?.scrollLeft??0},this.#ie=void 0,this.#oe=void 0,this.#Ut([]),n.push(B(document,`pointermove`,e=>{let t=this.#ee;t!==void 0&&e.pointerType===`mouse`&&e.pointerId===t.pointerId&&(t.clientX=e.clientX,this.#Ot())},{capture:!0,passive:!0}))):t.button===0&&ft(t)&&(this.#ie=this.#oe?.map(e=>({...e}))),this.#Ke(n),t.shiftKey){let e=this.#oe?.at(-1);if(e!==void 0){let t=e.direction===-1?e.end:e.start;this.#mt({start:t,end:t,direction:0})}this.#te=!0}},{passive:!0}),B(e,`keydown`,e=>{if(!i(e)||(this.#K=!0,this.#J=!1,e.isComposing||e.keyCode===229))return;if(e.key===`Tab`&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&!e.isComposing&&!this.#Z&&(!e.altKey||this.#e.editPrediction?.mode===`subtle`)&&this.#be?.rendered===!0){this.#Vt(),e.preventDefault();return}if(e.key===`Escape`&&this.#be!==void 0){this.#Lt(!0),e.preventDefault();return}let t=vt(e,this.#e.keymap);if(t!==void 0){e.preventDefault(),t===`simplifySelection`&&(this.#W?.close(),this.#W=void 0,this.#fe=!1,this.#G?.cleanup(),this.#G=void 0),this.#$e(t);return}let n=pt(e),r=this.#n?.document;if(this.#oe!==void 0&&this.#oe.length>0&&n!==void 0&&r!==void 0){let t={getSoftLineOffsets:this.#Ie?e=>this.#xn(e):void 0,resolveRenderableLine:this.#Me};e.shiftKey?this.#Ut(en(r,this.#oe,n,t)):this.#Ut(Jt(r,this.#oe,n,t)),this.#ht(),e.preventDefault();return}if((e.key.length===1?e.key.toLowerCase():e.key)===`v`&&ft(e)){if(e.repeat&&this.#Fe){e.preventDefault();return}if(this.#e.clipboard!==void 0){e.preventDefault(),b(this.#Xe);return}}if(this.#W!==void 0){let t=yt(e);if(t!==void 0){e.preventDefault(),this.#W.navigate(t===`previous`);return}}}),B(e,`copy`,e=>{i(e)&&(e.preventDefault(),this.#Ct()?e.clipboardData?.setData(`text`,this.#wt()):this.#tn(e.clipboardData,this.#$t(),this.#en()))}),B(e,`cut`,e=>{if(i(e)){if(e.preventDefault(),this.#Ct())e.clipboardData?.setData(`text`,this.#wt());else{let t=this.#en();this.#tn(e.clipboardData,this.#nn(),t)}}}),B(e,`paste`,e=>{if(!i(e))return;e.preventDefault();let t=e.clipboardData,n=this.#n?.document;if(t===null||n===void 0)return;let r=t.getData(`text`),a=this.#oe?.length??0;if(a>1){let e=t.getData(Mi);if(e!==void 0)try{let t=JSON.parse(e);Array.isArray(t)&&t.length===a&&(r=t)}catch{}}this.#in(Array.isArray(r)?r.map(e=>n.normalizeEol(e)):n.normalizeEol(r),void 0,!0,`document`)}),B(e,`beforeinput`,e=>{if(i(e)){if(e.inputType===`insertCompositionText`){this.#Lt(!0);return}e.preventDefault(),this.#ct(e.inputType,e.data)}}),B(e,`drop`,e=>{i(e)&&e.preventDefault()}),B(e,`compositionstart`,e=>{i(e)&&(this.#Lt(!0),this.#Z=!0,this.#q=!0)},{passive:!0}),B(e,`compositionend`,e=>{if(!i(e))return;this.#q=!1;let t=this.#Z;this.#Z=!1,(e.data!==``||!t)&&this.#ct(`insertText`,e.data)},{passive:!0})];let a=this.#S?.shadowRoot?.querySelector(`[data-deletions]`);if(a!=null&&this.#o.push(B(a,`pointerdown`,e=>{let t=e.composedPath();if(k(t)){this.#Je();return}let n=t[0],r=n instanceof HTMLElement?n.closest(`[data-column-number]`):null;if(r instanceof HTMLElement){if(this.#qe()){this.#Je();return}if(this.#St(r,a,e.pointerType===`mouse`))return}this.#Tt(!0),this.#oe!==void 0&&this.#Ut([])},{passive:!0})),t!==void 0){let e=(e,t=!1)=>{let n=e;return n?.dataset.lineNumberContent===void 0?t&&n?.tagName===`SPAN`&&(n=n.closest(`[data-line]`)):n=n.parentElement??void 0,n},n=e=>{if(e===void 0)return;let t=e.dataset.lineType,n=V(e)??V(e,`columnNumber`);if(n!==void 0&&t!==void 0&&mn(t))return n-1};this.#o.push(B(t,`pointerdown`,t=>{let r=t.composedPath();if(k(r)){this.#Je();return}let i=e(r[0]);if(i!==void 0&&this.#qe()){this.#Je();return}if(i?.dataset.lineType===`change-deletion`){let e=i.closest(`[data-code]`);e!=null&&this.#St(i,e,t.pointerType===`mouse`);return}if(t.pointerType!==`mouse`)return;let a=this.#n?.document,o=n(i);if(o===void 0||a===void 0)return;this.#K=!0,this.#H?.removePopover();let s=this.#vt(o,o,a);this.#Q=!0,this.#ne=s,this.#Ut([s]),this.#mt(s),this.#lt(),this.#Ke([B(document,`mousemove`,t=>{if(!this.#Q)return;let r=this.#n?.document,i=n(e(t.composedPath()[0],!0));if(i===void 0||r===void 0)return;let a=this.#ne?.start.line??i,o=this.#vt(a,i,r);this.#ne??=o,this.#Ut([o]),this.#lt(o.direction===-1?o.start:o.end)},{passive:!0})])},{passive:!0}))}this.#H?.listenHover(e),this.#j?.disconnect(),this.#j=new ResizeObserver(this.#at),this.#j.observe(e),this.#j.observe(e.parentElement),this.#Ze(e)}#Xe=async()=>{let e=this.#e.clipboard;if(e!==void 0){let t=await e.readText(),n=this.#oe?.length??0;if(n>1){let r=await e.readText(Mi);try{let e=JSON.parse(r);Array.isArray(e)&&e.length===n&&(t=e)}catch{}}let r=this.#n?.document;r!=null&&this.#in(Array.isArray(t)?t.map(e=>r.normalizeEol(e)):r.normalizeEol(t),void 0,!0,`document`)}};#Ze(e){this.#Fe&&this.#Pe===`split`&&this.#Ie&&(this.#d={top:e.offsetTop-this.#r.paddingTop,left:e.offsetLeft-this.#gn()},this.#e.__debug===!0&&console.log(`[diffs/editor] content offset:`,this.#d))}get#Qe(){if(this.#Fe&&this.#Pe===`split`&&this.#Ie)return this.#d}#$e(e){let t=this.#n?.document;if(t!=null)switch(e){case`openSearchPanel`:this.#Zt(`find`);break;case`openSearchReplacePanel`:this.#Zt(`replace`);break;case`findNextMatch`:{let e=this.#oe;if(e===void 0)break;if(e.some(W)){let n=e.map(e=>W(e)?Rn(t,e):e);this.#Ut(n),this.focus()}else{let n=Tn(t,e);if(n!==void 0){this.#Ut(n);let e=n.at(-1);e!==void 0&&this.#Ne(G(e).line),this.#ht()}}break}case`moveLineUp`:case`moveLineDown`:this.#it(e===`moveLineUp`?-1:1);break;case`copyLineUp`:case`copyLineDown`:this.#nt(e===`copyLineUp`?-1:1);break;case`simplifySelection`:{let e=this.#oe,t=e?.at(-1);if(e===void 0||t===void 0)break;if(e.length>1)this.#Ut([t]),this.#lt(G(t));else if(!W(t)){let e=G(t);this.#Ut([{start:e,end:e,direction:0}]),this.#lt(e)}break}case`insertBlankLine`:this.#rt();break;case`deleteHardLineForward`:this.#cn();break;case`toggleComment`:case`toggleBlockComment`:{let n=this.#oe;if(n===void 0)break;let{lineComment:r,blockComment:i}=Ir(t.languageId,this.#e.languageCommentConfig);if(e===`toggleComment`&&r!==null){this.#tt(Lr(t,n,r));break}let a=e===`toggleComment`,o=Vr(t,n,i,a);o!==void 0&&this.#tt(o.edits,a?void 0:e=>o.nextSelectionOffsets.map(([t,n,r])=>({start:e.positionAt(t),end:e.positionAt(n),direction:r})));break}case`indent`:case`outdent`:case`indentLess`:case`indentMore`:if(this.#oe!==void 0){let n=[],r=[],i=new Set,a=[];for(let o of this.#oe){let s=o.start.line,c=e===`outdent`||e===`indentLess`,l=e===`indentLess`||e===`indentMore`;if(s!==o.end.line||c||l){let e=qt(t,o,this.#r.tabSize,c);for(let t of e[0]){let e=t.range.start.line;i.has(e)||(i.add(e),n.push(t))}r.push(e[1])}else{let e=t.charAt({line:s,character:0})===` `?` `:` `.repeat(this.#r.tabSize);n.push({range:o,newText:e}),a.push({line:s,startCharacter:o.start.character,addedLength:e.length-(o.end.character-o.start.character),selectionIndex:r.length});let i={line:o.start.line,character:o.start.character+e.length};r.push({start:i,end:i,direction:0})}}for(let e of a){let t=0;for(let n of a)n.line===e.line&&n.startCharacter<e.startCharacter&&(t+=n.addedLength);if(t!==0){let n=r[e.selectionIndex],i={line:e.line,character:n.start.character+t};r[e.selectionIndex]={start:i,end:i,direction:0}}}let o=t.applyEdits(n,!0,this.#oe,r);o!==void 0&&this.#un(o,r)}break;case`selectAll`:{let e=En(t);this.#Ut([e]),this.focus();let n=this.#pn(),r=n[0]?.[0],i=n.at(-1)?.[1];r!==void 0&&i!==void 0&&(this.#J=!0,this.#mt({start:{line:r,character:0},end:{line:i,character:t.getLineLength(i)},direction:1}));break}case`moveCursorToDocStart`:case`moveCursorToDocEnd`:{let n=Dn(t,e===`moveCursorToDocEnd`,this.#Fe);this.#Ut([n]),this.#Ne(G(n).line),this.#ht()}break;case`expandSelectionDocStart`:case`expandSelectionDocEnd`:{let n=e===`expandSelectionDocEnd`,r=this.#oe;if(r!==void 0){let e=Dn(t,n,this.#Fe);this.#Ut(xn(r,e)),this.#Ne(G(e).line),this.#ht()}}break;case`undo`:case`redo`:this.#et(e)}}#et(e){let t=this.#n?.document;if(t==null||e===`undo`&&!t.canUndo||e===`redo`&&!t.canRedo)return;let n=this.#oe,r=n?.map(e=>[t.offsetAt(e.start),t.offsetAt(e.end)]),i=e===`undo`?t.undo():t.redo();if(i===void 0)return;let[a,o,s,c]=i,l=o??(n!==void 0&&r!==void 0&&c!==void 0?vn(t,n,r,c):void 0),u=s??(this.#L==null?void 0:jt(a,this.#L));this.#un(a,l,u)}#tt(e,t){let n=this.#n?.document,r=this.#oe;if(n===void 0||r===void 0)return;let i=t===void 0,a=i?r.map(e=>[n.offsetAt(e.start),n.offsetAt(e.end)]):void 0,o=i?e.map(e=>{let t=n.offsetAt(e.range.start),r=n.offsetAt(e.range.end);return{start:Math.min(t,r),end:Math.max(t,r),text:e.newText}}).sort((e,t)=>{let n=e.start-t.start;return n===0?e.end-t.end:n}):void 0,s=n.applyEdits(e,!0,r,void 0,!0);if(s===void 0)return;let c=i?vn(n,r,a,o):t(n);n.setLastUndoSelectionsAfter(c),this.#un(s,c,this.#fn(s))}#nt(e){let t=this.#n?.document,n=this.#oe;if(t===void 0||n===void 0)return;let r=Cn(n);if(r.length===0)return;let i=[],a=0,o=[];for(let n of r){i.push(a);let r=n.endLine-n.startLine+1;a+=r;let s=t.getText({start:{line:n.startLine,character:0},end:{line:n.endLine,character:t.getLineLength(n.endLine)}});if(e>0){let e={line:n.startLine,character:0};o.push({range:{start:e,end:e},newText:s+t.eol})}else if(n.endLine<t.lineCount-1){let e={line:n.endLine+1,character:0};o.push({range:{start:e,end:e},newText:s+t.eol})}else{let e={line:n.endLine,character:t.getLineLength(n.endLine)};o.push({range:{start:e,end:e},newText:t.eol+s})}}let s=n.map(t=>{let n=t.start.line,a=0,o=r.length-1;for(;a<=o;){let e=a+o>>>1,t=r[e];if(n<t.startLine)o=e-1;else if(n>t.endLine)a=e+1;else{a=e;break}}let s=Math.max(0,a<=o?a:o),c=r[s],l=i[s]+(e>0?c.endLine-c.startLine+1:0);return{start:{...t.start,line:t.start.line+l},end:{...t.end,line:t.end.line+l},direction:t.direction}});this.#tt(o,()=>s)}#rt(){let e=this.#n?.document,t=this.#oe;if(e===void 0||t===void 0)return;let n=t.map(e=>G(e).line),r=Array.from(new Set(n)).sort((e,t)=>e-t),i=new Map,a=new Map,o=[];for(let t=0;t<r.length;t++){let n=r[t],s=e.getLineText(n),c=/^\s*/.exec(s)?.[0]??``;i.set(n,t),a.set(n,c);let l={line:n,character:e.getLineLength(n)};o.push({range:{start:l,end:l},newText:e.eol+c})}let s=t.map((e,t)=>{let r=n[t],o={line:r+1+i.get(r),character:a.get(r).length};return{start:o,end:o,direction:0}});this.#tt(o,()=>s)}#it(e){let t=this.#n?.document,n=this.#oe;if(t===void 0||n===void 0)return;let r=Cn(n);if(r.length===0||e<0&&r[0].startLine===0||e>0&&r.at(-1).endLine>=t.lineCount-1)return;let i=t.lineCount,a=e=>e<i-1?{line:e+1,character:0}:{line:e,character:t.getLineLength(e)},o=(e,n)=>{let r=e.map(e=>t.getLineText(e)).join(t.eol);return n?r+t.eol:r},s=[];if(e<0)for(let e of r){let t=e.startLine-1,n=[];for(let t=e.startLine;t<=e.endLine;t++)n.push(t);s.push({range:{start:{line:t,character:0},end:a(e.endLine)},newText:o([...n,t],e.endLine<i-1)})}else for(let e=r.length-1;e>=0;e--){let t=r[e],n=t.endLine+1,c=[];for(let e=t.startLine;e<=t.endLine;e++)c.push(e);s.push({range:{start:{line:t.startLine,character:0},end:a(n)},newText:o([n,...c],n<i-1)})}let c=r.at(-1),l=e>0&&c.endLine===i-2?t.getLineLength(c.endLine):t.getLineLength(i-1),u=n.map(n=>wn(n,e,i,e=>e===i-1?l:t.getLineLength(e))),d=t.applyEdits(s,!0,n,u,!0);d!==void 0&&this.#un(d,u)}#at=()=>{let e=this.#L?.length??0,t=this.#f,n=this.#p;this.#f=void 0,this.#p=void 0;let r=this.#gn()!==t,i=this.#_n()!==n;(r||i)&&(this.#g.clear(),this.#_=void 0,this.#r.clearTextWidthCache(),i&&(this.#h.clear(),(this.#Ie||e>0)&&this.#m.clear()),(this.#oe!==void 0||this.#se!==void 0||this.#H!==void 0)&&(this.#Ut(this.#oe??[]),this.#oe!==void 0&&this.#Y&&this.focus()),this.#H?.removePopover(),this.#Ze(this.#w),this.#Wt())};#ot(){if(this.#pe)return;let e=document.fonts;e!==void 0&&(this.#pe=!0,e.ready.then(()=>{this.#w!==void 0&&this.#r.remeasureCharacterWidth()&&(this.#f=void 0,this.#p=void 0,this.#Re(),this.#h.clear(),(this.#oe!==void 0||this.#se!==void 0||this.#H!==void 0)&&this.#Ut(this.#oe??[]),this.#Wt(),this.#H?.removePopover())}))}#st(e,t,n=this.#B,r){let i=this.#i,a=this.#M,o=this.#N,s=this.#n?.document,c=this.#C,l=this.#w;if(i==null||a==null||o==null||s==null||l==null)return;i.stopBackgroundTokenize();let u=performance.now(),d=i.tokenize(e,n,!this.#Fe&&this.#Ae!=null),f=performance.now();if(d.size>0){let e=l.children,t=new Set;for(let e of d.keys())this.#je(e)&&t.add(e);for(let n=0;n<e.length;n++){let r=e[n];if(r!==void 0){let e=V(r),n=r.dataset.lineType;if(e===void 0||n===`change-deletion`)continue;let i=e-1;if(t.has(i)){let e=d.get(i);if(r.replaceChildren(...bi(e)),t.delete(i),t.size===0)break}}}if(t.size>0){let n=0;for(let t=e.length-1;t>=0;t--){let r=e[t],i=V(r);if(i!==void 0&&r.dataset.lineType!==`change-deletion`){n=i;break}}for(let e of t){if(e<n)continue;let t=d.get(e),r=String(e+1);z(`div`,{dataset:{line:r,lineType:`context`,lineIndex:e.toString()},children:bi(t)},l),c!==void 0&&z(`div`,{dataset:{lineType:`context`,columnNumber:r,lineIndex:e.toString()},children:[z(`span`,{dataset:{lineNumberContent:``},textContent:r})]},c)}}}if(e.lineDelta<0)for(let t of[l.children,c?.children??[]])for(let n=t.length-1;n>=0;n--){let r=t[n],i=V(r)??V(r,`columnNumber`),a=r.dataset.lineType;if(i!==void 0&&a!==`change-deletion`){if(i-1<e.lineCount)break;r.remove()}}let p=e.lineDelta!==0;if(p){let e=l.children.length;for(let t of l.children){let{bufferSize:n}=t.dataset;n!==void 0&&(e+=parseInt(n)-1)}l.style.gridRow=`span `+e,c!==void 0&&(c.style.gridRow=`span `+e)}a.updateRenderCache(d,i.themeType,{shouldRefreshDiffsView:this.#Fe&&!p,lineCountChangeInFlight:p}),p&&o(s,t,r),(p||this.#Fe&&this.#Pe===`unified`)&&this.#Re(),t!=null&&(this.#L=t,(!this.#Fe||!p)&&Lt(t,l,c,a.getAnnotationSlotName)),this.#Wt(),this.#e.__debug===!0&&console.log(`[diffs/editor] re-render in: ${H(performance.now()-f)}ms,`,`tokenize in: ${H(f-u)}ms (${d.size} dirty lines)`)}#ct(e,t){switch(e){case`insertText`:{let e=t??``,n=this.#n?.document,r=this.#oe,i=n!==void 0&&r!==void 0?sn(n,r,e,this.#e.autoSurround):void 0;this.#in(i??e);break}case`insertCompositionText`:break;case`insertLineBreak`:case`insertParagraph`:this.#in(this.#n?.document?.eol??`
|
|
586
586
|
`);break;case`deleteContentBackward`:this.#an();break;case`deleteContentForward`:this.#an(!0);break;case`deleteSoftLineBackward`:case`deleteHardLineBackward`:this.#on();break;case`deleteWordBackward`:this.#sn();break;case`insertTranspose`:this.#ln();break;default:console.warn(`[diffs] Unknown input type: ${e}`,t)}}#lt(e,t=!0,n){this.#Y=!0,e===void 0?n?.()===!1?this.#Y=!1:this.#w?.focus({preventScroll:t}):(this.#q=!0,this.#mt({start:e,end:e,direction:0}),b(()=>{if(n?.()===!1||!this.#Y){this.#q=!1;return}this.#w?.focus({preventScroll:t}),b(()=>{this.#q=!1})}))}#ut(e){let t=this.#X;if(t==null)return;if(this.#fe){this.#X=void 0,this.#Y=!1,this.#q=!1;return}let n=this.#w;if(n==null||!this.#dt(n)){this.#X=void 0,this.#Y=!1;return}let r=()=>{if(this.#X!==t)return!1;let e=this.#dt(n);return this.#X=void 0,e};if(e!=null){this.#lt(e,!0,r);return}let i=this.#oe?.at(-1);if(i==null){this.#lt(void 0,!0,r);return}let a=i.direction===-1?i.end:i.start;this.#lt(a,!0,r)}#dt(e){let t=this.#S,n=t?.shadowRoot;if(t==null||n==null||this.#w!==e||!n.contains(e))return!1;let{activeElement:r}=n;if(r===e||r!=null&&e.contains(r))return!0;if(r!=null)return!1;let{ownerDocument:i}=t,{activeElement:a}=i;return a==null||a===i.body||a===i.documentElement||a===t}#ft(e=0){let t=this.#w,n=this.#S;if(this.#n?.document==null||t==null||n==null)return;let r=this.#He();if(r===void 0)return;let i,a;if(r instanceof HTMLElement){let e=r.getBoundingClientRect();i=e.top,a=e.bottom}else i=0,a=r.defaultView?.innerHeight??0;let o=n.shadowRoot?.querySelector(`[data-diffs-header][data-sticky]`);if(o!=null&&(i=Math.max(i,o.getBoundingClientRect().bottom)),Number.isFinite(e)&&(i+=Math.max(0,e)),!(a<=i))for(let e of t.children){let t=e,n=V(t),r=t.dataset.lineType;if(n==null||r==null||!mn(r))continue;let o=t.getBoundingClientRect();if(!(o.bottom<=o.top)&&o.top>=i&&o.top<a)return n}}#pt(e,t){let n={start:e,end:e,direction:0};this.#K=!1,this.#Ut([n]),this.#Ne(e.line),t?this.#lt(e,!0):this.#ht()}#mt(e){let t=window.getSelection();if(t===null)return;let{start:n,end:r,direction:i}=e;K(n,r)>0&&([n,r]=[r,n]);let a=this.#hn(n.line),o=this.#hn(r.line);if(a===void 0||o===void 0)return;let[s,c]=Ln(a,n.character),[l,u]=Ln(o,r.character);i===-1&&([s,c,l,u]=[l,u,s,c]);try{t.setBaseAndExtent(s,bt(s,c),l,bt(l,u))}catch(e){console.error(`[diffs/editor] failed to update window selection:`,e)}}#ht(e=!1,t=`nearest`){let n=this.#oe?.at(-1);if(n===void 0)return;let r=this.#A;if(r!==void 0){if(r.scrollIntoView({block:t,inline:`nearest`}),!e){let e=n.direction===-1?n.end:n.start;this.#X===void 0?this.#lt(e):this.#ut(e)}}else{let t=G(n);this.#_t(t.line,t.character,e)}}#gt(){let e=this.#W===void 0?0:48,t=this.#gn()+this.#r.ch;return`${e}px ${this.#r.ch}px 0 ${t}px`}#_t(e,t=0,n=!1){this.__postponeBgTokenizeToNextFrame();let r=z(`div`,{style:{position:`absolute`,left:`0`,width:`2px`,height:this.#r.lineHeight+`px`,scrollMargin:this.#gt()}});if(this.#hn(e)!==void 0){let[i,a]=this.#yn(e,t),o=this.#vn(e)+a*this.#r.lineHeight;if(r.style.top=o+`px`,r.style.left=i+`px`,this.#E?.appendChild(r),r.scrollIntoView({block:`center`,inline:`nearest`}),!n){let n={line:e,character:t};this.#X===void 0?this.#lt(n):this.#ut(n)}this.#ce=void 0,this.#le=void 0,this.#ue=!1,this.#de=!1}else{let i=this.#Ae?.getLinePosition?.(e+1);if(i!==void 0)r.style.top=i.top+`px`,this.#S?.shadowRoot?.appendChild(r),r.scrollIntoView({block:`center`,inline:`nearest`}),i.height>0&&this.#je(e)?(this.#ce=e,this.#le=t,this.#de=n):(this.#ce=void 0,this.#le=void 0,this.#de=!1);else{let i=0;if(this.#ce===e&&this.#w!==void 0)for(let t=this.#w.childElementCount-1;t>=0;t--){let n=this.#w.children[t],r=n.dataset.lineType,a=V(n);if(r!==void 0&&mn(r)&&a!==void 0){i=(e-(a-1))*this.#r.lineHeight;break}}let a=((this.#L??[]).filter(t=>t.lineNumber<e).length+e)*this.#r.lineHeight+i;r.style.top=a+`px`,this.#S?.shadowRoot?.appendChild(r),r.scrollIntoView({block:`center`,inline:`nearest`}),this.#ce===e&&(i===0||this.#ue)||!this.#je(e)?(this.#ce=void 0,this.#le=void 0,this.#ue=!1,this.#de=!1):(this.#ce=e,this.#le=t,this.#ue=i!==0,this.#de=n)}}r.remove()}#vt(e,t,n){let r=e=>({line:e,character:0}),i=e=>({line:e,character:n.getLineText(e).length});return t<e?{start:r(t),end:i(e),direction:-1}:{start:r(e),end:i(t),direction:1}}#yt(e){let t=e.composedPath()[0];return t instanceof HTMLElement&&t.closest(`[data-line]`)?.getAttribute(`data-line-type`)===`change-deletion`}#bt(e,t,n){let r=[...n.querySelectorAll(`[data-content] > [data-line]`)],i=r.indexOf(e),a=r.indexOf(t),[o,s]=a<i?[t,e]:[e,t],c=window.getSelection();if(c!==null){let e=document.createRange();e.setStart(o,0),e.setEnd(s,s.childNodes.length),c.removeAllRanges(),c.addRange(e)}this.#Tt(!0),this.#Ut([]),this.#Et(V(t)??null,!0,`deletions`);let l=Math.min(i,a),u=Math.max(i,a);this.#re=l<0?``:r.slice(l,u+1).filter(e=>e.getAttribute(`data-line-type`)===`change-deletion`).map(e=>e.textContent??``).join(`
|
|
587
587
|
`)}#xt(e,t){let n=e.parentElement;if(n==null||t==null)return;let r=[...n.children].indexOf(e),i=t.children[r];return i instanceof HTMLElement?i:void 0}#St(e,t,n){let r=t.querySelector(`[data-content]`),i=this.#xt(e,r);return i!==void 0&&(this.#bt(i,i,t),n&&this.#Ke([B(document,`mousemove`,e=>{let n=e.composedPath()[0],a=n instanceof HTMLElement?n.closest(`[data-column-number]`):null;if(a instanceof HTMLElement&&t.contains(a)){let e=this.#xt(a,r);e!==void 0&&this.#bt(i,e,t)}},{passive:!0})]),!0)}#Ct(){return this.#S?.shadowRoot?.querySelector(`pre`)?.hasAttribute(`data-deleted-text-selection`)??!1}#wt(){return this.#re===``?window.getSelection()?.toString()??``:this.#re}#Tt(e){let t=this.#S?.shadowRoot?.querySelector(`pre`);t!=null&&(e?(t.setAttribute(`data-deleted-text-selection`,``),this.#Et(null),this.#re=``):(t.removeAttribute(`data-deleted-text-selection`),this.#re=``))}#Et(e,t=!1,n=`additions`){try{this.#M?.setEditorActiveLine(e,{lineNumberOnly:t,side:n})}catch{}}#Dt(){this.#me===void 0&&(this.#me=requestAnimationFrame(()=>{this.#me=void 0,(this.#oe!==void 0||this.#se!==void 0||this.#H!==void 0)&&this.#Ut(this.#oe??[])}))}#Ot(){let e=this.#ee,t=this.#ne,n=this.#n?.document;if(e===void 0||e.focusLine===void 0||t===void 0||n===void 0)return!1;let r=t.direction===-1?t.end:t.start,i=this.#w?.parentElement?.scrollLeft??0,a=(e.clientX-e.startClientX+i-e.startScrollLeft)/this.#r.ch,o=a<0?-Math.round(-a):Math.round(a),s=Math.max(0,r.character+o),c={line:e.focusLine,character:s};if(e.renderedGoal!==void 0&&K(e.renderedGoal,c)===0)return!0;e.renderedGoal=c;let l=[],u=c.line<r.line?-1:1;for(let e=r.line;;e+=u){if(this.#je(e)){let t=n.getLineText(e),i=Math.min(r.character,t.length),a=Math.min(s,t.length),o=Xt(t,i),c=a===i?o:Xt(t,a);l.push({start:{line:e,character:Math.min(o,c)},end:{line:e,character:Math.max(o,c)},direction:o===c?0:o<c?1:-1})}if(e===c.line)break}return this.#Ut(l),!0}#kt(){for(let[e,t]of this.#D??[])e.startsWith(`editPrediction`)&&(t.remove(),this.#D?.delete(e))}#At(e,t,n){let r=t[n],i=n,a=r.range.end.line;for(;i+1<t.length&&t[i+1].range.start.line<=a;)i++,a=Math.max(a,t[i].range.end.line);if(i===n&&(r.newText.length===0||K(r.range.start,r.range.end)===0))return{edit:r,endIndex:i};let o=r.range.start,s={line:a,character:e.getLineLength(a)},c=[],l=e.offsetAt(o);for(let r=n;r<=i;r++){let n=t[r],i=e.offsetAt(n.range.start),a=e.offsetAt(n.range.end);c.push(e.getTextSlice(l,i),n.newText),l=a}return c.push(e.getTextSlice(l,e.offsetAt(s))),{edit:{range:{start:o,end:s},newText:c.join(``)},endIndex:i}}#jt(){let e=this.#be,t=this.#n?.document;if(e==null||t==null||e.document!==t||e.version!==t.version||this.#e.editPrediction?.mode===`subtle`&&!this.#ve)return;let{edits:n}=e.response,r=[],i=n.length>0;for(let e=0;e<n.length;){let{edit:a,endIndex:o}=this.#At(t,n,e);for(let e=a.range.start.line;i&&e<=a.range.end.line;e++)i=this.#Cn(e);r.push({edit:a,startIndex:e,endIndex:o}),e=o+1}return{groups:r,allVisible:i}}#Mt(e,t,n,r,i){this.#Ie?(e.dataset.wrap=``,e.style.width=`calc(100cqw - ${r}px)`):(delete e.dataset.wrap,e.style.width=`max-content`);let a=t.split(/\r\n|\r|\n/);for(let t=0;t<a.length;t++){let o=a[t],s=t===a.length-1?i:void 0,c=o.length===0&&s===void 0,l=z(`span`,{dataset:c?[`editPredictionLine`,`empty`]:`editPredictionLine`,textContent:c?``:o},e);s!==void 0&&z(`span`,{dataset:`editPredictionSuffix`},l).append(s),t===0&&n!==r&&(l.style.textIndent=`${n-r}px`)}}#Nt(e){let t=this.#be,n=this.#n?.document;if(t==null||n==null)return;let{edit:r,startIndex:i,endIndex:a}=e,{start:o,end:s}=r.range;if(!(K(o,s)===0&&o.character<n.getLineLength(o.line))||t.response.edits[i-1]?.range.end.line===o.line||t.response.edits[a+1]?.range.start.line===o.line)return;let c=this.#hn(o.line);if(c===void 0)return document.createTextNode(n.getLineText(o.line).slice(o.character));let[l,u]=Ln(c,o.character),d=document.createRange();d.selectNodeContents(c),d.setStart(l,bt(l,u));let f=d.cloneContents();return f.firstChild?.textContent===``&&f.firstChild.remove(),f}#Pt(e){let{edit:t}=e,{start:n}=t.range,[r,i]=this.#yn(n.line,n.character),a=1,o=t.newText.split(/\r\n|\r|\n/).length,s=this.#E;if(this.#Ie&&s!=null){a=Math.max(1,this.#xn(n.line).length-1);let i=z(`span`,{dataset:`editPrediction`,style:{visibility:`hidden`}},s);this.#Mt(i,t.newText,r,this.#yn(n.line,0)[0],this.#Nt(e));let{width:c,height:l}=i.getBoundingClientRect();i.remove();let{lineHeight:u}=this.#r;c>0&&l>0&&u>0&&(o=Math.round(l/u))}return Math.max(0,o-(a-i))}#Ft(e=!0){let t=new Map,n=new Map,r=this.#Ce,i=!1,a=this.#w,o=this.#jt();if(a!=null&&o!=null&&o.allVisible){for(let e of o.groups){let{edit:t}=e;if(t.newText.length===0)continue;let r=this.#Pt(e);r>(n.get(t.range.start.line)??0)&&n.set(t.range.start.line,r)}if(n.size>0){let e,o=this.#B?.startingLine??0;for(let[s,c]of n){i||=r.get(s)!==c;let n=this.#hn(s);if(n===void 0)continue;let l=s-o;if(a.children[l]!==n){if(e===void 0){e=new Map;for(let t=0;t<a.children.length;t++)e.set(a.children[t],t)}l=e.get(n)??-1}if(l<0)continue;t.set(n,c);let u=this.#C?.children[l];u instanceof HTMLElement&&t.set(u,c);let d=this.#It(l);d!=null&&(t.set(d.content,(t.get(d.content)??0)+c),t.set(d.gutter,(t.get(d.gutter)??0)+c))}}}let s=!1;for(let[e,n]of this.#Se)t.get(e)!==n&&(delete e.dataset.editPredictionSpacer,e.style.removeProperty(`--diffs-edit-prediction-spacer-height`),s=!0);for(let[e,n]of t)this.#Se.get(e)!==n&&(e.dataset.editPredictionSpacer=``,e.style.setProperty(`--diffs-edit-prediction-spacer-height`,`${n}lh`),s=!0);this.#Se=t,(i||n.size!==r.size)&&(this.#Ce=n,e&&this.#Ae?.syncGhostTextRows()),s&&this.#Re()}#It(e){let t=this.#T,n=this.#w;if(t==null||n==null||!this.#Fe||this.#Pe!==`split`||this.#Ie)return;let r=0;for(let t=0;t<e;t++)r+=Fi(n.children[t]);let{content:i,gutter:a}=t,o=0;for(let e=0;e<i.children.length;e++){let t=i.children[e];if(o+=Fi(t),o>r){let n=a.children[e];if(!(t instanceof HTMLElement)||!(n instanceof HTMLElement))throw Error(`Editor: deletions column rows and gutter cells are out of step`);return{content:t,gutter:n}}}}#Lt(e,t=!0){this.#he!==void 0&&(clearTimeout(this.#he),this.#he=void 0),this.#ge?.abort(),this.#ge=void 0,this.#_e++,this.#ve=!1,this.#ye=!1,this.#be=void 0,this.#Ft(t),e&&this.#kt()}#Rt(e){let t=this.#e.editPrediction;if(t===void 0)return!1;let n=e.replaceAll(`\\`,`/`);return(t.include===void 0||t.include.some(e=>Mr(n,e)))&&t.exclude?.some(e=>Mr(n,e))!==!0}#zt(){this.#Lt(!0);let e=this.#oe?.[0];if(this.#e.editPrediction===void 0||this.#n?.document===void 0||this.#n?.fileInfo===void 0||this.#oe?.length!==1||e===void 0||!W(e))return;let t=this.#n?.document,n=t.offsetAt(G(e));this.#he=setTimeout(()=>{this.#he=void 0;let e=this.#e.editPrediction,r=this.#oe?.[0],i=this.#n?.fileInfo?.name;if(e===void 0||i===void 0||this.#n?.document!==t||this.#oe?.length!==1||r===void 0||!W(r)||t.offsetAt(G(r))!==n||!this.#Rt(i))return;let a=e=>this.#mn(e)&&this.#je(e);if(!a(G(r).line)){this.#ye=!0;return}let o=jr(i,t,n,this.#xe,a);if(o===void 0)return;let s=t.offsetAt({line:o.excerptStartLine,character:0}),c=s+o.editableRange.start,l=s+o.editableRange.end,u=new AbortController,d=++this.#_e;this.#ge=u;let f;try{f=e.provider.predict(o,{signal:u.signal})}catch{this.#ge=void 0;return}Promise.resolve(f).then(e=>{let r=this.#oe?.[0];if(u.signal.aborted||d!==this.#_e||this.#ge!==u||this.#n?.document!==t||t.version!==o.version||this.#oe?.length!==1||r===void 0||!W(r)||t.offsetAt(G(r))!==n||e==null||!Array.isArray(e.edits)||e.edits.length===0||e.edits.length>Oi||e.newCursor==null)return;let i=[],a=0;for(let n of e.edits){if(n==null||typeof n.newText!=`string`||!Ii(t,n.range?.start)||!Ii(t,n.range?.end)||K(n.range.start,n.range.end)>0||(a+=Ai.encode(n.newText).byteLength,a>ki))return;let e=t.offsetAt(n.range.start),r=t.offsetAt(n.range.end),o=t.resolveEdits([n])[0];if(o.start!==e||o.end!==r)return;i.push(o)}i.sort((e,t)=>{let n=e.start-t.start;return n===0?e.end-t.end:n});for(let e=0;e<i.length;e++){let t=i[e];if(t.start<c||t.end>l||e>0&&i[e-1].end>t.start)return}let s=i.filter(e=>e.text!==t.getTextSlice(e.start,e.end));if(s.length===0)return;let f=t.positionAt(s[0].start),p=t.positionAt(s.at(-1).end),m=t.offsetAt({line:f.line,character:0}),h=t.offsetAt({line:p.line,character:t.getLineLength(p.line)}),g=[],_=m;for(let e of s)g.push(t.getTextSlice(_,e.start),e.text),_=e.end;g.push(t.getTextSlice(_,h));let v=g.join(``).split(/\r\n|\r|\n/),y=f.line+v.length-1,b=v.length-(p.line-f.line+1),x=e.newCursor;if(!(!Number.isInteger(x.line)||!Number.isInteger(x.character)||x.line<0||x.character<0)){if(x.line>=f.line&&x.line<=y){let e=v[x.line-f.line];if(x.character>e.length||Li(e,x.character))return}else{let e=x.line<f.line?x.line:x.line-b;if(e<0||e>=t.lineCount||x.character>t.getLineLength(e))return;let n=t.offsetAt({line:e,character:x.character});if(Li(t.charAt(n-1)+t.charAt(n),1))return}this.#be={document:t,version:o.version,cursorOffset:n,rendered:!1,response:{edits:s.map(e=>({range:{start:t.positionAt(e.start),end:t.positionAt(e.end)},newText:e.text})),newCursor:{...x}}},this.#Ut(this.#oe)}}).catch(()=>{}).finally(()=>{this.#ge===u&&(this.#ge=void 0)})},Di)}#Bt(e,t){let n=this.#n?.document,r=this.#n?.fileInfo?.name,i=tt(e);n!==void 0&&r!==void 0&&i!==void 0&&this.#Rt(r)&&(this.#xe=kr(this.#xe,r,n,i,t))}#Vt(){let e=this.#be,t=this.#n?.document,n=this.#oe?.[0];if(e===void 0||!e.rendered||t===void 0||e.document!==t||e.version!==t.version||this.#oe?.length!==1||n===void 0||!W(n)||t.offsetAt(G(n))!==e.cursorOffset)return;let{edits:r,newCursor:i}=e.response;this.#Lt(!0);let a=t.applyEdits(r.map(e=>({range:{start:{...e.range.start},end:{...e.range.end}},newText:e.newText})),!0,this.#oe,void 0,!0);if(a===void 0){this.#zt();return}let o=t.normalizePosition(i),s=[{start:o,end:o,direction:0}];t.setLastUndoSelectionsAfter(s),this.#un(a,s,this.#fn(a),{editSource:`prediction`})}#Ht(e){let t=this.#be,n=this.#n?.document;t!==void 0&&(t.rendered=!1);let r=this.#jt();if(t!=null&&n!=null&&r!=null&&r.allVisible){for(let t of r.groups){let{edit:r,endIndex:i}=t,{start:a,end:o}=r.range,s=r.newText.length===0,c=K(a,o)!==0,l=n.getLineLength(a.line),u=!c&&a.character<l;if(c?this.#Gt(e,s?`editPredictionDeletion`:`editPredictionReplacement`,{start:a,end:o}):u&&this.#Gt(e,`editPredictionInsertion`,{start:a,end:{line:a.line,character:l}}),s)continue;let[d,f]=this.#yn(a.line,a.character),p=this.#yn(a.line,0)[0],m=this.#vn(a.line)+f*this.#r.lineHeight,h=`editPrediction-${i}`,g=this.#D?.get(h);if(g===void 0?g=z(`span`,{ariaHidden:`true`,contentEditable:`false`,dataset:`editPrediction`},e.fragment):(this.#D?.delete(h),g.replaceChildren()),c){g.dataset.replacement=``;let e=this.#hn(a.line);e!==void 0&&g.style.setProperty(`--diffs-edit-prediction-bg`,getComputedStyle(e).getPropertyValue(`--diffs-line-bg`))}else delete g.dataset.replacement,g.style.removeProperty(`--diffs-edit-prediction-bg`);this.#Mt(g,r.newText,d,p,this.#Nt(t)),g.style.transform=`translateX(${p}px) translateY(${m}px)`,e.elements.set(h,g)}t.rendered=!0}}#Ut(e){this.__postponeBgTokenizeToNextFrame();let t=this.#oe,n=t?.length!==e.length;if(!n&&t!==void 0)for(let r=0;r<e.length;r++){let i=t[r],a=e[r];if(i.direction!==a.direction||K(i.start,a.start)!==0||K(i.end,a.end)!==0){n=!0;break}}if(n&&this.#Lt(!0),this.#Ft(),this.#A=void 0,this.#Et(null),e.length===0&&this.#se===void 0&&this.#H===void 0){this.#oe=void 0,this.#D?.forEach(e=>e.remove()),this.#D?.clear(),this.#G?.cleanup(),this.#G=void 0,n&&this.#zt();return}let r=document.createDocumentFragment(),i={fragment:r,elements:new Map};if(e.length>0){let t=Sn(e),n=t.at(-1);this.#oe=t;let r=t.some(e=>!W(e)),a=G(n).line+1;this.#Et(a,r);for(let e of t)W(e)||this.#Gt(i,`selection`,e),this.#Yt(i,e,e===n);let o=this.#e.matchBrackets!==!1&&this.#n?.document!=null&&this.#i!==void 0&&W(n)?Kr(this.#n?.document,this.#i,n.start):void 0;if(o!==void 0)for(let e of o)this.#Gt(i,`bracketMatch`,e)}let a=this.#n?.document;if(this.#se!==void 0&&a!==void 0){let e=this.#se,t=this.#B,n=t!=null&&Number.isFinite(t.totalLines)||this.#Fe&&this.#ke?.options.expandUnchanged!==!0?this.#pn():void 0,r=this.#oe?.at(-1),o=r===void 0?-1:a.offsetAt(r.start),s=r===void 0?-1:a.offsetAt(r.end),c=0,l=n?.length??1;for(let t=0;t<l;t++){let r=1/0,l=n?.[t];if(l!==void 0){let[t,n]=l,i=a.offsetAt({line:t,character:0}),o=n+1;r=o<a.lineCount?a.offsetAt({line:o,character:0}):a.offsetAt({line:o-1,character:a.getLineLength(o-1)});let s=c,u=e.length;for(;s<u;){let t=s+Math.floor((u-s)/2);e[t][1]<=i?s=t+1:u=t}c=s}for(;c<e.length;c++){let[t,n]=e[c];if(t>=r)break;let l={start:a.positionAt(t),end:a.positionAt(n)},u=o===t&&s===n;this.#Gt(i,`match`,l,u?`focus`:void 0)}}}if(this.#H!==void 0&&a!==void 0)for(let e of this.#H.markers)this.#Gt(i,`marker`,e,ur(e.severity));this.#Ht(i),this.#E?.appendChild(r),this.#D?.forEach(e=>e.remove()),this.#D?.clear(),this.#D=i.elements,this.#Xt(),n&&this.#zt()}#Wt(){let e=this.#U,t=this.#e.renderCaret,n=this.#E;if(this.#k?.forEach(e=>e.remove()),this.#k=void 0,e===void 0||t===void 0||n===void 0){this.#O?.forEach(e=>e.remove()),this.#O=void 0;return}let r=this.#O??=new Map;for(let[e,t]of r)this.#Cn(e.caret.focus.line)||(t.remove(),r.delete(e));let i=document.createDocumentFragment(),a=[];for(let n of e){let{caret:e}=n,{line:o,character:s}=e.focus;if(n.anchorOffset!==n.focusOffset){let t={fragment:i,elements:new Map};this.#Gt(t,`caretHighlight`,n.anchorOffset<n.focusOffset?{start:e.anchor,end:e.focus}:{start:e.focus,end:e.anchor},void 0,e.focus);for(let n of t.elements.values())n.style.setProperty(`--diffs-caret-highlight-bg`,`color-mix(in srgb, ${e.metadata.color} 32%, transparent)`),a.push(n)}if(!this.#Cn(o))continue;let c=r.get(n);c===void 0&&(c=z(`div`,{dataset:`remoteCaret`,children:[t(e)]},i),r.set(n,c));let[l,u]=this.#yn(o,s),d=this.#vn(o)+u*this.#r.lineHeight;c.style.transform=`translateX(${l}px) translateY(${d}px)`}this.#k=a,n.appendChild(i)}#Gt(e,t,n,r,i){if(this.#n?.document==null)return;let{start:a,end:o}=n,s=a.line,c=o.line+1;if(this.#B!==void 0){let{startingLine:e,totalLines:t}=this.#B;s=Math.max(s,e),c=Math.min(c,e+t)}for(let n=s;n<c;n++){if(!this.#Cn(n))continue;let s=n===o.line,c=n===a.line?a.character:0,l=s?o.character:this.#n?.document.getLineLength(n);if(c===l&&(t===`editPredictionDeletion`||t===`editPredictionReplacement`)){if(s&&n!==a.line)continue;let[i,o]=this.#yn(n,c);this.#Jt(e,t,n,o,i,this.#r.ch,r);continue}if(this.#Ie){let a=this.#_n(),o=this.#n?.document.getLineText(n);if(2*this.#r.ch+this.#r.measureTextWidth(o)>a){this.#Kt(e,n,o,c,l,s,t,r,i);continue}}let u=0,d=0,f=0;u=c===0?this.#gn()+this.#r.ch+(this.#Qe?.left??0):this.#yn(n,c)[0],!s&&t===`selection`&&(f=this.#r.ch),d=c===l?f:this.#yn(n,l)[0]-u+f,this.#Jt(e,t,n,0,u,d,r,{start:i?.line===a.line&&i.character===a.character&&n===a.line,end:i?.line===o.line&&i.character===o.character&&n===o.line})}}#Kt(e,t,n,r,i,a,o,s,c){let l=this.#xn(t),u=l.length-1,d=this.#gn()+this.#r.ch+(this.#Qe?.left??0);for(let f=0;f<u;f++){let p=l[f],m=l[f+1],h=Math.max(r,p),g=Math.min(i,m);if(h>g)continue;let _=this.#qt(n,p,h),v=d+_,y=0;!a&&f===u-1&&o===`selection`&&(y=this.#r.ch);let b=h===g?y:this.#qt(n,p,g)-_+y;this.#Jt(e,o,t,f,v,b,s,{start:c?.line===t&&c.character===r&&h===r,end:c?.line===t&&c.character===i&&g===i})}}#qt(e,t,n){if(n<=t)return 0;let r=e.slice(t,n),i=hi(r,this.#r.tabSize);return i===-1?this.#r.measureTextWidth(r):i*this.#r.ch}#Jt(e,t,n,r,i,a,o,s){if(a===0)return;let{ch:c,lineHeight:l}=this.#r,u=this.#vn(n)+r*l,d=`${t}-${n}/${r}-${i}-${a} ${o??``}`,f=this.#D,p=(this.#e.roundedSelection??!0)&&(t===`selection`||t===`caretHighlight`),m=(n,r,i,a)=>{let o=this.#vn(n)+r*l,s=this.#hn(n),u=`initial`;s!==void 0&&(s.dataset.lineType===`change-addition`||s.dataset.selectedLine!==void 0)&&(u=getComputedStyle(s).getPropertyValue(`--diffs-line-bg`));let d=`width:${c}px;transform:translateX(${i}px) translateY(${o}px);--diffs-selection-corner-bg:${u}`,p={selectionCorner:``,[a]:``},m=`${t}-block-${n}/${r}-${i}-1ch`,h=m+`-`+a;if(a===`rbl`){let t=m+`-rtl`,n=e.elements.get(t);n!==void 0&&(n.remove(),e.elements.delete(t),h+=`-rtl`,p.rtl=``)}let g=e.elements.get(h);g===void 0&&(f?.has(h)===!0?(g=f.get(h),g.style.cssText=d,f.delete(h)):g=z(`div`,{dataset:t===`caretHighlight`?`caretHighlightRange`:`selectionRange`,style:{cssText:d},children:[z(`div`,{dataset:p})]},e.fragment),e.elements.set(h,g))},h=t=>{let o=i+a,l=t.dataset,u=e.previousSelectionRange;if((u===void 0||u.line!==n||u.wrapLine!==r)&&(e.previousSelectionRange={element:t,line:n,wrapLine:r,left:i,width:a}),u===void 0||o<=u.left)[`rtl`,`rtr`,`rbl`,`rbr`].forEach(e=>{l[e]=``});else{let e=u.line,t=u.wrapLine,a=u.left,s=u.element.dataset,d=a+u.width;a>i&&m(e,t,a-c,`rbr`),delete s.rbl,delete l.rtl,delete l.rtr,o>=d&&delete s.rbr,o>d&&(m(e,t,d,`rbl`),l.rtr=``),o<d&&m(n,r,o,`rtl`),i<a&&(l.rtl=``),l.rbl=``,l.rbr=``}s?.start===!0&&(delete l.rtl,delete l.rbl),s?.end===!0&&(delete l.rtr,delete l.rbr)},g=e.elements.get(d);if(g!==void 0){p&&h(g);return}if(f?.has(d)===!0?(g=f.get(d),f.delete(d)):g=z(`div`,{dataset:o?[t+`Range`,o]:t+`Range`},e.fragment),g.style.width=`${a}px`,g.style.transform=`translateX(${i}px) translateY(${u}px)`,t===`editPredictionInsertion`||t===`editPredictionReplacement`){let e=this.#hn(n);e!==void 0&&g.style.setProperty(`--diffs-edit-prediction-bg`,getComputedStyle(e).getPropertyValue(`--diffs-line-bg`))}else g.style.removeProperty(`--diffs-edit-prediction-bg`);p&&h(g),e.elements.set(d,g)}#Yt(e,t,n){let{line:r,character:i}=G(t);if(!this.#Cn(r))return;let[a,o]=this.#yn(r,i),s=`caret-`+r+`/`+o+`:`+i;if(e.elements.has(s))return;let c=z(`div`,{dataset:`caret`,style:{transform:`translateX(${a-1}px) translateY(${this.#vn(r)+o*this.#r.lineHeight}px)`}},e.fragment);e.elements.set(s,c),n&&(c.style.scrollMargin=this.#gt(),this.#A=c)}#Xt(){let e=this.#oe?.at(-1),t=this.#E,n=this.#n?.document,r=this.#e.renderSelectionAction,i=()=>{this.#G?.cleanup(),this.#G=void 0};if(this.#e.enabledSelectionAction!==!0||r===void 0||e===void 0||W(e)||this.#$||t===void 0||n===void 0){i();return}let a=G(e);if(!this.#Cn(a.line)){i();return}if(this.#G===void 0){if(!this.#K)return;let a=()=>this.#oe?.at(-1)??e,o=r({textDocument:n,get selection(){return a()},applyEdits:e=>this.applyEdits(e),getSelectionText:()=>this.#n?.document?.getText(a())??``,replaceSelectionText:e=>{this.#in(e,[a()])},close:()=>{i(),this.#ht()}});this.#G=new ci(o,t,()=>this.#Xt()),this.#Le().resetPlacement(ji)}let o=this.#r.lineHeight,s=e.direction===-1,c={placeAbove:s,anchor:a},l=s?{placeAbove:!1,anchor:e.end}:{placeAbove:!0,anchor:e.start},u=this.#G.height,d=e=>{let[t,n]=this.#yn(e.anchor.line,e.anchor.character),r=this.#vn(e.anchor.line)+n*o,i=e.placeAbove?r:r+o,a=e.placeAbove?i-u:i;return{top:a,bottom:a+u,left:t,anchorTop:i,rowTop:r}},f=d(c),p=n.lineCount,m=s?a.line<3:a.line>=p-3,h=this.#Cn(l.anchor.line)?d(l):void 0,g=this.#Le(),_=g.getPlacementBounds(),v=h!==void 0&&g.choosePlacement({preferred:f,fallback:h,viewport:_,popoverHeight:u,atDocumentEdge:m,placementKey:ji})===`fallback`;h===void 0&&g.setPlacement(`preferred`,ji);let{placeAbove:y}=v?l:c,{left:b,anchorTop:x}=v&&h!==void 0?h:f,S=s?f.rowTop:h?.rowTop??-1/0,C=(s?h?.rowTop??1/0:f.rowTop)+(e.end.line>e.start.line&&e.end.character===0?0:o),w=_===void 0||C>_.top&&S<_.bottom;this.#G.reposition(b,x,this.#gn(),y,w,_)}#Zt(e){if(this.#W!==void 0){this.#W.setMode(e);return}this.#Qt(e)}#Qt(e){this.#W?.cleanup();let t=this.#n?.document,n=this.#S?.shadowRoot?.querySelector(`pre`),r=this.#oe;if(t===void 0||n==null)return;let i=``,a;if(r!==void 0&&r.length>0){let e=r.at(-1);if(W(e)){e=Rn(t,e),this.#Ut([...r.slice(0,-1),e]);let n=t.getText(e);n!==``&&!n.includes(`
|
|
588
|
-
`)&&(i=n,a=[t.offsetAt(e.start),t.offsetAt(e.end)])}}let o=([e,n],r)=>{let i=gn(t,e,n);this.#Ut([i]),this.#Ne(G(i).line),this.#ht(!0),this.#fe=r},s=new si({textDocument:t,containerElement:n,defaultQuery:i,mode:e,initialMatch:a,scrollToMatch:o,applyReplace:e=>{if(e.length===0)return;let n=t.applyEdits(e.map(e=>({range:{start:t.positionAt(e.start),end:t.positionAt(e.end)},newText:e.text})),!0,this.#oe);n!==void 0&&this.#un(n,void 0,this.#fn(n),{skipSearchRefresh:!0})},onUpdate:(e,n)=>{if(e.length===0){this.#se=void 0,this.#Ut(this.#oe??[]);return}if(this.#se=e,n?.syncSelection===!1){this.#Ut(this.#oe??[]);let n=this.#oe?.at(-1);if(n!==void 0){let r=t.offsetAt(n.start),i=t.offsetAt(n.end);for(let t of e)if(t[0]===r&&t[1]===i)return t}return}let r=this.#oe?.at(-1),i=0,a;r!==void 0&&(i=t.offsetAt(r.start));for(let t of e)if(t[0]>=i){a=t;break}return a===void 0?this.#Ut(this.#oe??[]):o(a,!0),a},onClose:()=>{this.#W=void 0,this.#fe=!1,this.#se=void 0,this.#Ut(this.#oe??[])}});this.#W=s,this.#fe=!1}#$t(){let e=this.#n?.document,t=this.#oe;return e===void 0||t===void 0?``:jn(e,t)}#en(){let e=this.#n?.document,t=this.#oe;return e===void 0||t===void 0?[]:An(e,t)}#tn(e,t,n){e!==null&&(e.setData(`text`,t),n.length>1&&e.setData(Mi,JSON.stringify(n)))}#nn(){let e=this.#n?.document,t=this.#oe;if(e===void 0||t===void 0||t.length===0)return``;if(t.some(e=>W(e))){let n=In(e,t);return this.#rn(n.edits,n.nextSelectionOffsets),n.text}let n=jn(e,t);return this.#in(``,void 0,!0),n}#rn(e,t){let n=this.#n?.document,r=this.#oe;if(n===void 0||r===void 0||e.length===0)return;let i=n.applyResolvedEdits(e,!0,r,void 0,!0);if(i===void 0)return;let a=t.map(e=>{let t=n.positionAt(e);return{start:t,end:t,direction:0}});n.setLastUndoSelectionsAfter(a),this.#un(i,a,this.#fn(i))}#in(e,t=this.#oe,n=!1,r=`selection`){if(t===void 0)return;let i=this.#n?.document,a=t.at(-1);if(i===void 0||a===void 0)return;let{nextSelections:o,change:s}=Array.isArray(e)&&e.length===t.length?an(i,t,e,this.#L,n,r):tn(i,t,{start:i.offsetAt(a.start),end:i.offsetAt(a.end),text:Array.isArray(e)?e.join(i.eol):e},this.#L,void 0,n);s!==void 0&&this.#un(s,o,this.#fn(s))}#an(e=!1){let t=this.#oe,n=this.#n?.document;if(t===void 0||n===void 0)return;let{nextSelections:r,change:i}=pn(n,t,e,this.#L,this.#r.tabSize);i!==void 0&&this.#un(i,r,this.#fn(i))}#on(){let e=this.#oe,t=this.#n?.document;if(e===void 0||t===void 0)return;let{nextSelections:n,change:r}=un(t,e,this.#Ie?(e,t)=>{let n=this.#xn(e);for(let e=0;e+1<n.length;e++){let r=n[e],i=n[e+1];if(t>=r&&t<=i)return r}return 0}:void 0,this.#L);r!==void 0&&this.#un(r,n,this.#fn(r))}#sn(){let e=this.#oe,t=this.#n?.document;if(e===void 0||t===void 0)return;let{nextSelections:n,change:r}=dn(t,e,this.#L);r!==void 0&&this.#un(r,n,this.#fn(r))}#cn(){let e=this.#oe,t=this.#n?.document;if(e===void 0||t===void 0)return;let{nextSelections:n,change:r}=ln(t,e,this.#L);r!==void 0&&this.#un(r,n,this.#fn(r))}#ln(){let e=this.#oe,t=this.#n?.document;if(e===void 0||t===void 0)return;let{nextSelections:n,change:r}=cn(t,e,this.#L);r!==void 0&&this.#un(r,n,this.#fn(r))}#un(e,t,n,r){this.#be!=null&&this.#Lt(!0);let i=this.#n?.document;if(i!==void 0&&this.#U!==void 0)for(let t of this.#U)t.anchorOffset=_n(t.anchorOffset,e.changes),t.focusOffset=_n(t.focusOffset,e.changes),t.caret.anchor=i.positionAt(t.anchorOffset),t.caret.focus=i.positionAt(t.focusOffset);if(e.lineDelta!==0||this.#Ie)for(let t of this.#m.keys())t>=e.startLine&&this.#m.delete(t);if(this.#h.size>0){if(e.lineDelta===0&&(e.changedLineRanges.length===1||e.changedLineChanges?.every(([,,e])=>e===0)===!0))for(let[t,n]of e.changedLineRanges)for(let e=t;e<=n;e++)this.#h.delete(e);else for(let t of this.#h.keys())t>=e.startLine&&this.#h.delete(t)}this.#_=void 0;let a=this.#B,o;if(a!==void 0&&t!==void 0&&t.length>0){let n=t.at(-1),r=a.startingLine+a.totalLines;if(n.end.line>=r){let t=n.end.line-a.startingLine+1,i=this.#V===void 0||this.#V===1/0?1/0:this.#V*Ti;e.startLine<=r&&t<=i&&this.#je(n.end.line)?(n.end.line>r&&(o=!0),a={...a,totalLines:t},this.#B=a):o=!0}}if(this.#st(e,n,a,o),t!=null&&this.#Ut(t),this.#M?.__acknowledgeDocumentUpdate(),this.#Ee(),this.#Bt(e,r?.editSource??`user`),this.#zt(),this.#dn(e.changes,n??this.#L),r?.skipSearchRefresh!==!0&&this.#W!==void 0&&this.#se!==void 0&&this.#W.updateMatches({syncSelection:!1}),t!=null&&r?.skipFocus!==!0){let e=t.at(-1);if(e!==void 0&&this.#Ne(G(e).line),this.#A!==void 0)requestAnimationFrame(()=>{this.#A?.scrollIntoView({block:`nearest`,inline:`nearest`})});else if(t.length>0){let e=G(t.at(-1));this.#_t(e.line,e.character)}this.focus({preventScroll:!0})}}#dn(e,t){let n=this.getFile(),r=this.#P;n!=null&&r!=null&&r(e,n,t)}#fn(e){if(this.#L!=null){let t=jt(e,this.#L);if(t!=null)return this.#n?.document?.setLastUndoLineAnnotations(this.#L,t),t}}#pn(){let e=this.#w;if(e===void 0)return[];let t=[];for(let n of e.children){let e=n,r=e.dataset.lineType,i=V(e);if(i===void 0||r===void 0||!mn(r))continue;let a=i-1,o=t.at(-1);o!==void 0&&a<=o[1]+1?o[1]=Math.max(o[1],a):t.push([a,a])}return t}#mn(e){let t=this.#B;return t==null||e>=t.startingLine&&e<t.startingLine+t.totalLines}#hn(e){let t=this.#g.get(e);if(t!==void 0)return t??void 0;let n=this.#B;if(!this.#mn(e))return;let r=this.#w;if(r!==void 0){if(n!==void 0){let{startingLine:i}=n,{children:a}=r;for(let n=e-i;n<=a.length;n++){let r=a[n];if(r===void 0)break;let i=V(r),o=r.dataset.lineType;if(i!==void 0&&i===e+1&&o!==void 0&&mn(o)){t=r;break}}}return t??=r.querySelector(`[data-line="${e+1}"]`+(this.#Pe===`unified`?`:not([data-line-type="change-deletion"])`:``)),t!==void 0&&this.#g.set(e,t),t??void 0}}#gn(){if(this.#C===void 0)return 0;if(this.#f===void 0){let e=this.#w?.parentElement?.style.getPropertyValue(`--diffs-column-number-width`);this.#f=e!==void 0&&e.length>2&&e.endsWith(`px`)?parseInt(e.slice(0,-2),10):this.#C.offsetWidth}return this.#f}#_n(){if(this.#w===void 0)return 0;if(this.#p===void 0){let e=this.#w.parentElement?.style.getPropertyValue(`--diffs-column-content-width`);this.#p=e!==void 0&&e.length>2&&e.endsWith(`px`)?parseFloat(e.slice(0,-2)):this.#w.offsetWidth}return this.#p}#vn(e){let t=this.#m.get(e);if(t!==void 0)return t;let n=this.#hn(e);if(n===void 0)return-1;let r=n.offsetTop+this.#r.paddingTop;return r+=this.#Qe?.top??0,this.#m.set(e,r),r}#yn(e,t){if(this.#_!==void 0&&this.#_[0]===e&&this.#_[1]===t)return[this.#_[2],this.#_[3]];let n=this.#n?.document?.getLineText(e),r=this.#gn()+this.#r.ch;if(n===void 0||n.length===0||t<=0)return[r+(this.#Qe?.left??0),0];let i=pi(n,Math.min(t,n.length)),a=n.slice(0,i),o=hi(a,this.#r.tabSize),s=0,c=0;if(s=o===-1?r+this.#r.measureTextWidth(a):r+o*this.#r.ch,this.#Ie){let t=this.#_n();if(2*this.#r.ch+this.#r.measureTextWidth(n)>t){let t=this.#bn(e);if(t==null)return[s+(this.#Qe?.left??0),0];for(let e=0;e+1<t.length;e++){let a=t[e];if(i<=t[e+1]){c=e;let t=n.slice(a,i),o=hi(t,this.#r.tabSize);s=o===-1?r+this.#r.measureTextWidth(t):r+o*this.#r.ch;break}}}s+=this.#Qe?.left??0}return this.#_===void 0?this.#_=[e,t,s,c]:(this.#_[0]=e,this.#_[1]=t,this.#_[2]=s,this.#_[3]=c),[s,c]}#bn(e){let t=this.#h.get(e);if(t!==void 0)return t;this.#h.size>=Ei&&this.#h.clear();let n=this.#n?.document?.getLineText(e);if(n===void 0||n.length===0){let t=new Uint32Array([0]);return this.#h.set(e,t),t}let r=this.#w;if(r==null||!r.isConnected)return;let i=z(`div`,{style:{position:`absolute`,top:`0`,left:`0`,width:`100%`,boxSizing:`border-box`,visibility:`hidden`,pointerEvents:`none`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,font:`inherit`,paddingInline:`1ch`,tabSize:this.#r.tabSize.toString()},textContent:n},r),a=i.firstChild,o=document.createRange(),s=[];try{let t=i.getBoundingClientRect();if(t.width===0)return;let r=mi(n),c=t.left+this.#r.ch,l=r===void 0?n.length:r.length-1,u=e=>r===void 0?e:r[e],d=e=>{o.setStart(a,u(e)),o.setEnd(a,u(e+1));let t=o.getClientRects();return t.item(t.length-1)??o.getBoundingClientRect()};s.push(0);let f=d(0).top,p=1;for(;p<l;){let e=p,t=l;for(;e<t;){let n=e+t>>1;d(n).top>f?t=n:e=n+1}if(e>=l)break;let{left:n,top:r}=d(e),i=h()&&n-c>this.#r.ch/2;s.push(u(i?e-1:e)),f=r,p=e+1}let m=new Uint32Array(s.length+1);for(let e=0;e<s.length;e++)m[e]=s[e];return m[s.length]=n.length,this.#h.set(e,m),m}finally{i.remove()}}#xn(e){let t=this.#bn(e);if(t!==void 0)return t;let n=this.#n?.document?.getLineText(e)?.length??0;return Uint32Array.of(0,n)}#Sn({startContainer:e,endContainer:t}){let n=this.#w;return n!==void 0&&n.contains(e)&&n.contains(t)}#Cn(e){let t=this.#n?.document?.lineCount??0;return e<0||e>=t?!1:this.#hn(e)!==void 0}};function Pi({type:e,editStateKey:t,owner:n,initialState:r,previousSession:i}){if(r!=null&&r.type!==e)throw TypeError(`Editor: initialState: a ${r.type} state cannot initialize a ${e} editor`);let a=r;return t==null?a??i??(e===`file`?{type:`file`}:{type:`file-diff`}):dt.activate(e,t,n,a)}function Fi(e){return e instanceof HTMLElement?Number(e.dataset.bufferSize??1):1}function Ii(e,t){return t!==void 0&&Number.isInteger(t.line)&&Number.isInteger(t.character)&&t.line>=0&&t.line<e.lineCount&&t.character>=0&&t.character<=e.getLineLength(t.line)}function Li(e,t){let n=e.charCodeAt(t-1),r=e.charCodeAt(t);return t>0&&t<e.length&&n>=55296&&n<=56319&&r>=56320&&r<=57343}r();var Ri=n();function zi(e,t,n,r,i){let o=(0,Ri.c)(15),c;o[0]!==r||o[1]!==n||o[2]!==e||o[3]!==t?(c=ie(r,e,t,n),o[0]=r,o[1]=n,o[2]=e,o[3]=t,o[4]=c):c=o[4];let l=c,u=s(ne),d;o[5]!==r||o[6]!==i||o[7]!==e||o[8]!==t||o[9]!==u||o[10]!==l?(d=function(n){if(!n)return;let o=document.createElement(`div`);n.append(o);let s=new _e;s.setup(n,o);let c=()=>({...v(u.get(se),{overflow:u.get(ae).lineOverflow}),onEditChange:e=>{a(r.change(e.file.contents))},onEditComplete:Bi}),d=new j(c(),s);d.render({file:l.file,containerWrapper:o});let f=new Ni(`file`,{onAttach(e){n.matches(`:focus-within`)||e.focus({lineNumber:1,character:0})},onBlur(){r.state.value.error||a(r.save())}});r.attachEditor(e),f.edit(d);let p=()=>{d.setOptions(c()),d.rerender()},m=u.subscribe(ae,p),h=u.subscribe(se,p);return()=>{m(),h(),f.cleanUp(`discard`),d.cleanUp(),s.cleanUp(),o.remove(),a(r.finishEditing(e,()=>i(t),()=>F(r,e,l)))}},o[5]=r,o[6]=i,o[7]=e,o[8]=t,o[9]=u,o[10]=l,o[11]=d):d=o[11];let f=d,p;return o[12]!==f||o[13]!==l.initialText?(p={initialText:l.initialText,attach:f},o[12]=f,o[13]=l.initialText,o[14]=p):p=o[14],p}function Bi(){return`reject`}var $=i();function Vi(e){let n=(0,Ri.c)(42),{owner:r,path:i,draft:a,state:s,active:c,changed:l,onDone:u,onDiscard:d,renderToolbar:f}=e,p=a.blocked,m;n[0]!==a||n[1]!==r?(m=te(r,a,ee.add),n[0]=a,n[1]=r,n[2]=m):m=n[2];let{copyDraft:h,save:g,done:_,discard:v,notifyUnsaved:b}=m,{initialText:x,attach:S}=zi(r,i,s.text,a,b),C;n[3]!==p||n[4]!==x||n[5]!==s?(C=Hi(s,p,x),n[3]=p,n[4]=x,n[5]=s,n[6]=C):C=n[6];let w=C,T;n[7]===w?T=n[8]:(T=(0,$.jsx)(`span`,{role:`status`,className:`text-xs text-muted-foreground`,children:w}),n[7]=w,n[8]=T);let E;n[9]!==_||n[10]!==u?(E=()=>void _(u),n[9]=_,n[10]=u,n[11]=E):E=n[11];let D;n[12]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,$.jsx)(t,{className:`size-3.5`}),n[12]=D):D=n[12];let O;n[13]!==p||n[14]!==E?(O=(0,$.jsxs)(o,{size:`sm`,disabled:p,onClick:E,children:[D,`Done`]}),n[13]=p,n[14]=E,n[15]=O):O=n[15];let k;n[16]!==T||n[17]!==O?(k=(0,$.jsxs)($.Fragment,{children:[T,O]}),n[16]=T,n[17]=O,n[18]=k):k=n[18];let A=k,j;n[19]!==c||n[20]!==g?(j=c&&(0,$.jsx)(Ui,{onSave:()=>void g()}),n[19]=c,n[20]=g,n[21]=j):j=n[21];let M;n[22]!==A||n[23]!==f?(M=f?.(A),n[22]=A,n[23]=f,n[24]=M):M=n[24];let N;n[25]===l?N=n[26]:(N=l&&(0,$.jsx)(`p`,{className:`border-b bg-graph-4/10 px-3.5 py-1.5 text-xs text-graph-4`,children:`Saving edits the changes you are reviewing.`}),n[25]=l,n[26]=N);let P;n[27]!==p||n[28]!==h||n[29]!==v||n[30]!==d||n[31]!==g||n[32]!==s.error?(P=s.error!==null&&s.error!==void 0&&(0,$.jsxs)(`div`,{role:`alert`,className:`flex items-center gap-2 border-b px-3.5 py-2 text-xs text-destructive`,children:[(0,$.jsxs)(`span`,{className:`flex-1`,children:[p?`The file changed on disk since you opened it. Reload it before saving.`:y(s.error),` `,`Your draft is kept here.`]}),(0,$.jsx)(o,{size:`xs`,variant:`outline`,onClick:h,children:`Copy draft`}),!p&&(0,$.jsx)(o,{size:`xs`,variant:`outline`,onClick:()=>void g(),children:`Retry save`}),(0,$.jsx)(o,{size:`xs`,variant:`ghost`,onClick:()=>v(d),children:p?`Reload`:`Discard draft and reload`})]}),n[27]=p,n[28]=h,n[29]=v,n[30]=d,n[31]=g,n[32]=s.error,n[33]=P):P=n[33];let F;n[34]===S?F=n[35]:(F=(0,$.jsx)(`div`,{ref:S,className:`min-h-0 flex-1 overflow-auto`}),n[34]=S,n[35]=F);let I;return n[36]!==N||n[37]!==P||n[38]!==F||n[39]!==j||n[40]!==M?(I=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[j,M,N,P,F]}),n[36]=N,n[37]=P,n[38]=F,n[39]=j,n[40]=M,n[41]=I):I=n[41],I}function Hi(e,t,n){return t?`Not saving: changed on disk`:e.error?`Not saved`:e.saving?`Saving…`:e.text===e.savedText?e.text===n?`Saves as you pause`:`Saved`:`Unsaved changes`}function Ui(e){let t=(0,Ri.c)(1),{onSave:n}=e,r;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={ignoreInputs:!1},t[0]=r):r=t[0],re(A.saveFile,n,r),null}export{Vi as default};
|
|
588
|
+
`)&&(i=n,a=[t.offsetAt(e.start),t.offsetAt(e.end)])}}let o=([e,n],r)=>{let i=gn(t,e,n);this.#Ut([i]),this.#Ne(G(i).line),this.#ht(!0),this.#fe=r},s=new si({textDocument:t,containerElement:n,defaultQuery:i,mode:e,initialMatch:a,scrollToMatch:o,applyReplace:e=>{if(e.length===0)return;let n=t.applyEdits(e.map(e=>({range:{start:t.positionAt(e.start),end:t.positionAt(e.end)},newText:e.text})),!0,this.#oe);n!==void 0&&this.#un(n,void 0,this.#fn(n),{skipSearchRefresh:!0})},onUpdate:(e,n)=>{if(e.length===0){this.#se=void 0,this.#Ut(this.#oe??[]);return}if(this.#se=e,n?.syncSelection===!1){this.#Ut(this.#oe??[]);let n=this.#oe?.at(-1);if(n!==void 0){let r=t.offsetAt(n.start),i=t.offsetAt(n.end);for(let t of e)if(t[0]===r&&t[1]===i)return t}return}let r=this.#oe?.at(-1),i=0,a;r!==void 0&&(i=t.offsetAt(r.start));for(let t of e)if(t[0]>=i){a=t;break}return a===void 0?this.#Ut(this.#oe??[]):o(a,!0),a},onClose:()=>{this.#W=void 0,this.#fe=!1,this.#se=void 0,this.#Ut(this.#oe??[])}});this.#W=s,this.#fe=!1}#$t(){let e=this.#n?.document,t=this.#oe;return e===void 0||t===void 0?``:jn(e,t)}#en(){let e=this.#n?.document,t=this.#oe;return e===void 0||t===void 0?[]:An(e,t)}#tn(e,t,n){e!==null&&(e.setData(`text`,t),n.length>1&&e.setData(Mi,JSON.stringify(n)))}#nn(){let e=this.#n?.document,t=this.#oe;if(e===void 0||t===void 0||t.length===0)return``;if(t.some(e=>W(e))){let n=In(e,t);return this.#rn(n.edits,n.nextSelectionOffsets),n.text}let n=jn(e,t);return this.#in(``,void 0,!0),n}#rn(e,t){let n=this.#n?.document,r=this.#oe;if(n===void 0||r===void 0||e.length===0)return;let i=n.applyResolvedEdits(e,!0,r,void 0,!0);if(i===void 0)return;let a=t.map(e=>{let t=n.positionAt(e);return{start:t,end:t,direction:0}});n.setLastUndoSelectionsAfter(a),this.#un(i,a,this.#fn(i))}#in(e,t=this.#oe,n=!1,r=`selection`){if(t===void 0)return;let i=this.#n?.document,a=t.at(-1);if(i===void 0||a===void 0)return;let{nextSelections:o,change:s}=Array.isArray(e)&&e.length===t.length?an(i,t,e,this.#L,n,r):tn(i,t,{start:i.offsetAt(a.start),end:i.offsetAt(a.end),text:Array.isArray(e)?e.join(i.eol):e},this.#L,void 0,n);s!==void 0&&this.#un(s,o,this.#fn(s))}#an(e=!1){let t=this.#oe,n=this.#n?.document;if(t===void 0||n===void 0)return;let{nextSelections:r,change:i}=pn(n,t,e,this.#L,this.#r.tabSize);i!==void 0&&this.#un(i,r,this.#fn(i))}#on(){let e=this.#oe,t=this.#n?.document;if(e===void 0||t===void 0)return;let{nextSelections:n,change:r}=un(t,e,this.#Ie?(e,t)=>{let n=this.#xn(e);for(let e=0;e+1<n.length;e++){let r=n[e],i=n[e+1];if(t>=r&&t<=i)return r}return 0}:void 0,this.#L);r!==void 0&&this.#un(r,n,this.#fn(r))}#sn(){let e=this.#oe,t=this.#n?.document;if(e===void 0||t===void 0)return;let{nextSelections:n,change:r}=dn(t,e,this.#L);r!==void 0&&this.#un(r,n,this.#fn(r))}#cn(){let e=this.#oe,t=this.#n?.document;if(e===void 0||t===void 0)return;let{nextSelections:n,change:r}=ln(t,e,this.#L);r!==void 0&&this.#un(r,n,this.#fn(r))}#ln(){let e=this.#oe,t=this.#n?.document;if(e===void 0||t===void 0)return;let{nextSelections:n,change:r}=cn(t,e,this.#L);r!==void 0&&this.#un(r,n,this.#fn(r))}#un(e,t,n,r){this.#be!=null&&this.#Lt(!0);let i=this.#n?.document;if(i!==void 0&&this.#U!==void 0)for(let t of this.#U)t.anchorOffset=_n(t.anchorOffset,e.changes),t.focusOffset=_n(t.focusOffset,e.changes),t.caret.anchor=i.positionAt(t.anchorOffset),t.caret.focus=i.positionAt(t.focusOffset);if(e.lineDelta!==0||this.#Ie)for(let t of this.#m.keys())t>=e.startLine&&this.#m.delete(t);if(this.#h.size>0){if(e.lineDelta===0&&(e.changedLineRanges.length===1||e.changedLineChanges?.every(([,,e])=>e===0)===!0))for(let[t,n]of e.changedLineRanges)for(let e=t;e<=n;e++)this.#h.delete(e);else for(let t of this.#h.keys())t>=e.startLine&&this.#h.delete(t)}this.#_=void 0;let a=this.#B,o;if(a!==void 0&&t!==void 0&&t.length>0){let n=t.at(-1),r=a.startingLine+a.totalLines;if(n.end.line>=r){let t=n.end.line-a.startingLine+1,i=this.#V===void 0||this.#V===1/0?1/0:this.#V*Ti;e.startLine<=r&&t<=i&&this.#je(n.end.line)?(n.end.line>r&&(o=!0),a={...a,totalLines:t},this.#B=a):o=!0}}if(this.#st(e,n,a,o),t!=null&&this.#Ut(t),this.#M?.__acknowledgeDocumentUpdate(),this.#Ee(),this.#Bt(e,r?.editSource??`user`),this.#zt(),this.#dn(e.changes,n??this.#L),r?.skipSearchRefresh!==!0&&this.#W!==void 0&&this.#se!==void 0&&this.#W.updateMatches({syncSelection:!1}),t!=null&&r?.skipFocus!==!0){let e=t.at(-1);if(e!==void 0&&this.#Ne(G(e).line),this.#A!==void 0)requestAnimationFrame(()=>{this.#A?.scrollIntoView({block:`nearest`,inline:`nearest`})});else if(t.length>0){let e=G(t.at(-1));this.#_t(e.line,e.character)}this.focus({preventScroll:!0})}}#dn(e,t){let n=this.getFile(),r=this.#P;n!=null&&r!=null&&r(e,n,t)}#fn(e){if(this.#L!=null){let t=jt(e,this.#L);if(t!=null)return this.#n?.document?.setLastUndoLineAnnotations(this.#L,t),t}}#pn(){let e=this.#w;if(e===void 0)return[];let t=[];for(let n of e.children){let e=n,r=e.dataset.lineType,i=V(e);if(i===void 0||r===void 0||!mn(r))continue;let a=i-1,o=t.at(-1);o!==void 0&&a<=o[1]+1?o[1]=Math.max(o[1],a):t.push([a,a])}return t}#mn(e){let t=this.#B;return t==null||e>=t.startingLine&&e<t.startingLine+t.totalLines}#hn(e){let t=this.#g.get(e);if(t!==void 0)return t??void 0;let n=this.#B;if(!this.#mn(e))return;let r=this.#w;if(r!==void 0){if(n!==void 0){let{startingLine:i}=n,{children:a}=r;for(let n=e-i;n<=a.length;n++){let r=a[n];if(r===void 0)break;let i=V(r),o=r.dataset.lineType;if(i!==void 0&&i===e+1&&o!==void 0&&mn(o)){t=r;break}}}return t??=r.querySelector(`[data-line="${e+1}"]`+(this.#Pe===`unified`?`:not([data-line-type="change-deletion"])`:``)),t!==void 0&&this.#g.set(e,t),t??void 0}}#gn(){if(this.#C===void 0)return 0;if(this.#f===void 0){let e=this.#w?.parentElement?.style.getPropertyValue(`--diffs-column-number-width`);this.#f=e!==void 0&&e.length>2&&e.endsWith(`px`)?parseInt(e.slice(0,-2),10):this.#C.offsetWidth}return this.#f}#_n(){if(this.#w===void 0)return 0;if(this.#p===void 0){let e=this.#w.parentElement?.style.getPropertyValue(`--diffs-column-content-width`);this.#p=e!==void 0&&e.length>2&&e.endsWith(`px`)?parseFloat(e.slice(0,-2)):this.#w.offsetWidth}return this.#p}#vn(e){let t=this.#m.get(e);if(t!==void 0)return t;let n=this.#hn(e);if(n===void 0)return-1;let r=n.offsetTop+this.#r.paddingTop;return r+=this.#Qe?.top??0,this.#m.set(e,r),r}#yn(e,t){if(this.#_!==void 0&&this.#_[0]===e&&this.#_[1]===t)return[this.#_[2],this.#_[3]];let n=this.#n?.document?.getLineText(e),r=this.#gn()+this.#r.ch;if(n===void 0||n.length===0||t<=0)return[r+(this.#Qe?.left??0),0];let i=pi(n,Math.min(t,n.length)),a=n.slice(0,i),o=hi(a,this.#r.tabSize),s=0,c=0;if(s=o===-1?r+this.#r.measureTextWidth(a):r+o*this.#r.ch,this.#Ie){let t=this.#_n();if(2*this.#r.ch+this.#r.measureTextWidth(n)>t){let t=this.#bn(e);if(t==null)return[s+(this.#Qe?.left??0),0];for(let e=0;e+1<t.length;e++){let a=t[e];if(i<=t[e+1]){c=e;let t=n.slice(a,i),o=hi(t,this.#r.tabSize);s=o===-1?r+this.#r.measureTextWidth(t):r+o*this.#r.ch;break}}}s+=this.#Qe?.left??0}return this.#_===void 0?this.#_=[e,t,s,c]:(this.#_[0]=e,this.#_[1]=t,this.#_[2]=s,this.#_[3]=c),[s,c]}#bn(e){let t=this.#h.get(e);if(t!==void 0)return t;this.#h.size>=Ei&&this.#h.clear();let n=this.#n?.document?.getLineText(e);if(n===void 0||n.length===0){let t=new Uint32Array([0]);return this.#h.set(e,t),t}let r=this.#w;if(r==null||!r.isConnected)return;let i=z(`div`,{style:{position:`absolute`,top:`0`,left:`0`,width:`100%`,boxSizing:`border-box`,visibility:`hidden`,pointerEvents:`none`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,font:`inherit`,paddingInline:`1ch`,tabSize:this.#r.tabSize.toString()},textContent:n},r),a=i.firstChild,o=document.createRange(),s=[];try{let t=i.getBoundingClientRect();if(t.width===0)return;let r=mi(n),c=t.left+this.#r.ch,l=r===void 0?n.length:r.length-1,u=e=>r===void 0?e:r[e],d=e=>{o.setStart(a,u(e)),o.setEnd(a,u(e+1));let t=o.getClientRects();return t.item(t.length-1)??o.getBoundingClientRect()};s.push(0);let f=d(0).top,p=1;for(;p<l;){let e=p,t=l;for(;e<t;){let n=e+t>>1;d(n).top>f?t=n:e=n+1}if(e>=l)break;let{left:n,top:r}=d(e),i=h()&&n-c>this.#r.ch/2;s.push(u(i?e-1:e)),f=r,p=e+1}let m=new Uint32Array(s.length+1);for(let e=0;e<s.length;e++)m[e]=s[e];return m[s.length]=n.length,this.#h.set(e,m),m}finally{i.remove()}}#xn(e){let t=this.#bn(e);if(t!==void 0)return t;let n=this.#n?.document?.getLineText(e)?.length??0;return Uint32Array.of(0,n)}#Sn({startContainer:e,endContainer:t}){let n=this.#w;return n!==void 0&&n.contains(e)&&n.contains(t)}#Cn(e){let t=this.#n?.document?.lineCount??0;return e<0||e>=t?!1:this.#hn(e)!==void 0}};function Pi({type:e,editStateKey:t,owner:n,initialState:r,previousSession:i}){if(r!=null&&r.type!==e)throw TypeError(`Editor: initialState: a ${r.type} state cannot initialize a ${e} editor`);let a=r;return t==null?a??i??(e===`file`?{type:`file`}:{type:`file-diff`}):dt.activate(e,t,n,a)}function Fi(e){return e instanceof HTMLElement?Number(e.dataset.bufferSize??1):1}function Ii(e,t){return t!==void 0&&Number.isInteger(t.line)&&Number.isInteger(t.character)&&t.line>=0&&t.line<e.lineCount&&t.character>=0&&t.character<=e.getLineLength(t.line)}function Li(e,t){let n=e.charCodeAt(t-1),r=e.charCodeAt(t);return t>0&&t<e.length&&n>=55296&&n<=56319&&r>=56320&&r<=57343}i();var Ri=n();function zi(e,t,n,r,i){let s=(0,Ri.c)(15),c;s[0]!==r||s[1]!==n||s[2]!==e||s[3]!==t?(c=ie(r,e,t,n),s[0]=r,s[1]=n,s[2]=e,s[3]=t,s[4]=c):c=s[4];let l=c,u=a(ne),d;s[5]!==r||s[6]!==i||s[7]!==e||s[8]!==t||s[9]!==u||s[10]!==l?(d=function(n){if(!n)return;let a=document.createElement(`div`);n.append(a);let s=new _e;s.setup(n,a);let c=()=>({...v(u.get(se),{overflow:u.get(ae).lineOverflow}),onEditChange:e=>{o(r.change(e.file.contents))},onEditComplete:Bi}),d=new j(c(),s);d.render({file:l.file,containerWrapper:a});let f=new Ni(`file`,{onAttach(e){n.matches(`:focus-within`)||e.focus({lineNumber:1,character:0})},onBlur(){r.state.value.error||o(r.save())}});r.attachEditor(e),f.edit(d);let p=()=>{d.setOptions(c()),d.rerender()},m=u.subscribe(ae,p),h=u.subscribe(se,p);return()=>{m(),h(),f.cleanUp(`discard`),d.cleanUp(),s.cleanUp(),a.remove(),o(r.finishEditing(e,()=>i(t),()=>F(r,e,l)))}},s[5]=r,s[6]=i,s[7]=e,s[8]=t,s[9]=u,s[10]=l,s[11]=d):d=s[11];let f=d,p;return s[12]!==f||s[13]!==l.initialText?(p={initialText:l.initialText,attach:f},s[12]=f,s[13]=l.initialText,s[14]=p):p=s[14],p}function Bi(){return`reject`}var $=r();function Vi(e){let n=(0,Ri.c)(42),{owner:r,path:i,draft:a,state:o,active:c,changed:l,onDone:u,onDiscard:d,renderToolbar:f}=e,p=a.blocked,m;n[0]!==a||n[1]!==r?(m=te(r,a,ee.add),n[0]=a,n[1]=r,n[2]=m):m=n[2];let{copyDraft:h,save:g,done:_,discard:v,notifyUnsaved:b}=m,{initialText:x,attach:S}=zi(r,i,o.text,a,b),C;n[3]!==p||n[4]!==x||n[5]!==o?(C=Hi(o,p,x),n[3]=p,n[4]=x,n[5]=o,n[6]=C):C=n[6];let w=C,T;n[7]===w?T=n[8]:(T=(0,$.jsx)(`span`,{role:`status`,className:`text-xs text-muted-foreground`,children:w}),n[7]=w,n[8]=T);let E;n[9]!==_||n[10]!==u?(E=()=>void _(u),n[9]=_,n[10]=u,n[11]=E):E=n[11];let D;n[12]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,$.jsx)(t,{className:`size-3.5`}),n[12]=D):D=n[12];let O;n[13]!==p||n[14]!==E?(O=(0,$.jsxs)(s,{size:`sm`,disabled:p,onClick:E,children:[D,`Done`]}),n[13]=p,n[14]=E,n[15]=O):O=n[15];let k;n[16]!==T||n[17]!==O?(k=(0,$.jsxs)($.Fragment,{children:[T,O]}),n[16]=T,n[17]=O,n[18]=k):k=n[18];let A=k,j;n[19]!==c||n[20]!==g?(j=c&&(0,$.jsx)(Ui,{onSave:()=>void g()}),n[19]=c,n[20]=g,n[21]=j):j=n[21];let M;n[22]!==A||n[23]!==f?(M=f?.(A),n[22]=A,n[23]=f,n[24]=M):M=n[24];let N;n[25]===l?N=n[26]:(N=l&&(0,$.jsx)(`p`,{className:`border-b bg-graph-4/10 px-3.5 py-1.5 text-xs text-graph-4`,children:`Saving edits the changes you are reviewing.`}),n[25]=l,n[26]=N);let P;n[27]!==p||n[28]!==h||n[29]!==v||n[30]!==d||n[31]!==g||n[32]!==o.error?(P=o.error!==null&&o.error!==void 0&&(0,$.jsxs)(`div`,{role:`alert`,className:`flex items-center gap-2 border-b px-3.5 py-2 text-xs text-destructive`,children:[(0,$.jsxs)(`span`,{className:`flex-1`,children:[p?`The file changed on disk since you opened it. Reload it before saving.`:y(o.error),` `,`Your draft is kept here.`]}),(0,$.jsx)(s,{size:`xs`,variant:`outline`,onClick:h,children:`Copy draft`}),!p&&(0,$.jsx)(s,{size:`xs`,variant:`outline`,onClick:()=>void g(),children:`Retry save`}),(0,$.jsx)(s,{size:`xs`,variant:`ghost`,onClick:()=>v(d),children:p?`Reload`:`Discard draft and reload`})]}),n[27]=p,n[28]=h,n[29]=v,n[30]=d,n[31]=g,n[32]=o.error,n[33]=P):P=n[33];let F;n[34]===S?F=n[35]:(F=(0,$.jsx)(`div`,{ref:S,className:`min-h-0 flex-1 overflow-auto`}),n[34]=S,n[35]=F);let I;return n[36]!==N||n[37]!==P||n[38]!==F||n[39]!==j||n[40]!==M?(I=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[j,M,N,P,F]}),n[36]=N,n[37]=P,n[38]=F,n[39]=j,n[40]=M,n[41]=I):I=n[41],I}function Hi(e,t,n){return t?`Not saving: changed on disk`:e.error?`Not saved`:e.saving?`Saving…`:e.text===e.savedText?e.text===n?`Saves as you pause`:`Saved`:`Unsaved changes`}function Ui(e){let t=(0,Ri.c)(1),{onSave:n}=e,r;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={ignoreInputs:!1},t[0]=r):r=t[0],re(A.saveFile,n,r),null}export{Vi as default};
|