nostr-components 0.2.2 → 0.2.4
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/assets/nostr-user-component-BOdux8_6.js +2 -0
- package/dist/assets/nostr-user-component-BOdux8_6.js.map +1 -0
- package/dist/components/nostr-follow-button.es.js +1 -1
- package/dist/components/nostr-like.es.js +1 -1
- package/dist/components/nostr-like.es.js.map +1 -1
- package/dist/components/nostr-profile-badge.es.js +1 -1
- package/dist/components/nostr-profile.es.js +1 -1
- package/dist/components/nostr-zap.es.js +2 -2
- package/dist/components/nostr-zap.es.js.map +1 -1
- package/dist/nostr-components.es.js +1 -1
- package/dist/nostr-components.umd.js +3 -3
- package/dist/nostr-components.umd.js.map +1 -1
- package/package.json +1 -4
- package/dist/assets/nostr-user-component-Q7GeeFyu.js +0 -2
- package/dist/assets/nostr-user-component-Q7GeeFyu.js.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var l=Object.defineProperty;var p=(i,r,e)=>r in i?l(i,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[r]=e;var n=(i,r,e)=>p(i,typeof r!="symbol"?r+"":r,e);import{N as h,a as o}from"./base-styles-CBypR3FR.js";import{U as c}from"./user-resolver-C-E6KdwY.js";const d="nc:user";class C extends h{constructor(e=!0){super(e);n(this,"user",null);n(this,"profile",null);n(this,"userStatus",this.channel("user"));n(this,"loadSeq",0);n(this,"resolver",new c(this.nostrService))}static get observedAttributes(){return[...super.observedAttributes,"npub","pubkey","nip05"]}connectedCallback(){var e;(e=super.connectedCallback)==null||e.call(this),this.userStatus.get()==o.Idle&&this.initChannelStatus("user",o.Loading,{reflectOverall:!1}),this.validateInputs()&&this.resolveUserAndProfile().catch(t=>{console.error("[NostrUserComponent] init failed:",t)})}attributeChangedCallback(e,t,s){var u;t!==s&&((u=super.attributeChangedCallback)==null||u.call(this,e,t,s),(e==="npub"||e==="nip05"||e==="pubkey")&&this.validateInputs()&&this.resolveUserAndProfile())}validateInputs(){if(!super.validateInputs())return this.userStatus.set(o.Idle),!1;const e=this.getAttribute("npub"),t=this.getAttribute("pubkey"),s=this.getAttribute("nip05"),u=this.tagName.toLowerCase(),a=this.resolver.validateInputs({npub:e,pubkey:t,nip05:s});return a?(this.userStatus.set(o.Error,a),console.error(`Nostr-Components: ${u}: ${a}`),!1):(this.errorMessage="",!0)}async resolveUserAndProfile(){const e=++this.loadSeq;try{await this.ensureNostrConnected()}catch(t){if(e!==this.loadSeq)return;console.error("[NostrUserComponent] Relay connect failed before user/profile load:",t);return}this.userStatus.set(o.Loading);try{const{user:t,profile:s}=await this.resolver.resolveUser({npub:this.getAttribute("npub"),pubkey:this.getAttribute("pubkey"),nip05:this.getAttribute("nip05")});if(e!==this.loadSeq)return;if(s==null){this.userStatus.set(o.Error,"Profile not found");return}this.user=t,this.profile=s,this.userStatus.set(o.Ready),this.dispatchEvent(new CustomEvent(d,{detail:{user:this.user,profile:this.profile},bubbles:!0,composed:!0})),this.onUserReady(this.user,this.profile)}catch(t){if(e!==this.loadSeq)return;const s=t instanceof Error?t.message:"Failed to load user/profile";console.error("[NostrUserComponent] "+s,t),this.userStatus.set(o.Error,s)}}renderContent(){}onUserReady(e,t){}}export{C as N};
|
|
2
|
+
//# sourceMappingURL=nostr-user-component-BOdux8_6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nostr-user-component-BOdux8_6.js","sources":["../../src/base/user-component/nostr-user-component.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n\nimport { NDKUser, NDKUserProfile } from '@nostr-dev-kit/ndk';\nimport { NostrBaseComponent, NCStatus } from '../base-component/nostr-base-component';\nimport { UserResolver } from '../resolvers/user-resolver';\n\nconst EVT_USER = 'nc:user';\n\n/**\n * NostrUserComponent\n * ==================\n * Extension of `NostrBaseComponent` that resolves and manages a Nostr user.\n *\n * Overview\n * - Accepts identity attributes (`npub`, `nip05`, or `pubkey`) and validates them.\n * - Resolves an `NDKUser` via the shared `nostrService` and fetches its profile.\n * - Exposes resolved `user` and `profile` to subclasses for rendering or logic.\n * - Emits lifecycle events for status and user readiness.\n *\n * Observed attributes\n * - `npub` — user's Nostr public key (bech32 npub)\n * - `nip05` — NIP-05 identifier (e.g. `alice@example.com`)\n * - `pubkey` — raw hex-encoded public key\n *\n * Events\n * - `nc:status` — from base, reflects connection and user/profile loading status\n * - `nc:user` — fired when a user and profile are successfully resolved\n */\n\nexport class NostrUserComponent extends NostrBaseComponent {\n\n protected user: NDKUser | null = null;\n protected profile: NDKUserProfile | null = null;\n\n protected userStatus = this.channel('user');\n\n // guard to ignore stale user fetches\n private loadSeq = 0;\n\n private resolver = new UserResolver(this.nostrService);\n\n constructor(shadow: boolean = true) {\n super(shadow);\n }\n\n /** Lifecycle methods */\n static get observedAttributes() {\n return [\n ...super.observedAttributes,\n 'npub',\n 'pubkey',\n 'nip05',\n ];\n }\n\n connectedCallback() {\n super.connectedCallback?.();\n\n if (this.userStatus.get() == NCStatus.Idle) {\n this.initChannelStatus('user', NCStatus.Loading, { reflectOverall: false });\n }\n\n if (this.validateInputs()) {\n this.resolveUserAndProfile().catch(e => {\n console.error('[NostrUserComponent] init failed:', e);\n });\n }\n }\n\n attributeChangedCallback(\n name: string,\n oldValue: string | null,\n newValue: string | null\n ) {\n if (oldValue === newValue) return;\n super.attributeChangedCallback?.(name, oldValue, newValue);\n\n if (name === 'npub' || name === 'nip05' || name === 'pubkey') {\n if (this.validateInputs()) {\n // Re-resolve user + profile on identity changes\n void this.resolveUserAndProfile();\n }\n }\n }\n\n /** Protected methods */\n protected validateInputs(): boolean {\n\n if (!super.validateInputs()) {\n this.userStatus.set(NCStatus.Idle);\n return false;\n }\n\n const npub = this.getAttribute(\"npub\");\n const pubkey = this.getAttribute(\"pubkey\");\n const nip05 = this.getAttribute(\"nip05\");\n const tagName = this.tagName.toLowerCase();\n\n const err = this.resolver.validateInputs({\n npub: npub,\n pubkey: pubkey,\n nip05: nip05,\n });\n\n if (err) {\n this.userStatus.set(NCStatus.Error, err);\n console.error(`Nostr-Components: ${tagName}: ${err}`);\n return false;\n }\n\n this.errorMessage = \"\";\n return true;\n\n }\n\n protected async resolveUserAndProfile(): Promise<void> {\n const seq = ++this.loadSeq; // token to prevent stale writes\n\n // Ensure relays are connected; handle failure inside to avoid unhandled rejection\n try {\n await this.ensureNostrConnected();\n } catch (e) {\n if (seq !== this.loadSeq) return; // stale\n // Base already set status=Error, but make the failure explicit here too\n console.error('[NostrUserComponent] Relay connect failed before user/profile load:', e);\n return;\n }\n\n this.userStatus.set(NCStatus.Loading);\n\n try {\n const { user, profile } = await this.resolver.resolveUser({\n npub: this.getAttribute('npub'),\n pubkey: this.getAttribute('pubkey'),\n nip05: this.getAttribute('nip05'),\n });\n\n // stale call check\n if (seq !== this.loadSeq) return;\n\n if (profile == null) {\n this.userStatus.set(NCStatus.Error, \"Profile not found\");\n return;\n }\n\n this.user = user;\n this.profile = profile;\n this.userStatus.set(NCStatus.Ready);\n // Notify listeners that user + profile are available\n this.dispatchEvent(new CustomEvent(EVT_USER, {\n detail: { user: this.user, profile: this.profile },\n bubbles: true,\n composed: true,\n }));\n this.onUserReady(this.user!, this.profile);\n } catch (err) {\n if (seq !== this.loadSeq) return; // stale\n const msg = err instanceof Error ? err.message : 'Failed to load user/profile';\n console.error('[NostrUserComponent] ' + msg, err);\n this.userStatus.set(NCStatus.Error, msg);\n }\n }\n\n protected renderContent() { }\n\n /** Hook for subclasses to react when user/profile are ready (e.g., render). */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected onUserReady(_user: NDKUser, _profile: NDKUserProfile | null) { }\n}\n"],"names":["EVT_USER","NostrUserComponent","NostrBaseComponent","shadow","__publicField","UserResolver","_a","NCStatus","e","name","oldValue","newValue","npub","pubkey","nip05","tagName","err","seq","user","profile","msg","_user","_profile"],"mappings":"yQAMA,MAAMA,EAAW,UAuBV,MAAMC,UAA2BC,CAAmB,CAYzD,YAAYC,EAAkB,GA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,QACzBT,EAAG,CACN,GAAAS,IAAQ,KAAK,QAAS,OAElB,QAAA,MAAM,sEAAuET,CAAC,EACtF,MAAA,CAGG,KAAA,WAAW,IAAID,EAAS,OAAO,EAEhC,GAAA,CACF,KAAM,CAAE,KAAAW,EAAM,QAAAC,CAAA,EAAY,MAAM,KAAK,SAAS,YAAY,CACxD,KAAM,KAAK,aAAa,MAAM,EAC9B,OAAQ,KAAK,aAAa,QAAQ,EAClC,MAAO,KAAK,aAAa,OAAO,CAAA,CACjC,EAGG,GAAAF,IAAQ,KAAK,QAAS,OAE1B,GAAIE,GAAW,KAAM,CACnB,KAAK,WAAW,IAAIZ,EAAS,MAAO,mBAAmB,EACvD,MAAA,CAGF,KAAK,KAAOW,EACZ,KAAK,QAAUC,EACV,KAAA,WAAW,IAAIZ,EAAS,KAAK,EAE7B,KAAA,cAAc,IAAI,YAAYP,EAAU,CAC3C,OAAQ,CAAE,KAAM,KAAK,KAAM,QAAS,KAAK,OAAQ,EACjD,QAAS,GACT,SAAU,EAAA,CACX,CAAC,EACF,KAAK,YAAY,KAAK,KAAO,KAAK,OAAO,QAClCgB,EAAK,CACR,GAAAC,IAAQ,KAAK,QAAS,OAC1B,MAAMG,EAAMJ,aAAe,MAAQA,EAAI,QAAU,8BACzC,QAAA,MAAM,wBAA0BI,EAAKJ,CAAG,EAChD,KAAK,WAAW,IAAIT,EAAS,MAAOa,CAAG,CAAA,CACzC,CAGQ,eAAgB,CAAA,CAIhB,YAAYC,EAAgBC,EAAiC,CAAA,CACzE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var v=Object.defineProperty;var w=(n,e,o)=>e in n?v(n,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[e]=o;var f=(n,e,o)=>w(n,typeof e!="symbol"?e+"":e,o);import{d as m}from"../assets/nostr-service-pr_crY62.js";import{N as p}from"../assets/nostr-user-component-
|
|
1
|
+
var v=Object.defineProperty;var w=(n,e,o)=>e in n?v(n,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[e]=o;var f=(n,e,o)=>w(n,typeof e!="symbol"?e+"":e,o);import{d as m}from"../assets/nostr-service-pr_crY62.js";import{N as p}from"../assets/nostr-user-component-BOdux8_6.js";import{b as y,g as k,a as b}from"../assets/theme-C1r1Zw8r.js";import{e as c,g as S,a as l}from"../assets/base-styles-CBypR3FR.js";import"../assets/user-resolver-C-E6KdwY.js";import"../assets/icons-Dr_d9MII.js";function C({isLoading:n,isError:e,errorMessage:o,isFollowed:t,isFollowing:r,showAvatar:i=!1,user:s,profile:a,customText:h="Follow me on nostr"}){if(r)return F();if(n)return x();if(e)return N(o||"");const u=t?y("light"):i&&s&&(a!=null&&a.image)?`<img src="${c(a.image)}" alt="${c(a.name||s.npub)}" class="user-avatar" />`:k(),g=t?"Followed":`<span>${c(h)}</span>`;return d(u,g)}function x(){return d(b(),"<span>Loading...</span>")}function F(){return d(b(),"<span>Following...</span>")}function N(n){return d('<div class="error-icon">⚠</div>',c(n))}function d(n,e){return`
|
|
2
2
|
<div class='nostr-follow-button-container'>
|
|
3
3
|
<div class='nostr-follow-button-left-container'>
|
|
4
4
|
${n}
|
|
@@ -289,7 +289,7 @@ var m=Object.defineProperty;var w=(r,e,t)=>e in r?m(r,e,{enumerable:!0,configura
|
|
|
289
289
|
<li>Works with a browser extension like <a href="https://getalby.com" target="_blank" rel="noopener noreferrer">Alby</a> or nos2x</li>
|
|
290
290
|
</ul>
|
|
291
291
|
</div>
|
|
292
|
-
`,e.showModal()};new TextDecoder("utf-8");new TextEncoder;function k(r){r.indexOf("://")===-1&&(r="wss://"+r);let e=new URL(r);return e.pathname=e.pathname.replace(/\/+/g,"/"),e.pathname.endsWith("/")&&(e.pathname=e.pathname.slice(0,-1)),(e.port==="80"&&e.protocol==="ws:"||e.port==="443"&&e.protocol==="wss:")&&(e.port=""),e.searchParams.sort(),e.hash="",e.toString()}async function
|
|
292
|
+
`,e.showModal()};new TextDecoder("utf-8");new TextEncoder;function k(r){r.indexOf("://")===-1&&(r="wss://"+r);let e=new URL(r);return e.pathname=e.pathname.replace(/\/+/g,"/"),e.pathname.endsWith("/")&&(e.pathname=e.pathname.slice(0,-1)),(e.port==="80"&&e.protocol==="ws:"||e.port==="443"&&e.protocol==="wss:")&&(e.port=""),e.searchParams.sort(),e.hash="",e.toString()}async function I(r,e){const t=k(r),n=new f;try{const o=await n.querySync(e,{kinds:[17],"#k":["web"],"#i":[t],limit:1e3}),s=[];let a=0,l=0;for(const c of o)s.push({authorPubkey:c.pubkey,date:new Date(c.created_at*1e3),content:c.content}),c.content==="-"?l++:a++;return s.sort((c,h)=>h.date.getTime()-c.date.getTime()),{totalCount:a-l,likeDetails:s,likedCount:a,dislikedCount:l}}catch(o){throw o instanceof Error?o:new Error(String(o))}finally{n.close(e)}}function v(r,e){return{kind:17,content:e,tags:[["k","web"],["i",r]],created_at:Math.floor(Date.now()/1e3)}}function M(r){return v(r,"+")}function H(r){return v(r,"-")}async function P(r,e,t){const n=new f,o=r;try{const s=await n.querySync(t,{kinds:[17],authors:[e],"#k":["web"],"#i":[o],limit:1});if(s.length===0)return!1;const a=s[0];return a.content==="+"||a.content===""}catch(s){return console.error("Nostr-Components: Like button: Error checking user like status",s),!1}finally{n.close(t)}}async function T(){try{if(typeof window<"u"&&window.nostr)return await window.nostr.getPublicKey()}catch(r){console.error("Nostr-Components: Like button: Error getting user pubkey",r)}return null}async function p(r){try{if(typeof window<"u"&&window.nostr)return await window.nostr.signEvent(r);throw new Error("NIP-07 extension not available")}catch(e){throw console.error("Nostr-Components: Like button: Error signing event",e),e}}function _(){return typeof window<"u"&&!!window.nostr}class F extends x{constructor(){super();d(this,"likeActionStatus",this.channel("likeAction"));d(this,"likeListStatus",this.channel("likeList"));d(this,"currentUrl","");d(this,"isLiked",!1);d(this,"likeCount",0);d(this,"cachedLikeDetails",null);d(this,"loadSeq",0)}connectedCallback(){var t;(t=super.connectedCallback)==null||t.call(this),this.likeListStatus.get()===i.Idle&&this.initChannelStatus("likeList",i.Loading,{reflectOverall:!1}),this.attachDelegatedListeners(),this.render()}static get observedAttributes(){return[...super.observedAttributes,"url","text"]}attributeChangedCallback(t,n,o){n!==o&&(super.attributeChangedCallback(t,n,o),(t==="url"||t==="text")&&(this.likeActionStatus.set(i.Ready),this.likeListStatus.set(i.Loading),this.isLiked=!1,this.errorMessage="",this.updateLikeCount(),this.render()))}validateInputs(){if(!super.validateInputs())return this.likeActionStatus.set(i.Idle),this.likeListStatus.set(i.Idle),!1;const t=this.getAttribute("url"),n=this.getAttribute("text"),o=this.tagName.toLowerCase();let s=null;return t&&(C(t)||(s="Invalid URL format")),n&&n.length>32&&(s="Max text length: 32 characters"),s?(this.likeActionStatus.set(i.Error,s),this.likeListStatus.set(i.Error,s),console.error(`Nostr-Components: ${o}: ${s}`),!1):!0}onStatusChange(t){this.render()}onNostrRelaysConnected(){this.updateLikeCount(),this.render()}ensureCurrentUrl(){this.currentUrl||(this.currentUrl=k(this.getAttribute("url")||window.location.href))}async updateLikeCount(){const t=++this.loadSeq;try{await this.ensureNostrConnected(),this.currentUrl=k(this.getAttribute("url")||window.location.href),this.likeListStatus.set(i.Loading),this.render();const n=await I(this.currentUrl,this.getRelays());if(t!==this.loadSeq)return;this.likeCount=n.totalCount,this.cachedLikeDetails=n,this.likeListStatus.set(i.Ready)}catch(n){console.error("[NostrLike] Failed to fetch like count:",n),this.likeListStatus.set(i.Error,"Failed to load likes")}finally{this.render()}}async handleLikeClick(){if(this.ensureCurrentUrl(),!this.currentUrl){this.likeActionStatus.set(i.Error,"Invalid URL"),this.render();return}if(this.likeActionStatus.set(i.Loading),!_()){this.likeActionStatus.set(i.Error,"Please install a Nostr browser extension (Alby, nos2x, etc.)"),this.render();return}try{const t=await T();t&&(this.isLiked=await P(this.currentUrl,t,this.getRelays()))}catch(t){console.error("[NostrLike] Failed to check user like status:",t),this.likeActionStatus.set(i.Error,"Failed to check user like status")}finally{this.render()}if(this.isLiked){if(!window.confirm("You have already liked this. Do you want to unlike it?")){this.likeActionStatus.set(i.Ready),this.render();return}await this.handleUnlike()}else await this.handleLike()}async handleLike(){if(this.ensureCurrentUrl(),!this.currentUrl){this.likeActionStatus.set(i.Error,"Invalid URL"),this.render();return}this.likeActionStatus.set(i.Loading),this.render();try{const t=M(this.currentUrl),n=await p(t);await new g(this.nostrService.getNDK(),n).publish(),this.isLiked=!0,this.likeCount++,this.likeActionStatus.set(i.Ready),await this.updateLikeCount()}catch(t){console.error("[NostrLike] Failed to like:",t),this.isLiked=!1,this.likeCount--;const n=t instanceof Error?t.message:"Failed to like";this.likeActionStatus.set(i.Error,n)}finally{this.render()}}async handleUnlike(){if(this.ensureCurrentUrl(),!this.currentUrl){this.likeActionStatus.set(i.Error,"Invalid URL"),this.render();return}this.likeActionStatus.set(i.Loading),this.render();try{const t=H(this.currentUrl),n=await p(t);await new g(this.nostrService.getNDK(),n).publish(),this.isLiked=!1,this.likeCount>0&&this.likeCount--,this.likeActionStatus.set(i.Ready),await this.updateLikeCount()}catch(t){console.error("[NostrLike] Failed to unlike:",t),this.isLiked=!0,this.likeCount++;const n=t instanceof Error?t.message:"Failed to unlike";this.likeActionStatus.set(i.Error,n)}finally{this.render()}}async handleCountClick(){if(!(this.likeCount===0||!this.cachedLikeDetails))try{const{openLikersDialog:t}=await y(async()=>{const{openLikersDialog:n}=await import("../assets/dialog-likers-BzTesCZa.js");return{openLikersDialog:n}},__vite__mapDeps([0,1,2,3,4,5,6]));await t({likeDetails:this.cachedLikeDetails.likeDetails,theme:this.theme==="dark"?"dark":"light"})}catch(t){console.error("[NostrLike] Error opening likers dialog:",t)}}async handleHelpClick(){try{await $(this.theme==="dark"?"dark":"light")}catch(t){console.error("[NostrLike] Error showing help dialog:",t)}}attachDelegatedListeners(){this.delegateEvent("click",".nostr-like-button",t=>{var n,o;(n=t.preventDefault)==null||n.call(t),(o=t.stopPropagation)==null||o.call(t),this.handleLikeClick()}),this.delegateEvent("click",".like-count",t=>{var n,o;(n=t.preventDefault)==null||n.call(t),(o=t.stopPropagation)==null||o.call(t),this.handleCountClick()}),this.delegateEvent("click",".help-icon",t=>{var n,o;(n=t.preventDefault)==null||n.call(t),(o=t.stopPropagation)==null||o.call(t),this.handleHelpClick()})}renderContent(){const t=this.likeActionStatus.get()===i.Loading||this.conn.get()===i.Loading,n=this.likeListStatus.get()===i.Loading,o=this.computeOverall()===i.Error,s=this.errorMessage,a=this.getAttribute("text")||"Like",l={isLoading:t,isError:o,errorMessage:s,buttonText:a,isLiked:this.isLiked,likeCount:this.likeCount,hasLikes:this.likeCount>0,isCountLoading:n,theme:this.theme};this.shadowRoot.innerHTML=`
|
|
293
293
|
${z()}
|
|
294
294
|
${S(l)}
|
|
295
295
|
`}}customElements.define("nostr-like",F);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"mappings":";6ZAcO,SAASA,EAAiB,CAC/B,UAAAC,EACA,QAAAC,EACA,aAAAC,EACA,WAAAC,EACA,QAAAC,EACA,UAAAC,EACA,SAAAC,EAAW,GACX,eAAAC,EAAiB,GACjB,MAAAC,EAAQ,OACV,EAAoC,CAElC,GAAIP,EACK,OAAAQ,EAAYP,GAAgB,EAAE,EAGjC,MAAAQ,EAAcC,EAAgBP,EAASI,CAAK,EAC5CI,EAAcR,EAChB,qBACA,SAASS,EAAWV,CAAU,CAAC,UAEnC,OAAOW,EAAgBJ,EAAaE,EAAaP,EAAWC,EAAUF,EAASJ,EAAWO,CAAc,CAC1G,CAEA,SAASE,EAAYP,EAA8B,CAC1C,OAAAa,EACL,wCACAF,EAAWX,CAAY,CACzB,CACF,CAEA,SAASa,EAAqBC,EAAqBC,EAA8B,CACxE;AAAA;AAAA;AAAA,UAGCD,CAAW;AAAA;AAAA;AAAA,UAGXC,CAAY;AAAA;AAAA;AAAA,GAItB,CAEA,SAASH,EACPJ,EACAE,EACAP,EACAC,EAAoB,GACpBF,EAAmB,GACnBJ,EAAqB,GACrBO,EAA0B,GAClB,CACR,IAAIW,EAAY,GAChB,OAAIX,EACUW,EAAA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C7FlD,EAAiB,KAAK,eAAe,QAAUkD,EAAS,QACxDxD,EAAU,KAAK,eAAe,IAAMwD,EAAS,MAC7CvD,EAAe,KAAK,aACpBC,EAAa,KAAK,aAAa,MAAM,GAAK,OAE1CwE,EAAyC,CAC7C,UAAA3E,EACA,QAAAC,EACA,aAAAC,EACA,WAAAC,EACA,QAAS,KAAK,QACd,UAAW,KAAK,UAChB,SAAU,KAAK,UAAY,EAC3B,eAAAI,EACA,MAAO,KAAK,KACd,EAEA,KAAK,WAAY,UAAY;AAAA,QACzBc,EAAqB;AAAA,QACrBtB,EAAiB4E,CAAa,CAAC;AAAA,MAGvC,CAEA,eAAe,OAAO,aAAcrB,CAAS","names":["renderLikeButton","isLoading","isError","errorMessage","buttonText","isLiked","likeCount","hasLikes","isCountLoading","theme","renderError","iconContent","getThumbsUpIcon","textContent","escapeHtml","renderContainer","renderErrorContainer","leftContent","rightContent","countHtml","likedColor","outlineColor","getLikeButtonStyles","getComponentStyles","getHelpDialogStyles","injectHelpDialogStyles","style","showHelpDialog","dialogComponent","normalizeURL","url","p","fetchLikesForUrl","relays","normalizedUrl","pool","SimplePool","events","likes","likedCount","dislikedCount","event","a","b","error","createReactionEvent","content","createLikeEvent","createUnlikeEvent","hasUserLiked","userPubkey","latest","getUserPubkey","signEvent","isNip07Available","NostrLike","NostrBaseComponent","__publicField","NCStatus","_a","name","oldValue","newValue","urlAttr","textAttr","tagName","isValidUrl","_status","seq","result","signedEvent","NDKEvent","openLikersDialog","__vitePreload","e","_b","renderOptions"],"ignoreList":[4],"sources":["../../src/nostr-like/render.ts","../../src/nostr-like/style.ts","../../src/nostr-like/dialog-help-style.ts","../../src/nostr-like/dialog-help.ts","../../node_modules/nostr-tools/lib/esm/utils.js","../../src/nostr-like/like-utils.ts","../../src/nostr-like/nostr-like.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n\nimport { escapeHtml } from '../common/utils';\nimport { IRenderOptions } from '../base/render-options';\n\nexport interface RenderLikeButtonOptions extends IRenderOptions {\n buttonText: string;\n isLiked: boolean;\n likeCount: number;\n hasLikes?: boolean;\n isCountLoading?: boolean;\n theme?: 'light' | 'dark';\n}\n\nexport function renderLikeButton({\n isLoading,\n isError,\n errorMessage,\n buttonText,\n isLiked,\n likeCount,\n hasLikes = false,\n isCountLoading = false,\n theme = 'light',\n}: RenderLikeButtonOptions): string {\n\n if (isError) {\n return renderError(errorMessage || '');\n }\n\n const iconContent = getThumbsUpIcon(isLiked, theme);\n const textContent = isLiked \n ? `<span>Liked</span>`\n : `<span>${escapeHtml(buttonText)}</span>`;\n\n return renderContainer(iconContent, textContent, likeCount, hasLikes, isLiked, isLoading, isCountLoading);\n}\n\nfunction renderError(errorMessage: string): string {\n return renderErrorContainer(\n '<div class=\"error-icon\">⚠</div>',\n escapeHtml(errorMessage)\n );\n}\n\nfunction renderErrorContainer(leftContent: string, rightContent: string): string {\n return `\n <div class=\"nostr-like-button-container\">\n <div class=\"nostr-like-button-left-container\">\n ${leftContent}\n </div>\n <div class=\"nostr-like-button-right-container\">\n ${rightContent}\n </div>\n </div>\n `;\n}\n\nfunction renderContainer(\n iconContent: string, \n textContent: string, \n likeCount: number, \n hasLikes: boolean = false,\n isLiked: boolean = false,\n isLoading: boolean = false,\n isCountLoading: boolean = false\n): string {\n let countHtml = '';\n if (isCountLoading) {\n countHtml = '<span class=\"like-count skeleton\"></span>';\n } else if (likeCount > 0) {\n const label = likeCount === 1 ? 'like' : 'likes';\n countHtml = `<span class=\"like-count${hasLikes ? ' clickable' : ''}\">${likeCount} ${label}</span>`;\n }\n \n const buttonClass = isLiked ? 'nostr-like-button liked' : 'nostr-like-button';\n const helpIconHtml = `<button class=\"help-icon\" title=\"What is a like?\">?</button>`;\n \n return `\n <div class=\"nostr-like-button-container\">\n <button class=\"${buttonClass}\">\n ${iconContent}\n ${isLoading ? '<span class=\"button-text-skeleton\"></span>' : textContent}\n </button>\n ${countHtml} ${helpIconHtml}\n </div>\n `;\n}\n\nfunction getThumbsUpIcon(isLiked: boolean, theme: 'light' | 'dark' = 'light'): string {\n // Determine colors based on theme\n const likedColor = theme === 'dark' ? '#8ab4f8' : '#1877f2'; // Light blue for dark theme, blue for light theme\n const outlineColor = theme === 'dark' ? '#e0e7ff' : '#0d46a1'; // Light color for dark theme, dark blue for light theme\n\n if (isLiked) {\n // Filled thumbs up\n return `<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 100 100\" width=\"24\" height=\"24\">\n <path d=\"M93.6,53.1c2.6-1.5,4.2-4.4,3.8-7.6c-0.5-4-4.2-6.8-8.2-6.8l-25,0c0.2-0.5,0.5-1.2,0.7-1.8c1.5-3.8,4.3-10.8,4.3-18 c0-8.1-5.7-13-9.6-13.3C57.2,5.5,55.4,7,55,9.7c-0.7,5.1-4.1,12.6-5.5,15.5c-0.4,0.9-0.9,1.7-1.6,2.4c-2.3,2.6-8.1,9-13.6,12.8 c0,0.2,0.1,0.5,0.1,0.7v47.9c0,0.4-0.1,0.8-0.1,1.2c9.4,2.7,17.9,4,27.2,4l21.3,0c3.7,0,7.2-2.5,7.9-6.1c0.6-3-0.5-5.7-2.5-7.5 c3.4-0.8,6-3.9,6-7.5c0-2.3-1-4.4-2.7-5.8c3.4-0.8,6-3.9,6-7.5C97.5,57,96,54.5,93.6,53.1z\" fill=\"${likedColor}\"/>\n <path d=\"M23.4,36.9H6.7c-2.3,0-4.2,1.9-4.2,4.2v47.9c0,2.3,1.9,4.2,4.2,4.2h16.7c2.3,0,4.2-1.9,4.2-4.2V41.2 C27.6,38.8,25.8,36.9,23.4,36.9z M15.1,85.9c-2.4,0-4.4-2-4.4-4.4s2-4.4,4.4-4.4c2.4,0,4.4,2,4.4,4.4S17.5,85.9,15.1,85.9z\" fill=\"${likedColor}\"/>\n </svg>`;\n } else {\n // Outline thumbs up\n return `<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 100 100\" width=\"24\" height=\"24\">\n <path d=\"M93.6,53.1c2.6-1.5,4.2-4.4,3.8-7.6c-0.5-4-4.2-6.8-8.2-6.8l-25,0c0.2-0.5,0.5-1.2,0.7-1.8c1.5-3.8,4.3-10.8,4.3-18 c0-8.1-5.7-13-9.6-13.3C57.2,5.5,55.4,7,55,9.7c-0.7,5.1-4.1,12.6-5.5,15.5c-0.4,0.9-0.9,1.7-1.6,2.4c-2.3,2.6-8.1,9-13.6,12.8 c0,0.2,0.1,0.5,0.1,0.7v47.9c0,0.4-0.1,0.8-0.1,1.2c9.4,2.7,17.9,4,27.2,4l21.3,0c3.7,0,7.2-2.5,7.9-6.1c0.6-3-0.5-5.7-2.5-7.5 c3.4-0.8,6-3.9,6-7.5c0-2.3-1-4.4-2.7-5.8c3.4-0.8,6-3.9,6-7.5C97.5,57,96,54.5,93.6,53.1z\" fill=\"none\" stroke=\"${outlineColor}\" stroke-width=\"2\"/>\n <path d=\"M23.4,36.9H6.7c-2.3,0-4.2,1.9-4.2,4.2v47.9c0,2.3,1.9,4.2,4.2,4.2h16.7c2.3,0,4.2-1.9,4.2-4.2V41.2 C27.6,38.8,25.8,36.9,23.4,36.9z M15.1,85.9c-2.4,0-4.4-2-4.4-4.4s2-4.4,4.4-4.4c2.4,0,4.4,2,4.4,4.4S17.5,85.9,15.1,85.9z\" fill=\"none\" stroke=\"${outlineColor}\" stroke-width=\"2\"/>\n </svg>`;\n }\n}\n","// SPDX-License-Identifier: MIT\n\nimport { getComponentStyles } from '../common/base-styles';\n\nexport function getLikeButtonStyles(): string {\n const customStyles = `\n /* === LIKE BUTTON CONTAINER PATTERN === */\n :host {\n /* Icon sizing (overridable via CSS variables) */\n --nostrc-icon-height: 25px;\n --nostrc-icon-width: 25px;\n\n /* Like button CSS variables (overridable by parent components) */\n --nostrc-like-btn-padding: var(--nostrc-spacing-sm) var(--nostrc-spacing-md);\n --nostrc-like-btn-border-radius: var(--nostrc-border-radius-md);\n --nostrc-like-btn-border: var(--nostrc-border-width) solid var(--nostrc-color-border);\n --nostrc-like-btn-min-height: 47px;\n --nostrc-like-btn-width: auto;\n --nostrc-like-btn-horizontal-alignment: left;\n --nostrc-like-btn-bg: var(--nostrc-theme-bg, #ffffff);\n --nostrc-like-btn-color: var(--nostrc-theme-text-primary, #333333);\n --nostrc-like-btn-font-family: var(--nostrc-font-family-primary);\n --nostrc-like-btn-font-size: var(--nostrc-font-size-base);\n \n /* Hover state variables */\n --nostrc-like-btn-hover-bg: var(--nostrc-theme-hover-bg, rgba(0, 0, 0, 0.05));\n --nostrc-like-btn-hover-color: var(--nostrc-theme-text-primary, #333333);\n --nostrc-like-btn-hover-border: var(--nostrc-border-width) solid var(--nostrc-theme-border, var(--nostrc-color-border));\n\n /* Liked state variables */\n --nostrc-like-btn-liked-bg: #e7f3ff;\n --nostrc-like-btn-liked-color: #1877f2;\n --nostrc-like-btn-liked-border: #1877f2;\n --nostrc-like-btn-liked-hover-bg: #d1e7ff;\n\n /* Make the host a flex container for button + count */\n display: inline-flex;\n flex-direction: row;\n align-items: center;\n gap: var(--nostrc-spacing-md);\n font-family: var(--nostrc-like-btn-font-family);\n font-size: var(--nostrc-like-btn-font-size);\n }\n\n /* Focus state for accessibility */\n :host(:focus-visible) {\n outline: 2px solid var(--nostrc-color-primary, #007bff);\n outline-offset: 2px;\n }\n\n :host(.is-error) .nostr-like-button-container {\n border: var(--nostrc-border-width) solid var(--nostrc-color-error-text);\n border-radius: var(--nostrc-border-radius-md);\n padding: var(--nostrc-spacing-sm);\n color: var(--nostrc-color-error-text);\n }\n\n .nostr-like-button-container {\n display: flex;\n align-items: center;\n gap: var(--nostrc-spacing-md);\n width: fit-content;\n }\n\n .nostr-like-button-left-container {\n display: flex;\n align-items: center;\n }\n\n .nostr-like-button-right-container {\n display: flex;\n align-items: center;\n }\n\n .nostr-like-button {\n display: flex;\n align-items: center;\n justify-content: var(--nostrc-like-btn-horizontal-alignment);\n gap: var(--nostrc-spacing-sm);\n background: var(--nostrc-like-btn-bg);\n color: var(--nostrc-like-btn-color);\n border: var(--nostrc-like-btn-border);\n border-radius: var(--nostrc-like-btn-border-radius);\n padding: var(--nostrc-like-btn-padding);\n min-height: var(--nostrc-like-btn-min-height);\n width: var(--nostrc-like-btn-width);\n cursor: pointer;\n transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;\n font-family: inherit;\n font-size: inherit;\n }\n\n /* Hover state on the button */\n .nostr-like-button:hover {\n background: var(--nostrc-like-btn-hover-bg);\n color: var(--nostrc-like-btn-hover-color);\n border: var(--nostrc-like-btn-hover-border);\n }\n\n /* Liked state */\n .nostr-like-button.liked {\n background: var(--nostrc-like-btn-liked-bg);\n color: var(--nostrc-like-btn-liked-color);\n border: var(--nostrc-border-width) solid var(--nostrc-like-btn-liked-border);\n }\n\n .nostr-like-button.liked:hover {\n background: var(--nostrc-like-btn-liked-hover-bg);\n }\n\n .nostr-like-button:disabled {\n pointer-events: none;\n user-select: none;\n opacity: 0.6;\n }\n\n :host:not([status=\"ready\"]) .nostr-like-button {\n cursor: not-allowed;\n }\n\n /* SVG Icon Styles */\n .nostr-like-button svg {\n display: inline-block;\n vertical-align: middle;\n width: var(--nostrc-icon-width);\n height: var(--nostrc-icon-height);\n }\n\n /* Like count display */\n .like-count {\n font-size: var(--nostrc-font-size-sm);\n color: var(--nostrc-theme-text-secondary, #666666);\n white-space: nowrap;\n text-decoration: underline;\n text-decoration-color: transparent;\n transition: text-decoration-color 0.2s ease, color 0.2s ease;\n }\n\n /* Clickable like count */\n .like-count.clickable {\n cursor: pointer;\n text-decoration-color: currentColor;\n }\n\n .like-count.clickable:hover {\n color: var(--nostrc-color-primary, #7f00ff);\n text-decoration-color: var(--nostrc-color-primary, #7f00ff);\n }\n\n /* Help icon */\n .help-icon {\n background: none;\n border: 1px solid var(--nostrc-color-border, #e0e0e0);\n border-radius: var(--nostrc-border-radius-full, 50%);\n width: var(--nostrc-help-icon-size, 16px);\n height: var(--nostrc-help-icon-size, 16px);\n font-size: calc(var(--nostrc-help-icon-size, 16px) * 0.7);\n font-weight: bold;\n color: var(--nostrc-theme-text-secondary, #666666);\n cursor: pointer;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n margin-left: var(--nostrc-spacing-xs, 4px);\n transition: all 0.2s ease;\n }\n\n .help-icon:hover {\n background: var(--nostrc-color-hover-background, rgba(0, 0, 0, 0.05));\n border-color: var(--nostrc-color-primary, #7f00ff);\n color: var(--nostrc-color-primary, #7f00ff);\n }\n\n /* Skeleton loader for like count */\n .like-count.skeleton {\n background: linear-gradient(90deg, \n var(--nostrc-skeleton-color-min) 25%, \n var(--nostrc-skeleton-color-max) 50%, \n var(--nostrc-skeleton-color-min) 75%\n );\n background-size: 200% 100%;\n animation: skeleton-loading var(--nostrc-skeleton-duration) var(--nostrc-skeleton-timing-function) var(--nostrc-skeleton-iteration-count);\n border-radius: var(--nostrc-border-radius-sm);\n width: 80px;\n height: 1.2em;\n display: inline-block;\n }\n\n /* Skeleton loader for button text */\n .button-text-skeleton {\n background: linear-gradient(90deg, \n var(--nostrc-skeleton-color-min) 25%, \n var(--nostrc-skeleton-color-max) 50%, \n var(--nostrc-skeleton-color-min) 75%\n );\n background-size: 200% 100%;\n animation: skeleton-loading var(--nostrc-skeleton-duration) var(--nostrc-skeleton-timing-function) var(--nostrc-skeleton-iteration-count);\n border-radius: var(--nostrc-border-radius-sm);\n width: 60px;\n height: 1em;\n display: inline-block;\n }\n\n @keyframes skeleton-loading {\n 0% {\n background-position: 200% 0;\n }\n 100% {\n background-position: -200% 0;\n }\n }\n\n /* Error message styling */\n .nostr-like-button-error small {\n color: var(--nostrc-color-error-text);\n font-size: var(--nostrc-font-size-sm);\n line-height: 1em;\n max-width: 250px;\n white-space: pre-line;\n }\n `;\n \n return getComponentStyles(customStyles);\n}\n","// SPDX-License-Identifier: MIT\n\nexport function getHelpDialogStyles(): string {\n return `\n .help-content {\n padding: var(--nostrc-spacing-md, 12px);\n }\n\n .help-content p {\n margin: 0 0 var(--nostrc-spacing-md, 12px) 0;\n color: var(--nostrc-theme-text-primary, #333333);\n line-height: 1.5;\n }\n\n .help-content p:last-child {\n margin-bottom: 0;\n }\n\n .help-content ul {\n margin: 0 0 var(--nostrc-spacing-md, 12px) 0;\n padding-left: var(--nostrc-spacing-lg, 16px);\n color: var(--nostrc-theme-text-primary, #333333);\n }\n\n .help-content li {\n margin-bottom: var(--nostrc-spacing-xs, 4px);\n line-height: 1.5;\n }\n\n .help-content li:last-child {\n margin-bottom: 0;\n }\n\n .help-content strong {\n font-weight: 600;\n color: var(--nostrc-theme-text-primary, #333333);\n }\n\n .help-content a {\n color: var(--nostrc-theme-primary, #0066cc);\n text-decoration: underline;\n }\n\n .help-content a:hover {\n color: var(--nostrc-theme-primary-hover, #0052a3);\n }\n `;\n}\n\n","// SPDX-License-Identifier: MIT\n\n// Import for side effects to register the custom element\nimport '../base/dialog-component/dialog-component';\nimport type { DialogComponent } from '../base/dialog-component/dialog-component';\nimport { getHelpDialogStyles } from './dialog-help-style';\n\nexport const injectHelpDialogStyles = (): void => {\n // Check if styles are already injected\n if (document.querySelector('style[data-help-dialog-styles]')) return;\n \n const style = document.createElement('style');\n style.setAttribute('data-help-dialog-styles', 'true');\n style.textContent = getHelpDialogStyles();\n document.head.appendChild(style);\n};\n\nexport const showHelpDialog = async (theme?: 'light' | 'dark'): Promise<void> => {\n injectHelpDialogStyles();\n \n if (!customElements.get('dialog-component')) {\n await customElements.whenDefined('dialog-component');\n }\n \n const dialogComponent = document.createElement('dialog-component') as DialogComponent;\n dialogComponent.setAttribute('header', 'What is a Like?');\n if (theme) {\n dialogComponent.setAttribute('data-theme', theme);\n }\n \n // Set dialog content\n dialogComponent.innerHTML = `\n <div class=\"help-content\">\n <p>Like any webpage to show your appreciation! Your likes are stored on Nostr, a decentralized network you control—no accounts needed.</p>\n <ul>\n <li>Like any webpage or article</li>\n <li>See who liked the content</li>\n <li>Works with a browser extension like <a href=\"https://getalby.com\" target=\"_blank\" rel=\"noopener noreferrer\">Alby</a> or nos2x</li>\n </ul>\n </div>\n `;\n \n dialogComponent.showModal();\n};\n\n","// utils.ts\nvar utf8Decoder = new TextDecoder(\"utf-8\");\nvar utf8Encoder = new TextEncoder();\nfunction normalizeURL(url) {\n if (url.indexOf(\"://\") === -1)\n url = \"wss://\" + url;\n let p = new URL(url);\n p.pathname = p.pathname.replace(/\\/+/g, \"/\");\n if (p.pathname.endsWith(\"/\"))\n p.pathname = p.pathname.slice(0, -1);\n if (p.port === \"80\" && p.protocol === \"ws:\" || p.port === \"443\" && p.protocol === \"wss:\")\n p.port = \"\";\n p.searchParams.sort();\n p.hash = \"\";\n return p.toString();\n}\nfunction insertEventIntoDescendingList(sortedArray, event) {\n const [idx, found] = binarySearch(sortedArray, (b) => {\n if (event.id === b.id)\n return 0;\n if (event.created_at === b.created_at)\n return -1;\n return b.created_at - event.created_at;\n });\n if (!found) {\n sortedArray.splice(idx, 0, event);\n }\n return sortedArray;\n}\nfunction insertEventIntoAscendingList(sortedArray, event) {\n const [idx, found] = binarySearch(sortedArray, (b) => {\n if (event.id === b.id)\n return 0;\n if (event.created_at === b.created_at)\n return -1;\n return event.created_at - b.created_at;\n });\n if (!found) {\n sortedArray.splice(idx, 0, event);\n }\n return sortedArray;\n}\nfunction binarySearch(arr, compare) {\n let start = 0;\n let end = arr.length - 1;\n while (start <= end) {\n const mid = Math.floor((start + end) / 2);\n const cmp = compare(arr[mid]);\n if (cmp === 0) {\n return [mid, true];\n }\n if (cmp < 0) {\n end = mid - 1;\n } else {\n start = mid + 1;\n }\n }\n return [start, false];\n}\nvar QueueNode = class {\n value;\n next = null;\n prev = null;\n constructor(message) {\n this.value = message;\n }\n};\nvar Queue = class {\n first;\n last;\n constructor() {\n this.first = null;\n this.last = null;\n }\n enqueue(value) {\n const newNode = new QueueNode(value);\n if (!this.last) {\n this.first = newNode;\n this.last = newNode;\n } else if (this.last === this.first) {\n this.last = newNode;\n this.last.prev = this.first;\n this.first.next = newNode;\n } else {\n newNode.prev = this.last;\n this.last.next = newNode;\n this.last = newNode;\n }\n return true;\n }\n dequeue() {\n if (!this.first)\n return null;\n if (this.first === this.last) {\n const target2 = this.first;\n this.first = null;\n this.last = null;\n return target2.value;\n }\n const target = this.first;\n this.first = target.next;\n return target.value;\n }\n};\nexport {\n Queue,\n QueueNode,\n binarySearch,\n insertEventIntoAscendingList,\n insertEventIntoDescendingList,\n normalizeURL,\n utf8Decoder,\n utf8Encoder\n};\n","// SPDX-License-Identifier: MIT\n\nimport { SimplePool } from 'nostr-tools';\nimport { normalizeURL } from 'nostr-tools/utils';\n\n/**\n * Helper utilities for Nostr like operations using NIP-25 External Content Reactions.\n * These are deliberately kept self-contained so `nostr-like` Web Component can import\n * everything from a single module without polluting the rest of the codebase.\n */\n\nexport interface LikeDetails {\n authorPubkey: string;\n date: Date;\n content: string;\n}\n\nexport interface LikeCountResult {\n totalCount: number;\n likeDetails: LikeDetails[];\n likedCount: number;\n dislikedCount: number;\n}\n\n/**\n * Fetch all likes for a URL using NIP-25 kind 17 events\n */\nexport async function fetchLikesForUrl(\n url: string, \n relays: string[]\n): Promise<LikeCountResult> {\n // Normalize URL at the beginning for consistent comparison with tags\n const normalizedUrl = normalizeURL(url);\n \n const pool = new SimplePool();\n \n try {\n // Query kind 17 events (both likes and unlikes)\n const events = await pool.querySync(relays, {\n kinds: [17],\n '#k': ['web'],\n '#i': [normalizedUrl],\n limit: 1000\n });\n \n const likes: LikeDetails[] = [];\n let likedCount = 0;\n let dislikedCount = 0;\n \n for (const event of events) {\n likes.push({\n authorPubkey: event.pubkey,\n date: new Date(event.created_at * 1000),\n content: event.content\n });\n \n if (event.content === '-') {\n dislikedCount++;\n } else {\n likedCount++;\n }\n }\n \n likes.sort((a, b) => b.date.getTime() - a.date.getTime());\n \n const totalCount = likedCount - dislikedCount;\n \n return {\n totalCount: totalCount,\n likeDetails: likes,\n likedCount: likedCount,\n dislikedCount: dislikedCount\n };\n } catch (error) {\n // Rethrow error so callers can handle relay/network failures appropriately\n throw error instanceof Error ? error : new Error(String(error));\n } finally {\n pool.close(relays);\n }\n}\n\n/**\n * Create reaction event (kind 17)\n * @param url - URL to react to\n * @param content - '+' for like, '-' for unlike\n */\nexport function createReactionEvent(url: string, content: '+' | '-'): any {\n return {\n kind: 17,\n content,\n tags: [\n ['k', 'web'],\n ['i', url]\n ],\n created_at: Math.floor(Date.now() / 1000)\n };\n}\n\n/**\n * Create like event (kind 17)\n * @deprecated Use createReactionEvent(url, '+') instead\n */\nexport function createLikeEvent(url: string): any {\n return createReactionEvent(url, '+');\n}\n\n/**\n * Create unlike event (kind 17 with '-' content)\n * @deprecated Use createReactionEvent(url, '-') instead\n */\nexport function createUnlikeEvent(url: string): any {\n return createReactionEvent(url, '-');\n}\n\n/**\n * Check if user has liked a URL\n */\nexport async function hasUserLiked(\n url: string,\n userPubkey: string,\n relays: string[]\n): Promise<boolean> {\n const pool = new SimplePool();\n const normalizedUrl = url;\n \n try {\n // Get user's latest reaction for this URL\n const events = await pool.querySync(relays, {\n kinds: [17],\n authors: [userPubkey],\n '#k': ['web'],\n '#i': [normalizedUrl],\n limit: 1\n });\n \n if (events.length === 0) return false;\n \n // Check if latest reaction is a like (not an unlike)\n const latest = events[0];\n return latest.content === '+' || latest.content === '';\n } catch (error) {\n console.error(\"Nostr-Components: Like button: Error checking user like status\", error);\n return false;\n } finally {\n pool.close(relays);\n }\n}\n\n/**\n * Get user's pubkey from NIP-07 signer\n */\nexport async function getUserPubkey(): Promise<string | null> {\n try {\n if (typeof window !== 'undefined' && (window as any).nostr) {\n const nip07signer = (window as any).nostr;\n const user = await nip07signer.getPublicKey();\n return user;\n }\n } catch (error) {\n console.error(\"Nostr-Components: Like button: Error getting user pubkey\", error);\n }\n return null;\n}\n\n/**\n * Sign event with NIP-07\n */\nexport async function signEvent(event: any): Promise<any> {\n try {\n if (typeof window !== 'undefined' && (window as any).nostr) {\n const nip07signer = (window as any).nostr;\n const signedEvent = await nip07signer.signEvent(event);\n return signedEvent;\n }\n throw new Error('NIP-07 extension not available');\n } catch (error) {\n console.error(\"Nostr-Components: Like button: Error signing event\", error);\n throw error;\n }\n}\n\n/**\n * Check if NIP-07 extension is available\n */\nexport function isNip07Available(): boolean {\n return typeof window !== 'undefined' && !!(window as any).nostr;\n}\n","// SPDX-License-Identifier: MIT\n\nimport { NostrBaseComponent } from '../base/base-component/nostr-base-component';\nimport { NCStatus } from '../base/base-component/nostr-base-component';\nimport { NDKEvent } from '@nostr-dev-kit/ndk';\nimport { renderLikeButton, RenderLikeButtonOptions } from './render';\nimport { getLikeButtonStyles } from './style';\nimport { showHelpDialog } from './dialog-help';\nimport { isValidUrl } from '../common/utils';\nimport { \n fetchLikesForUrl, \n createLikeEvent,\n createUnlikeEvent,\n hasUserLiked, \n getUserPubkey, \n signEvent, \n isNip07Available,\n LikeCountResult \n} from './like-utils';\nimport { normalizeURL } from 'nostr-tools/utils';\n\n/**\n * <nostr-like>\n * Attributes:\n * - url (optional) : URL to like (default: current page URL)\n * - text (optional) : custom text (default \"Like\") (Max 32 characters)\n * - relays (optional) : comma-separated relay URLs\n * - data-theme (optional) : \"light\" | \"dark\" (default light)\n * \n * Features:\n * - URL-based likes using NIP-25 kind 17 events\n * - Click count to view likers\n */\nexport default class NostrLike extends NostrBaseComponent {\n protected likeActionStatus = this.channel('likeAction');\n protected likeListStatus = this.channel('likeList');\n \n private currentUrl: string = '';\n private isLiked: boolean = false;\n private likeCount: number = 0;\n private cachedLikeDetails: LikeCountResult | null = null;\n private loadSeq = 0;\n\n constructor() {\n super();\n this.likeListStatus.set(NCStatus.Loading);\n }\n\n connectedCallback() {\n super.connectedCallback?.();\n this.attachDelegatedListeners();\n this.render();\n }\n\n static get observedAttributes() {\n return [\n ...super.observedAttributes,\n 'url',\n 'text'\n ];\n }\n\n attributeChangedCallback(\n name: string,\n oldValue: string | null,\n newValue: string | null\n ) {\n if (oldValue === newValue) return;\n super.attributeChangedCallback(name, oldValue, newValue);\n \n if (name === 'url' || name === 'text') {\n this.likeActionStatus.set(NCStatus.Ready);\n this.likeListStatus.set(NCStatus.Loading);\n this.isLiked = false;\n this.errorMessage = '';\n this.updateLikeCount();\n this.render();\n }\n }\n\n /** Base class functions */\n protected validateInputs(): boolean {\n if (!super.validateInputs()) {\n this.likeActionStatus.set(NCStatus.Idle);\n this.likeListStatus.set(NCStatus.Idle);\n return false;\n }\n\n const urlAttr = this.getAttribute('url');\n const textAttr = this.getAttribute('text');\n const tagName = this.tagName.toLowerCase();\n\n let errorMessage: string | null = null;\n\n if (urlAttr) {\n if (!isValidUrl(urlAttr)) {\n errorMessage = 'Invalid URL format';\n }\n }\n\n if (textAttr && textAttr.length > 32) {\n errorMessage = 'Max text length: 32 characters';\n }\n\n if (errorMessage) {\n this.likeActionStatus.set(NCStatus.Error, errorMessage);\n this.likeListStatus.set(NCStatus.Error, errorMessage);\n console.error(`Nostr-Components: ${tagName}: ${errorMessage}`);\n return false;\n }\n\n return true;\n }\n\n protected onStatusChange(_status: NCStatus) {\n this.render();\n }\n\n protected onNostrRelaysConnected() {\n this.updateLikeCount();\n this.render();\n }\n\n /** Private functions */\n /**\n * Lazy initializer for currentUrl - ensures it's set before like/unlike operations\n */\n private ensureCurrentUrl(): void {\n if (!this.currentUrl) {\n this.currentUrl = normalizeURL(this.getAttribute('url') || window.location.href);\n }\n }\n\n private async updateLikeCount() {\n const seq = ++this.loadSeq;\n try {\n await this.ensureNostrConnected();\n this.currentUrl = normalizeURL(this.getAttribute('url') || window.location.href);\n this.likeListStatus.set(NCStatus.Loading);\n this.render();\n \n const result = await fetchLikesForUrl(this.currentUrl, this.getRelays());\n if (seq !== this.loadSeq) return; // stale\n this.likeCount = result.totalCount;\n this.cachedLikeDetails = result;\n this.likeListStatus.set(NCStatus.Ready);\n } catch (error) {\n console.error('[NostrLike] Failed to fetch like count:', error);\n this.likeListStatus.set(NCStatus.Error, 'Failed to load likes');\n } finally {\n this.render();\n }\n }\n\n // TODO: Do onboarding logic here\n private async handleLikeClick() {\n // Ensure currentUrl is set before proceeding\n this.ensureCurrentUrl();\n \n if (!this.currentUrl) {\n this.likeActionStatus.set(NCStatus.Error, 'Invalid URL');\n this.render();\n return;\n }\n\n this.likeActionStatus.set(NCStatus.Loading);\n if (!isNip07Available()) {\n this.likeActionStatus.set(NCStatus.Error, \n 'Please install a Nostr browser extension (Alby, nos2x, etc.)'\n );\n this.render();\n return;\n }\n\n // Check user like status\n try {\n const userPubkey = await getUserPubkey();\n if (userPubkey) {\n this.isLiked = await hasUserLiked(this.currentUrl, userPubkey, this.getRelays());\n }\n } catch (error) {\n console.error('[NostrLike] Failed to check user like status:', error);\n this.likeActionStatus.set(NCStatus.Error, 'Failed to check user like status');\n } finally {\n this.render();\n }\n\n // If already liked, show confirmation dialog\n if (this.isLiked) {\n const confirmed = window.confirm('You have already liked this. Do you want to unlike it?');\n if (!confirmed) {\n this.likeActionStatus.set(NCStatus.Ready);\n this.render();\n return;\n }\n \n // Proceed with unlike\n await this.handleUnlike();\n } else {\n // Proceed with like\n await this.handleLike();\n }\n }\n\n private async handleLike() {\n // Ensure currentUrl is set before proceeding\n this.ensureCurrentUrl();\n \n if (!this.currentUrl) {\n this.likeActionStatus.set(NCStatus.Error, 'Invalid URL');\n this.render();\n return;\n }\n\n this.likeActionStatus.set(NCStatus.Loading);\n this.render();\n\n try {\n // Create like event\n const event = createLikeEvent(this.currentUrl);\n \n // Sign with NIP-07\n const signedEvent = await signEvent(event);\n \n // Create NDKEvent and publish\n const ndkEvent = new NDKEvent(this.nostrService.getNDK(), signedEvent);\n await ndkEvent.publish();\n \n // Update state optimistically\n this.isLiked = true;\n this.likeCount++;\n this.likeActionStatus.set(NCStatus.Ready);\n \n // Refresh like count to get accurate data\n await this.updateLikeCount();\n } catch (error) {\n console.error('[NostrLike] Failed to like:', error);\n \n // Rollback optimistic update\n this.isLiked = false;\n this.likeCount--;\n \n const errorMessage = error instanceof Error ? error.message : 'Failed to like';\n this.likeActionStatus.set(NCStatus.Error, errorMessage);\n } finally {\n this.render();\n }\n }\n\n private async handleUnlike() {\n // Ensure currentUrl is set before proceeding\n this.ensureCurrentUrl();\n \n if (!this.currentUrl) {\n this.likeActionStatus.set(NCStatus.Error, 'Invalid URL');\n this.render();\n return;\n }\n\n this.likeActionStatus.set(NCStatus.Loading);\n this.render();\n \n try {\n // Create unlike event\n const event = createUnlikeEvent(this.currentUrl);\n \n // Sign with NIP-07\n const signedEvent = await signEvent(event);\n \n // Create NDKEvent and publish\n const ndkEvent = new NDKEvent(this.nostrService.getNDK(), signedEvent);\n await ndkEvent.publish();\n \n // Update state optimistically\n this.isLiked = false;\n if (this.likeCount > 0) {\n this.likeCount--;\n }\n this.likeActionStatus.set(NCStatus.Ready);\n \n // Refresh like count to get accurate data\n await this.updateLikeCount();\n } catch (error) {\n console.error('[NostrLike] Failed to unlike:', error);\n \n // Rollback optimistic update\n this.isLiked = true;\n this.likeCount++;\n \n const errorMessage = error instanceof Error ? error.message : 'Failed to unlike';\n this.likeActionStatus.set(NCStatus.Error, errorMessage);\n } finally {\n this.render();\n }\n }\n\n private async handleCountClick() {\n if (this.likeCount === 0 || !this.cachedLikeDetails) {\n return;\n }\n\n try {\n // Import dialog dynamically to avoid circular dependencies\n const { openLikersDialog } = await import('./dialog-likers');\n await openLikersDialog({\n likeDetails: this.cachedLikeDetails.likeDetails,\n theme: this.theme === 'dark' ? 'dark' : 'light',\n });\n } catch (error) {\n console.error('[NostrLike] Error opening likers dialog:', error);\n }\n }\n\n private async handleHelpClick() {\n try {\n await showHelpDialog(this.theme === 'dark' ? 'dark' : 'light');\n } catch (error) {\n console.error('[NostrLike] Error showing help dialog:', error);\n }\n }\n\n private attachDelegatedListeners() {\n this.delegateEvent('click', '.nostr-like-button', (e) => {\n e.preventDefault?.();\n e.stopPropagation?.();\n void this.handleLikeClick();\n });\n\n this.delegateEvent('click', '.like-count', (e) => {\n e.preventDefault?.();\n e.stopPropagation?.();\n void this.handleCountClick();\n });\n\n this.delegateEvent('click', '.help-icon', (e) => {\n e.preventDefault?.();\n e.stopPropagation?.();\n this.handleHelpClick();\n });\n }\n\n protected renderContent() {\n // console.log(`Like: Render: conn: ${this.conn.get()}, likeActionStatus: ${this.likeActionStatus.get()}, likeListStatus: ${this.likeListStatus.get()}`);\n const isLoading = this.likeActionStatus.get() === NCStatus.Loading || this.conn.get() === NCStatus.Loading;\n const isCountLoading = this.likeListStatus.get() === NCStatus.Loading;\n const isError = this.computeOverall() === NCStatus.Error;\n const errorMessage = this.errorMessage;\n const buttonText = this.getAttribute('text') || 'Like';\n\n const renderOptions: RenderLikeButtonOptions = {\n isLoading,\n isError,\n errorMessage,\n buttonText,\n isLiked: this.isLiked,\n likeCount: this.likeCount,\n hasLikes: this.likeCount > 0,\n isCountLoading,\n theme: this.theme as 'light' | 'dark',\n };\n\n this.shadowRoot!.innerHTML = `\n ${getLikeButtonStyles()}\n ${renderLikeButton(renderOptions)}\n `;\n }\n}\n\ncustomElements.define('nostr-like', NostrLike);\n"],"file":"components/nostr-like.es.js"}
|
|
1
|
+
{"version":3,"mappings":";6ZAcO,SAASA,EAAiB,CAC/B,UAAAC,EACA,QAAAC,EACA,aAAAC,EACA,WAAAC,EACA,QAAAC,EACA,UAAAC,EACA,SAAAC,EAAW,GACX,eAAAC,EAAiB,GACjB,MAAAC,EAAQ,OACV,EAAoC,CAElC,GAAIP,EACK,OAAAQ,EAAYP,GAAgB,EAAE,EAGjC,MAAAQ,EAAcC,EAAgBP,EAASI,CAAK,EAC5CI,EAAcR,EAChB,qBACA,SAASS,EAAWV,CAAU,CAAC,UAEnC,OAAOW,EAAgBJ,EAAaE,EAAaP,EAAWC,EAAUF,EAASJ,EAAWO,CAAc,CAC1G,CAEA,SAASE,EAAYP,EAA8B,CAC1C,OAAAa,EACL,wCACAF,EAAWX,CAAY,CACzB,CACF,CAEA,SAASa,EAAqBC,EAAqBC,EAA8B,CACxE;AAAA;AAAA;AAAA,UAGCD,CAAW;AAAA;AAAA;AAAA,UAGXC,CAAY;AAAA;AAAA;AAAA,GAItB,CAEA,SAASH,EACPJ,EACAE,EACAP,EACA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,IACAC,EAAAD,EAAE,kBAAF,MAAAC,EAAA,KAAAD,GACA,KAAK,gBAAgB,EACtB,EAGO,eAAgB,CAElB,MAAAzE,EAAY,KAAK,iBAAiB,IAAI,IAAM0D,EAAS,SAAW,KAAK,KAAK,IAAI,IAAMA,EAAS,QAC7FnD,EAAiB,KAAK,eAAe,QAAUmD,EAAS,QACxDzD,EAAU,KAAK,eAAe,IAAMyD,EAAS,MAC7CxD,EAAe,KAAK,aACpBC,EAAa,KAAK,aAAa,MAAM,GAAK,OAE1CwE,EAAyC,CAC7C,UAAA3E,EACA,QAAAC,EACA,aAAAC,EACA,WAAAC,EACA,QAAS,KAAK,QACd,UAAW,KAAK,UAChB,SAAU,KAAK,UAAY,EAC3B,eAAAI,EACA,MAAO,KAAK,KACd,EAEA,KAAK,WAAY,UAAY;AAAA,QACzBc,EAAqB;AAAA,QACrBtB,EAAiB4E,CAAa,CAAC;AAAA,MAGvC,CAEA,eAAe,OAAO,aAAcrB,CAAS","names":["renderLikeButton","isLoading","isError","errorMessage","buttonText","isLiked","likeCount","hasLikes","isCountLoading","theme","renderError","iconContent","getThumbsUpIcon","textContent","escapeHtml","renderContainer","renderErrorContainer","leftContent","rightContent","countHtml","likedColor","outlineColor","getLikeButtonStyles","getComponentStyles","getHelpDialogStyles","injectHelpDialogStyles","style","showHelpDialog","dialogComponent","normalizeURL","url","p","fetchLikesForUrl","relays","normalizedUrl","pool","SimplePool","events","likes","likedCount","dislikedCount","event","a","b","error","createReactionEvent","content","createLikeEvent","createUnlikeEvent","hasUserLiked","userPubkey","latest","getUserPubkey","signEvent","isNip07Available","NostrLike","NostrBaseComponent","__publicField","_a","NCStatus","name","oldValue","newValue","urlAttr","textAttr","tagName","isValidUrl","_status","seq","result","signedEvent","NDKEvent","openLikersDialog","__vitePreload","e","_b","renderOptions"],"ignoreList":[4],"sources":["../../src/nostr-like/render.ts","../../src/nostr-like/style.ts","../../src/nostr-like/dialog-help-style.ts","../../src/nostr-like/dialog-help.ts","../../node_modules/nostr-tools/lib/esm/utils.js","../../src/nostr-like/like-utils.ts","../../src/nostr-like/nostr-like.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n\nimport { escapeHtml } from '../common/utils';\nimport { IRenderOptions } from '../base/render-options';\n\nexport interface RenderLikeButtonOptions extends IRenderOptions {\n buttonText: string;\n isLiked: boolean;\n likeCount: number;\n hasLikes?: boolean;\n isCountLoading?: boolean;\n theme?: 'light' | 'dark';\n}\n\nexport function renderLikeButton({\n isLoading,\n isError,\n errorMessage,\n buttonText,\n isLiked,\n likeCount,\n hasLikes = false,\n isCountLoading = false,\n theme = 'light',\n}: RenderLikeButtonOptions): string {\n\n if (isError) {\n return renderError(errorMessage || '');\n }\n\n const iconContent = getThumbsUpIcon(isLiked, theme);\n const textContent = isLiked \n ? `<span>Liked</span>`\n : `<span>${escapeHtml(buttonText)}</span>`;\n\n return renderContainer(iconContent, textContent, likeCount, hasLikes, isLiked, isLoading, isCountLoading);\n}\n\nfunction renderError(errorMessage: string): string {\n return renderErrorContainer(\n '<div class=\"error-icon\">⚠</div>',\n escapeHtml(errorMessage)\n );\n}\n\nfunction renderErrorContainer(leftContent: string, rightContent: string): string {\n return `\n <div class=\"nostr-like-button-container\">\n <div class=\"nostr-like-button-left-container\">\n ${leftContent}\n </div>\n <div class=\"nostr-like-button-right-container\">\n ${rightContent}\n </div>\n </div>\n `;\n}\n\nfunction renderContainer(\n iconContent: string, \n textContent: string, \n likeCount: number, \n hasLikes: boolean = false,\n isLiked: boolean = false,\n isLoading: boolean = false,\n isCountLoading: boolean = false\n): string {\n let countHtml = '';\n if (isCountLoading) {\n countHtml = '<span class=\"like-count skeleton\"></span>';\n } else if (likeCount > 0) {\n const label = likeCount === 1 ? 'like' : 'likes';\n countHtml = `<span class=\"like-count${hasLikes ? ' clickable' : ''}\">${likeCount} ${label}</span>`;\n }\n \n const buttonClass = isLiked ? 'nostr-like-button liked' : 'nostr-like-button';\n const helpIconHtml = `<button class=\"help-icon\" title=\"What is a like?\">?</button>`;\n \n return `\n <div class=\"nostr-like-button-container\">\n <button class=\"${buttonClass}\">\n ${iconContent}\n ${isLoading ? '<span class=\"button-text-skeleton\"></span>' : textContent}\n </button>\n ${countHtml} ${helpIconHtml}\n </div>\n `;\n}\n\nfunction getThumbsUpIcon(isLiked: boolean, theme: 'light' | 'dark' = 'light'): string {\n // Determine colors based on theme\n const likedColor = theme === 'dark' ? '#8ab4f8' : '#1877f2'; // Light blue for dark theme, blue for light theme\n const outlineColor = theme === 'dark' ? '#e0e7ff' : '#0d46a1'; // Light color for dark theme, dark blue for light theme\n\n if (isLiked) {\n // Filled thumbs up\n return `<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 100 100\" width=\"24\" height=\"24\">\n <path d=\"M93.6,53.1c2.6-1.5,4.2-4.4,3.8-7.6c-0.5-4-4.2-6.8-8.2-6.8l-25,0c0.2-0.5,0.5-1.2,0.7-1.8c1.5-3.8,4.3-10.8,4.3-18 c0-8.1-5.7-13-9.6-13.3C57.2,5.5,55.4,7,55,9.7c-0.7,5.1-4.1,12.6-5.5,15.5c-0.4,0.9-0.9,1.7-1.6,2.4c-2.3,2.6-8.1,9-13.6,12.8 c0,0.2,0.1,0.5,0.1,0.7v47.9c0,0.4-0.1,0.8-0.1,1.2c9.4,2.7,17.9,4,27.2,4l21.3,0c3.7,0,7.2-2.5,7.9-6.1c0.6-3-0.5-5.7-2.5-7.5 c3.4-0.8,6-3.9,6-7.5c0-2.3-1-4.4-2.7-5.8c3.4-0.8,6-3.9,6-7.5C97.5,57,96,54.5,93.6,53.1z\" fill=\"${likedColor}\"/>\n <path d=\"M23.4,36.9H6.7c-2.3,0-4.2,1.9-4.2,4.2v47.9c0,2.3,1.9,4.2,4.2,4.2h16.7c2.3,0,4.2-1.9,4.2-4.2V41.2 C27.6,38.8,25.8,36.9,23.4,36.9z M15.1,85.9c-2.4,0-4.4-2-4.4-4.4s2-4.4,4.4-4.4c2.4,0,4.4,2,4.4,4.4S17.5,85.9,15.1,85.9z\" fill=\"${likedColor}\"/>\n </svg>`;\n } else {\n // Outline thumbs up\n return `<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 100 100\" width=\"24\" height=\"24\">\n <path d=\"M93.6,53.1c2.6-1.5,4.2-4.4,3.8-7.6c-0.5-4-4.2-6.8-8.2-6.8l-25,0c0.2-0.5,0.5-1.2,0.7-1.8c1.5-3.8,4.3-10.8,4.3-18 c0-8.1-5.7-13-9.6-13.3C57.2,5.5,55.4,7,55,9.7c-0.7,5.1-4.1,12.6-5.5,15.5c-0.4,0.9-0.9,1.7-1.6,2.4c-2.3,2.6-8.1,9-13.6,12.8 c0,0.2,0.1,0.5,0.1,0.7v47.9c0,0.4-0.1,0.8-0.1,1.2c9.4,2.7,17.9,4,27.2,4l21.3,0c3.7,0,7.2-2.5,7.9-6.1c0.6-3-0.5-5.7-2.5-7.5 c3.4-0.8,6-3.9,6-7.5c0-2.3-1-4.4-2.7-5.8c3.4-0.8,6-3.9,6-7.5C97.5,57,96,54.5,93.6,53.1z\" fill=\"none\" stroke=\"${outlineColor}\" stroke-width=\"2\"/>\n <path d=\"M23.4,36.9H6.7c-2.3,0-4.2,1.9-4.2,4.2v47.9c0,2.3,1.9,4.2,4.2,4.2h16.7c2.3,0,4.2-1.9,4.2-4.2V41.2 C27.6,38.8,25.8,36.9,23.4,36.9z M15.1,85.9c-2.4,0-4.4-2-4.4-4.4s2-4.4,4.4-4.4c2.4,0,4.4,2,4.4,4.4S17.5,85.9,15.1,85.9z\" fill=\"none\" stroke=\"${outlineColor}\" stroke-width=\"2\"/>\n </svg>`;\n }\n}\n","// SPDX-License-Identifier: MIT\n\nimport { getComponentStyles } from '../common/base-styles';\n\nexport function getLikeButtonStyles(): string {\n const customStyles = `\n /* === LIKE BUTTON CONTAINER PATTERN === */\n :host {\n /* Icon sizing (overridable via CSS variables) */\n --nostrc-icon-height: 25px;\n --nostrc-icon-width: 25px;\n\n /* Like button CSS variables (overridable by parent components) */\n --nostrc-like-btn-padding: var(--nostrc-spacing-sm) var(--nostrc-spacing-md);\n --nostrc-like-btn-border-radius: var(--nostrc-border-radius-md);\n --nostrc-like-btn-border: var(--nostrc-border-width) solid var(--nostrc-color-border);\n --nostrc-like-btn-min-height: 47px;\n --nostrc-like-btn-width: auto;\n --nostrc-like-btn-horizontal-alignment: left;\n --nostrc-like-btn-bg: var(--nostrc-theme-bg, #ffffff);\n --nostrc-like-btn-color: var(--nostrc-theme-text-primary, #333333);\n --nostrc-like-btn-font-family: var(--nostrc-font-family-primary);\n --nostrc-like-btn-font-size: var(--nostrc-font-size-base);\n \n /* Hover state variables */\n --nostrc-like-btn-hover-bg: var(--nostrc-theme-hover-bg, rgba(0, 0, 0, 0.05));\n --nostrc-like-btn-hover-color: var(--nostrc-theme-text-primary, #333333);\n --nostrc-like-btn-hover-border: var(--nostrc-border-width) solid var(--nostrc-theme-border, var(--nostrc-color-border));\n\n /* Liked state variables */\n --nostrc-like-btn-liked-bg: #e7f3ff;\n --nostrc-like-btn-liked-color: #1877f2;\n --nostrc-like-btn-liked-border: #1877f2;\n --nostrc-like-btn-liked-hover-bg: #d1e7ff;\n\n /* Make the host a flex container for button + count */\n display: inline-flex;\n flex-direction: row;\n align-items: center;\n gap: var(--nostrc-spacing-md);\n font-family: var(--nostrc-like-btn-font-family);\n font-size: var(--nostrc-like-btn-font-size);\n }\n\n /* Focus state for accessibility */\n :host(:focus-visible) {\n outline: 2px solid var(--nostrc-color-primary, #007bff);\n outline-offset: 2px;\n }\n\n :host(.is-error) .nostr-like-button-container {\n border: var(--nostrc-border-width) solid var(--nostrc-color-error-text);\n border-radius: var(--nostrc-border-radius-md);\n padding: var(--nostrc-spacing-sm);\n color: var(--nostrc-color-error-text);\n }\n\n .nostr-like-button-container {\n display: flex;\n align-items: center;\n gap: var(--nostrc-spacing-md);\n width: fit-content;\n }\n\n .nostr-like-button-left-container {\n display: flex;\n align-items: center;\n }\n\n .nostr-like-button-right-container {\n display: flex;\n align-items: center;\n }\n\n .nostr-like-button {\n display: flex;\n align-items: center;\n justify-content: var(--nostrc-like-btn-horizontal-alignment);\n gap: var(--nostrc-spacing-sm);\n background: var(--nostrc-like-btn-bg);\n color: var(--nostrc-like-btn-color);\n border: var(--nostrc-like-btn-border);\n border-radius: var(--nostrc-like-btn-border-radius);\n padding: var(--nostrc-like-btn-padding);\n min-height: var(--nostrc-like-btn-min-height);\n width: var(--nostrc-like-btn-width);\n cursor: pointer;\n transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;\n font-family: inherit;\n font-size: inherit;\n }\n\n /* Hover state on the button */\n .nostr-like-button:hover {\n background: var(--nostrc-like-btn-hover-bg);\n color: var(--nostrc-like-btn-hover-color);\n border: var(--nostrc-like-btn-hover-border);\n }\n\n /* Liked state */\n .nostr-like-button.liked {\n background: var(--nostrc-like-btn-liked-bg);\n color: var(--nostrc-like-btn-liked-color);\n border: var(--nostrc-border-width) solid var(--nostrc-like-btn-liked-border);\n }\n\n .nostr-like-button.liked:hover {\n background: var(--nostrc-like-btn-liked-hover-bg);\n }\n\n .nostr-like-button:disabled {\n pointer-events: none;\n user-select: none;\n opacity: 0.6;\n }\n\n :host:not([status=\"ready\"]) .nostr-like-button {\n cursor: not-allowed;\n }\n\n /* SVG Icon Styles */\n .nostr-like-button svg {\n display: inline-block;\n vertical-align: middle;\n width: var(--nostrc-icon-width);\n height: var(--nostrc-icon-height);\n }\n\n /* Like count display */\n .like-count {\n font-size: var(--nostrc-font-size-sm);\n color: var(--nostrc-theme-text-secondary, #666666);\n white-space: nowrap;\n text-decoration: underline;\n text-decoration-color: transparent;\n transition: text-decoration-color 0.2s ease, color 0.2s ease;\n }\n\n /* Clickable like count */\n .like-count.clickable {\n cursor: pointer;\n text-decoration-color: currentColor;\n }\n\n .like-count.clickable:hover {\n color: var(--nostrc-color-primary, #7f00ff);\n text-decoration-color: var(--nostrc-color-primary, #7f00ff);\n }\n\n /* Help icon */\n .help-icon {\n background: none;\n border: 1px solid var(--nostrc-color-border, #e0e0e0);\n border-radius: var(--nostrc-border-radius-full, 50%);\n width: var(--nostrc-help-icon-size, 16px);\n height: var(--nostrc-help-icon-size, 16px);\n font-size: calc(var(--nostrc-help-icon-size, 16px) * 0.7);\n font-weight: bold;\n color: var(--nostrc-theme-text-secondary, #666666);\n cursor: pointer;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n margin-left: var(--nostrc-spacing-xs, 4px);\n transition: all 0.2s ease;\n }\n\n .help-icon:hover {\n background: var(--nostrc-color-hover-background, rgba(0, 0, 0, 0.05));\n border-color: var(--nostrc-color-primary, #7f00ff);\n color: var(--nostrc-color-primary, #7f00ff);\n }\n\n /* Skeleton loader for like count */\n .like-count.skeleton {\n background: linear-gradient(90deg, \n var(--nostrc-skeleton-color-min) 25%, \n var(--nostrc-skeleton-color-max) 50%, \n var(--nostrc-skeleton-color-min) 75%\n );\n background-size: 200% 100%;\n animation: skeleton-loading var(--nostrc-skeleton-duration) var(--nostrc-skeleton-timing-function) var(--nostrc-skeleton-iteration-count);\n border-radius: var(--nostrc-border-radius-sm);\n width: 80px;\n height: 1.2em;\n display: inline-block;\n }\n\n /* Skeleton loader for button text */\n .button-text-skeleton {\n background: linear-gradient(90deg, \n var(--nostrc-skeleton-color-min) 25%, \n var(--nostrc-skeleton-color-max) 50%, \n var(--nostrc-skeleton-color-min) 75%\n );\n background-size: 200% 100%;\n animation: skeleton-loading var(--nostrc-skeleton-duration) var(--nostrc-skeleton-timing-function) var(--nostrc-skeleton-iteration-count);\n border-radius: var(--nostrc-border-radius-sm);\n width: 60px;\n height: 1em;\n display: inline-block;\n }\n\n @keyframes skeleton-loading {\n 0% {\n background-position: 200% 0;\n }\n 100% {\n background-position: -200% 0;\n }\n }\n\n /* Error message styling */\n .nostr-like-button-error small {\n color: var(--nostrc-color-error-text);\n font-size: var(--nostrc-font-size-sm);\n line-height: 1em;\n max-width: 250px;\n white-space: pre-line;\n }\n `;\n \n return getComponentStyles(customStyles);\n}\n","// SPDX-License-Identifier: MIT\n\nexport function getHelpDialogStyles(): string {\n return `\n .help-content {\n padding: var(--nostrc-spacing-md, 12px);\n }\n\n .help-content p {\n margin: 0 0 var(--nostrc-spacing-md, 12px) 0;\n color: var(--nostrc-theme-text-primary, #333333);\n line-height: 1.5;\n }\n\n .help-content p:last-child {\n margin-bottom: 0;\n }\n\n .help-content ul {\n margin: 0 0 var(--nostrc-spacing-md, 12px) 0;\n padding-left: var(--nostrc-spacing-lg, 16px);\n color: var(--nostrc-theme-text-primary, #333333);\n }\n\n .help-content li {\n margin-bottom: var(--nostrc-spacing-xs, 4px);\n line-height: 1.5;\n }\n\n .help-content li:last-child {\n margin-bottom: 0;\n }\n\n .help-content strong {\n font-weight: 600;\n color: var(--nostrc-theme-text-primary, #333333);\n }\n\n .help-content a {\n color: var(--nostrc-theme-primary, #0066cc);\n text-decoration: underline;\n }\n\n .help-content a:hover {\n color: var(--nostrc-theme-primary-hover, #0052a3);\n }\n `;\n}\n\n","// SPDX-License-Identifier: MIT\n\n// Import for side effects to register the custom element\nimport '../base/dialog-component/dialog-component';\nimport type { DialogComponent } from '../base/dialog-component/dialog-component';\nimport { getHelpDialogStyles } from './dialog-help-style';\n\nexport const injectHelpDialogStyles = (): void => {\n // Check if styles are already injected\n if (document.querySelector('style[data-help-dialog-styles]')) return;\n \n const style = document.createElement('style');\n style.setAttribute('data-help-dialog-styles', 'true');\n style.textContent = getHelpDialogStyles();\n document.head.appendChild(style);\n};\n\nexport const showHelpDialog = async (theme?: 'light' | 'dark'): Promise<void> => {\n injectHelpDialogStyles();\n \n if (!customElements.get('dialog-component')) {\n await customElements.whenDefined('dialog-component');\n }\n \n const dialogComponent = document.createElement('dialog-component') as DialogComponent;\n dialogComponent.setAttribute('header', 'What is a Like?');\n if (theme) {\n dialogComponent.setAttribute('data-theme', theme);\n }\n \n // Set dialog content\n dialogComponent.innerHTML = `\n <div class=\"help-content\">\n <p>Like any webpage to show your appreciation! Your likes are stored on Nostr, a decentralized network you control—no accounts needed.</p>\n <ul>\n <li>Like any webpage or article</li>\n <li>See who liked the content</li>\n <li>Works with a browser extension like <a href=\"https://getalby.com\" target=\"_blank\" rel=\"noopener noreferrer\">Alby</a> or nos2x</li>\n </ul>\n </div>\n `;\n \n dialogComponent.showModal();\n};\n\n","// utils.ts\nvar utf8Decoder = new TextDecoder(\"utf-8\");\nvar utf8Encoder = new TextEncoder();\nfunction normalizeURL(url) {\n if (url.indexOf(\"://\") === -1)\n url = \"wss://\" + url;\n let p = new URL(url);\n p.pathname = p.pathname.replace(/\\/+/g, \"/\");\n if (p.pathname.endsWith(\"/\"))\n p.pathname = p.pathname.slice(0, -1);\n if (p.port === \"80\" && p.protocol === \"ws:\" || p.port === \"443\" && p.protocol === \"wss:\")\n p.port = \"\";\n p.searchParams.sort();\n p.hash = \"\";\n return p.toString();\n}\nfunction insertEventIntoDescendingList(sortedArray, event) {\n const [idx, found] = binarySearch(sortedArray, (b) => {\n if (event.id === b.id)\n return 0;\n if (event.created_at === b.created_at)\n return -1;\n return b.created_at - event.created_at;\n });\n if (!found) {\n sortedArray.splice(idx, 0, event);\n }\n return sortedArray;\n}\nfunction insertEventIntoAscendingList(sortedArray, event) {\n const [idx, found] = binarySearch(sortedArray, (b) => {\n if (event.id === b.id)\n return 0;\n if (event.created_at === b.created_at)\n return -1;\n return event.created_at - b.created_at;\n });\n if (!found) {\n sortedArray.splice(idx, 0, event);\n }\n return sortedArray;\n}\nfunction binarySearch(arr, compare) {\n let start = 0;\n let end = arr.length - 1;\n while (start <= end) {\n const mid = Math.floor((start + end) / 2);\n const cmp = compare(arr[mid]);\n if (cmp === 0) {\n return [mid, true];\n }\n if (cmp < 0) {\n end = mid - 1;\n } else {\n start = mid + 1;\n }\n }\n return [start, false];\n}\nvar QueueNode = class {\n value;\n next = null;\n prev = null;\n constructor(message) {\n this.value = message;\n }\n};\nvar Queue = class {\n first;\n last;\n constructor() {\n this.first = null;\n this.last = null;\n }\n enqueue(value) {\n const newNode = new QueueNode(value);\n if (!this.last) {\n this.first = newNode;\n this.last = newNode;\n } else if (this.last === this.first) {\n this.last = newNode;\n this.last.prev = this.first;\n this.first.next = newNode;\n } else {\n newNode.prev = this.last;\n this.last.next = newNode;\n this.last = newNode;\n }\n return true;\n }\n dequeue() {\n if (!this.first)\n return null;\n if (this.first === this.last) {\n const target2 = this.first;\n this.first = null;\n this.last = null;\n return target2.value;\n }\n const target = this.first;\n this.first = target.next;\n return target.value;\n }\n};\nexport {\n Queue,\n QueueNode,\n binarySearch,\n insertEventIntoAscendingList,\n insertEventIntoDescendingList,\n normalizeURL,\n utf8Decoder,\n utf8Encoder\n};\n","// SPDX-License-Identifier: MIT\n\nimport { SimplePool } from 'nostr-tools';\nimport { normalizeURL } from 'nostr-tools/utils';\n\n/**\n * Helper utilities for Nostr like operations using NIP-25 External Content Reactions.\n * These are deliberately kept self-contained so `nostr-like` Web Component can import\n * everything from a single module without polluting the rest of the codebase.\n */\n\nexport interface LikeDetails {\n authorPubkey: string;\n date: Date;\n content: string;\n}\n\nexport interface LikeCountResult {\n totalCount: number;\n likeDetails: LikeDetails[];\n likedCount: number;\n dislikedCount: number;\n}\n\n/**\n * Fetch all likes for a URL using NIP-25 kind 17 events\n */\nexport async function fetchLikesForUrl(\n url: string, \n relays: string[]\n): Promise<LikeCountResult> {\n // Normalize URL at the beginning for consistent comparison with tags\n const normalizedUrl = normalizeURL(url);\n \n const pool = new SimplePool();\n \n try {\n // Query kind 17 events (both likes and unlikes)\n const events = await pool.querySync(relays, {\n kinds: [17],\n '#k': ['web'],\n '#i': [normalizedUrl],\n limit: 1000\n });\n \n const likes: LikeDetails[] = [];\n let likedCount = 0;\n let dislikedCount = 0;\n \n for (const event of events) {\n likes.push({\n authorPubkey: event.pubkey,\n date: new Date(event.created_at * 1000),\n content: event.content\n });\n \n if (event.content === '-') {\n dislikedCount++;\n } else {\n likedCount++;\n }\n }\n \n likes.sort((a, b) => b.date.getTime() - a.date.getTime());\n \n const totalCount = likedCount - dislikedCount;\n \n return {\n totalCount: totalCount,\n likeDetails: likes,\n likedCount: likedCount,\n dislikedCount: dislikedCount\n };\n } catch (error) {\n // Rethrow error so callers can handle relay/network failures appropriately\n throw error instanceof Error ? error : new Error(String(error));\n } finally {\n pool.close(relays);\n }\n}\n\n/**\n * Create reaction event (kind 17)\n * @param url - URL to react to\n * @param content - '+' for like, '-' for unlike\n */\nexport function createReactionEvent(url: string, content: '+' | '-'): any {\n return {\n kind: 17,\n content,\n tags: [\n ['k', 'web'],\n ['i', url]\n ],\n created_at: Math.floor(Date.now() / 1000)\n };\n}\n\n/**\n * Create like event (kind 17)\n * @deprecated Use createReactionEvent(url, '+') instead\n */\nexport function createLikeEvent(url: string): any {\n return createReactionEvent(url, '+');\n}\n\n/**\n * Create unlike event (kind 17 with '-' content)\n * @deprecated Use createReactionEvent(url, '-') instead\n */\nexport function createUnlikeEvent(url: string): any {\n return createReactionEvent(url, '-');\n}\n\n/**\n * Check if user has liked a URL\n */\nexport async function hasUserLiked(\n url: string,\n userPubkey: string,\n relays: string[]\n): Promise<boolean> {\n const pool = new SimplePool();\n const normalizedUrl = url;\n \n try {\n // Get user's latest reaction for this URL\n const events = await pool.querySync(relays, {\n kinds: [17],\n authors: [userPubkey],\n '#k': ['web'],\n '#i': [normalizedUrl],\n limit: 1\n });\n \n if (events.length === 0) return false;\n \n // Check if latest reaction is a like (not an unlike)\n const latest = events[0];\n return latest.content === '+' || latest.content === '';\n } catch (error) {\n console.error(\"Nostr-Components: Like button: Error checking user like status\", error);\n return false;\n } finally {\n pool.close(relays);\n }\n}\n\n/**\n * Get user's pubkey from NIP-07 signer\n */\nexport async function getUserPubkey(): Promise<string | null> {\n try {\n if (typeof window !== 'undefined' && (window as any).nostr) {\n const nip07signer = (window as any).nostr;\n const user = await nip07signer.getPublicKey();\n return user;\n }\n } catch (error) {\n console.error(\"Nostr-Components: Like button: Error getting user pubkey\", error);\n }\n return null;\n}\n\n/**\n * Sign event with NIP-07\n */\nexport async function signEvent(event: any): Promise<any> {\n try {\n if (typeof window !== 'undefined' && (window as any).nostr) {\n const nip07signer = (window as any).nostr;\n const signedEvent = await nip07signer.signEvent(event);\n return signedEvent;\n }\n throw new Error('NIP-07 extension not available');\n } catch (error) {\n console.error(\"Nostr-Components: Like button: Error signing event\", error);\n throw error;\n }\n}\n\n/**\n * Check if NIP-07 extension is available\n */\nexport function isNip07Available(): boolean {\n return typeof window !== 'undefined' && !!(window as any).nostr;\n}\n","// SPDX-License-Identifier: MIT\n\nimport { NostrBaseComponent } from '../base/base-component/nostr-base-component';\nimport { NCStatus } from '../base/base-component/nostr-base-component';\nimport { NDKEvent } from '@nostr-dev-kit/ndk';\nimport { renderLikeButton, RenderLikeButtonOptions } from './render';\nimport { getLikeButtonStyles } from './style';\nimport { showHelpDialog } from './dialog-help';\nimport { isValidUrl } from '../common/utils';\nimport { \n fetchLikesForUrl, \n createLikeEvent,\n createUnlikeEvent,\n hasUserLiked, \n getUserPubkey, \n signEvent, \n isNip07Available,\n LikeCountResult \n} from './like-utils';\nimport { normalizeURL } from 'nostr-tools/utils';\n\n/**\n * <nostr-like>\n * Attributes:\n * - url (optional) : URL to like (default: current page URL)\n * - text (optional) : custom text (default \"Like\") (Max 32 characters)\n * - relays (optional) : comma-separated relay URLs\n * - data-theme (optional) : \"light\" | \"dark\" (default light)\n * \n * Features:\n * - URL-based likes using NIP-25 kind 17 events\n * - Click count to view likers\n */\nexport default class NostrLike extends NostrBaseComponent {\n protected likeActionStatus = this.channel('likeAction');\n protected likeListStatus = this.channel('likeList');\n \n private currentUrl: string = '';\n private isLiked: boolean = false;\n private likeCount: number = 0;\n private cachedLikeDetails: LikeCountResult | null = null;\n private loadSeq = 0;\n\n constructor() {\n super();\n }\n\n connectedCallback() {\n super.connectedCallback?.();\n if (this.likeListStatus.get() === NCStatus.Idle) {\n this.initChannelStatus('likeList', NCStatus.Loading, { reflectOverall: false });\n }\n this.attachDelegatedListeners();\n this.render();\n }\n\n static get observedAttributes() {\n return [\n ...super.observedAttributes,\n 'url',\n 'text'\n ];\n }\n\n attributeChangedCallback(\n name: string,\n oldValue: string | null,\n newValue: string | null\n ) {\n if (oldValue === newValue) return;\n super.attributeChangedCallback(name, oldValue, newValue);\n \n if (name === 'url' || name === 'text') {\n this.likeActionStatus.set(NCStatus.Ready);\n this.likeListStatus.set(NCStatus.Loading);\n this.isLiked = false;\n this.errorMessage = '';\n this.updateLikeCount();\n this.render();\n }\n }\n\n /** Base class functions */\n protected validateInputs(): boolean {\n if (!super.validateInputs()) {\n this.likeActionStatus.set(NCStatus.Idle);\n this.likeListStatus.set(NCStatus.Idle);\n return false;\n }\n\n const urlAttr = this.getAttribute('url');\n const textAttr = this.getAttribute('text');\n const tagName = this.tagName.toLowerCase();\n\n let errorMessage: string | null = null;\n\n if (urlAttr) {\n if (!isValidUrl(urlAttr)) {\n errorMessage = 'Invalid URL format';\n }\n }\n\n if (textAttr && textAttr.length > 32) {\n errorMessage = 'Max text length: 32 characters';\n }\n\n if (errorMessage) {\n this.likeActionStatus.set(NCStatus.Error, errorMessage);\n this.likeListStatus.set(NCStatus.Error, errorMessage);\n console.error(`Nostr-Components: ${tagName}: ${errorMessage}`);\n return false;\n }\n\n return true;\n }\n\n protected onStatusChange(_status: NCStatus) {\n this.render();\n }\n\n protected onNostrRelaysConnected() {\n this.updateLikeCount();\n this.render();\n }\n\n /** Private functions */\n /**\n * Lazy initializer for currentUrl - ensures it's set before like/unlike operations\n */\n private ensureCurrentUrl(): void {\n if (!this.currentUrl) {\n this.currentUrl = normalizeURL(this.getAttribute('url') || window.location.href);\n }\n }\n\n private async updateLikeCount() {\n const seq = ++this.loadSeq;\n try {\n await this.ensureNostrConnected();\n this.currentUrl = normalizeURL(this.getAttribute('url') || window.location.href);\n this.likeListStatus.set(NCStatus.Loading);\n this.render();\n \n const result = await fetchLikesForUrl(this.currentUrl, this.getRelays());\n if (seq !== this.loadSeq) return; // stale\n this.likeCount = result.totalCount;\n this.cachedLikeDetails = result;\n this.likeListStatus.set(NCStatus.Ready);\n } catch (error) {\n console.error('[NostrLike] Failed to fetch like count:', error);\n this.likeListStatus.set(NCStatus.Error, 'Failed to load likes');\n } finally {\n this.render();\n }\n }\n\n // TODO: Do onboarding logic here\n private async handleLikeClick() {\n // Ensure currentUrl is set before proceeding\n this.ensureCurrentUrl();\n \n if (!this.currentUrl) {\n this.likeActionStatus.set(NCStatus.Error, 'Invalid URL');\n this.render();\n return;\n }\n\n this.likeActionStatus.set(NCStatus.Loading);\n if (!isNip07Available()) {\n this.likeActionStatus.set(NCStatus.Error, \n 'Please install a Nostr browser extension (Alby, nos2x, etc.)'\n );\n this.render();\n return;\n }\n\n // Check user like status\n try {\n const userPubkey = await getUserPubkey();\n if (userPubkey) {\n this.isLiked = await hasUserLiked(this.currentUrl, userPubkey, this.getRelays());\n }\n } catch (error) {\n console.error('[NostrLike] Failed to check user like status:', error);\n this.likeActionStatus.set(NCStatus.Error, 'Failed to check user like status');\n } finally {\n this.render();\n }\n\n // If already liked, show confirmation dialog\n if (this.isLiked) {\n const confirmed = window.confirm('You have already liked this. Do you want to unlike it?');\n if (!confirmed) {\n this.likeActionStatus.set(NCStatus.Ready);\n this.render();\n return;\n }\n \n // Proceed with unlike\n await this.handleUnlike();\n } else {\n // Proceed with like\n await this.handleLike();\n }\n }\n\n private async handleLike() {\n // Ensure currentUrl is set before proceeding\n this.ensureCurrentUrl();\n \n if (!this.currentUrl) {\n this.likeActionStatus.set(NCStatus.Error, 'Invalid URL');\n this.render();\n return;\n }\n\n this.likeActionStatus.set(NCStatus.Loading);\n this.render();\n\n try {\n // Create like event\n const event = createLikeEvent(this.currentUrl);\n \n // Sign with NIP-07\n const signedEvent = await signEvent(event);\n \n // Create NDKEvent and publish\n const ndkEvent = new NDKEvent(this.nostrService.getNDK(), signedEvent);\n await ndkEvent.publish();\n \n // Update state optimistically\n this.isLiked = true;\n this.likeCount++;\n this.likeActionStatus.set(NCStatus.Ready);\n \n // Refresh like count to get accurate data\n await this.updateLikeCount();\n } catch (error) {\n console.error('[NostrLike] Failed to like:', error);\n \n // Rollback optimistic update\n this.isLiked = false;\n this.likeCount--;\n \n const errorMessage = error instanceof Error ? error.message : 'Failed to like';\n this.likeActionStatus.set(NCStatus.Error, errorMessage);\n } finally {\n this.render();\n }\n }\n\n private async handleUnlike() {\n // Ensure currentUrl is set before proceeding\n this.ensureCurrentUrl();\n \n if (!this.currentUrl) {\n this.likeActionStatus.set(NCStatus.Error, 'Invalid URL');\n this.render();\n return;\n }\n\n this.likeActionStatus.set(NCStatus.Loading);\n this.render();\n \n try {\n // Create unlike event\n const event = createUnlikeEvent(this.currentUrl);\n \n // Sign with NIP-07\n const signedEvent = await signEvent(event);\n \n // Create NDKEvent and publish\n const ndkEvent = new NDKEvent(this.nostrService.getNDK(), signedEvent);\n await ndkEvent.publish();\n \n // Update state optimistically\n this.isLiked = false;\n if (this.likeCount > 0) {\n this.likeCount--;\n }\n this.likeActionStatus.set(NCStatus.Ready);\n \n // Refresh like count to get accurate data\n await this.updateLikeCount();\n } catch (error) {\n console.error('[NostrLike] Failed to unlike:', error);\n \n // Rollback optimistic update\n this.isLiked = true;\n this.likeCount++;\n \n const errorMessage = error instanceof Error ? error.message : 'Failed to unlike';\n this.likeActionStatus.set(NCStatus.Error, errorMessage);\n } finally {\n this.render();\n }\n }\n\n private async handleCountClick() {\n if (this.likeCount === 0 || !this.cachedLikeDetails) {\n return;\n }\n\n try {\n // Import dialog dynamically to avoid circular dependencies\n const { openLikersDialog } = await import('./dialog-likers');\n await openLikersDialog({\n likeDetails: this.cachedLikeDetails.likeDetails,\n theme: this.theme === 'dark' ? 'dark' : 'light',\n });\n } catch (error) {\n console.error('[NostrLike] Error opening likers dialog:', error);\n }\n }\n\n private async handleHelpClick() {\n try {\n await showHelpDialog(this.theme === 'dark' ? 'dark' : 'light');\n } catch (error) {\n console.error('[NostrLike] Error showing help dialog:', error);\n }\n }\n\n private attachDelegatedListeners() {\n this.delegateEvent('click', '.nostr-like-button', (e) => {\n e.preventDefault?.();\n e.stopPropagation?.();\n void this.handleLikeClick();\n });\n\n this.delegateEvent('click', '.like-count', (e) => {\n e.preventDefault?.();\n e.stopPropagation?.();\n void this.handleCountClick();\n });\n\n this.delegateEvent('click', '.help-icon', (e) => {\n e.preventDefault?.();\n e.stopPropagation?.();\n this.handleHelpClick();\n });\n }\n\n protected renderContent() {\n // console.log(`Like: Render: conn: ${this.conn.get()}, likeActionStatus: ${this.likeActionStatus.get()}, likeListStatus: ${this.likeListStatus.get()}`);\n const isLoading = this.likeActionStatus.get() === NCStatus.Loading || this.conn.get() === NCStatus.Loading;\n const isCountLoading = this.likeListStatus.get() === NCStatus.Loading;\n const isError = this.computeOverall() === NCStatus.Error;\n const errorMessage = this.errorMessage;\n const buttonText = this.getAttribute('text') || 'Like';\n\n const renderOptions: RenderLikeButtonOptions = {\n isLoading,\n isError,\n errorMessage,\n buttonText,\n isLiked: this.isLiked,\n likeCount: this.likeCount,\n hasLikes: this.likeCount > 0,\n isCountLoading,\n theme: this.theme as 'light' | 'dark',\n };\n\n this.shadowRoot!.innerHTML = `\n ${getLikeButtonStyles()}\n ${renderLikeButton(renderOptions)}\n `;\n }\n}\n\ncustomElements.define('nostr-like', NostrLike);\n"],"file":"components/nostr-like.es.js"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{m as v,e as s,g as m,a as d,p as b}from"../assets/base-styles-CBypR3FR.js";import{N as y}from"../assets/nostr-user-component-
|
|
1
|
+
import{m as v,e as s,g as m,a as d,p as b}from"../assets/base-styles-CBypR3FR.js";import{N as y}from"../assets/nostr-user-component-BOdux8_6.js";import{h as w}from"../assets/nostr-service-pr_crY62.js";import{r as x,a as C,b as E,c as N}from"../assets/copy-delegation-C4uvRTVM.js";import"../assets/user-resolver-C-E6KdwY.js";function A({isLoading:n,isError:r,errorMessage:o,userProfile:e,ndkUser:t,showNpub:a,showFollow:c}){if(n)return L();if(r||e==null)return S(o||"");const i=e.displayName||e.name||v((t==null?void 0:t.npub)||""),p=s(i),f=s(e.picture||w),g=(t==null?void 0:t.npub)||"",h=(e==null?void 0:e.nip05)||"",u=s((t==null?void 0:t.pubkey)||"");return l(`<img src='${f}' alt='Nostr profile image of ${p}' loading="lazy" decoding="async"/>`,`${x({name:i})}
|
|
2
2
|
${e.nip05?C(h):""}
|
|
3
3
|
${a===!0?E(g||""):""}
|
|
4
4
|
${c===!0&&(t!=null&&t.pubkey)?`<nostr-follow-button pubkey="${u}"></nostr-follow-button>`:""}`)}function L(){return l('<div class="skeleton img-skeleton"></div>',`<div class="skeleton" style="width: 120px;"></div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var S=Object.defineProperty;var L=(e,o,t)=>o in e?S(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t;var n=(e,o,t)=>L(e,typeof o!="symbol"?o+"":o,t);import{e as k,g as $,a as p}from"../assets/base-styles-CBypR3FR.js";import{N as z}from"../assets/nostr-user-component-
|
|
1
|
+
var S=Object.defineProperty;var L=(e,o,t)=>o in e?S(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t;var n=(e,o,t)=>L(e,typeof o!="symbol"?o+"":o,t);import{e as k,g as $,a as p}from"../assets/base-styles-CBypR3FR.js";import{N as z}from"../assets/nostr-user-component-BOdux8_6.js";import{r as F,a as C,b as E,d as N,c as A}from"../assets/copy-delegation-C4uvRTVM.js";import"../assets/nostr-service-pr_crY62.js";import"../assets/user-resolver-C-E6KdwY.js";function l(e,o,t){const s=k(e);return`
|
|
2
2
|
<div class="stat" data-orientation="horizontal" aria-busy="${t}" aria-live="polite">
|
|
3
3
|
<div class="stat-inner">
|
|
4
4
|
<div class="stat-value">
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/zap-utils-B1sz0Abx.js","assets/nostr-service-pr_crY62.js","assets/utils--bxLbhGF.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
var Yt=Object.defineProperty;var Jt=(e,t,n)=>t in e?Yt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var _=(e,t,n)=>Jt(e,typeof t!="symbol"?t+"":t,n);import{N as Gt}from"../assets/nostr-user-component-
|
|
2
|
+
var Yt=Object.defineProperty;var Jt=(e,t,n)=>t in e?Yt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var _=(e,t,n)=>Jt(e,typeof t!="symbol"?t+"":t,n);import{N as Gt}from"../assets/nostr-user-component-BOdux8_6.js";import{n as Qt,g as St,h as G,e as X,f as kt,c as At,a as N}from"../assets/base-styles-CBypR3FR.js";import"../assets/dialog-component-Dqg0QU9I.js";import{getProfileMetadata as Wt,getZapEndpoint as Xt,fetchInvoice as te,listenForZapReceipt as ee,getBatchedProfileMetadata as ne,extractProfileMetadataContent as Nt,fetchTotalZapAmount as oe}from"../assets/zap-utils-B1sz0Abx.js";import{_ as re}from"../assets/preload-helper-D7HrI6pR.js";import{i as ae}from"../assets/utils--bxLbhGF.js";import"../assets/user-resolver-C-E6KdwY.js";import"../assets/nostr-service-pr_crY62.js";const ie=(e="light")=>{const t=e==="dark";return`
|
|
3
3
|
/* === ZAP DIALOG CONTENT STYLES === */
|
|
4
4
|
.zap-dialog-content {
|
|
5
5
|
text-align: center;
|
|
@@ -687,7 +687,7 @@ Minimum version required to store current data is: `+a+`.
|
|
|
687
687
|
max-width: 250px;
|
|
688
688
|
white-space: pre-line;
|
|
689
689
|
}
|
|
690
|
-
`)}class hn extends Gt{constructor(){super();_(this,"zapActionStatus",this.channel("zapAction"));_(this,"zapListStatus",this.channel("zapList"));_(this,"totalZapAmount",null);_(this,"cachedZapDetails",[]);_(this,"cachedAmountDialog",null)
|
|
690
|
+
`)}class hn extends Gt{constructor(){super();_(this,"zapActionStatus",this.channel("zapAction"));_(this,"zapListStatus",this.channel("zapList"));_(this,"totalZapAmount",null);_(this,"cachedZapDetails",[]);_(this,"cachedAmountDialog",null)}connectedCallback(){var n;(n=super.connectedCallback)==null||n.call(this),this.zapListStatus.get()==N.Idle&&this.initChannelStatus("zapList",N.Loading,{reflectOverall:!1}),this.attachDelegatedListeners(),this.render()}static get observedAttributes(){return[...super.observedAttributes,"text","amount","default-amount","url"]}attributeChangedCallback(n,o,r){o!==r&&(super.attributeChangedCallback(n,o,r),this.render())}disconnectedCallback(){this.cachedAmountDialog&&typeof this.cachedAmountDialog.close=="function"&&this.cachedAmountDialog.close()}onStatusChange(n){this.render()}onUserReady(n,o){this.render(),this.updateZapCount()}validateInputs(){if(!super.validateInputs())return this.zapActionStatus.set(N.Idle),this.zapListStatus.set(N.Idle),!1;const n=this.getAttribute("text"),o=this.getAttribute("amount"),r=this.getAttribute("default-amount"),a=this.getAttribute("url"),s=this.tagName.toLowerCase();let i=null;if(n&&n.length>128)i="Max text length: 128 characters";else if(o){const c=Number(o);isNaN(c)||c<=0?i="Invalid amount":c>21e4&&(i="Amount too high (max 210,000 sats)")}else if(r){const c=Number(r);isNaN(c)||c<=0?i="Invalid default-amount":c>21e4&&(i="Default-amount too high (max 210,000 sats)")}else a&&(At(a)||(i="Invalid URL format"));return i?(this.zapActionStatus.set(N.Error,i),this.zapListStatus.set(N.Error,i),this.userStatus.set(N.Idle),console.error(`Nostr-Components: ${s}: ${i}`),!1):!0}async handleZapClick(){if(this.userStatus.get()===N.Ready){this.zapActionStatus.set(N.Loading),this.render();try{if(!this.user){this.zapActionStatus.set(N.Error,"Could not resolve user to zap."),this.render();return}const n=this.getRelays().join(","),o=this.user.npub;this.cachedAmountDialog=await Ge({npub:o,relays:n,cachedDialogComponent:this.cachedAmountDialog,theme:this.theme==="dark"?"dark":"light",fixedAmount:(()=>{const r=this.getAttribute("amount");if(!r)return;const a=Number(r);if(isNaN(a)||a<=0||a>21e4){console.error("Nostr-Components: Zap button: Max zap amount: 210,000 sats");return}return a})(),defaultAmount:(()=>{const r=this.getAttribute("default-amount");if(!r)return 21;const a=Number(r);return isNaN(a)||a<=0||a>21e4?(console.error("Nostr-Components: Zap button: Max zap amount: 210,000 sats"),21):a})(),url:this.getAttribute("url")||void 0,anon:!1}),this.zapActionStatus.set(N.Ready)}catch(n){this.zapActionStatus.set(N.Error,(n==null?void 0:n.message)||"Unable to zap")}finally{this.render()}}}async handleHelpClick(){try{await en(this.theme==="dark"?"dark":"light")}catch(n){console.error("Error showing help dialog:",n)}}async handleZappersClick(){if(this.cachedZapDetails.length!==0)try{await an({zapDetails:this.cachedZapDetails,theme:this.theme==="dark"?"dark":"light"})}catch(n){console.error("Nostr-Components: Zap button: Error opening zappers dialog",n)}}attachDelegatedListeners(){this.delegateEvent("click",".nostr-zap-button",n=>{var o,r;(o=n.preventDefault)==null||o.call(n),(r=n.stopPropagation)==null||r.call(n),this.handleZapClick()}),this.delegateEvent("click",".help-icon",n=>{var o,r;(o=n.preventDefault)==null||o.call(n),(r=n.stopPropagation)==null||r.call(n),this.handleHelpClick()}),this.delegateEvent("click",".total-zap-amount",n=>{var o,r;(o=n.preventDefault)==null||o.call(n),(r=n.stopPropagation)==null||r.call(n),this.handleZappersClick()})}async updateZapCount(){if(this.user)try{this.zapListStatus.set(N.Loading),this.render(),await this.ensureNostrConnected();const n=await oe({pubkey:this.user.pubkey,relays:this.getRelays(),url:this.getAttribute("url")||void 0});this.totalZapAmount=n.totalAmount,this.cachedZapDetails=n.zapDetails,this.zapListStatus.set(N.Ready)}catch(n){console.error("Nostr-Components: Zap button: Failed to fetch zap count",n),this.totalZapAmount=null,this.zapListStatus.set(N.Error)}finally{this.render()}}renderContent(){const n=this.userStatus.get()==N.Loading,o=this.zapListStatus.get()==N.Loading,r=this.computeOverall()===N.Error,a=this.errorMessage,s=this.getAttribute("text")||"Zap",i={isLoading:n,isAmountLoading:o,isError:r,isSuccess:!1,errorMessage:a,buttonText:s,totalZapAmount:this.totalZapAmount,hasZaps:this.cachedZapDetails.length>0};this.shadowRoot.innerHTML=`
|
|
691
691
|
${gn()}
|
|
692
692
|
${un(i)}
|
|
693
693
|
`}}customElements.define("nostr-zap",hn);
|