RevelaOS/assets/index-a87278a7.js
2024-03-30 12:00:38 +00:00

1 line
7.5 KiB
JavaScript

import{a as re,u as W,s as ve,I as q}from"./Editor-58f9343f.js";import{E as oe,b as be,B as ne,C as ce,S as xe}from"./utils-wvIv1qJ9-967f341c.js";import"./index-4bca499f.js";const de=re("","color:#0000;display:none;contain:strict;padding:0 var(--_pse) 0 var(--padding-left);"),ie=(t,a,d=/[_\p{N}\p{L}]{2}/u)=>a?d.test(t.slice(a-(t.codePointAt(a-2)>65535?2:1),a+(t.codePointAt(a)>65535?2:1))):!1,pe=t=>{const a=document.createElement("span"),d=[new Text],l=[],n=de.cloneNode(),p=[],b=()=>{p[0]&&(p.length=0,n.style.display="none")};let h;return a.append(""),t.overlays.append(n),{search(c,s,i,r,f,y,C){if(!c)return b();r||(c=oe(c));const x=t.value,T=f?x.slice(...f):x,E=f?f[0]:0,A=`gum${s?"":"i"}`,w=typeof y=="number"?(m,g)=>m>y||g<=y:y;try{let m,g,v,u=0;for(p.length=0,h=RegExp(c,A);m=h.exec(T);)g=m[0].length,v=m.index+E,g||(h.lastIndex+=x.codePointAt(v)>65535?2:1),!(i&&(ie(x,v,C)||ie(x,v+g,C)))&&(!w||w(v,v+g))&&(p[u++]=[v,v+g])}catch(m){return m.message}finally{const m=Math.min(p.length*2,2e4),g=n.childNodes.length,v=x.slice(m?p[m/2-1][1]:0);for(let u=d.length;u<=m;)d[u++]=a.cloneNode(!0),d[u++]=new Text;for(let u=g-1;u>m;)d[u--].remove();g<=m&&n.append(...d.slice(g,m+1));for(let u=0,F=0;u<m;++u){const[M,_]=p[u/2],P=x.slice(F,M),k=x.slice(M,F=_);P!=l[u]&&(d[u].data=l[u]=P),k!=l[++u]&&(d[u].firstChild.data=l[u]=k)}v!=l[m]&&(d[m].data=l[m]=v),n.style.display=""}},container:n,get regex(){return h},matches:p,stopSearch:b}};de.setAttribute("aria-hidden",!0);const he=(t,a)=>({update(d){this.update=()=>{};const l=this.api=pe(d),n=l.container;n.style.zIndex=-1,n.className=t,d.addListener("selectionChange",a(d,l))}}),Ce=(t,a=1,d=200)=>he("selection-matches",(l,n)=>([p,b],h)=>{h=l.focused?h.slice(p,b):"";let c=h.search(/\S/),s=(h=h.trim()).length;n.search(a>s||s>d?"":h,t,!1,!1,void 0,p+c)}),Ae=(t,a)=>Object.assign(he("word-matches",(d,l)=>{let n=!1;return d.addListener("update",()=>n=!0),([p,b],h)=>{if(p<b||!d.focused||n)l.search("");else{let c=`[_$\\p{L}\\d${a&&a(p)?"-":""}]`,s=h.slice(0,p).match(RegExp(c+"*$","u")),i=s.index,r=s[0]+h.slice(p).match(RegExp("^"+c+"*","u"))[0];l.search(/^-*(\d|$)/.test(r)||t&&!t(i,i+r.length)?"":r,!0,!0,!1,void 0,t,RegExp(c+"{2}","u"))}n=!1}}),{setFilter(d){t=d}}),ye=t=>{const{getSelection:a,textarea:d}=t,l=pe(t),n=()=>{const c=a()[0],s=l.matches,i=s.length;for(let r=i;r;)if(c>s[--r][1])return r==i-1?0:r+1;return i?0:-1};let p,b,h;return Object.assign(l,{next(){const c=a()[1],s=l.matches,i=s.length;for(let r=0,f;r<i;r++)if(f=s[r],f[0]-(f[0]==f[1])>=c)return r;return i?0:-1},prev(){const c=a()[0],s=l.matches,i=s.length;for(let r=i,f;r;)if(f=s[--r],f[1]+(f[0]==f[1])<=c)return r;return i-1},closest:n,selectMatch(c,s){h?.();const i=l.matches[c];i&&(h=()=>{p?.classList.remove("match-highlight"),b?.classList.remove("match"),d.removeEventListener("focus",h),h=null},t.setSelection(...i),d.addEventListener("focus",h),p=t.activeLine,p.classList.add("match-highlight"),b=l.container.children[c],b&&(b.classList.add("match"),be(t,b,s)))},replace(c){if(!l.matches[0])return;const s=n(),[i,r]=l.matches[s],[f,y]=a();if(i!=f||r!=y)return this.selectMatch(s),s;ne(t,c)},replaceAll(c){const{matches:s}=l;if(!s[0])return;let i=t.value,[r,f]=a(),y=c.length,C=r,x=f,T="",E=s.length;for(let A=0;A<E;A++){const[w,m]=s[A],g=y-m+w,v=u=>w>u?0:u>=m?g:g<0&&u>w+y?y+w-u:0;x+=v(f),C+=v(r),T+=A?i.slice(s[A-1][1],w)+c:c}ne(t,T,s[0][0],s[E-1][1],C,x)},destroy(){h?.(),l.container.remove()}})},Ee=re('<div dir="ltr" class="prism-search"><button aria-expanded="false" title="Toggle Replace" class="pce-expand"></button><div spellcheck="false"><div><div class="pce-input pce-find"><input autocorrect="off" autocapitalize="off" placeholder="Find" aria-label="Find"><button class="prev-match" title="Previous Match (Shift+Enter)"></button><button class="next-match" title="Next Match (Enter)"></button><div class="search-error"></div></div><button class="pce-close" title="Close (Esc)"></button></div><div class="pce-input pce-replace"><input autocorrect="off" autocapitalize="off" placeholder="Replace" aria-label="Replace"><button title="(Enter)">Replace</button><button>All</button></div><div class="pce-options"><div class="pce-match-count">0<span> of </span>0</div><button aria-pressed="false" class="pce-regex"><span aria-hidden="true"></span></button><button aria-pressed="false"><span aria-hidden="true">Aa</span></button><button aria-pressed="false" class="pce-whole"><span aria-hidden="true">ab</span></button><button aria-pressed="false" class="pce-in-selection"></button></div></div></div>',"display:none;align-items:flex-start;justify-content:flex-end;","prism-search-container"),le=(t,a)=>t.setAttribute(a,t.getAttribute(a)=="false"),G=(t,a)=>parseFloat(getComputedStyle(t)[a]),Ne=()=>{let t,a,d,l,n,p,b,h,c=!1,s;const i=Ee.cloneNode(!0),r=i.firstChild,[f,y]=r.children,C=y.children,[x,T]=C[0].children,[E,A,w,m]=x.children,[g,v,u]=C[1].children,[F,M,_,P,k]=C[2].children,[H,,ue]=F.childNodes;return{update(S){this.update=()=>{},S.extensions.searchWidget=this;const{textarea:I,wrapper:J,overlays:me,scrollContainer:O,getSelection:D}=S,L=ye(S),z=e=>{const o=L.search(E.value,d,l,a,n),$=o?-1:c?L.next():L.closest();H.data=$+1,ue.data=L.matches.length,x.classList.toggle("pce-error",!!o),o?m.textContent=o:e&&L.selectMatch($,h)},K=e=>{if(e.keyCode>>1==35&&ce(e)==(W?4:2)){q(e),X();let[o,$]=D(),N=S.value,R=N.slice(o,$)||N.slice(0,o).match(/[_\p{N}\p{L}]*$/u)[0]+N.slice(o).match(/^[_\p{N}\p{L}]*/u)[0];/^$|\n/.test(R)?z():(a&&(R=oe(R)),document.execCommand("insertText",!1,R)||(E.value=R),E.select())}},Q=()=>{n&&(b=D())},V=()=>{if(n){const e=t-(t=S.value.length),[,o]=b,[$,N]=n;o<=N&&(n[1]-=e,o<=$-+(e<0)&&(n[0]-=e))}z(c),c=!1},X=(e=!0)=>{p||(p=!0,s==null&&(h=s=G(J,"marginTop")),S.addListener("update",V),I.addEventListener("beforeinput",Q),i.style.display="flex",U(),Y(),ee?.observe(O)),e&&(E.focus(),E.select())},Z=this.close=(e=!0)=>{p&&(p=!1,L.stopSearch(),S.removeListener("update",V),I.removeEventListener("beforeinput",Q),i.style.display="none",U(),ee?.disconnect(),e&&I.focus())},j=e=>{if(L.matches[0]){const o=L[e?"next":"prev"]();L.selectMatch(o,h),H.data=o+1}},U=()=>{const e=p?G(r,"top")+G(r,"height"):s,o=O.scrollTop+e-h;J.style.marginTop=e+"px",O.scrollTop=o,h=e},Y=()=>y.style.setProperty("--search-width",`min(${O.clientWidth-2}px - 2.4em - var(--padding-left),20em)`),ee=window.ResizeObserver&&new ResizeObserver(Y),te=()=>{c=!0,L.replace(g.value)},se=()=>{L.replaceAll(g.value)},fe={p:_,w:P,r:M,l:k},ge=new Map([[w,()=>j(!0)],[A,j],[T,Z],[v,te],[u,se],[f,()=>{le(f,"aria-expanded"),U()}],[_,()=>d=!d],[M,()=>a=!a],[P,()=>l=!l],[k,()=>{const e=S.value;n?n=void 0:(n=D().slice(0,2),/\n/.test(e.slice(...n))&&(n=xe(e,...n).slice(1))),t=e.length}]]),B=` (Alt+${W?"Cmd+":""}`;_.title=`Preserve Case${B}P)`,P.title=`Match Whole Word${B}W)`,M.title=`RegExp Search${B}R)`,k.title=`Find in Selection${B}L)`,u.title=`(${W?"Cmd":"Ctrl+Alt"}+Enter)`,I.addEventListener("keydown",K),ve&&i.addEventListener("focusin",e=>{i.contains(e.relatedTarget)||(E.focus(),e.target.focus())}),i.addEventListener("click",e=>{const o=e.target;ge.get(o)?.(),o.matches("input~*")&&o.focus(),o.matches(".pce-options>button")&&(le(o,"aria-pressed"),z(!0),e.isTrusted&&o.focus())}),E.oninput=()=>p&&z(!0),i.addEventListener("keydown",e=>{const o=ce(e),$=e.target,N=e.key,R=$==E;if(o==(W?5:1)){let ae=fe[W?e.code[3].toLowerCase():N];ae&&(q(e),ae.click(),$.focus())}else N=="Enter"&&$.tagName=="INPUT"?(q(e),o?o==8&&R?j():o==(W?4:3)&&!R&&se():R?j(!0):te(),$.focus()):!o&&N=="Escape"?Z():K(e)}),this.open=e=>{X(e),z()},me.append(i),L.container.className="pce-matches"},widgetEl:r,close(){},open(){}}};export{Ae as highlightCurrentWord,Ce as highlightSelectionMatches,Ne as searchWidget};