nostr-components 0.2.0
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/LICENSE +21 -0
- package/README.md +334 -0
- package/dist/assets/base-styles-CBypR3FR.js +145 -0
- package/dist/assets/base-styles-CBypR3FR.js.map +1 -0
- package/dist/assets/copy-delegation-C4uvRTVM.js +15 -0
- package/dist/assets/copy-delegation-C4uvRTVM.js.map +1 -0
- package/dist/assets/dialog-component-Dqg0QU9I.js +66 -0
- package/dist/assets/dialog-component-Dqg0QU9I.js.map +1 -0
- package/dist/assets/dialog-likers-BzTesCZa.js +238 -0
- package/dist/assets/dialog-likers-BzTesCZa.js.map +1 -0
- package/dist/assets/icons-Dr_d9MII.js +105 -0
- package/dist/assets/icons-Dr_d9MII.js.map +1 -0
- package/dist/assets/nip05-utils-BNBHUmkr.js +2 -0
- package/dist/assets/nip05-utils-BNBHUmkr.js.map +1 -0
- package/dist/assets/nostr-service-pr_crY62.js +78 -0
- package/dist/assets/nostr-service-pr_crY62.js.map +1 -0
- package/dist/assets/nostr-user-component-Q7GeeFyu.js +2 -0
- package/dist/assets/nostr-user-component-Q7GeeFyu.js.map +1 -0
- package/dist/assets/preload-helper-D7HrI6pR.js +2 -0
- package/dist/assets/preload-helper-D7HrI6pR.js.map +1 -0
- package/dist/assets/pure-jrVhRVpB.js +2 -0
- package/dist/assets/pure-jrVhRVpB.js.map +1 -0
- package/dist/assets/theme-C1r1Zw8r.js +2 -0
- package/dist/assets/theme-C1r1Zw8r.js.map +1 -0
- package/dist/assets/user-resolver-C-E6KdwY.js +2 -0
- package/dist/assets/user-resolver-C-E6KdwY.js.map +1 -0
- package/dist/assets/utils--bxLbhGF.js +2 -0
- package/dist/assets/utils--bxLbhGF.js.map +1 -0
- package/dist/assets/zap-utils-B1sz0Abx.js +2 -0
- package/dist/assets/zap-utils-B1sz0Abx.js.map +1 -0
- package/dist/components/nostr-comment.es.js +924 -0
- package/dist/components/nostr-comment.es.js.map +1 -0
- package/dist/components/nostr-dm.es.js +217 -0
- package/dist/components/nostr-dm.es.js.map +1 -0
- package/dist/components/nostr-follow-button.es.js +103 -0
- package/dist/components/nostr-follow-button.es.js.map +1 -0
- package/dist/components/nostr-like.es.js +296 -0
- package/dist/components/nostr-like.es.js.map +1 -0
- package/dist/components/nostr-live-chat.es.js +523 -0
- package/dist/components/nostr-live-chat.es.js.map +1 -0
- package/dist/components/nostr-post.es.js +441 -0
- package/dist/components/nostr-post.es.js.map +1 -0
- package/dist/components/nostr-profile-badge.es.js +100 -0
- package/dist/components/nostr-profile-badge.es.js.map +1 -0
- package/dist/components/nostr-profile.es.js +287 -0
- package/dist/components/nostr-profile.es.js.map +1 -0
- package/dist/components/nostr-zap.es.js +694 -0
- package/dist/components/nostr-zap.es.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/nostr-comment.d.ts +4 -0
- package/dist/nostr-components.es.js +2 -0
- package/dist/nostr-components.es.js.map +1 -0
- package/dist/nostr-components.umd.js +4200 -0
- package/dist/nostr-components.umd.js.map +1 -0
- package/dist/nostr-dm.d.ts +4 -0
- package/dist/nostr-follow-button.d.ts +4 -0
- package/dist/nostr-like.d.ts +4 -0
- package/dist/nostr-live-chat.d.ts +4 -0
- package/dist/nostr-post.d.ts +4 -0
- package/dist/nostr-profile-badge.d.ts +4 -0
- package/dist/nostr-profile.d.ts +4 -0
- package/dist/nostr-zap.d.ts +4 -0
- package/dist/src/base/base-component/nostr-base-component.d.ts +116 -0
- package/dist/src/base/copy-delegation.d.ts +5 -0
- package/dist/src/base/dialog-component/dialog-component.d.ts +67 -0
- package/dist/src/base/dialog-component/style.d.ts +5 -0
- package/dist/src/base/event-component/nostr-event-component.d.ts +53 -0
- package/dist/src/base/render-options.d.ts +5 -0
- package/dist/src/base/resolvers/event-resolver.d.ts +20 -0
- package/dist/src/base/resolvers/user-resolver.d.ts +19 -0
- package/dist/src/base/text-row/render-name.d.ts +7 -0
- package/dist/src/base/text-row/render-nip05.d.ts +1 -0
- package/dist/src/base/text-row/render-npub.d.ts +1 -0
- package/dist/src/base/text-row/render-text-row.d.ts +9 -0
- package/dist/src/base/user-component/nostr-user-component.d.ts +43 -0
- package/dist/src/common/base-styles.d.ts +44 -0
- package/dist/src/common/constants.d.ts +4 -0
- package/dist/src/common/date-utils.d.ts +9 -0
- package/dist/src/common/icons.d.ts +7 -0
- package/dist/src/common/nip05-utils.d.ts +13 -0
- package/dist/src/common/nostr-service.d.ts +40 -0
- package/dist/src/common/theme.d.ts +4 -0
- package/dist/src/common/types.d.ts +1 -0
- package/dist/src/common/utils.d.ts +34 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/nostr-comment/nostr-comment.d.ts +60 -0
- package/dist/src/nostr-comment/render.d.ts +15 -0
- package/dist/src/nostr-comment/utils.d.ts +81 -0
- package/dist/src/nostr-dm/nostr-dm.d.ts +34 -0
- package/dist/src/nostr-dm/render.d.ts +15 -0
- package/dist/src/nostr-follow-button/nostr-follow-button.d.ts +24 -0
- package/dist/src/nostr-follow-button/render.d.ts +11 -0
- package/dist/src/nostr-follow-button/style.d.ts +1 -0
- package/dist/src/nostr-like/dialog-help-style.d.ts +1 -0
- package/dist/src/nostr-like/dialog-help.d.ts +2 -0
- package/dist/src/nostr-like/dialog-likers-style.d.ts +1 -0
- package/dist/src/nostr-like/dialog-likers.d.ts +24 -0
- package/dist/src/nostr-like/like-utils.d.ts +52 -0
- package/dist/src/nostr-like/nostr-like.d.ts +49 -0
- package/dist/src/nostr-like/render.d.ts +10 -0
- package/dist/src/nostr-like/style.d.ts +1 -0
- package/dist/src/nostr-live-chat/nostr-live-chat.d.ts +65 -0
- package/dist/src/nostr-live-chat/render.d.ts +31 -0
- package/dist/src/nostr-post/nostr-post.d.ts +25 -0
- package/dist/src/nostr-post/parse-text.d.ts +8 -0
- package/dist/src/nostr-post/render-content.d.ts +5 -0
- package/dist/src/nostr-post/render.d.ts +19 -0
- package/dist/src/nostr-post/style.d.ts +1 -0
- package/dist/src/nostr-profile/nostr-profile.d.ts +24 -0
- package/dist/src/nostr-profile/render-stats.d.ts +1 -0
- package/dist/src/nostr-profile/render.d.ts +22 -0
- package/dist/src/nostr-profile/style.d.ts +1 -0
- package/dist/src/nostr-profile-badge/nostr-profile-badge.d.ts +34 -0
- package/dist/src/nostr-profile-badge/render.d.ts +11 -0
- package/dist/src/nostr-profile-badge/style.d.ts +1 -0
- package/dist/src/nostr-zap/dialog-help-style.d.ts +5 -0
- package/dist/src/nostr-zap/dialog-help.d.ts +2 -0
- package/dist/src/nostr-zap/dialog-zap-style.d.ts +6 -0
- package/dist/src/nostr-zap/dialog-zap.d.ts +31 -0
- package/dist/src/nostr-zap/dialog-zappers-style.d.ts +1 -0
- package/dist/src/nostr-zap/dialog-zappers.d.ts +25 -0
- package/dist/src/nostr-zap/nostr-zap.d.ts +45 -0
- package/dist/src/nostr-zap/render.d.ts +9 -0
- package/dist/src/nostr-zap/style.d.ts +1 -0
- package/dist/src/nostr-zap/zap-utils.d.ts +53 -0
- package/dist/themes/dark.css +10 -0
- package/dist/themes/light.css +10 -0
- package/dist/themes.css +52 -0
- package/dist/vite.config.d.ts +2 -0
- package/dist/vite.config.esm.d.ts +2 -0
- package/dist/vite.config.umd.d.ts +2 -0
- package/package.json +95 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dialog-likers-BzTesCZa.js","assets/preload-helper-D7HrI6pR.js","assets/dialog-component-Dqg0QU9I.js","assets/zap-utils-B1sz0Abx.js","assets/nostr-service-pr_crY62.js","assets/utils--bxLbhGF.js","assets/base-styles-CBypR3FR.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
var m=Object.defineProperty;var w=(r,e,t)=>e in r?m(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var d=(r,e,t)=>w(r,typeof e!="symbol"?e+"":e,t);import{_ as y}from"../assets/preload-helper-D7HrI6pR.js";import{e as b,g as L,N as x,a as i,c as C}from"../assets/base-styles-CBypR3FR.js";import{S as f,e as g}from"../assets/nostr-service-pr_crY62.js";import"../assets/dialog-component-Dqg0QU9I.js";function S({isLoading:r,isError:e,errorMessage:t,buttonText:n,isLiked:o,likeCount:s,hasLikes:a=!1,isCountLoading:l=!1,theme:u="light"}){if(e)return E(t||"");const c=N(o,u),h=o?"<span>Liked</span>":`<span>${b(n)}</span>`;return U(c,h,s,a,o,r,l)}function E(r){return A('<div class="error-icon">⚠</div>',b(r))}function A(r,e){return`
|
|
3
|
+
<div class="nostr-like-button-container">
|
|
4
|
+
<div class="nostr-like-button-left-container">
|
|
5
|
+
${r}
|
|
6
|
+
</div>
|
|
7
|
+
<div class="nostr-like-button-right-container">
|
|
8
|
+
${e}
|
|
9
|
+
</div>
|
|
10
|
+
</div>
|
|
11
|
+
`}function U(r,e,t,n=!1,o=!1,s=!1,a=!1){let l="";return a?l='<span class="like-count skeleton"></span>':t>0&&(l=`<span class="like-count${n?" clickable":""}">${t} ${t===1?"like":"likes"}</span>`),`
|
|
12
|
+
<div class="nostr-like-button-container">
|
|
13
|
+
<button class="${o?"nostr-like-button liked":"nostr-like-button"}">
|
|
14
|
+
${r}
|
|
15
|
+
${s?'<span class="button-text-skeleton"></span>':e}
|
|
16
|
+
</button>
|
|
17
|
+
${l} <button class="help-icon" title="What is a like?">?</button>
|
|
18
|
+
</div>
|
|
19
|
+
`}function N(r,e="light"){const t=e==="dark"?"#8ab4f8":"#1877f2",n=e==="dark"?"#e0e7ff":"#0d46a1";return r?`<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 100 100" width="24" height="24">
|
|
20
|
+
<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="${t}"/>
|
|
21
|
+
<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="${t}"/>
|
|
22
|
+
</svg>`:`<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 100 100" width="24" height="24">
|
|
23
|
+
<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="${n}" stroke-width="2"/>
|
|
24
|
+
<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="${n}" stroke-width="2"/>
|
|
25
|
+
</svg>`}function z(){return L(`
|
|
26
|
+
/* === LIKE BUTTON CONTAINER PATTERN === */
|
|
27
|
+
:host {
|
|
28
|
+
/* Icon sizing (overridable via CSS variables) */
|
|
29
|
+
--nostrc-icon-height: 25px;
|
|
30
|
+
--nostrc-icon-width: 25px;
|
|
31
|
+
|
|
32
|
+
/* Like button CSS variables (overridable by parent components) */
|
|
33
|
+
--nostrc-like-btn-padding: var(--nostrc-spacing-sm) var(--nostrc-spacing-md);
|
|
34
|
+
--nostrc-like-btn-border-radius: var(--nostrc-border-radius-md);
|
|
35
|
+
--nostrc-like-btn-border: var(--nostrc-border-width) solid var(--nostrc-color-border);
|
|
36
|
+
--nostrc-like-btn-min-height: 47px;
|
|
37
|
+
--nostrc-like-btn-width: auto;
|
|
38
|
+
--nostrc-like-btn-horizontal-alignment: left;
|
|
39
|
+
--nostrc-like-btn-bg: var(--nostrc-theme-bg, #ffffff);
|
|
40
|
+
--nostrc-like-btn-color: var(--nostrc-theme-text-primary, #333333);
|
|
41
|
+
--nostrc-like-btn-font-family: var(--nostrc-font-family-primary);
|
|
42
|
+
--nostrc-like-btn-font-size: var(--nostrc-font-size-base);
|
|
43
|
+
|
|
44
|
+
/* Hover state variables */
|
|
45
|
+
--nostrc-like-btn-hover-bg: var(--nostrc-theme-hover-bg, rgba(0, 0, 0, 0.05));
|
|
46
|
+
--nostrc-like-btn-hover-color: var(--nostrc-theme-text-primary, #333333);
|
|
47
|
+
--nostrc-like-btn-hover-border: var(--nostrc-border-width) solid var(--nostrc-theme-border, var(--nostrc-color-border));
|
|
48
|
+
|
|
49
|
+
/* Liked state variables */
|
|
50
|
+
--nostrc-like-btn-liked-bg: #e7f3ff;
|
|
51
|
+
--nostrc-like-btn-liked-color: #1877f2;
|
|
52
|
+
--nostrc-like-btn-liked-border: #1877f2;
|
|
53
|
+
--nostrc-like-btn-liked-hover-bg: #d1e7ff;
|
|
54
|
+
|
|
55
|
+
/* Make the host a flex container for button + count */
|
|
56
|
+
display: inline-flex;
|
|
57
|
+
flex-direction: row;
|
|
58
|
+
align-items: center;
|
|
59
|
+
gap: var(--nostrc-spacing-md);
|
|
60
|
+
font-family: var(--nostrc-like-btn-font-family);
|
|
61
|
+
font-size: var(--nostrc-like-btn-font-size);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* Focus state for accessibility */
|
|
65
|
+
:host(:focus-visible) {
|
|
66
|
+
outline: 2px solid var(--nostrc-color-primary, #007bff);
|
|
67
|
+
outline-offset: 2px;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
:host(.is-error) .nostr-like-button-container {
|
|
71
|
+
border: var(--nostrc-border-width) solid var(--nostrc-color-error-text);
|
|
72
|
+
border-radius: var(--nostrc-border-radius-md);
|
|
73
|
+
padding: var(--nostrc-spacing-sm);
|
|
74
|
+
color: var(--nostrc-color-error-text);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.nostr-like-button-container {
|
|
78
|
+
display: flex;
|
|
79
|
+
align-items: center;
|
|
80
|
+
gap: var(--nostrc-spacing-md);
|
|
81
|
+
width: fit-content;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.nostr-like-button-left-container {
|
|
85
|
+
display: flex;
|
|
86
|
+
align-items: center;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.nostr-like-button-right-container {
|
|
90
|
+
display: flex;
|
|
91
|
+
align-items: center;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.nostr-like-button {
|
|
95
|
+
display: flex;
|
|
96
|
+
align-items: center;
|
|
97
|
+
justify-content: var(--nostrc-like-btn-horizontal-alignment);
|
|
98
|
+
gap: var(--nostrc-spacing-sm);
|
|
99
|
+
background: var(--nostrc-like-btn-bg);
|
|
100
|
+
color: var(--nostrc-like-btn-color);
|
|
101
|
+
border: var(--nostrc-like-btn-border);
|
|
102
|
+
border-radius: var(--nostrc-like-btn-border-radius);
|
|
103
|
+
padding: var(--nostrc-like-btn-padding);
|
|
104
|
+
min-height: var(--nostrc-like-btn-min-height);
|
|
105
|
+
width: var(--nostrc-like-btn-width);
|
|
106
|
+
cursor: pointer;
|
|
107
|
+
transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
|
|
108
|
+
font-family: inherit;
|
|
109
|
+
font-size: inherit;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/* Hover state on the button */
|
|
113
|
+
.nostr-like-button:hover {
|
|
114
|
+
background: var(--nostrc-like-btn-hover-bg);
|
|
115
|
+
color: var(--nostrc-like-btn-hover-color);
|
|
116
|
+
border: var(--nostrc-like-btn-hover-border);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* Liked state */
|
|
120
|
+
.nostr-like-button.liked {
|
|
121
|
+
background: var(--nostrc-like-btn-liked-bg);
|
|
122
|
+
color: var(--nostrc-like-btn-liked-color);
|
|
123
|
+
border: var(--nostrc-border-width) solid var(--nostrc-like-btn-liked-border);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.nostr-like-button.liked:hover {
|
|
127
|
+
background: var(--nostrc-like-btn-liked-hover-bg);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.nostr-like-button:disabled {
|
|
131
|
+
pointer-events: none;
|
|
132
|
+
user-select: none;
|
|
133
|
+
opacity: 0.6;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
:host:not([status="ready"]) .nostr-like-button {
|
|
137
|
+
cursor: not-allowed;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/* SVG Icon Styles */
|
|
141
|
+
.nostr-like-button svg {
|
|
142
|
+
display: inline-block;
|
|
143
|
+
vertical-align: middle;
|
|
144
|
+
width: var(--nostrc-icon-width);
|
|
145
|
+
height: var(--nostrc-icon-height);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* Like count display */
|
|
149
|
+
.like-count {
|
|
150
|
+
font-size: var(--nostrc-font-size-sm);
|
|
151
|
+
color: var(--nostrc-theme-text-secondary, #666666);
|
|
152
|
+
white-space: nowrap;
|
|
153
|
+
text-decoration: underline;
|
|
154
|
+
text-decoration-color: transparent;
|
|
155
|
+
transition: text-decoration-color 0.2s ease, color 0.2s ease;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/* Clickable like count */
|
|
159
|
+
.like-count.clickable {
|
|
160
|
+
cursor: pointer;
|
|
161
|
+
text-decoration-color: currentColor;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.like-count.clickable:hover {
|
|
165
|
+
color: var(--nostrc-color-primary, #7f00ff);
|
|
166
|
+
text-decoration-color: var(--nostrc-color-primary, #7f00ff);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/* Help icon */
|
|
170
|
+
.help-icon {
|
|
171
|
+
background: none;
|
|
172
|
+
border: 1px solid var(--nostrc-color-border, #e0e0e0);
|
|
173
|
+
border-radius: var(--nostrc-border-radius-full, 50%);
|
|
174
|
+
width: var(--nostrc-help-icon-size, 16px);
|
|
175
|
+
height: var(--nostrc-help-icon-size, 16px);
|
|
176
|
+
font-size: calc(var(--nostrc-help-icon-size, 16px) * 0.7);
|
|
177
|
+
font-weight: bold;
|
|
178
|
+
color: var(--nostrc-theme-text-secondary, #666666);
|
|
179
|
+
cursor: pointer;
|
|
180
|
+
display: inline-flex;
|
|
181
|
+
align-items: center;
|
|
182
|
+
justify-content: center;
|
|
183
|
+
margin-left: var(--nostrc-spacing-xs, 4px);
|
|
184
|
+
transition: all 0.2s ease;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.help-icon:hover {
|
|
188
|
+
background: var(--nostrc-color-hover-background, rgba(0, 0, 0, 0.05));
|
|
189
|
+
border-color: var(--nostrc-color-primary, #7f00ff);
|
|
190
|
+
color: var(--nostrc-color-primary, #7f00ff);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/* Skeleton loader for like count */
|
|
194
|
+
.like-count.skeleton {
|
|
195
|
+
background: linear-gradient(90deg,
|
|
196
|
+
var(--nostrc-skeleton-color-min) 25%,
|
|
197
|
+
var(--nostrc-skeleton-color-max) 50%,
|
|
198
|
+
var(--nostrc-skeleton-color-min) 75%
|
|
199
|
+
);
|
|
200
|
+
background-size: 200% 100%;
|
|
201
|
+
animation: skeleton-loading var(--nostrc-skeleton-duration) var(--nostrc-skeleton-timing-function) var(--nostrc-skeleton-iteration-count);
|
|
202
|
+
border-radius: var(--nostrc-border-radius-sm);
|
|
203
|
+
width: 80px;
|
|
204
|
+
height: 1.2em;
|
|
205
|
+
display: inline-block;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/* Skeleton loader for button text */
|
|
209
|
+
.button-text-skeleton {
|
|
210
|
+
background: linear-gradient(90deg,
|
|
211
|
+
var(--nostrc-skeleton-color-min) 25%,
|
|
212
|
+
var(--nostrc-skeleton-color-max) 50%,
|
|
213
|
+
var(--nostrc-skeleton-color-min) 75%
|
|
214
|
+
);
|
|
215
|
+
background-size: 200% 100%;
|
|
216
|
+
animation: skeleton-loading var(--nostrc-skeleton-duration) var(--nostrc-skeleton-timing-function) var(--nostrc-skeleton-iteration-count);
|
|
217
|
+
border-radius: var(--nostrc-border-radius-sm);
|
|
218
|
+
width: 60px;
|
|
219
|
+
height: 1em;
|
|
220
|
+
display: inline-block;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
@keyframes skeleton-loading {
|
|
224
|
+
0% {
|
|
225
|
+
background-position: 200% 0;
|
|
226
|
+
}
|
|
227
|
+
100% {
|
|
228
|
+
background-position: -200% 0;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/* Error message styling */
|
|
233
|
+
.nostr-like-button-error small {
|
|
234
|
+
color: var(--nostrc-color-error-text);
|
|
235
|
+
font-size: var(--nostrc-font-size-sm);
|
|
236
|
+
line-height: 1em;
|
|
237
|
+
max-width: 250px;
|
|
238
|
+
white-space: pre-line;
|
|
239
|
+
}
|
|
240
|
+
`)}function D(){return`
|
|
241
|
+
.help-content {
|
|
242
|
+
padding: var(--nostrc-spacing-md, 12px);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.help-content p {
|
|
246
|
+
margin: 0 0 var(--nostrc-spacing-md, 12px) 0;
|
|
247
|
+
color: var(--nostrc-theme-text-primary, #333333);
|
|
248
|
+
line-height: 1.5;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
.help-content p:last-child {
|
|
252
|
+
margin-bottom: 0;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
.help-content ul {
|
|
256
|
+
margin: 0 0 var(--nostrc-spacing-md, 12px) 0;
|
|
257
|
+
padding-left: var(--nostrc-spacing-lg, 16px);
|
|
258
|
+
color: var(--nostrc-theme-text-primary, #333333);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.help-content li {
|
|
262
|
+
margin-bottom: var(--nostrc-spacing-xs, 4px);
|
|
263
|
+
line-height: 1.5;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.help-content li:last-child {
|
|
267
|
+
margin-bottom: 0;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.help-content strong {
|
|
271
|
+
font-weight: 600;
|
|
272
|
+
color: var(--nostrc-theme-text-primary, #333333);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
.help-content a {
|
|
276
|
+
color: var(--nostrc-theme-primary, #0066cc);
|
|
277
|
+
text-decoration: underline;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
.help-content a:hover {
|
|
281
|
+
color: var(--nostrc-theme-primary-hover, #0052a3);
|
|
282
|
+
}
|
|
283
|
+
`}const R=()=>{if(document.querySelector("style[data-help-dialog-styles]"))return;const r=document.createElement("style");r.setAttribute("data-help-dialog-styles","true"),r.textContent=D(),document.head.appendChild(r)},$=async r=>{R(),customElements.get("dialog-component")||await customElements.whenDefined("dialog-component");const e=document.createElement("dialog-component");e.setAttribute("header","What is a Like?"),r&&e.setAttribute("data-theme",r),e.innerHTML=`
|
|
284
|
+
<div class="help-content">
|
|
285
|
+
<p>Like any webpage to show your appreciation! Your likes are stored on Nostr, a decentralized network you control—no accounts needed.</p>
|
|
286
|
+
<ul>
|
|
287
|
+
<li>Like any webpage or article</li>
|
|
288
|
+
<li>See who liked the content</li>
|
|
289
|
+
<li>Works with a browser extension like <a href="https://getalby.com" target="_blank" rel="noopener noreferrer">Alby</a> or nos2x</li>
|
|
290
|
+
</ul>
|
|
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 M(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 I(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);this.likeListStatus.set(i.Loading)}connectedCallback(){var t;(t=super.connectedCallback)==null||t.call(this),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 M(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=I(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
|
+
${z()}
|
|
294
|
+
${S(l)}
|
|
295
|
+
`}}customElements.define("nostr-like",F);
|
|
296
|
+
//# sourceMappingURL=nostr-like.es.js.map
|
|
@@ -0,0 +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,EAAi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AGM,0BAA2B,CACjC,KAAK,cAAc,QAAS,qBAAuB8B,GAAM,UACvDf,EAAAe,EAAE,iBAAF,MAAAf,EAAA,KAAAe,IACAC,EAAAD,EAAE,kBAAF,MAAAC,EAAA,KAAAD,GACK,KAAK,gBAAgB,EAC3B,EAED,KAAK,cAAc,QAAS,cAAgBA,GAAM,UAChDf,EAAAe,EAAE,iBAAF,MAAAf,EAAA,KAAAe,IACAC,EAAAD,EAAE,kBAAF,MAAAC,EAAA,KAAAD,GACK,KAAK,iBAAiB,EAC5B,EAED,KAAK,cAAc,QAAS,aAAeA,GAAM,UAC/Cf,EAAAe,EAAE,iBAAF,MAAAf,EAAA,KAAAe,IACAC,EAAAD,EAAE,kBAAF,MAAAC,EAAA,KAAAD,GACA,KAAK,gBAAgB,EACtB,EAGO,eAAgB,CAElB,MAAAzE,EAAY,KAAK,iBAAiB,IAAI,IAAMyD,EAAS,SAAW,KAAK,KAAK,IAAI,IAAMA,EAAS,QAC7FlD,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"}
|