-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathprism_editor.js
More file actions
28 lines (28 loc) · 27.6 KB
/
prism_editor.js
File metadata and controls
28 lines (28 loc) · 27.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var ye={},ge=Symbol(),he=Symbol(),Fe=e=>typeof e=="string"?V[e]:e,V={plain:ye,plaintext:ye,text:ye,txt:ye},ze=(e,t)=>(t[he]||Ge)(e,t),Ge=(e,t)=>{for(var n=[e],a,l=[],u=0;a=Fe(t[ge]);)delete t[ge],Object.assign(t,a);for(Xe(e,t,n,0);l[u++]=n[0],n=n[1];);return l},Ye=(e,t,n)=>e.replace(/&/g,"&").replace(t,n),He="</span>",ke="",ue="",Qe=e=>{for(var t="",n=e.length,a=0;a<n;)t+=Je(e[a++]);return t},Je=e=>{if(e instanceof fe){var{type:t,alias:n,content:a}=e,l=ke,u=ue,f=`<span class="token ${t+(n?" "+n:"")+(t=="keyword"&&typeof a=="string"?" keyword-"+a:"")}">`;ue+=He,ke+=f;var d=Je(a);return ke=l,ue=u,f+d+He}return typeof e!="string"?Qe(e):(e=Ye(e,/</g,"<"),ue&&e.includes(`
`)?e.replace(/\n/g,ue+`
`+ke):e)},Xe=(e,t,n,a,l)=>{for(var u in t)if(t[u])for(var f=0,d=t[u],y=Array.isArray(d)?d:[d];f<y.length;++f){if(l&&l[0]==u&&l[1]==f)return;for(var v=y[f],b=v.pattern||v,i=Fe(v.inside),m=v.lookbehind,g=v.greedy&&b.global,k=v.alias,h=n,r=a;h&&(!l||r<l[2]);r+=h[0].length,h=h[1]){var s=h[0],o=0,c,p;if(!(s instanceof fe)){if(b.lastIndex=g?r:0,c=b.exec(g?e:s),!c&&g)break;if(c&&c[0]){if(m&&c[1]&&(p=c[1].length,c.index+=p,c[0]=c[0].slice(p)),g){for(var C=c.index,w=C+c[0].length,$;C>=r+($=h[0].length);h=h[1],r+=$);if(h[0]instanceof fe)continue;for(var S=h,d=r;(d+=S[0].length)<w;S=S[1],o++);s=e.slice(r,d),c.index-=r}for(var C=c.index,T=c[0],I=s.slice(C+T.length),L=r+s.length,O=new fe(u,i?ze(T,i):T,T,k),M=h,W=0,N;M=M[1],W++<o;);I&&(!M||M[0]instanceof fe?M=[I,M]:M[0]=I+M[0]),r+=C,h[0]=C?s.slice(0,C):O,C?h=h[1]=[O,M]:h[1]=M,o&&(Xe(e,t,h,r,N=[u,f,L]),L=N[2]),l&&L>l[2]&&(l[2]=L)}}}}};function fe(e,t,n,a){this.type=e,this.content=t,this.alias=a,this.length=n.length}const ut=(e,t,...n)=>{var N;let a,l=[],u,f="",d,y=!1,v=!0,b=[],i,m=0;const g=gt(),k=g.firstChild,h=k.children,r=h[0],s=r.firstChild,o={language:"text",value:f},c=new Set(n),p={},w=E=>{var D;Object.assign(o,E);let x=f!=(f=(D=E.value)!=null?D:f),R=a!=(a=o.language);i=!!o.readOnly,g.style.tabSize=o.tabSize||2,s.inputMode=i?"none":"",s.setAttribute("aria-readonly",i),C(),S(),x&&(y||s.remove(),s.value=f,s.selectionEnd=0,y||r.prepend(s)),(x||R)&&$()},$=()=>{b=ze(f=s.value,V[a]||{}),O("tokenize",b,a,f);let E=Qe(b).split(`
`),x=0,R=m,D=m=E.length;for(;E[x]==l[x]&&x<D;)++x;for(;D&&E[--D]==l[--R];);if(x==D&&x==R)h[x+1].innerHTML=E[x]+`
`;else{let B=R<x?R:x-1,z=B,P="";for(;z<D;)P+=`<div class=pce-line aria-hidden=true>${E[++z]}
</div>`;for(z=D<x?D:x-1;z<R;z++)h[x+1].remove();for(P&&h[B+1].insertAdjacentHTML("afterend",P),z=B+1;z<m;)h[++z].setAttribute("data-line",z);g.style.setProperty("--number-width",(0|Math.log10(m))+1+".001ch")}O("update",f),M(!0),v&&setTimeout(setTimeout,0,()=>v=!0),l=E,v=!1},S=E=>{(E||c).forEach(x=>{typeof x=="object"?(x.update(W,o),E&&c.add(x)):(x(W,o),E||c.delete(x))})},C=([E,x]=T())=>{g.className=`prism-code-editor language-${a}${o.lineNumbers==!1?"":" show-line-numbers"} pce-${o.wordWrap?"":"no"}wrap${o.rtl?" pce-rtl":""} pce-${E<x?"has":"no"}-selection${y?" pce-focus":""}${i?" pce-readonly":""}${o.class?" "+o.class:""}`},T=()=>[s.selectionStart,s.selectionEnd,s.selectionDirection],I={Escape(){s.blur()}},L={},O=(E,...x)=>{var R,D;(R=p[E])==null||R.forEach(B=>B.apply(W,x)),(D=o["on"+E[0].toUpperCase()+E.slice(1)])==null||D.apply(W,x)},M=E=>{if(E||v){const x=T(),R=h[d=De(f,0,x[x[2]<"f"?0:1])];R!=u&&(u==null||u.classList.remove("active-line"),R.classList.add("active-line"),u=R),C(x),O("selectionChange",x,f)}},W={container:g,wrapper:k,lines:h,textarea:s,get activeLine(){return d},get value(){return f},options:o,get focused(){return y},get tokens(){return b},inputCommandMap:L,keyCommandMap:I,extensions:{},setOptions:w,update:$,getSelection:T,addExtensions(...E){S(E)},on:(E,x)=>((p[E]||(p[E]=new Set)).add(x),()=>p[E].delete(x)),remove(){g.remove()}};return K(s,"keydown",E=>{var x;(x=I[E.key])!=null&&x.call(I,E,T(),f)&&H(E)}),K(s,"beforeinput",E=>{var x;(i||E.inputType=="insertText"&&((x=L[E.data])!=null&&x.call(L,E,T(),f)))&&H(E)}),K(s,"input",$),K(s,"blur",()=>{oe=null,y=!1,C()}),K(s,"focus",()=>{oe=M,y=!0,C()}),K(s,"selectionchange",E=>{M(),H(E)}),(N=ft(e))==null||N.append(g),t&&w(t),W},q="u">typeof window?document:null,Me=q==null?void 0:q.createElement("div"),re=(e,t)=>(Me&&(Me.innerHTML=e,t=Me.firstChild),()=>t.cloneNode(!0)),K=(e,t,n,a)=>e.addEventListener(t,n,a),ft=e=>typeof e=="string"?q.querySelector(e):e,De=(e,t=0,n=1/0)=>{let a=1;for(;(t=e.indexOf(`
`,t)+1)&&t<=n;a++);return a},Ie={},gt=re("<div><div class=pce-wrapper><div class=pce-overlays><textarea class=pce-textarea spellcheck=false autocapitalize=off autocomplete=off>"),H=e=>{e.preventDefault(),e.stopImmediatePropagation()};let oe;q&&K(q,"selectionchange",()=>oe==null?void 0:oe());const ht=(e,t,n)=>t.indexOf(e[0])+1||n&&t.indexOf(e[n])+1,dt=(e=!0,t="()[]{}")=>{let n,a;const l=[],u=b=>{b.extensions.matchBrackets=u,b.on("tokenize",y),e&&b.tokens[0]?b.update():y(b.tokens)},f=u.brackets=[],d=u.pairs=[],y=b=>{if(d.length=f.length=a=n=0,v(b,0),e)for(let i=0,m;m=f[i];){let g=m[0].alias;m[0].alias=(g?g+" ":"")+`bracket-${i++in d?"level-"+m[3]%12:"error"}`}},v=(b,i)=>{let m,g=0;for(;m=b[g++];){let k=m.length;if(typeof m!="string"){let h=m.content;if(Array.isArray(h))v(h,i);else if((m.alias||m.type)=="punctuation"){let r=ht(h,t,k-1),s=r%2;if(r){if(f[n]=[m,i,i+k,a,h,!!s],s)l[a++]=[n,r+1];else for(let o=a;o;){let c=l[--o];r==c[1]&&(d[d[n]=c[0]]=n,f[n][3]=a=o,o=0)}n++}}}i+=k}};return u},Ze=(e,t,n=0)=>{const a=e.container.style;a.scrollPaddingBlock=`calc(var(--_sp) + ${n}px) calc(var(--_sp) + ${Ae&&!t.textContent?t.offsetHeight:0}px)`,t.scrollIntoView({block:"nearest"}),a.scrollPaddingBlock=""},de=(e,t)=>t?e.lastIndexOf(`
`,t-1)+1:0,ve=(e,t)=>(t=e.indexOf(`
`,t))+1?t:e.length,Y=(e,t,n,a)=>K(e.textarea,t,n,a),Se=(e,t)=>parseFloat(getComputedStyle(e)[t]),vt=(e,t)=>{const n=t.getBoundingClientRect(),a=e.lines[0].getBoundingClientRect();return{top:n.y-a.y,bottom:a.bottom-n.bottom,left:n.x-a.x,right:a.right-n.right,height:n.height}},G=(e,t)=>{e.data!=t&&(e.data=t)},bt=new Set("xml,rss,atom,jsx,tsx,xquery,xeora,xeoracube,actionscript".split(",")),mt=/^(?:area|base|w?br|col|embed|hr|img|input|link|meta|source|track)$/i;let ie;const ne=e=>e.replace(/[$+?|.^*()[\]{}\\]/g,"\\$&"),$e=(e,t)=>e.slice(de(e,t),t),Z=(e,t,n=t)=>[e.slice(t=de(e,t),n=ve(e,n)).split(`
`),t,n],Te=(e,t,n=0,a=n,l=e.getSelection()[0])=>{var b;const u=e.value,f=e.lines[De(u,0,l)],d=q.createTreeWalker(f,5);let y=d.lastChild(),v=ve(u,l)+1-l-y.length;for(;-v<=a&&(y=d.previousNode());)if(!y.lastChild&&(v-=y.length||0,v<=n)){for(;y!=f;y=y.parentNode)if((b=y.matches)!=null&&b.call(y,t))return y}},Re=(e,t)=>{var n;return((n=Te(e,"[class*=language-]",0,0,t))==null?void 0:n.className.match(/language-(\S*)/)[1])||e.options.language},j=(e,t,n,a,l,u)=>{if(e.options.readOnly)return;ie=e.getSelection(),a!=null||(a=n);let f=e.textarea,d=e.value,y=Ae&&!d[a!=null?a:ie[1]]&&/\n$/.test(t)&&/^$|\n$/.test(d),v;e.focused||f.focus(),n!=null&&f.setSelectionRange(n,a),l!=null&&(v=e.on("update",()=>{f.setSelectionRange(l,u!=null?u:l,ie[2]),v()})),Ce||f.dispatchEvent(new InputEvent("beforeinput",{data:t})),Ae||Ce?(y&&(f.selectionEnd--,t=t.slice(0,-1)),Ce&&(t+=`
`),q.execCommand(t?"insertHTML":"delete",!1,Ye(t,/</g,"<")),y&&f.selectionStart++):q.execCommand(t?"insertText":"delete",!1,t),ie=0},et=(e,t,n=t,a)=>{let l=e.focused,u=e.textarea,f;l||(K(u,"focus",d=>{f=d.relatedTarget},{once:!0}),u.focus()),u.setSelectionRange(t,n,a),oe(!(!l&&(f?f.focus():u.blur())))},tt=q?navigator.userAgent:"",Q=q?/Mac|iPhone|iP[ao]d/.test(navigator.platform):!1,Ae=/Chrome\//.test(tt),Ce=!Ae&&/AppleWebKit\//.test(tt),se=e=>e.altKey+e.ctrlKey*2+e.metaKey*4+e.shiftKey*8,nt=(e,t)=>e.lines[0].append(t),yt=()=>e=>{let t,n=[],a=()=>{var y;let u=e.extensions.matchBrackets,[f,d]=e.getSelection();if(u){let v=u.brackets,b=u.pairs,i,m;if(e.focused&&f==d){for(let g=0,k;k=v[++g];)if(!k[5]&&k[2]>=d&&((y=v[b[g]])==null?void 0:y[1])<=d){i=v[b[g]],m=k;break}}m!=t&&(l(),m?(n=[i,m].map(g=>Te(e,".punctuation",0,-1,g[1])),n[0]!=n[1]&&i[2]==m[1]&&(n[0].textContent+=n[1].textContent,n[1].textContent="",n[1]=n[0]),l(!0)):n=[]),t=m}},l=u=>n.forEach(f=>f.classList.toggle("active-bracket",!!u));Y(e,"focus",a),Y(e,"blur",a),e.on("selectionChange",a)};let Pe=!1;const le=Q?4:2,kt=e=>Pe=e,te=e=>e.search(/\S|$/),xt=(e=['""',"''","``","()","[]","{}"],t=new RegExp("([^$\\w'\"`][\"'`]|.[[({])[.,:;\\])}>\\s]|.[[({]`","s"))=>(n,a)=>{let l;const{keyCommandMap:u,inputCommandMap:f,getSelection:d,container:y}=n,v=navigator.clipboard,b=({insertSpaces:r=!0,tabSize:s}=a)=>[r?" ":" ",r?s||2:1],i=()=>{var r;return!a.readOnly&&!((r=n.extensions.cursor)!=null&&r.scrollIntoView())},m=([r,s],[o,c],p,w)=>(r<s||!w&&t.test((p[s-1]||" ")+o+(p[s]||" ")))&&!j(n,o+p.slice(r,s)+c,null,null,r+1,s+1),g=([r,s],o,c)=>r==s&&c[s]==o&&!et(n,r+1),k=(r,s,o,c,p,w)=>{let $=s.join(`
`);if($!=r.join(`
`)){const S=r.length-1,C=s[S],T=r[S],I=T.length-C.length,L=s[0].length-r[0].length,O=o+te((L<0?s:r)[0]),M=c-T.length+te(I>0?C:T),W=o-c+$.length+I,N=O>p?p:Math.max(O,p+L),E=w+o-c+$.length;j(n,$,o,c,N,w<M?E+I:Math.max(M+W,E))}},h=(r,s,o,c,p,w,$,S)=>{k(s,s.map(r?C=>C.slice(te(C)?S-te(C)%S:0):C=>C&&$.repeat(S-te(C)%S)+C),o,c,p,w)};f["<"]=(r,s,o)=>m(s,"<>",o,!0),e.forEach(([r,s])=>{const o=r==s;f[r]=(c,p,w)=>(o&&g(p,s,w)||m(p,r+s,w))&&i(),o||(f[s]=(c,p,w)=>g(p,s,w)&&i())}),f[">"]=(r,s,o)=>{var p,w;const c=(w=(p=Ie[Re(n)])==null?void 0:p.autoCloseTags)==null?void 0:w.call(p,s,o,n);c&&(j(n,">"+c,null,null,s[0]+1),H(r))},u.Tab=(r,[s,o],c)=>{if(Pe||a.readOnly||se(r)&6)return;const[p,w]=b(a),$=r.shiftKey,[S,C,T]=Z(c,s,o);return s<o||$?h($,S,C,T,s,o,p,w):j(n,p.repeat(w-(s-C)%w)),i()},u.Enter=(r,s,o)=>{var p,w,$;const c=se(r)&7;if(!c||c==le){c&&(s[0]=s[1]=Z(o,s[1])[2]);const[S,C]=b(),[T,I]=s,L=(p=Ie[Re(n)])==null?void 0:p.autoIndent,O=Math.floor(te($e(o,T))/C)*C,M=(w=L==null?void 0:L[0])!=null&&w.call(L,s,o,n)?C:0,W=($=L==null?void 0:L[1])==null?void 0:$.call(L,s,o,n),N=`
`+S.repeat(O+M)+(W?`
`+S.repeat(O):"");if(N[1]||o[I])return j(n,N,T,I,T+O+M+1),i()}},u.Backspace=(r,[s,o],c)=>{if(s==o){const p=$e(c,s),w=a.tabSize||2,$=e.includes(c.slice(s-1,s+1)),S=/[^ ]/.test(p)?0:(p.length-1)%w+1;if($||S>1)return j(n,"",s-($?1:S),s+$),i()}};for(let r=0;r<2;r++)u[r?"ArrowDown":"ArrowUp"]=(s,[o,c],p)=>{const w=se(s);if(w==1){const $=r?o:de(p,o)-1,S=r?p.indexOf(`
`,c)+1:c;if($>-1&&S>0){const[C,T,I]=Z(p,$,S),L=C[r?"pop":"shift"](),O=(L.length+1)*(r?1:-1);C[r?"unshift":"push"](L),j(n,C.join(`
`),T,I,o+O,c+O)}return i()}else if(w==9){const[$,S,C]=Z(p,o,c),T=$.join(`
`),I=r?T.length+1:0;return j(n,T+`
`+T,S,C,o+I,c+I),i()}else if(w==2&&!Q)return y.scrollBy(0,Se(y,"lineHeight")*(r?1:-1)),!0};Y(n,"keydown",r=>{var $;const s=se(r),o=r.keyCode,[c,p,w]=d();if(s==le&&(o==221||o==219))h(o==219,...Z(n.value,c,p),c,p,...b()),i(),H(r);else if(s==(Q?10:2)&&o==77)kt(!Pe),H(r);else if(o==191&&s==le||o==65&&s==9){const S=n.value,C=s==9,T=C?c:de(S,c),I=Ie[Re(n,T)]||{},{line:L,block:O}=(($=I.getComments)==null?void 0:$.call(I,n,T,S))||I.comments||{},[M,W,N]=Z(S,c,p),E=M.length-1;if(C){if(O){const[x,R]=O,D=S.slice(c,p),B=S.slice(0,c).search(ne(x)+" ?$"),z=RegExp("^ ?"+ne(R)).test(S.slice(p));B+1&&z?j(n,D,B,p+ +(S[p]==" ")+R.length,B,B+p-c):j(n,`${x} ${D} ${R}`,c,p,c+x.length+1,p+x.length+1),i(),H(r)}}else if(L){const x=ne(L),R=RegExp(`^\\s*(${x} ?|$)`),D=RegExp(x+" ?"),B=!/\S/.test(S.slice(W,N)),z=M.map(M.every(P=>R.test(P))&&!B?P=>P.replace(D,""):P=>B||/\S/.test(P)?P.replace(/^\s*/,`$&${L} `):P);k(M,z,W,N,c,p),i(),H(r)}else if(O){const[x,R]=O,D=te(M[0]),B=M[0].startsWith(x,D)&&M[E].endsWith(R),z=M.slice();z[0]=M[0].replace(B?RegExp(ne(x)+" ?"):/(?=\S)|$/,B?"":x+" ");let P=z[0].length-M[0].length;z[E]=B?z[E].replace(RegExp(`( ?${ne(R)})?$`),""):z[E]+" "+R;let J=z.join(`
`),ee=D+W,pe=ee>c?c:Math.max(c+P,ee),be=ee>p-(c!=p)?p:Math.min(Math.max(ee,p+P),W+J.length);j(n,J,W,N,pe,Math.max(pe,be)),i(),H(r)}}else if(s==8+le&&o==75){const S=n.value,[C,T,I]=Z(S,c,p),L=w>"f"?p-I+C.pop().length:c-T,O=ve(S,I+1)-I-1;j(n,"",T-!!T,I+!T,T+Math.min(L,O)),i(),H(r)}}),["copy","cut","paste"].forEach(r=>Y(n,r,s=>{const[o,c]=d();if(o==c&&v){const[[p],w,$]=Z(n.value,o,c);r=="paste"?s.clipboardData.getData("text/plain")==l&&(j(n,l+`
`,w,w,o+l.length+1),i(),H(s)):(v.writeText(l=p),r=="cut"&&(j(n,"",w,$+1),i()),H(s))}}))},wt=(e=999)=>{let t=0,n,a,l=!1,u,f,d,y,v,b;const i=[],m=h=>{h>=e&&(h--,i.shift()),i.splice(t=h,e,[n.value,b(),b()])},g=h=>{var r;i[h]&&(v.value=i[h][0],v.setSelectionRange(...i[h][h<t?2:1]),n.update(),(r=n.extensions.cursor)==null||r.scrollIntoView(),t=h,a=!1)},k=(h,r)=>{h.extensions.history=k,n=h,b=h.getSelection,v||m(0),v=h.textarea,h.on("selectionChange",()=>{a=l,l=!1}),Y(h,"beforeinput",s=>{let o=s.data,c=s.inputType,p=s.timeStamp;/history/.test(c)?(g(t+(c[7]=="U"?-1:1)),H(s)):(y=a&&(u==c||p-d<99&&c.slice(-4)=="Drop")&&!ie&&(o!=" "||f==o))||(i[t][2]=ie||b()),l=!0,f=o,d=p,u=c}),Y(h,"input",()=>m(t+!y)),Y(h,"keydown",s=>{if(!r.readOnly){const o=se(s),c=s.keyCode,p=o==le&&c==90,w=o==le+8&&c==90||!Q&&o==le&&c==89;p?(g(t-1),H(s)):w&&(g(t+1),H(s))}})};return k.clear=()=>{m(0),a=!1},k.has=h=>t+h in i,k.go=h=>g(t+h),k},St=e=>{let t=[],n,a=[],l,u,f=[],d=(v,b,i)=>{n=i,a.length=t.length=l=u=0,y(v,b,0)},y=(v,b,i)=>{let m=bt.has(b),g=0,k=v.length;for(;g<k;){const h=v[g++],r=h.content,s=h.length;if(Array.isArray(r))if(h.type=="tag"&&n[i]=="<"){const o=r[0].length,c=r[2]?n.substr(i+o,r[1].length):"",p=r[r.length-1].length<2&&(m||!mt.test(c));if(r[2]&&y(r,b,i),p)if(o>1)for(let w=u;w;)c==f[--w][1]&&(t[t[l]=f[u=w][0]]=l,w=0);else f[u++]=[l,c];a[l++]=[h,i,i+s,c,o>1,p]}else{let o=h.alias||h.type;y(r,o.slice(0,9)=="language-"?o.slice(9):b,i)}i+=s}};return e.on("tokenize",d),d(e.tokens,e.options.language,e.value),{tags:a,pairs:t}},Ct=(e,t)=>{for(let n=0,a=t.length;n<a;n++)if(t[n][1]<=e&&t[n][2]>=e)return n},Et=()=>e=>{var f;let t,n;const{tags:a,pairs:l}=(f=e.extensions).matchTags||(f.matchTags=St(e)),u=d=>[t,n].forEach(y=>{y&&y.classList.toggle("active-tagname",!d)});e.on("selectionChange",([d,y])=>{let v,b,i;d==y&&e.focused&&(i=Ct(d,a),i+1&&(i=l[i],i+1&&(v=Te(e,".tag>.tag"))&&(b=Te(e,".tag>.tag",2,0,a[i][1])))),t!=v&&(u(!0),t=v,n=b,u())})},$t=re("<div style=position:absolute;top:0;opacity:0;padding-right:inherit> <span><span></span> "),Tt=()=>{let e;const t=$t(),[n,a]=t.childNodes,[l,u]=a.childNodes,f=v=>{const b=e.value,i=e.lines[e.activeLine],m=v[v[2]<"f"?0:1];G(n,$e(b,m)),G(u,b.slice(m,ve(b,m))+`
`),t.parentNode!=i&&i.prepend(t)},d=()=>Ze(e,l),y=v=>{v.on("selectionChange",f),e=v,v.extensions.cursor=y,Y(v,"input",b=>{/history/.test(b.inputType)&&d()}),v.activeLine&&f(v.getSelection())};return y.getPosition=()=>vt(e,l),y.scrollIntoView=d,y.element=l,y},At=re("<div class=guide-indents> "),Lt=()=>{let e,t=0,n,a,l,u=[],f=[],d,y=b=>{n=[];const i=Mt(b,e),m=i.length;for(let g=0,k=[],h=i[0];h;g++){const r=(u[g]||(u[g]=q.createElement("div"))).style,[s,o,c]=h,p=f[g];h=i[g+1],s!=(p==null?void 0:p[0])&&(r.top=s+"00%"),o!=(p==null?void 0:p[1])&&(r.left=o+"00%"),c!=(p==null?void 0:p[2])&&(r.height=c+"00%");const w=k[0]!=s&&(h==null?void 0:h[0])!=s,$=k[0]+k[1]!=s+c&&(h==null?void 0:h[0])+(h==null?void 0:h[1])!=s+c;for(let S=-w,C=c+$;S<C;S++)n[S+s]=g;k=f[g]=i[g]}for(let g=m;g<t;)u[g++].remove();d.append(...u.slice(t,t=m))},v=()=>{const b=u[n[l.activeLine-1]];b!=a&&(a&&(a.className=""),b&&(b.className="active-indent"),a=b)};return{update(b,i){if(!l){l=b;let m=b.lines[0];(d=m.querySelector(".guide-indents"))?(u.push(...d.children),a=u.find(g=>g.className)):m.append(d=At()),b.on("update",y),b.on("selectionChange",v)}d.style.display=i.wordWrap?"none":"",e!=(e=i.tabSize||2)&&(y(b.value),v())}}},Mt=(e,t)=>{const n=e.split(`
`),a=n.length,l=[],u=[];for(let f=0,d=-1,y=0,v=0;;y++){let b=y==a,i=n[y],m=b?0:i.search(/\S/),g=0,k=0;if(m<0)d<0&&(d=y);else{for(;k<m;)g+=i[k++]==" "?t-g%t:1;for(g&&(g=Math.ceil(g/t)),k=g;k<f;k++)l[k][2]=(d<0||k==g&&!b?y:d)-l[k][0];for(k=f;k<g;)u[v++]=l[k]=[d<0||k>f?y:d,k++,0];d=-1,f=g}if(b)break}return u},It=re('<div style="color:#0000;contain:strict;padding:0 var(--_pse) 0 var(--padding-left)" aria-hidden=true> '),Rt=re("<span> "),je=(e,t,n=/[_\p{N}\p{L}]{2}/u)=>t?n.test(e.slice(t-(e.codePointAt(t-2)>65535?2:1),t+(e.codePointAt(t)>65535?2:1))):!1,Be=e=>{const t=It(),n=[t.firstChild],a=[],l=()=>{a[0]&&(a.length=0,t.remove())};let u,f=0;return{search(d,y,v,b,i,m,g){if(!d)return l();b||(d=ne(d));const k=e.value,h=i?k.slice(...i):k,r=i?i[0]:0;let s,o,c,p=0;try{for(u=RegExp(d,`gum${y?"":"i"}`);s=u.exec(h);)o=s[0].length,c=s.index+r,o||(u.lastIndex+=k.codePointAt(c)>65535?2:1),!(v&&(je(k,c,g)||je(k,c+o,g)))&&(!m||m(c,c+o))&&(a[p++]=[c,c+o])}catch(w){return l(),w.message}if(p){for(a.length=p,o=Math.min(p*2,2e4),p=n.length;p<=o;)n[p++]=Rt(),n[p++]=new Text;for(p=o;p<f;)n[++p].remove();f<o&&t.append(...n.slice(f+1,o+1));let w=0;for(p=0;p<o;){const[$,S]=a[p/2];G(n[p++],k.slice(w,$)),G(n[p++].firstChild,k.slice($,w=S))}G(n[o],k.slice(w)),t.parentNode||nt(e,t),f=o}else l()},container:t,get regex(){return u},matches:a,stopSearch:l}},Pt=e=>{const t=e.getSelection,n=Be(e),a=n.container,l=n.matches,u=()=>{const i=t()[0],m=l.length;for(let g=m;g;)if(i>=l[--g][1])return(g+(l[g][0]<i))%m;return m?0:-1},f=()=>{y==null||y.classList.toggle("match-highlight"),v==null||v.classList.toggle("pce-match")},d=()=>{b&&(f(),b=!1)};let y,v,b=!1;return Y(e,"focus",d),Object.assign(n,{next(){const i=t()[1],m=l.length;for(let g=0,k;g<m;g++)if(k=l[g],k[0]-(k[0]==k[1])>=i)return g;return m?0:-1},prev(){const i=t()[0],m=l.length;for(let g=m,k;g;)if(k=l[--g],k[1]+(k[0]==k[1])<=i)return g;return m-1},closest:u,selectMatch(i,m){d(),l[i]&&(et(e,...l[i]),y=e.lines[e.activeLine],v=a.children[i],b=!0,f(),v&&Ze(e,v,m))},replace(i){if(l[0]){let m=u(),[g,k]=l[m],[h,r]=t();return g!=h||k!=r?m:e.value.slice(g,k)==i?l[++m]?m:0:j(e,i)}},replaceAll(i){if(!l[0])return;let m=e.value,[g,k]=t(),h=i.length,r=g,s=k,o="",c=l.length;for(let p=0;p<c;p++){const[w,$]=l[p],S=h-$+w,C=T=>w>T?0:T>=$?S:S<0&&T>w+h?h+w-T:0;s+=C(k),r+=C(g),o+=p?m.slice(l[p-1][1],w)+i:i}j(e,o,l[0][0],l[c-1][1],r,s)},destroy(){e.textarea.removeEventListener("focus",d),d(),a.remove()}})},_t=(e,t=1,n=200)=>{const a=l=>{const u=a.api=Be(l),f=u.container;f.style.zIndex=-1,f.className="selection-matches",l.on("selectionChange",([d,y],v)=>{v=l.focused?v.slice(d,y):"",d+=v.search(/\S/),v=v.trim();let b=v.length;u.search(t>b||b>n?"":v,e,!1,!1,void 0,(i,m)=>i>d||m<=d)})};return a},xe=` (Alt+${Q?"Cmd+":""}`,Ot=re(`<div class=prism-search-container style=display:flex;align-items:flex-start;justify-content:flex-end><div dir=ltr class=prism-search><button type=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 type=button class=prev-match title="Previous Match (Shift+Enter)"></button><button type=button class=next-match title="Next Match (Enter)"></button><div class=search-error></div></div><button type=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 type=button title=(Enter)>Replace</button><button type=button title=(${Q?"Cmd":"Ctrl+Alt"}+Enter)>All</button></div><div class=pce-options><div class=pce-match-count>0<span> of </span>0</div><button type=button aria-pressed=false class=pce-regex title="RegExp Search${xe}R)"><span aria-hidden=true></span></button><button type=button aria-pressed=false title="Preserve Case${xe}P)"><span aria-hidden=true>Aa</span></button><button type=button aria-pressed=false class=pce-whole title="Match Whole Word${xe}W)"><span aria-hidden=true>ab</span></button><button type=button aria-pressed=false class=pce-in-selection title="Find in Selection${xe}L)">`),Ve=(e,t)=>e.setAttribute(t,e.getAttribute(t)=="false"),zt=()=>{let e,t,n,a,l,u,f,d,y,v=!1,b;const i=x=>{x.extensions.searchWidget=i;const{textarea:R,wrapper:D,container:B,getSelection:z}=x,P=Pt(x),J=A=>{A&&!Ce&&R.setSelectionRange(...d);const _=P.search(c.value,n,a,t,l),F=_?-1:v?P.next():P.closest();G(N,F+1),G(E,P.matches.length),s.classList.toggle("pce-error",!!_),_?$.textContent=_:(A||v)&&P.selectMatch(F,y)},ee=A=>{if(A.keyCode>>1==35&&se(A)==(Q?4:2)){H(A),pe();let[_,F]=z(),U=x.value,X=U.slice(_,F)||/[_\p{N}\p{L}]*$/u.exec($e(U,_))[0]+/^[_\p{N}\p{L}]*/u.exec(U.slice(_))[0];/^$|\n/.test(X)?J():(t&&(X=ne(X)),q.execCommand("insertText",!1,X),c.select())}},pe=(A=!0)=>{u||(u=!0,b==null&&(y=b=Se(D,"marginTop")),d=z(),nt(x,m),Le(),We(),ae==null||ae.observe(B)),A&&c.select()},be=i.close=(A=!0)=>{u&&(u=!1,P.stopSearch(),m.remove(),Le(),ae==null||ae.disconnect(),A&&R.focus())},me=A=>{if(P.matches[0]){const _=P[A?"next":"prev"]();P.selectMatch(_,y),G(N,_+1)}},Le=()=>{const A=u?Se(g,"top")+Se(g,"height"):b,_=B.scrollTop+A-y;D.style.marginTop=u?A+"px":"",B.scrollTop=_,y=A},We=()=>h.style.setProperty("--search-width",`min(${B.clientWidth-2}px - 2.9em,20em)`),ae=window.ResizeObserver&&new ResizeObserver(We),ot=()=>{v=!0;const A=P.replace(S.value);A!=null&&(G(N,A+1),P.selectMatch(A,y)),v=!1},rt=()=>{P.replaceAll(S.value)},Ne={80:O,87:M,82:L,76:W},pt=new Map([[w,()=>me(!0)],[p,me],[o,be],[C,ot],[T,rt],[k,()=>{Ve(k,"aria-expanded"),Le()}],[O,()=>n=!n],[L,()=>t=!t],[M,()=>a=!a],[W,()=>{const A=x.value;l?l=void 0:(l=z().slice(0,2),De(A,...l)>1&&(l=[de(A,l[0]),ve(A,l[1])])),e=A.length}]]);K(R,"keydown",ee),K(R,"beforeinput",()=>{u&&l&&(f=z())}),x.on("update",()=>{if(u){if(l&&f){const A=e-(e=x.value.length),_=f[1];_<=l[1]&&(l[1]-=A,_<=l[0]-+(A<0)&&(l[0]-=A))}J()}}),x.on("selectionChange",A=>{u&&x.focused&&(d=A)}),K(m,"click",A=>{var U;const _=A.target,F=x.on("update",()=>_.focus());(U=pt.get(_))==null||U(),_.matches(".pce-options>button")&&(Ve(_,"aria-pressed"),J(!0)),F()}),K(c,"input",()=>u&&J(!0)),K(m,"keydown",A=>{const _=se(A),F=A.target,U=A.keyCode,X=F==c;_==(Q?5:1)?Ne[U]&&(H(A),Ne[U].click()):U==13&&F.tagName=="INPUT"?(H(A),_?_==8&&X?me():_==(Q?4:3)&&!X&&T.click():X?me(!0):C.click(),F.focus()):!_&&U==27?be():ee(A)}),i.open=A=>{pe(A),J()},P.container.className="pce-matches"},m=Ot(),g=i.element=m.firstChild,[k,h]=g.children,r=h.children,[s,o]=r[0].children,[c,p,w,$]=s.children,[S,C,T]=r[1].children,[I,L,O,M,W]=r[2].children,[N,,E]=I.childNodes;return i.open=i.close=()=>{},i},Dt=e=>t=>{const n=Be(t),a=n.matches,l=n.container,u=l.children,f=[],d=()=>{const y=t.value,[v,b]=t.getSelection();{n.search(" | ",!0,!1,!0,[v,b]);for(let i=0,m=a.length;i<m;i++)y[a[i][0]]==" "==!f[i]&&(u[i].className=(f[i]=!f[i])?"pce-tab":"")}};l.className="pce-invisibles",t.value&&d(),t.on("selectionChange",d)};var Ee=(e,t)=>{if(t.has(e))return t.get(e);var n=e,a=Bt.call(e).slice(8,-1);if(a=="Object"){t.set(e,n={});for(var l in e)n[l]=Ee(e[l],t);e[ge]&&(n[ge]=Ee(e[ge],t)),e[he]&&(n[he]=e[he])}else if(a=="Array"){t.set(e,n=[]);for(var u=0,f=e.length;u<f;u++)n[u]=Ee(e[u],t)}return n},st=e=>Ee(e,new Map),lt=(e,t,n)=>{var a={};for(var l in e)a[l]=e[l],delete e[l];for(var l in a)l==t&&Object.assign(e,n),n.hasOwnProperty(l)||(e[l]=a[l])},Bt={}.toString,at=(e,t)=>e.replace(/<(\d+)>/g,(n,a)=>`(?:${t[+a]})`),Wt=(e,t,n)=>RegExp(at(e,t),n),it=[{pattern:/&[a-z\d]{1,8};/i,alias:"named-entity"},/&#x?[a-f\d]{1,8};/i],Nt={pattern:/<!--(?:(?!<!--)[^])*?-->/g,greedy:!0},Ht={pattern:/<\/?(?!\d)[^\s/=>$<%]+(?:\s(?:\s*[^\s/=>]+(?:\s*=\s*(?!\s)(?:"[^"]*"|'[^']*'|[^\s"'=>]+(?=[\s>]))?|(?=[\s/>])))+)?\s*\/?>/g,greedy:!0,inside:{punctuation:/^<\/?|\/?>$/,tag:{pattern:/^\S+/,inside:{namespace:/^[^:]+:/}},"attr-value":[{pattern:/(=\s*)(?:"[^"]*"|'[^']*'|[^\s>]+)/g,lookbehind:!0,greedy:!0,inside:{punctuation:/^["']|["']$/,entity:it}}],"attr-equals":/=/,"attr-name":{pattern:/\S+/,inside:{namespace:/^[^:]+:/}}}};V.rss=V.atom=V.ssml=V.xml={comment:Nt,prolog:{pattern:/<\?[^]+?\?>/g,greedy:!0},doctype:{pattern:/<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/gi,greedy:!0,inside:{"internal-subset":{pattern:/(\[)[^]+(?=\]\s*>$)/,lookbehind:!0,inside:"xml"},string:/"[^"]*"|'[^']*'/,punctuation:/^<!|[>[\]]/,"doctype-tag":/^DOCTYPE/i,name:/\S+/}},cdata:{pattern:/<!\[CDATA\[[^]*?\]\]>/gi,greedy:!0},tag:Ht,entity:it,"markup-bracket":{pattern:/[()[\]{}]/,alias:"punctuation"}};var _e=(e,t)=>(e["language-"+t]={pattern:/[^]+/,inside:t},e),Ke=(e,t)=>({pattern:RegExp(`(<${e}[^>]*>)(?!</${e}>)(?:<!\\[CDATA\\[(?:[^\\]]|\\](?!\\]>))*\\]\\]>|(?!<!\\[CDATA\\[)[^])+?(?=</${e}>)`,"gi"),lookbehind:!0,greedy:!0,inside:_e({"included-cdata":{pattern:/<!\[CDATA\[[^]*?\]\]>/i,inside:_e({cdata:/^<!\[CDATA\[|\]\]>$/i},t)}},t)}),qe=(e,t,n=e)=>({pattern:RegExp(`([\\s"']${e}\\s*=\\s*)(?:"[^"]*"|'[^']*'|[^\\s>]+)`,"gi"),lookbehind:!0,greedy:!0,alias:n,inside:_e({punctuation:/^["']|["']$/},t)}),ct=V.svg=V.mathml=V.html=V.markup=st(V.xml);ct.tag.inside["attr-value"].unshift(qe("style","css"),qe("on[a-z]+","javascript","script"));lt(ct,"cdata",{style:Ke("style","css"),script:Ke("script","javascript")});var jt=[`(?:\\\\.|[^\\\\
]|
(?!
))`],we=e=>Wt(`((?:^|[^\\\\])(?:\\\\\\\\)*)(?:${e})`,jt,"g"),Oe=/(?:\\.|``(?:[^\n`]|`(?!`))+``|`[^\n`]+`|[^\\\n|`])+/,Ue=at(`\\|?<0>(?:\\|<0>)+\\|?(?:
|(?![\\s\\S]))`,[Oe.source]),Vt=`\\|?[ ]*:?-{3,}:?[ ]*(?:\\|[ ]*:?-{3,}:?[ ]*)+\\|?
`,ce=V.md=V.markdown=st(V.html);lt(ce,"prolog",{"front-matter-block":{pattern:/(^(?:\s*\n)?)---(?!.)[^]*?\n---(?!.)/g,lookbehind:!0,greedy:!0,inside:{punctuation:/^---|---$/,"front-matter":{pattern:/\S(?:[^]*\S)?/,alias:"language-yaml",inside:"yaml"}}},blockquote:{pattern:/^>(?:[ ]*>)*/m,alias:"punctuation"},table:{pattern:RegExp("^"+Ue+Vt+"(?:"+Ue+")*","m"),inside:{"table-header-row":{pattern:/^.+/,inside:{"table-header":{pattern:Oe,alias:"important",inside:ce},punctuation:/\|/}},"table-data-rows":{pattern:/(.+\n)[^]+/,lookbehind:!0,inside:{"table-data":{pattern:Oe,inside:ce},punctuation:/\|/}},"table-line":{pattern:/.+/,inside:{punctuation:/\S+/}}}},code:[{pattern:/(^[ ]*\n)(?: | ).+(?:\n(?: | ).+)*/m,lookbehind:!0,alias:"keyword"},{pattern:/^(```+)[^`][^]*?^\1`*$/mg,greedy:!0,inside:{punctuation:/^`+|`+$/,"code-language":/^.+/,"code-block":/(?!^)[^]+(?=\n)/,[he](e,t){var n=Ge(e,t),a;return n[5]&&(a=(/[a-z][\w-]*/i.exec(n[1].content.replace(/\b#/g,"sharp").replace(/\b\+\+/g,"pp"))||[""])[0].toLowerCase(),n[3].alias="language-"+a,(t=V[a])&&(n[3].content=ze(n[3].content,t))),n}}}],title:[{pattern:/\S.*\n(?:==+|--+)(?=[ ]*$)/m,alias:"important",inside:{punctuation:/=+$|-+$/}},{pattern:/(^\s*)#.+/m,lookbehind:!0,alias:"important",inside:{punctuation:/^#+|#+$/}}],hr:{pattern:/(^\s*)([*-])(?:[ ]*\2){2,}(?=\s*$)/m,lookbehind:!0,alias:"punctuation"},list:{pattern:/(^\s*)(?:[*+-]|\d+\.)(?=[ ].)/m,lookbehind:!0,alias:"punctuation"},"url-reference":{pattern:/!?\[[^\]]+\]:[ ]+(?:\S+|<(?:\\.|[^\\>])+>)(?:[ ]+(?:"(?:\\.|[^\\"])*"|'(?:\\.|[^\\'])*'|\((?:\\.|[^\\)])*\)))?/,inside:{variable:{pattern:/^(!?\[)[^\]]+/,lookbehind:!0},string:/(?:"(?:\\.|[^\\"])*"|'(?:\\.|[^\\'])*'|\((?:\\.|[^\\)])*\))$/,punctuation:/^[[\]!:]|<|>/},alias:"url"},bold:{pattern:we("\\b__(?:(?!_)<0>|_(?:(?!_)<0>)+_)+__\\b|\\*\\*(?:(?!\\*)<0>|\\*(?:(?!\\*)<0>)+\\*)+\\*\\*"),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^..)[^]+(?=..)/,lookbehind:!0,inside:{}},punctuation:/../}},italic:{pattern:we("\\b_(?:(?!_)<0>|__(?:(?!_)<0>)+__)+_\\b|\\*(?:(?!\\*)<0>|\\*\\*(?:(?!\\*)<0>)+\\*\\*)+\\*"),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(?!^)[^]+(?=.)/,inside:{}},punctuation:/./}},strike:{pattern:we("(~~?)(?:(?!~)<0>)+\\2"),lookbehind:!0,greedy:!0,inside:{punctuation:/^~~?|~~?$/,content:{pattern:/[^]+/,inside:{}}}},"code-snippet":{pattern:/(^|[^\\`])(`+)[^\n`](?:|.*?[^\n`])\2(?!`)/g,lookbehind:!0,greedy:!0,alias:"code keyword"},url:{pattern:we('!?\\[(?:(?!\\])<0>)+\\](?:\\([^\\s)]+(?:[ ]+"(?:\\\\.|[^\\\\"])*")?\\)|[ ]?\\[(?:(?!\\])<0>)+\\])'),lookbehind:!0,greedy:!0,inside:{operator:/^!/,content:{pattern:/(^\[)[^\]]+(?=\])/,lookbehind:!0,inside:{}},variable:{pattern:/(^\][ ]?\[)[^\]]+(?=\]$)/,lookbehind:!0},url:{pattern:/(^\]\()[^\s)]+/,lookbehind:!0},string:{pattern:/(^[ ]+)"(?:\\.|[^\\"])*"(?=\)$)/,lookbehind:!0},"markup-bracket":ce["markup-bracket"]}}});["url","bold","italic","strike"].forEach(e=>{["url","bold","italic","strike","code-snippet","markup-bracket"].forEach(t=>{e!=t&&(ce[e].inside.content.inside[t]=ce[t])})});window.prismEditor=(e,t,...n)=>ut(e,t,dt(),Lt(),xt(),wt(),_t(),zt(),Dt(),Et(),yt(),Tt(),...n);