nostr-web-components
Version:
collection of web components that provide quick access to basic nostr things
11 lines (10 loc) • 2.35 kB
JavaScript
var m=Object.defineProperty;var k=(s,a,t)=>a in s?m(s,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[a]=t;var l=(s,a,t)=>k(s,typeof a!="symbol"?a+"":a,t);import{decodeNostrURI as g}from"@nostr/tools/nip19";import{normalizeURL as f}from"@nostr/tools/utils";import{b as h,p as u}from"./nostr.js";import{d as b}from"./utils.js";import"@nostr/tools/pool";import"@nostr/gadgets/lists";import"@nostr/gadgets/global";import"@nostr/gadgets/metadata";import"@nostr/tools/nip05";class c extends HTMLElement{constructor(){super();l(this,"set",b(async()=>{let t=null,y=this.getAttribute("event");if(y)try{t=JSON.parse(y)}catch{}if(!t){let e=this.getAttribute("ref");if(e){let{type:d,data:o}=g(e),i=[],r,p;if(d==="nevent"){let n=o;i=n.relays||[],r=n.author,p={ids:[n.id]}}else if(d==="naddr"){let n=o;p={authors:[n.pubkey],"#d":[n.identifier],kinds:[n.kind]},i=n.relays||[],r=n.pubkey}else if(d==="note")p={ids:[o]};else if(e.match(/[0-9a-f]{64}/))p={ids:[e]};else return;i=i.map(f),r&&(i=await h(r)),t=await u.get(i,p)}}if(t){const{shadowRoot:e}=this;e.innerHTML=`<pre part="pre" style="white-space: pre-wrap; word-break: break-all">{
<span part="key">"id":</span> <span part="id" id="id"></span>
<span part="key">"pubkey":</span> <span part="pubkey" id="pubkey"></span>
<span part="key">"kind":</span> <span part="kind" id="kind"></span>
<span part="key">"created_at":</span> <span part="created_at" id="created_at"></span>
<span part="key">"tags":</span> <span part="tags" id="tags"></span>
<span part="key">"content":</span> <span part="content" id="content"></span>
<span part="key">"sig":</span> <span part="sig" id="sig"></span>
}</pre>`,e.getElementById("id").textContent=t.id,e.getElementById("pubkey").textContent=t.pubkey,e.getElementById("kind").textContent=`${t.kind}`,e.getElementById("created_at").textContent=`${t.created_at}`,e.getElementById("tags").textContent=JSON.stringify(t.tags),e.getElementById("content").textContent=t.content,e.getElementById("sig").textContent=t.sig}},200));this.attachShadow({mode:"open"})}connectedCallback(){this.style.display="inline-block",this.style.width="fit-content",this.style.height="fit-content",this.set()}attributeChangedCallback(){this.set()}}l(c,"observedAttributes",["ref","event"]);window.customElements.define("nostr-event-json",c);
//# sourceMappingURL=nostr-event-json.js.map