pleasenobugs 0.3.0 → 0.5.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.
Files changed (40) hide show
  1. package/README.md +85 -53
  2. package/dist/chunks/client-C6NaBcR4.js +363 -0
  3. package/dist/chunks/demo-pEOxDlaa.js +240 -0
  4. package/dist/chunks/index-DNGYeoDU.js +3179 -0
  5. package/dist/client.js +7 -326
  6. package/dist/index.js +6 -6
  7. package/dist/pleasenobugs.iife.js +2 -2
  8. package/dist/types/client.d.ts +13 -3
  9. package/dist/types/client.d.ts.map +1 -1
  10. package/dist/types/demo.d.ts +4 -2
  11. package/dist/types/demo.d.ts.map +1 -1
  12. package/dist/types/element.d.ts +12 -6
  13. package/dist/types/element.d.ts.map +1 -1
  14. package/dist/types/i18n.d.ts +41 -6
  15. package/dist/types/i18n.d.ts.map +1 -1
  16. package/dist/types/index.d.ts +3 -3
  17. package/dist/types/index.d.ts.map +1 -1
  18. package/dist/types/prefs.d.ts +10 -0
  19. package/dist/types/prefs.d.ts.map +1 -0
  20. package/dist/types/readonly.d.ts +3 -2
  21. package/dist/types/readonly.d.ts.map +1 -1
  22. package/dist/types/signer.d.ts +7 -0
  23. package/dist/types/signer.d.ts.map +1 -1
  24. package/dist/types/ui/App.d.ts +7 -2
  25. package/dist/types/ui/App.d.ts.map +1 -1
  26. package/dist/types/ui/Compose.d.ts +7 -9
  27. package/dist/types/ui/Compose.d.ts.map +1 -1
  28. package/dist/types/ui/Face.d.ts +17 -0
  29. package/dist/types/ui/Face.d.ts.map +1 -0
  30. package/dist/types/ui/PostCard.d.ts +6 -3
  31. package/dist/types/ui/PostCard.d.ts.map +1 -1
  32. package/dist/types/ui/Settings.d.ts +38 -0
  33. package/dist/types/ui/Settings.d.ts.map +1 -0
  34. package/dist/types/ui/Sheets.d.ts +49 -7
  35. package/dist/types/ui/Sheets.d.ts.map +1 -1
  36. package/dist/types/ui/icons.d.ts +11 -0
  37. package/dist/types/ui/icons.d.ts.map +1 -1
  38. package/package.json +3 -3
  39. package/dist/chunks/demo-CL3oK-zC.js +0 -212
  40. package/dist/chunks/index--SJW3aE-.js +0 -2749
package/README.md CHANGED
@@ -22,9 +22,12 @@ wallet by itself; everywhere else it reads, and your app can hand it a signer.
22
22
  Each opens on the tiles (bug, idea, review), with the board one tap under
23
23
  them. `start="board"` opens on the board instead.
24
24
 
25
- `floating` and `overlay` cover the whole screen on a phone. From 640 pixels
26
- wide they are a panel in the bottom-right corner instead, 375 wide and up to
27
- 640 tall, over a dimmed page; a click beside it or Escape closes it.
25
+ `floating` and `overlay` are a sheet from the bottom on a phone: nearly the
26
+ whole screen, with a strip of your app still in view above it, dimmed
27
+ (`--pnb-sheet-top`). A tap on that strip, a swipe down on the sheet's top or
28
+ its X closes it. From 640 pixels wide they are a panel in the bottom-right
29
+ corner instead, 375 wide and up to 640 tall, over a dimmed page; a click
30
+ beside it or Escape closes it.
28
31
 
29
32
  From a button of your own:
30
33
 
@@ -39,16 +42,17 @@ menuItem.onclick = () => open({ project: 'YOUR_PROJECT_ID', server: 'https://YOU
39
42
  |---|---|
40
43
  | `project`, `server` | Required. |
41
44
  | `mode` | `inline`, `floating` or `overlay`. |
42
- | `start` | `tiles` (default) or `board`: what opens first. A `readonly` board is always the board. |
43
- | `theme` | `nimiq` (default): the Nimiq Foundation's 2026 brand, navy on white with a gold round button. `nimiq-dark`: the same on navy. |
45
+ | `start` | `tiles` (default) or `board`: what opens first. A `readonly` board is always the board, and so is the board for somebody not signed in outside Nimiq Pay: they read first, and **Send feedback** (or a vote) asks them to sign in, in a sheet, before the tiles. |
46
+ | `theme` | `light` (default): minimal, white with near-black words and buttons. `dark`: the same on near-black. `pleasenobugs`: dark purple with raised turquoise buttons. `nimiq`: the Nimiq Foundation's 2026 brand, navy on white with a gold round button. `nimiq-dark`: the same on navy. |
44
47
  | `lang` | The language of your `strings`, so dates follow it: `nl` writes "14 sep". English by default. |
45
- | `app-name` | What answers are signed with ("Shitti says"). Defaults to the project's name. |
46
- | `name` | A display name you already know, offered when the user chooses to show theirs. |
48
+ | `app-name` | What answers are signed with ("My app says"). Defaults to the project's name. |
49
+ | `name` | A display name you already know, filled in when a user who has not chosen one on this board is asked for one on their first post. |
50
+ | `logo` | The image before the board's title. PleaseNoBugs' own little bug when absent; a URL for your app's own logo (about 22px high is how it shows); `none` for no logo. |
47
51
  | `kinds` | Which kinds to offer, of the ones your project takes: `bug,idea,review` by default. `kinds="bug,idea"` leaves reviews off the tiles and out of the list. |
48
52
  | `screenshots` | Who sees screenshots on bugs and ideas. On the board for everyone by default, each one only after its author ticks that everyone may see it. `owners` keeps them for your eyes only; `off` leaves the "Add a screenshot" button out. An unknown value counts as `owners`. The project's own rule (`PNB_PROJECT_SCREENSHOTS` on the server) wins when it is stricter. |
49
- | `names` | `off` leaves out "Show my name", so every post is anonymous. For a board on a public page. |
50
- | `readonly` | The board to read and scroll through, nothing else: no **+**, no votes (the count still shows), no "Sign in", and it never asks a wallet or sends a proof, not even inside Nimiq Pay. Every post shows as anonymous and without its screenshot, whatever its author chose, because a read-only board is usually shown somewhere other than the app its authors wrote for. |
51
- | `demo` | A board of sample posts in the page's memory, with no server: `<please-no-bugs demo>`. Voting and writing work, nothing is sent or stored, and a reload starts over. For trying the widget, or showing it off. `demo="owner"` is the same board as its owner sees it: answer, set a status and "Fixed in", write updates. |
53
+ | `names` | `off` leaves the name and "Post anonymously" out of Settings and never asks for a name: every post is anonymous, with no name and no identicon. |
54
+ | `readonly` | The board to read and scroll through, nothing else: no **Send feedback**, no votes (the count still shows), no "Sign in", and it never asks a wallet or sends a proof, not even inside Nimiq Pay. Every post shows as anonymous and without its screenshot, whatever its author chose, because a read-only board is usually shown somewhere other than the app its authors wrote for. |
55
+ | `demo` | A board of sample posts in the page's memory, with no server: `<please-no-bugs demo>`. Voting and writing work, nothing is sent or stored, and a reload starts over. For trying the widget, or showing it off. `demo="owner"` is the same board as its owner sees it: answer, set a status and "Fixed in", write updates. With a `server`, a demo still keeps its posts in the page and asks that server only for the identicons. |
52
56
  | `screen` | With `demo` only: hold one screen in view, `button`, `tiles`, `board`, `write`, `sent` or `updates`. What the website's Make it yours uses to show each part. |
53
57
 
54
58
  | Property | |
@@ -64,11 +68,22 @@ Events: `pleasenobugs:posted` (`detail: { id, kind }`) and `pleasenobugs:close`.
64
68
 
65
69
  ## What your users see
66
70
 
67
- Tapping **+** opens three tiles: **Report a bug**, **Share an idea** and
71
+ Tapping **Send feedback**, at the foot of the board, opens three tiles: **Report a bug**, **Share an idea** and
68
72
  **Write a review**. A review is one to five stars and a few words, shown on the
69
73
  board with the average on top, so people can see what others like about your
70
74
  app. One review per wallet.
71
75
 
76
+ A post goes out with **the user's wallet identicon and a name**, never their
77
+ whole address. The name is asked for once, as their first post goes up, and
78
+ changed any time in **Settings**, behind their identicon in the top right;
79
+ changing it changes it on their earlier posts too. Without a name, others see
80
+ the address cut short (`NQ12 … AB34`). **"Post anonymously"**, also in
81
+ Settings, leaves name and identicon off every post. Outside Nimiq Pay,
82
+ Settings also has **Log out**. Top or Newest is chosen in the **Filter**
83
+ panel, with the kind and the status. The identicon is
84
+ drawn by your PleaseNoBugs server (`/v1/identicons/…`), like screenshots, so
85
+ the page needs that server in its `img-src`.
86
+
72
87
  A bug or an idea can carry **a screenshot, shown on the board** under the
73
88
  post, so everybody can see what is meant. Before picking one the user reads
74
89
  that everyone will see it and should check it for a balance, an address or a
@@ -118,32 +133,33 @@ authors get the note. Until you write the first one, only you see the button.
118
133
 
119
134
  The widget lives in a shadow root, so your CSS cannot break it. These custom
120
135
  properties cross that boundary on purpose and are the theming API. The
121
- defaults below are the `nimiq` look; `nimiq-dark` sets the colours again on
122
- navy:
136
+ defaults below are the `light` look; `dark`, `pleasenobugs`, `nimiq` and
137
+ `nimiq-dark` set the colours again:
123
138
 
124
139
  ```css
125
140
  please-no-bugs {
126
- --pnb-bg: #ffffff; /* the page */
127
- --pnb-surface: #fafaf8; /* a card */
128
- --pnb-surface-2: #f2f3f4; /* a chip or field inside a card */
129
- --pnb-sunken: #f2f3f4; /* the Top/New trough */
130
- --pnb-line: #e6e6e9;
131
- --pnb-text: #040724;
132
- --pnb-text-quiet: #686a7c;
133
- --pnb-accent: #040724;
134
- --pnb-on-accent: #ffffff;
135
- --pnb-danger: #cb0015;
136
- --pnb-bug: #cb0015; --pnb-idea: #ffb700; --pnb-review: #4f5166;
137
- --pnb-planned: #ffc758; --pnb-done: #040724; --pnb-declined: #9b9ca7;
138
- --pnb-on-dot: #ffffff; /* the glyph on a chip's dot; or per kind and status: */
141
+ --pnb-bg: #fff; /* the page */
142
+ --pnb-surface: #f4f4f5; /* a card */
143
+ --pnb-surface-2: #ececee; /* a chip or field inside a card */
144
+ --pnb-sunken: #ececee; /* the Top/New trough */
145
+ --pnb-line: #e4e4e7;
146
+ --pnb-text: #111;
147
+ --pnb-text-quiet: #6b6b72;
148
+ --pnb-accent: #111;
149
+ --pnb-accent-fill: var(--pnb-accent); /* what buttons are painted with; may be a gradient */
150
+ --pnb-on-accent: #fff;
151
+ --pnb-danger: #d23b2f;
152
+ --pnb-bug: #e5484d; --pnb-idea: #8b5cf6; --pnb-review: #e9a00b;
153
+ --pnb-planned: #8a8fb8; --pnb-done: #21bca5; --pnb-declined: #8a8fb8;
154
+ --pnb-on-dot: #fff; /* the glyph on a chip's dot; or per kind and status: */
139
155
  --pnb-on-bug: var(--pnb-on-dot); /* --pnb-on-idea, -review, -planned, -done, -declined */
140
- --pnb-star: #ffb700;
141
- --pnb-filter: var(--pnb-text); /* the chosen filter, and the chosen status in your answer sheet */
142
- --pnb-on-filter: var(--pnb-bg); /* its words: set both, as they are not picked for you */
156
+ --pnb-star: #f5a524;
157
+ --pnb-filter: color-mix(in srgb, var(--pnb-text) 16%, var(--pnb-bg)); /* the chosen filter, and the chosen status in your answer sheet: a state, so grey, not the button black */
158
+ --pnb-on-filter: var(--pnb-text); /* and its words */
143
159
  --pnb-tile-bug: var(--pnb-bug); /* the three tiles; may be gradients */
144
160
  --pnb-tile-idea: var(--pnb-idea);
145
161
  --pnb-tile-review: var(--pnb-review);
146
- --pnb-tile-ink: #ffffff; /* the words on them */
162
+ --pnb-tile-ink: #fff; /* the words on them */
147
163
  --pnb-tile-ink-bug: var(--pnb-tile-ink); /* the words on one tile (-idea, -review too) */
148
164
  --pnb-tile-dot-bug: transparent; /* a disc behind each tile's glyph (-idea, -review too) */
149
165
  --pnb-tile-glyph-bug: var(--pnb-tile-ink-bug); /* and the glyph's colour (-idea, -review too) */
@@ -151,25 +167,24 @@ please-no-bugs {
151
167
  --pnb-choose-title: var(--pnb-text); /* the question above the tiles */
152
168
  --pnb-title-board: var(--pnb-text); /* the title in the board's bar */
153
169
  --pnb-title-write: var(--pnb-text); /* the title above the form */
154
- --pnb-card: #ffffff; /* the posts and the rating on the board, */
170
+ --pnb-card: #fff; /* the posts and the rating on the board, */
155
171
  --pnb-card-text: var(--pnb-text); /* their words, */
156
172
  --pnb-card-quiet: var(--pnb-text-quiet); /* and their names, dates and counts */
157
- --pnb-field: #f2f3f4; /* every field you type in (form, search, answer, update), */
173
+ --pnb-field: var(--pnb-surface); /* every field you type in (form, search, answer, update), */
158
174
  --pnb-field-text: var(--pnb-text); /* what is typed in it, */
159
175
  --pnb-field-quiet: var(--pnb-text-quiet); /* its hint while empty, */
160
176
  --pnb-field-line: var(--pnb-line); /* and the line round it */
177
+ --pnb-field-in-card: var(--pnb-surface); /* a field inside a card: the version and link under "Fixed in" */
161
178
  --pnb-news: var(--pnb-surface-2); /* the note on top of the board ("... answered your idea"), */
162
179
  --pnb-news-line: var(--pnb-accent); /* its line, */
163
180
  --pnb-news-text: var(--pnb-text); /* its words, */
164
181
  --pnb-news-link: var(--pnb-accent); /* its link, */
165
182
  --pnb-news-quiet: var(--pnb-text-quiet); /* and its small words and close */
166
- --pnb-filter-btn: #ffffff; /* the Filter button: its ground, */
183
+ --pnb-filter-btn: #fff; /* the Filter button: its ground, */
167
184
  --pnb-filter-btn-text: var(--pnb-text); /* its word, */
168
- --pnb-filter-btn-line: #cdcdd3; /* and its line */
185
+ --pnb-filter-btn-line: var(--pnb-line); /* and its line */
169
186
  --pnb-bar-icon: var(--pnb-text); /* the icons in every bar: close, back, updates, new post */
170
- --pnb-order: var(--pnb-sunken); /* behind Top / New, */
171
- --pnb-order-text: var(--pnb-text-quiet); /* and the word not chosen */
172
- --pnb-vote: #f2f3f4; /* the vote button, */
187
+ --pnb-vote: var(--pnb-surface-2); /* the vote button, */
173
188
  --pnb-vote-text: var(--pnb-card-text); /* its count, */
174
189
  --pnb-vote-on: var(--pnb-accent); /* a vote you gave, */
175
190
  --pnb-on-vote-on: var(--pnb-on-accent); /* and its count */
@@ -181,21 +196,23 @@ please-no-bugs {
181
196
  --pnb-switch-on: var(--pnb-accent); /* the switch when on, */
182
197
  --pnb-on-switch-on: var(--pnb-on-accent); /* and its knob */
183
198
  --pnb-shot-line: var(--pnb-line); /* the line round "Add screenshot" */
184
- --pnb-order-on: var(--pnb-surface); /* the chosen half of Top/New, */
185
- --pnb-on-order: var(--pnb-text); /* and its words */
186
199
  --pnb-sent: var(--pnb-bg); /* behind "Feedback sent!" */
187
200
  --pnb-sent-title: var(--pnb-text); /* its title, */
188
201
  --pnb-sent-note: var(--pnb-text-quiet); /* its small words and "Back to the board", */
189
- --pnb-sent-check: #040724; /* and the disc behind its tick */
190
- --pnb-on-sent-check: #ffffff; /* the tick itself */
191
- --pnb-fab: #ffb700; /* the round floating button */
192
- --pnb-on-fab: #040724; /* its glyph */
193
- --pnb-fab-shadow: var(--pnb-shadow); /* its shadow, */
202
+ --pnb-sent-check: var(--pnb-done); /* and the disc behind its tick */
203
+ --pnb-on-sent-check: #fff; /* the tick itself */
204
+ --pnb-raise: none; /* a filled button's shadow; `pleasenobugs` raises it */
205
+ --pnb-raise-pressed: none; /* its shadow while pressed */
206
+ --pnb-raise-sink: 0px; /* how far it sinks when pressed */
207
+ --pnb-fab: var(--pnb-accent-fill); /* the round floating button, and Send feedback at the foot of the board */
208
+ --pnb-on-fab: #fff; /* its glyph */
209
+ --pnb-fab-shadow: 0 8px 24px rgba(0, 0, 0, 0.16); /* its shadow, */
194
210
  --pnb-fab-shadow-pressed: var(--pnb-fab-shadow); /* pressed, */
195
- --pnb-fab-squeeze: 0.94; /* and how small it gets pressed */
211
+ --pnb-fab-squeeze: 0.94; /* and how small it gets pressed */
196
212
  --pnb-radius-panel: 16px; /* the panel on a wide screen */
197
213
  --pnb-radius: 10px;
198
- --pnb-radius-sheet: 16px;
214
+ --pnb-radius-sheet: 16px; /* the sheet on a phone, and sheets inside */
215
+ --pnb-sheet-top: 48px; /* how much of your app stays in view above the sheet on a phone */
199
216
  --pnb-radius-pill: 999px; /* filters, chips, votes, Top/New, buttons */
200
217
  --pnb-font: inherit; /* your app's font */
201
218
  --pnb-z: 2147483000; /* overlay and floating button */
@@ -205,8 +222,8 @@ please-no-bugs {
205
222
  ```
206
223
 
207
224
  **Inside Nimiq Pay, set the two insets yourself if you measure Pay's bar.**
208
- Pay draws its own bar over the page and `env()` cannot see it, so a full-screen
209
- board can end up underneath it. Only the overlay and the floating button use
225
+ Pay draws its own bar over the page and `env()` cannot see it, so the sheet can
226
+ end up underneath it. Only the overlay and the floating button use
210
227
  them; an inline board ignores both.
211
228
 
212
229
  ## Reusing your app's own login
@@ -218,9 +235,19 @@ to the widget and nobody signs twice:
218
235
  board.appLogin = { address, publicKey, signature, message: 'Sign in to My app' };
219
236
  ```
220
237
 
221
- The project has to list that exact message first (`loginMessages`, through the
222
- dashboard or `create-project --login-message`). Set `appLogin` to `null` when
223
- the user logs out of your app.
238
+ The project has to accept that message first: set `PNB_PROJECT_LOGIN_MESSAGE`
239
+ on your server (on a server that already runs, set it and restart; with one
240
+ project it is added to that one), or use the dashboard or
241
+ `create-project --login-message`. If your login message changes every time,
242
+ because it carries a date or a random code, give its fixed start followed by
243
+ `*`, like `Sign in to My app*` (at least 12 characters before the `*`). Set
244
+ `appLogin` to `null` when the user logs out of your app.
245
+
246
+ This is how a mini app in Nimiq Pay, or a website with its own wallet login,
247
+ lets its users post and vote without signing anything again. Without it, the
248
+ widget asks the wallet to sign once by itself, at the first vote or post:
249
+ inside Nimiq Pay a short confirmation, kept for a month; in a browser through
250
+ the Nimiq Hub, kept until the tab closes.
224
251
 
225
252
  ## Signing outside Nimiq Pay
226
253
 
@@ -238,8 +265,13 @@ document.querySelector('please-no-bugs').signer = async (message) => {
238
265
  };
239
266
  ```
240
267
 
241
- Without a signer outside Nimiq Pay, the board is read-only and says so when
242
- somebody tries to post.
268
+ With a signer and outside Nimiq Pay, the board offers **"Sign in with Nimiq"**
269
+ on top until the user has signed in, since signing opens a wallet window
270
+ there. Without a signer outside Nimiq Pay, the board is read-only and says
271
+ "Sign in with your Nimiq wallet to post and vote" when somebody tries to post.
272
+ On a website with its own wallet login, that is the moment to hand the login
273
+ over with `appLogin` (above): set it once the user has signed in to your site,
274
+ and back to `null` when they sign out.
243
275
 
244
276
  ## Headless
245
277
 
@@ -0,0 +1,363 @@
1
+ function b(t) {
2
+ return t.replace(/\s+/g, "").toUpperCase();
3
+ }
4
+ function Z(t) {
5
+ const n = b(t);
6
+ return `${n.slice(0, 4)} … ${n.slice(-4)}`;
7
+ }
8
+ const M = 30 * 24 * 60 * 60 * 1e3, x = 5 * 60 * 1e3;
9
+ function J(t) {
10
+ return [
11
+ "PleaseNoBugs login",
12
+ `Project: ${t.project}`,
13
+ `Origin: ${D(t.origin)}`,
14
+ `Issued: ${new Date(t.issued).toISOString()}`
15
+ ].join(`
16
+ `);
17
+ }
18
+ function D(t) {
19
+ try {
20
+ return new URL(t).origin;
21
+ } catch {
22
+ return t;
23
+ }
24
+ }
25
+ function U(t, n = Date.now()) {
26
+ return Number.isFinite(t) && t <= n + x && n - t <= M;
27
+ }
28
+ function F(t) {
29
+ return `Nimiq ${K(JSON.stringify(t))}`;
30
+ }
31
+ function K(t) {
32
+ const n = new TextEncoder().encode(t);
33
+ let o = "";
34
+ for (const s of n)
35
+ o += String.fromCharCode(s);
36
+ return btoa(o).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
37
+ }
38
+ const W = [
39
+ // Dutch
40
+ "aan",
41
+ "als",
42
+ "bij",
43
+ "dan",
44
+ "dat",
45
+ "deze",
46
+ "die",
47
+ "dit",
48
+ "een",
49
+ "heb",
50
+ "het",
51
+ "ik",
52
+ "is",
53
+ "kan",
54
+ "kun",
55
+ "maar",
56
+ "met",
57
+ "mijn",
58
+ "niet",
59
+ "ook",
60
+ "van",
61
+ "voor",
62
+ "wil",
63
+ "word",
64
+ "wordt",
65
+ "zijn",
66
+ "zou",
67
+ "graag",
68
+ "meer",
69
+ "moet",
70
+ // English
71
+ "and",
72
+ "are",
73
+ "but",
74
+ "can",
75
+ "for",
76
+ "have",
77
+ "more",
78
+ "not",
79
+ "should",
80
+ "that",
81
+ "the",
82
+ "this",
83
+ "want",
84
+ "when",
85
+ "with",
86
+ "would",
87
+ "you",
88
+ "your",
89
+ // German
90
+ "aber",
91
+ "auch",
92
+ "bitte",
93
+ "dass",
94
+ "denn",
95
+ "ein",
96
+ "eine",
97
+ "einen",
98
+ "gerne",
99
+ "ich",
100
+ "ist",
101
+ "kann",
102
+ "mehr",
103
+ "mein",
104
+ "meine",
105
+ "nicht",
106
+ "oder",
107
+ "sein",
108
+ "sollte",
109
+ "und",
110
+ "wenn",
111
+ "werden",
112
+ "wird",
113
+ "wollen",
114
+ "möchte",
115
+ // Every board is about an app
116
+ "app"
117
+ ];
118
+ function ee(t = []) {
119
+ const n = /* @__PURE__ */ new Set([...W, ...[...t].map((r) => r.toLowerCase())]), o = /* @__PURE__ */ new WeakMap(), s = (r) => new Set(r.toLowerCase().replace(/[^\p{L}\p{N}\s]/gu, " ").split(/\s+/).filter((m) => m.length >= 4 && !n.has(m)));
120
+ return function(m, T, w = 3) {
121
+ const p = s(T);
122
+ return p.size < 2 ? [] : m.map((u) => {
123
+ let l = o.get(u);
124
+ l || (l = s(u.text), o.set(u, l));
125
+ let d = 0;
126
+ for (const h of p)
127
+ l.has(h) && d++;
128
+ return { post: u, shared: d };
129
+ }).filter((u) => u.shared >= 2).sort((u, l) => l.shared - u.shared || l.post.votes - u.post.votes).slice(0, w).map((u) => u.post);
130
+ };
131
+ }
132
+ function te(t, n) {
133
+ const o = [...t];
134
+ return n === "new" ? o.sort((s, r) => r.at - s.at) : o.sort((s, r) => r.votes - s.votes || r.at - s.at);
135
+ }
136
+ class E extends Error {
137
+ constructor(n, o) {
138
+ super(o ?? n), this.reason = n, this.name = "SignerError";
139
+ }
140
+ }
141
+ const B = 2e3;
142
+ function j() {
143
+ return typeof window < "u" && !!window.nimiq;
144
+ }
145
+ function H(t) {
146
+ return window.nimiq ? Promise.resolve(window.nimiq) : new Promise((n, o) => {
147
+ const s = Date.now(), r = setInterval(() => {
148
+ window.nimiq ? (clearInterval(r), n(window.nimiq)) : Date.now() - s > t && (clearInterval(r), o(new E("no_wallet", "Not running inside Nimiq Pay")));
149
+ }, 50);
150
+ });
151
+ }
152
+ function Q(t = B) {
153
+ return async (n) => {
154
+ const o = await H(t), s = await o.listAccounts();
155
+ if (!Array.isArray(s) || !s.length) throw new E("no_account");
156
+ const r = await o.sign(n);
157
+ if (!r || !("signature" in r))
158
+ throw new E("declined", r && "error" in r ? r.error.message : void 0);
159
+ return { address: s[0], publicKey: r.publicKey, signature: r.signature };
160
+ };
161
+ }
162
+ async function V() {
163
+ try {
164
+ const t = await window.nimiq?.listAccounts();
165
+ return Array.isArray(t) && t.length ? t[0] : null;
166
+ } catch {
167
+ return null;
168
+ }
169
+ }
170
+ function ne(t) {
171
+ const n = t.server.replace(/\/+$/, ""), o = t.project, s = D(t.origin ?? (typeof location < "u" ? location.origin : "")), r = t.signer === null ? void 0 : t.signer ?? (j() ? Q() : void 0), m = t.fetch ?? globalThis.fetch.bind(globalThis), T = j(), w = `pleasenobugs.proof.${o}.${s}`, p = t.storage === void 0 ? T ? Y() : X(w) : t.storage, u = t.account ?? (t.signer === void 0 && T ? V : void 0);
172
+ let l = 0, d = R(), h = null, N = !1;
173
+ function P() {
174
+ if (N || !t.appLogin) return null;
175
+ const e = typeof t.appLogin == "function" ? t.appLogin() : t.appLogin;
176
+ return e ? { ...e, origin: s, issued: 0 } : null;
177
+ }
178
+ function R() {
179
+ try {
180
+ const e = p?.getItem(w);
181
+ if (!e) return null;
182
+ const a = JSON.parse(e);
183
+ return U(a.issued) ? a : null;
184
+ } catch {
185
+ return null;
186
+ }
187
+ }
188
+ function v(e) {
189
+ d = e;
190
+ try {
191
+ e ? p?.setItem(w, JSON.stringify(e)) : p?.removeItem(w);
192
+ } catch {
193
+ }
194
+ }
195
+ async function z() {
196
+ if (!u || !d || Date.now() - l < 3e4) return;
197
+ l = Date.now();
198
+ const e = await u();
199
+ e && d && b(e) !== b(d.address) && v(null);
200
+ }
201
+ function q() {
202
+ const e = P();
203
+ return e || (d && !U(d.issued) && v(null), d);
204
+ }
205
+ function _() {
206
+ const e = P();
207
+ return e ? Promise.resolve({ ok: !0, data: b(e.address) }) : r ? h || (h = (async () => {
208
+ try {
209
+ const a = Date.now(), c = await r(J({ project: o, origin: s, issued: a }));
210
+ return v({ ...c, origin: s, issued: a }), { ok: !0, data: b(c.address) };
211
+ } catch (a) {
212
+ return a instanceof E && a.reason === "no_wallet" ? { ok: !1, status: 0, error: "no_signer" } : { ok: !1, status: 0, error: "declined" };
213
+ } finally {
214
+ h = null;
215
+ }
216
+ })(), h) : Promise.resolve({ ok: !1, status: 0, error: "no_signer" });
217
+ }
218
+ async function i(e, a, c) {
219
+ c.auth !== "none" && await z();
220
+ const I = async ($) => {
221
+ const O = {};
222
+ c.body !== void 0 && (O["content-type"] = "application/json"), $ && (O.authorization = F($));
223
+ let y;
224
+ try {
225
+ y = await m(`${n}${a}`, {
226
+ method: e,
227
+ headers: O,
228
+ ...c.body !== void 0 ? { body: JSON.stringify(c.body) } : {}
229
+ });
230
+ } catch {
231
+ return { ok: !1, status: 0, error: "network" };
232
+ }
233
+ if (y.ok && c.blob) {
234
+ const C = await y.blob().catch(() => null);
235
+ return C ? { ok: !0, data: C } : { ok: !1, status: 0, error: "network" };
236
+ }
237
+ const k = await y.json().catch(() => null);
238
+ if (y.ok) return { ok: !0, data: k };
239
+ const G = k && typeof k.error == "string" ? k.error : "internal";
240
+ return { ok: !1, status: y.status, error: G, body: k };
241
+ };
242
+ if (c.auth === "none") return I(null);
243
+ let S = q();
244
+ if (!S && c.auth === "required") {
245
+ const $ = await _();
246
+ if (!$.ok) return $;
247
+ S = q();
248
+ }
249
+ const L = await I(S);
250
+ if (L.ok || L.status !== 401 || !S) return L;
251
+ if (S.message !== void 0 ? N = !0 : v(null), c.auth === "optional") return I(null);
252
+ const A = await _();
253
+ return A.ok ? I(q()) : A;
254
+ }
255
+ const f = (e = "") => `/v1/projects/${encodeURIComponent(o)}${e}`, g = (e) => f(`/posts/${encodeURIComponent(e)}`);
256
+ return {
257
+ /** The project this client talks to. */
258
+ project: o,
259
+ /** Whether the user can be signed in at all: a signer, or an app login. */
260
+ get canSign() {
261
+ return !!r || P() !== null;
262
+ },
263
+ /** The signed-in address, if a proof is stored. */
264
+ address() {
265
+ const e = q();
266
+ return e ? b(e.address) : null;
267
+ },
268
+ signIn: _,
269
+ /** Forget the stored proof. The next write asks the wallet again. */
270
+ signOut() {
271
+ v(null);
272
+ },
273
+ /** The whole board, plus `me` when signed in. Never prompts. */
274
+ board: () => i("GET", f("/posts"), { auth: "optional" }),
275
+ me: () => i("GET", f("/me"), { auth: "required" }),
276
+ answers: () => i("GET", f("/answers"), { auth: "required" }),
277
+ /**
278
+ * Write one. A review needs `rating` (1 to 5); a bug or an idea may carry
279
+ * `shot`, a screenshot as base64. It goes on the board for everyone only
280
+ * with `board: true`, which says the user agreed; without it only the
281
+ * project's owners see it.
282
+ */
283
+ post: (e) => i("POST", f("/posts"), { body: e, auth: "required" }),
284
+ /** A post's screenshot: anybody's for one on the board, owners' for any. */
285
+ shot: (e) => i("GET", `${g(e)}/shot`, { auth: "optional", blob: !0 }),
286
+ /**
287
+ * Where a screenshot on the board can be read without a proof, for an
288
+ * `<img>` to load by itself.
289
+ */
290
+ shotUrl: (e) => `${n}${g(e)}/shot`,
291
+ /** Where the server draws an identicon, by the code a post carries in `face`. */
292
+ faceUrl: (e) => `${n}/v1/identicons/${encodeURIComponent(e)}.svg`,
293
+ vote: (e, a) => i("POST", `${g(e)}/vote`, {
294
+ body: { up: a },
295
+ auth: "required"
296
+ }),
297
+ remove: (e) => i("DELETE", g(e), { auth: "required" }),
298
+ setName: (e) => i("PUT", f("/me"), { body: { name: e }, auth: "required" }),
299
+ /**
300
+ * An owner answering a post. `fix` says where the fix is, on a bug or an
301
+ * idea set to done: `{ version?, link? }`, the link on github.com or
302
+ * gitlab.com. Moving a post away from done takes its fix away by itself.
303
+ */
304
+ manage: (e, a) => i("POST", `${g(e)}/manage`, { body: a, auth: "required" }),
305
+ /**
306
+ * Write under a post: an owner for the app, whenever they like; its
307
+ * author only right after the app, on a bug or an idea that is not done
308
+ * (`not_your_turn`, `closed` otherwise). `message.id` is yours to mint.
309
+ */
310
+ say: (e, a) => i("POST", `${g(e)}/messages`, { body: a, auth: "required" }),
311
+ /**
312
+ * Change your own last message before anybody answered it (`text`), or,
313
+ * as an owner, take an author's message off the board or put it back
314
+ * (`hidden`).
315
+ */
316
+ editMessage: (e, a, c) => i("PATCH", `${g(e)}/messages/${encodeURIComponent(a)}`, {
317
+ body: c,
318
+ auth: "required"
319
+ }),
320
+ /** Take your own last message back, before anybody answered it. */
321
+ unsay: (e, a) => i("DELETE", `${g(e)}/messages/${encodeURIComponent(a)}`, { auth: "required" }),
322
+ /** What changed in the app, newest first. Anybody's to read; never prompts. */
323
+ updates: () => i("GET", f("/updates"), { auth: "optional" }),
324
+ /**
325
+ * An owner writing one. `link` is a page on github.com or gitlab.com;
326
+ * `posts` are the bugs and ideas it fixed, which go to done with its
327
+ * version and link.
328
+ */
329
+ postUpdate: (e) => i("POST", f("/updates"), { body: e, auth: "required" }),
330
+ /** An owner taking one off the page. The posts it fixed stay done. */
331
+ removeUpdate: (e) => i("DELETE", f(`/updates/${encodeURIComponent(e)}`), { auth: "required" })
332
+ };
333
+ }
334
+ function X(t) {
335
+ try {
336
+ globalThis.localStorage?.removeItem(t);
337
+ } catch {
338
+ }
339
+ try {
340
+ const n = globalThis.sessionStorage, o = "__pleasenobugs__";
341
+ return n.setItem(o, "1"), n.removeItem(o), n;
342
+ } catch {
343
+ return null;
344
+ }
345
+ }
346
+ function Y() {
347
+ try {
348
+ const t = globalThis.localStorage, n = "__pleasenobugs__";
349
+ return t.setItem(n, "1"), t.removeItem(n), t;
350
+ } catch {
351
+ return null;
352
+ }
353
+ }
354
+ export {
355
+ E as S,
356
+ ne as a,
357
+ b,
358
+ ee as c,
359
+ Z as d,
360
+ j as i,
361
+ Q as n,
362
+ te as s
363
+ };