@sigport/elements 0.0.0-stage → 0.1.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/dist/auto.js ADDED
@@ -0,0 +1,1242 @@
1
+ // src/define.ts
2
+ import { createSigport } from "@sigport/core";
3
+ import { all, BUILT_IN_IDS } from "@sigport/core/all";
4
+
5
+ // src/button.ts
6
+ import { describeAccount as describeAccount2 } from "@sigport/core";
7
+ import { LitElement as LitElement3, css as css2, html as html3, nothing as nothing3 } from "lit";
8
+
9
+ // src/icons.ts
10
+ import { svg } from "lit";
11
+ function icon(paths, size = 18) {
12
+ return svg`<svg width=${size} height=${size} viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${paths.map((d) => svg`<path d=${d}></path>`)}</svg>`;
13
+ }
14
+ var PATHS = {
15
+ info: ["M3 12a9 9 0 1 0 18 0a9 9 0 1 0-18 0", "M12 11v5", "M12 8h.01"],
16
+ download: ["M12 4v12", "M6 11l6 6 6-6", "M5 20h14"],
17
+ open: ["M14 4h6v6", "M20 4l-9 9", "M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"],
18
+ chevronRight: ["M9 6l6 6-6 6"],
19
+ chevronDown: ["M6 9l6 6 6-6"],
20
+ chevronUp: ["M6 15l6-6 6 6"],
21
+ back: ["M15 6l-6 6 6 6"],
22
+ qr: ["M4 4h6v6H4z", "M14 4h6v6h-6z", "M4 14h6v6H4z", "M14 14h2", "M18 14h2v2", "M14 18h2v2h-2"],
23
+ copy: ["M9 9h10v10H9z", "M5 15V5h10"],
24
+ refresh: ["M20 11a8 8 0 1 0-2.3 5.7", "M20 5v6h-6"],
25
+ close: ["M6 6l12 12", "M18 6L6 18"],
26
+ grip: ["M9 6h.01", "M9 12h.01", "M9 18h.01", "M15 6h.01", "M15 12h.01", "M15 18h.01"],
27
+ tap: ["M7 17L17 7", "M8 7h9v9"]
28
+ };
29
+
30
+ // src/signin.ts
31
+ import {
32
+ describeAccount,
33
+ describeCatalog,
34
+ describeRows,
35
+ shortRelay as shortRelay2
36
+ } from "@sigport/core";
37
+ import { LitElement as LitElement2, html as html2, nothing as nothing2, svg as svg2 } from "lit";
38
+ import { encode } from "uqr";
39
+
40
+ // src/relays.ts
41
+ import { relayAddress, shortRelay } from "@sigport/core";
42
+ import { LitElement, html, nothing } from "lit";
43
+
44
+ // src/strings.ts
45
+ var DEFAULT_STRINGS = {
46
+ label: "Sign in",
47
+ title: "Choose how to sign in",
48
+ lede: "Your key stays with you. This site only asks it to sign.",
49
+ looking: "Looking for ways to sign in\u2026",
50
+ others: "Other sign-in options",
51
+ back: "All sign-in options",
52
+ remembered: "Remembered",
53
+ signInRemembered: "Sign in",
54
+ forget: "Forget",
55
+ signedInAs: "Signed in as",
56
+ signOut: "Sign out",
57
+ switchAccount: "Use another identity",
58
+ ready: "Ready",
59
+ pairingNote: "Scan it with your signer app",
60
+ making: "Making a pairing code\u2026",
61
+ moreApps: "Show {count} more",
62
+ waiting: "Waiting for your signer to accept\u2026",
63
+ finding: "Finding a relay your signer can reach\u2026",
64
+ tryAgain: "Try again",
65
+ tryAgainNote: "Check the relays again and make a new code",
66
+ noAnswer: "no answer",
67
+ via: "via",
68
+ change: "Change",
69
+ changeRelays: "Change relays",
70
+ openInSigner: "Open in your signer app",
71
+ tapToOpen: "Tap to open your signer app",
72
+ opening: "Opening your signer\u2026",
73
+ nothingOpened: "Nothing opened?",
74
+ getSigner: "Get a signer app",
75
+ orCopy: "or copy the code.",
76
+ relaysTitle: "Pairing relays",
77
+ relaysLede: "Your signer answers on one of these. They are tried in order.",
78
+ addRelay: "Add a relay",
79
+ addRelayPlaceholder: "relay.example.com",
80
+ add: "Add",
81
+ checking: "Checking\u2026",
82
+ relayNoAnswer: "{relay} did not answer. Check the address, or try another relay.",
83
+ relayInvalid: "That is not a relay address. It looks like relay.example.com.",
84
+ relayDuplicate: "That relay is already in the list.",
85
+ useRelays: "Use these relays",
86
+ resetRelays: "Reset",
87
+ moveUp: "Move up",
88
+ moveDown: "Move down",
89
+ remove: "Remove",
90
+ suggested: "Suggested from relay monitors (NIP-66)",
91
+ seenBy: "Seen by {count} monitors",
92
+ seenByOne: "Seen by 1 monitor",
93
+ checkedAgo: "checked {time} ago",
94
+ copy: "Copy code",
95
+ copied: "Copied",
96
+ copyFailed: "This browser would not copy. Scan the code instead.",
97
+ orPaste: "or paste a code",
98
+ /** Between the paste field and the pairing code, under `paste-first`. */
99
+ orPair: "or pair from the signer",
100
+ apps: "Apps",
101
+ extensionsTitle: "Browser extensions",
102
+ extensionsLede: "An extension keeps your key in this browser and signs when a site asks. Pick one to sign in, or get one.",
103
+ appsTitle: "Signer apps",
104
+ appsLede: "Apps that hold your key and sign for this site.",
105
+ installedRecheck: "Installed one just now?",
106
+ recheck: "Check again",
107
+ footer: "Secured by",
108
+ button: "Sign in",
109
+ close: "Close"
110
+ };
111
+
112
+ // src/relays.ts
113
+ var ago = (seconds) => {
114
+ const elapsed = Math.max(0, Date.now() / 1e3 - seconds);
115
+ if (elapsed < 3600) return `${Math.max(1, Math.round(elapsed / 60))} min`;
116
+ if (elapsed < 86400) return `${Math.round(elapsed / 3600)} h`;
117
+ return `${Math.round(elapsed / 86400)} d`;
118
+ };
119
+ var SigportRelays = class extends LitElement {
120
+ constructor() {
121
+ super();
122
+ this.dragging = null;
123
+ this.lookup = 0;
124
+ this.strings = {};
125
+ this.draft = [];
126
+ this.query = "";
127
+ this.suggestions = [];
128
+ this.active = -1;
129
+ this.adding = false;
130
+ this.problem = null;
131
+ }
132
+ static {
133
+ this.properties = {
134
+ sigport: { attribute: false },
135
+ strings: { attribute: false },
136
+ draft: { state: true },
137
+ query: { state: true },
138
+ suggestions: { state: true },
139
+ active: { state: true },
140
+ adding: { state: true },
141
+ problem: { state: true }
142
+ };
143
+ }
144
+ // The panel's shadow root styles this, so it renders in place.
145
+ createRenderRoot() {
146
+ return this;
147
+ }
148
+ get t() {
149
+ return { ...DEFAULT_STRINGS, ...this.strings };
150
+ }
151
+ connectedCallback() {
152
+ super.connectedCallback();
153
+ const sigport = this.sigport;
154
+ if (!sigport) return;
155
+ const known = new Map((sigport.getState().pairing?.checks ?? []).map((check) => [check.url, check]));
156
+ this.draft = sigport.pairingRelays().map((url) => {
157
+ const check = known.get(url);
158
+ return check?.status === "ok" ? { url, status: "ok", ...check.ms !== void 0 ? { ms: check.ms } : {} } : { url, status: "checking" };
159
+ });
160
+ for (const entry of this.draft) if (entry.status === "checking") void this.check(entry.url);
161
+ }
162
+ async check(url) {
163
+ const result = await this.sigport?.checkRelay(url) ?? { ok: false };
164
+ this.draft = this.draft.map((entry) => entry.url === url ? { url, status: result.ok ? "ok" : "failed", ...result.ms !== void 0 ? { ms: result.ms } : {} } : entry);
165
+ return result.ok;
166
+ }
167
+ move(from, to) {
168
+ if (to < 0 || to >= this.draft.length || from === to) return;
169
+ const next = [...this.draft];
170
+ const [entry] = next.splice(from, 1);
171
+ next.splice(to, 0, entry);
172
+ this.draft = next;
173
+ }
174
+ async add(text) {
175
+ const t = this.t;
176
+ const url = relayAddress(text);
177
+ if (!url) {
178
+ this.problem = t.relayInvalid;
179
+ return;
180
+ }
181
+ if (this.draft.some((entry) => entry.url === url)) {
182
+ this.problem = t.relayDuplicate;
183
+ return;
184
+ }
185
+ this.problem = null;
186
+ this.adding = true;
187
+ const result = await this.sigport?.checkRelay(url) ?? { ok: false };
188
+ this.adding = false;
189
+ if (!result.ok) {
190
+ this.problem = t.relayNoAnswer.replace("{relay}", shortRelay(url));
191
+ return;
192
+ }
193
+ this.draft = [...this.draft, { url, status: "ok", ...result.ms !== void 0 ? { ms: result.ms } : {} }];
194
+ this.query = "";
195
+ this.suggestions = [];
196
+ this.active = -1;
197
+ }
198
+ async type(value) {
199
+ this.query = value;
200
+ this.problem = null;
201
+ this.active = -1;
202
+ const sigport = this.sigport;
203
+ if (!sigport?.suggestsRelays || !value.trim()) {
204
+ this.suggestions = [];
205
+ return;
206
+ }
207
+ const ask = ++this.lookup;
208
+ const found = await sigport.suggestRelays(value, 6);
209
+ if (ask === this.lookup) this.suggestions = found.filter((entry) => !this.draft.some((relay) => relay.url === entry.url)).slice(0, 5);
210
+ }
211
+ keys(event) {
212
+ const count = this.suggestions.length;
213
+ if (event.key === "ArrowDown" && count) {
214
+ event.preventDefault();
215
+ this.active = (this.active + 1) % count;
216
+ } else if (event.key === "ArrowUp" && count) {
217
+ event.preventDefault();
218
+ this.active = (this.active - 1 + count) % count;
219
+ } else if (event.key === "Escape") {
220
+ this.suggestions = [];
221
+ } else if (event.key === "Enter") {
222
+ event.preventDefault();
223
+ const picked = this.suggestions[this.active];
224
+ void this.add(picked ? picked.url : this.query);
225
+ }
226
+ }
227
+ render() {
228
+ const t = this.t;
229
+ const sigport = this.sigport;
230
+ const ready = this.draft.some((entry) => entry.status === "ok");
231
+ return html`
232
+ <ul class="relays" part="relays">
233
+ ${this.draft.map(
234
+ (entry, index) => html`<li
235
+ class="relay-row ${index === 0 ? "first" : ""}"
236
+ draggable="true"
237
+ @dragstart=${() => this.dragging = index}
238
+ @dragover=${(event) => event.preventDefault()}
239
+ @drop=${() => (this.dragging !== null && this.move(this.dragging, index), this.dragging = null)}
240
+ >
241
+ <span class="grip" aria-hidden="true">${icon(PATHS.grip, 16)}</span>
242
+ <code>${shortRelay(entry.url)}</code>
243
+ <small class="relay-state ${entry.status}"><span class="dot ${entry.status}" aria-hidden="true"></span>${entry.status === "ok" ? `${entry.ms ?? "\u2013"} ms` : entry.status === "failed" ? t.noAnswer : t.checking}</small>
244
+ <span class="relay-tools">
245
+ <button type="button" class="icon" aria-label="${t.moveUp}: ${shortRelay(entry.url)}" title=${t.moveUp} ?disabled=${index === 0} @click=${() => this.move(index, index - 1)}>${icon(PATHS.chevronUp, 16)}</button>
246
+ <button type="button" class="icon" aria-label="${t.moveDown}: ${shortRelay(entry.url)}" title=${t.moveDown} ?disabled=${index === this.draft.length - 1} @click=${() => this.move(index, index + 1)}>${icon(PATHS.chevronDown, 16)}</button>
247
+ <button type="button" class="icon" aria-label="${t.remove}: ${shortRelay(entry.url)}" title=${t.remove} @click=${() => this.draft = this.draft.filter((other) => other.url !== entry.url)}>${icon(PATHS.close, 16)}</button>
248
+ </span>
249
+ </li>`
250
+ )}
251
+ </ul>
252
+ <form class="add-relay" @submit=${(event) => (event.preventDefault(), void this.add(this.suggestions[this.active]?.url ?? this.query))}>
253
+ <label class="field" for="relay-input">${t.addRelay}</label>
254
+ <div class="combo">
255
+ <input
256
+ id="relay-input"
257
+ part="input"
258
+ class="mono"
259
+ inputmode="url"
260
+ autocomplete="off"
261
+ autocapitalize="off"
262
+ spellcheck="false"
263
+ placeholder=${t.addRelayPlaceholder}
264
+ role="combobox"
265
+ aria-expanded=${this.suggestions.length ? "true" : "false"}
266
+ aria-controls="relay-suggestions"
267
+ aria-activedescendant=${this.active >= 0 ? `relay-suggestion-${this.active}` : ""}
268
+ .value=${this.query}
269
+ @input=${(event) => void this.type(event.target.value)}
270
+ @keydown=${(event) => this.keys(event)}
271
+ @focus=${() => void this.sigport?.suggestRelays("", 0)}
272
+ />
273
+ <button type="submit" class="btn" part="button" ?disabled=${!this.query.trim() || this.adding}>${this.adding ? t.checking : t.add}</button>
274
+ </div>
275
+ ${this.suggestions.length ? html`<div class="suggest" part="suggestions">
276
+ <ul id="relay-suggestions" role="listbox">
277
+ ${this.suggestions.map(
278
+ (entry, index) => html`<li
279
+ id="relay-suggestion-${index}"
280
+ role="option"
281
+ aria-selected=${index === this.active ? "true" : "false"}
282
+ class=${index === this.active ? "active" : ""}
283
+ @mousedown=${(event) => (event.preventDefault(), void this.add(entry.url))}
284
+ >
285
+ <code>${shortRelay(entry.url)}</code>
286
+ <span class="meta">${entry.name ? `${entry.name} \xB7 ` : ""}${entry.monitors === 1 ? t.seenByOne : t.seenBy.replace("{count}", String(entry.monitors))} · ${t.checkedAgo.replace("{time}", ago(entry.checkedAt))}</span>
287
+ ${entry.rtt !== void 0 ? html`<span class="rtt">${entry.rtt} ms</span>` : nothing}
288
+ </li>`
289
+ )}
290
+ </ul>
291
+ <p class="source">${t.suggested}</p>
292
+ </div>` : nothing}
293
+ </form>
294
+ ${this.problem ? html`<p class="error" part="error" role="alert">${this.problem}</p>` : nothing}
295
+ <div class="actions">
296
+ <button type="button" class="btn primary" part="button" ?disabled=${!ready} @click=${() => void sigport?.setPairingRelays(this.draft.map((entry) => entry.url))}>${t.useRelays}</button>
297
+ <button type="button" class="btn quiet" part="button" @click=${() => void sigport?.setPairingRelays(null)}>${t.resetRelays}</button>
298
+ </div>
299
+ `;
300
+ }
301
+ };
302
+
303
+ // src/styles.ts
304
+ import { css } from "lit";
305
+ var styles = css`
306
+ :host {
307
+ --sigport-font: Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
308
+ --sigport-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
309
+ --sigport-radius: 12px;
310
+ --sigport-width: 28rem;
311
+ --sigport-raised: #ffffff;
312
+ --sigport-bg: #ffffff;
313
+ --sigport-sunken: #f4f4f5;
314
+ --sigport-ink: #18181b;
315
+ --sigport-muted: #52525b;
316
+ --sigport-line: #e4e4e7;
317
+ --sigport-line-strong: #d4d4d8;
318
+ --sigport-accent: #18181b;
319
+ --sigport-accent-ink: #ffffff;
320
+ --sigport-top-bg: #f4f4f5;
321
+ --sigport-danger: #b91c1c;
322
+ --sigport-ok: #15803d;
323
+ --sigport-ease: cubic-bezier(0.2, 0.7, 0.2, 1);
324
+ display: block;
325
+ width: 100%;
326
+ max-width: var(--sigport-width);
327
+ font-family: var(--sigport-font);
328
+ color: var(--sigport-ink);
329
+ -webkit-font-smoothing: antialiased;
330
+ color-scheme: light;
331
+ }
332
+
333
+ :host([theme='dark']) {
334
+ --sigport-raised: #111113;
335
+ --sigport-bg: #18181b;
336
+ --sigport-sunken: #27272a;
337
+ --sigport-ink: #fafafa;
338
+ --sigport-muted: #a1a1aa;
339
+ --sigport-line: #27272a;
340
+ --sigport-line-strong: #3f3f46;
341
+ --sigport-accent: #fafafa;
342
+ --sigport-accent-ink: #09090b;
343
+ --sigport-top-bg: #27272a;
344
+ --sigport-danger: #f87171;
345
+ --sigport-ok: #4ade80;
346
+ color-scheme: dark;
347
+ }
348
+
349
+ @media (prefers-color-scheme: dark) {
350
+ :host([theme='auto']) {
351
+ --sigport-raised: #111113;
352
+ --sigport-bg: #18181b;
353
+ --sigport-sunken: #27272a;
354
+ --sigport-ink: #fafafa;
355
+ --sigport-muted: #a1a1aa;
356
+ --sigport-line: #27272a;
357
+ --sigport-line-strong: #3f3f46;
358
+ --sigport-accent: #fafafa;
359
+ --sigport-accent-ink: #09090b;
360
+ --sigport-top-bg: #27272a;
361
+ --sigport-danger: #f87171;
362
+ --sigport-ok: #4ade80;
363
+ color-scheme: dark;
364
+ }
365
+ }
366
+
367
+ * { box-sizing: border-box; }
368
+
369
+ .card {
370
+ background: var(--sigport-raised);
371
+ border: 1px solid var(--sigport-line);
372
+ border-radius: calc(var(--sigport-radius) + 4px);
373
+ overflow: hidden;
374
+ }
375
+ :host([bare]) .card { background: none; border: 0; border-radius: 0; }
376
+
377
+ .viewport { overflow: hidden; }
378
+ .track {
379
+ display: grid;
380
+ grid-template-columns: 100% 100%;
381
+ align-items: start;
382
+ transition: transform 340ms var(--sigport-ease);
383
+ }
384
+ .track.deep { transform: translateX(-100%); }
385
+ .pane { padding: var(--sigport-pad, clamp(20px, 5vw, 32px)); display: flex; flex-direction: column; gap: 20px; min-width: 0; }
386
+ .pane.away { visibility: hidden; height: 0; padding-block: 0; overflow: hidden; }
387
+ @media (prefers-reduced-motion: reduce) { .track { transition: none; } }
388
+
389
+ header { display: flex; flex-direction: column; gap: 8px; }
390
+ .label { margin: 0; font-family: var(--sigport-mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--sigport-muted); }
391
+ h2 { margin: 0; font-size: 24px; line-height: 1.2; font-weight: 600; letter-spacing: -0.01em; }
392
+ .lede, .note { margin: 0; font-size: 14px; line-height: 1.5; color: var(--sigport-muted); }
393
+ .lede { font-size: var(--sigport-lede-size, 14px); }
394
+ .note { font-size: 13px; }
395
+
396
+ ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
397
+ li { display: flex; gap: 8px; min-width: 0; }
398
+
399
+ .row {
400
+ flex: 1;
401
+ min-width: 0;
402
+ min-height: 60px;
403
+ display: flex;
404
+ align-items: center;
405
+ gap: 12px;
406
+ padding: 10px 14px;
407
+ font: inherit;
408
+ text-align: left;
409
+ text-decoration: none;
410
+ cursor: pointer;
411
+ color: var(--sigport-ink);
412
+ background: var(--sigport-bg);
413
+ border: 1px solid var(--sigport-line-strong);
414
+ border-radius: var(--sigport-radius);
415
+ transition: border-color 160ms var(--sigport-ease), background 160ms var(--sigport-ease);
416
+ }
417
+ .row:hover:not(:disabled) { border-color: var(--sigport-accent); }
418
+ .row:focus-visible, .side:focus-visible, .btn:focus-visible, .back:focus-visible, .more:focus-visible, input:focus-visible {
419
+ outline: 2px solid var(--sigport-accent);
420
+ outline-offset: 2px;
421
+ }
422
+ .row.top { background: var(--sigport-top-bg); border-color: var(--sigport-accent); }
423
+ .row.quiet { background: transparent; border-color: var(--sigport-line); }
424
+ .row.dashed { border-style: dashed; }
425
+ .row:disabled { opacity: 0.55; cursor: not-allowed; }
426
+
427
+ .tile {
428
+ flex: none;
429
+ width: 34px;
430
+ height: 34px;
431
+ border-radius: calc(var(--sigport-radius) - 3px);
432
+ display: grid;
433
+ place-items: center;
434
+ background: var(--sigport-sunken);
435
+ color: var(--sigport-ink);
436
+ font-weight: 700;
437
+ font-size: 15px;
438
+ overflow: hidden;
439
+ }
440
+ .tile img { width: 34px; height: 34px; display: block; }
441
+ .tile.extension, .tile.passkey { background: var(--sigport-ink); color: var(--sigport-raised); }
442
+ .tile.remote { background: var(--sigport-line-strong); }
443
+ .tile.logo { background: none; }
444
+ .row.top .tile:not(.extension):not(.passkey):not(.remote):not(.logo) { background: var(--sigport-raised); }
445
+
446
+ .words { flex: 1; min-width: 0; display: grid; gap: 2px; }
447
+ .name { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; }
448
+ .hint { font-size: 13px; color: var(--sigport-muted); overflow-wrap: anywhere; }
449
+ .chev { color: var(--sigport-muted); display: grid; flex: none; }
450
+ .badge { font-size: 11px; font-weight: 600; letter-spacing: 0.02em; padding: 2px 7px; border-radius: 999px; background: var(--sigport-accent); color: var(--sigport-accent-ink); }
451
+
452
+ .side {
453
+ flex: none;
454
+ width: 60px;
455
+ min-height: 60px;
456
+ display: grid;
457
+ place-items: center;
458
+ padding: 0;
459
+ font: inherit;
460
+ cursor: pointer;
461
+ color: var(--sigport-ink);
462
+ background: var(--sigport-raised);
463
+ border: 1px solid var(--sigport-line-strong);
464
+ border-radius: var(--sigport-radius);
465
+ transition: border-color 160ms var(--sigport-ease);
466
+ }
467
+ .side:hover { border-color: var(--sigport-accent); }
468
+
469
+ .toggle { justify-content: center; padding-top: 4px; }
470
+ .more, .back {
471
+ display: inline-flex;
472
+ align-items: center;
473
+ gap: 6px;
474
+ min-height: 44px;
475
+ padding: 0 14px;
476
+ font: inherit;
477
+ font-size: 14px;
478
+ color: var(--sigport-muted);
479
+ background: none;
480
+ border: 0;
481
+ border-radius: 999px;
482
+ cursor: pointer;
483
+ }
484
+ .more:hover, .back:hover { color: var(--sigport-ink); }
485
+ .back { align-self: flex-start; margin: -10px 0 -6px -12px; padding: 0 12px 0 8px; }
486
+
487
+ form { display: grid; gap: 12px; }
488
+ form .group { display: grid; gap: 12px; }
489
+ .visually-hidden, :host([compact]) .field-label, :host([compact]) .status.quiet { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
490
+ :host([compact]) .qr-code, :host([compact]) .qr-slot { width: min(100%, 168px); }
491
+ :host([compact]) .qr-code > svg { padding: 10px; }
492
+ :host([compact]) figure.qr { gap: 10px; }
493
+ :host([compact]) form .group.single { display: flex; align-items: flex-end; gap: 8px; }
494
+ :host([compact]) form .group.single > .field { flex: 1; }
495
+ :host([compact]) form .group.single > .actions { margin: 0; flex-wrap: nowrap; }
496
+ .chip.copy { display: grid; place-items: center; width: 28px; padding: 0; }
497
+ label.field { display: grid; gap: 6px; font-size: 13px; font-weight: 500; }
498
+ input {
499
+ min-height: 44px;
500
+ width: 100%;
501
+ padding: 0 12px;
502
+ font: inherit;
503
+ font-size: 15px;
504
+ color: var(--sigport-ink);
505
+ background: var(--sigport-bg);
506
+ border: 1px solid var(--sigport-line-strong);
507
+ border-radius: var(--sigport-radius);
508
+ }
509
+ input.mono { font-family: var(--sigport-mono); font-size: 13px; }
510
+ .actions { display: flex; flex-wrap: wrap; gap: 8px; }
511
+ .btn {
512
+ display: inline-flex;
513
+ align-items: center;
514
+ justify-content: center;
515
+ gap: 8px;
516
+ min-height: 44px;
517
+ padding: 0 16px;
518
+ font: inherit;
519
+ font-size: 14px;
520
+ font-weight: 600;
521
+ cursor: pointer;
522
+ color: var(--sigport-ink);
523
+ background: var(--sigport-bg);
524
+ border: 1px solid var(--sigport-line-strong);
525
+ border-radius: var(--sigport-radius);
526
+ }
527
+ .btn.primary { color: var(--sigport-accent-ink); background: var(--sigport-accent); border-color: var(--sigport-accent); }
528
+ .btn:disabled { opacity: 0.55; cursor: not-allowed; }
529
+ .btn.quiet { border-color: transparent; background: none; color: var(--sigport-muted); }
530
+
531
+ .or { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--sigport-muted); }
532
+ .or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--sigport-line); }
533
+
534
+ figure.qr { margin: 0; display: grid; justify-items: center; gap: 12px; }
535
+ .qr-slot { width: min(100%, 220px); aspect-ratio: 1; border: 1px solid var(--sigport-line); border-radius: var(--sigport-radius); background: var(--sigport-sunken); }
536
+ .qr-code { position: relative; display: block; width: min(100%, 220px); border-radius: var(--sigport-radius); -webkit-tap-highlight-color: transparent; }
537
+ .qr-code > svg { display: block; width: 100%; height: auto; padding: 12px; background: #fff; border: 1px solid var(--sigport-line); border-radius: var(--sigport-radius); }
538
+ .qr-code:focus-visible { outline: 2px solid var(--sigport-accent); outline-offset: 3px; }
539
+ .tap-mark { position: absolute; right: 8px; bottom: 8px; display: none; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: #18181b; color: #fff; box-shadow: 0 2px 8px rgb(0 0 0 / 0.25); }
540
+ .tap-hint { display: none; margin: 0; font-size: 13px; font-weight: 600; }
541
+ @media (pointer: coarse) { .tap-mark { display: grid; } .tap-hint { display: block; } }
542
+ .relay-line { display: inline-flex; align-items: center; gap: 8px; margin: 0; padding: 4px 4px 4px 10px; font-size: 13px; color: var(--sigport-muted); border: 1px solid var(--sigport-line); border-radius: 999px; }
543
+ .relay-line code { font: 500 12.5px var(--sigport-mono); color: var(--sigport-ink); }
544
+ .chip { min-height: 28px; padding: 0 10px; font: inherit; font-size: 13px; font-weight: 600; color: var(--sigport-ink); background: var(--sigport-sunken); border: 0; border-radius: 999px; cursor: pointer; }
545
+ .chip:hover { background: var(--sigport-line-strong); }
546
+ .chip:focus-visible, .icon:focus-visible, .qr-code:focus-visible { outline: 2px solid var(--sigport-accent); outline-offset: 2px; }
547
+ .note.opened { text-align: center; }
548
+ .note.opened a { color: var(--sigport-ink); }
549
+ .actions.center { justify-content: center; }
550
+ .btn.small { min-height: 36px; font-size: 13px; }
551
+ .qr-slot { display: grid; place-items: center; }
552
+ .checks { list-style: none; margin: 0; padding: 0 12px; display: grid; gap: 8px; width: 100%; }
553
+ .checks li { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--sigport-muted); }
554
+ .checks code { flex: 1; font: 500 12px var(--sigport-mono); color: var(--sigport-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
555
+ .checks .ms { font: 11px var(--sigport-mono); }
556
+ .dot.ok { background: var(--sigport-ok); animation: none; }
557
+ .dot.failed { background: var(--sigport-danger); animation: none; }
558
+ .dot.waiting { background: transparent; border: 1.5px solid var(--sigport-line-strong); animation: none; }
559
+ sigport-relays { display: flex; flex-direction: column; gap: 16px; }
560
+ .relays { gap: 8px; }
561
+ .relay-row { align-items: center; gap: 8px; min-height: 52px; padding: 4px 4px 4px 10px; border: 1px solid var(--sigport-line-strong); border-radius: var(--sigport-radius); background: var(--sigport-bg); }
562
+ .relay-row.first { border-color: var(--sigport-accent); }
563
+ .relay-row .grip { color: var(--sigport-muted); display: grid; cursor: grab; }
564
+ .relay-row code { flex: 1; min-width: 0; font: 500 13px var(--sigport-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
565
+ .relay-state { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--sigport-muted); white-space: nowrap; }
566
+ .relay-tools { display: flex; }
567
+ .icon { width: 36px; height: 40px; display: grid; place-items: center; padding: 0; color: var(--sigport-muted); background: none; border: 0; border-radius: 10px; cursor: pointer; }
568
+ .icon:hover:not(:disabled) { color: var(--sigport-ink); background: var(--sigport-sunken); }
569
+ .icon:disabled { opacity: 0.35; cursor: default; }
570
+ .add-relay { gap: 6px; }
571
+ .add-relay .field { font-size: 13px; font-weight: 500; }
572
+ .combo { display: flex; gap: 8px; }
573
+ .combo input { flex: 1; }
574
+ .suggest { margin-top: 2px; border: 1px solid var(--sigport-line-strong); border-radius: var(--sigport-radius); overflow: hidden; background: var(--sigport-bg); }
575
+ .suggest ul { gap: 0; }
576
+ .suggest li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 10px 14px; border-top: 1px solid var(--sigport-line); cursor: pointer; }
577
+ .suggest li:first-child { border-top: 0; }
578
+ .suggest li.active, .suggest li:hover { background: var(--sigport-sunken); }
579
+ .suggest code { font: 500 13px var(--sigport-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
580
+ .suggest .meta { grid-column: 1; font-size: 12px; color: var(--sigport-muted); }
581
+ .suggest .rtt { grid-row: 1 / 3; grid-column: 2; align-self: center; font: 12px var(--sigport-mono); color: var(--sigport-muted); }
582
+ .suggest .source { margin: 0; padding: 8px 14px; font-size: 11.5px; color: var(--sigport-muted); border-top: 1px solid var(--sigport-line); }
583
+ .status { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0; font-size: 13px; color: var(--sigport-muted); }
584
+ .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sigport-muted); animation: pulse 1.4s ease-in-out infinite; }
585
+ @keyframes pulse { 50% { opacity: 0.25; } }
586
+ @media (prefers-reduced-motion: reduce) { .dot { animation: none; } }
587
+
588
+ .recheck { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--sigport-muted); padding-top: 16px; border-top: 1px solid var(--sigport-line); }
589
+ .error { margin: 0; padding: 10px 12px; font-size: 14px; color: var(--sigport-danger); background: color-mix(in srgb, var(--sigport-danger) 8%, transparent); border-radius: var(--sigport-radius); }
590
+ .foot { margin: 0; text-align: center; font-size: 12px; color: var(--sigport-muted); }
591
+ .foot a { color: var(--sigport-ink); text-underline-offset: 2px; }
592
+ .account { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--sigport-line); border-radius: var(--sigport-radius); }
593
+ .looking { margin: 0; min-height: 60px; font-size: 14px; color: var(--sigport-muted); }
594
+ .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
595
+ `;
596
+
597
+ // src/signin.ts
598
+ if (typeof customElements !== "undefined" && !customElements.get("sigport-relays")) customElements.define("sigport-relays", SigportRelays);
599
+ var appsLimitConverter = {
600
+ fromAttribute: (value) => {
601
+ if (value === null) return void 0;
602
+ const text = value.trim().toLowerCase();
603
+ if (text === "auto" || text === "none") return text;
604
+ const number = Number(text);
605
+ return Number.isFinite(number) && number >= 0 ? Math.floor(number) : void 0;
606
+ },
607
+ toAttribute: (value) => value === void 0 ? null : String(value)
608
+ };
609
+ var hideAppsConverter = {
610
+ fromAttribute: (value) => {
611
+ if (value === null) return false;
612
+ const text = value.trim();
613
+ if (text === "" || text.toLowerCase() === "true" || text.toLowerCase() === "hide-apps") return true;
614
+ if (text.toLowerCase() === "false") return false;
615
+ return text.split(",").map((id) => id.trim()).filter(Boolean);
616
+ },
617
+ toAttribute: (value) => value === true ? "" : value === false ? null : typeof value === "string" ? value : value.join(",")
618
+ };
619
+ function appsHidden(setting, adapterId) {
620
+ if (setting === true) return true;
621
+ if (!setting) return false;
622
+ const ids = typeof setting === "string" ? setting.split(",").map((id) => id.trim()) : setting;
623
+ return ids.includes(adapterId);
624
+ }
625
+ var SigportSignIn = class _SigportSignIn extends LitElement2 {
626
+ constructor() {
627
+ super();
628
+ this.refit = () => {
629
+ this.fitted = /* @__PURE__ */ new Map();
630
+ };
631
+ this.expanded = /* @__PURE__ */ new Set();
632
+ this.opening = "idle";
633
+ this.fitted = /* @__PURE__ */ new Map();
634
+ this.hideApps = false;
635
+ this.hideChevrons = false;
636
+ this.sides = "all";
637
+ this.pasteFirst = false;
638
+ this.suggestRelays = false;
639
+ this.manualPairing = false;
640
+ this.strings = {};
641
+ this.theme = "auto";
642
+ this.bare = false;
643
+ this.hideFooter = false;
644
+ this.compact = false;
645
+ this.showOthers = false;
646
+ this.deep = false;
647
+ this.settled = true;
648
+ this.copied = "idle";
649
+ this.switching = false;
650
+ }
651
+ static {
652
+ this.styles = styles;
653
+ }
654
+ static {
655
+ this.properties = {
656
+ sigport: { attribute: false },
657
+ strings: { attribute: false },
658
+ theme: { reflect: true },
659
+ include: {},
660
+ exclude: {},
661
+ appName: { attribute: "app-name" },
662
+ snapId: { attribute: "snap-id" },
663
+ relays: {},
664
+ namespace: {},
665
+ bare: { type: Boolean, reflect: true },
666
+ hideFooter: { type: Boolean, attribute: "hide-footer" },
667
+ compact: { type: Boolean, reflect: true },
668
+ hideApps: { attribute: "hide-apps", converter: hideAppsConverter },
669
+ hideChevrons: { type: Boolean, attribute: "hide-chevrons" },
670
+ sides: {},
671
+ pasteFirst: { type: Boolean, attribute: "paste-first" },
672
+ appsLimit: { attribute: "apps-limit", converter: appsLimitConverter },
673
+ appsMore: { attribute: "apps-more" },
674
+ manualPairing: { type: Boolean, attribute: "manual-pairing" },
675
+ relayTimeout: { type: Number, attribute: "relay-timeout" },
676
+ suggestRelays: { type: Boolean, attribute: "suggest-relays" },
677
+ relayMonitors: { attribute: "relay-monitors" },
678
+ monitorPubkeys: { attribute: "monitor-pubkeys" },
679
+ monitorMaxAge: { attribute: "monitor-max-age" },
680
+ expanded: { state: true },
681
+ state: { state: true },
682
+ showOthers: { state: true },
683
+ deep: { state: true },
684
+ settled: { state: true },
685
+ copied: { state: true },
686
+ opening: { state: true },
687
+ fitted: { state: true },
688
+ switching: { state: true }
689
+ };
690
+ }
691
+ get t() {
692
+ return { ...DEFAULT_STRINGS, ...this.strings };
693
+ }
694
+ connectedCallback() {
695
+ super.connectedCallback();
696
+ globalThis.addEventListener?.("resize", this.refit);
697
+ this.requestUpdate();
698
+ }
699
+ disconnectedCallback() {
700
+ super.disconnectedCallback();
701
+ globalThis.removeEventListener?.("resize", this.refit);
702
+ clearTimeout(this.openTimer);
703
+ this.unsubscribe?.();
704
+ this.unsubscribe = void 0;
705
+ this.attached = void 0;
706
+ this.dropOwned();
707
+ }
708
+ willUpdate(_changed) {
709
+ if (!this.isConnected) return;
710
+ if (this.sigport && this.sigport !== this.owned) this.dropOwned();
711
+ if (!this.sigport && _SigportSignIn.createDefault) {
712
+ this.owned = this.sigport = _SigportSignIn.createDefault(this);
713
+ this.attach();
714
+ return;
715
+ }
716
+ this.attach();
717
+ }
718
+ /** Destroy the session this element made itself, if it made one. Sessions passed in are never destroyed here. */
719
+ dropOwned() {
720
+ const owned = this.owned;
721
+ this.owned = void 0;
722
+ if (!owned) return;
723
+ owned.destroy();
724
+ if (this.sigport === owned) this.sigport = void 0;
725
+ }
726
+ attach() {
727
+ if (this.unsubscribe && this.attached === this.sigport) return;
728
+ this.unsubscribe?.();
729
+ this.unsubscribe = void 0;
730
+ const sigport = this.attached = this.sigport;
731
+ if (!sigport) return;
732
+ this.state = sigport.getState();
733
+ this.lastActive = this.state.active?.id ?? null;
734
+ this.unsubscribe = sigport.subscribe((state) => this.receive(state));
735
+ void sigport.detect();
736
+ }
737
+ receive(state) {
738
+ const active = state.active?.id ?? null;
739
+ if (active !== this.lastActive) {
740
+ this.lastActive = active;
741
+ this.switching = false;
742
+ if (state.active) this.dispatchEvent(new CustomEvent("sigport-signin", { detail: { account: state.active }, bubbles: true, composed: true }));
743
+ else this.dispatchEvent(new CustomEvent("sigport-signout", { bubbles: true, composed: true }));
744
+ }
745
+ if (state.screen !== this.lastScreen) {
746
+ this.fitted = /* @__PURE__ */ new Map();
747
+ this.opening = "idle";
748
+ const deep = state.screen.name !== "list";
749
+ if (deep !== this.deep) this.slide(deep);
750
+ if (deep) this.lastScreen = state.screen;
751
+ this.copied = "idle";
752
+ }
753
+ this.state = state;
754
+ }
755
+ updated(changed) {
756
+ super.updated(changed);
757
+ this.fit();
758
+ }
759
+ /**
760
+ * The `auto` app limit: when the card runs past the bottom of the window,
761
+ * list fewer apps (never under two) behind `Show more`. It only shrinks, and
762
+ * starts again on a new screen or a resize.
763
+ */
764
+ fit() {
765
+ if (!this.settled || !this.deep || typeof innerHeight === "undefined") return;
766
+ const list2 = this.renderRoot.querySelector(".pane.detail ul.apps");
767
+ const card = this.renderRoot.querySelector(".card");
768
+ const adapterId = list2?.dataset.adapter;
769
+ if (!list2 || !card || !adapterId || this.expanded.has(adapterId)) return;
770
+ const setting = this.appsLimit ?? this.sigport?.adapter(adapterId)?.catalogLimit ?? "auto";
771
+ if (setting !== "auto") return;
772
+ const box = card.getBoundingClientRect();
773
+ if (!box.height) return;
774
+ const top = box.top >= 0 && box.top < innerHeight / 2 ? box.top : 16;
775
+ const overflow = box.height - (innerHeight - top - 16);
776
+ if (overflow <= 0) return;
777
+ const rows = [...list2.querySelectorAll(":scope > li:not(.toggle)")];
778
+ const row = rows[0]?.getBoundingClientRect().height ?? 0;
779
+ if (!row) return;
780
+ const toggle = list2.querySelector(":scope > li.toggle") ? 0 : 44;
781
+ let keep = Math.max(2, rows.length - Math.ceil((overflow + toggle) / (row + 8)));
782
+ if (rows.length - keep === 1) keep = Math.max(2, keep - 1);
783
+ if (keep < rows.length && keep !== this.fitted.get(adapterId)) this.fitted = new Map([...this.fitted, [adapterId, keep]]);
784
+ }
785
+ /** Slide, then hide the pane that left, so the card takes the height of the one that stayed. */
786
+ slide(deep) {
787
+ this.settled = false;
788
+ this.deep = deep;
789
+ clearTimeout(this.settleTimer);
790
+ this.settleTimer = setTimeout(() => {
791
+ this.settled = true;
792
+ const pane = this.renderRoot.querySelector(deep ? ".pane.detail" : ".pane.list");
793
+ pane?.querySelector(deep ? ".back" : "h2")?.focus?.();
794
+ }, 360);
795
+ }
796
+ render() {
797
+ const state = this.state;
798
+ const t = this.t;
799
+ if (!state || !this.sigport) return html2`<div class="card" part="card"><div class="pane"><p class="looking" role="status">${t.looking}</p></div></div>`;
800
+ const awayList = this.deep && this.settled;
801
+ const awayDetail = !this.deep && this.settled;
802
+ return html2`
803
+ <div class="card" part="card" aria-busy=${state.busy ? "true" : "false"}>
804
+ <div class="viewport">
805
+ <div class="track ${this.deep ? "deep" : ""}">
806
+ <section class="pane list ${awayList ? "away" : ""}" ?inert=${this.deep} aria-hidden=${this.deep ? "true" : "false"}>${this.renderHome(state)}</section>
807
+ <section class="pane detail ${awayDetail ? "away" : ""}" ?inert=${!this.deep} aria-hidden=${this.deep ? "false" : "true"}>${this.renderDetail(state)}</section>
808
+ </div>
809
+ </div>
810
+ </div>
811
+ `;
812
+ }
813
+ renderHeader() {
814
+ const t = this.t;
815
+ return html2`<header part="header"><p class="label">${t.label}</p><h2 part="title" tabindex="-1">${t.title}</h2><p class="lede" part="lede">${t.lede}</p></header>`;
816
+ }
817
+ renderHome(state) {
818
+ const t = this.t;
819
+ const sigport = this.sigport;
820
+ if (state.active && !this.switching) {
821
+ const who = describeAccount(state.active);
822
+ return html2`
823
+ <header part="header"><p class="label">${t.signedInAs}</p><h2 part="title" tabindex="-1"><slot name="account-${state.active.pubkey}">${who.name}</slot></h2><p class="lede" part="lede">${who.via}</p></header>
824
+ <div class="actions">
825
+ <button type="button" class="btn primary" part="button" @click=${() => sigport.signOut()}>${t.signOut}</button>
826
+ <button type="button" class="btn" part="button" @click=${() => this.switching = true}>${t.switchAccount}</button>
827
+ </div>
828
+ ${this.renderFooter()}
829
+ `;
830
+ }
831
+ const remembered = state.accounts.filter((account) => account.id !== state.active?.id);
832
+ const rows = describeRows(sigport, state);
833
+ return html2`
834
+ ${this.renderHeader()}
835
+ ${remembered.length ? html2`<section aria-label=${t.remembered}>
836
+ <p class="label" style="margin-bottom:8px">${t.remembered}</p>
837
+ <ul>
838
+ ${remembered.map((account) => {
839
+ const who = describeAccount(account);
840
+ return html2`<li class="account">
841
+ <span class="words"><span class="name"><slot name="account-${account.pubkey}">${who.name}</slot></span><span class="hint">${who.via}</span></span>
842
+ <button type="button" class="btn" part="button" ?disabled=${state.busy} @click=${() => sigport.resume(account)}>${t.signInRemembered}</button>
843
+ <button type="button" class="btn quiet" part="button" aria-label="${t.forget} ${who.name}" @click=${() => sigport.forget(account)}>${t.forget}</button>
844
+ </li>`;
845
+ })}
846
+ </ul>
847
+ </section>` : nothing2}
848
+ ${state.status !== "ready" ? html2`<p class="looking" role="status">${t.looking}</p>` : html2`<ul aria-label=${t.title}>
849
+ ${rows.shown.map((row) => this.renderRow(row, state))}
850
+ ${rows.others.length ? html2`<li class="toggle">
851
+ <button type="button" class="more" aria-expanded=${this.showOthers ? "true" : "false"} @click=${() => this.showOthers = !this.showOthers}>
852
+ ${t.others} (${rows.others.length}) ${icon(this.showOthers ? PATHS.chevronUp : PATHS.chevronDown, 14)}
853
+ </button>
854
+ </li>` : nothing2}
855
+ ${this.showOthers ? rows.others.map((row) => this.renderRow(row, state)) : nothing2}
856
+ </ul>`}
857
+ ${!this.deep && state.error ? html2`<p class="error" part="error" role="alert">${state.error}</p>` : nothing2}
858
+ ${this.renderFooter()}
859
+ `;
860
+ }
861
+ renderFooter() {
862
+ if (this.hideFooter) return nothing2;
863
+ return html2`<p class="foot">${this.t.footer} <a href="https://github.com/sigport/sigport" target="_blank" rel="noopener">sigport</a></p>`;
864
+ }
865
+ /** An icon tile. An adapter's row passes `adapter`, so a page can style one method's tile with `::part(tile-<id>)`. */
866
+ renderTile(row, adapter = false) {
867
+ const part = adapter ? `tile tile-${row.id}` : "tile";
868
+ if (row.logo) return html2`<span class="tile logo" part=${part} aria-hidden="true"><img src=${row.logo} alt="" width="34" height="34" /></span>`;
869
+ if (row.icon) return html2`<span class="tile ${row.id}" part=${part} aria-hidden="true">${icon(row.icon)}</span>`;
870
+ return html2`<span class="tile" part=${part} aria-hidden="true">${row.label.slice(0, 1)}</span>`;
871
+ }
872
+ renderRow(row, state) {
873
+ const sigport = this.sigport;
874
+ const side = this.sides === "none" || this.sides === "disabled" && row.enabled ? void 0 : row.side;
875
+ return html2`<li>
876
+ <button
877
+ type="button"
878
+ part="row"
879
+ class="row ${row.emphasis} ${row.dashed ? "dashed" : ""}"
880
+ data-adapter=${row.id}
881
+ ?disabled=${state.busy || !row.enabled}
882
+ @click=${() => sigport.choose(row.id)}
883
+ >
884
+ ${this.renderTile(row, true)}
885
+ <span class="words"><span class="name">${row.label}</span><span class="hint">${row.note}</span></span>
886
+ ${row.opens && !this.hideChevrons ? html2`<span class="chev" aria-hidden="true">${icon(PATHS.chevronRight, 16)}</span>` : nothing2}
887
+ </button>
888
+ ${side ? side.kind === "catalog" ? html2`<button type="button" class="side" part="side" aria-label=${side.label} title=${side.label} @click=${() => sigport.openCatalog(row.id)}>${icon(PATHS.info)}</button>` : html2`<a class="side" part="side" href=${side.href} target="_blank" rel="noopener noreferrer" aria-label=${side.label} title=${side.label}>${icon(PATHS[side.kind])}</a>` : nothing2}
889
+ </li>`;
890
+ }
891
+ renderDetail(state) {
892
+ const screen = state.screen.name === "list" ? this.lastScreen : state.screen;
893
+ if (!screen || screen.name === "list") return nothing2;
894
+ const sigport = this.sigport;
895
+ const t = this.t;
896
+ const back = html2`<button type="button" class="back" @click=${() => sigport.back()}>${icon(PATHS.back)} ${t.back}</button>`;
897
+ const error = this.deep && state.error ? html2`<p class="error" part="error" role="alert">${state.error}</p>` : nothing2;
898
+ if (screen.name === "relays") {
899
+ const title = sigport.viewOf(screen.adapter)?.title ?? t.back;
900
+ return html2`<button type="button" class="back" @click=${() => sigport.back()}>${icon(PATHS.back)} ${title}</button>
901
+ <header part="header"><h2 part="title">${t.relaysTitle}</h2><p class="lede" part="lede">${t.relaysLede}</p></header>
902
+ <sigport-relays .sigport=${sigport} .strings=${this.strings}></sigport-relays>`;
903
+ }
904
+ if (screen.name === "catalog") {
905
+ const adapter2 = sigport.adapter(screen.adapter);
906
+ const isExtension = adapter2?.kind === "extension";
907
+ return html2`${back}
908
+ <header part="header"><h2 part="title">${isExtension ? t.extensionsTitle : `${adapter2?.label ?? ""}: ${t.apps}`}</h2><p class="lede" part="lede">${isExtension ? t.extensionsLede : t.appsLede}</p></header>
909
+ ${this.renderCatalog(screen.adapter, state)}
910
+ ${error}
911
+ <div class="recheck"><span>${t.installedRecheck}</span><button type="button" class="btn" part="button" @click=${() => sigport.recheck()}>${icon(PATHS.refresh, 16)} ${t.recheck}</button></div>`;
912
+ }
913
+ let view;
914
+ if (screen.name === "unlock") {
915
+ const account = sigport.manager.getAccount(screen.account);
916
+ view = account ? sigport.adapter(screen.adapter)?.unlock?.view?.(account) : void 0;
917
+ } else view = sigport.viewOf(screen.adapter);
918
+ if (!view) return back;
919
+ const adapter = sigport.adapter(screen.adapter);
920
+ const catalog = screen.name === "view" && adapter?.catalog?.length && !appsHidden(this.hideApps, screen.adapter);
921
+ const form = Boolean(view.fields?.length || view.actions?.length);
922
+ return html2`${back}
923
+ <header part="header"><h2 part="title">${view.title}</h2>${view.lede ? html2`<p class="lede" part="lede">${view.lede}</p>` : nothing2}</header>
924
+ ${this.pasteFirst && view.pairing && form ? html2`${this.renderForm(view, state)}<div class="or">${t.orPair}</div>${this.renderPairing(view, state)}` : html2`${view.pairing ? this.renderPairing(view, state) : nothing2}
925
+ ${view.pairing && form ? html2`<div class="or">${t.orPaste}</div>` : nothing2}
926
+ ${form ? this.renderForm(view, state) : nothing2}`}
927
+ ${view.note ? html2`<p class="note">${view.note}</p>` : nothing2}
928
+ ${error}
929
+ ${catalog ? html2`<p class="label" id="signer-apps" style="margin-top:4px">${t.appsTitle}</p>${this.renderCatalog(screen.adapter, state)}` : nothing2}`;
930
+ }
931
+ renderPairing(view, state) {
932
+ const t = this.t;
933
+ const sigport = this.sigport;
934
+ const pairing = state.pairing;
935
+ const changeRelays = view.pairing.relays ? html2`<button type="button" class="btn quiet small" part="button" @click=${() => sigport.openRelays()}>${t.changeRelays}</button>` : nothing2;
936
+ if (pairing && !pairing.uri) {
937
+ return html2`<figure class="qr" part="qr">
938
+ <div class="qr-slot" aria-hidden=${pairing.checks?.length ? "false" : "true"}>
939
+ ${pairing.checks?.length ? html2`<ul class="checks">
940
+ ${pairing.checks.map(
941
+ (check) => html2`<li><span class="dot ${check.status}" aria-hidden="true"></span><code>${shortRelay2(check.url)}</code><span class="ms">${check.status === "ok" ? `${check.ms ?? ""} ms` : check.status === "failed" ? t.noAnswer : check.status === "checking" ? "\u2026" : ""}</span></li>`
942
+ )}
943
+ </ul>` : nothing2}
944
+ </div>
945
+ <p class="status" role="status"><span class="dot" aria-hidden="true"></span>${pairing.checks?.length ? t.finding : t.making}</p>
946
+ </figure>`;
947
+ }
948
+ if (!pairing?.uri) {
949
+ return html2`<ul><li>
950
+ <button type="button" part="row" class="row top" ?disabled=${state.busy} @click=${() => sigport.startPairing()}>
951
+ <span class="tile" part="tile" aria-hidden="true">${icon(PATHS.qr)}</span>
952
+ <span class="words"><span class="name">${state.error ? t.tryAgain : view.pairing.label}</span><span class="hint">${state.error ? t.tryAgainNote : t.pairingNote}</span></span>
953
+ ${this.hideChevrons ? nothing2 : html2`<span class="chev" aria-hidden="true">${icon(PATHS.chevronRight, 16)}</span>`}
954
+ </button>
955
+ </li></ul>
956
+ ${state.error ? html2`<div class="actions center">${changeRelays}</div>` : nothing2}`;
957
+ }
958
+ const uri = pairing.uri;
959
+ const qr = encode(uri, { ecc: "M", border: 0 });
960
+ const d = qr.data.flatMap((row, y) => row.map((dark, x) => dark ? `M${x} ${y}h1v1h-1z` : "")).join("");
961
+ const copy = async () => {
962
+ try {
963
+ await navigator.clipboard.writeText(uri);
964
+ this.copied = "done";
965
+ } catch {
966
+ this.copied = "failed";
967
+ }
968
+ };
969
+ const tapped = () => {
970
+ this.opening = "trying";
971
+ clearTimeout(this.openTimer);
972
+ this.openTimer = setTimeout(() => {
973
+ if (this.opening === "trying" && document.visibilityState === "visible") this.opening = "missed";
974
+ }, 1500);
975
+ };
976
+ const viewing = state.screen.name === "view" ? state.screen.adapter : "";
977
+ const signerApps = sigport.adapter(viewing)?.catalog?.length && !appsHidden(this.hideApps, viewing);
978
+ return html2`<figure class="qr" part="qr">
979
+ <a class="qr-code" part="qr-code" href=${uri} aria-label=${t.openInSigner} title=${t.openInSigner} @click=${tapped}>
980
+ ${svg2`<svg viewBox="0 0 ${qr.size} ${qr.size}" role="img" aria-label="Pairing code as a QR code" shape-rendering="crispEdges"><path d=${d} fill="#000"></path></svg>`}
981
+ <span class="tap-mark" aria-hidden="true">${icon(PATHS.tap, 16)}</span>
982
+ </a>
983
+ <p class="tap-hint">${t.tapToOpen}</p>
984
+ ${pairing.relay ? html2`<p class="relay-line" part="relay"><span class="dot ok" aria-hidden="true"></span>${t.via} <code>${shortRelay2(pairing.relay)}</code><button type="button" class="chip" @click=${() => sigport.openRelays()}>${t.change}</button>${this.compact ? html2`<button type="button" class="chip copy" aria-label=${t.copy} title=${this.copied === "done" ? t.copied : t.copy} @click=${copy}>${icon(PATHS.copy, 14)}</button>` : nothing2}</p>` : nothing2}
985
+ ${this.opening === "trying" ? html2`<p class="status" role="status"><span class="dot" aria-hidden="true"></span>${t.opening}</p>` : this.opening === "missed" ? html2`<p class="note opened" role="status">${t.nothingOpened} ${signerApps ? html2`<a href="#signer-apps" @click=${(event) => (event.preventDefault(), this.renderRoot.querySelector("#signer-apps")?.scrollIntoView({ block: "nearest", behavior: "smooth" }))}>${t.getSigner}</a>` : nothing2} ${t.orCopy}</p>` : nothing2}
986
+ ${this.compact && pairing.relay ? nothing2 : html2`<div class="actions"><button type="button" class="btn" part="button" @click=${copy}>${icon(PATHS.copy, 16)} ${this.copied === "done" ? t.copied : t.copy}</button></div>`}
987
+ ${this.copied === "failed" ? html2`<p class="note">${t.copyFailed}</p>` : nothing2}
988
+ <p class="status ${this.compact ? "quiet" : ""}" role="status"><span class="dot" aria-hidden="true"></span>${t.waiting}</p>
989
+ </figure>`;
990
+ }
991
+ renderForm(view, state) {
992
+ const sigport = this.sigport;
993
+ const fields = view.fields ?? [];
994
+ const actions = view.actions ?? [];
995
+ const claimed = new Set(actions.flatMap((action) => action.fields ?? []));
996
+ const drawn = /* @__PURE__ */ new Set();
997
+ const values = (form) => Object.fromEntries([...new FormData(form).entries()].map(([key, value]) => [key, String(value)]));
998
+ const run = (action, form) => {
999
+ if (form) void sigport.run(action.id, values(form));
1000
+ };
1001
+ const fieldsBefore = (action) => {
1002
+ const names = action.fields ?? fields.filter((field) => !claimed.has(field.name)).map((field) => field.name);
1003
+ const fresh = fields.filter((field) => names.includes(field.name) && !drawn.has(field.name));
1004
+ for (const field of fresh) drawn.add(field.name);
1005
+ return fresh;
1006
+ };
1007
+ const primary = actions.find((action) => action.primary) ?? actions[0];
1008
+ const groups = [];
1009
+ for (const action of actions) {
1010
+ const fresh = fieldsBefore(action);
1011
+ const last = groups.at(-1);
1012
+ if (last && !fresh.length) last.actions.push(action);
1013
+ else groups.push({ fields: [...fresh], actions: [action] });
1014
+ }
1015
+ const leftover = fields.filter((field) => !drawn.has(field.name));
1016
+ if (leftover.length) groups.unshift({ fields: leftover, actions: [] });
1017
+ return html2`<form
1018
+ @submit=${(event) => {
1019
+ event.preventDefault();
1020
+ if (primary) run(primary, event.currentTarget);
1021
+ }}
1022
+ @input=${() => this.requestUpdate()}
1023
+ >
1024
+ ${groups.map(
1025
+ (group) => html2`<div class="group ${group.fields.length === 1 && group.actions.length === 1 ? "single" : ""}">
1026
+ ${group.fields.map(
1027
+ (field) => html2`<label class="field" part="field"
1028
+ ><span class="field-label">${field.label}</span><input
1029
+ part="input"
1030
+ class=${field.mono ? "mono" : ""}
1031
+ name=${field.name}
1032
+ type=${field.type ?? "text"}
1033
+ .value=${field.value ?? ""}
1034
+ placeholder=${field.placeholder ?? (this.compact ? field.label : "")}
1035
+ autocomplete=${field.autocomplete ?? "off"}
1036
+ spellcheck="false"
1037
+ /></label>`
1038
+ )}
1039
+ ${group.actions.length ? html2`<div class="actions">
1040
+ ${group.actions.map(
1041
+ (action) => html2`<button
1042
+ type=${action === primary ? "submit" : "button"}
1043
+ part="button"
1044
+ class="btn ${action.primary ? "primary" : ""}"
1045
+ ?disabled=${state.busy || !this.filled(action)}
1046
+ @click=${(event) => {
1047
+ if (action === primary) return;
1048
+ run(action, event.currentTarget.closest("form"));
1049
+ }}
1050
+ >
1051
+ ${action.label}
1052
+ </button>`
1053
+ )}
1054
+ </div>` : nothing2}
1055
+ </div>`
1056
+ )}
1057
+ </form>`;
1058
+ }
1059
+ /** Whether the fields an action needs have something in them. */
1060
+ filled(action) {
1061
+ if (!action.needs?.length) return true;
1062
+ const form = this.renderRoot.querySelector(".pane.detail form");
1063
+ if (!form) return false;
1064
+ return action.needs.every((name) => String(new FormData(form).get(name) ?? "").trim().length > 0);
1065
+ }
1066
+ renderCatalog(adapterId, state) {
1067
+ const sigport = this.sigport;
1068
+ const setting = this.appsLimit ?? sigport.adapter(adapterId)?.catalogLimit ?? "auto";
1069
+ const limit = typeof setting === "number" ? setting : setting === "auto" ? this.fitted.get(adapterId) ?? Infinity : Infinity;
1070
+ const { shown, hidden, more } = describeCatalog(sigport, adapterId, state, {
1071
+ ...limit !== void 0 ? { limit } : {},
1072
+ expanded: this.expanded.has(adapterId)
1073
+ });
1074
+ const usable = state.availability[adapterId] === "ready";
1075
+ const words = (this.appsMore ?? more ?? this.t.moreApps).replace("{count}", String(hidden.length));
1076
+ return html2`<ul class="apps" data-adapter=${adapterId}>
1077
+ ${shown.map((app) => {
1078
+ const tile = this.renderTile({ id: app.id, logo: app.logo, label: app.name });
1079
+ if (app.installed) {
1080
+ return html2`<li>
1081
+ <button type="button" part="row" class="row top" ?disabled=${state.busy || !usable} @click=${() => sigport.choose(adapterId)}>
1082
+ ${tile}<span class="words"><span class="name">${app.name}<span class="badge">${this.t.ready}</span></span><span class="hint">${app.platforms}</span></span>
1083
+ </button>
1084
+ </li>`;
1085
+ }
1086
+ const label = `${app.link === "download" ? "Get" : "Open"} ${app.name}`;
1087
+ return html2`<li>
1088
+ <a part="row" class="row quiet" href=${app.href} target="_blank" rel="noopener noreferrer">
1089
+ ${tile}<span class="words"><span class="name">${app.name}</span><span class="hint">${app.platforms}</span></span>
1090
+ </a>
1091
+ <a class="side" part="side" href=${app.href} target="_blank" rel="noopener noreferrer" aria-label=${label} title=${label}>${icon(app.link === "download" ? PATHS.download : PATHS.open)}</a>
1092
+ </li>`;
1093
+ })}
1094
+ ${hidden.length ? html2`<li class="toggle"><button type="button" class="more" part="more" @click=${() => this.expanded = /* @__PURE__ */ new Set([...this.expanded, adapterId])}>${words} ${icon(PATHS.chevronDown, 16)}</button></li>` : nothing2}
1095
+ </ul>`;
1096
+ }
1097
+ };
1098
+
1099
+ // src/button.ts
1100
+ var SigportButton = class extends LitElement3 {
1101
+ static {
1102
+ this.styles = [
1103
+ styles,
1104
+ css2`
1105
+ :host { display: inline-block; width: auto; max-width: none; }
1106
+ dialog { padding: 0; border: 0; background: none; width: min(100vw - 24px, var(--sigport-width)); max-height: calc(100dvh - 24px); overflow: auto; color: inherit; }
1107
+ dialog::backdrop { background: rgb(9 9 11 / 0.5); }
1108
+ .close { position: absolute; top: 12px; right: 12px; z-index: 1; width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; color: var(--sigport-muted); cursor: pointer; border-radius: 999px; }
1109
+ .close:hover { color: var(--sigport-ink); }
1110
+ .wrap { position: relative; }
1111
+ `
1112
+ ];
1113
+ }
1114
+ static {
1115
+ this.properties = {
1116
+ sigport: { attribute: false },
1117
+ strings: { attribute: false },
1118
+ theme: { reflect: true },
1119
+ include: {},
1120
+ exclude: {},
1121
+ appName: { attribute: "app-name" },
1122
+ snapId: { attribute: "snap-id" },
1123
+ relays: {},
1124
+ namespace: {},
1125
+ hideApps: { attribute: "hide-apps", converter: hideAppsConverter },
1126
+ hideChevrons: { type: Boolean, attribute: "hide-chevrons" },
1127
+ sides: {},
1128
+ pasteFirst: { type: Boolean, attribute: "paste-first" },
1129
+ appsLimit: { attribute: "apps-limit", converter: appsLimitConverter },
1130
+ relayTimeout: { type: Number, attribute: "relay-timeout" },
1131
+ suggestRelays: { type: Boolean, attribute: "suggest-relays" },
1132
+ relayMonitors: { attribute: "relay-monitors" },
1133
+ monitorPubkeys: { attribute: "monitor-pubkeys" },
1134
+ monitorMaxAge: { attribute: "monitor-max-age" },
1135
+ appsMore: { attribute: "apps-more" },
1136
+ manualPairing: { type: Boolean, attribute: "manual-pairing" },
1137
+ compact: { type: Boolean },
1138
+ state: { state: true }
1139
+ };
1140
+ }
1141
+ constructor() {
1142
+ super();
1143
+ this.strings = {};
1144
+ this.theme = "auto";
1145
+ this.hideApps = false;
1146
+ this.hideChevrons = false;
1147
+ this.sides = "all";
1148
+ this.pasteFirst = false;
1149
+ this.manualPairing = false;
1150
+ this.compact = false;
1151
+ this.suggestRelays = false;
1152
+ }
1153
+ connectedCallback() {
1154
+ super.connectedCallback();
1155
+ this.requestUpdate();
1156
+ }
1157
+ disconnectedCallback() {
1158
+ super.disconnectedCallback();
1159
+ this.unsubscribe?.();
1160
+ this.unsubscribe = void 0;
1161
+ this.attached = void 0;
1162
+ const owned = this.owned;
1163
+ this.owned = void 0;
1164
+ if (owned) {
1165
+ owned.destroy();
1166
+ if (this.sigport === owned) this.sigport = void 0;
1167
+ }
1168
+ }
1169
+ willUpdate() {
1170
+ if (!this.isConnected) return;
1171
+ if (this.owned && this.sigport !== this.owned) {
1172
+ this.owned.destroy();
1173
+ this.owned = void 0;
1174
+ }
1175
+ if (!this.sigport && SigportSignIn.createDefault) {
1176
+ this.owned = this.sigport = SigportSignIn.createDefault(this);
1177
+ }
1178
+ if (this.sigport !== this.attached) {
1179
+ this.unsubscribe?.();
1180
+ this.attached = this.sigport;
1181
+ this.unsubscribe = this.sigport?.subscribe((state) => this.state = state);
1182
+ this.state = this.sigport?.getState();
1183
+ }
1184
+ }
1185
+ /** Open the panel. */
1186
+ open() {
1187
+ this.renderRoot.querySelector("dialog")?.showModal();
1188
+ }
1189
+ /** Close the panel. */
1190
+ close() {
1191
+ this.renderRoot.querySelector("dialog")?.close();
1192
+ this.sigport?.back();
1193
+ }
1194
+ render() {
1195
+ const t = { ...DEFAULT_STRINGS, ...this.strings };
1196
+ const active = this.state?.active;
1197
+ return html3`
1198
+ <button type="button" class="btn ${active ? "" : "primary"}" part="button" @click=${() => this.open()}>
1199
+ ${active ? describeAccount2(active).name : t.button}
1200
+ </button>
1201
+ <dialog part="dialog" aria-label=${t.label} @close=${() => this.sigport?.back()} @click=${(event) => event.target === event.currentTarget && this.close()}>
1202
+ <div class="wrap">
1203
+ <button type="button" class="close" aria-label=${t.close} @click=${() => this.close()}>${icon(PATHS.close)}</button>
1204
+ ${this.sigport ? html3`<sigport-signin .sigport=${this.sigport} .strings=${this.strings} theme=${this.theme} .hideApps=${this.hideApps} ?hide-chevrons=${this.hideChevrons} .sides=${this.sides} ?paste-first=${this.pasteFirst} .appsLimit=${this.appsLimit} .appsMore=${this.appsMore} ?compact=${this.compact} @sigport-signin=${() => this.close()}></sigport-signin>` : nothing3}
1205
+ </div>
1206
+ </dialog>
1207
+ `;
1208
+ }
1209
+ };
1210
+
1211
+ // src/define.ts
1212
+ var list = (value) => value?.split(",").map((item) => item.trim()).filter(Boolean);
1213
+ SigportSignIn.createDefault = (element) => {
1214
+ const limit = element.appsLimit;
1215
+ const monitors = list(element.relayMonitors);
1216
+ const authors = list(element.monitorPubkeys);
1217
+ const suggestions = element.suggestRelays ? { ...monitors?.length ? { monitors } : {}, ...authors?.length ? { authors } : {}, ...element.monitorMaxAge ? { maxAge: element.monitorMaxAge } : {} } : void 0;
1218
+ const apps = (id) => ({
1219
+ ...appsHidden(element.hideApps, id) ? { apps: false } : {},
1220
+ ...limit !== void 0 ? { appsLimit: limit } : {},
1221
+ ...element.appsMore ? { appsMore: element.appsMore } : {}
1222
+ });
1223
+ return createSigport({
1224
+ adapters: all({
1225
+ ...element.snapId ? { metamask: { snapId: element.snapId } } : {},
1226
+ extension: apps("extension"),
1227
+ remote: { ...apps("remote"), ...element.relays ? { relays: list(element.relays) } : {}, ...element.manualPairing ? { autoPairing: false } : {} }
1228
+ }),
1229
+ ...element.include ? { include: list(element.include).filter((id) => BUILT_IN_IDS.includes(id)) } : {},
1230
+ ...element.exclude ? { exclude: list(element.exclude) } : {},
1231
+ ...element.appName ? { app: { name: element.appName } } : {},
1232
+ ...element.namespace ? { namespace: element.namespace } : {},
1233
+ ...element.relayTimeout !== void 0 && Number.isFinite(element.relayTimeout) ? { relayTimeoutMs: element.relayTimeout } : {},
1234
+ ...suggestions ? { relaySuggestions: suggestions } : {}
1235
+ });
1236
+ };
1237
+ if (!customElements.get("sigport-signin")) customElements.define("sigport-signin", SigportSignIn);
1238
+ if (!customElements.get("sigport-button")) customElements.define("sigport-button", SigportButton);
1239
+ export {
1240
+ SigportButton,
1241
+ SigportSignIn
1242
+ };