window.nostr.js 0.4.1 → 0.4.2
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/dist/index.html +1 -1
- package/dist/window.nostr.js +1 -1
- package/justfile +1 -6
- package/package.json +1 -1
- package/src/App.svelte +1 -1
- package/dist/iframe.js +0 -22
- package/dist/iframe.js.map +0 -7
- package/iframe/build.js +0 -9
- package/iframe/iframe.ts +0 -28
package/dist/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>dev</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-Kz_u8dYi.js"></script>
|
|
8
8
|
</head>
|
|
9
9
|
<body
|
|
10
10
|
style="
|
package/dist/window.nostr.js
CHANGED
|
@@ -17,7 +17,7 @@ var bl=Object.defineProperty;var wl=(Ye,j,Pe)=>j in Ye?bl(Ye,j,{enumerable:!0,co
|
|
|
17
17
|
After that you will be returned to this page.`),b=Y(),h=P("button"),g=F("Start account creation »"),k(n,"class","text-center text-lg"),k(o,"class","mt-4 text-center text-sm leading-4"),k(h,"class",d="mt-4 block w-full cursor-pointer rounded border-0 px-2 py-1 text-lg text-white disabled:cursor-default disabled:bg-neutral-400 disabled:text-neutral-200 bg-"+t[0]+"-900 hover:bg-"+t[0]+"-950"),k(e,"class","m-auto w-full")},m(m,S){K(m,e,S),O(e,n),O(e,r),O(e,o),O(o,i),O(o,s),O(s,a),O(o,l),O(o,f),O(o,u),O(e,b),O(e,h),O(h,g),p||(w=ne(h,"click",t[49]),p=!0)},p(m,S){S[0]&32768&&c!==(c=new URL(m[15]).host+"")&&He(a,c),S[0]&1&&d!==(d="mt-4 block w-full cursor-pointer rounded border-0 px-2 py-1 text-lg text-white disabled:cursor-default disabled:bg-neutral-400 disabled:text-neutral-200 bg-"+m[0]+"-900 hover:bg-"+m[0]+"-950")&&k(h,"class",d)},i:j,o:j,d(m){m&&z(e),p=!1,w()}}}function Co(t){let e,n,r=t[23].picture&&Uo(t),o=t[23].name&&Po(t);return{c(){e=P("div"),r&&r.c(),n=Y(),o&&o.c(),k(e,"class","mb-2 flex items-center justify-center gap-2")},m(i,s){K(i,e,s),r&&r.m(e,null),O(e,n),o&&o.m(e,null)},p(i,s){i[23].picture?r?r.p(i,s):(r=Uo(i),r.c(),r.m(e,n)):r&&(r.d(1),r=null),i[23].name?o?o.p(i,s):(o=Po(i),o.c(),o.m(e,null)):o&&(o.d(1),o=null)},d(i){i&&z(e),r&&r.d(),o&&o.d()}}}function Uo(t){let e,n,r;return{c(){e=P("img"),Ze(e.src,n=t[23].picture)||k(e,"src",n),k(e,"alt",""),k(e,"class",r="h-10 w-10 rounded-full border-2 border-solid border-transparent group-hover:border-"+t[0]+"-100")},m(o,i){K(o,e,i)},p(o,i){i[0]&8388608&&!Ze(e.src,n=o[23].picture)&&k(e,"src",n),i[0]&1&&r!==(r="h-10 w-10 rounded-full border-2 border-solid border-transparent group-hover:border-"+o[0]+"-100")&&k(e,"class",r)},d(o){o&&z(e)}}}function Po(t){let e,n=t[23].name+"",r;return{c(){e=P("div"),r=F(n),k(e,"class","text-3xl decoration-2 underline-offset-4 group-hover:underline")},m(o,i){K(o,e,i),O(e,r)},p(o,i){i[0]&8388608&&n!==(n=o[23].name+"")&&He(r,n)},d(o){o&&z(e)}}}function Ro(t){let e,n;return{c(){e=P("div"),n=F(t[21]),k(e,"class","my-2 rounded bg-yellow-100 p-2 text-center text-sm leading-4 text-red-400")},m(r,o){K(r,e,o),O(e,n)},p(r,o){o[0]&2097152&&He(n,r[21])},d(r){r&&z(e)}}}function Na(t){let e;return{c(){e=F("Connect »")},m(n,r){K(n,e,r)},i:j,o:j,d(n){n&&z(e)}}}function La(t){let e,n,r;return n=new No({}),{c(){e=F(`Connecting to bunker
|
|
18
18
|
`),ur(n.$$.fragment)},m(o,i){K(o,e,i),ln(n,o,i),r=!0},i(o){r||(me(n.$$.fragment,o),r=!0)},o(o){xe(n.$$.fragment,o),r=!1},d(o){o&&z(e),un(n,o)}}}function Ho(t){let e,n,r,o,i;return{c(){e=P("div"),n=F(`Waiting too much?
|
|
19
19
|
`),r=P("button"),r.textContent="Cancel the connection",k(r,"class","cursor-pointer border-0 bg-transparent text-sm text-white underline"),k(e,"class","mt-6 text-center text-sm leading-3")},m(s,c){K(s,e,c),O(e,n),O(e,r),o||(i=ne(r,"click",t[42]),o=!0)},p:j,d(s){s&&z(e),o=!1,i()}}}function Mo(t){let e,n,r,o,i,s,c;return{c(){e=P("div"),n=F("Do you need a Nostr account?"),r=P("br"),o=Y(),i=P("button"),i.textContent="Sign up now",k(i,"class","cursor-pointer border-0 bg-transparent text-sm text-white underline"),k(e,"class","mt-6 text-center text-sm leading-3")},m(a,l){K(a,e,l),O(e,n),O(e,r),O(e,o),O(e,i),s||(c=ne(i,"click",t[38]),s=!0)},p:j,d(a){a&&z(e),s=!1,c()}}}function jo(t){let e,n,r;return{c(){e=P("option"),k(e,"label",n=t[82].domain),e.__value=r=t[82],rt(e,e.__value),k(e,"class","px-2 py-1 text-lg")},m(o,i){K(o,e,i)},p(o,i){i[0]&16777216&&n!==(n=o[82].domain)&&k(e,"label",n),i[0]&16777216&&r!==(r=o[82])&&(e.__value=r,rt(e,e.__value))},d(o){o&&z(e)}}}function Ta(t){let e,n;return{c(){e=P("img"),Ze(e.src,n=t[23].picture)||k(e,"src",n),k(e,"alt",""),k(e,"class","h-6 w-6 rounded-full")},m(r,o){K(r,e,o)},p(r,o){o[0]&8388608&&!Ze(e.src,n=r[23].picture)&&k(e,"src",n)},i:j,o:j,d(r){r&&z(e)}}}function Ca(t){let e,n,r,o=(t[23].name||t[23].npub.slice(0,7)+"…"+t[23].npub.slice(-4))+"",i;function s(l,f){return l[23].picture?Ha:Ra}let c=s(t),a=c(t);return{c(){e=P("div"),a.c(),n=Y(),r=P("div"),i=F(o),k(r,"class","inline-block max-w-56 overflow-hidden overflow-ellipsis whitespace-nowrap"),k(e,"class","flex items-center px-2")},m(l,f){K(l,e,f),a.m(e,null),O(e,n),O(e,r),O(r,i)},p(l,f){c===(c=s(l))&&a?a.p(l,f):(a.d(1),a=c(l),a&&(a.c(),a.m(e,n))),f[0]&8388608&&o!==(o=(l[23].name||l[23].npub.slice(0,7)+"…"+l[23].npub.slice(-4))+"")&&He(i,o)},i:j,o:j,d(l){l&&z(e),a.d()}}}function Ua(t){let e;function n(i,s){return i[2]?ja:Ma}let r=n(t),o=r(t);return{c(){o.c(),e=sn()},m(i,s){o.m(i,s),K(i,e,s)},p(i,s){r!==(r=n(i))&&(o.d(1),o=r(i),o&&(o.c(),o.m(e.parentNode,e)))},i:j,o:j,d(i){i&&z(e),o.d(i)}}}function Pa(t){let e,n,r,o;return r=new No({}),{c(){e=P("div"),n=F(`Connecting to bunker
|
|
20
|
-
`),ur(r.$$.fragment),k(e,"class","flex items-center px-2")},m(i,s){K(i,e,s),O(e,n),ln(r,e,null),o=!0},p:j,i(i){o||(me(r.$$.fragment,i),o=!0)},o(i){xe(r.$$.fragment,i),o=!1},d(i){i&&z(e),un(r)}}}function Ra(t){let e;return{c(){e=P("span"),e.textContent="☉",k(e,"class","mr-2")},m(n,r){K(n,e,r)},p:j,d(n){n&&z(e)}}}function Ha(t){let e,n;return{c(){e=P("img"),Ze(e.src,n=t[23].picture)||k(e,"src",n),k(e,"alt",""),k(e,"class","mr-2 h-5 w-5 rounded-full")},m(r,o){K(r,e,o)},p(r,o){o[0]&8388608&&!Ze(e.src,n=r[23].picture)&&k(e,"src",n)},d(r){r&&z(e)}}}function Ma(t){let e;return{c(){e=P("div"),e.textContent="Connect with Nostr",k(e,"class","flex items-center px-2")},m(n,r){K(n,e,r)},d(n){n&&z(e)}}}function ja(t){let e;return{c(){e=P("div"),e.textContent="N",k(e,"class","w-6 text-center")},m(n,r){K(n,e,r)},d(n){n&&z(e)}}}function qo(t){let e,n,r,o;return{c(){e=P("iframe"),k(e,"title","~"),Ze(e.src,n="https://the-nostr.org/iframe.html")||k(e,"src",n)},m(i,s){K(i,e,s),t[58](e),r||(o=ne(e,"load",t[31]),r=!0)},p:j,d(i){i&&z(e),t[58](null),r=!1,o()}}}function qa(t){let e,n,r,o,i,s,c,a,l;const f=[Ea,xa,va],u=[];function b(g,d){return!g[27]&&!g[23]&&g[1]?0:g[27]?2:1}n=b(t),r=u[n]=f[n](t);let h=t[7]&&qo(t);return{c(){e=P("div"),r.c(),i=Y(),h&&h.c(),s=sn(),k(e,"class","draggable animate-fadein font-sans text-white"),k(e,"style",o="position: fixed; "+(t[27]&&t[5]?"width: 100vw;":"")+"; right: "+(t[27]&&t[5]?"0":t[3])+"px; user-select: none; "+(t[27]&&t[5]?"bottom: 0px":t[26]+":"+t[25]+"px")),sr(e,"cursor-pointer",!t[23]&&!t[27])},m(g,d){K(g,e,d),u[n].m(e,null),t[57](e),K(g,i,d),h&&h.m(g,d),K(g,s,d),c=!0,a||(l=[ne(Xn,"click",t[32]),ne(Xn,"mouseup",t[45]),ne(Xn,"mousemove",t[44]),ne(e,"mousedown",t[43])],a=!0)},p(g,d){let p=n;n=b(g),n===p?u[n].p(g,d):(Pt(),xe(u[p],1,1,()=>{u[p]=null}),Rt(),r=u[n],r?r.p(g,d):(r=u[n]=f[n](g),r.c()),me(r,1),r.m(e,null)),(!c||d[0]&234881064&&o!==(o="position: fixed; "+(g[27]&&g[5]?"width: 100vw;":"")+"; right: "+(g[27]&&g[5]?"0":g[3])+"px; user-select: none; "+(g[27]&&g[5]?"bottom: 0px":g[26]+":"+g[25]+"px")))&&k(e,"style",o),(!c||d[0]&142606336)&&sr(e,"cursor-pointer",!g[23]&&!g[27]),g[7]?h?h.p(g,d):(h=qo(g),h.c(),h.m(s.parentNode,s)):h&&(h.d(1),h=null)},i(g){c||(me(r),c=!0)},o(g){xe(r),c=!1},d(g){g&&(z(e),z(i),z(s)),u[n].d(),t[57](null),h&&h.d(g),a=!1,Re(l)}}}const zo="We could not connect to a NIP-46 bunker with that url, are you sure it is set up correctly?",Ko="We were not able to connect using this address. For it to work it has to come from a NIP-46 provider.",Fe=20;function er(t){return window.open(t,"window.nostr","width=600,height=800,popup=yes")}function za(t,e,n){let r,o,i,s,c,a;const l=ya("only screen and (max-width: 640px)");Xo(t,l,L=>n(5,a=L));const f={ORIGIN:"wnj:origin",CLIENT_SECRET:"wnj:clientSecret",Y_POS:"wnj:ypos",CALLBACK_TOKEN:"wnj:callbackToken",BUNKER_POINTER:"wnj:bunkerPointer",CACHED_PUBKEY:"wnj:cachedPubKey",IGNORE_IFRAME:"wnj:ignoreIframe"};let u,{accent:b}=e,{position:h="top"}=e,{startHidden:g}=e,{compactMode:d}=e;const p=window,w=new $s;let m=!1,S,T,R,_,x,y,E;const U=localStorage.getItem(f.CLIENT_SECRET);U?E=pn(U):(E=ks(),localStorage.setItem(f.CLIENT_SECRET,fe(E)));let N="closed",M,W,V,v,A,C,H=null,I=null,q=null,D=!1,$,X,Q,ce=!1,J,re,ue=[],{right:ae=20}=e,Be=!1,Ge=!1,Ce,ge,Ue;const Bt={pool:w,onauth(L){$?n(15,H=L):J?(n(17,q=L),n(27,i=!0)):n(16,I=L)}},It=gr(()=>{switch(N){case"justopened":n(47,N="opened");break;case"justclosed":n(47,N="closed");break}},500);function Xt(){n(47,N="justopened"),It()}function Ot(){n(47,N="justclosed"),It()}function en(){if(M&&!C){Nt();return}Xt()}rr();let Zo={isWnj:!0,async getPublicKey(){return!A&&!C&&Xt(),(await v).getPublicKey()},async signEvent(L){try{return!A&&!C&&en(),await(await v).signEvent(L)}finally{n(17,q=null),Ot()}},async getRelays(){return!A&&!C&&en(),(await v).getRelays()},nip04:{async encrypt(L,Z){return!A&&!C&&en(),(await v).nip04Encrypt(L,Z)},async decrypt(L,Z){return!A&&!C&&en(),(await v).nip04Decrypt(L,Z)}}};function rr(){Ot(),M=null,v=new Promise((L,Z)=>{W=L,V=Z}),n(23,J=null),n(14,A=!1),n(18,D=!1),n(19,$=!1),C=!1,re=null,n(21,Q="")}ii(()=>{if(!M){let L=localStorage.getItem(f.BUNKER_POINTER);L?(M=JSON.parse(L),tn(),localStorage.getItem(f.CACHED_PUBKEY)||Nt()):localStorage.getItem(f.IGNORE_IFRAME)||n(7,m=!0)}if(p.nostr&&!p.nostr.isWnj){p.destroyWnj();return}else Object.defineProperty(window,"nostr",{get(){return Zo},set(L){Zo=L,L.isWnj||p.destroyWnj()},configurable:!0});return()=>{re&&re.close()}});function Wa(){var Z;window.addEventListener("message",L),(Z=S==null?void 0:S.contentWindow)==null||Z.postMessage({getbunker:!0},"*");async function L(ve){let{bunker:Lt}=ve.data;Lt&&(M=await So(Lt),tn(),Nt(),window.removeEventListener("message",L))}}function Da(L){Math.abs(o-ge)>6||Date.now()-Ue>600||N==="justopened"||N==="justclosed"||(L.composedPath().find(Z=>Z.id==="wnj")?Xt():Ot())}function Va(L){Ot(),n(19,$=!1),n(15,H=null),n(16,I=null),n(17,q=null),L.stopPropagation()}function Fa(L){n(22,ce=!0),L.stopPropagation()}function Ga(L){n(22,ce=!1),L.stopPropagation()}async function Ya(L){L.preventDefault();try{if(M=await So(T.value),!M){T.value.match(Qt)?n(21,Q=zo):n(21,Q=Ko);return}T.setCustomValidity(""),n(21,Q=""),await Nt(),tn()}catch{T.value.match(Qt)?n(21,Q=zo):n(21,Q=Ko),n(14,A=!1)}}async function Za(L){L.preventDefault(),localStorage.removeItem(f.BUNKER_POINTER),localStorage.removeItem(f.CACHED_PUBKEY),localStorage.setItem(f.IGNORE_IFRAME,""),rr()}async function Ja(L){L.preventDefault(),n(19,$=!0),ue.length===0&&(n(24,ue=await fa(w,["wss://relay.nostr.band","wss://nos.lol","wss://nostr-pub.wellorder.net"])),n(12,y=ue[0]))}function Qa(L){n(19,$=!1)}async function Xa(L){if(L.preventDefault(),!y)return;n(20,X=!0);let Z=await ua(y,Bt,_.value,y.domain,void 0,E);n(20,X=!1),Xt(),n(19,$=!1),M=Z.bp,tn(),Nt(Z)}const el=gr(async()=>{y&&_.value.length>0&&(await da(_.value+"@"+y.domain)?_.setCustomValidity(`'${_.value}' is already taken.`):_.setCustomValidity(""))},500);function tl(){n(18,D=!1),n(14,A=!1),V("connection aborted"),rr()}async function Nt(L=void 0){L=L||new Bo(E,M,Bt),n(14,A=!0);let Z=setTimeout(()=>{n(18,D=!0),n(27,i=!0)},5e3);try{await L.connect(),C=!0,localStorage.setItem(f.BUNKER_POINTER,JSON.stringify(M)),Ot(),W(L)}catch(ve){V((ve==null?void 0:ve.message)||String(ve))}finally{clearTimeout(Z),n(14,A=!1),n(18,D=!1),n(15,H=null),n(16,I=null),n(17,q=null)}}async function tn(){let L=localStorage.getItem(f.CACHED_PUBKEY);L||(L=await(await v).getPublicKey(),localStorage.setItem(f.CACHED_PUBKEY,L)),n(23,J={pubkey:L,npub:ga(L),event:null}),re=w.subscribeMany(["wss://purplepag.es","wss://relay.snort.social","wss://relay.nos.social"],[{kinds:[0],authors:[L]}],{onevent(Z){var ve;if(!((((ve=J.event)==null?void 0:ve.created_at)||0)>=Z.created_at))try{let{name:Lt,picture:pl}=JSON.parse(Z.content);n(23,J.event=Z,J),n(23,J.name=Lt,J),n(23,J.picture=pl,J)}catch{}}})}function nl(L){if(i)return;Be=!0;const Z=u.getBoundingClientRect();Ce=L.clientY-Z.top,ge=o,Ue=Date.now()}function rl(L){Be&&(r==="top"?n(25,o=L.clientY):n(25,o=window.innerHeight-L.clientY),n(25,o-=Ce),n(48,Ge=!0),o<Fe&&n(25,o=Fe),o>window.innerHeight-Fe&&n(25,o=window.innerHeight-Fe))}function ol(){if(Be=!1,setTimeout(()=>{n(48,Ge=!1)},10),Ge){const L=u.getBoundingClientRect(),Z=window.innerHeight,ve=Z/2;L.top<ve?(n(26,r="top"),n(25,o=L.top)):(n(26,r="bottom"),n(25,o=Z-L.bottom)),o<Fe&&n(25,o=Fe),localStorage.setItem(f.ORIGIN,r),localStorage.setItem(f.Y_POS,o.toString())}}const il=()=>er(H),sl=()=>er(I),cl=()=>{er(q)};function al(L){it[L?"unshift":"push"](()=>{_=L,n(10,_)})}function ll(){x=this.value,n(11,x)}function ul(){y=ri(this),n(12,y),n(24,ue)}function fl(L){it[L?"unshift":"push"](()=>{T=L,n(9,T)})}function dl(){R=this.value,n(4,R)}function hl(L){it[L?"unshift":"push"](()=>{u=L,n(6,u)})}function gl(L){it[L?"unshift":"push"](()=>{S=L,n(8,S)})}return t.$$set=L=>{"accent"in L&&n(0,b=L.accent),"position"in L&&n(46,h=L.position),"startHidden"in L&&n(1,g=L.startHidden),"compactMode"in L&&n(2,d=L.compactMode),"right"in L&&n(3,ae=L.right)},t.$$.update=()=>{t.$$.dirty[0]&32|t.$$.dirty[1]&32768&&n(26,r=a?"bottom":localStorage.getItem(f.ORIGIN)||h),t.$$.dirty[0]&32&&n(25,o=a?Fe:parseInt(localStorage.getItem(f.Y_POS)||"0")||Fe),t.$$.dirty[1]&65536&&n(27,i=N==="justopened"||N==="opened"),t.$$.dirty[0]&1|t.$$.dirty[1]&131072&&n(29,s=Ge?"cursor-grabbing outline-dashed outline-"+b+"-500 outline-1 outline-offset-4":"outline-none"),t.$$.dirty[0]&16&&n(28,c=R&&(R.match(Qt)||R.match(Io)))},[b,g,d,ae,R,a,u,m,S,T,_,x,y,E,A,H,I,q,D,$,X,Q,ce,J,ue,o,r,i,c,s,l,Wa,Da,Va,Fa,Ga,Ya,Za,Ja,Qa,Xa,el,tl,nl,rl,ol,h,N,Ge,il,sl,cl,al,ll,ul,fl,dl,hl,gl]}class Ka extends dr{constructor(e){super(),fr(this,e,za,qa,rn,{accent:0,position:46,startHidden:1,compactMode:2,right:3},null,[-1,-1,-1])}}const yt=window;yt.destroyWnj=()=>{setTimeout(()=>{$a.$destroy()},1)};const tr=document.createElement("div");tr.style.zIndex="90000",document.body.appendChild(tr);const nr=document.createElement("div");nr.id="wnj";const $o=document.createElement("style");$o.innerHTML=Ye;const Wo=tr.attachShadow({mode:"open"});Wo.appendChild(nr),Wo.appendChild($o);const $a=new Ka({target:nr,props:{accent:((Do=yt.wnjParams)==null?void 0:Do.accent)||"cyan",position:((Vo=yt.wnjParams)==null?void 0:Vo.position)==="bottom"?"bottom":"top",startHidden:(Fo=yt.wnjParams)==null?void 0:Fo.startHidden,compactMode:(Go=yt.wnjParams)==null?void 0:Go.compactMode}});if(!((Yo=yt.wnjParams)!=null&&Yo.disableOverflowFix)){const t=document.createElement("style"),e=`
|
|
20
|
+
`),ur(r.$$.fragment),k(e,"class","flex items-center px-2")},m(i,s){K(i,e,s),O(e,n),ln(r,e,null),o=!0},p:j,i(i){o||(me(r.$$.fragment,i),o=!0)},o(i){xe(r.$$.fragment,i),o=!1},d(i){i&&z(e),un(r)}}}function Ra(t){let e;return{c(){e=P("span"),e.textContent="☉",k(e,"class","mr-2")},m(n,r){K(n,e,r)},p:j,d(n){n&&z(e)}}}function Ha(t){let e,n;return{c(){e=P("img"),Ze(e.src,n=t[23].picture)||k(e,"src",n),k(e,"alt",""),k(e,"class","mr-2 h-5 w-5 rounded-full")},m(r,o){K(r,e,o)},p(r,o){o[0]&8388608&&!Ze(e.src,n=r[23].picture)&&k(e,"src",n)},d(r){r&&z(e)}}}function Ma(t){let e;return{c(){e=P("div"),e.textContent="Connect with Nostr",k(e,"class","flex items-center px-2")},m(n,r){K(n,e,r)},d(n){n&&z(e)}}}function ja(t){let e;return{c(){e=P("div"),e.textContent="N",k(e,"class","w-6 text-center")},m(n,r){K(n,e,r)},d(n){n&&z(e)}}}function qo(t){let e,n,r,o;return{c(){e=P("iframe"),k(e,"title","~"),Ze(e.src,n="https://join.the-nostr.org/iframe.html")||k(e,"src",n)},m(i,s){K(i,e,s),t[58](e),r||(o=ne(e,"load",t[31]),r=!0)},p:j,d(i){i&&z(e),t[58](null),r=!1,o()}}}function qa(t){let e,n,r,o,i,s,c,a,l;const f=[Ea,xa,va],u=[];function b(g,d){return!g[27]&&!g[23]&&g[1]?0:g[27]?2:1}n=b(t),r=u[n]=f[n](t);let h=t[7]&&qo(t);return{c(){e=P("div"),r.c(),i=Y(),h&&h.c(),s=sn(),k(e,"class","draggable animate-fadein font-sans text-white"),k(e,"style",o="position: fixed; "+(t[27]&&t[5]?"width: 100vw;":"")+"; right: "+(t[27]&&t[5]?"0":t[3])+"px; user-select: none; "+(t[27]&&t[5]?"bottom: 0px":t[26]+":"+t[25]+"px")),sr(e,"cursor-pointer",!t[23]&&!t[27])},m(g,d){K(g,e,d),u[n].m(e,null),t[57](e),K(g,i,d),h&&h.m(g,d),K(g,s,d),c=!0,a||(l=[ne(Xn,"click",t[32]),ne(Xn,"mouseup",t[45]),ne(Xn,"mousemove",t[44]),ne(e,"mousedown",t[43])],a=!0)},p(g,d){let p=n;n=b(g),n===p?u[n].p(g,d):(Pt(),xe(u[p],1,1,()=>{u[p]=null}),Rt(),r=u[n],r?r.p(g,d):(r=u[n]=f[n](g),r.c()),me(r,1),r.m(e,null)),(!c||d[0]&234881064&&o!==(o="position: fixed; "+(g[27]&&g[5]?"width: 100vw;":"")+"; right: "+(g[27]&&g[5]?"0":g[3])+"px; user-select: none; "+(g[27]&&g[5]?"bottom: 0px":g[26]+":"+g[25]+"px")))&&k(e,"style",o),(!c||d[0]&142606336)&&sr(e,"cursor-pointer",!g[23]&&!g[27]),g[7]?h?h.p(g,d):(h=qo(g),h.c(),h.m(s.parentNode,s)):h&&(h.d(1),h=null)},i(g){c||(me(r),c=!0)},o(g){xe(r),c=!1},d(g){g&&(z(e),z(i),z(s)),u[n].d(),t[57](null),h&&h.d(g),a=!1,Re(l)}}}const zo="We could not connect to a NIP-46 bunker with that url, are you sure it is set up correctly?",Ko="We were not able to connect using this address. For it to work it has to come from a NIP-46 provider.",Fe=20;function er(t){return window.open(t,"window.nostr","width=600,height=800,popup=yes")}function za(t,e,n){let r,o,i,s,c,a;const l=ya("only screen and (max-width: 640px)");Xo(t,l,L=>n(5,a=L));const f={ORIGIN:"wnj:origin",CLIENT_SECRET:"wnj:clientSecret",Y_POS:"wnj:ypos",CALLBACK_TOKEN:"wnj:callbackToken",BUNKER_POINTER:"wnj:bunkerPointer",CACHED_PUBKEY:"wnj:cachedPubKey",IGNORE_IFRAME:"wnj:ignoreIframe"};let u,{accent:b}=e,{position:h="top"}=e,{startHidden:g}=e,{compactMode:d}=e;const p=window,w=new $s;let m=!1,S,T,R,_,x,y,E;const U=localStorage.getItem(f.CLIENT_SECRET);U?E=pn(U):(E=ks(),localStorage.setItem(f.CLIENT_SECRET,fe(E)));let N="closed",M,W,V,v,A,C,H=null,I=null,q=null,D=!1,$,X,Q,ce=!1,J,re,ue=[],{right:ae=20}=e,Be=!1,Ge=!1,Ce,ge,Ue;const Bt={pool:w,onauth(L){$?n(15,H=L):J?(n(17,q=L),n(27,i=!0)):n(16,I=L)}},It=gr(()=>{switch(N){case"justopened":n(47,N="opened");break;case"justclosed":n(47,N="closed");break}},500);function Xt(){n(47,N="justopened"),It()}function Ot(){n(47,N="justclosed"),It()}function en(){if(M&&!C){Nt();return}Xt()}rr();let Zo={isWnj:!0,async getPublicKey(){return!A&&!C&&Xt(),(await v).getPublicKey()},async signEvent(L){try{return!A&&!C&&en(),await(await v).signEvent(L)}finally{n(17,q=null),Ot()}},async getRelays(){return!A&&!C&&en(),(await v).getRelays()},nip04:{async encrypt(L,Z){return!A&&!C&&en(),(await v).nip04Encrypt(L,Z)},async decrypt(L,Z){return!A&&!C&&en(),(await v).nip04Decrypt(L,Z)}}};function rr(){Ot(),M=null,v=new Promise((L,Z)=>{W=L,V=Z}),n(23,J=null),n(14,A=!1),n(18,D=!1),n(19,$=!1),C=!1,re=null,n(21,Q="")}ii(()=>{if(!M){let L=localStorage.getItem(f.BUNKER_POINTER);L?(M=JSON.parse(L),tn(),localStorage.getItem(f.CACHED_PUBKEY)||Nt()):localStorage.getItem(f.IGNORE_IFRAME)||n(7,m=!0)}if(p.nostr&&!p.nostr.isWnj){p.destroyWnj();return}else Object.defineProperty(window,"nostr",{get(){return Zo},set(L){Zo=L,L.isWnj||p.destroyWnj()},configurable:!0});return()=>{re&&re.close()}});function Wa(){var Z;window.addEventListener("message",L),(Z=S==null?void 0:S.contentWindow)==null||Z.postMessage({getbunker:!0},"*");async function L(ve){let{bunker:Lt}=ve.data;Lt&&(M=await So(Lt),tn(),Nt(),window.removeEventListener("message",L))}}function Da(L){Math.abs(o-ge)>6||Date.now()-Ue>600||N==="justopened"||N==="justclosed"||(L.composedPath().find(Z=>Z.id==="wnj")?Xt():Ot())}function Va(L){Ot(),n(19,$=!1),n(15,H=null),n(16,I=null),n(17,q=null),L.stopPropagation()}function Fa(L){n(22,ce=!0),L.stopPropagation()}function Ga(L){n(22,ce=!1),L.stopPropagation()}async function Ya(L){L.preventDefault();try{if(M=await So(T.value),!M){T.value.match(Qt)?n(21,Q=zo):n(21,Q=Ko);return}T.setCustomValidity(""),n(21,Q=""),await Nt(),tn()}catch{T.value.match(Qt)?n(21,Q=zo):n(21,Q=Ko),n(14,A=!1)}}async function Za(L){L.preventDefault(),localStorage.removeItem(f.BUNKER_POINTER),localStorage.removeItem(f.CACHED_PUBKEY),localStorage.setItem(f.IGNORE_IFRAME,""),rr()}async function Ja(L){L.preventDefault(),n(19,$=!0),ue.length===0&&(n(24,ue=await fa(w,["wss://relay.nostr.band","wss://nos.lol","wss://nostr-pub.wellorder.net"])),n(12,y=ue[0]))}function Qa(L){n(19,$=!1)}async function Xa(L){if(L.preventDefault(),!y)return;n(20,X=!0);let Z=await ua(y,Bt,_.value,y.domain,void 0,E);n(20,X=!1),Xt(),n(19,$=!1),M=Z.bp,tn(),Nt(Z)}const el=gr(async()=>{y&&_.value.length>0&&(await da(_.value+"@"+y.domain)?_.setCustomValidity(`'${_.value}' is already taken.`):_.setCustomValidity(""))},500);function tl(){n(18,D=!1),n(14,A=!1),V("connection aborted"),rr()}async function Nt(L=void 0){L=L||new Bo(E,M,Bt),n(14,A=!0);let Z=setTimeout(()=>{n(18,D=!0),n(27,i=!0)},5e3);try{await L.connect(),C=!0,localStorage.setItem(f.BUNKER_POINTER,JSON.stringify(M)),Ot(),W(L)}catch(ve){V((ve==null?void 0:ve.message)||String(ve))}finally{clearTimeout(Z),n(14,A=!1),n(18,D=!1),n(15,H=null),n(16,I=null),n(17,q=null)}}async function tn(){let L=localStorage.getItem(f.CACHED_PUBKEY);L||(L=await(await v).getPublicKey(),localStorage.setItem(f.CACHED_PUBKEY,L)),n(23,J={pubkey:L,npub:ga(L),event:null}),re=w.subscribeMany(["wss://purplepag.es","wss://relay.snort.social","wss://relay.nos.social"],[{kinds:[0],authors:[L]}],{onevent(Z){var ve;if(!((((ve=J.event)==null?void 0:ve.created_at)||0)>=Z.created_at))try{let{name:Lt,picture:pl}=JSON.parse(Z.content);n(23,J.event=Z,J),n(23,J.name=Lt,J),n(23,J.picture=pl,J)}catch{}}})}function nl(L){if(i)return;Be=!0;const Z=u.getBoundingClientRect();Ce=L.clientY-Z.top,ge=o,Ue=Date.now()}function rl(L){Be&&(r==="top"?n(25,o=L.clientY):n(25,o=window.innerHeight-L.clientY),n(25,o-=Ce),n(48,Ge=!0),o<Fe&&n(25,o=Fe),o>window.innerHeight-Fe&&n(25,o=window.innerHeight-Fe))}function ol(){if(Be=!1,setTimeout(()=>{n(48,Ge=!1)},10),Ge){const L=u.getBoundingClientRect(),Z=window.innerHeight,ve=Z/2;L.top<ve?(n(26,r="top"),n(25,o=L.top)):(n(26,r="bottom"),n(25,o=Z-L.bottom)),o<Fe&&n(25,o=Fe),localStorage.setItem(f.ORIGIN,r),localStorage.setItem(f.Y_POS,o.toString())}}const il=()=>er(H),sl=()=>er(I),cl=()=>{er(q)};function al(L){it[L?"unshift":"push"](()=>{_=L,n(10,_)})}function ll(){x=this.value,n(11,x)}function ul(){y=ri(this),n(12,y),n(24,ue)}function fl(L){it[L?"unshift":"push"](()=>{T=L,n(9,T)})}function dl(){R=this.value,n(4,R)}function hl(L){it[L?"unshift":"push"](()=>{u=L,n(6,u)})}function gl(L){it[L?"unshift":"push"](()=>{S=L,n(8,S)})}return t.$$set=L=>{"accent"in L&&n(0,b=L.accent),"position"in L&&n(46,h=L.position),"startHidden"in L&&n(1,g=L.startHidden),"compactMode"in L&&n(2,d=L.compactMode),"right"in L&&n(3,ae=L.right)},t.$$.update=()=>{t.$$.dirty[0]&32|t.$$.dirty[1]&32768&&n(26,r=a?"bottom":localStorage.getItem(f.ORIGIN)||h),t.$$.dirty[0]&32&&n(25,o=a?Fe:parseInt(localStorage.getItem(f.Y_POS)||"0")||Fe),t.$$.dirty[1]&65536&&n(27,i=N==="justopened"||N==="opened"),t.$$.dirty[0]&1|t.$$.dirty[1]&131072&&n(29,s=Ge?"cursor-grabbing outline-dashed outline-"+b+"-500 outline-1 outline-offset-4":"outline-none"),t.$$.dirty[0]&16&&n(28,c=R&&(R.match(Qt)||R.match(Io)))},[b,g,d,ae,R,a,u,m,S,T,_,x,y,E,A,H,I,q,D,$,X,Q,ce,J,ue,o,r,i,c,s,l,Wa,Da,Va,Fa,Ga,Ya,Za,Ja,Qa,Xa,el,tl,nl,rl,ol,h,N,Ge,il,sl,cl,al,ll,ul,fl,dl,hl,gl]}class Ka extends dr{constructor(e){super(),fr(this,e,za,qa,rn,{accent:0,position:46,startHidden:1,compactMode:2,right:3},null,[-1,-1,-1])}}const yt=window;yt.destroyWnj=()=>{setTimeout(()=>{$a.$destroy()},1)};const tr=document.createElement("div");tr.style.zIndex="90000",document.body.appendChild(tr);const nr=document.createElement("div");nr.id="wnj";const $o=document.createElement("style");$o.innerHTML=Ye;const Wo=tr.attachShadow({mode:"open"});Wo.appendChild(nr),Wo.appendChild($o);const $a=new Ka({target:nr,props:{accent:((Do=yt.wnjParams)==null?void 0:Do.accent)||"cyan",position:((Vo=yt.wnjParams)==null?void 0:Vo.position)==="bottom"?"bottom":"top",startHidden:(Fo=yt.wnjParams)==null?void 0:Fo.startHidden,compactMode:(Go=yt.wnjParams)==null?void 0:Go.compactMode}});if(!((Yo=yt.wnjParams)!=null&&Yo.disableOverflowFix)){const t=document.createElement("style"),e=`
|
|
21
21
|
html, body {
|
|
22
22
|
overflow: auto;
|
|
23
23
|
height: 100%;
|
package/justfile
CHANGED
package/package.json
CHANGED
package/src/App.svelte
CHANGED
package/dist/iframe.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
(() => {
|
|
3
|
-
// iframe/iframe.ts
|
|
4
|
-
var SHARED_BUNKER_KEY = "wnj:root:sharedBunker";
|
|
5
|
-
window.onmessage = async (ev) => {
|
|
6
|
-
const { bunker, getbunker } = ev.data;
|
|
7
|
-
if (bunker) {
|
|
8
|
-
if (!ev.origin.startsWith("https://join.the-nostr.org") && !ev.origin.startsWith("http://localhost:6711")) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
if (bunker) {
|
|
12
|
-
localStorage.setItem(SHARED_BUNKER_KEY, bunker);
|
|
13
|
-
} else {
|
|
14
|
-
console.error("wnj iframe got an invalid bunker url:", bunker);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
if (getbunker) {
|
|
18
|
-
const bunker2 = localStorage.getItem(SHARED_BUNKER_KEY);
|
|
19
|
-
window.parent.postMessage({ bunker: bunker2 }, "*");
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
})();
|
package/dist/iframe.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../iframe/iframe.ts"],
|
|
4
|
-
"sourcesContent": ["const SHARED_BUNKER_KEY = 'wnj:root:sharedBunker'\n\nwindow.onmessage = async (ev: MessageEvent) => {\n const {bunker, getbunker} = ev.data\n\n // set the bunker URL\n if (bunker) {\n // we only accept these websites to be setting the bunker URL\n if (\n !ev.origin.startsWith('https://join.the-nostr.org') &&\n !ev.origin.startsWith('http://localhost:6711')\n ) {\n return\n }\n\n if (bunker) {\n localStorage.setItem(SHARED_BUNKER_KEY, bunker)\n } else {\n console.error('wnj iframe got an invalid bunker url:', bunker)\n }\n }\n\n if (getbunker) {\n // any website can get the bunker URL if it is set\n const bunker = localStorage.getItem(SHARED_BUNKER_KEY)\n window.parent.postMessage({bunker}, '*') // we reply even if it's undefined so they know\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;AAAA,MAAM,oBAAoB;AAE1B,SAAO,YAAY,OAAO,OAAqB;AAC7C,UAAM,EAAC,QAAQ,UAAS,IAAI,GAAG;AAG/B,QAAI,QAAQ;AAEV,UACE,CAAC,GAAG,OAAO,WAAW,4BAA4B,KAClD,CAAC,GAAG,OAAO,WAAW,uBAAuB,GAC7C;AACA;AAAA,MACF;AAEA,UAAI,QAAQ;AACV,qBAAa,QAAQ,mBAAmB,MAAM;AAAA,MAChD,OAAO;AACL,gBAAQ,MAAM,yCAAyC,MAAM;AAAA,MAC/D;AAAA,IACF;AAEA,QAAI,WAAW;AAEb,YAAMA,UAAS,aAAa,QAAQ,iBAAiB;AACrD,aAAO,OAAO,YAAY,EAAC,QAAAA,QAAM,GAAG,GAAG;AAAA,IACzC;AAAA,EACF;",
|
|
6
|
-
"names": ["bunker"]
|
|
7
|
-
}
|
package/iframe/build.js
DELETED
package/iframe/iframe.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const SHARED_BUNKER_KEY = 'wnj:root:sharedBunker'
|
|
2
|
-
|
|
3
|
-
window.onmessage = async (ev: MessageEvent) => {
|
|
4
|
-
const {bunker, getbunker} = ev.data
|
|
5
|
-
|
|
6
|
-
// set the bunker URL
|
|
7
|
-
if (bunker) {
|
|
8
|
-
// we only accept these websites to be setting the bunker URL
|
|
9
|
-
if (
|
|
10
|
-
!ev.origin.startsWith('https://join.the-nostr.org') &&
|
|
11
|
-
!ev.origin.startsWith('http://localhost:6711')
|
|
12
|
-
) {
|
|
13
|
-
return
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (bunker) {
|
|
17
|
-
localStorage.setItem(SHARED_BUNKER_KEY, bunker)
|
|
18
|
-
} else {
|
|
19
|
-
console.error('wnj iframe got an invalid bunker url:', bunker)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (getbunker) {
|
|
24
|
-
// any website can get the bunker URL if it is set
|
|
25
|
-
const bunker = localStorage.getItem(SHARED_BUNKER_KEY)
|
|
26
|
-
window.parent.postMessage({bunker}, '*') // we reply even if it's undefined so they know
|
|
27
|
-
}
|
|
28
|
-
}
|